ts-ref-kit 1.0.0

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.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -0
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.js +3 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/parser/index.d.ts +3 -0
  7. package/dist/parser/index.js +4 -0
  8. package/dist/parser/index.js.map +1 -0
  9. package/dist/parser/path-match.d.ts +7 -0
  10. package/dist/parser/path-match.js +37 -0
  11. package/dist/parser/path-match.js.map +1 -0
  12. package/dist/parser/reflect-loader.d.ts +9 -0
  13. package/dist/parser/reflect-loader.js +93 -0
  14. package/dist/parser/reflect-loader.js.map +1 -0
  15. package/dist/parser/reflect-parser-plugin.d.ts +7 -0
  16. package/dist/parser/reflect-parser-plugin.js +27 -0
  17. package/dist/parser/reflect-parser-plugin.js.map +1 -0
  18. package/dist/parser/reflect-parser.d.ts +74 -0
  19. package/dist/parser/reflect-parser.js +611 -0
  20. package/dist/parser/reflect-parser.js.map +1 -0
  21. package/dist/reflect-json/Mappable.d.ts +13 -0
  22. package/dist/reflect-json/Mappable.js +48 -0
  23. package/dist/reflect-json/Mappable.js.map +1 -0
  24. package/dist/reflect-json/decorate.d.ts +18 -0
  25. package/dist/reflect-json/decorate.js +62 -0
  26. package/dist/reflect-json/decorate.js.map +1 -0
  27. package/dist/reflect-json/index.d.ts +6 -0
  28. package/dist/reflect-json/index.js +7 -0
  29. package/dist/reflect-json/index.js.map +1 -0
  30. package/dist/reflect-json/json-translation.d.ts +38 -0
  31. package/dist/reflect-json/json-translation.js +243 -0
  32. package/dist/reflect-json/json-translation.js.map +1 -0
  33. package/dist/reflect-json/reflect-extension.d.ts +13 -0
  34. package/dist/reflect-json/reflect-extension.js +30 -0
  35. package/dist/reflect-json/reflect-extension.js.map +1 -0
  36. package/dist/reflect-json/types.d.ts +15 -0
  37. package/dist/reflect-json/types.js +2 -0
  38. package/dist/reflect-json/types.js.map +1 -0
  39. package/dist/reflect-json/utils.d.ts +9 -0
  40. package/dist/reflect-json/utils.js +48 -0
  41. package/dist/reflect-json/utils.js.map +1 -0
  42. package/dist/reflect-types/ClassDefinition.d.ts +26 -0
  43. package/dist/reflect-types/ClassDefinition.js +90 -0
  44. package/dist/reflect-types/ClassDefinition.js.map +1 -0
  45. package/dist/reflect-types/EnumDefinition.d.ts +8 -0
  46. package/dist/reflect-types/EnumDefinition.js +20 -0
  47. package/dist/reflect-types/EnumDefinition.js.map +1 -0
  48. package/dist/reflect-types/InterfaceDefinition.d.ts +16 -0
  49. package/dist/reflect-types/InterfaceDefinition.js +49 -0
  50. package/dist/reflect-types/InterfaceDefinition.js.map +1 -0
  51. package/dist/reflect-types/MethodDefinition.d.ts +15 -0
  52. package/dist/reflect-types/MethodDefinition.js +21 -0
  53. package/dist/reflect-types/MethodDefinition.js.map +1 -0
  54. package/dist/reflect-types/PropertyDefinition.d.ts +18 -0
  55. package/dist/reflect-types/PropertyDefinition.js +15 -0
  56. package/dist/reflect-types/PropertyDefinition.js.map +1 -0
  57. package/dist/reflect-types/assert-type.d.ts +12 -0
  58. package/dist/reflect-types/assert-type.js +35 -0
  59. package/dist/reflect-types/assert-type.js.map +1 -0
  60. package/dist/reflect-types/function-validate.d.ts +10 -0
  61. package/dist/reflect-types/function-validate.js +77 -0
  62. package/dist/reflect-types/function-validate.js.map +1 -0
  63. package/dist/reflect-types/index.d.ts +11 -0
  64. package/dist/reflect-types/index.js +12 -0
  65. package/dist/reflect-types/index.js.map +1 -0
  66. package/dist/reflect-types/package.d.ts +13 -0
  67. package/dist/reflect-types/package.js +25 -0
  68. package/dist/reflect-types/package.js.map +1 -0
  69. package/dist/reflect-types/reflect-context.d.ts +16 -0
  70. package/dist/reflect-types/reflect-context.js +109 -0
  71. package/dist/reflect-types/reflect-context.js.map +1 -0
  72. package/dist/reflect-types/reflect-definitions.d.ts +100 -0
  73. package/dist/reflect-types/reflect-definitions.js +29 -0
  74. package/dist/reflect-types/reflect-definitions.js.map +1 -0
  75. package/dist/reflect-types/reflect-types.d.ts +20 -0
  76. package/dist/reflect-types/reflect-types.js +83 -0
  77. package/dist/reflect-types/reflect-types.js.map +1 -0
  78. package/dist/reflect-types/reflect-validate.d.ts +24 -0
  79. package/dist/reflect-types/reflect-validate.js +313 -0
  80. package/dist/reflect-types/reflect-validate.js.map +1 -0
  81. package/package.json +36 -0
@@ -0,0 +1,90 @@
1
+ import { fillMethod, fillProperty, getClassDefinition, getInterfaceDefinition } from './index';
2
+ export class ClassDefinition {
3
+ constructor(def) {
4
+ var _a, _b;
5
+ this.name = def.name;
6
+ this.superClassName = def.superClassName || 'Object';
7
+ this.superClass = getClassDefinition(this.superClassName);
8
+ this._implementationNames = def.implementations || [];
9
+ this.methods = ((_a = def.methods) === null || _a === void 0 ? void 0 : _a.map(fillMethod)) || [];
10
+ this.properties = ((_b = def.properties) === null || _b === void 0 ? void 0 : _b.map(fillProperty)) || [];
11
+ this.jsClass = def.jsClass;
12
+ }
13
+ get allMethods() {
14
+ const results = {};
15
+ if (this.superClassName !== 'Object') {
16
+ const superClassDef = getClassDefinition(this.superClassName);
17
+ if (superClassDef) {
18
+ Object.assign(results, Object.assign({}, superClassDef.allMethods));
19
+ }
20
+ }
21
+ Object.assign(results, Object.assign({}, toDictionary(this.methods, it => [it.name, it])));
22
+ return results;
23
+ }
24
+ get allProperties() {
25
+ var _a;
26
+ return Object.assign(((_a = this.superClass) === null || _a === void 0 ? void 0 : _a.allProperties) || {}, toDictionary(this.properties, it => [it.name, it]));
27
+ }
28
+ get implementations() {
29
+ if (!this._implementations) {
30
+ return mapNotNull(this._implementationNames, getInterfaceDefinition);
31
+ }
32
+ return this._implementations;
33
+ }
34
+ get allImplementations() {
35
+ var _a, _b;
36
+ if (this._allImplementations === undefined) {
37
+ const result = new Set(this.implementations);
38
+ this.implementations.forEach(interfaceDef => {
39
+ interfaceDef.allImplementations.forEach(it => result.add(it));
40
+ });
41
+ (_b = (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.allImplementations) === null || _b === void 0 ? void 0 : _b.forEach(it => result.add(it));
42
+ this._allImplementations = Array.from(result);
43
+ }
44
+ return this._allImplementations;
45
+ }
46
+ getProperty(propName) {
47
+ return this.properties.find(it => it.name === propName);
48
+ }
49
+ get type() {
50
+ var _a, _b;
51
+ const props = {};
52
+ (_b = (_a = this.superClass) === null || _a === void 0 ? void 0 : _a.type.typeLiteralMembers) === null || _b === void 0 ? void 0 : _b.forEach(prop => (props[prop.name] = prop));
53
+ this.properties.forEach(prop => (props[prop.name] = prop));
54
+ return {
55
+ name: this.name,
56
+ typeLiteralMembers: Object.values(props)
57
+ };
58
+ }
59
+ isSubClassOf(typeName) {
60
+ var _a;
61
+ if (this.name === typeName)
62
+ return true;
63
+ if ((_a = this.superClass) === null || _a === void 0 ? void 0 : _a.isSubClassOf(typeName))
64
+ return true;
65
+ return this.implementations.map(it => it.name).includes(typeName);
66
+ }
67
+ isSuperClassOf(typeName) {
68
+ if (this.name === typeName)
69
+ return true;
70
+ const classDef = getClassDefinition(typeName);
71
+ if (!classDef)
72
+ return false;
73
+ return classDef.isSubClassOf(this.name);
74
+ }
75
+ toString() {
76
+ return `class ${this.name}`;
77
+ }
78
+ }
79
+ function toDictionary(arr, handler) {
80
+ const dict = {};
81
+ arr.forEach(item => {
82
+ const [key, value] = handler(item);
83
+ dict[key] = value;
84
+ });
85
+ return dict;
86
+ }
87
+ function mapNotNull(arr, mapper) {
88
+ return ((arr === null || arr === void 0 ? void 0 : arr.map(mapper).filter(it => it !== undefined)) || []);
89
+ }
90
+ //# sourceMappingURL=ClassDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClassDefinition.js","sourceRoot":"","sources":["../../src/reflect-types/ClassDefinition.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,sBAAsB,EAIvB,MAAM,SAAS,CAAA;AAGhB,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,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;QAClC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IACnB,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,UAAU,CAAO,GAAoB,EAAE,MAAkC;IAChF,OAAO,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC,KAAI,EAAE,CAAQ,CAAA;AACvE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { RawEnumDefinition, TypeDefinition } from './reflect-definitions';
2
+ export declare class EnumDefinition {
3
+ readonly name: string;
4
+ readonly members: Map<string, TypeDefinition>;
5
+ constructor(def: RawEnumDefinition);
6
+ get type(): TypeDefinition;
7
+ get names(): string[];
8
+ }
@@ -0,0 +1,20 @@
1
+ export class EnumDefinition {
2
+ constructor(def) {
3
+ this.name = def.name;
4
+ this.members = new Map();
5
+ def.members.forEach(member => {
6
+ const value = member.initializer === undefined ? { name: 'number' } : { literalValue: member.initializer };
7
+ this.members.set(member.name, value);
8
+ });
9
+ }
10
+ get type() {
11
+ return {
12
+ name: this.name,
13
+ unionMembers: Array.from(this.members.values())
14
+ };
15
+ }
16
+ get names() {
17
+ return Array.from(this.members.keys());
18
+ }
19
+ }
20
+ //# sourceMappingURL=EnumDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnumDefinition.js","sourceRoot":"","sources":["../../src/reflect-types/EnumDefinition.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,cAAc;IAIzB,YAAY,GAAsB;QAChC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAA;QACxB,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAC3B,MAAM,KAAK,GACT,MAAM,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,WAAW,EAAE,CAAA;YAC9F,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACtC,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,IAAI;QACN,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;SAChD,CAAA;IACH,CAAC;IAED,IAAI,KAAK;QACP,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;IACxC,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import type { RawInterfaceDefinition, TypeDefinition } from './index';
2
+ import { MethodDefinition, PropertyDefinition } from './index';
3
+ export declare class InterfaceDefinition {
4
+ readonly name: string;
5
+ readonly methods: MethodDefinition[];
6
+ readonly properties: PropertyDefinition[];
7
+ private readonly _implementationNames;
8
+ private _implementations?;
9
+ private _allImplementations?;
10
+ constructor(def: RawInterfaceDefinition);
11
+ get implementations(): InterfaceDefinition[];
12
+ get allImplementations(): InterfaceDefinition[];
13
+ get type(): TypeDefinition;
14
+ toString(): string;
15
+ buildBaseObject(): {};
16
+ }
@@ -0,0 +1,49 @@
1
+ import { fillMethod, fillProperty, getInterfaceDefinition } from './index';
2
+ import { mapNotNull, setValue } from './package';
3
+ export class InterfaceDefinition {
4
+ constructor(def) {
5
+ var _a, _b;
6
+ this.name = def.name;
7
+ this._implementationNames = def.implementations || [];
8
+ this.methods = ((_a = def.methods) === null || _a === void 0 ? void 0 : _a.map(fillMethod)) || [];
9
+ this.properties = ((_b = def.properties) === null || _b === void 0 ? void 0 : _b.map(fillProperty)) || [];
10
+ }
11
+ get implementations() {
12
+ if (!this._implementations) {
13
+ this._implementations = mapNotNull(this._implementationNames, getInterfaceDefinition);
14
+ }
15
+ return this._implementations;
16
+ }
17
+ get allImplementations() {
18
+ if (this._allImplementations === undefined) {
19
+ const result = new Set(this.implementations);
20
+ this.implementations.forEach(interfaceDef => {
21
+ interfaceDef.allImplementations.forEach(it => result.add(it));
22
+ });
23
+ this._allImplementations = Array.from(result);
24
+ }
25
+ return this._allImplementations;
26
+ }
27
+ get type() {
28
+ const props = {};
29
+ this.allImplementations.forEach(parentInterface => {
30
+ const interfaceProps = parentInterface.type.typeLiteralMembers;
31
+ interfaceProps === null || interfaceProps === void 0 ? void 0 : interfaceProps.forEach(prop => (props[prop.name] = prop));
32
+ });
33
+ this.properties.forEach(prop => (props[prop.name] = prop));
34
+ return {
35
+ name: this.name,
36
+ typeLiteralMembers: Object.values(props)
37
+ };
38
+ }
39
+ toString() {
40
+ return `interface ${this.name}`;
41
+ }
42
+ buildBaseObject() {
43
+ const result = {};
44
+ this.properties.forEach(it => setValue(result, it.name, undefined));
45
+ this.methods.forEach(it => setValue(result, it.name, () => undefined));
46
+ return result;
47
+ }
48
+ }
49
+ //# sourceMappingURL=InterfaceDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InterfaceDefinition.js","sourceRoot":"","sources":["../../src/reflect-types/InterfaceDefinition.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,sBAAsB,EAGvB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEhD,MAAM,OAAO,mBAAmB;IAQ9B,YAAY,GAA2B;;QACrC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;QACpB,IAAI,CAAC,oBAAoB,GAAG,GAAG,CAAC,eAAe,IAAI,EAAE,CAAA;QACrD,IAAI,CAAC,OAAO,GAAG,CAAA,MAAA,GAAG,C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5D,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QAC1D,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,kBAAkB,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;SACzC,CAAA;IACH,CAAC;IAED,QAAQ;QACN,OAAO,aAAa,IAAI,CAAC,IAAI,EAAE,CAAA;IACjC,CAAC;IAED,eAAe;QACb,MAAM,MAAM,GAAG,EAAE,CAAA;QACjB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAA;QACnE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;QACtE,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ import { type RawMethodDefinition, type TypeDefinition } from './index';
2
+ export declare class MethodDefinition {
3
+ name: string;
4
+ isPrivate: boolean;
5
+ isStatic: boolean;
6
+ isAsync: boolean;
7
+ returnType: TypeDefinition;
8
+ args: {
9
+ name: string;
10
+ type?: TypeDefinition;
11
+ isOptional: boolean;
12
+ }[];
13
+ constructor(def: RawMethodDefinition);
14
+ }
15
+ export declare function fillMethod(rawMethod: RawMethodDefinition): MethodDefinition;
@@ -0,0 +1,21 @@
1
+ import { fillType } from './index';
2
+ export class MethodDefinition {
3
+ constructor(def) {
4
+ var _a;
5
+ this.name = def.name;
6
+ this.returnType = fillType(def.returnType);
7
+ this.args =
8
+ ((_a = def.args) === null || _a === void 0 ? void 0 : _a.map(arg => ({
9
+ name: arg.name,
10
+ type: fillType(arg.type),
11
+ isOptional: arg.isOptional
12
+ }))) || [];
13
+ this.isPrivate = def.isPrivate || false;
14
+ this.isStatic = def.isStatic || false;
15
+ this.isAsync = def.isAsync || false;
16
+ }
17
+ }
18
+ export function fillMethod(rawMethod) {
19
+ return new MethodDefinition(rawMethod);
20
+ }
21
+ //# sourceMappingURL=MethodDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodDefinition.js","sourceRoot":"","sources":["../../src/reflect-types/MethodDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAiD,MAAM,SAAS,CAAA;AAEjF,MAAM,OAAO,gBAAgB;IAY3B,YAAY,GAAwB;;QAClC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QAC1C,IAAI,CAAC,IAAI;YACP,CAAA,MAAA,GAAG,CAAC,IAAI,0CAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACpB,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;gBACxB,UAAU,EAAE,GAAG,CAAC,UAAU;aAC3B,CAAC,CAAC,KAAI,EAAE,CAAA;QACX,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,IAAI,KAAK,CAAA;QACvC,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,IAAI,KAAK,CAAA;QACrC,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,KAAK,CAAA;IACrC,CAAC;CACF;AAED,MAAM,UAAU,UAAU,CAAC,SAA8B;IACvD,OAAO,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAA;AACxC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { type RawPropertyDefinition, type TypeDefinition } from './index';
2
+ export declare class PropertyDefinition {
3
+ name: string;
4
+ isOptional: boolean;
5
+ isPrivate: boolean;
6
+ isStatic: boolean;
7
+ type: TypeDefinition;
8
+ accessor?: {
9
+ getter?: {
10
+ isPrivate: boolean;
11
+ };
12
+ setter?: {
13
+ isPrivate: boolean;
14
+ };
15
+ };
16
+ constructor(def: RawPropertyDefinition);
17
+ }
18
+ export declare function fillProperty(rawProperty: RawPropertyDefinition): PropertyDefinition;
@@ -0,0 +1,15 @@
1
+ import { fillType } from './index';
2
+ export class PropertyDefinition {
3
+ constructor(def) {
4
+ this.name = def.name;
5
+ this.isOptional = def.isOptional || false;
6
+ this.isPrivate = def.isPrivate || false;
7
+ this.isStatic = def.isStatic || false;
8
+ this.type = fillType(def.type);
9
+ this.accessor = def.accessor && Object.assign({}, def.accessor);
10
+ }
11
+ }
12
+ export function fillProperty(rawProperty) {
13
+ return new PropertyDefinition(rawProperty);
14
+ }
15
+ //# sourceMappingURL=PropertyDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyDefinition.js","sourceRoot":"","sources":["../../src/reflect-types/PropertyDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmD,MAAM,SAAS,CAAA;AAEnF,MAAM,OAAO,kBAAkB;IAW7B,YAAY,GAA0B;QACpC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,KAAK,CAAA;QACzC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,IAAI,KAAK,CAAA;QACvC,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,IAAI,KAAK,CAAA;QACrC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC9B,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,sBAAS,GAAG,CAAC,QAAQ,CAAE,CAAA;IACrD,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAC,WAAkC;IAC7D,OAAO,IAAI,kBAAkB,CAAC,WAAW,CAAC,CAAA;AAC5C,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type TypeDefinition } from '.';
2
+ export type Type = string | {
3
+ array: Type;
4
+ } | {
5
+ union: Type[];
6
+ } | {
7
+ intersection: Type[];
8
+ } | {
9
+ tuple: Type[];
10
+ };
11
+ export declare function getTypeDef(type: Type): TypeDefinition;
12
+ export declare function assertType<T>(data: T, type: Type, depth?: number): T;
@@ -0,0 +1,35 @@
1
+ import { getTypeDefinition, validateValue } from '.';
2
+ export function getTypeDef(type) {
3
+ if (typeof type === 'string')
4
+ return getTypeDefinition(type);
5
+ const arrayType = type;
6
+ if (arrayType.array)
7
+ return { arrayElementType: getTypeDef(arrayType.array) };
8
+ const unionType = type;
9
+ if (unionType.union)
10
+ return {
11
+ unionMembers: unionType.union.map(getTypeDef)
12
+ };
13
+ const intersectionMembers = type;
14
+ if (intersectionMembers.intersection)
15
+ return {
16
+ intersectionMembers: intersectionMembers.intersection.map(getTypeDef)
17
+ };
18
+ const tupleType = type;
19
+ if (tupleType.tuple)
20
+ return {
21
+ tupleMembers: tupleType.tuple.map(getTypeDef)
22
+ };
23
+ throw new Error(`unknown type: ${type}`);
24
+ }
25
+ export function assertType(data, type, depth = 5) {
26
+ const validateResult = validateValue(data, getTypeDef(type), depth);
27
+ if (!validateResult.success) {
28
+ console.error(`assert failed with type: ${type}`);
29
+ console.dir(validateResult);
30
+ debugger;
31
+ // throw new Error(`assert failed with type: ${type}, ${validateResult.errorMessage}`)
32
+ }
33
+ return data;
34
+ }
35
+ //# sourceMappingURL=assert-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-type.js","sourceRoot":"","sources":["../../src/reflect-types/assert-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,iBAAiB,EAAE,aAAa,EAAE,MAAM,GAAG,CAAA;AAiBzE,MAAM,UAAU,UA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
1
+ import { type AnyFunction } from './package';
2
+ declare const VALIDATE_WRAPPER: unique symbol;
3
+ declare global {
4
+ interface Function {
5
+ [VALIDATE_WRAPPER]: AnyFunction;
6
+ }
7
+ }
8
+ export declare const ReflectValidate: MethodDecorator;
9
+ export declare function safeCall(target: object, methodName: string, ...args: unknown[]): unknown;
10
+ export {};
@@ -0,0 +1,77 @@
1
+ import { anyType, getClassDefinition, validateValue } from '.';
2
+ import { getValue } from './package';
3
+ const VALIDATE_WRAPPER = Symbol('VALIDATE_WRAPPER');
4
+ export const ReflectValidate = (target, propertyKey, descriptor) => wrapValidateMethod(target, propertyKey, descriptor);
5
+ function wrapValidateMethod(target, methodName, descriptor) {
6
+ const func = descriptor.value;
7
+ if (typeof func !== 'function')
8
+ return;
9
+ if (getValue(func, VALIDATE_WRAPPER))
10
+ return;
11
+ const getMethodDef = () => { var _a, _b; return (_b = (_a = getClassDefinition(target)) === null || _a === void 0 ? void 0 : _a.methods) === null || _b === void 0 ? void 0 : _b.find(it => it.name === methodName); };
12
+ const validateArgs = (args) => validateMethodParams(target, getMethodDef(), args);
13
+ const validateReturn = (result) => validateMethodReturnValue(target, getMethodDef(), result);
14
+ const newFunc = function (...args) {
15
+ validateArgs(args);
16
+ const result = func.call(this, ...args);
17
+ return validateReturn(result);
18
+ };
19
+ newFunc[VALIDATE_WRAPPER] = func;
20
+ descriptor.value = newFunc;
21
+ }
22
+ function validateMethodParams(target, methodDef, args) {
23
+ var _a;
24
+ (_a = methodDef === null || methodDef === void 0 ? void 0 : methodDef.args) === null || _a === void 0 ? void 0 : _a.forEach((argDef, index) => {
25
+ const arg = args === null || args === void 0 ? void 0 : args[index];
26
+ if (arg === undefined) {
27
+ if (!argDef.isOptional)
28
+ throw new Error(`Illegal arguments for ${getMethodDescription(target.constructor.name, methodDef)}: ${argDef.name} is not optional`);
29
+ else
30
+ return;
31
+ }
32
+ const validResult = validateValue(arg, argDef.type || anyType, 1);
33
+ if (!validResult.success) {
34
+ console.error('validateResult', validResult);
35
+ throw new Error(`Illegal arguments for ${getMethodDescription(target.constructor.name, methodDef)}: ${argDef.name}: ${argDef.name} ${validResult.errorMessage}`);
36
+ }
37
+ });
38
+ }
39
+ function validateMethodReturnValue(target, methodDef, result) {
40
+ var _a;
41
+ if (!methodDef)
42
+ return result;
43
+ const checkValue = (value, type) => {
44
+ const validateResult = validateValue(value, type, 5);
45
+ if (!validateResult.success) {
46
+ console.error(validateResult);
47
+ debugger;
48
+ throw new Error(`result for ${getMethodDescription(target.constructor.name, methodDef)} doesn't match type ${type.name}: ${validateResult.errorMessage}`);
49
+ }
50
+ return value;
51
+ };
52
+ let returnType = methodDef.returnType;
53
+ if (returnType.name === 'Promise') {
54
+ returnType = ((_a = returnType.generics) === null || _a === void 0 ? void 0 : _a[0]) || anyType;
55
+ }
56
+ if (result instanceof Promise) {
57
+ return result.then(res => checkValue(res, returnType || anyType));
58
+ }
59
+ else {
60
+ return checkValue(result, returnType || anyType);
61
+ }
62
+ }
63
+ function getMethodDescription(className, methodDef) {
64
+ var _a;
65
+ return `${className}.${methodDef.name}(${(_a = methodDef.args) === null || _a === void 0 ? void 0 : _a.map(it => it.name).join(', ')})`;
66
+ }
67
+ export function safeCall(target, methodName, ...args) {
68
+ const classDef = getClassDefinition(target);
69
+ if (!classDef)
70
+ return;
71
+ const methodDef = classDef.allMethods[methodName];
72
+ if (!methodDef)
73
+ return;
74
+ validateMethodParams(target, methodDef, args);
75
+ return getValue(target, methodName).apply(target, args);
76
+ }
77
+ //# sourceMappingURL=function-validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-validate.js","sourceRoot":"","sources":["../../src/reflect-types/function-validate.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,kBAAkB,EAClB,aAAa,EAGd,MAAM,GAAG,CAAA;AACV,OAAO,EAAoB,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEtD,MAAM,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AA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AE,IAAI,CAAC,CAAA;IAC7C,OAAQ,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAiB,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AAC1E,CAAC"}
@@ -0,0 +1,11 @@
1
+ export * from './reflect-definitions';
2
+ export * from './reflect-context';
3
+ export * from './ClassDefinition';
4
+ export * from './InterfaceDefinition';
5
+ export * from './EnumDefinition';
6
+ export * from './MethodDefinition';
7
+ export * from './PropertyDefinition';
8
+ export * from './reflect-types';
9
+ export * from './reflect-validate';
10
+ export * from './assert-type';
11
+ export * from './function-validate';
@@ -0,0 +1,12 @@
1
+ export * from './reflect-definitions';
2
+ export * from './reflect-context';
3
+ export * from './ClassDefinition';
4
+ export * from './InterfaceDefinition';
5
+ export * from './EnumDefinition';
6
+ export * from './MethodDefinition';
7
+ export * from './PropertyDefinition';
8
+ export * from './reflect-types';
9
+ export * from './reflect-validate';
10
+ export * from './assert-type';
11
+ export * from './function-validate';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reflect-types/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,13 @@
1
+ export type Dictionary<T> = {
2
+ [key: string]: T;
3
+ };
4
+ type Any = any;
5
+ export type AnyConstructorFunction = new (...args: Any[]) => Any;
6
+ export type AnyFunction = (...args: Any[]) => Any;
7
+ export declare function setValue<T>(target: unknown, field: string | symbol, value: T): void;
8
+ export declare function getValue<T>(target: unknown, field: string | symbol): T | undefined;
9
+ export declare function mapNotNull<T, U>(arr: T[] | undefined, mapper: (item: T) => U | undefined): U[];
10
+ export declare function spy(variables: {
11
+ [prop: string]: unknown;
12
+ }): void;
13
+ export {};
@@ -0,0 +1,25 @@
1
+ const IS_PRODUCTION = false;
2
+ export function setValue(target, field, value) {
3
+ if (target === undefined)
4
+ return;
5
+ target[field] = value;
6
+ }
7
+ export function getValue(target, field) {
8
+ if (target === undefined)
9
+ return undefined;
10
+ return target[field];
11
+ }
12
+ export function mapNotNull(arr, mapper) {
13
+ return ((arr === null || arr === void 0 ? void 0 : arr.map(mapper).filter(it => it !== undefined)) || []);
14
+ }
15
+ export function spy(variables) {
16
+ if (IS_PRODUCTION)
17
+ return;
18
+ try {
19
+ Object.entries(variables).forEach(entry => Object.defineProperty(globalThis, entry[0], { value: entry[1] }));
20
+ }
21
+ catch (e) {
22
+ console.log(e);
23
+ }
24
+ }
25
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.js","sourceRoot":"","sources":["../../src/reflect-types/package.ts"],"names":[],"mappings":"AAGA,MAAM,aAAa,GAAG,KAAK,CAAA;AAK3B,MAAM,UAAU,QAAQ,CAAI,MAAe,EAAE,KAAsB,EAAE,KAAQ;IAC3E,IAAI,MAAM,KAAK,SAAS;QAAE,OACzB;IAAC,MAAwC,CAAC,KAAK,CAAC,GAAG,KAAK,CAAA;AAC3D,CAAC;AACD,MAAM,UAAU,QAAQ,CAAI,MAAe,EAAE,KAAsB;IACjE,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC1C,OAAQ,MAAwC,CAAC,KAAK,CAAC,CAAA;AACzD,CAAC;AACD,MAAM,UAAU,UAAU,CAAO,GAAoB,EAAE,MAAkC;IACvF,OAAO,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC,KAAI,EAAE,CAAQ,CAAA;AACvE,CAAC;AACD,MAAM,UAAU,GAAG,CAAC,SAAsC;IACxD,IAAI,aAAa;QAAE,OAAM;IACzB,IAAI,CAAC;QACH,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CACxC,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CACjE,CAAA;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAChB,CAAC;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { AnyConstructorFunction } from './package';
2
+ import { type TypeDefinition } from './index';
3
+ import { ClassDefinition, EnumDefinition, InterfaceDefinition } from './index';
4
+ export declare const ReflectClass: ClassDecorator;
5
+ export declare const ReflectContext: {
6
+ getClassDefinition: typeof getClassDefinition;
7
+ getInterfaceDefinition: typeof getInterfaceDefinition;
8
+ getEnumDefinition: typeof getEnumDefinition;
9
+ getTypeAliasDefinition: typeof getTypeAliasDefinition;
10
+ };
11
+ export declare function getClassByName(className: string): AnyConstructorFunction | undefined;
12
+ declare function getClassDefinition(arg: AnyConstructorFunction | object | string): ClassDefinition | undefined;
13
+ declare function getInterfaceDefinition(name: string): InterfaceDefinition | undefined;
14
+ declare function getEnumDefinition(name: string): EnumDefinition | undefined;
15
+ declare function getTypeAliasDefinition(name: string): TypeDefinition | undefined;
16
+ export {};
@@ -0,0 +1,109 @@
1
+ import { fillType } from './index';
2
+ import { ClassDefinition, EnumDefinition, InterfaceDefinition } from './index';
3
+ const classMap = new Map();
4
+ const interfaceMap = new Map();
5
+ const enumMap = new Map();
6
+ const typeAliasMap = new Map();
7
+ const classPool = new Map();
8
+ export const ReflectClass = ((jsClass) => {
9
+ classPool.set(jsClass.name, jsClass);
10
+ });
11
+ const primitiveMap = {
12
+ string: String,
13
+ number: Number,
14
+ boolean: Boolean,
15
+ object: Object
16
+ };
17
+ export const ReflectContext = {
18
+ getClassDefinition,
19
+ getInterfaceDefinition,
20
+ getEnumDefinition,
21
+ getTypeAliasDefinition
22
+ };
23
+ const reflect = Reflect;
24
+ export function getClassByName(className) {
25
+ return (reflect.__classDef[className] ||
26
+ globalThis[className] ||
27
+ primitiveMap[className]);
28
+ }
29
+ function getClassDefinition(arg) {
30
+ var _a, _b;
31
+ let className;
32
+ switch (typeof arg) {
33
+ case 'function':
34
+ className = arg.name;
35
+ break;
36
+ case 'string':
37
+ className = arg;
38
+ break;
39
+ case 'object':
40
+ className = arg.constructor.name;
41
+ break;
42
+ default:
43
+ return undefined;
44
+ }
45
+ if (!classMap.has(className)) {
46
+ const rawClassDef = (_a = reflect.__classes) === null || _a === void 0 ? void 0 : _a[className];
47
+ if (!rawClassDef)
48
+ return undefined;
49
+ const jsClass = (_b = reflect.__classDef) === null || _b === void 0 ? void 0 : _b[className];
50
+ classMap.set(className, new ClassDefinition(Object.assign(Object.assign({}, rawClassDef), { jsClass })));
51
+ }
52
+ return classMap.get(className);
53
+ }
54
+ function getInterfaceDefinition(name) {
55
+ var _a;
56
+ if (!interfaceMap.has(name)) {
57
+ const interfaceMeta = (_a = reflect.__interfaces) === null || _a === void 0 ? void 0 : _a[name];
58
+ if (!interfaceMeta)
59
+ return undefined;
60
+ interfaceMap.set(name, new InterfaceDefinition(interfaceMeta));
61
+ }
62
+ return interfaceMap.get(name);
63
+ }
64
+ function getEnumDefinition(name) {
65
+ var _a;
66
+ if (!enumMap.has(name)) {
67
+ const enumMeta = (_a = reflect.__enums) === null || _a === void 0 ? void 0 : _a[name];
68
+ if (!enumMeta)
69
+ return undefined;
70
+ enumMap.set(name, new EnumDefinition(enumMeta));
71
+ }
72
+ return enumMap.get(name);
73
+ }
74
+ function getTypeAliasDefinition(name) {
75
+ var _a;
76
+ if (!typeAliasMap.has(name)) {
77
+ const typeAliasMeta = fillType((_a = reflect.__typeAliases) === null || _a === void 0 ? void 0 : _a[name]);
78
+ if (!typeAliasMeta)
79
+ return undefined;
80
+ typeAliasMap.set(name, typeAliasMeta);
81
+ }
82
+ return typeAliasMap.get(name);
83
+ }
84
+ reflect.initReflectContext = () => {
85
+ reflect.__classes &&
86
+ Object.entries(reflect.__classes).map(([className, rawClassDef]) => {
87
+ const jsClass = reflect.__classDef[className];
88
+ if (!jsClass)
89
+ return undefined;
90
+ classMap.set(className, new ClassDefinition(Object.assign(Object.assign({}, rawClassDef), { jsClass })));
91
+ });
92
+ reflect.__interfaces &&
93
+ Object.entries(reflect.__interfaces).map(([name, interfaceMeta]) => interfaceMap.set(name, new InterfaceDefinition(interfaceMeta)));
94
+ reflect.__enums &&
95
+ Object.entries(reflect.__enums).map(([name, enumMeta]) => enumMap.set(name, new EnumDefinition(enumMeta)));
96
+ reflect.__typeAliases &&
97
+ Object.entries(reflect.__typeAliases).map(([name, def]) => {
98
+ typeAliasMap.set(name, fillType(def));
99
+ });
100
+ [
101
+ '__classDef',
102
+ '__classes',
103
+ '__interfaces',
104
+ '__enums',
105
+ '__typeAliases',
106
+ 'initReflectContext'
107
+ ].forEach(it => delete reflect[it]);
108
+ };
109
+ //# sourceMappingURL=reflect-context.js.map