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.cjs.js CHANGED
@@ -938,7 +938,7 @@ class Client extends EventEmitter {
938
938
  Key: this.config.keyPrefix ? path.join(this.config.keyPrefix, key) : key
939
939
  };
940
940
  try {
941
- const response = await this.client.send(new clientS3.HeadObjectCommand(options2));
941
+ const response = await this.sendCommand(new clientS3.HeadObjectCommand(options2));
942
942
  this.emit("headObject", response, options2);
943
943
  return response;
944
944
  } catch (error) {
@@ -3566,6 +3566,7 @@ class Schema {
3566
3566
  version,
3567
3567
  attributes
3568
3568
  } = lodashEs.isString(data) ? JSON.parse(data) : data;
3569
+ attributes = Schema._importAttributes(attributes);
3569
3570
  const schema = new Schema({
3570
3571
  map,
3571
3572
  name,
@@ -3575,22 +3576,60 @@ class Schema {
3575
3576
  });
3576
3577
  return schema;
3577
3578
  }
3579
+ /**
3580
+ * Recursively import attributes, parsing only stringified objects (legacy)
3581
+ */
3582
+ static _importAttributes(attrs) {
3583
+ if (typeof attrs === "string") {
3584
+ try {
3585
+ const parsed = JSON.parse(attrs);
3586
+ if (typeof parsed === "object" && parsed !== null) {
3587
+ return Schema._importAttributes(parsed);
3588
+ }
3589
+ } catch (e) {
3590
+ }
3591
+ return attrs;
3592
+ }
3593
+ if (Array.isArray(attrs)) {
3594
+ return attrs.map((a) => Schema._importAttributes(a));
3595
+ }
3596
+ if (typeof attrs === "object" && attrs !== null) {
3597
+ const out = {};
3598
+ for (const [k, v] of Object.entries(attrs)) {
3599
+ out[k] = Schema._importAttributes(v);
3600
+ }
3601
+ return out;
3602
+ }
3603
+ return attrs;
3604
+ }
3578
3605
  export() {
3579
3606
  const data = {
3580
3607
  version: this.version,
3581
3608
  name: this.name,
3582
3609
  options: this.options,
3583
- attributes: lodashEs.cloneDeep(this.attributes),
3610
+ attributes: this._exportAttributes(this.attributes),
3584
3611
  map: this.map
3585
3612
  };
3586
- for (const [name, definition] of Object.entries(this.attributes)) {
3587
- if (typeof definition !== "string") {
3588
- data.attributes[name] = JSON.stringify(definition);
3589
- } else {
3590
- data.attributes[name] = definition;
3613
+ return data;
3614
+ }
3615
+ /**
3616
+ * Recursively export attributes, keeping objects as objects and only serializing leaves as string
3617
+ */
3618
+ _exportAttributes(attrs) {
3619
+ if (typeof attrs === "string") {
3620
+ return attrs;
3621
+ }
3622
+ if (Array.isArray(attrs)) {
3623
+ return attrs.map((a) => this._exportAttributes(a));
3624
+ }
3625
+ if (typeof attrs === "object" && attrs !== null) {
3626
+ const out = {};
3627
+ for (const [k, v] of Object.entries(attrs)) {
3628
+ out[k] = this._exportAttributes(v);
3591
3629
  }
3630
+ return out;
3592
3631
  }
3593
- return data;
3632
+ return attrs;
3594
3633
  }
3595
3634
  async applyHooksActions(resourceItem, hook) {
3596
3635
  for (const [attribute, actions] of Object.entries(this.options.hooks[hook])) {
@@ -9568,7 +9607,19 @@ class Resource extends EventEmitter {
9568
9607
  */
9569
9608
  getDefinitionHash() {
9570
9609
  const exportedSchema = this.schema.export();
9571
- const stableString = jsonStableStringify(exportedSchema);
9610
+ const stableSchema = {
9611
+ ...exportedSchema,
9612
+ attributes: { ...exportedSchema.attributes }
9613
+ };
9614
+ if (this.options.timestamps) {
9615
+ delete stableSchema.attributes.createdAt;
9616
+ delete stableSchema.attributes.updatedAt;
9617
+ if (stableSchema.options && stableSchema.options.partitions) {
9618
+ delete stableSchema.options.partitions.byCreatedDate;
9619
+ delete stableSchema.options.partitions.byUpdatedDate;
9620
+ }
9621
+ }
9622
+ const stableString = jsonStableStringify(stableSchema);
9572
9623
  return `sha256:${crypto.createHash("sha256").update(stableString).digest("hex")}`;
9573
9624
  }
9574
9625
  /**
@@ -9762,7 +9813,7 @@ class Database extends EventEmitter {
9762
9813
  this.version = "1";
9763
9814
  this.s3dbVersion = (() => {
9764
9815
  try {
9765
- return true ? "4.0.2" : "latest";
9816
+ return true ? "4.1.0" : "latest";
9766
9817
  } catch (e) {
9767
9818
  return "latest";
9768
9819
  }