angular-odata 0.115.0 → 0.121.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/README.md +4 -2
- package/esm2020/lib/api.mjs +7 -7
- package/esm2020/lib/cache/cache.mjs +3 -3
- package/esm2020/lib/client.mjs +33 -27
- package/esm2020/lib/index.mjs +2 -2
- package/esm2020/lib/loaders.mjs +33 -0
- package/esm2020/lib/models/collection.mjs +79 -48
- package/esm2020/lib/models/model.mjs +35 -9
- package/esm2020/lib/models/options.mjs +99 -39
- package/esm2020/lib/module.mjs +21 -17
- package/esm2020/lib/options.mjs +4 -3
- package/esm2020/lib/resources/path/handlers.mjs +8 -8
- package/esm2020/lib/resources/path/segments.mjs +6 -6
- package/esm2020/lib/resources/query/builder.mjs +1 -1
- package/esm2020/lib/resources/query/expressions/count.mjs +5 -5
- package/esm2020/lib/resources/query/expressions/expand.mjs +18 -18
- package/esm2020/lib/resources/query/handlers.mjs +45 -45
- package/esm2020/lib/resources/query/options.mjs +27 -27
- package/esm2020/lib/resources/request.mjs +1 -1
- package/esm2020/lib/resources/resource.mjs +11 -9
- package/esm2020/lib/resources/responses/annotations.mjs +1 -1
- package/esm2020/lib/resources/types/action.mjs +16 -7
- package/esm2020/lib/resources/types/batch.mjs +135 -31
- package/esm2020/lib/resources/types/count.mjs +4 -4
- package/esm2020/lib/resources/types/entity-set.mjs +5 -7
- package/esm2020/lib/resources/types/entity.mjs +5 -5
- package/esm2020/lib/resources/types/function.mjs +16 -7
- package/esm2020/lib/resources/types/media.mjs +3 -3
- package/esm2020/lib/resources/types/metadata.mjs +3 -3
- package/esm2020/lib/resources/types/navigation-property.mjs +7 -9
- package/esm2020/lib/resources/types/options.mjs +1 -1
- package/esm2020/lib/resources/types/property.mjs +6 -10
- package/esm2020/lib/resources/types/reference.mjs +3 -3
- package/esm2020/lib/resources/types/singleton.mjs +4 -4
- package/esm2020/lib/resources/types/value.mjs +3 -3
- package/esm2020/lib/schema/parsers/edm.mjs +18 -17
- package/esm2020/lib/schema/parsers/enum-type.mjs +1 -1
- package/esm2020/lib/schema/parsers/structured-type.mjs +31 -19
- package/esm2020/lib/schema/structured-type.mjs +7 -1
- package/esm2020/lib/services/factory.mjs +3 -3
- package/esm2020/lib/settings.mjs +2 -2
- package/esm2020/lib/types.mjs +101 -32
- package/esm2020/lib/utils/enums.mjs +20 -20
- package/esm2020/lib/utils/strings.mjs +2 -2
- package/fesm2015/angular-odata.mjs +761 -406
- package/fesm2015/angular-odata.mjs.map +1 -1
- package/fesm2020/angular-odata.mjs +763 -404
- package/fesm2020/angular-odata.mjs.map +1 -1
- package/lib/api.d.ts +3 -3
- package/lib/client.d.ts +8 -7
- package/lib/index.d.ts +1 -1
- package/lib/loaders.d.ts +15 -0
- package/lib/models/collection.d.ts +21 -13
- package/lib/models/model.d.ts +10 -5
- package/lib/models/options.d.ts +20 -7
- package/lib/module.d.ts +12 -6
- package/lib/options.d.ts +6 -2
- package/lib/resources/path/handlers.d.ts +2 -2
- package/lib/resources/path/segments.d.ts +2 -2
- package/lib/resources/query/builder.d.ts +4 -1
- package/lib/resources/query/handlers.d.ts +3 -3
- package/lib/resources/query/options.d.ts +21 -21
- package/lib/resources/request.d.ts +4 -4
- package/lib/resources/resource.d.ts +4 -6
- package/lib/resources/types/action.d.ts +19 -2
- package/lib/resources/types/batch.d.ts +16 -5
- package/lib/resources/types/entity-set.d.ts +8 -8
- package/lib/resources/types/entity.d.ts +5 -5
- package/lib/resources/types/function.d.ts +17 -2
- package/lib/resources/types/navigation-property.d.ts +11 -11
- package/lib/resources/types/options.d.ts +0 -3
- package/lib/resources/types/property.d.ts +4 -4
- package/lib/resources/types/reference.d.ts +5 -5
- package/lib/resources/types/singleton.d.ts +5 -5
- package/lib/schema/parsers/edm.d.ts +2 -2
- package/lib/schema/parsers/enum-type.d.ts +2 -2
- package/lib/schema/parsers/structured-type.d.ts +8 -7
- package/lib/schema/structured-type.d.ts +3 -1
- package/lib/services/entity-set.d.ts +1 -6
- package/lib/settings.d.ts +3 -3
- package/lib/types.d.ts +46 -3
- package/lib/utils/enums.d.ts +18 -6
- package/lib/utils/strings.d.ts +4 -1
- package/package.json +1 -1
- package/esm2020/lib/tokens.mjs +0 -3
- package/lib/tokens.d.ts +0 -3
|
@@ -1,41 +1,111 @@
|
|
|
1
1
|
import * as i1 from '@angular/common/http';
|
|
2
2
|
import { HttpHeaders, HttpParams, HttpResponse, HttpErrorResponse, HttpEventType, HttpClientModule } from '@angular/common/http';
|
|
3
|
-
import { of, throwError, Subject, map as map$1,
|
|
3
|
+
import { of, throwError, Subject, map as map$1, EMPTY, Observable, forkJoin, NEVER } from 'rxjs';
|
|
4
4
|
import { tap, startWith, map, expand, reduce, finalize, switchMap, catchError } from 'rxjs/operators';
|
|
5
5
|
import * as i0 from '@angular/core';
|
|
6
6
|
import { EventEmitter, Injectable, InjectionToken, NgModule } from '@angular/core';
|
|
7
|
+
import { CommonModule } from '@angular/common';
|
|
7
8
|
|
|
8
|
-
var
|
|
9
|
-
(function (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})(
|
|
23
|
-
var
|
|
24
|
-
(function (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})(
|
|
9
|
+
var PathSegment;
|
|
10
|
+
(function (PathSegment) {
|
|
11
|
+
PathSegment["batch"] = "batch";
|
|
12
|
+
PathSegment["metadata"] = "metadata";
|
|
13
|
+
PathSegment["entitySet"] = "entitySet";
|
|
14
|
+
PathSegment["singleton"] = "singleton";
|
|
15
|
+
PathSegment["type"] = "type";
|
|
16
|
+
PathSegment["property"] = "property";
|
|
17
|
+
PathSegment["navigationProperty"] = "navigationProperty";
|
|
18
|
+
PathSegment["reference"] = "reference";
|
|
19
|
+
PathSegment["value"] = "value";
|
|
20
|
+
PathSegment["count"] = "count";
|
|
21
|
+
PathSegment["function"] = "function";
|
|
22
|
+
PathSegment["action"] = "action";
|
|
23
|
+
})(PathSegment || (PathSegment = {}));
|
|
24
|
+
var QueryOption;
|
|
25
|
+
(function (QueryOption) {
|
|
26
|
+
QueryOption["select"] = "select";
|
|
27
|
+
QueryOption["expand"] = "expand";
|
|
28
|
+
QueryOption["compute"] = "compute";
|
|
29
|
+
QueryOption["filter"] = "filter";
|
|
30
|
+
QueryOption["search"] = "search";
|
|
31
|
+
QueryOption["transform"] = "transform";
|
|
32
|
+
QueryOption["orderBy"] = "orderBy";
|
|
33
|
+
QueryOption["top"] = "top";
|
|
34
|
+
QueryOption["skip"] = "skip";
|
|
35
|
+
QueryOption["skiptoken"] = "skiptoken";
|
|
36
|
+
QueryOption["format"] = "format";
|
|
37
|
+
QueryOption["levels"] = "levels";
|
|
38
|
+
QueryOption["count"] = "count";
|
|
39
|
+
})(QueryOption || (QueryOption = {}));
|
|
40
|
+
var EdmType;
|
|
41
|
+
(function (EdmType) {
|
|
42
|
+
//Edm.Guid 16-byte (128-bit) unique identifier
|
|
43
|
+
EdmType["Guid"] = "Edm.Guid";
|
|
44
|
+
//Edm.Int16 Signed 16-bit integer
|
|
45
|
+
EdmType["Int16"] = "Edm.Int16";
|
|
46
|
+
//Edm.String Sequence of UTF-8 characters
|
|
47
|
+
EdmType["String"] = "Edm.String";
|
|
48
|
+
//Edm.Boolean Binary-valued logic
|
|
49
|
+
EdmType["Boolean"] = "Edm.Boolean";
|
|
50
|
+
//Edm.Byte Unsigned 8-bit integer
|
|
51
|
+
EdmType["Byte"] = "Edm.Byte";
|
|
52
|
+
//Edm.SByte Signed 8-bit integer
|
|
53
|
+
EdmType["SByte"] = "Edm.SByte";
|
|
54
|
+
//Edm.Int32 Signed 16-bit integer
|
|
55
|
+
EdmType["Int32"] = "Edm.Int32";
|
|
56
|
+
//Edm.Int64 Signed 16-bit integer
|
|
57
|
+
EdmType["Int64"] = "Edm.Int64";
|
|
58
|
+
//Edm.Date Date without a time-zone offset
|
|
59
|
+
EdmType["Date"] = "Edm.Date";
|
|
60
|
+
//Edm.TimeOfDay Clock time 00:00-23:59:59.999999999999
|
|
61
|
+
EdmType["TimeOfDay"] = "Edm.TimeOfDay";
|
|
62
|
+
//Edm.DateTimeOffset Date and time with a time-zone offset, no leap seconds
|
|
63
|
+
EdmType["DateTimeOffset"] = "Edm.DateTimeOffset";
|
|
64
|
+
//Edm.Duration Signed duration in days, hours, minutes, and (sub)seconds
|
|
65
|
+
EdmType["Duration"] = "Edm.Duration";
|
|
66
|
+
//Edm.Decimal Numeric values with fixed precision and scale
|
|
67
|
+
EdmType["Decimal"] = "Edm.Decimal";
|
|
68
|
+
//Edm.Double IEEE 754 binary64 floating-point number (15-17 decimal digits)
|
|
69
|
+
EdmType["Double"] = "Edm.Double";
|
|
70
|
+
//Edm.Single IEEE 754 binary32 floating-point number (6-9 decimal digits)
|
|
71
|
+
EdmType["Single"] = "Edm.Single";
|
|
72
|
+
//Edm.Binary Binary data
|
|
73
|
+
EdmType["Binary"] = "Edm.Binary";
|
|
74
|
+
//Edm.Stream Binary data stream
|
|
75
|
+
EdmType["Stream"] = "Edm.Stream";
|
|
76
|
+
//Edm.Geography Abstract base type for all Geography types
|
|
77
|
+
EdmType["Geography"] = "Edm.Geography";
|
|
78
|
+
//Edm.GeographyPoint A point in a round-earth coordinate system
|
|
79
|
+
EdmType["GeographyPoint"] = "Edm.GeographyPoint";
|
|
80
|
+
//Edm.GeographyLineString Line string in a round-earth coordinate system
|
|
81
|
+
EdmType["GeographyLineString"] = "Edm.GeographyLineString";
|
|
82
|
+
//Edm.GeographyPolygon Polygon in a round-earth coordinate system
|
|
83
|
+
EdmType["GeographyPolygon"] = "Edm.GeographyPolygon";
|
|
84
|
+
//Edm.GeographyMultiPoint Collection of points in a round-earth coordinate system
|
|
85
|
+
EdmType["GeographyMultiPoint"] = "Edm.GeographyMultiPoint";
|
|
86
|
+
//Edm.GeographyMultiLineString Collection of line strings in a round-earth coordinate system
|
|
87
|
+
EdmType["GeographyMultiLineString"] = "Edm.GeographyMultiLineString";
|
|
88
|
+
//Edm.GeographyMultiPolygon Collection of polygons in a round-earth coordinate system
|
|
89
|
+
EdmType["GeographyMultiPolygon"] = "Edm.GeographyMultiPolygon";
|
|
90
|
+
//Edm.GeographyCollection Collection of arbitrary Geography values
|
|
91
|
+
EdmType["GeographyCollection"] = "Edm.GeographyCollection";
|
|
92
|
+
//Edm.Geometry Abstract base type for all Geometry types
|
|
93
|
+
EdmType["Geometry"] = "Edm.Geometry";
|
|
94
|
+
//Edm.GeometryPoint Point in a flat-earth coordinate system
|
|
95
|
+
EdmType["GeometryPoint"] = "Edm.GeometryPoint";
|
|
96
|
+
//Edm.GeometryLineString Line string in a flat-earth coordinate system
|
|
97
|
+
EdmType["GeometryLineString"] = "Edm.GeometryLineString";
|
|
98
|
+
//Edm.GeometryPolygon Polygon in a flat-earth coordinate system
|
|
99
|
+
EdmType["GeometryPolygon"] = "Edm.GeometryPolygon";
|
|
100
|
+
//Edm.GeometryMultiPoint Collection of points in a flat-earth coordinate system
|
|
101
|
+
EdmType["GeometryMultiPoint"] = "Edm.GeometryMultiPoint";
|
|
102
|
+
//Edm.GeometryMultiLineString Collection of line strings in a flat-earth coordinate system
|
|
103
|
+
EdmType["GeometryMultiLineString"] = "Edm.GeometryMultiLineString";
|
|
104
|
+
//Edm.GeometryMultiPolygon Collection of polygons in a flat-earth coordinate system
|
|
105
|
+
EdmType["GeometryMultiPolygon"] = "Edm.GeometryMultiPolygon";
|
|
106
|
+
//Edm.GeometryCollection Collection of arbitrary Geometry values
|
|
107
|
+
EdmType["GeometryCollection"] = "Edm.GeometryCollection";
|
|
108
|
+
})(EdmType || (EdmType = {}));
|
|
39
109
|
const NONE_PARSER = {
|
|
40
110
|
deserialize: (value) => value,
|
|
41
111
|
serialize: (value) => value,
|
|
@@ -147,7 +217,7 @@ class ODataCache {
|
|
|
147
217
|
scope(req) {
|
|
148
218
|
const segments = req.resource.cloneSegments();
|
|
149
219
|
return segments.segments({ key: true }).reduce((acc, s) => {
|
|
150
|
-
if (s.name ===
|
|
220
|
+
if (s.name === PathSegment.entitySet)
|
|
151
221
|
acc = [...acc, s.path()];
|
|
152
222
|
return acc;
|
|
153
223
|
}, ['request']);
|
|
@@ -979,45 +1049,45 @@ const Durations = {
|
|
|
979
1049
|
};
|
|
980
1050
|
|
|
981
1051
|
const Enums = {
|
|
982
|
-
names(
|
|
983
|
-
return Object.values(
|
|
1052
|
+
names(enums) {
|
|
1053
|
+
return Object.values(enums).filter((v) => typeof v === 'string');
|
|
984
1054
|
},
|
|
985
|
-
values(
|
|
986
|
-
return Object.values(
|
|
1055
|
+
values(enums) {
|
|
1056
|
+
return Object.values(enums).filter((v) => typeof v === 'number');
|
|
987
1057
|
},
|
|
988
|
-
toValue(
|
|
989
|
-
if (value in
|
|
990
|
-
return typeof value === 'string' ?
|
|
1058
|
+
toValue(enums, value) {
|
|
1059
|
+
if (value in enums)
|
|
1060
|
+
return typeof value === 'string' ? enums[value] : value;
|
|
991
1061
|
return undefined;
|
|
992
1062
|
},
|
|
993
|
-
toValues(
|
|
1063
|
+
toValues(enums, value) {
|
|
994
1064
|
if (typeof value === 'number') {
|
|
995
|
-
return this.values(
|
|
1065
|
+
return this.values(enums).filter((v) => (value & v) === v);
|
|
996
1066
|
}
|
|
997
1067
|
if (typeof value === 'string') {
|
|
998
1068
|
value = value.split(',').map((o) => o.trim());
|
|
999
1069
|
}
|
|
1000
|
-
if (Array.isArray(value) && value.every((v) => v in
|
|
1001
|
-
return value.map((o) => this.toValue(
|
|
1070
|
+
if (Array.isArray(value) && value.every((v) => v in enums)) {
|
|
1071
|
+
return value.map((o) => this.toValue(enums, o));
|
|
1002
1072
|
}
|
|
1003
1073
|
return [];
|
|
1004
1074
|
},
|
|
1005
|
-
toName(
|
|
1006
|
-
if (value in
|
|
1007
|
-
return typeof value === 'number' ?
|
|
1075
|
+
toName(enums, value) {
|
|
1076
|
+
if (value in enums)
|
|
1077
|
+
return typeof value === 'number' ? enums[value] : value;
|
|
1008
1078
|
return undefined;
|
|
1009
1079
|
},
|
|
1010
|
-
toNames(
|
|
1080
|
+
toNames(enums, value) {
|
|
1011
1081
|
if (typeof value === 'number') {
|
|
1012
|
-
return this.values(
|
|
1082
|
+
return this.values(enums)
|
|
1013
1083
|
.filter((v) => (value & v) === v)
|
|
1014
|
-
.map((v) => this.toName(
|
|
1084
|
+
.map((v) => this.toName(enums, v));
|
|
1015
1085
|
}
|
|
1016
1086
|
if (typeof value === 'string') {
|
|
1017
1087
|
value = value.split(',').map((o) => o.trim());
|
|
1018
1088
|
}
|
|
1019
|
-
if (Array.isArray(value) && value.every((v) => v in
|
|
1020
|
-
return value.map((o) => this.toName(
|
|
1089
|
+
if (Array.isArray(value) && value.every((v) => v in enums)) {
|
|
1090
|
+
return value.map((o) => this.toName(enums, o));
|
|
1021
1091
|
}
|
|
1022
1092
|
return [];
|
|
1023
1093
|
},
|
|
@@ -1477,7 +1547,7 @@ function now() {
|
|
|
1477
1547
|
return (glast = time > last ? time : last + 1);
|
|
1478
1548
|
}
|
|
1479
1549
|
const Strings = {
|
|
1480
|
-
uniqueId(prefix, suffix) {
|
|
1550
|
+
uniqueId({ prefix, suffix, } = {}) {
|
|
1481
1551
|
return (prefix ? prefix : '') + now().toString(36) + (suffix ? suffix : '');
|
|
1482
1552
|
},
|
|
1483
1553
|
titleCase(text) {
|
|
@@ -1991,8 +2061,8 @@ class CountField {
|
|
|
1991
2061
|
}
|
|
1992
2062
|
render({ aliases, escape, prefix, }) {
|
|
1993
2063
|
const params = [
|
|
1994
|
-
|
|
1995
|
-
|
|
2064
|
+
QueryOption.filter,
|
|
2065
|
+
QueryOption.search,
|
|
1996
2066
|
]
|
|
1997
2067
|
.filter((key) => !Types.isEmpty(this.values[key]))
|
|
1998
2068
|
.reduce((acc, key) => {
|
|
@@ -2011,7 +2081,7 @@ class CountField {
|
|
|
2011
2081
|
return count;
|
|
2012
2082
|
}
|
|
2013
2083
|
filter(opts) {
|
|
2014
|
-
return this.option(
|
|
2084
|
+
return this.option(QueryOption.filter, FilterExpression.filter(opts, this.values[QueryOption.filter]));
|
|
2015
2085
|
}
|
|
2016
2086
|
clone() {
|
|
2017
2087
|
const values = Object.keys(this.values).reduce((acc, key) => Object.assign(acc, { [key]: Objects.clone(this.values[key]) }), {});
|
|
@@ -2435,14 +2505,14 @@ class ExpandField {
|
|
|
2435
2505
|
}
|
|
2436
2506
|
render({ aliases, escape, prefix, }) {
|
|
2437
2507
|
const params = [
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2508
|
+
QueryOption.select,
|
|
2509
|
+
QueryOption.expand,
|
|
2510
|
+
QueryOption.filter,
|
|
2511
|
+
QueryOption.search,
|
|
2512
|
+
QueryOption.orderBy,
|
|
2513
|
+
QueryOption.skip,
|
|
2514
|
+
QueryOption.top,
|
|
2515
|
+
QueryOption.levels,
|
|
2446
2516
|
]
|
|
2447
2517
|
.filter((key) => !Types.isEmpty(this.values[key]))
|
|
2448
2518
|
.reduce((acc, key) => {
|
|
@@ -2465,28 +2535,28 @@ class ExpandField {
|
|
|
2465
2535
|
return new ExpandField(this.field.clone(), values);
|
|
2466
2536
|
}
|
|
2467
2537
|
select(opts) {
|
|
2468
|
-
return this.option(
|
|
2538
|
+
return this.option(QueryOption.select, SelectExpression.select(opts, this.values[QueryOption.select]));
|
|
2469
2539
|
}
|
|
2470
2540
|
expand(opts) {
|
|
2471
|
-
return this.option(
|
|
2541
|
+
return this.option(QueryOption.expand, ExpandExpression.expand(opts, this.values[QueryOption.expand]));
|
|
2472
2542
|
}
|
|
2473
2543
|
filter(opts) {
|
|
2474
|
-
return this.option(
|
|
2544
|
+
return this.option(QueryOption.filter, FilterExpression.filter(opts, this.values[QueryOption.filter]));
|
|
2475
2545
|
}
|
|
2476
2546
|
search(opts) {
|
|
2477
|
-
return this.option(
|
|
2547
|
+
return this.option(QueryOption.search, SearchExpression.search(opts, this.values[QueryOption.search]));
|
|
2478
2548
|
}
|
|
2479
2549
|
orderBy(opts) {
|
|
2480
|
-
return this.option(
|
|
2550
|
+
return this.option(QueryOption.orderBy, OrderByExpression.orderBy(opts, this.values[QueryOption.orderBy]));
|
|
2481
2551
|
}
|
|
2482
2552
|
skip(n) {
|
|
2483
|
-
return this.option(
|
|
2553
|
+
return this.option(QueryOption.skip, n);
|
|
2484
2554
|
}
|
|
2485
2555
|
top(n) {
|
|
2486
|
-
return this.option(
|
|
2556
|
+
return this.option(QueryOption.top, n);
|
|
2487
2557
|
}
|
|
2488
2558
|
levels(n) {
|
|
2489
|
-
return this.option(
|
|
2559
|
+
return this.option(QueryOption.levels, n);
|
|
2490
2560
|
}
|
|
2491
2561
|
// Option Handler
|
|
2492
2562
|
option(name, opts) {
|
|
@@ -2726,54 +2796,54 @@ class ODataQueryOptionsHandler {
|
|
|
2726
2796
|
}
|
|
2727
2797
|
select(opts) {
|
|
2728
2798
|
if (Types.isFunction(opts)) {
|
|
2729
|
-
return this.options.expression(
|
|
2799
|
+
return this.options.expression(QueryOption.select, SelectExpression.select(opts, this.options.expression(QueryOption.select)));
|
|
2730
2800
|
}
|
|
2731
|
-
return this.options.option(
|
|
2801
|
+
return this.options.option(QueryOption.select, opts);
|
|
2732
2802
|
}
|
|
2733
2803
|
expand(opts) {
|
|
2734
2804
|
if (Types.isFunction(opts)) {
|
|
2735
|
-
return this.options.expression(
|
|
2805
|
+
return this.options.expression(QueryOption.expand, ExpandExpression.expand(opts, this.options.expression(QueryOption.expand)));
|
|
2736
2806
|
}
|
|
2737
|
-
return this.options.option(
|
|
2807
|
+
return this.options.option(QueryOption.expand, opts);
|
|
2738
2808
|
}
|
|
2739
2809
|
compute(opts) {
|
|
2740
2810
|
if (Types.isFunction(opts)) {
|
|
2741
|
-
return this.options.expression(
|
|
2811
|
+
return this.options.expression(QueryOption.compute, ComputeExpression.compute(opts, this.options.expression(QueryOption.compute)));
|
|
2742
2812
|
}
|
|
2743
|
-
return this.options.option(
|
|
2813
|
+
return this.options.option(QueryOption.compute, opts);
|
|
2744
2814
|
}
|
|
2745
2815
|
format(opts) {
|
|
2746
|
-
return this.options.option(
|
|
2816
|
+
return this.options.option(QueryOption.format, opts);
|
|
2747
2817
|
}
|
|
2748
2818
|
transform(opts) {
|
|
2749
|
-
return this.options.option(
|
|
2819
|
+
return this.options.option(QueryOption.transform, opts);
|
|
2750
2820
|
}
|
|
2751
2821
|
search(opts) {
|
|
2752
2822
|
if (Types.isFunction(opts)) {
|
|
2753
|
-
return this.options.expression(
|
|
2823
|
+
return this.options.expression(QueryOption.search, SearchExpression.search(opts, this.options.expression(QueryOption.search)));
|
|
2754
2824
|
}
|
|
2755
|
-
return this.options.option(
|
|
2825
|
+
return this.options.option(QueryOption.search, opts);
|
|
2756
2826
|
}
|
|
2757
2827
|
filter(opts) {
|
|
2758
2828
|
if (Types.isFunction(opts)) {
|
|
2759
|
-
return this.options.expression(
|
|
2829
|
+
return this.options.expression(QueryOption.filter, FilterExpression.filter(opts, this.options.expression(QueryOption.filter)));
|
|
2760
2830
|
}
|
|
2761
|
-
return this.options.option(
|
|
2831
|
+
return this.options.option(QueryOption.filter, opts);
|
|
2762
2832
|
}
|
|
2763
2833
|
orderBy(opts) {
|
|
2764
2834
|
if (Types.isFunction(opts)) {
|
|
2765
|
-
return this.options.option(
|
|
2835
|
+
return this.options.option(QueryOption.orderBy, OrderByExpression.orderBy(opts, this.options.expression(QueryOption.orderBy)));
|
|
2766
2836
|
}
|
|
2767
|
-
return this.options.option(
|
|
2837
|
+
return this.options.option(QueryOption.orderBy, opts);
|
|
2768
2838
|
}
|
|
2769
2839
|
top(opts) {
|
|
2770
|
-
return this.options.option(
|
|
2840
|
+
return this.options.option(QueryOption.top, opts);
|
|
2771
2841
|
}
|
|
2772
2842
|
skip(opts) {
|
|
2773
|
-
return this.options.option(
|
|
2843
|
+
return this.options.option(QueryOption.skip, opts);
|
|
2774
2844
|
}
|
|
2775
2845
|
skiptoken(opts) {
|
|
2776
|
-
return this.options.option(
|
|
2846
|
+
return this.options.option(QueryOption.skiptoken, opts);
|
|
2777
2847
|
}
|
|
2778
2848
|
/**
|
|
2779
2849
|
* Shortcut for set $top, $skip, $skiptoken.
|
|
@@ -2785,7 +2855,7 @@ class ODataQueryOptionsHandler {
|
|
|
2785
2855
|
this.skiptoken(skiptoken);
|
|
2786
2856
|
}
|
|
2787
2857
|
else {
|
|
2788
|
-
this.options.remove(
|
|
2858
|
+
this.options.remove(QueryOption.skiptoken);
|
|
2789
2859
|
}
|
|
2790
2860
|
}
|
|
2791
2861
|
if (skip !== undefined) {
|
|
@@ -2793,7 +2863,7 @@ class ODataQueryOptionsHandler {
|
|
|
2793
2863
|
this.skip(skip);
|
|
2794
2864
|
}
|
|
2795
2865
|
else {
|
|
2796
|
-
this.options.remove(
|
|
2866
|
+
this.options.remove(QueryOption.skip);
|
|
2797
2867
|
}
|
|
2798
2868
|
}
|
|
2799
2869
|
if (top !== undefined) {
|
|
@@ -2801,7 +2871,7 @@ class ODataQueryOptionsHandler {
|
|
|
2801
2871
|
this.top(top);
|
|
2802
2872
|
}
|
|
2803
2873
|
else {
|
|
2804
|
-
this.options.remove(
|
|
2874
|
+
this.options.remove(QueryOption.top);
|
|
2805
2875
|
}
|
|
2806
2876
|
}
|
|
2807
2877
|
}
|
|
@@ -2809,9 +2879,9 @@ class ODataQueryOptionsHandler {
|
|
|
2809
2879
|
* Shortcut for clear pagination by unset $top, $skip, $skiptoken.
|
|
2810
2880
|
*/
|
|
2811
2881
|
clearPaging() {
|
|
2812
|
-
this.options.remove(
|
|
2813
|
-
this.options.remove(
|
|
2814
|
-
this.options.remove(
|
|
2882
|
+
this.options.remove(QueryOption.skip);
|
|
2883
|
+
this.options.remove(QueryOption.top);
|
|
2884
|
+
this.options.remove(QueryOption.skiptoken);
|
|
2815
2885
|
}
|
|
2816
2886
|
/**
|
|
2817
2887
|
* Shortcut for clear query.
|
|
@@ -2832,76 +2902,76 @@ class ODataQueryOptionsHandler {
|
|
|
2832
2902
|
apply(query) {
|
|
2833
2903
|
if (query.select !== undefined) {
|
|
2834
2904
|
if (query.select instanceof SelectExpression) {
|
|
2835
|
-
this.options.expression(
|
|
2905
|
+
this.options.expression(QueryOption.select, query.select);
|
|
2836
2906
|
}
|
|
2837
2907
|
else if (query.select !== null) {
|
|
2838
|
-
this.options.option(
|
|
2908
|
+
this.options.option(QueryOption.select, query.select);
|
|
2839
2909
|
}
|
|
2840
2910
|
else {
|
|
2841
|
-
this.options.remove(
|
|
2911
|
+
this.options.remove(QueryOption.select);
|
|
2842
2912
|
}
|
|
2843
2913
|
}
|
|
2844
2914
|
if (query.expand !== undefined) {
|
|
2845
2915
|
if (query.expand instanceof ExpandExpression) {
|
|
2846
|
-
this.options.expression(
|
|
2916
|
+
this.options.expression(QueryOption.expand, query.expand);
|
|
2847
2917
|
}
|
|
2848
2918
|
else if (query.expand !== null) {
|
|
2849
|
-
this.options.option(
|
|
2919
|
+
this.options.option(QueryOption.expand, query.expand);
|
|
2850
2920
|
}
|
|
2851
2921
|
else {
|
|
2852
|
-
this.options.remove(
|
|
2922
|
+
this.options.remove(QueryOption.expand);
|
|
2853
2923
|
}
|
|
2854
2924
|
}
|
|
2855
2925
|
if (query.compute !== undefined) {
|
|
2856
2926
|
if (query.compute instanceof ComputeExpression) {
|
|
2857
|
-
this.options.expression(
|
|
2927
|
+
this.options.expression(QueryOption.compute, query.compute);
|
|
2858
2928
|
}
|
|
2859
2929
|
else if (query.compute !== null) {
|
|
2860
|
-
this.options.option(
|
|
2930
|
+
this.options.option(QueryOption.compute, query.compute);
|
|
2861
2931
|
}
|
|
2862
2932
|
else {
|
|
2863
|
-
this.options.remove(
|
|
2933
|
+
this.options.remove(QueryOption.compute);
|
|
2864
2934
|
}
|
|
2865
2935
|
}
|
|
2866
2936
|
if (query.transform !== undefined) {
|
|
2867
2937
|
if (query.transform !== null) {
|
|
2868
|
-
this.options.option(
|
|
2938
|
+
this.options.option(QueryOption.transform, query.transform);
|
|
2869
2939
|
}
|
|
2870
2940
|
else {
|
|
2871
|
-
this.options.remove(
|
|
2941
|
+
this.options.remove(QueryOption.transform);
|
|
2872
2942
|
}
|
|
2873
2943
|
}
|
|
2874
2944
|
if (query.search !== undefined) {
|
|
2875
2945
|
if (query.search instanceof SearchExpression) {
|
|
2876
|
-
this.options.expression(
|
|
2946
|
+
this.options.expression(QueryOption.search, query.search);
|
|
2877
2947
|
}
|
|
2878
2948
|
else if (query.search !== null) {
|
|
2879
|
-
this.options.option(
|
|
2949
|
+
this.options.option(QueryOption.search, query.search);
|
|
2880
2950
|
}
|
|
2881
2951
|
else {
|
|
2882
|
-
this.options.remove(
|
|
2952
|
+
this.options.remove(QueryOption.search);
|
|
2883
2953
|
}
|
|
2884
2954
|
}
|
|
2885
2955
|
if (query.filter !== undefined) {
|
|
2886
2956
|
if (query.filter instanceof FilterExpression) {
|
|
2887
|
-
this.options.expression(
|
|
2957
|
+
this.options.expression(QueryOption.filter, query.filter);
|
|
2888
2958
|
}
|
|
2889
2959
|
else if (query.filter !== null) {
|
|
2890
|
-
this.options.option(
|
|
2960
|
+
this.options.option(QueryOption.filter, query.filter);
|
|
2891
2961
|
}
|
|
2892
2962
|
else {
|
|
2893
|
-
this.options.remove(
|
|
2963
|
+
this.options.remove(QueryOption.filter);
|
|
2894
2964
|
}
|
|
2895
2965
|
}
|
|
2896
2966
|
if (query.orderBy !== undefined) {
|
|
2897
2967
|
if (query.orderBy instanceof OrderByExpression) {
|
|
2898
|
-
this.options.expression(
|
|
2968
|
+
this.options.expression(QueryOption.orderBy, query.orderBy);
|
|
2899
2969
|
}
|
|
2900
2970
|
else if (query.orderBy !== null) {
|
|
2901
|
-
this.options.option(
|
|
2971
|
+
this.options.option(QueryOption.orderBy, query.orderBy);
|
|
2902
2972
|
}
|
|
2903
2973
|
else {
|
|
2904
|
-
this.options.remove(
|
|
2974
|
+
this.options.remove(QueryOption.orderBy);
|
|
2905
2975
|
}
|
|
2906
2976
|
}
|
|
2907
2977
|
this.paging(query);
|
|
@@ -2919,19 +2989,19 @@ class ODataQueryOptions {
|
|
|
2919
2989
|
pathAndParams(escape = false) {
|
|
2920
2990
|
let aliases = [];
|
|
2921
2991
|
let options = [
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2992
|
+
QueryOption.select,
|
|
2993
|
+
QueryOption.filter,
|
|
2994
|
+
QueryOption.search,
|
|
2995
|
+
QueryOption.compute,
|
|
2996
|
+
QueryOption.transform,
|
|
2997
|
+
QueryOption.orderBy,
|
|
2998
|
+
QueryOption.top,
|
|
2999
|
+
QueryOption.skip,
|
|
3000
|
+
QueryOption.skiptoken,
|
|
3001
|
+
QueryOption.expand,
|
|
3002
|
+
QueryOption.format,
|
|
3003
|
+
QueryOption.levels,
|
|
3004
|
+
QueryOption.count,
|
|
2935
3005
|
]
|
|
2936
3006
|
.filter((key) => !Types.isEmpty(this.values.get(key)))
|
|
2937
3007
|
.reduce((acc, key) => {
|
|
@@ -2966,18 +3036,18 @@ class ODataQueryOptions {
|
|
|
2966
3036
|
}
|
|
2967
3037
|
toQueryArguments() {
|
|
2968
3038
|
return {
|
|
2969
|
-
select: this.values.get(
|
|
2970
|
-
expand: this.values.get(
|
|
2971
|
-
transform: this.values.get(
|
|
2972
|
-
compute: this.values.get(
|
|
2973
|
-
search: this.values.get(
|
|
2974
|
-
filter: this.values.get(
|
|
2975
|
-
orderBy: this.values.get(
|
|
2976
|
-
top: this.values.get(
|
|
2977
|
-
skip: this.values.get(
|
|
2978
|
-
skiptoken: this.values.get(
|
|
2979
|
-
levels: this.values.get(
|
|
2980
|
-
count: this.values.get(
|
|
3039
|
+
select: this.values.get(QueryOption.select) || null,
|
|
3040
|
+
expand: this.values.get(QueryOption.expand) || null,
|
|
3041
|
+
transform: this.values.get(QueryOption.transform) || null,
|
|
3042
|
+
compute: this.values.get(QueryOption.compute) || null,
|
|
3043
|
+
search: this.values.get(QueryOption.search) || null,
|
|
3044
|
+
filter: this.values.get(QueryOption.filter) || null,
|
|
3045
|
+
orderBy: this.values.get(QueryOption.orderBy) || null,
|
|
3046
|
+
top: this.values.get(QueryOption.top) || null,
|
|
3047
|
+
skip: this.values.get(QueryOption.skip) || null,
|
|
3048
|
+
skiptoken: this.values.get(QueryOption.skiptoken) || null,
|
|
3049
|
+
levels: this.values.get(QueryOption.levels) || null,
|
|
3050
|
+
count: this.values.get(QueryOption.count) || null,
|
|
2981
3051
|
};
|
|
2982
3052
|
}
|
|
2983
3053
|
clone() {
|
|
@@ -3064,30 +3134,30 @@ class ODataPathSegmentsHandler {
|
|
|
3064
3134
|
this.segments = segments;
|
|
3065
3135
|
}
|
|
3066
3136
|
entitySet() {
|
|
3067
|
-
return this.segments.get(
|
|
3137
|
+
return this.segments.get(PathSegment.entitySet);
|
|
3068
3138
|
}
|
|
3069
3139
|
singleton() {
|
|
3070
|
-
return this.segments.get(
|
|
3140
|
+
return this.segments.get(PathSegment.singleton);
|
|
3071
3141
|
}
|
|
3072
3142
|
action() {
|
|
3073
|
-
return this.segments.get(
|
|
3143
|
+
return this.segments.get(PathSegment.action);
|
|
3074
3144
|
}
|
|
3075
3145
|
function() {
|
|
3076
|
-
return this.segments.get(
|
|
3146
|
+
return this.segments.get(PathSegment.function);
|
|
3077
3147
|
}
|
|
3078
3148
|
keys(values) {
|
|
3079
3149
|
return this.segments.keys(values);
|
|
3080
3150
|
}
|
|
3081
3151
|
property() {
|
|
3082
|
-
return this.segments.get(
|
|
3152
|
+
return this.segments.get(PathSegment.property);
|
|
3083
3153
|
}
|
|
3084
3154
|
navigationProperty() {
|
|
3085
|
-
return this.segments.get(
|
|
3155
|
+
return this.segments.get(PathSegment.navigationProperty);
|
|
3086
3156
|
}
|
|
3087
3157
|
}
|
|
3088
3158
|
|
|
3089
3159
|
function pathSegmentsBuilder(segment, escape = false) {
|
|
3090
|
-
if (segment.name ===
|
|
3160
|
+
if (segment.name === PathSegment.function) {
|
|
3091
3161
|
let [path, params] = segment.parameters
|
|
3092
3162
|
? buildPathAndQuery({
|
|
3093
3163
|
func: { [segment.path]: segment.parameters },
|
|
@@ -3178,9 +3248,9 @@ class ODataPathSegments {
|
|
|
3178
3248
|
let segments = [...this._segments];
|
|
3179
3249
|
if (key)
|
|
3180
3250
|
segments = segments.filter((s) => [
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3251
|
+
PathSegment.entitySet,
|
|
3252
|
+
PathSegment.navigationProperty,
|
|
3253
|
+
PathSegment.property,
|
|
3184
3254
|
].indexOf(s.name) !== -1);
|
|
3185
3255
|
return segments.map((s) => new SegmentHandler(s));
|
|
3186
3256
|
}
|
|
@@ -3844,31 +3914,31 @@ const toBoolean = (v) => Boolean(v);
|
|
|
3844
3914
|
const toDate = (v) => new Date(v);
|
|
3845
3915
|
const EDM_PARSERS = {
|
|
3846
3916
|
//Edm.Guid 16-byte (128-bit) unique identifier
|
|
3847
|
-
|
|
3917
|
+
[EdmType.Guid]: EdmParser(Identity, Identity, (v) => raw(v)),
|
|
3848
3918
|
//Edm.Int16 Signed 16-bit integer
|
|
3849
|
-
|
|
3919
|
+
[EdmType.Int16]: EdmParser(toNumber, toNumber, toNumber),
|
|
3850
3920
|
//Edm.String Sequence of UTF-8 characters
|
|
3851
|
-
|
|
3921
|
+
[EdmType.String]: EdmParser(toString, toString, toString),
|
|
3852
3922
|
//Edm.Boolean Binary-valued logic
|
|
3853
|
-
|
|
3923
|
+
[EdmType.Boolean]: EdmParser(toBoolean, toBoolean, toBoolean),
|
|
3854
3924
|
//Edm.Byte Unsigned 8-bit integer
|
|
3855
|
-
|
|
3925
|
+
[EdmType.Byte]: EdmParser(toNumber, toNumber, toNumber),
|
|
3856
3926
|
//Edm.SByte Signed 8-bit integer
|
|
3857
|
-
|
|
3927
|
+
[EdmType.SByte]: EdmParser(toNumber, toNumber, toNumber),
|
|
3858
3928
|
//Edm.Int32 Signed 16-bit integer
|
|
3859
|
-
|
|
3929
|
+
[EdmType.Int32]: EdmParser(toNumber, toNumber, toNumber),
|
|
3860
3930
|
//Edm.Int64 Signed 16-bit integer
|
|
3861
|
-
|
|
3931
|
+
[EdmType.Int64]: EdmParser(toNumber, toNumber, toNumber),
|
|
3862
3932
|
//Edm.Date Date without a time-zone offset
|
|
3863
|
-
|
|
3933
|
+
[EdmType.Date]: EdmParser((v) => new Date(`${v}T00:00:00.000Z`), (v) => toDate(v).toISOString().substring(0, 10), (v) => raw(toDate(v).toISOString().substring(0, 10))),
|
|
3864
3934
|
//Edm.TimeOfDay Clock time 00:00-23:59:59.999999999999
|
|
3865
|
-
|
|
3935
|
+
[EdmType.TimeOfDay]: EdmParser((v) => new Date(`1970-01-01T${v}Z`), (v) => toDate(v).toISOString().substring(11, 23), (v) => raw(toDate(v).toISOString().substring(11, 23))),
|
|
3866
3936
|
//Edm.DateTimeOffset Date and time with a time-zone offset, no leap seconds
|
|
3867
|
-
|
|
3937
|
+
[EdmType.DateTimeOffset]: EdmParser(toDate, (v) => toDate(v).toISOString(), (v) => raw(toDate(v).toISOString())),
|
|
3868
3938
|
//Edm.Duration Signed duration in days, hours, minutes, and (sub)seconds
|
|
3869
|
-
|
|
3939
|
+
[EdmType.Duration]: EdmParser((v) => Durations.toDuration(v), (v) => Durations.toString(v), (v) => raw(Durations.toString(v))),
|
|
3870
3940
|
//Edm.Decimal Numeric values with fixed precision and scale
|
|
3871
|
-
|
|
3941
|
+
[EdmType.Decimal]: EdmParser((v, o) => {
|
|
3872
3942
|
if (typeof v === 'string' && o.ieee754Compatible) {
|
|
3873
3943
|
return parseFloat(v);
|
|
3874
3944
|
}
|
|
@@ -3893,11 +3963,11 @@ const EDM_PARSERS = {
|
|
|
3893
3963
|
return v;
|
|
3894
3964
|
}),
|
|
3895
3965
|
//Edm.Double IEEE 754 binary64 floating-point number (15-17 decimal digits)
|
|
3896
|
-
|
|
3966
|
+
[EdmType.Double]: EdmParser((v) => (v === 'INF' ? Infinity : v), (v) => (v === Infinity ? 'INF' : v), (v) => raw(v === Infinity ? 'INF' : v.toString())),
|
|
3897
3967
|
//Edm.Single IEEE 754 binary32 floating-point number (6-9 decimal digits)
|
|
3898
|
-
|
|
3968
|
+
[EdmType.Single]: EdmParser((v) => (v === 'INF' ? Infinity : v), (v) => (v === Infinity ? 'INF' : v), (v) => raw(v === Infinity ? 'INF' : v.toString())),
|
|
3899
3969
|
//Edm.Binary Binary data
|
|
3900
|
-
|
|
3970
|
+
[EdmType.Binary]: EdmParser((v) => ArrayBuffers.toArrayBuffer(v), (v) => ArrayBuffers.toString(v), (v) => raw(ArrayBuffers.toString(v))),
|
|
3901
3971
|
};
|
|
3902
3972
|
/*
|
|
3903
3973
|
Edm.Stream Binary data stream
|
|
@@ -4061,7 +4131,7 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
|
|
|
4061
4131
|
this.referentials = (field.referentials || []).map((referential) => new ODataReferential(referential));
|
|
4062
4132
|
this.default = field.default;
|
|
4063
4133
|
this.maxLength = field.maxLength;
|
|
4064
|
-
this.nullable = field.nullable
|
|
4134
|
+
this.nullable = field.nullable ?? true;
|
|
4065
4135
|
this.collection = Boolean(field.collection);
|
|
4066
4136
|
this.navigation = Boolean(field.navigation);
|
|
4067
4137
|
this.precision = field.precision;
|
|
@@ -4179,36 +4249,42 @@ class ODataStructuredTypeFieldParser extends ODataAnnotatable {
|
|
|
4179
4249
|
? this.parser.toJsonSchema(options)
|
|
4180
4250
|
: { title: this.name, type: 'object' };
|
|
4181
4251
|
if ([
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4252
|
+
EdmType.String,
|
|
4253
|
+
EdmType.Date,
|
|
4254
|
+
EdmType.TimeOfDay,
|
|
4255
|
+
EdmType.DateTimeOffset,
|
|
4256
|
+
EdmType.Guid,
|
|
4257
|
+
EdmType.Binary,
|
|
4188
4258
|
].indexOf(this.type) !== -1) {
|
|
4189
4259
|
schema.type = 'string';
|
|
4190
|
-
if (this.type ===
|
|
4260
|
+
if (this.type === EdmType.Date)
|
|
4191
4261
|
schema.format = 'date';
|
|
4192
|
-
else if (this.type ===
|
|
4262
|
+
else if (this.type === EdmType.TimeOfDay)
|
|
4193
4263
|
schema.format = 'time';
|
|
4194
|
-
else if (this.type ===
|
|
4264
|
+
else if (this.type === EdmType.DateTimeOffset)
|
|
4195
4265
|
schema.format = 'date-time';
|
|
4196
|
-
else if (this.type ===
|
|
4266
|
+
else if (this.type === EdmType.Guid)
|
|
4197
4267
|
schema.pattern =
|
|
4198
4268
|
'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$';
|
|
4199
|
-
else if (this.type ===
|
|
4269
|
+
else if (this.type === EdmType.Binary)
|
|
4200
4270
|
schema.contentEncoding = 'base64';
|
|
4201
|
-
else if (this.type ===
|
|
4271
|
+
else if (this.type === EdmType.String && this.maxLength)
|
|
4202
4272
|
schema.maxLength = this.maxLength;
|
|
4203
4273
|
}
|
|
4204
|
-
else if ([
|
|
4274
|
+
else if ([
|
|
4275
|
+
EdmType.Int64,
|
|
4276
|
+
EdmType.Int32,
|
|
4277
|
+
EdmType.Int16,
|
|
4278
|
+
EdmType.Byte,
|
|
4279
|
+
EdmType.SByte,
|
|
4280
|
+
].indexOf(this.type) !== -1) {
|
|
4205
4281
|
//TODO: Range
|
|
4206
4282
|
schema.type = 'integer';
|
|
4207
4283
|
}
|
|
4208
|
-
else if ([
|
|
4284
|
+
else if ([EdmType.Decimal, EdmType.Double].indexOf(this.type) !== -1) {
|
|
4209
4285
|
schema.type = 'number';
|
|
4210
4286
|
}
|
|
4211
|
-
else if ([
|
|
4287
|
+
else if ([EdmType.Boolean].indexOf(this.type) !== -1) {
|
|
4212
4288
|
schema.type = 'boolean';
|
|
4213
4289
|
}
|
|
4214
4290
|
if (this.default)
|
|
@@ -4261,6 +4337,7 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
|
|
|
4261
4337
|
constructor(config, namespace, alias) {
|
|
4262
4338
|
super(config);
|
|
4263
4339
|
this.children = [];
|
|
4340
|
+
this._fields = [];
|
|
4264
4341
|
this.name = config.name;
|
|
4265
4342
|
this.base = config.base;
|
|
4266
4343
|
this.open = config.open || false;
|
|
@@ -4268,7 +4345,12 @@ class ODataStructuredTypeParser extends ODataAnnotatable {
|
|
|
4268
4345
|
this.alias = alias;
|
|
4269
4346
|
if (Array.isArray(config.keys))
|
|
4270
4347
|
this._keys = config.keys.map((key) => new ODataEntityTypeKey(key));
|
|
4271
|
-
|
|
4348
|
+
Object.entries(config.fields).forEach(([name, config]) => this.addField(name, config));
|
|
4349
|
+
}
|
|
4350
|
+
addField(name, config) {
|
|
4351
|
+
const field = new ODataStructuredTypeFieldParser(name, this, config);
|
|
4352
|
+
this._fields.push(field);
|
|
4353
|
+
return field;
|
|
4272
4354
|
}
|
|
4273
4355
|
/**
|
|
4274
4356
|
* Create a nicer looking title.
|
|
@@ -4829,6 +4911,9 @@ class ODataStructuredType extends ODataSchemaElement {
|
|
|
4829
4911
|
isCompoundKey() {
|
|
4830
4912
|
return this.keys().length > 1;
|
|
4831
4913
|
}
|
|
4914
|
+
isOpenType() {
|
|
4915
|
+
return this.open;
|
|
4916
|
+
}
|
|
4832
4917
|
/**
|
|
4833
4918
|
* Find the field parser for the given field name.
|
|
4834
4919
|
* @param name Name of the field
|
|
@@ -4837,6 +4922,9 @@ class ODataStructuredType extends ODataSchemaElement {
|
|
|
4837
4922
|
field(name) {
|
|
4838
4923
|
return this.parser.field(name);
|
|
4839
4924
|
}
|
|
4925
|
+
addField(name, config) {
|
|
4926
|
+
return this.parser.addField(name, config);
|
|
4927
|
+
}
|
|
4840
4928
|
/**
|
|
4841
4929
|
* Find a parent schema of the structured type.
|
|
4842
4930
|
* @param predicate Function for evaluate the schemas in the hierarchy.
|
|
@@ -5040,37 +5128,39 @@ class ODataResource {
|
|
|
5040
5128
|
return Boolean(this.pathSegments.last({ key: true })?.hasKey());
|
|
5041
5129
|
}
|
|
5042
5130
|
hasEntityKey() {
|
|
5043
|
-
return Boolean(this.pathSegments.get(
|
|
5131
|
+
return Boolean(this.pathSegments.get(PathSegment.entitySet)?.hasKey());
|
|
5044
5132
|
}
|
|
5045
5133
|
clearKey() {
|
|
5046
5134
|
return this.pathSegments.last({ key: true })?.clearKey();
|
|
5047
5135
|
}
|
|
5048
5136
|
//#region Models
|
|
5049
|
-
asModel(entity, { annots
|
|
5137
|
+
asModel(entity, { annots } = {}) {
|
|
5138
|
+
const reset = annots !== undefined;
|
|
5050
5139
|
let resource = this;
|
|
5051
5140
|
const type = annots?.type || this.returnType();
|
|
5052
5141
|
if (type === undefined)
|
|
5053
5142
|
throw Error('');
|
|
5054
|
-
const
|
|
5143
|
+
const ModelType = this.api.modelForType(type);
|
|
5055
5144
|
let entitySet = annots?.entitySet;
|
|
5056
5145
|
if (entitySet !== undefined) {
|
|
5057
5146
|
resource = this.api.entitySet(entitySet).entity(entity);
|
|
5058
5147
|
resource.query((q) => q.apply(this.queryOptions.toQueryArguments()));
|
|
5059
5148
|
}
|
|
5060
|
-
return new
|
|
5149
|
+
return new ModelType(entity, { resource, annots, reset });
|
|
5061
5150
|
}
|
|
5062
|
-
asCollection(entities, { annots
|
|
5151
|
+
asCollection(entities, { annots } = {}) {
|
|
5152
|
+
const reset = annots !== undefined;
|
|
5063
5153
|
let resource = this;
|
|
5064
5154
|
const type = annots?.type || this.returnType();
|
|
5065
5155
|
if (type === undefined)
|
|
5066
5156
|
throw Error('');
|
|
5067
|
-
const
|
|
5157
|
+
const CollectionType = this.api.collectionForType(type);
|
|
5068
5158
|
let path = annots?.entitySet;
|
|
5069
5159
|
if (path !== undefined) {
|
|
5070
5160
|
resource = this.api.entitySet(path);
|
|
5071
5161
|
resource.query((q) => q.apply(this.queryOptions.toQueryArguments()));
|
|
5072
5162
|
}
|
|
5073
|
-
return new
|
|
5163
|
+
return new CollectionType(entities, { resource, annots, reset });
|
|
5074
5164
|
}
|
|
5075
5165
|
//#endregion
|
|
5076
5166
|
isSubtypeOf(other) {
|
|
@@ -5257,7 +5347,7 @@ class ODataActionResource extends ODataResource {
|
|
|
5257
5347
|
path = schema !== undefined ? schema.path() : path;
|
|
5258
5348
|
if (path === undefined)
|
|
5259
5349
|
throw new Error(`ODataActionResource: path is required`);
|
|
5260
|
-
const segment = segments.add(
|
|
5350
|
+
const segment = segments.add(PathSegment.action, path);
|
|
5261
5351
|
if (schema !== undefined)
|
|
5262
5352
|
segment.type(schema.type());
|
|
5263
5353
|
return new ODataActionResource(api, {
|
|
@@ -5325,7 +5415,7 @@ class ODataActionResource extends ODataResource {
|
|
|
5325
5415
|
* @returns Observable of the result of the action
|
|
5326
5416
|
*/
|
|
5327
5417
|
callModel(params, options = {}) {
|
|
5328
|
-
return this.call(params, { responseType: 'entity', ...options }).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots
|
|
5418
|
+
return this.call(params, { responseType: 'entity', ...options }).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots }) : null));
|
|
5329
5419
|
}
|
|
5330
5420
|
/**
|
|
5331
5421
|
* Execute the action and return the result as a entities
|
|
@@ -5343,9 +5433,18 @@ class ODataActionResource extends ODataResource {
|
|
|
5343
5433
|
* @returns Observable of the result of the action
|
|
5344
5434
|
*/
|
|
5345
5435
|
callCollection(params, options = {}) {
|
|
5346
|
-
return this.call(params, { responseType: 'entities', ...options }).pipe(map(({ entities, annots }) => entities
|
|
5347
|
-
|
|
5348
|
-
|
|
5436
|
+
return this.call(params, { responseType: 'entities', ...options }).pipe(map(({ entities, annots }) => entities ? this.asCollection(entities, { annots }) : null));
|
|
5437
|
+
}
|
|
5438
|
+
//#endregion
|
|
5439
|
+
callArraybuffer(params, { alias, ...options } = {}) {
|
|
5440
|
+
return this.call(params, {
|
|
5441
|
+
responseType: 'arraybuffer',
|
|
5442
|
+
alias,
|
|
5443
|
+
...options,
|
|
5444
|
+
});
|
|
5445
|
+
}
|
|
5446
|
+
callBlob(params, { alias, ...options } = {}) {
|
|
5447
|
+
return this.call(params, { responseType: 'blob', alias, ...options });
|
|
5349
5448
|
}
|
|
5350
5449
|
}
|
|
5351
5450
|
|
|
@@ -5363,8 +5462,13 @@ class ODataBatchRequest extends Subject {
|
|
|
5363
5462
|
constructor(request) {
|
|
5364
5463
|
super();
|
|
5365
5464
|
this.request = request;
|
|
5465
|
+
this.id = Strings.uniqueId({ prefix: 'r' });
|
|
5466
|
+
this.group = Strings.uniqueId({ prefix: 'g' });
|
|
5366
5467
|
}
|
|
5367
5468
|
toString() {
|
|
5469
|
+
return this.toLegacy();
|
|
5470
|
+
}
|
|
5471
|
+
toLegacy() {
|
|
5368
5472
|
//TODO: Relative or Absolute url ?
|
|
5369
5473
|
let res = [
|
|
5370
5474
|
`${this.request.method} ${this.request.pathWithParams} ${HTTP11}`,
|
|
@@ -5383,8 +5487,34 @@ class ODataBatchRequest extends Subject {
|
|
|
5383
5487
|
.map((key) => `${key}: ${(headers.getAll(key) || []).join(',')}`),
|
|
5384
5488
|
];
|
|
5385
5489
|
}
|
|
5490
|
+
if (this.request.method === 'GET' || this.request.method === 'DELETE') {
|
|
5491
|
+
res.push(NEWLINE);
|
|
5492
|
+
}
|
|
5493
|
+
else {
|
|
5494
|
+
res.push(`${NEWLINE}${JSON.stringify(this.request.body)}`);
|
|
5495
|
+
}
|
|
5386
5496
|
return res.join(NEWLINE);
|
|
5387
5497
|
}
|
|
5498
|
+
toJson() {
|
|
5499
|
+
//TODO: Relative or Absolute url ?
|
|
5500
|
+
let res = {
|
|
5501
|
+
id: this.id,
|
|
5502
|
+
method: this.request.method,
|
|
5503
|
+
url: this.request.pathWithParams,
|
|
5504
|
+
//'atomicityGroup': this.group
|
|
5505
|
+
//"dependsOn": ["g1", "g2", "r2"]
|
|
5506
|
+
};
|
|
5507
|
+
if (this.request.headers instanceof HttpHeaders) {
|
|
5508
|
+
let headers = this.request.headers;
|
|
5509
|
+
res['headers'] = headers
|
|
5510
|
+
.keys()
|
|
5511
|
+
.map((key) => `${key}: ${(headers.getAll(key) || []).join(',')}`);
|
|
5512
|
+
}
|
|
5513
|
+
if (!(this.request.method === 'GET' || this.request.method === 'DELETE')) {
|
|
5514
|
+
res['body'] = this.request.body;
|
|
5515
|
+
}
|
|
5516
|
+
return res;
|
|
5517
|
+
}
|
|
5388
5518
|
onLoad(response) {
|
|
5389
5519
|
if (response.ok) {
|
|
5390
5520
|
this.next(response);
|
|
@@ -5419,7 +5549,7 @@ class ODataBatchResource extends ODataResource {
|
|
|
5419
5549
|
//#region Factory
|
|
5420
5550
|
static factory(api) {
|
|
5421
5551
|
let segments = new ODataPathSegments();
|
|
5422
|
-
segments.add(
|
|
5552
|
+
segments.add(PathSegment.batch, $BATCH);
|
|
5423
5553
|
return new ODataBatchResource(api, { segments });
|
|
5424
5554
|
}
|
|
5425
5555
|
clone() {
|
|
@@ -5453,16 +5583,49 @@ class ODataBatchResource extends ODataResource {
|
|
|
5453
5583
|
// Store original requester
|
|
5454
5584
|
var handler = this.storeRequester();
|
|
5455
5585
|
// Execute the context
|
|
5456
|
-
const
|
|
5586
|
+
const result = ctx(this);
|
|
5457
5587
|
// Restore original requester
|
|
5458
5588
|
this.restoreRequester(handler);
|
|
5459
|
-
return
|
|
5589
|
+
return result;
|
|
5460
5590
|
}
|
|
5461
5591
|
send(options) {
|
|
5462
|
-
if (this.
|
|
5463
|
-
return
|
|
5592
|
+
if (this.api.options.jsonBatchFormat) {
|
|
5593
|
+
return this.sendJson(options);
|
|
5594
|
+
}
|
|
5595
|
+
else {
|
|
5596
|
+
return this.sendLegacy(options);
|
|
5464
5597
|
}
|
|
5465
|
-
|
|
5598
|
+
}
|
|
5599
|
+
sendJson(options) {
|
|
5600
|
+
const headers = Http.mergeHttpHeaders((options && options.headers) || {}, {
|
|
5601
|
+
[ODATA_VERSION]: VERSION_4_0,
|
|
5602
|
+
});
|
|
5603
|
+
return this.api
|
|
5604
|
+
.request('POST', this, {
|
|
5605
|
+
body: ODataBatchResource.buildJsonBody(this._requests),
|
|
5606
|
+
responseType: 'json',
|
|
5607
|
+
observe: 'response',
|
|
5608
|
+
headers: headers,
|
|
5609
|
+
params: options ? options.params : undefined,
|
|
5610
|
+
withCredentials: options ? options.withCredentials : undefined,
|
|
5611
|
+
})
|
|
5612
|
+
.pipe(map$1((response) => {
|
|
5613
|
+
if (this._responses == null) {
|
|
5614
|
+
this._responses = [];
|
|
5615
|
+
}
|
|
5616
|
+
this._responses = [
|
|
5617
|
+
...this._responses,
|
|
5618
|
+
...ODataBatchResource.parseJsonResponse(this._requests, response),
|
|
5619
|
+
];
|
|
5620
|
+
Arrays.zip(this._requests, this._responses).forEach((tuple) => {
|
|
5621
|
+
if (!tuple[0].isStopped)
|
|
5622
|
+
tuple[0].onLoad(tuple[1]);
|
|
5623
|
+
});
|
|
5624
|
+
return response;
|
|
5625
|
+
}));
|
|
5626
|
+
}
|
|
5627
|
+
sendLegacy(options) {
|
|
5628
|
+
const bound = Strings.uniqueId({ prefix: BATCH_PREFIX });
|
|
5466
5629
|
const headers = Http.mergeHttpHeaders((options && options.headers) || {}, {
|
|
5467
5630
|
[ODATA_VERSION]: VERSION_4_0,
|
|
5468
5631
|
[CONTENT_TYPE]: MULTIPART_MIXED_BOUNDARY + bound,
|
|
@@ -5470,7 +5633,7 @@ class ODataBatchResource extends ODataResource {
|
|
|
5470
5633
|
});
|
|
5471
5634
|
return this.api
|
|
5472
5635
|
.request('POST', this, {
|
|
5473
|
-
body: ODataBatchResource.
|
|
5636
|
+
body: ODataBatchResource.buildLegacyBody(bound, this._requests),
|
|
5474
5637
|
responseType: 'text',
|
|
5475
5638
|
observe: 'response',
|
|
5476
5639
|
headers: headers,
|
|
@@ -5483,7 +5646,7 @@ class ODataBatchResource extends ODataResource {
|
|
|
5483
5646
|
}
|
|
5484
5647
|
this._responses = [
|
|
5485
5648
|
...this._responses,
|
|
5486
|
-
...ODataBatchResource.
|
|
5649
|
+
...ODataBatchResource.parseLegacyResponse(this._requests, response),
|
|
5487
5650
|
];
|
|
5488
5651
|
Arrays.zip(this._requests, this._responses).forEach((tuple) => {
|
|
5489
5652
|
if (!tuple[0].isStopped)
|
|
@@ -5499,22 +5662,22 @@ class ODataBatchResource extends ODataResource {
|
|
|
5499
5662
|
* @returns The result of execute the context
|
|
5500
5663
|
*/
|
|
5501
5664
|
exec(ctx, options) {
|
|
5502
|
-
let
|
|
5503
|
-
|
|
5504
|
-
firstValueFrom(send$);
|
|
5505
|
-
return ctx$;
|
|
5506
|
-
//return this.send(options).pipe(switchMap(() => ctx$));
|
|
5665
|
+
let result = this.add(ctx);
|
|
5666
|
+
return this.send(options).pipe(map$1((response) => [result, response]));
|
|
5507
5667
|
}
|
|
5508
5668
|
body() {
|
|
5509
|
-
return ODataBatchResource.
|
|
5669
|
+
return ODataBatchResource.buildLegacyBody(Strings.uniqueId({ prefix: BATCH_PREFIX }), this._requests);
|
|
5510
5670
|
}
|
|
5511
|
-
|
|
5671
|
+
json() {
|
|
5672
|
+
return ODataBatchResource.buildJsonBody(this._requests);
|
|
5673
|
+
}
|
|
5674
|
+
static buildLegacyBody(batchBoundary, requests) {
|
|
5512
5675
|
let res = [];
|
|
5513
5676
|
let changesetBoundary = null;
|
|
5514
5677
|
let changesetId = 1;
|
|
5515
|
-
for (const
|
|
5678
|
+
for (const request of requests) {
|
|
5516
5679
|
// if method is GET and there is a changeset boundary open then close it
|
|
5517
|
-
if (
|
|
5680
|
+
if (request.request.method === 'GET' && changesetBoundary !== null) {
|
|
5518
5681
|
res.push(`${BOUNDARY_PREFIX_SUFFIX}${changesetBoundary}${BOUNDARY_PREFIX_SUFFIX}`);
|
|
5519
5682
|
changesetBoundary = null;
|
|
5520
5683
|
}
|
|
@@ -5523,9 +5686,9 @@ class ODataBatchResource extends ODataResource {
|
|
|
5523
5686
|
res.push(`${BOUNDARY_PREFIX_SUFFIX}${batchBoundary}`);
|
|
5524
5687
|
}
|
|
5525
5688
|
// if method is not GET and there is no changeset boundary open then open a changeset boundary
|
|
5526
|
-
if (
|
|
5689
|
+
if (request.request.method !== 'GET') {
|
|
5527
5690
|
if (changesetBoundary === null) {
|
|
5528
|
-
changesetBoundary = Strings.uniqueId(CHANGESET_PREFIX);
|
|
5691
|
+
changesetBoundary = Strings.uniqueId({ prefix: CHANGESET_PREFIX });
|
|
5529
5692
|
res.push(`${CONTENT_TYPE}: ${MULTIPART_MIXED_BOUNDARY}${changesetBoundary}`);
|
|
5530
5693
|
res.push(NEWLINE);
|
|
5531
5694
|
}
|
|
@@ -5533,17 +5696,11 @@ class ODataBatchResource extends ODataResource {
|
|
|
5533
5696
|
}
|
|
5534
5697
|
res.push(`${CONTENT_TYPE}: ${APPLICATION_HTTP}`);
|
|
5535
5698
|
res.push(`${CONTENT_TRANSFER_ENCODING}: ${BINARY}`);
|
|
5536
|
-
if (
|
|
5699
|
+
if (request.request.method !== 'GET') {
|
|
5537
5700
|
res.push(`${CONTENT_ID}: ${changesetId++}`);
|
|
5538
5701
|
}
|
|
5539
5702
|
res.push(NEWLINE);
|
|
5540
|
-
res.push(`${
|
|
5541
|
-
if (batch.request.method === 'GET' || batch.request.method === 'DELETE') {
|
|
5542
|
-
res.push(NEWLINE);
|
|
5543
|
-
}
|
|
5544
|
-
else {
|
|
5545
|
-
res.push(`${NEWLINE}${JSON.stringify(batch.request.body)}`);
|
|
5546
|
-
}
|
|
5703
|
+
res.push(`${request.toLegacy()}`);
|
|
5547
5704
|
}
|
|
5548
5705
|
if (res.length) {
|
|
5549
5706
|
if (changesetBoundary !== null) {
|
|
@@ -5554,7 +5711,12 @@ class ODataBatchResource extends ODataResource {
|
|
|
5554
5711
|
}
|
|
5555
5712
|
return res.join(NEWLINE);
|
|
5556
5713
|
}
|
|
5557
|
-
static
|
|
5714
|
+
static buildJsonBody(requests) {
|
|
5715
|
+
return {
|
|
5716
|
+
requests: requests.map((request) => request.toJson()),
|
|
5717
|
+
};
|
|
5718
|
+
}
|
|
5719
|
+
static parseLegacyResponse(requests, response) {
|
|
5558
5720
|
let chunks = [];
|
|
5559
5721
|
const contentType = response.headers.get(CONTENT_TYPE) || '';
|
|
5560
5722
|
const batchBoundary = Http.boundaryDelimiter(contentType);
|
|
@@ -5670,13 +5832,54 @@ class ODataBatchResource extends ODataResource {
|
|
|
5670
5832
|
});
|
|
5671
5833
|
});
|
|
5672
5834
|
}
|
|
5835
|
+
static parseJsonResponse(requests, response) {
|
|
5836
|
+
const responses = (response.body ? response.body : {})['responses'] ?? [];
|
|
5837
|
+
return responses.map((response, index) => {
|
|
5838
|
+
let request = requests[index].request;
|
|
5839
|
+
let code = response['status'];
|
|
5840
|
+
let headers = new HttpHeaders(response['headers']);
|
|
5841
|
+
let body = response['body'];
|
|
5842
|
+
if (code === 0) {
|
|
5843
|
+
code = !!body ? 200 : 0;
|
|
5844
|
+
}
|
|
5845
|
+
let ok = code >= 200 && code < 300;
|
|
5846
|
+
if (request.responseType === 'json' && typeof body === 'string') {
|
|
5847
|
+
const originalBody = body;
|
|
5848
|
+
body = body.replace(XSSI_PREFIX, '');
|
|
5849
|
+
try {
|
|
5850
|
+
body = body !== '' ? JSON.parse(body) : null;
|
|
5851
|
+
}
|
|
5852
|
+
catch (error) {
|
|
5853
|
+
body = originalBody;
|
|
5854
|
+
if (ok) {
|
|
5855
|
+
ok = false;
|
|
5856
|
+
body = { error, text: body };
|
|
5857
|
+
}
|
|
5858
|
+
}
|
|
5859
|
+
}
|
|
5860
|
+
return ok
|
|
5861
|
+
? new HttpResponse({
|
|
5862
|
+
body,
|
|
5863
|
+
headers,
|
|
5864
|
+
status: code,
|
|
5865
|
+
url: request.urlWithParams,
|
|
5866
|
+
})
|
|
5867
|
+
: new HttpErrorResponse({
|
|
5868
|
+
// The error in this case is the response body (error from the server).
|
|
5869
|
+
error: body,
|
|
5870
|
+
headers,
|
|
5871
|
+
status: code,
|
|
5872
|
+
url: request.urlWithParams,
|
|
5873
|
+
});
|
|
5874
|
+
});
|
|
5875
|
+
}
|
|
5673
5876
|
}
|
|
5674
5877
|
|
|
5675
5878
|
class ODataCountResource extends ODataResource {
|
|
5676
5879
|
//#region Factory
|
|
5677
5880
|
static factory(api, { segments, query, }) {
|
|
5678
|
-
segments.add(
|
|
5679
|
-
query?.keep(
|
|
5881
|
+
segments.add(PathSegment.count, $COUNT).type('Edm.Int32');
|
|
5882
|
+
query?.keep(QueryOption.filter, QueryOption.search);
|
|
5680
5883
|
return new ODataCountResource(api, { segments, query });
|
|
5681
5884
|
}
|
|
5682
5885
|
clone() {
|
|
@@ -5706,7 +5909,7 @@ class ODataFunctionResource extends ODataResource {
|
|
|
5706
5909
|
path = schema !== undefined ? schema.path() : path;
|
|
5707
5910
|
if (path === undefined)
|
|
5708
5911
|
throw new Error(`ODataActionResource: path is required`);
|
|
5709
|
-
const segment = segments.add(
|
|
5912
|
+
const segment = segments.add(PathSegment.function, path);
|
|
5710
5913
|
if (schema !== undefined)
|
|
5711
5914
|
segment.type(schema.type());
|
|
5712
5915
|
return new ODataFunctionResource(api, {
|
|
@@ -5808,7 +6011,7 @@ class ODataFunctionResource extends ODataResource {
|
|
|
5808
6011
|
responseType: 'entity',
|
|
5809
6012
|
alias,
|
|
5810
6013
|
...options,
|
|
5811
|
-
}).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots
|
|
6014
|
+
}).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots }) : null));
|
|
5812
6015
|
}
|
|
5813
6016
|
/**
|
|
5814
6017
|
* Execute the function with the given parameters and return the result as a entities
|
|
@@ -5836,16 +6039,25 @@ class ODataFunctionResource extends ODataResource {
|
|
|
5836
6039
|
responseType: 'entities',
|
|
5837
6040
|
alias,
|
|
5838
6041
|
...options,
|
|
5839
|
-
}).pipe(map(({ entities, annots }) => entities
|
|
5840
|
-
|
|
5841
|
-
|
|
6042
|
+
}).pipe(map(({ entities, annots }) => entities ? this.asCollection(entities, { annots }) : null));
|
|
6043
|
+
}
|
|
6044
|
+
//#endregion
|
|
6045
|
+
callArraybuffer(params, { alias, ...options } = {}) {
|
|
6046
|
+
return this.call(params, {
|
|
6047
|
+
responseType: 'arraybuffer',
|
|
6048
|
+
alias,
|
|
6049
|
+
...options,
|
|
6050
|
+
});
|
|
6051
|
+
}
|
|
6052
|
+
callBlob(params, { alias, ...options } = {}) {
|
|
6053
|
+
return this.call(params, { responseType: 'blob', alias, ...options });
|
|
5842
6054
|
}
|
|
5843
6055
|
}
|
|
5844
6056
|
|
|
5845
6057
|
class ODataMediaResource extends ODataResource {
|
|
5846
6058
|
//#region Factory
|
|
5847
6059
|
static factory(api, { segments, query, }) {
|
|
5848
|
-
segments.add(
|
|
6060
|
+
segments.add(PathSegment.value, $VALUE);
|
|
5849
6061
|
return new ODataMediaResource(api, { segments, query });
|
|
5850
6062
|
}
|
|
5851
6063
|
clone() {
|
|
@@ -5887,7 +6099,7 @@ class ODataValueResource extends ODataResource {
|
|
|
5887
6099
|
static factory(api, { type, schema, segments, query, }) {
|
|
5888
6100
|
const baseType = type;
|
|
5889
6101
|
const bindingType = schema?.type();
|
|
5890
|
-
const segment = segments.add(
|
|
6102
|
+
const segment = segments.add(PathSegment.value, $VALUE);
|
|
5891
6103
|
if (schema !== undefined)
|
|
5892
6104
|
segment.type(schema.type());
|
|
5893
6105
|
else if (type !== undefined)
|
|
@@ -5926,7 +6138,7 @@ class ODataValueResource extends ODataResource {
|
|
|
5926
6138
|
class ODataPropertyResource extends ODataResource {
|
|
5927
6139
|
//#region Factory
|
|
5928
6140
|
static factory(api, { path, type, schema, segments, query, }) {
|
|
5929
|
-
const segment = segments.add(
|
|
6141
|
+
const segment = segments.add(PathSegment.property, path);
|
|
5930
6142
|
if (schema !== undefined)
|
|
5931
6143
|
segment.type(schema.type());
|
|
5932
6144
|
else if (type !== undefined)
|
|
@@ -6063,7 +6275,7 @@ class ODataPropertyResource extends ODataResource {
|
|
|
6063
6275
|
* @returns The model
|
|
6064
6276
|
*/
|
|
6065
6277
|
fetchModel(options = {}) {
|
|
6066
|
-
return this.fetch({ responseType: 'entity', ...options }).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots
|
|
6278
|
+
return this.fetch({ responseType: 'entity', ...options }).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots }) : null));
|
|
6067
6279
|
}
|
|
6068
6280
|
/**
|
|
6069
6281
|
* Fetch the entities
|
|
@@ -6079,16 +6291,12 @@ class ODataPropertyResource extends ODataResource {
|
|
|
6079
6291
|
* @returns The collection
|
|
6080
6292
|
*/
|
|
6081
6293
|
fetchCollection(options = {}) {
|
|
6082
|
-
return this.fetch({ responseType: 'entities', ...options }).pipe(map(({ entities, annots }) => entities
|
|
6083
|
-
? this.asCollection(entities, { annots, reset: true })
|
|
6084
|
-
: null));
|
|
6294
|
+
return this.fetch({ responseType: 'entities', ...options }).pipe(map(({ entities, annots }) => entities ? this.asCollection(entities, { annots }) : null));
|
|
6085
6295
|
}
|
|
6086
6296
|
fetchOne(options) {
|
|
6087
6297
|
let res = this.clone();
|
|
6088
6298
|
res.query((q) => q.top(1));
|
|
6089
|
-
return res
|
|
6090
|
-
.fetch({ responseType: 'entities', ...options })
|
|
6091
|
-
.pipe(map(({ entities, annots }) => ({
|
|
6299
|
+
return res.fetch({ responseType: 'entities', ...options }).pipe(map(({ entities, annots }) => ({
|
|
6092
6300
|
entity: entities !== null ? entities[0] || null : null,
|
|
6093
6301
|
annots,
|
|
6094
6302
|
})));
|
|
@@ -6131,7 +6339,7 @@ class ODataPropertyResource extends ODataResource {
|
|
|
6131
6339
|
class ODataReferenceResource extends ODataResource {
|
|
6132
6340
|
//#region Factory
|
|
6133
6341
|
static factory(api, { segments, query, }) {
|
|
6134
|
-
segments.add(
|
|
6342
|
+
segments.add(PathSegment.reference, $REF);
|
|
6135
6343
|
query?.clear();
|
|
6136
6344
|
return new ODataReferenceResource(api, { segments, query });
|
|
6137
6345
|
}
|
|
@@ -6220,12 +6428,12 @@ class ODataReferenceResource extends ODataResource {
|
|
|
6220
6428
|
class ODataNavigationPropertyResource extends ODataResource {
|
|
6221
6429
|
//#region Factory
|
|
6222
6430
|
static factory(api, { path, type, schema, segments, query, }) {
|
|
6223
|
-
const segment = segments.add(
|
|
6431
|
+
const segment = segments.add(PathSegment.navigationProperty, path);
|
|
6224
6432
|
if (schema !== undefined)
|
|
6225
6433
|
segment.type(schema.type());
|
|
6226
6434
|
else if (type !== undefined)
|
|
6227
6435
|
segment.type(type);
|
|
6228
|
-
query?.keep(
|
|
6436
|
+
query?.keep(QueryOption.format);
|
|
6229
6437
|
return new ODataNavigationPropertyResource(api, {
|
|
6230
6438
|
segments,
|
|
6231
6439
|
query,
|
|
@@ -6314,7 +6522,7 @@ class ODataNavigationPropertyResource extends ODataResource {
|
|
|
6314
6522
|
!castSchema.isSubtypeOf(baseSchema))
|
|
6315
6523
|
throw new Error(`Cannot cast to ${type}`);
|
|
6316
6524
|
const segments = this.cloneSegments();
|
|
6317
|
-
segments.add(
|
|
6525
|
+
segments.add(PathSegment.type, type).type(type);
|
|
6318
6526
|
return new ODataNavigationPropertyResource(this.api, {
|
|
6319
6527
|
segments,
|
|
6320
6528
|
schema: castSchema,
|
|
@@ -6393,7 +6601,7 @@ class ODataNavigationPropertyResource extends ODataResource {
|
|
|
6393
6601
|
* @returns The model
|
|
6394
6602
|
*/
|
|
6395
6603
|
fetchModel(options = {}) {
|
|
6396
|
-
return this.fetch({ responseType: 'entity', ...options }).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots
|
|
6604
|
+
return this.fetch({ responseType: 'entity', ...options }).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots }) : null));
|
|
6397
6605
|
}
|
|
6398
6606
|
/**
|
|
6399
6607
|
* Fetch entities
|
|
@@ -6409,9 +6617,7 @@ class ODataNavigationPropertyResource extends ODataResource {
|
|
|
6409
6617
|
* @returns The collection
|
|
6410
6618
|
*/
|
|
6411
6619
|
fetchCollection(options = {}) {
|
|
6412
|
-
return this.fetch({ responseType: 'entities', ...options }).pipe(map(({ entities, annots }) => entities
|
|
6413
|
-
? this.asCollection(entities, { annots, reset: true })
|
|
6414
|
-
: null));
|
|
6620
|
+
return this.fetch({ responseType: 'entities', ...options }).pipe(map(({ entities, annots }) => entities ? this.asCollection(entities, { annots }) : null));
|
|
6415
6621
|
}
|
|
6416
6622
|
/**
|
|
6417
6623
|
* Fetch all entities
|
|
@@ -6458,7 +6664,7 @@ class ODataNavigationPropertyResource extends ODataResource {
|
|
|
6458
6664
|
class ODataEntityResource extends ODataResource {
|
|
6459
6665
|
//#region Factory
|
|
6460
6666
|
static factory(api, { schema, segments, query, }) {
|
|
6461
|
-
query?.keep(
|
|
6667
|
+
query?.keep(QueryOption.expand, QueryOption.select, QueryOption.format);
|
|
6462
6668
|
return new ODataEntityResource(api, { segments, query, schema });
|
|
6463
6669
|
}
|
|
6464
6670
|
clone() {
|
|
@@ -6505,7 +6711,7 @@ class ODataEntityResource extends ODataResource {
|
|
|
6505
6711
|
!castSchema.isSubtypeOf(baseSchema))
|
|
6506
6712
|
throw new Error(`cast: Cannot cast to ${type}`);
|
|
6507
6713
|
const segments = this.cloneSegments();
|
|
6508
|
-
segments.add(
|
|
6714
|
+
segments.add(PathSegment.type, type).type(type);
|
|
6509
6715
|
return new ODataEntityResource(this.api, {
|
|
6510
6716
|
segments,
|
|
6511
6717
|
schema: castSchema,
|
|
@@ -6551,7 +6757,7 @@ class ODataEntityResource extends ODataResource {
|
|
|
6551
6757
|
return this.fetch(options).pipe(map(({ entity }) => entity));
|
|
6552
6758
|
}
|
|
6553
6759
|
fetchModel(options) {
|
|
6554
|
-
return this.fetch(options).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots
|
|
6760
|
+
return this.fetch(options).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots }) : null));
|
|
6555
6761
|
}
|
|
6556
6762
|
}
|
|
6557
6763
|
|
|
@@ -6559,7 +6765,7 @@ class ODataEntitySetResource extends ODataResource {
|
|
|
6559
6765
|
//#region Factory
|
|
6560
6766
|
static factory(api, { path, schema, query, }) {
|
|
6561
6767
|
const segments = new ODataPathSegments();
|
|
6562
|
-
const segment = segments.add(
|
|
6768
|
+
const segment = segments.add(PathSegment.entitySet, path);
|
|
6563
6769
|
if (schema !== undefined)
|
|
6564
6770
|
segment.type(schema.type());
|
|
6565
6771
|
return new ODataEntitySetResource(api, { segments, query, schema });
|
|
@@ -6599,7 +6805,7 @@ class ODataEntitySetResource extends ODataResource {
|
|
|
6599
6805
|
!castSchema.isSubtypeOf(baseSchema))
|
|
6600
6806
|
throw new Error(`Cannot cast to ${type}`);
|
|
6601
6807
|
const segments = this.cloneSegments();
|
|
6602
|
-
segments.add(
|
|
6808
|
+
segments.add(PathSegment.type, type).type(type);
|
|
6603
6809
|
return new ODataEntitySetResource(this.api, {
|
|
6604
6810
|
segments,
|
|
6605
6811
|
schema: castSchema,
|
|
@@ -6659,9 +6865,7 @@ class ODataEntitySetResource extends ODataResource {
|
|
|
6659
6865
|
return this.fetch(options).pipe(map(({ entities }) => entities));
|
|
6660
6866
|
}
|
|
6661
6867
|
fetchCollection(options) {
|
|
6662
|
-
return this.fetch(options).pipe(map(({ entities, annots }) => entities
|
|
6663
|
-
? this.asCollection(entities, { annots, reset: true })
|
|
6664
|
-
: null));
|
|
6868
|
+
return this.fetch(options).pipe(map(({ entities, annots }) => entities ? this.asCollection(entities, { annots }) : null));
|
|
6665
6869
|
}
|
|
6666
6870
|
}
|
|
6667
6871
|
|
|
@@ -7829,7 +8033,7 @@ class ODataMetadataResource extends ODataResource {
|
|
|
7829
8033
|
//#region Factory
|
|
7830
8034
|
static factory(api) {
|
|
7831
8035
|
let segments = new ODataPathSegments();
|
|
7832
|
-
segments.add(
|
|
8036
|
+
segments.add(PathSegment.metadata, $METADATA);
|
|
7833
8037
|
return new ODataMetadataResource(api, segments);
|
|
7834
8038
|
}
|
|
7835
8039
|
clone() {
|
|
@@ -7851,7 +8055,7 @@ class ODataSingletonResource extends ODataResource {
|
|
|
7851
8055
|
//#region Factory
|
|
7852
8056
|
static factory(api, { path, schema, query, }) {
|
|
7853
8057
|
const segments = new ODataPathSegments();
|
|
7854
|
-
const segment = segments.add(
|
|
8058
|
+
const segment = segments.add(PathSegment.singleton, path);
|
|
7855
8059
|
if (schema !== undefined)
|
|
7856
8060
|
segment.type(schema.type());
|
|
7857
8061
|
return new ODataSingletonResource(api, { segments, query, schema });
|
|
@@ -7961,7 +8165,7 @@ class ODataSingletonResource extends ODataResource {
|
|
|
7961
8165
|
* @returns Observable of the entity.
|
|
7962
8166
|
*/
|
|
7963
8167
|
fetchModel(options) {
|
|
7964
|
-
return this.fetch(options).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots
|
|
8168
|
+
return this.fetch(options).pipe(map(({ entity, annots }) => entity ? this.asModel(entity, { annots }) : null));
|
|
7965
8169
|
}
|
|
7966
8170
|
}
|
|
7967
8171
|
|
|
@@ -8303,28 +8507,27 @@ class ODataModelField {
|
|
|
8303
8507
|
throw Error(`No Collection type for ${this.name}`);
|
|
8304
8508
|
return new Collection((value || []), {
|
|
8305
8509
|
annots: annots,
|
|
8306
|
-
parent: [parent, this],
|
|
8307
8510
|
reset,
|
|
8511
|
+
parent: [parent, this],
|
|
8308
8512
|
});
|
|
8309
8513
|
}
|
|
8310
8514
|
}
|
|
8311
8515
|
class ODataModelOptions {
|
|
8312
8516
|
constructor({ options, schema, }) {
|
|
8517
|
+
this._fields = [];
|
|
8313
8518
|
this.children = [];
|
|
8519
|
+
this.tsToEdm = {
|
|
8520
|
+
string: EdmType.String,
|
|
8521
|
+
number: EdmType.Int32,
|
|
8522
|
+
bigint: EdmType.Int64,
|
|
8523
|
+
boolean: EdmType.Boolean,
|
|
8524
|
+
};
|
|
8314
8525
|
this.name = schema.name;
|
|
8315
8526
|
this.base = schema.base;
|
|
8316
8527
|
this.open = schema.open;
|
|
8317
8528
|
this.schema = schema;
|
|
8318
8529
|
this.cid = options?.cid || CID_FIELD_NAME;
|
|
8319
|
-
|
|
8320
|
-
const { field, ...opts } = options;
|
|
8321
|
-
if (field === undefined || name === undefined)
|
|
8322
|
-
throw new Error('Model Properties need name and field');
|
|
8323
|
-
const parser = this.schema.field(field);
|
|
8324
|
-
if (parser === undefined)
|
|
8325
|
-
throw new Error(`No parser for ${field} with name = ${name}`);
|
|
8326
|
-
return new ODataModelField(this, { name, field, parser, ...opts });
|
|
8327
|
-
});
|
|
8530
|
+
Object.entries(options.fields).forEach(([name, options]) => this.addField(name, options));
|
|
8328
8531
|
}
|
|
8329
8532
|
get api() {
|
|
8330
8533
|
return this.schema.api;
|
|
@@ -8332,6 +8535,9 @@ class ODataModelOptions {
|
|
|
8332
8535
|
type({ alias = false } = {}) {
|
|
8333
8536
|
return this.schema.type({ alias });
|
|
8334
8537
|
}
|
|
8538
|
+
isOpenType() {
|
|
8539
|
+
return this.schema.isOpenType();
|
|
8540
|
+
}
|
|
8335
8541
|
isTypeOf(type) {
|
|
8336
8542
|
return this.schema.isTypeOf(type);
|
|
8337
8543
|
}
|
|
@@ -8389,15 +8595,57 @@ class ODataModelOptions {
|
|
|
8389
8595
|
];
|
|
8390
8596
|
}
|
|
8391
8597
|
field(name) {
|
|
8392
|
-
let field = this.
|
|
8393
|
-
include_parents: true,
|
|
8394
|
-
include_navigation: true,
|
|
8395
|
-
}).find((modelField) => modelField.name === name || modelField.field === name);
|
|
8598
|
+
let field = this.findField(name);
|
|
8396
8599
|
//Throw error if not found
|
|
8397
8600
|
if (field === undefined)
|
|
8398
8601
|
throw new Error(`No field with name ${name}`);
|
|
8399
8602
|
return field;
|
|
8400
8603
|
}
|
|
8604
|
+
findField(name) {
|
|
8605
|
+
return this.fields({
|
|
8606
|
+
include_parents: true,
|
|
8607
|
+
include_navigation: true,
|
|
8608
|
+
}).find((modelField) => modelField.name === name || modelField.field === name);
|
|
8609
|
+
}
|
|
8610
|
+
addField(name, options) {
|
|
8611
|
+
const { field, parser, ...opts } = options;
|
|
8612
|
+
if (field === undefined || name === undefined)
|
|
8613
|
+
throw new Error('Model Properties need name and field');
|
|
8614
|
+
const fieldParser = parser ?? this.schema.field(field);
|
|
8615
|
+
if (fieldParser === undefined)
|
|
8616
|
+
throw new Error(`No parser for ${field} with name = ${name}`);
|
|
8617
|
+
const modelField = new ODataModelField(this, {
|
|
8618
|
+
name,
|
|
8619
|
+
field,
|
|
8620
|
+
parser: fieldParser,
|
|
8621
|
+
...opts,
|
|
8622
|
+
});
|
|
8623
|
+
this._fields.push(modelField);
|
|
8624
|
+
return modelField;
|
|
8625
|
+
}
|
|
8626
|
+
modelFieldFactory(self, name, type) {
|
|
8627
|
+
const structuredFieldParser = this.schema.addField(name, { type });
|
|
8628
|
+
structuredFieldParser.configure({
|
|
8629
|
+
findOptionsForType: (type) => this.api.findOptionsForType(type),
|
|
8630
|
+
parserForType: (type) => this.api.parserForType(type),
|
|
8631
|
+
options: this.api.options,
|
|
8632
|
+
});
|
|
8633
|
+
const modelField = this.addField(name, {
|
|
8634
|
+
field: name,
|
|
8635
|
+
parser: structuredFieldParser,
|
|
8636
|
+
});
|
|
8637
|
+
modelField.configure({
|
|
8638
|
+
findOptionsForType: (type) => this.api.findOptionsForType(type),
|
|
8639
|
+
options: this.api.options,
|
|
8640
|
+
concurrency: false,
|
|
8641
|
+
});
|
|
8642
|
+
Object.defineProperty(self, modelField.name, {
|
|
8643
|
+
configurable: true,
|
|
8644
|
+
get: () => this.get(self, modelField),
|
|
8645
|
+
set: (value) => this.set(self, modelField, value),
|
|
8646
|
+
});
|
|
8647
|
+
return modelField;
|
|
8648
|
+
}
|
|
8401
8649
|
attach(self, resource) {
|
|
8402
8650
|
if (self._resource !== null &&
|
|
8403
8651
|
resource.type() !== self._resource.type() &&
|
|
@@ -8505,8 +8753,8 @@ class ODataModelOptions {
|
|
|
8505
8753
|
for (let field of fields) {
|
|
8506
8754
|
Object.defineProperty(self, field.name, {
|
|
8507
8755
|
configurable: true,
|
|
8508
|
-
get: () => this.
|
|
8509
|
-
set: (value) => this.
|
|
8756
|
+
get: () => this.get(self, field),
|
|
8757
|
+
set: (value) => this.set(self, field, value),
|
|
8510
8758
|
});
|
|
8511
8759
|
}
|
|
8512
8760
|
}
|
|
@@ -8631,16 +8879,11 @@ class ODataModelOptions {
|
|
|
8631
8879
|
hasKey(self) {
|
|
8632
8880
|
return this.resolveKey(self) !== undefined;
|
|
8633
8881
|
}
|
|
8634
|
-
|
|
8635
|
-
// Build new resource
|
|
8636
|
-
const query = self._resource?.cloneQuery();
|
|
8637
|
-
let resource = this.modelResourceFactory(query);
|
|
8638
|
-
if (resource === undefined)
|
|
8639
|
-
throw new Error('Model does not have associated Entity endpoint');
|
|
8882
|
+
withResource(self, resource, ctx) {
|
|
8640
8883
|
// Push
|
|
8641
8884
|
self.pushResource(resource);
|
|
8642
8885
|
// Execute function
|
|
8643
|
-
const result =
|
|
8886
|
+
const result = ctx(self);
|
|
8644
8887
|
if (result instanceof Observable) {
|
|
8645
8888
|
return result.pipe(finalize(() => {
|
|
8646
8889
|
// Pop
|
|
@@ -8653,6 +8896,14 @@ class ODataModelOptions {
|
|
|
8653
8896
|
return result;
|
|
8654
8897
|
}
|
|
8655
8898
|
}
|
|
8899
|
+
asEntity(self, ctx) {
|
|
8900
|
+
// Build new resource
|
|
8901
|
+
const query = self._resource?.cloneQuery();
|
|
8902
|
+
let resource = this.modelResourceFactory(query);
|
|
8903
|
+
if (resource === undefined)
|
|
8904
|
+
throw new Error('Model does not have associated Entity endpoint');
|
|
8905
|
+
return this.withResource(self, resource, ctx);
|
|
8906
|
+
}
|
|
8656
8907
|
toEntity(self, { client_id = false, include_navigation = false, include_concurrency = false, include_computed = false, include_key = true, include_non_field = false, changes_only = false, field_mapping = false, chain = [], } = {}) {
|
|
8657
8908
|
let attrs = self.attributes({
|
|
8658
8909
|
changes_only,
|
|
@@ -8687,6 +8938,7 @@ class ODataModelOptions {
|
|
|
8687
8938
|
client_id,
|
|
8688
8939
|
include_navigation,
|
|
8689
8940
|
include_concurrency,
|
|
8941
|
+
include_computed,
|
|
8690
8942
|
include_non_field,
|
|
8691
8943
|
field_mapping,
|
|
8692
8944
|
changes_only: changesOnly,
|
|
@@ -8702,6 +8954,7 @@ class ODataModelOptions {
|
|
|
8702
8954
|
client_id,
|
|
8703
8955
|
include_navigation,
|
|
8704
8956
|
include_concurrency,
|
|
8957
|
+
include_computed,
|
|
8705
8958
|
include_non_field,
|
|
8706
8959
|
field_mapping,
|
|
8707
8960
|
changes_only: changesOnly,
|
|
@@ -8823,7 +9076,7 @@ class ODataModelOptions {
|
|
|
8823
9076
|
}).find((field) => (self._reset && field.field === key) || field.name === key);
|
|
8824
9077
|
if (field !== undefined) {
|
|
8825
9078
|
// Delegated to private setter
|
|
8826
|
-
if (this.
|
|
9079
|
+
if (this.set(self, field, value)) {
|
|
8827
9080
|
changes.push(field.name);
|
|
8828
9081
|
}
|
|
8829
9082
|
}
|
|
@@ -8851,7 +9104,7 @@ class ODataModelOptions {
|
|
|
8851
9104
|
static isCollection(obj) {
|
|
8852
9105
|
return Types.rawType(obj) === 'Collection';
|
|
8853
9106
|
}
|
|
8854
|
-
|
|
9107
|
+
_updateCollection(self, field, collection, value) {
|
|
8855
9108
|
collection._annotations = field.annotationsFactory(self.annots());
|
|
8856
9109
|
collection.assign(value, {
|
|
8857
9110
|
reset: self._reset,
|
|
@@ -8860,7 +9113,7 @@ class ODataModelOptions {
|
|
|
8860
9113
|
});
|
|
8861
9114
|
return collection.hasChanged();
|
|
8862
9115
|
}
|
|
8863
|
-
|
|
9116
|
+
_updateModel(self, field, model, value) {
|
|
8864
9117
|
model._annotations = field.annotationsFactory(self.annots());
|
|
8865
9118
|
model.assign(value, {
|
|
8866
9119
|
reset: self._reset,
|
|
@@ -8869,13 +9122,14 @@ class ODataModelOptions {
|
|
|
8869
9122
|
});
|
|
8870
9123
|
return model.hasChanged();
|
|
8871
9124
|
}
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
9125
|
+
get(self, field) {
|
|
9126
|
+
const modelField = field instanceof ODataModelField ? field : this.findField(field);
|
|
9127
|
+
if (modelField !== undefined && modelField.isStructuredType()) {
|
|
9128
|
+
const relation = self._relations.get(modelField.name);
|
|
9129
|
+
if (modelField.navigation &&
|
|
8876
9130
|
(relation?.model === null || ODataModelOptions.isModel(relation?.model))) {
|
|
8877
9131
|
// Check for reference
|
|
8878
|
-
const referenced = this.resolveReferenced(self,
|
|
9132
|
+
const referenced = this.resolveReferenced(self, modelField);
|
|
8879
9133
|
if (relation?.model !== null &&
|
|
8880
9134
|
referenced !== null &&
|
|
8881
9135
|
referenced !== undefined) {
|
|
@@ -8899,7 +9153,7 @@ class ODataModelOptions {
|
|
|
8899
9153
|
return this.attributes(self, {
|
|
8900
9154
|
include_concurrency: true,
|
|
8901
9155
|
include_computed: true,
|
|
8902
|
-
})[
|
|
9156
|
+
})[modelField !== undefined ? modelField.name : field];
|
|
8903
9157
|
}
|
|
8904
9158
|
}
|
|
8905
9159
|
_setStructured(self, field, value) {
|
|
@@ -8940,7 +9194,7 @@ class ODataModelOptions {
|
|
|
8940
9194
|
}
|
|
8941
9195
|
else if (Types.isArray(value)) {
|
|
8942
9196
|
// New value is array
|
|
8943
|
-
changed = this.
|
|
9197
|
+
changed = this._updateCollection(self, field, currentCollection, value);
|
|
8944
9198
|
}
|
|
8945
9199
|
}
|
|
8946
9200
|
else if (ODataModelOptions.isModel(current)) {
|
|
@@ -8962,7 +9216,7 @@ class ODataModelOptions {
|
|
|
8962
9216
|
}
|
|
8963
9217
|
}
|
|
8964
9218
|
else if (Types.isPlainObject(value)) {
|
|
8965
|
-
changed = this.
|
|
9219
|
+
changed = this._updateModel(self, field, currentModel, value);
|
|
8966
9220
|
}
|
|
8967
9221
|
}
|
|
8968
9222
|
else {
|
|
@@ -9039,10 +9293,19 @@ class ODataModelOptions {
|
|
|
9039
9293
|
}
|
|
9040
9294
|
return changed;
|
|
9041
9295
|
}
|
|
9042
|
-
|
|
9043
|
-
|
|
9044
|
-
|
|
9045
|
-
|
|
9296
|
+
set(self, field, value, { type } = {}) {
|
|
9297
|
+
let modelField = field instanceof ODataModelField ? field : this.findField(field);
|
|
9298
|
+
if (modelField === undefined &&
|
|
9299
|
+
this.isOpenType() &&
|
|
9300
|
+
typeof field === 'string') {
|
|
9301
|
+
type = type ?? this.tsToEdm[typeof value] ?? '';
|
|
9302
|
+
modelField = this.modelFieldFactory(self, field, type);
|
|
9303
|
+
}
|
|
9304
|
+
if (modelField === undefined)
|
|
9305
|
+
throw new Error(`No field with name ${field}`);
|
|
9306
|
+
return modelField.isStructuredType()
|
|
9307
|
+
? this._setStructured(self, modelField, value)
|
|
9308
|
+
: this._setValue(self, modelField, value, modelField.isKey());
|
|
9046
9309
|
}
|
|
9047
9310
|
_unlink(self, relation) {
|
|
9048
9311
|
if (relation.subscription !== undefined) {
|
|
@@ -9153,8 +9416,9 @@ class ODataCollection {
|
|
|
9153
9416
|
!this._resource.isSubtypeOf(resource))
|
|
9154
9417
|
throw new Error(`attach: Can't reattach ${this._resource.type()} to ${resource.type()}`);
|
|
9155
9418
|
this._entries.forEach(({ model }) => {
|
|
9156
|
-
const
|
|
9157
|
-
|
|
9419
|
+
const modelResource = this._model.meta.modelResourceFactory(resource.cloneQuery());
|
|
9420
|
+
if (modelResource !== undefined)
|
|
9421
|
+
model.attach(modelResource);
|
|
9158
9422
|
});
|
|
9159
9423
|
const current = this._resource;
|
|
9160
9424
|
if (current === null || !current.isEqualTo(resource)) {
|
|
@@ -9166,16 +9430,11 @@ class ODataCollection {
|
|
|
9166
9430
|
}));
|
|
9167
9431
|
}
|
|
9168
9432
|
}
|
|
9169
|
-
|
|
9170
|
-
// Build new resource
|
|
9171
|
-
const query = this._resource?.cloneQuery();
|
|
9172
|
-
let resource = this._model.meta.collectionResourceFactory(query);
|
|
9173
|
-
if (resource === undefined)
|
|
9174
|
-
throw new Error('asEntitySet: Collection does not have associated EntitySet endpoint');
|
|
9433
|
+
withResource(resource, ctx) {
|
|
9175
9434
|
// Push
|
|
9176
9435
|
this.pushResource(resource);
|
|
9177
9436
|
// Execute
|
|
9178
|
-
const result =
|
|
9437
|
+
const result = ctx(this);
|
|
9179
9438
|
if (result instanceof Observable) {
|
|
9180
9439
|
return result.pipe(finalize(() => this.popResource()));
|
|
9181
9440
|
}
|
|
@@ -9185,6 +9444,14 @@ class ODataCollection {
|
|
|
9185
9444
|
return result;
|
|
9186
9445
|
}
|
|
9187
9446
|
}
|
|
9447
|
+
asEntitySet(ctx) {
|
|
9448
|
+
// Build new resource
|
|
9449
|
+
const query = this._resource?.cloneQuery();
|
|
9450
|
+
let resource = this._model.meta.collectionResourceFactory(query);
|
|
9451
|
+
if (resource === undefined)
|
|
9452
|
+
throw new Error('asEntitySet: Collection does not have associated EntitySet endpoint');
|
|
9453
|
+
return this.withResource(resource, ctx);
|
|
9454
|
+
}
|
|
9188
9455
|
annots() {
|
|
9189
9456
|
return this._annotations;
|
|
9190
9457
|
}
|
|
@@ -9236,22 +9503,23 @@ class ODataCollection {
|
|
|
9236
9503
|
annots: this.annots(),
|
|
9237
9504
|
});
|
|
9238
9505
|
}
|
|
9239
|
-
_request(obs
|
|
9506
|
+
_request(obs$, { remove } = {}) {
|
|
9240
9507
|
this.events$.emit(new ODataModelEvent('request', {
|
|
9241
9508
|
collection: this,
|
|
9242
9509
|
options: { observable: obs$ },
|
|
9243
9510
|
}));
|
|
9244
9511
|
return obs$.pipe(map(({ entities, annots }) => {
|
|
9245
9512
|
this._annotations = annots;
|
|
9246
|
-
|
|
9513
|
+
const models = (entities || []).map((entity) => this.modelFactory(entity, { reset: true }));
|
|
9514
|
+
this.assign(models, { reset: true, remove });
|
|
9247
9515
|
this.events$.emit(new ODataModelEvent('sync', {
|
|
9248
9516
|
collection: this,
|
|
9249
|
-
options: { entities, annots },
|
|
9517
|
+
options: { models, entities, annots },
|
|
9250
9518
|
}));
|
|
9251
|
-
return
|
|
9519
|
+
return models;
|
|
9252
9520
|
}));
|
|
9253
9521
|
}
|
|
9254
|
-
fetch({ withCount, ...options } = {}) {
|
|
9522
|
+
fetch({ withCount, remove, ...options } = {}) {
|
|
9255
9523
|
const resource = this.resource();
|
|
9256
9524
|
const obs$ = resource instanceof ODataEntitySetResource
|
|
9257
9525
|
? resource.fetch({ withCount, ...options })
|
|
@@ -9260,20 +9528,21 @@ class ODataCollection {
|
|
|
9260
9528
|
withCount,
|
|
9261
9529
|
...options,
|
|
9262
9530
|
});
|
|
9263
|
-
return this._request(obs
|
|
9531
|
+
return this._request(obs$, { remove });
|
|
9264
9532
|
}
|
|
9265
|
-
fetchAll({ withCount, ...options } = {}) {
|
|
9533
|
+
fetchAll({ withCount, remove, ...options } = {}) {
|
|
9266
9534
|
const resource = this.resource();
|
|
9267
9535
|
const obs$ = resource.fetchAll({ withCount, ...options });
|
|
9268
|
-
return this._request(obs
|
|
9536
|
+
return this._request(obs$, { remove });
|
|
9269
9537
|
}
|
|
9270
|
-
fetchMany(top, { withCount, ...options } = {}) {
|
|
9538
|
+
fetchMany(top, { withCount, remove, ...options } = {}) {
|
|
9271
9539
|
const resource = this.resource();
|
|
9540
|
+
resource.query((q) => remove || this.length == 0 ? q.skip().clear() : q.skip(this.length));
|
|
9272
9541
|
const obs$ = resource.fetchMany(top, { withCount, ...options });
|
|
9273
|
-
return this._request(obs
|
|
9542
|
+
return this._request(obs$, { remove: remove ?? false });
|
|
9274
9543
|
}
|
|
9275
|
-
fetchOne({ withCount, ...options } = {}) {
|
|
9276
|
-
return this.fetchMany(1, { withCount, ...options }).pipe(map((
|
|
9544
|
+
fetchOne({ withCount, remove, ...options } = {}) {
|
|
9545
|
+
return this.fetchMany(1, { withCount, remove, ...options }).pipe(map((models) => models[0]));
|
|
9277
9546
|
}
|
|
9278
9547
|
/**
|
|
9279
9548
|
* Save all models in the collection
|
|
@@ -9492,18 +9761,33 @@ class ODataCollection {
|
|
|
9492
9761
|
return of(this.removeModel(model, { silent }));
|
|
9493
9762
|
}
|
|
9494
9763
|
}
|
|
9764
|
+
_moveModel(model, position) {
|
|
9765
|
+
const key = model.key();
|
|
9766
|
+
let entry = this._findEntry({
|
|
9767
|
+
model,
|
|
9768
|
+
key,
|
|
9769
|
+
cid: model[this._model.meta.cid],
|
|
9770
|
+
});
|
|
9771
|
+
if (entry === undefined || entry.state === ODataModelState.Removed) {
|
|
9772
|
+
return model;
|
|
9773
|
+
}
|
|
9774
|
+
// Now remove
|
|
9775
|
+
const index = this._entries.indexOf(entry);
|
|
9776
|
+
this._entries.splice(index, 1);
|
|
9777
|
+
this._entries.splice(position, 0, entry);
|
|
9778
|
+
return entry.model;
|
|
9779
|
+
}
|
|
9495
9780
|
create(attrs = {}, { silent = false, server = true, } = {}) {
|
|
9496
9781
|
const model = this.modelFactory(attrs);
|
|
9497
9782
|
return (model.isValid() && server ? model.save() : of(model)).pipe(switchMap((model) => this.add(model, { silent, server })), map(() => model));
|
|
9498
9783
|
}
|
|
9499
|
-
set(path, value) {
|
|
9500
|
-
const Model = this._model;
|
|
9784
|
+
set(path, value, {}) {
|
|
9501
9785
|
const pathArray = (Types.isArray(path) ? path : path.match(/([^[.\]])+/g));
|
|
9502
9786
|
if (pathArray.length === 0)
|
|
9503
9787
|
return undefined;
|
|
9504
9788
|
if (pathArray.length > 1) {
|
|
9505
9789
|
const model = this._entries[Number(pathArray[0])].model;
|
|
9506
|
-
return model.set(pathArray.slice(1), value);
|
|
9790
|
+
return model.set(pathArray.slice(1), value, {});
|
|
9507
9791
|
}
|
|
9508
9792
|
if (pathArray.length === 1 && ODataModelOptions.isModel(value)) {
|
|
9509
9793
|
let toAdd = [];
|
|
@@ -9532,7 +9816,6 @@ class ODataCollection {
|
|
|
9532
9816
|
}
|
|
9533
9817
|
}
|
|
9534
9818
|
get(path) {
|
|
9535
|
-
const Model = this._model;
|
|
9536
9819
|
const pathArray = (Types.isArray(path) ? path : `${path}`.match(/([^[.\]])+/g));
|
|
9537
9820
|
if (pathArray.length === 0)
|
|
9538
9821
|
return undefined;
|
|
@@ -9542,6 +9825,16 @@ class ODataCollection {
|
|
|
9542
9825
|
}
|
|
9543
9826
|
return value;
|
|
9544
9827
|
}
|
|
9828
|
+
has(path) {
|
|
9829
|
+
const pathArray = (Types.isArray(path) ? path : `${path}`.match(/([^[.\]])+/g));
|
|
9830
|
+
if (pathArray.length === 0)
|
|
9831
|
+
return false;
|
|
9832
|
+
const value = this.models()[Number(pathArray[0])];
|
|
9833
|
+
if (pathArray.length > 1 && ODataModelOptions.isModel(value)) {
|
|
9834
|
+
return value.has(pathArray.slice(1));
|
|
9835
|
+
}
|
|
9836
|
+
return value !== undefined;
|
|
9837
|
+
}
|
|
9545
9838
|
reset({ path, silent = false, } = {}) {
|
|
9546
9839
|
let toAdd = [];
|
|
9547
9840
|
let toChange = [];
|
|
@@ -9605,8 +9898,9 @@ class ODataCollection {
|
|
|
9605
9898
|
}));
|
|
9606
9899
|
}
|
|
9607
9900
|
}
|
|
9608
|
-
assign(objects, { reset = false, reparent = false, silent = false, } = {}) {
|
|
9901
|
+
assign(objects, { remove = true, reset = false, reparent = false, silent = false, } = {}) {
|
|
9609
9902
|
const Model = this._model;
|
|
9903
|
+
const offset = remove ? 0 : this.length;
|
|
9610
9904
|
let toAdd = [];
|
|
9611
9905
|
let toChange = [];
|
|
9612
9906
|
let toRemove = [];
|
|
@@ -9614,6 +9908,7 @@ class ODataCollection {
|
|
|
9614
9908
|
let modelMap = [];
|
|
9615
9909
|
objects.forEach((obj, index) => {
|
|
9616
9910
|
const isModel = ODataModelOptions.isModel(obj);
|
|
9911
|
+
const position = index + offset;
|
|
9617
9912
|
const key = Model !== null && Model.meta ? Model.meta.resolveKey(obj) : undefined;
|
|
9618
9913
|
const cid = Model.meta.cid in obj ? obj[Model.meta.cid] : undefined;
|
|
9619
9914
|
// Try find entry
|
|
@@ -9642,38 +9937,37 @@ class ODataCollection {
|
|
|
9642
9937
|
}
|
|
9643
9938
|
// Model Change?
|
|
9644
9939
|
if (model.hasChanged())
|
|
9645
|
-
toChange.push(model);
|
|
9940
|
+
toChange.push([model, position]);
|
|
9646
9941
|
}
|
|
9647
9942
|
// Has Sort or Index Change?
|
|
9648
|
-
if (toSort.length > 0 ||
|
|
9649
|
-
toSort.push([model,
|
|
9943
|
+
if (toSort.length > 0 || position !== this.models().indexOf(model)) {
|
|
9944
|
+
toSort.push([model, position]);
|
|
9650
9945
|
}
|
|
9651
9946
|
}
|
|
9652
9947
|
else {
|
|
9653
9948
|
// Add
|
|
9654
9949
|
model = isModel
|
|
9655
9950
|
? obj
|
|
9656
|
-
: this.modelFactory(obj
|
|
9657
|
-
|
|
9658
|
-
});
|
|
9659
|
-
toAdd.push([model, index]);
|
|
9951
|
+
: this.modelFactory(obj);
|
|
9952
|
+
toAdd.push([model, position]);
|
|
9660
9953
|
}
|
|
9661
9954
|
modelMap.push(model[Model.meta.cid]);
|
|
9662
9955
|
});
|
|
9663
|
-
|
|
9664
|
-
.
|
|
9665
|
-
|
|
9666
|
-
|
|
9667
|
-
|
|
9668
|
-
|
|
9669
|
-
|
|
9956
|
+
if (remove) {
|
|
9957
|
+
this._entries.forEach((entry, position) => {
|
|
9958
|
+
if (modelMap.indexOf(entry.model[Model.meta.cid]) === -1)
|
|
9959
|
+
toRemove.push([entry.model, position]);
|
|
9960
|
+
});
|
|
9961
|
+
}
|
|
9962
|
+
// Apply remove, add and sort
|
|
9963
|
+
toRemove.forEach(([model, position]) => {
|
|
9964
|
+
this._removeModel(model, { silent, reset });
|
|
9670
9965
|
});
|
|
9671
|
-
toAdd.forEach((
|
|
9672
|
-
this._addModel(
|
|
9966
|
+
toAdd.forEach(([model, position]) => {
|
|
9967
|
+
this._addModel(model, { silent, reset, reparent, position });
|
|
9673
9968
|
});
|
|
9674
|
-
toSort.forEach((
|
|
9675
|
-
this.
|
|
9676
|
-
this._addModel(m[0], { silent: true, reset, position: m[1], reparent });
|
|
9969
|
+
toSort.forEach(([model, position]) => {
|
|
9970
|
+
this._moveModel(model, position);
|
|
9677
9971
|
});
|
|
9678
9972
|
if ((!silent &&
|
|
9679
9973
|
(toAdd.length > 0 ||
|
|
@@ -9693,9 +9987,9 @@ class ODataCollection {
|
|
|
9693
9987
|
}));
|
|
9694
9988
|
}
|
|
9695
9989
|
}
|
|
9696
|
-
query(
|
|
9990
|
+
query(ctx) {
|
|
9697
9991
|
const resource = this.resource();
|
|
9698
|
-
resource.query(
|
|
9992
|
+
resource.query(ctx);
|
|
9699
9993
|
this.attach(resource);
|
|
9700
9994
|
return this;
|
|
9701
9995
|
}
|
|
@@ -9924,7 +10218,7 @@ class ODataModel {
|
|
|
9924
10218
|
// Client Id
|
|
9925
10219
|
this[this._meta.cid] =
|
|
9926
10220
|
data[this._meta.cid] ||
|
|
9927
|
-
Strings.uniqueId(`${Klass.meta.schema.name.toLowerCase()}-`);
|
|
10221
|
+
Strings.uniqueId({ prefix: `${Klass.meta.schema.name.toLowerCase()}-` });
|
|
9928
10222
|
let attrs = this.annots().attributes(data, 'full');
|
|
9929
10223
|
let defaults = this.defaults();
|
|
9930
10224
|
this.assign(Objects.merge(defaults, attrs), {
|
|
@@ -10007,6 +10301,9 @@ class ODataModel {
|
|
|
10007
10301
|
key({ field_mapping = false, resolve = true, } = {}) {
|
|
10008
10302
|
return this._meta.resolveKey(this, { field_mapping, resolve });
|
|
10009
10303
|
}
|
|
10304
|
+
isOpenModel() {
|
|
10305
|
+
return this._meta.isOpenType();
|
|
10306
|
+
}
|
|
10010
10307
|
isParentOf(child) {
|
|
10011
10308
|
return (child !== this &&
|
|
10012
10309
|
ODataModelOptions.chain(child).some((p) => p[0] === this));
|
|
@@ -10064,29 +10361,40 @@ class ODataModel {
|
|
|
10064
10361
|
field_mapping,
|
|
10065
10362
|
});
|
|
10066
10363
|
}
|
|
10067
|
-
set(path, value) {
|
|
10364
|
+
set(path, value, { type } = {}) {
|
|
10068
10365
|
const pathArray = (Types.isArray(path) ? path : path.match(/([^[.\]])+/g));
|
|
10069
10366
|
if (pathArray.length === 0)
|
|
10070
10367
|
return undefined;
|
|
10071
10368
|
if (pathArray.length > 1) {
|
|
10072
10369
|
const model = this[pathArray[0]];
|
|
10073
|
-
return model.set(pathArray.slice(1), value);
|
|
10370
|
+
return model.set(pathArray.slice(1), value, {});
|
|
10074
10371
|
}
|
|
10075
10372
|
if (pathArray.length === 1) {
|
|
10076
|
-
return (this
|
|
10373
|
+
return this._meta.set(this, pathArray[0], value, { type });
|
|
10077
10374
|
}
|
|
10078
10375
|
}
|
|
10079
10376
|
get(path) {
|
|
10080
10377
|
const pathArray = (Types.isArray(path) ? path : path.match(/([^[.\]])+/g));
|
|
10081
10378
|
if (pathArray.length === 0)
|
|
10082
10379
|
return undefined;
|
|
10083
|
-
const value = this
|
|
10380
|
+
const value = this._meta.get(this, pathArray[0]);
|
|
10084
10381
|
if (pathArray.length > 1 &&
|
|
10085
10382
|
(value instanceof ODataModel || value instanceof ODataCollection)) {
|
|
10086
10383
|
return value.get(pathArray.slice(1));
|
|
10087
10384
|
}
|
|
10088
10385
|
return value;
|
|
10089
10386
|
}
|
|
10387
|
+
has(path) {
|
|
10388
|
+
const pathArray = (Types.isArray(path) ? path : path.match(/([^[.\]])+/g));
|
|
10389
|
+
if (pathArray.length === 0)
|
|
10390
|
+
return false;
|
|
10391
|
+
const value = this._meta.get(this, pathArray[0]);
|
|
10392
|
+
if (pathArray.length > 1 &&
|
|
10393
|
+
(value instanceof ODataModel || value instanceof ODataCollection)) {
|
|
10394
|
+
return value.has(pathArray.slice(1));
|
|
10395
|
+
}
|
|
10396
|
+
return value !== undefined;
|
|
10397
|
+
}
|
|
10090
10398
|
reset({ path, silent = false, } = {}) {
|
|
10091
10399
|
const pathArray = (path === undefined
|
|
10092
10400
|
? []
|
|
@@ -10209,10 +10517,10 @@ class ODataModel {
|
|
|
10209
10517
|
}
|
|
10210
10518
|
/**
|
|
10211
10519
|
* Create an execution context for change the internal query of a resource
|
|
10212
|
-
* @param
|
|
10520
|
+
* @param ctx Function to execute
|
|
10213
10521
|
*/
|
|
10214
|
-
query(
|
|
10215
|
-
return this._meta.query(this, this.resource(),
|
|
10522
|
+
query(ctx) {
|
|
10523
|
+
return this._meta.query(this, this.resource(), ctx);
|
|
10216
10524
|
}
|
|
10217
10525
|
/**
|
|
10218
10526
|
* Perform a check on the internal state of the model and return true if the model is changed.
|
|
@@ -10225,6 +10533,9 @@ class ODataModel {
|
|
|
10225
10533
|
isNew() {
|
|
10226
10534
|
return !this._meta.hasKey(this);
|
|
10227
10535
|
}
|
|
10536
|
+
withResource(resource, ctx) {
|
|
10537
|
+
return this._meta.withResource(this, resource, ctx);
|
|
10538
|
+
}
|
|
10228
10539
|
/**
|
|
10229
10540
|
* Create an execution context for a given function, where the model is bound to its entity endpoint
|
|
10230
10541
|
* @param ctx Context function
|
|
@@ -10245,6 +10556,10 @@ class ODataModel {
|
|
|
10245
10556
|
return func.callModel(params, options);
|
|
10246
10557
|
case 'collection':
|
|
10247
10558
|
return func.callCollection(params, options);
|
|
10559
|
+
case 'blob':
|
|
10560
|
+
return func.callBlob(params, options);
|
|
10561
|
+
case 'arraybuffer':
|
|
10562
|
+
return func.callArraybuffer(params, options);
|
|
10248
10563
|
default:
|
|
10249
10564
|
return func.call(params, { responseType, ...options });
|
|
10250
10565
|
}
|
|
@@ -10261,12 +10576,17 @@ class ODataModel {
|
|
|
10261
10576
|
return action.callModel(params, options);
|
|
10262
10577
|
case 'collection':
|
|
10263
10578
|
return action.callCollection(params, options);
|
|
10579
|
+
case 'blob':
|
|
10580
|
+
return action.callBlob(params, options);
|
|
10581
|
+
case 'arraybuffer':
|
|
10582
|
+
return action.callArraybuffer(params, options);
|
|
10264
10583
|
default:
|
|
10265
10584
|
return action.call(params, { responseType, ...options });
|
|
10266
10585
|
}
|
|
10267
10586
|
}
|
|
10268
10587
|
// Cast
|
|
10269
10588
|
cast(type) {
|
|
10589
|
+
//: ODataModel<S> {
|
|
10270
10590
|
const resource = this.resource();
|
|
10271
10591
|
if (!(resource instanceof ODataEntityResource))
|
|
10272
10592
|
throw new Error(`cast: Can't cast to derived model without ODataEntityResource`);
|
|
@@ -10397,9 +10717,10 @@ class ODataApiOptions {
|
|
|
10397
10717
|
this.accept = config.accept;
|
|
10398
10718
|
Object.assign(this.etag, config.etag || {});
|
|
10399
10719
|
this.prefer = config.prefer;
|
|
10400
|
-
this.deleteRefBy = config.deleteRefBy
|
|
10720
|
+
this.deleteRefBy = config.deleteRefBy ?? 'path';
|
|
10401
10721
|
this.nonParenthesisForEmptyParameterFunction =
|
|
10402
|
-
config.nonParenthesisForEmptyParameterFunction
|
|
10722
|
+
config.nonParenthesisForEmptyParameterFunction ?? false;
|
|
10723
|
+
this.jsonBatchFormat = config.jsonBatchFormat ?? false;
|
|
10403
10724
|
}
|
|
10404
10725
|
get parserOptions() {
|
|
10405
10726
|
return {
|
|
@@ -10468,20 +10789,20 @@ class ODataApi {
|
|
|
10468
10789
|
const segments = new ODataPathSegments(json.segments);
|
|
10469
10790
|
const query = new ODataQueryOptions(json.options);
|
|
10470
10791
|
switch (segments.last()?.name) {
|
|
10471
|
-
case
|
|
10792
|
+
case PathSegment.entitySet:
|
|
10472
10793
|
if (segments.last()?.hasKey()) {
|
|
10473
10794
|
return new ODataEntityResource(this, { segments, query });
|
|
10474
10795
|
}
|
|
10475
10796
|
else {
|
|
10476
10797
|
return new ODataEntitySetResource(this, { segments, query });
|
|
10477
10798
|
}
|
|
10478
|
-
case
|
|
10799
|
+
case PathSegment.navigationProperty:
|
|
10479
10800
|
return new ODataNavigationPropertyResource(this, { segments, query });
|
|
10480
|
-
case
|
|
10801
|
+
case PathSegment.singleton:
|
|
10481
10802
|
return new ODataSingletonResource(this, { segments, query });
|
|
10482
|
-
case
|
|
10803
|
+
case PathSegment.action:
|
|
10483
10804
|
return new ODataActionResource(this, { segments, query });
|
|
10484
|
-
case
|
|
10805
|
+
case PathSegment.function:
|
|
10485
10806
|
return new ODataFunctionResource(this, { segments, query });
|
|
10486
10807
|
}
|
|
10487
10808
|
throw new Error('No Resource for json');
|
|
@@ -10779,7 +11100,7 @@ class ODataApi {
|
|
|
10779
11100
|
}
|
|
10780
11101
|
|
|
10781
11102
|
class ODataSettings {
|
|
10782
|
-
constructor(
|
|
11103
|
+
constructor(configs) {
|
|
10783
11104
|
this.apis = configs.map((config) => new ODataApi(config));
|
|
10784
11105
|
if (this.apis.length > 1) {
|
|
10785
11106
|
if (this.apis.some((c) => c.name === undefined))
|
|
@@ -10981,6 +11302,37 @@ class ODataSettings {
|
|
|
10981
11302
|
}
|
|
10982
11303
|
}
|
|
10983
11304
|
|
|
11305
|
+
class ODataConfigLoader {
|
|
11306
|
+
}
|
|
11307
|
+
class ODataConfigSyncLoader {
|
|
11308
|
+
constructor(passedConfigs) {
|
|
11309
|
+
this.passedConfigs = passedConfigs;
|
|
11310
|
+
}
|
|
11311
|
+
loadConfigs() {
|
|
11312
|
+
if (Array.isArray(this.passedConfigs)) {
|
|
11313
|
+
return of(this.passedConfigs);
|
|
11314
|
+
}
|
|
11315
|
+
return of([this.passedConfigs]);
|
|
11316
|
+
}
|
|
11317
|
+
}
|
|
11318
|
+
class ODataConfigAsyncLoader {
|
|
11319
|
+
constructor(configs$) {
|
|
11320
|
+
this.configs$ = configs$;
|
|
11321
|
+
}
|
|
11322
|
+
loadConfigs() {
|
|
11323
|
+
if (Array.isArray(this.configs$)) {
|
|
11324
|
+
return forkJoin(this.configs$);
|
|
11325
|
+
}
|
|
11326
|
+
const singleConfigOrArray = this.configs$;
|
|
11327
|
+
return singleConfigOrArray.pipe(map((value) => {
|
|
11328
|
+
if (Array.isArray(value)) {
|
|
11329
|
+
return value;
|
|
11330
|
+
}
|
|
11331
|
+
return [value];
|
|
11332
|
+
}));
|
|
11333
|
+
}
|
|
11334
|
+
}
|
|
11335
|
+
|
|
10984
11336
|
function addBody(options, body) {
|
|
10985
11337
|
return {
|
|
10986
11338
|
body,
|
|
@@ -10995,21 +11347,23 @@ function addBody(options, body) {
|
|
|
10995
11347
|
};
|
|
10996
11348
|
}
|
|
10997
11349
|
class ODataClient {
|
|
10998
|
-
constructor(http,
|
|
11350
|
+
constructor(http, loader) {
|
|
10999
11351
|
this.http = http;
|
|
11000
|
-
this.
|
|
11001
|
-
this.
|
|
11002
|
-
|
|
11003
|
-
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
|
|
11007
|
-
|
|
11008
|
-
|
|
11009
|
-
|
|
11010
|
-
|
|
11011
|
-
|
|
11012
|
-
|
|
11352
|
+
this.loader = loader;
|
|
11353
|
+
this.loader.loadConfigs().subscribe((config) => {
|
|
11354
|
+
this.settings = new ODataSettings(config);
|
|
11355
|
+
this.settings.configure({
|
|
11356
|
+
requester: (req) => this.http.request(req.method, `${req.url}`, {
|
|
11357
|
+
body: req.body,
|
|
11358
|
+
context: req.context,
|
|
11359
|
+
headers: req.headers,
|
|
11360
|
+
observe: req.observe,
|
|
11361
|
+
params: req.params,
|
|
11362
|
+
reportProgress: req.reportProgress,
|
|
11363
|
+
responseType: req.responseType,
|
|
11364
|
+
withCredentials: req.withCredentials,
|
|
11365
|
+
}),
|
|
11366
|
+
});
|
|
11013
11367
|
});
|
|
11014
11368
|
}
|
|
11015
11369
|
//#region Resolve Building Blocks
|
|
@@ -11029,6 +11383,9 @@ class ODataClient {
|
|
|
11029
11383
|
this.settings.findApiForType(value);
|
|
11030
11384
|
return api || this.settings.defaultApi();
|
|
11031
11385
|
}
|
|
11386
|
+
defaultApi() {
|
|
11387
|
+
return this.settings.defaultApi();
|
|
11388
|
+
}
|
|
11032
11389
|
/**
|
|
11033
11390
|
* Resolve the parser for the given string type.
|
|
11034
11391
|
* @param type The string type of the parser.
|
|
@@ -11091,7 +11448,8 @@ class ODataClient {
|
|
|
11091
11448
|
* @returns The service for the given type.
|
|
11092
11449
|
*/
|
|
11093
11450
|
serviceForType(type) {
|
|
11094
|
-
return this.injector.get(this.settings
|
|
11451
|
+
//return this.injector.get(this.settings!.serviceForType(type));
|
|
11452
|
+
return undefined;
|
|
11095
11453
|
}
|
|
11096
11454
|
/**
|
|
11097
11455
|
* Resolve the service for the given string entity type.
|
|
@@ -11099,7 +11457,8 @@ class ODataClient {
|
|
|
11099
11457
|
* @returns The service for the given entity type.
|
|
11100
11458
|
*/
|
|
11101
11459
|
serviceForEntityType(type) {
|
|
11102
|
-
return this.injector.get(this.settings
|
|
11460
|
+
//return this.injector.get(this.settings!.serviceForEntityType(type));
|
|
11461
|
+
return undefined;
|
|
11103
11462
|
}
|
|
11104
11463
|
enumTypeByName(name) {
|
|
11105
11464
|
return this.settings.enumTypeByName(name);
|
|
@@ -11120,7 +11479,8 @@ class ODataClient {
|
|
|
11120
11479
|
return this.settings.collectionByName(name);
|
|
11121
11480
|
}
|
|
11122
11481
|
serviceByName(name) {
|
|
11123
|
-
return this.injector.get(this.settings
|
|
11482
|
+
//return this.injector.get(this.settings!.serviceByName(name));
|
|
11483
|
+
return undefined;
|
|
11124
11484
|
}
|
|
11125
11485
|
fromJSON(json, apiNameOrType) {
|
|
11126
11486
|
return this.apiFor(apiNameOrType).fromJSON(json);
|
|
@@ -11212,16 +11572,11 @@ class ODataClient {
|
|
|
11212
11572
|
return this.request('PUT', resource, addBody(options, body));
|
|
11213
11573
|
}
|
|
11214
11574
|
}
|
|
11215
|
-
ODataClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.
|
|
11216
|
-
ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.
|
|
11217
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.
|
|
11218
|
-
type: Injectable
|
|
11219
|
-
|
|
11220
|
-
providedIn: 'root',
|
|
11221
|
-
}]
|
|
11222
|
-
}], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: ODataSettings }, { type: i0.Injector }]; } });
|
|
11223
|
-
|
|
11224
|
-
const ODATA_CONFIGURATIONS = new InjectionToken('odata.configuraions');
|
|
11575
|
+
ODataClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.6", ngImport: i0, type: ODataClient, deps: [{ token: i1.HttpClient }, { token: ODataConfigLoader }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
11576
|
+
ODataClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.6", ngImport: i0, type: ODataClient });
|
|
11577
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.6", ngImport: i0, type: ODataClient, decorators: [{
|
|
11578
|
+
type: Injectable
|
|
11579
|
+
}], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: ODataConfigLoader }]; } });
|
|
11225
11580
|
|
|
11226
11581
|
class ODataBaseService {
|
|
11227
11582
|
constructor(client, name, apiNameOrEntityType) {
|
|
@@ -11472,25 +11827,29 @@ class ODataServiceFactory {
|
|
|
11472
11827
|
})(this.client, singletonName, apiNameOrEntityType);
|
|
11473
11828
|
}
|
|
11474
11829
|
}
|
|
11475
|
-
ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.
|
|
11476
|
-
ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.
|
|
11477
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.
|
|
11830
|
+
ODataServiceFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.6", ngImport: i0, type: ODataServiceFactory, deps: [{ token: ODataClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
11831
|
+
ODataServiceFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.6", ngImport: i0, type: ODataServiceFactory });
|
|
11832
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.6", ngImport: i0, type: ODataServiceFactory, decorators: [{
|
|
11478
11833
|
type: Injectable
|
|
11479
11834
|
}], ctorParameters: function () { return [{ type: ODataClient }]; } });
|
|
11480
11835
|
|
|
11481
|
-
|
|
11482
|
-
|
|
11836
|
+
const ODATA_CONFIG = new InjectionToken('odata.config');
|
|
11837
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
11838
|
+
function createSyncLoader(passedConfig) {
|
|
11839
|
+
return new ODataConfigSyncLoader(passedConfig.config);
|
|
11483
11840
|
}
|
|
11484
11841
|
class ODataModule {
|
|
11485
|
-
static forRoot(
|
|
11842
|
+
static forRoot(passedConfig) {
|
|
11486
11843
|
return {
|
|
11487
11844
|
ngModule: ODataModule,
|
|
11488
11845
|
providers: [
|
|
11489
|
-
|
|
11490
|
-
{
|
|
11491
|
-
|
|
11492
|
-
|
|
11493
|
-
|
|
11846
|
+
// Make the ODATA_CONFIG available through injection
|
|
11847
|
+
{ provide: ODATA_CONFIG, useValue: passedConfig },
|
|
11848
|
+
// Create the loader: Either the one getting passed or a sync one
|
|
11849
|
+
passedConfig?.loader || {
|
|
11850
|
+
provide: ODataConfigLoader,
|
|
11851
|
+
useFactory: createSyncLoader,
|
|
11852
|
+
deps: [ODATA_CONFIG],
|
|
11494
11853
|
},
|
|
11495
11854
|
ODataClient,
|
|
11496
11855
|
ODataServiceFactory,
|
|
@@ -11498,13 +11857,13 @@ class ODataModule {
|
|
|
11498
11857
|
};
|
|
11499
11858
|
}
|
|
11500
11859
|
}
|
|
11501
|
-
ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.
|
|
11502
|
-
ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.
|
|
11503
|
-
ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.
|
|
11504
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.
|
|
11860
|
+
ODataModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.6", ngImport: i0, type: ODataModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
11861
|
+
ODataModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.6", ngImport: i0, type: ODataModule, imports: [CommonModule, HttpClientModule] });
|
|
11862
|
+
ODataModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.6", ngImport: i0, type: ODataModule, providers: [ODataClient, ODataServiceFactory], imports: [CommonModule, HttpClientModule] });
|
|
11863
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.6", ngImport: i0, type: ODataModule, decorators: [{
|
|
11505
11864
|
type: NgModule,
|
|
11506
11865
|
args: [{
|
|
11507
|
-
imports: [HttpClientModule],
|
|
11866
|
+
imports: [CommonModule, HttpClientModule],
|
|
11508
11867
|
providers: [ODataClient, ODataServiceFactory],
|
|
11509
11868
|
}]
|
|
11510
11869
|
}] });
|
|
@@ -11517,6 +11876,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.1", ngImpor
|
|
|
11517
11876
|
* Generated bundle index. Do not edit.
|
|
11518
11877
|
*/
|
|
11519
11878
|
|
|
11520
|
-
export { BUBBLING, Dates, Durations, EDM_PARSERS, Enums, Http, INCLUDE_DEEP, INCLUDE_SHALLOW, ITEM_ROOT, Model, ModelField, NONE_PARSER,
|
|
11879
|
+
export { BUBBLING, Dates, Durations, EDM_PARSERS, EdmType, Enums, Http, INCLUDE_DEEP, INCLUDE_SHALLOW, ITEM_ROOT, Model, ModelField, NONE_PARSER, ODATA_CONFIG, OData, ODataActionResource, ODataAnnotations, ODataApi, ODataBaseService, ODataBatchRequest, ODataBatchResource, ODataCache, ODataCallable, ODataCallableParser, ODataClient, ODataCollection, ODataConfigAsyncLoader, ODataConfigLoader, ODataConfigSyncLoader, ODataCountResource, ODataEntitiesAnnotations, ODataEntityAnnotations, ODataEntityContainer, ODataEntityResource, ODataEntitySet, ODataEntitySetResource, ODataEntitySetService, ODataEntityTypeKey, ODataEnumType, ODataEnumTypeFieldParser, ODataEnumTypeParser, ODataFunctionResource, ODataInMemoryCache, ODataInStorageCache, ODataMediaResource, ODataMetadata, ODataMetadataResource, ODataModel, ODataModelEvent, ODataModelField, ODataModelOptions, ODataModelState, ODataModule, ODataNavigationPropertyResource, ODataParameterParser, ODataPathSegments, ODataPathSegmentsHandler, ODataPropertyAnnotations, ODataPropertyResource, ODataQueryOptionHandler, ODataQueryOptions, ODataQueryOptionsHandler, ODataReferenceResource, ODataReferential, ODataRequest, ODataResource, ODataResponse, ODataSchema, ODataServiceFactory, ODataSettings, ODataSingletonResource, ODataSingletonService, ODataStructuredType, ODataStructuredTypeFieldParser, ODataStructuredTypeParser, ODataValueResource, Objects, PathSegment, QueryCustomTypes, QueryOption, RESERVED_FIELD_NAMES, SegmentHandler, StandardAggregateMethods, Strings, Types, Urls, alias, binary, buildPathAndQuery, createSyncLoader, duration, isQueryCustomType, normalizeValue, raw };
|
|
11521
11880
|
//# sourceMappingURL=angular-odata.mjs.map
|
|
11522
11881
|
//# sourceMappingURL=angular-odata.mjs.map
|