sodas-sdk 1.1.11 → 1.1.12

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.
@@ -1975,6 +1975,70 @@ class Dataset extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"] {
1975
1975
  }
1976
1976
  });
1977
1977
  }
1978
+ static syncToCurrentHub(dataset) {
1979
+ return __awaiter(this, void 0, void 0, function* () {
1980
+ var _a;
1981
+ try {
1982
+ const checkExisting = yield Dataset.getDBRecordByAssetID((0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(dataset.assetID));
1983
+ if (checkExisting) {
1984
+ checkExisting.populateToSync(dataset);
1985
+ yield checkExisting.updateDBRecord();
1986
+ }
1987
+ }
1988
+ catch (error) {
1989
+ if (axios__WEBPACK_IMPORTED_MODULE_6__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
1990
+ const newDataset = new Dataset();
1991
+ newDataset.populateToSync(dataset);
1992
+ yield newDataset.createDBRecord();
1993
+ }
1994
+ else {
1995
+ throw error;
1996
+ }
1997
+ }
1998
+ });
1999
+ }
2000
+ populateToSync(source) {
2001
+ const excludedKeys = new Set([
2002
+ "ID",
2003
+ "DatasetID",
2004
+ "IsVersionOf",
2005
+ "PreviousVersionID",
2006
+ "NextVersionID",
2007
+ "VersionInfos",
2008
+ "InSeriesID",
2009
+ "FirstID",
2010
+ "PreviousID",
2011
+ "NextID",
2012
+ "LastID",
2013
+ "DistributionIDs",
2014
+ ]);
2015
+ for (const key in source) {
2016
+ if (!Object.prototype.hasOwnProperty.call(source, key))
2017
+ continue;
2018
+ if (key === "Distributions")
2019
+ continue;
2020
+ if (excludedKeys.has(key))
2021
+ continue;
2022
+ const value = source[key];
2023
+ if (value !== undefined) {
2024
+ this[key] = value;
2025
+ }
2026
+ }
2027
+ // Handle distributions separately so that we can preserve identity fields
2028
+ // of existing distributions while syncing other fields, and create new
2029
+ // distributions for any additional ones in the source.
2030
+ const sourceDistributions = source.Distributions;
2031
+ if (!sourceDistributions || sourceDistributions.length === 0) {
2032
+ return;
2033
+ }
2034
+ this.Distributions = [];
2035
+ for (let i = 0; i < sourceDistributions.length; i++) {
2036
+ const srcDist = sourceDistributions[i];
2037
+ const targetDist = new _distribution__WEBPACK_IMPORTED_MODULE_5__["default"]();
2038
+ targetDist.populateToSync(srcDist);
2039
+ this.Distributions.push(targetDist);
2040
+ }
2041
+ }
1978
2042
  createDBRecord() {
1979
2043
  const _super = Object.create(null, {
1980
2044
  createDBRecord: { get: () => super.createDBRecord }
@@ -2165,6 +2229,7 @@ __webpack_require__.r(__webpack_exports__);
2165
2229
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2166
2230
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
2167
2231
  /* harmony export */ });
2232
+ /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! axios */ "./node_modules/axios/lib/axios.js");
2168
2233
  /* harmony import */ var _core_error__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/error */ "./lib/core/error.ts");
2169
2234
  /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
2170
2235
  /* harmony import */ var _core_util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/util */ "./lib/core/util.ts");
@@ -2184,10 +2249,105 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
2184
2249
 
2185
2250
 
2186
2251
 
2252
+
2187
2253
  /**
2188
2254
  * Represents a series of datasets.
2189
2255
  */
2190
2256
  class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"] {
2257
+ static syncToCurrentHub(datasetSeries) {
2258
+ return __awaiter(this, void 0, void 0, function* () {
2259
+ var _a;
2260
+ try {
2261
+ const checkExisting = yield DatasetSeries.getDBRecordByAssetID((0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(datasetSeries.assetID));
2262
+ if (checkExisting) {
2263
+ yield checkExisting.populateToSync(datasetSeries);
2264
+ yield checkExisting.updateDBRecord();
2265
+ }
2266
+ }
2267
+ catch (error) {
2268
+ if (axios__WEBPACK_IMPORTED_MODULE_5__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
2269
+ const newDatasetSeries = new DatasetSeries();
2270
+ yield newDatasetSeries.populateToSync(datasetSeries);
2271
+ yield newDatasetSeries.createDBRecord();
2272
+ }
2273
+ else {
2274
+ throw error;
2275
+ }
2276
+ }
2277
+ });
2278
+ }
2279
+ /**
2280
+ * Populates this instance with values from the given DatasetSeries, except for:
2281
+ * - DB identity / temporal fields (ID, IRI, Issued, Modified, CreatedAt, UpdatedAt)
2282
+ * - Version/lineage fields (IsVersionOf, PreviousVersionID, NextVersionID, VersionInfos)
2283
+ * - Series identity fields (DatasetSeriesID, InSeriesID)
2284
+ * - Fields explicitly set to `undefined` on the source instance
2285
+ *
2286
+ * Additionally, when SeriesMembers are present on the source, this method
2287
+ * resolves each member via Dataset.getDBRecordByAssetID (by AssetID) and
2288
+ * replaces this.SeriesMemberIDs with the resolved IDs.
2289
+ */
2290
+ populateToSync(source) {
2291
+ return __awaiter(this, void 0, void 0, function* () {
2292
+ var _a;
2293
+ const excludedKeys = new Set([
2294
+ "ID",
2295
+ "IsVersionOf",
2296
+ "PreviousVersionID",
2297
+ "NextVersionID",
2298
+ "VersionInfos",
2299
+ "DatasetSeriesID",
2300
+ "InSeriesID",
2301
+ ]);
2302
+ for (const key in source) {
2303
+ if (!Object.prototype.hasOwnProperty.call(source, key))
2304
+ continue;
2305
+ if (key === "SeriesMembers")
2306
+ continue;
2307
+ if (excludedKeys.has(key))
2308
+ continue;
2309
+ const value = source[key];
2310
+ if (value !== undefined) {
2311
+ this[key] = value;
2312
+ }
2313
+ }
2314
+ this.SeriesMembers = [];
2315
+ const sourceMembers = source.SeriesMembers;
2316
+ if (!sourceMembers || sourceMembers.length === 0) {
2317
+ return;
2318
+ }
2319
+ const resolvedIDs = [];
2320
+ for (const member of sourceMembers) {
2321
+ if (!member)
2322
+ continue;
2323
+ const assetIDStr = member.assetID;
2324
+ if (!assetIDStr)
2325
+ continue;
2326
+ const assetID = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(assetIDStr);
2327
+ // Prefer existing record by AssetID; if not found, create a new one.
2328
+ try {
2329
+ const existing = yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecordByAssetID(assetID);
2330
+ if (existing) {
2331
+ existing.populateToSync(member);
2332
+ yield existing.updateDBRecord();
2333
+ resolvedIDs.push(existing.id);
2334
+ }
2335
+ }
2336
+ catch (error) {
2337
+ if (axios__WEBPACK_IMPORTED_MODULE_5__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
2338
+ const newMember = new _dataset__WEBPACK_IMPORTED_MODULE_3__["default"]();
2339
+ newMember.populateToSync(member);
2340
+ yield newMember.createDBRecord();
2341
+ resolvedIDs.push(newMember.id);
2342
+ }
2343
+ else {
2344
+ throw error;
2345
+ }
2346
+ }
2347
+ }
2348
+ this.SeriesMemberIDs = resolvedIDs;
2349
+ });
2350
+ }
2191
2351
  /**
2192
2352
  * Initializes or updates the API_URL and LIST_URL for Dataset.
2193
2353
  *
@@ -2228,11 +2388,17 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
2228
2388
  }
2229
2389
  populateSeriesMembersFromDTO(dto) {
2230
2390
  return __awaiter(this, void 0, void 0, function* () {
2391
+ this.SeriesMembers = [];
2231
2392
  if (dto.SeriesMemberIDs && dto.SeriesMemberIDs.length != 0) {
2232
2393
  this.SeriesMemberIDs = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asIDs)(dto.SeriesMemberIDs);
2233
- this.SeriesMembers = yield Promise.all(dto.SeriesMemberIDs.map((seriesMemberID) => __awaiter(this, void 0, void 0, function* () {
2234
- return yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecord(seriesMemberID);
2235
- })));
2394
+ if (this.SeriesMemberIDs && this.SeriesMemberIDs.length != 0) {
2395
+ for (const seriesMemberID of this.SeriesMemberIDs) {
2396
+ const seriesMember = yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecord(seriesMemberID);
2397
+ if (seriesMember) {
2398
+ this.SeriesMembers.push(seriesMember);
2399
+ }
2400
+ }
2401
+ }
2236
2402
  }
2237
2403
  });
2238
2404
  }
@@ -2251,6 +2417,17 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
2251
2417
  yield _super.deleteDBRecord.call(this);
2252
2418
  });
2253
2419
  }
2420
+ /**
2421
+ * Creates a dataset series DB record in an interoperated context
2422
+ * (e.g. together with related Dataset instances or other resources).
2423
+ *
2424
+ * The implementation will be added later.
2425
+ */
2426
+ createInteroperatedDBRecord() {
2427
+ return __awaiter(this, void 0, void 0, function* () {
2428
+ // TODO: Implement interoperated create logic.
2429
+ });
2430
+ }
2254
2431
  appendSeriesMember(dataset) {
2255
2432
  if (!this.SeriesMemberIDs) {
2256
2433
  this.SeriesMemberIDs = [];
@@ -2283,7 +2460,7 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
2283
2460
  get datasetSeriesID() {
2284
2461
  return this.DatasetSeriesID;
2285
2462
  }
2286
- get seriesMembereIDs() {
2463
+ get seriesMemberIDs() {
2287
2464
  return this.SeriesMemberIDs;
2288
2465
  }
2289
2466
  get seriesMembers() {
@@ -2709,8 +2886,8 @@ __webpack_require__.r(__webpack_exports__);
2709
2886
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2710
2887
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
2711
2888
  /* harmony export */ });
2712
- /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
2713
- /* harmony import */ var _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../SODAS_SDK_FILE/dataFile */ "./lib/SODAS_SDK_FILE/dataFile.ts");
2889
+ /* harmony import */ var _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../SODAS_SDK_FILE/dataFile */ "./lib/SODAS_SDK_FILE/dataFile.ts");
2890
+ /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
2714
2891
  /* harmony import */ var _dcatClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../dcatClass */ "./lib/SODAS_SDK_CLASS/dcatClass.ts");
2715
2892
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
2716
2893
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -2725,6 +2902,24 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
2725
2902
 
2726
2903
 
2727
2904
  class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2905
+ /**
2906
+ * Populates this instance with values from the given Distribution, except for:
2907
+ * - DB identity / temporal fields (ID, IRI, Issued, Modified, CreatedAt, UpdatedAt)
2908
+ * - Fields that are explicitly set to `undefined` on the source instance
2909
+ */
2910
+ populateToSync(source) {
2911
+ const excludedKeys = new Set(["ID", "IsDistributionOf", "AccessServiceID"]);
2912
+ for (const key in source) {
2913
+ if (!Object.prototype.hasOwnProperty.call(source, key))
2914
+ continue;
2915
+ if (excludedKeys.has(key))
2916
+ continue;
2917
+ const value = source[key];
2918
+ if (value !== undefined) {
2919
+ this[key] = value;
2920
+ }
2921
+ }
2922
+ }
2728
2923
  toDTO() {
2729
2924
  return Object.assign(Object.assign(Object.assign(Object.assign({}, super.toDTO()), (this.IsDistributionOf && { IsDistributionOf: this.IsDistributionOf })), (this.AccessServiceID && { AccessServiceID: this.AccessServiceID })), { AccessURL: this.AccessURL, ByteSize: this.ByteSize, CompressFormat: this.CompressFormat, DownloadURL: this.DownloadURL, MediaType: this.MediaType, PackageFormat: this.PackageFormat, SpatialResolutionInMeters: this.SpatialResolutionInMeters, TemporalResolution: this.TemporalResolution, AccessRights: this.AccessRights, ConformsTo: this.ConformsTo, DescriptionML: this.DescriptionML, Format: this.Format, License: this.License, Rights: this.Rights, TitleML: this.TitleML, HasPolicy: this.HasPolicy, Checksum: this.Checksum });
2730
2925
  }
@@ -2736,7 +2931,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2736
2931
  yield _super.populateFromDTO.call(this, dto);
2737
2932
  const distributionDTO = dto;
2738
2933
  distributionDTO.AccessServiceID &&
2739
- (this.AccessServiceID = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(distributionDTO.AccessServiceID));
2934
+ (this.AccessServiceID = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distributionDTO.AccessServiceID));
2740
2935
  distributionDTO.AccessURL && (this.AccessURL = distributionDTO.AccessURL);
2741
2936
  distributionDTO.ByteSize && (this.ByteSize = distributionDTO.ByteSize);
2742
2937
  distributionDTO.CompressFormat &&
@@ -2764,7 +2959,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2764
2959
  distributionDTO.HasPolicy && (this.HasPolicy = distributionDTO.HasPolicy);
2765
2960
  distributionDTO.Checksum && (this.Checksum = distributionDTO.Checksum);
2766
2961
  distributionDTO.IsDistributionOf &&
2767
- (this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(distributionDTO.IsDistributionOf));
2962
+ (this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distributionDTO.IsDistributionOf));
2768
2963
  });
2769
2964
  }
2770
2965
  /**
@@ -2780,7 +2975,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2780
2975
  Distribution.DOWNLOAD_API_URL = `${url}/data/download`;
2781
2976
  }
2782
2977
  static configureBucketName(bucketName) {
2783
- _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"].configureBucketName(bucketName);
2978
+ _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"].configureBucketName(bucketName);
2784
2979
  }
2785
2980
  /**
2786
2981
  * Sets file information for a browser environment.
@@ -2788,7 +2983,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2788
2983
  */
2789
2984
  setUploadingDataForBrowser(file) {
2790
2985
  if (!this.UploadingData) {
2791
- this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"]();
2986
+ this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"]();
2792
2987
  }
2793
2988
  this.UploadingData.setFileForBrowser(file);
2794
2989
  }
@@ -2798,7 +2993,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2798
2993
  */
2799
2994
  setUploadingDataForNode(filePath) {
2800
2995
  if (!this.UploadingData) {
2801
- this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"]();
2996
+ this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"]();
2802
2997
  }
2803
2998
  this.UploadingData.setFileForNode(filePath);
2804
2999
  }
@@ -2991,7 +3186,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2991
3186
  return this.IsDistributionOf;
2992
3187
  }
2993
3188
  set isDistributionOf(value) {
2994
- this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(value);
3189
+ this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(value);
2995
3190
  }
2996
3191
  }
2997
3192
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Distribution);
@@ -3246,6 +3441,27 @@ class DCAT_MODEL extends _sodasSDKClass__WEBPACK_IMPORTED_MODULE_3__["default"]
3246
3441
  }
3247
3442
  });
3248
3443
  }
3444
+ /**
3445
+ * Checks whether a DB record exists for the given AssetID and returns its ID.
3446
+ *
3447
+ * This method wraps getDBRecordByAssetID and converts a 404 response to `null`,
3448
+ * while rethrowing any other kind of error.
3449
+ */
3450
+ static checkDBRecordOfAssetID(assetID) {
3451
+ return __awaiter(this, void 0, void 0, function* () {
3452
+ var _a;
3453
+ try {
3454
+ const record = (yield this.getDBRecordByAssetID(assetID));
3455
+ return record.id;
3456
+ }
3457
+ catch (error) {
3458
+ if (axios__WEBPACK_IMPORTED_MODULE_4__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
3459
+ return null;
3460
+ }
3461
+ throw error;
3462
+ }
3463
+ });
3464
+ }
3249
3465
  updateDBRecord() {
3250
3466
  return __awaiter(this, void 0, void 0, function* () {
3251
3467
  this.throwErrorIfAPIURLNotSet();