@tstdl/base 0.78.0-beta1 → 0.78.0-beta4
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/api/server/gateway.js.map +1 -1
- package/api/types.d.ts +4 -3
- package/api/types.js.map +1 -1
- package/container/container.js.map +1 -1
- package/container/resolve-chain.d.ts +5 -5
- package/container/resolve-chain.js.map +1 -1
- package/database/mongo/mongo-base.repository.js.map +1 -1
- package/database/mongo/types.d.ts +2 -2
- package/key-value-store/mongo/mongo-key-value.model.d.ts +1 -0
- package/mail/template-providers/file-mail-template.provider.js +2 -2
- package/mail/template-providers/file-mail-template.provider.js.map +1 -1
- package/package.json +5 -5
- package/queue/mongo/mongo-job.repository.js +1 -1
- package/queue/mongo/mongo-job.repository.js.map +1 -1
- package/reflection/registry.d.ts +8 -8
- package/reflection/registry.js.map +1 -1
- package/schema/coercers/uint8-array.coercer.js +2 -8
- package/schema/coercers/uint8-array.coercer.js.map +1 -1
- package/schema/decorators/array.d.ts +3 -2
- package/schema/decorators/array.js.map +1 -1
- package/schema/decorators/defaulted.d.ts +3 -2
- package/schema/decorators/defaulted.js.map +1 -1
- package/schema/decorators/property.d.ts +3 -3
- package/schema/decorators/property.js +2 -1
- package/schema/decorators/property.js.map +1 -1
- package/schema/decorators/types.d.ts +2 -2
- package/schema/decorators/utils.js +1 -1
- package/schema/decorators/utils.js.map +1 -1
- package/schema/schema.d.ts +8 -9
- package/schema/schema.js +8 -7
- package/schema/schema.js.map +1 -1
- package/schema/schemas/any.js +1 -1
- package/schema/schemas/any.js.map +1 -1
- package/schema/schemas/array.d.ts +3 -2
- package/schema/schemas/array.js +1 -2
- package/schema/schemas/array.js.map +1 -1
- package/schema/schemas/assign.d.ts +5 -5
- package/schema/schemas/assign.js +0 -1
- package/schema/schemas/assign.js.map +1 -1
- package/schema/schemas/boolean.js +1 -2
- package/schema/schemas/boolean.js.map +1 -1
- package/schema/schemas/constraint.d.ts +1 -1
- package/schema/schemas/constraint.js +1 -2
- package/schema/schemas/constraint.js.map +1 -1
- package/schema/schemas/date.js +1 -2
- package/schema/schemas/date.js.map +1 -1
- package/schema/schemas/defaulted.d.ts +3 -2
- package/schema/schemas/defaulted.js +1 -2
- package/schema/schemas/defaulted.js.map +1 -1
- package/schema/schemas/enumeration.js +1 -2
- package/schema/schemas/enumeration.js.map +1 -1
- package/schema/schemas/exclude.js.map +1 -1
- package/schema/schemas/instance.js +1 -1
- package/schema/schemas/instance.js.map +1 -1
- package/schema/schemas/literal.js +1 -2
- package/schema/schemas/literal.js.map +1 -1
- package/schema/schemas/nullable.d.ts +2 -3
- package/schema/schemas/nullable.js +1 -1
- package/schema/schemas/nullable.js.map +1 -1
- package/schema/schemas/number.js +4 -2
- package/schema/schemas/number.js.map +1 -1
- package/schema/schemas/object.d.ts +1 -1
- package/schema/schemas/object.js.map +1 -1
- package/schema/schemas/optional.d.ts +1 -1
- package/schema/schemas/optional.js +1 -1
- package/schema/schemas/optional.js.map +1 -1
- package/schema/schemas/pick.js.map +1 -1
- package/schema/schemas/readable-stream.js +2 -3
- package/schema/schemas/readable-stream.js.map +1 -1
- package/schema/schemas/record.d.ts +4 -4
- package/schema/schemas/record.js +2 -2
- package/schema/schemas/record.js.map +1 -1
- package/schema/schemas/regexp.js +2 -2
- package/schema/schemas/regexp.js.map +1 -1
- package/schema/schemas/string.js +1 -2
- package/schema/schemas/string.js.map +1 -1
- package/schema/schemas/transform.d.ts +2 -2
- package/schema/schemas/transform.js +1 -3
- package/schema/schemas/transform.js.map +1 -1
- package/schema/schemas/uint8-array.d.ts +1 -1
- package/schema/schemas/uint8-array.js +2 -2
- package/schema/schemas/uint8-array.js.map +1 -1
- package/schema/schemas/union.d.ts +8 -4
- package/schema/schemas/union.js +4 -3
- package/schema/schemas/union.js.map +1 -1
- package/schema/schemas/unknown.js +1 -1
- package/schema/schemas/unknown.js.map +1 -1
- package/schema/transformers/generic.d.ts +8 -8
- package/schema/transformers/generic.js.map +1 -1
- package/schema/transformers/lowercase.d.ts +2 -2
- package/schema/transformers/lowercase.js.map +1 -1
- package/schema/transformers/trim.d.ts +2 -2
- package/schema/transformers/trim.js.map +1 -1
- package/schema/transformers/uppercase.d.ts +2 -2
- package/schema/transformers/uppercase.js.map +1 -1
- package/schema/types.d.ts +53 -47
- package/schema/types.js +39 -6
- package/schema/types.js.map +1 -1
- package/schema/utils/schema.d.ts +4 -8
- package/schema/utils/schema.js +5 -27
- package/schema/utils/schema.js.map +1 -1
- package/schema/utils/value-type.d.ts +2 -3
- package/schema/utils/value-type.js +1 -17
- package/schema/utils/value-type.js.map +1 -1
- package/templates/providers/file-template.provider.js.map +1 -1
- package/types.d.ts +33 -0
|
@@ -5,5 +5,5 @@ export declare type Uint8ArraySchemaOptions = Coercible & {
|
|
|
5
5
|
minimumLength?: number;
|
|
6
6
|
maximumLength?: number;
|
|
7
7
|
};
|
|
8
|
-
export declare function uint8Array(options?: Uint8ArraySchemaOptions): Schema<Uint8Array>;
|
|
8
|
+
export declare function uint8Array(options?: Uint8ArraySchemaOptions): Schema<globalThis.Uint8Array>;
|
|
9
9
|
export declare function Uint8Array(options?: Uint8ArraySchemaOptions): Decorator<'property' | 'accessor'>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.Uint8Array = exports.uint8Array = void 0;
|
|
4
5
|
const type_guards_1 = require("../../utils/type-guards");
|
|
@@ -15,8 +16,7 @@ function uint8Array(options = {}) {
|
|
|
15
16
|
if ((0, type_guards_1.isDefined)(options.maximumLength)) {
|
|
16
17
|
constraints.push(new maximum_length_1.MaximumLengthConstraint(options.maximumLength));
|
|
17
18
|
}
|
|
18
|
-
return (0, types_1.valueSchema)({
|
|
19
|
-
type: globalThis.Uint8Array,
|
|
19
|
+
return (0, types_1.valueSchema)(globalThis.Uint8Array, {
|
|
20
20
|
coercers: (options.coerce == true) ? uint8_array_coercer_1.uint8ArrayCoercer : undefined,
|
|
21
21
|
valueConstraints: constraints
|
|
22
22
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8-array.js","sourceRoot":"","sources":["../../../source/schema/schemas/uint8-array.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"uint8-array.js","sourceRoot":"","sources":["../../../source/schema/schemas/uint8-array.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,yDAAgD;AAChD,yEAAoE;AACpE,kEAAwE;AACxE,kEAAwE;AACxE,8CAA2E;AAG3E,oCAAuC;AAOvC,SAAgB,UAAU,CAAC,UAAmC,EAAE;IAC9D,MAAM,WAAW,GAA4B,EAAE,CAAC;IAEhD,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,aAAa,CAAC,EAAE;QACpC,WAAW,CAAC,IAAI,CAAC,IAAI,wCAAuB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;KACtE;IAED,IAAI,IAAA,uBAAS,EAAC,OAAO,CAAC,aAAa,CAAC,EAAE;QACpC,WAAW,CAAC,IAAI,CAAC,IAAI,wCAAuB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;KACtE;IAED,OAAO,IAAA,mBAAW,EAAC,UAAU,CAAC,UAAU,EAAE;QACxC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,uCAAiB,CAAC,CAAC,CAAC,SAAS;QAClE,gBAAgB,EAAE,WAAW;KAC9B,CAAC,CAAC;AACL,CAAC;AAfD,gCAeC;AAED,SAAgB,UAAU,CAAC,OAAiC;IAC1D,OAAO,IAAA,uDAA0C,EAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AACzE,CAAC;AAFD,gCAEC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { Decorator } from "../../reflection";
|
|
2
|
-
import type {
|
|
3
|
-
export declare
|
|
4
|
-
export declare function union<
|
|
5
|
-
export declare function
|
|
2
|
+
import type { ValueSchema, ValueType } from '../types';
|
|
3
|
+
export declare function union<T1, O1, T2, O2>(schema1: ValueType<T1, O1>, schema2: ValueType<T2, O2>): ValueSchema<T1 | T2, O1 | O2>;
|
|
4
|
+
export declare function union<T1, O1, T2, O2, T3, O3>(schema1: ValueType<T1, O1>, schema2: ValueType<T2, O2>, schema3: ValueType<T3, O3>): ValueSchema<T1 | T2 | T3, O1 | O2 | O3>;
|
|
5
|
+
export declare function union<T1, O1, T2, O2, T3, O3, T4, O4>(schema1: ValueType<T1, O1>, schema2: ValueType<T2, O2>, schema3: ValueType<T3, O3>, schema4: ValueType<T4, O4>): ValueSchema<T1 | T2 | T3 | T4, O1 | O2 | O3 | O4>;
|
|
6
|
+
export declare function union<T1, O1, T2, O2, T3, O3, T4, O4, T5, O5>(schema1: ValueType<T1, O1>, schema2: ValueType<T2, O2>, schema3: ValueType<T3, O3>, schema4: ValueType<T4, O4>, schema5: ValueType<T5, O5>): ValueSchema<T1 | T2 | T3 | T4 | T5, O1 | O2 | O3 | O4 | O5>;
|
|
7
|
+
export declare function union<T1, O1, T2, O2, T3, O3, T4, O4, T5, O5, T6, O6>(schema1: ValueType<T1, O1>, schema2: ValueType<T2, O2>, schema3: ValueType<T3, O3>, schema4: ValueType<T4, O4>, schema5: ValueType<T5, O5>, schema6: ValueType<T6>): ValueSchema<T1 | T2 | T3 | T4 | T5 | T6, O1 | O2 | O3 | O4 | O5 | O6>;
|
|
8
|
+
export declare function union(...schemas: ValueType[]): ValueSchema;
|
|
9
|
+
export declare function Union(...schemas: ValueType[]): Decorator<'property' | 'accessor'>;
|
package/schema/schemas/union.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.Union = exports.union = void 0;
|
|
5
|
+
const type_guards_1 = require("../../utils/type-guards");
|
|
4
6
|
const decorators_1 = require("../decorators");
|
|
5
7
|
const types_1 = require("../types");
|
|
6
8
|
function union(...schemas) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
9
|
+
(0, type_guards_1.assert)(schemas.length >= 2, 'Assign requires at least 2 schemas.');
|
|
10
|
+
return (0, types_1.valueSchema)(schemas);
|
|
10
11
|
}
|
|
11
12
|
exports.union = union;
|
|
12
13
|
function Union(...schemas) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union.js","sourceRoot":"","sources":["../../../source/schema/schemas/union.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"union.js","sourceRoot":"","sources":["../../../source/schema/schemas/union.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,yDAA6C;AAC7C,8CAA2E;AAE3E,oCAAuC;AAQvC,SAAgB,KAAK,CAAC,GAAG,OAAoB;IAC3C,IAAA,oBAAM,EAAC,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,qCAAqC,CAAC,CAAC;IACnE,OAAO,IAAA,mBAAW,EAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAHD,sBAGC;AAED,SAAgB,KAAK,CAAC,GAAG,OAAoB;IAC3C,OAAO,IAAA,uDAA0C,EAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;AACvE,CAAC;AAFD,sBAEC"}
|
|
@@ -5,7 +5,7 @@ exports.Unknwon = exports.unknown = void 0;
|
|
|
5
5
|
const decorators_1 = require("../decorators");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
7
|
function unknown() {
|
|
8
|
-
return (0, types_1.valueSchema)(
|
|
8
|
+
return (0, types_1.valueSchema)('any');
|
|
9
9
|
}
|
|
10
10
|
exports.unknown = unknown;
|
|
11
11
|
function Unknwon() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../source/schema/schemas/unknown.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,8CAA2E;AAE3E,oCAAuC;AAEvC,SAAgB,OAAO;IACrB,OAAO,IAAA,mBAAW,EAAC,
|
|
1
|
+
{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../source/schema/schemas/unknown.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,8CAA2E;AAE3E,oCAAuC;AAEvC,SAAgB,OAAO;IACrB,OAAO,IAAA,mBAAW,EAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAFD,0BAEC;AAED,SAAgB,OAAO;IACrB,OAAO,IAAA,uDAA0C,EAAC,OAAO,EAAE,CAAC,CAAC;AAC/D,CAAC;AAFD,0BAEC"}
|
|
@@ -2,12 +2,12 @@ import type { Decorator } from "../../reflection";
|
|
|
2
2
|
import type { OneOrMany, TypedOmit } from "../../types";
|
|
3
3
|
import type { TransformResult, ValueType } from '../types';
|
|
4
4
|
import { SchemaValueTransformer } from '../types';
|
|
5
|
-
export declare type GenericTransformFunction<T> = (value: T) => TypedOmit<TransformResult
|
|
6
|
-
export declare class GenericTransformer<T> extends SchemaValueTransformer {
|
|
7
|
-
readonly sourceType: OneOrMany<ValueType
|
|
8
|
-
readonly targetType: ValueType
|
|
9
|
-
readonly transformFunction: GenericTransformFunction<
|
|
10
|
-
constructor(sourceType: OneOrMany<ValueType
|
|
11
|
-
transform(value:
|
|
5
|
+
export declare type GenericTransformFunction<T, O> = (value: T) => TypedOmit<TransformResult<O>, 'success'>;
|
|
6
|
+
export declare class GenericTransformer<T, O, TransformOutput> extends SchemaValueTransformer<T, O, TransformOutput> {
|
|
7
|
+
readonly sourceType: OneOrMany<ValueType<T, O>>;
|
|
8
|
+
readonly targetType: ValueType<TransformOutput>;
|
|
9
|
+
readonly transformFunction: GenericTransformFunction<O, TransformOutput>;
|
|
10
|
+
constructor(sourceType: OneOrMany<ValueType<T, O>>, targetType: ValueType<TransformOutput>, transformFunction: GenericTransformFunction<O, TransformOutput>);
|
|
11
|
+
transform(value: O): TransformResult<TransformOutput>;
|
|
12
12
|
}
|
|
13
|
-
export declare function Transform<T>(sourceType: OneOrMany<ValueType
|
|
13
|
+
export declare function Transform<T, O, TransformOutput>(sourceType: OneOrMany<ValueType<T, O>>, targetType: ValueType, transformFunction: GenericTransformFunction<O, TransformOutput>): Decorator<'property' | 'accessor'>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../../../source/schema/transformers/generic.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAIzD,yDAAgD;AAChD,8CAAsE;AAEtE,oCAAkD;AAIlD,MAAa,
|
|
1
|
+
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../../../source/schema/transformers/generic.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAIzD,yDAAgD;AAChD,8CAAsE;AAEtE,oCAAkD;AAIlD,MAAa,kBAA0C,SAAQ,8BAA6C;IAK1G,YAAY,UAAsC,EAAE,UAAsC,EAAE,iBAA+D;QACzJ,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAED,SAAS,CAAC,KAAQ;QAChB,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAE7C,IAAI,IAAA,uBAAS,EAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YAC3B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;SAChD;QAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAM,EAAE,CAAC;IACjD,CAAC;CACF;AAtBD,gDAsBC;AAED,SAAgB,SAAS,CAAwB,UAAsC,EAAE,UAAqB,EAAE,iBAA+D;IAC7K,OAAO,IAAA,kDAAqC,EAAC,IAAI,kBAAkB,CAAC,UAAU,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAClH,CAAC;AAFD,8BAEC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Decorator } from "../../reflection";
|
|
2
2
|
import type { TransformResult } from '../types';
|
|
3
3
|
import { SchemaValueTransformer } from '../types';
|
|
4
|
-
export declare class LowercaseTransformer extends SchemaValueTransformer {
|
|
4
|
+
export declare class LowercaseTransformer extends SchemaValueTransformer<string, string, string> {
|
|
5
5
|
readonly sourceType: StringConstructor;
|
|
6
6
|
readonly targetType: StringConstructor;
|
|
7
|
-
transform(value: string): TransformResult
|
|
7
|
+
transform(value: string): TransformResult<string>;
|
|
8
8
|
}
|
|
9
9
|
export declare function Lowercase(): Decorator<'property' | 'accessor'>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lowercase.js","sourceRoot":"","sources":["../../../source/schema/transformers/lowercase.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,8CAAsE;AAEtE,oCAAkD;AAElD,MAAa,oBAAqB,SAAQ,
|
|
1
|
+
{"version":3,"file":"lowercase.js","sourceRoot":"","sources":["../../../source/schema/transformers/lowercase.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,8CAAsE;AAEtE,oCAAkD;AAElD,MAAa,oBAAqB,SAAQ,8BAA8C;IAAxF;;QACW,eAAU,GAAG,MAAM,CAAC;QACpB,eAAU,GAAG,MAAM,CAAC;IAK/B,CAAC;IAHC,SAAS,CAAC,KAAa;QACrB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;IACvD,CAAC;CACF;AAPD,oDAOC;AAED,SAAgB,SAAS;IACvB,OAAO,IAAA,kDAAqC,EAAC,IAAI,oBAAoB,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAC7F,CAAC;AAFD,8BAEC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Decorator } from "../../reflection";
|
|
2
2
|
import type { TransformResult } from '../types';
|
|
3
3
|
import { SchemaValueTransformer } from '../types';
|
|
4
|
-
export declare class TrimTransformer extends SchemaValueTransformer {
|
|
4
|
+
export declare class TrimTransformer extends SchemaValueTransformer<string, string, string> {
|
|
5
5
|
readonly sourceType: StringConstructor;
|
|
6
6
|
readonly targetType: StringConstructor;
|
|
7
|
-
transform(value: string): TransformResult
|
|
7
|
+
transform(value: string): TransformResult<string>;
|
|
8
8
|
}
|
|
9
9
|
export declare function Trim(): Decorator<'property' | 'accessor'>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trim.js","sourceRoot":"","sources":["../../../source/schema/transformers/trim.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,8CAAsE;AAEtE,oCAAkD;AAElD,MAAa,eAAgB,SAAQ,
|
|
1
|
+
{"version":3,"file":"trim.js","sourceRoot":"","sources":["../../../source/schema/transformers/trim.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,8CAAsE;AAEtE,oCAAkD;AAElD,MAAa,eAAgB,SAAQ,8BAA8C;IAAnF;;QACW,eAAU,GAAG,MAAM,CAAC;QACpB,eAAU,GAAG,MAAM,CAAC;IAK/B,CAAC;IAHC,SAAS,CAAC,KAAa;QACrB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;IAChD,CAAC;CACF;AAPD,0CAOC;AAED,SAAgB,IAAI;IAClB,OAAO,IAAA,kDAAqC,EAAC,IAAI,eAAe,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AACxF,CAAC;AAFD,oBAEC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Decorator } from "../../reflection";
|
|
2
2
|
import type { TransformResult } from '../types';
|
|
3
3
|
import { SchemaValueTransformer } from '../types';
|
|
4
|
-
export declare class UppercaseTransformer extends SchemaValueTransformer {
|
|
4
|
+
export declare class UppercaseTransformer extends SchemaValueTransformer<string, string, string> {
|
|
5
5
|
readonly sourceType: StringConstructor;
|
|
6
6
|
readonly targetType: StringConstructor;
|
|
7
|
-
transform(value: string): TransformResult
|
|
7
|
+
transform(value: string): TransformResult<string>;
|
|
8
8
|
}
|
|
9
9
|
export declare function Uppercase(): Decorator<'property' | 'accessor'>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uppercase.js","sourceRoot":"","sources":["../../../source/schema/transformers/uppercase.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,8CAAsE;AAEtE,oCAAkD;AAElD,MAAa,oBAAqB,SAAQ,
|
|
1
|
+
{"version":3,"file":"uppercase.js","sourceRoot":"","sources":["../../../source/schema/transformers/uppercase.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAGzD,8CAAsE;AAEtE,oCAAkD;AAElD,MAAa,oBAAqB,SAAQ,8BAA8C;IAAxF;;QACW,eAAU,GAAG,MAAM,CAAC;QACpB,eAAU,GAAG,MAAM,CAAC;IAK/B,CAAC;IAHC,SAAS,CAAC,KAAa;QACrB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;IACvD,CAAC;CACF;AAPD,oDAOC;AAED,SAAgB,SAAS;IACvB,OAAO,IAAA,kDAAqC,EAAC,IAAI,oBAAoB,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAC7F,CAAC;AAFD,8BAEC"}
|
package/schema/types.d.ts
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
import type { JsonPath } from "../json-path/json-path";
|
|
2
|
-
import type { OneOrMany, Record, Type } from "../types";
|
|
3
|
-
import type { Schema } from './schema';
|
|
2
|
+
import type { AbstractConstructor, OneOrMany, Record, Type, TypedOmit } from "../types";
|
|
3
|
+
import type { Schema, SchemaTestable } from './schema';
|
|
4
4
|
import type { SchemaError } from './schema.error';
|
|
5
|
-
declare const
|
|
6
|
-
export declare type SchemaFactoryFunction<T extends Record> = (data: T) =>
|
|
7
|
-
export declare type SchemaFactory<T extends Record> = {
|
|
8
|
-
type: Type<T
|
|
5
|
+
declare const schemaOutputTypeSymbol: unique symbol;
|
|
6
|
+
export declare type SchemaFactoryFunction<T extends Record, O = T> = (data: T) => NormalizeValueType<O>;
|
|
7
|
+
export declare type SchemaFactory<T extends Record, O = T> = {
|
|
8
|
+
type: Type<T>;
|
|
9
9
|
builder?: undefined;
|
|
10
10
|
} | {
|
|
11
11
|
type?: undefined;
|
|
12
|
-
builder: SchemaFactoryFunction<T>;
|
|
12
|
+
builder: SchemaFactoryFunction<T, O>;
|
|
13
13
|
};
|
|
14
14
|
export declare type ObjectSchemaProperties<T extends Record> = {
|
|
15
|
-
[K in keyof T]-?:
|
|
15
|
+
[K in keyof T]-?: OneOrMany<ValueType<T[K]>>;
|
|
16
16
|
};
|
|
17
|
-
export declare type
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
export declare type NormalizedObjectSchemaProperties<T> = {
|
|
18
|
+
[K in keyof T]: Schema<T[K]>;
|
|
19
|
+
};
|
|
20
|
+
export declare type SchemaOutput<T extends SchemaTestable> = T extends ObjectSchema<any, infer O> ? O : T extends ValueSchema<any, infer O> ? O : T extends TypeSchema ? InstanceType<T> : never;
|
|
21
|
+
export declare type ObjectSchema<T extends Record = any, O extends Record = T> = {
|
|
22
|
+
[schemaOutputTypeSymbol]?: O;
|
|
23
|
+
factory?: SchemaFactory<T, O>;
|
|
20
24
|
properties: ObjectSchemaProperties<T>;
|
|
21
25
|
mask?: boolean;
|
|
22
|
-
allowUnknownProperties?:
|
|
26
|
+
allowUnknownProperties?: OneOrMany<ValueType>;
|
|
23
27
|
};
|
|
24
|
-
export declare type
|
|
25
|
-
|
|
26
|
-
type:
|
|
28
|
+
export declare type TypeSchema<T = any, O = T> = AbstractConstructor<T & O>;
|
|
29
|
+
export declare type ValueSchema<T = unknown, O = T> = {
|
|
30
|
+
type: OneOrMany<ValueType<T, O>>;
|
|
27
31
|
array?: boolean;
|
|
28
32
|
optional?: boolean;
|
|
29
33
|
nullable?: boolean;
|
|
@@ -35,22 +39,22 @@ export declare type ValueSchema<T = any> = {
|
|
|
35
39
|
arrayConstraints?: OneOrMany<SchemaArrayConstraint>;
|
|
36
40
|
valueConstraints?: OneOrMany<SchemaValueConstraint>;
|
|
37
41
|
};
|
|
38
|
-
export declare type NormalizedObjectSchema<T extends Record = any> = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
42
|
+
export declare type NormalizedObjectSchema<T extends Record = any, O extends Record = T> = {
|
|
43
|
+
[schemaOutputTypeSymbol]?: O;
|
|
44
|
+
factory?: SchemaFactory<T, O>;
|
|
45
|
+
properties: NormalizedObjectSchemaProperties<T>;
|
|
43
46
|
mask?: boolean;
|
|
44
47
|
allowUnknownProperties: Set<Schema>;
|
|
45
48
|
};
|
|
46
|
-
export declare type NormalizedValueSchema<T = any> = {
|
|
47
|
-
|
|
49
|
+
export declare type NormalizedValueSchema<T = any, O = T> = {
|
|
50
|
+
[schemaOutputTypeSymbol]?: O;
|
|
51
|
+
type: Set<ResolvedValueType<T, O>>;
|
|
48
52
|
array: boolean;
|
|
49
53
|
optional: boolean;
|
|
50
54
|
nullable: boolean;
|
|
51
55
|
coerce: boolean;
|
|
52
56
|
coercers: Map<ValueType, SchemaValueCoercer[]>;
|
|
53
|
-
transformers: readonly SchemaValueTransformer[];
|
|
57
|
+
transformers: readonly SchemaValueTransformer<any, any, any>[];
|
|
54
58
|
arrayConstraints: readonly SchemaArrayConstraint[];
|
|
55
59
|
valueConstraints: readonly SchemaValueConstraint[];
|
|
56
60
|
};
|
|
@@ -61,37 +65,35 @@ export declare type SchemaContext = {
|
|
|
61
65
|
export declare type ConstraintContext = SchemaContext;
|
|
62
66
|
export declare type TransformerContext = SchemaContext;
|
|
63
67
|
export declare type CoercerContext = SchemaContext;
|
|
64
|
-
export declare type
|
|
65
|
-
export declare type
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export declare type ValueTypes<T = any> = OneOrMany<ValueType<T>>;
|
|
70
|
-
export declare type DeferredValueTypes<T = any> = {
|
|
71
|
-
deferred: () => ValueTypes<T>;
|
|
68
|
+
export declare type NormalizeValueType<T> = T extends String ? string : T extends Number ? number : T extends Boolean ? boolean : T extends BigInt ? bigint : T extends Symbol ? symbol : T extends 'undefined' ? undefined : T extends 'null' ? null : T;
|
|
69
|
+
export declare type NormalizeToValueType<T> = T extends string ? typeof String : T extends number ? typeof Number : T extends boolean ? typeof Boolean : T extends bigint ? typeof BigInt : T extends symbol ? typeof Symbol : T extends undefined ? 'undefined' : T extends null ? 'null' : never;
|
|
70
|
+
export declare type ValueType<T = any, O = T> = Schema<T, O> | TypeSchema<T, O> | NormalizeToValueType<T> | DeferredValueType<T, O> | 'undefined' | 'null' | 'any';
|
|
71
|
+
export declare type DeferredValueType<T = unknown, O = T> = {
|
|
72
|
+
deferred: () => ValueType<T, O>;
|
|
72
73
|
};
|
|
73
|
-
export declare type
|
|
74
|
+
export declare type ResolvedValueType<T = unknown, O = T> = Exclude<ValueType<T, O>, DeferredValueType>;
|
|
75
|
+
export declare type ValueTypeOutput<T extends ValueType | DeferredValueType> = T extends (ValueType<infer _, infer O> | DeferredValueType<infer _, infer O>) ? NormalizeValueType<O> : never;
|
|
74
76
|
export declare type Coercible = {
|
|
75
77
|
coerce?: boolean;
|
|
76
78
|
};
|
|
77
79
|
export declare const primitiveValueTypes: ValueType[];
|
|
78
|
-
export declare const primitiveValueTypesSet: Set<ValueType<any>>;
|
|
80
|
+
export declare const primitiveValueTypesSet: Set<ValueType<any, any>>;
|
|
79
81
|
export declare abstract class SchemaArrayConstraint {
|
|
80
82
|
abstract validate(value: readonly unknown[], path: JsonPath, context: ConstraintContext): ConstraintResult;
|
|
81
83
|
}
|
|
82
84
|
export declare type OptionKeys<T extends Record> = readonly (keyof T)[];
|
|
83
85
|
export declare abstract class SchemaValueConstraint {
|
|
84
|
-
abstract readonly suitableTypes:
|
|
86
|
+
abstract readonly suitableTypes: OneOrMany<ValueType>;
|
|
85
87
|
abstract readonly expects: OneOrMany<string>;
|
|
86
88
|
abstract validate(value: unknown, path: JsonPath, context: ConstraintContext): ConstraintResult;
|
|
87
89
|
}
|
|
88
|
-
export declare abstract class SchemaValueTransformer {
|
|
89
|
-
abstract readonly sourceType:
|
|
90
|
-
abstract readonly targetType: ValueType
|
|
91
|
-
abstract transform(value:
|
|
90
|
+
export declare abstract class SchemaValueTransformer<T = any, O = T, TransformOutput = O> {
|
|
91
|
+
abstract readonly sourceType: OneOrMany<ValueType<T, O>>;
|
|
92
|
+
abstract readonly targetType: ValueType<TransformOutput>;
|
|
93
|
+
abstract transform(value: O, path: JsonPath, context: TransformerContext): TransformResult<TransformOutput>;
|
|
92
94
|
}
|
|
93
95
|
export declare abstract class SchemaValueCoercer {
|
|
94
|
-
abstract readonly sourceType:
|
|
96
|
+
abstract readonly sourceType: OneOrMany<ValueType>;
|
|
95
97
|
abstract readonly targetType: ValueType;
|
|
96
98
|
abstract coerce(value: unknown, path: JsonPath, context: CoercerContext): CoerceResult;
|
|
97
99
|
}
|
|
@@ -132,19 +134,23 @@ export declare type CoerceResult = {
|
|
|
132
134
|
value?: undefined;
|
|
133
135
|
error: SchemaError;
|
|
134
136
|
};
|
|
135
|
-
export declare type TransformResult = {
|
|
137
|
+
export declare type TransformResult<T> = {
|
|
136
138
|
success: true;
|
|
137
|
-
value:
|
|
139
|
+
value: T;
|
|
138
140
|
error?: undefined;
|
|
139
141
|
} | {
|
|
140
142
|
success: false;
|
|
141
143
|
value?: undefined;
|
|
142
144
|
error: SchemaError;
|
|
143
145
|
};
|
|
144
|
-
export declare function objectSchema<T
|
|
145
|
-
export declare function valueSchema<T
|
|
146
|
-
export declare function isSchema<T>(value: ValueType<T>): value is Schema<T>;
|
|
147
|
-
export declare function isObjectSchema<T>(value: ValueType<T>): value is ObjectSchema<T>;
|
|
148
|
-
export declare function isValueSchema<T>(value: ValueType<T>): value is ValueSchema<T>;
|
|
149
|
-
export declare function isDeferredValueType<T>(value:
|
|
146
|
+
export declare function objectSchema<T, O = T>(schema: ObjectSchema<T, O>): ObjectSchema<T, O>;
|
|
147
|
+
export declare function valueSchema<T, O = T>(type: ValueSchema<T, O>['type'], options?: TypedOmit<ValueSchema<T, O>, 'type'>): ValueSchema<T, O>;
|
|
148
|
+
export declare function isSchema<T, O>(value: ValueType<T, O>): value is Schema<T, O>;
|
|
149
|
+
export declare function isObjectSchema<T extends Record, O extends Record>(value: ValueType<T, O>): value is ObjectSchema<T, O>;
|
|
150
|
+
export declare function isValueSchema<T, O>(value: ValueType<T, O>): value is ValueSchema<T, O>;
|
|
151
|
+
export declare function isDeferredValueType<T, O>(value: ValueType<T, O>): value is DeferredValueType<T, O>;
|
|
152
|
+
export declare function deferrableValueTypesToValueTypes<T, O>(valueTypes: OneOrMany<ValueType<T, O>>): OneOrMany<ResolvedValueType<T, O>>;
|
|
153
|
+
export declare function deferrableValueTypeToResolvedValueTypes<T, O>(valueType: ValueType<T, O>): ResolvedValueType<T, O>;
|
|
154
|
+
export declare function valueTypeToSchema<T, O>(valueType: ValueType<T, O>): Schema<T, O>;
|
|
155
|
+
export declare function valueTypesToSchema<T, O>(valueType: OneOrMany<ValueType<T, O>>): Schema<T, O>;
|
|
150
156
|
export {};
|
package/schema/types.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDeferredValueType = exports.isValueSchema = exports.isObjectSchema = exports.isSchema = exports.valueSchema = exports.objectSchema = exports.SchemaValueCoercer = exports.SchemaValueTransformer = exports.SchemaValueConstraint = exports.SchemaArrayConstraint = exports.primitiveValueTypesSet = exports.primitiveValueTypes = void 0;
|
|
4
|
-
const object_1 = require("../utils/object/object");
|
|
4
|
+
exports.valueTypesToSchema = exports.valueTypeToSchema = exports.deferrableValueTypeToResolvedValueTypes = exports.deferrableValueTypesToValueTypes = exports.isDeferredValueType = exports.isValueSchema = exports.isObjectSchema = exports.isSchema = exports.valueSchema = exports.objectSchema = exports.SchemaValueCoercer = exports.SchemaValueTransformer = exports.SchemaValueConstraint = exports.SchemaArrayConstraint = exports.primitiveValueTypesSet = exports.primitiveValueTypes = void 0;
|
|
5
5
|
const type_guards_1 = require("../utils/type-guards");
|
|
6
|
-
exports.primitiveValueTypes = [String, Number, Boolean, BigInt, Symbol, Function, 'undefined', 'null'
|
|
6
|
+
exports.primitiveValueTypes = [String, Number, Boolean, BigInt, Symbol, Function, 'undefined', 'null'];
|
|
7
7
|
exports.primitiveValueTypesSet = new Set(exports.primitiveValueTypes);
|
|
8
8
|
class SchemaArrayConstraint {
|
|
9
9
|
}
|
|
@@ -21,8 +21,8 @@ function objectSchema(schema) {
|
|
|
21
21
|
return schema;
|
|
22
22
|
}
|
|
23
23
|
exports.objectSchema = objectSchema;
|
|
24
|
-
function valueSchema(
|
|
25
|
-
return
|
|
24
|
+
function valueSchema(type, options) {
|
|
25
|
+
return { type, ...options };
|
|
26
26
|
}
|
|
27
27
|
exports.valueSchema = valueSchema;
|
|
28
28
|
function isSchema(value) {
|
|
@@ -38,7 +38,40 @@ function isValueSchema(value) {
|
|
|
38
38
|
}
|
|
39
39
|
exports.isValueSchema = isValueSchema;
|
|
40
40
|
function isDeferredValueType(value) {
|
|
41
|
-
return (0, type_guards_1.isObject)(value) && (0,
|
|
41
|
+
return (0, type_guards_1.isObject)(value) && (0, type_guards_1.isFunction)(value.deferred);
|
|
42
42
|
}
|
|
43
43
|
exports.isDeferredValueType = isDeferredValueType;
|
|
44
|
+
function deferrableValueTypesToValueTypes(valueTypes) {
|
|
45
|
+
if ((0, type_guards_1.isArray)(valueTypes)) {
|
|
46
|
+
return valueTypes.flatMap((valueType) => deferrableValueTypesToValueTypes(valueType));
|
|
47
|
+
}
|
|
48
|
+
return deferrableValueTypeToResolvedValueTypes(valueTypes);
|
|
49
|
+
}
|
|
50
|
+
exports.deferrableValueTypesToValueTypes = deferrableValueTypesToValueTypes;
|
|
51
|
+
function deferrableValueTypeToResolvedValueTypes(valueType) {
|
|
52
|
+
return isDeferredValueType(valueType)
|
|
53
|
+
? deferrableValueTypeToResolvedValueTypes(valueType.deferred())
|
|
54
|
+
: valueType;
|
|
55
|
+
}
|
|
56
|
+
exports.deferrableValueTypeToResolvedValueTypes = deferrableValueTypeToResolvedValueTypes;
|
|
57
|
+
function valueTypeToSchema(valueType) {
|
|
58
|
+
if ((0, type_guards_1.isFunction)(valueType) || (0, type_guards_1.isString)(valueType)) {
|
|
59
|
+
return valueSchema(valueType);
|
|
60
|
+
}
|
|
61
|
+
if (isDeferredValueType(valueType)) {
|
|
62
|
+
return valueTypeToSchema(valueType.deferred());
|
|
63
|
+
}
|
|
64
|
+
return valueType;
|
|
65
|
+
}
|
|
66
|
+
exports.valueTypeToSchema = valueTypeToSchema;
|
|
67
|
+
function valueTypesToSchema(valueType) {
|
|
68
|
+
if ((0, type_guards_1.isFunction)(valueType) || (0, type_guards_1.isArray)(valueType) || (0, type_guards_1.isString)(valueType)) {
|
|
69
|
+
return valueSchema(valueType);
|
|
70
|
+
}
|
|
71
|
+
if (isDeferredValueType(valueType)) {
|
|
72
|
+
return valueTypeToSchema(valueType);
|
|
73
|
+
}
|
|
74
|
+
return valueType;
|
|
75
|
+
}
|
|
76
|
+
exports.valueTypesToSchema = valueTypesToSchema;
|
|
44
77
|
//# sourceMappingURL=types.js.map
|
package/schema/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../source/schema/types.ts"],"names":[],"mappings":";;;
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-
import type {
|
|
2
|
-
import type { MaybeDeferredValueTypes, NormalizedObjectSchema, NormalizedValueSchema, ObjectSchema, ValueSchema, ValueTypes } from '../types';
|
|
1
|
+
import type { NormalizedObjectSchema, NormalizedValueSchema, ObjectSchema, ValueSchema } from '../types';
|
|
3
2
|
export declare const normalizeSchema: typeof _normalizeObjectSchema;
|
|
4
3
|
export declare const normalizeValueSchema: typeof _normalizeValueSchema;
|
|
5
4
|
export declare const getArrayItemSchema: typeof _getArrayItemSchema;
|
|
6
|
-
export declare function _normalizeObjectSchema<T>(objectSchema: ObjectSchema<T>): NormalizedObjectSchema<T>;
|
|
7
|
-
export declare function _normalizeValueSchema<T>(valueSchema: ValueSchema<T>): NormalizedValueSchema<T>;
|
|
8
|
-
declare function _getArrayItemSchema<T>(valueSchema: ValueSchema<T>): ValueSchema<T>;
|
|
9
|
-
export declare function maybeDeferredValueTypesToValueTypes<T>(valueTypes: MaybeDeferredValueTypes<T>): ValueTypes<T>;
|
|
10
|
-
export declare function valueTypesToSchema<T>(valueType: ValueTypes<T>): Schema<T>;
|
|
11
|
-
export declare function maybeDeferredValueTypesToSchema<T>(valueType: MaybeDeferredValueTypes<T>): Schema<T>;
|
|
5
|
+
export declare function _normalizeObjectSchema<T, O>(objectSchema: ObjectSchema<T, O>): NormalizedObjectSchema<T, O>;
|
|
6
|
+
export declare function _normalizeValueSchema<T, O>(valueSchema: ValueSchema<T, O>): NormalizedValueSchema<T, O>;
|
|
7
|
+
declare function _getArrayItemSchema<T, O>(valueSchema: ValueSchema<T, O>): ValueSchema<T, O>;
|
|
12
8
|
export {};
|
package/schema/utils/schema.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports._normalizeValueSchema = exports._normalizeObjectSchema = exports.getArrayItemSchema = exports.normalizeValueSchema = exports.normalizeSchema = void 0;
|
|
4
4
|
const array_1 = require("../../utils/array/array");
|
|
5
5
|
const memoize_1 = require("../../utils/function/memoize");
|
|
6
6
|
const object_1 = require("../../utils/object/object");
|
|
7
|
-
const type_guards_1 = require("../../utils/type-guards");
|
|
8
7
|
const types_1 = require("../types");
|
|
9
8
|
exports.normalizeSchema = (0, memoize_1.memoizeSingle)(_normalizeObjectSchema, { weak: true });
|
|
10
9
|
exports.normalizeValueSchema = (0, memoize_1.memoizeSingle)(_normalizeValueSchema, { weak: true });
|
|
@@ -12,17 +11,17 @@ exports.getArrayItemSchema = (0, memoize_1.memoizeSingle)(_getArrayItemSchema, {
|
|
|
12
11
|
function _normalizeObjectSchema(objectSchema) {
|
|
13
12
|
const normalizedObjectSchema = {
|
|
14
13
|
factory: objectSchema.factory,
|
|
15
|
-
properties: (0, object_1.mapObjectValues)(objectSchema.properties,
|
|
14
|
+
properties: (0, object_1.mapObjectValues)(objectSchema.properties, types_1.valueTypesToSchema),
|
|
16
15
|
mask: objectSchema.mask,
|
|
17
|
-
allowUnknownProperties: new Set((0, array_1.toArray)(objectSchema.allowUnknownProperties ?? []).map(
|
|
16
|
+
allowUnknownProperties: new Set((0, array_1.toArray)(objectSchema.allowUnknownProperties ?? []).map(types_1.valueTypesToSchema))
|
|
18
17
|
};
|
|
19
18
|
return normalizedObjectSchema;
|
|
20
19
|
}
|
|
21
20
|
exports._normalizeObjectSchema = _normalizeObjectSchema;
|
|
22
21
|
function _normalizeValueSchema(valueSchema) {
|
|
23
|
-
const valueTypes =
|
|
22
|
+
const valueTypes = (0, array_1.toArray)((0, types_1.deferrableValueTypesToValueTypes)(valueSchema.type));
|
|
24
23
|
const normalizedValueSchema = {
|
|
25
|
-
type: new Set(
|
|
24
|
+
type: new Set(valueTypes),
|
|
26
25
|
array: valueSchema.array ?? false,
|
|
27
26
|
optional: valueSchema.optional ?? false,
|
|
28
27
|
nullable: valueSchema.nullable ?? false,
|
|
@@ -54,25 +53,4 @@ function _getArrayItemSchema(valueSchema) {
|
|
|
54
53
|
};
|
|
55
54
|
return itemSchema;
|
|
56
55
|
}
|
|
57
|
-
function maybeDeferredValueTypesToValueTypes(valueTypes) {
|
|
58
|
-
if ((0, type_guards_1.isArray)(valueTypes)) {
|
|
59
|
-
return valueTypes.flatMap((valueType) => maybeDeferredValueTypesToValueTypes(valueType));
|
|
60
|
-
}
|
|
61
|
-
return (0, types_1.isDeferredValueType)(valueTypes)
|
|
62
|
-
? valueTypes.deferred()
|
|
63
|
-
: valueTypes;
|
|
64
|
-
}
|
|
65
|
-
exports.maybeDeferredValueTypesToValueTypes = maybeDeferredValueTypesToValueTypes;
|
|
66
|
-
function valueTypesToSchema(valueType) {
|
|
67
|
-
if ((0, type_guards_1.isFunction)(valueType) || (0, type_guards_1.isArray)(valueType) || (0, type_guards_1.isString)(valueType)) {
|
|
68
|
-
return { type: valueType };
|
|
69
|
-
}
|
|
70
|
-
return valueType;
|
|
71
|
-
}
|
|
72
|
-
exports.valueTypesToSchema = valueTypesToSchema;
|
|
73
|
-
function maybeDeferredValueTypesToSchema(valueType) {
|
|
74
|
-
const deferredValueTypes = maybeDeferredValueTypesToValueTypes(valueType);
|
|
75
|
-
return valueTypesToSchema(deferredValueTypes);
|
|
76
|
-
}
|
|
77
|
-
exports.maybeDeferredValueTypesToSchema = maybeDeferredValueTypesToSchema;
|
|
78
56
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../source/schema/utils/schema.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAC9C,0DAAyD;AACzD,sDAAwD;
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../source/schema/utils/schema.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAC9C,0DAAyD;AACzD,sDAAwD;AAExD,oCAAgF;AAEnE,QAAA,eAAe,GAAG,IAAA,uBAAa,EAAC,sBAAsB,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AACxE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A,eAAO,EAAC,WAAW,CAAC,gBAAgB,IAAI,EAAE,CAAC;KAC9D,CAAC;IAEF,KAAK,MAAM,OAAO,IAAI,IAAA,eAAO,EAAC,WAAW,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE;QACzD,KAAK,MAAM,UAAU,IAAI,IAAA,eAAO,EAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YACpD,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;gBACnD,qBAAqB,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;aACpD;YAED,qBAAqB,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC/D;KACF;IAED,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AA1BD,sDA0BC;AAED,SAAS,mBAAmB,CAAO,WAA8B;IAC/D,MAAM,UAAU,GAAsB;QACpC,IAAI,EAAE,WAAW,CAAC,IAAI;QACtB,KAAK,EAAE,KAAK;QACZ,QAAQ,EAAE,KAAK;QACf,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,WAAW,CAAC,YAAY;QACtC,gBAAgB,EAAE,WAAW,CAAC,gBAAgB;KAC/C,CAAC;IAEF,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ValueType } from '../types';
|
|
2
|
-
export declare function getValueType(value: unknown):
|
|
1
|
+
import type { ResolvedValueType, ValueType } from '../types';
|
|
2
|
+
export declare function getValueType(value: unknown): ResolvedValueType;
|
|
3
3
|
export declare function getValueTypeName(valueType: ValueType): string;
|
|
4
|
-
export declare function valueTypeHasValueType(valueType: ValueType, typeToCheck: ValueType): boolean;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getValueTypeName = exports.getValueType = void 0;
|
|
4
4
|
const type_guards_1 = require("../../utils/type-guards");
|
|
5
|
-
const types_1 = require("../types");
|
|
6
|
-
const schema_1 = require("./schema");
|
|
7
5
|
function getValueType(value) {
|
|
8
6
|
if ((0, type_guards_1.isUndefined)(value)) {
|
|
9
7
|
return 'undefined';
|
|
@@ -18,18 +16,4 @@ function getValueTypeName(valueType) {
|
|
|
18
16
|
return (0, type_guards_1.isString)(valueType) ? valueType : (0, type_guards_1.isFunction)(valueType) ? valueType.name : 'object';
|
|
19
17
|
}
|
|
20
18
|
exports.getValueTypeName = getValueTypeName;
|
|
21
|
-
function valueTypeHasValueType(valueType, typeToCheck) {
|
|
22
|
-
if ((0, types_1.isValueSchema)(valueType)) {
|
|
23
|
-
const resolvedValueTypes = (0, schema_1.maybeDeferredValueTypesToValueTypes)(valueType.type);
|
|
24
|
-
if ((0, type_guards_1.isArray)(resolvedValueTypes)) {
|
|
25
|
-
return resolvedValueTypes.some((innerType) => valueTypeHasValueType(innerType, typeToCheck));
|
|
26
|
-
}
|
|
27
|
-
return valueTypeHasValueType(resolvedValueTypes, typeToCheck);
|
|
28
|
-
}
|
|
29
|
-
if ((0, types_1.isObjectSchema)(valueType)) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
return valueType == typeToCheck;
|
|
33
|
-
}
|
|
34
|
-
exports.valueTypeHasValueType = valueTypeHasValueType;
|
|
35
19
|
//# sourceMappingURL=value-type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value-type.js","sourceRoot":"","sources":["../../../source/schema/utils/value-type.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"value-type.js","sourceRoot":"","sources":["../../../source/schema/utils/value-type.ts"],"names":[],"mappings":";;;AACA,yDAAgF;AAGhF,SAAgB,YAAY,CAAC,KAAc;IACzC,IAAI,IAAA,yBAAW,EAAC,KAAK,CAAC,EAAE;QACtB,OAAO,WAAW,CAAC;KACpB;IAED,IAAI,IAAA,oBAAM,EAAC,KAAK,CAAC,EAAE;QACjB,OAAO,MAAM,CAAC;KACf;IAED,OAAQ,KAAgB,CAAC,WAAmB,CAAC;AAC/C,CAAC;AAVD,oCAUC;AAED,SAAgB,gBAAgB,CAAC,SAAoB;IACnD,OAAO,IAAA,sBAAQ,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,wBAAU,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC7F,CAAC;AAFD,4CAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-template.provider.js","sourceRoot":"","sources":["../../../source/templates/providers/file-template.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,+CAAwE;AAExE,yCAA6D;AAI7D,+EAAyE;AAe5D,QAAA,0BAA0B,GAA+B,EAAE,CAAC;AAEzE,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"file-template.provider.js","sourceRoot":"","sources":["../../../source/templates/providers/file-template.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,+CAAwE;AAExE,yCAA6D;AAI7D,+EAAyE;AAe5D,QAAA,0BAA0B,GAA+B,EAAE,CAAC;AAEzE,MAAM,kBAAkB,GAAG,IAAA,eAAM,EAAe;IAC9C,IAAI,EAAE,IAAA,eAAM,GAAE;IACd,QAAQ,EAAE,IAAA,iBAAQ,EAAC,IAAA,eAAM,GAAE,CAAC;IAC5B,YAAY,EAAE,IAAA,iBAAQ,EAAC,IAAA,eAAM,GAAE,CAAC;IAChC,OAAO,EAAE,IAAA,iBAAQ,EAAC,IAAA,gBAAO,GAAE,CAAC;CAC7B,CAAC,CAAC;AAKH,IAAa,oBAAoB,GAAjC,MAAa,oBAAqB,SAAQ,sDAAgD;IAGxF,YAAyB,QAAgB;QACvC,KAAK,CAAC,kBAAkB,EAAE,QAAQ,EAAE,CAAC,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACtE,CAAC;CACF,CAAA;AANY,oBAAoB;IAHhC,IAAA,qBAAS,EAAC;QACT,uBAAuB,EAAE,GAAG,EAAE,CAAC,kCAA0B,CAAC,QAAQ;KACnE,CAAC;IAIa,WAAA,IAAA,qBAAS,GAAE,CAAA;;GAHb,oBAAoB,CAMhC;AANY,oDAAoB;AAQjC,SAAgB,6BAA6B,CAAC,SAA8C,EAAE;IAC5F,kCAA0B,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,kCAA0B,CAAC,QAAQ,CAAC;AAC/F,CAAC;AAFD,sEAEC;AAED,SAAgB,YAAY,CAAyB,QAAW;IAC9D,OAAO,QAAQ,CAAC;AAClB,CAAC;AAFD,oCAEC"}
|
package/types.d.ts
CHANGED
|
@@ -143,3 +143,36 @@ export declare type DeepPartialObject<T> = {
|
|
|
143
143
|
export declare type DeepPartialArray<T> = DeepPartial<T>[];
|
|
144
144
|
export declare type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
|
145
145
|
export declare type BinaryData = ArrayBuffer | ArrayBufferView;
|
|
146
|
+
declare type JoinPaths<K, P> = K extends string | number ? P extends string | number ? `${K}${'' extends P ? '' : '.'}${P}` : never : never;
|
|
147
|
+
declare type Prev = [
|
|
148
|
+
never,
|
|
149
|
+
0,
|
|
150
|
+
1,
|
|
151
|
+
2,
|
|
152
|
+
3,
|
|
153
|
+
4,
|
|
154
|
+
5,
|
|
155
|
+
6,
|
|
156
|
+
7,
|
|
157
|
+
8,
|
|
158
|
+
9,
|
|
159
|
+
10,
|
|
160
|
+
11,
|
|
161
|
+
12,
|
|
162
|
+
13,
|
|
163
|
+
14,
|
|
164
|
+
15,
|
|
165
|
+
16,
|
|
166
|
+
17,
|
|
167
|
+
18,
|
|
168
|
+
19,
|
|
169
|
+
20,
|
|
170
|
+
...0[]
|
|
171
|
+
];
|
|
172
|
+
export declare type Paths<T, D extends number = 10> = [D] extends [never] ? never : T extends object ? {
|
|
173
|
+
[K in keyof T]-?: K extends string | number ? `${K}` | (Paths<T[K], Prev[D]> extends infer R ? JoinPaths<K, R> : never) : never;
|
|
174
|
+
}[keyof T] : '';
|
|
175
|
+
export declare type LeavePaths<T, D extends number = 10> = [D] extends [never] ? never : T extends object ? {
|
|
176
|
+
[K in keyof T]-?: JoinPaths<K, LeavePaths<T[K], Prev[D]>>;
|
|
177
|
+
}[keyof T] : '';
|
|
178
|
+
export {};
|