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.cjs.js CHANGED
@@ -746,7 +746,7 @@ class NoSuchBucket extends BaseError {
746
746
  }
747
747
  class NoSuchKey extends BaseError {
748
748
  constructor({ bucket, key, ...rest }) {
749
- super({ ...rest, bucket, message: `Key does not exists [bucket:${bucket}/${key}]` });
749
+ super({ ...rest, bucket, message: `Key [${key}] does not exists [bucket:${bucket}/${key}]` });
750
750
  this.key = key;
751
751
  }
752
752
  }
@@ -1185,11 +1185,19 @@ class Client extends EventEmitter {
1185
1185
  }
1186
1186
 
1187
1187
  async function dynamicCrypto() {
1188
- if (lodashEs.isObject(process)) {
1189
- return (await Promise.resolve().then(function () { return _polyfillNode_crypto; })).webcrypto;
1190
- } else {
1191
- return window.crypto;
1188
+ let lib;
1189
+ if (process) {
1190
+ try {
1191
+ const { webcrypto } = await Promise.resolve().then(function () { return _polyfillNode_crypto; });
1192
+ lib = webcrypto;
1193
+ } catch (error) {
1194
+ throw new Error("Crypto API not available");
1195
+ }
1196
+ } else if (window) {
1197
+ lib = window.crypto;
1192
1198
  }
1199
+ if (!lib) throw new Error("Could not load any crypto library");
1200
+ return lib;
1193
1201
  }
1194
1202
  async function sha256(message) {
1195
1203
  const cryptoLib = await dynamicCrypto();
@@ -1336,9 +1344,9 @@ const SchemaActions = {
1336
1344
  toString: (value) => String(value),
1337
1345
  fromArray: (value, { separator }) => (value || []).join(separator),
1338
1346
  toArray: (value, { separator }) => (value || "").split(separator),
1339
- toNumber: (value) => lodashEs.isString(value) ? value.includes(".") ? parseFloat(value) : parseInt(value) : value,
1340
1347
  toJSON: (value) => JSON.stringify(value),
1341
- fromJSON: (value) => JSON.parse(value)
1348
+ fromJSON: (value) => JSON.parse(value),
1349
+ toNumber: (value) => lodashEs.isString(value) ? value.includes(".") ? parseFloat(value) : parseInt(value) : value
1342
1350
  };
1343
1351
  class Schema {
1344
1352
  constructor(args) {
@@ -1407,8 +1415,8 @@ class Schema {
1407
1415
  this.addHook("afterUnmap", name, "toNumber");
1408
1416
  }
1409
1417
  if (definition.includes("boolean")) {
1410
- this.addHook("beforeMap", name, "toJson");
1411
- this.addHook("afterUnmap", name, "fromJson");
1418
+ this.addHook("beforeMap", name, "toJSON");
1419
+ this.addHook("afterUnmap", name, "fromJSON");
1412
1420
  }
1413
1421
  }
1414
1422
  }