@cloudize/sdk-core 23.1.4 → 23.2.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/lib/classes/index.d.ts +5 -5
- package/lib/classes/index.js +15 -15
- package/lib/classes/resource.container.d.ts +57 -57
- package/lib/classes/resource.container.js +322 -322
- package/lib/classes/resource.header.params.d.ts +3 -3
- package/lib/classes/resource.header.params.js +2 -2
- package/lib/classes/resource.object.d.ts +38 -38
- package/lib/classes/resource.object.js +279 -279
- package/lib/classes/resource.path.params.d.ts +3 -3
- package/lib/classes/resource.path.params.js +2 -2
- package/lib/classes/sdk.config.d.ts +21 -21
- package/lib/classes/sdk.config.js +46 -46
- package/lib/exceptions/index.d.ts +1 -1
- package/lib/exceptions/index.js +8 -8
- package/lib/exceptions/sdk.exception.d.ts +6 -6
- package/lib/exceptions/sdk.exception.js +14 -14
- package/lib/helpers/index.d.ts +3 -3
- package/lib/helpers/index.js +30 -30
- package/lib/index.d.ts +5 -5
- package/lib/index.js +21 -21
- package/lib/interfaces/index.d.ts +2 -2
- package/lib/interfaces/index.js +10 -10
- package/lib/interfaces/resource.interfaces.d.ts +94 -94
- package/lib/interfaces/resource.interfaces.js +101 -101
- package/lib/interfaces/sdk.errors.d.ts +17 -17
- package/lib/interfaces/sdk.errors.js +2 -2
- package/lib/type-guards/index.d.ts +6 -6
- package/lib/type-guards/index.js +30 -30
- package/package.json +12 -12
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { IResourceContainer, IResourceObject, IResourceObjectAttributes, IResourceObjectRelationships, ResourceObjectUri } from '..';
|
|
2
|
-
export declare enum ResourceObjectMode {
|
|
3
|
-
NewDocument = 0,
|
|
4
|
-
ExistingDocument = 1
|
|
5
|
-
}
|
|
6
|
-
export default class ResourceObject implements IResourceObject {
|
|
7
|
-
private _container;
|
|
8
|
-
private _id;
|
|
9
|
-
private _mode;
|
|
10
|
-
private _uri;
|
|
11
|
-
constructor(container: IResourceContainer, mode: ResourceObjectMode);
|
|
12
|
-
protected EndpointContentType(): string;
|
|
13
|
-
protected LoadAttributes(value: any): void;
|
|
14
|
-
protected LoadRelationships(value: any): void;
|
|
15
|
-
protected RelationshipType(relationshipName: string): string;
|
|
16
|
-
UpdateAttributes(value: any): void;
|
|
17
|
-
UpdateRelationships(value: any): void;
|
|
18
|
-
LoadData(value: any): IResourceObject;
|
|
19
|
-
protected SerializeAttributesPayload(shadow: any, data: any): any;
|
|
20
|
-
protected SerializeRelationshipsPayload(shadow: any, data: any): any;
|
|
21
|
-
protected GetInsertPayload(): any;
|
|
22
|
-
protected GetUpdatePayload(): any;
|
|
23
|
-
Delete(): Promise<void>;
|
|
24
|
-
private GetHeaderValue;
|
|
25
|
-
private HasHeader;
|
|
26
|
-
private InsertResource;
|
|
27
|
-
private UpdateResource;
|
|
28
|
-
Save(): Promise<void>;
|
|
29
|
-
get type(): string;
|
|
30
|
-
get id(): string;
|
|
31
|
-
set id(value: string);
|
|
32
|
-
get attributes(): IResourceObjectAttributes;
|
|
33
|
-
get relationships(): IResourceObjectRelationships;
|
|
34
|
-
protected get shadowAttributes(): IResourceObjectAttributes;
|
|
35
|
-
protected get shadowRelationships(): IResourceObjectRelationships;
|
|
36
|
-
get uri(): ResourceObjectUri;
|
|
37
|
-
}
|
|
38
|
-
export type ResourceObjectClass = typeof ResourceObject;
|
|
1
|
+
import { IResourceContainer, IResourceObject, IResourceObjectAttributes, IResourceObjectRelationships, ResourceObjectUri } from '..';
|
|
2
|
+
export declare enum ResourceObjectMode {
|
|
3
|
+
NewDocument = 0,
|
|
4
|
+
ExistingDocument = 1
|
|
5
|
+
}
|
|
6
|
+
export default class ResourceObject implements IResourceObject {
|
|
7
|
+
private _container;
|
|
8
|
+
private _id;
|
|
9
|
+
private _mode;
|
|
10
|
+
private _uri;
|
|
11
|
+
constructor(container: IResourceContainer, mode: ResourceObjectMode);
|
|
12
|
+
protected EndpointContentType(): string;
|
|
13
|
+
protected LoadAttributes(value: any): void;
|
|
14
|
+
protected LoadRelationships(value: any): void;
|
|
15
|
+
protected RelationshipType(relationshipName: string): string;
|
|
16
|
+
UpdateAttributes(value: any): void;
|
|
17
|
+
UpdateRelationships(value: any): void;
|
|
18
|
+
LoadData(value: any): IResourceObject;
|
|
19
|
+
protected SerializeAttributesPayload(shadow: any, data: any): any;
|
|
20
|
+
protected SerializeRelationshipsPayload(shadow: any, data: any): any;
|
|
21
|
+
protected GetInsertPayload(): any;
|
|
22
|
+
protected GetUpdatePayload(): any;
|
|
23
|
+
Delete(): Promise<void>;
|
|
24
|
+
private GetHeaderValue;
|
|
25
|
+
private HasHeader;
|
|
26
|
+
private InsertResource;
|
|
27
|
+
private UpdateResource;
|
|
28
|
+
Save(): Promise<void>;
|
|
29
|
+
get type(): string;
|
|
30
|
+
get id(): string;
|
|
31
|
+
set id(value: string);
|
|
32
|
+
get attributes(): IResourceObjectAttributes;
|
|
33
|
+
get relationships(): IResourceObjectRelationships;
|
|
34
|
+
protected get shadowAttributes(): IResourceObjectAttributes;
|
|
35
|
+
protected get shadowRelationships(): IResourceObjectRelationships;
|
|
36
|
+
get uri(): ResourceObjectUri;
|
|
37
|
+
}
|
|
38
|
+
export type ResourceObjectClass = typeof ResourceObject;
|
|
@@ -1,279 +1,279 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ResourceObjectMode = void 0;
|
|
13
|
-
const json_1 = require("@cloudize/json");
|
|
14
|
-
const __1 = require("..");
|
|
15
|
-
var ResourceObjectMode;
|
|
16
|
-
(function (ResourceObjectMode) {
|
|
17
|
-
ResourceObjectMode[ResourceObjectMode["NewDocument"] = 0] = "NewDocument";
|
|
18
|
-
ResourceObjectMode[ResourceObjectMode["ExistingDocument"] = 1] = "ExistingDocument";
|
|
19
|
-
})(ResourceObjectMode = exports.ResourceObjectMode || (exports.ResourceObjectMode = {}));
|
|
20
|
-
class ResourceObject {
|
|
21
|
-
constructor(container, mode) {
|
|
22
|
-
this._mode = ResourceObjectMode.NewDocument;
|
|
23
|
-
this._container = container;
|
|
24
|
-
this._mode = mode;
|
|
25
|
-
}
|
|
26
|
-
EndpointContentType() {
|
|
27
|
-
throw new Error('Method or Property not implemented.');
|
|
28
|
-
}
|
|
29
|
-
LoadAttributes(value) {
|
|
30
|
-
throw new Error('Method or Property not implemented.');
|
|
31
|
-
}
|
|
32
|
-
LoadRelationships(value) {
|
|
33
|
-
throw new Error('Method or Property not implemented.');
|
|
34
|
-
}
|
|
35
|
-
RelationshipType(relationshipName) {
|
|
36
|
-
throw new Error('Method or Property not implemented.');
|
|
37
|
-
}
|
|
38
|
-
UpdateAttributes(value) {
|
|
39
|
-
throw new Error('Method or Property not implemented.');
|
|
40
|
-
}
|
|
41
|
-
UpdateRelationships(value) {
|
|
42
|
-
throw new Error('Method or Property not implemented.');
|
|
43
|
-
}
|
|
44
|
-
LoadData(value) {
|
|
45
|
-
if (!(0, json_1.hasProperty)(value, 'type') || (value.type !== this.type)) {
|
|
46
|
-
throw new __1.SDKException('INVALID-RESOURCE-MAPPING', 'The resource data being loaded cannot be '
|
|
47
|
-
+ 'read into this object');
|
|
48
|
-
}
|
|
49
|
-
if ((0, json_1.hasProperty)(value, 'id'))
|
|
50
|
-
this._id = value.id;
|
|
51
|
-
if ((0, json_1.hasProperty)(value, 'attributes'))
|
|
52
|
-
this.LoadAttributes(value.attributes);
|
|
53
|
-
if ((0, json_1.hasProperty)(value, 'relationships'))
|
|
54
|
-
this.LoadRelationships(value.relationships);
|
|
55
|
-
if ((0, json_1.hasProperty)(value, 'links') && (0, json_1.isObject)(value.links) && (0, json_1.hasProperty)(value.links, 'self')
|
|
56
|
-
&& (0, json_1.isString)(value.links.self)) {
|
|
57
|
-
this._uri = value.links.self;
|
|
58
|
-
}
|
|
59
|
-
this._mode = ResourceObjectMode.ExistingDocument;
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
SerializeAttributesPayload(shadow, data) {
|
|
63
|
-
if ((0, json_1.areEqual)(shadow, data))
|
|
64
|
-
return undefined;
|
|
65
|
-
if ((0, json_1.isUndefined)(data) && (0, json_1.isUndefined)(shadow))
|
|
66
|
-
return undefined;
|
|
67
|
-
if ((0, json_1.isUndefined)(shadow))
|
|
68
|
-
return data;
|
|
69
|
-
if ((0, json_1.isDate)(data))
|
|
70
|
-
return data;
|
|
71
|
-
if ((0, json_1.isArray)(data))
|
|
72
|
-
return data;
|
|
73
|
-
if ((0, json_1.isObject)(data)) {
|
|
74
|
-
if ((Object.keys(data).length === 2)
|
|
75
|
-
&& ((0, json_1.hasProperty)(data, 'latitude') && (0, json_1.isNumber)(data.latitude))
|
|
76
|
-
&& ((0, json_1.hasProperty)(data, 'longitude') && (0, json_1.isNumber)(data.longitude))) {
|
|
77
|
-
return data;
|
|
78
|
-
}
|
|
79
|
-
const payload = {};
|
|
80
|
-
for (const fieldName in data) {
|
|
81
|
-
if ((0, json_1.hasProperty)(data, fieldName)) {
|
|
82
|
-
if ((0, json_1.isDefined)(shadow))
|
|
83
|
-
payload[fieldName] = this.SerializeAttributesPayload(shadow[fieldName], data[fieldName]);
|
|
84
|
-
else
|
|
85
|
-
payload[fieldName] = this.SerializeAttributesPayload(undefined, data[fieldName]);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if ((0, json_1.isDefined)(shadow) && (0, json_1.isObject)(shadow)) {
|
|
89
|
-
for (const fieldName in shadow) {
|
|
90
|
-
if ((0, json_1.hasProperty)(shadow, fieldName)) {
|
|
91
|
-
if ((0, json_1.isDefinedAndNotNull)(shadow[fieldName]) && (0, json_1.isUndefinedOrNull)(data[fieldName]))
|
|
92
|
-
payload[fieldName] = null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return payload;
|
|
97
|
-
}
|
|
98
|
-
return data;
|
|
99
|
-
}
|
|
100
|
-
SerializeRelationshipsPayload(shadow, data) {
|
|
101
|
-
if ((0, json_1.areEqual)(shadow, data))
|
|
102
|
-
return undefined;
|
|
103
|
-
if ((0, json_1.isUndefined)(data) && (0, json_1.isUndefined)(shadow))
|
|
104
|
-
return undefined;
|
|
105
|
-
if ((0, json_1.isObject)(data)) {
|
|
106
|
-
const payload = {};
|
|
107
|
-
for (const fieldName in data) {
|
|
108
|
-
if ((0, json_1.hasProperty)(data, fieldName)) {
|
|
109
|
-
if ((0, json_1.isDefinedAndNotNull)(data[fieldName])) {
|
|
110
|
-
if ((0, __1.isResourceObjectRelationships)(data[fieldName])) {
|
|
111
|
-
payload[fieldName] = {
|
|
112
|
-
data: [],
|
|
113
|
-
};
|
|
114
|
-
for (const relationship of data[fieldName]) {
|
|
115
|
-
payload[fieldName].data.push({
|
|
116
|
-
type: relationship.type,
|
|
117
|
-
id: relationship.id,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else if ((0, __1.isResourceObjectRelationship)(data[fieldName])) {
|
|
122
|
-
if ((0, json_1.isUndefined)(shadow)
|
|
123
|
-
|| (0, json_1.isUndefined)(shadow[fieldName])
|
|
124
|
-
|| ((shadow[fieldName].type !== data[fieldName].type) || (shadow[fieldName].id !== data[fieldName].id))) {
|
|
125
|
-
if (data[fieldName].id === null) {
|
|
126
|
-
payload[fieldName] = { data: null };
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
payload[fieldName] = {
|
|
130
|
-
data: {
|
|
131
|
-
type: data[fieldName].type,
|
|
132
|
-
id: data[fieldName].id,
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if ((0, json_1.isDefined)(shadow) && (0, json_1.isObject)(shadow)) {
|
|
142
|
-
for (const fieldName in shadow) {
|
|
143
|
-
if ((0, json_1.hasProperty)(shadow, fieldName)) {
|
|
144
|
-
if ((0, json_1.isDefinedAndNotNull)(shadow[fieldName]) && (0, json_1.isUndefinedOrNull)(data[fieldName]))
|
|
145
|
-
payload[fieldName] = null;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return payload;
|
|
150
|
-
}
|
|
151
|
-
return data;
|
|
152
|
-
}
|
|
153
|
-
GetInsertPayload() {
|
|
154
|
-
const payload = {
|
|
155
|
-
data: {
|
|
156
|
-
type: this.type,
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
if ((0, json_1.isDefined)(this.id))
|
|
160
|
-
payload.data.id = this.id;
|
|
161
|
-
if ((0, json_1.isDefined)(this.attributes)) {
|
|
162
|
-
payload.data.attributes = this.SerializeAttributesPayload(this.shadowAttributes, this.attributes);
|
|
163
|
-
}
|
|
164
|
-
if ((0, json_1.isDefined)(this.relationships)) {
|
|
165
|
-
payload.data.relationships = this.SerializeRelationshipsPayload(this.shadowRelationships, this.relationships);
|
|
166
|
-
}
|
|
167
|
-
(0, json_1.redactUndefinedValues)(payload);
|
|
168
|
-
return payload;
|
|
169
|
-
}
|
|
170
|
-
GetUpdatePayload() {
|
|
171
|
-
const payload = {
|
|
172
|
-
data: {
|
|
173
|
-
type: this.type,
|
|
174
|
-
id: this.id,
|
|
175
|
-
},
|
|
176
|
-
};
|
|
177
|
-
if ((0, json_1.isDefined)(this.attributes)) {
|
|
178
|
-
payload.data.attributes = this.SerializeAttributesPayload(this.shadowAttributes, this.attributes);
|
|
179
|
-
}
|
|
180
|
-
if ((0, json_1.isDefined)(this.relationships)) {
|
|
181
|
-
payload.data.relationships = this.SerializeRelationshipsPayload(this.shadowRelationships, this.relationships);
|
|
182
|
-
}
|
|
183
|
-
(0, json_1.redactUndefinedValues)(payload);
|
|
184
|
-
return payload;
|
|
185
|
-
}
|
|
186
|
-
Delete() {
|
|
187
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
yield this._container.Delete(this);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
GetHeaderValue(headers, key) {
|
|
192
|
-
let value;
|
|
193
|
-
for (const headerName in headers) {
|
|
194
|
-
if (headerName.toLowerCase() === key.toLowerCase()) {
|
|
195
|
-
value = headers[headerName];
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return value;
|
|
199
|
-
}
|
|
200
|
-
HasHeader(headers, key) {
|
|
201
|
-
let hasHeader = false;
|
|
202
|
-
for (const headerName in headers) {
|
|
203
|
-
if (headerName.toLowerCase() === key.toLowerCase()) {
|
|
204
|
-
hasHeader = true;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return hasHeader;
|
|
208
|
-
}
|
|
209
|
-
InsertResource() {
|
|
210
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
-
const queryUri = this._container.uri;
|
|
212
|
-
const queryHeaders = this._container.GetHeaders('INSERT');
|
|
213
|
-
const queryOptions = {};
|
|
214
|
-
const payload = this.GetInsertPayload();
|
|
215
|
-
const response = yield this._container.restClient.Post(queryUri, payload, queryHeaders, queryOptions);
|
|
216
|
-
if (!this.HasHeader(response.headers, 'location')) {
|
|
217
|
-
throw new __1.SDKException('INVALID-LOCATION', 'The save operation was unable to retrieve the location '
|
|
218
|
-
+ 'of the resource created by the API.');
|
|
219
|
-
}
|
|
220
|
-
if (!this.HasHeader(response.headers, 'x-api-resource-id')) {
|
|
221
|
-
throw new __1.SDKException('INVALID-RESOURCE-ID', 'The save operation was unable to retrieve the '
|
|
222
|
-
+ 'identifier of the resource created by the API.');
|
|
223
|
-
}
|
|
224
|
-
this.id = this.GetHeaderValue(response.headers, 'x-api-resource-id');
|
|
225
|
-
this._uri = this.GetHeaderValue(response.headers, 'location');
|
|
226
|
-
this._mode = ResourceObjectMode.ExistingDocument;
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
UpdateResource() {
|
|
230
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
-
const queryUri = this.uri;
|
|
232
|
-
const queryHeaders = this._container.GetHeaders('UPDATE');
|
|
233
|
-
const queryOptions = {};
|
|
234
|
-
const payload = this.GetUpdatePayload();
|
|
235
|
-
yield this._container.restClient.Patch(queryUri, payload, queryHeaders, queryOptions);
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
Save() {
|
|
239
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
-
if (this._mode === ResourceObjectMode.NewDocument) {
|
|
241
|
-
yield this.InsertResource();
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
yield this.UpdateResource();
|
|
245
|
-
}
|
|
246
|
-
if ((0, json_1.isDefined)(this.attributes)) {
|
|
247
|
-
this.shadowAttributes.LoadData(this.attributes, __1.ResourceObjectAttributesLoadType.Replace);
|
|
248
|
-
}
|
|
249
|
-
if ((0, json_1.isDefined)(this.relationships)) {
|
|
250
|
-
this.shadowRelationships.LoadData(this.relationships, __1.ResourceObjectRelationshipsLoadType.Replace);
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
get type() {
|
|
255
|
-
throw new Error('Method or Property not implemented.');
|
|
256
|
-
}
|
|
257
|
-
get id() {
|
|
258
|
-
return this._id;
|
|
259
|
-
}
|
|
260
|
-
set id(value) {
|
|
261
|
-
this._id = value;
|
|
262
|
-
}
|
|
263
|
-
get attributes() {
|
|
264
|
-
throw new Error('Method or Property not implemented.');
|
|
265
|
-
}
|
|
266
|
-
get relationships() {
|
|
267
|
-
throw new Error('Method or Property not implemented.');
|
|
268
|
-
}
|
|
269
|
-
get shadowAttributes() {
|
|
270
|
-
throw new Error('Method or Property not implemented.');
|
|
271
|
-
}
|
|
272
|
-
get shadowRelationships() {
|
|
273
|
-
throw new Error('Method or Property not implemented.');
|
|
274
|
-
}
|
|
275
|
-
get uri() {
|
|
276
|
-
return this._uri;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
exports.default = ResourceObject;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ResourceObjectMode = void 0;
|
|
13
|
+
const json_1 = require("@cloudize/json");
|
|
14
|
+
const __1 = require("..");
|
|
15
|
+
var ResourceObjectMode;
|
|
16
|
+
(function (ResourceObjectMode) {
|
|
17
|
+
ResourceObjectMode[ResourceObjectMode["NewDocument"] = 0] = "NewDocument";
|
|
18
|
+
ResourceObjectMode[ResourceObjectMode["ExistingDocument"] = 1] = "ExistingDocument";
|
|
19
|
+
})(ResourceObjectMode = exports.ResourceObjectMode || (exports.ResourceObjectMode = {}));
|
|
20
|
+
class ResourceObject {
|
|
21
|
+
constructor(container, mode) {
|
|
22
|
+
this._mode = ResourceObjectMode.NewDocument;
|
|
23
|
+
this._container = container;
|
|
24
|
+
this._mode = mode;
|
|
25
|
+
}
|
|
26
|
+
EndpointContentType() {
|
|
27
|
+
throw new Error('Method or Property not implemented.');
|
|
28
|
+
}
|
|
29
|
+
LoadAttributes(value) {
|
|
30
|
+
throw new Error('Method or Property not implemented.');
|
|
31
|
+
}
|
|
32
|
+
LoadRelationships(value) {
|
|
33
|
+
throw new Error('Method or Property not implemented.');
|
|
34
|
+
}
|
|
35
|
+
RelationshipType(relationshipName) {
|
|
36
|
+
throw new Error('Method or Property not implemented.');
|
|
37
|
+
}
|
|
38
|
+
UpdateAttributes(value) {
|
|
39
|
+
throw new Error('Method or Property not implemented.');
|
|
40
|
+
}
|
|
41
|
+
UpdateRelationships(value) {
|
|
42
|
+
throw new Error('Method or Property not implemented.');
|
|
43
|
+
}
|
|
44
|
+
LoadData(value) {
|
|
45
|
+
if (!(0, json_1.hasProperty)(value, 'type') || (value.type !== this.type)) {
|
|
46
|
+
throw new __1.SDKException('INVALID-RESOURCE-MAPPING', 'The resource data being loaded cannot be '
|
|
47
|
+
+ 'read into this object');
|
|
48
|
+
}
|
|
49
|
+
if ((0, json_1.hasProperty)(value, 'id'))
|
|
50
|
+
this._id = value.id;
|
|
51
|
+
if ((0, json_1.hasProperty)(value, 'attributes'))
|
|
52
|
+
this.LoadAttributes(value.attributes);
|
|
53
|
+
if ((0, json_1.hasProperty)(value, 'relationships'))
|
|
54
|
+
this.LoadRelationships(value.relationships);
|
|
55
|
+
if ((0, json_1.hasProperty)(value, 'links') && (0, json_1.isObject)(value.links) && (0, json_1.hasProperty)(value.links, 'self')
|
|
56
|
+
&& (0, json_1.isString)(value.links.self)) {
|
|
57
|
+
this._uri = value.links.self;
|
|
58
|
+
}
|
|
59
|
+
this._mode = ResourceObjectMode.ExistingDocument;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
SerializeAttributesPayload(shadow, data) {
|
|
63
|
+
if ((0, json_1.areEqual)(shadow, data))
|
|
64
|
+
return undefined;
|
|
65
|
+
if ((0, json_1.isUndefined)(data) && (0, json_1.isUndefined)(shadow))
|
|
66
|
+
return undefined;
|
|
67
|
+
if ((0, json_1.isUndefined)(shadow))
|
|
68
|
+
return data;
|
|
69
|
+
if ((0, json_1.isDate)(data))
|
|
70
|
+
return data;
|
|
71
|
+
if ((0, json_1.isArray)(data))
|
|
72
|
+
return data;
|
|
73
|
+
if ((0, json_1.isObject)(data)) {
|
|
74
|
+
if ((Object.keys(data).length === 2)
|
|
75
|
+
&& ((0, json_1.hasProperty)(data, 'latitude') && (0, json_1.isNumber)(data.latitude))
|
|
76
|
+
&& ((0, json_1.hasProperty)(data, 'longitude') && (0, json_1.isNumber)(data.longitude))) {
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
const payload = {};
|
|
80
|
+
for (const fieldName in data) {
|
|
81
|
+
if ((0, json_1.hasProperty)(data, fieldName)) {
|
|
82
|
+
if ((0, json_1.isDefined)(shadow))
|
|
83
|
+
payload[fieldName] = this.SerializeAttributesPayload(shadow[fieldName], data[fieldName]);
|
|
84
|
+
else
|
|
85
|
+
payload[fieldName] = this.SerializeAttributesPayload(undefined, data[fieldName]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if ((0, json_1.isDefined)(shadow) && (0, json_1.isObject)(shadow)) {
|
|
89
|
+
for (const fieldName in shadow) {
|
|
90
|
+
if ((0, json_1.hasProperty)(shadow, fieldName)) {
|
|
91
|
+
if ((0, json_1.isDefinedAndNotNull)(shadow[fieldName]) && (0, json_1.isUndefinedOrNull)(data[fieldName]))
|
|
92
|
+
payload[fieldName] = null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return payload;
|
|
97
|
+
}
|
|
98
|
+
return data;
|
|
99
|
+
}
|
|
100
|
+
SerializeRelationshipsPayload(shadow, data) {
|
|
101
|
+
if ((0, json_1.areEqual)(shadow, data))
|
|
102
|
+
return undefined;
|
|
103
|
+
if ((0, json_1.isUndefined)(data) && (0, json_1.isUndefined)(shadow))
|
|
104
|
+
return undefined;
|
|
105
|
+
if ((0, json_1.isObject)(data)) {
|
|
106
|
+
const payload = {};
|
|
107
|
+
for (const fieldName in data) {
|
|
108
|
+
if ((0, json_1.hasProperty)(data, fieldName)) {
|
|
109
|
+
if ((0, json_1.isDefinedAndNotNull)(data[fieldName])) {
|
|
110
|
+
if ((0, __1.isResourceObjectRelationships)(data[fieldName])) {
|
|
111
|
+
payload[fieldName] = {
|
|
112
|
+
data: [],
|
|
113
|
+
};
|
|
114
|
+
for (const relationship of data[fieldName]) {
|
|
115
|
+
payload[fieldName].data.push({
|
|
116
|
+
type: relationship.type,
|
|
117
|
+
id: relationship.id,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if ((0, __1.isResourceObjectRelationship)(data[fieldName])) {
|
|
122
|
+
if ((0, json_1.isUndefined)(shadow)
|
|
123
|
+
|| (0, json_1.isUndefined)(shadow[fieldName])
|
|
124
|
+
|| ((shadow[fieldName].type !== data[fieldName].type) || (shadow[fieldName].id !== data[fieldName].id))) {
|
|
125
|
+
if (data[fieldName].id === null) {
|
|
126
|
+
payload[fieldName] = { data: null };
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
payload[fieldName] = {
|
|
130
|
+
data: {
|
|
131
|
+
type: data[fieldName].type,
|
|
132
|
+
id: data[fieldName].id,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if ((0, json_1.isDefined)(shadow) && (0, json_1.isObject)(shadow)) {
|
|
142
|
+
for (const fieldName in shadow) {
|
|
143
|
+
if ((0, json_1.hasProperty)(shadow, fieldName)) {
|
|
144
|
+
if ((0, json_1.isDefinedAndNotNull)(shadow[fieldName]) && (0, json_1.isUndefinedOrNull)(data[fieldName]))
|
|
145
|
+
payload[fieldName] = null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return payload;
|
|
150
|
+
}
|
|
151
|
+
return data;
|
|
152
|
+
}
|
|
153
|
+
GetInsertPayload() {
|
|
154
|
+
const payload = {
|
|
155
|
+
data: {
|
|
156
|
+
type: this.type,
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
if ((0, json_1.isDefined)(this.id))
|
|
160
|
+
payload.data.id = this.id;
|
|
161
|
+
if ((0, json_1.isDefined)(this.attributes)) {
|
|
162
|
+
payload.data.attributes = this.SerializeAttributesPayload(this.shadowAttributes, this.attributes);
|
|
163
|
+
}
|
|
164
|
+
if ((0, json_1.isDefined)(this.relationships)) {
|
|
165
|
+
payload.data.relationships = this.SerializeRelationshipsPayload(this.shadowRelationships, this.relationships);
|
|
166
|
+
}
|
|
167
|
+
(0, json_1.redactUndefinedValues)(payload);
|
|
168
|
+
return payload;
|
|
169
|
+
}
|
|
170
|
+
GetUpdatePayload() {
|
|
171
|
+
const payload = {
|
|
172
|
+
data: {
|
|
173
|
+
type: this.type,
|
|
174
|
+
id: this.id,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
if ((0, json_1.isDefined)(this.attributes)) {
|
|
178
|
+
payload.data.attributes = this.SerializeAttributesPayload(this.shadowAttributes, this.attributes);
|
|
179
|
+
}
|
|
180
|
+
if ((0, json_1.isDefined)(this.relationships)) {
|
|
181
|
+
payload.data.relationships = this.SerializeRelationshipsPayload(this.shadowRelationships, this.relationships);
|
|
182
|
+
}
|
|
183
|
+
(0, json_1.redactUndefinedValues)(payload);
|
|
184
|
+
return payload;
|
|
185
|
+
}
|
|
186
|
+
Delete() {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
yield this._container.Delete(this);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
GetHeaderValue(headers, key) {
|
|
192
|
+
let value;
|
|
193
|
+
for (const headerName in headers) {
|
|
194
|
+
if (headerName.toLowerCase() === key.toLowerCase()) {
|
|
195
|
+
value = headers[headerName];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
HasHeader(headers, key) {
|
|
201
|
+
let hasHeader = false;
|
|
202
|
+
for (const headerName in headers) {
|
|
203
|
+
if (headerName.toLowerCase() === key.toLowerCase()) {
|
|
204
|
+
hasHeader = true;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return hasHeader;
|
|
208
|
+
}
|
|
209
|
+
InsertResource() {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
const queryUri = this._container.uri;
|
|
212
|
+
const queryHeaders = this._container.GetHeaders('INSERT');
|
|
213
|
+
const queryOptions = {};
|
|
214
|
+
const payload = this.GetInsertPayload();
|
|
215
|
+
const response = yield this._container.restClient.Post(queryUri, payload, queryHeaders, queryOptions);
|
|
216
|
+
if (!this.HasHeader(response.headers, 'location')) {
|
|
217
|
+
throw new __1.SDKException('INVALID-LOCATION', 'The save operation was unable to retrieve the location '
|
|
218
|
+
+ 'of the resource created by the API.');
|
|
219
|
+
}
|
|
220
|
+
if (!this.HasHeader(response.headers, 'x-api-resource-id')) {
|
|
221
|
+
throw new __1.SDKException('INVALID-RESOURCE-ID', 'The save operation was unable to retrieve the '
|
|
222
|
+
+ 'identifier of the resource created by the API.');
|
|
223
|
+
}
|
|
224
|
+
this.id = this.GetHeaderValue(response.headers, 'x-api-resource-id');
|
|
225
|
+
this._uri = this.GetHeaderValue(response.headers, 'location');
|
|
226
|
+
this._mode = ResourceObjectMode.ExistingDocument;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
UpdateResource() {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
const queryUri = this.uri;
|
|
232
|
+
const queryHeaders = this._container.GetHeaders('UPDATE');
|
|
233
|
+
const queryOptions = {};
|
|
234
|
+
const payload = this.GetUpdatePayload();
|
|
235
|
+
yield this._container.restClient.Patch(queryUri, payload, queryHeaders, queryOptions);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
Save() {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
if (this._mode === ResourceObjectMode.NewDocument) {
|
|
241
|
+
yield this.InsertResource();
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
yield this.UpdateResource();
|
|
245
|
+
}
|
|
246
|
+
if ((0, json_1.isDefined)(this.attributes)) {
|
|
247
|
+
this.shadowAttributes.LoadData(this.attributes, __1.ResourceObjectAttributesLoadType.Replace);
|
|
248
|
+
}
|
|
249
|
+
if ((0, json_1.isDefined)(this.relationships)) {
|
|
250
|
+
this.shadowRelationships.LoadData(this.relationships, __1.ResourceObjectRelationshipsLoadType.Replace);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
get type() {
|
|
255
|
+
throw new Error('Method or Property not implemented.');
|
|
256
|
+
}
|
|
257
|
+
get id() {
|
|
258
|
+
return this._id;
|
|
259
|
+
}
|
|
260
|
+
set id(value) {
|
|
261
|
+
this._id = value;
|
|
262
|
+
}
|
|
263
|
+
get attributes() {
|
|
264
|
+
throw new Error('Method or Property not implemented.');
|
|
265
|
+
}
|
|
266
|
+
get relationships() {
|
|
267
|
+
throw new Error('Method or Property not implemented.');
|
|
268
|
+
}
|
|
269
|
+
get shadowAttributes() {
|
|
270
|
+
throw new Error('Method or Property not implemented.');
|
|
271
|
+
}
|
|
272
|
+
get shadowRelationships() {
|
|
273
|
+
throw new Error('Method or Property not implemented.');
|
|
274
|
+
}
|
|
275
|
+
get uri() {
|
|
276
|
+
return this._uri;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
exports.default = ResourceObject;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type ResourcePathParams = {
|
|
2
|
-
[index: string]: string;
|
|
3
|
-
};
|
|
1
|
+
export type ResourcePathParams = {
|
|
2
|
+
[index: string]: string;
|
|
3
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|