xml-model 1.3.3 → 2.0.0-beta.1
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/README.md +39 -35
- package/dist/index.d.ts +3 -7
- package/dist/index.js +18 -17
- package/dist/model.d.ts +53 -0
- package/dist/model.js +69 -0
- package/dist/util/zod.d.ts +4 -0
- package/dist/util/zod.js +21 -0
- package/dist/xml/codec.d.ts +87 -0
- package/dist/xml/codec.js +385 -0
- package/dist/xml/examples.d.ts +188 -0
- package/dist/xml/index.d.ts +5 -79
- package/dist/xml/index.js +14 -54
- package/dist/xml/model.d.ts +18 -0
- package/dist/xml/model.js +37 -0
- package/dist/xml/schema-meta.d.ts +57 -0
- package/dist/xml/schema-meta.js +96 -0
- package/dist/xml/xml-js.d.ts +138 -3
- package/dist/xml/xml-js.js +89 -5
- package/package.json +10 -23
- package/dist/_virtual/Reflect.js +0 -8
- package/dist/_virtual/Reflect2.js +0 -5
- package/dist/_virtual/_commonjsHelpers.js +0 -47
- package/dist/defaults.d.ts +0 -28
- package/dist/defaults.js +0 -165
- package/dist/errors.d.ts +0 -40
- package/dist/errors.js +0 -45
- package/dist/middleware.d.ts +0 -10
- package/dist/middleware.js +0 -25
- package/dist/model/built-ins.d.ts +0 -3
- package/dist/model/built-ins.js +0 -43
- package/dist/model/index.d.ts +0 -69
- package/dist/model/index.js +0 -264
- package/dist/model/property.d.ts +0 -18
- package/dist/model/property.js +0 -67
- package/dist/model/registry.d.ts +0 -9
- package/dist/model/registry.js +0 -19
- package/dist/model/types.d.ts +0 -109
- package/dist/node_modules/reflect-metadata/Reflect.js +0 -806
- package/dist/types.d.ts +0 -25
- package/dist/util/is-regexp.d.ts +0 -12
- package/dist/util/is-regexp.js +0 -8
- package/dist/util/merge-maps.d.ts +0 -2
- package/dist/util/merge-maps.js +0 -23
- package/dist/vite/index.d.ts +0 -80
- package/dist/vite/index.js +0 -71
- package/dist/vite/node_modules/typescript-rtti/dist.esm/common/format.js +0 -105
- package/dist/vite/node_modules/typescript-rtti/dist.esm/common/index.js +0 -55
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/api-call-transformer.js +0 -152
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/common/class-analyzer.js +0 -83
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/common/compile-error.js +0 -8
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/common/import-analyzer.js +0 -89
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/common/interface-analyzer.js +0 -58
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/common/visitor-base.js +0 -93
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/declarations-emitter.js +0 -31
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/encode-parameter.js +0 -64
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/find-relative-path.js +0 -41
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/flags.js +0 -43
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/forward-ref.js +0 -20
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/get-exports-for-symbol.js +0 -64
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/index.js +0 -130
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/legacy-decorator.js +0 -10
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/legacy-type-encoder.js +0 -82
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/literal-node.js +0 -9
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/metadata-collector.js +0 -56
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/metadata-decorator.js +0 -80
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/metadata-emitter.js +0 -425
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/metadata-encoder.js +0 -212
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/rt-helper.js +0 -96
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/rtti-visitor-base.js +0 -28
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/serialize.js +0 -31
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/type-encoder.js +0 -76
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/type-literal.js +0 -499
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/utils.js +0 -906
- package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/workarounds.js +0 -7
package/dist/types.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export type { Constructor } from 'typescript-rtti';
|
|
2
|
-
/** A record with unknown values, keyed by string, number, or symbol. */
|
|
3
|
-
export type UnknownRecord = Record<string | number | symbol, unknown>;
|
|
4
|
-
/** Any object type. Used instead of `UnknownRecord` because it is compatible with class instances. */
|
|
5
|
-
export type UnknownObject = object;
|
|
6
|
-
/** Key-value map of XML attributes. Values may be strings, numbers, or absent. */
|
|
7
|
-
export interface XMLAttributes {
|
|
8
|
-
[key: string]: string | number | undefined;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* A single node in the xml-js element tree.
|
|
12
|
-
* Used as the internal representation for all XML parsing and serialisation.
|
|
13
|
-
*/
|
|
14
|
-
export interface XMLElement {
|
|
15
|
-
type?: string;
|
|
16
|
-
name?: string;
|
|
17
|
-
attributes?: XMLAttributes;
|
|
18
|
-
elements?: Array<XMLElement>;
|
|
19
|
-
text?: string | number | boolean;
|
|
20
|
-
}
|
|
21
|
-
/** The root of an xml-js document: a wrapper object whose `elements` array holds top-level nodes. */
|
|
22
|
-
export type XMLRoot = {
|
|
23
|
-
elements: XMLElement[];
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/util/is-regexp.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stolen from https://github.com/sindresorhus/is-regexp/blob/main/index.js
|
|
3
|
-
*
|
|
4
|
-
* see https://github.com/sindresorhus/is#why-not-just-use-instanceof-instead-of-this-package
|
|
5
|
-
*
|
|
6
|
-
* could use `import { isRegExp } from "node:util/types"` but I want isomorphic lib
|
|
7
|
-
* @param value
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
export declare function isRegExp(value: unknown): value is RegExp;
|
|
11
|
-
export default isRegExp;
|
|
12
|
-
//# sourceMappingURL=is-regexp.d.ts.map
|
package/dist/util/is-regexp.js
DELETED
package/dist/util/merge-maps.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
function mergeMaps(...sources) {
|
|
2
|
-
const res = /* @__PURE__ */ new Map();
|
|
3
|
-
sources.forEach((source) => {
|
|
4
|
-
const overrides = /* @__PURE__ */ new Map();
|
|
5
|
-
const additions = /* @__PURE__ */ new Map();
|
|
6
|
-
source.forEach((val, key) => (res.has(key) ? overrides : additions).set(key, val));
|
|
7
|
-
if (overrides.size) {
|
|
8
|
-
const entries = Array.from(res.entries());
|
|
9
|
-
entries.forEach((entry) => {
|
|
10
|
-
const key = entry[0];
|
|
11
|
-
if (overrides.has(key)) entry[1] = overrides.get(key);
|
|
12
|
-
});
|
|
13
|
-
res.clear();
|
|
14
|
-
entries.forEach(([key, val]) => res.set(key, val));
|
|
15
|
-
}
|
|
16
|
-
additions.forEach((val, key) => res.set(key, val));
|
|
17
|
-
});
|
|
18
|
-
return res;
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
mergeMaps as default
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=merge-maps.js.map
|
package/dist/vite/index.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
import { RollupTypescriptOptions } from '@rollup/plugin-typescript';
|
|
3
|
-
/**
|
|
4
|
-
* Vite plugin that preserves class names at build time.
|
|
5
|
-
*
|
|
6
|
-
* When Building, class names are changed but the library relies on them
|
|
7
|
-
* so they need to be preserved.
|
|
8
|
-
*
|
|
9
|
-
* @returns A Vite plugin that rewrites mangled class name expressions and enables `keepNames`.
|
|
10
|
-
*/
|
|
11
|
-
export declare function FixClassNames(): {
|
|
12
|
-
name: string;
|
|
13
|
-
enforce: "post";
|
|
14
|
-
transform(this: import('rollup').TransformPluginContext, code: string, id: string): {
|
|
15
|
-
code: string;
|
|
16
|
-
map: any;
|
|
17
|
-
};
|
|
18
|
-
config(this: import('vite').ConfigPluginContext): {
|
|
19
|
-
esbuild: {
|
|
20
|
-
keepNames: true;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
/** Options for the `TypescriptRTTI` and `XMLModelVitePlugin` plugins. */
|
|
25
|
-
export type RTTIPluginOptions = {
|
|
26
|
-
/**
|
|
27
|
-
* Options forwarded to `@rollup/plugin-typescript`.
|
|
28
|
-
*
|
|
29
|
-
* The plugin may not work correctly if you override the `transformers` property,
|
|
30
|
-
* as these options are shallow-merged (not deep-merged).
|
|
31
|
-
*/
|
|
32
|
-
typescript?: RollupTypescriptOptions;
|
|
33
|
-
/**
|
|
34
|
-
* Restrict RTTI transformation to files matching this pattern.
|
|
35
|
-
*
|
|
36
|
-
* When omitted, all files are transformed.
|
|
37
|
-
*/
|
|
38
|
-
include?: RegExp;
|
|
39
|
-
/** Exclude files matching this pattern from RTTI transformation. */
|
|
40
|
-
exclude?: RegExp;
|
|
41
|
-
/** Print debug logs from the RTTI transformer. */
|
|
42
|
-
debug?: boolean;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Vite plugin that applies the `typescript-rtti` TypeScript transformer.
|
|
46
|
-
*
|
|
47
|
-
* This transformer emits the runtime type metadata that xml-model uses to
|
|
48
|
-
* introspect property types without manual annotations.
|
|
49
|
-
*
|
|
50
|
-
* @param options - Plugin options controlling which files are transformed.
|
|
51
|
-
* @returns A configured `@rollup/plugin-typescript` instance with the RTTI transformer injected.
|
|
52
|
-
*/
|
|
53
|
-
export declare function TypescriptRTTI(options?: RTTIPluginOptions): import('rollup').Plugin<any>;
|
|
54
|
-
/** Alias for `RTTIPluginOptions`. */
|
|
55
|
-
export type XMLModelVitePluginOptions = RTTIPluginOptions;
|
|
56
|
-
/**
|
|
57
|
-
* Main xml-model Vite plugin.
|
|
58
|
-
*
|
|
59
|
-
* Combines `FixClassNames`, `TypescriptRTTI`, and an internal resolver that
|
|
60
|
-
* rewrites the `xml-model/dist/*` import paths emitted by typescript-rtti back
|
|
61
|
-
* to the canonical `xml-model/*` paths exported by the package.
|
|
62
|
-
*
|
|
63
|
-
* @param options - Options forwarded to `TypescriptRTTI`.
|
|
64
|
-
* @returns An array of Vite plugins.
|
|
65
|
-
*/
|
|
66
|
-
export declare function XMLModelVitePlugin(options?: RTTIPluginOptions): (Plugin<any> | import('rollup').Plugin<any> | {
|
|
67
|
-
name: string;
|
|
68
|
-
enforce: "post";
|
|
69
|
-
transform(this: import('rollup').TransformPluginContext, code: string, id: string): {
|
|
70
|
-
code: string;
|
|
71
|
-
map: any;
|
|
72
|
-
};
|
|
73
|
-
config(this: import('vite').ConfigPluginContext): {
|
|
74
|
-
esbuild: {
|
|
75
|
-
keepNames: true;
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
})[];
|
|
79
|
-
export default XMLModelVitePlugin;
|
|
80
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/vite/index.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import typescript from "@rollup/plugin-typescript";
|
|
2
|
-
import transformer from "./node_modules/typescript-rtti/dist.esm/transformer/index.js";
|
|
3
|
-
function FixClassNames() {
|
|
4
|
-
return {
|
|
5
|
-
name: "fix-class-names",
|
|
6
|
-
enforce: "post",
|
|
7
|
-
transform(code, id) {
|
|
8
|
-
if (!id.endsWith(".ts") && !id.endsWith(".tsx")) return;
|
|
9
|
-
const fixed = code.replace(/let\s+(\w+)\s*=\s*class\s+(?!extends)\w+/g, "let $1 = class $1");
|
|
10
|
-
return { code: fixed, map: null };
|
|
11
|
-
},
|
|
12
|
-
config() {
|
|
13
|
-
return {
|
|
14
|
-
esbuild: {
|
|
15
|
-
// if not using this ClassName is changed back to ClassName2 on build
|
|
16
|
-
keepNames: true
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function TypescriptRTTI(options = {}) {
|
|
23
|
-
const { typescript: rollupPluginTypescriptOptions, include, exclude, debug = false } = options;
|
|
24
|
-
const doTransform = !include && !exclude ? () => true : (path) => {
|
|
25
|
-
if (exclude?.test(path)) return false;
|
|
26
|
-
return include ? include.test(path) : true;
|
|
27
|
-
};
|
|
28
|
-
return typescript({
|
|
29
|
-
transformers: {
|
|
30
|
-
before: [
|
|
31
|
-
{
|
|
32
|
-
type: "program",
|
|
33
|
-
factory: (program) => {
|
|
34
|
-
if (debug) console.debug("[RTTI] Transformer is running!");
|
|
35
|
-
const transformerFactory = transformer(program);
|
|
36
|
-
return (context) => {
|
|
37
|
-
const transform = transformerFactory(context);
|
|
38
|
-
return (source) => {
|
|
39
|
-
if (doTransform(source.fileName)) {
|
|
40
|
-
if (debug) console.debug(`[RTTI] transforming ${source.fileName}`);
|
|
41
|
-
return transform(source);
|
|
42
|
-
} else return source;
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
]
|
|
48
|
-
},
|
|
49
|
-
// set declaration to `false` to let plugin dts handle the declarations
|
|
50
|
-
declaration: false,
|
|
51
|
-
...rollupPluginTypescriptOptions
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function XMLModelVitePlugin(options = {}) {
|
|
55
|
-
const distResolver = {
|
|
56
|
-
name: "xml-model-resolve-dist",
|
|
57
|
-
enforce: "pre",
|
|
58
|
-
async resolveId(id) {
|
|
59
|
-
const match = id.match(/^xml-model\/dist\/(.*)/);
|
|
60
|
-
if (match) return this.resolve(`xml-model/${match[1]}`);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
return [FixClassNames(), TypescriptRTTI(options), distResolver];
|
|
64
|
-
}
|
|
65
|
-
export {
|
|
66
|
-
FixClassNames,
|
|
67
|
-
TypescriptRTTI,
|
|
68
|
-
XMLModelVitePlugin,
|
|
69
|
-
XMLModelVitePlugin as default
|
|
70
|
-
};
|
|
71
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
const require$1 = createRequire(import.meta.url);
|
|
3
|
-
const F_READONLY = "R";
|
|
4
|
-
const F_ABSTRACT = "A";
|
|
5
|
-
const F_PUBLIC = "$";
|
|
6
|
-
const F_PRIVATE = "#";
|
|
7
|
-
const F_PROTECTED = "@";
|
|
8
|
-
const F_PROPERTY = "P";
|
|
9
|
-
const F_METHOD = "M";
|
|
10
|
-
const F_STATIC = "S";
|
|
11
|
-
const F_CLASS = "C";
|
|
12
|
-
const F_INTERFACE = "I";
|
|
13
|
-
const F_FUNCTION = "F";
|
|
14
|
-
const F_ARROW_FUNCTION = ">";
|
|
15
|
-
const F_OPTIONAL = "?";
|
|
16
|
-
const F_REST = "3";
|
|
17
|
-
const F_ASYNC = "a";
|
|
18
|
-
const F_EXPORTED = "e";
|
|
19
|
-
const F_INFERRED = ".";
|
|
20
|
-
const F_OMITTED = ",";
|
|
21
|
-
const F_ARRAY_BINDING = "[";
|
|
22
|
-
const F_OBJECT_BINDING = "O";
|
|
23
|
-
const T_UNION = "|";
|
|
24
|
-
const T_INTERSECTION = "&";
|
|
25
|
-
const T_ANY = "~";
|
|
26
|
-
const T_UNKNOWN = "U";
|
|
27
|
-
const T_VOID = "V";
|
|
28
|
-
const T_UNDEFINED = "u";
|
|
29
|
-
const T_NULL = "n";
|
|
30
|
-
const T_TUPLE = "T";
|
|
31
|
-
const T_ARRAY = "[";
|
|
32
|
-
const T_THIS = "t";
|
|
33
|
-
const T_GENERIC = "g";
|
|
34
|
-
const T_MAPPED = "m";
|
|
35
|
-
const T_TRUE = "1";
|
|
36
|
-
const T_FALSE = "0";
|
|
37
|
-
const T_CALLSITE = "c";
|
|
38
|
-
const T_STAND_IN = "5";
|
|
39
|
-
const T_OBJECT = "O";
|
|
40
|
-
const T_ENUM = "e";
|
|
41
|
-
const T_FUNCTION = "F";
|
|
42
|
-
const T_INTRINSICS = [T_VOID, T_ANY, T_UNKNOWN, T_UNDEFINED, T_TRUE, T_FALSE, T_THIS, T_NULL];
|
|
43
|
-
const TI_VOID = { TΦ: T_VOID };
|
|
44
|
-
const TI_ANY = { TΦ: T_ANY };
|
|
45
|
-
const TI_UNKNOWN = { TΦ: T_UNKNOWN };
|
|
46
|
-
const TI_UNDEFINED = { TΦ: T_UNDEFINED };
|
|
47
|
-
const TI_TRUE = { TΦ: T_TRUE };
|
|
48
|
-
const TI_FALSE = { TΦ: T_FALSE };
|
|
49
|
-
const TI_THIS = { TΦ: T_THIS };
|
|
50
|
-
const TI_NULL = { TΦ: T_NULL };
|
|
51
|
-
function isLiteralNode(node) {
|
|
52
|
-
return !!node["$__isTSNode"];
|
|
53
|
-
}
|
|
54
|
-
export {
|
|
55
|
-
F_ABSTRACT,
|
|
56
|
-
F_ARRAY_BINDING,
|
|
57
|
-
F_ARROW_FUNCTION,
|
|
58
|
-
F_ASYNC,
|
|
59
|
-
F_CLASS,
|
|
60
|
-
F_EXPORTED,
|
|
61
|
-
F_FUNCTION,
|
|
62
|
-
F_INFERRED,
|
|
63
|
-
F_INTERFACE,
|
|
64
|
-
F_METHOD,
|
|
65
|
-
F_OBJECT_BINDING,
|
|
66
|
-
F_OMITTED,
|
|
67
|
-
F_OPTIONAL,
|
|
68
|
-
F_PRIVATE,
|
|
69
|
-
F_PROPERTY,
|
|
70
|
-
F_PROTECTED,
|
|
71
|
-
F_PUBLIC,
|
|
72
|
-
F_READONLY,
|
|
73
|
-
F_REST,
|
|
74
|
-
F_STATIC,
|
|
75
|
-
TI_ANY,
|
|
76
|
-
TI_FALSE,
|
|
77
|
-
TI_NULL,
|
|
78
|
-
TI_THIS,
|
|
79
|
-
TI_TRUE,
|
|
80
|
-
TI_UNDEFINED,
|
|
81
|
-
TI_UNKNOWN,
|
|
82
|
-
TI_VOID,
|
|
83
|
-
T_ANY,
|
|
84
|
-
T_ARRAY,
|
|
85
|
-
T_CALLSITE,
|
|
86
|
-
T_ENUM,
|
|
87
|
-
T_FALSE,
|
|
88
|
-
T_FUNCTION,
|
|
89
|
-
T_GENERIC,
|
|
90
|
-
T_INTERSECTION,
|
|
91
|
-
T_INTRINSICS,
|
|
92
|
-
T_MAPPED,
|
|
93
|
-
T_NULL,
|
|
94
|
-
T_OBJECT,
|
|
95
|
-
T_STAND_IN,
|
|
96
|
-
T_THIS,
|
|
97
|
-
T_TRUE,
|
|
98
|
-
T_TUPLE,
|
|
99
|
-
T_UNDEFINED,
|
|
100
|
-
T_UNION,
|
|
101
|
-
T_UNKNOWN,
|
|
102
|
-
T_VOID,
|
|
103
|
-
isLiteralNode
|
|
104
|
-
};
|
|
105
|
-
//# sourceMappingURL=format.js.map
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { F_ABSTRACT, F_ARRAY_BINDING, F_ARROW_FUNCTION, F_ASYNC, F_CLASS, F_EXPORTED, F_FUNCTION, F_INFERRED, F_INTERFACE, F_METHOD, F_OBJECT_BINDING, F_OMITTED, F_OPTIONAL, F_PRIVATE, F_PROPERTY, F_PROTECTED, F_PUBLIC, F_READONLY, F_REST, F_STATIC, TI_ANY, TI_FALSE, TI_NULL, TI_THIS, TI_TRUE, TI_UNDEFINED, TI_UNKNOWN, TI_VOID, T_ANY, T_ARRAY, T_CALLSITE, T_ENUM, T_FALSE, T_FUNCTION, T_GENERIC, T_INTERSECTION, T_INTRINSICS, T_MAPPED, T_NULL, T_OBJECT, T_STAND_IN, T_THIS, T_TRUE, T_TUPLE, T_UNDEFINED, T_UNION, T_UNKNOWN, T_VOID, isLiteralNode } from "./format.js";
|
|
3
|
-
const require$1 = createRequire(import.meta.url);
|
|
4
|
-
export {
|
|
5
|
-
F_ABSTRACT,
|
|
6
|
-
F_ARRAY_BINDING,
|
|
7
|
-
F_ARROW_FUNCTION,
|
|
8
|
-
F_ASYNC,
|
|
9
|
-
F_CLASS,
|
|
10
|
-
F_EXPORTED,
|
|
11
|
-
F_FUNCTION,
|
|
12
|
-
F_INFERRED,
|
|
13
|
-
F_INTERFACE,
|
|
14
|
-
F_METHOD,
|
|
15
|
-
F_OBJECT_BINDING,
|
|
16
|
-
F_OMITTED,
|
|
17
|
-
F_OPTIONAL,
|
|
18
|
-
F_PRIVATE,
|
|
19
|
-
F_PROPERTY,
|
|
20
|
-
F_PROTECTED,
|
|
21
|
-
F_PUBLIC,
|
|
22
|
-
F_READONLY,
|
|
23
|
-
F_REST,
|
|
24
|
-
F_STATIC,
|
|
25
|
-
TI_ANY,
|
|
26
|
-
TI_FALSE,
|
|
27
|
-
TI_NULL,
|
|
28
|
-
TI_THIS,
|
|
29
|
-
TI_TRUE,
|
|
30
|
-
TI_UNDEFINED,
|
|
31
|
-
TI_UNKNOWN,
|
|
32
|
-
TI_VOID,
|
|
33
|
-
T_ANY,
|
|
34
|
-
T_ARRAY,
|
|
35
|
-
T_CALLSITE,
|
|
36
|
-
T_ENUM,
|
|
37
|
-
T_FALSE,
|
|
38
|
-
T_FUNCTION,
|
|
39
|
-
T_GENERIC,
|
|
40
|
-
T_INTERSECTION,
|
|
41
|
-
T_INTRINSICS,
|
|
42
|
-
T_MAPPED,
|
|
43
|
-
T_NULL,
|
|
44
|
-
T_OBJECT,
|
|
45
|
-
T_STAND_IN,
|
|
46
|
-
T_THIS,
|
|
47
|
-
T_TRUE,
|
|
48
|
-
T_TUPLE,
|
|
49
|
-
T_UNDEFINED,
|
|
50
|
-
T_UNION,
|
|
51
|
-
T_UNKNOWN,
|
|
52
|
-
T_VOID,
|
|
53
|
-
isLiteralNode
|
|
54
|
-
};
|
|
55
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { Visit } from "./common/visitor-base.js";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
import { isStatement, getRttiDocTagFromSignature, hasFlag } from "./utils.js";
|
|
4
|
-
import { RttiVisitor } from "./rtti-visitor-base.js";
|
|
5
|
-
import { serialize } from "./serialize.js";
|
|
6
|
-
import { TypeEncoder } from "./type-encoder.js";
|
|
7
|
-
import { literalNode } from "./literal-node.js";
|
|
8
|
-
import { createRequire } from "node:module";
|
|
9
|
-
var __decorate = function(decorators, target, key, desc) {
|
|
10
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
12
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
|
-
};
|
|
15
|
-
var __metadata = function(k, v) {
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
17
|
-
};
|
|
18
|
-
const require$1 = createRequire(import.meta.url);
|
|
19
|
-
class ApiCallTransformer extends RttiVisitor {
|
|
20
|
-
constructor() {
|
|
21
|
-
super(...arguments);
|
|
22
|
-
this.typeEncoder = new TypeEncoder(this.ctx);
|
|
23
|
-
}
|
|
24
|
-
static transform(node, ctx) {
|
|
25
|
-
let transformer = new ApiCallTransformer(ctx);
|
|
26
|
-
return transformer.visitNode(node);
|
|
27
|
-
}
|
|
28
|
-
everyNode(node) {
|
|
29
|
-
if (isStatement(node) && node.parent && ts.isSourceFile(node.parent)) {
|
|
30
|
-
this.ctx.currentTopStatement = node;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
isRttiCall(expr, name) {
|
|
34
|
-
if (!ts.isIdentifier(expr.expression))
|
|
35
|
-
return false;
|
|
36
|
-
return ts.isIdentifier(expr.expression) && this.isAnyImportedSymbol(this.checker.getSymbolAtLocation(expr.expression), ["typescript-rtti", "./FΦtypescript-rtti", "./FΦtypescript-rtti.js"], name ? [name] : ["reify", "reflect"]);
|
|
37
|
-
}
|
|
38
|
-
isAnyImportedSymbol(symbol, packageName, names) {
|
|
39
|
-
if (!symbol || !names.includes(symbol.name))
|
|
40
|
-
return false;
|
|
41
|
-
return this.isSymbolFromPackage(symbol, packageName);
|
|
42
|
-
}
|
|
43
|
-
isImportedSymbol(symbol, packageName, name) {
|
|
44
|
-
return this.isAnyImportedSymbol(symbol, [packageName], [name]);
|
|
45
|
-
}
|
|
46
|
-
isSymbolFromPackage(symbol, packageNames) {
|
|
47
|
-
let decls = Array.from(symbol.getDeclarations());
|
|
48
|
-
let importSpecifier = decls.find((x) => x.kind === ts.SyntaxKind.ImportSpecifier);
|
|
49
|
-
if (!importSpecifier)
|
|
50
|
-
return false;
|
|
51
|
-
let modSpecifier = importSpecifier.parent.parent.parent.moduleSpecifier;
|
|
52
|
-
if (!ts.isStringLiteral(modSpecifier))
|
|
53
|
-
return false;
|
|
54
|
-
for (let packageName of packageNames) {
|
|
55
|
-
let matches = modSpecifier.text === packageName || modSpecifier.text.match(new RegExp(`^https?:.*/${packageName}/index.js$`)) || modSpecifier.text.match(new RegExp(`^https?:.*/${packageName}/index.ts$`)) || modSpecifier.text.match(new RegExp(`^https?:.*/${packageName}/?$`));
|
|
56
|
-
if (matches)
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
isCallSiteTypeRef(typeNode) {
|
|
62
|
-
if (!typeNode)
|
|
63
|
-
return false;
|
|
64
|
-
if (typeNode.kind === ts.SyntaxKind.TypeReference) {
|
|
65
|
-
let typeRef = typeNode;
|
|
66
|
-
if (!typeRef.typeName)
|
|
67
|
-
return false;
|
|
68
|
-
if (typeRef.typeName.kind === ts.SyntaxKind.Identifier && typeRef.typeName.text === "CallSite") {
|
|
69
|
-
let symbol = this.checker.getSymbolAtLocation(typeRef.typeName);
|
|
70
|
-
return this.isImportedSymbol(symbol, "typescript-rtti", "CallSite");
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
isCallSiteParameter(param) {
|
|
76
|
-
return !!(param === null || param === void 0 ? void 0 : param.questionToken) && this.isCallSiteTypeRef(param === null || param === void 0 ? void 0 : param.type);
|
|
77
|
-
}
|
|
78
|
-
typeOfParamSymbol(symbol) {
|
|
79
|
-
return this.checker.getTypeOfSymbolAtLocation(symbol, symbol.getDeclarations()[0]);
|
|
80
|
-
}
|
|
81
|
-
callExpr(expr) {
|
|
82
|
-
var _a;
|
|
83
|
-
let signature = this.checker.getResolvedSignature(expr);
|
|
84
|
-
if (!signature) {
|
|
85
|
-
debugger;
|
|
86
|
-
if (globalThis.RTTI_TRACE)
|
|
87
|
-
console.warn(`RTTI: Could not find signature for call expression '${expr.getText()}'`);
|
|
88
|
-
return expr;
|
|
89
|
-
}
|
|
90
|
-
let params = signature.parameters;
|
|
91
|
-
let callSiteArgIndex = params.findIndex((x) => this.isCallSiteParameter(x.valueDeclaration));
|
|
92
|
-
if (callSiteArgIndex < 0) {
|
|
93
|
-
let callSiteArgFromJsDoc = getRttiDocTagFromSignature(signature, "callsite");
|
|
94
|
-
if (callSiteArgFromJsDoc)
|
|
95
|
-
callSiteArgIndex = Number(callSiteArgFromJsDoc);
|
|
96
|
-
}
|
|
97
|
-
if (this.isRttiCall(expr, "reflect") && callSiteArgIndex < 0) {
|
|
98
|
-
callSiteArgIndex = 1;
|
|
99
|
-
} else if (this.isRttiCall(expr, "reify") && callSiteArgIndex < 0) {
|
|
100
|
-
callSiteArgIndex = 0;
|
|
101
|
-
}
|
|
102
|
-
if (callSiteArgIndex >= 0 && callSiteArgIndex >= expr.arguments.length) {
|
|
103
|
-
let args = Array.from(expr.arguments);
|
|
104
|
-
while (callSiteArgIndex > args.length) {
|
|
105
|
-
args.push(ts.factory.createVoidZero());
|
|
106
|
-
}
|
|
107
|
-
args.push(serialize({
|
|
108
|
-
TΦ: "c",
|
|
109
|
-
t: void 0,
|
|
110
|
-
p: expr.arguments.map((x) => literalNode(this.referToType(this.checker.getTypeAtLocation(x)))),
|
|
111
|
-
r: void 0,
|
|
112
|
-
tp: ((_a = expr.typeArguments) !== null && _a !== void 0 ? _a : []).map((x) => literalNode(this.referToType(this.checker.getTypeAtLocation(x))))
|
|
113
|
-
}));
|
|
114
|
-
return ts.factory.updateCallExpression(this.visitEachChild(expr), expr.expression, expr.typeArguments, args);
|
|
115
|
-
} else {
|
|
116
|
-
return this.visitEachChild(expr);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
referToType(type) {
|
|
120
|
-
if (hasFlag(type.flags, ts.TypeFlags.TypeVariable)) {
|
|
121
|
-
let symbol = type.symbol;
|
|
122
|
-
let decl = symbol.declarations[0];
|
|
123
|
-
if (ts.isTypeParameterDeclaration(decl)) {
|
|
124
|
-
let parentDecl = decl.parent;
|
|
125
|
-
if (ts.isFunctionDeclaration(parentDecl) || ts.isArrowFunction(parentDecl) || ts.isMethodDeclaration(parentDecl) || ts.isFunctionExpression(parentDecl)) {
|
|
126
|
-
let typeIndex = parentDecl.typeParameters.findIndex((tp) => this.checker.getTypeAtLocation(tp) === type);
|
|
127
|
-
if (typeIndex >= 0) {
|
|
128
|
-
let callSiteArgIndex = parentDecl.parameters.findIndex((p) => this.isCallSiteParameter(p));
|
|
129
|
-
if (callSiteArgIndex >= 0) {
|
|
130
|
-
let callSiteArg = parentDecl.parameters[callSiteArgIndex];
|
|
131
|
-
if (ts.isIdentifier(callSiteArg.name)) {
|
|
132
|
-
let callSiteName = callSiteArg.name.text;
|
|
133
|
-
return ts.factory.createElementAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(callSiteName), "tp"), typeIndex);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return this.typeEncoder.referToType(type);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
__decorate([
|
|
144
|
-
Visit(ts.SyntaxKind.CallExpression),
|
|
145
|
-
__metadata("design:type", Function),
|
|
146
|
-
__metadata("design:paramtypes", [Object]),
|
|
147
|
-
__metadata("design:returntype", void 0)
|
|
148
|
-
], ApiCallTransformer.prototype, "callExpr", null);
|
|
149
|
-
export {
|
|
150
|
-
ApiCallTransformer
|
|
151
|
-
};
|
|
152
|
-
//# sourceMappingURL=api-call-transformer.js.map
|
package/dist/vite/node_modules/typescript-rtti/dist.esm/transformer/common/class-analyzer.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { VisitorBase, Visit } from "./visitor-base.js";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
import { getModifiers } from "../utils.js";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
|
-
var __decorate = function(decorators, target, key, desc) {
|
|
6
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
-
};
|
|
11
|
-
var __metadata = function(k, v) {
|
|
12
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
13
|
-
};
|
|
14
|
-
const require$1 = createRequire(import.meta.url);
|
|
15
|
-
class ClassAnalyzer extends VisitorBase {
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
this.details = {
|
|
19
|
-
methodNames: [],
|
|
20
|
-
propertyNames: [],
|
|
21
|
-
staticMethodNames: [],
|
|
22
|
-
staticPropertyNames: []
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
isStatic(decl) {
|
|
26
|
-
return getModifiers(decl).some((x) => x.kind === ts.SyntaxKind.StaticKeyword);
|
|
27
|
-
}
|
|
28
|
-
static analyze(decl, context) {
|
|
29
|
-
try {
|
|
30
|
-
let analyzer = new ClassAnalyzer(context);
|
|
31
|
-
analyzer.visitEachChild(decl);
|
|
32
|
-
return analyzer.details;
|
|
33
|
-
} catch (e) {
|
|
34
|
-
console.error(`RTTI: During analyzer for class ${decl.name.getText()}: ${e.message}`);
|
|
35
|
-
throw e;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
addItem(list, prop) {
|
|
39
|
-
if (!list.includes(prop))
|
|
40
|
-
list.push(prop);
|
|
41
|
-
}
|
|
42
|
-
property(decl) {
|
|
43
|
-
this.addItem(this.isStatic(decl) ? this.details.staticPropertyNames : this.details.propertyNames, decl.name);
|
|
44
|
-
}
|
|
45
|
-
method(decl) {
|
|
46
|
-
this.addItem(this.isStatic(decl) ? this.details.staticMethodNames : this.details.methodNames, decl.name);
|
|
47
|
-
}
|
|
48
|
-
ctor(decl) {
|
|
49
|
-
for (let param of decl.parameters) {
|
|
50
|
-
let paramModifiers = getModifiers(param);
|
|
51
|
-
let isProperty = paramModifiers && (paramModifiers.some((x) => x.kind === ts.SyntaxKind.PublicKeyword) || paramModifiers.some((x) => x.kind === ts.SyntaxKind.ProtectedKeyword) || paramModifiers.some((x) => x.kind === ts.SyntaxKind.PrivateKeyword) || paramModifiers.some((x) => x.kind === ts.SyntaxKind.ReadonlyKeyword));
|
|
52
|
-
if (isProperty) {
|
|
53
|
-
if (ts.isIdentifier(param.name)) {
|
|
54
|
-
this.addItem(this.details.propertyNames, param.name);
|
|
55
|
-
} else {
|
|
56
|
-
throw new Error(`Unexpected binding name as property in constructor for class ${decl.name.getText()}! Please file a bug!`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
__decorate([
|
|
63
|
-
Visit([ts.SyntaxKind.PropertyDeclaration, ts.SyntaxKind.GetAccessor, ts.SyntaxKind.SetAccessor]),
|
|
64
|
-
__metadata("design:type", Function),
|
|
65
|
-
__metadata("design:paramtypes", [Object]),
|
|
66
|
-
__metadata("design:returntype", void 0)
|
|
67
|
-
], ClassAnalyzer.prototype, "property", null);
|
|
68
|
-
__decorate([
|
|
69
|
-
Visit(ts.SyntaxKind.MethodDeclaration),
|
|
70
|
-
__metadata("design:type", Function),
|
|
71
|
-
__metadata("design:paramtypes", [Object]),
|
|
72
|
-
__metadata("design:returntype", void 0)
|
|
73
|
-
], ClassAnalyzer.prototype, "method", null);
|
|
74
|
-
__decorate([
|
|
75
|
-
Visit(ts.SyntaxKind.Constructor),
|
|
76
|
-
__metadata("design:type", Function),
|
|
77
|
-
__metadata("design:paramtypes", [Object]),
|
|
78
|
-
__metadata("design:returntype", void 0)
|
|
79
|
-
], ClassAnalyzer.prototype, "ctor", null);
|
|
80
|
-
export {
|
|
81
|
-
ClassAnalyzer
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=class-analyzer.js.map
|