@apigames/sdk-core 22.1.10 → 22.1.11
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.js +2 -1
- package/lib/classes/resource.object.d.ts +1 -1
- package/lib/classes/resource.object.js +28 -23
- package/lib/interfaces/index.d.ts +1 -1
- package/lib/interfaces/index.js +3 -1
- package/lib/interfaces/resource.object.d.ts +10 -2
- package/lib/interfaces/resource.object.js +11 -1
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ exports.ResourceFilterType = void 0;
|
|
|
13
13
|
const json_1 = require("@apigames/json");
|
|
14
14
|
const rest_client_1 = require("@apigames/rest-client");
|
|
15
15
|
const __1 = require("..");
|
|
16
|
+
const resource_object_1 = require("./resource.object");
|
|
16
17
|
const hash = require('object-hash');
|
|
17
18
|
var ResourceFilterType;
|
|
18
19
|
(function (ResourceFilterType) {
|
|
@@ -98,7 +99,7 @@ class ResourceContainer {
|
|
|
98
99
|
if ((0, json_1.hasProperty)(resourceData, 'type') && (0, json_1.isString)(resourceData.type)) {
|
|
99
100
|
if ((0, json_1.hasProperty)(resourceData, 'id') && (0, json_1.isString)(resourceData.id)) {
|
|
100
101
|
const ResourceClass = (0, __1.SDKConfig)().ResourceClass(resourceData.type);
|
|
101
|
-
return new ResourceClass(this).LoadData(resourceData);
|
|
102
|
+
return new ResourceClass(this, resource_object_1.ResourceObjectMode.ExistingDocument).LoadData(resourceData);
|
|
102
103
|
}
|
|
103
104
|
throw new __1.SDKException('INVALID-RESOURCE-ID', 'The resource being loaded doesn\'t have the required resource id.');
|
|
104
105
|
}
|
|
@@ -8,7 +8,7 @@ export default class ResourceObject implements IResourceObject {
|
|
|
8
8
|
private _id;
|
|
9
9
|
private _mode;
|
|
10
10
|
private _uri;
|
|
11
|
-
constructor(container: IResourceContainer);
|
|
11
|
+
constructor(container: IResourceContainer, mode: ResourceObjectMode);
|
|
12
12
|
protected EndpointContentType(): string;
|
|
13
13
|
protected LoadAttributes(value: any): void;
|
|
14
14
|
protected LoadRelationships(value: any): void;
|
|
@@ -18,9 +18,10 @@ var ResourceObjectMode;
|
|
|
18
18
|
ResourceObjectMode[ResourceObjectMode["ExistingDocument"] = 1] = "ExistingDocument";
|
|
19
19
|
})(ResourceObjectMode = exports.ResourceObjectMode || (exports.ResourceObjectMode = {}));
|
|
20
20
|
class ResourceObject {
|
|
21
|
-
constructor(container) {
|
|
21
|
+
constructor(container, mode) {
|
|
22
22
|
this._mode = ResourceObjectMode.NewDocument;
|
|
23
23
|
this._container = container;
|
|
24
|
+
this._mode = mode;
|
|
24
25
|
}
|
|
25
26
|
EndpointContentType() {
|
|
26
27
|
throw new Error('Method or Property not implemented.');
|
|
@@ -63,6 +64,8 @@ class ResourceObject {
|
|
|
63
64
|
return undefined;
|
|
64
65
|
if ((0, json_1.isUndefined)(data) && (0, json_1.isUndefined)(shadow))
|
|
65
66
|
return undefined;
|
|
67
|
+
if ((0, json_1.isUndefined)(shadow))
|
|
68
|
+
return data;
|
|
66
69
|
if ((0, json_1.isArray)(data))
|
|
67
70
|
return data;
|
|
68
71
|
if ((0, json_1.isObject)(data)) {
|
|
@@ -83,7 +86,7 @@ class ResourceObject {
|
|
|
83
86
|
if ((0, json_1.isDefined)(shadow) && (0, json_1.isObject)(shadow)) {
|
|
84
87
|
for (const fieldName in shadow) {
|
|
85
88
|
if ((0, json_1.hasProperty)(shadow, fieldName)) {
|
|
86
|
-
if ((0, json_1.
|
|
89
|
+
if ((0, json_1.isDefinedAndNotNull)(shadow[fieldName]) && (0, json_1.isUndefinedOrNull)(data[fieldName]))
|
|
87
90
|
payload[fieldName] = null;
|
|
88
91
|
}
|
|
89
92
|
}
|
|
@@ -101,25 +104,27 @@ class ResourceObject {
|
|
|
101
104
|
const payload = {};
|
|
102
105
|
for (const fieldName in data) {
|
|
103
106
|
if ((0, json_1.hasProperty)(data, fieldName)) {
|
|
104
|
-
if ((0, json_1.
|
|
105
|
-
|
|
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])) {
|
|
107
|
+
if ((0, json_1.isDefinedAndNotNull)(data[fieldName])) {
|
|
108
|
+
if ((0, json_1.isArrayOfStrings)(data[fieldName])) {
|
|
117
109
|
payload[fieldName] = {
|
|
118
|
-
data:
|
|
119
|
-
type: this.RelationshipType(fieldName),
|
|
120
|
-
id: data[fieldName],
|
|
121
|
-
},
|
|
110
|
+
data: [],
|
|
122
111
|
};
|
|
112
|
+
for (const key of data[fieldName]) {
|
|
113
|
+
payload[fieldName].data.push({
|
|
114
|
+
type: this.RelationshipType(fieldName),
|
|
115
|
+
id: key,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if ((0, json_1.isString)(data[fieldName])) {
|
|
120
|
+
if ((0, json_1.isUndefined)(shadow) || !(0, json_1.areEqual)(shadow[fieldName], data[fieldName])) {
|
|
121
|
+
payload[fieldName] = {
|
|
122
|
+
data: {
|
|
123
|
+
type: this.RelationshipType(fieldName),
|
|
124
|
+
id: data[fieldName],
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
130
|
}
|
|
@@ -127,7 +132,7 @@ class ResourceObject {
|
|
|
127
132
|
if ((0, json_1.isDefined)(shadow) && (0, json_1.isObject)(shadow)) {
|
|
128
133
|
for (const fieldName in shadow) {
|
|
129
134
|
if ((0, json_1.hasProperty)(shadow, fieldName)) {
|
|
130
|
-
if ((0, json_1.
|
|
135
|
+
if ((0, json_1.isDefinedAndNotNull)(shadow[fieldName]) && (0, json_1.isUndefinedOrNull)(data[fieldName]))
|
|
131
136
|
payload[fieldName] = null;
|
|
132
137
|
}
|
|
133
138
|
}
|
|
@@ -230,7 +235,7 @@ class ResourceObject {
|
|
|
230
235
|
const queryUri = this.uri;
|
|
231
236
|
const queryHeaders = this.GetHeaders();
|
|
232
237
|
const queryOptions = {};
|
|
233
|
-
const payload = this.
|
|
238
|
+
const payload = this.GetUpdatePayload();
|
|
234
239
|
yield this._container.restClient.Patch(queryUri, payload, queryHeaders, queryOptions);
|
|
235
240
|
});
|
|
236
241
|
}
|
|
@@ -243,10 +248,10 @@ class ResourceObject {
|
|
|
243
248
|
yield this.UpdateResource();
|
|
244
249
|
}
|
|
245
250
|
if ((0, json_1.isDefined)(this.attributes)) {
|
|
246
|
-
this.shadowAttributes.LoadData(this.attributes);
|
|
251
|
+
this.shadowAttributes.LoadData(this.attributes, __1.ResourceObjectAttributesLoadType.Replace);
|
|
247
252
|
}
|
|
248
253
|
if ((0, json_1.isDefined)(this.relationships)) {
|
|
249
|
-
this.shadowRelationships.LoadData(this.relationships);
|
|
254
|
+
this.shadowRelationships.LoadData(this.relationships, __1.ResourceObjectRelationshipsLoadType.Replace);
|
|
250
255
|
}
|
|
251
256
|
});
|
|
252
257
|
}
|
|
@@ -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, ResourceObjectRelationshipKey, ResourceObjectRelationshipKeys, ResourceObjectUri, ResourceObjectRelationshipBase, } from './resource.object';
|
|
3
|
+
export { IResourceObject, IResourceObjectAttributes, IResourceObjectRelationships, GeospatialPoint, ResourceObjectAttributeBase, ResourceObjectAttributesLoadType, ResourceObjectRelationshipLinkObject, ResourceObjectRelationship, ResourceObjectRelationships, ResourceObjectRelationshipsLoadType, ResourceObjectRelationshipKey, ResourceObjectRelationshipKeys, ResourceObjectUri, ResourceObjectRelationshipBase, } from './resource.object';
|
package/lib/interfaces/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResourceObjectRelationshipBase = exports.ResourceObjectAttributeBase = exports.GeospatialPoint = void 0;
|
|
3
|
+
exports.ResourceObjectRelationshipBase = exports.ResourceObjectRelationshipsLoadType = exports.ResourceObjectAttributesLoadType = exports.ResourceObjectAttributeBase = exports.GeospatialPoint = void 0;
|
|
4
4
|
var resource_object_1 = require("./resource.object");
|
|
5
5
|
Object.defineProperty(exports, "GeospatialPoint", { enumerable: true, get: function () { return resource_object_1.GeospatialPoint; } });
|
|
6
6
|
Object.defineProperty(exports, "ResourceObjectAttributeBase", { enumerable: true, get: function () { return resource_object_1.ResourceObjectAttributeBase; } });
|
|
7
|
+
Object.defineProperty(exports, "ResourceObjectAttributesLoadType", { enumerable: true, get: function () { return resource_object_1.ResourceObjectAttributesLoadType; } });
|
|
8
|
+
Object.defineProperty(exports, "ResourceObjectRelationshipsLoadType", { enumerable: true, get: function () { return resource_object_1.ResourceObjectRelationshipsLoadType; } });
|
|
7
9
|
Object.defineProperty(exports, "ResourceObjectRelationshipBase", { enumerable: true, get: function () { return resource_object_1.ResourceObjectRelationshipBase; } });
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export declare type ResourceObjectType = string;
|
|
2
2
|
export declare type ResourceObjectIdentifier = string;
|
|
3
|
+
export declare enum ResourceObjectAttributesLoadType {
|
|
4
|
+
Replace = 0,
|
|
5
|
+
Update = 1
|
|
6
|
+
}
|
|
3
7
|
export interface IResourceObjectAttributes {
|
|
4
|
-
LoadData(data: any): void;
|
|
8
|
+
LoadData(data: any, action: ResourceObjectAttributesLoadType): void;
|
|
5
9
|
}
|
|
6
10
|
export declare type ResourceObjectRelationshipLinkObject = {
|
|
7
11
|
type: ResourceObjectType;
|
|
@@ -15,8 +19,12 @@ export declare type ResourceObjectRelationships = {
|
|
|
15
19
|
};
|
|
16
20
|
export declare type ResourceObjectRelationshipKey = string;
|
|
17
21
|
export declare type ResourceObjectRelationshipKeys = ResourceObjectRelationshipKey[];
|
|
22
|
+
export declare enum ResourceObjectRelationshipsLoadType {
|
|
23
|
+
Replace = 0,
|
|
24
|
+
Update = 1
|
|
25
|
+
}
|
|
18
26
|
export interface IResourceObjectRelationships {
|
|
19
|
-
LoadData(data: any): void;
|
|
27
|
+
LoadData(data: any, action: ResourceObjectRelationshipsLoadType): void;
|
|
20
28
|
}
|
|
21
29
|
export declare type ResourceObjectUri = string;
|
|
22
30
|
export declare class ResourceObjectAttributeBase {
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResourceObjectRelationshipBase = exports.GeospatialPoint = exports.ResourceObjectAttributeBase = void 0;
|
|
3
|
+
exports.ResourceObjectRelationshipBase = exports.GeospatialPoint = exports.ResourceObjectAttributeBase = exports.ResourceObjectRelationshipsLoadType = exports.ResourceObjectAttributesLoadType = void 0;
|
|
4
4
|
const json_1 = require("@apigames/json");
|
|
5
5
|
const helpers_1 = require("../helpers");
|
|
6
|
+
var ResourceObjectAttributesLoadType;
|
|
7
|
+
(function (ResourceObjectAttributesLoadType) {
|
|
8
|
+
ResourceObjectAttributesLoadType[ResourceObjectAttributesLoadType["Replace"] = 0] = "Replace";
|
|
9
|
+
ResourceObjectAttributesLoadType[ResourceObjectAttributesLoadType["Update"] = 1] = "Update";
|
|
10
|
+
})(ResourceObjectAttributesLoadType = exports.ResourceObjectAttributesLoadType || (exports.ResourceObjectAttributesLoadType = {}));
|
|
11
|
+
var ResourceObjectRelationshipsLoadType;
|
|
12
|
+
(function (ResourceObjectRelationshipsLoadType) {
|
|
13
|
+
ResourceObjectRelationshipsLoadType[ResourceObjectRelationshipsLoadType["Replace"] = 0] = "Replace";
|
|
14
|
+
ResourceObjectRelationshipsLoadType[ResourceObjectRelationshipsLoadType["Update"] = 1] = "Update";
|
|
15
|
+
})(ResourceObjectRelationshipsLoadType = exports.ResourceObjectRelationshipsLoadType || (exports.ResourceObjectRelationshipsLoadType = {}));
|
|
6
16
|
class ResourceObjectAttributeBase {
|
|
7
17
|
static LoadDateTime(value) {
|
|
8
18
|
return (0, helpers_1.LoadDateTime)(value);
|