@sumaris-net/ngx-components 2.0.0-rc39 → 2.0.0-rc40
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/esm2020/src/app/core/services/model/entity.decorators.mjs +61 -41
- package/fesm2015/sumaris-net.ngx-components.mjs +62 -42
- package/fesm2015/sumaris-net.ngx-components.mjs.map +1 -1
- package/fesm2020/sumaris-net.ngx-components.mjs +60 -40
- package/fesm2020/sumaris-net.ngx-components.mjs.map +1 -1
- package/package.json +1 -1
- package/src/app/core/services/model/entity.decorators.d.ts +1 -8
|
@@ -11168,7 +11168,6 @@ EntityClasses.CLASSES_BY_NAME = new Map();
|
|
|
11168
11168
|
function EntityClass(opts) {
|
|
11169
11169
|
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
|
11170
11170
|
return function (constructor) {
|
|
11171
|
-
var _a, _b;
|
|
11172
11171
|
// Make sure the class extends Entity
|
|
11173
11172
|
if (!environment.production) {
|
|
11174
11173
|
const obj = new constructor();
|
|
@@ -11176,61 +11175,82 @@ function EntityClass(opts) {
|
|
|
11176
11175
|
throw new Error(`Class ${constructor.name} must extends <<Entity>> to be able to use @FromObject!`);
|
|
11177
11176
|
}
|
|
11178
11177
|
}
|
|
11179
|
-
const
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
|
|
11183
|
-
|
|
11184
|
-
|
|
11185
|
-
|
|
11186
|
-
|
|
11187
|
-
|
|
11188
|
-
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
|
|
11193
|
-
|
|
11194
|
-
|
|
11195
|
-
|
|
11196
|
-
return Object.assign({}, source);
|
|
11197
|
-
}
|
|
11198
|
-
},
|
|
11199
|
-
_a.TYPENAME = typename,
|
|
11200
|
-
_a);
|
|
11201
|
-
// Register the entity class
|
|
11202
|
-
EntityClasses.register(typename, decoratedClass);
|
|
11203
|
-
return decoratedClass;
|
|
11204
|
-
}
|
|
11205
|
-
const decoratedClass = (_b = class extends constructor {
|
|
11206
|
-
static fromObject(source, opts) {
|
|
11178
|
+
const clazz = constructor;
|
|
11179
|
+
const typename = opts.typename || `${constructor.name}VO`;
|
|
11180
|
+
// Define static field TYPENAME
|
|
11181
|
+
clazz.TYPENAME = typename;
|
|
11182
|
+
// Define static fromObject()
|
|
11183
|
+
if (!clazz.fromObject) {
|
|
11184
|
+
if (opts.fromObjectReuseStrategy === 'clone') {
|
|
11185
|
+
constructor.fromObject = function (source, opts) {
|
|
11186
|
+
if (!source)
|
|
11187
|
+
return undefined;
|
|
11188
|
+
if (source instanceof constructor)
|
|
11189
|
+
return source.clone(opts);
|
|
11190
|
+
const target = new constructor();
|
|
11191
|
+
target.fromObject(source, opts);
|
|
11192
|
+
return target;
|
|
11193
|
+
};
|
|
11194
|
+
constructor.asObject = function (source, opts) {
|
|
11207
11195
|
if (!source)
|
|
11208
11196
|
return undefined;
|
|
11209
|
-
if (source instanceof
|
|
11197
|
+
if (source instanceof constructor)
|
|
11198
|
+
return source.asObject(opts);
|
|
11199
|
+
return Object.assign({}, source);
|
|
11200
|
+
};
|
|
11201
|
+
}
|
|
11202
|
+
else {
|
|
11203
|
+
clazz.fromObject = function (source, opts) {
|
|
11204
|
+
if (!source)
|
|
11205
|
+
return undefined;
|
|
11206
|
+
if (source instanceof constructor) {
|
|
11210
11207
|
// DEBUG
|
|
11211
11208
|
//console.debug('@EntityClass() fromObject() => will recycle existing object: ', source);
|
|
11212
11209
|
return source;
|
|
11213
11210
|
}
|
|
11214
|
-
const target = new
|
|
11211
|
+
const target = new constructor();
|
|
11215
11212
|
target.fromObject(source, opts);
|
|
11216
11213
|
return target;
|
|
11217
|
-
}
|
|
11218
|
-
|
|
11214
|
+
};
|
|
11215
|
+
clazz.asObject = function (source, opts) {
|
|
11219
11216
|
if (!source)
|
|
11220
11217
|
return undefined;
|
|
11221
|
-
if (source instanceof
|
|
11218
|
+
if (source instanceof constructor) {
|
|
11222
11219
|
return source.asObject(opts);
|
|
11223
11220
|
}
|
|
11224
11221
|
// DEBUG
|
|
11225
11222
|
//console.debug('@EntityClass() asObject() => will recycle existing object: ', source);
|
|
11226
11223
|
return source;
|
|
11227
|
-
}
|
|
11228
|
-
}
|
|
11229
|
-
|
|
11230
|
-
|
|
11224
|
+
};
|
|
11225
|
+
}
|
|
11226
|
+
}
|
|
11227
|
+
// Define static asObject()
|
|
11228
|
+
if (!clazz.asObject) {
|
|
11229
|
+
if (opts.fromObjectReuseStrategy === 'clone') {
|
|
11230
|
+
clazz.asObject = function (source, opts) {
|
|
11231
|
+
if (!source)
|
|
11232
|
+
return undefined;
|
|
11233
|
+
if (source instanceof constructor)
|
|
11234
|
+
return source.asObject(opts);
|
|
11235
|
+
return Object.assign({}, source);
|
|
11236
|
+
};
|
|
11237
|
+
}
|
|
11238
|
+
else {
|
|
11239
|
+
clazz.asObject = function (source, opts) {
|
|
11240
|
+
if (!source)
|
|
11241
|
+
return undefined;
|
|
11242
|
+
if (source instanceof constructor) {
|
|
11243
|
+
return source.asObject(opts);
|
|
11244
|
+
}
|
|
11245
|
+
// DEBUG
|
|
11246
|
+
//console.debug('@EntityClass() asObject() => will recycle existing object: ', source);
|
|
11247
|
+
return source;
|
|
11248
|
+
};
|
|
11249
|
+
}
|
|
11250
|
+
}
|
|
11231
11251
|
// Register the entity class
|
|
11232
|
-
EntityClasses.register(typename,
|
|
11233
|
-
return
|
|
11252
|
+
EntityClasses.register(typename, constructor);
|
|
11253
|
+
return constructor;
|
|
11234
11254
|
};
|
|
11235
11255
|
}
|
|
11236
11256
|
|