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.
@@ -5556,6 +5556,70 @@ class Dataset extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"] {
5556
5556
  }
5557
5557
  });
5558
5558
  }
5559
+ static syncToCurrentHub(dataset) {
5560
+ return __awaiter(this, void 0, void 0, function* () {
5561
+ var _a;
5562
+ try {
5563
+ const checkExisting = yield Dataset.getDBRecordByAssetID((0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(dataset.assetID));
5564
+ if (checkExisting) {
5565
+ checkExisting.populateToSync(dataset);
5566
+ yield checkExisting.updateDBRecord();
5567
+ }
5568
+ }
5569
+ catch (error) {
5570
+ if (axios__WEBPACK_IMPORTED_MODULE_6__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
5571
+ const newDataset = new Dataset();
5572
+ newDataset.populateToSync(dataset);
5573
+ yield newDataset.createDBRecord();
5574
+ }
5575
+ else {
5576
+ throw error;
5577
+ }
5578
+ }
5579
+ });
5580
+ }
5581
+ populateToSync(source) {
5582
+ const excludedKeys = new Set([
5583
+ "ID",
5584
+ "DatasetID",
5585
+ "IsVersionOf",
5586
+ "PreviousVersionID",
5587
+ "NextVersionID",
5588
+ "VersionInfos",
5589
+ "InSeriesID",
5590
+ "FirstID",
5591
+ "PreviousID",
5592
+ "NextID",
5593
+ "LastID",
5594
+ "DistributionIDs",
5595
+ ]);
5596
+ for (const key in source) {
5597
+ if (!Object.prototype.hasOwnProperty.call(source, key))
5598
+ continue;
5599
+ if (key === "Distributions")
5600
+ continue;
5601
+ if (excludedKeys.has(key))
5602
+ continue;
5603
+ const value = source[key];
5604
+ if (value !== undefined) {
5605
+ this[key] = value;
5606
+ }
5607
+ }
5608
+ // Handle distributions separately so that we can preserve identity fields
5609
+ // of existing distributions while syncing other fields, and create new
5610
+ // distributions for any additional ones in the source.
5611
+ const sourceDistributions = source.Distributions;
5612
+ if (!sourceDistributions || sourceDistributions.length === 0) {
5613
+ return;
5614
+ }
5615
+ this.Distributions = [];
5616
+ for (let i = 0; i < sourceDistributions.length; i++) {
5617
+ const srcDist = sourceDistributions[i];
5618
+ const targetDist = new _distribution__WEBPACK_IMPORTED_MODULE_5__["default"]();
5619
+ targetDist.populateToSync(srcDist);
5620
+ this.Distributions.push(targetDist);
5621
+ }
5622
+ }
5559
5623
  createDBRecord() {
5560
5624
  const _super = Object.create(null, {
5561
5625
  createDBRecord: { get: () => super.createDBRecord }
@@ -5746,6 +5810,7 @@ __webpack_require__.r(__webpack_exports__);
5746
5810
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
5747
5811
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
5748
5812
  /* harmony export */ });
5813
+ /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! axios */ "./node_modules/axios/lib/axios.js");
5749
5814
  /* harmony import */ var _core_error__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/error */ "./lib/core/error.ts");
5750
5815
  /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
5751
5816
  /* harmony import */ var _core_util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/util */ "./lib/core/util.ts");
@@ -5765,10 +5830,105 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
5765
5830
 
5766
5831
 
5767
5832
 
5833
+
5768
5834
  /**
5769
5835
  * Represents a series of datasets.
5770
5836
  */
5771
5837
  class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"] {
5838
+ static syncToCurrentHub(datasetSeries) {
5839
+ return __awaiter(this, void 0, void 0, function* () {
5840
+ var _a;
5841
+ try {
5842
+ const checkExisting = yield DatasetSeries.getDBRecordByAssetID((0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(datasetSeries.assetID));
5843
+ if (checkExisting) {
5844
+ yield checkExisting.populateToSync(datasetSeries);
5845
+ yield checkExisting.updateDBRecord();
5846
+ }
5847
+ }
5848
+ catch (error) {
5849
+ if (axios__WEBPACK_IMPORTED_MODULE_5__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
5850
+ const newDatasetSeries = new DatasetSeries();
5851
+ yield newDatasetSeries.populateToSync(datasetSeries);
5852
+ yield newDatasetSeries.createDBRecord();
5853
+ }
5854
+ else {
5855
+ throw error;
5856
+ }
5857
+ }
5858
+ });
5859
+ }
5860
+ /**
5861
+ * Populates this instance with values from the given DatasetSeries, except for:
5862
+ * - DB identity / temporal fields (ID, IRI, Issued, Modified, CreatedAt, UpdatedAt)
5863
+ * - Version/lineage fields (IsVersionOf, PreviousVersionID, NextVersionID, VersionInfos)
5864
+ * - Series identity fields (DatasetSeriesID, InSeriesID)
5865
+ * - Fields explicitly set to `undefined` on the source instance
5866
+ *
5867
+ * Additionally, when SeriesMembers are present on the source, this method
5868
+ * resolves each member via Dataset.getDBRecordByAssetID (by AssetID) and
5869
+ * replaces this.SeriesMemberIDs with the resolved IDs.
5870
+ */
5871
+ populateToSync(source) {
5872
+ return __awaiter(this, void 0, void 0, function* () {
5873
+ var _a;
5874
+ const excludedKeys = new Set([
5875
+ "ID",
5876
+ "IsVersionOf",
5877
+ "PreviousVersionID",
5878
+ "NextVersionID",
5879
+ "VersionInfos",
5880
+ "DatasetSeriesID",
5881
+ "InSeriesID",
5882
+ ]);
5883
+ for (const key in source) {
5884
+ if (!Object.prototype.hasOwnProperty.call(source, key))
5885
+ continue;
5886
+ if (key === "SeriesMembers")
5887
+ continue;
5888
+ if (excludedKeys.has(key))
5889
+ continue;
5890
+ const value = source[key];
5891
+ if (value !== undefined) {
5892
+ this[key] = value;
5893
+ }
5894
+ }
5895
+ this.SeriesMembers = [];
5896
+ const sourceMembers = source.SeriesMembers;
5897
+ if (!sourceMembers || sourceMembers.length === 0) {
5898
+ return;
5899
+ }
5900
+ const resolvedIDs = [];
5901
+ for (const member of sourceMembers) {
5902
+ if (!member)
5903
+ continue;
5904
+ const assetIDStr = member.assetID;
5905
+ if (!assetIDStr)
5906
+ continue;
5907
+ const assetID = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(assetIDStr);
5908
+ // Prefer existing record by AssetID; if not found, create a new one.
5909
+ try {
5910
+ const existing = yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecordByAssetID(assetID);
5911
+ if (existing) {
5912
+ existing.populateToSync(member);
5913
+ yield existing.updateDBRecord();
5914
+ resolvedIDs.push(existing.id);
5915
+ }
5916
+ }
5917
+ catch (error) {
5918
+ if (axios__WEBPACK_IMPORTED_MODULE_5__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
5919
+ const newMember = new _dataset__WEBPACK_IMPORTED_MODULE_3__["default"]();
5920
+ newMember.populateToSync(member);
5921
+ yield newMember.createDBRecord();
5922
+ resolvedIDs.push(newMember.id);
5923
+ }
5924
+ else {
5925
+ throw error;
5926
+ }
5927
+ }
5928
+ }
5929
+ this.SeriesMemberIDs = resolvedIDs;
5930
+ });
5931
+ }
5772
5932
  /**
5773
5933
  * Initializes or updates the API_URL and LIST_URL for Dataset.
5774
5934
  *
@@ -5809,11 +5969,17 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
5809
5969
  }
5810
5970
  populateSeriesMembersFromDTO(dto) {
5811
5971
  return __awaiter(this, void 0, void 0, function* () {
5972
+ this.SeriesMembers = [];
5812
5973
  if (dto.SeriesMemberIDs && dto.SeriesMemberIDs.length != 0) {
5813
5974
  this.SeriesMemberIDs = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asIDs)(dto.SeriesMemberIDs);
5814
- this.SeriesMembers = yield Promise.all(dto.SeriesMemberIDs.map((seriesMemberID) => __awaiter(this, void 0, void 0, function* () {
5815
- return yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecord(seriesMemberID);
5816
- })));
5975
+ if (this.SeriesMemberIDs && this.SeriesMemberIDs.length != 0) {
5976
+ for (const seriesMemberID of this.SeriesMemberIDs) {
5977
+ const seriesMember = yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecord(seriesMemberID);
5978
+ if (seriesMember) {
5979
+ this.SeriesMembers.push(seriesMember);
5980
+ }
5981
+ }
5982
+ }
5817
5983
  }
5818
5984
  });
5819
5985
  }
@@ -5832,6 +5998,17 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
5832
5998
  yield _super.deleteDBRecord.call(this);
5833
5999
  });
5834
6000
  }
6001
+ /**
6002
+ * Creates a dataset series DB record in an interoperated context
6003
+ * (e.g. together with related Dataset instances or other resources).
6004
+ *
6005
+ * The implementation will be added later.
6006
+ */
6007
+ createInteroperatedDBRecord() {
6008
+ return __awaiter(this, void 0, void 0, function* () {
6009
+ // TODO: Implement interoperated create logic.
6010
+ });
6011
+ }
5835
6012
  appendSeriesMember(dataset) {
5836
6013
  if (!this.SeriesMemberIDs) {
5837
6014
  this.SeriesMemberIDs = [];
@@ -5864,7 +6041,7 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
5864
6041
  get datasetSeriesID() {
5865
6042
  return this.DatasetSeriesID;
5866
6043
  }
5867
- get seriesMembereIDs() {
6044
+ get seriesMemberIDs() {
5868
6045
  return this.SeriesMemberIDs;
5869
6046
  }
5870
6047
  get seriesMembers() {
@@ -6290,8 +6467,8 @@ __webpack_require__.r(__webpack_exports__);
6290
6467
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
6291
6468
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
6292
6469
  /* harmony export */ });
6293
- /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
6294
- /* harmony import */ var _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../SODAS_SDK_FILE/dataFile */ "./lib/SODAS_SDK_FILE/dataFile.ts");
6470
+ /* harmony import */ var _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../SODAS_SDK_FILE/dataFile */ "./lib/SODAS_SDK_FILE/dataFile.ts");
6471
+ /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
6295
6472
  /* harmony import */ var _dcatClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../dcatClass */ "./lib/SODAS_SDK_CLASS/dcatClass.ts");
6296
6473
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
6297
6474
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -6306,6 +6483,24 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
6306
6483
 
6307
6484
 
6308
6485
  class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6486
+ /**
6487
+ * Populates this instance with values from the given Distribution, except for:
6488
+ * - DB identity / temporal fields (ID, IRI, Issued, Modified, CreatedAt, UpdatedAt)
6489
+ * - Fields that are explicitly set to `undefined` on the source instance
6490
+ */
6491
+ populateToSync(source) {
6492
+ const excludedKeys = new Set(["ID", "IsDistributionOf", "AccessServiceID"]);
6493
+ for (const key in source) {
6494
+ if (!Object.prototype.hasOwnProperty.call(source, key))
6495
+ continue;
6496
+ if (excludedKeys.has(key))
6497
+ continue;
6498
+ const value = source[key];
6499
+ if (value !== undefined) {
6500
+ this[key] = value;
6501
+ }
6502
+ }
6503
+ }
6309
6504
  toDTO() {
6310
6505
  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 });
6311
6506
  }
@@ -6317,7 +6512,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6317
6512
  yield _super.populateFromDTO.call(this, dto);
6318
6513
  const distributionDTO = dto;
6319
6514
  distributionDTO.AccessServiceID &&
6320
- (this.AccessServiceID = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(distributionDTO.AccessServiceID));
6515
+ (this.AccessServiceID = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distributionDTO.AccessServiceID));
6321
6516
  distributionDTO.AccessURL && (this.AccessURL = distributionDTO.AccessURL);
6322
6517
  distributionDTO.ByteSize && (this.ByteSize = distributionDTO.ByteSize);
6323
6518
  distributionDTO.CompressFormat &&
@@ -6345,7 +6540,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6345
6540
  distributionDTO.HasPolicy && (this.HasPolicy = distributionDTO.HasPolicy);
6346
6541
  distributionDTO.Checksum && (this.Checksum = distributionDTO.Checksum);
6347
6542
  distributionDTO.IsDistributionOf &&
6348
- (this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(distributionDTO.IsDistributionOf));
6543
+ (this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distributionDTO.IsDistributionOf));
6349
6544
  });
6350
6545
  }
6351
6546
  /**
@@ -6361,7 +6556,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6361
6556
  Distribution.DOWNLOAD_API_URL = `${url}/data/download`;
6362
6557
  }
6363
6558
  static configureBucketName(bucketName) {
6364
- _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"].configureBucketName(bucketName);
6559
+ _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"].configureBucketName(bucketName);
6365
6560
  }
6366
6561
  /**
6367
6562
  * Sets file information for a browser environment.
@@ -6369,7 +6564,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6369
6564
  */
6370
6565
  setUploadingDataForBrowser(file) {
6371
6566
  if (!this.UploadingData) {
6372
- this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"]();
6567
+ this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"]();
6373
6568
  }
6374
6569
  this.UploadingData.setFileForBrowser(file);
6375
6570
  }
@@ -6379,7 +6574,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6379
6574
  */
6380
6575
  setUploadingDataForNode(filePath) {
6381
6576
  if (!this.UploadingData) {
6382
- this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"]();
6577
+ this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"]();
6383
6578
  }
6384
6579
  this.UploadingData.setFileForNode(filePath);
6385
6580
  }
@@ -6572,7 +6767,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6572
6767
  return this.IsDistributionOf;
6573
6768
  }
6574
6769
  set isDistributionOf(value) {
6575
- this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(value);
6770
+ this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(value);
6576
6771
  }
6577
6772
  }
6578
6773
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Distribution);
@@ -6827,6 +7022,27 @@ class DCAT_MODEL extends _sodasSDKClass__WEBPACK_IMPORTED_MODULE_3__["default"]
6827
7022
  }
6828
7023
  });
6829
7024
  }
7025
+ /**
7026
+ * Checks whether a DB record exists for the given AssetID and returns its ID.
7027
+ *
7028
+ * This method wraps getDBRecordByAssetID and converts a 404 response to `null`,
7029
+ * while rethrowing any other kind of error.
7030
+ */
7031
+ static checkDBRecordOfAssetID(assetID) {
7032
+ return __awaiter(this, void 0, void 0, function* () {
7033
+ var _a;
7034
+ try {
7035
+ const record = (yield this.getDBRecordByAssetID(assetID));
7036
+ return record.id;
7037
+ }
7038
+ catch (error) {
7039
+ if (axios__WEBPACK_IMPORTED_MODULE_4__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
7040
+ return null;
7041
+ }
7042
+ throw error;
7043
+ }
7044
+ });
7045
+ }
6830
7046
  updateDBRecord() {
6831
7047
  return __awaiter(this, void 0, void 0, function* () {
6832
7048
  this.throwErrorIfAPIURLNotSet();