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.
@@ -5540,6 +5540,70 @@ class Dataset extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"] {
5540
5540
  }
5541
5541
  });
5542
5542
  }
5543
+ static syncToCurrentHub(dataset) {
5544
+ return __awaiter(this, void 0, void 0, function* () {
5545
+ var _a;
5546
+ try {
5547
+ const checkExisting = yield Dataset.getDBRecordByAssetID((0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(dataset.assetID));
5548
+ if (checkExisting) {
5549
+ checkExisting.populateToSync(dataset);
5550
+ yield checkExisting.updateDBRecord();
5551
+ }
5552
+ }
5553
+ catch (error) {
5554
+ if (axios__WEBPACK_IMPORTED_MODULE_6__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
5555
+ const newDataset = new Dataset();
5556
+ newDataset.populateToSync(dataset);
5557
+ yield newDataset.createDBRecord();
5558
+ }
5559
+ else {
5560
+ throw error;
5561
+ }
5562
+ }
5563
+ });
5564
+ }
5565
+ populateToSync(source) {
5566
+ const excludedKeys = new Set([
5567
+ "ID",
5568
+ "DatasetID",
5569
+ "IsVersionOf",
5570
+ "PreviousVersionID",
5571
+ "NextVersionID",
5572
+ "VersionInfos",
5573
+ "InSeriesID",
5574
+ "FirstID",
5575
+ "PreviousID",
5576
+ "NextID",
5577
+ "LastID",
5578
+ "DistributionIDs",
5579
+ ]);
5580
+ for (const key in source) {
5581
+ if (!Object.prototype.hasOwnProperty.call(source, key))
5582
+ continue;
5583
+ if (key === "Distributions")
5584
+ continue;
5585
+ if (excludedKeys.has(key))
5586
+ continue;
5587
+ const value = source[key];
5588
+ if (value !== undefined) {
5589
+ this[key] = value;
5590
+ }
5591
+ }
5592
+ // Handle distributions separately so that we can preserve identity fields
5593
+ // of existing distributions while syncing other fields, and create new
5594
+ // distributions for any additional ones in the source.
5595
+ const sourceDistributions = source.Distributions;
5596
+ if (!sourceDistributions || sourceDistributions.length === 0) {
5597
+ return;
5598
+ }
5599
+ this.Distributions = [];
5600
+ for (let i = 0; i < sourceDistributions.length; i++) {
5601
+ const srcDist = sourceDistributions[i];
5602
+ const targetDist = new _distribution__WEBPACK_IMPORTED_MODULE_5__["default"]();
5603
+ targetDist.populateToSync(srcDist);
5604
+ this.Distributions.push(targetDist);
5605
+ }
5606
+ }
5543
5607
  createDBRecord() {
5544
5608
  const _super = Object.create(null, {
5545
5609
  createDBRecord: { get: () => super.createDBRecord }
@@ -5596,6 +5660,9 @@ class Dataset extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"] {
5596
5660
  }
5597
5661
  else {
5598
5662
  yield distribution.createDBRecord();
5663
+ if (!this.DistributionIDs) {
5664
+ this.DistributionIDs = [];
5665
+ }
5599
5666
  this.DistributionIDs.push((0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distribution.id));
5600
5667
  }
5601
5668
  }
@@ -5729,6 +5796,7 @@ __webpack_require__.r(__webpack_exports__);
5729
5796
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
5730
5797
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
5731
5798
  /* harmony export */ });
5799
+ /* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! axios */ "./node_modules/axios/lib/axios.js");
5732
5800
  /* harmony import */ var _core_error__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/error */ "./lib/core/error.ts");
5733
5801
  /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
5734
5802
  /* harmony import */ var _core_util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../core/util */ "./lib/core/util.ts");
@@ -5748,10 +5816,105 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
5748
5816
 
5749
5817
 
5750
5818
 
5819
+
5751
5820
  /**
5752
5821
  * Represents a series of datasets.
5753
5822
  */
5754
5823
  class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"] {
5824
+ static syncToCurrentHub(datasetSeries) {
5825
+ return __awaiter(this, void 0, void 0, function* () {
5826
+ var _a;
5827
+ try {
5828
+ const checkExisting = yield DatasetSeries.getDBRecordByAssetID((0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(datasetSeries.assetID));
5829
+ if (checkExisting) {
5830
+ yield checkExisting.populateToSync(datasetSeries);
5831
+ yield checkExisting.updateDBRecord();
5832
+ }
5833
+ }
5834
+ catch (error) {
5835
+ if (axios__WEBPACK_IMPORTED_MODULE_5__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
5836
+ const newDatasetSeries = new DatasetSeries();
5837
+ yield newDatasetSeries.populateToSync(datasetSeries);
5838
+ yield newDatasetSeries.createDBRecord();
5839
+ }
5840
+ else {
5841
+ throw error;
5842
+ }
5843
+ }
5844
+ });
5845
+ }
5846
+ /**
5847
+ * Populates this instance with values from the given DatasetSeries, except for:
5848
+ * - DB identity / temporal fields (ID, IRI, Issued, Modified, CreatedAt, UpdatedAt)
5849
+ * - Version/lineage fields (IsVersionOf, PreviousVersionID, NextVersionID, VersionInfos)
5850
+ * - Series identity fields (DatasetSeriesID, InSeriesID)
5851
+ * - Fields explicitly set to `undefined` on the source instance
5852
+ *
5853
+ * Additionally, when SeriesMembers are present on the source, this method
5854
+ * resolves each member via Dataset.getDBRecordByAssetID (by AssetID) and
5855
+ * replaces this.SeriesMemberIDs with the resolved IDs.
5856
+ */
5857
+ populateToSync(source) {
5858
+ return __awaiter(this, void 0, void 0, function* () {
5859
+ var _a;
5860
+ const excludedKeys = new Set([
5861
+ "ID",
5862
+ "IsVersionOf",
5863
+ "PreviousVersionID",
5864
+ "NextVersionID",
5865
+ "VersionInfos",
5866
+ "DatasetSeriesID",
5867
+ "InSeriesID",
5868
+ ]);
5869
+ for (const key in source) {
5870
+ if (!Object.prototype.hasOwnProperty.call(source, key))
5871
+ continue;
5872
+ if (key === "SeriesMembers")
5873
+ continue;
5874
+ if (excludedKeys.has(key))
5875
+ continue;
5876
+ const value = source[key];
5877
+ if (value !== undefined) {
5878
+ this[key] = value;
5879
+ }
5880
+ }
5881
+ this.SeriesMembers = [];
5882
+ const sourceMembers = source.SeriesMembers;
5883
+ if (!sourceMembers || sourceMembers.length === 0) {
5884
+ return;
5885
+ }
5886
+ const resolvedIDs = [];
5887
+ for (const member of sourceMembers) {
5888
+ if (!member)
5889
+ continue;
5890
+ const assetIDStr = member.assetID;
5891
+ if (!assetIDStr)
5892
+ continue;
5893
+ const assetID = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(assetIDStr);
5894
+ // Prefer existing record by AssetID; if not found, create a new one.
5895
+ try {
5896
+ const existing = yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecordByAssetID(assetID);
5897
+ if (existing) {
5898
+ existing.populateToSync(member);
5899
+ yield existing.updateDBRecord();
5900
+ resolvedIDs.push(existing.id);
5901
+ }
5902
+ }
5903
+ catch (error) {
5904
+ if (axios__WEBPACK_IMPORTED_MODULE_5__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
5905
+ const newMember = new _dataset__WEBPACK_IMPORTED_MODULE_3__["default"]();
5906
+ newMember.populateToSync(member);
5907
+ yield newMember.createDBRecord();
5908
+ resolvedIDs.push(newMember.id);
5909
+ }
5910
+ else {
5911
+ throw error;
5912
+ }
5913
+ }
5914
+ }
5915
+ this.SeriesMemberIDs = resolvedIDs;
5916
+ });
5917
+ }
5755
5918
  /**
5756
5919
  * Initializes or updates the API_URL and LIST_URL for Dataset.
5757
5920
  *
@@ -5792,11 +5955,17 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
5792
5955
  }
5793
5956
  populateSeriesMembersFromDTO(dto) {
5794
5957
  return __awaiter(this, void 0, void 0, function* () {
5958
+ this.SeriesMembers = [];
5795
5959
  if (dto.SeriesMemberIDs && dto.SeriesMemberIDs.length != 0) {
5796
5960
  this.SeriesMemberIDs = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asIDs)(dto.SeriesMemberIDs);
5797
- this.SeriesMembers = yield Promise.all(dto.SeriesMemberIDs.map((seriesMemberID) => __awaiter(this, void 0, void 0, function* () {
5798
- return yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecord(seriesMemberID);
5799
- })));
5961
+ if (this.SeriesMemberIDs && this.SeriesMemberIDs.length != 0) {
5962
+ for (const seriesMemberID of this.SeriesMemberIDs) {
5963
+ const seriesMember = yield _dataset__WEBPACK_IMPORTED_MODULE_3__["default"].getDBRecord(seriesMemberID);
5964
+ if (seriesMember) {
5965
+ this.SeriesMembers.push(seriesMember);
5966
+ }
5967
+ }
5968
+ }
5800
5969
  }
5801
5970
  });
5802
5971
  }
@@ -5815,6 +5984,17 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
5815
5984
  yield _super.deleteDBRecord.call(this);
5816
5985
  });
5817
5986
  }
5987
+ /**
5988
+ * Creates a dataset series DB record in an interoperated context
5989
+ * (e.g. together with related Dataset instances or other resources).
5990
+ *
5991
+ * The implementation will be added later.
5992
+ */
5993
+ createInteroperatedDBRecord() {
5994
+ return __awaiter(this, void 0, void 0, function* () {
5995
+ // TODO: Implement interoperated create logic.
5996
+ });
5997
+ }
5818
5998
  appendSeriesMember(dataset) {
5819
5999
  if (!this.SeriesMemberIDs) {
5820
6000
  this.SeriesMemberIDs = [];
@@ -5847,7 +6027,7 @@ class DatasetSeries extends _dcatResource__WEBPACK_IMPORTED_MODULE_4__["default"
5847
6027
  get datasetSeriesID() {
5848
6028
  return this.DatasetSeriesID;
5849
6029
  }
5850
- get seriesMembereIDs() {
6030
+ get seriesMemberIDs() {
5851
6031
  return this.SeriesMemberIDs;
5852
6032
  }
5853
6033
  get seriesMembers() {
@@ -6271,8 +6451,8 @@ __webpack_require__.r(__webpack_exports__);
6271
6451
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
6272
6452
  /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
6273
6453
  /* harmony export */ });
6274
- /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
6275
- /* harmony import */ var _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../SODAS_SDK_FILE/dataFile */ "./lib/SODAS_SDK_FILE/dataFile.ts");
6454
+ /* harmony import */ var _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../SODAS_SDK_FILE/dataFile */ "./lib/SODAS_SDK_FILE/dataFile.ts");
6455
+ /* harmony import */ var _core_type__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../core/type */ "./lib/core/type.ts");
6276
6456
  /* harmony import */ var _dcatClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../dcatClass */ "./lib/SODAS_SDK_CLASS/dcatClass.ts");
6277
6457
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
6278
6458
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -6287,6 +6467,24 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
6287
6467
 
6288
6468
 
6289
6469
  class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6470
+ /**
6471
+ * Populates this instance with values from the given Distribution, except for:
6472
+ * - DB identity / temporal fields (ID, IRI, Issued, Modified, CreatedAt, UpdatedAt)
6473
+ * - Fields that are explicitly set to `undefined` on the source instance
6474
+ */
6475
+ populateToSync(source) {
6476
+ const excludedKeys = new Set(["ID", "IsDistributionOf", "AccessServiceID"]);
6477
+ for (const key in source) {
6478
+ if (!Object.prototype.hasOwnProperty.call(source, key))
6479
+ continue;
6480
+ if (excludedKeys.has(key))
6481
+ continue;
6482
+ const value = source[key];
6483
+ if (value !== undefined) {
6484
+ this[key] = value;
6485
+ }
6486
+ }
6487
+ }
6290
6488
  toDTO() {
6291
6489
  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 });
6292
6490
  }
@@ -6298,7 +6496,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6298
6496
  yield _super.populateFromDTO.call(this, dto);
6299
6497
  const distributionDTO = dto;
6300
6498
  distributionDTO.AccessServiceID &&
6301
- (this.AccessServiceID = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(distributionDTO.AccessServiceID));
6499
+ (this.AccessServiceID = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distributionDTO.AccessServiceID));
6302
6500
  distributionDTO.AccessURL && (this.AccessURL = distributionDTO.AccessURL);
6303
6501
  distributionDTO.ByteSize && (this.ByteSize = distributionDTO.ByteSize);
6304
6502
  distributionDTO.CompressFormat &&
@@ -6326,7 +6524,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6326
6524
  distributionDTO.HasPolicy && (this.HasPolicy = distributionDTO.HasPolicy);
6327
6525
  distributionDTO.Checksum && (this.Checksum = distributionDTO.Checksum);
6328
6526
  distributionDTO.IsDistributionOf &&
6329
- (this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(distributionDTO.IsDistributionOf));
6527
+ (this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(distributionDTO.IsDistributionOf));
6330
6528
  });
6331
6529
  }
6332
6530
  /**
@@ -6342,7 +6540,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6342
6540
  Distribution.DOWNLOAD_API_URL = `${url}/data/download`;
6343
6541
  }
6344
6542
  static configureBucketName(bucketName) {
6345
- _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"].configureBucketName(bucketName);
6543
+ _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"].configureBucketName(bucketName);
6346
6544
  }
6347
6545
  /**
6348
6546
  * Sets file information for a browser environment.
@@ -6350,7 +6548,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6350
6548
  */
6351
6549
  setUploadingDataForBrowser(file) {
6352
6550
  if (!this.UploadingData) {
6353
- this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"]();
6551
+ this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"]();
6354
6552
  }
6355
6553
  this.UploadingData.setFileForBrowser(file);
6356
6554
  }
@@ -6360,7 +6558,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6360
6558
  */
6361
6559
  setUploadingDataForNode(filePath) {
6362
6560
  if (!this.UploadingData) {
6363
- this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_1__["default"]();
6561
+ this.UploadingData = new _SODAS_SDK_FILE_dataFile__WEBPACK_IMPORTED_MODULE_0__["default"]();
6364
6562
  }
6365
6563
  this.UploadingData.setFileForNode(filePath);
6366
6564
  }
@@ -6553,7 +6751,7 @@ class Distribution extends _dcatClass__WEBPACK_IMPORTED_MODULE_2__["default"] {
6553
6751
  return this.IsDistributionOf;
6554
6752
  }
6555
6753
  set isDistributionOf(value) {
6556
- this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_0__.asID)(value);
6754
+ this.IsDistributionOf = (0,_core_type__WEBPACK_IMPORTED_MODULE_1__.asID)(value);
6557
6755
  }
6558
6756
  }
6559
6757
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Distribution);
@@ -6806,6 +7004,27 @@ class DCAT_MODEL extends _sodasSDKClass__WEBPACK_IMPORTED_MODULE_3__["default"]
6806
7004
  }
6807
7005
  });
6808
7006
  }
7007
+ /**
7008
+ * Checks whether a DB record exists for the given AssetID and returns its ID.
7009
+ *
7010
+ * This method wraps getDBRecordByAssetID and converts a 404 response to `null`,
7011
+ * while rethrowing any other kind of error.
7012
+ */
7013
+ static checkDBRecordOfAssetID(assetID) {
7014
+ return __awaiter(this, void 0, void 0, function* () {
7015
+ var _a;
7016
+ try {
7017
+ const record = (yield this.getDBRecordByAssetID(assetID));
7018
+ return record.id;
7019
+ }
7020
+ catch (error) {
7021
+ if (axios__WEBPACK_IMPORTED_MODULE_4__["default"].isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
7022
+ return null;
7023
+ }
7024
+ throw error;
7025
+ }
7026
+ });
7027
+ }
6809
7028
  updateDBRecord() {
6810
7029
  return __awaiter(this, void 0, void 0, function* () {
6811
7030
  this.throwErrorIfAPIURLNotSet();