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
2 changes: 1 addition & 1 deletion 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.1",
"version": "0.1.2",
"description": "",
"author": {
"name": "VitruviusLabs"
Expand Down
1 change: 1 addition & 0 deletions packages/ddd/src/_index.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./base/_index.mjs";
export * from "./blank-record/_index.mjs";
export * from "./value-object/_index.mjs";
export * from "./predefined-type/_index.mjs";
2 changes: 1 addition & 1 deletion packages/ddd/src/base/auxiliary/meta-property/_index.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type * from "./definition/_index.mjs";
export * from "./base-meta-property.mjs";
export * from "./meta-property.mjs";
export * from "./predefined-meta-property.mjs";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type * from "./base-meta-property.type.mjs";
export type * from "./meta-property.type.mjs";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { MetaProperty } from "../../meta-property.mjs";
import type { PropertyType } from "../../../property/definition/type/property.type.mjs";
import type { PropertyDefinitionType } from "../../../property-definition/definition/type/property-definition.type.mjs";

type MetaPropertyType = MetaProperty<unknown, PropertyDefinitionType, PropertyType>;

export type { MetaPropertyType };
53 changes: 53 additions & 0 deletions packages/ddd/src/base/auxiliary/meta-property/meta-property.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { PropertyDefinition } from "../property-definition/property-definition.mjs";
import type { Property } from "../property/property.mjs";
import type { PropertyInstantiationInterface } from "../property/definition/interface/property-instantiation.interface.mjs";
import type { TypeDefinition } from "../type-definition/type-definition.mjs";

abstract class MetaProperty<T, PD extends PropertyDefinition<T> = PropertyDefinition<T>, P extends Property<T, PD> = Property<T, PD>>
{
public abstract getPropertyDefinition(): Promise<PD>;

protected abstract createProperty(parameters: PropertyInstantiationInterface<T, PD>): P;

public async createNewProperty(value: T): Promise<P>
{
const definition: PD = await this.getPropertyDefinition();

const property: P = this.createProperty({
definition: definition,
value: value,
existing: false,
});

return property;
}

public async createExistingProperty(value: unknown): Promise<P>
{
const property_definition: PD = await this.getPropertyDefinition();

const type_definition: TypeDefinition<T> = property_definition.getTypeDefinition();

const normalized_value: T = await this.normalize(value, type_definition);

await type_definition.verify(normalized_value);

const property: P = this.createProperty({
definition: property_definition,
value: normalized_value,
existing: true,
});

return property;
}

// eslint-disable-next-line @ts/class-methods-use-this, @ts/require-await
public async normalize(value: unknown, type_definition: TypeDefinition<T>): Promise<T>
{
type_definition.assertType(value);

return value;
}
}

export { MetaProperty };
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { BasePropertyDefinition } from "../property-definition/base-property-definition.mjs";
import type { BaseProperty } from "../property/base-property.mjs";
import { BaseMetaProperty } from "./base-meta-property.mjs";
import type { PropertyDefinition } from "../property-definition/property-definition.mjs";
import type { Property } from "../property/property.mjs";
import { MetaProperty } from "./meta-property.mjs";

abstract class PredefinedMetaProperty<T, PD extends BasePropertyDefinition<T>, P extends BaseProperty<T, PD> = BaseProperty<T, PD>> extends BaseMetaProperty<T, PD, P>
abstract class PredefinedMetaProperty<T, PD extends PropertyDefinition<T> = PropertyDefinition<T>, P extends Property<T, PD> = Property<T, PD>> extends MetaProperty<T, PD, P>
{
protected abstract getInitialValue(): Promise<T>;

public async createPredefinedProperty(): Promise<P>
{
// @ts-expect-error -- We have to assume this is the correct definition
const definition: PD = await this.getPropertyDefinition();

const property: P = this.createProperty({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export type * from "./definition/_index.mjs";
export * from "./base-property-definition-instantiation-interface.mjs";
export * from "./base-property-definition.mjs";
export * from "./property-definition.mjs";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export type * from "./interface/_index.mjs";
export type * from "./type/_index.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type * from "./property-definition-instantiation-interface.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { TypeDefinition } from "../../../type-definition/type-definition.mjs";

interface PropertyDefinitionInstantiationInterface<T>
{
identifier: string;
typeDefinition: TypeDefinition<T>;
}

export type { PropertyDefinitionInstantiationInterface };
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type * from "./base-property-definition.type.mjs";
export type * from "./property-definition.type.mjs";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { PropertyDefinition } from "../../property-definition.mjs";

type PropertyDefinitionType = PropertyDefinition<unknown>;

export type { PropertyDefinitionType };
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { NoValue } from "@vitruvius-labs/ts-predicate";
import type { BaseTypeDefinition } from "../type-definition/base-type-definition.mjs";
import type { BasePropertyDefinitionInstantiationInterface } from "./base-property-definition-instantiation-interface.mjs";
import type { TypeDefinition } from "../type-definition/type-definition.mjs";
import type { PropertyDefinitionInstantiationInterface } from "./definition/interface/property-definition-instantiation-interface.mjs";

abstract class BasePropertyDefinition<T>
class PropertyDefinition<T>
{
protected readonly identifier: string;
protected readonly typeDefinition: BaseTypeDefinition<T>;
protected readonly typeDefinition: TypeDefinition<T>;

public constructor(parameters: BasePropertyDefinitionInstantiationInterface<T>)
public constructor(parameters: PropertyDefinitionInstantiationInterface<T>)
{
this.identifier = parameters.identifier;
this.typeDefinition = parameters.typeDefinition;
Expand All @@ -18,7 +18,7 @@ abstract class BasePropertyDefinition<T>
return this.identifier;
}

public getTypeDefinition(): BaseTypeDefinition<T>
public getTypeDefinition(): TypeDefinition<T>
{
return this.typeDefinition;
}
Expand All @@ -31,4 +31,4 @@ abstract class BasePropertyDefinition<T>
}
}

export { BasePropertyDefinition };
export { PropertyDefinition };
4 changes: 2 additions & 2 deletions packages/ddd/src/base/auxiliary/property/_index.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type * from "./definition/_index.mjs";
export * from "./base-immutable-property.mjs";
export * from "./base-property.mjs";
export * from "./immutable-property.mjs";
export * from "./property.mjs";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type * from "./base-property-instantiation.interface.mjs";
export type * from "./property-instantiation.interface.mjs";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { PropertyDefinition } from "../../../property-definition/property-definition.mjs";

interface PropertyInstantiationInterface<T, PD extends PropertyDefinition<T>>
{
definition: PD;
value: T;
existing: boolean;
}

export type { PropertyInstantiationInterface };
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type * from "./base-property.type.mjs";
export type * from "./property.type.mjs";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Property } from "../../property.mjs";
import type { PropertyDefinitionType } from "../../../property-definition/definition/type/property-definition.type.mjs";

type PropertyType = Property<unknown, PropertyDefinitionType>;

export type { PropertyType };
20 changes: 20 additions & 0 deletions packages/ddd/src/base/auxiliary/property/immutable-property.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { PropertyDefinition } from "../property-definition/property-definition.mjs";
import type { PropertyInstantiationInterface } from "./definition/interface/property-instantiation.interface.mjs";
import { Property } from "./property.mjs";

class ImmutableProperty<T, PD extends PropertyDefinition<T> = PropertyDefinition<T>> extends Property<T, PD>
{
public constructor(parameters: PropertyInstantiationInterface<T, PD>)
{
super(parameters);

this.disableMutability();
}

public override setValue(): never
{
throw new Error(`Property "${this.getDefinition().getIdentifier()}" is immutable.`);
}
}

export { ImmutableProperty };
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { NoValue } from "@vitruvius-labs/ts-predicate";
import type { BasePropertyDefinition } from "../property-definition/base-property-definition.mjs";
import type { BasePropertyInstantiationInterface } from "./definition/interface/base-property-instantiation.interface.mjs";
import type { PropertyDefinition } from "../property-definition/property-definition.mjs";
import type { PropertyInstantiationInterface } from "./definition/interface/property-instantiation.interface.mjs";

class BaseProperty<T, PD extends BasePropertyDefinition<T>>
class Property<T, PD extends PropertyDefinition<T> = PropertyDefinition<T>>
{
private readonly definition: PD;
private mutability: boolean;
private value: T;
private previousValue: T | typeof NoValue;

public constructor(parameters: BasePropertyInstantiationInterface<T, PD>)
public constructor(parameters: PropertyInstantiationInterface<T, PD>)
{
this.definition = parameters.definition;
this.mutability = true;
Expand Down Expand Up @@ -78,4 +78,4 @@ class BaseProperty<T, PD extends BasePropertyDefinition<T>>
}
}

export { BaseProperty };
export { Property };
5 changes: 1 addition & 4 deletions packages/ddd/src/base/auxiliary/type-definition/_index.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export * from "./base-optional-type-definition.mjs";
export * from "./base-required-type-definition.mjs";
export * from "./base-type-definition.mjs";
export * from "./nullable-type-definition.mjs";
export * from "./type-definition.mjs";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
abstract class BaseTypeDefinition<T>
abstract class TypeDefinition<T>
{
public abstract assertType(value: unknown): asserts value is T;
public abstract isOptional(): boolean;
public abstract getEmptyValue(): T;
public abstract isEmptyValue(value: T): boolean;
public abstract assertType(value: unknown): asserts value is T;

// eslint-disable-next-line @ts/class-methods-use-this
public isEqual(value_a: T, value_b: T): boolean
Expand All @@ -16,4 +16,4 @@ abstract class BaseTypeDefinition<T>
public async verify(value: T): Promise<void> {}
}

export { BaseTypeDefinition };
export { TypeDefinition };
Loading
Loading