s3db.js 4.1.0 → 4.1.2

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.
package/dist/s3db.es.js CHANGED
@@ -936,7 +936,7 @@ class Client extends EventEmitter {
936
936
  Key: this.config.keyPrefix ? path.join(this.config.keyPrefix, key) : key
937
937
  };
938
938
  try {
939
- const response = await this.client.send(new HeadObjectCommand(options2));
939
+ const response = await this.sendCommand(new HeadObjectCommand(options2));
940
940
  this.emit("headObject", response, options2);
941
941
  return response;
942
942
  } catch (error) {
@@ -3564,6 +3564,7 @@ class Schema {
3564
3564
  version,
3565
3565
  attributes
3566
3566
  } = isString$1(data) ? JSON.parse(data) : data;
3567
+ attributes = Schema._importAttributes(attributes);
3567
3568
  const schema = new Schema({
3568
3569
  map,
3569
3570
  name,
@@ -3573,22 +3574,60 @@ class Schema {
3573
3574
  });
3574
3575
  return schema;
3575
3576
  }
3577
+ /**
3578
+ * Recursively import attributes, parsing only stringified objects (legacy)
3579
+ */
3580
+ static _importAttributes(attrs) {
3581
+ if (typeof attrs === "string") {
3582
+ try {
3583
+ const parsed = JSON.parse(attrs);
3584
+ if (typeof parsed === "object" && parsed !== null) {
3585
+ return Schema._importAttributes(parsed);
3586
+ }
3587
+ } catch (e) {
3588
+ }
3589
+ return attrs;
3590
+ }
3591
+ if (Array.isArray(attrs)) {
3592
+ return attrs.map((a) => Schema._importAttributes(a));
3593
+ }
3594
+ if (typeof attrs === "object" && attrs !== null) {
3595
+ const out = {};
3596
+ for (const [k, v] of Object.entries(attrs)) {
3597
+ out[k] = Schema._importAttributes(v);
3598
+ }
3599
+ return out;
3600
+ }
3601
+ return attrs;
3602
+ }
3576
3603
  export() {
3577
3604
  const data = {
3578
3605
  version: this.version,
3579
3606
  name: this.name,
3580
3607
  options: this.options,
3581
- attributes: cloneDeep(this.attributes),
3608
+ attributes: this._exportAttributes(this.attributes),
3582
3609
  map: this.map
3583
3610
  };
3584
- for (const [name, definition] of Object.entries(this.attributes)) {
3585
- if (typeof definition !== "string") {
3586
- data.attributes[name] = JSON.stringify(definition);
3587
- } else {
3588
- data.attributes[name] = definition;
3611
+ return data;
3612
+ }
3613
+ /**
3614
+ * Recursively export attributes, keeping objects as objects and only serializing leaves as string
3615
+ */
3616
+ _exportAttributes(attrs) {
3617
+ if (typeof attrs === "string") {
3618
+ return attrs;
3619
+ }
3620
+ if (Array.isArray(attrs)) {
3621
+ return attrs.map((a) => this._exportAttributes(a));
3622
+ }
3623
+ if (typeof attrs === "object" && attrs !== null) {
3624
+ const out = {};
3625
+ for (const [k, v] of Object.entries(attrs)) {
3626
+ out[k] = this._exportAttributes(v);
3589
3627
  }
3628
+ return out;
3590
3629
  }
3591
- return data;
3630
+ return attrs;
3592
3631
  }
3593
3632
  async applyHooksActions(resourceItem, hook) {
3594
3633
  for (const [attribute, actions] of Object.entries(this.options.hooks[hook])) {
@@ -9565,8 +9604,13 @@ class Resource extends EventEmitter {
9565
9604
  * @returns {string} SHA256 hash of the schema definition
9566
9605
  */
9567
9606
  getDefinitionHash() {
9568
- const exportedSchema = this.schema.export();
9569
- const stableString = jsonStableStringify(exportedSchema);
9607
+ const attributes = this.schema.export().attributes;
9608
+ const stableAttributes = { ...attributes };
9609
+ if (this.options.timestamps) {
9610
+ delete stableAttributes.createdAt;
9611
+ delete stableAttributes.updatedAt;
9612
+ }
9613
+ const stableString = jsonStableStringify(stableAttributes);
9570
9614
  return `sha256:${createHash("sha256").update(stableString).digest("hex")}`;
9571
9615
  }
9572
9616
  /**
@@ -9760,7 +9804,7 @@ class Database extends EventEmitter {
9760
9804
  this.version = "1";
9761
9805
  this.s3dbVersion = (() => {
9762
9806
  try {
9763
- return true ? "4.0.2" : "latest";
9807
+ return true ? "4.1.1" : "latest";
9764
9808
  } catch (e) {
9765
9809
  return "latest";
9766
9810
  }
@@ -9875,7 +9919,13 @@ class Database extends EventEmitter {
9875
9919
  * @returns {string} SHA256 hash
9876
9920
  */
9877
9921
  generateDefinitionHash(definition) {
9878
- const stableString = jsonStableStringify(definition);
9922
+ const attributes = definition.attributes;
9923
+ const stableAttributes = { ...attributes };
9924
+ if (definition.options?.timestamps) {
9925
+ delete stableAttributes.createdAt;
9926
+ delete stableAttributes.updatedAt;
9927
+ }
9928
+ const stableString = jsonStableStringify(stableAttributes);
9879
9929
  return `sha256:${createHash("sha256").update(stableString).digest("hex")}`;
9880
9930
  }
9881
9931
  /**