typescript-class-helpers 21.0.32 → 21.0.35
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/browser/fesm2022/typescript-class-helpers-browser.mjs +119 -559
- package/browser/fesm2022/typescript-class-helpers-browser.mjs.map +1 -1
- package/browser/package.json +1 -1
- package/browser/types/typescript-class-helpers-browser.d.ts +13 -148
- package/browser-prod/fesm2022/typescript-class-helpers-browser.mjs +94 -529
- package/browser-prod/fesm2022/typescript-class-helpers-browser.mjs.map +1 -1
- package/browser-prod/package.json +1 -1
- package/browser-prod/types/typescript-class-helpers-browser.d.ts +12 -139
- package/browser-prod.split-namespaces.json +19 -29
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/index.d.ts +1 -48
- package/lib/index.js +15 -197
- package/lib/index.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/typescript-class-helpers.d.ts +18 -0
- package/lib/typescript-class-helpers.js +182 -0
- package/lib/typescript-class-helpers.js.map +1 -0
- package/lib-prod/build-info._auto-generated_.d.ts +1 -1
- package/lib-prod/build-info._auto-generated_.js +1 -1
- package/lib-prod/index.d.ts +1 -48
- package/lib-prod/index.js +1 -193
- package/lib-prod/index.js.map +1 -1
- package/lib-prod/package.json +1 -1
- package/lib-prod/typescript-class-helpers.d.ts +16 -0
- package/lib-prod/typescript-class-helpers.js +168 -0
- package/lib-prod/typescript-class-helpers.js.map +1 -0
- package/lib-prod.split-namespaces.json +19 -29
- package/package.json +1 -1
- package/websql/fesm2022/typescript-class-helpers-websql.mjs +119 -558
- package/websql/fesm2022/typescript-class-helpers-websql.mjs.map +1 -1
- package/websql/package.json +1 -1
- package/websql/types/typescript-class-helpers-websql.d.ts +13 -149
- package/websql-prod/fesm2022/typescript-class-helpers-websql.mjs +94 -528
- package/websql-prod/fesm2022/typescript-class-helpers-websql.mjs.map +1 -1
- package/websql-prod/package.json +1 -1
- package/websql-prod/types/typescript-class-helpers-websql.d.ts +12 -140
- package/websql-prod.split-namespaces.json +19 -29
- package/lib/classname.d.ts +0 -16
- package/lib/classname.js +0 -198
- package/lib/classname.js.map +0 -1
- package/lib/describe-class.d.ts +0 -6
- package/lib/describe-class.js +0 -77
- package/lib/describe-class.js.map +0 -1
- package/lib/errors-messages.d.ts +0 -1
- package/lib/errors-messages.js +0 -15
- package/lib/errors-messages.js.map +0 -1
- package/lib/models.d.ts +0 -83
- package/lib/models.js +0 -63
- package/lib/models.js.map +0 -1
- package/lib/registerd-db.d.ts +0 -5
- package/lib/registerd-db.js +0 -8
- package/lib/registerd-db.js.map +0 -1
- package/lib/set-class-name.d.ts +0 -2
- package/lib/set-class-name.js +0 -100
- package/lib/set-class-name.js.map +0 -1
- package/lib/storage.d.ts +0 -1
- package/lib/storage.js +0 -27
- package/lib/storage.js.map +0 -1
- package/lib/symbols.d.ts +0 -7
- package/lib/symbols.js +0 -12
- package/lib/symbols.js.map +0 -1
- package/lib-prod/classname.d.ts +0 -14
- package/lib-prod/classname.js +0 -186
- package/lib-prod/classname.js.map +0 -1
- package/lib-prod/describe-class.d.ts +0 -6
- package/lib-prod/describe-class.js +0 -73
- package/lib-prod/describe-class.js.map +0 -1
- package/lib-prod/errors-messages.d.ts +0 -1
- package/lib-prod/errors-messages.js +0 -12
- package/lib-prod/errors-messages.js.map +0 -1
- package/lib-prod/models.d.ts +0 -81
- package/lib-prod/models.js +0 -55
- package/lib-prod/models.js.map +0 -1
- package/lib-prod/registerd-db.d.ts +0 -5
- package/lib-prod/registerd-db.js +0 -5
- package/lib-prod/registerd-db.js.map +0 -1
- package/lib-prod/set-class-name.d.ts +0 -2
- package/lib-prod/set-class-name.js +0 -97
- package/lib-prod/set-class-name.js.map +0 -1
- package/lib-prod/storage.d.ts +0 -1
- package/lib-prod/storage.js +0 -24
- package/lib-prod/storage.js.map +0 -1
- package/lib-prod/symbols.d.ts +0 -7
- package/lib-prod/symbols.js +0 -9
- package/lib-prod/symbols.js.map +0 -1
|
@@ -1,227 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ___NS__isNil, ___NS__isString, ___NS__isFunction, Helpers__NS__log, CoreModels__NS__ClassNameStaticProperty, ___NS__isUndefined, ___NS__isNull, ___NS__uniq } from 'tnp-core/browser-prod';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated
|
|
5
|
-
*/
|
|
6
|
-
class Models__NS__ParamConfig {
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated
|
|
10
|
-
*/
|
|
11
|
-
class Models__NS__MethodConfig {
|
|
12
|
-
constructor() {
|
|
13
|
-
/* */
|
|
14
|
-
/* */
|
|
15
|
-
this.parameters = {};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated
|
|
20
|
-
*/
|
|
21
|
-
class Models__NS__ClassConfig {
|
|
22
|
-
constructor() {
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
this.singleton = void 0;
|
|
25
|
-
this.injections = [];
|
|
26
|
-
this.vChildren = [];
|
|
27
|
-
this.methods = {};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
//end of namespace Models
|
|
31
|
-
|
|
32
|
-
const SYMBOL = {
|
|
33
|
-
MODELS_MAPPING: Symbol(),
|
|
34
|
-
DEFAULT_MODEL: Symbol(),
|
|
35
|
-
STORAGE: 'classesstorage',
|
|
36
|
-
CLASSES: 'classes',
|
|
37
|
-
ClassNameStaticProperty: CoreModels__NS__ClassNameStaticProperty,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
function defaultValues() {
|
|
41
|
-
return ___NS__cloneDeep({
|
|
42
|
-
[SYMBOL.CLASSES]: []
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function getStorage(property) {
|
|
46
|
-
/* */
|
|
47
|
-
/* */
|
|
48
|
-
/* */
|
|
49
|
-
/* */
|
|
50
|
-
if (typeof property === 'string') {
|
|
51
|
-
const storageInClassStaticProp = getStorage();
|
|
52
|
-
return storageInClassStaticProp[property];
|
|
53
|
-
}
|
|
54
|
-
if (typeof defaultValues.prototype[SYMBOL.STORAGE] === 'undefined') {
|
|
55
|
-
defaultValues.prototype[SYMBOL.STORAGE] = defaultValues();
|
|
56
|
-
}
|
|
57
|
-
return defaultValues.prototype[SYMBOL.STORAGE];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function getClasses$1() {
|
|
61
|
-
const s = getStorage();
|
|
62
|
-
return s[SYMBOL.CLASSES];
|
|
63
|
-
}
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
function setClassName(target, className, options) {
|
|
66
|
-
let { classFamily, uniqueKey, classNameInBrowser, singleton } = options || {
|
|
67
|
-
classFamily: void 0,
|
|
68
|
-
uniqueKey: 'id',
|
|
69
|
-
classNameInBrowser: void 0,
|
|
70
|
-
singleton: void 0,
|
|
71
|
-
autoinstance: false
|
|
72
|
-
};
|
|
73
|
-
if (!___NS__isUndefined(singleton) && ___NS__isBoolean(singleton) && singleton) {
|
|
74
|
-
singleton = 'first-instance';
|
|
75
|
-
}
|
|
76
|
-
if (!uniqueKey) {
|
|
77
|
-
uniqueKey = 'id';
|
|
78
|
-
}
|
|
79
|
-
if (target) {
|
|
80
|
-
const config = ___NS__first(CLASSNAME__NS__getClassConfig(target));
|
|
81
|
-
config.className = className;
|
|
82
|
-
config.uniqueKey = uniqueKey;
|
|
83
|
-
config.classNameInBrowser = classNameInBrowser;
|
|
84
|
-
// console.log(`Setting class Name to "${target.name}"`)
|
|
85
|
-
}
|
|
86
|
-
const existed = getClasses$1()
|
|
87
|
-
.find(f => f.className === className);
|
|
88
|
-
if (existed) {
|
|
89
|
-
existed.target = target;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
const res = {
|
|
93
|
-
className,
|
|
94
|
-
classNameInBrowser,
|
|
95
|
-
target,
|
|
96
|
-
uniqueKey,
|
|
97
|
-
classFamily
|
|
98
|
-
};
|
|
99
|
-
if (___NS__isUndefined(classFamily)) {
|
|
100
|
-
Object.defineProperty(res, 'classFamily', {
|
|
101
|
-
get: function () {
|
|
102
|
-
const parent = Object.getPrototypeOf(target);
|
|
103
|
-
if (!___NS__isFunction(parent) || parent.name === 'Object' || parent.name === '') {
|
|
104
|
-
return className;
|
|
105
|
-
}
|
|
106
|
-
const classNameNew = CLASSNAME__NS__getClassName(parent);
|
|
107
|
-
return CLASSNAME__NS__getClassFamilyByClassName(classNameNew);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
getClasses$1().push(res);
|
|
112
|
-
}
|
|
113
|
-
const Original = target;
|
|
114
|
-
if (singleton === 'first-instance' || singleton === 'last-instance') {
|
|
115
|
-
const obj = {
|
|
116
|
-
// @ts-ignore
|
|
117
|
-
decoratedConstructor: function (...args) {
|
|
118
|
-
// console.log(`DECORATED CONSTRUCTOR OF ${Original.name}`)
|
|
119
|
-
const context = Original.apply(this, args);
|
|
120
|
-
const existedSingleton = CLASS.getSingleton(Original);
|
|
121
|
-
if (!existedSingleton || singleton === 'last-instance') {
|
|
122
|
-
CLASS.setSingletonObj(Original, this);
|
|
123
|
-
CLASS.setSingletonObj(obj.decoratedConstructor, this);
|
|
124
|
-
// console.log(`Singleton created for "${className}", mode: ${singleton} `);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
// console.log('ingleton exists')
|
|
128
|
-
}
|
|
129
|
-
return context;
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
// copy prototype so intanceof operator still works
|
|
133
|
-
obj.decoratedConstructor.prototype = Original.prototype;
|
|
134
|
-
// @ts-ignore
|
|
135
|
-
Object.keys(Original).forEach((name) => { obj.decoratedConstructor[name] = Original[name]; });
|
|
136
|
-
Object.defineProperty(obj.decoratedConstructor, 'name', {
|
|
137
|
-
value: className,
|
|
138
|
-
configurable: true,
|
|
139
|
-
});
|
|
140
|
-
// (obj.decoratedConstructor as any).name = className;
|
|
141
|
-
// console.log('return new contruor', decoratedConstructor)
|
|
142
|
-
return obj.decoratedConstructor;
|
|
143
|
-
}
|
|
144
|
-
else if (singleton === 'autoinstance') {
|
|
145
|
-
// console.log(`AUTOINSTANCE FOR ${target.name}`)
|
|
146
|
-
const auto = new Original();
|
|
147
|
-
CLASS.setSingletonObj(Original, auto);
|
|
148
|
-
// console.log(`Singleton created for "${className}", mode: ${singleton} `)
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const registerd = {
|
|
153
|
-
configs: [],
|
|
154
|
-
classes: [],
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const ERROR_MSG_CLASS_WITHOUT_DECORATOR = `[typescript-class-helpers][getClassName(...)](PRODUCTION MODE ERROR)
|
|
158
|
-
Please use decoartor @CLASSNAME for each entity or controller
|
|
159
|
-
This is preventing class name problem in minified code.
|
|
160
|
-
|
|
161
|
-
import { CLASS } from 'typescript-class-helpers';
|
|
162
|
-
|
|
163
|
-
@CLASS.NAME('ExampleClass')
|
|
164
|
-
class ExampleClass {
|
|
165
|
-
...
|
|
166
|
-
}
|
|
167
|
-
`;
|
|
168
|
-
|
|
169
|
-
/* */
|
|
170
3
|
/* */
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
function CLASSNAME__NS__getClassConfig(target, configs = [], callerTarget) {
|
|
177
|
-
if (!___NS__isFunction(target)) {
|
|
178
|
-
throw `[typescript-class-helper][getClassConfig] Cannot get class config from: ${target}`;
|
|
179
|
-
}
|
|
180
|
-
let config;
|
|
181
|
-
const parentClass = Object.getPrototypeOf(target);
|
|
182
|
-
const isValidParent = ___NS__isFunction(parentClass) && parentClass.name !== '';
|
|
183
|
-
if (registerd.classes.includes(target)) {
|
|
184
|
-
config =
|
|
185
|
-
registerd.configs[registerd.classes.findIndex(c => c === target)];
|
|
4
|
+
const REGISTRY_SYMBOL = Symbol.for('TAON.CLASS_REGISTRY');
|
|
5
|
+
function getRegistry() {
|
|
6
|
+
const g = globalThis;
|
|
7
|
+
if (!g[REGISTRY_SYMBOL]) {
|
|
8
|
+
g[REGISTRY_SYMBOL] = new Map();
|
|
186
9
|
}
|
|
187
|
-
|
|
188
|
-
config = new Models__NS__ClassConfig();
|
|
189
|
-
config.classReference = target;
|
|
190
|
-
registerd.classes.push(target);
|
|
191
|
-
}
|
|
192
|
-
registerd.configs[registerd.classes.findIndex(c => c === target)] = config;
|
|
193
|
-
if (callerTarget) {
|
|
194
|
-
const callerTargetConfig = registerd.configs[registerd.classes.findIndex(c => c === callerTarget)];
|
|
195
|
-
if (!config.vChildren.includes(callerTargetConfig)) {
|
|
196
|
-
config.vChildren.push(callerTargetConfig);
|
|
197
|
-
}
|
|
198
|
-
callerTargetConfig.vParent = config;
|
|
199
|
-
}
|
|
200
|
-
configs.push(config);
|
|
201
|
-
return isValidParent
|
|
202
|
-
? CLASSNAME__NS__getClassConfig(parentClass, configs, target)
|
|
203
|
-
: configs;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* PLEASE PROVIDE NAME AS TYPED STRING, NOT VARIABLE
|
|
207
|
-
* Decorator requred for production mode
|
|
208
|
-
* @param name Name of class
|
|
209
|
-
*/
|
|
210
|
-
function CLASSNAME__NS__CLASSNAME(className, options) {
|
|
211
|
-
return function (target) {
|
|
212
|
-
// console.log(`CLASSNAME Inited ${className}`)
|
|
213
|
-
return setClassName(target, className, options);
|
|
214
|
-
};
|
|
10
|
+
return g[REGISTRY_SYMBOL];
|
|
215
11
|
}
|
|
216
|
-
|
|
12
|
+
const classes = getRegistry();
|
|
13
|
+
function getClassName(target) {
|
|
217
14
|
if (___NS__isNil(target)) {
|
|
218
|
-
// console.log(target);
|
|
219
|
-
// Helpers__NS__warn(`[typescript-class-helpers][getClassName] target is nil`)
|
|
220
15
|
return void 0;
|
|
221
16
|
}
|
|
222
17
|
if (___NS__isString(target)) {
|
|
223
|
-
// console.log(target);
|
|
224
|
-
Helpers__NS__log(`[typescript-class-helpers][getClassName] target is string: '${target}', produciton: ${production}`);
|
|
225
18
|
return target;
|
|
226
19
|
}
|
|
227
20
|
if (target === Date) {
|
|
@@ -235,80 +28,71 @@ function CLASSNAME__NS__getClassName(target, production = false) {
|
|
|
235
28
|
Helpers__NS__log(`[typescript-class-helpers][getClassName] target is not a class`);
|
|
236
29
|
return void 0;
|
|
237
30
|
}
|
|
238
|
-
if (target[
|
|
239
|
-
return target[
|
|
240
|
-
}
|
|
241
|
-
const configs = CLASSNAME__NS__getClassConfig(target);
|
|
242
|
-
const config = ___NS__first(configs);
|
|
243
|
-
const classNameInBrowser = config?.classNameInBrowser;
|
|
244
|
-
if (UtilsOs__NS__isBrowser && ___NS__isString(classNameInBrowser)) {
|
|
245
|
-
return classNameInBrowser;
|
|
246
|
-
}
|
|
247
|
-
const className = config?.className;
|
|
248
|
-
if (typeof className === 'string') {
|
|
249
|
-
return className;
|
|
250
|
-
}
|
|
251
|
-
if (production) {
|
|
252
|
-
console.log('class without @CLASS.NAME deocrator', target);
|
|
253
|
-
throw new Error(ERROR_MSG_CLASS_WITHOUT_DECORATOR);
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
// Helpers__NS__log('check for ' + target.name)
|
|
257
|
-
// setTimeout(() => {
|
|
258
|
-
// // Helpers__NS__log('check for ' + target.name + ' === ' + config.className)/
|
|
259
|
-
// // TODO this may work, but not yet in singleton/morphi
|
|
260
|
-
// if (!config.className) {
|
|
261
|
-
// if (target?.name && target.name !== 'Object') {
|
|
262
|
-
// ConfigHelpers.log(`[typescript-class-helpers] Please use @CLASS.NAME`
|
|
263
|
-
// + `('${(target?.name && !!target.name) ? target.name : '...'}') decorator for class ${target?.name}`)
|
|
264
|
-
// }
|
|
265
|
-
// }
|
|
266
|
-
// })
|
|
31
|
+
if (!___NS__isNil(target[CoreModels__NS__ClassNameStaticProperty])) {
|
|
32
|
+
return target[CoreModels__NS__ClassNameStaticProperty];
|
|
267
33
|
}
|
|
268
34
|
// special thing when cloning classes
|
|
269
35
|
if (target.name?.startsWith('class_')) {
|
|
270
36
|
return '';
|
|
271
37
|
}
|
|
272
|
-
return
|
|
38
|
+
return;
|
|
273
39
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
// console.log('className',className)
|
|
278
|
-
let c = getClasses().find(c => c.className === className);
|
|
279
|
-
// console.log('c',c)
|
|
280
|
-
if (c) {
|
|
281
|
-
return c.uniqueKey;
|
|
40
|
+
function getFromObject(o) {
|
|
41
|
+
if (___NS__isUndefined(o) || ___NS__isNull(o)) {
|
|
42
|
+
return;
|
|
282
43
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
function CLASSNAME__NS__getClassFamilyByClassName(className) {
|
|
286
|
-
let c = getClasses().find(c => c.className === className);
|
|
287
|
-
// console.log('getClasses()', getClasses())
|
|
288
|
-
if (c) {
|
|
289
|
-
return c.classFamily;
|
|
44
|
+
if (o.constructor) {
|
|
45
|
+
return o.constructor;
|
|
290
46
|
}
|
|
47
|
+
const p = Object.getPrototypeOf(o);
|
|
48
|
+
return p && p.constructor;
|
|
291
49
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
50
|
+
const notAllowedAsMethodName = [
|
|
51
|
+
'length',
|
|
52
|
+
'name',
|
|
53
|
+
'arguments',
|
|
54
|
+
'caller',
|
|
55
|
+
'constructor',
|
|
56
|
+
'apply',
|
|
57
|
+
'bind',
|
|
58
|
+
'call',
|
|
59
|
+
'toString',
|
|
60
|
+
'__defineGetter__',
|
|
61
|
+
'__defineSetter__',
|
|
62
|
+
'hasOwnProperty',
|
|
63
|
+
'__lookupGetter__',
|
|
64
|
+
'__lookupSetter__',
|
|
65
|
+
'isPrototypeOf',
|
|
66
|
+
'propertyIsEnumerable',
|
|
67
|
+
'valueOf',
|
|
68
|
+
'__proto__',
|
|
69
|
+
'toLocaleString',
|
|
70
|
+
];
|
|
71
|
+
//namespace CLASS
|
|
72
|
+
/**
|
|
73
|
+
* PLEASE PROVIDE NAME AS TYPED STRING, NOT VARIABLE
|
|
74
|
+
* Decorator requred for production mode
|
|
75
|
+
* @param name Name of class
|
|
76
|
+
*/
|
|
77
|
+
function CLASS__NS__NAME(className) {
|
|
78
|
+
return function (target) {
|
|
79
|
+
return CLASS__NS__setClassName(target, className);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function CLASS__NS__setName(target, className) {
|
|
83
|
+
CLASS__NS__setClassName(target, className);
|
|
301
84
|
}
|
|
302
|
-
function
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
let c = getClasses().find(c => c.className === className);
|
|
306
|
-
// console.log('c',c)
|
|
307
|
-
if (c && ___NS__isString(c.uniqueKey)) {
|
|
308
|
-
return obj[c.uniqueKey];
|
|
85
|
+
function CLASS__NS__getClassNameFromObjInstanceOrClassFn(target) {
|
|
86
|
+
if (typeof target === 'object') {
|
|
87
|
+
return CLASS__NS__getNameFromObject(target);
|
|
309
88
|
}
|
|
89
|
+
return getClassName(target);
|
|
310
90
|
}
|
|
311
|
-
function
|
|
91
|
+
function CLASS__NS__setClassName(target, className) {
|
|
92
|
+
target[CoreModels__NS__ClassNameStaticProperty] = className;
|
|
93
|
+
classes.set(className, target);
|
|
94
|
+
}
|
|
95
|
+
function CLASS__NS__getBy(className) {
|
|
312
96
|
let res;
|
|
313
97
|
if (Array.isArray(className)) {
|
|
314
98
|
if (className.length !== 1) {
|
|
@@ -332,278 +116,59 @@ function CLASSNAME__NS__getClassBy(className) {
|
|
|
332
116
|
if (className === 'FormData') {
|
|
333
117
|
res = FormData;
|
|
334
118
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
res = c.target;
|
|
338
|
-
}
|
|
339
|
-
// console.log(`getClassBy "${className} return \n\n ${res} \n\n`)
|
|
340
|
-
// @ts-ignore
|
|
341
|
-
return res;
|
|
119
|
+
const classFromMap = classes.get(className);
|
|
120
|
+
return classFromMap ? classFromMap : res;
|
|
342
121
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
* @DEPRECATED
|
|
347
|
-
* Describe fields assigned in class
|
|
348
|
-
*/
|
|
349
|
-
const FRegEx = new RegExp(/(?:this\.)(.+?(?= ))/g);
|
|
350
|
-
function describeFromClassStringify(target, parent = false) {
|
|
351
|
-
// @ts-ignore
|
|
352
|
-
var result = [];
|
|
353
|
-
if (parent) {
|
|
354
|
-
var proto = Object.getPrototypeOf(target.prototype);
|
|
355
|
-
if (proto) {
|
|
356
|
-
// @ts-ignore
|
|
357
|
-
result = result.concat(describeFromClassStringify(proto.constructor, parent));
|
|
358
|
-
}
|
|
122
|
+
function CLASS__NS__getFromObject(o) {
|
|
123
|
+
if (___NS__isUndefined(o) || ___NS__isNull(o)) {
|
|
124
|
+
return;
|
|
359
125
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
// console.log({
|
|
363
|
-
// classString,
|
|
364
|
-
// });
|
|
365
|
-
result = result.concat(matches);
|
|
366
|
-
return result.map(prop => prop
|
|
367
|
-
.replace('this.', '')
|
|
368
|
-
.replace('.', '')
|
|
369
|
-
.replace(')', '')
|
|
370
|
-
.replace('(', ''));
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Describe fields assigne through @DefaultModelWithMapping decorator
|
|
374
|
-
* without functions
|
|
375
|
-
*/
|
|
376
|
-
function describeByDefaultModelsAndMapping(target) {
|
|
377
|
-
let res = {};
|
|
378
|
-
if (target) {
|
|
379
|
-
// @ts-ignore
|
|
380
|
-
if (target[SYMBOL.DEFAULT_MODEL]) {
|
|
381
|
-
// @ts-ignore
|
|
382
|
-
Object.keys(target[SYMBOL.DEFAULT_MODEL])
|
|
383
|
-
.filter(key => {
|
|
384
|
-
// @ts-ignore
|
|
385
|
-
return !___NS__isFunction(target[SYMBOL.DEFAULT_MODEL][key]);
|
|
386
|
-
})
|
|
387
|
-
.forEach(key => {
|
|
388
|
-
// @ts-ignore
|
|
389
|
-
return res[key] = null;
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
// @ts-ignore
|
|
393
|
-
let mapping = target[SYMBOL.MODELS_MAPPING];
|
|
394
|
-
if (___NS__isArray(mapping)) {
|
|
395
|
-
mapping.forEach(m => {
|
|
396
|
-
Object.keys(m)
|
|
397
|
-
.forEach(key => {
|
|
398
|
-
// @ts-ignore
|
|
399
|
-
res[key] = null;
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
else if (mapping) {
|
|
404
|
-
Object.keys(mapping)
|
|
405
|
-
.forEach(key => {
|
|
406
|
-
// @ts-ignore
|
|
407
|
-
res[key] = null;
|
|
408
|
-
});
|
|
409
|
-
}
|
|
126
|
+
if (o.constructor) {
|
|
127
|
+
return o.constructor;
|
|
410
128
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
return propNames;
|
|
129
|
+
const p = Object.getPrototypeOf(o);
|
|
130
|
+
return p && p.constructor;
|
|
414
131
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
static getBy(className) {
|
|
418
|
-
return CLASSNAME__NS__getClassBy(className);
|
|
419
|
-
}
|
|
420
|
-
static getFromObject(o) {
|
|
421
|
-
if (___NS__isUndefined(o) || ___NS__isNull(o)) {
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
if (o.constructor) {
|
|
425
|
-
return o.constructor;
|
|
426
|
-
}
|
|
427
|
-
const p = Object.getPrototypeOf(o);
|
|
428
|
-
return p && p.constructor;
|
|
429
|
-
}
|
|
430
|
-
static getName(target, production = false) {
|
|
431
|
-
return CLASSNAME__NS__getClassName(target, production);
|
|
432
|
-
}
|
|
433
|
-
static getNameFromObject(o) {
|
|
434
|
-
const fnCLass = this.getFromObject(o);
|
|
435
|
-
return this.getName(fnCLass);
|
|
436
|
-
}
|
|
437
|
-
static getConfigs(target) {
|
|
438
|
-
return CLASSNAME__NS__getClassConfig(target);
|
|
439
|
-
}
|
|
440
|
-
static describeProperites(target) {
|
|
441
|
-
const d1 = describeFromClassStringify(target);
|
|
442
|
-
const d2 = describeByDefaultModelsAndMapping(target);
|
|
443
|
-
let uniq = {};
|
|
444
|
-
// @ts-ignore
|
|
445
|
-
d1.concat(d2).forEach(p => uniq[p] = p);
|
|
446
|
-
return Object.keys(uniq)
|
|
447
|
-
.filter(d => !!d)
|
|
448
|
-
.filter(d => typeof target.prototype[d] !== 'function');
|
|
449
|
-
}
|
|
132
|
+
function CLASS__NS__getName(target) {
|
|
133
|
+
return getClassName(target);
|
|
450
134
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
'toString',
|
|
457
|
-
'__defineGetter__',
|
|
458
|
-
'__defineSetter__', 'hasOwnProperty',
|
|
459
|
-
'__lookupGetter__', '__lookupSetter__',
|
|
460
|
-
'isPrototypeOf', 'propertyIsEnumerable',
|
|
461
|
-
'valueOf', '__proto__', 'toLocaleString',
|
|
462
|
-
];
|
|
463
|
-
const getMethodsNames = (classOrClassInstance, allMethodsNames = []) => {
|
|
135
|
+
function CLASS__NS__getNameFromObject(o) {
|
|
136
|
+
const fnCLass = CLASS__NS__getFromObject(o);
|
|
137
|
+
return CLASS__NS__getName(fnCLass);
|
|
138
|
+
}
|
|
139
|
+
const CLASS__NS__getMethodsNames = (classOrClassInstance, allMethodsNames = []) => {
|
|
464
140
|
if (!classOrClassInstance) {
|
|
465
141
|
return allMethodsNames;
|
|
466
142
|
}
|
|
467
143
|
const isClassFunction = ___NS__isFunction(classOrClassInstance);
|
|
468
|
-
const classFun =
|
|
469
|
-
|
|
144
|
+
const classFun = isClassFunction
|
|
145
|
+
? classOrClassInstance
|
|
146
|
+
: Object.getPrototypeOf(classOrClassInstance);
|
|
147
|
+
const objectToCheck = isClassFunction
|
|
148
|
+
? classOrClassInstance?.prototype
|
|
149
|
+
: classOrClassInstance;
|
|
470
150
|
const prototypeObj = Object.getPrototypeOf(objectToCheck || {});
|
|
471
151
|
const properties = ___NS__uniq([
|
|
472
152
|
...Object.getOwnPropertyNames(objectToCheck || {}),
|
|
473
153
|
...Object.getOwnPropertyNames(prototypeObj || {}),
|
|
474
154
|
...Object.keys(objectToCheck || {}),
|
|
475
155
|
...Object.keys(prototypeObj || {}),
|
|
476
|
-
])
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
156
|
+
]).filter(f => !!f && !notAllowedAsMethodName.includes(f));
|
|
157
|
+
properties
|
|
158
|
+
.filter(methodName => typeof objectToCheck[methodName] === 'function')
|
|
159
|
+
.forEach(p => allMethodsNames.push(p));
|
|
160
|
+
if (!classFun ||
|
|
161
|
+
!classFun.constructor ||
|
|
162
|
+
classFun?.constructor?.name === 'Object') {
|
|
480
163
|
return allMethodsNames;
|
|
481
164
|
}
|
|
482
|
-
return
|
|
483
|
-
};
|
|
484
|
-
const CLASS = {
|
|
485
|
-
NAME: CLASSNAME__NS__CLASSNAME,
|
|
486
|
-
setName: setClassName,
|
|
487
|
-
getBy: TchHelpers.getBy,
|
|
488
|
-
/**
|
|
489
|
-
* @deprecated
|
|
490
|
-
*/
|
|
491
|
-
getSingleton(target) {
|
|
492
|
-
if (typeof target !== 'function') {
|
|
493
|
-
console.error(`[typescript-class-helpers][setSingletonObj] Type of target is not a function`);
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
const config = TchHelpers.getConfigs(target)[0];
|
|
497
|
-
// console.log(`getSingleton for ${target.name}: `, config.singleton)
|
|
498
|
-
return config.singleton;
|
|
499
|
-
},
|
|
500
|
-
/**
|
|
501
|
-
* @deprecated
|
|
502
|
-
*/
|
|
503
|
-
setSingletonObj(target, singletonObject) {
|
|
504
|
-
// console.log('SET SINGLETON', singletonObject)
|
|
505
|
-
if (typeof target !== 'function') {
|
|
506
|
-
console.error(`[typescript-class-helpers][setSingletonObj] Type of target is not a function`);
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
if (Array.isArray(singletonObject)) {
|
|
510
|
-
console.error(`[typescript-class-helpers][setSingletonObj] Singleton instance cant be an array`);
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
if (typeof singletonObject !== 'object') {
|
|
514
|
-
console.error(`[typescript-class-helpers][setSingletonObj] Singleton instance cant must be a object`);
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
const className = CLASS.getName(target);
|
|
518
|
-
// console.log(`SINGLETON SET for TARGET ${className}`)
|
|
519
|
-
const config = TchHelpers.getConfigs(target)[0];
|
|
520
|
-
if (config.singleton) {
|
|
521
|
-
console.warn(`[typescript-class-helpers] You are trying to set singleton of "${className}" second time with different object.`);
|
|
522
|
-
}
|
|
523
|
-
config.singleton = singletonObject;
|
|
524
|
-
},
|
|
525
|
-
/**
|
|
526
|
-
* @deprecated
|
|
527
|
-
*/
|
|
528
|
-
getConfigs: TchHelpers.getConfigs,
|
|
529
|
-
/**
|
|
530
|
-
* @deprecated
|
|
531
|
-
*/
|
|
532
|
-
getConfig: (target) => {
|
|
533
|
-
return ___NS__first(TchHelpers.getConfigs(target));
|
|
534
|
-
},
|
|
535
|
-
getMethodsNames(classOrClassInstance) {
|
|
536
|
-
return getMethodsNames(classOrClassInstance);
|
|
537
|
-
},
|
|
538
|
-
getFromObject: TchHelpers.getFromObject,
|
|
539
|
-
getName: TchHelpers.getName,
|
|
540
|
-
getNameFromObject: TchHelpers.getNameFromObject,
|
|
541
|
-
describeProperites: TchHelpers.describeProperites,
|
|
542
|
-
/**
|
|
543
|
-
* @deprecated
|
|
544
|
-
*/
|
|
545
|
-
OBJECT: (obj) => {
|
|
546
|
-
return {
|
|
547
|
-
get indexValue() {
|
|
548
|
-
return CLASSNAME__NS__getObjectIndexValue(obj);
|
|
549
|
-
},
|
|
550
|
-
get indexProperty() {
|
|
551
|
-
return CLASSNAME__NS__getObjectIndexPropertyValue(obj);
|
|
552
|
-
},
|
|
553
|
-
get isClassObject() {
|
|
554
|
-
if (!___NS__isObject(obj) || ___NS__isArray(obj) || ___NS__isRegExp(obj) ||
|
|
555
|
-
___NS__isBuffer(obj) || ___NS__isArrayBuffer(obj)) {
|
|
556
|
-
return false;
|
|
557
|
-
}
|
|
558
|
-
if (___NS__isDate(obj)) {
|
|
559
|
-
return true;
|
|
560
|
-
}
|
|
561
|
-
const className = CLASS.getNameFromObject(obj);
|
|
562
|
-
return ___NS__isString(className) && className !== 'Object';
|
|
563
|
-
},
|
|
564
|
-
isEqual: (anotherObj, compareDeep = false) => {
|
|
565
|
-
if (!CLASS.OBJECT(obj).isClassObject || !CLASS.OBJECT(anotherObj).isClassObject) {
|
|
566
|
-
return false;
|
|
567
|
-
}
|
|
568
|
-
if (obj === anotherObj) {
|
|
569
|
-
// console.log(`EQ v1: , v2: - class1 ${CLASS.getNameFromObject(obj)}, class2 ${CLASS.getNameFromObject(anotherObj)}`, obj, anotherObj)
|
|
570
|
-
return true;
|
|
571
|
-
}
|
|
572
|
-
const v1 = CLASSNAME__NS__getObjectIndexValue(obj);
|
|
573
|
-
const v2 = CLASSNAME__NS__getObjectIndexValue(anotherObj);
|
|
574
|
-
const f1 = CLASSNAME__NS__getObjectClassFamily(obj);
|
|
575
|
-
const f2 = CLASSNAME__NS__getObjectClassFamily(anotherObj);
|
|
576
|
-
const isFamilyDiff = (!___NS__isString(f1) || !___NS__isString(f2) || (f1 !== f2));
|
|
577
|
-
// console.log(`DIFF FAMILY ${isFamilyDiff} v1: ${CLASSNAME__NS__getObjectClassFamily(obj)}, v2: ${CLASSNAME__NS__getObjectClassFamily(anotherObj)} - class1 ${CLASS.getNameFromObject(obj)}, class2 ${CLASS.getNameFromObject(anotherObj)}`)
|
|
578
|
-
if (isFamilyDiff) {
|
|
579
|
-
// console.log(`DIFF v1: ${v1}, v2: ${v2} - class1 ${CLASS.getNameFromObject(obj)}, class2 ${CLASS.getNameFromObject(anotherObj)}`)
|
|
580
|
-
return false;
|
|
581
|
-
}
|
|
582
|
-
if (!CLASS.OBJECT(obj).isClassObject || !CLASS.OBJECT(anotherObj).isClassObject) {
|
|
583
|
-
// console.log(`NOT CLASS v1: ${v1}, v2: ${v2} - class1 ${CLASS.getNameFromObject(obj)}, class2 ${CLASS.getNameFromObject(anotherObj)}`)
|
|
584
|
-
return false;
|
|
585
|
-
}
|
|
586
|
-
// console.log(`v1: ${v1} ,class ${CLASS.getNameFromObject(obj)} ,prop: ${CLASS.OBJECT(obj).indexProperty}`)
|
|
587
|
-
// console.log(`v2: ${v2} ,class ${CLASS.getNameFromObject(anotherObj)} ,prop: ${CLASS.OBJECT(anotherObj).indexProperty}`)
|
|
588
|
-
// console.log(`v1: ${v1}, v2: ${v2} - class1 ${CLASS.getNameFromObject(obj)}, class2 ${CLASS.getNameFromObject(anotherObj)}`)
|
|
589
|
-
// console.log('')
|
|
590
|
-
if ((___NS__isNumber(v1) && ___NS__isNumber(v2)) || (___NS__isString(v1) && ___NS__isString(v2))) {
|
|
591
|
-
const res = (v1 === v2);
|
|
592
|
-
// @ts-ignore
|
|
593
|
-
return res;
|
|
594
|
-
}
|
|
595
|
-
if (compareDeep) {
|
|
596
|
-
return ___NS__isEqual(v1, v2);
|
|
597
|
-
}
|
|
598
|
-
return false;
|
|
599
|
-
}
|
|
600
|
-
};
|
|
601
|
-
}
|
|
165
|
+
return CLASS__NS__getMethodsNames(Object.getPrototypeOf(classFun), allMethodsNames);
|
|
602
166
|
};
|
|
167
|
+
//end of namespace CLASS
|
|
603
168
|
|
|
604
169
|
/**
|
|
605
170
|
* Generated bundle index. Do not edit.
|
|
606
171
|
*/
|
|
607
172
|
|
|
608
|
-
export {
|
|
173
|
+
export { CLASS__NS__NAME, CLASS__NS__getBy, CLASS__NS__getClassNameFromObjInstanceOrClassFn, CLASS__NS__getFromObject, CLASS__NS__getMethodsNames, CLASS__NS__getName, CLASS__NS__getNameFromObject, CLASS__NS__setClassName, CLASS__NS__setName, getClassName, getFromObject };
|
|
609
174
|
//# sourceMappingURL=typescript-class-helpers-browser.mjs.map
|