@apigames/sdk-core 22.1.4 → 22.1.7
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/lib/classes/resource.container.d.ts +1 -1
- package/lib/classes/resource.object.d.ts +7 -2
- package/lib/classes/resource.object.js +102 -9
- package/lib/interfaces/index.d.ts +1 -1
- package/lib/interfaces/resource.object.d.ts +6 -1
- package/lib/interfaces/resource.object.js +7 -16
- package/package.json +1 -1
|
@@ -35,7 +35,7 @@ export default class ResourceContainer implements IResourceContainer {
|
|
|
35
35
|
Count(): Promise<number>;
|
|
36
36
|
Find(): Promise<void>;
|
|
37
37
|
Get(id: string): Promise<void>;
|
|
38
|
-
|
|
38
|
+
InitParams(): void;
|
|
39
39
|
private GetHeaders;
|
|
40
40
|
private GetQueryParams;
|
|
41
41
|
IncludedObject(type: string, id: string): IResourceObject;
|
|
@@ -12,9 +12,12 @@ export default class ResourceObject implements IResourceObject {
|
|
|
12
12
|
protected EndpointContentType(): string;
|
|
13
13
|
protected LoadAttributes(value: any): void;
|
|
14
14
|
protected LoadRelationships(value: any): void;
|
|
15
|
-
protected
|
|
16
|
-
|
|
15
|
+
protected RelationshipType(relationshipName: string): string;
|
|
16
|
+
UpdateAttributes(value: any): void;
|
|
17
|
+
UpdateRelationships(value: any): void;
|
|
17
18
|
LoadData(value: any): IResourceObject;
|
|
19
|
+
protected SerializeAttributesPayload(shadow: any, data: any): any;
|
|
20
|
+
protected SerializeRelationshipsPayload(shadow: any, data: any): any;
|
|
18
21
|
protected GetInsertPayload(): any;
|
|
19
22
|
protected GetUpdatePayload(): any;
|
|
20
23
|
Delete(): Promise<void>;
|
|
@@ -29,6 +32,8 @@ export default class ResourceObject implements IResourceObject {
|
|
|
29
32
|
set id(value: string);
|
|
30
33
|
get attributes(): IResourceObjectAttributes;
|
|
31
34
|
get relationships(): IResourceObjectRelationships;
|
|
35
|
+
protected get shadowAttributes(): IResourceObjectAttributes;
|
|
36
|
+
protected get shadowRelationships(): IResourceObjectRelationships;
|
|
32
37
|
get uri(): ResourceObjectUri;
|
|
33
38
|
}
|
|
34
39
|
export declare type ResourceObjectClass = typeof ResourceObject;
|
|
@@ -31,6 +31,9 @@ class ResourceObject {
|
|
|
31
31
|
LoadRelationships(value) {
|
|
32
32
|
throw new Error('Method or Property not implemented.');
|
|
33
33
|
}
|
|
34
|
+
RelationshipType(relationshipName) {
|
|
35
|
+
throw new Error('Method or Property not implemented.');
|
|
36
|
+
}
|
|
34
37
|
UpdateAttributes(value) {
|
|
35
38
|
throw new Error('Method or Property not implemented.');
|
|
36
39
|
}
|
|
@@ -55,6 +58,84 @@ class ResourceObject {
|
|
|
55
58
|
this._mode = ResourceObjectMode.ExistingDocument;
|
|
56
59
|
return this;
|
|
57
60
|
}
|
|
61
|
+
SerializeAttributesPayload(shadow, data) {
|
|
62
|
+
if ((0, json_1.areEqual)(shadow, data))
|
|
63
|
+
return undefined;
|
|
64
|
+
if ((0, json_1.isUndefined)(data) && (0, json_1.isUndefined)(shadow))
|
|
65
|
+
return undefined;
|
|
66
|
+
if ((0, json_1.isArray)(data))
|
|
67
|
+
return data;
|
|
68
|
+
if ((0, json_1.isObject)(data)) {
|
|
69
|
+
if ((Object.keys(data).length === 2)
|
|
70
|
+
&& ((0, json_1.hasProperty)(data, 'latitude') && (0, json_1.isNumber)(data.latitude))
|
|
71
|
+
&& ((0, json_1.hasProperty)(data, 'longitude') && (0, json_1.isNumber)(data.longitude))) {
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
const payload = {};
|
|
75
|
+
for (const fieldName in data) {
|
|
76
|
+
if ((0, json_1.hasProperty)(data, fieldName)) {
|
|
77
|
+
if ((0, json_1.isDefined)(shadow))
|
|
78
|
+
payload[fieldName] = this.SerializeAttributesPayload(shadow[fieldName], data[fieldName]);
|
|
79
|
+
else
|
|
80
|
+
payload[fieldName] = this.SerializeAttributesPayload(undefined, data[fieldName]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if ((0, json_1.isDefined)(shadow) && (0, json_1.isObject)(shadow)) {
|
|
84
|
+
for (const fieldName in shadow) {
|
|
85
|
+
if ((0, json_1.hasProperty)(shadow, fieldName)) {
|
|
86
|
+
if ((0, json_1.isUndefined)(data[fieldName]))
|
|
87
|
+
payload[fieldName] = null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return payload;
|
|
92
|
+
}
|
|
93
|
+
return data;
|
|
94
|
+
}
|
|
95
|
+
SerializeRelationshipsPayload(shadow, data) {
|
|
96
|
+
if ((0, json_1.areEqual)(shadow, data))
|
|
97
|
+
return undefined;
|
|
98
|
+
if ((0, json_1.isUndefined)(data) && (0, json_1.isUndefined)(shadow))
|
|
99
|
+
return undefined;
|
|
100
|
+
if ((0, json_1.isObject)(data)) {
|
|
101
|
+
const payload = {};
|
|
102
|
+
for (const fieldName in data) {
|
|
103
|
+
if ((0, json_1.hasProperty)(data, fieldName)) {
|
|
104
|
+
if ((0, json_1.isArrayOfStrings)(data[fieldName])) {
|
|
105
|
+
payload[fieldName] = {
|
|
106
|
+
data: [],
|
|
107
|
+
};
|
|
108
|
+
for (const key of data[fieldName]) {
|
|
109
|
+
payload[fieldName].data.push({
|
|
110
|
+
type: this.RelationshipType(fieldName),
|
|
111
|
+
id: key,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if ((0, json_1.isString)(data[fieldName])) {
|
|
116
|
+
if ((0, json_1.isUndefined)(shadow) || !(0, json_1.areEqual)(shadow[fieldName], data[fieldName])) {
|
|
117
|
+
payload[fieldName] = {
|
|
118
|
+
data: {
|
|
119
|
+
type: this.RelationshipType(fieldName),
|
|
120
|
+
id: data[fieldName],
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if ((0, json_1.isDefined)(shadow) && (0, json_1.isObject)(shadow)) {
|
|
128
|
+
for (const fieldName in shadow) {
|
|
129
|
+
if ((0, json_1.hasProperty)(shadow, fieldName)) {
|
|
130
|
+
if ((0, json_1.isUndefined)(data[fieldName]))
|
|
131
|
+
payload[fieldName] = null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return payload;
|
|
136
|
+
}
|
|
137
|
+
return data;
|
|
138
|
+
}
|
|
58
139
|
GetInsertPayload() {
|
|
59
140
|
const payload = {
|
|
60
141
|
data: {
|
|
@@ -63,10 +144,13 @@ class ResourceObject {
|
|
|
63
144
|
};
|
|
64
145
|
if ((0, json_1.isDefined)(this.id))
|
|
65
146
|
payload.data.id = this.id;
|
|
66
|
-
if ((0, json_1.isDefined)(this.attributes))
|
|
67
|
-
payload.data.attributes = this.attributes;
|
|
68
|
-
|
|
69
|
-
|
|
147
|
+
if ((0, json_1.isDefined)(this.attributes)) {
|
|
148
|
+
payload.data.attributes = this.SerializeAttributesPayload(this.shadowAttributes, this.attributes);
|
|
149
|
+
}
|
|
150
|
+
if ((0, json_1.isDefined)(this.relationships)) {
|
|
151
|
+
payload.data.relationships = this.SerializeRelationshipsPayload(this.shadowRelationships, this.relationships);
|
|
152
|
+
}
|
|
153
|
+
(0, json_1.redactUndefinedValues)(payload);
|
|
70
154
|
return payload;
|
|
71
155
|
}
|
|
72
156
|
GetUpdatePayload() {
|
|
@@ -76,10 +160,13 @@ class ResourceObject {
|
|
|
76
160
|
id: this.id,
|
|
77
161
|
},
|
|
78
162
|
};
|
|
79
|
-
if ((0, json_1.isDefined)(this.attributes))
|
|
80
|
-
payload.data.attributes = this.attributes;
|
|
81
|
-
|
|
82
|
-
|
|
163
|
+
if ((0, json_1.isDefined)(this.attributes)) {
|
|
164
|
+
payload.data.attributes = this.SerializeAttributesPayload(this.shadowAttributes, this.attributes);
|
|
165
|
+
}
|
|
166
|
+
if ((0, json_1.isDefined)(this.relationships)) {
|
|
167
|
+
payload.data.relationships = this.SerializeRelationshipsPayload(this.shadowRelationships, this.relationships);
|
|
168
|
+
}
|
|
169
|
+
(0, json_1.redactUndefinedValues)(payload);
|
|
83
170
|
return payload;
|
|
84
171
|
}
|
|
85
172
|
Delete() {
|
|
@@ -143,7 +230,7 @@ class ResourceObject {
|
|
|
143
230
|
const queryUri = this.uri;
|
|
144
231
|
const queryHeaders = this.GetHeaders();
|
|
145
232
|
const queryOptions = {};
|
|
146
|
-
const payload = this.
|
|
233
|
+
const payload = this.GetInsertPayload();
|
|
147
234
|
yield this._container.restClient.Patch(queryUri, payload, queryHeaders, queryOptions);
|
|
148
235
|
});
|
|
149
236
|
}
|
|
@@ -172,6 +259,12 @@ class ResourceObject {
|
|
|
172
259
|
get relationships() {
|
|
173
260
|
throw new Error('Method or Property not implemented.');
|
|
174
261
|
}
|
|
262
|
+
get shadowAttributes() {
|
|
263
|
+
throw new Error('Method or Property not implemented.');
|
|
264
|
+
}
|
|
265
|
+
get shadowRelationships() {
|
|
266
|
+
throw new Error('Method or Property not implemented.');
|
|
267
|
+
}
|
|
175
268
|
get uri() {
|
|
176
269
|
return this._uri;
|
|
177
270
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ISDKError, ISDKRequestError, ISDKException, ISDKRequestException, } from './sdk.errors';
|
|
2
2
|
export { IResourceContainer, ResourceFilterName, ResourceFilterValue, ResourceSortOption, ResourceIncludeOption, } from './resource.container';
|
|
3
|
-
export { IResourceObject, IResourceObjectAttributes, IResourceObjectRelationships, GeospatialPoint, ResourceObjectAttributeBase, ResourceObjectRelationshipLinkObject, ResourceObjectRelationship, ResourceObjectRelationships, ResourceObjectUri, ResourceObjectRelationshipBase, } from './resource.object';
|
|
3
|
+
export { IResourceObject, IResourceObjectAttributes, IResourceObjectRelationships, GeospatialPoint, ResourceObjectAttributeBase, ResourceObjectRelationshipLinkObject, ResourceObjectRelationship, ResourceObjectRelationships, ResourceObjectRelationshipKey, ResourceObjectRelationshipKeys, ResourceObjectUri, ResourceObjectRelationshipBase, } from './resource.object';
|
|
@@ -13,6 +13,8 @@ export declare type ResourceObjectRelationship = {
|
|
|
13
13
|
export declare type ResourceObjectRelationships = {
|
|
14
14
|
data: ResourceObjectRelationshipLinkObject[];
|
|
15
15
|
};
|
|
16
|
+
export declare type ResourceObjectRelationshipKey = string;
|
|
17
|
+
export declare type ResourceObjectRelationshipKeys = ResourceObjectRelationshipKey[];
|
|
16
18
|
export interface IResourceObjectRelationships {
|
|
17
19
|
LoadData(data: any): void;
|
|
18
20
|
}
|
|
@@ -27,7 +29,8 @@ export declare class GeospatialPoint extends ResourceObjectAttributeBase impleme
|
|
|
27
29
|
LoadData(data: any): void;
|
|
28
30
|
}
|
|
29
31
|
export declare class ResourceObjectRelationshipBase {
|
|
30
|
-
protected static
|
|
32
|
+
protected static LoadRelationshipKey(expectedType: string, value: any): ResourceObjectRelationshipKey;
|
|
33
|
+
static RelationshipType(relationshipName: string): string;
|
|
31
34
|
}
|
|
32
35
|
export interface IResourceObject {
|
|
33
36
|
type: ResourceObjectType;
|
|
@@ -38,4 +41,6 @@ export interface IResourceObject {
|
|
|
38
41
|
LoadData(value: any): IResourceObject;
|
|
39
42
|
Delete(): Promise<void>;
|
|
40
43
|
Save(): Promise<void>;
|
|
44
|
+
UpdateAttributes(value: any): void;
|
|
45
|
+
UpdateRelationships(value: any): void;
|
|
41
46
|
}
|
|
@@ -9,13 +9,6 @@ class ResourceObjectAttributeBase {
|
|
|
9
9
|
}
|
|
10
10
|
static LoadGeospatialPoint(value) {
|
|
11
11
|
return (0, helpers_1.LoadGeospatialPoint)(value);
|
|
12
|
-
if ((0, json_1.isDefined)(value) && (0, json_1.hasProperty)(value, 'longitude') && (0, json_1.isNumber)(value.longitude)
|
|
13
|
-
&& (0, json_1.hasProperty)(value, 'latitude') && (0, json_1.isNumber)(value.latitude)) {
|
|
14
|
-
const geospatialPoint = new GeospatialPoint();
|
|
15
|
-
geospatialPoint.LoadData(value);
|
|
16
|
-
return geospatialPoint;
|
|
17
|
-
}
|
|
18
|
-
return undefined;
|
|
19
12
|
}
|
|
20
13
|
}
|
|
21
14
|
exports.ResourceObjectAttributeBase = ResourceObjectAttributeBase;
|
|
@@ -27,18 +20,16 @@ class GeospatialPoint extends ResourceObjectAttributeBase {
|
|
|
27
20
|
}
|
|
28
21
|
exports.GeospatialPoint = GeospatialPoint;
|
|
29
22
|
class ResourceObjectRelationshipBase {
|
|
30
|
-
static
|
|
23
|
+
static LoadRelationshipKey(expectedType, value) {
|
|
31
24
|
if ((0, json_1.isDefined)(value) && ((0, json_1.hasProperty)(value, 'data') && (0, json_1.isObject)(value.data)
|
|
32
25
|
&& (0, json_1.hasProperty)(value.data, 'type') && (0, json_1.isString)(value.data.type)
|
|
33
|
-
&& (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
type: value.data.type,
|
|
37
|
-
id: value.data.id,
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
26
|
+
&& (value.data.type === expectedType)
|
|
27
|
+
&& (0, json_1.hasProperty)(value.data, 'id') && (0, json_1.isString)(value.data.id)))
|
|
28
|
+
return value.data.id;
|
|
41
29
|
return undefined;
|
|
42
30
|
}
|
|
31
|
+
static RelationshipType(relationshipName) {
|
|
32
|
+
throw new Error('Method or Property not implemented.');
|
|
33
|
+
}
|
|
43
34
|
}
|
|
44
35
|
exports.ResourceObjectRelationshipBase = ResourceObjectRelationshipBase;
|