typescript-class-helpers 21.0.26 → 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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-class-helpers/browser",
3
- "version": "21.0.26",
3
+ "version": "21.0.27",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^21.0.0",
6
6
  "@angular/core": "^21.0.0"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-class-helpers/browser-prod",
3
- "version": "21.0.26",
3
+ "version": "21.0.27",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^21.0.0",
6
6
  "@angular/core": "^21.0.0"
@@ -21,4 +21,4 @@ export declare const CURRENT_PACKAGE_TAON_VERSION = "v21";
21
21
  /**
22
22
  * Autogenerated by current cli tool. Use *tnp release* to bump version.
23
23
  */
24
- export declare const CURRENT_PACKAGE_VERSION = "21.0.26";
24
+ export declare const CURRENT_PACKAGE_VERSION = "21.0.27";
@@ -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.26';
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
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "typescript-class-helpers/lib",
3
- "version": "21.0.26"
3
+ "version": "21.0.27"
4
4
  }
@@ -1,14 +1,26 @@
1
- const BUILD_FRAMEWORK_CLI_NAME = "tnp";
2
- const APP_ID = "com.domain.example.typescript-class-helpers";
3
- const BUILD_BASE_HREF = "";
4
- const PROJECT_NPM_NAME = "typescript-class-helpers";
5
- const CURRENT_PACKAGE_TAON_VERSION = "v21";
6
- const CURRENT_PACKAGE_VERSION = "21.0.26";
7
- export {
8
- APP_ID,
9
- BUILD_BASE_HREF,
10
- BUILD_FRAMEWORK_CLI_NAME,
11
- CURRENT_PACKAGE_TAON_VERSION,
12
- CURRENT_PACKAGE_VERSION,
13
- PROJECT_NPM_NAME
14
- };
1
+ // THIS FILE IS GENERATED - DO NOT MODIFY
2
+ /**
3
+ * Autogenerated by current cli tool
4
+ */
5
+ export const BUILD_FRAMEWORK_CLI_NAME = 'tnp';
6
+ /**
7
+ * This value can be change in taon.jsonc (appId)
8
+ */
9
+ export const APP_ID = 'com.domain.example.typescript-class-helpers';
10
+ /**
11
+ * Autogenerated by current cli tool
12
+ */
13
+ export const BUILD_BASE_HREF = '';
14
+ /**
15
+ * This value can be change in taon.jsonc (overrideNpmName)
16
+ */
17
+ export const PROJECT_NPM_NAME = 'typescript-class-helpers';
18
+ /**
19
+ * Taon version from you project taon.json
20
+ */
21
+ export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
22
+ /**
23
+ * Autogenerated by current cli tool. Use *tnp release* to bump version.
24
+ */
25
+ export const CURRENT_PACKAGE_VERSION = '21.0.27';
26
+ // THIS FILE IS GENERATED - DO NOT MODIFY
@@ -1,155 +1,185 @@
1
- import { ___NS__first, ___NS__isFunction, ___NS__isNil, ___NS__isString, UtilsOs__NS__isBrowser } from "tnp-core/lib-prod";
2
- import { Models__NS__ClassConfig } 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
- import * as FormData from "form-data";
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
11
13
  function getClasses() {
12
- const s = getStorage();
13
- return s[SYMBOL.CLASSES];
14
+ const s = getStorage();
15
+ return s[SYMBOL.CLASSES];
14
16
  }
15
- function CLASSNAME__NS__getClassConfig(target, configs = [], callerTarget) {
16
- if (!___NS__isFunction(target)) {
17
- throw `[typescript-class-helper][getClassConfig] Cannot get class config from: ${target}`;
18
- }
19
- let config;
20
- const parentClass = Object.getPrototypeOf(target);
21
- const isValidParent = ___NS__isFunction(parentClass) && parentClass.name !== "";
22
- if (registerd.classes.includes(target)) {
23
- config = registerd.configs[registerd.classes.findIndex((c) => c === target)];
24
- } else {
25
- config = new Models__NS__ClassConfig();
26
- config.classReference = target;
27
- registerd.classes.push(target);
28
- }
29
- registerd.configs[registerd.classes.findIndex((c) => c === target)] = config;
30
- if (callerTarget) {
31
- const callerTargetConfig = registerd.configs[registerd.classes.findIndex((c) => c === callerTarget)];
32
- if (!config.vChildren.includes(callerTargetConfig)) {
33
- config.vChildren.push(callerTargetConfig);
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}`;
34
21
  }
35
- callerTargetConfig.vParent = config;
36
- }
37
- configs.push(config);
38
- return isValidParent ? CLASSNAME__NS__getClassConfig(parentClass, configs, target) : configs;
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;
39
46
  }
40
- function CLASSNAME__NS__CLASSNAME(className, options) {
41
- return function(target) {
42
- return setClassName(target, className, options);
43
- };
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
+ };
44
57
  }
45
- function CLASSNAME__NS__getClassName(target, production = false) {
46
- if (___NS__isNil(target)) {
47
- return void 0;
48
- }
49
- if (___NS__isString(target)) {
50
- Helpers__NS__log(
51
- `[typescript-class-helpers][getClassName] target is string: '${target}', produciton: ${production}`
52
- );
53
- return target;
54
- }
55
- if (target === Date) {
56
- return "Date";
57
- }
58
- if (target === FormData) {
59
- return "FormData";
60
- }
61
- if (!___NS__isFunction(target)) {
62
- Helpers__NS__log(
63
- `[typescript-class-helpers][getClassName] target is not a class`
64
- );
65
- return void 0;
66
- }
67
- if (target[SYMBOL.ClassNameStaticProperty]) {
68
- return target[SYMBOL.ClassNameStaticProperty];
69
- }
70
- const configs = CLASSNAME__NS__getClassConfig(target);
71
- const config = ___NS__first(configs);
72
- const classNameInBrowser = config?.classNameInBrowser;
73
- if (UtilsOs__NS__isBrowser && ___NS__isString(classNameInBrowser)) {
74
- return classNameInBrowser;
75
- }
76
- const className = config?.className;
77
- if (typeof className === "string") {
78
- return className;
79
- }
80
- if (production) {
81
- console.log("class without @CLASS.NAME deocrator", target);
82
- throw new Error(ERROR_MSG_CLASS_WITHOUT_DECORATOR);
83
- } else {
84
- }
85
- if (target.name?.startsWith("class_")) {
86
- return "";
87
- }
88
- return target.name;
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;
89
115
  }
90
- function CLASSNAME__NS__getObjectIndexPropertyValue(obj) {
91
- const className = TchHelpers.getNameFromObject(obj);
92
- let c = getClasses().find((c2) => c2.className === className);
93
- if (c) {
94
- return c.uniqueKey;
95
- }
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
+ }
96
125
  }
97
- function CLASSNAME__NS__getClassFamilyByClassName(className) {
98
- let c = getClasses().find((c2) => c2.className === className);
99
- if (c) {
100
- return c.classFamily;
101
- }
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
+ }
102
133
  }
103
- function CLASSNAME__NS__getObjectClassFamily(obj) {
104
- const className = TchHelpers.getNameFromObject(obj);
105
- let c = getClasses().find((c2) => c2.className === className);
106
- if (c) {
107
- return c.classFamily;
108
- }
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
+ }
109
143
  }
110
- function CLASSNAME__NS__getObjectIndexValue(obj) {
111
- const className = TchHelpers.getNameFromObject(obj);
112
- let c = getClasses().find((c2) => c2.className === className);
113
- if (c && ___NS__isString(c.uniqueKey)) {
114
- return obj[c.uniqueKey];
115
- }
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
+ }
116
152
  }
117
- function CLASSNAME__NS__getClassBy(className) {
118
- let res;
119
- if (Array.isArray(className)) {
120
- if (className.length !== 1) {
121
- throw `Mapping error... please use proper class names:
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:
122
158
  {
123
159
  propertyObject: 'MyClassName',
124
160
  propertyWithArray: ['MyClassName']
125
161
  }
126
162
 
127
163
  `;
164
+ }
165
+ className = className[0];
128
166
  }
129
- className = className[0];
130
- }
131
- if (typeof className === "function") {
132
- res = className;
133
- }
134
- if (className === "Date") {
135
- res = Date;
136
- }
137
- if (className === "FormData") {
138
- res = FormData;
139
- }
140
- let c = getClasses().find((c2) => c2.className === className);
141
- if (c) {
142
- res = c.target;
143
- }
144
- return res;
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;
145
184
  }
146
- export {
147
- CLASSNAME__NS__CLASSNAME,
148
- CLASSNAME__NS__getClassBy,
149
- CLASSNAME__NS__getClassConfig,
150
- CLASSNAME__NS__getClassFamilyByClassName,
151
- CLASSNAME__NS__getClassName,
152
- CLASSNAME__NS__getObjectClassFamily,
153
- CLASSNAME__NS__getObjectIndexPropertyValue,
154
- CLASSNAME__NS__getObjectIndexValue
155
- };
185
+ //end of namespace CLASSNAME
@@ -1,49 +1,72 @@
1
- import { ___NS__isArray, ___NS__isFunction } from "tnp-core/lib-prod";
2
- import { SYMBOL } from "./symbols";
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
+ */
3
7
  const FRegEx = new RegExp(/(?:this\.)(.+?(?= ))/g);
4
- function describeFromClassStringify(target, parent = false) {
5
- var result = [];
6
- if (parent) {
7
- var proto = Object.getPrototypeOf(target.prototype);
8
- if (proto) {
9
- result = result.concat(describeFromClassStringify(proto.constructor, parent));
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
+ }
10
17
  }
11
- }
12
- const classString = target.toString();
13
- const matches = classString.match(FRegEx) || [];
14
- result = result.concat(matches);
15
- return result.map(
16
- (prop) => prop.replace("this.", "").replace(".", "").replace(")", "").replace("(", "")
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('(', ''));
18
29
  }
19
- function describeByDefaultModelsAndMapping(target) {
20
- let res = {};
21
- if (target) {
22
- if (target[SYMBOL.DEFAULT_MODEL]) {
23
- Object.keys(target[SYMBOL.DEFAULT_MODEL]).filter((key) => {
24
- return !___NS__isFunction(target[SYMBOL.DEFAULT_MODEL][key]);
25
- }).forEach((key) => {
26
- return res[key] = null;
27
- });
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
+ }
28
68
  }
29
- let mapping = target[SYMBOL.MODELS_MAPPING];
30
- if (___NS__isArray(mapping)) {
31
- mapping.forEach((m) => {
32
- Object.keys(m).forEach((key) => {
33
- res[key] = null;
34
- });
35
- });
36
- } else if (mapping) {
37
- Object.keys(mapping).forEach((key) => {
38
- res[key] = null;
39
- });
40
- }
41
- }
42
- let propNames = Object.keys(res).filter((f) => !!f);
43
- propNames = (!propNames.includes("id") ? ["id"] : []).concat(propNames);
44
- return propNames;
69
+ let propNames = Object.keys(res).filter(f => !!f);
70
+ propNames = (!propNames.includes('id') ? ['id'] : []).concat(propNames);
71
+ return propNames;
45
72
  }
46
- export {
47
- describeByDefaultModelsAndMapping,
48
- describeFromClassStringify
49
- };