s3db.js 7.4.1 → 7.4.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
@@ -11183,6 +11183,14 @@ ${JSON.stringify(validation, null, 2)}`,
11183
11183
  this.passphrase = passphrase ?? "secret";
11184
11184
  this.versioningEnabled = versioningEnabled;
11185
11185
  this.idGenerator = this.configureIdGenerator(customIdGenerator, idSize);
11186
+ if (typeof customIdGenerator === "number" && customIdGenerator > 0) {
11187
+ this.idSize = customIdGenerator;
11188
+ } else if (typeof idSize === "number" && idSize > 0) {
11189
+ this.idSize = idSize;
11190
+ } else {
11191
+ this.idSize = 22;
11192
+ }
11193
+ this.idGeneratorType = this.getIdGeneratorType(customIdGenerator, this.idSize);
11186
11194
  this.config = {
11187
11195
  cache,
11188
11196
  hooks,
@@ -11238,7 +11246,7 @@ ${JSON.stringify(validation, null, 2)}`,
11238
11246
  */
11239
11247
  configureIdGenerator(customIdGenerator, idSize) {
11240
11248
  if (typeof customIdGenerator === "function") {
11241
- return customIdGenerator;
11249
+ return () => String(customIdGenerator());
11242
11250
  }
11243
11251
  if (typeof customIdGenerator === "number" && customIdGenerator > 0) {
11244
11252
  return nanoid.customAlphabet(nanoid.urlAlphabet, customIdGenerator);
@@ -11248,6 +11256,19 @@ ${JSON.stringify(validation, null, 2)}`,
11248
11256
  }
11249
11257
  return idGenerator;
11250
11258
  }
11259
+ /**
11260
+ * Get a serializable representation of the ID generator type
11261
+ * @param {Function|number} customIdGenerator - Custom ID generator function or size
11262
+ * @param {number} idSize - Size for auto-generated IDs
11263
+ * @returns {string|number} Serializable ID generator type
11264
+ * @private
11265
+ */
11266
+ getIdGeneratorType(customIdGenerator, idSize) {
11267
+ if (typeof customIdGenerator === "function") {
11268
+ return "custom_function";
11269
+ }
11270
+ return idSize;
11271
+ }
11251
11272
  /**
11252
11273
  * Get resource options (for backward compatibility with tests)
11253
11274
  */
@@ -13367,6 +13388,18 @@ ${JSON.stringify(validation, null, 2)}`,
13367
13388
  const currentVersion = resourceMetadata.currentVersion || "v0";
13368
13389
  const versionData = resourceMetadata.versions?.[currentVersion];
13369
13390
  if (versionData) {
13391
+ let restoredIdGenerator, restoredIdSize;
13392
+ if (versionData.idGenerator !== void 0) {
13393
+ if (versionData.idGenerator === "custom_function") {
13394
+ restoredIdGenerator = void 0;
13395
+ restoredIdSize = versionData.idSize || 22;
13396
+ } else if (typeof versionData.idGenerator === "number") {
13397
+ restoredIdGenerator = versionData.idGenerator;
13398
+ restoredIdSize = versionData.idSize || versionData.idGenerator;
13399
+ }
13400
+ } else {
13401
+ restoredIdSize = versionData.idSize || 22;
13402
+ }
13370
13403
  this.resources[name] = new resource_class_default({
13371
13404
  name,
13372
13405
  client: this.client,
@@ -13386,7 +13419,9 @@ ${JSON.stringify(validation, null, 2)}`,
13386
13419
  autoDecrypt: versionData.autoDecrypt !== void 0 ? versionData.autoDecrypt : true,
13387
13420
  hooks: versionData.hooks || {},
13388
13421
  versioningEnabled: this.versioningEnabled,
13389
- map: versionData.map
13422
+ map: versionData.map,
13423
+ idGenerator: restoredIdGenerator,
13424
+ idSize: restoredIdSize
13390
13425
  });
13391
13426
  }
13392
13427
  }
@@ -13547,6 +13582,8 @@ ${JSON.stringify(validation, null, 2)}`,
13547
13582
  autoDecrypt: resource.config.autoDecrypt,
13548
13583
  cache: resource.config.cache,
13549
13584
  hooks: resource.config.hooks,
13585
+ idSize: resource.idSize,
13586
+ idGenerator: resource.idGeneratorType,
13550
13587
  createdAt: isNewVersion ? (/* @__PURE__ */ new Date()).toISOString() : existingVersionData?.createdAt
13551
13588
  }
13552
13589
  }