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