ng2-rest 21.0.22 → 21.0.24

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 (45) hide show
  1. package/browser/package.json +1 -1
  2. package/browser-prod/package.json +1 -1
  3. package/lib/build-info._auto-generated_.d.ts +1 -1
  4. package/lib/build-info._auto-generated_.js +1 -1
  5. package/lib/package.json +1 -1
  6. package/lib-prod/axios-interceptors.js +16 -0
  7. package/lib-prod/{build-info._auto-generated_.ts → build-info._auto-generated_.js} +1 -2
  8. package/lib-prod/content-type.js +11 -0
  9. package/lib-prod/{cookie.ts → cookie.js} +7 -17
  10. package/lib-prod/env/{env.angular-node-app.ts → env.angular-node-app.js} +1 -1
  11. package/lib-prod/env/{env.docs-webapp.ts → env.docs-webapp.js} +1 -1
  12. package/lib-prod/env/{env.electron-app.ts → env.electron-app.js} +1 -1
  13. package/lib-prod/env/{env.mobile-app.ts → env.mobile-app.js} +1 -1
  14. package/lib-prod/env/{env.npm-lib-and-cli-tool.ts → env.npm-lib-and-cli-tool.js} +1 -1
  15. package/lib-prod/env/{env.vscode-plugin.ts → env.vscode-plugin.js} +1 -1
  16. package/lib-prod/helpers.js +17 -0
  17. package/lib-prod/{index._auto-generated_.ts → index._auto-generated_.js} +1 -1
  18. package/lib-prod/{index.ts → index.js} +1 -1
  19. package/lib-prod/mapping.js +271 -0
  20. package/lib-prod/models.js +173 -0
  21. package/lib-prod/other/simple-resource.js +129 -0
  22. package/lib-prod/package.json +1 -1
  23. package/lib-prod/params.js +304 -0
  24. package/lib-prod/resource-service.js +205 -0
  25. package/lib-prod/rest-headers.js +136 -0
  26. package/lib-prod/rest-request.js +373 -0
  27. package/lib-prod/rest.class.js +131 -0
  28. package/lib-prod.split-namespaces.json +5 -61
  29. package/package.json +1 -1
  30. package/websql/package.json +1 -1
  31. package/websql-prod/package.json +1 -1
  32. package/lib-prod/axios-interceptors.ts +0 -47
  33. package/lib-prod/content-type.ts +0 -13
  34. package/lib-prod/helpers.ts +0 -22
  35. package/lib-prod/lib-info.md +0 -8
  36. package/lib-prod/mapping.ts +0 -342
  37. package/lib-prod/migrations/migrations-info.md +0 -6
  38. package/lib-prod/models.ts +0 -370
  39. package/lib-prod/other/simple-resource.ts +0 -226
  40. package/lib-prod/params.ts +0 -332
  41. package/lib-prod/resource-service.ts +0 -270
  42. package/lib-prod/rest-headers.ts +0 -161
  43. package/lib-prod/rest-request.ts +0 -662
  44. package/lib-prod/rest.class.ts +0 -244
  45. /package/lib-prod/env/{index.ts → index.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng2-rest/browser",
3
- "version": "21.0.22",
3
+ "version": "21.0.24",
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": "ng2-rest/browser-prod",
3
- "version": "21.0.22",
3
+ "version": "21.0.24",
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.22";
24
+ export declare const CURRENT_PACKAGE_VERSION = "21.0.24";
@@ -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.22';
28
+ exports.CURRENT_PACKAGE_VERSION = '21.0.24';
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": "ng2-rest/lib",
3
- "version": "21.0.22"
3
+ "version": "21.0.24"
4
4
  }
@@ -0,0 +1,16 @@
1
+ import axios from 'axios';
2
+ import { from } from 'rxjs';
3
+ // Optional helper for passing around context (browser/client)
4
+ // === Backend handler (last in chain) ===
5
+ export class AxiosBackendHandler {
6
+ handle(req) {
7
+ // axios returns a Promise; wrap as Observable
8
+ return from(axios.request(req));
9
+ }
10
+ }
11
+ // === Chain builder (request: forward order, response: reverse order) ===
12
+ export const buildInterceptorChain = (interceptors, backend) => {
13
+ return interceptors.reduceRight((next, interceptor) => ({
14
+ handle: req => interceptor.intercept({ req, next }),
15
+ }), backend);
16
+ };
@@ -22,6 +22,5 @@ export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
22
22
  /**
23
23
  * Autogenerated by current cli tool. Use *tnp release* to bump version.
24
24
  */
25
- export const CURRENT_PACKAGE_VERSION = '21.0.22';
25
+ export const CURRENT_PACKAGE_VERSION = '21.0.24';
26
26
  // THIS FILE IS GENERATED - DO NOT MODIFY
27
-
@@ -0,0 +1,11 @@
1
+ import { RestHeaders } from "./rest-headers";
2
+ export const CONTENT_TYPE = {
3
+ APPLICATION_JSON: RestHeaders.from({
4
+ 'Content-Type': 'application/json',
5
+ 'Accept': 'application/json'
6
+ }),
7
+ APPLICATINO_VND_API_JSON: RestHeaders.from({
8
+ 'Content-Type': 'application/vnd.api+json',
9
+ 'Accept': 'application/vnd.api+json'
10
+ }),
11
+ };
@@ -1,36 +1,26 @@
1
1
  export class Cookie {
2
-
3
- public static get Instance(): Cookie {
2
+ static get Instance() {
4
3
  if (!Cookie.__instance) {
5
4
  Cookie.__instance = new Cookie();
6
5
  }
7
- return Cookie.__instance as any;
6
+ return Cookie.__instance;
8
7
  }
9
- private static __instance;
10
-
11
- private constructor() {
8
+ constructor() {
12
9
  }
13
-
14
- read(name: string) {
10
+ read(name) {
15
11
  var result = new RegExp('(?:^|; )' + encodeURIComponent(name) + '=([^;]*)').exec(document.cookie);
16
12
  return result ? result[1] : null;
17
13
  }
18
-
19
- write(name: string, value: string, days?: number) {
14
+ write(name, value, days) {
20
15
  if (!days) {
21
16
  days = 365 * 20;
22
17
  }
23
-
24
18
  var date = new Date();
25
19
  date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
26
-
27
20
  var expires = "; expires=" + date.toUTCString();
28
-
29
21
  document.cookie = name + "=" + value + expires + "; path=/";
30
22
  }
31
-
32
- remove(name: string) {
23
+ remove(name) {
33
24
  this.write(name, "", -1);
34
25
  }
35
-
36
- }
26
+ }
@@ -63,4 +63,4 @@ export const ENV_ANGULAR_NODE_APP_IS_CI_PROCESS = undefined;
63
63
  export const ENV_ANGULAR_NODE_APP_DOCKER_ADDITIONAL_CONTAINER = undefined;
64
64
  export const ENV_ANGULAR_NODE_APP_DOCKER_SKIP_START_IN_ORDER = undefined;
65
65
  export const ENV_ANGULAR_NODE_APP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
66
- // THIS FILE IS GENERATED - DO NOT MODIFY
66
+ // THIS FILE IS GENERATED - DO NOT MODIFY
@@ -63,4 +63,4 @@ export const ENV_DOCS_WEBAPP_IS_CI_PROCESS = undefined;
63
63
  export const ENV_DOCS_WEBAPP_DOCKER_ADDITIONAL_CONTAINER = undefined;
64
64
  export const ENV_DOCS_WEBAPP_DOCKER_SKIP_START_IN_ORDER = undefined;
65
65
  export const ENV_DOCS_WEBAPP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
66
- // THIS FILE IS GENERATED - DO NOT MODIFY
66
+ // THIS FILE IS GENERATED - DO NOT MODIFY
@@ -63,4 +63,4 @@ export const ENV_ELECTRON_APP_IS_CI_PROCESS = undefined;
63
63
  export const ENV_ELECTRON_APP_DOCKER_ADDITIONAL_CONTAINER = undefined;
64
64
  export const ENV_ELECTRON_APP_DOCKER_SKIP_START_IN_ORDER = undefined;
65
65
  export const ENV_ELECTRON_APP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
66
- // THIS FILE IS GENERATED - DO NOT MODIFY
66
+ // THIS FILE IS GENERATED - DO NOT MODIFY
@@ -63,4 +63,4 @@ export const ENV_MOBILE_APP_IS_CI_PROCESS = undefined;
63
63
  export const ENV_MOBILE_APP_DOCKER_ADDITIONAL_CONTAINER = undefined;
64
64
  export const ENV_MOBILE_APP_DOCKER_SKIP_START_IN_ORDER = undefined;
65
65
  export const ENV_MOBILE_APP_DOCKER_SKIP_USING_MYSQL_DB = undefined;
66
- // THIS FILE IS GENERATED - DO NOT MODIFY
66
+ // THIS FILE IS GENERATED - DO NOT MODIFY
@@ -63,4 +63,4 @@ export const ENV_NPM_LIB_AND_CLI_TOOL_IS_CI_PROCESS = undefined;
63
63
  export const ENV_NPM_LIB_AND_CLI_TOOL_DOCKER_ADDITIONAL_CONTAINER = undefined;
64
64
  export const ENV_NPM_LIB_AND_CLI_TOOL_DOCKER_SKIP_START_IN_ORDER = undefined;
65
65
  export const ENV_NPM_LIB_AND_CLI_TOOL_DOCKER_SKIP_USING_MYSQL_DB = undefined;
66
- // THIS FILE IS GENERATED - DO NOT MODIFY
66
+ // THIS FILE IS GENERATED - DO NOT MODIFY
@@ -63,4 +63,4 @@ export const ENV_VSCODE_PLUGIN_IS_CI_PROCESS = undefined;
63
63
  export const ENV_VSCODE_PLUGIN_DOCKER_ADDITIONAL_CONTAINER = undefined;
64
64
  export const ENV_VSCODE_PLUGIN_DOCKER_SKIP_START_IN_ORDER = undefined;
65
65
  export const ENV_VSCODE_PLUGIN_DOCKER_SKIP_USING_MYSQL_DB = undefined;
66
- // THIS FILE IS GENERATED - DO NOT MODIFY
66
+ // THIS FILE IS GENERATED - DO NOT MODIFY
@@ -0,0 +1,17 @@
1
+ import { Mapping__NS__decode, Mapping__NS__encode } from './mapping';
2
+ //namespace Helpers
3
+ export const Helpers__NS__getMapping = () => {
4
+ return {
5
+ encode(json, mapping) {
6
+ return Mapping__NS__encode(json, mapping);
7
+ },
8
+ decode(json, autodetect = false) {
9
+ return Mapping__NS__decode(json, autodetect);
10
+ },
11
+ };
12
+ };
13
+ export const Helpers__NS__checkValidUrl = (url) => {
14
+ let regex = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/;
15
+ return regex.test(url);
16
+ };
17
+ //end of namespace Helpers
@@ -2,4 +2,4 @@
2
2
  // This file is auto-generated during init process. Do not modify.
3
3
  // This is only placeholder.
4
4
  // Use property "shouldGenerateAutogenIndexFile: true"
5
- // in taon.jsonc to enable ts exports auto generation.
5
+ // in taon.jsonc to enable ts exports auto generation.
@@ -7,4 +7,4 @@ export * from './helpers';
7
7
  export * from './content-type';
8
8
  export * from './axios-interceptors';
9
9
  export { SimpleResource } from './other/simple-resource';
10
- export { interpolateParamsToUrl } from './params';
10
+ export { interpolateParamsToUrl } from './params';
@@ -0,0 +1,271 @@
1
+ import { Stream } from 'node:stream'; // @backend
2
+ import { walk } from 'lodash-walk-object/lib-prod';
3
+ import { ___NS__cloneDeep, ___NS__first, ___NS__get, ___NS__isArray, ___NS__isBoolean, ___NS__isFunction, ___NS__isNull, ___NS__isNumber, ___NS__isObject, ___NS__isString, ___NS__isUndefined, ___NS__merge, ___NS__omit, ___NS__set, UtilsOs__NS__isBrowser } from 'tnp-core/lib-prod';
4
+ import { CLASS, SYMBOL } from 'typescript-class-helpers/lib-prod';
5
+ //namespace Mapping
6
+ export function Mapping__NS__decode(json, autodetect = false) {
7
+ // console.log('DECODE isBrowser', HelpersLog.isBrowser)
8
+ if (___NS__isUndefined(json)) {
9
+ return void 0;
10
+ }
11
+ let mapping = decodeFromDecorator(___NS__isArray(json) ? ___NS__first(json) : json, !autodetect);
12
+ if (autodetect) {
13
+ mapping = ___NS__merge(getMappingNaive(json), mapping);
14
+ }
15
+ return mapping;
16
+ }
17
+ export function Mapping__NS__encode(json, mapping, circular = []) {
18
+ if (___NS__isString(json) || ___NS__isBoolean(json) || ___NS__isNumber(json)) {
19
+ return json;
20
+ }
21
+ if (mapping['']) {
22
+ const decoratorMapping = Mapping__NS__getModelsMapping(CLASS.getBy(mapping['']));
23
+ mapping = ___NS__merge(mapping, decoratorMapping);
24
+ }
25
+ let res;
26
+ if (___NS__isArray(circular) && circular.length > 0) {
27
+ res = setMappingCirc(json, mapping, circular);
28
+ }
29
+ else {
30
+ res = setMapping(json, mapping);
31
+ }
32
+ return res;
33
+ }
34
+ function decodeFromDecorator(json, production = false) {
35
+ const entityClass = CLASS.getFromObject(json);
36
+ const mappings = Mapping__NS__getModelsMapping(entityClass);
37
+ return mappings;
38
+ }
39
+ export function Mapping__NS__getModelsMapping(entity) {
40
+ if (!___NS__isFunction(entity) || entity === Object) {
41
+ return {};
42
+ }
43
+ const className = CLASS.getName(entity);
44
+ // console.log(`getMaping for: '${className}' `)
45
+ let enityOWnMapping = ___NS__isArray(entity[SYMBOL.MODELS_MAPPING])
46
+ ? entity[SYMBOL.MODELS_MAPPING]
47
+ : [{ '': className }];
48
+ let res = {};
49
+ let parents = enityOWnMapping
50
+ .filter(m => !___NS__isUndefined(m['']) && m[''] !== className)
51
+ .map(m => m['']);
52
+ enityOWnMapping.reverse().forEach(m => {
53
+ m = ___NS__cloneDeep(m);
54
+ // console.log(`'${className}' m:`, m)
55
+ Object.keys(m).forEach(key => {
56
+ const v = m[key];
57
+ const isArr = ___NS__isArray(v);
58
+ const model = isArr ? ___NS__first(v) : v;
59
+ if (parents.includes(model)) {
60
+ m[key] = isArr ? [className] : className;
61
+ }
62
+ });
63
+ res = ___NS__merge(res, m);
64
+ });
65
+ res[''] = className;
66
+ // console.log(`mapping for ${className} : ${JSON.stringify(res)}`)
67
+ return res;
68
+ }
69
+ function add(o, path, mapping = {}) {
70
+ if (!o || Array.isArray(o) || typeof o !== 'object')
71
+ return;
72
+ const proptotypeObj = Object.getPrototypeOf(o);
73
+ if (!proptotypeObj) {
74
+ return;
75
+ }
76
+ const objectClassName = CLASS.getName(proptotypeObj.constructor);
77
+ const resolveClass = CLASS.getBy(objectClassName);
78
+ if (!resolveClass) {
79
+ if (objectClassName !== 'Object') {
80
+ if (UtilsOs__NS__isBrowser) {
81
+ console.error(`Cannot resolve class "${objectClassName}" while mapping.`);
82
+ }
83
+ }
84
+ return;
85
+ }
86
+ if (!mapping[path])
87
+ mapping[path] = CLASS.getName(resolveClass);
88
+ }
89
+ /**
90
+ * USE ONLY IN DEVELOPMENT
91
+ * @param c
92
+ * @param path
93
+ * @param mapping
94
+ * @param level
95
+ */
96
+ function getMappingNaive(c, path = '', mapping = {}, level = 0) {
97
+ if (c === null || c === undefined) {
98
+ return;
99
+ }
100
+ //#region @backend
101
+ if (c instanceof Stream) {
102
+ return;
103
+ }
104
+ //#endregion
105
+ // console.log({c})
106
+ if (Array.isArray(c)) {
107
+ c.forEach(c => getMappingNaive(c, path, mapping, level));
108
+ return mapping;
109
+ }
110
+ if (++level === 16)
111
+ return;
112
+ add(c, path, mapping);
113
+ for (var p in c) {
114
+ if (___NS__isFunction(c.hasOwnProperty) && c.hasOwnProperty(p)) {
115
+ const v = c[p];
116
+ if (Array.isArray(v) && v.length > 0) {
117
+ // reducer as impovement
118
+ v.forEach((elem, i) => {
119
+ // const currentPaht = [`path[${i}]`, p].filter(c => c.trim() != '').join('.');
120
+ const currentPaht = [path, p].filter(c => c.trim() != '').join('.');
121
+ getMappingNaive(elem, currentPaht, mapping, level);
122
+ });
123
+ }
124
+ else if (typeof v === 'object') {
125
+ const currentPaht = [path, p].filter(c => c.trim() != '').join('.');
126
+ add(v, currentPaht, mapping);
127
+ getMappingNaive(v, currentPaht, mapping, level);
128
+ }
129
+ }
130
+ }
131
+ return mapping;
132
+ }
133
+ function getMappingPathFrom(pathLodhas) {
134
+ if (!___NS__isString(pathLodhas)) {
135
+ return void 0;
136
+ }
137
+ const regex = /\[([0-9a-zA-Z]|\'|\")*\]/g;
138
+ pathLodhas = pathLodhas.replace(regex, '').replace('..', '.');
139
+ if (pathLodhas.startsWith('.')) {
140
+ pathLodhas = pathLodhas.slice(1);
141
+ }
142
+ return pathLodhas;
143
+ }
144
+ function setMappingCirc(json, mapping = {}, circular = []) {
145
+ const mainClassFn = !___NS__isArray(json) && CLASS.getBy(mapping['']);
146
+ // console.log(mapping)
147
+ walk.Object(json, (v, lodashPath, changeValue) => {
148
+ if (!___NS__isUndefined(v) && !___NS__isNull(v)) {
149
+ const mappingPath = getMappingPathFrom(lodashPath);
150
+ if (!___NS__isUndefined(mapping[mappingPath])) {
151
+ const isArray = ___NS__isArray(mapping[mappingPath]);
152
+ if (!isArray) {
153
+ const className = isArray
154
+ ? ___NS__first(mapping[mappingPath])
155
+ : mapping[mappingPath];
156
+ const classFN = CLASS.getBy(className);
157
+ if (___NS__isFunction(classFN)) {
158
+ // console.log(`mapping: '${mappingPath}', lp: '${lodashPath}' class: '${className}' , set `, v.location)
159
+ changeValue(___NS__merge(new classFN(), v));
160
+ }
161
+ }
162
+ }
163
+ }
164
+ });
165
+ circular.forEach(c => {
166
+ const ref = ___NS__get(json, c.circuralTargetPath);
167
+ ___NS__set(json, c.pathToObj, ref);
168
+ });
169
+ if (___NS__isFunction(mainClassFn)) {
170
+ json = ___NS__merge(new mainClassFn(), json);
171
+ }
172
+ return json;
173
+ }
174
+ function setMapping(json, mapping = {}) {
175
+ // console.log('mapping', mapping)
176
+ if (Array.isArray(json)) {
177
+ return json.map(j => {
178
+ return setMapping(j, mapping);
179
+ });
180
+ }
181
+ const mainClassFn = CLASS.getBy(mapping['']);
182
+ for (const key in json) {
183
+ if (json.hasOwnProperty(key)) {
184
+ // if (mainClassFn && mainClassFn.name === 'Project') {
185
+ // // console.log(`OWn property: "${key}"`)
186
+ // }
187
+ if (___NS__isArray(json[key])) {
188
+ json[key] = json[key].map(arrObj => {
189
+ const objMapping = Mapping__NS__getModelsMapping(CLASS.getBy(mapping[key]));
190
+ return setMapping(arrObj, objMapping);
191
+ });
192
+ }
193
+ else if (___NS__isObject(json[key])) {
194
+ const objMapping = Mapping__NS__getModelsMapping(CLASS.getBy(mapping[key]));
195
+ json[key] = setMapping(json[key], objMapping);
196
+ }
197
+ }
198
+ // else {
199
+ // if (mainClassFn && mainClassFn.name === 'Project') {
200
+ // // console.log(`Not own property: "${key}"`)
201
+ // }
202
+ // }
203
+ }
204
+ Object.keys(mapping)
205
+ .filter(key => key !== '' && key.split('.').length >= 2)
206
+ .forEach(lodasPath => {
207
+ // console.log(`Loadsh path: ${lodasPath}`)
208
+ const objMapping = Mapping__NS__getModelsMapping(CLASS.getBy(mapping[lodasPath]));
209
+ const input = ___NS__get(json, lodasPath);
210
+ if (!___NS__isUndefined(input)) {
211
+ const res = setMapping(input, objMapping);
212
+ ___NS__set(json, lodasPath, res);
213
+ }
214
+ });
215
+ if (!mainClassFn) {
216
+ return json;
217
+ }
218
+ return ___NS__merge(new mainClassFn(), json);
219
+ }
220
+ export function Mapping__NS__DefaultModelWithMapping(defaultModelValues, mapping) {
221
+ return function (target) {
222
+ if (!___NS__isArray(target[SYMBOL.MODELS_MAPPING])) {
223
+ target[SYMBOL.MODELS_MAPPING] = [];
224
+ }
225
+ target[SYMBOL.MODELS_MAPPING].push({
226
+ '': CLASS.getName(target),
227
+ });
228
+ if (___NS__isObject(mapping)) {
229
+ target[SYMBOL.MODELS_MAPPING] = target[SYMBOL.MODELS_MAPPING].concat(mapping);
230
+ Object.keys(mapping).forEach(key => {
231
+ const v = mapping;
232
+ if (___NS__isUndefined(v) || ___NS__isFunction(v)) {
233
+ throw `
234
+
235
+
236
+ Class: '${target.name}'
237
+ [ng2rest] Bad mapping value for path: ${key} , please use type: <string> or [<string>]
238
+ `;
239
+ }
240
+ });
241
+ }
242
+ if (___NS__isObject(defaultModelValues)) {
243
+ const toMerge = {};
244
+ const describedTarget = CLASS.describeProperites(target).filter(prop => /^([a-zA-Z0-9]|\_|\#)+$/.test(prop));
245
+ // console.log(`describedTarget: ${describedTarget} for ${target.name}`)
246
+ describedTarget.forEach(propDefInConstr => {
247
+ if (defaultModelValues[propDefInConstr]) {
248
+ console.warn(`
249
+
250
+ CONFLICT: default value for property: "${propDefInConstr}"
251
+ in class "${target.name}" already defined as typescript
252
+ default class proprty value.
253
+
254
+ `);
255
+ }
256
+ else {
257
+ toMerge[propDefInConstr] = null; // TODO from toString I can't know that
258
+ }
259
+ });
260
+ // console.log(`merge "${JSON.stringify(target.prototype)}" with "${JSON.stringify(defaultModelValues)}"`)
261
+ target[SYMBOL.DEFAULT_MODEL] = ___NS__merge(toMerge, defaultModelValues);
262
+ const propsToOmmit = Object.keys(target[SYMBOL.DEFAULT_MODEL]).filter(key => {
263
+ const descriptor = Object.getOwnPropertyDescriptor(target.prototype, key);
264
+ return !!descriptor;
265
+ });
266
+ ___NS__merge(target.prototype, ___NS__omit(target[SYMBOL.DEFAULT_MODEL], propsToOmmit));
267
+ // console.log(`DEFAULT VALUE MERGE for ${target.name}`)
268
+ }
269
+ };
270
+ }
271
+ //end of namespace Mapping
@@ -0,0 +1,173 @@
1
+ import { JSON10 } from 'json10/lib-prod';
2
+ import { ___NS__merge } from 'tnp-core/lib-prod';
3
+ import { CoreModels__NS__TaonHttpErrorCustomProp } from 'tnp-core/lib-prod';
4
+ import { Helpers__NS__isBlob } from 'tnp-core/lib-prod';
5
+ import { Cookie } from './cookie';
6
+ import { Mapping__NS__encode } from './mapping';
7
+ class RestCommonHttpResponseWrapper {
8
+ }
9
+ export class RestResponseWrapper extends RestCommonHttpResponseWrapper {
10
+ }
11
+ export class RestErrorResponseWrapper extends RestCommonHttpResponseWrapper {
12
+ }
13
+ [];
14
+ export class Models__NS__BaseBody {
15
+ toJSON(data, opt) {
16
+ opt = opt || { isJSONArray: false };
17
+ let r = opt.isJSONArray ? [] : {};
18
+ if (typeof data === 'string') {
19
+ try {
20
+ let parsed = JSON.parse(data);
21
+ if (typeof parsed === 'string' && parsed.trim().startsWith('{')) {
22
+ parsed = JSON.parse(parsed);
23
+ }
24
+ if (opt.parsingError && parsed[CoreModels__NS__TaonHttpErrorCustomProp]) {
25
+ return ___NS__merge(new RestErrorResponseWrapper(), parsed);
26
+ }
27
+ return parsed;
28
+ }
29
+ catch (e) { }
30
+ }
31
+ else if (typeof data === 'object') {
32
+ return data;
33
+ }
34
+ return r;
35
+ }
36
+ }
37
+ export class Models__NS__HttpBody extends Models__NS__BaseBody {
38
+ constructor(responseText, isArray = false, entity, circular) {
39
+ super();
40
+ this.responseText = responseText;
41
+ this.isArray = isArray;
42
+ this.entity = entity;
43
+ this.circular = circular;
44
+ }
45
+ get blob() {
46
+ return this.responseText;
47
+ }
48
+ get booleanValue() {
49
+ if (!Helpers__NS__isBlob(this.responseText)) {
50
+ return ['ok', 'true'].includes(this.responseText?.trim());
51
+ }
52
+ }
53
+ get numericValue() {
54
+ if (!Helpers__NS__isBlob(this.responseText)) {
55
+ return Number(this.responseText?.trim());
56
+ }
57
+ }
58
+ get rawJson() {
59
+ if (!Helpers__NS__isBlob(this.responseText)) {
60
+ let res = this.toJSON(this.responseText, { isJSONArray: this.isArray });
61
+ if (this.circular && Array.isArray(this.circular)) {
62
+ res = JSON10.parse(JSON.stringify(res), this.circular);
63
+ }
64
+ return res;
65
+ }
66
+ }
67
+ get json() {
68
+ const isBlob = Helpers__NS__isBlob(this.responseText);
69
+ if (isBlob) {
70
+ return void 0;
71
+ }
72
+ if (this.entity && typeof this.entity === 'function') {
73
+ return this.entity(); // @LAST
74
+ }
75
+ if (this.entity && typeof this.entity === 'object') {
76
+ const json = this.toJSON(this.responseText, {
77
+ isJSONArray: this.isArray,
78
+ });
79
+ return Mapping__NS__encode(json, this.entity, this.circular);
80
+ }
81
+ let res = this.toJSON(this.responseText, { isJSONArray: this.isArray });
82
+ if (this.circular && Array.isArray(this.circular)) {
83
+ res = JSON10.parse(JSON.stringify(res), this.circular);
84
+ }
85
+ return res;
86
+ }
87
+ /**
88
+ * undefined when blob
89
+ */
90
+ get text() {
91
+ if (!Helpers__NS__isBlob(this.responseText)) {
92
+ return this.responseText
93
+ .replace(/^\"/, '')
94
+ .replace(/\"$/, '');
95
+ }
96
+ }
97
+ }
98
+ export class Models__NS__ErrorBody extends Models__NS__BaseBody {
99
+ constructor(data) {
100
+ super();
101
+ this.data = data;
102
+ }
103
+ get json() {
104
+ return this.toJSON(this.data, { parsingError: true });
105
+ }
106
+ get text() {
107
+ return this.data;
108
+ }
109
+ }
110
+ export class Models__NS__BaseResponse {
111
+ static { this.cookies = Cookie.Instance; }
112
+ get cookies() {
113
+ return Models__NS__BaseResponse.cookies;
114
+ }
115
+ constructor(responseText, headers, statusCode, isArray = false) {
116
+ this.responseText = responseText;
117
+ this.headers = headers;
118
+ this.statusCode = statusCode;
119
+ this.isArray = isArray;
120
+ }
121
+ }
122
+ export class Models__NS__HttpResponse extends Models__NS__BaseResponse {
123
+ // public readonly TOTAL_COUNT_HEADER = 'X-Total-Count'.toLowerCase();
124
+ // public get totalElements(): number {
125
+ // return Number(this.headers.get(this.TOTAL_COUNT_HEADER));
126
+ // }
127
+ constructor(sourceRequest, responseText, headers, statusCode, entity, circular, jobid, isArray = false) {
128
+ // console.log({
129
+ // sourceRequest, responseText, headers, statusCode, entity, circular, jobid, isArray
130
+ // })
131
+ super(responseText, headers, statusCode, isArray);
132
+ this.sourceRequest = sourceRequest;
133
+ this.responseText = responseText;
134
+ this.headers = headers;
135
+ this.statusCode = statusCode;
136
+ this.entity = entity;
137
+ this.circular = circular;
138
+ this.jobid = jobid;
139
+ this.isArray = isArray;
140
+ this.init();
141
+ }
142
+ init() {
143
+ if (typeof this.entity === 'string') {
144
+ // const headerWithMapping = headers.get(entity);
145
+ let entityJSON = this.headers?.getAll(this.entity);
146
+ if (!!entityJSON) {
147
+ this.entity = JSON.parse(entityJSON.join());
148
+ }
149
+ }
150
+ if (typeof this.circular === 'string') {
151
+ // const headerWithMapping = headers.get(circular);
152
+ let circuralJSON = this.headers?.getAll(this.circular);
153
+ if (!!circuralJSON) {
154
+ this.circular = JSON.parse(circuralJSON.join());
155
+ }
156
+ }
157
+ this.body = new Models__NS__HttpBody(this.responseText, this.isArray, this.entity, this.circular);
158
+ }
159
+ }
160
+ // | 'json' - I am parsing json from text...
161
+ //#endregion
162
+ //end of namespace Models
163
+ export class HttpResponseError extends Models__NS__BaseResponse {
164
+ // public tryRecconect() {
165
+ // }
166
+ constructor(message, responseText, headers, statusCode, jobid, sourceRequest) {
167
+ super(responseText, headers, statusCode);
168
+ this.message = message;
169
+ this.jobid = jobid;
170
+ this.sourceRequest = sourceRequest;
171
+ this.body = new Models__NS__ErrorBody(responseText);
172
+ }
173
+ }