@atscript/typescript 0.0.1 → 0.0.16
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 +8 -20
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +7 -6
- package/dist/index.mjs +3 -3
- 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"));
|
|
@@ -281,7 +281,7 @@ var TypeRenderer = class extends BaseRenderer {
|
|
|
281
281
|
this.writeln("static __is_anscript_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: () => Validator<${asClass}>`);
|
|
285
285
|
}
|
|
286
286
|
this.pop();
|
|
287
287
|
}
|
|
@@ -315,7 +315,7 @@ 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";
|
|
@@ -323,7 +323,7 @@ else if ((0, __atscript_core.isPrimitive)(realDef)) typeDef = "TAtscriptTypeFina
|
|
|
323
323
|
this.writeln(`const __is_anscript_annotated_type: true`);
|
|
324
324
|
this.writeln(`const type: ${typeDef}`);
|
|
325
325
|
this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
|
|
326
|
-
this.writeln(`const validator: () => Validator
|
|
326
|
+
this.writeln(`const validator: () => Validator<${node.id}>`);
|
|
327
327
|
this.popln();
|
|
328
328
|
}
|
|
329
329
|
renderJsDoc(node) {
|
|
@@ -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
|
@@ -279,7 +279,7 @@ var TypeRenderer = class extends BaseRenderer {
|
|
|
279
279
|
this.writeln("static __is_anscript_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: () => Validator<${asClass}>`);
|
|
283
283
|
}
|
|
284
284
|
this.pop();
|
|
285
285
|
}
|
|
@@ -313,7 +313,7 @@ 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";
|
|
@@ -321,7 +321,7 @@ else if ((0, __atscript_core.isPrimitive)(realDef)) typeDef = "TAtscriptTypeFina
|
|
|
321
321
|
this.writeln(`const __is_anscript_annotated_type: true`);
|
|
322
322
|
this.writeln(`const type: ${typeDef}`);
|
|
323
323
|
this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
|
|
324
|
-
this.writeln(`const validator: () => Validator
|
|
324
|
+
this.writeln(`const validator: () => Validator<${node.id}>`);
|
|
325
325
|
this.popln();
|
|
326
326
|
}
|
|
327
327
|
renderJsDoc(node) {
|
package/dist/index.d.ts
CHANGED
|
@@ -12,10 +12,10 @@ interface TValidatorOptions {
|
|
|
12
12
|
unknwonProps: 'strip' | 'ignore' | 'error';
|
|
13
13
|
errorLimit: number;
|
|
14
14
|
}
|
|
15
|
-
declare class Validator {
|
|
16
|
-
protected readonly def:
|
|
15
|
+
declare class Validator<T extends TAtscriptAnnotatedTypeConstructor> {
|
|
16
|
+
protected readonly def: T;
|
|
17
17
|
protected opts: TValidatorOptions;
|
|
18
|
-
constructor(def:
|
|
18
|
+
constructor(def: T, opts?: Partial<TValidatorOptions>);
|
|
19
19
|
errors: TError[];
|
|
20
20
|
protected stackErrors: TError[][];
|
|
21
21
|
protected stackPath: string[];
|
|
@@ -25,7 +25,7 @@ declare class Validator {
|
|
|
25
25
|
protected clear(): void;
|
|
26
26
|
protected error(message: string, path?: string, details?: TError[]): void;
|
|
27
27
|
protected throw(): void;
|
|
28
|
-
validate(value: any, safe?: boolean):
|
|
28
|
+
validate<TT = InstanceType<T>>(value: any, safe?: boolean): value is TT;
|
|
29
29
|
protected _validate(def: TAtscriptAnnotatedType, value: any): boolean;
|
|
30
30
|
protected validateUnion(def: TAtscriptAnnotatedType<TAtscriptTypeComplex>, value: any): boolean;
|
|
31
31
|
protected validateIntersection(def: TAtscriptAnnotatedType<TAtscriptTypeComplex>, value: any): boolean;
|
|
@@ -67,10 +67,11 @@ type TAtscriptTypeDef = TAtscriptTypeComplex | TAtscriptTypeFinal | TAtscriptTyp
|
|
|
67
67
|
interface TAtscriptAnnotatedType<T = TAtscriptTypeDef> {
|
|
68
68
|
__is_anscript_annotated_type: true;
|
|
69
69
|
type: T;
|
|
70
|
-
validator: (opts?: TValidatorOptions) => Validator
|
|
70
|
+
validator: (opts?: TValidatorOptions) => Validator<any>;
|
|
71
71
|
metadata: TMetadataMap<AtscriptMetadata>;
|
|
72
72
|
optional?: boolean;
|
|
73
73
|
}
|
|
74
|
+
type TAtscriptAnnotatedTypeConstructor = TAtscriptAnnotatedType & (new (...args: any[]) => any);
|
|
74
75
|
declare function isAnnotatedType(type: any): type is TAtscriptAnnotatedType;
|
|
75
76
|
type TKind = '' | 'array' | 'object' | 'union' | 'intersection' | 'tuple';
|
|
76
77
|
declare function defineAnnotatedType(_kind?: TKind, base?: any): {
|
|
@@ -95,4 +96,4 @@ interface TMetadataMap<O extends object> extends Map<keyof O, O[keyof O]> {
|
|
|
95
96
|
set<K extends keyof O>(key: K, value: O[K]): this;
|
|
96
97
|
}
|
|
97
98
|
|
|
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 };
|
|
99
|
+
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
|
@@ -254,7 +254,7 @@ var TypeRenderer = class extends BaseRenderer {
|
|
|
254
254
|
this.writeln("static __is_anscript_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: () => Validator<${asClass}>`);
|
|
258
258
|
}
|
|
259
259
|
this.pop();
|
|
260
260
|
}
|
|
@@ -288,7 +288,7 @@ 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";
|
|
@@ -296,7 +296,7 @@ else if (isPrimitive(realDef)) typeDef = "TAtscriptTypeFinal";
|
|
|
296
296
|
this.writeln(`const __is_anscript_annotated_type: true`);
|
|
297
297
|
this.writeln(`const type: ${typeDef}`);
|
|
298
298
|
this.writeln(`const metadata: TMetadataMap<AtscriptMetadata>`);
|
|
299
|
-
this.writeln(`const validator: () => Validator
|
|
299
|
+
this.writeln(`const validator: () => Validator<${node.id}>`);
|
|
300
300
|
this.popln();
|
|
301
301
|
}
|
|
302
302
|
renderJsDoc(node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
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.16"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"vitest": "^3.0.0"
|