sodas-sdk 1.1.11 → 1.1.13

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 }
@@ -2031,6 +2095,9 @@ class Dataset extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"] {
2031
2095
  }
2032
2096
  else {
2033
2097
  yield distribution.createDBRecord();
2098
+ if (!this.DistributionIDs) {
2099
+ this.DistributionIDs = [];
2100
+ }
2034
2101
  this.DistributionIDs.push((0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distribution.id));
2035
2102
  }
2036
2103
  }
@@ -2165,6 +2232,7 @@ __webpack_require__.r(__webpack_exports__);
2165
2232
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2166
2233
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
2167
2234
  /* harmony export */ });
2235
+ /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! axios */ "./node_modules/axios/lib/axios.js");
2168
2236
  /* harmony import */ var _core_error__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/error */ "./lib/core/error.ts");
2169
2237
  /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
2170
2238
  /* harmony import */ var _core_util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/util */ "./lib/core/util.ts");
@@ -2184,10 +2252,105 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
2184
2252
 
2185
2253
 
2186
2254
 
2255
+
2187
2256
  /**
2188
2257
  * Represents a series of datasets.
2189
2258
  */
2190
2259
  class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"] {
2260
+ static syncToCurrentHub(datasetSeries) {
2261
+ return __awaiter(this, void 0, void 0, function* () {
2262
+ var _a;
2263
+ try {
2264
+ const checkExisting = yield DatasetSeries.getDBRecordByAssetID((0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(datasetSeries.assetID));
2265
+ if (checkExisting) {
2266
+ yield checkExisting.populateToSync(datasetSeries);
2267
+ yield checkExisting.updateDBRecord();
2268
+ }
2269
+ }
2270
+ catch (error) {
2271
+ if (axios__WEBPACK_IMPORTED_MODULE_5__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
2272
+ const newDatasetSeries = new DatasetSeries();
2273
+ yield newDatasetSeries.populateToSync(datasetSeries);
2274
+ yield newDatasetSeries.createDBRecord();
2275
+ }
2276
+ else {
2277
+ throw error;
2278
+ }
2279
+ }
2280
+ });
2281
+ }
2282
+ /**
2283
+ * Populates this instance with values from the given DatasetSeries, except for:
2284
+ * - DB identity / temporal fields (ID, IRI, Issued, Modified, CreatedAt, UpdatedAt)
2285
+ * - Version/lineage fields (IsVersionOf, PreviousVersionID, NextVersionID, VersionInfos)
2286
+ * - Series identity fields (DatasetSeriesID, InSeriesID)
2287
+ * - Fields explicitly set to `undefined` on the source instance
2288
+ *
2289
+ * Additionally, when SeriesMembers are present on the source, this method
2290
+ * resolves each member via Dataset.getDBRecordByAssetID (by AssetID) and
2291
+ * replaces this.SeriesMemberIDs with the resolved IDs.
2292
+ */
2293
+ populateToSync(source) {
2294
+ return __awaiter(this, void 0, void 0, function* () {
2295
+ var _a;
2296
+ const excludedKeys = new Set([
2297
+ "ID",
2298
+ "IsVersionOf",
2299
+ "PreviousVersionID",
2300
+ "NextVersionID",
2301
+ "VersionInfos",
2302
+ "DatasetSeriesID",
2303
+ "InSeriesID",
2304
+ ]);
2305
+ for (const key in source) {
2306
+ if (!Object.prototype.hasOwnProperty.call(source, key))
2307
+ continue;
2308
+ if (key === "SeriesMembers")
2309
+ continue;
2310
+ if (excludedKeys.has(key))
2311
+ continue;
2312
+ const value = source[key];
2313
+ if (value !== undefined) {
2314
+ this[key] = value;
2315
+ }
2316
+ }
2317
+ this.SeriesMembers = [];
2318
+ const sourceMembers = source.SeriesMembers;
2319
+ if (!sourceMembers || sourceMembers.length === 0) {
2320
+ return;
2321
+ }
2322
+ const resolvedIDs = [];
2323
+ for (const member of sourceMembers) {
2324
+ if (!member)
2325
+ continue;
2326
+ const assetIDStr = member.assetID;
2327
+ if (!assetIDStr)
2328
+ continue;
2329
+ const assetID = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(assetIDStr);
2330
+ // Prefer existing record by AssetID; if not found, create a new one.
2331
+ try {
2332
+ const existing = yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecordByAssetID(assetID);
2333
+ if (existing) {
2334
+ existing.populateToSync(member);
2335
+ yield existing.updateDBRecord();
2336
+ resolvedIDs.push(existing.id);
2337
+ }
2338
+ }
2339
+ catch (error) {
2340
+ if (axios__WEBPACK_IMPORTED_MODULE_5__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
2341
+ const newMember = new _dataset__WEBPACK_IMPORTED_MODULE_3__["default"]();
2342
+ newMember.populateToSync(member);
2343
+ yield newMember.createDBRecord();
2344
+ resolvedIDs.push(newMember.id);
2345
+ }
2346
+ else {
2347
+ throw error;
2348
+ }
2349
+ }
2350
+ }
2351
+ this.SeriesMemberIDs = resolvedIDs;
2352
+ });
2353
+ }
2191
2354
  /**
2192
2355
  * Initializes or updates the API_URL and LIST_URL for Dataset.
2193
2356
  *
@@ -2228,11 +2391,17 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
2228
2391
  }
2229
2392
  populateSeriesMembersFromDTO(dto) {
2230
2393
  return __awaiter(this, void 0, void 0, function* () {
2394
+ this.SeriesMembers = [];
2231
2395
  if (dto.SeriesMemberIDs && dto.SeriesMemberIDs.length != 0) {
2232
2396
  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
- })));
2397
+ if (this.SeriesMemberIDs && this.SeriesMemberIDs.length != 0) {
2398
+ for (const seriesMemberID of this.SeriesMemberIDs) {
2399
+ const seriesMember = yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecord(seriesMemberID);
2400
+ if (seriesMember) {
2401
+ this.SeriesMembers.push(seriesMember);
2402
+ }
2403
+ }
2404
+ }
2236
2405
  }
2237
2406
  });
2238
2407
  }
@@ -2251,6 +2420,17 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
2251
2420
  yield _super.deleteDBRecord.call(this);
2252
2421
  });
2253
2422
  }
2423
+ /**
2424
+ * Creates a dataset series DB record in an interoperated context
2425
+ * (e.g. together with related Dataset instances or other resources).
2426
+ *
2427
+ * The implementation will be added later.
2428
+ */
2429
+ createInteroperatedDBRecord() {
2430
+ return __awaiter(this, void 0, void 0, function* () {
2431
+ // TODO: Implement interoperated create logic.
2432
+ });
2433
+ }
2254
2434
  appendSeriesMember(dataset) {
2255
2435
  if (!this.SeriesMemberIDs) {
2256
2436
  this.SeriesMemberIDs = [];
@@ -2283,7 +2463,7 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
2283
2463
  get datasetSeriesID() {
2284
2464
  return this.DatasetSeriesID;
2285
2465
  }
2286
- get seriesMembereIDs() {
2466
+ get seriesMemberIDs() {
2287
2467
  return this.SeriesMemberIDs;
2288
2468
  }
2289
2469
  get seriesMembers() {
@@ -2709,8 +2889,8 @@ __webpack_require__.r(__webpack_exports__);
2709
2889
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2710
2890
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
2711
2891
  /* 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");
2892
+ /* harmony import */ var _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../SODAS_SDK_FILE/dataFile */ "./lib/SODAS_SDK_FILE/dataFile.ts");
2893
+ /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
2714
2894
  /* harmony import */ var _dcatClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../dcatClass */ "./lib/SODAS_SDK_CLASS/dcatClass.ts");
2715
2895
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
2716
2896
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -2725,6 +2905,24 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
2725
2905
 
2726
2906
 
2727
2907
  class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2908
+ /**
2909
+ * Populates this instance with values from the given Distribution, except for:
2910
+ * - DB identity / temporal fields (ID, IRI, Issued, Modified, CreatedAt, UpdatedAt)
2911
+ * - Fields that are explicitly set to `undefined` on the source instance
2912
+ */
2913
+ populateToSync(source) {
2914
+ const excludedKeys = new Set(["ID", "IsDistributionOf", "AccessServiceID"]);
2915
+ for (const key in source) {
2916
+ if (!Object.prototype.hasOwnProperty.call(source, key))
2917
+ continue;
2918
+ if (excludedKeys.has(key))
2919
+ continue;
2920
+ const value = source[key];
2921
+ if (value !== undefined) {
2922
+ this[key] = value;
2923
+ }
2924
+ }
2925
+ }
2728
2926
  toDTO() {
2729
2927
  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
2928
  }
@@ -2736,7 +2934,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2736
2934
  yield _super.populateFromDTO.call(this, dto);
2737
2935
  const distributionDTO = dto;
2738
2936
  distributionDTO.AccessServiceID &&
2739
- (this.AccessServiceID = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(distributionDTO.AccessServiceID));
2937
+ (this.AccessServiceID = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distributionDTO.AccessServiceID));
2740
2938
  distributionDTO.AccessURL && (this.AccessURL = distributionDTO.AccessURL);
2741
2939
  distributionDTO.ByteSize && (this.ByteSize = distributionDTO.ByteSize);
2742
2940
  distributionDTO.CompressFormat &&
@@ -2764,7 +2962,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2764
2962
  distributionDTO.HasPolicy && (this.HasPolicy = distributionDTO.HasPolicy);
2765
2963
  distributionDTO.Checksum && (this.Checksum = distributionDTO.Checksum);
2766
2964
  distributionDTO.IsDistributionOf &&
2767
- (this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(distributionDTO.IsDistributionOf));
2965
+ (this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distributionDTO.IsDistributionOf));
2768
2966
  });
2769
2967
  }
2770
2968
  /**
@@ -2780,7 +2978,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2780
2978
  Distribution.DOWNLOAD_API_URL = `${url}/data/download`;
2781
2979
  }
2782
2980
  static configureBucketName(bucketName) {
2783
- _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"].configureBucketName(bucketName);
2981
+ _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"].configureBucketName(bucketName);
2784
2982
  }
2785
2983
  /**
2786
2984
  * Sets file information for a browser environment.
@@ -2788,7 +2986,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2788
2986
  */
2789
2987
  setUploadingDataForBrowser(file) {
2790
2988
  if (!this.UploadingData) {
2791
- this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"]();
2989
+ this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"]();
2792
2990
  }
2793
2991
  this.UploadingData.setFileForBrowser(file);
2794
2992
  }
@@ -2798,7 +2996,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2798
2996
  */
2799
2997
  setUploadingDataForNode(filePath) {
2800
2998
  if (!this.UploadingData) {
2801
- this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"]();
2999
+ this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"]();
2802
3000
  }
2803
3001
  this.UploadingData.setFileForNode(filePath);
2804
3002
  }
@@ -2991,7 +3189,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
2991
3189
  return this.IsDistributionOf;
2992
3190
  }
2993
3191
  set isDistributionOf(value) {
2994
- this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(value);
3192
+ this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(value);
2995
3193
  }
2996
3194
  }
2997
3195
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Distribution);
@@ -3246,6 +3444,27 @@ class DCAT_MODEL extends _sodasSDKClass__WEBPACK_IMPORTED_MODULE_3__["default"]
3246
3444
  }
3247
3445
  });
3248
3446
  }
3447
+ /**
3448
+ * Checks whether a DB record exists for the given AssetID and returns its ID.
3449
+ *
3450
+ * This method wraps getDBRecordByAssetID and converts a 404 response to `null`,
3451
+ * while rethrowing any other kind of error.
3452
+ */
3453
+ static checkDBRecordOfAssetID(assetID) {
3454
+ return __awaiter(this, void 0, void 0, function* () {
3455
+ var _a;
3456
+ try {
3457
+ const record = (yield this.getDBRecordByAssetID(assetID));
3458
+ return record.id;
3459
+ }
3460
+ catch (error) {
3461
+ if (axios__WEBPACK_IMPORTED_MODULE_4__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
3462
+ return null;
3463
+ }
3464
+ throw error;
3465
+ }
3466
+ });
3467
+ }
3249
3468
  updateDBRecord() {
3250
3469
  return __awaiter(this, void 0, void 0, function* () {
3251
3470
  this.throwErrorIfAPIURLNotSet();