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.
- package/LICENSE +21 -0
- package/README.md +67 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/index.d.ts +3 -0
- package/dist/parser/index.js +4 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/path-match.d.ts +7 -0
- package/dist/parser/path-match.js +37 -0
- package/dist/parser/path-match.js.map +1 -0
- package/dist/parser/reflect-loader.d.ts +9 -0
- package/dist/parser/reflect-loader.js +93 -0
- package/dist/parser/reflect-loader.js.map +1 -0
- package/dist/parser/reflect-parser-plugin.d.ts +7 -0
- package/dist/parser/reflect-parser-plugin.js +27 -0
- package/dist/parser/reflect-parser-plugin.js.map +1 -0
- package/dist/parser/reflect-parser.d.ts +74 -0
- package/dist/parser/reflect-parser.js +611 -0
- package/dist/parser/reflect-parser.js.map +1 -0
- package/dist/reflect-json/Mappable.d.ts +13 -0
- package/dist/reflect-json/Mappable.js +48 -0
- package/dist/reflect-json/Mappable.js.map +1 -0
- package/dist/reflect-json/decorate.d.ts +18 -0
- package/dist/reflect-json/decorate.js +62 -0
- package/dist/reflect-json/decorate.js.map +1 -0
- package/dist/reflect-json/index.d.ts +6 -0
- package/dist/reflect-json/index.js +7 -0
- package/dist/reflect-json/index.js.map +1 -0
- package/dist/reflect-json/json-translation.d.ts +38 -0
- package/dist/reflect-json/json-translation.js +243 -0
- package/dist/reflect-json/json-translation.js.map +1 -0
- package/dist/reflect-json/reflect-extension.d.ts +13 -0
- package/dist/reflect-json/reflect-extension.js +30 -0
- package/dist/reflect-json/reflect-extension.js.map +1 -0
- package/dist/reflect-json/types.d.ts +15 -0
- package/dist/reflect-json/types.js +2 -0
- package/dist/reflect-json/types.js.map +1 -0
- package/dist/reflect-json/utils.d.ts +9 -0
- package/dist/reflect-json/utils.js +48 -0
- package/dist/reflect-json/utils.js.map +1 -0
- package/dist/reflect-types/ClassDefinition.d.ts +26 -0
- package/dist/reflect-types/ClassDefinition.js +90 -0
- package/dist/reflect-types/ClassDefinition.js.map +1 -0
- package/dist/reflect-types/EnumDefinition.d.ts +8 -0
- package/dist/reflect-types/EnumDefinition.js +20 -0
- package/dist/reflect-types/EnumDefinition.js.map +1 -0
- package/dist/reflect-types/InterfaceDefinition.d.ts +16 -0
- package/dist/reflect-types/InterfaceDefinition.js +49 -0
- package/dist/reflect-types/InterfaceDefinition.js.map +1 -0
- package/dist/reflect-types/MethodDefinition.d.ts +15 -0
- package/dist/reflect-types/MethodDefinition.js +21 -0
- package/dist/reflect-types/MethodDefinition.js.map +1 -0
- package/dist/reflect-types/PropertyDefinition.d.ts +18 -0
- package/dist/reflect-types/PropertyDefinition.js +15 -0
- package/dist/reflect-types/PropertyDefinition.js.map +1 -0
- package/dist/reflect-types/assert-type.d.ts +12 -0
- package/dist/reflect-types/assert-type.js +35 -0
- package/dist/reflect-types/assert-type.js.map +1 -0
- package/dist/reflect-types/function-validate.d.ts +10 -0
- package/dist/reflect-types/function-validate.js +77 -0
- package/dist/reflect-types/function-validate.js.map +1 -0
- package/dist/reflect-types/index.d.ts +11 -0
- package/dist/reflect-types/index.js +12 -0
- package/dist/reflect-types/index.js.map +1 -0
- package/dist/reflect-types/package.d.ts +13 -0
- package/dist/reflect-types/package.js +25 -0
- package/dist/reflect-types/package.js.map +1 -0
- package/dist/reflect-types/reflect-context.d.ts +16 -0
- package/dist/reflect-types/reflect-context.js +109 -0
- package/dist/reflect-types/reflect-context.js.map +1 -0
- package/dist/reflect-types/reflect-definitions.d.ts +100 -0
- package/dist/reflect-types/reflect-definitions.js +29 -0
- package/dist/reflect-types/reflect-definitions.js.map +1 -0
- package/dist/reflect-types/reflect-types.d.ts +20 -0
- package/dist/reflect-types/reflect-types.js +83 -0
- package/dist/reflect-types/reflect-types.js.map +1 -0
- package/dist/reflect-types/reflect-validate.d.ts +24 -0
- package/dist/reflect-types/reflect-validate.js +313 -0
- package/dist/reflect-types/reflect-validate.js.map +1 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Reflect-Types
|
|
2
|
+
|
|
3
|
+
A TypeScript library for type reflection and validation.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
- Type reflection for classes, interfaces, enums, and more
|
|
7
|
+
- JSON serialization and deserialization with type validation
|
|
8
|
+
- Function parameter and return type validation
|
|
9
|
+
- Decorator support for enhancing type metadata
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install reflect-types
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Basic Reflection
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { reflect } from 'reflect-types';
|
|
23
|
+
|
|
24
|
+
class User {
|
|
25
|
+
name: string;
|
|
26
|
+
age: number;
|
|
27
|
+
|
|
28
|
+
constructor(name: string, age: number) {
|
|
29
|
+
this.name = name;
|
|
30
|
+
this.age = age;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const userType = reflect(User);
|
|
35
|
+
console.log(userType.name); // 'User'
|
|
36
|
+
console.log(userType.properties); // { name: { type: String }, age: { type: Number } }
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### JSON Serialization
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { serialize, deserialize } from 'reflect-types/reflect-json';
|
|
43
|
+
|
|
44
|
+
const user = new User('John', 30);
|
|
45
|
+
const json = serialize(user);
|
|
46
|
+
console.log(json); // { name: 'John', age: 30 }
|
|
47
|
+
|
|
48
|
+
const deserializedUser = deserialize(json, User);
|
|
49
|
+
console.log(deserializedUser instanceof User); // true
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Parser API
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { parseType } from 'reflect-types/parser';
|
|
56
|
+
|
|
57
|
+
const typeInfo = parseType('User<string, number>');
|
|
58
|
+
console.log(typeInfo); // { name: 'User', generics: [String, Number] }
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Documentation
|
|
62
|
+
|
|
63
|
+
For more detailed documentation, please visit our [GitHub repository](https://github.com/yourusername/reflect-types).
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
MIT License (see LICENSE file for details)
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检查文件路径是否匹配 glob 规则
|
|
3
|
+
* @param filePath 要检查的文件路径(绝对或相对路径)
|
|
4
|
+
* @param pattern glob 规则,如 `/src/**\/.ts`
|
|
5
|
+
* @returns 是否匹配
|
|
6
|
+
*/
|
|
7
|
+
export default function isPathMatch(filePath, pattern) {
|
|
8
|
+
const match = (pattern) => {
|
|
9
|
+
// 1. 规范化路径(统一为 / 分隔符)
|
|
10
|
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
11
|
+
let normalizedPattern = pattern.replace(/\\/g, '/');
|
|
12
|
+
// 2. 处理 `**` 递归匹配
|
|
13
|
+
// 将 `**` 转换为临时占位符 <<double_star>>
|
|
14
|
+
normalizedPattern = normalizedPattern.replace(/\*\*/g, '<<double_star>>');
|
|
15
|
+
// 3. 转义正则特殊字符(除了 * 和 ?)
|
|
16
|
+
const escapedPattern = normalizedPattern
|
|
17
|
+
.replace(/([.+^${}()|[\]\\])/g, '\\$1')
|
|
18
|
+
// 恢复占位符为 `**` 的正则表达式
|
|
19
|
+
.replace(/<<double_star>>/g, '.*')
|
|
20
|
+
// 将 * 转换为非路径分隔符的任意字符匹配
|
|
21
|
+
.replace(/\*/g, '[^/]*');
|
|
22
|
+
// 4. 处理开头和结尾
|
|
23
|
+
let regexPattern = escapedPattern;
|
|
24
|
+
if (!pattern.startsWith('/') && !pattern.startsWith('*')) {
|
|
25
|
+
// 非绝对路径模式:匹配任意中间路径
|
|
26
|
+
regexPattern = '.*' + regexPattern;
|
|
27
|
+
}
|
|
28
|
+
// 添加严格匹配
|
|
29
|
+
regexPattern = '^' + regexPattern + '$';
|
|
30
|
+
// 5. 执行正则测试
|
|
31
|
+
const regex = new RegExp(regexPattern);
|
|
32
|
+
return regex.test(normalizedPath);
|
|
33
|
+
};
|
|
34
|
+
const patterns = pattern instanceof Array ? pattern : [pattern];
|
|
35
|
+
return patterns.some(match);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=path-match.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-match.js","sourceRoot":"","sources":["../../src/parser/path-match.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,QAAgB,EAAE,OAA0B;IAC9E,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,EAAE;QAChC,sBAAsB;QACtB,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QACnD,IAAI,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAEnD,kBAAkB;QAClB,kCAAkC;QAClC,iBAAiB,GAAG,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAA;QAEzE,wBAAwB;QACxB,MAAM,cAAc,GAAG,iBAAiB;aACrC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC;YACvC,qBAAqB;aACpB,OAAO,CAAC,kBAAkB,EAAE,IAAI,CAAC;YAClC,uBAAuB;aACtB,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAE1B,aAAa;QACb,IAAI,YAAY,GAAG,cAAc,CAAA;QACjC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACzD,mBAAmB;YACnB,YAAY,GAAG,IAAI,GAAG,YAAY,CAAA;QACpC,CAAC;QAED,SAAS;QACT,YAAY,GAAG,GAAG,GAAG,YAAY,GAAG,GAAG,CAAA;QAEvC,YAAY;QACZ,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAA;QACtC,OAAO,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IACnC,CAAC,CAAA;IACD,MAAM,QAAQ,GAAG,OAAO,YAAY,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;IAC/D,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ReflectLoaderOptions {
|
|
2
|
+
sourcePaths: string | string[];
|
|
3
|
+
exclude?: string | RegExp | (string | RegExp)[];
|
|
4
|
+
forEnabledClassOnly?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function reflectLoader(options: ReflectLoaderOptions): {
|
|
7
|
+
outputAllMetas: () => string;
|
|
8
|
+
transform: (sourceCode: string, sourceFileName: string) => string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { parseSource } from './reflect-parser';
|
|
3
|
+
import isPathMatch from './path-match';
|
|
4
|
+
export function reflectLoader(options) {
|
|
5
|
+
const { sourcePaths, exclude, forEnabledClassOnly } = options;
|
|
6
|
+
if (!sourcePaths) {
|
|
7
|
+
throw new Error('need provide source paths for reflect loader');
|
|
8
|
+
}
|
|
9
|
+
// console.log(
|
|
10
|
+
// `sourcePaths: ${sourcePaths}, exclude: ${exclude}, forEnabledClassOnly: ${forEnabledClassOnly}`
|
|
11
|
+
// )
|
|
12
|
+
const { classDefinitions, interfaceDefinitions, enumDefinitions, typeAliasDefinitions } = parseSource(sourcePaths, exclude);
|
|
13
|
+
const preStmt = [];
|
|
14
|
+
const postStmt = [];
|
|
15
|
+
function getAllImplementations(name) {
|
|
16
|
+
let def = classDefinitions.get(name);
|
|
17
|
+
const allSuperTypes = [];
|
|
18
|
+
if (def) {
|
|
19
|
+
def.superClassName && allSuperTypes.push(def.superClassName);
|
|
20
|
+
allSuperTypes.push(...(def.implementations || []));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
def = interfaceDefinitions.get(name);
|
|
24
|
+
if (def) {
|
|
25
|
+
allSuperTypes.push(...(def.implementations || []));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
def = typeAliasDefinitions.get(name);
|
|
29
|
+
if (def) {
|
|
30
|
+
allSuperTypes.push(...(def.implementations || []));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return allSuperTypes.flatMap(it => [it, ...getAllImplementations(it)]) || [];
|
|
35
|
+
}
|
|
36
|
+
function isImplements(def, interfaceName) {
|
|
37
|
+
const allImpls = getAllImplementations(def.name);
|
|
38
|
+
return allImpls.includes(interfaceName);
|
|
39
|
+
}
|
|
40
|
+
function parse(node) {
|
|
41
|
+
if (ts.isClassDeclaration(node) && node.name !== undefined) {
|
|
42
|
+
const name = node.name.text;
|
|
43
|
+
const meta = classDefinitions.get(name);
|
|
44
|
+
if (!name || !meta)
|
|
45
|
+
return;
|
|
46
|
+
if (forEnabledClassOnly && !isImplements(meta, 'EnableReflect'))
|
|
47
|
+
return;
|
|
48
|
+
postStmt.push(`Reflect.__classDef = Object.assign(Reflect.__classDef || {}, { ${name} })`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
node.forEachChild(parse);
|
|
52
|
+
}
|
|
53
|
+
function outputAllMetas() {
|
|
54
|
+
const outputStmt = [];
|
|
55
|
+
classDefinitions.forEach((meta, name) => {
|
|
56
|
+
if (forEnabledClassOnly && !isImplements(meta, 'EnableReflect'))
|
|
57
|
+
return;
|
|
58
|
+
outputStmt.push(`Reflect.__classes = Object.assign(Reflect.__classes || {}, { ${name}: ${JSON.stringify(meta)} })`);
|
|
59
|
+
});
|
|
60
|
+
interfaceDefinitions.forEach((meta, name) => {
|
|
61
|
+
if (forEnabledClassOnly && !isImplements(meta, 'EnableReflect'))
|
|
62
|
+
return;
|
|
63
|
+
outputStmt.push(`Reflect.__interfaces = Object.assign(Reflect.__interfaces || {}, { ${name}: ${JSON.stringify(meta)} })`);
|
|
64
|
+
});
|
|
65
|
+
enumDefinitions.forEach((meta, name) => {
|
|
66
|
+
outputStmt.push(`Reflect.__enums = Object.assign(Reflect.__enums || {}, { ${name}: ${JSON.stringify(meta)} })`);
|
|
67
|
+
});
|
|
68
|
+
typeAliasDefinitions.forEach((meta, name) => {
|
|
69
|
+
outputStmt.push(`Reflect.__typeAliases = Object.assign(Reflect.__typeAliases || {}, { ${name}: ${JSON.stringify(meta)} })`);
|
|
70
|
+
});
|
|
71
|
+
// outputStmt.push('Reflect.initReflectContext()')
|
|
72
|
+
return outputStmt.join('\n');
|
|
73
|
+
}
|
|
74
|
+
const transform = (sourceCode, sourceFileName) => {
|
|
75
|
+
const sourcePathPatterns = (typeof sourcePaths === 'string' ? [sourcePaths] : sourcePaths).map(it => it + '/**.ts');
|
|
76
|
+
if (!isPathMatch(sourceFileName, sourcePathPatterns))
|
|
77
|
+
return;
|
|
78
|
+
// console.log(`transform id: ${sourceFileName}`)
|
|
79
|
+
try {
|
|
80
|
+
const sourceFile = ts.createSourceFile(sourceFileName, sourceCode, ts.ScriptTarget.Latest, false);
|
|
81
|
+
preStmt.length = 0;
|
|
82
|
+
postStmt.length = 0;
|
|
83
|
+
parse(sourceFile);
|
|
84
|
+
return `${preStmt.join(';')};${sourceCode};${postStmt.join(';')}`;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.error(`[reflect-parser-plugin] Error processing ${sourceFileName}:`, error);
|
|
88
|
+
return null; // 出错时跳过转换
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return { outputAllMetas, transform };
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=reflect-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflect-loader.js","sourceRoot":"","sources":["../../src/parser/reflect-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAC3B,OAAO,EACL,WAAW,EAIZ,MAAM,kBAAkB,CAAA;AAEzB,OAAO,WAAW,MAAM,cAAc,CAAA;AAUtC,MAAM,UAAU,aAAa,CAAC,OAA6B;IACzD,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAA;IAC7D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;IACjE,CAAC;IACD,eAAe;IACf,oGAAoG;IACpG,IAAI;IAEJ,MAAM,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,eAAe,EAAE,oBAAoB,EAAE,GACrF,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;IACnC,MAAM,OAAO,GAAa,EAAE,CAAA;IAC5B,MAAM,QAAQ,GAAa,EAAE,CAAA;IAE7B,SAAS,qBAAqB,CAAC,IAAY;QACzC,IAAI,GAAG,GAAQ,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACzC,MAAM,aAAa,GAAa,EAAE,CAAA;QAClC,IAAI,GAAG,EAAE,CAAC;YACR,GAAG,CAAC,cAAc,IAAI,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;YAC5D,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,CAAA;QACpD,CAAC;aAAM,CAAC;YACN,GAAG,GAAG,oBAAoB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YACpC,IAAI,GAAG,EAAE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C,CAAC,WAAW,CAAC,CAAC,GAAG,CAC5F,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,QAAQ,CACpB,CAAA;QACD,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,kBAAkB,CAAC;YAAE,OAAM;QAC5D,iDAAiD;QACjD,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CACpC,cAAc,EACd,UAAU,EACV,EAAE,CAAC,YAAY,CAAC,MAAM,EACtB,KAAK,CACN,CAAA;YACD,OAAO,CAAC,MAAM,GAAG,CAAC,CAAA;YAClB,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAA;YACnB,KAAK,CAAC,UAAU,CAAC,CAAA;YACjB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,UAAU,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;QACnE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,6CAA6C,cAAc,GAAG,EAAE,KAAK,CAAC,CAAA;YACpF,OAAO,IAAI,CAAA,CAAC,UAAU;QACxB,CAAC;IACH,CAAC,CAAA;IACD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,CAAA;AACtC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { reflectLoader } from './reflect-loader';
|
|
2
|
+
const projectPath = process.cwd().replace(/\\/g, '/') + '/';
|
|
3
|
+
export default function reflectParserPlugin(options) {
|
|
4
|
+
const loader = reflectLoader(options);
|
|
5
|
+
return {
|
|
6
|
+
name: 'reflect-parser-plugin',
|
|
7
|
+
enforce: 'pre',
|
|
8
|
+
// banner: loader.outputAllMetas(),
|
|
9
|
+
// renderChunk: (code, chunk) => {
|
|
10
|
+
// if (chunk.isEntry) {
|
|
11
|
+
// return `${loader.outputAllMetas()}\n${code}`
|
|
12
|
+
// } else {
|
|
13
|
+
// return code
|
|
14
|
+
// }
|
|
15
|
+
// },
|
|
16
|
+
transform: (sourceCode, sourceFileName) => {
|
|
17
|
+
sourceFileName = sourceFileName.replace(projectPath, '');
|
|
18
|
+
if (sourceFileName === options.entry) {
|
|
19
|
+
return `${loader.outputAllMetas()}\n${sourceCode}`;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return loader.transform(sourceCode, sourceFileName);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=reflect-parser-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflect-parser-plugin.js","sourceRoot":"","sources":["../../src/parser/reflect-parser-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAwB,MAAM,kBAAkB,CAAA;AAKtE,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,GAAG,CAAA;AAC3D,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,OAAgB;IAC1D,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;IACrC,OAAO;QACL,IAAI,EAAE,uBAAuB;QAC7B,OAAO,EAAE,KAAK;QACd,mCAAmC;QACnC,kCAAkC;QAClC,yBAAyB;QACzB,mDAAmD;QACnD,aAAa;QACb,kBAAkB;QAClB,MAAM;QACN,KAAK;QACL,SAAS,EAAE,CAAC,UAAkB,EAAE,cAAsB,EAAE,EAAE;YACxD,cAAc,GAAG,cAAc,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;YACxD,IAAI,cAAc,KAAK,OAAO,CAAC,KAAK,EAAE,CAAC;gBACrC,OAAO,GAAG,MAAM,CAAC,cAAc,EAAE,KAAK,UAAU,EAAE,CAAA;YACpD,CAAC;iBAAM,CAAC;gBACN,OAAO,MAAM,CAAC,SAAS,CAAC,UAAU,EAAE,cAAc,CAAC,CAAA;YACrD,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
type Any = any;
|
|
2
|
+
export interface RawClassDefinition {
|
|
3
|
+
name: string;
|
|
4
|
+
superClassName?: string;
|
|
5
|
+
implementations?: string[];
|
|
6
|
+
methods?: RawMethodDefinition[];
|
|
7
|
+
properties?: RawPropertyDefinition[];
|
|
8
|
+
}
|
|
9
|
+
export interface RawInterfaceDefinition {
|
|
10
|
+
name: string;
|
|
11
|
+
implementations?: string[];
|
|
12
|
+
methods?: RawMethodDefinition[];
|
|
13
|
+
properties?: RawPropertyDefinition[];
|
|
14
|
+
indexElementType?: RawTypeDef;
|
|
15
|
+
}
|
|
16
|
+
export interface RawEnumDefinition {
|
|
17
|
+
name: string;
|
|
18
|
+
members: {
|
|
19
|
+
name: string;
|
|
20
|
+
initializer: string | undefined;
|
|
21
|
+
}[];
|
|
22
|
+
}
|
|
23
|
+
export interface RawMethodDefinition {
|
|
24
|
+
name: string;
|
|
25
|
+
isPrivate?: boolean;
|
|
26
|
+
isStatic?: boolean;
|
|
27
|
+
isAsync?: boolean;
|
|
28
|
+
returnType?: RawTypeDef;
|
|
29
|
+
args?: {
|
|
30
|
+
name: string;
|
|
31
|
+
type?: RawTypeDef;
|
|
32
|
+
isOptional: boolean;
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
35
|
+
export interface RawPropertyDefinition {
|
|
36
|
+
name: string;
|
|
37
|
+
isOptional?: boolean;
|
|
38
|
+
isPrivate?: boolean;
|
|
39
|
+
isStatic?: boolean;
|
|
40
|
+
type?: RawTypeDef;
|
|
41
|
+
accessor?: {
|
|
42
|
+
getter?: {
|
|
43
|
+
isPrivate: boolean;
|
|
44
|
+
};
|
|
45
|
+
setter?: {
|
|
46
|
+
isPrivate: boolean;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
type RawTypeDef = string | RawTypeDefinition;
|
|
51
|
+
export interface RawTypeDefinition {
|
|
52
|
+
arrayElementType?: RawTypeDef;
|
|
53
|
+
indexElementType?: RawTypeDef;
|
|
54
|
+
literalValue?: Any;
|
|
55
|
+
typeLiteralMembers?: RawPropertyDefinition[];
|
|
56
|
+
unionMembers?: RawTypeDef[];
|
|
57
|
+
intersectionMembers?: RawTypeDef[];
|
|
58
|
+
generics?: RawTypeDef[];
|
|
59
|
+
isFunction?: boolean;
|
|
60
|
+
tupleMembers?: RawTypeDef[];
|
|
61
|
+
isOptionalInTuple?: boolean;
|
|
62
|
+
isConstructor?: boolean;
|
|
63
|
+
}
|
|
64
|
+
type FilePathRule = string | RegExp | (string | RegExp)[];
|
|
65
|
+
export declare function setupReflectTypes(filePaths: string | string[], exclude?: FilePathRule, distFolder?: string): Promise<void>;
|
|
66
|
+
export declare function updateReflectModules(filePath: string, distFolder: string): Promise<void>;
|
|
67
|
+
export declare function parseSource(filePaths?: string | string[], exclude?: FilePathRule): {
|
|
68
|
+
classDefinitions: Map<string, RawClassDefinition>;
|
|
69
|
+
interfaceDefinitions: Map<string, RawInterfaceDefinition>;
|
|
70
|
+
enumDefinitions: Map<string, RawEnumDefinition>;
|
|
71
|
+
typeAliasDefinitions: Map<string, RawTypeDef>;
|
|
72
|
+
constTypeDefinitions: Map<string, RawTypeDef>;
|
|
73
|
+
};
|
|
74
|
+
export {};
|