angular-odata 0.160.0 → 0.161.0
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/fesm2022/angular-odata.mjs +45 -62
- package/fesm2022/angular-odata.mjs.map +1 -1
- package/package.json +1 -1
- package/types/angular-odata.d.ts +36 -34
|
@@ -2153,9 +2153,9 @@ class ODataEnumTypeParser extends ODataAnnotatable {
|
|
|
2153
2153
|
}
|
|
2154
2154
|
return schema;
|
|
2155
2155
|
}
|
|
2156
|
-
validate(value, { method, navigation = false, }
|
|
2156
|
+
validate(value, { method, navigation = false, }) {
|
|
2157
2157
|
if (this.flags) {
|
|
2158
|
-
|
|
2158
|
+
const fields = this.fields(value);
|
|
2159
2159
|
return value && fields.length === 0 ? ['mismatch'] : undefined;
|
|
2160
2160
|
}
|
|
2161
2161
|
else {
|
|
@@ -2195,6 +2195,7 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
|
|
|
2195
2195
|
navigation;
|
|
2196
2196
|
nullable;
|
|
2197
2197
|
default;
|
|
2198
|
+
optimisticConcurrency = false;
|
|
2198
2199
|
maxLength;
|
|
2199
2200
|
precision;
|
|
2200
2201
|
scale;
|
|
@@ -2215,7 +2216,7 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
|
|
|
2215
2216
|
this.precision = field.precision;
|
|
2216
2217
|
this.scale = field.scale;
|
|
2217
2218
|
}
|
|
2218
|
-
validate(value, { method, navigation = false, }
|
|
2219
|
+
validate(value, { method, navigation = false, }) {
|
|
2219
2220
|
let errors;
|
|
2220
2221
|
if (this.collection && Array.isArray(value)) {
|
|
2221
2222
|
errors = value.map((v) => this.validate(v, { method, navigation }));
|
|
@@ -2231,12 +2232,8 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
|
|
|
2231
2232
|
}
|
|
2232
2233
|
else {
|
|
2233
2234
|
// IsEdmType
|
|
2234
|
-
const computed = this.annotatedValue(COMPUTED);
|
|
2235
2235
|
errors = [];
|
|
2236
|
-
if (!this.nullable
|
|
2237
|
-
(value === null || (value === undefined && method !== 'modify')) && // Is null or undefined without patch?
|
|
2238
|
-
!(computed && method === 'create') // Not (Is Computed field and create) ?
|
|
2239
|
-
) {
|
|
2236
|
+
if (method !== 'modify' && value == null && !(this.nullable || this.isComputed())) {
|
|
2240
2237
|
errors.push(`required`);
|
|
2241
2238
|
}
|
|
2242
2239
|
if (this.maxLength !== undefined &&
|
|
@@ -2304,12 +2301,13 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
|
|
|
2304
2301
|
});
|
|
2305
2302
|
}
|
|
2306
2303
|
//#endregion
|
|
2307
|
-
configure({ options, parserForType, }) {
|
|
2304
|
+
configure({ options, optimisticConcurrency, parserForType, }) {
|
|
2308
2305
|
this.parserOptions = options;
|
|
2309
2306
|
this.parser = parserForType(this.type);
|
|
2310
|
-
if (
|
|
2307
|
+
if (optimisticConcurrency !== undefined)
|
|
2308
|
+
this.optimisticConcurrency = optimisticConcurrency;
|
|
2309
|
+
if (this.default !== undefined)
|
|
2311
2310
|
this.default = this.deserialize(this.default, options);
|
|
2312
|
-
}
|
|
2313
2311
|
}
|
|
2314
2312
|
//#region Json Schema
|
|
2315
2313
|
// https://json-schema.org/
|
|
@@ -2386,6 +2384,12 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
|
|
|
2386
2384
|
isKey() {
|
|
2387
2385
|
return this.structured.keys({ include_parents: true }).some((k) => k.name === this.name);
|
|
2388
2386
|
}
|
|
2387
|
+
isComputed() {
|
|
2388
|
+
return this.annotatedValue(COMPUTED);
|
|
2389
|
+
}
|
|
2390
|
+
isOptimisticConcurrency() {
|
|
2391
|
+
return this.optimisticConcurrency;
|
|
2392
|
+
}
|
|
2389
2393
|
hasReferentials() {
|
|
2390
2394
|
return this.referentials.length !== 0;
|
|
2391
2395
|
}
|
|
@@ -2518,14 +2522,18 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
|
|
|
2518
2522
|
const parserOptions = { ...this.parserOptions, ...options };
|
|
2519
2523
|
return raw(JSON.stringify(this.serialize(value, parserOptions)));
|
|
2520
2524
|
}
|
|
2521
|
-
configure({ options, parserForType, }) {
|
|
2525
|
+
configure({ options, entitySet, parserForType, }) {
|
|
2522
2526
|
this.parserOptions = options;
|
|
2523
2527
|
if (this.base !== undefined) {
|
|
2524
2528
|
this.parent = parserForType(this.base);
|
|
2525
2529
|
if (this.parent !== undefined)
|
|
2526
2530
|
this.parent.children.push(this);
|
|
2527
2531
|
}
|
|
2528
|
-
|
|
2532
|
+
const optimisticConcurrencyFields = entitySet?.annotatedValue(OPTIMISTIC_CONCURRENCY) ?? [];
|
|
2533
|
+
this._fields.forEach((field) => {
|
|
2534
|
+
const optimisticConcurrency = optimisticConcurrencyFields.indexOf(field.name) !== -1;
|
|
2535
|
+
field.configure({ options, optimisticConcurrency, parserForType });
|
|
2536
|
+
});
|
|
2529
2537
|
}
|
|
2530
2538
|
/**
|
|
2531
2539
|
* Returns all fields of the structured type.
|
|
@@ -2677,7 +2685,7 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
|
|
|
2677
2685
|
}
|
|
2678
2686
|
return schema;
|
|
2679
2687
|
}
|
|
2680
|
-
validate(attrs, { method, navigation = false, }
|
|
2688
|
+
validate(attrs, { method, navigation = false, }) {
|
|
2681
2689
|
const errors = {};
|
|
2682
2690
|
const fields = this.fields({
|
|
2683
2691
|
include_navigation: true,
|
|
@@ -2995,8 +3003,10 @@ class ODataStructuredType extends ODataParserSchemaElement {
|
|
|
2995
3003
|
if (this.parent !== undefined)
|
|
2996
3004
|
this.parent.children.push(this);
|
|
2997
3005
|
}
|
|
3006
|
+
const entitySet = this.api.findEntitySetForEntityType(this.type()) ?? this.api.findEntitySetForEntityType(this.type({ alias: true }));
|
|
2998
3007
|
this.parser.configure({
|
|
2999
3008
|
options,
|
|
3009
|
+
entitySet,
|
|
3000
3010
|
parserForType: (t) => this.api.parserForType(t),
|
|
3001
3011
|
});
|
|
3002
3012
|
if (this.model !== undefined) {
|
|
@@ -3180,7 +3190,7 @@ class ODataStructuredType extends ODataParserSchemaElement {
|
|
|
3180
3190
|
* @param method Method to use for the process validation
|
|
3181
3191
|
* @returns Object with the errors
|
|
3182
3192
|
*/
|
|
3183
|
-
validate(attrs, { method, navigation = false, }
|
|
3193
|
+
validate(attrs, { method, navigation = false, }) {
|
|
3184
3194
|
return this.parser.validate(attrs, { method, navigation });
|
|
3185
3195
|
}
|
|
3186
3196
|
}
|
|
@@ -10750,7 +10760,7 @@ class ODataCollection {
|
|
|
10750
10760
|
}
|
|
10751
10761
|
create(attrs = {}, { silent = false, server = true } = {}) {
|
|
10752
10762
|
const model = this.modelFactory(attrs);
|
|
10753
|
-
return (model.isValid() && server ? model.save() : of(model)).pipe(switchMap((model) => this.add(model, { silent, server })), map(() => model));
|
|
10763
|
+
return (model.isValid({ method: 'create' }) && server ? model.save() : of(model)).pipe(switchMap((model) => this.add(model, { silent, server })), map(() => model));
|
|
10754
10764
|
}
|
|
10755
10765
|
set(path, value, {}) {
|
|
10756
10766
|
const pathArray = (Types.isArray(path) ? path : path.match(/([^[.\]])+/g));
|
|
@@ -11204,10 +11214,10 @@ class ODataModel {
|
|
|
11204
11214
|
}
|
|
11205
11215
|
// Validation
|
|
11206
11216
|
_errors;
|
|
11207
|
-
validate({ method, navigation = false, }
|
|
11217
|
+
validate({ method, navigation = false, }) {
|
|
11208
11218
|
return this._meta.validate(this, { method, navigation });
|
|
11209
11219
|
}
|
|
11210
|
-
isValid({ method, navigation = false, }
|
|
11220
|
+
isValid({ method, navigation = false, }) {
|
|
11211
11221
|
this._errors = this.validate({ method, navigation });
|
|
11212
11222
|
if (this._errors !== undefined)
|
|
11213
11223
|
this.events$.trigger(ODataModelEventType.Invalid, {
|
|
@@ -11809,9 +11819,6 @@ class ODataModelField {
|
|
|
11809
11819
|
parser;
|
|
11810
11820
|
options;
|
|
11811
11821
|
default;
|
|
11812
|
-
required;
|
|
11813
|
-
concurrency;
|
|
11814
|
-
maxLength;
|
|
11815
11822
|
minLength;
|
|
11816
11823
|
min;
|
|
11817
11824
|
max;
|
|
@@ -11823,9 +11830,6 @@ class ODataModelField {
|
|
|
11823
11830
|
this.field = field;
|
|
11824
11831
|
this.parser = parser;
|
|
11825
11832
|
this.default = opts.default || parser.default;
|
|
11826
|
-
this.required = Boolean(opts.required || !parser.nullable);
|
|
11827
|
-
this.concurrency = Boolean(opts.concurrency);
|
|
11828
|
-
this.maxLength = opts.maxLength || parser.maxLength;
|
|
11829
11833
|
this.minLength = opts.minLength;
|
|
11830
11834
|
this.min = opts.min;
|
|
11831
11835
|
this.max = opts.max;
|
|
@@ -11843,16 +11847,20 @@ class ODataModelField {
|
|
|
11843
11847
|
annotatedValue(term) {
|
|
11844
11848
|
return this.parser.annotatedValue(term);
|
|
11845
11849
|
}
|
|
11846
|
-
configure({
|
|
11850
|
+
configure({ options }) {
|
|
11847
11851
|
this.parserOptions = options;
|
|
11848
|
-
if (concurrency)
|
|
11849
|
-
this.concurrency = concurrency;
|
|
11850
11852
|
if (this.default !== undefined)
|
|
11851
11853
|
this.default = this.deserialize(this.default, options);
|
|
11852
11854
|
}
|
|
11853
11855
|
isKey() {
|
|
11854
11856
|
return this.parser.isKey();
|
|
11855
11857
|
}
|
|
11858
|
+
isComputed() {
|
|
11859
|
+
return this.parser.isComputed();
|
|
11860
|
+
}
|
|
11861
|
+
isOptimisticConcurrency() {
|
|
11862
|
+
return this.parser.isOptimisticConcurrency();
|
|
11863
|
+
}
|
|
11856
11864
|
hasReferentials() {
|
|
11857
11865
|
return this.parser.hasReferentials();
|
|
11858
11866
|
}
|
|
@@ -11882,7 +11890,7 @@ class ODataModelField {
|
|
|
11882
11890
|
throw new Error(`Could not find enum type for ${this.parser.type}`);
|
|
11883
11891
|
return enumType;
|
|
11884
11892
|
}
|
|
11885
|
-
validate(value, { method, navigation = false, }
|
|
11893
|
+
validate(value, { method, navigation = false, }) {
|
|
11886
11894
|
if (ODataModelOptions.isModel(value)) {
|
|
11887
11895
|
return !value.isValid({ method, navigation }) ? value._errors : undefined;
|
|
11888
11896
|
}
|
|
@@ -11892,21 +11900,7 @@ class ODataModelField {
|
|
|
11892
11900
|
: undefined;
|
|
11893
11901
|
}
|
|
11894
11902
|
else {
|
|
11895
|
-
const computed = this.annotatedValue(COMPUTED);
|
|
11896
11903
|
const errors = this.parser?.validate(value, { method, navigation }) ?? [];
|
|
11897
|
-
if (this.required &&
|
|
11898
|
-
(value === null || (value === undefined && method !== 'modify')) && // Is null or undefined without patch?
|
|
11899
|
-
!(computed && method === 'create') // Not (Is Computed field and create) ?
|
|
11900
|
-
) {
|
|
11901
|
-
if (errors.indexOf('required') === -1)
|
|
11902
|
-
errors.push(`required`);
|
|
11903
|
-
}
|
|
11904
|
-
if (this.maxLength !== undefined &&
|
|
11905
|
-
typeof value === 'string' &&
|
|
11906
|
-
value.length > this.maxLength) {
|
|
11907
|
-
if (errors.indexOf('maxlength') === -1)
|
|
11908
|
-
errors.push(`maxlength`);
|
|
11909
|
-
}
|
|
11910
11904
|
if (this.minLength !== undefined &&
|
|
11911
11905
|
typeof value === 'string' &&
|
|
11912
11906
|
value.length < this.minLength) {
|
|
@@ -12010,11 +12004,11 @@ class ODataModelAttribute {
|
|
|
12010
12004
|
get navigation() {
|
|
12011
12005
|
return this._field.navigation;
|
|
12012
12006
|
}
|
|
12013
|
-
|
|
12014
|
-
return this._field.
|
|
12007
|
+
isComputed() {
|
|
12008
|
+
return this._field.isComputed();
|
|
12015
12009
|
}
|
|
12016
|
-
|
|
12017
|
-
return
|
|
12010
|
+
isOptimisticConcurrency() {
|
|
12011
|
+
return this._field.isOptimisticConcurrency();
|
|
12018
12012
|
}
|
|
12019
12013
|
get referentials() {
|
|
12020
12014
|
return this._field.referentials;
|
|
@@ -12184,17 +12178,7 @@ class ODataModelOptions {
|
|
|
12184
12178
|
this.parent.children.push(this);
|
|
12185
12179
|
}
|
|
12186
12180
|
this.entitySet = this.api.findEntitySetForEntityType(this.type());
|
|
12187
|
-
|
|
12188
|
-
if (this.entitySet !== undefined) {
|
|
12189
|
-
concurrencyFields = this.entitySet.annotatedValue(OPTIMISTIC_CONCURRENCY) ?? [];
|
|
12190
|
-
}
|
|
12191
|
-
this._fields.forEach((field) => {
|
|
12192
|
-
const concurrency = concurrencyFields.indexOf(field.field) !== -1;
|
|
12193
|
-
field.configure({
|
|
12194
|
-
concurrency,
|
|
12195
|
-
options,
|
|
12196
|
-
});
|
|
12197
|
-
});
|
|
12181
|
+
this._fields.forEach((field) => field.configure({ options, }));
|
|
12198
12182
|
}
|
|
12199
12183
|
fields({ include_navigation, include_parents, }) {
|
|
12200
12184
|
return [
|
|
@@ -12252,8 +12236,7 @@ class ODataModelOptions {
|
|
|
12252
12236
|
parser: structuredFieldParser,
|
|
12253
12237
|
});
|
|
12254
12238
|
modelField.configure({
|
|
12255
|
-
options: this.api.options
|
|
12256
|
-
concurrency: false,
|
|
12239
|
+
options: this.api.options
|
|
12257
12240
|
});
|
|
12258
12241
|
Object.defineProperty(self, modelField.name, {
|
|
12259
12242
|
configurable: true,
|
|
@@ -12450,7 +12433,7 @@ class ODataModelOptions {
|
|
|
12450
12433
|
return null;
|
|
12451
12434
|
return resolve ? Objects.resolveKey(referenced, { single }) : Object.fromEntries(referenced);
|
|
12452
12435
|
}
|
|
12453
|
-
validate(self, { method, navigation = false, }
|
|
12436
|
+
validate(self, { method, navigation = false, }) {
|
|
12454
12437
|
const errors = this.fields({
|
|
12455
12438
|
include_parents: true,
|
|
12456
12439
|
include_navigation: navigation,
|
|
@@ -12517,9 +12500,9 @@ class ODataModelOptions {
|
|
|
12517
12500
|
.reduce((acc, attr) => {
|
|
12518
12501
|
const name = field_mapping ? attr.fieldName : attr.name;
|
|
12519
12502
|
let value = attr.get();
|
|
12520
|
-
const computed = attr.
|
|
12503
|
+
const computed = attr.isComputed();
|
|
12521
12504
|
const navigation = attr.navigation;
|
|
12522
|
-
const concurrency = attr.
|
|
12505
|
+
const concurrency = attr.isOptimisticConcurrency();
|
|
12523
12506
|
if (ODataModelOptions.isModel(value)) {
|
|
12524
12507
|
value = value.toEntity({
|
|
12525
12508
|
client_id,
|