typescript-class-helpers 21.0.25 → 21.0.27
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/package.json +1 -1
- package/browser-prod/package.json +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/package.json +1 -1
- package/lib-prod/{build-info._auto-generated_.ts → build-info._auto-generated_.js} +1 -2
- package/lib-prod/classname.js +185 -0
- package/lib-prod/describe-class.js +72 -0
- package/lib-prod/env/{env.angular-node-app.ts → env.angular-node-app.js} +1 -1
- package/lib-prod/env/{env.docs-webapp.ts → env.docs-webapp.js} +1 -1
- package/lib-prod/env/{env.electron-app.ts → env.electron-app.js} +1 -1
- package/lib-prod/env/{env.mobile-app.ts → env.mobile-app.js} +1 -1
- package/lib-prod/env/{env.npm-lib-and-cli-tool.ts → env.npm-lib-and-cli-tool.js} +1 -1
- package/lib-prod/env/{env.vscode-plugin.ts → env.vscode-plugin.js} +1 -1
- package/lib-prod/{errors-messages.ts → errors-messages.js} +1 -1
- package/lib-prod/{index._auto-generated_.ts → index._auto-generated_.js} +1 -1
- package/lib-prod/index.js +193 -0
- package/lib-prod/models.js +27 -0
- package/lib-prod/package.json +1 -1
- package/lib-prod/registerd-db.js +4 -0
- package/lib-prod/set-class-name.js +96 -0
- package/lib-prod/storage.js +23 -0
- package/lib-prod/symbols.js +8 -0
- package/lib-prod.split-namespaces.json +6 -18
- package/package.json +1 -1
- package/websql/package.json +1 -1
- package/websql-prod/package.json +1 -1
- package/lib-prod/classname.ts +0 -225
- package/lib-prod/describe-class.ts +0 -80
- package/lib-prod/index.ts +0 -223
- package/lib-prod/lib-info.md +0 -8
- package/lib-prod/migrations/migrations-info.md +0 -6
- package/lib-prod/models.ts +0 -88
- package/lib-prod/registerd-db.ts +0 -5
- package/lib-prod/set-class-name.ts +0 -112
- package/lib-prod/storage.ts +0 -29
- package/lib-prod/symbols.ts +0 -9
- /package/lib-prod/env/{index.ts → index.js} +0 -0
package/browser/package.json
CHANGED
|
@@ -25,6 +25,6 @@ exports.CURRENT_PACKAGE_TAON_VERSION = 'v21';
|
|
|
25
25
|
/**
|
|
26
26
|
* Autogenerated by current cli tool. Use *tnp release* to bump version.
|
|
27
27
|
*/
|
|
28
|
-
exports.CURRENT_PACKAGE_VERSION = '21.0.
|
|
28
|
+
exports.CURRENT_PACKAGE_VERSION = '21.0.27';
|
|
29
29
|
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
30
30
|
//# sourceMappingURL=build-info._auto-generated_.js.map
|
package/lib/package.json
CHANGED
|
@@ -22,6 +22,5 @@ export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
|
|
|
22
22
|
/**
|
|
23
23
|
* Autogenerated by current cli tool. Use *tnp release* to bump version.
|
|
24
24
|
*/
|
|
25
|
-
export const CURRENT_PACKAGE_VERSION = '21.0.
|
|
25
|
+
export const CURRENT_PACKAGE_VERSION = '21.0.27';
|
|
26
26
|
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
27
|
-
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { ___NS__first, ___NS__isFunction, ___NS__isNil, ___NS__isString, UtilsOs__NS__isBrowser } from 'tnp-core/lib-prod';
|
|
2
|
+
import { Models } from './models';
|
|
3
|
+
import { SYMBOL } from './symbols';
|
|
4
|
+
import { TchHelpers } from './index';
|
|
5
|
+
import { Helpers__NS__log } from 'tnp-core/lib-prod';
|
|
6
|
+
import { getStorage } from './storage';
|
|
7
|
+
import { setClassName } from './set-class-name';
|
|
8
|
+
import { registerd } from './registerd-db';
|
|
9
|
+
import { ERROR_MSG_CLASS_WITHOUT_DECORATOR } from './errors-messages';
|
|
10
|
+
//#region @backend
|
|
11
|
+
import * as FormData from 'form-data';
|
|
12
|
+
//#endregion
|
|
13
|
+
function getClasses() {
|
|
14
|
+
const s = getStorage();
|
|
15
|
+
return s[SYMBOL.CLASSES];
|
|
16
|
+
}
|
|
17
|
+
//namespace CLASSNAME
|
|
18
|
+
export function CLASSNAME__NS__getClassConfig(target, configs = [], callerTarget) {
|
|
19
|
+
if (!___NS__isFunction(target)) {
|
|
20
|
+
throw `[typescript-class-helper][getClassConfig] Cannot get class config from: ${target}`;
|
|
21
|
+
}
|
|
22
|
+
let config;
|
|
23
|
+
const parentClass = Object.getPrototypeOf(target);
|
|
24
|
+
const isValidParent = ___NS__isFunction(parentClass) && parentClass.name !== '';
|
|
25
|
+
if (registerd.classes.includes(target)) {
|
|
26
|
+
config =
|
|
27
|
+
registerd.configs[registerd.classes.findIndex(c => c === target)];
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
config = new Models.ClassConfig();
|
|
31
|
+
config.classReference = target;
|
|
32
|
+
registerd.classes.push(target);
|
|
33
|
+
}
|
|
34
|
+
registerd.configs[registerd.classes.findIndex(c => c === target)] = config;
|
|
35
|
+
if (callerTarget) {
|
|
36
|
+
const callerTargetConfig = registerd.configs[registerd.classes.findIndex(c => c === callerTarget)];
|
|
37
|
+
if (!config.vChildren.includes(callerTargetConfig)) {
|
|
38
|
+
config.vChildren.push(callerTargetConfig);
|
|
39
|
+
}
|
|
40
|
+
callerTargetConfig.vParent = config;
|
|
41
|
+
}
|
|
42
|
+
configs.push(config);
|
|
43
|
+
return isValidParent
|
|
44
|
+
? CLASSNAME__NS__getClassConfig(parentClass, configs, target)
|
|
45
|
+
: configs;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* PLEASE PROVIDE NAME AS TYPED STRING, NOT VARIABLE
|
|
49
|
+
* Decorator requred for production mode
|
|
50
|
+
* @param name Name of class
|
|
51
|
+
*/
|
|
52
|
+
export function CLASSNAME__NS__CLASSNAME(className, options) {
|
|
53
|
+
return function (target) {
|
|
54
|
+
// console.log(`CLASSNAME Inited ${className}`)
|
|
55
|
+
return setClassName(target, className, options);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function CLASSNAME__NS__getClassName(target, production = false) {
|
|
59
|
+
if (___NS__isNil(target)) {
|
|
60
|
+
// console.log(target);
|
|
61
|
+
// Helpers__NS__warn(`[typescript-class-helpers][getClassName] target is nil`)
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
if (___NS__isString(target)) {
|
|
65
|
+
// console.log(target);
|
|
66
|
+
Helpers__NS__log(`[typescript-class-helpers][getClassName] target is string: '${target}', produciton: ${production}`);
|
|
67
|
+
return target;
|
|
68
|
+
}
|
|
69
|
+
if (target === Date) {
|
|
70
|
+
return 'Date';
|
|
71
|
+
}
|
|
72
|
+
if (target === FormData) {
|
|
73
|
+
return 'FormData';
|
|
74
|
+
}
|
|
75
|
+
if (!___NS__isFunction(target)) {
|
|
76
|
+
// console.log(target);
|
|
77
|
+
Helpers__NS__log(`[typescript-class-helpers][getClassName] target is not a class`);
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
if (target[SYMBOL.ClassNameStaticProperty]) {
|
|
81
|
+
return target[SYMBOL.ClassNameStaticProperty];
|
|
82
|
+
}
|
|
83
|
+
const configs = CLASSNAME__NS__getClassConfig(target);
|
|
84
|
+
const config = ___NS__first(configs);
|
|
85
|
+
const classNameInBrowser = config?.classNameInBrowser;
|
|
86
|
+
if (UtilsOs__NS__isBrowser && ___NS__isString(classNameInBrowser)) {
|
|
87
|
+
return classNameInBrowser;
|
|
88
|
+
}
|
|
89
|
+
const className = config?.className;
|
|
90
|
+
if (typeof className === 'string') {
|
|
91
|
+
return className;
|
|
92
|
+
}
|
|
93
|
+
if (production) {
|
|
94
|
+
console.log('class without @CLASS.NAME deocrator', target);
|
|
95
|
+
throw new Error(ERROR_MSG_CLASS_WITHOUT_DECORATOR);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// Helpers__NS__log('check for ' + target.name)
|
|
99
|
+
// setTimeout(() => {
|
|
100
|
+
// // Helpers__NS__log('check for ' + target.name + ' === ' + config.className)/
|
|
101
|
+
// // TODO this may work, but not yet in singleton/morphi
|
|
102
|
+
// if (!config.className) {
|
|
103
|
+
// if (target?.name && target.name !== 'Object') {
|
|
104
|
+
// ConfigHelpers.log(`[typescript-class-helpers] Please use @CLASS.NAME`
|
|
105
|
+
// + `('${(target?.name && !!target.name) ? target.name : '...'}') decorator for class ${target?.name}`)
|
|
106
|
+
// }
|
|
107
|
+
// }
|
|
108
|
+
// })
|
|
109
|
+
}
|
|
110
|
+
// special thing when cloning classes
|
|
111
|
+
if (target.name?.startsWith('class_')) {
|
|
112
|
+
return '';
|
|
113
|
+
}
|
|
114
|
+
return target.name;
|
|
115
|
+
}
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
export function CLASSNAME__NS__getObjectIndexPropertyValue(obj) {
|
|
118
|
+
const className = TchHelpers.getNameFromObject(obj);
|
|
119
|
+
// console.log('className',className)
|
|
120
|
+
let c = getClasses().find(c => c.className === className);
|
|
121
|
+
// console.log('c',c)
|
|
122
|
+
if (c) {
|
|
123
|
+
return c.uniqueKey;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
export function CLASSNAME__NS__getClassFamilyByClassName(className) {
|
|
128
|
+
let c = getClasses().find(c => c.className === className);
|
|
129
|
+
// console.log('getClasses()', getClasses())
|
|
130
|
+
if (c) {
|
|
131
|
+
return c.classFamily;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// @ts-ignore
|
|
135
|
+
export function CLASSNAME__NS__getObjectClassFamily(obj) {
|
|
136
|
+
const className = TchHelpers.getNameFromObject(obj);
|
|
137
|
+
// console.log('className',className)
|
|
138
|
+
let c = getClasses().find(c => c.className === className);
|
|
139
|
+
// console.log('c',c)
|
|
140
|
+
if (c) {
|
|
141
|
+
return c.classFamily;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export function CLASSNAME__NS__getObjectIndexValue(obj) {
|
|
145
|
+
const className = TchHelpers.getNameFromObject(obj);
|
|
146
|
+
// console.log('className',className)
|
|
147
|
+
let c = getClasses().find(c => c.className === className);
|
|
148
|
+
// console.log('c',c)
|
|
149
|
+
if (c && ___NS__isString(c.uniqueKey)) {
|
|
150
|
+
return obj[c.uniqueKey];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export function CLASSNAME__NS__getClassBy(className) {
|
|
154
|
+
let res;
|
|
155
|
+
if (Array.isArray(className)) {
|
|
156
|
+
if (className.length !== 1) {
|
|
157
|
+
throw `Mapping error... please use proper class names:
|
|
158
|
+
{
|
|
159
|
+
propertyObject: 'MyClassName',
|
|
160
|
+
propertyWithArray: ['MyClassName']
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
`;
|
|
164
|
+
}
|
|
165
|
+
className = className[0];
|
|
166
|
+
}
|
|
167
|
+
if (typeof className === 'function') {
|
|
168
|
+
// TODO QUICK_FIX
|
|
169
|
+
res = className;
|
|
170
|
+
}
|
|
171
|
+
if (className === 'Date') {
|
|
172
|
+
res = Date;
|
|
173
|
+
}
|
|
174
|
+
if (className === 'FormData') {
|
|
175
|
+
res = FormData;
|
|
176
|
+
}
|
|
177
|
+
let c = getClasses().find(c => c.className === className);
|
|
178
|
+
if (c) {
|
|
179
|
+
res = c.target;
|
|
180
|
+
}
|
|
181
|
+
// console.log(`getClassBy "${className} return \n\n ${res} \n\n`)
|
|
182
|
+
// @ts-ignore
|
|
183
|
+
return res;
|
|
184
|
+
}
|
|
185
|
+
//end of namespace CLASSNAME
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ___NS__isArray, ___NS__isFunction } from 'tnp-core/lib-prod';
|
|
2
|
+
import { SYMBOL } from './symbols';
|
|
3
|
+
/**
|
|
4
|
+
* @DEPRECATED
|
|
5
|
+
* Describe fields assigned in class
|
|
6
|
+
*/
|
|
7
|
+
const FRegEx = new RegExp(/(?:this\.)(.+?(?= ))/g);
|
|
8
|
+
export function describeFromClassStringify(target, parent = false) {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
var result = [];
|
|
11
|
+
if (parent) {
|
|
12
|
+
var proto = Object.getPrototypeOf(target.prototype);
|
|
13
|
+
if (proto) {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
result = result.concat(describeFromClassStringify(proto.constructor, parent));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const classString = target.toString();
|
|
19
|
+
const matches = classString.match(FRegEx) || [];
|
|
20
|
+
// console.log({
|
|
21
|
+
// classString,
|
|
22
|
+
// });
|
|
23
|
+
result = result.concat(matches);
|
|
24
|
+
return result.map(prop => prop
|
|
25
|
+
.replace('this.', '')
|
|
26
|
+
.replace('.', '')
|
|
27
|
+
.replace(')', '')
|
|
28
|
+
.replace('(', ''));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Describe fields assigne through @DefaultModelWithMapping decorator
|
|
32
|
+
* without functions
|
|
33
|
+
*/
|
|
34
|
+
export function describeByDefaultModelsAndMapping(target) {
|
|
35
|
+
let res = {};
|
|
36
|
+
if (target) {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
if (target[SYMBOL.DEFAULT_MODEL]) {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
Object.keys(target[SYMBOL.DEFAULT_MODEL])
|
|
41
|
+
.filter(key => {
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
return !___NS__isFunction(target[SYMBOL.DEFAULT_MODEL][key]);
|
|
44
|
+
})
|
|
45
|
+
.forEach(key => {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
return res[key] = null;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
let mapping = target[SYMBOL.MODELS_MAPPING];
|
|
52
|
+
if (___NS__isArray(mapping)) {
|
|
53
|
+
mapping.forEach(m => {
|
|
54
|
+
Object.keys(m)
|
|
55
|
+
.forEach(key => {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
res[key] = null;
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else if (mapping) {
|
|
62
|
+
Object.keys(mapping)
|
|
63
|
+
.forEach(key => {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
res[key] = null;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
let propNames = Object.keys(res).filter(f => !!f);
|
|
70
|
+
propNames = (!propNames.includes('id') ? ['id'] : []).concat(propNames);
|
|
71
|
+
return propNames;
|
|
72
|
+
}
|
|
@@ -63,4 +63,4 @@ export const ENV_ANGULAR_NODE_APP_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_ANGULAR_NODE_APP_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_ANGULAR_NODE_APP_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_ANGULAR_NODE_APP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -63,4 +63,4 @@ export const ENV_DOCS_WEBAPP_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_DOCS_WEBAPP_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_DOCS_WEBAPP_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_DOCS_WEBAPP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -63,4 +63,4 @@ export const ENV_ELECTRON_APP_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_ELECTRON_APP_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_ELECTRON_APP_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_ELECTRON_APP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -63,4 +63,4 @@ export const ENV_MOBILE_APP_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_MOBILE_APP_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_MOBILE_APP_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_MOBILE_APP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -63,4 +63,4 @@ export const ENV_NPM_LIB_AND_CLI_TOOL_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_NPM_LIB_AND_CLI_TOOL_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_NPM_LIB_AND_CLI_TOOL_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_NPM_LIB_AND_CLI_TOOL_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -63,4 +63,4 @@ export const ENV_VSCODE_PLUGIN_IS_CI_PROCESS = undefined;
|
|
|
63
63
|
export const ENV_VSCODE_PLUGIN_DOCKER_ADDITIONAL_CONTAINER = undefined;
|
|
64
64
|
export const ENV_VSCODE_PLUGIN_DOCKER_SKIP_START_IN_ORDER = undefined;
|
|
65
65
|
export const ENV_VSCODE_PLUGIN_DOCKER_SKIP_USING_MYSQL_DB = undefined;
|
|
66
|
-
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
66
|
+
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { ___NS__first, ___NS__isArray, ___NS__isArrayBuffer, ___NS__isBuffer, ___NS__isDate, ___NS__isEqual, ___NS__isFunction, ___NS__isNull, ___NS__isNumber, ___NS__isObject, ___NS__isRegExp, ___NS__isString, ___NS__isUndefined, ___NS__uniq } from 'tnp-core/lib-prod';
|
|
2
|
+
import { CLASSNAME__NS__CLASSNAME, CLASSNAME__NS__getClassBy, CLASSNAME__NS__getClassConfig, CLASSNAME__NS__getClassName, CLASSNAME__NS__getObjectClassFamily, CLASSNAME__NS__getObjectIndexPropertyValue, CLASSNAME__NS__getObjectIndexValue } from './classname';
|
|
3
|
+
import { describeFromClassStringify, describeByDefaultModelsAndMapping } from './describe-class';
|
|
4
|
+
import { setClassName } from './set-class-name';
|
|
5
|
+
export { Models } from './models';
|
|
6
|
+
export { SYMBOL } from './symbols';
|
|
7
|
+
export class TchHelpers {
|
|
8
|
+
static getBy(className) {
|
|
9
|
+
return CLASSNAME__NS__getClassBy(className);
|
|
10
|
+
}
|
|
11
|
+
static getFromObject(o) {
|
|
12
|
+
if (___NS__isUndefined(o) || ___NS__isNull(o)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (o.constructor) {
|
|
16
|
+
return o.constructor;
|
|
17
|
+
}
|
|
18
|
+
const p = Object.getPrototypeOf(o);
|
|
19
|
+
return p && p.constructor;
|
|
20
|
+
}
|
|
21
|
+
static getName(target, production = false) {
|
|
22
|
+
return CLASSNAME__NS__getClassName(target, production);
|
|
23
|
+
}
|
|
24
|
+
static getNameFromObject(o) {
|
|
25
|
+
const fnCLass = this.getFromObject(o);
|
|
26
|
+
return this.getName(fnCLass);
|
|
27
|
+
}
|
|
28
|
+
static getConfigs(target) {
|
|
29
|
+
return CLASSNAME__NS__getClassConfig(target);
|
|
30
|
+
}
|
|
31
|
+
static describeProperites(target) {
|
|
32
|
+
const d1 = describeFromClassStringify(target);
|
|
33
|
+
const d2 = describeByDefaultModelsAndMapping(target);
|
|
34
|
+
let uniq = {};
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
d1.concat(d2).forEach(p => uniq[p] = p);
|
|
37
|
+
return Object.keys(uniq)
|
|
38
|
+
.filter(d => !!d)
|
|
39
|
+
.filter(d => typeof target.prototype[d] !== 'function');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const notAllowedAsMethodName = [
|
|
43
|
+
'length', 'name',
|
|
44
|
+
'arguments', 'caller',
|
|
45
|
+
'constructor', 'apply',
|
|
46
|
+
'bind', 'call',
|
|
47
|
+
'toString',
|
|
48
|
+
'__defineGetter__',
|
|
49
|
+
'__defineSetter__', 'hasOwnProperty',
|
|
50
|
+
'__lookupGetter__', '__lookupSetter__',
|
|
51
|
+
'isPrototypeOf', 'propertyIsEnumerable',
|
|
52
|
+
'valueOf', '__proto__', 'toLocaleString',
|
|
53
|
+
];
|
|
54
|
+
const getMethodsNames = (classOrClassInstance, allMethodsNames = []) => {
|
|
55
|
+
if (!classOrClassInstance) {
|
|
56
|
+
return allMethodsNames;
|
|
57
|
+
}
|
|
58
|
+
const isClassFunction = ___NS__isFunction(classOrClassInstance);
|
|
59
|
+
const classFun = (isClassFunction ? classOrClassInstance : Object.getPrototypeOf(classOrClassInstance));
|
|
60
|
+
const objectToCheck = isClassFunction ? classOrClassInstance?.prototype : classOrClassInstance;
|
|
61
|
+
const prototypeObj = Object.getPrototypeOf(objectToCheck || {});
|
|
62
|
+
const properties = ___NS__uniq([
|
|
63
|
+
...Object.getOwnPropertyNames(objectToCheck || {}),
|
|
64
|
+
...Object.getOwnPropertyNames(prototypeObj || {}),
|
|
65
|
+
...Object.keys(objectToCheck || {}),
|
|
66
|
+
...Object.keys(prototypeObj || {}),
|
|
67
|
+
])
|
|
68
|
+
.filter(f => !!f && !notAllowedAsMethodName.includes(f));
|
|
69
|
+
properties.filter((methodName) => typeof objectToCheck[methodName] === 'function').forEach(p => allMethodsNames.push(p));
|
|
70
|
+
if (!classFun || !classFun.constructor || classFun?.constructor?.name === 'Object') {
|
|
71
|
+
return allMethodsNames;
|
|
72
|
+
}
|
|
73
|
+
return getMethodsNames(Object.getPrototypeOf(classFun), allMethodsNames);
|
|
74
|
+
};
|
|
75
|
+
export const CLASS = {
|
|
76
|
+
NAME: CLASSNAME__NS__CLASSNAME,
|
|
77
|
+
setName: setClassName,
|
|
78
|
+
getBy: TchHelpers.getBy,
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated
|
|
81
|
+
*/
|
|
82
|
+
getSingleton(target) {
|
|
83
|
+
if (typeof target !== 'function') {
|
|
84
|
+
console.error(`[typescript-class-helpers][setSingletonObj] Type of target is not a function`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const config = TchHelpers.getConfigs(target)[0];
|
|
88
|
+
// console.log(`getSingleton for ${target.name}: `, config.singleton)
|
|
89
|
+
return config.singleton;
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* @deprecated
|
|
93
|
+
*/
|
|
94
|
+
setSingletonObj(target, singletonObject) {
|
|
95
|
+
// console.log('SET SINGLETON', singletonObject)
|
|
96
|
+
if (typeof target !== 'function') {
|
|
97
|
+
console.error(`[typescript-class-helpers][setSingletonObj] Type of target is not a function`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (Array.isArray(singletonObject)) {
|
|
101
|
+
console.error(`[typescript-class-helpers][setSingletonObj] Singleton instance cant be an array`);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (typeof singletonObject !== 'object') {
|
|
105
|
+
console.error(`[typescript-class-helpers][setSingletonObj] Singleton instance cant must be a object`);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const className = CLASS.getName(target);
|
|
109
|
+
// console.log(`SINGLETON SET for TARGET ${className}`)
|
|
110
|
+
const config = TchHelpers.getConfigs(target)[0];
|
|
111
|
+
if (config.singleton) {
|
|
112
|
+
console.warn(`[typescript-class-helpers] You are trying to set singleton of "${className}" second time with different object.`);
|
|
113
|
+
}
|
|
114
|
+
config.singleton = singletonObject;
|
|
115
|
+
},
|
|
116
|
+
/**
|
|
117
|
+
* @deprecated
|
|
118
|
+
*/
|
|
119
|
+
getConfigs: TchHelpers.getConfigs,
|
|
120
|
+
/**
|
|
121
|
+
* @deprecated
|
|
122
|
+
*/
|
|
123
|
+
getConfig: (target) => {
|
|
124
|
+
return ___NS__first(TchHelpers.getConfigs(target));
|
|
125
|
+
},
|
|
126
|
+
getMethodsNames(classOrClassInstance) {
|
|
127
|
+
return getMethodsNames(classOrClassInstance);
|
|
128
|
+
},
|
|
129
|
+
getFromObject: TchHelpers.getFromObject,
|
|
130
|
+
getName: TchHelpers.getName,
|
|
131
|
+
getNameFromObject: TchHelpers.getNameFromObject,
|
|
132
|
+
describeProperites: TchHelpers.describeProperites,
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated
|
|
135
|
+
*/
|
|
136
|
+
OBJECT: (obj) => {
|
|
137
|
+
return {
|
|
138
|
+
get indexValue() {
|
|
139
|
+
return CLASSNAME__NS__getObjectIndexValue(obj);
|
|
140
|
+
},
|
|
141
|
+
get indexProperty() {
|
|
142
|
+
return CLASSNAME__NS__getObjectIndexPropertyValue(obj);
|
|
143
|
+
},
|
|
144
|
+
get isClassObject() {
|
|
145
|
+
if (!___NS__isObject(obj) || ___NS__isArray(obj) || ___NS__isRegExp(obj) ||
|
|
146
|
+
___NS__isBuffer(obj) || ___NS__isArrayBuffer(obj)) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
if (___NS__isDate(obj)) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
const className = CLASS.getNameFromObject(obj);
|
|
153
|
+
return ___NS__isString(className) && className !== 'Object';
|
|
154
|
+
},
|
|
155
|
+
isEqual: (anotherObj, compareDeep = false) => {
|
|
156
|
+
if (!CLASS.OBJECT(obj).isClassObject || !CLASS.OBJECT(anotherObj).isClassObject) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
if (obj === anotherObj) {
|
|
160
|
+
// console.log(`EQ v1: , v2: - class1 ${CLASS.getNameFromObject(obj)}, class2 ${CLASS.getNameFromObject(anotherObj)}`, obj, anotherObj)
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
const v1 = CLASSNAME__NS__getObjectIndexValue(obj);
|
|
164
|
+
const v2 = CLASSNAME__NS__getObjectIndexValue(anotherObj);
|
|
165
|
+
const f1 = CLASSNAME__NS__getObjectClassFamily(obj);
|
|
166
|
+
const f2 = CLASSNAME__NS__getObjectClassFamily(anotherObj);
|
|
167
|
+
const isFamilyDiff = (!___NS__isString(f1) || !___NS__isString(f2) || (f1 !== f2));
|
|
168
|
+
// console.log(`DIFF FAMILY ${isFamilyDiff} v1: ${CLASSNAME__NS__getObjectClassFamily(obj)}, v2: ${CLASSNAME__NS__getObjectClassFamily(anotherObj)} - class1 ${CLASS.getNameFromObject(obj)}, class2 ${CLASS.getNameFromObject(anotherObj)}`)
|
|
169
|
+
if (isFamilyDiff) {
|
|
170
|
+
// console.log(`DIFF v1: ${v1}, v2: ${v2} - class1 ${CLASS.getNameFromObject(obj)}, class2 ${CLASS.getNameFromObject(anotherObj)}`)
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
if (!CLASS.OBJECT(obj).isClassObject || !CLASS.OBJECT(anotherObj).isClassObject) {
|
|
174
|
+
// console.log(`NOT CLASS v1: ${v1}, v2: ${v2} - class1 ${CLASS.getNameFromObject(obj)}, class2 ${CLASS.getNameFromObject(anotherObj)}`)
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
// console.log(`v1: ${v1} ,class ${CLASS.getNameFromObject(obj)} ,prop: ${CLASS.OBJECT(obj).indexProperty}`)
|
|
178
|
+
// console.log(`v2: ${v2} ,class ${CLASS.getNameFromObject(anotherObj)} ,prop: ${CLASS.OBJECT(anotherObj).indexProperty}`)
|
|
179
|
+
// console.log(`v1: ${v1}, v2: ${v2} - class1 ${CLASS.getNameFromObject(obj)}, class2 ${CLASS.getNameFromObject(anotherObj)}`)
|
|
180
|
+
// console.log('')
|
|
181
|
+
if ((___NS__isNumber(v1) && ___NS__isNumber(v2)) || (___NS__isString(v1) && ___NS__isString(v2))) {
|
|
182
|
+
const res = (v1 === v2);
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
return res;
|
|
185
|
+
}
|
|
186
|
+
if (compareDeep) {
|
|
187
|
+
return ___NS__isEqual(v1, v2);
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated
|
|
3
|
+
*/
|
|
4
|
+
export class Models__NS__ParamConfig {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
*/
|
|
9
|
+
export class Models__NS__MethodConfig {
|
|
10
|
+
constructor() {
|
|
11
|
+
//#endregion
|
|
12
|
+
this.parameters = {};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated
|
|
17
|
+
*/
|
|
18
|
+
export class Models__NS__ClassConfig {
|
|
19
|
+
constructor() {
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
this.singleton = void 0;
|
|
22
|
+
this.injections = [];
|
|
23
|
+
this.vChildren = [];
|
|
24
|
+
this.methods = {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//end of namespace Models
|
package/lib-prod/package.json
CHANGED