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