s3db.js 3.2.0 → 3.2.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.iife.js CHANGED
@@ -739,7 +739,7 @@ ${JSON.stringify(rest, null, 2)}`;
739
739
  }
740
740
  class NoSuchKey extends BaseError {
741
741
  constructor({ bucket, key, ...rest }) {
742
- super({ ...rest, bucket, message: `Key does not exists [bucket:${bucket}/${key}]` });
742
+ super({ ...rest, bucket, message: `Key [${key}] does not exists [bucket:${bucket}/${key}]` });
743
743
  this.key = key;
744
744
  }
745
745
  }
@@ -1178,11 +1178,19 @@ ${JSON.stringify(validation, null, 2)}`
1178
1178
  }
1179
1179
 
1180
1180
  async function dynamicCrypto() {
1181
- if (lodashEs.isObject(process)) {
1182
- return (await Promise.resolve().then(function () { return _polyfillNode_crypto; })).webcrypto;
1183
- } else {
1184
- return window.crypto;
1181
+ let lib;
1182
+ if (process) {
1183
+ try {
1184
+ const { webcrypto } = await Promise.resolve().then(function () { return _polyfillNode_crypto; });
1185
+ lib = webcrypto;
1186
+ } catch (error) {
1187
+ throw new Error("Crypto API not available");
1188
+ }
1189
+ } else if (window) {
1190
+ lib = window.crypto;
1185
1191
  }
1192
+ if (!lib) throw new Error("Could not load any crypto library");
1193
+ return lib;
1186
1194
  }
1187
1195
  async function sha256(message) {
1188
1196
  const cryptoLib = await dynamicCrypto();
@@ -1329,9 +1337,9 @@ ${JSON.stringify(validation, null, 2)}`
1329
1337
  toString: (value) => String(value),
1330
1338
  fromArray: (value, { separator }) => (value || []).join(separator),
1331
1339
  toArray: (value, { separator }) => (value || "").split(separator),
1332
- toNumber: (value) => lodashEs.isString(value) ? value.includes(".") ? parseFloat(value) : parseInt(value) : value,
1333
1340
  toJSON: (value) => JSON.stringify(value),
1334
- fromJSON: (value) => JSON.parse(value)
1341
+ fromJSON: (value) => JSON.parse(value),
1342
+ toNumber: (value) => lodashEs.isString(value) ? value.includes(".") ? parseFloat(value) : parseInt(value) : value
1335
1343
  };
1336
1344
  class Schema {
1337
1345
  constructor(args) {
@@ -1400,8 +1408,8 @@ ${JSON.stringify(validation, null, 2)}`
1400
1408
  this.addHook("afterUnmap", name, "toNumber");
1401
1409
  }
1402
1410
  if (definition.includes("boolean")) {
1403
- this.addHook("beforeMap", name, "toJson");
1404
- this.addHook("afterUnmap", name, "fromJson");
1411
+ this.addHook("beforeMap", name, "toJSON");
1412
+ this.addHook("afterUnmap", name, "fromJSON");
1405
1413
  }
1406
1414
  }
1407
1415
  }