s3db.js 3.1.1 → 3.2.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
@@ -1336,9 +1336,9 @@ const SchemaActions = {
1336
1336
  toString: (value) => String(value),
1337
1337
  fromArray: (value, { separator }) => (value || []).join(separator),
1338
1338
  toArray: (value, { separator }) => (value || "").split(separator),
1339
- toNumber: (value) => lodashEs.isString(value) ? value.includes(".") ? parseFloat(value) : parseInt(value) : value,
1340
1339
  toJSON: (value) => JSON.stringify(value),
1341
- fromJSON: (value) => JSON.parse(value)
1340
+ fromJSON: (value) => JSON.parse(value),
1341
+ toNumber: (value) => lodashEs.isString(value) ? value.includes(".") ? parseFloat(value) : parseInt(value) : value
1342
1342
  };
1343
1343
  class Schema {
1344
1344
  constructor(args) {
@@ -1365,7 +1365,7 @@ class Schema {
1365
1365
  this.reversedMap = lodashEs.invert(map);
1366
1366
  } else {
1367
1367
  const flatAttrs = flat.flatten(this.attributes, { safe: true });
1368
- this.reversedMap = { ...Object.keys(flatAttrs).filter((k) => !k.startsWith("$$")) };
1368
+ this.reversedMap = { ...Object.keys(flatAttrs).filter((k) => !k.includes("$$")) };
1369
1369
  this.map = lodashEs.invert(this.reversedMap);
1370
1370
  }
1371
1371
  }
@@ -1407,8 +1407,8 @@ class Schema {
1407
1407
  this.addHook("afterUnmap", name, "toNumber");
1408
1408
  }
1409
1409
  if (definition.includes("boolean")) {
1410
- this.addHook("beforeMap", name, "toJson");
1411
- this.addHook("afterUnmap", name, "fromJson");
1410
+ this.addHook("beforeMap", name, "toJSON");
1411
+ this.addHook("afterUnmap", name, "fromJSON");
1412
1412
  }
1413
1413
  }
1414
1414
  }
@@ -1678,6 +1678,16 @@ class Resource extends EventEmitter {
1678
1678
  this.emit("get", data);
1679
1679
  return data;
1680
1680
  }
1681
+ async exists(id) {
1682
+ try {
1683
+ await this.client.headObject(
1684
+ join(`resource=${this.name}`, `id=${id}`)
1685
+ );
1686
+ return true;
1687
+ } catch (error) {
1688
+ return false;
1689
+ }
1690
+ }
1681
1691
  async update(id, attributes) {
1682
1692
  const live = await this.get(id);
1683
1693
  const attrs = lodashEs.merge(live, attributes);