@routier/core 0.2.0 → 0.2.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/dist/assertions/index.d.ts +30 -0
- package/dist/assertions/index.js +88 -4
- package/dist/assertions/index.js.map +1 -1
- package/dist/capabilities/index.js +25 -16
- package/dist/capabilities/index.js.map +1 -1
- package/dist/codegen/blocks.test.d.ts +1 -0
- package/dist/codegen/handlers/SetHandlerBuilder.d.ts +4 -0
- package/dist/codegen/handlers/index.d.ts +1 -0
- package/dist/codegen/handlers/serialize/SerializeComputedHandler.d.ts +6 -0
- package/dist/codegen/handlers/set/SetComplexHandler.d.ts +6 -0
- package/dist/codegen/index.js +1 -0
- package/dist/codegen/index.js.map +1 -1
- package/dist/codegen/utils.test.d.ts +1 -0
- package/dist/collections/Changes.d.ts +2 -2
- package/dist/collections/IdSet.test.d.ts +1 -0
- package/dist/collections/TagCollection.contract.test.d.ts +1 -0
- package/dist/collections/TagCollection.d.ts +7 -7
- package/dist/collections/index.js +1 -1
- package/dist/collections/index.js.map +1 -1
- package/dist/expressions/constants.d.ts +2 -0
- package/dist/expressions/index.d.ts +2 -0
- package/dist/expressions/index.js +401 -34
- package/dist/expressions/index.js.map +1 -1
- package/dist/expressions/sql.d.ts +28 -0
- package/dist/expressions/sql.test.d.ts +1 -0
- package/dist/expressions/utils.d.ts +1 -2
- package/dist/index.js +1669 -610
- package/dist/index.js.map +1 -1
- package/dist/performance/index.js +18 -7
- package/dist/performance/index.js.map +1 -1
- package/dist/pipeline/index.js +18 -7
- package/dist/pipeline/index.js.map +1 -1
- package/dist/plugins/index.d.ts +0 -1
- package/dist/plugins/index.js +126 -694
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/query/Query.test.d.ts +1 -0
- package/dist/plugins/query/QueryOptionsCollection.d.ts +1 -0
- package/dist/plugins/translators/SqlTranslator.test.d.ts +1 -0
- package/dist/plugins/translators/TranslatedArrayValue.d.ts +3 -1
- package/dist/plugins/translators/TranslatedGroupValue.d.ts +3 -1
- package/dist/plugins/translators/TranslatedSingleValue.d.ts +3 -1
- package/dist/plugins/translators/TranslatedValues.test.d.ts +1 -0
- package/dist/plugins/translators/types.d.ts +8 -1
- package/dist/plugins/types.d.ts +6 -10
- package/dist/results/Result.d.ts +2 -2
- package/dist/results/Result.test.d.ts +1 -0
- package/dist/results/index.js.map +1 -1
- package/dist/results/utils.test.d.ts +1 -0
- package/dist/schema/PropertyInfo.d.ts +5 -1
- package/dist/schema/SchemaDefinition.d.ts +29 -1
- package/dist/schema/communication/broadcast.test.d.ts +1 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +1151 -132
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/property/base/SchemaBase.d.ts +3 -1
- package/dist/schema/property/modifiers/SchemaDeserialize.d.ts +5 -1
- package/dist/schema/property/modifiers/SchemaForeignKey.d.ts +15 -0
- package/dist/schema/property/modifiers/SchemaKey.d.ts +2 -0
- package/dist/schema/property/modifiers/SchemaNullable.d.ts +5 -1
- package/dist/schema/property/modifiers/SchemaOptional.d.ts +3 -1
- package/dist/schema/property/modifiers/SchemaTag.d.ts +27 -0
- package/dist/schema/property/modifiers/SchemaTracked.d.ts +5 -1
- package/dist/schema/property/modifiers/index.d.ts +2 -0
- package/dist/schema/property/types/SchemaArray.d.ts +2 -0
- package/dist/schema/property/types/SchemaBoolean.d.ts +2 -0
- package/dist/schema/property/types/SchemaDate.d.ts +2 -0
- package/dist/schema/property/types/SchemaNumber.d.ts +5 -1
- package/dist/schema/property/types/SchemaObject.d.ts +2 -0
- package/dist/schema/property/types/SchemaString.d.ts +5 -1
- package/dist/schema/types.d.ts +37 -27
- package/dist/schema/utils/standardJsonSchema.d.ts +90 -0
- package/dist/schema/utils/standardJsonSchema.test.d.ts +1 -0
- package/dist/utilities/functions.d.ts +1 -1
- package/dist/utilities/index.js +153 -15
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/runtime.test.d.ts +1 -0
- package/dist/utilities/uuid.test.d.ts +1 -0
- package/package.json +2 -2
- package/readme.md +1 -1
- package/dist/plugins/replication/OptimisticReplicationDbPlugin.d.ts +0 -23
- package/dist/plugins/replication/ReplicationDbPlugin.d.ts +0 -22
- package/dist/plugins/replication/index.d.ts +0 -3
- package/dist/plugins/replication/types.d.ts +0 -5
- package/dist/schema/testSchemas.test.d.ts +0 -314
- /package/dist/{pipeline/WorkPipeline.test.d.ts → codegen/SlotPath.test.d.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DefaultValue, FunctionBody, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
1
|
+
import { DefaultValue, ForeignKey, FunctionBody, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
2
2
|
export declare abstract class SchemaBase<T extends any, TModifiers extends SchemaModifiers> {
|
|
3
3
|
abstract instance: T;
|
|
4
4
|
modifiers: TModifiers;
|
|
@@ -11,6 +11,8 @@ export declare abstract class SchemaBase<T extends any, TModifiers extends Schem
|
|
|
11
11
|
isDistict: boolean;
|
|
12
12
|
indexes: string[];
|
|
13
13
|
fromPropertyName: string | null;
|
|
14
|
+
foreignKeyDefinition: ForeignKey<unknown> | null;
|
|
15
|
+
tags: string[];
|
|
14
16
|
injected: any;
|
|
15
17
|
defaultValue: DefaultValue<T> | null;
|
|
16
18
|
valueSerializer: PropertySerializer<T> | null;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
|
|
1
|
+
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
|
|
2
2
|
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaDefault } from "./SchemaDefault";
|
|
3
4
|
import { SchemaFrom } from "./SchemaFrom";
|
|
5
|
+
import { SchemaOptional } from "./SchemaOptional";
|
|
4
6
|
import { SchemaSerialize } from "./SchemaSerialize";
|
|
5
7
|
export declare class SchemaDeserialize<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
6
8
|
instance: T;
|
|
@@ -8,4 +10,6 @@ export declare class SchemaDeserialize<T extends any, TModifiers extends SchemaM
|
|
|
8
10
|
constructor(deserializer: PropertyDeserializer<T>, current: SchemaBase<T, TModifiers>);
|
|
9
11
|
serialize(serializer: PropertySerializer<T>): SchemaSerialize<T, "serialize" | TModifiers>;
|
|
10
12
|
from(propertyName: string): SchemaFrom<T, TModifiers>;
|
|
13
|
+
optional(): SchemaOptional<T, "optional" | TModifiers>;
|
|
14
|
+
default<I = never>(value: DefaultValue<T | null, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
|
|
11
15
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
2
|
+
import { SchemaIdentity } from "./SchemaIdentity";
|
|
3
|
+
import { SchemaDefault } from "./SchemaDefault";
|
|
4
|
+
import { CompiledSchema, DefaultValue, InferType, SchemaModifiers } from "../../types";
|
|
5
|
+
import { SchemaFrom } from "./SchemaFrom";
|
|
6
|
+
import { SchemaTag } from "./SchemaTag";
|
|
7
|
+
export declare class SchemaForeignKey<T extends any, TModifiers extends SchemaModifiers, K extends {}> extends SchemaBase<T, TModifiers> {
|
|
8
|
+
instance: T;
|
|
9
|
+
private _schemaForeignKey;
|
|
10
|
+
constructor(current: SchemaBase<T, TModifiers>, relatingSchema: CompiledSchema<K>, property: keyof InferType<CompiledSchema<K>>);
|
|
11
|
+
identity(): SchemaIdentity<T, "identity" | TModifiers>;
|
|
12
|
+
default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
|
|
13
|
+
from(propertyName: string): SchemaFrom<T, TModifiers>;
|
|
14
|
+
tag(...tags: string[]): SchemaTag<T, TModifiers>;
|
|
15
|
+
}
|
|
@@ -3,6 +3,7 @@ import { SchemaIdentity } from "./SchemaIdentity";
|
|
|
3
3
|
import { SchemaDefault } from "./SchemaDefault";
|
|
4
4
|
import { DefaultValue, IdType, SchemaModifiers } from "../../types";
|
|
5
5
|
import { SchemaFrom } from "./SchemaFrom";
|
|
6
|
+
import { SchemaTag } from "./SchemaTag";
|
|
6
7
|
export declare class SchemaKey<T extends IdType, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
7
8
|
instance: T;
|
|
8
9
|
private _schemaKey;
|
|
@@ -10,4 +11,5 @@ export declare class SchemaKey<T extends IdType, TModifiers extends SchemaModifi
|
|
|
10
11
|
identity(): SchemaIdentity<T, "identity" | TModifiers>;
|
|
11
12
|
default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
|
|
12
13
|
from(propertyName: string): SchemaFrom<T, TModifiers>;
|
|
14
|
+
tag(...tags: string[]): SchemaTag<T, TModifiers>;
|
|
13
15
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { SchemaModifiers } from "../../types";
|
|
1
|
+
import { DefaultValue, PropertyDeserializer, SchemaModifiers } from "../../types";
|
|
2
2
|
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaDefault } from "./SchemaDefault";
|
|
4
|
+
import { SchemaDeserialize } from "./SchemaDeserialize";
|
|
3
5
|
import { SchemaOptional } from "./SchemaOptional";
|
|
4
6
|
export declare class SchemaNullable<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
5
7
|
instance: T;
|
|
6
8
|
private _schemaNullable;
|
|
7
9
|
constructor(current: SchemaBase<T, TModifiers>);
|
|
8
10
|
optional(): SchemaOptional<T, "optional" | TModifiers>;
|
|
11
|
+
default<I = never>(value: DefaultValue<T | null, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
|
|
12
|
+
deserialize(deserializer: PropertyDeserializer<T | null>): SchemaDeserialize<T, "deserialize" | TModifiers>;
|
|
9
13
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { SchemaModifiers } from "../../types";
|
|
1
|
+
import { PropertyDeserializer, SchemaModifiers } from "../../types";
|
|
2
2
|
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaDeserialize } from "./SchemaDeserialize";
|
|
3
4
|
import { SchemaNullable } from "./SchemaNullable";
|
|
4
5
|
export declare class SchemaOptional<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
5
6
|
instance: T;
|
|
6
7
|
private _schemaOptional;
|
|
7
8
|
constructor(current: SchemaBase<T, TModifiers>);
|
|
8
9
|
nullable(): SchemaNullable<T, "nullable" | TModifiers>;
|
|
10
|
+
deserialize(deserializer: PropertyDeserializer<T | undefined>): SchemaDeserialize<T, "deserialize" | TModifiers>;
|
|
9
11
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
|
|
2
|
+
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaArray } from "../types";
|
|
4
|
+
import { SchemaDefault } from "./SchemaDefault";
|
|
5
|
+
import { SchemaDeserialize } from "./SchemaDeserialize";
|
|
6
|
+
import { SchemaDistinct } from "./SchemaDistinct";
|
|
7
|
+
import { SchemaFrom } from "./SchemaFrom";
|
|
8
|
+
import { SchemaIndex } from "./SchemaIndex";
|
|
9
|
+
import { SchemaNullable } from "./SchemaNullable";
|
|
10
|
+
import { SchemaOptional } from "./SchemaOptional";
|
|
11
|
+
import { SchemaReadonly } from "./SchemaReadonly";
|
|
12
|
+
import { SchemaSerialize } from "./SchemaSerialize";
|
|
13
|
+
export declare class SchemaTag<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
14
|
+
instance: T;
|
|
15
|
+
private _schemaTag;
|
|
16
|
+
constructor(tags: string[], current: SchemaBase<T, TModifiers>);
|
|
17
|
+
from(propertyName: string): SchemaFrom<T, TModifiers>;
|
|
18
|
+
optional(): SchemaOptional<T, "optional" | TModifiers>;
|
|
19
|
+
nullable(): SchemaNullable<T, "nullable" | TModifiers>;
|
|
20
|
+
default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
|
|
21
|
+
readonly(): SchemaReadonly<T, "readonly" | TModifiers>;
|
|
22
|
+
deserialize(deserializer: PropertyDeserializer<T>): SchemaDeserialize<T, "deserialize" | TModifiers>;
|
|
23
|
+
serialize(serializer: PropertySerializer<T>): SchemaSerialize<T, "serialize" | TModifiers>;
|
|
24
|
+
array(): SchemaArray<this, TModifiers>;
|
|
25
|
+
index(...indexes: string[]): SchemaIndex<T, TModifiers>;
|
|
26
|
+
distinct(): SchemaDistinct<T, "distinct" | TModifiers>;
|
|
27
|
+
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { IdType, SchemaModifiers } from "../../types";
|
|
1
|
+
import { CompiledSchema, IdType, InferType, SchemaModifiers } from "../../types";
|
|
2
2
|
import { SchemaBase } from "../base/SchemaBase";
|
|
3
|
+
import { SchemaForeignKey } from "./SchemaForeignKey";
|
|
3
4
|
import { SchemaKey } from "./SchemaKey";
|
|
5
|
+
import { SchemaTag } from "./SchemaTag";
|
|
4
6
|
export declare class SchemaTracked<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
5
7
|
instance: T;
|
|
6
8
|
private _schemaTracked;
|
|
7
9
|
constructor(current: SchemaBase<T, TModifiers>);
|
|
8
10
|
key(): T extends IdType ? SchemaKey<T, TModifiers | "key"> : never;
|
|
11
|
+
foreignKey<K extends {}>(relatingSchema: CompiledSchema<K>, property: keyof InferType<CompiledSchema<K>>): SchemaForeignKey<T, TModifiers, K>;
|
|
12
|
+
tag(...tags: string[]): SchemaTag<T, TModifiers>;
|
|
9
13
|
}
|
|
@@ -7,6 +7,7 @@ import { SchemaSerialize } from '../modifiers/SchemaSerialize';
|
|
|
7
7
|
import { SchemaIndex } from "../modifiers/SchemaIndex";
|
|
8
8
|
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
9
9
|
import { SchemaFrom } from "../modifiers/SchemaFrom";
|
|
10
|
+
import { SchemaTag } from "../modifiers/SchemaTag";
|
|
10
11
|
export declare class SchemaArray<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T[], TModifiers> {
|
|
11
12
|
instance: T[];
|
|
12
13
|
type: SchemaTypes;
|
|
@@ -20,4 +21,5 @@ export declare class SchemaArray<T extends any, TModifiers extends SchemaModifie
|
|
|
20
21
|
deserialize(deserializer: PropertyDeserializer<T[]>): SchemaDeserialize<T[], "deserialize" | TModifiers>;
|
|
21
22
|
serialize(serializer: PropertySerializer<T[]>): SchemaSerialize<T[], "serialize" | TModifiers>;
|
|
22
23
|
index(...indexes: string[]): SchemaIndex<T[], TModifiers>;
|
|
24
|
+
tag(...tags: string[]): SchemaTag<T[], TModifiers>;
|
|
23
25
|
}
|
|
@@ -9,6 +9,7 @@ import { SchemaNullable } from "../modifiers/SchemaNullable";
|
|
|
9
9
|
import { SchemaOptional } from "../modifiers/SchemaOptional";
|
|
10
10
|
import { SchemaReadonly } from "../modifiers/SchemaReadonly";
|
|
11
11
|
import { SchemaSerialize } from "../modifiers/SchemaSerialize";
|
|
12
|
+
import { SchemaTag } from "../modifiers/SchemaTag";
|
|
12
13
|
import { SchemaArray } from "./SchemaArray";
|
|
13
14
|
export declare class SchemaBoolean<T extends boolean, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
14
15
|
instance: T;
|
|
@@ -24,4 +25,5 @@ export declare class SchemaBoolean<T extends boolean, TModifiers extends SchemaM
|
|
|
24
25
|
array(): SchemaArray<this, TModifiers>;
|
|
25
26
|
index(...indexes: string[]): SchemaIndex<T, TModifiers>;
|
|
26
27
|
distinct(): SchemaDistinct<T, "distinct" | TModifiers>;
|
|
28
|
+
tag(...tags: string[]): SchemaTag<T, TModifiers>;
|
|
27
29
|
}
|
|
@@ -9,6 +9,7 @@ import { SchemaNullable } from "../modifiers/SchemaNullable";
|
|
|
9
9
|
import { SchemaOptional } from "../modifiers/SchemaOptional";
|
|
10
10
|
import { SchemaReadonly } from "../modifiers/SchemaReadonly";
|
|
11
11
|
import { SchemaSerialize } from "../modifiers/SchemaSerialize";
|
|
12
|
+
import { SchemaTag } from "../modifiers/SchemaTag";
|
|
12
13
|
import { SchemaArray } from "./SchemaArray";
|
|
13
14
|
export declare class SchemaDate<T extends Date, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
14
15
|
instance: T;
|
|
@@ -24,4 +25,5 @@ export declare class SchemaDate<T extends Date, TModifiers extends SchemaModifie
|
|
|
24
25
|
array(): SchemaArray<this, TModifiers>;
|
|
25
26
|
index(...indexes: string[]): SchemaIndex<T, TModifiers>;
|
|
26
27
|
distinct(): SchemaDistinct<T, "distinct" | TModifiers>;
|
|
28
|
+
tag(...tags: string[]): SchemaTag<T, TModifiers>;
|
|
27
29
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
1
|
+
import { CompiledSchema, DefaultValue, InferType, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
2
2
|
import { SchemaBase } from "../base/SchemaBase";
|
|
3
3
|
import { SchemaDefault } from "../modifiers/SchemaDefault";
|
|
4
4
|
import { SchemaDeserialize } from "../modifiers/SchemaDeserialize";
|
|
5
5
|
import { SchemaDistinct } from "../modifiers/SchemaDistinct";
|
|
6
|
+
import { SchemaForeignKey } from "../modifiers/SchemaForeignKey";
|
|
6
7
|
import { SchemaFrom } from "../modifiers/SchemaFrom";
|
|
7
8
|
import { SchemaIdentity } from "../modifiers/SchemaIdentity";
|
|
8
9
|
import { SchemaIndex } from "../modifiers/SchemaIndex";
|
|
@@ -11,6 +12,7 @@ import { SchemaNullable } from "../modifiers/SchemaNullable";
|
|
|
11
12
|
import { SchemaOptional } from "../modifiers/SchemaOptional";
|
|
12
13
|
import { SchemaReadonly } from "../modifiers/SchemaReadonly";
|
|
13
14
|
import { SchemaSerialize } from "../modifiers/SchemaSerialize";
|
|
15
|
+
import { SchemaTag } from "../modifiers/SchemaTag";
|
|
14
16
|
import { SchemaArray } from "./SchemaArray";
|
|
15
17
|
export declare class SchemaNumber<T extends number, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
16
18
|
instance: T;
|
|
@@ -21,6 +23,7 @@ export declare class SchemaNumber<T extends number, TModifiers extends SchemaMod
|
|
|
21
23
|
optional(): SchemaOptional<T, "optional" | TModifiers>;
|
|
22
24
|
nullable(): SchemaNullable<T, "nullable" | TModifiers>;
|
|
23
25
|
key(): SchemaKey<T, "key" | TModifiers>;
|
|
26
|
+
foreignKey<K extends {}>(relatingSchema: CompiledSchema<K>, property: keyof InferType<CompiledSchema<K>>): SchemaForeignKey<T, TModifiers, K>;
|
|
24
27
|
default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
|
|
25
28
|
readonly(): SchemaReadonly<T, "readonly" | TModifiers>;
|
|
26
29
|
deserialize(deserializer: PropertyDeserializer<T>): SchemaDeserialize<T, "deserialize" | TModifiers>;
|
|
@@ -29,4 +32,5 @@ export declare class SchemaNumber<T extends number, TModifiers extends SchemaMod
|
|
|
29
32
|
array(): SchemaArray<this, TModifiers>;
|
|
30
33
|
index(...indexes: string[]): SchemaIndex<T, TModifiers>;
|
|
31
34
|
distinct(): SchemaDistinct<T, "distinct" | TModifiers>;
|
|
35
|
+
tag(...tags: string[]): SchemaTag<T, TModifiers>;
|
|
32
36
|
}
|
|
@@ -5,6 +5,7 @@ import { SchemaFrom } from "../modifiers/SchemaFrom";
|
|
|
5
5
|
import { SchemaIdentity } from "../modifiers/SchemaIdentity";
|
|
6
6
|
import { SchemaNullable } from "../modifiers/SchemaNullable";
|
|
7
7
|
import { SchemaOptional } from "../modifiers/SchemaOptional";
|
|
8
|
+
import { SchemaTag } from "../modifiers/SchemaTag";
|
|
8
9
|
import { SchemaArray } from "./SchemaArray";
|
|
9
10
|
export declare class SchemaObject<T extends {}, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
10
11
|
instance: T;
|
|
@@ -17,4 +18,5 @@ export declare class SchemaObject<T extends {}, TModifiers extends SchemaModifie
|
|
|
17
18
|
default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
|
|
18
19
|
identity(): SchemaIdentity<T, "identity" | "readonly" | TModifiers>;
|
|
19
20
|
array(): SchemaArray<this, TModifiers>;
|
|
21
|
+
tag(...tags: string[]): SchemaTag<T, TModifiers>;
|
|
20
22
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
1
|
+
import { CompiledSchema, DefaultValue, InferType, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
|
|
2
2
|
import { SchemaBase } from "../base/SchemaBase";
|
|
3
3
|
import { SchemaDefault } from "../modifiers/SchemaDefault";
|
|
4
4
|
import { SchemaDeserialize } from "../modifiers/SchemaDeserialize";
|
|
5
5
|
import { SchemaDistinct } from "../modifiers/SchemaDistinct";
|
|
6
|
+
import { SchemaForeignKey } from "../modifiers/SchemaForeignKey";
|
|
6
7
|
import { SchemaFrom } from "../modifiers/SchemaFrom";
|
|
7
8
|
import { SchemaIdentity } from "../modifiers/SchemaIdentity";
|
|
8
9
|
import { SchemaIndex } from "../modifiers/SchemaIndex";
|
|
@@ -11,6 +12,7 @@ import { SchemaNullable } from "../modifiers/SchemaNullable";
|
|
|
11
12
|
import { SchemaOptional } from "../modifiers/SchemaOptional";
|
|
12
13
|
import { SchemaReadonly } from "../modifiers/SchemaReadonly";
|
|
13
14
|
import { SchemaSerialize } from "../modifiers/SchemaSerialize";
|
|
15
|
+
import { SchemaTag } from "../modifiers/SchemaTag";
|
|
14
16
|
import { SchemaArray } from "./SchemaArray";
|
|
15
17
|
export declare class SchemaString<T extends string, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
|
|
16
18
|
instance: T;
|
|
@@ -21,6 +23,7 @@ export declare class SchemaString<T extends string, TModifiers extends SchemaMod
|
|
|
21
23
|
optional(): SchemaOptional<T, "optional" | TModifiers>;
|
|
22
24
|
nullable(): SchemaNullable<T, "nullable" | TModifiers>;
|
|
23
25
|
key(): SchemaKey<T, "key" | TModifiers>;
|
|
26
|
+
foreignKey<K extends {}>(relatingSchema: CompiledSchema<K>, property: keyof InferType<CompiledSchema<K>>): SchemaForeignKey<T, TModifiers, K>;
|
|
24
27
|
default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
|
|
25
28
|
readonly(): SchemaReadonly<T, "readonly" | TModifiers>;
|
|
26
29
|
deserialize(deserializer: PropertyDeserializer<T>): SchemaDeserialize<T, "deserialize" | TModifiers>;
|
|
@@ -29,4 +32,5 @@ export declare class SchemaString<T extends string, TModifiers extends SchemaMod
|
|
|
29
32
|
array(): SchemaArray<this, TModifiers>;
|
|
30
33
|
index(...indexes: string[]): SchemaIndex<T, TModifiers>;
|
|
31
34
|
distinct(): SchemaDistinct<T, "distinct" | TModifiers>;
|
|
35
|
+
tag(...tags: string[]): SchemaTag<T, TModifiers>;
|
|
32
36
|
}
|
package/dist/schema/types.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { SchemaDefinition } from "./SchemaDefinition";
|
|
2
|
-
import { SchemaBase } from "./property/base/SchemaBase";
|
|
3
|
-
import { SchemaArray } from "./property/types/SchemaArray";
|
|
4
|
-
import { SchemaObject } from "./property/types/SchemaObject";
|
|
5
|
-
import { PropertyInfo } from "./PropertyInfo";
|
|
6
|
-
import { DeepPartial } from "../types";
|
|
7
|
-
import { SchemaFunction } from "./table";
|
|
8
|
-
import { SchemaOptional } from "./property/modifiers";
|
|
9
|
-
import { Branded } from "../utilities/types";
|
|
1
|
+
import type { SchemaDefinition } from "./SchemaDefinition";
|
|
2
|
+
import type { SchemaBase } from "./property/base/SchemaBase";
|
|
3
|
+
import type { SchemaArray } from "./property/types/SchemaArray";
|
|
4
|
+
import type { SchemaObject } from "./property/types/SchemaObject";
|
|
5
|
+
import type { PropertyInfo } from "./PropertyInfo";
|
|
6
|
+
import type { DeepPartial } from "../types";
|
|
7
|
+
import type { SchemaFunction } from "./table";
|
|
8
|
+
import type { SchemaOptional } from "./property/modifiers";
|
|
9
|
+
import type { Branded } from "../utilities/types";
|
|
10
10
|
export type DefaultValue<T, I = never> = T | ((injected: I) => T);
|
|
11
11
|
export type FunctionBody<TEntity, TResult> = (entity: TEntity, collectionName: CollectionName) => TResult;
|
|
12
12
|
export type IdType = string | number;
|
|
13
|
+
export type ForeignKey<T extends {}> = {
|
|
14
|
+
schema: CompiledSchema<T>;
|
|
15
|
+
property: PropertyInfo<T>;
|
|
16
|
+
};
|
|
13
17
|
export declare enum SchemaTypes {
|
|
14
18
|
Array = "Array",
|
|
15
19
|
Boolean = "Boolean",
|
|
@@ -83,7 +87,7 @@ export interface ISchemaSubscription<T extends {}> extends Disposable {
|
|
|
83
87
|
send(changes: SubscriptionChanges<T>): void;
|
|
84
88
|
onMessage(callback: (changes: SubscriptionChanges<T>) => void): void;
|
|
85
89
|
}
|
|
86
|
-
type Enrich<TEntity extends {}> = {
|
|
90
|
+
export type Enrich<TEntity extends {}> = {
|
|
87
91
|
(entity: InferType<TEntity>, changeTrackingType: ChangeTrackingType): InferType<TEntity>;
|
|
88
92
|
(entity: InferCreateType<TEntity>, changeTrackingType: ChangeTrackingType): InferCreateType<TEntity>;
|
|
89
93
|
};
|
|
@@ -95,7 +99,11 @@ export type Preprocess<TEntity extends {}> = {
|
|
|
95
99
|
(entity: InferCreateType<TEntity>): InferType<TEntity>;
|
|
96
100
|
(entity: InferType<TEntity>): InferType<TEntity>;
|
|
97
101
|
};
|
|
102
|
+
export type SetProperties<TEntity extends {}> = (destination: InferType<TEntity> | InferCreateType<TEntity>, source: InferType<TEntity> | InferCreateType<TEntity>) => void;
|
|
98
103
|
export type CompiledSchemaCore<TEntity extends {}> = Omit<CompiledSchema<TEntity>, "createSubscription">;
|
|
104
|
+
export type CompiledSchemaWithMetadata<TEntity extends {}, TMetadata> = {
|
|
105
|
+
readonly metadata: TMetadata;
|
|
106
|
+
} & CompiledSchema<TEntity>;
|
|
99
107
|
/**
|
|
100
108
|
* Represents a fully compiled schema with all utilities and metadata for an entity type.
|
|
101
109
|
*/
|
|
@@ -130,6 +138,8 @@ export type CompiledSchema<TEntity extends {}> = {
|
|
|
130
138
|
compare: (a: InferType<TEntity>, fromDb: InferType<TEntity>) => boolean;
|
|
131
139
|
/** Deserializes an entity from storage format. */
|
|
132
140
|
deserialize: (entity: InferType<TEntity>) => InferType<TEntity>;
|
|
141
|
+
/** Sets 1 or many properties from the source object onto the destination object with change tracking. */
|
|
142
|
+
set: SetProperties<TEntity>;
|
|
133
143
|
/** Combines serializing and preparing an entity for saving. */
|
|
134
144
|
preprocess: Preprocess<TEntity>;
|
|
135
145
|
/** Combines deserializing and enriching an entity for selection. */
|
|
@@ -170,6 +180,7 @@ type InferPrimitive<T> = T extends SchemaOptional<infer C, infer __> ? C extends
|
|
|
170
180
|
export type InferType<T> = T extends CompiledSchema<infer R> ? InferCompiledSchema<R> : T extends {} ? InferCompiledSchema<T> : T;
|
|
171
181
|
export type InferCreateType<T> = T extends CompiledSchema<infer R> ? InferCompiledCreateSchema<R> : T extends {} ? InferCompiledCreateSchema<T> : unknown;
|
|
172
182
|
export type InferMappedType<T> = T extends SchemaBase<infer K, infer __> ? InferType<K> : InferCompiledSchema<T>;
|
|
183
|
+
export type InferRoot<T> = T extends CompiledSchema<infer R> ? R : never;
|
|
173
184
|
type HasModifier<T, K extends keyof T, M extends SchemaModifiers> = T[K] extends SchemaBase<any, infer Mods> ? M extends Mods ? true : false : false;
|
|
174
185
|
type IsPlainProperty<T, K extends keyof T> = [
|
|
175
186
|
HasModifier<T, K, "readonly">,
|
|
@@ -180,21 +191,24 @@ type IsPlainProperty<T, K extends keyof T> = [
|
|
|
180
191
|
false,
|
|
181
192
|
false
|
|
182
193
|
] ? true : false;
|
|
183
|
-
type
|
|
194
|
+
type IsCreateExcluded<T, K extends keyof T> = [
|
|
184
195
|
HasModifier<T, K, "identity">,
|
|
185
|
-
HasModifier<T, K, "default">,
|
|
186
196
|
HasModifier<T, K, "computed">,
|
|
187
|
-
HasModifier<T, K, "unmapped"
|
|
188
|
-
HasModifier<T, K, "optional">,
|
|
189
|
-
HasModifier<T, K, "nullable">
|
|
197
|
+
HasModifier<T, K, "unmapped">
|
|
190
198
|
] extends [
|
|
191
199
|
false,
|
|
192
200
|
false,
|
|
193
|
-
false
|
|
194
|
-
|
|
201
|
+
false
|
|
202
|
+
] ? false : true;
|
|
203
|
+
type IsCreateOptional<T, K extends keyof T> = [
|
|
204
|
+
HasModifier<T, K, "optional">,
|
|
205
|
+
HasModifier<T, K, "default">
|
|
206
|
+
] extends [
|
|
195
207
|
false,
|
|
196
208
|
false
|
|
197
|
-
] ?
|
|
209
|
+
] ? false : true;
|
|
210
|
+
type IsCreateNullable<T, K extends keyof T> = HasModifier<T, K, "nullable"> extends true ? true : false;
|
|
211
|
+
type InferCreateProperty<T, K extends keyof T> = IsCreateNullable<T, K> extends true ? null | InferPrimitive<T[K]> : InferPrimitive<T[K]>;
|
|
198
212
|
type InferCompiledSchema<T> = CoalesceEmpty<{
|
|
199
213
|
[K in keyof T as IsPlainProperty<T, K> extends true ? K : never]: InferPrimitive<T[K]>;
|
|
200
214
|
}, {
|
|
@@ -204,15 +218,11 @@ type InferCompiledSchema<T> = CoalesceEmpty<{
|
|
|
204
218
|
}, {
|
|
205
219
|
[K in keyof T as HasModifier<T, K, "nullable"> extends true ? K : never]: null | InferPrimitive<T[K]>;
|
|
206
220
|
}>;
|
|
207
|
-
type InferCompiledCreateSchema<T> =
|
|
208
|
-
[K in keyof T as
|
|
209
|
-
}
|
|
210
|
-
[K in keyof T as
|
|
211
|
-
}
|
|
212
|
-
[K in keyof T as HasModifier<T, K, "default"> extends true ? K : never]?: InferPrimitive<T[K]>;
|
|
213
|
-
}, {
|
|
214
|
-
[K in keyof T as HasModifier<T, K, "nullable"> extends true ? K : never]: null | InferPrimitive<T[K]>;
|
|
215
|
-
}>;
|
|
221
|
+
type InferCompiledCreateSchema<T> = {
|
|
222
|
+
[K in keyof T as IsCreateExcluded<T, K> extends true ? never : IsCreateOptional<T, K> extends true ? K : never]?: InferCreateProperty<T, K>;
|
|
223
|
+
} & {
|
|
224
|
+
[K in keyof T as IsCreateExcluded<T, K> extends true ? never : IsCreateOptional<T, K> extends true ? never : K]: InferCreateProperty<T, K>;
|
|
225
|
+
};
|
|
216
226
|
type IsEmptyObject<T> = keyof T extends never ? true : false;
|
|
217
227
|
type CoalesceEmpty<T1 extends {}, T2 extends {}, T3 extends {}, T4 extends {}> = (IsEmptyObject<T1> extends true ? {} : T1) & (IsEmptyObject<T2> extends true ? {} : T2) & (IsEmptyObject<T3> extends true ? {} : T3) & (IsEmptyObject<T4> extends true ? {} : T4);
|
|
218
228
|
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { PropertyInfo } from '../PropertyInfo';
|
|
2
|
+
import { CompiledSchema, InferCreateType, InferType } from '../types';
|
|
3
|
+
import { SchemaDefinition } from '../SchemaDefinition';
|
|
4
|
+
/**
|
|
5
|
+
* Standard JSON Schema V1 interface types
|
|
6
|
+
* Based on https://standardschema.dev/json-schema
|
|
7
|
+
*/
|
|
8
|
+
export interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
9
|
+
readonly '~standard': StandardTypedV1.Props<Input, Output>;
|
|
10
|
+
}
|
|
11
|
+
export declare namespace StandardTypedV1 {
|
|
12
|
+
interface Props<Input = unknown, Output = Input> {
|
|
13
|
+
readonly version: 1;
|
|
14
|
+
readonly vendor: string;
|
|
15
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
16
|
+
}
|
|
17
|
+
interface Types<Input = unknown, Output = Input> {
|
|
18
|
+
readonly input: Input;
|
|
19
|
+
readonly output: Output;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
|
|
23
|
+
readonly '~standard': StandardJSONSchemaV1.Props<Input, Output>;
|
|
24
|
+
}
|
|
25
|
+
export declare namespace StandardJSONSchemaV1 {
|
|
26
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
27
|
+
readonly jsonSchema: StandardJSONSchemaV1.Converter;
|
|
28
|
+
}
|
|
29
|
+
interface Converter {
|
|
30
|
+
readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
31
|
+
readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
type Target = 'draft-2020-12' | 'draft-07' | 'openapi-3.0' | ({} & string);
|
|
34
|
+
interface Options {
|
|
35
|
+
readonly target: Target;
|
|
36
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Converts a Routier PropertyInfo to a JSON Schema property definition.
|
|
41
|
+
*/
|
|
42
|
+
export declare function propertyInfoToJsonSchema(property: PropertyInfo<any>, target: StandardJSONSchemaV1.Target, visited?: Set<string>, useOutputType?: boolean): Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Converts a CompiledSchema to a JSON Schema object schema.
|
|
45
|
+
*/
|
|
46
|
+
export declare function compiledSchemaToJsonSchema<T extends {}>(compiledSchema: CompiledSchema<T>, target: StandardJSONSchemaV1.Target, useOutputType?: boolean): Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* Creates Standard JSON Schema V1 props for a compiled schema.
|
|
49
|
+
*/
|
|
50
|
+
export declare function createStandardJsonSchemaProps<T extends {}>(compiledSchema: CompiledSchema<T>): StandardJSONSchemaV1.Props<InferCreateType<T>, InferType<T>>;
|
|
51
|
+
/**
|
|
52
|
+
* Parses a JSON string containing a JSON Schema and rehydrates it into a Routier SchemaDefinition.
|
|
53
|
+
* This is a convenience wrapper around `rehydrateSchemaFromJsonSchema` that handles JSON parsing.
|
|
54
|
+
*
|
|
55
|
+
* @param jsonString - The JSON string containing the JSON Schema
|
|
56
|
+
* @param collectionName - The collection name for the schema (if not in x-routier metadata)
|
|
57
|
+
* @returns A SchemaDefinition that can be compiled
|
|
58
|
+
* @throws Error if the JSON string is invalid or doesn't contain a valid JSON Schema
|
|
59
|
+
*/
|
|
60
|
+
export declare function rehydrateSchemaFromJsonString(jsonString: string, collectionName?: string): SchemaDefinition<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Rehydrates a JSON Schema back into a Routier SchemaDefinition.
|
|
63
|
+
* This parses the JSON Schema structure and reconstructs the schema using Routier's builder API.
|
|
64
|
+
*
|
|
65
|
+
* @param jsonSchema - The JSON Schema object to rehydrate
|
|
66
|
+
* @param collectionName - The collection name for the schema (if not in x-routier metadata)
|
|
67
|
+
* @returns A SchemaDefinition that can be compiled
|
|
68
|
+
*/
|
|
69
|
+
export declare function rehydrateSchemaFromJsonSchema(jsonSchema: Record<string, unknown>, collectionName?: string): SchemaDefinition<any>;
|
|
70
|
+
/**
|
|
71
|
+
* Attempts to extract type information from a compiled schema for better type inference.
|
|
72
|
+
*
|
|
73
|
+
* Note: TypeScript types are compile-time only, so we can't extract actual type information at runtime.
|
|
74
|
+
* The Standard JSON Schema spec allows libraries to advertise their inferred types via the `types` property,
|
|
75
|
+
* but this requires compile-time type information that isn't available at runtime.
|
|
76
|
+
*
|
|
77
|
+
* For proper type inference, consumers should use TypeScript's type system:
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const schema = s.define("users", { ... }).compile();
|
|
80
|
+
* type User = InferType<typeof schema>;
|
|
81
|
+
* type CreateUser = InferCreateType<typeof schema>;
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @param compiledSchema - The compiled schema to extract type info from
|
|
85
|
+
* @returns A description of the type names (for documentation purposes only)
|
|
86
|
+
*/
|
|
87
|
+
export declare function extractTypeInfo<T extends {}>(compiledSchema: CompiledSchema<T>): {
|
|
88
|
+
inputType: string;
|
|
89
|
+
outputType: string;
|
|
90
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const noop: (...
|
|
1
|
+
export declare const noop: (..._args: any[]) => void;
|