s3db.js 4.1.0 → 4.1.1

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])) {
@@ -9566,7 +9605,19 @@ class Resource extends EventEmitter {
9566
9605
  */
9567
9606
  getDefinitionHash() {
9568
9607
  const exportedSchema = this.schema.export();
9569
- const stableString = jsonStableStringify(exportedSchema);
9608
+ const stableSchema = {
9609
+ ...exportedSchema,
9610
+ attributes: { ...exportedSchema.attributes }
9611
+ };
9612
+ if (this.options.timestamps) {
9613
+ delete stableSchema.attributes.createdAt;
9614
+ delete stableSchema.attributes.updatedAt;
9615
+ if (stableSchema.options && stableSchema.options.partitions) {
9616
+ delete stableSchema.options.partitions.byCreatedDate;
9617
+ delete stableSchema.options.partitions.byUpdatedDate;
9618
+ }
9619
+ }
9620
+ const stableString = jsonStableStringify(stableSchema);
9570
9621
  return `sha256:${createHash("sha256").update(stableString).digest("hex")}`;
9571
9622
  }
9572
9623
  /**
@@ -9760,7 +9811,7 @@ class Database extends EventEmitter {
9760
9811
  this.version = "1";
9761
9812
  this.s3dbVersion = (() => {
9762
9813
  try {
9763
- return true ? "4.0.2" : "latest";
9814
+ return true ? "4.1.0" : "latest";
9764
9815
  } catch (e) {
9765
9816
  return "latest";
9766
9817
  }