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.iife.js CHANGED
@@ -1329,9 +1329,9 @@ ${JSON.stringify(validation, null, 2)}`
1329
1329
  toString: (value) => String(value),
1330
1330
  fromArray: (value, { separator }) => (value || []).join(separator),
1331
1331
  toArray: (value, { separator }) => (value || "").split(separator),
1332
- toNumber: (value) => lodashEs.isString(value) ? value.includes(".") ? parseFloat(value) : parseInt(value) : value,
1333
1332
  toJSON: (value) => JSON.stringify(value),
1334
- fromJSON: (value) => JSON.parse(value)
1333
+ fromJSON: (value) => JSON.parse(value),
1334
+ toNumber: (value) => lodashEs.isString(value) ? value.includes(".") ? parseFloat(value) : parseInt(value) : value
1335
1335
  };
1336
1336
  class Schema {
1337
1337
  constructor(args) {
@@ -1358,7 +1358,7 @@ ${JSON.stringify(validation, null, 2)}`
1358
1358
  this.reversedMap = lodashEs.invert(map);
1359
1359
  } else {
1360
1360
  const flatAttrs = flat.flatten(this.attributes, { safe: true });
1361
- this.reversedMap = { ...Object.keys(flatAttrs).filter((k) => !k.startsWith("$$")) };
1361
+ this.reversedMap = { ...Object.keys(flatAttrs).filter((k) => !k.includes("$$")) };
1362
1362
  this.map = lodashEs.invert(this.reversedMap);
1363
1363
  }
1364
1364
  }
@@ -1400,8 +1400,8 @@ ${JSON.stringify(validation, null, 2)}`
1400
1400
  this.addHook("afterUnmap", name, "toNumber");
1401
1401
  }
1402
1402
  if (definition.includes("boolean")) {
1403
- this.addHook("beforeMap", name, "toJson");
1404
- this.addHook("afterUnmap", name, "fromJson");
1403
+ this.addHook("beforeMap", name, "toJSON");
1404
+ this.addHook("afterUnmap", name, "fromJSON");
1405
1405
  }
1406
1406
  }
1407
1407
  }
@@ -1671,6 +1671,16 @@ ${JSON.stringify(validation, null, 2)}`
1671
1671
  this.emit("get", data);
1672
1672
  return data;
1673
1673
  }
1674
+ async exists(id) {
1675
+ try {
1676
+ await this.client.headObject(
1677
+ join(`resource=${this.name}`, `id=${id}`)
1678
+ );
1679
+ return true;
1680
+ } catch (error) {
1681
+ return false;
1682
+ }
1683
+ }
1674
1684
  async update(id, attributes) {
1675
1685
  const live = await this.get(id);
1676
1686
  const attrs = lodashEs.merge(live, attributes);