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.
@@ -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 }
@@ -5612,6 +5676,9 @@ class Dataset extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"] {
5612
5676
  }
5613
5677
  else {
5614
5678
  yield distribution.createDBRecord();
5679
+ if (!this.DistributionIDs) {
5680
+ this.DistributionIDs = [];
5681
+ }
5615
5682
  this.DistributionIDs.push((0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distribution.id));
5616
5683
  }
5617
5684
  }
@@ -5746,6 +5813,7 @@ __webpack_require__.r(__webpack_exports__);
5746
5813
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
5747
5814
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
5748
5815
  /* harmony export */ });
5816
+ /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! axios */ "./node_modules/axios/lib/axios.js");
5749
5817
  /* harmony import */ var _core_error__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/error */ "./lib/core/error.ts");
5750
5818
  /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
5751
5819
  /* harmony import */ var _core_util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/util */ "./lib/core/util.ts");
@@ -5765,10 +5833,105 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
5765
5833
 
5766
5834
 
5767
5835
 
5836
+
5768
5837
  /**
5769
5838
  * Represents a series of datasets.
5770
5839
  */
5771
5840
  class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"] {
5841
+ static syncToCurrentHub(datasetSeries) {
5842
+ return __awaiter(this, void 0, void 0, function* () {
5843
+ var _a;
5844
+ try {
5845
+ const checkExisting = yield DatasetSeries.getDBRecordByAssetID((0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(datasetSeries.assetID));
5846
+ if (checkExisting) {
5847
+ yield checkExisting.populateToSync(datasetSeries);
5848
+ yield checkExisting.updateDBRecord();
5849
+ }
5850
+ }
5851
+ catch (error) {
5852
+ if (axios__WEBPACK_IMPORTED_MODULE_5__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
5853
+ const newDatasetSeries = new DatasetSeries();
5854
+ yield newDatasetSeries.populateToSync(datasetSeries);
5855
+ yield newDatasetSeries.createDBRecord();
5856
+ }
5857
+ else {
5858
+ throw error;
5859
+ }
5860
+ }
5861
+ });
5862
+ }
5863
+ /**
5864
+ * Populates this instance with values from the given DatasetSeries, except for:
5865
+ * - DB identity / temporal fields (ID, IRI, Issued, Modified, CreatedAt, UpdatedAt)
5866
+ * - Version/lineage fields (IsVersionOf, PreviousVersionID, NextVersionID, VersionInfos)
5867
+ * - Series identity fields (DatasetSeriesID, InSeriesID)
5868
+ * - Fields explicitly set to `undefined` on the source instance
5869
+ *
5870
+ * Additionally, when SeriesMembers are present on the source, this method
5871
+ * resolves each member via Dataset.getDBRecordByAssetID (by AssetID) and
5872
+ * replaces this.SeriesMemberIDs with the resolved IDs.
5873
+ */
5874
+ populateToSync(source) {
5875
+ return __awaiter(this, void 0, void 0, function* () {
5876
+ var _a;
5877
+ const excludedKeys = new Set([
5878
+ "ID",
5879
+ "IsVersionOf",
5880
+ "PreviousVersionID",
5881
+ "NextVersionID",
5882
+ "VersionInfos",
5883
+ "DatasetSeriesID",
5884
+ "InSeriesID",
5885
+ ]);
5886
+ for (const key in source) {
5887
+ if (!Object.prototype.hasOwnProperty.call(source, key))
5888
+ continue;
5889
+ if (key === "SeriesMembers")
5890
+ continue;
5891
+ if (excludedKeys.has(key))
5892
+ continue;
5893
+ const value = source[key];
5894
+ if (value !== undefined) {
5895
+ this[key] = value;
5896
+ }
5897
+ }
5898
+ this.SeriesMembers = [];
5899
+ const sourceMembers = source.SeriesMembers;
5900
+ if (!sourceMembers || sourceMembers.length === 0) {
5901
+ return;
5902
+ }
5903
+ const resolvedIDs = [];
5904
+ for (const member of sourceMembers) {
5905
+ if (!member)
5906
+ continue;
5907
+ const assetIDStr = member.assetID;
5908
+ if (!assetIDStr)
5909
+ continue;
5910
+ const assetID = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(assetIDStr);
5911
+ // Prefer existing record by AssetID; if not found, create a new one.
5912
+ try {
5913
+ const existing = yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecordByAssetID(assetID);
5914
+ if (existing) {
5915
+ existing.populateToSync(member);
5916
+ yield existing.updateDBRecord();
5917
+ resolvedIDs.push(existing.id);
5918
+ }
5919
+ }
5920
+ catch (error) {
5921
+ if (axios__WEBPACK_IMPORTED_MODULE_5__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
5922
+ const newMember = new _dataset__WEBPACK_IMPORTED_MODULE_3__["default"]();
5923
+ newMember.populateToSync(member);
5924
+ yield newMember.createDBRecord();
5925
+ resolvedIDs.push(newMember.id);
5926
+ }
5927
+ else {
5928
+ throw error;
5929
+ }
5930
+ }
5931
+ }
5932
+ this.SeriesMemberIDs = resolvedIDs;
5933
+ });
5934
+ }
5772
5935
  /**
5773
5936
  * Initializes or updates the API_URL and LIST_URL for Dataset.
5774
5937
  *
@@ -5809,11 +5972,17 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
5809
5972
  }
5810
5973
  populateSeriesMembersFromDTO(dto) {
5811
5974
  return __awaiter(this, void 0, void 0, function* () {
5975
+ this.SeriesMembers = [];
5812
5976
  if (dto.SeriesMemberIDs && dto.SeriesMemberIDs.length != 0) {
5813
5977
  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
- })));
5978
+ if (this.SeriesMemberIDs && this.SeriesMemberIDs.length != 0) {
5979
+ for (const seriesMemberID of this.SeriesMemberIDs) {
5980
+ const seriesMember = yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecord(seriesMemberID);
5981
+ if (seriesMember) {
5982
+ this.SeriesMembers.push(seriesMember);
5983
+ }
5984
+ }
5985
+ }
5817
5986
  }
5818
5987
  });
5819
5988
  }
@@ -5832,6 +6001,17 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
5832
6001
  yield _super.deleteDBRecord.call(this);
5833
6002
  });
5834
6003
  }
6004
+ /**
6005
+ * Creates a dataset series DB record in an interoperated context
6006
+ * (e.g. together with related Dataset instances or other resources).
6007
+ *
6008
+ * The implementation will be added later.
6009
+ */
6010
+ createInteroperatedDBRecord() {
6011
+ return __awaiter(this, void 0, void 0, function* () {
6012
+ // TODO: Implement interoperated create logic.
6013
+ });
6014
+ }
5835
6015
  appendSeriesMember(dataset) {
5836
6016
  if (!this.SeriesMemberIDs) {
5837
6017
  this.SeriesMemberIDs = [];
@@ -5864,7 +6044,7 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
5864
6044
  get datasetSeriesID() {
5865
6045
  return this.DatasetSeriesID;
5866
6046
  }
5867
- get seriesMembereIDs() {
6047
+ get seriesMemberIDs() {
5868
6048
  return this.SeriesMemberIDs;
5869
6049
  }
5870
6050
  get seriesMembers() {
@@ -6290,8 +6470,8 @@ __webpack_require__.r(__webpack_exports__);
6290
6470
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
6291
6471
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
6292
6472
  /* 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");
6473
+ /* harmony import */ var _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../SODAS_SDK_FILE/dataFile */ "./lib/SODAS_SDK_FILE/dataFile.ts");
6474
+ /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
6295
6475
  /* harmony import */ var _dcatClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../dcatClass */ "./lib/SODAS_SDK_CLASS/dcatClass.ts");
6296
6476
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
6297
6477
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -6306,6 +6486,24 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
6306
6486
 
6307
6487
 
6308
6488
  class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6489
+ /**
6490
+ * Populates this instance with values from the given Distribution, except for:
6491
+ * - DB identity / temporal fields (ID, IRI, Issued, Modified, CreatedAt, UpdatedAt)
6492
+ * - Fields that are explicitly set to `undefined` on the source instance
6493
+ */
6494
+ populateToSync(source) {
6495
+ const excludedKeys = new Set(["ID", "IsDistributionOf", "AccessServiceID"]);
6496
+ for (const key in source) {
6497
+ if (!Object.prototype.hasOwnProperty.call(source, key))
6498
+ continue;
6499
+ if (excludedKeys.has(key))
6500
+ continue;
6501
+ const value = source[key];
6502
+ if (value !== undefined) {
6503
+ this[key] = value;
6504
+ }
6505
+ }
6506
+ }
6309
6507
  toDTO() {
6310
6508
  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
6509
  }
@@ -6317,7 +6515,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6317
6515
  yield _super.populateFromDTO.call(this, dto);
6318
6516
  const distributionDTO = dto;
6319
6517
  distributionDTO.AccessServiceID &&
6320
- (this.AccessServiceID = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(distributionDTO.AccessServiceID));
6518
+ (this.AccessServiceID = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distributionDTO.AccessServiceID));
6321
6519
  distributionDTO.AccessURL && (this.AccessURL = distributionDTO.AccessURL);
6322
6520
  distributionDTO.ByteSize && (this.ByteSize = distributionDTO.ByteSize);
6323
6521
  distributionDTO.CompressFormat &&
@@ -6345,7 +6543,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6345
6543
  distributionDTO.HasPolicy && (this.HasPolicy = distributionDTO.HasPolicy);
6346
6544
  distributionDTO.Checksum && (this.Checksum = distributionDTO.Checksum);
6347
6545
  distributionDTO.IsDistributionOf &&
6348
- (this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(distributionDTO.IsDistributionOf));
6546
+ (this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distributionDTO.IsDistributionOf));
6349
6547
  });
6350
6548
  }
6351
6549
  /**
@@ -6361,7 +6559,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6361
6559
  Distribution.DOWNLOAD_API_URL = `${url}/data/download`;
6362
6560
  }
6363
6561
  static configureBucketName(bucketName) {
6364
- _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"].configureBucketName(bucketName);
6562
+ _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"].configureBucketName(bucketName);
6365
6563
  }
6366
6564
  /**
6367
6565
  * Sets file information for a browser environment.
@@ -6369,7 +6567,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6369
6567
  */
6370
6568
  setUploadingDataForBrowser(file) {
6371
6569
  if (!this.UploadingData) {
6372
- this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"]();
6570
+ this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"]();
6373
6571
  }
6374
6572
  this.UploadingData.setFileForBrowser(file);
6375
6573
  }
@@ -6379,7 +6577,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6379
6577
  */
6380
6578
  setUploadingDataForNode(filePath) {
6381
6579
  if (!this.UploadingData) {
6382
- this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"]();
6580
+ this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"]();
6383
6581
  }
6384
6582
  this.UploadingData.setFileForNode(filePath);
6385
6583
  }
@@ -6572,7 +6770,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6572
6770
  return this.IsDistributionOf;
6573
6771
  }
6574
6772
  set isDistributionOf(value) {
6575
- this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(value);
6773
+ this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(value);
6576
6774
  }
6577
6775
  }
6578
6776
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Distribution);
@@ -6827,6 +7025,27 @@ class DCAT_MODEL extends _sodasSDKClass__WEBPACK_IMPORTED_MODULE_3__["default"]
6827
7025
  }
6828
7026
  });
6829
7027
  }
7028
+ /**
7029
+ * Checks whether a DB record exists for the given AssetID and returns its ID.
7030
+ *
7031
+ * This method wraps getDBRecordByAssetID and converts a 404 response to `null`,
7032
+ * while rethrowing any other kind of error.
7033
+ */
7034
+ static checkDBRecordOfAssetID(assetID) {
7035
+ return __awaiter(this, void 0, void 0, function* () {
7036
+ var _a;
7037
+ try {
7038
+ const record = (yield this.getDBRecordByAssetID(assetID));
7039
+ return record.id;
7040
+ }
7041
+ catch (error) {
7042
+ if (axios__WEBPACK_IMPORTED_MODULE_4__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
7043
+ return null;
7044
+ }
7045
+ throw error;
7046
+ }
7047
+ });
7048
+ }
6830
7049
  updateDBRecord() {
6831
7050
  return __awaiter(this, void 0, void 0, function* () {
6832
7051
  this.throwErrorIfAPIURLNotSet();