@atscript/typescript 0.0.15 → 0.0.17
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/cli.cjs +14 -26
- package/dist/index.cjs +28 -14
- package/dist/index.d.ts +10 -8
- package/dist/index.mjs +28 -14
- package/package.json +4 -4
package/dist/cli.cjs
CHANGED
|
@@ -22,8 +22,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
|
|
24
24
|
//#endregion
|
|
25
|
-
const moost = __toESM(require("moost"));
|
|
26
25
|
const __moostjs_event_cli = __toESM(require("@moostjs/event-cli"));
|
|
26
|
+
const moost = __toESM(require("moost"));
|
|
27
27
|
const path = __toESM(require("path"));
|
|
28
28
|
const __atscript_core = __toESM(require("@atscript/core"));
|
|
29
29
|
const fs = __toESM(require("fs"));
|
|
@@ -204,7 +204,7 @@ function wrapProp(name) {
|
|
|
204
204
|
return name;
|
|
205
205
|
}
|
|
206
206
|
function escapeQuotes(str) {
|
|
207
|
-
return str.replace(/"/g, "\\\"");
|
|
207
|
+
return str.replace(/"/g, "\\\"").replace(/\\/g, "\\\\");
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
//#endregion
|
|
@@ -219,7 +219,7 @@ var TypeRenderer = class extends BaseRenderer {
|
|
|
219
219
|
this.writeln(" * Do not edit this file!");
|
|
220
220
|
this.writeln(" */");
|
|
221
221
|
this.writeln();
|
|
222
|
-
this.writeln("import type { TAtscriptTypeObject, TAtscriptTypeComplex, TAtscriptTypeFinal, TAtscriptTypeArray, TMetadataMap, Validator } from \"@atscript/typescript\"");
|
|
222
|
+
this.writeln("import type { TAtscriptTypeObject, TAtscriptTypeComplex, TAtscriptTypeFinal, TAtscriptTypeArray, TMetadataMap, Validator, TAtscriptAnnotatedTypeConstructor, TValidatorOptions } from \"@atscript/typescript\"");
|
|
223
223
|
}
|
|
224
224
|
post() {
|
|
225
225
|
this.writeln("// prettier-ignore-end");
|
|
@@ -278,10 +278,10 @@ var TypeRenderer = class extends BaseRenderer {
|
|
|
278
278
|
this.writeln();
|
|
279
279
|
}
|
|
280
280
|
if (asClass) {
|
|
281
|
-
this.writeln("static
|
|
281
|
+
this.writeln("static __is_atscript_annotated_type: true");
|
|
282
282
|
this.writeln(`static type: TAtscriptTypeObject<keyof ${asClass}>`);
|
|
283
283
|
this.writeln(`static metadata: TMetadataMap<AtscriptMetadata>`);
|
|
284
|
-
this.writeln(`static validator: () => Validator
|
|
284
|
+
this.writeln(`static validator: <TT extends TAtscriptAnnotatedTypeConstructor = ${asClass}>(opts?: TValidatorOptions) => Validator<TT>`);
|
|
285
285
|
}
|
|
286
286
|
this.pop();
|
|
287
287
|
}
|
|
@@ -315,15 +315,15 @@ else this.writeln("{}");
|
|
|
315
315
|
let realDef = def;
|
|
316
316
|
if ((0, __atscript_core.isRef)(def)) realDef = this.doc.unwindType(def.id, def.chain)?.def || realDef;
|
|
317
317
|
realDef = this.doc.mergeIntersection(realDef);
|
|
318
|
-
if ((0, __atscript_core.isStructure)(realDef) || (0, __atscript_core.isInterface)(realDef)) typeDef = `TAtscriptTypeObject<keyof ${node.id}
|
|
318
|
+
if ((0, __atscript_core.isStructure)(realDef) || (0, __atscript_core.isInterface)(realDef)) typeDef = `TAtscriptTypeObject<keyof ${node.id}>`;
|
|
319
319
|
else if ((0, __atscript_core.isGroup)(realDef)) typeDef = "TAtscriptTypeComplex";
|
|
320
320
|
else if ((0, __atscript_core.isArray)(realDef)) typeDef = "TAtscriptTypeArray";
|
|
321
321
|
else if ((0, __atscript_core.isPrimitive)(realDef)) typeDef = "TAtscriptTypeFinal";
|
|
322
322
|
}
|
|
323
|
-
this.writeln(`const
|
|
323
|
+
this.writeln(`const __is_atscript_annotated_type: true`);
|
|
324
324
|
this.writeln(`const type: ${typeDef}`);
|
|
325
325
|
this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
|
|
326
|
-
this.writeln(`
|
|
326
|
+
this.writeln(`static validator: <TT extends TAtscriptAnnotatedTypeConstructor = ${node.id}>(opts?: TValidatorOptions) => Validator<TT>`);
|
|
327
327
|
this.popln();
|
|
328
328
|
}
|
|
329
329
|
renderJsDoc(node) {
|
|
@@ -382,7 +382,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
382
382
|
this.write(exported ? "export " : "");
|
|
383
383
|
this.write(`class ${node.id} `);
|
|
384
384
|
this.blockln("{}");
|
|
385
|
-
this.writeln("static
|
|
385
|
+
this.writeln("static __is_atscript_annotated_type = true");
|
|
386
386
|
this.writeln("static type = {}");
|
|
387
387
|
this.writeln("static metadata = new Map()");
|
|
388
388
|
this.popln();
|
|
@@ -395,7 +395,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
395
395
|
this.write(exported ? "export " : "");
|
|
396
396
|
this.write(`class ${node.id} `);
|
|
397
397
|
this.blockln("{}");
|
|
398
|
-
this.writeln("static
|
|
398
|
+
this.writeln("static __is_atscript_annotated_type = true");
|
|
399
399
|
this.writeln("static type = {}");
|
|
400
400
|
this.writeln("static metadata = new Map()");
|
|
401
401
|
this.popln();
|
|
@@ -706,21 +706,9 @@ Commands = _ts_decorate([
|
|
|
706
706
|
|
|
707
707
|
//#endregion
|
|
708
708
|
//#region packages/typescript/src/cli/cli.ts
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
globalCliOptions: [{
|
|
714
|
-
keys: ["help"],
|
|
715
|
-
description: "Display instructions for the command."
|
|
716
|
-
}]
|
|
717
|
-
});
|
|
718
|
-
app.adapter(cli);
|
|
719
|
-
app.registerControllers(Commands);
|
|
720
|
-
app.applyGlobalInterceptors((0, __moostjs_event_cli.cliHelpInterceptor)({
|
|
721
|
-
colors: true,
|
|
722
|
-
lookupLevel: 3
|
|
723
|
-
}));
|
|
724
|
-
app.init();
|
|
709
|
+
new __moostjs_event_cli.CliApp().controllers(Commands).useHelp({ name: "asc" }).useOptions([{
|
|
710
|
+
keys: ["help"],
|
|
711
|
+
description: "Display instructions for the command."
|
|
712
|
+
}]).start();
|
|
725
713
|
|
|
726
714
|
//#endregion
|
package/dist/index.cjs
CHANGED
|
@@ -202,7 +202,7 @@ function wrapProp(name) {
|
|
|
202
202
|
return name;
|
|
203
203
|
}
|
|
204
204
|
function escapeQuotes(str) {
|
|
205
|
-
return str.replace(/"/g, "\\\"");
|
|
205
|
+
return str.replace(/"/g, "\\\"").replace(/\\/g, "\\\\");
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
//#endregion
|
|
@@ -217,7 +217,7 @@ var TypeRenderer = class extends BaseRenderer {
|
|
|
217
217
|
this.writeln(" * Do not edit this file!");
|
|
218
218
|
this.writeln(" */");
|
|
219
219
|
this.writeln();
|
|
220
|
-
this.writeln("import type { TAtscriptTypeObject, TAtscriptTypeComplex, TAtscriptTypeFinal, TAtscriptTypeArray, TMetadataMap, Validator } from \"@atscript/typescript\"");
|
|
220
|
+
this.writeln("import type { TAtscriptTypeObject, TAtscriptTypeComplex, TAtscriptTypeFinal, TAtscriptTypeArray, TMetadataMap, Validator, TAtscriptAnnotatedTypeConstructor, TValidatorOptions } from \"@atscript/typescript\"");
|
|
221
221
|
}
|
|
222
222
|
post() {
|
|
223
223
|
this.writeln("// prettier-ignore-end");
|
|
@@ -276,10 +276,10 @@ var TypeRenderer = class extends BaseRenderer {
|
|
|
276
276
|
this.writeln();
|
|
277
277
|
}
|
|
278
278
|
if (asClass) {
|
|
279
|
-
this.writeln("static
|
|
279
|
+
this.writeln("static __is_atscript_annotated_type: true");
|
|
280
280
|
this.writeln(`static type: TAtscriptTypeObject<keyof ${asClass}>`);
|
|
281
281
|
this.writeln(`static metadata: TMetadataMap<AtscriptMetadata>`);
|
|
282
|
-
this.writeln(`static validator: () => Validator
|
|
282
|
+
this.writeln(`static validator: <TT extends TAtscriptAnnotatedTypeConstructor = ${asClass}>(opts?: TValidatorOptions) => Validator<TT>`);
|
|
283
283
|
}
|
|
284
284
|
this.pop();
|
|
285
285
|
}
|
|
@@ -313,15 +313,15 @@ else this.writeln("{}");
|
|
|
313
313
|
let realDef = def;
|
|
314
314
|
if ((0, __atscript_core.isRef)(def)) realDef = this.doc.unwindType(def.id, def.chain)?.def || realDef;
|
|
315
315
|
realDef = this.doc.mergeIntersection(realDef);
|
|
316
|
-
if ((0, __atscript_core.isStructure)(realDef) || (0, __atscript_core.isInterface)(realDef)) typeDef = `TAtscriptTypeObject<keyof ${node.id}
|
|
316
|
+
if ((0, __atscript_core.isStructure)(realDef) || (0, __atscript_core.isInterface)(realDef)) typeDef = `TAtscriptTypeObject<keyof ${node.id}>`;
|
|
317
317
|
else if ((0, __atscript_core.isGroup)(realDef)) typeDef = "TAtscriptTypeComplex";
|
|
318
318
|
else if ((0, __atscript_core.isArray)(realDef)) typeDef = "TAtscriptTypeArray";
|
|
319
319
|
else if ((0, __atscript_core.isPrimitive)(realDef)) typeDef = "TAtscriptTypeFinal";
|
|
320
320
|
}
|
|
321
|
-
this.writeln(`const
|
|
321
|
+
this.writeln(`const __is_atscript_annotated_type: true`);
|
|
322
322
|
this.writeln(`const type: ${typeDef}`);
|
|
323
323
|
this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
|
|
324
|
-
this.writeln(`
|
|
324
|
+
this.writeln(`static validator: <TT extends TAtscriptAnnotatedTypeConstructor = ${node.id}>(opts?: TValidatorOptions) => Validator<TT>`);
|
|
325
325
|
this.popln();
|
|
326
326
|
}
|
|
327
327
|
renderJsDoc(node) {
|
|
@@ -380,7 +380,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
380
380
|
this.write(exported ? "export " : "");
|
|
381
381
|
this.write(`class ${node.id} `);
|
|
382
382
|
this.blockln("{}");
|
|
383
|
-
this.writeln("static
|
|
383
|
+
this.writeln("static __is_atscript_annotated_type = true");
|
|
384
384
|
this.writeln("static type = {}");
|
|
385
385
|
this.writeln("static metadata = new Map()");
|
|
386
386
|
this.popln();
|
|
@@ -393,7 +393,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
393
393
|
this.write(exported ? "export " : "");
|
|
394
394
|
this.write(`class ${node.id} `);
|
|
395
395
|
this.blockln("{}");
|
|
396
|
-
this.writeln("static
|
|
396
|
+
this.writeln("static __is_atscript_annotated_type = true");
|
|
397
397
|
this.writeln("static type = {}");
|
|
398
398
|
this.writeln("static metadata = new Map()");
|
|
399
399
|
this.popln();
|
|
@@ -763,10 +763,24 @@ var Validator = class {
|
|
|
763
763
|
let passed = true;
|
|
764
764
|
const valueKeys = new Set(Object.keys(value));
|
|
765
765
|
const typeKeys = new Set();
|
|
766
|
+
const skipList = new Set();
|
|
767
|
+
if (this.opts.skipList) {
|
|
768
|
+
const path$2 = this.stackPath.length > 1 ? this.stackPath.slice(1).join(".") + "." : "";
|
|
769
|
+
this.opts.skipList.forEach((item) => {
|
|
770
|
+
if (item.startsWith(path$2)) {
|
|
771
|
+
const key = item.slice(path$2.length);
|
|
772
|
+
skipList.add(key);
|
|
773
|
+
valueKeys.delete(key);
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
let partialFunctionMatched = false;
|
|
778
|
+
if (typeof this.opts.partial === "function") partialFunctionMatched = this.opts.partial(def, this.stackPath.join(".").slice(1));
|
|
766
779
|
for (const [key, item] of def.type.props.entries()) {
|
|
780
|
+
if (skipList.has(key)) continue;
|
|
767
781
|
typeKeys.add(key);
|
|
768
782
|
if (value[key] === undefined) {
|
|
769
|
-
if (this.opts.partial === "deep" || this.opts.partial === true && this.stackPath.length <= 1) continue;
|
|
783
|
+
if (partialFunctionMatched || this.opts.partial === "deep" || this.opts.partial === true && this.stackPath.length <= 1) continue;
|
|
770
784
|
}
|
|
771
785
|
this.push(key);
|
|
772
786
|
if (this._validate(item, value[key])) this.pop(false);
|
|
@@ -908,7 +922,7 @@ var ValidatorError = class extends Error {
|
|
|
908
922
|
//#endregion
|
|
909
923
|
//#region packages/typescript/src/annotated-type.ts
|
|
910
924
|
function isAnnotatedType(type) {
|
|
911
|
-
return type && type.
|
|
925
|
+
return type && type.__is_atscript_annotated_type;
|
|
912
926
|
}
|
|
913
927
|
function defineAnnotatedType(_kind, base) {
|
|
914
928
|
const kind = _kind || "";
|
|
@@ -923,7 +937,7 @@ function defineAnnotatedType(_kind, base) {
|
|
|
923
937
|
type.tags = new Set();
|
|
924
938
|
const metadata = base?.metadata || new Map();
|
|
925
939
|
if (base) Object.assign(base, {
|
|
926
|
-
|
|
940
|
+
__is_atscript_annotated_type: true,
|
|
927
941
|
metadata,
|
|
928
942
|
type,
|
|
929
943
|
validator(opts) {
|
|
@@ -931,7 +945,7 @@ function defineAnnotatedType(_kind, base) {
|
|
|
931
945
|
}
|
|
932
946
|
});
|
|
933
947
|
else base = {
|
|
934
|
-
|
|
948
|
+
__is_atscript_annotated_type: true,
|
|
935
949
|
metadata,
|
|
936
950
|
type,
|
|
937
951
|
validator(opts) {
|
|
@@ -984,7 +998,7 @@ else throw new Error(`Can't find prop ${typeName}${keys}`);
|
|
|
984
998
|
if (!newBase && keys) throw new Error(`Can't find prop ${typeName}${keys}`);
|
|
985
999
|
else if (!newBase) throw new Error(`"${typeName}" is not annotated type`);
|
|
986
1000
|
this.$type = {
|
|
987
|
-
|
|
1001
|
+
__is_atscript_annotated_type: true,
|
|
988
1002
|
type: newBase.type,
|
|
989
1003
|
metadata,
|
|
990
1004
|
validator(opts) {
|
package/dist/index.d.ts
CHANGED
|
@@ -8,14 +8,15 @@ interface TError {
|
|
|
8
8
|
details?: TError[];
|
|
9
9
|
}
|
|
10
10
|
interface TValidatorOptions {
|
|
11
|
-
partial: boolean | 'deep';
|
|
11
|
+
partial: boolean | 'deep' | ((type: TAtscriptAnnotatedType<TAtscriptTypeObject>, path: string) => boolean);
|
|
12
12
|
unknwonProps: 'strip' | 'ignore' | 'error';
|
|
13
13
|
errorLimit: number;
|
|
14
|
+
skipList?: Set<string>;
|
|
14
15
|
}
|
|
15
|
-
declare class Validator {
|
|
16
|
-
protected readonly def:
|
|
16
|
+
declare class Validator<T extends TAtscriptAnnotatedTypeConstructor> {
|
|
17
|
+
protected readonly def: T;
|
|
17
18
|
protected opts: TValidatorOptions;
|
|
18
|
-
constructor(def:
|
|
19
|
+
constructor(def: T, opts?: Partial<TValidatorOptions>);
|
|
19
20
|
errors: TError[];
|
|
20
21
|
protected stackErrors: TError[][];
|
|
21
22
|
protected stackPath: string[];
|
|
@@ -25,7 +26,7 @@ declare class Validator {
|
|
|
25
26
|
protected clear(): void;
|
|
26
27
|
protected error(message: string, path?: string, details?: TError[]): void;
|
|
27
28
|
protected throw(): void;
|
|
28
|
-
validate(value: any, safe?: boolean):
|
|
29
|
+
validate<TT = T>(value: any, safe?: boolean): value is TT;
|
|
29
30
|
protected _validate(def: TAtscriptAnnotatedType, value: any): boolean;
|
|
30
31
|
protected validateUnion(def: TAtscriptAnnotatedType<TAtscriptTypeComplex>, value: any): boolean;
|
|
31
32
|
protected validateIntersection(def: TAtscriptAnnotatedType<TAtscriptTypeComplex>, value: any): boolean;
|
|
@@ -65,12 +66,13 @@ interface TAtscriptTypeFinal {
|
|
|
65
66
|
}
|
|
66
67
|
type TAtscriptTypeDef = TAtscriptTypeComplex | TAtscriptTypeFinal | TAtscriptTypeArray | TAtscriptTypeObject<string>;
|
|
67
68
|
interface TAtscriptAnnotatedType<T = TAtscriptTypeDef> {
|
|
68
|
-
|
|
69
|
+
__is_atscript_annotated_type: true;
|
|
69
70
|
type: T;
|
|
70
|
-
validator: (opts?: TValidatorOptions) => Validator
|
|
71
|
+
validator: <TT extends TAtscriptAnnotatedTypeConstructor>(opts?: Partial<TValidatorOptions>) => Validator<TT>;
|
|
71
72
|
metadata: TMetadataMap<AtscriptMetadata>;
|
|
72
73
|
optional?: boolean;
|
|
73
74
|
}
|
|
75
|
+
type TAtscriptAnnotatedTypeConstructor = TAtscriptAnnotatedType & (new (...args: any[]) => any);
|
|
74
76
|
declare function isAnnotatedType(type: any): type is TAtscriptAnnotatedType;
|
|
75
77
|
type TKind = '' | 'array' | 'object' | 'union' | 'intersection' | 'tuple';
|
|
76
78
|
declare function defineAnnotatedType(_kind?: TKind, base?: any): {
|
|
@@ -95,4 +97,4 @@ interface TMetadataMap<O extends object> extends Map<keyof O, O[keyof O]> {
|
|
|
95
97
|
set<K extends keyof O>(key: K, value: O[K]): this;
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
export { type TAtscriptAnnotatedType, type TAtscriptTypeArray, type TAtscriptTypeComplex, type TAtscriptTypeDef, type TAtscriptTypeFinal, type TAtscriptTypeObject, type TMetadataMap, type TValidatorOptions, Validator, ValidatorError, tsPlugin as default, defineAnnotatedType, isAnnotatedType };
|
|
100
|
+
export { type TAtscriptAnnotatedType, type TAtscriptAnnotatedTypeConstructor, type TAtscriptTypeArray, type TAtscriptTypeComplex, type TAtscriptTypeDef, type TAtscriptTypeFinal, type TAtscriptTypeObject, type TMetadataMap, type TValidatorOptions, Validator, ValidatorError, tsPlugin as default, defineAnnotatedType, isAnnotatedType };
|
package/dist/index.mjs
CHANGED
|
@@ -177,7 +177,7 @@ function wrapProp(name) {
|
|
|
177
177
|
return name;
|
|
178
178
|
}
|
|
179
179
|
function escapeQuotes(str) {
|
|
180
|
-
return str.replace(/"/g, "\\\"");
|
|
180
|
+
return str.replace(/"/g, "\\\"").replace(/\\/g, "\\\\");
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
//#endregion
|
|
@@ -192,7 +192,7 @@ var TypeRenderer = class extends BaseRenderer {
|
|
|
192
192
|
this.writeln(" * Do not edit this file!");
|
|
193
193
|
this.writeln(" */");
|
|
194
194
|
this.writeln();
|
|
195
|
-
this.writeln("import type { TAtscriptTypeObject, TAtscriptTypeComplex, TAtscriptTypeFinal, TAtscriptTypeArray, TMetadataMap, Validator } from \"@atscript/typescript\"");
|
|
195
|
+
this.writeln("import type { TAtscriptTypeObject, TAtscriptTypeComplex, TAtscriptTypeFinal, TAtscriptTypeArray, TMetadataMap, Validator, TAtscriptAnnotatedTypeConstructor, TValidatorOptions } from \"@atscript/typescript\"");
|
|
196
196
|
}
|
|
197
197
|
post() {
|
|
198
198
|
this.writeln("// prettier-ignore-end");
|
|
@@ -251,10 +251,10 @@ var TypeRenderer = class extends BaseRenderer {
|
|
|
251
251
|
this.writeln();
|
|
252
252
|
}
|
|
253
253
|
if (asClass) {
|
|
254
|
-
this.writeln("static
|
|
254
|
+
this.writeln("static __is_atscript_annotated_type: true");
|
|
255
255
|
this.writeln(`static type: TAtscriptTypeObject<keyof ${asClass}>`);
|
|
256
256
|
this.writeln(`static metadata: TMetadataMap<AtscriptMetadata>`);
|
|
257
|
-
this.writeln(`static validator: () => Validator
|
|
257
|
+
this.writeln(`static validator: <TT extends TAtscriptAnnotatedTypeConstructor = ${asClass}>(opts?: TValidatorOptions) => Validator<TT>`);
|
|
258
258
|
}
|
|
259
259
|
this.pop();
|
|
260
260
|
}
|
|
@@ -288,15 +288,15 @@ else this.writeln("{}");
|
|
|
288
288
|
let realDef = def;
|
|
289
289
|
if (isRef(def)) realDef = this.doc.unwindType(def.id, def.chain)?.def || realDef;
|
|
290
290
|
realDef = this.doc.mergeIntersection(realDef);
|
|
291
|
-
if (isStructure(realDef) || isInterface(realDef)) typeDef = `TAtscriptTypeObject<keyof ${node.id}
|
|
291
|
+
if (isStructure(realDef) || isInterface(realDef)) typeDef = `TAtscriptTypeObject<keyof ${node.id}>`;
|
|
292
292
|
else if (isGroup(realDef)) typeDef = "TAtscriptTypeComplex";
|
|
293
293
|
else if (isArray(realDef)) typeDef = "TAtscriptTypeArray";
|
|
294
294
|
else if (isPrimitive(realDef)) typeDef = "TAtscriptTypeFinal";
|
|
295
295
|
}
|
|
296
|
-
this.writeln(`const
|
|
296
|
+
this.writeln(`const __is_atscript_annotated_type: true`);
|
|
297
297
|
this.writeln(`const type: ${typeDef}`);
|
|
298
298
|
this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
|
|
299
|
-
this.writeln(`
|
|
299
|
+
this.writeln(`static validator: <TT extends TAtscriptAnnotatedTypeConstructor = ${node.id}>(opts?: TValidatorOptions) => Validator<TT>`);
|
|
300
300
|
this.popln();
|
|
301
301
|
}
|
|
302
302
|
renderJsDoc(node) {
|
|
@@ -355,7 +355,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
355
355
|
this.write(exported ? "export " : "");
|
|
356
356
|
this.write(`class ${node.id} `);
|
|
357
357
|
this.blockln("{}");
|
|
358
|
-
this.writeln("static
|
|
358
|
+
this.writeln("static __is_atscript_annotated_type = true");
|
|
359
359
|
this.writeln("static type = {}");
|
|
360
360
|
this.writeln("static metadata = new Map()");
|
|
361
361
|
this.popln();
|
|
@@ -368,7 +368,7 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
368
368
|
this.write(exported ? "export " : "");
|
|
369
369
|
this.write(`class ${node.id} `);
|
|
370
370
|
this.blockln("{}");
|
|
371
|
-
this.writeln("static
|
|
371
|
+
this.writeln("static __is_atscript_annotated_type = true");
|
|
372
372
|
this.writeln("static type = {}");
|
|
373
373
|
this.writeln("static metadata = new Map()");
|
|
374
374
|
this.popln();
|
|
@@ -738,10 +738,24 @@ var Validator = class {
|
|
|
738
738
|
let passed = true;
|
|
739
739
|
const valueKeys = new Set(Object.keys(value));
|
|
740
740
|
const typeKeys = new Set();
|
|
741
|
+
const skipList = new Set();
|
|
742
|
+
if (this.opts.skipList) {
|
|
743
|
+
const path$1 = this.stackPath.length > 1 ? this.stackPath.slice(1).join(".") + "." : "";
|
|
744
|
+
this.opts.skipList.forEach((item) => {
|
|
745
|
+
if (item.startsWith(path$1)) {
|
|
746
|
+
const key = item.slice(path$1.length);
|
|
747
|
+
skipList.add(key);
|
|
748
|
+
valueKeys.delete(key);
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
let partialFunctionMatched = false;
|
|
753
|
+
if (typeof this.opts.partial === "function") partialFunctionMatched = this.opts.partial(def, this.stackPath.join(".").slice(1));
|
|
741
754
|
for (const [key, item] of def.type.props.entries()) {
|
|
755
|
+
if (skipList.has(key)) continue;
|
|
742
756
|
typeKeys.add(key);
|
|
743
757
|
if (value[key] === undefined) {
|
|
744
|
-
if (this.opts.partial === "deep" || this.opts.partial === true && this.stackPath.length <= 1) continue;
|
|
758
|
+
if (partialFunctionMatched || this.opts.partial === "deep" || this.opts.partial === true && this.stackPath.length <= 1) continue;
|
|
745
759
|
}
|
|
746
760
|
this.push(key);
|
|
747
761
|
if (this._validate(item, value[key])) this.pop(false);
|
|
@@ -883,7 +897,7 @@ var ValidatorError = class extends Error {
|
|
|
883
897
|
//#endregion
|
|
884
898
|
//#region packages/typescript/src/annotated-type.ts
|
|
885
899
|
function isAnnotatedType(type) {
|
|
886
|
-
return type && type.
|
|
900
|
+
return type && type.__is_atscript_annotated_type;
|
|
887
901
|
}
|
|
888
902
|
function defineAnnotatedType(_kind, base) {
|
|
889
903
|
const kind = _kind || "";
|
|
@@ -898,7 +912,7 @@ function defineAnnotatedType(_kind, base) {
|
|
|
898
912
|
type.tags = new Set();
|
|
899
913
|
const metadata = base?.metadata || new Map();
|
|
900
914
|
if (base) Object.assign(base, {
|
|
901
|
-
|
|
915
|
+
__is_atscript_annotated_type: true,
|
|
902
916
|
metadata,
|
|
903
917
|
type,
|
|
904
918
|
validator(opts) {
|
|
@@ -906,7 +920,7 @@ function defineAnnotatedType(_kind, base) {
|
|
|
906
920
|
}
|
|
907
921
|
});
|
|
908
922
|
else base = {
|
|
909
|
-
|
|
923
|
+
__is_atscript_annotated_type: true,
|
|
910
924
|
metadata,
|
|
911
925
|
type,
|
|
912
926
|
validator(opts) {
|
|
@@ -959,7 +973,7 @@ else throw new Error(`Can't find prop ${typeName}${keys}`);
|
|
|
959
973
|
if (!newBase && keys) throw new Error(`Can't find prop ${typeName}${keys}`);
|
|
960
974
|
else if (!newBase) throw new Error(`"${typeName}" is not annotated type`);
|
|
961
975
|
this.$type = {
|
|
962
|
-
|
|
976
|
+
__is_atscript_annotated_type: true,
|
|
963
977
|
type: newBase.type,
|
|
964
978
|
metadata,
|
|
965
979
|
validator(opts) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "Atscript: typescript-gen support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"homepage": "https://github.com/moostjs/atscript/tree/main/packages/typescript#readme",
|
|
48
48
|
"license": "ISC",
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@moostjs/event-cli": "^0.5.
|
|
51
|
-
"moost": "^0.5.
|
|
52
|
-
"@atscript/core": "^0.0.
|
|
50
|
+
"@moostjs/event-cli": "^0.5.26",
|
|
51
|
+
"moost": "^0.5.26",
|
|
52
|
+
"@atscript/core": "^0.0.17"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"vitest": "^3.0.0"
|