@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.
- package/README.md +3 -3
- package/bundle.umd.dev.js +12563 -76
- package/bundle.umd.min.js +1 -1
- package/index.js +5 -1
- package/index.web.js +5 -1
- package/lib/cache/MetadataCacheRepository.js +1 -0
- package/lib/cache/QuadTreeIndexCacheRepository.js +1 -0
- package/lib/cache/index.js +5 -1
- package/lib/client/ArtifactClient.d.ts +2 -1
- package/lib/client/ArtifactClient.js +31 -43
- package/lib/client/CatalogClient.d.ts +3 -1
- package/lib/client/CatalogClient.js +59 -78
- package/lib/client/CatalogRequest.js +4 -3
- package/lib/client/CatalogVersionRequest.js +6 -3
- package/lib/client/CatalogsRequest.js +5 -3
- package/lib/client/ConfigClient.d.ts +1 -1
- package/lib/client/ConfigClient.js +13 -23
- package/lib/client/DataRequest.js +7 -6
- package/lib/client/IndexLayerClient.d.ts +1 -1
- package/lib/client/IndexLayerClient.js +37 -40
- package/lib/client/IndexQueryRequest.js +2 -0
- package/lib/client/LayerVersionsRequest.js +5 -3
- package/lib/client/PartitionsRequest.js +10 -7
- package/lib/client/PollRequest.js +2 -0
- package/lib/client/QuadKeyPartitionsRequest.d.ts +1 -1
- package/lib/client/QuadKeyPartitionsRequest.js +7 -3
- package/lib/client/QuadTreeIndexRequest.d.ts +1 -1
- package/lib/client/QuadTreeIndexRequest.js +11 -3
- package/lib/client/QueryClient.d.ts +2 -1
- package/lib/client/QueryClient.js +85 -96
- package/lib/client/SchemaDetailsRequest.js +5 -3
- package/lib/client/SchemaRequest.js +5 -3
- package/lib/client/SeekRequest.js +3 -0
- package/lib/client/StatisticsClient.d.ts +2 -1
- package/lib/client/StatisticsClient.js +51 -65
- package/lib/client/StatisticsRequest.js +9 -4
- package/lib/client/StreamLayerClient.d.ts +4 -1
- package/lib/client/StreamLayerClient.js +117 -139
- package/lib/client/SubscribeRequest.js +4 -0
- package/lib/client/SummaryRequest.js +5 -2
- package/lib/client/TileRequest.js +6 -6
- package/lib/client/UnsubscribeRequest.js +2 -0
- package/lib/client/VersionedLayerClient.d.ts +4 -1
- package/lib/client/VersionedLayerClient.js +131 -135
- package/lib/client/VolatileLayerClient.d.ts +4 -1
- package/lib/client/VolatileLayerClient.js +104 -108
- package/lib/client/index.js +5 -1
- package/lib/index.js +5 -1
- package/lib/utils/getTile.d.ts +2 -1
- package/lib/utils/getTile.js +93 -99
- package/lib/utils/index.js +5 -1
- package/lib/utils/validateBillingTag.js +1 -2
- package/lib/utils/validatePartitionsIdsList.js +1 -2
- package/package.json +11 -55
- package/webpack.config.js +2 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (C) 2019-
|
|
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
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
.
|
|
130
|
-
.
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
|
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
|
|
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-
|
|
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
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (dataHandle
|
|
89
|
-
|
|
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
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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;
|
package/lib/client/index.js
CHANGED
|
@@ -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.
|
|
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];
|