@routier/core 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +91 -0
- package/rspack.config.mjs +65 -0
- package/src/assertions/index.ts +37 -0
- package/src/codegen/SlotPath.ts +20 -0
- package/src/codegen/blocks.ts +578 -0
- package/src/codegen/handlers/CloneHandlerBuilder.ts +13 -0
- package/src/codegen/handlers/CompareHandlerBuilder.ts +13 -0
- package/src/codegen/handlers/DeserializeHandlerBuilder.ts +20 -0
- package/src/codegen/handlers/EnableChangeTrackingHandlerBuilder.ts +13 -0
- package/src/codegen/handlers/EnrichmentHandlerBuilder.ts +28 -0
- package/src/codegen/handlers/FreezeHandlerBuilder.ts +13 -0
- package/src/codegen/handlers/HashHandlerBuilder.ts +25 -0
- package/src/codegen/handlers/HashTypeHandlerBuilder.ts +11 -0
- package/src/codegen/handlers/IdSelectorHandlerBuilder.ts +10 -0
- package/src/codegen/handlers/MergeHandlerBuilder.ts +19 -0
- package/src/codegen/handlers/PrepareHandlerBuilder.ts +23 -0
- package/src/codegen/handlers/SerializeHandlerBuilder.ts +15 -0
- package/src/codegen/handlers/StripHandlerBuilder.ts +18 -0
- package/src/codegen/handlers/clone/CloneObjectHandler.ts +29 -0
- package/src/codegen/handlers/clone/CloneValueHandler.ts +33 -0
- package/src/codegen/handlers/compare/CompareObjectHandler.ts +15 -0
- package/src/codegen/handlers/compare/CompareValueHandler.ts +27 -0
- package/src/codegen/handlers/deserialize/DeserializeComputedValueHandler.ts +16 -0
- package/src/codegen/handlers/deserialize/DeserializeDateHandler.ts +45 -0
- package/src/codegen/handlers/deserialize/DeserializeFunctionHandler.ts +16 -0
- package/src/codegen/handlers/deserialize/DeserializeObjectHandler.ts +29 -0
- package/src/codegen/handlers/deserialize/DeserializeValueHandler.ts +33 -0
- package/src/codegen/handlers/enableChangeTracking/EnableChangeTrackingObjectHandler.ts +20 -0
- package/src/codegen/handlers/enableChangeTracking/EnableChangeTrackingPrimitiveValueHandler.ts +15 -0
- package/src/codegen/handlers/enrichment/EnrichmentComputedValueHandler.ts +37 -0
- package/src/codegen/handlers/enrichment/EnrichmentDefaultFunctionHandler.ts +50 -0
- package/src/codegen/handlers/enrichment/EnrichmentDefaultValueHandler.ts +18 -0
- package/src/codegen/handlers/enrichment/EnrichmentFunctionHandler.ts +38 -0
- package/src/codegen/handlers/enrichment/EnrichmentNullableObjectHandler.ts +44 -0
- package/src/codegen/handlers/enrichment/EnrichmentObjectHandler.ts +29 -0
- package/src/codegen/handlers/enrichment/EnrichmentObjectIdentityHandler.ts +16 -0
- package/src/codegen/handlers/enrichment/EnrichmentPrimitiveHandler.ts +13 -0
- package/src/codegen/handlers/enrichment/EnrichmentPrimitiveIdentityHandler.ts +21 -0
- package/src/codegen/handlers/freeze/FreezeObjectHandler.ts +20 -0
- package/src/codegen/handlers/freeze/FreezePrimitiveValueHandler.ts +15 -0
- package/src/codegen/handlers/hash/HashComputedValueHandler.ts +15 -0
- package/src/codegen/handlers/hash/HashDateHandler.ts +26 -0
- package/src/codegen/handlers/hash/HashFunctionHandler.ts +16 -0
- package/src/codegen/handlers/hash/HashIdentityHandler.ts +15 -0
- package/src/codegen/handlers/hash/HashKeyHandler.ts +26 -0
- package/src/codegen/handlers/hash/HashValueHandler.ts +26 -0
- package/src/codegen/handlers/hashType/HashTypeValueHandler.ts +20 -0
- package/src/codegen/handlers/idSelector/IdSelectorValueHandler.ts +28 -0
- package/src/codegen/handlers/index.ts +13 -0
- package/src/codegen/handlers/merge/MergeComputedValueHandler.ts +37 -0
- package/src/codegen/handlers/merge/MergeDefaultFunctionHandler.ts +40 -0
- package/src/codegen/handlers/merge/MergeDefaultValueHandler.ts +32 -0
- package/src/codegen/handlers/merge/MergeFunctionHandler.ts +16 -0
- package/src/codegen/handlers/merge/MergePrimitiveHandler.ts +21 -0
- package/src/codegen/handlers/prepare/PrepareComputedValueHandler.ts +16 -0
- package/src/codegen/handlers/prepare/PrepareFunctionHandler.ts +16 -0
- package/src/codegen/handlers/prepare/PrepareIdentityHandler.ts +21 -0
- package/src/codegen/handlers/prepare/PrepareKeyHandler.ts +21 -0
- package/src/codegen/handlers/prepare/PrepareObjectHandler.ts +38 -0
- package/src/codegen/handlers/prepare/PrepareValueHandler.ts +36 -0
- package/src/codegen/handlers/serialize/SerializeDateHandler.ts +45 -0
- package/src/codegen/handlers/serialize/SerializeObjectHandler.ts +28 -0
- package/src/codegen/handlers/serialize/SerializeValueHandler.ts +33 -0
- package/src/codegen/handlers/strip/StripIdentityHandler.ts +15 -0
- package/src/codegen/handlers/strip/StripKeyHandler.ts +15 -0
- package/src/codegen/handlers/strip/StripObjectHandler.ts +35 -0
- package/src/codegen/handlers/strip/StripValueHandler.ts +36 -0
- package/src/codegen/handlers/types.ts +119 -0
- package/src/codegen/index.ts +2 -0
- package/src/codegen/types.ts +2 -0
- package/src/codegen/utils.ts +74 -0
- package/src/collections/Changes.test.ts +337 -0
- package/src/collections/Changes.ts +177 -0
- package/src/collections/IdSet.ts +28 -0
- package/src/collections/MemoryDataCollection.test.ts +424 -0
- package/src/collections/MemoryDataCollection.ts +134 -0
- package/src/collections/SchemaCollection.ts +22 -0
- package/src/collections/TagCollection.test.ts +443 -0
- package/src/collections/TagCollection.ts +62 -0
- package/src/collections/index.ts +5 -0
- package/src/errors/SchemaError.ts +6 -0
- package/src/errors/index.ts +1 -0
- package/src/expressions/index.ts +3 -0
- package/src/expressions/parser.test.ts +913 -0
- package/src/expressions/parser.ts +661 -0
- package/src/expressions/types.ts +184 -0
- package/src/expressions/utils.test.ts +346 -0
- package/src/expressions/utils.ts +59 -0
- package/src/index.ts +12 -0
- package/src/performance/index.ts +26 -0
- package/src/pipeline/SyncronousQueue.test.ts +269 -0
- package/src/pipeline/SyncronousQueue.ts +30 -0
- package/src/pipeline/TrampolinePipeline.test.ts +374 -0
- package/src/pipeline/TrampolinePipeline.ts +437 -0
- package/src/pipeline/index.ts +2 -0
- package/src/plugins/EphemeralDataPlugin.ts +132 -0
- package/src/plugins/capabilities/DbPluginCapability.ts +111 -0
- package/src/plugins/capabilities/index.ts +2 -0
- package/src/plugins/capabilities/logging/DbPluginLoggingCapability.ts +261 -0
- package/src/plugins/capabilities/logging/index.ts +1 -0
- package/src/plugins/index.ts +6 -0
- package/src/plugins/query/Query.ts +67 -0
- package/src/plugins/query/QueryOptionsCollection.test.ts +86 -0
- package/src/plugins/query/QueryOptionsCollection.ts +154 -0
- package/src/plugins/query/index.ts +3 -0
- package/src/plugins/query/types.ts +46 -0
- package/src/plugins/replication/OptimisticReplicationDbPlugin.ts +202 -0
- package/src/plugins/replication/ReplicationDbPlugin.ts +137 -0
- package/src/plugins/replication/index.ts +3 -0
- package/src/plugins/replication/types.ts +5 -0
- package/src/plugins/translators/DataTranslator.ts +46 -0
- package/src/plugins/translators/JsonTranslator.test.ts +618 -0
- package/src/plugins/translators/JsonTranslator.ts +211 -0
- package/src/plugins/translators/SqlTranslator.ts +45 -0
- package/src/plugins/translators/index.ts +3 -0
- package/src/plugins/types.ts +114 -0
- package/src/results/Result.ts +91 -0
- package/src/results/index.ts +3 -0
- package/src/results/types.ts +17 -0
- package/src/results/utils.ts +15 -0
- package/src/schema/PropertyInfo.test.ts +479 -0
- package/src/schema/PropertyInfo.ts +374 -0
- package/src/schema/SchemaDefinition.ts +626 -0
- package/src/schema/builder.ts +18 -0
- package/src/schema/index.ts +7 -0
- package/src/schema/property/base/SchemaBase.ts +49 -0
- package/src/schema/property/base/index.ts +1 -0
- package/src/schema/property/modifiers/SchemaDefault.ts +29 -0
- package/src/schema/property/modifiers/SchemaDeserialize.ts +23 -0
- package/src/schema/property/modifiers/SchemaDistinct.ts +14 -0
- package/src/schema/property/modifiers/SchemaFrom.ts +54 -0
- package/src/schema/property/modifiers/SchemaIdentity.ts +13 -0
- package/src/schema/property/modifiers/SchemaIndex.ts +60 -0
- package/src/schema/property/modifiers/SchemaKey.ts +28 -0
- package/src/schema/property/modifiers/SchemaNullable.ts +18 -0
- package/src/schema/property/modifiers/SchemaOptional.ts +19 -0
- package/src/schema/property/modifiers/SchemaReadonly.ts +34 -0
- package/src/schema/property/modifiers/SchemaSerialize.ts +18 -0
- package/src/schema/property/modifiers/SchemaTracked.ts +14 -0
- package/src/schema/property/modifiers/index.ts +12 -0
- package/src/schema/property/types/SchemaArray.ts +50 -0
- package/src/schema/property/types/SchemaBoolean.ts +59 -0
- package/src/schema/property/types/SchemaDate.ts +58 -0
- package/src/schema/property/types/SchemaNumber.ts +69 -0
- package/src/schema/property/types/SchemaObject.ts +44 -0
- package/src/schema/property/types/SchemaString.ts +69 -0
- package/src/schema/property/types/index.ts +6 -0
- package/src/schema/table/SchemaComputed.ts +20 -0
- package/src/schema/table/SchemaFunction.ts +15 -0
- package/src/schema/table/index.ts +2 -0
- package/src/schema/types.ts +238 -0
- package/src/types/index.ts +5 -0
- package/src/utilities/arrays.test.ts +312 -0
- package/src/utilities/arrays.ts +12 -0
- package/src/utilities/dates.test.ts +388 -0
- package/src/utilities/dates.ts +11 -0
- package/src/utilities/dbPluginEventUtils.ts +44 -0
- package/src/utilities/index.ts +10 -0
- package/src/utilities/objects.ts +7 -0
- package/src/utilities/queryOptionsCollection.ts +16 -0
- package/src/utilities/replication.ts +23 -0
- package/src/utilities/runtime.ts +3 -0
- package/src/utilities/strings.ts +18 -0
- package/src/utilities/types.ts +1 -0
- package/src/utilities/uuid.ts +56 -0
- package/tsconfig.json +28 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DefaultValue, FunctionBody, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
2
|
+
|
|
3
|
+
export abstract class SchemaBase<T extends any, TModifiers extends SchemaModifiers> {
|
|
4
|
+
|
|
5
|
+
abstract instance: T;
|
|
6
|
+
modifiers: TModifiers;
|
|
7
|
+
|
|
8
|
+
isNullable: boolean = false;
|
|
9
|
+
isUnmapped: boolean = false;
|
|
10
|
+
isOptional: boolean = false;
|
|
11
|
+
isKey: boolean = false;
|
|
12
|
+
isIdentity: boolean = false;
|
|
13
|
+
isReadonly: boolean = false;
|
|
14
|
+
isDistict: boolean = false;
|
|
15
|
+
indexes: string[] = [];
|
|
16
|
+
fromPropertyName: string | null = null;
|
|
17
|
+
|
|
18
|
+
injected: any = null;
|
|
19
|
+
defaultValue: DefaultValue<T> | null = null;
|
|
20
|
+
valueSerializer: PropertySerializer<T> | null = null;
|
|
21
|
+
valueDeserializer: PropertyDeserializer<T> | null = null;
|
|
22
|
+
type: SchemaTypes;
|
|
23
|
+
functionBody: FunctionBody<any, T> | null;
|
|
24
|
+
private _schemaBase = true;
|
|
25
|
+
readonly literals: T[] = [];
|
|
26
|
+
|
|
27
|
+
constructor(entity?: SchemaBase<T, TModifiers>, literals?: T[]) {
|
|
28
|
+
|
|
29
|
+
if (entity != null) {
|
|
30
|
+
this.valueSerializer = entity.valueSerializer;
|
|
31
|
+
this.valueDeserializer = entity.valueDeserializer;
|
|
32
|
+
this.functionBody = entity.functionBody;
|
|
33
|
+
this.isNullable = entity.isNullable;
|
|
34
|
+
this.isOptional = entity.isOptional;
|
|
35
|
+
this.isKey = entity.isKey;
|
|
36
|
+
this.isIdentity = entity.isIdentity;
|
|
37
|
+
this.isReadonly = entity.isReadonly;
|
|
38
|
+
this.defaultValue = entity.defaultValue;
|
|
39
|
+
this.type = entity.type;
|
|
40
|
+
this.injected = entity.injected;
|
|
41
|
+
this.indexes = entity.indexes;
|
|
42
|
+
this.fromPropertyName = entity.fromPropertyName;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (literals) {
|
|
46
|
+
this.literals = literals;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SchemaBase';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaDeserialize } from "./SchemaDeserialize";
|
|
4
|
+
import { SchemaFrom } from "./SchemaFrom";
|
|
5
|
+
import { SchemaSerialize } from "./SchemaSerialize";
|
|
6
|
+
|
|
7
|
+
export class SchemaDefault<T extends any, I, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
8
|
+
instance: T;
|
|
9
|
+
private _schemaDefault = true;
|
|
10
|
+
|
|
11
|
+
constructor(defaultValue: DefaultValue<T, I>, injected: I, current: SchemaBase<T, TModifiers>) {
|
|
12
|
+
super(current);
|
|
13
|
+
this.instance = current.instance;
|
|
14
|
+
this.injected = injected;
|
|
15
|
+
this.defaultValue = defaultValue;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
serialize(serializer: PropertySerializer<T>) {
|
|
19
|
+
return new SchemaSerialize<T, TModifiers | "serialize">(serializer, this);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
deserialize(deserializer: PropertyDeserializer<T>) {
|
|
23
|
+
return new SchemaDeserialize<T, TModifiers | "deserialize">(deserializer, this);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
from(propertyName: string) {
|
|
27
|
+
return new SchemaFrom<T, TModifiers>(propertyName, this);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaFrom } from "./SchemaFrom";
|
|
4
|
+
import { SchemaSerialize } from "./SchemaSerialize";
|
|
5
|
+
|
|
6
|
+
export class SchemaDeserialize<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
7
|
+
instance: T;
|
|
8
|
+
private _schemaDeserialize = true;
|
|
9
|
+
|
|
10
|
+
constructor(deserializer: PropertyDeserializer<T>, current: SchemaBase<T, TModifiers>) {
|
|
11
|
+
super(current);
|
|
12
|
+
this.instance = current.instance;
|
|
13
|
+
this.valueDeserializer = deserializer;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
serialize(serializer: PropertySerializer<T>) {
|
|
17
|
+
return new SchemaSerialize<T, TModifiers | "serialize">(serializer, this);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
from(propertyName: string) {
|
|
21
|
+
return new SchemaFrom<T, TModifiers>(propertyName, this);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SchemaModifiers } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
|
|
4
|
+
export class SchemaDistinct<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
5
|
+
|
|
6
|
+
instance: T;
|
|
7
|
+
private _schemaDistinct = true;
|
|
8
|
+
|
|
9
|
+
constructor(current: SchemaBase<T, TModifiers>) {
|
|
10
|
+
super(current);
|
|
11
|
+
this.instance = current.instance;
|
|
12
|
+
this.isDistict = true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaDefault } from "./SchemaDefault";
|
|
4
|
+
import { SchemaDeserialize } from "./SchemaDeserialize";
|
|
5
|
+
import { SchemaDistinct } from "./SchemaDistinct";
|
|
6
|
+
import { SchemaIdentity } from "./SchemaIdentity";
|
|
7
|
+
import { SchemaKey } from "./SchemaKey";
|
|
8
|
+
import { SchemaNullable } from "./SchemaNullable";
|
|
9
|
+
import { SchemaOptional } from "./SchemaOptional";
|
|
10
|
+
import { SchemaReadonly } from "./SchemaReadonly";
|
|
11
|
+
import { SchemaSerialize } from "./SchemaSerialize";
|
|
12
|
+
|
|
13
|
+
export class SchemaFrom<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
14
|
+
instance: T;
|
|
15
|
+
private _schemaFrom = true;
|
|
16
|
+
|
|
17
|
+
constructor(propertyName: string, current: SchemaBase<T, TModifiers>) {
|
|
18
|
+
super(current);
|
|
19
|
+
this.instance = current.instance;
|
|
20
|
+
this.fromPropertyName = propertyName;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
default<I = never>(value: DefaultValue<T, I>, injected?: I) {
|
|
24
|
+
return new SchemaDefault<T, I, TModifiers | "default">(value, injected, this);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
deserialize(deserializer: PropertyDeserializer<T>) {
|
|
28
|
+
return new SchemaDeserialize<T, TModifiers | "deserialize">(deserializer, this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
distinct() {
|
|
32
|
+
return new SchemaDistinct<T, TModifiers | "distinct">(this);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
identity() {
|
|
36
|
+
return new SchemaIdentity<T, TModifiers | "identity" | "readonly">(this);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
optional() {
|
|
40
|
+
return new SchemaOptional<T, TModifiers | "optional">(this);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
nullable() {
|
|
44
|
+
return new SchemaNullable<T, TModifiers | "nullable">(this);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
readonly() {
|
|
48
|
+
return new SchemaReadonly<T, TModifiers | "readonly">(this);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
serialize(serializer: PropertySerializer<T>) {
|
|
52
|
+
return new SchemaSerialize<T, TModifiers | "serialize">(serializer, this);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SchemaModifiers } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
|
|
4
|
+
export class SchemaIdentity<T, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
5
|
+
instance: T;
|
|
6
|
+
private _schemaIdentity = true;
|
|
7
|
+
|
|
8
|
+
constructor(current: SchemaBase<T, TModifiers>) {
|
|
9
|
+
super(current);
|
|
10
|
+
this.instance = current.instance;
|
|
11
|
+
this.isIdentity = true;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { uuidv4 } from "../../../utilities";
|
|
2
|
+
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
|
|
3
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
4
|
+
import { SchemaDefault } from "./SchemaDefault";
|
|
5
|
+
import { SchemaDeserialize } from "./SchemaDeserialize";
|
|
6
|
+
import { SchemaDistinct } from "./SchemaDistinct";
|
|
7
|
+
import { SchemaFrom } from "./SchemaFrom";
|
|
8
|
+
import { SchemaNullable } from "./SchemaNullable";
|
|
9
|
+
import { SchemaOptional } from "./SchemaOptional";
|
|
10
|
+
import { SchemaReadonly } from "./SchemaReadonly";
|
|
11
|
+
import { SchemaSerialize } from "./SchemaSerialize";
|
|
12
|
+
|
|
13
|
+
export class SchemaIndex<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
14
|
+
|
|
15
|
+
instance: T;
|
|
16
|
+
private _schemaIndex = true;
|
|
17
|
+
|
|
18
|
+
constructor(current: SchemaBase<T, TModifiers>, ...indexes: string[]) {
|
|
19
|
+
super(current);
|
|
20
|
+
this.instance = current.instance;
|
|
21
|
+
|
|
22
|
+
if (indexes.length === 0) {
|
|
23
|
+
indexes.push(uuidv4()); // Create our own unique index identifier
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.indexes = indexes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
optional() {
|
|
30
|
+
return new SchemaOptional<T, TModifiers | "optional">(this);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
nullable() {
|
|
34
|
+
return new SchemaNullable<T, TModifiers | "nullable">(this);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
default<I = never>(value: DefaultValue<T, I>, injected?: I) {
|
|
38
|
+
return new SchemaDefault<T, I, TModifiers | "default">(value, injected, this);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
readonly() {
|
|
42
|
+
return new SchemaReadonly<T, TModifiers | "readonly">(this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
deserialize(deserializer: PropertyDeserializer<T>) {
|
|
46
|
+
return new SchemaDeserialize<T, TModifiers | "deserialize">(deserializer, this);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
serialize(serializer: PropertySerializer<T>) {
|
|
50
|
+
return new SchemaSerialize<T, TModifiers | "serialize">(serializer, this);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
distinct() {
|
|
54
|
+
return new SchemaDistinct<T, TModifiers | "distinct">(this);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
from(propertyName: string) {
|
|
58
|
+
return new SchemaFrom<T, TModifiers>(propertyName, this);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
2
|
+
import { SchemaIdentity } from "./SchemaIdentity";
|
|
3
|
+
import { SchemaDefault } from "./SchemaDefault";
|
|
4
|
+
import { DefaultValue, IdType, SchemaModifiers } from "../../types";
|
|
5
|
+
import { SchemaFrom } from "./SchemaFrom";
|
|
6
|
+
|
|
7
|
+
export class SchemaKey<T extends IdType, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
8
|
+
instance: T;
|
|
9
|
+
private _schemaKey = true;
|
|
10
|
+
|
|
11
|
+
constructor(current: SchemaBase<T, TModifiers>) {
|
|
12
|
+
super(current);
|
|
13
|
+
this.instance = current.instance;
|
|
14
|
+
this.isKey = true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
identity() {
|
|
18
|
+
return new SchemaIdentity<T, TModifiers | "identity">(this);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
default<I = never>(value: DefaultValue<T, I>, injected?: I) {
|
|
22
|
+
return new SchemaDefault<T, I, TModifiers | "default">(value, injected, this);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
from(propertyName: string) {
|
|
26
|
+
return new SchemaFrom<T, TModifiers>(propertyName, this);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SchemaModifiers } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaOptional } from "./SchemaOptional";
|
|
4
|
+
|
|
5
|
+
export class SchemaNullable<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
6
|
+
instance: T;
|
|
7
|
+
private _schemaNullable = true;
|
|
8
|
+
|
|
9
|
+
constructor(current: SchemaBase<T, TModifiers>) {
|
|
10
|
+
super(current);
|
|
11
|
+
this.instance = current.instance;
|
|
12
|
+
this.isNullable = true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
optional() {
|
|
16
|
+
return new SchemaOptional<T, TModifiers | "optional">(this);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SchemaModifiers } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaNullable } from "./SchemaNullable";
|
|
4
|
+
|
|
5
|
+
export class SchemaOptional<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
6
|
+
|
|
7
|
+
instance: T;
|
|
8
|
+
private _schemaOptional = true;
|
|
9
|
+
|
|
10
|
+
constructor(current: SchemaBase<T, TModifiers>) {
|
|
11
|
+
super(current);
|
|
12
|
+
this.instance = current.instance;
|
|
13
|
+
this.isOptional = true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
nullable() {
|
|
17
|
+
return new SchemaNullable<T, TModifiers | "nullable">(this);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaDefault } from "./SchemaDefault";
|
|
4
|
+
import { SchemaDeserialize } from "./SchemaDeserialize";
|
|
5
|
+
import { SchemaFrom } from "./SchemaFrom";
|
|
6
|
+
import { SchemaSerialize } from "./SchemaSerialize";
|
|
7
|
+
|
|
8
|
+
export class SchemaReadonly<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
9
|
+
|
|
10
|
+
instance: T;
|
|
11
|
+
private _schemaReadonly = true;
|
|
12
|
+
|
|
13
|
+
constructor(current: SchemaBase<T, TModifiers>) {
|
|
14
|
+
super(current);
|
|
15
|
+
this.instance = current.instance;
|
|
16
|
+
this.isReadonly = true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
default<I = never>(value: DefaultValue<T, I>, injected?: I) {
|
|
20
|
+
return new SchemaDefault<T, I, TModifiers | "default">(value, injected, this);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
deserializer(deserializer: PropertyDeserializer<T>) {
|
|
24
|
+
return new SchemaDeserialize<T, TModifiers | "deserialize">(deserializer, this);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
serializer(serializer: PropertySerializer<T>) {
|
|
28
|
+
return new SchemaSerialize<T, TModifiers | "deserialize">(serializer, this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
from(propertyName: string) {
|
|
32
|
+
return new SchemaFrom<T, TModifiers>(propertyName, this);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaDeserialize } from "./SchemaDeserialize";
|
|
4
|
+
|
|
5
|
+
export class SchemaSerialize<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
6
|
+
instance: T;
|
|
7
|
+
private _schemaSerialize = true;
|
|
8
|
+
|
|
9
|
+
constructor(serializer: PropertySerializer<T>, current: SchemaBase<T, TModifiers>) {
|
|
10
|
+
super(current);
|
|
11
|
+
this.instance = current.instance;
|
|
12
|
+
this.valueSerializer = serializer;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
deserializer(deserializer: PropertyDeserializer<T>) {
|
|
16
|
+
return new SchemaDeserialize<T, TModifiers | "deserialize">(deserializer, this);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SchemaModifiers } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
|
|
4
|
+
export class SchemaTracked<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
5
|
+
|
|
6
|
+
instance: T;
|
|
7
|
+
private _schemaTracked = true;
|
|
8
|
+
|
|
9
|
+
constructor(current: SchemaBase<T, TModifiers>) {
|
|
10
|
+
super(current);
|
|
11
|
+
this.instance = current.instance;
|
|
12
|
+
this.isUnmapped = false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './SchemaDefault';
|
|
2
|
+
export * from './SchemaDeserialize';
|
|
3
|
+
export * from './SchemaDistinct';
|
|
4
|
+
export * from './SchemaIdentity';
|
|
5
|
+
export * from './SchemaIndex';
|
|
6
|
+
export * from './SchemaKey';
|
|
7
|
+
export * from './SchemaNullable';
|
|
8
|
+
export * from './SchemaOptional';
|
|
9
|
+
export * from './SchemaReadonly';
|
|
10
|
+
export * from './SchemaSerialize';
|
|
11
|
+
export * from './SchemaTracked';
|
|
12
|
+
export * from './SchemaFrom';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
2
|
+
import { SchemaDefault } from "../modifiers/SchemaDefault";
|
|
3
|
+
import { SchemaNullable } from "../modifiers/SchemaNullable";
|
|
4
|
+
import { SchemaOptional } from "../modifiers/SchemaOptional";
|
|
5
|
+
import { SchemaDeserialize } from '../modifiers/SchemaDeserialize';
|
|
6
|
+
import { SchemaSerialize } from '../modifiers/SchemaSerialize';
|
|
7
|
+
import { SchemaIndex } from "../modifiers/SchemaIndex";
|
|
8
|
+
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
9
|
+
import { SchemaFrom } from "../modifiers/SchemaFrom";
|
|
10
|
+
|
|
11
|
+
export class SchemaArray<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T[], TModifiers> {
|
|
12
|
+
|
|
13
|
+
instance: T[];
|
|
14
|
+
type = SchemaTypes.Array;
|
|
15
|
+
private _schemaArray = true;
|
|
16
|
+
readonly innerSchema?: SchemaBase<any, any>; // we need to know the type of the array, that is what this is for
|
|
17
|
+
|
|
18
|
+
constructor(entity?: SchemaBase<T[], TModifiers>, literals?: T[][]) {
|
|
19
|
+
super(entity, literals);
|
|
20
|
+
this.innerSchema = entity;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
from(propertyName: string) {
|
|
24
|
+
return new SchemaFrom<T[], TModifiers>(propertyName, this);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
optional() {
|
|
28
|
+
return new SchemaOptional<T[], TModifiers | "optional">(this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
nullable() {
|
|
32
|
+
return new SchemaNullable<T[], TModifiers | "nullable">(this);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
default<I = never>(value: DefaultValue<T[], I>, injected?: I) {
|
|
36
|
+
return new SchemaDefault<T[], I, TModifiers | "default">(value, injected, this);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
deserialize(deserializer: PropertyDeserializer<T[]>) {
|
|
40
|
+
return new SchemaDeserialize<T[], TModifiers | "deserialize">(deserializer, this);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
serialize(serializer: PropertySerializer<T[]>) {
|
|
44
|
+
return new SchemaSerialize<T[], TModifiers | "serialize">(serializer, this);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
index(...indexes: string[]) {
|
|
48
|
+
return new SchemaIndex<T[], TModifiers>(this as any, ...indexes);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaDefault } from "../modifiers/SchemaDefault";
|
|
4
|
+
import { SchemaDeserialize } from "../modifiers/SchemaDeserialize";
|
|
5
|
+
import { SchemaDistinct } from "../modifiers/SchemaDistinct";
|
|
6
|
+
import { SchemaFrom } from "../modifiers/SchemaFrom";
|
|
7
|
+
import { SchemaIndex } from "../modifiers/SchemaIndex";
|
|
8
|
+
import { SchemaNullable } from "../modifiers/SchemaNullable";
|
|
9
|
+
import { SchemaOptional } from "../modifiers/SchemaOptional";
|
|
10
|
+
import { SchemaReadonly } from "../modifiers/SchemaReadonly";
|
|
11
|
+
import { SchemaSerialize } from "../modifiers/SchemaSerialize";
|
|
12
|
+
import { SchemaArray } from "./SchemaArray";
|
|
13
|
+
|
|
14
|
+
export class SchemaBoolean<T extends boolean, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
15
|
+
|
|
16
|
+
instance: T;
|
|
17
|
+
type = SchemaTypes.Boolean;
|
|
18
|
+
private _schemaBoolean = true;
|
|
19
|
+
|
|
20
|
+
from(propertyName: string) {
|
|
21
|
+
return new SchemaFrom<T, TModifiers>(propertyName, this);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
optional() {
|
|
25
|
+
return new SchemaOptional<T, TModifiers | "optional">(this);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
nullable() {
|
|
29
|
+
return new SchemaNullable<T, TModifiers | "nullable">(this);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
default<I = never>(value: DefaultValue<T, I>, injected?: I) {
|
|
33
|
+
return new SchemaDefault<T, I, TModifiers | "default">(value, injected, this);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
readonly() {
|
|
37
|
+
return new SchemaReadonly<T, TModifiers | "readonly">(this);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
deserialize(deserializer: PropertyDeserializer<T>) {
|
|
41
|
+
return new SchemaDeserialize<T, TModifiers | "deserialize">(deserializer, this);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
serialize(serializer: PropertySerializer<T>) {
|
|
45
|
+
return new SchemaSerialize<T, TModifiers | "serialize">(serializer, this);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
array() {
|
|
49
|
+
return new SchemaArray<typeof this, TModifiers>(this as any);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
index(...indexes: string[]) {
|
|
53
|
+
return new SchemaIndex<T, TModifiers>(this as any, ...indexes);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
distinct() {
|
|
57
|
+
return new SchemaDistinct<T, TModifiers | "distinct">(this);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaDefault } from "../modifiers/SchemaDefault";
|
|
4
|
+
import { SchemaDeserialize } from "../modifiers/SchemaDeserialize";
|
|
5
|
+
import { SchemaDistinct } from "../modifiers/SchemaDistinct";
|
|
6
|
+
import { SchemaFrom } from "../modifiers/SchemaFrom";
|
|
7
|
+
import { SchemaIndex } from "../modifiers/SchemaIndex";
|
|
8
|
+
import { SchemaNullable } from "../modifiers/SchemaNullable";
|
|
9
|
+
import { SchemaOptional } from "../modifiers/SchemaOptional";
|
|
10
|
+
import { SchemaReadonly } from "../modifiers/SchemaReadonly";
|
|
11
|
+
import { SchemaSerialize } from "../modifiers/SchemaSerialize";
|
|
12
|
+
import { SchemaArray } from "./SchemaArray";
|
|
13
|
+
|
|
14
|
+
export class SchemaDate<T extends Date, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
15
|
+
|
|
16
|
+
instance: T;
|
|
17
|
+
type = SchemaTypes.Date;
|
|
18
|
+
private _schemaDate = true;
|
|
19
|
+
|
|
20
|
+
from(propertyName: string) {
|
|
21
|
+
return new SchemaFrom<T, TModifiers>(propertyName, this);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
optional() {
|
|
25
|
+
return new SchemaOptional<T, TModifiers | "optional">(this);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
nullable() {
|
|
29
|
+
return new SchemaNullable<T, TModifiers | "nullable">(this);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
default<I = never>(value: DefaultValue<T, I>, injected?: I) {
|
|
33
|
+
return new SchemaDefault<T, I, TModifiers | "default">(value, injected, this);
|
|
34
|
+
}
|
|
35
|
+
readonly() {
|
|
36
|
+
return new SchemaReadonly<T, TModifiers | "readonly">(this);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
deserialize(deserializer: PropertyDeserializer<T>) {
|
|
40
|
+
return new SchemaDeserialize<T, TModifiers | "deserialize">(deserializer, this);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
serialize(serializer: PropertySerializer<T>) {
|
|
44
|
+
return new SchemaSerialize<T, TModifiers | "serialize">(serializer, this);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
array() {
|
|
48
|
+
return new SchemaArray<typeof this, TModifiers>(this as any);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
index(...indexes: string[]) {
|
|
52
|
+
return new SchemaIndex<T, TModifiers>(this as any, ...indexes);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
distinct() {
|
|
56
|
+
return new SchemaDistinct<T, TModifiers | "distinct">(this);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaDefault } from "../modifiers/SchemaDefault";
|
|
4
|
+
import { SchemaDeserialize } from "../modifiers/SchemaDeserialize";
|
|
5
|
+
import { SchemaDistinct } from "../modifiers/SchemaDistinct";
|
|
6
|
+
import { SchemaFrom } from "../modifiers/SchemaFrom";
|
|
7
|
+
import { SchemaIdentity } from "../modifiers/SchemaIdentity";
|
|
8
|
+
import { SchemaIndex } from "../modifiers/SchemaIndex";
|
|
9
|
+
import { SchemaKey } from "../modifiers/SchemaKey";
|
|
10
|
+
import { SchemaNullable } from "../modifiers/SchemaNullable";
|
|
11
|
+
import { SchemaOptional } from "../modifiers/SchemaOptional";
|
|
12
|
+
import { SchemaReadonly } from "../modifiers/SchemaReadonly";
|
|
13
|
+
import { SchemaSerialize } from "../modifiers/SchemaSerialize";
|
|
14
|
+
import { SchemaArray } from "./SchemaArray";
|
|
15
|
+
|
|
16
|
+
export class SchemaNumber<T extends number, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
17
|
+
|
|
18
|
+
instance: T;
|
|
19
|
+
type = SchemaTypes.Number;
|
|
20
|
+
private _schemaNumber = true;
|
|
21
|
+
|
|
22
|
+
from(propertyName: string) {
|
|
23
|
+
return new SchemaFrom<T, TModifiers>(propertyName, this);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
optional() {
|
|
27
|
+
return new SchemaOptional<T, TModifiers | "optional">(this);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
nullable() {
|
|
31
|
+
return new SchemaNullable<T, TModifiers | "nullable">(this);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
key() {
|
|
35
|
+
return new SchemaKey<T, TModifiers | "key">(this);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
default<I = never>(value: DefaultValue<T, I>, injected?: I) {
|
|
39
|
+
return new SchemaDefault<T, I, TModifiers | "default">(value, injected, this);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
readonly() {
|
|
43
|
+
return new SchemaReadonly<T, TModifiers | "readonly">(this);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
deserialize(deserializer: PropertyDeserializer<T>) {
|
|
47
|
+
return new SchemaDeserialize<T, TModifiers | "deserialize">(deserializer, this);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
serialize(serializer: PropertySerializer<T>) {
|
|
51
|
+
return new SchemaSerialize<T, TModifiers | "serialize">(serializer, this);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
identity() {
|
|
55
|
+
return new SchemaIdentity<T, TModifiers | "identity" | "readonly">(this);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
array() {
|
|
59
|
+
return new SchemaArray<typeof this, TModifiers>(this as any);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
index(...indexes: string[]) {
|
|
63
|
+
return new SchemaIndex<T, TModifiers>(this as any, ...indexes);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
distinct() {
|
|
67
|
+
return new SchemaDistinct<T, TModifiers | "distinct">(this);
|
|
68
|
+
}
|
|
69
|
+
}
|