ng2-rest 21.0.15 → 21.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/fesm2022/ng2-rest-browser.mjs +3 -5
- package/browser/fesm2022/ng2-rest-browser.mjs.map +1 -1
- package/browser/package.json +1 -1
- package/browser/types/ng2-rest-browser.d.ts +2 -8
- package/browser-prod/fesm2022/ng2-rest-browser.mjs +376 -393
- package/browser-prod/fesm2022/ng2-rest-browser.mjs.map +1 -1
- package/browser-prod/package.json +23 -0
- package/browser-prod/types/ng2-rest-browser.d.ts +194 -204
- package/browser-prod.split-namespaces.json +72 -0
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/models.d.ts +2 -8
- package/lib/models.js +2 -4
- package/lib/models.js.map +1 -1
- package/lib/package.json +4 -0
- package/lib/rest-request.js.map +1 -1
- package/lib/rest.class.js +0 -1
- package/lib/rest.class.js.map +1 -1
- package/lib-prod/build-info._auto-generated_.d.ts +1 -1
- package/lib-prod/build-info._auto-generated_.js +1 -1
- package/lib-prod/helpers.d.ts +3 -3
- package/lib-prod/helpers.js +2 -2
- package/lib-prod/helpers.js.map +1 -1
- package/lib-prod/mapping.d.ts +10 -12
- package/lib-prod/mapping.js +238 -240
- package/lib-prod/mapping.js.map +1 -1
- package/lib-prod/models.d.ts +141 -149
- package/lib-prod/models.js +153 -160
- package/lib-prod/models.js.map +1 -1
- package/lib-prod/other/simple-resource.d.ts +11 -11
- package/lib-prod/package.json +4 -0
- package/lib-prod/params.d.ts +2 -2
- package/lib-prod/resource-service.d.ts +7 -7
- package/lib-prod/rest-request.d.ts +8 -8
- package/lib-prod/rest-request.js +3 -3
- package/lib-prod/rest-request.js.map +1 -1
- package/lib-prod/rest.class.d.ts +18 -18
- package/lib-prod/rest.class.js +0 -1
- package/lib-prod/rest.class.js.map +1 -1
- package/lib-prod.split-namespaces.json +72 -0
- package/package.json +1 -1
- package/websql/fesm2022/ng2-rest-websql.mjs +3 -5
- package/websql/fesm2022/ng2-rest-websql.mjs.map +1 -1
- package/websql/package.json +1 -1
- package/websql/types/ng2-rest-websql.d.ts +2 -8
- package/websql-prod/fesm2022/ng2-rest-websql.mjs +376 -393
- package/websql-prod/fesm2022/ng2-rest-websql.mjs.map +1 -1
- package/websql-prod/package.json +23 -0
- package/websql-prod/types/ng2-rest-websql.d.ts +194 -204
- package/websql-prod.split-namespaces.json +72 -0
- package/lib/request-cache.d.ts +0 -18
- package/lib/request-cache.js +0 -118
- package/lib/request-cache.js.map +0 -1
- package/migrations/index.d.ts +0 -1
- package/migrations/index.js +0 -19
- package/migrations/index.js.map +0 -1
- package/migrations/migrations_index._auto-generated_.d.ts +0 -0
- package/migrations/migrations_index._auto-generated_.js +0 -4
- package/migrations/migrations_index._auto-generated_.js.map +0 -1
- package/tmp-environment.json +0 -43
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { from, firstValueFrom, Subject, Observable } from 'rxjs';
|
|
2
2
|
import { diffChars } from 'diff';
|
|
3
|
-
import { _,
|
|
3
|
+
import { _, UtilsOs_isBrowser, CoreHelpers, CoreModels_TaonHttpErrorCustomProp, Helpers as Helpers$1, UtilsOs_isSSRMode } from 'tnp-core/websql-prod';
|
|
4
4
|
import { Log, Level } from 'ng2-logger/websql-prod';
|
|
5
5
|
import { walk } from 'lodash-walk-object/websql-prod';
|
|
6
|
-
import { CLASS, SYMBOL
|
|
6
|
+
import { CLASS, SYMBOL } from 'typescript-class-helpers/websql-prod';
|
|
7
7
|
import { JSON10 } from 'json10/websql-prod';
|
|
8
8
|
import axios from 'axios';
|
|
9
9
|
|
|
@@ -35,277 +35,272 @@ class Cookie {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/* */
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return void 0;
|
|
44
|
-
}
|
|
45
|
-
let mapping = decodeFromDecorator(_.isArray(json) ? _.first(json) : json, !autodetect);
|
|
46
|
-
if (autodetect) {
|
|
47
|
-
mapping = _.merge(getMappingNaive(json), mapping);
|
|
48
|
-
}
|
|
49
|
-
return mapping;
|
|
38
|
+
//namespace Mapping
|
|
39
|
+
function Mapping_decode(json, autodetect = false) {
|
|
40
|
+
// console.log('DECODE isBrowser', HelpersLog.isBrowser)
|
|
41
|
+
if (_.isUndefined(json)) {
|
|
42
|
+
return void 0;
|
|
50
43
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return json;
|
|
55
|
-
}
|
|
56
|
-
if (mapping['']) {
|
|
57
|
-
const decoratorMapping = getModelsMapping(CLASS.getBy(mapping['']));
|
|
58
|
-
mapping = _.merge(mapping, decoratorMapping);
|
|
59
|
-
}
|
|
60
|
-
let res;
|
|
61
|
-
if (_.isArray(circular) && circular.length > 0) {
|
|
62
|
-
res = setMappingCirc(json, mapping, circular);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
res = setMapping(json, mapping);
|
|
66
|
-
}
|
|
67
|
-
return res;
|
|
44
|
+
let mapping = decodeFromDecorator(_.isArray(json) ? _.first(json) : json, !autodetect);
|
|
45
|
+
if (autodetect) {
|
|
46
|
+
mapping = _.merge(getMappingNaive(json), mapping);
|
|
68
47
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
48
|
+
return mapping;
|
|
49
|
+
}
|
|
50
|
+
function Mapping_encode(json, mapping, circular = []) {
|
|
51
|
+
if (_.isString(json) || _.isBoolean(json) || _.isNumber(json)) {
|
|
52
|
+
return json;
|
|
53
|
+
}
|
|
54
|
+
if (mapping['']) {
|
|
55
|
+
const decoratorMapping = Mapping_getModelsMapping(CLASS.getBy(mapping['']));
|
|
56
|
+
mapping = _.merge(mapping, decoratorMapping);
|
|
57
|
+
}
|
|
58
|
+
let res;
|
|
59
|
+
if (_.isArray(circular) && circular.length > 0) {
|
|
60
|
+
res = setMappingCirc(json, mapping, circular);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
res = setMapping(json, mapping);
|
|
64
|
+
}
|
|
65
|
+
return res;
|
|
66
|
+
}
|
|
67
|
+
function decodeFromDecorator(json, production = false) {
|
|
68
|
+
const entityClass = CLASS.getFromObject(json);
|
|
69
|
+
const mappings = Mapping_getModelsMapping(entityClass);
|
|
70
|
+
return mappings;
|
|
71
|
+
}
|
|
72
|
+
function Mapping_getModelsMapping(entity) {
|
|
73
|
+
if (!_.isFunction(entity) || entity === Object) {
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
const className = CLASS.getName(entity);
|
|
77
|
+
// console.log(`getMaping for: '${className}' `)
|
|
78
|
+
let enityOWnMapping = _.isArray(entity[SYMBOL.MODELS_MAPPING])
|
|
79
|
+
? entity[SYMBOL.MODELS_MAPPING]
|
|
80
|
+
: [{ '': className }];
|
|
81
|
+
let res = {};
|
|
82
|
+
let parents = enityOWnMapping
|
|
83
|
+
.filter(m => !_.isUndefined(m['']) && m[''] !== className)
|
|
84
|
+
.map(m => m['']);
|
|
85
|
+
enityOWnMapping.reverse().forEach(m => {
|
|
86
|
+
m = _.cloneDeep(m);
|
|
87
|
+
// console.log(`'${className}' m:`, m)
|
|
88
|
+
Object.keys(m).forEach(key => {
|
|
89
|
+
const v = m[key];
|
|
90
|
+
const isArr = _.isArray(v);
|
|
91
|
+
const model = isArr ? _.first(v) : v;
|
|
92
|
+
if (parents.includes(model)) {
|
|
93
|
+
m[key] = isArr ? [className] : className;
|
|
94
|
+
}
|
|
100
95
|
});
|
|
101
|
-
res
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
res = _.merge(res, m);
|
|
97
|
+
});
|
|
98
|
+
res[''] = className;
|
|
99
|
+
// console.log(`mapping for ${className} : ${JSON.stringify(res)}`)
|
|
100
|
+
return res;
|
|
101
|
+
}
|
|
102
|
+
function add(o, path, mapping = {}) {
|
|
103
|
+
if (!o || Array.isArray(o) || typeof o !== 'object')
|
|
104
|
+
return;
|
|
105
|
+
const proptotypeObj = Object.getPrototypeOf(o);
|
|
106
|
+
if (!proptotypeObj) {
|
|
107
|
+
return;
|
|
104
108
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const objectClassName = CLASS.getName(proptotypeObj.constructor);
|
|
114
|
-
const resolveClass = CLASS.getBy(objectClassName);
|
|
115
|
-
if (!resolveClass) {
|
|
116
|
-
if (objectClassName !== 'Object') {
|
|
117
|
-
if (UtilsOs.isBrowser) {
|
|
118
|
-
console.error(`Cannot resolve class "${objectClassName}" while mapping.`);
|
|
119
|
-
}
|
|
109
|
+
const objectClassName = CLASS.getName(proptotypeObj.constructor);
|
|
110
|
+
const resolveClass = CLASS.getBy(objectClassName);
|
|
111
|
+
if (!resolveClass) {
|
|
112
|
+
if (objectClassName !== 'Object') {
|
|
113
|
+
if (UtilsOs_isBrowser) {
|
|
114
|
+
console.error(`Cannot resolve class "${objectClassName}" while mapping.`);
|
|
120
115
|
}
|
|
121
|
-
return;
|
|
122
116
|
}
|
|
123
|
-
|
|
124
|
-
mapping[path] = CLASS.getName(resolveClass);
|
|
117
|
+
return;
|
|
125
118
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
else if (typeof v === 'object') {
|
|
119
|
+
if (!mapping[path])
|
|
120
|
+
mapping[path] = CLASS.getName(resolveClass);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* USE ONLY IN DEVELOPMENT
|
|
124
|
+
* @param c
|
|
125
|
+
* @param path
|
|
126
|
+
* @param mapping
|
|
127
|
+
* @param level
|
|
128
|
+
*/
|
|
129
|
+
function getMappingNaive(c, path = '', mapping = {}, level = 0) {
|
|
130
|
+
if (c === null || c === undefined) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
/* */
|
|
134
|
+
/* */
|
|
135
|
+
/* */
|
|
136
|
+
/* */
|
|
137
|
+
// console.log({c})
|
|
138
|
+
if (Array.isArray(c)) {
|
|
139
|
+
c.forEach(c => getMappingNaive(c, path, mapping, level));
|
|
140
|
+
return mapping;
|
|
141
|
+
}
|
|
142
|
+
if (++level === 16)
|
|
143
|
+
return;
|
|
144
|
+
add(c, path, mapping);
|
|
145
|
+
for (var p in c) {
|
|
146
|
+
if (_.isFunction(c.hasOwnProperty) && c.hasOwnProperty(p)) {
|
|
147
|
+
const v = c[p];
|
|
148
|
+
if (Array.isArray(v) && v.length > 0) {
|
|
149
|
+
// reducer as impovement
|
|
150
|
+
v.forEach((elem, i) => {
|
|
151
|
+
// const currentPaht = [`path[${i}]`, p].filter(c => c.trim() != '').join('.');
|
|
161
152
|
const currentPaht = [path, p].filter(c => c.trim() != '').join('.');
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
153
|
+
getMappingNaive(elem, currentPaht, mapping, level);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
else if (typeof v === 'object') {
|
|
157
|
+
const currentPaht = [path, p].filter(c => c.trim() != '').join('.');
|
|
158
|
+
add(v, currentPaht, mapping);
|
|
159
|
+
getMappingNaive(v, currentPaht, mapping, level);
|
|
165
160
|
}
|
|
166
161
|
}
|
|
167
|
-
return mapping;
|
|
168
162
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
163
|
+
return mapping;
|
|
164
|
+
}
|
|
165
|
+
function getMappingPathFrom(pathLodhas) {
|
|
166
|
+
if (!_.isString(pathLodhas)) {
|
|
167
|
+
return void 0;
|
|
168
|
+
}
|
|
169
|
+
const regex = /\[([0-9a-zA-Z]|\'|\")*\]/g;
|
|
170
|
+
pathLodhas = pathLodhas.replace(regex, '').replace('..', '.');
|
|
171
|
+
if (pathLodhas.startsWith('.')) {
|
|
172
|
+
pathLodhas = pathLodhas.slice(1);
|
|
173
|
+
}
|
|
174
|
+
return pathLodhas;
|
|
175
|
+
}
|
|
176
|
+
function setMappingCirc(json, mapping = {}, circular = []) {
|
|
177
|
+
const mainClassFn = !_.isArray(json) && CLASS.getBy(mapping['']);
|
|
178
|
+
// console.log(mapping)
|
|
179
|
+
walk.Object(json, (v, lodashPath, changeValue) => {
|
|
180
|
+
if (!_.isUndefined(v) && !_.isNull(v)) {
|
|
181
|
+
const mappingPath = getMappingPathFrom(lodashPath);
|
|
182
|
+
if (!_.isUndefined(mapping[mappingPath])) {
|
|
183
|
+
const isArray = _.isArray(mapping[mappingPath]);
|
|
184
|
+
if (!isArray) {
|
|
185
|
+
const className = isArray
|
|
186
|
+
? _.first(mapping[mappingPath])
|
|
187
|
+
: mapping[mappingPath];
|
|
188
|
+
const classFN = CLASS.getBy(className);
|
|
189
|
+
if (_.isFunction(classFN)) {
|
|
190
|
+
// console.log(`mapping: '${mappingPath}', lp: '${lodashPath}' class: '${className}' , set `, v.location)
|
|
191
|
+
changeValue(_.merge(new classFN(), v));
|
|
197
192
|
}
|
|
198
193
|
}
|
|
199
194
|
}
|
|
200
|
-
});
|
|
201
|
-
circular.forEach(c => {
|
|
202
|
-
const ref = _.get(json, c.circuralTargetPath);
|
|
203
|
-
_.set(json, c.pathToObj, ref);
|
|
204
|
-
});
|
|
205
|
-
if (_.isFunction(mainClassFn)) {
|
|
206
|
-
json = _.merge(new mainClassFn(), json);
|
|
207
195
|
}
|
|
208
|
-
|
|
196
|
+
});
|
|
197
|
+
circular.forEach(c => {
|
|
198
|
+
const ref = _.get(json, c.circuralTargetPath);
|
|
199
|
+
_.set(json, c.pathToObj, ref);
|
|
200
|
+
});
|
|
201
|
+
if (_.isFunction(mainClassFn)) {
|
|
202
|
+
json = _.merge(new mainClassFn(), json);
|
|
209
203
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
json[key] = json[key].map(arrObj => {
|
|
225
|
-
const objMapping = getModelsMapping(CLASS.getBy(mapping[key]));
|
|
226
|
-
return setMapping(arrObj, objMapping);
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
else if (_.isObject(json[key])) {
|
|
230
|
-
const objMapping = getModelsMapping(CLASS.getBy(mapping[key]));
|
|
231
|
-
json[key] = setMapping(json[key], objMapping);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
// else {
|
|
235
|
-
// if (mainClassFn && mainClassFn.name === 'Project') {
|
|
236
|
-
// // console.log(`Not own property: "${key}"`)
|
|
237
|
-
// }
|
|
204
|
+
return json;
|
|
205
|
+
}
|
|
206
|
+
function setMapping(json, mapping = {}) {
|
|
207
|
+
// console.log('mapping', mapping)
|
|
208
|
+
if (Array.isArray(json)) {
|
|
209
|
+
return json.map(j => {
|
|
210
|
+
return setMapping(j, mapping);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const mainClassFn = CLASS.getBy(mapping['']);
|
|
214
|
+
for (const key in json) {
|
|
215
|
+
if (json.hasOwnProperty(key)) {
|
|
216
|
+
// if (mainClassFn && mainClassFn.name === 'Project') {
|
|
217
|
+
// // console.log(`OWn property: "${key}"`)
|
|
238
218
|
// }
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
_.set(json, lodasPath, res);
|
|
219
|
+
if (_.isArray(json[key])) {
|
|
220
|
+
json[key] = json[key].map(arrObj => {
|
|
221
|
+
const objMapping = Mapping_getModelsMapping(CLASS.getBy(mapping[key]));
|
|
222
|
+
return setMapping(arrObj, objMapping);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
else if (_.isObject(json[key])) {
|
|
226
|
+
const objMapping = Mapping_getModelsMapping(CLASS.getBy(mapping[key]));
|
|
227
|
+
json[key] = setMapping(json[key], objMapping);
|
|
249
228
|
}
|
|
250
|
-
});
|
|
251
|
-
if (!mainClassFn) {
|
|
252
|
-
return json;
|
|
253
229
|
}
|
|
254
|
-
|
|
230
|
+
// else {
|
|
231
|
+
// if (mainClassFn && mainClassFn.name === 'Project') {
|
|
232
|
+
// // console.log(`Not own property: "${key}"`)
|
|
233
|
+
// }
|
|
234
|
+
// }
|
|
255
235
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
236
|
+
Object.keys(mapping)
|
|
237
|
+
.filter(key => key !== '' && key.split('.').length >= 2)
|
|
238
|
+
.forEach(lodasPath => {
|
|
239
|
+
// console.log(`Loadsh path: ${lodasPath}`)
|
|
240
|
+
const objMapping = Mapping_getModelsMapping(CLASS.getBy(mapping[lodasPath]));
|
|
241
|
+
const input = _.get(json, lodasPath);
|
|
242
|
+
if (!_.isUndefined(input)) {
|
|
243
|
+
const res = setMapping(input, objMapping);
|
|
244
|
+
_.set(json, lodasPath, res);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
if (!mainClassFn) {
|
|
248
|
+
return json;
|
|
249
|
+
}
|
|
250
|
+
return _.merge(new mainClassFn(), json);
|
|
251
|
+
}
|
|
252
|
+
function Mapping_DefaultModelWithMapping(defaultModelValues, mapping) {
|
|
253
|
+
return function (target) {
|
|
254
|
+
if (!_.isArray(target[SYMBOL.MODELS_MAPPING])) {
|
|
255
|
+
target[SYMBOL.MODELS_MAPPING] = [];
|
|
256
|
+
}
|
|
257
|
+
target[SYMBOL.MODELS_MAPPING].push({
|
|
258
|
+
'': CLASS.getName(target),
|
|
259
|
+
});
|
|
260
|
+
if (_.isObject(mapping)) {
|
|
261
|
+
target[SYMBOL.MODELS_MAPPING] = target[SYMBOL.MODELS_MAPPING].concat(mapping);
|
|
262
|
+
Object.keys(mapping).forEach(key => {
|
|
263
|
+
const v = mapping;
|
|
264
|
+
if (_.isUndefined(v) || _.isFunction(v)) {
|
|
265
|
+
throw `
|
|
270
266
|
|
|
271
267
|
|
|
272
268
|
Class: '${target.name}'
|
|
273
269
|
[ng2rest] Bad mapping value for path: ${key} , please use type: <string> or [<string>]
|
|
274
270
|
`;
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
if (_.isObject(defaultModelValues)) {
|
|
275
|
+
const toMerge = {};
|
|
276
|
+
const describedTarget = CLASS.describeProperites(target).filter(prop => /^([a-zA-Z0-9]|\_|\#)+$/.test(prop));
|
|
277
|
+
// console.log(`describedTarget: ${describedTarget} for ${target.name}`)
|
|
278
|
+
describedTarget.forEach(propDefInConstr => {
|
|
279
|
+
if (defaultModelValues[propDefInConstr]) {
|
|
280
|
+
console.warn(`
|
|
285
281
|
|
|
286
282
|
CONFLICT: default value for property: "${propDefInConstr}"
|
|
287
283
|
in class "${target.name}" already defined as typescript
|
|
288
284
|
default class proprty value.
|
|
289
285
|
|
|
290
286
|
`);
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
})(Mapping || (Mapping = {}));
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
toMerge[propDefInConstr] = null; // TODO from toString I can't know that
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
// console.log(`merge "${JSON.stringify(target.prototype)}" with "${JSON.stringify(defaultModelValues)}"`)
|
|
293
|
+
target[SYMBOL.DEFAULT_MODEL] = _.merge(toMerge, defaultModelValues);
|
|
294
|
+
const propsToOmmit = Object.keys(target[SYMBOL.DEFAULT_MODEL]).filter(key => {
|
|
295
|
+
const descriptor = Object.getOwnPropertyDescriptor(target.prototype, key);
|
|
296
|
+
return !!descriptor;
|
|
297
|
+
});
|
|
298
|
+
_.merge(target.prototype, _.omit(target[SYMBOL.DEFAULT_MODEL], propsToOmmit));
|
|
299
|
+
// console.log(`DEFAULT VALUE MERGE for ${target.name}`)
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
//end of namespace Mapping
|
|
309
304
|
|
|
310
305
|
// @ts-ignore
|
|
311
306
|
class Helpers extends CoreHelpers {
|
|
@@ -313,10 +308,10 @@ class Helpers extends CoreHelpers {
|
|
|
313
308
|
static get Mapping() {
|
|
314
309
|
return {
|
|
315
310
|
encode(json, mapping) {
|
|
316
|
-
return
|
|
311
|
+
return Mapping_encode(json, mapping);
|
|
317
312
|
},
|
|
318
313
|
decode(json, autodetect = false) {
|
|
319
|
-
return
|
|
314
|
+
return Mapping_decode(json, autodetect);
|
|
320
315
|
}
|
|
321
316
|
};
|
|
322
317
|
}
|
|
@@ -649,172 +644,161 @@ class RestResponseWrapper extends RestCommonHttpResponseWrapper {
|
|
|
649
644
|
}
|
|
650
645
|
class RestErrorResponseWrapper extends RestCommonHttpResponseWrapper {
|
|
651
646
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
(
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
let r = opt.isJSONArray ? [] : {};
|
|
663
|
-
if (typeof data === 'string') {
|
|
664
|
-
try {
|
|
665
|
-
let parsed = JSON.parse(data);
|
|
666
|
-
if (typeof parsed === 'string' && parsed.trim().startsWith('{')) {
|
|
667
|
-
parsed = JSON.parse(parsed);
|
|
668
|
-
}
|
|
669
|
-
if (opt.parsingError && parsed[CoreModels.TaonHttpErrorCustomProp]) {
|
|
670
|
-
return _.merge(new RestErrorResponseWrapper(), parsed);
|
|
671
|
-
}
|
|
672
|
-
return parsed;
|
|
647
|
+
[];
|
|
648
|
+
class Models_BaseBody {
|
|
649
|
+
toJSON(data, opt) {
|
|
650
|
+
opt = opt || { isJSONArray: false };
|
|
651
|
+
let r = opt.isJSONArray ? [] : {};
|
|
652
|
+
if (typeof data === 'string') {
|
|
653
|
+
try {
|
|
654
|
+
let parsed = JSON.parse(data);
|
|
655
|
+
if (typeof parsed === 'string' && parsed.trim().startsWith('{')) {
|
|
656
|
+
parsed = JSON.parse(parsed);
|
|
673
657
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
return
|
|
658
|
+
if (opt.parsingError && parsed[CoreModels_TaonHttpErrorCustomProp]) {
|
|
659
|
+
return _.merge(new RestErrorResponseWrapper(), parsed);
|
|
660
|
+
}
|
|
661
|
+
return parsed;
|
|
678
662
|
}
|
|
679
|
-
|
|
663
|
+
catch (e) { }
|
|
680
664
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
class HttpBody extends BaseBody {
|
|
684
|
-
constructor(responseText, isArray = false, entity, circular) {
|
|
685
|
-
super();
|
|
686
|
-
this.responseText = responseText;
|
|
687
|
-
this.isArray = isArray;
|
|
688
|
-
this.entity = entity;
|
|
689
|
-
this.circular = circular;
|
|
690
|
-
}
|
|
691
|
-
get blob() {
|
|
692
|
-
return this.responseText;
|
|
665
|
+
else if (typeof data === 'object') {
|
|
666
|
+
return data;
|
|
693
667
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
668
|
+
return r;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
class Models_HttpBody extends Models_BaseBody {
|
|
672
|
+
constructor(responseText, isArray = false, entity, circular) {
|
|
673
|
+
super();
|
|
674
|
+
this.responseText = responseText;
|
|
675
|
+
this.isArray = isArray;
|
|
676
|
+
this.entity = entity;
|
|
677
|
+
this.circular = circular;
|
|
678
|
+
}
|
|
679
|
+
get blob() {
|
|
680
|
+
return this.responseText;
|
|
681
|
+
}
|
|
682
|
+
get booleanValue() {
|
|
683
|
+
if (!Helpers$1.isBlob(this.responseText)) {
|
|
684
|
+
return ['ok', 'true'].includes(this.responseText?.trim());
|
|
703
685
|
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
res = JSON10.parse(JSON.stringify(res), this.circular);
|
|
709
|
-
}
|
|
710
|
-
return res;
|
|
711
|
-
}
|
|
686
|
+
}
|
|
687
|
+
get numericValue() {
|
|
688
|
+
if (!Helpers$1.isBlob(this.responseText)) {
|
|
689
|
+
return Number(this.responseText?.trim());
|
|
712
690
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
return void 0;
|
|
717
|
-
}
|
|
718
|
-
if (this.entity && typeof this.entity === 'function') {
|
|
719
|
-
return this.entity(); // @LAST
|
|
720
|
-
}
|
|
721
|
-
if (this.entity && typeof this.entity === 'object') {
|
|
722
|
-
const json = this.toJSON(this.responseText, {
|
|
723
|
-
isJSONArray: this.isArray,
|
|
724
|
-
});
|
|
725
|
-
return Mapping.encode(json, this.entity, this.circular);
|
|
726
|
-
}
|
|
691
|
+
}
|
|
692
|
+
get rawJson() {
|
|
693
|
+
if (!Helpers$1.isBlob(this.responseText)) {
|
|
727
694
|
let res = this.toJSON(this.responseText, { isJSONArray: this.isArray });
|
|
728
695
|
if (this.circular && Array.isArray(this.circular)) {
|
|
729
696
|
res = JSON10.parse(JSON.stringify(res), this.circular);
|
|
730
697
|
}
|
|
731
698
|
return res;
|
|
732
699
|
}
|
|
733
|
-
/**
|
|
734
|
-
* undefined when blob
|
|
735
|
-
*/
|
|
736
|
-
get text() {
|
|
737
|
-
if (!Helpers$1.isBlob(this.responseText)) {
|
|
738
|
-
return this.responseText
|
|
739
|
-
.replace(/^\"/, '')
|
|
740
|
-
.replace(/\"$/, '');
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
700
|
}
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
701
|
+
get json() {
|
|
702
|
+
const isBlob = Helpers$1.isBlob(this.responseText);
|
|
703
|
+
if (isBlob) {
|
|
704
|
+
return void 0;
|
|
705
|
+
}
|
|
706
|
+
if (this.entity && typeof this.entity === 'function') {
|
|
707
|
+
return this.entity(); // @LAST
|
|
749
708
|
}
|
|
750
|
-
|
|
751
|
-
|
|
709
|
+
if (this.entity && typeof this.entity === 'object') {
|
|
710
|
+
const json = this.toJSON(this.responseText, {
|
|
711
|
+
isJSONArray: this.isArray,
|
|
712
|
+
});
|
|
713
|
+
return Mapping_encode(json, this.entity, this.circular);
|
|
752
714
|
}
|
|
753
|
-
|
|
754
|
-
|
|
715
|
+
let res = this.toJSON(this.responseText, { isJSONArray: this.isArray });
|
|
716
|
+
if (this.circular && Array.isArray(this.circular)) {
|
|
717
|
+
res = JSON10.parse(JSON.stringify(res), this.circular);
|
|
755
718
|
}
|
|
719
|
+
return res;
|
|
756
720
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
this.headers = headers;
|
|
766
|
-
this.statusCode = statusCode;
|
|
767
|
-
this.isArray = isArray;
|
|
721
|
+
/**
|
|
722
|
+
* undefined when blob
|
|
723
|
+
*/
|
|
724
|
+
get text() {
|
|
725
|
+
if (!Helpers$1.isBlob(this.responseText)) {
|
|
726
|
+
return this.responseText
|
|
727
|
+
.replace(/^\"/, '')
|
|
728
|
+
.replace(/\"$/, '');
|
|
768
729
|
}
|
|
769
730
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
731
|
+
}
|
|
732
|
+
class Models_ErrorBody extends Models_BaseBody {
|
|
733
|
+
constructor(data) {
|
|
734
|
+
super();
|
|
735
|
+
this.data = data;
|
|
736
|
+
}
|
|
737
|
+
get json() {
|
|
738
|
+
return this.toJSON(this.data, { parsingError: true });
|
|
739
|
+
}
|
|
740
|
+
get text() {
|
|
741
|
+
return this.data;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
class Models_BaseResponse {
|
|
745
|
+
static { this.cookies = Cookie.Instance; }
|
|
746
|
+
get cookies() {
|
|
747
|
+
return Models_BaseResponse.cookies;
|
|
748
|
+
}
|
|
749
|
+
constructor(responseText, headers, statusCode, isArray = false) {
|
|
750
|
+
this.responseText = responseText;
|
|
751
|
+
this.headers = headers;
|
|
752
|
+
this.statusCode = statusCode;
|
|
753
|
+
this.isArray = isArray;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
class Models_HttpResponse extends Models_BaseResponse {
|
|
757
|
+
// public readonly TOTAL_COUNT_HEADER = 'X-Total-Count'.toLowerCase();
|
|
758
|
+
// public get totalElements(): number {
|
|
759
|
+
// return Number(this.headers.get(this.TOTAL_COUNT_HEADER));
|
|
760
|
+
// }
|
|
761
|
+
constructor(sourceRequest, responseText, headers, statusCode, entity, circular, jobid, isArray = false) {
|
|
762
|
+
// console.log({
|
|
763
|
+
// sourceRequest, responseText, headers, statusCode, entity, circular, jobid, isArray
|
|
764
|
+
// })
|
|
765
|
+
super(responseText, headers, statusCode, isArray);
|
|
766
|
+
this.sourceRequest = sourceRequest;
|
|
767
|
+
this.responseText = responseText;
|
|
768
|
+
this.headers = headers;
|
|
769
|
+
this.statusCode = statusCode;
|
|
770
|
+
this.entity = entity;
|
|
771
|
+
this.circular = circular;
|
|
772
|
+
this.jobid = jobid;
|
|
773
|
+
this.isArray = isArray;
|
|
774
|
+
this.init();
|
|
775
|
+
}
|
|
776
|
+
init() {
|
|
777
|
+
if (typeof this.entity === 'string') {
|
|
778
|
+
// const headerWithMapping = headers.get(entity);
|
|
779
|
+
let entityJSON = this.headers?.getAll(this.entity);
|
|
780
|
+
if (!!entityJSON) {
|
|
781
|
+
this.entity = JSON.parse(entityJSON.join());
|
|
798
782
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
783
|
+
}
|
|
784
|
+
if (typeof this.circular === 'string') {
|
|
785
|
+
// const headerWithMapping = headers.get(circular);
|
|
786
|
+
let circuralJSON = this.headers?.getAll(this.circular);
|
|
787
|
+
if (!!circuralJSON) {
|
|
788
|
+
this.circular = JSON.parse(circuralJSON.join());
|
|
805
789
|
}
|
|
806
|
-
this.body = new HttpBody(this.responseText, this.isArray, this.entity, this.circular);
|
|
807
790
|
}
|
|
791
|
+
this.body = new Models_HttpBody(this.responseText, this.isArray, this.entity, this.circular);
|
|
808
792
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
class HttpResponseError extends
|
|
793
|
+
}
|
|
794
|
+
/* */
|
|
795
|
+
/* */
|
|
796
|
+
/* */
|
|
797
|
+
/* */
|
|
798
|
+
/* */
|
|
799
|
+
/* */
|
|
800
|
+
//end of namespace Models
|
|
801
|
+
class HttpResponseError extends Models_BaseResponse {
|
|
818
802
|
// public tryRecconect() {
|
|
819
803
|
// }
|
|
820
804
|
constructor(message, responseText, headers, statusCode, jobid, sourceRequest) {
|
|
@@ -822,7 +806,7 @@ class HttpResponseError extends Models.BaseResponse {
|
|
|
822
806
|
this.message = message;
|
|
823
807
|
this.jobid = jobid;
|
|
824
808
|
this.sourceRequest = sourceRequest;
|
|
825
|
-
this.body = new
|
|
809
|
+
this.body = new Models_ErrorBody(responseText);
|
|
826
810
|
}
|
|
827
811
|
}
|
|
828
812
|
|
|
@@ -1014,7 +998,7 @@ class RestRequest {
|
|
|
1014
998
|
const entity = this.meta[jobid].entity;
|
|
1015
999
|
const circular = this.meta[jobid].circular;
|
|
1016
1000
|
const success = Resource['_listenSuccess'];
|
|
1017
|
-
const reqResp = new
|
|
1001
|
+
const reqResp = new Models_HttpResponse(sourceRequest, res.data, res.headers, res.code, entity, circular, jobid, isArray);
|
|
1018
1002
|
success.next(reqResp);
|
|
1019
1003
|
this.subjectInuUse[jobid].next(reqResp);
|
|
1020
1004
|
this.meta[jobid] = void 0;
|
|
@@ -1241,7 +1225,7 @@ class RestRequest {
|
|
|
1241
1225
|
});
|
|
1242
1226
|
//#region DISPOSE @UNCOMMENT AFTER TESTS
|
|
1243
1227
|
// if (objectIDToCreateOrLast > 2) {
|
|
1244
|
-
// const oldReq:
|
|
1228
|
+
// const oldReq: Models_ReplayData = this.replaySubjects[meta.endpoint][meta.path][method][(objectIDToCreateOrLast - 2)];
|
|
1245
1229
|
// if (_.isUndefined(this.meta[oldReq.id])) {
|
|
1246
1230
|
// // cant delete this - for counter purpose
|
|
1247
1231
|
// this.replaySubjects[meta.endpoint][meta.path][method][(objectIDToCreateOrLast - 2)] = {};
|
|
@@ -1285,7 +1269,7 @@ class RestRequest {
|
|
|
1285
1269
|
}
|
|
1286
1270
|
jsonp(url, body, headers, meta, isArray, mockHttp, axiosOptions) {
|
|
1287
1271
|
const method = 'jsonp';
|
|
1288
|
-
if (
|
|
1272
|
+
if (UtilsOs_isSSRMode) {
|
|
1289
1273
|
const emptyStuff = Promise.resolve();
|
|
1290
1274
|
emptyStuff.observable = new Observable();
|
|
1291
1275
|
console.warn(`Cannot perform jsonp request in SSR mode`);
|
|
@@ -1340,7 +1324,6 @@ const CONTENT_TYPE = {
|
|
|
1340
1324
|
|
|
1341
1325
|
//#region import
|
|
1342
1326
|
// import { Log, Level } from 'ng2-logger/src';
|
|
1343
|
-
// const log = Log.create('rest.class', Level.__NOTHING)
|
|
1344
1327
|
//#endregion
|
|
1345
1328
|
class Rest {
|
|
1346
1329
|
mock(mock) {
|
|
@@ -1800,5 +1783,5 @@ class SimpleResource {
|
|
|
1800
1783
|
* Generated bundle index. Do not edit.
|
|
1801
1784
|
*/
|
|
1802
1785
|
|
|
1803
|
-
export { AxiosBackendHandler, CONTENT_TYPE, Helpers, HttpResponseError,
|
|
1786
|
+
export { AxiosBackendHandler, CONTENT_TYPE, Helpers, HttpResponseError, Mapping_DefaultModelWithMapping, Mapping_decode, Mapping_encode, Mapping_getModelsMapping, Models_BaseBody, Models_BaseResponse, Models_ErrorBody, Models_HttpBody, Models_HttpResponse, Resource, Rest, RestErrorResponseWrapper, RestHeaders, RestResponseWrapper, SimpleResource, buildInterceptorChain, interpolateParamsToUrl };
|
|
1804
1787
|
//# sourceMappingURL=ng2-rest-websql.mjs.map
|