@here/olp-sdk-dataservice-read 2.0.0 → 3.0.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.
Files changed (55) hide show
  1. package/README.md +3 -3
  2. package/bundle.umd.dev.js +12563 -76
  3. package/bundle.umd.min.js +1 -1
  4. package/index.js +5 -1
  5. package/index.web.js +5 -1
  6. package/lib/cache/MetadataCacheRepository.js +1 -0
  7. package/lib/cache/QuadTreeIndexCacheRepository.js +1 -0
  8. package/lib/cache/index.js +5 -1
  9. package/lib/client/ArtifactClient.d.ts +2 -1
  10. package/lib/client/ArtifactClient.js +31 -43
  11. package/lib/client/CatalogClient.d.ts +3 -1
  12. package/lib/client/CatalogClient.js +59 -78
  13. package/lib/client/CatalogRequest.js +4 -3
  14. package/lib/client/CatalogVersionRequest.js +6 -3
  15. package/lib/client/CatalogsRequest.js +5 -3
  16. package/lib/client/ConfigClient.d.ts +1 -1
  17. package/lib/client/ConfigClient.js +13 -23
  18. package/lib/client/DataRequest.js +7 -6
  19. package/lib/client/IndexLayerClient.d.ts +1 -1
  20. package/lib/client/IndexLayerClient.js +37 -40
  21. package/lib/client/IndexQueryRequest.js +2 -0
  22. package/lib/client/LayerVersionsRequest.js +5 -3
  23. package/lib/client/PartitionsRequest.js +10 -7
  24. package/lib/client/PollRequest.js +2 -0
  25. package/lib/client/QuadKeyPartitionsRequest.d.ts +1 -1
  26. package/lib/client/QuadKeyPartitionsRequest.js +7 -3
  27. package/lib/client/QuadTreeIndexRequest.d.ts +1 -1
  28. package/lib/client/QuadTreeIndexRequest.js +11 -3
  29. package/lib/client/QueryClient.d.ts +2 -1
  30. package/lib/client/QueryClient.js +85 -96
  31. package/lib/client/SchemaDetailsRequest.js +5 -3
  32. package/lib/client/SchemaRequest.js +5 -3
  33. package/lib/client/SeekRequest.js +3 -0
  34. package/lib/client/StatisticsClient.d.ts +2 -1
  35. package/lib/client/StatisticsClient.js +51 -65
  36. package/lib/client/StatisticsRequest.js +9 -4
  37. package/lib/client/StreamLayerClient.d.ts +4 -1
  38. package/lib/client/StreamLayerClient.js +117 -139
  39. package/lib/client/SubscribeRequest.js +4 -0
  40. package/lib/client/SummaryRequest.js +5 -2
  41. package/lib/client/TileRequest.js +6 -6
  42. package/lib/client/UnsubscribeRequest.js +2 -0
  43. package/lib/client/VersionedLayerClient.d.ts +4 -1
  44. package/lib/client/VersionedLayerClient.js +131 -135
  45. package/lib/client/VolatileLayerClient.d.ts +4 -1
  46. package/lib/client/VolatileLayerClient.js +104 -108
  47. package/lib/client/index.js +5 -1
  48. package/lib/index.js +5 -1
  49. package/lib/utils/getTile.d.ts +2 -1
  50. package/lib/utils/getTile.js +93 -99
  51. package/lib/utils/index.js +5 -1
  52. package/lib/utils/validateBillingTag.js +1 -2
  53. package/lib/utils/validatePartitionsIdsList.js +1 -2
  54. package/package.json +11 -55
  55. package/webpack.config.js +2 -7
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (C) 2019-2021 HERE Europe B.V.
3
+ * Copyright (C) 2019-2026 HERE Europe B.V.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -17,31 +17,41 @@
17
17
  * SPDX-License-Identifier: Apache-2.0
18
18
  * License-Filename: LICENSE
19
19
  */
20
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
21
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
- return new (P || (P = Promise))(function (resolve, reject) {
23
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
- step((generator = generator.apply(thisArg, _arguments || [])).next());
27
- });
28
- };
29
20
  Object.defineProperty(exports, "__esModule", { value: true });
30
21
  exports.VersionedLayerClient = void 0;
31
22
  const olp_sdk_core_1 = require("@here/olp-sdk-core");
32
23
  const olp_sdk_dataservice_api_1 = require("@here/olp-sdk-dataservice-api");
33
- const olp_sdk_dataservice_read_1 = require("@here/olp-sdk-dataservice-read");
24
+ const MetadataCacheRepository_1 = require("../cache/MetadataCacheRepository");
25
+ const getTile_1 = require("../utils/getTile");
26
+ const PartitionsRequest_1 = require("./PartitionsRequest");
27
+ const QuadKeyPartitionsRequest_1 = require("./QuadKeyPartitionsRequest");
28
+ const QuadTreeIndexRequest_1 = require("./QuadTreeIndexRequest");
29
+ const QueryClient_1 = require("./QueryClient");
34
30
  /**
35
31
  * Describes a versioned layer and provides the possibility to get partitions metadata and data.
36
32
  */
37
33
  class VersionedLayerClient {
34
+ apiVersion = "v1";
35
+ /**
36
+ * HRN of the catalog.
37
+ */
38
+ hrn;
39
+ /**
40
+ * The ID of the layer.
41
+ */
42
+ layerId;
43
+ /**
44
+ * The [[OlpClientSettings]] instance.
45
+ */
46
+ settings;
47
+ // Layer version.
48
+ version;
38
49
  /**
39
50
  * Creates the [[VersionedLayerClient]] instance with VersionedLayerClientParams.
40
51
  *
41
52
  * @param params parameters for use to initialize VersionLayerClient.
42
53
  */
43
54
  constructor(params) {
44
- this.apiVersion = "v1";
45
55
  this.hrn = params.catalogHrn.toString();
46
56
  this.layerId = params.layerId;
47
57
  this.settings = params.settings;
@@ -62,21 +72,19 @@ class VersionedLayerClient {
62
72
  *
63
73
  * @return Tile data (if it exists) or the nearest parent tile data
64
74
  */
65
- getAggregatedData(request, abortSignal) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- let catalogVersion = this.version;
68
- if (catalogVersion === undefined) {
69
- catalogVersion = yield this.getLatestVersion(request.getBillingTag());
70
- }
71
- const params = {
72
- catalogHrn: olp_sdk_core_1.HRN.fromString(this.hrn),
73
- layerId: this.layerId,
74
- layerType: "versioned",
75
- settings: this.settings,
76
- catalogVersion
77
- };
78
- return olp_sdk_dataservice_read_1.getTile(request, params, abortSignal);
79
- });
75
+ async getAggregatedData(request, abortSignal) {
76
+ let catalogVersion = this.version;
77
+ if (catalogVersion === undefined) {
78
+ catalogVersion = await this.getLatestVersion(request.getBillingTag());
79
+ }
80
+ const params = {
81
+ catalogHrn: olp_sdk_core_1.HRN.fromString(this.hrn),
82
+ layerId: this.layerId,
83
+ layerType: "versioned",
84
+ settings: this.settings,
85
+ catalogVersion
86
+ };
87
+ return (0, getTile_1.getTile)(request, params, abortSignal);
80
88
  }
81
89
  /**
82
90
  * Fetches partition data using one of the following methods: ID, quadkey, or data handle.
@@ -89,84 +97,80 @@ class VersionedLayerClient {
89
97
  *
90
98
  * @return The data from the requested partition.
91
99
  */
92
- getData(dataRequest, abortSignal) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- const dataHandle = dataRequest.getDataHandle();
95
- if (dataHandle) {
96
- return this.downloadPartition(dataHandle, abortSignal, dataRequest.getBillingTag());
97
- }
98
- const partitionId = dataRequest.getPartitionId();
99
- if (this.version === undefined) {
100
- // fetch the latest version and lock it to the instance.
101
- this.version = yield this.getLatestVersion(dataRequest.getBillingTag()).catch(error => Promise.reject(error));
102
- }
103
- if (this.version === undefined) {
104
- return Promise.reject(new Error(`Unable to retrieve latest version. Please provide version to the DataRequest or lock version in the constructor`));
105
- }
106
- if (partitionId) {
107
- const partitionIdDataHandle = yield this.getDataHandleByPartitionId(partitionId, dataRequest.getFetchOption(), dataRequest.getBillingTag()).catch(error => Promise.reject(error));
108
- return this.downloadPartition(partitionIdDataHandle, abortSignal, dataRequest.getBillingTag());
109
- }
110
- return Promise.reject(new Error(`No data provided. Add dataHandle, partitionId or quadKey to the DataRequest object`));
111
- });
100
+ async getData(dataRequest, abortSignal) {
101
+ const dataHandle = dataRequest.getDataHandle();
102
+ if (dataHandle) {
103
+ return this.downloadPartition(dataHandle, abortSignal, dataRequest.getBillingTag());
104
+ }
105
+ const partitionId = dataRequest.getPartitionId();
106
+ if (this.version === undefined) {
107
+ // fetch the latest version and lock it to the instance.
108
+ this.version = await this.getLatestVersion(dataRequest.getBillingTag());
109
+ }
110
+ if (this.version === undefined) {
111
+ return Promise.reject(new Error(`Unable to retrieve latest version. Please provide version to the DataRequest or lock version in the constructor`));
112
+ }
113
+ if (partitionId) {
114
+ const partitionIdDataHandle = await this.getDataHandleByPartitionId(partitionId, dataRequest.getFetchOption(), dataRequest.getBillingTag());
115
+ return this.downloadPartition(partitionIdDataHandle, abortSignal, dataRequest.getBillingTag());
116
+ }
117
+ return Promise.reject(new Error(`No data provided. Add dataHandle, partitionId or quadKey to the DataRequest object`));
112
118
  }
113
- getPartitions(request, abortSignal) {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- if (this.version === undefined) {
116
- // fetch the latest version and lock it to the instance.
117
- this.version = yield this.getLatestVersion(request.getBillingTag()).catch(error => Promise.reject(error));
118
- }
119
- if (this.version === undefined) {
120
- return Promise.reject(new Error(`Unable to retrieve latest version. Please provide version to the Request or lock version in the constructor`));
119
+ async getPartitions(request, abortSignal) {
120
+ if (this.version === undefined) {
121
+ // fetch the latest version and lock it to the instance.
122
+ this.version = await this.getLatestVersion(request.getBillingTag());
123
+ }
124
+ if (this.version === undefined) {
125
+ return Promise.reject(new Error(`Unable to retrieve latest version. Please provide version to the Request or lock version in the constructor`));
126
+ }
127
+ if (request instanceof QuadKeyPartitionsRequest_1.QuadKeyPartitionsRequest) {
128
+ const quadKey = request.getQuadKey();
129
+ if (!quadKey) {
130
+ return Promise.reject(new Error("Please provide correct QuadKey"));
121
131
  }
122
- if (request instanceof olp_sdk_dataservice_read_1.QuadKeyPartitionsRequest) {
123
- const quadKey = request.getQuadKey();
124
- if (!quadKey) {
125
- return Promise.reject(new Error("Please provide correct QuadKey"));
132
+ const queryClient = new QueryClient_1.QueryClient(this.settings);
133
+ const quadTreeIndexRequest = new QuadTreeIndexRequest_1.QuadTreeIndexRequest(olp_sdk_core_1.HRN.fromString(this.hrn), this.layerId, "versioned")
134
+ .withQuadKey(quadKey)
135
+ .withVersion(this.version)
136
+ .withDepth(request.getDepth())
137
+ .withAdditionalFields(request.getAdditionalFields());
138
+ return queryClient.fetchQuadTreeIndex(quadTreeIndexRequest, abortSignal);
139
+ }
140
+ if (request.getPartitionIds()) {
141
+ const queryClient = new QueryClient_1.QueryClient(this.settings);
142
+ return queryClient.getPartitionsById(request, this.layerId, olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal, this.version);
143
+ }
144
+ const cache = new MetadataCacheRepository_1.MetadataCacheRepository(this.settings.cache);
145
+ if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly) {
146
+ const partitions = cache.get(request, this.hrn.toString(), this.layerId, this.version);
147
+ if (partitions) {
148
+ const additionalFields = request.getAdditionalFields();
149
+ let existFields;
150
+ if (additionalFields) {
151
+ existFields = additionalFields.filter((field) => {
152
+ return partitions.every((partition) => partition[field] !== undefined);
153
+ });
126
154
  }
127
- const queryClient = new olp_sdk_dataservice_read_1.QueryClient(this.settings);
128
- const quadTreeIndexRequest = new olp_sdk_dataservice_read_1.QuadTreeIndexRequest(olp_sdk_core_1.HRN.fromString(this.hrn), this.layerId, "versioned")
129
- .withQuadKey(quadKey)
130
- .withVersion(this.version)
131
- .withDepth(request.getDepth())
132
- .withAdditionalFields(request.getAdditionalFields());
133
- return queryClient.fetchQuadTreeIndex(quadTreeIndexRequest, abortSignal);
134
- }
135
- if (request.getPartitionIds()) {
136
- const queryClient = new olp_sdk_dataservice_read_1.QueryClient(this.settings);
137
- return queryClient.getPartitionsById(request, this.layerId, olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal, this.version);
138
- }
139
- const cache = new olp_sdk_dataservice_read_1.MetadataCacheRepository(this.settings.cache);
140
- if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly) {
141
- const partitions = cache.get(request, this.hrn.toString(), this.layerId, this.version);
142
- if (partitions) {
143
- const additionalFields = request.getAdditionalFields();
144
- let existFields;
145
- if (additionalFields) {
146
- existFields = additionalFields.filter((field) => {
147
- return partitions.every(partition => partition[field] !== undefined);
148
- });
149
- }
150
- if (!additionalFields ||
151
- !existFields ||
152
- additionalFields.length === existFields.length) {
153
- return Promise.resolve({ partitions });
154
- }
155
+ if (!additionalFields ||
156
+ !existFields ||
157
+ additionalFields.length === existFields.length) {
158
+ return Promise.resolve({ partitions });
155
159
  }
156
160
  }
157
- const metaRequestBilder = yield this.getRequestBuilder("metadata", olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal).catch(error => Promise.reject(error));
158
- const metadata = yield olp_sdk_dataservice_api_1.MetadataApi.getPartitions(metaRequestBilder, {
159
- version: this.version,
160
- layerId: this.layerId,
161
- additionalFields: request.getAdditionalFields(),
162
- billingTag: request.getBillingTag()
163
- }).catch(error => Promise.reject(error));
164
- if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly &&
165
- metadata.partitions.length) {
166
- cache.put(request, this.hrn.toString(), this.layerId, metadata.partitions, this.version);
167
- }
168
- return Promise.resolve(metadata);
161
+ }
162
+ const metaRequestBilder = await this.getRequestBuilder("metadata", olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal);
163
+ const metadata = await olp_sdk_dataservice_api_1.MetadataApi.getPartitions(metaRequestBilder, {
164
+ version: this.version,
165
+ layerId: this.layerId,
166
+ additionalFields: request.getAdditionalFields(),
167
+ billingTag: request.getBillingTag()
169
168
  });
169
+ if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly &&
170
+ metadata.partitions.length) {
171
+ cache.put(request, this.hrn.toString(), this.layerId, metadata.partitions, this.version);
172
+ }
173
+ return Promise.resolve(metadata);
170
174
  }
171
175
  /**
172
176
  * Fetch and returns partition metadata
@@ -175,44 +179,38 @@ class VersionedLayerClient {
175
179
  * @param fetchOption The option of caching (online only or return from cache if exist)
176
180
  * @returns A promise of partition metadata which used to get partition data
177
181
  */
178
- getDataHandleByPartitionId(partitionId, fetchOption, billingTag) {
179
- return __awaiter(this, void 0, void 0, function* () {
180
- const queryClient = new olp_sdk_dataservice_read_1.QueryClient(this.settings);
181
- const partitionsRequest = new olp_sdk_dataservice_read_1.PartitionsRequest()
182
- .withPartitionIds([partitionId])
183
- .withFetchOption(fetchOption);
184
- if (billingTag) {
185
- partitionsRequest.withBillingTag(billingTag);
186
- }
187
- const metadata = yield queryClient.getPartitionsById(partitionsRequest, this.layerId, olp_sdk_core_1.HRN.fromString(this.hrn), undefined, this.version);
188
- return metadata.partitions &&
189
- metadata.partitions[0] &&
190
- metadata.partitions[0].dataHandle
191
- ? metadata.partitions[0].dataHandle
192
- : Promise.reject(new olp_sdk_core_1.HttpError(olp_sdk_core_1.STATUS_CODES.NOT_FOUND, `No partition dataHandle for partition ${partitionId}. HRN: ${this.hrn}`));
193
- });
182
+ async getDataHandleByPartitionId(partitionId, fetchOption, billingTag) {
183
+ const queryClient = new QueryClient_1.QueryClient(this.settings);
184
+ const partitionsRequest = new PartitionsRequest_1.PartitionsRequest()
185
+ .withPartitionIds([partitionId])
186
+ .withFetchOption(fetchOption);
187
+ if (billingTag) {
188
+ partitionsRequest.withBillingTag(billingTag);
189
+ }
190
+ const metadata = await queryClient.getPartitionsById(partitionsRequest, this.layerId, olp_sdk_core_1.HRN.fromString(this.hrn), undefined, this.version);
191
+ return metadata.partitions &&
192
+ metadata.partitions[0] &&
193
+ metadata.partitions[0].dataHandle
194
+ ? metadata.partitions[0].dataHandle
195
+ : Promise.reject(new olp_sdk_core_1.HttpError(olp_sdk_core_1.STATUS_CODES.NOT_FOUND, `No partition dataHandle for partition ${partitionId}. HRN: ${this.hrn}`));
194
196
  }
195
197
  /**
196
198
  * Gets the latest available catalog version what can be used as latest layer version
197
199
  */
198
- getLatestVersion(billingTag) {
199
- return __awaiter(this, void 0, void 0, function* () {
200
- const builder = yield this.getRequestBuilder("metadata", olp_sdk_core_1.HRN.fromString(this.hrn)).catch(error => Promise.reject(error));
201
- const latestVersion = yield olp_sdk_dataservice_api_1.MetadataApi.latestVersion(builder, {
202
- startVersion: -1,
203
- billingTag
204
- }).catch(error => Promise.reject(error));
205
- return Promise.resolve(latestVersion.version);
200
+ async getLatestVersion(billingTag) {
201
+ const builder = await this.getRequestBuilder("metadata", olp_sdk_core_1.HRN.fromString(this.hrn));
202
+ const latestVersion = await olp_sdk_dataservice_api_1.MetadataApi.latestVersion(builder, {
203
+ startVersion: -1,
204
+ billingTag
206
205
  });
206
+ return Promise.resolve(latestVersion.version);
207
207
  }
208
- downloadPartition(dataHandle, abortSignal, billingTag) {
209
- return __awaiter(this, void 0, void 0, function* () {
210
- const builder = yield this.getRequestBuilder("blob", olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal).catch(error => Promise.reject(error));
211
- return olp_sdk_dataservice_api_1.BlobApi.getBlob(builder, {
212
- dataHandle,
213
- layerId: this.layerId,
214
- billingTag
215
- });
208
+ async downloadPartition(dataHandle, abortSignal, billingTag) {
209
+ const builder = await this.getRequestBuilder("blob", olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal);
210
+ return olp_sdk_dataservice_api_1.BlobApi.getBlob(builder, {
211
+ dataHandle,
212
+ layerId: this.layerId,
213
+ billingTag
216
214
  });
217
215
  }
218
216
  /**
@@ -221,10 +219,8 @@ class VersionedLayerClient {
221
219
  *
222
220
  * @returns requestBuilder
223
221
  */
224
- getRequestBuilder(builderType, hrn, abortSignal) {
225
- return __awaiter(this, void 0, void 0, function* () {
226
- return olp_sdk_core_1.RequestFactory.create(builderType, this.apiVersion, this.settings, hrn, abortSignal);
227
- });
222
+ async getRequestBuilder(builderType, hrn, abortSignal) {
223
+ return olp_sdk_core_1.RequestFactory.create(builderType, this.apiVersion, this.settings, hrn, abortSignal);
228
224
  }
229
225
  }
230
226
  exports.VersionedLayerClient = VersionedLayerClient;
@@ -1,6 +1,9 @@
1
1
  import { HRN, OlpClientSettings } from "@here/olp-sdk-core";
2
2
  import { MetadataApi, QueryApi } from "@here/olp-sdk-dataservice-api";
3
- import { DataRequest, PartitionsRequest, QuadKeyPartitionsRequest, TileRequest } from "@here/olp-sdk-dataservice-read";
3
+ import { DataRequest } from "./DataRequest";
4
+ import { PartitionsRequest } from "./PartitionsRequest";
5
+ import { QuadKeyPartitionsRequest } from "./QuadKeyPartitionsRequest";
6
+ import { TileRequest } from "./TileRequest";
4
7
  /**
5
8
  * Parameters for use to initialize VolatileLayerClient.
6
9
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (C) 2019-2021 HERE Europe B.V.
3
+ * Copyright (C) 2019-2026 HERE Europe B.V.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -17,31 +17,39 @@
17
17
  * SPDX-License-Identifier: Apache-2.0
18
18
  * License-Filename: LICENSE
19
19
  */
20
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
21
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
- return new (P || (P = Promise))(function (resolve, reject) {
23
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
- step((generator = generator.apply(thisArg, _arguments || [])).next());
27
- });
28
- };
29
20
  Object.defineProperty(exports, "__esModule", { value: true });
30
21
  exports.VolatileLayerClient = void 0;
31
22
  const olp_sdk_core_1 = require("@here/olp-sdk-core");
32
23
  const olp_sdk_dataservice_api_1 = require("@here/olp-sdk-dataservice-api");
33
- const olp_sdk_dataservice_read_1 = require("@here/olp-sdk-dataservice-read");
24
+ const MetadataCacheRepository_1 = require("../cache/MetadataCacheRepository");
25
+ const getTile_1 = require("../utils/getTile");
26
+ const PartitionsRequest_1 = require("./PartitionsRequest");
27
+ const QuadKeyPartitionsRequest_1 = require("./QuadKeyPartitionsRequest");
28
+ const QuadTreeIndexRequest_1 = require("./QuadTreeIndexRequest");
29
+ const QueryClient_1 = require("./QueryClient");
34
30
  /**
35
31
  * Describes a voaltile layer and provides the possibility to get partitions metadata and data.
36
32
  */
37
33
  class VolatileLayerClient {
34
+ apiVersion = "v1";
35
+ /**
36
+ * HRN of the catalog.
37
+ */
38
+ hrn;
39
+ /**
40
+ * The ID of the layer.
41
+ */
42
+ layerId;
43
+ /**
44
+ * The [[OlpClientSettings]] instance.
45
+ */
46
+ settings;
38
47
  /**
39
48
  * Creates the [[VolatileLayerClient]] instance with VolatileLayerClientParams.
40
49
  *
41
50
  * @param params parameters for use to initialize VolatileLayerClient.
42
51
  */
43
52
  constructor(params) {
44
- this.apiVersion = "v1";
45
53
  this.hrn = params.catalogHrn.toString();
46
54
  this.layerId = params.layerId;
47
55
  this.settings = params.settings;
@@ -59,16 +67,14 @@ class VolatileLayerClient {
59
67
  *
60
68
  * @return Tile data (if it exists) or the nearest parent tile data
61
69
  */
62
- getAggregatedData(request, abortSignal) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- const params = {
65
- catalogHrn: olp_sdk_core_1.HRN.fromString(this.hrn),
66
- layerId: this.layerId,
67
- layerType: "volatile",
68
- settings: this.settings
69
- };
70
- return olp_sdk_dataservice_read_1.getTile(request, params, abortSignal);
71
- });
70
+ async getAggregatedData(request, abortSignal) {
71
+ const params = {
72
+ catalogHrn: olp_sdk_core_1.HRN.fromString(this.hrn),
73
+ layerId: this.layerId,
74
+ layerType: "volatile",
75
+ settings: this.settings
76
+ };
77
+ return (0, getTile_1.getTile)(request, params, abortSignal);
72
78
  }
73
79
  /**
74
80
  * Fetches partition data using one of the following methods: ID, quadkey, or data handle.
@@ -81,79 +87,73 @@ class VolatileLayerClient {
81
87
  *
82
88
  * @return The data from the requested partition.
83
89
  */
84
- getData(dataRequest, abortSignal) {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- const dataHandle = dataRequest.getDataHandle();
87
- const partitionId = dataRequest.getPartitionId();
88
- if (dataHandle !== undefined || partitionId !== undefined) {
89
- if (dataHandle) {
90
- return this.downloadPartition(dataHandle, abortSignal, dataRequest.getBillingTag());
91
- }
92
- if (partitionId) {
93
- const partitionIdDataHandle = yield this.getDataHandleByPartitionId(partitionId, dataRequest.getFetchOption(), dataRequest.getBillingTag()).catch(error => Promise.reject(error));
94
- return this.downloadPartition(partitionIdDataHandle, abortSignal, dataRequest.getBillingTag());
95
- }
90
+ async getData(dataRequest, abortSignal) {
91
+ const dataHandle = dataRequest.getDataHandle();
92
+ const partitionId = dataRequest.getPartitionId();
93
+ if (dataHandle !== undefined || partitionId !== undefined) {
94
+ if (dataHandle) {
95
+ return this.downloadPartition(dataHandle, abortSignal, dataRequest.getBillingTag());
96
96
  }
97
- return Promise.reject(new Error(`No data provided. Add dataHandle, partitionId or quadKey to the DataRequest object`));
98
- });
99
- }
100
- getPartitions(request, abortSignal) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- if (request instanceof olp_sdk_dataservice_read_1.QuadKeyPartitionsRequest) {
103
- const quadKey = request.getQuadKey();
104
- if (!quadKey) {
105
- return Promise.reject(new Error("Please provide correct QuadKey"));
106
- }
107
- const queryClient = new olp_sdk_dataservice_read_1.QueryClient(this.settings);
108
- const quadTreeIndexRequest = new olp_sdk_dataservice_read_1.QuadTreeIndexRequest(olp_sdk_core_1.HRN.fromString(this.hrn), this.layerId, "volatile")
109
- .withQuadKey(quadKey)
110
- .withDepth(request.getDepth())
111
- .withAdditionalFields(request.getAdditionalFields());
112
- return queryClient.fetchQuadTreeIndex(quadTreeIndexRequest, abortSignal);
97
+ if (partitionId) {
98
+ const partitionIdDataHandle = await this.getDataHandleByPartitionId(partitionId, dataRequest.getFetchOption(), dataRequest.getBillingTag());
99
+ return this.downloadPartition(partitionIdDataHandle, abortSignal, dataRequest.getBillingTag());
113
100
  }
114
- if (request.getPartitionIds()) {
115
- const queryClient = new olp_sdk_dataservice_read_1.QueryClient(this.settings);
116
- return queryClient.getPartitionsById(request, this.layerId, olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal);
101
+ }
102
+ return Promise.reject(new Error(`No data provided. Add dataHandle, partitionId or quadKey to the DataRequest object`));
103
+ }
104
+ async getPartitions(request, abortSignal) {
105
+ if (request instanceof QuadKeyPartitionsRequest_1.QuadKeyPartitionsRequest) {
106
+ const quadKey = request.getQuadKey();
107
+ if (!quadKey) {
108
+ return Promise.reject(new Error("Please provide correct QuadKey"));
117
109
  }
118
- const cache = new olp_sdk_dataservice_read_1.MetadataCacheRepository(this.settings.cache);
119
- if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly) {
120
- const partitions = cache.get(request, this.hrn.toString(), this.layerId);
121
- if (partitions) {
122
- const additionalFields = request.getAdditionalFields();
123
- let existFields;
124
- if (additionalFields) {
125
- existFields = additionalFields.filter((field) => {
126
- return partitions.every(partition => partition[field] !== undefined);
127
- });
128
- }
129
- if (!additionalFields ||
130
- !existFields ||
131
- additionalFields.length === existFields.length) {
132
- return Promise.resolve({ partitions });
133
- }
110
+ const queryClient = new QueryClient_1.QueryClient(this.settings);
111
+ const quadTreeIndexRequest = new QuadTreeIndexRequest_1.QuadTreeIndexRequest(olp_sdk_core_1.HRN.fromString(this.hrn), this.layerId, "volatile")
112
+ .withQuadKey(quadKey)
113
+ .withDepth(request.getDepth())
114
+ .withAdditionalFields(request.getAdditionalFields());
115
+ return queryClient.fetchQuadTreeIndex(quadTreeIndexRequest, abortSignal);
116
+ }
117
+ if (request.getPartitionIds()) {
118
+ const queryClient = new QueryClient_1.QueryClient(this.settings);
119
+ return queryClient.getPartitionsById(request, this.layerId, olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal);
120
+ }
121
+ const cache = new MetadataCacheRepository_1.MetadataCacheRepository(this.settings.cache);
122
+ if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly) {
123
+ const partitions = cache.get(request, this.hrn.toString(), this.layerId);
124
+ if (partitions) {
125
+ const additionalFields = request.getAdditionalFields();
126
+ let existFields;
127
+ if (additionalFields) {
128
+ existFields = additionalFields.filter((field) => {
129
+ return partitions.every((partition) => partition[field] !== undefined);
130
+ });
131
+ }
132
+ if (!additionalFields ||
133
+ !existFields ||
134
+ additionalFields.length === existFields.length) {
135
+ return Promise.resolve({ partitions });
134
136
  }
135
137
  }
136
- const metaRequestBilder = yield this.getRequestBuilder("metadata", olp_sdk_core_1.HRN.fromString(this.hrn)).catch(error => Promise.reject(error));
137
- const metadata = yield olp_sdk_dataservice_api_1.MetadataApi.getPartitions(metaRequestBilder, {
138
- layerId: this.layerId,
139
- additionalFields: request.getAdditionalFields(),
140
- billingTag: request.getBillingTag()
141
- }).catch(error => Promise.reject(error));
142
- if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly &&
143
- metadata.partitions.length) {
144
- cache.put(request, this.hrn.toString(), this.layerId, metadata.partitions);
145
- }
146
- return Promise.resolve(metadata);
138
+ }
139
+ const metaRequestBilder = await this.getRequestBuilder("metadata", olp_sdk_core_1.HRN.fromString(this.hrn));
140
+ const metadata = await olp_sdk_dataservice_api_1.MetadataApi.getPartitions(metaRequestBilder, {
141
+ layerId: this.layerId,
142
+ additionalFields: request.getAdditionalFields(),
143
+ billingTag: request.getBillingTag()
147
144
  });
145
+ if (request.getFetchOption() !== olp_sdk_core_1.FetchOptions.OnlineOnly &&
146
+ metadata.partitions.length) {
147
+ cache.put(request, this.hrn.toString(), this.layerId, metadata.partitions);
148
+ }
149
+ return Promise.resolve(metadata);
148
150
  }
149
- downloadPartition(dataHandle, abortSignal, billingTag) {
150
- return __awaiter(this, void 0, void 0, function* () {
151
- const builder = yield this.getRequestBuilder("volatile-blob", olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal).catch(error => Promise.reject(error));
152
- return olp_sdk_dataservice_api_1.VolatileBlobApi.getVolatileBlob(builder, {
153
- dataHandle,
154
- layerId: this.layerId,
155
- billingTag
156
- });
151
+ async downloadPartition(dataHandle, abortSignal, billingTag) {
152
+ const builder = await this.getRequestBuilder("volatile-blob", olp_sdk_core_1.HRN.fromString(this.hrn), abortSignal);
153
+ return olp_sdk_dataservice_api_1.VolatileBlobApi.getVolatileBlob(builder, {
154
+ dataHandle,
155
+ layerId: this.layerId,
156
+ billingTag
157
157
  });
158
158
  }
159
159
  /**
@@ -162,10 +162,8 @@ class VolatileLayerClient {
162
162
  *
163
163
  * @returns requestBuilder
164
164
  */
165
- getRequestBuilder(builderType, hrn, abortSignal) {
166
- return __awaiter(this, void 0, void 0, function* () {
167
- return olp_sdk_core_1.RequestFactory.create(builderType, this.apiVersion, this.settings, hrn, abortSignal);
168
- });
165
+ async getRequestBuilder(builderType, hrn, abortSignal) {
166
+ return olp_sdk_core_1.RequestFactory.create(builderType, this.apiVersion, this.settings, hrn, abortSignal);
169
167
  }
170
168
  /**
171
169
  * Fetch and returns partition metadata
@@ -173,22 +171,20 @@ class VolatileLayerClient {
173
171
  * @param fetchOption The option of caching (online only or return from cache if exist)
174
172
  * @returns A promise of partition metadata which used to get partition data
175
173
  */
176
- getDataHandleByPartitionId(partitionId, fetchOption, billingTag) {
177
- return __awaiter(this, void 0, void 0, function* () {
178
- const queryClient = new olp_sdk_dataservice_read_1.QueryClient(this.settings);
179
- const partitionsRequest = new olp_sdk_dataservice_read_1.PartitionsRequest()
180
- .withPartitionIds([partitionId])
181
- .withFetchOption(fetchOption);
182
- if (billingTag) {
183
- partitionsRequest.withBillingTag(billingTag);
184
- }
185
- const metadata = yield queryClient.getPartitionsById(partitionsRequest, this.layerId, olp_sdk_core_1.HRN.fromString(this.hrn));
186
- return metadata.partitions &&
187
- metadata.partitions[0] &&
188
- metadata.partitions[0].dataHandle
189
- ? metadata.partitions[0].dataHandle
190
- : Promise.reject(new olp_sdk_core_1.HttpError(olp_sdk_core_1.STATUS_CODES.NOT_FOUND, `No partition dataHandle for partition ${partitionId}. HRN: ${this.hrn}`));
191
- });
174
+ async getDataHandleByPartitionId(partitionId, fetchOption, billingTag) {
175
+ const queryClient = new QueryClient_1.QueryClient(this.settings);
176
+ const partitionsRequest = new PartitionsRequest_1.PartitionsRequest()
177
+ .withPartitionIds([partitionId])
178
+ .withFetchOption(fetchOption);
179
+ if (billingTag) {
180
+ partitionsRequest.withBillingTag(billingTag);
181
+ }
182
+ const metadata = await queryClient.getPartitionsById(partitionsRequest, this.layerId, olp_sdk_core_1.HRN.fromString(this.hrn));
183
+ return metadata.partitions &&
184
+ metadata.partitions[0] &&
185
+ metadata.partitions[0].dataHandle
186
+ ? metadata.partitions[0].dataHandle
187
+ : Promise.reject(new olp_sdk_core_1.HttpError(olp_sdk_core_1.STATUS_CODES.NOT_FOUND, `No partition dataHandle for partition ${partitionId}. HRN: ${this.hrn}`));
192
188
  }
193
189
  }
194
190
  exports.VolatileLayerClient = VolatileLayerClient;
@@ -19,7 +19,11 @@
19
19
  */
20
20
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
21
  if (k2 === undefined) k2 = k;
22
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
22
+ var desc = Object.getOwnPropertyDescriptor(m, k);
23
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
+ desc = { enumerable: true, get: function() { return m[k]; } };
25
+ }
26
+ Object.defineProperty(o, k2, desc);
23
27
  }) : (function(o, m, k, k2) {
24
28
  if (k2 === undefined) k2 = k;
25
29
  o[k2] = m[k];