@spinajs/reflection 2.0.180 → 2.0.182

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.
@@ -1,2 +1,2 @@
1
- export * from 'typescript-mix';
1
+ export * from 'typescript-mix';
2
2
  //# sourceMappingURL=index.browser.d.ts.map
@@ -1,21 +1,21 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- // expose only use() to allow mixins
18
- // all typescript compilation stuff is
19
- // disablbed on browser
20
- __exportStar(require("typescript-mix"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // expose only use() to allow mixins
18
+ // all typescript compilation stuff is
19
+ // disablbed on browser
20
+ __exportStar(require("typescript-mix"), exports);
21
21
  //# sourceMappingURL=index.browser.js.map
@@ -1,35 +1,35 @@
1
- import { Exception } from '@spinajs/exceptions';
2
- export * from 'typescript-mix';
3
- /**
4
- * Exception thrown when some error during reflection occurs
5
- */
6
- export declare class ReflectionException extends Exception {
7
- }
8
- /**
9
- * Helper class for extracting various information from typescript source code
10
- */
11
- export declare class TypescriptCompiler {
12
- private tsFile;
13
- private compiled;
14
- constructor(filename: string);
15
- /**
16
- *
17
- * Extracts all members info from typescript class eg. method name, parameters, return types etc.
18
- *
19
- * @param className - name of class to parse
20
- */
21
- getClassMembers(className: string): Map<string, any>;
22
- private walkClassNode;
23
- private walkMemberNode;
24
- }
25
- /**
26
- * Returns resolved instances of classes from specified files.
27
- * It automatically checks if should resolve promise or not, calls resolve strategy, checks if should return new or signleton etc, resolves
28
- * dependencies etc.
29
- *
30
- * @param filter - files to look at, uses glob pattern to search
31
- * @param configPath - dir paths taken from app config eg. "system.dirs.controllers". Path MUST be avaible in configuration
32
- *
33
- */
34
- export declare function ResolveFromFiles(filter: string, configPath: string, typeMatcher?: (fileName: string) => string): (target: any, propertyKey: string | symbol) => void;
1
+ import { Exception } from '@spinajs/exceptions';
2
+ export * from 'typescript-mix';
3
+ /**
4
+ * Exception thrown when some error during reflection occurs
5
+ */
6
+ export declare class ReflectionException extends Exception {
7
+ }
8
+ /**
9
+ * Helper class for extracting various information from typescript source code
10
+ */
11
+ export declare class TypescriptCompiler {
12
+ private tsFile;
13
+ private compiled;
14
+ constructor(filename: string);
15
+ /**
16
+ *
17
+ * Extracts all members info from typescript class eg. method name, parameters, return types etc.
18
+ *
19
+ * @param className - name of class to parse
20
+ */
21
+ getClassMembers(className: string): Map<string, any>;
22
+ private walkClassNode;
23
+ private walkMemberNode;
24
+ }
25
+ /**
26
+ * Returns resolved instances of classes from specified files.
27
+ * It automatically checks if should resolve promise or not, calls resolve strategy, checks if should return new or signleton etc, resolves
28
+ * dependencies etc.
29
+ *
30
+ * @param filter - files to look at, uses glob pattern to search
31
+ * @param configPath - dir paths taken from app config eg. "system.dirs.controllers". Path MUST be avaible in configuration
32
+ *
33
+ */
34
+ export declare function ResolveFromFiles(filter: string, configPath: string, typeMatcher?: (fileName: string) => string): (target: any, propertyKey: string | symbol) => void;
35
35
  //# sourceMappingURL=index.d.ts.map
package/lib/cjs/index.js CHANGED
@@ -1,182 +1,182 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- var __importDefault = (this && this.__importDefault) || function (mod) {
29
- return (mod && mod.__esModule) ? mod : { "default": mod };
30
- };
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.ResolveFromFiles = exports.TypescriptCompiler = exports.ReflectionException = void 0;
33
- const fs = __importStar(require("fs"));
34
- const glob_1 = __importDefault(require("glob"));
35
- const path = __importStar(require("path"));
36
- const typescript_1 = __importDefault(require("typescript"));
37
- const lodash_1 = __importDefault(require("lodash"));
38
- const configuration_common_1 = require("@spinajs/configuration-common");
39
- const di_1 = require("@spinajs/di");
40
- const exceptions_1 = require("@spinajs/exceptions");
41
- const log_common_1 = require("@spinajs/log-common");
42
- __exportStar(require("typescript-mix"), exports);
43
- /**
44
- * Exception thrown when some error during reflection occurs
45
- */
46
- class ReflectionException extends exceptions_1.Exception {
47
- }
48
- exports.ReflectionException = ReflectionException;
49
- /**
50
- * Helper class for extracting various information from typescript source code
51
- */
52
- class TypescriptCompiler {
53
- constructor(filename) {
54
- this.tsFile = filename;
55
- this.compiled = typescript_1.default.createProgram([this.tsFile], {
56
- module: typescript_1.default.ModuleKind.NodeNext,
57
- target: typescript_1.default.ScriptTarget.Latest,
58
- });
59
- }
60
- /**
61
- *
62
- * Extracts all members info from typescript class eg. method name, parameters, return types etc.
63
- *
64
- * @param className - name of class to parse
65
- */
66
- getClassMembers(className) {
67
- const members = new Map();
68
- const sourceFile = this.compiled.getSourceFile(this.tsFile);
69
- // Walk the tree to search for classes
70
- typescript_1.default.forEachChild(sourceFile, this.walkClassNode(className, this.walkMemberNode((method) => {
71
- // method.name.getText() returns null ?
72
- // UGLY HACK FOR THIS
73
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
74
- members.set(method.name.text, method);
75
- })));
76
- return members;
77
- }
78
- walkClassNode(className, callback) {
79
- return (node) => {
80
- if (node.kind === typescript_1.default.SyntaxKind.ClassDeclaration) {
81
- const cldecl = node;
82
- if (cldecl.name.text === className) {
83
- callback(cldecl);
84
- }
85
- }
86
- };
87
- }
88
- walkMemberNode(callback) {
89
- return (node) => {
90
- for (const member of node.members) {
91
- if (member.kind === typescript_1.default.SyntaxKind.MethodDeclaration) {
92
- const method = member;
93
- callback(method);
94
- }
95
- }
96
- };
97
- }
98
- }
99
- exports.TypescriptCompiler = TypescriptCompiler;
100
- /**
101
- * Returns resolved instances of classes from specified files.
102
- * It automatically checks if should resolve promise or not, calls resolve strategy, checks if should return new or signleton etc, resolves
103
- * dependencies etc.
104
- *
105
- * @param filter - files to look at, uses glob pattern to search
106
- * @param configPath - dir paths taken from app config eg. "system.dirs.controllers". Path MUST be avaible in configuration
107
- *
108
- */
109
- function ResolveFromFiles(filter, configPath, typeMatcher) {
110
- return _listOrResolveFromFiles(filter, configPath, typeMatcher);
111
- }
112
- exports.ResolveFromFiles = ResolveFromFiles;
113
- function _listOrResolveFromFiles(filter, configPath, typeMatcher) {
114
- return (target, propertyKey) => {
115
- if (!filter) {
116
- throw new exceptions_1.InvalidArgument('filter parameter is null or empty');
117
- }
118
- if (!configPath) {
119
- throw new exceptions_1.InvalidArgument('configPath parameter is null or empty');
120
- }
121
- let instances = null;
122
- const getter = () => {
123
- if (!instances) {
124
- instances = _loadInstances();
125
- }
126
- return instances;
127
- };
128
- Object.defineProperty(target, propertyKey, {
129
- enumerable: true,
130
- get: getter,
131
- });
132
- async function _loadInstances() {
133
- const config = di_1.DI.get(configuration_common_1.Configuration);
134
- const logger = di_1.DI.resolve(log_common_1.Log, ['reflection']);
135
- let directories = config.get(configPath);
136
- if (!directories || directories.length === 0) {
137
- return [];
138
- }
139
- if (!Array.isArray(directories)) {
140
- directories = [directories];
141
- }
142
- // eslint-disable -next-line @typescript-eslint/await-thenable
143
- const fPromises = lodash_1.default.uniq(directories)
144
- .filter((d) => {
145
- /* eslint-disable */
146
- const exists = fs.existsSync(path.normalize(d));
147
- if (!exists) {
148
- logger.warn(`Directory ${d} not exists`);
149
- }
150
- return exists;
151
- })
152
- .flatMap((d) => glob_1.default.sync(path.join(d, filter).replace(/\\/g, '/')))
153
- .flatMap((f) => {
154
- logger.trace(`Loading file ${f}`);
155
- return di_1.DI.__spinajs_require__(f).then((fTypes) => {
156
- for (const key of Object.keys(fTypes)) {
157
- const nameToResolve = typeMatcher ? typeMatcher(path.parse(f).name, key) : key;
158
- const type = fTypes[`${nameToResolve}`];
159
- if (type.prototype instanceof di_1.AsyncService) {
160
- return di_1.DI.resolve(type).then((instance) => {
161
- return {
162
- file: f,
163
- instance,
164
- name: nameToResolve,
165
- type,
166
- };
167
- });
168
- }
169
- return Promise.resolve({
170
- file: f,
171
- instance: di_1.DI.resolve(type),
172
- name: nameToResolve,
173
- type,
174
- });
175
- }
176
- });
177
- });
178
- return Promise.all(fPromises);
179
- }
180
- };
181
- }
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ var __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.ResolveFromFiles = exports.TypescriptCompiler = exports.ReflectionException = void 0;
33
+ const fs = __importStar(require("fs"));
34
+ const glob_1 = __importDefault(require("glob"));
35
+ const path = __importStar(require("path"));
36
+ const typescript_1 = __importDefault(require("typescript"));
37
+ const lodash_1 = __importDefault(require("lodash"));
38
+ const configuration_common_1 = require("@spinajs/configuration-common");
39
+ const di_1 = require("@spinajs/di");
40
+ const exceptions_1 = require("@spinajs/exceptions");
41
+ const log_common_1 = require("@spinajs/log-common");
42
+ __exportStar(require("typescript-mix"), exports);
43
+ /**
44
+ * Exception thrown when some error during reflection occurs
45
+ */
46
+ class ReflectionException extends exceptions_1.Exception {
47
+ }
48
+ exports.ReflectionException = ReflectionException;
49
+ /**
50
+ * Helper class for extracting various information from typescript source code
51
+ */
52
+ class TypescriptCompiler {
53
+ constructor(filename) {
54
+ this.tsFile = filename;
55
+ this.compiled = typescript_1.default.createProgram([this.tsFile], {
56
+ module: typescript_1.default.ModuleKind.NodeNext,
57
+ target: typescript_1.default.ScriptTarget.Latest,
58
+ });
59
+ }
60
+ /**
61
+ *
62
+ * Extracts all members info from typescript class eg. method name, parameters, return types etc.
63
+ *
64
+ * @param className - name of class to parse
65
+ */
66
+ getClassMembers(className) {
67
+ const members = new Map();
68
+ const sourceFile = this.compiled.getSourceFile(this.tsFile);
69
+ // Walk the tree to search for classes
70
+ typescript_1.default.forEachChild(sourceFile, this.walkClassNode(className, this.walkMemberNode((method) => {
71
+ // method.name.getText() returns null ?
72
+ // UGLY HACK FOR THIS
73
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
74
+ members.set(method.name.text, method);
75
+ })));
76
+ return members;
77
+ }
78
+ walkClassNode(className, callback) {
79
+ return (node) => {
80
+ if (node.kind === typescript_1.default.SyntaxKind.ClassDeclaration) {
81
+ const cldecl = node;
82
+ if (cldecl.name.text === className) {
83
+ callback(cldecl);
84
+ }
85
+ }
86
+ };
87
+ }
88
+ walkMemberNode(callback) {
89
+ return (node) => {
90
+ for (const member of node.members) {
91
+ if (member.kind === typescript_1.default.SyntaxKind.MethodDeclaration) {
92
+ const method = member;
93
+ callback(method);
94
+ }
95
+ }
96
+ };
97
+ }
98
+ }
99
+ exports.TypescriptCompiler = TypescriptCompiler;
100
+ /**
101
+ * Returns resolved instances of classes from specified files.
102
+ * It automatically checks if should resolve promise or not, calls resolve strategy, checks if should return new or signleton etc, resolves
103
+ * dependencies etc.
104
+ *
105
+ * @param filter - files to look at, uses glob pattern to search
106
+ * @param configPath - dir paths taken from app config eg. "system.dirs.controllers". Path MUST be avaible in configuration
107
+ *
108
+ */
109
+ function ResolveFromFiles(filter, configPath, typeMatcher) {
110
+ return _listOrResolveFromFiles(filter, configPath, typeMatcher);
111
+ }
112
+ exports.ResolveFromFiles = ResolveFromFiles;
113
+ function _listOrResolveFromFiles(filter, configPath, typeMatcher) {
114
+ return (target, propertyKey) => {
115
+ if (!filter) {
116
+ throw new exceptions_1.InvalidArgument('filter parameter is null or empty');
117
+ }
118
+ if (!configPath) {
119
+ throw new exceptions_1.InvalidArgument('configPath parameter is null or empty');
120
+ }
121
+ let instances = null;
122
+ const getter = () => {
123
+ if (!instances) {
124
+ instances = _loadInstances();
125
+ }
126
+ return instances;
127
+ };
128
+ Object.defineProperty(target, propertyKey, {
129
+ enumerable: true,
130
+ get: getter,
131
+ });
132
+ async function _loadInstances() {
133
+ const config = di_1.DI.get(configuration_common_1.Configuration);
134
+ const logger = di_1.DI.resolve(log_common_1.Log, ['reflection']);
135
+ let directories = config.get(configPath);
136
+ if (!directories || directories.length === 0) {
137
+ return [];
138
+ }
139
+ if (!Array.isArray(directories)) {
140
+ directories = [directories];
141
+ }
142
+ // eslint-disable -next-line @typescript-eslint/await-thenable
143
+ const fPromises = lodash_1.default.uniq(directories)
144
+ .filter((d) => {
145
+ /* eslint-disable */
146
+ const exists = fs.existsSync(path.normalize(d));
147
+ if (!exists) {
148
+ logger.warn(`Directory ${d} not exists`);
149
+ }
150
+ return exists;
151
+ })
152
+ .flatMap((d) => glob_1.default.sync(path.join(d, filter).replace(/\\/g, '/')))
153
+ .flatMap((f) => {
154
+ logger.trace(`Loading file ${f}`);
155
+ return di_1.DI.__spinajs_require__(f).then((fTypes) => {
156
+ for (const key of Object.keys(fTypes)) {
157
+ const nameToResolve = typeMatcher ? typeMatcher(path.parse(f).name, key) : key;
158
+ const type = fTypes[`${nameToResolve}`];
159
+ if (type.prototype instanceof di_1.AsyncService) {
160
+ return di_1.DI.resolve(type).then((instance) => {
161
+ return {
162
+ file: f,
163
+ instance,
164
+ name: nameToResolve,
165
+ type,
166
+ };
167
+ });
168
+ }
169
+ return Promise.resolve({
170
+ file: f,
171
+ instance: di_1.DI.resolve(type),
172
+ name: nameToResolve,
173
+ type,
174
+ });
175
+ }
176
+ });
177
+ });
178
+ return Promise.all(fPromises);
179
+ }
180
+ };
181
+ }
182
182
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- export * from 'typescript-mix';
1
+ export * from 'typescript-mix';
2
2
  //# sourceMappingURL=index.browser.d.ts.map
@@ -1,5 +1,5 @@
1
- // expose only use() to allow mixins
2
- // all typescript compilation stuff is
3
- // disablbed on browser
4
- export * from 'typescript-mix';
1
+ // expose only use() to allow mixins
2
+ // all typescript compilation stuff is
3
+ // disablbed on browser
4
+ export * from 'typescript-mix';
5
5
  //# sourceMappingURL=index.browser.js.map
@@ -1,35 +1,35 @@
1
- import { Exception } from '@spinajs/exceptions';
2
- export * from 'typescript-mix';
3
- /**
4
- * Exception thrown when some error during reflection occurs
5
- */
6
- export declare class ReflectionException extends Exception {
7
- }
8
- /**
9
- * Helper class for extracting various information from typescript source code
10
- */
11
- export declare class TypescriptCompiler {
12
- private tsFile;
13
- private compiled;
14
- constructor(filename: string);
15
- /**
16
- *
17
- * Extracts all members info from typescript class eg. method name, parameters, return types etc.
18
- *
19
- * @param className - name of class to parse
20
- */
21
- getClassMembers(className: string): Map<string, any>;
22
- private walkClassNode;
23
- private walkMemberNode;
24
- }
25
- /**
26
- * Returns resolved instances of classes from specified files.
27
- * It automatically checks if should resolve promise or not, calls resolve strategy, checks if should return new or signleton etc, resolves
28
- * dependencies etc.
29
- *
30
- * @param filter - files to look at, uses glob pattern to search
31
- * @param configPath - dir paths taken from app config eg. "system.dirs.controllers". Path MUST be avaible in configuration
32
- *
33
- */
34
- export declare function ResolveFromFiles(filter: string, configPath: string, typeMatcher?: (fileName: string) => string): (target: any, propertyKey: string | symbol) => void;
1
+ import { Exception } from '@spinajs/exceptions';
2
+ export * from 'typescript-mix';
3
+ /**
4
+ * Exception thrown when some error during reflection occurs
5
+ */
6
+ export declare class ReflectionException extends Exception {
7
+ }
8
+ /**
9
+ * Helper class for extracting various information from typescript source code
10
+ */
11
+ export declare class TypescriptCompiler {
12
+ private tsFile;
13
+ private compiled;
14
+ constructor(filename: string);
15
+ /**
16
+ *
17
+ * Extracts all members info from typescript class eg. method name, parameters, return types etc.
18
+ *
19
+ * @param className - name of class to parse
20
+ */
21
+ getClassMembers(className: string): Map<string, any>;
22
+ private walkClassNode;
23
+ private walkMemberNode;
24
+ }
25
+ /**
26
+ * Returns resolved instances of classes from specified files.
27
+ * It automatically checks if should resolve promise or not, calls resolve strategy, checks if should return new or signleton etc, resolves
28
+ * dependencies etc.
29
+ *
30
+ * @param filter - files to look at, uses glob pattern to search
31
+ * @param configPath - dir paths taken from app config eg. "system.dirs.controllers". Path MUST be avaible in configuration
32
+ *
33
+ */
34
+ export declare function ResolveFromFiles(filter: string, configPath: string, typeMatcher?: (fileName: string) => string): (target: any, propertyKey: string | symbol) => void;
35
35
  //# sourceMappingURL=index.d.ts.map