Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/ddd/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vitruvius-labs/ddd",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"author": {
"name": "VitruviusLabs"
Expand Down Expand Up @@ -46,7 +46,6 @@
"ci:build": "pnpm build"
},
"dependencies": {
"@vitruvius-labs/ts-predicate": "workspace:^",
"@vitruvius-labs/toolbox": "workspace:^"
"@vitruvius-labs/ts-predicate": "workspace:^"
}
}
1 change: 1 addition & 0 deletions packages/ddd/src/_index.mts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./base/_index.mjs";
export * from "./blank-record/_index.mjs";
export * from "./predefined-type/_index.mjs";
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./date-type-definition.mjs";
export * from "./last-update-date-meta-property.mjs";
export * from "./registration-date-meta-property.mjs";
export * from "./repository-date-meta-property.mjs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RepositoryDatePropertyDefinition } from "./repository-date-property-def
import { PredefinedMetaProperty } from "../../../base/auxiliary/meta-property/predefined-meta-property.mjs";
import { RepositoryDateProperty } from "./repository-date-property.mjs";
import { NullableTypeDefinition } from "../../../base/auxiliary/type-definition/nullable-type-definition.mjs";
import { DateTypeDefinition } from "./date-type-definition.mjs";
import { DateTypeDefinition } from "../../../predefined-type/date/date-type-definition.mjs";

abstract class RepositoryDateMetaProperty extends PredefinedMetaProperty<Date | null, RepositoryDatePropertyDefinition, RepositoryDateProperty>
{
Expand All @@ -26,7 +26,10 @@ abstract class RepositoryDateMetaProperty extends PredefinedMetaProperty<Date |
{
const type_definition: BaseTypeDefinition<Date | null> = new NullableTypeDefinition(new DateTypeDefinition());

return new RepositoryDatePropertyDefinition(this.getIdentifier(), type_definition);
return new RepositoryDatePropertyDefinition({
identifier: this.getIdentifier(),
typeDefinition: type_definition,
});
}

// eslint-disable-next-line @ts/class-methods-use-this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import type { BaseTypeDefinition } from "../../../base/auxiliary/type-definition/base-type-definition.mjs";
import { BasePropertyDefinition } from "../../../base/auxiliary/property-definition/base-property-definition.mjs";

class RepositoryDatePropertyDefinition extends BasePropertyDefinition<Date | null>
{
public constructor(identifier: string, type_definition: BaseTypeDefinition<Date | null>)
{
super({
identifier: identifier,
typeDefinition: type_definition,
});
}
}
class RepositoryDatePropertyDefinition extends BasePropertyDefinition<Date | null> {}

export { RepositoryDatePropertyDefinition };
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { PredefinedMetaProperty } from "../../../base/auxiliary/meta-property/pr
import { RepositoryStatusEnum } from "./definition/enum/repository-status.enum.mjs";
import { RepositoryStatusPropertyDefinition } from "./repository-status-property-definition.mjs";
import { RepositoryStatusProperty } from "./repository-status-property.mjs";
import { BlankRecordPropertyEnum } from "../../definition/enum/blank-record-property.enum.mjs";
import { RepositoryStatusTypeDefinition } from "./repository-status-type-definition.mjs";

class RepositoryStatusMetaProperty extends PredefinedMetaProperty<RepositoryStatusEnum, RepositoryStatusPropertyDefinition, RepositoryStatusProperty>
{
// eslint-disable-next-line @ts/class-methods-use-this, @ts/require-await
public async getPropertyDefinition(): Promise<RepositoryStatusPropertyDefinition>
{
return new RepositoryStatusPropertyDefinition();
return new RepositoryStatusPropertyDefinition({
identifier: BlankRecordPropertyEnum.REPOSITORY_STATUS,
typeDefinition: new RepositoryStatusTypeDefinition(),
});
}

// eslint-disable-next-line @ts/class-methods-use-this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import type { RepositoryStatusEnum } from "./definition/enum/repository-status.enum.mjs";
import { BasePropertyDefinition } from "../../../base/auxiliary/property-definition/base-property-definition.mjs";
import { BlankRecordPropertyEnum } from "../../definition/enum/blank-record-property.enum.mjs";
import { RepositoryStatusTypeDefinition } from "./repository-status-type-definition.mjs";

class RepositoryStatusPropertyDefinition extends BasePropertyDefinition<RepositoryStatusEnum>
{
public constructor()
{
super({
identifier: BlankRecordPropertyEnum.REPOSITORY_STATUS,
typeDefinition: new RepositoryStatusTypeDefinition(),
});
}
}
class RepositoryStatusPropertyDefinition extends BasePropertyDefinition<RepositoryStatusEnum> {}

export { RepositoryStatusPropertyDefinition };
2 changes: 0 additions & 2 deletions packages/ddd/src/blank-record/properties/uuid-v4/_index.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export type * from "./definition/_index.mjs";
export * from "./predicate/_index.mjs";
export * from "./uuid-v4-meta-property.mjs";
export * from "./uuid-v4-property-definition.mjs";
export * from "./uuid-v4-type-definition.mjs";
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import type { BasePropertyInstantiationInterface } from "../../../base/auxiliary
import { PredefinedMetaProperty } from "../../../base/auxiliary/meta-property/predefined-meta-property.mjs";
import { BaseImmutableProperty } from "../../../base/auxiliary/property/base-immutable-property.mjs";
import { UUIDv4PropertyDefinition } from "./uuid-v4-property-definition.mjs";
import { BlankRecordPropertyEnum } from "../../definition/enum/blank-record-property.enum.mjs";
import { UUIDv4TypeDefinition } from "../../../predefined-type/uuid-v4/uuid-v4-type-definition.mjs";

class UUIDv4MetaProperty extends PredefinedMetaProperty<UUID, UUIDv4PropertyDefinition, BaseImmutableProperty<UUID, UUIDv4PropertyDefinition>>
{
// eslint-disable-next-line @ts/class-methods-use-this, @ts/require-await
public async getPropertyDefinition(): Promise<UUIDv4PropertyDefinition>
{
return new UUIDv4PropertyDefinition();
return new UUIDv4PropertyDefinition({
identifier: BlankRecordPropertyEnum.UUID,
typeDefinition: new UUIDv4TypeDefinition(),
});
}

// eslint-disable-next-line @ts/class-methods-use-this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import type { UUID } from "node:crypto";
import { BasePropertyDefinition } from "../../../base/auxiliary/property-definition/base-property-definition.mjs";
import { UUIDv4TypeDefinition } from "./uuid-v4-type-definition.mjs";
import { BlankRecordPropertyEnum } from "../../definition/enum/blank-record-property.enum.mjs";

class UUIDv4PropertyDefinition extends BasePropertyDefinition<UUID>
{
public constructor()
{
super({
identifier: BlankRecordPropertyEnum.UUID,
typeDefinition: new UUIDv4TypeDefinition(),
});
}
}
class UUIDv4PropertyDefinition extends BasePropertyDefinition<UUID> {}

export { UUIDv4PropertyDefinition };
4 changes: 4 additions & 0 deletions packages/ddd/src/predefined-type/_index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./date/_index.mjs";
export * from "./lazy-reference/_index.mjs";
export * from "./password/_index.mjs";
export * from "./uuid-v4/_index.mjs";
1 change: 1 addition & 0 deletions packages/ddd/src/predefined-type/date/_index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./date-type-definition.mjs";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationError } from "@vitruvius-labs/ts-predicate";
import { BaseRequiredTypeDefinition } from "../../../base/auxiliary/type-definition/base-required-type-definition.mjs";
import { BaseRequiredTypeDefinition } from "../../base/auxiliary/type-definition/base-required-type-definition.mjs";

class DateTypeDefinition extends BaseRequiredTypeDefinition<Date>
{
Expand Down
3 changes: 3 additions & 0 deletions packages/ddd/src/predefined-type/lazy-reference/_index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./lazy-reference.mjs";
export * from "./null-reference.mjs";
export * from "./nullable-lazy-reference.mjs";
59 changes: 59 additions & 0 deletions packages/ddd/src/predefined-type/lazy-reference/lazy-reference.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { BaseRecord } from "../../base/primary/base-record.mjs";
import { NullableLazyReference } from "./nullable-lazy-reference.mjs";

abstract class LazyReference<T extends BaseRecord> extends NullableLazyReference<T>
{
protected readonly uuid: string;
protected cacheable: boolean;
protected cachedRecord: T | undefined;

public constructor(uuid: string)
{
super();

this.uuid = uuid;
this.cacheable = true;
this.cachedRecord = undefined;
}

protected abstract fetchRecord(): Promise<T>;

public getUUID(): string
{
return this.uuid;
}

public async getRecord(): Promise<T>
{
if (this.cachedRecord !== undefined)
{
return this.cachedRecord;
}

const record: T = await this.fetchRecord();

if (this.cacheable)
{
this.cachedRecord = record;
}

return record;
}

public enableCaching(): void
{
this.cacheable = true;
}

public disableCaching(): void
{
this.cacheable = false;
}

public clearCachedRecord(): void
{
this.cachedRecord = undefined;
}
}

export { LazyReference };
27 changes: 27 additions & 0 deletions packages/ddd/src/predefined-type/lazy-reference/null-reference.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { NullableLazyReference } from "./nullable-lazy-reference.mjs";

class NullReference extends NullableLazyReference<never>
{
// eslint-disable-next-line @ts/class-methods-use-this
public getUUID(): null
{
return null;
}

// eslint-disable-next-line @ts/class-methods-use-this, @ts/require-await
public async getRecord(): Promise<null>
{
return null;
}

// eslint-disable-next-line @ts/class-methods-use-this, @ts/no-empty-function
public enableCaching(): void {}

// eslint-disable-next-line @ts/class-methods-use-this, @ts/no-empty-function
public disableCaching(): void {}

// eslint-disable-next-line @ts/class-methods-use-this, @ts/no-empty-function
public clearCachedRecord(): void {}
}

export { NullReference };
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { BaseRecord } from "../../base/primary/base-record.mjs";

abstract class NullableLazyReference<T extends BaseRecord>
{
public abstract getUUID(): string | null;
public abstract getRecord(): Promise<T | null>;
public abstract enableCaching(): void;
public abstract disableCaching(): void;
public abstract clearCachedRecord(): void;
}

export { NullableLazyReference };
5 changes: 5 additions & 0 deletions packages/ddd/src/predefined-type/password/_index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type * from "./definition/_index.mjs";
export * from "./null-password.mjs";
export * from "./nullable-password.mjs";
export * from "./password.factory.mjs";
export * from "./password.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type * from "./interface/_index.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type * from "./password-instantiation.interface.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface PasswordInstantiationInterface
{
algorithm: string;
salt: string;
hash: string;
}

export type { PasswordInstantiationInterface };
30 changes: 30 additions & 0 deletions packages/ddd/src/predefined-type/password/null-password.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { NullablePassword } from "./nullable-password.mjs";

class NullPassword extends NullablePassword
{
// eslint-disable-next-line @ts/class-methods-use-this
public getAlgorithm(): null
{
return null;
}

// eslint-disable-next-line @ts/class-methods-use-this
public getSalt(): null
{
return null;
}

// eslint-disable-next-line @ts/class-methods-use-this
public getHash(): null
{
return null;
}

// eslint-disable-next-line @ts/class-methods-use-this
public verify(): false
{
return false;
}
}

export { NullPassword };
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
abstract class NullablePassword
{
public abstract getAlgorithm(): string | null;
public abstract getSalt(): string | null;
public abstract getHash(): string | null;
public abstract verify(password: string): boolean;
}

export { NullablePassword };
43 changes: 43 additions & 0 deletions packages/ddd/src/predefined-type/password/password.factory.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { hash as crypto_hash } from "node:crypto";
import type { NullablePassword } from "./nullable-password.mjs";
import { NullPassword } from "./null-password.mjs";
import { Password } from "./password.mjs";

class PasswordFactory
{
public static CreateNew(algorithm: string, salt: string, password: string): Password
{
const hash: string = crypto_hash(algorithm, password + salt);

return new Password({
algorithm: algorithm,
salt: salt,
hash: hash,
});
}

public static CreateExisting(algorithm: string, salt: string, hash: string): NullablePassword
{
return new Password({
algorithm: algorithm,
salt: salt,
hash: hash,
});
}

public static CreateNullable(algorithm: string | null, salt: string | null, hash: string | null): NullablePassword
{
if (algorithm === null || salt === null || hash === null)
{
return new NullPassword();
}

return new Password({
algorithm: algorithm,
salt: salt,
hash: hash,
});
}
}

export { PasswordFactory };
Loading
Loading