typescript-class-helpers 13.2.12 → 13.2.13
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/assets/shared/shared_folder_info.txt +1 -1
- package/browser/README.md +24 -24
- package/browser/esm2020/lib/classname.mjs +150 -150
- package/browser/esm2020/lib/describe-class.mjs +71 -71
- package/browser/esm2020/lib/errors-messages.mjs +3 -3
- package/browser/esm2020/lib/index.mjs +134 -134
- package/browser/esm2020/lib/models.mjs +26 -26
- package/browser/esm2020/lib/registerd-db.mjs +5 -5
- package/browser/esm2020/lib/set-class-name.mjs +89 -89
- package/browser/esm2020/lib/storage.mjs +23 -23
- package/browser/esm2020/lib/symbols.mjs +7 -7
- package/browser/esm2020/public-api.mjs +1 -1
- package/browser/esm2020/typescript-class-helpers.mjs +4 -4
- package/browser/fesm2015/typescript-class-helpers.mjs +476 -476
- package/browser/fesm2020/typescript-class-helpers.mjs +476 -476
- package/browser/lib/classname.d.ts +15 -15
- package/browser/lib/describe-class.d.ts +5 -5
- package/browser/lib/index.d.ts +32 -32
- package/browser/lib/models.d.ts +66 -66
- package/browser/lib/registerd-db.d.ts +4 -4
- package/browser/lib/set-class-name.d.ts +1 -1
- package/browser/lib/symbols.d.ts +5 -5
- package/browser/typescript-class-helpers.d.ts +4 -4
- package/client/README.md +24 -24
- package/client/esm2020/lib/classname.mjs +150 -150
- package/client/esm2020/lib/describe-class.mjs +71 -71
- package/client/esm2020/lib/errors-messages.mjs +3 -3
- package/client/esm2020/lib/index.mjs +134 -134
- package/client/esm2020/lib/models.mjs +26 -26
- package/client/esm2020/lib/registerd-db.mjs +5 -5
- package/client/esm2020/lib/set-class-name.mjs +89 -89
- package/client/esm2020/lib/storage.mjs +23 -23
- package/client/esm2020/lib/symbols.mjs +7 -7
- package/client/esm2020/public-api.mjs +1 -1
- package/client/esm2020/typescript-class-helpers.mjs +4 -4
- package/client/fesm2015/typescript-class-helpers.mjs +476 -476
- package/client/fesm2020/typescript-class-helpers.mjs +476 -476
- package/client/lib/classname.d.ts +15 -15
- package/client/lib/describe-class.d.ts +5 -5
- package/client/lib/index.d.ts +32 -32
- package/client/lib/models.d.ts +66 -66
- package/client/lib/registerd-db.d.ts +4 -4
- package/client/lib/set-class-name.d.ts +1 -1
- package/client/lib/symbols.d.ts +5 -5
- package/client/package.json +33 -31
- package/client/typescript-class-helpers.d.ts +4 -4
- package/index.d.ts +1 -1
- package/index.js.map +1 -1
- package/lib/classname.d.ts +16 -16
- package/lib/classname.js.map +1 -1
- package/lib/describe-class.d.ts +6 -6
- package/lib/describe-class.js.map +1 -1
- package/lib/errors-messages.d.ts +1 -1
- package/lib/errors-messages.js.map +1 -1
- package/lib/index.d.ts +33 -33
- package/lib/index.js.map +1 -1
- package/lib/models.d.ts +68 -68
- package/lib/models.js.map +1 -1
- package/lib/registerd-db.d.ts +5 -5
- package/lib/registerd-db.js.map +1 -1
- package/lib/set-class-name.d.ts +2 -2
- package/lib/set-class-name.js.map +1 -1
- package/lib/storage.d.ts +1 -1
- package/lib/storage.js.map +1 -1
- package/lib/symbols.d.ts +6 -6
- package/lib/symbols.js.map +1 -1
- package/package.json +3 -3
- package/package.json_devDependencies.json +223 -223
- package/package.json_tnp.json5 +51 -51
- package/tmp-environment.json +37 -35
- package/websql/README.md +24 -24
- package/websql/esm2020/lib/classname.mjs +150 -150
- package/websql/esm2020/lib/describe-class.mjs +71 -71
- package/websql/esm2020/lib/errors-messages.mjs +3 -3
- package/websql/esm2020/lib/index.mjs +134 -134
- package/websql/esm2020/lib/models.mjs +24 -24
- package/websql/esm2020/lib/registerd-db.mjs +5 -5
- package/websql/esm2020/lib/set-class-name.mjs +89 -89
- package/websql/esm2020/lib/storage.mjs +23 -23
- package/websql/esm2020/lib/symbols.mjs +7 -7
- package/websql/esm2020/public-api.mjs +1 -1
- package/websql/esm2020/typescript-class-helpers.mjs +4 -4
- package/websql/fesm2015/typescript-class-helpers.mjs +474 -474
- package/websql/fesm2020/typescript-class-helpers.mjs +474 -474
- package/websql/lib/classname.d.ts +15 -15
- package/websql/lib/describe-class.d.ts +5 -5
- package/websql/lib/index.d.ts +32 -32
- package/websql/lib/models.d.ts +67 -67
- package/websql/lib/registerd-db.d.ts +4 -4
- package/websql/lib/set-class-name.d.ts +1 -1
- package/websql/lib/symbols.d.ts +5 -5
- package/websql/typescript-class-helpers.d.ts +4 -4
|
@@ -1,152 +1,152 @@
|
|
|
1
1
|
import { _, Helpers } from 'tnp-core/browser';
|
|
2
2
|
export * from 'enum-values';
|
|
3
3
|
|
|
4
|
-
var Models;
|
|
5
|
-
(function (Models) {
|
|
6
|
-
class ParamConfig {
|
|
7
|
-
}
|
|
8
|
-
Models.ParamConfig = ParamConfig;
|
|
9
|
-
class MethodConfig {
|
|
10
|
-
constructor() {
|
|
11
|
-
/* */
|
|
12
|
-
/* */
|
|
13
|
-
this.parameters = {};
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
Models.MethodConfig = MethodConfig;
|
|
17
|
-
class ClassConfig {
|
|
18
|
-
constructor() {
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
this.singleton = void 0;
|
|
21
|
-
this.injections = [];
|
|
22
|
-
this.vChildren = [];
|
|
23
|
-
this.methods = {};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
Models.ClassConfig = ClassConfig;
|
|
27
|
-
})(Models || (Models = {}));
|
|
28
|
-
;
|
|
4
|
+
var Models;
|
|
5
|
+
(function (Models) {
|
|
6
|
+
class ParamConfig {
|
|
7
|
+
}
|
|
8
|
+
Models.ParamConfig = ParamConfig;
|
|
9
|
+
class MethodConfig {
|
|
10
|
+
constructor() {
|
|
11
|
+
/* */
|
|
12
|
+
/* */
|
|
13
|
+
this.parameters = {};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
Models.MethodConfig = MethodConfig;
|
|
17
|
+
class ClassConfig {
|
|
18
|
+
constructor() {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
this.singleton = void 0;
|
|
21
|
+
this.injections = [];
|
|
22
|
+
this.vChildren = [];
|
|
23
|
+
this.methods = {};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
Models.ClassConfig = ClassConfig;
|
|
27
|
+
})(Models || (Models = {}));
|
|
28
|
+
;
|
|
29
29
|
({}); // @--end-of-file-for-module=typescript-class-helpers lib/models.ts
|
|
30
30
|
|
|
31
|
-
const SYMBOL = {
|
|
32
|
-
MODELS_MAPPING: Symbol(),
|
|
33
|
-
DEFAULT_MODEL: Symbol(),
|
|
34
|
-
STORAGE: 'classesstorage',
|
|
35
|
-
CLASSES: 'classes',
|
|
36
|
-
};
|
|
31
|
+
const SYMBOL = {
|
|
32
|
+
MODELS_MAPPING: Symbol(),
|
|
33
|
+
DEFAULT_MODEL: Symbol(),
|
|
34
|
+
STORAGE: 'classesstorage',
|
|
35
|
+
CLASSES: 'classes',
|
|
36
|
+
};
|
|
37
37
|
({}); // @--end-of-file-for-module=typescript-class-helpers lib/symbols.ts
|
|
38
38
|
|
|
39
|
-
function defaultValues() {
|
|
40
|
-
return _.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
|
-
;
|
|
39
|
+
function defaultValues() {
|
|
40
|
+
return _.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
59
|
({}); // @--end-of-file-for-module=typescript-class-helpers lib/storage.ts
|
|
60
60
|
|
|
61
|
-
function getClasses$1() {
|
|
62
|
-
const s = getStorage();
|
|
63
|
-
return s[SYMBOL.CLASSES];
|
|
64
|
-
}
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
function setClassName(target, className, options) {
|
|
67
|
-
let { classFamily, uniqueKey, classNameInBrowser, singleton } = options || {
|
|
68
|
-
classFamily: void 0,
|
|
69
|
-
uniqueKey: 'id',
|
|
70
|
-
classNameInBrowser: void 0,
|
|
71
|
-
singleton: void 0,
|
|
72
|
-
autoinstance: false
|
|
73
|
-
};
|
|
74
|
-
if (!_.isUndefined(singleton) && _.isBoolean(singleton) && singleton) {
|
|
75
|
-
singleton = 'first-instance';
|
|
76
|
-
}
|
|
77
|
-
if (!uniqueKey) {
|
|
78
|
-
uniqueKey = 'id';
|
|
79
|
-
}
|
|
80
|
-
if (target) {
|
|
81
|
-
const config = _.first(CLASSNAME.getClassConfig(target));
|
|
82
|
-
config.className = className;
|
|
83
|
-
config.uniqueKey = uniqueKey;
|
|
84
|
-
config.classNameInBrowser = classNameInBrowser;
|
|
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 (_.isUndefined(classFamily)) {
|
|
100
|
-
Object.defineProperty(res, 'classFamily', {
|
|
101
|
-
get: function () {
|
|
102
|
-
const parent = Object.getPrototypeOf(target);
|
|
103
|
-
if (!_.isFunction(parent) || parent.name === 'Object' || parent.name === '') {
|
|
104
|
-
return className;
|
|
105
|
-
}
|
|
106
|
-
const classNameNew = CLASSNAME.getClassName(parent);
|
|
107
|
-
return CLASSNAME.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
|
-
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
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
}
|
|
126
|
-
return context;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
obj.decoratedConstructor.prototype = Original.prototype;
|
|
130
|
-
// @ts-ignore
|
|
131
|
-
Object.keys(Original).forEach((name) => { obj.decoratedConstructor[name] = Original[name]; });
|
|
132
|
-
Object.defineProperty(obj.decoratedConstructor, 'name', {
|
|
133
|
-
value: className,
|
|
134
|
-
configurable: true,
|
|
135
|
-
});
|
|
136
|
-
return obj.decoratedConstructor;
|
|
137
|
-
}
|
|
138
|
-
else if (singleton === 'autoinstance') {
|
|
139
|
-
const auto = new Original();
|
|
140
|
-
CLASS.setSingletonObj(Original, auto);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
;
|
|
61
|
+
function getClasses$1() {
|
|
62
|
+
const s = getStorage();
|
|
63
|
+
return s[SYMBOL.CLASSES];
|
|
64
|
+
}
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
function setClassName(target, className, options) {
|
|
67
|
+
let { classFamily, uniqueKey, classNameInBrowser, singleton } = options || {
|
|
68
|
+
classFamily: void 0,
|
|
69
|
+
uniqueKey: 'id',
|
|
70
|
+
classNameInBrowser: void 0,
|
|
71
|
+
singleton: void 0,
|
|
72
|
+
autoinstance: false
|
|
73
|
+
};
|
|
74
|
+
if (!_.isUndefined(singleton) && _.isBoolean(singleton) && singleton) {
|
|
75
|
+
singleton = 'first-instance';
|
|
76
|
+
}
|
|
77
|
+
if (!uniqueKey) {
|
|
78
|
+
uniqueKey = 'id';
|
|
79
|
+
}
|
|
80
|
+
if (target) {
|
|
81
|
+
const config = _.first(CLASSNAME.getClassConfig(target));
|
|
82
|
+
config.className = className;
|
|
83
|
+
config.uniqueKey = uniqueKey;
|
|
84
|
+
config.classNameInBrowser = classNameInBrowser;
|
|
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 (_.isUndefined(classFamily)) {
|
|
100
|
+
Object.defineProperty(res, 'classFamily', {
|
|
101
|
+
get: function () {
|
|
102
|
+
const parent = Object.getPrototypeOf(target);
|
|
103
|
+
if (!_.isFunction(parent) || parent.name === 'Object' || parent.name === '') {
|
|
104
|
+
return className;
|
|
105
|
+
}
|
|
106
|
+
const classNameNew = CLASSNAME.getClassName(parent);
|
|
107
|
+
return CLASSNAME.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
|
+
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
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
}
|
|
126
|
+
return context;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
obj.decoratedConstructor.prototype = Original.prototype;
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
Object.keys(Original).forEach((name) => { obj.decoratedConstructor[name] = Original[name]; });
|
|
132
|
+
Object.defineProperty(obj.decoratedConstructor, 'name', {
|
|
133
|
+
value: className,
|
|
134
|
+
configurable: true,
|
|
135
|
+
});
|
|
136
|
+
return obj.decoratedConstructor;
|
|
137
|
+
}
|
|
138
|
+
else if (singleton === 'autoinstance') {
|
|
139
|
+
const auto = new Original();
|
|
140
|
+
CLASS.setSingletonObj(Original, auto);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
;
|
|
144
144
|
({}); // @--end-of-file-for-module=typescript-class-helpers lib/set-class-name.ts
|
|
145
145
|
|
|
146
|
-
const registerd = {
|
|
147
|
-
configs: [],
|
|
148
|
-
classes: [],
|
|
149
|
-
};
|
|
146
|
+
const registerd = {
|
|
147
|
+
configs: [],
|
|
148
|
+
classes: [],
|
|
149
|
+
};
|
|
150
150
|
({}); // @--end-of-file-for-module=typescript-class-helpers lib/registerd-db.ts
|
|
151
151
|
|
|
152
152
|
const ERROR_MSG_CLASS_WITHOUT_DECORATOR = `[typescript-class-helpers][getClassName(...)](PRODUCTION MODE ERROR)
|
|
@@ -159,358 +159,358 @@ import { CLASS } from 'typescript-class-helpers/browser';
|
|
|
159
159
|
class ExampleClass {
|
|
160
160
|
...
|
|
161
161
|
}
|
|
162
|
-
`;
|
|
163
|
-
;
|
|
162
|
+
`;
|
|
163
|
+
;
|
|
164
164
|
({}); // @--end-of-file-for-module=typescript-class-helpers lib/errors-messages.ts
|
|
165
165
|
|
|
166
|
-
/* */
|
|
167
|
-
/* */
|
|
168
|
-
function getClasses() {
|
|
169
|
-
const s = getStorage();
|
|
170
|
-
return s[SYMBOL.CLASSES];
|
|
171
|
-
}
|
|
172
|
-
var CLASSNAME;
|
|
173
|
-
(function (CLASSNAME_1) {
|
|
174
|
-
function getClassConfig(target, configs = [], callerTarget) {
|
|
175
|
-
if (!_.isFunction(target)) {
|
|
176
|
-
throw `[typescript-class-helper][getClassConfig] Cannot get class config from: ${target}`;
|
|
177
|
-
}
|
|
178
|
-
let config;
|
|
179
|
-
const parentClass = Object.getPrototypeOf(target);
|
|
180
|
-
const isValidParent = (_.isFunction(parentClass) && parentClass.name !== '');
|
|
181
|
-
if (registerd.classes.includes(target)) {
|
|
182
|
-
config = registerd.configs[registerd.classes.findIndex(c => c === target)];
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
config = new Models.ClassConfig();
|
|
186
|
-
config.classReference = target;
|
|
187
|
-
registerd.classes.push(target);
|
|
188
|
-
}
|
|
189
|
-
registerd.configs[registerd.classes.findIndex(c => c === target)] = config;
|
|
190
|
-
if (callerTarget) {
|
|
191
|
-
const callerTargetConfig = registerd.configs[registerd.classes.findIndex(c => c === callerTarget)];
|
|
192
|
-
if (!config.vChildren.includes(callerTargetConfig)) {
|
|
193
|
-
config.vChildren.push(callerTargetConfig);
|
|
194
|
-
}
|
|
195
|
-
callerTargetConfig.vParent = config;
|
|
196
|
-
}
|
|
197
|
-
configs.push(config);
|
|
198
|
-
return isValidParent ? getClassConfig(parentClass, configs, target) : configs;
|
|
199
|
-
}
|
|
200
|
-
CLASSNAME_1.getClassConfig = getClassConfig;
|
|
201
|
-
/**
|
|
202
|
-
* PLEASE PROVIDE NAME AS TYPED STRING, NOT VARIABLE
|
|
203
|
-
* Decorator requred for production mode
|
|
204
|
-
* @param name Name of class
|
|
205
|
-
*/
|
|
206
|
-
function CLASSNAME(className, options) {
|
|
207
|
-
return function (target) {
|
|
208
|
-
return setClassName(target, className, options);
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
CLASSNAME_1.CLASSNAME = CLASSNAME;
|
|
212
|
-
function getClassName(target, production = false) {
|
|
213
|
-
if (_.isNil(target)) {
|
|
214
|
-
return void 0;
|
|
215
|
-
}
|
|
216
|
-
if (_.isString(target)) {
|
|
217
|
-
console.log(target);
|
|
218
|
-
Helpers.warn(`[typescript-class-helpers][getClassName] target is string: '${target}', produciton: ${production}`);
|
|
219
|
-
return target;
|
|
220
|
-
}
|
|
221
|
-
if (!_.isFunction(target)) {
|
|
222
|
-
console.log(target);
|
|
223
|
-
Helpers.warn(`[typescript-class-helpers][getClassName] target is not a class`);
|
|
224
|
-
return void 0;
|
|
225
|
-
}
|
|
226
|
-
const configs = getClassConfig(target);
|
|
227
|
-
const config = _.first(configs);
|
|
228
|
-
const classNameInBrowser = config === null || config === void 0 ? void 0 : config.classNameInBrowser;
|
|
229
|
-
if (Helpers.isBrowser && _.isString(classNameInBrowser)) {
|
|
230
|
-
return classNameInBrowser;
|
|
231
|
-
}
|
|
232
|
-
const className = config === null || config === void 0 ? void 0 : config.className;
|
|
233
|
-
if (className) {
|
|
234
|
-
return className;
|
|
235
|
-
}
|
|
236
|
-
if (production) {
|
|
237
|
-
console.log('class without @CLASS.NAME deocrator', target);
|
|
238
|
-
throw new Error(ERROR_MSG_CLASS_WITHOUT_DECORATOR);
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
}
|
|
242
|
-
return target.name;
|
|
243
|
-
}
|
|
244
|
-
CLASSNAME_1.getClassName = getClassName;
|
|
245
|
-
// @ts-ignore
|
|
246
|
-
function getObjectIndexPropertyValue(obj) {
|
|
247
|
-
const className = TchHelpers.getNameFromObject(obj);
|
|
248
|
-
let c = getClasses().find(c => c.className === className);
|
|
249
|
-
if (c) {
|
|
250
|
-
return c.uniqueKey;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
CLASSNAME_1.getObjectIndexPropertyValue = getObjectIndexPropertyValue;
|
|
254
|
-
// @ts-ignore
|
|
255
|
-
function getClassFamilyByClassName(className) {
|
|
256
|
-
let c = getClasses().find(c => c.className === className);
|
|
257
|
-
if (c) {
|
|
258
|
-
return c.classFamily;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
CLASSNAME_1.getClassFamilyByClassName = getClassFamilyByClassName;
|
|
262
|
-
// @ts-ignore
|
|
263
|
-
function getObjectClassFamily(obj) {
|
|
264
|
-
const className = TchHelpers.getNameFromObject(obj);
|
|
265
|
-
let c = getClasses().find(c => c.className === className);
|
|
266
|
-
if (c) {
|
|
267
|
-
return c.classFamily;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
CLASSNAME_1.getObjectClassFamily = getObjectClassFamily;
|
|
271
|
-
function getObjectIndexValue(obj) {
|
|
272
|
-
const className = TchHelpers.getNameFromObject(obj);
|
|
273
|
-
let c = getClasses().find(c => c.className === className);
|
|
274
|
-
if (c && _.isString(c.uniqueKey)) {
|
|
275
|
-
return obj[c.uniqueKey];
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
CLASSNAME_1.getObjectIndexValue = getObjectIndexValue;
|
|
279
|
-
function getClassBy(className) {
|
|
280
|
-
let res;
|
|
281
|
-
if (Array.isArray(className)) {
|
|
282
|
-
if (className.length !== 1) {
|
|
166
|
+
/* */
|
|
167
|
+
/* */
|
|
168
|
+
function getClasses() {
|
|
169
|
+
const s = getStorage();
|
|
170
|
+
return s[SYMBOL.CLASSES];
|
|
171
|
+
}
|
|
172
|
+
var CLASSNAME;
|
|
173
|
+
(function (CLASSNAME_1) {
|
|
174
|
+
function getClassConfig(target, configs = [], callerTarget) {
|
|
175
|
+
if (!_.isFunction(target)) {
|
|
176
|
+
throw `[typescript-class-helper][getClassConfig] Cannot get class config from: ${target}`;
|
|
177
|
+
}
|
|
178
|
+
let config;
|
|
179
|
+
const parentClass = Object.getPrototypeOf(target);
|
|
180
|
+
const isValidParent = (_.isFunction(parentClass) && parentClass.name !== '');
|
|
181
|
+
if (registerd.classes.includes(target)) {
|
|
182
|
+
config = registerd.configs[registerd.classes.findIndex(c => c === target)];
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
config = new Models.ClassConfig();
|
|
186
|
+
config.classReference = target;
|
|
187
|
+
registerd.classes.push(target);
|
|
188
|
+
}
|
|
189
|
+
registerd.configs[registerd.classes.findIndex(c => c === target)] = config;
|
|
190
|
+
if (callerTarget) {
|
|
191
|
+
const callerTargetConfig = registerd.configs[registerd.classes.findIndex(c => c === callerTarget)];
|
|
192
|
+
if (!config.vChildren.includes(callerTargetConfig)) {
|
|
193
|
+
config.vChildren.push(callerTargetConfig);
|
|
194
|
+
}
|
|
195
|
+
callerTargetConfig.vParent = config;
|
|
196
|
+
}
|
|
197
|
+
configs.push(config);
|
|
198
|
+
return isValidParent ? getClassConfig(parentClass, configs, target) : configs;
|
|
199
|
+
}
|
|
200
|
+
CLASSNAME_1.getClassConfig = getClassConfig;
|
|
201
|
+
/**
|
|
202
|
+
* PLEASE PROVIDE NAME AS TYPED STRING, NOT VARIABLE
|
|
203
|
+
* Decorator requred for production mode
|
|
204
|
+
* @param name Name of class
|
|
205
|
+
*/
|
|
206
|
+
function CLASSNAME(className, options) {
|
|
207
|
+
return function (target) {
|
|
208
|
+
return setClassName(target, className, options);
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
CLASSNAME_1.CLASSNAME = CLASSNAME;
|
|
212
|
+
function getClassName(target, production = false) {
|
|
213
|
+
if (_.isNil(target)) {
|
|
214
|
+
return void 0;
|
|
215
|
+
}
|
|
216
|
+
if (_.isString(target)) {
|
|
217
|
+
console.log(target);
|
|
218
|
+
Helpers.warn(`[typescript-class-helpers][getClassName] target is string: '${target}', produciton: ${production}`);
|
|
219
|
+
return target;
|
|
220
|
+
}
|
|
221
|
+
if (!_.isFunction(target)) {
|
|
222
|
+
console.log(target);
|
|
223
|
+
Helpers.warn(`[typescript-class-helpers][getClassName] target is not a class`);
|
|
224
|
+
return void 0;
|
|
225
|
+
}
|
|
226
|
+
const configs = getClassConfig(target);
|
|
227
|
+
const config = _.first(configs);
|
|
228
|
+
const classNameInBrowser = config === null || config === void 0 ? void 0 : config.classNameInBrowser;
|
|
229
|
+
if (Helpers.isBrowser && _.isString(classNameInBrowser)) {
|
|
230
|
+
return classNameInBrowser;
|
|
231
|
+
}
|
|
232
|
+
const className = config === null || config === void 0 ? void 0 : config.className;
|
|
233
|
+
if (className) {
|
|
234
|
+
return className;
|
|
235
|
+
}
|
|
236
|
+
if (production) {
|
|
237
|
+
console.log('class without @CLASS.NAME deocrator', target);
|
|
238
|
+
throw new Error(ERROR_MSG_CLASS_WITHOUT_DECORATOR);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
}
|
|
242
|
+
return target.name;
|
|
243
|
+
}
|
|
244
|
+
CLASSNAME_1.getClassName = getClassName;
|
|
245
|
+
// @ts-ignore
|
|
246
|
+
function getObjectIndexPropertyValue(obj) {
|
|
247
|
+
const className = TchHelpers.getNameFromObject(obj);
|
|
248
|
+
let c = getClasses().find(c => c.className === className);
|
|
249
|
+
if (c) {
|
|
250
|
+
return c.uniqueKey;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
CLASSNAME_1.getObjectIndexPropertyValue = getObjectIndexPropertyValue;
|
|
254
|
+
// @ts-ignore
|
|
255
|
+
function getClassFamilyByClassName(className) {
|
|
256
|
+
let c = getClasses().find(c => c.className === className);
|
|
257
|
+
if (c) {
|
|
258
|
+
return c.classFamily;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
CLASSNAME_1.getClassFamilyByClassName = getClassFamilyByClassName;
|
|
262
|
+
// @ts-ignore
|
|
263
|
+
function getObjectClassFamily(obj) {
|
|
264
|
+
const className = TchHelpers.getNameFromObject(obj);
|
|
265
|
+
let c = getClasses().find(c => c.className === className);
|
|
266
|
+
if (c) {
|
|
267
|
+
return c.classFamily;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
CLASSNAME_1.getObjectClassFamily = getObjectClassFamily;
|
|
271
|
+
function getObjectIndexValue(obj) {
|
|
272
|
+
const className = TchHelpers.getNameFromObject(obj);
|
|
273
|
+
let c = getClasses().find(c => c.className === className);
|
|
274
|
+
if (c && _.isString(c.uniqueKey)) {
|
|
275
|
+
return obj[c.uniqueKey];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
CLASSNAME_1.getObjectIndexValue = getObjectIndexValue;
|
|
279
|
+
function getClassBy(className) {
|
|
280
|
+
let res;
|
|
281
|
+
if (Array.isArray(className)) {
|
|
282
|
+
if (className.length !== 1) {
|
|
283
283
|
throw `Mapping error... please use proper class names:
|
|
284
284
|
{
|
|
285
285
|
propertyObject: 'MyClassName',
|
|
286
286
|
propertyWithArray: ['MyClassName']
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
`;
|
|
290
|
-
}
|
|
291
|
-
className = className[0];
|
|
292
|
-
}
|
|
293
|
-
if (typeof className === 'function') { // TODO QUICK_FIX
|
|
294
|
-
res = className;
|
|
295
|
-
}
|
|
296
|
-
if (className === 'Date') {
|
|
297
|
-
res = Date;
|
|
298
|
-
}
|
|
299
|
-
if (className === 'FormData') {
|
|
300
|
-
res = FormData;
|
|
301
|
-
}
|
|
302
|
-
let c = getClasses().find(c => c.className === className);
|
|
303
|
-
if (c) {
|
|
304
|
-
res = c.target;
|
|
305
|
-
}
|
|
306
|
-
// @ts-ignore
|
|
307
|
-
return res;
|
|
308
|
-
}
|
|
309
|
-
CLASSNAME_1.getClassBy = getClassBy;
|
|
310
|
-
})(CLASSNAME || (CLASSNAME = {}));
|
|
311
|
-
;
|
|
289
|
+
`;
|
|
290
|
+
}
|
|
291
|
+
className = className[0];
|
|
292
|
+
}
|
|
293
|
+
if (typeof className === 'function') { // TODO QUICK_FIX
|
|
294
|
+
res = className;
|
|
295
|
+
}
|
|
296
|
+
if (className === 'Date') {
|
|
297
|
+
res = Date;
|
|
298
|
+
}
|
|
299
|
+
if (className === 'FormData') {
|
|
300
|
+
res = FormData;
|
|
301
|
+
}
|
|
302
|
+
let c = getClasses().find(c => c.className === className);
|
|
303
|
+
if (c) {
|
|
304
|
+
res = c.target;
|
|
305
|
+
}
|
|
306
|
+
// @ts-ignore
|
|
307
|
+
return res;
|
|
308
|
+
}
|
|
309
|
+
CLASSNAME_1.getClassBy = getClassBy;
|
|
310
|
+
})(CLASSNAME || (CLASSNAME = {}));
|
|
311
|
+
;
|
|
312
312
|
({}); // @--end-of-file-for-module=typescript-class-helpers lib/classname.ts
|
|
313
313
|
|
|
314
|
-
/**
|
|
315
|
-
* @DEPRECATED
|
|
316
|
-
* Describe fields assigned in class
|
|
317
|
-
*/
|
|
318
|
-
const FRegEx = new RegExp(/(?:this\.)(.+?(?= ))/g);
|
|
319
|
-
function describeFromClassStringify(target, parent = false) {
|
|
320
|
-
// @ts-ignore
|
|
321
|
-
var result = [];
|
|
322
|
-
if (parent) {
|
|
323
|
-
var proto = Object.getPrototypeOf(target.prototype);
|
|
324
|
-
if (proto) {
|
|
325
|
-
// @ts-ignore
|
|
326
|
-
result = result.concat(describeFromClassStringify(proto.constructor, parent));
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
const classString = target.toString();
|
|
330
|
-
const matches = classString.match(FRegEx) || [];
|
|
331
|
-
result = result.concat(matches);
|
|
332
|
-
return result.map(prop => prop
|
|
333
|
-
.replace('this.', '')
|
|
334
|
-
.replace('.', '')
|
|
335
|
-
.replace(')', '')
|
|
336
|
-
.replace('(', ''));
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Describe fields assigne through @DefaultModelWithMapping decorator
|
|
340
|
-
* without functions
|
|
341
|
-
*/
|
|
342
|
-
function describeByDefaultModelsAndMapping(target) {
|
|
343
|
-
let res = {};
|
|
344
|
-
if (target) {
|
|
345
|
-
// @ts-ignore
|
|
346
|
-
if (target[SYMBOL.DEFAULT_MODEL]) {
|
|
347
|
-
// @ts-ignore
|
|
348
|
-
Object.keys(target[SYMBOL.DEFAULT_MODEL])
|
|
349
|
-
.filter(key => {
|
|
350
|
-
// @ts-ignore
|
|
351
|
-
return !_.isFunction(target[SYMBOL.DEFAULT_MODEL][key]);
|
|
352
|
-
})
|
|
353
|
-
.forEach(key => {
|
|
354
|
-
// @ts-ignore
|
|
355
|
-
return res[key] = null;
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
// @ts-ignore
|
|
359
|
-
let mapping = target[SYMBOL.MODELS_MAPPING];
|
|
360
|
-
if (_.isArray(mapping)) {
|
|
361
|
-
mapping.forEach(m => {
|
|
362
|
-
Object.keys(m)
|
|
363
|
-
.forEach(key => {
|
|
364
|
-
// @ts-ignore
|
|
365
|
-
res[key] = null;
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
else if (mapping) {
|
|
370
|
-
Object.keys(mapping)
|
|
371
|
-
.forEach(key => {
|
|
372
|
-
// @ts-ignore
|
|
373
|
-
res[key] = null;
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
let propNames = Object.keys(res).filter(f => !!f);
|
|
378
|
-
propNames = (!propNames.includes('id') ? ['id'] : []).concat(propNames);
|
|
379
|
-
return propNames;
|
|
380
|
-
}
|
|
381
|
-
;
|
|
314
|
+
/**
|
|
315
|
+
* @DEPRECATED
|
|
316
|
+
* Describe fields assigned in class
|
|
317
|
+
*/
|
|
318
|
+
const FRegEx = new RegExp(/(?:this\.)(.+?(?= ))/g);
|
|
319
|
+
function describeFromClassStringify(target, parent = false) {
|
|
320
|
+
// @ts-ignore
|
|
321
|
+
var result = [];
|
|
322
|
+
if (parent) {
|
|
323
|
+
var proto = Object.getPrototypeOf(target.prototype);
|
|
324
|
+
if (proto) {
|
|
325
|
+
// @ts-ignore
|
|
326
|
+
result = result.concat(describeFromClassStringify(proto.constructor, parent));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const classString = target.toString();
|
|
330
|
+
const matches = classString.match(FRegEx) || [];
|
|
331
|
+
result = result.concat(matches);
|
|
332
|
+
return result.map(prop => prop
|
|
333
|
+
.replace('this.', '')
|
|
334
|
+
.replace('.', '')
|
|
335
|
+
.replace(')', '')
|
|
336
|
+
.replace('(', ''));
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Describe fields assigne through @DefaultModelWithMapping decorator
|
|
340
|
+
* without functions
|
|
341
|
+
*/
|
|
342
|
+
function describeByDefaultModelsAndMapping(target) {
|
|
343
|
+
let res = {};
|
|
344
|
+
if (target) {
|
|
345
|
+
// @ts-ignore
|
|
346
|
+
if (target[SYMBOL.DEFAULT_MODEL]) {
|
|
347
|
+
// @ts-ignore
|
|
348
|
+
Object.keys(target[SYMBOL.DEFAULT_MODEL])
|
|
349
|
+
.filter(key => {
|
|
350
|
+
// @ts-ignore
|
|
351
|
+
return !_.isFunction(target[SYMBOL.DEFAULT_MODEL][key]);
|
|
352
|
+
})
|
|
353
|
+
.forEach(key => {
|
|
354
|
+
// @ts-ignore
|
|
355
|
+
return res[key] = null;
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
// @ts-ignore
|
|
359
|
+
let mapping = target[SYMBOL.MODELS_MAPPING];
|
|
360
|
+
if (_.isArray(mapping)) {
|
|
361
|
+
mapping.forEach(m => {
|
|
362
|
+
Object.keys(m)
|
|
363
|
+
.forEach(key => {
|
|
364
|
+
// @ts-ignore
|
|
365
|
+
res[key] = null;
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
else if (mapping) {
|
|
370
|
+
Object.keys(mapping)
|
|
371
|
+
.forEach(key => {
|
|
372
|
+
// @ts-ignore
|
|
373
|
+
res[key] = null;
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
let propNames = Object.keys(res).filter(f => !!f);
|
|
378
|
+
propNames = (!propNames.includes('id') ? ['id'] : []).concat(propNames);
|
|
379
|
+
return propNames;
|
|
380
|
+
}
|
|
381
|
+
;
|
|
382
382
|
({}); // @--end-of-file-for-module=typescript-class-helpers lib/describe-class.ts
|
|
383
383
|
|
|
384
|
-
class TchHelpers {
|
|
385
|
-
static getBy(className) {
|
|
386
|
-
return CLASSNAME.getClassBy(className);
|
|
387
|
-
}
|
|
388
|
-
static getFromObject(o) {
|
|
389
|
-
if (_.isUndefined(o) || _.isNull(o)) {
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
if (o.constructor) {
|
|
393
|
-
return o.constructor;
|
|
394
|
-
}
|
|
395
|
-
const p = Object.getPrototypeOf(o);
|
|
396
|
-
return p && p.constructor;
|
|
397
|
-
}
|
|
398
|
-
static getName(target, production = false) {
|
|
399
|
-
return CLASSNAME.getClassName(target, production);
|
|
400
|
-
}
|
|
401
|
-
static getNameFromObject(o) {
|
|
402
|
-
const fnCLass = this.getFromObject(o);
|
|
403
|
-
return this.getName(fnCLass);
|
|
404
|
-
}
|
|
405
|
-
static getConfigs(target) {
|
|
406
|
-
return CLASSNAME.getClassConfig(target);
|
|
407
|
-
}
|
|
408
|
-
static describeProperites(target) {
|
|
409
|
-
const d1 = describeFromClassStringify(target);
|
|
410
|
-
const d2 = describeByDefaultModelsAndMapping(target);
|
|
411
|
-
let uniq = {};
|
|
412
|
-
// @ts-ignore
|
|
413
|
-
d1.concat(d2).forEach(p => uniq[p] = p);
|
|
414
|
-
return Object.keys(uniq)
|
|
415
|
-
.filter(d => !!d)
|
|
416
|
-
.filter(d => typeof target.prototype[d] !== 'function');
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
const CLASS = {
|
|
420
|
-
NAME: CLASSNAME.CLASSNAME,
|
|
421
|
-
setName: setClassName,
|
|
422
|
-
getBy: TchHelpers.getBy,
|
|
423
|
-
getSingleton(target) {
|
|
424
|
-
if (typeof target !== 'function') {
|
|
425
|
-
console.error(`[typescript-class-helpers][setSingletonObj] Type of target is not a function`);
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
const config = TchHelpers.getConfigs(target)[0];
|
|
429
|
-
return config.singleton;
|
|
430
|
-
},
|
|
431
|
-
setSingletonObj(target, singletonObject) {
|
|
432
|
-
if (typeof target !== 'function') {
|
|
433
|
-
console.error(`[typescript-class-helpers][setSingletonObj] Type of target is not a function`);
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
if (Array.isArray(singletonObject)) {
|
|
437
|
-
console.error(`[typescript-class-helpers][setSingletonObj] Singleton instance cant be an array`);
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
if (typeof singletonObject !== 'object') {
|
|
441
|
-
console.error(`[typescript-class-helpers][setSingletonObj] Singleton instance cant must be a object`);
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
const className = CLASS.getName(target);
|
|
445
|
-
const config = TchHelpers.getConfigs(target)[0];
|
|
446
|
-
if (config.singleton) {
|
|
447
|
-
console.warn(`[typescript-class-helpers] You are trying to set singleton of "${className}" second time with different object.`);
|
|
448
|
-
}
|
|
449
|
-
config.singleton = singletonObject;
|
|
450
|
-
},
|
|
451
|
-
getConfigs: TchHelpers.getConfigs,
|
|
452
|
-
getConfig: (target) => {
|
|
453
|
-
return _.first(TchHelpers.getConfigs(target));
|
|
454
|
-
},
|
|
455
|
-
getFromObject: TchHelpers.getFromObject,
|
|
456
|
-
getName: TchHelpers.getName,
|
|
457
|
-
getNameFromObject: TchHelpers.getNameFromObject,
|
|
458
|
-
describeProperites: TchHelpers.describeProperites,
|
|
459
|
-
OBJECT: (obj) => {
|
|
460
|
-
return {
|
|
461
|
-
get indexValue() {
|
|
462
|
-
return CLASSNAME.getObjectIndexValue(obj);
|
|
463
|
-
},
|
|
464
|
-
get indexProperty() {
|
|
465
|
-
return CLASSNAME.getObjectIndexPropertyValue(obj);
|
|
466
|
-
},
|
|
467
|
-
get isClassObject() {
|
|
468
|
-
if (!_.isObject(obj) || _.isArray(obj) || _.isRegExp(obj) ||
|
|
469
|
-
_.isBuffer(obj) || _.isArrayBuffer(obj)) {
|
|
470
|
-
return false;
|
|
471
|
-
}
|
|
472
|
-
if (_.isDate(obj)) {
|
|
473
|
-
return true;
|
|
474
|
-
}
|
|
475
|
-
const className = CLASS.getNameFromObject(obj);
|
|
476
|
-
return _.isString(className) && className !== 'Object';
|
|
477
|
-
},
|
|
478
|
-
isEqual: (anotherObj, compareDeep = false) => {
|
|
479
|
-
if (!CLASS.OBJECT(obj).isClassObject || !CLASS.OBJECT(anotherObj).isClassObject) {
|
|
480
|
-
return false;
|
|
481
|
-
}
|
|
482
|
-
if (obj === anotherObj) {
|
|
483
|
-
return true;
|
|
484
|
-
}
|
|
485
|
-
const v1 = CLASSNAME.getObjectIndexValue(obj);
|
|
486
|
-
const v2 = CLASSNAME.getObjectIndexValue(anotherObj);
|
|
487
|
-
const f1 = CLASSNAME.getObjectClassFamily(obj);
|
|
488
|
-
const f2 = CLASSNAME.getObjectClassFamily(anotherObj);
|
|
489
|
-
const isFamilyDiff = (!_.isString(f1) || !_.isString(f2) || (f1 !== f2));
|
|
490
|
-
if (isFamilyDiff) {
|
|
491
|
-
return false;
|
|
492
|
-
}
|
|
493
|
-
if (!CLASS.OBJECT(obj).isClassObject || !CLASS.OBJECT(anotherObj).isClassObject) {
|
|
494
|
-
return false;
|
|
495
|
-
}
|
|
496
|
-
if ((_.isNumber(v1) && _.isNumber(v2)) || (_.isString(v1) && _.isString(v2))) {
|
|
497
|
-
const res = (v1 === v2);
|
|
498
|
-
// @ts-ignore
|
|
499
|
-
return res;
|
|
500
|
-
}
|
|
501
|
-
if (compareDeep) {
|
|
502
|
-
return _.isEqual(v1, v2);
|
|
503
|
-
}
|
|
504
|
-
return false;
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
;
|
|
384
|
+
class TchHelpers {
|
|
385
|
+
static getBy(className) {
|
|
386
|
+
return CLASSNAME.getClassBy(className);
|
|
387
|
+
}
|
|
388
|
+
static getFromObject(o) {
|
|
389
|
+
if (_.isUndefined(o) || _.isNull(o)) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (o.constructor) {
|
|
393
|
+
return o.constructor;
|
|
394
|
+
}
|
|
395
|
+
const p = Object.getPrototypeOf(o);
|
|
396
|
+
return p && p.constructor;
|
|
397
|
+
}
|
|
398
|
+
static getName(target, production = false) {
|
|
399
|
+
return CLASSNAME.getClassName(target, production);
|
|
400
|
+
}
|
|
401
|
+
static getNameFromObject(o) {
|
|
402
|
+
const fnCLass = this.getFromObject(o);
|
|
403
|
+
return this.getName(fnCLass);
|
|
404
|
+
}
|
|
405
|
+
static getConfigs(target) {
|
|
406
|
+
return CLASSNAME.getClassConfig(target);
|
|
407
|
+
}
|
|
408
|
+
static describeProperites(target) {
|
|
409
|
+
const d1 = describeFromClassStringify(target);
|
|
410
|
+
const d2 = describeByDefaultModelsAndMapping(target);
|
|
411
|
+
let uniq = {};
|
|
412
|
+
// @ts-ignore
|
|
413
|
+
d1.concat(d2).forEach(p => uniq[p] = p);
|
|
414
|
+
return Object.keys(uniq)
|
|
415
|
+
.filter(d => !!d)
|
|
416
|
+
.filter(d => typeof target.prototype[d] !== 'function');
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
const CLASS = {
|
|
420
|
+
NAME: CLASSNAME.CLASSNAME,
|
|
421
|
+
setName: setClassName,
|
|
422
|
+
getBy: TchHelpers.getBy,
|
|
423
|
+
getSingleton(target) {
|
|
424
|
+
if (typeof target !== 'function') {
|
|
425
|
+
console.error(`[typescript-class-helpers][setSingletonObj] Type of target is not a function`);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const config = TchHelpers.getConfigs(target)[0];
|
|
429
|
+
return config.singleton;
|
|
430
|
+
},
|
|
431
|
+
setSingletonObj(target, singletonObject) {
|
|
432
|
+
if (typeof target !== 'function') {
|
|
433
|
+
console.error(`[typescript-class-helpers][setSingletonObj] Type of target is not a function`);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (Array.isArray(singletonObject)) {
|
|
437
|
+
console.error(`[typescript-class-helpers][setSingletonObj] Singleton instance cant be an array`);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (typeof singletonObject !== 'object') {
|
|
441
|
+
console.error(`[typescript-class-helpers][setSingletonObj] Singleton instance cant must be a object`);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const className = CLASS.getName(target);
|
|
445
|
+
const config = TchHelpers.getConfigs(target)[0];
|
|
446
|
+
if (config.singleton) {
|
|
447
|
+
console.warn(`[typescript-class-helpers] You are trying to set singleton of "${className}" second time with different object.`);
|
|
448
|
+
}
|
|
449
|
+
config.singleton = singletonObject;
|
|
450
|
+
},
|
|
451
|
+
getConfigs: TchHelpers.getConfigs,
|
|
452
|
+
getConfig: (target) => {
|
|
453
|
+
return _.first(TchHelpers.getConfigs(target));
|
|
454
|
+
},
|
|
455
|
+
getFromObject: TchHelpers.getFromObject,
|
|
456
|
+
getName: TchHelpers.getName,
|
|
457
|
+
getNameFromObject: TchHelpers.getNameFromObject,
|
|
458
|
+
describeProperites: TchHelpers.describeProperites,
|
|
459
|
+
OBJECT: (obj) => {
|
|
460
|
+
return {
|
|
461
|
+
get indexValue() {
|
|
462
|
+
return CLASSNAME.getObjectIndexValue(obj);
|
|
463
|
+
},
|
|
464
|
+
get indexProperty() {
|
|
465
|
+
return CLASSNAME.getObjectIndexPropertyValue(obj);
|
|
466
|
+
},
|
|
467
|
+
get isClassObject() {
|
|
468
|
+
if (!_.isObject(obj) || _.isArray(obj) || _.isRegExp(obj) ||
|
|
469
|
+
_.isBuffer(obj) || _.isArrayBuffer(obj)) {
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
if (_.isDate(obj)) {
|
|
473
|
+
return true;
|
|
474
|
+
}
|
|
475
|
+
const className = CLASS.getNameFromObject(obj);
|
|
476
|
+
return _.isString(className) && className !== 'Object';
|
|
477
|
+
},
|
|
478
|
+
isEqual: (anotherObj, compareDeep = false) => {
|
|
479
|
+
if (!CLASS.OBJECT(obj).isClassObject || !CLASS.OBJECT(anotherObj).isClassObject) {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
if (obj === anotherObj) {
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
const v1 = CLASSNAME.getObjectIndexValue(obj);
|
|
486
|
+
const v2 = CLASSNAME.getObjectIndexValue(anotherObj);
|
|
487
|
+
const f1 = CLASSNAME.getObjectClassFamily(obj);
|
|
488
|
+
const f2 = CLASSNAME.getObjectClassFamily(anotherObj);
|
|
489
|
+
const isFamilyDiff = (!_.isString(f1) || !_.isString(f2) || (f1 !== f2));
|
|
490
|
+
if (isFamilyDiff) {
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
if (!CLASS.OBJECT(obj).isClassObject || !CLASS.OBJECT(anotherObj).isClassObject) {
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
if ((_.isNumber(v1) && _.isNumber(v2)) || (_.isString(v1) && _.isString(v2))) {
|
|
497
|
+
const res = (v1 === v2);
|
|
498
|
+
// @ts-ignore
|
|
499
|
+
return res;
|
|
500
|
+
}
|
|
501
|
+
if (compareDeep) {
|
|
502
|
+
return _.isEqual(v1, v2);
|
|
503
|
+
}
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
;
|
|
510
510
|
({}); // @--end-of-file-for-module=typescript-class-helpers lib/index.ts
|
|
511
511
|
|
|
512
|
-
/**
|
|
513
|
-
* Generated bundle index. Do not edit.
|
|
512
|
+
/**
|
|
513
|
+
* Generated bundle index. Do not edit.
|
|
514
514
|
*/
|
|
515
515
|
|
|
516
516
|
export { CLASS, Models, SYMBOL, TchHelpers };
|