s3db.js 3.3.0 → 3.3.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 +26 -3
- package/dist/s3db.cjs.min.js +4 -4
- package/dist/s3db.es.js +26 -3
- package/dist/s3db.es.min.js +3 -3
- package/dist/s3db.iife.js +26 -3
- package/dist/s3db.iife.min.js +4 -4
- package/package.json +11 -11
package/dist/s3db.iife.js
CHANGED
|
@@ -1617,10 +1617,19 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1617
1617
|
super();
|
|
1618
1618
|
this.name = name;
|
|
1619
1619
|
this.client = client;
|
|
1620
|
-
this.options = options;
|
|
1621
1620
|
this.observers = observers;
|
|
1622
1621
|
this.parallelism = parallelism;
|
|
1623
1622
|
this.passphrase = passphrase ?? "secret";
|
|
1623
|
+
this.options = {
|
|
1624
|
+
cache: false,
|
|
1625
|
+
autoDecrypt: true,
|
|
1626
|
+
timestamps: false,
|
|
1627
|
+
...options
|
|
1628
|
+
};
|
|
1629
|
+
if (options.timestamps) {
|
|
1630
|
+
attributes.createdAt = "string";
|
|
1631
|
+
attributes.updatedAt = "string";
|
|
1632
|
+
}
|
|
1624
1633
|
this.schema = new Schema({
|
|
1625
1634
|
name,
|
|
1626
1635
|
attributes,
|
|
@@ -1646,6 +1655,10 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1646
1655
|
return result;
|
|
1647
1656
|
}
|
|
1648
1657
|
async insert({ id, ...attributes }) {
|
|
1658
|
+
if (this.options.timestamps) {
|
|
1659
|
+
attributes.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1660
|
+
attributes.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1661
|
+
}
|
|
1649
1662
|
const {
|
|
1650
1663
|
errors,
|
|
1651
1664
|
isValid,
|
|
@@ -1676,7 +1689,8 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1676
1689
|
let data = await this.schema.unmapper(request.Metadata);
|
|
1677
1690
|
data.id = id;
|
|
1678
1691
|
data._length = request.ContentLength;
|
|
1679
|
-
data.
|
|
1692
|
+
data._lastModified = request.LastModified;
|
|
1693
|
+
if (request.VersionId) data._versionId = request.VersionId;
|
|
1680
1694
|
if (request.Expiration) data._expiresAt = request.Expiration;
|
|
1681
1695
|
this.emit("get", data);
|
|
1682
1696
|
return data;
|
|
@@ -1693,6 +1707,9 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1693
1707
|
}
|
|
1694
1708
|
async update(id, attributes) {
|
|
1695
1709
|
const live = await this.get(id);
|
|
1710
|
+
if (this.options.timestamps) {
|
|
1711
|
+
attributes.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1712
|
+
}
|
|
1696
1713
|
const attrs = lodashEs.merge(live, attributes);
|
|
1697
1714
|
delete attrs.id;
|
|
1698
1715
|
const { isValid, errors, data: validated } = await this.validate(attrs);
|
|
@@ -1719,6 +1736,13 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1719
1736
|
this.emit("delete", id);
|
|
1720
1737
|
return response;
|
|
1721
1738
|
}
|
|
1739
|
+
async upsert({ id, ...attributes }) {
|
|
1740
|
+
const exists = await this.exists(id);
|
|
1741
|
+
if (exists) {
|
|
1742
|
+
return this.update(id, attributes);
|
|
1743
|
+
}
|
|
1744
|
+
return this.insert({ id, ...attributes });
|
|
1745
|
+
}
|
|
1722
1746
|
async count() {
|
|
1723
1747
|
const count = await this.client.count({
|
|
1724
1748
|
prefix: `resource=${this.name}`
|
|
@@ -1910,7 +1934,6 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1910
1934
|
observers: [this],
|
|
1911
1935
|
client: this.client,
|
|
1912
1936
|
options: {
|
|
1913
|
-
autoDecrypt: true,
|
|
1914
1937
|
cache: this.cache,
|
|
1915
1938
|
...options
|
|
1916
1939
|
}
|