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.cjs.js +62 -12
- package/dist/s3db.cjs.min.js +7 -7
- package/dist/s3db.es.js +62 -12
- package/dist/s3db.es.min.js +7 -7
- package/dist/s3db.iife.js +62 -12
- package/dist/s3db.iife.min.js +7 -7
- package/package.json +14 -14
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.
|
|
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:
|
|
3610
|
+
attributes: this._exportAttributes(this.attributes),
|
|
3584
3611
|
map: this.map
|
|
3585
3612
|
};
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
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
|
|
3632
|
+
return attrs;
|
|
3594
3633
|
}
|
|
3595
3634
|
async applyHooksActions(resourceItem, hook) {
|
|
3596
3635
|
for (const [attribute, actions] of Object.entries(this.options.hooks[hook])) {
|
|
@@ -9567,8 +9606,13 @@ class Resource extends EventEmitter {
|
|
|
9567
9606
|
* @returns {string} SHA256 hash of the schema definition
|
|
9568
9607
|
*/
|
|
9569
9608
|
getDefinitionHash() {
|
|
9570
|
-
const
|
|
9571
|
-
const
|
|
9609
|
+
const attributes = this.schema.export().attributes;
|
|
9610
|
+
const stableAttributes = { ...attributes };
|
|
9611
|
+
if (this.options.timestamps) {
|
|
9612
|
+
delete stableAttributes.createdAt;
|
|
9613
|
+
delete stableAttributes.updatedAt;
|
|
9614
|
+
}
|
|
9615
|
+
const stableString = jsonStableStringify(stableAttributes);
|
|
9572
9616
|
return `sha256:${crypto.createHash("sha256").update(stableString).digest("hex")}`;
|
|
9573
9617
|
}
|
|
9574
9618
|
/**
|
|
@@ -9762,7 +9806,7 @@ class Database extends EventEmitter {
|
|
|
9762
9806
|
this.version = "1";
|
|
9763
9807
|
this.s3dbVersion = (() => {
|
|
9764
9808
|
try {
|
|
9765
|
-
return true ? "4.
|
|
9809
|
+
return true ? "4.1.1" : "latest";
|
|
9766
9810
|
} catch (e) {
|
|
9767
9811
|
return "latest";
|
|
9768
9812
|
}
|
|
@@ -9877,7 +9921,13 @@ class Database extends EventEmitter {
|
|
|
9877
9921
|
* @returns {string} SHA256 hash
|
|
9878
9922
|
*/
|
|
9879
9923
|
generateDefinitionHash(definition) {
|
|
9880
|
-
const
|
|
9924
|
+
const attributes = definition.attributes;
|
|
9925
|
+
const stableAttributes = { ...attributes };
|
|
9926
|
+
if (definition.options?.timestamps) {
|
|
9927
|
+
delete stableAttributes.createdAt;
|
|
9928
|
+
delete stableAttributes.updatedAt;
|
|
9929
|
+
}
|
|
9930
|
+
const stableString = jsonStableStringify(stableAttributes);
|
|
9881
9931
|
return `sha256:${crypto.createHash("sha256").update(stableString).digest("hex")}`;
|
|
9882
9932
|
}
|
|
9883
9933
|
/**
|