@cloudize/sdk-core 23.1.3

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.
@@ -0,0 +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;
@@ -0,0 +1,3 @@
1
+ export type ResourcePathParams = {
2
+ [index: string]: string;
3
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ import { ResourceObjectClass } from './resource.object';
2
+ export type SDKResourceMap = {
3
+ [index: string]: ResourceObjectClass;
4
+ };
5
+ export declare class SDKConfiguration {
6
+ private _accessToken;
7
+ private _apiKey;
8
+ private _hostName;
9
+ private _resourceMap;
10
+ constructor();
11
+ RegisterResourceClass(type: string, resourceClass: ResourceObjectClass): void;
12
+ ResourceClass(type: string): ResourceObjectClass;
13
+ FormatURL(path: string): string;
14
+ get accessToken(): string;
15
+ set accessToken(value: string);
16
+ get apiKey(): string;
17
+ set apiKey(value: string);
18
+ get hostName(): string;
19
+ set hostName(value: string);
20
+ }
21
+ export declare function SDKConfig(): SDKConfiguration;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDKConfig = exports.SDKConfiguration = void 0;
4
+ const json_1 = require("@cloudize/json");
5
+ class SDKConfiguration {
6
+ constructor() {
7
+ this._resourceMap = {};
8
+ }
9
+ RegisterResourceClass(type, resourceClass) {
10
+ this._resourceMap[type] = resourceClass;
11
+ }
12
+ ResourceClass(type) {
13
+ return this._resourceMap[type];
14
+ }
15
+ FormatURL(path) {
16
+ let url = this.hostName;
17
+ url = url.endsWith('/') ? url.slice(0, -1) : url;
18
+ return path.startsWith('/') ? `${url}${path}` : `${url}/${path}`;
19
+ }
20
+ get accessToken() {
21
+ return this._accessToken;
22
+ }
23
+ set accessToken(value) {
24
+ this._accessToken = value;
25
+ }
26
+ get apiKey() {
27
+ return this._apiKey;
28
+ }
29
+ set apiKey(value) {
30
+ this._apiKey = value;
31
+ }
32
+ get hostName() {
33
+ return this._hostName;
34
+ }
35
+ set hostName(value) {
36
+ this._hostName = value;
37
+ }
38
+ }
39
+ exports.SDKConfiguration = SDKConfiguration;
40
+ let configInstance;
41
+ function SDKConfig() {
42
+ if ((0, json_1.isUndefined)(configInstance))
43
+ configInstance = new SDKConfiguration();
44
+ return configInstance;
45
+ }
46
+ exports.SDKConfig = SDKConfig;
@@ -0,0 +1 @@
1
+ export { default as SDKException } from './sdk.exception';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SDKException = void 0;
7
+ var sdk_exception_1 = require("./sdk.exception");
8
+ Object.defineProperty(exports, "SDKException", { enumerable: true, get: function () { return __importDefault(sdk_exception_1).default; } });
@@ -0,0 +1,6 @@
1
+ import { ISDKException } from '..';
2
+ export default class SDKException extends Error implements ISDKException {
3
+ private _code;
4
+ constructor(code: string, message: string);
5
+ get code(): string;
6
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class SDKException extends Error {
4
+ constructor(code, message) {
5
+ super(message);
6
+ this._code = '';
7
+ this.name = 'SDKException';
8
+ this._code = code;
9
+ }
10
+ get code() {
11
+ return this._code;
12
+ }
13
+ }
14
+ exports.default = SDKException;
@@ -0,0 +1,3 @@
1
+ import { GeospatialPoint } from '../interfaces';
2
+ export declare function LoadDateTime(value: string): Date;
3
+ export declare function LoadGeospatialPoint(geospatialPoint: GeospatialPoint, value: any): GeospatialPoint;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoadGeospatialPoint = exports.LoadDateTime = void 0;
4
+ const json_1 = require("@cloudize/json");
5
+ const interfaces_1 = require("../interfaces");
6
+ function LoadDateTime(value) {
7
+ if ((0, json_1.isDefined)(value))
8
+ return new Date(value);
9
+ return undefined;
10
+ }
11
+ exports.LoadDateTime = LoadDateTime;
12
+ function LoadGeospatialPoint(geospatialPoint, value) {
13
+ if ((0, json_1.isUndefinedOrNull)(geospatialPoint)) {
14
+ if ((0, json_1.isDefined)(value) && (0, json_1.isObject)(value) && (Object.keys(value).length === 2)
15
+ && (0, json_1.hasProperty)(value, 'longitude') && (0, json_1.isNumber)(value.longitude)
16
+ && (0, json_1.hasProperty)(value, 'latitude') && (0, json_1.isNumber)(value.latitude)) {
17
+ const result = new interfaces_1.GeospatialPoint();
18
+ result.LoadData(value);
19
+ return result;
20
+ }
21
+ }
22
+ else if ((0, json_1.isDefined)(value) && (0, json_1.isObject)(value) && (Object.keys(value).length <= 2)
23
+ && (((0, json_1.hasProperty)(value, 'longitude') && (0, json_1.isNumber)(value.longitude))
24
+ || ((0, json_1.hasProperty)(value, 'latitude') && (0, json_1.isNumber)(value.latitude)))) {
25
+ geospatialPoint.LoadData(value);
26
+ return geospatialPoint;
27
+ }
28
+ return undefined;
29
+ }
30
+ exports.LoadGeospatialPoint = LoadGeospatialPoint;
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './interfaces';
2
+ export * from './exceptions';
3
+ export * from './classes';
4
+ export * from './helpers';
5
+ export * from './type-guards';
package/lib/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./interfaces"), exports);
18
+ __exportStar(require("./exceptions"), exports);
19
+ __exportStar(require("./classes"), exports);
20
+ __exportStar(require("./helpers"), exports);
21
+ __exportStar(require("./type-guards"), exports);
@@ -0,0 +1,2 @@
1
+ export { ISDKError, ISDKRequestError, ISDKException, ISDKRequestException, } from './sdk.errors';
2
+ export { IResourceContainer, ResourceContainerIncludedResourceTypes, ResourceFilterName, ResourceFilterValue, ResourceSortOption, ResourceIncludeOption, IResourceObject, IResourceObjectAttributes, IResourceObjectRelationships, GeospatialPoint, ResourceObjectAttributeBase, ResourceObjectAttributesLoadType, ResourceObjectRelationshipLinkObject, ResourceObjectRelationshipLink, ResourceObjectRelationshipsLinks, ResourceObjectRelationshipsLoadType, ResourceObjectRelationship, ResourceObjectRelationships, ResourceObjectUri, ResourceObjectRelationshipBase, } from './resource.interfaces';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResourceObjectRelationshipBase = exports.ResourceObjectRelationship = exports.ResourceObjectRelationshipsLoadType = exports.ResourceObjectAttributesLoadType = exports.ResourceObjectAttributeBase = exports.GeospatialPoint = void 0;
4
+ var resource_interfaces_1 = require("./resource.interfaces");
5
+ Object.defineProperty(exports, "GeospatialPoint", { enumerable: true, get: function () { return resource_interfaces_1.GeospatialPoint; } });
6
+ Object.defineProperty(exports, "ResourceObjectAttributeBase", { enumerable: true, get: function () { return resource_interfaces_1.ResourceObjectAttributeBase; } });
7
+ Object.defineProperty(exports, "ResourceObjectAttributesLoadType", { enumerable: true, get: function () { return resource_interfaces_1.ResourceObjectAttributesLoadType; } });
8
+ Object.defineProperty(exports, "ResourceObjectRelationshipsLoadType", { enumerable: true, get: function () { return resource_interfaces_1.ResourceObjectRelationshipsLoadType; } });
9
+ Object.defineProperty(exports, "ResourceObjectRelationship", { enumerable: true, get: function () { return resource_interfaces_1.ResourceObjectRelationship; } });
10
+ Object.defineProperty(exports, "ResourceObjectRelationshipBase", { enumerable: true, get: function () { return resource_interfaces_1.ResourceObjectRelationshipBase; } });
@@ -0,0 +1,94 @@
1
+ import { IRestClient } from '@cloudize/rest-client';
2
+ import { ResourceFilterType, ResourceHeaderParams } from '../classes';
3
+ export type ResourceObjectType = string;
4
+ export type ResourceObjectIdentifier = string;
5
+ export declare enum ResourceObjectAttributesLoadType {
6
+ Replace = 0,
7
+ Update = 1
8
+ }
9
+ export interface IResourceObjectAttributes {
10
+ LoadData(data: any, action: ResourceObjectAttributesLoadType): void;
11
+ }
12
+ export type ResourceObjectRelationshipLinkObject = {
13
+ type: ResourceObjectType;
14
+ id: ResourceObjectIdentifier;
15
+ };
16
+ export type ResourceObjectRelationshipLink = {
17
+ data: ResourceObjectRelationshipLinkObject;
18
+ };
19
+ export type ResourceObjectRelationshipsLinks = {
20
+ data: ResourceObjectRelationshipLinkObject[];
21
+ };
22
+ export type ResourceContainerIncludedResources = {
23
+ [id: string]: IResourceObject;
24
+ };
25
+ export type ResourceContainerIncludedResourceTypes = {
26
+ [type: string]: ResourceContainerIncludedResources;
27
+ };
28
+ export declare class ResourceObjectRelationship {
29
+ private _includes;
30
+ readonly type: ResourceObjectType;
31
+ id: ResourceObjectIdentifier | null;
32
+ constructor(includes: ResourceContainerIncludedResourceTypes, type: ResourceObjectType, id?: ResourceObjectIdentifier);
33
+ clear(): void;
34
+ get target(): IResourceObject;
35
+ }
36
+ export type ResourceObjectRelationships = ResourceObjectRelationship[];
37
+ export declare enum ResourceObjectRelationshipsLoadType {
38
+ Replace = 0,
39
+ Update = 1
40
+ }
41
+ export interface IResourceObjectRelationships {
42
+ LoadData(data: any, action: ResourceObjectRelationshipsLoadType): void;
43
+ }
44
+ export type ResourceObjectUri = string;
45
+ export declare class ResourceObjectAttributeBase {
46
+ protected static LoadDateTime(value: string): Date;
47
+ protected static LoadGeospatialPoint(geospatialPoint: GeospatialPoint, value: any): GeospatialPoint;
48
+ }
49
+ export declare class GeospatialPoint extends ResourceObjectAttributeBase implements IResourceObjectAttributes {
50
+ longitude: number;
51
+ latitude: number;
52
+ LoadData(data: any): void;
53
+ }
54
+ export declare class ResourceObjectRelationshipBase {
55
+ private _includes;
56
+ constructor(includes: ResourceContainerIncludedResourceTypes);
57
+ protected LoadRelationship(expectedType: string, value: any): ResourceObjectRelationship;
58
+ protected LoadRelationships(expectedType: string, value: any): ResourceObjectRelationships;
59
+ static RelationshipType(relationshipName: string): string;
60
+ }
61
+ export interface IResourceObject {
62
+ type: ResourceObjectType;
63
+ id?: ResourceObjectIdentifier;
64
+ attributes: IResourceObjectAttributes;
65
+ relationships: IResourceObjectRelationships;
66
+ uri: ResourceObjectUri;
67
+ LoadData(value: any): IResourceObject;
68
+ Delete(): Promise<void>;
69
+ Save(): Promise<void>;
70
+ UpdateAttributes(value: any): void;
71
+ UpdateRelationships(value: any): void;
72
+ }
73
+ export type ResourceFilterName = string;
74
+ export type ResourceFilterValue = string;
75
+ export type ResourceSortOption = string;
76
+ export type ResourceIncludeOption = string;
77
+ export interface IResourceContainer {
78
+ data: IResourceObject | IResourceObject[];
79
+ includes: ResourceContainerIncludedResourceTypes;
80
+ restClient: IRestClient;
81
+ uri: string;
82
+ Filter(filter: ResourceFilterName, selector: ResourceFilterType, value: ResourceFilterValue): IResourceContainer;
83
+ GetHeaders(action: string): ResourceHeaderParams;
84
+ Sort(option: ResourceSortOption): IResourceContainer;
85
+ Include(include: ResourceIncludeOption): IResourceContainer;
86
+ PageOffset(pageOffset: number, pageSize: number): IResourceContainer;
87
+ PageNumber(pageNumber: number, pageSize: number): IResourceContainer;
88
+ Add(): IResourceObject;
89
+ Count(): Promise<number>;
90
+ Delete(resource: IResourceObject): Promise<void>;
91
+ Find(): Promise<void>;
92
+ Get(id: string): Promise<void>;
93
+ IncludedObject(type: ResourceObjectType, id: ResourceObjectIdentifier): IResourceObject;
94
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResourceObjectRelationshipBase = exports.GeospatialPoint = exports.ResourceObjectAttributeBase = exports.ResourceObjectRelationshipsLoadType = exports.ResourceObjectRelationship = exports.ResourceObjectAttributesLoadType = void 0;
4
+ const json_1 = require("@cloudize/json");
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
+ class ResourceObjectRelationship {
12
+ constructor(includes, type, id) {
13
+ this._includes = includes;
14
+ this.type = type;
15
+ if (id)
16
+ this.id = id;
17
+ }
18
+ clear() {
19
+ this.id = null;
20
+ }
21
+ get target() {
22
+ if ((0, json_1.isDefined)(this.type) && (0, json_1.isDefined)(this.id) && (0, json_1.isDefined)(this._includes[this.type][this.id])) {
23
+ return this._includes[this.type][this.id];
24
+ }
25
+ return undefined;
26
+ }
27
+ }
28
+ exports.ResourceObjectRelationship = ResourceObjectRelationship;
29
+ var ResourceObjectRelationshipsLoadType;
30
+ (function (ResourceObjectRelationshipsLoadType) {
31
+ ResourceObjectRelationshipsLoadType[ResourceObjectRelationshipsLoadType["Replace"] = 0] = "Replace";
32
+ ResourceObjectRelationshipsLoadType[ResourceObjectRelationshipsLoadType["Update"] = 1] = "Update";
33
+ })(ResourceObjectRelationshipsLoadType = exports.ResourceObjectRelationshipsLoadType || (exports.ResourceObjectRelationshipsLoadType = {}));
34
+ class ResourceObjectAttributeBase {
35
+ static LoadDateTime(value) {
36
+ return (0, helpers_1.LoadDateTime)(value);
37
+ }
38
+ static LoadGeospatialPoint(geospatialPoint, value) {
39
+ return (0, helpers_1.LoadGeospatialPoint)(geospatialPoint, value);
40
+ }
41
+ }
42
+ exports.ResourceObjectAttributeBase = ResourceObjectAttributeBase;
43
+ class GeospatialPoint extends ResourceObjectAttributeBase {
44
+ LoadData(data) {
45
+ if ((0, json_1.hasProperty)(data, 'longitude'))
46
+ this.longitude = data.longitude;
47
+ if ((0, json_1.hasProperty)(data, 'latitude'))
48
+ this.latitude = data.latitude;
49
+ }
50
+ }
51
+ exports.GeospatialPoint = GeospatialPoint;
52
+ class ResourceObjectRelationshipBase {
53
+ constructor(includes) {
54
+ this._includes = includes;
55
+ }
56
+ LoadRelationship(expectedType, value) {
57
+ if ((0, json_1.isObject)(value)) {
58
+ if ((0, json_1.hasProperty)(value, 'data') && (0, json_1.isObject)(value.data) && (Object.keys(value.data).length === 2)
59
+ && (0, json_1.hasProperty)(value.data, 'type') && (0, json_1.isString)(value.data.type)
60
+ && (value.data.type === expectedType)
61
+ && (0, json_1.hasProperty)(value.data, 'id') && (0, json_1.isString)(value.data.id)) {
62
+ return new ResourceObjectRelationship(this._includes, value.data.type, value.data.id);
63
+ }
64
+ if ((Object.keys(value).length === 1) && (0, json_1.hasProperty)(value, 'id') && (0, json_1.isString)(value.id)) {
65
+ return new ResourceObjectRelationship(this._includes, expectedType, value.id);
66
+ }
67
+ }
68
+ return undefined;
69
+ }
70
+ LoadRelationships(expectedType, value) {
71
+ if ((0, json_1.isObject)(value)) {
72
+ if ((0, json_1.hasProperty)(value, 'data') && (0, json_1.isArray)(value.data)) {
73
+ const relationships = [];
74
+ for (const relationship of value.data) {
75
+ if ((0, json_1.isObject)(relationship) && (Object.keys(relationship).length === 2)
76
+ && (0, json_1.hasProperty)(relationship, 'type') && (0, json_1.isString)(relationship.type)
77
+ && (relationship.type === expectedType)
78
+ && (0, json_1.hasProperty)(relationship, 'id') && (0, json_1.isString)(relationship.id)) {
79
+ relationships.push(new ResourceObjectRelationship(this._includes, relationship.type, relationship.id));
80
+ }
81
+ }
82
+ return relationships;
83
+ }
84
+ }
85
+ else if ((0, json_1.isArray)(value)) {
86
+ const relationships = [];
87
+ for (const relationship of value) {
88
+ if ((0, json_1.isObject)(relationship) && (Object.keys(relationship).length === 1)
89
+ && (0, json_1.hasProperty)(relationship, 'id') && (0, json_1.isString)(relationship.id)) {
90
+ relationships.push(new ResourceObjectRelationship(this._includes, expectedType, relationship.id));
91
+ }
92
+ }
93
+ return relationships;
94
+ }
95
+ return undefined;
96
+ }
97
+ static RelationshipType(relationshipName) {
98
+ throw new Error('Method or Property not implemented.');
99
+ }
100
+ }
101
+ exports.ResourceObjectRelationshipBase = ResourceObjectRelationshipBase;