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.cjs.js CHANGED
@@ -11196,6 +11196,14 @@ class Resource extends EventEmitter {
11196
11196
  this.passphrase = passphrase ?? "secret";
11197
11197
  this.versioningEnabled = versioningEnabled;
11198
11198
  this.idGenerator = this.configureIdGenerator(customIdGenerator, idSize);
11199
+ if (typeof customIdGenerator === "number" && customIdGenerator > 0) {
11200
+ this.idSize = customIdGenerator;
11201
+ } else if (typeof idSize === "number" && idSize > 0) {
11202
+ this.idSize = idSize;
11203
+ } else {
11204
+ this.idSize = 22;
11205
+ }
11206
+ this.idGeneratorType = this.getIdGeneratorType(customIdGenerator, this.idSize);
11199
11207
  this.config = {
11200
11208
  cache,
11201
11209
  hooks,
@@ -11251,7 +11259,7 @@ class Resource extends EventEmitter {
11251
11259
  */
11252
11260
  configureIdGenerator(customIdGenerator, idSize) {
11253
11261
  if (typeof customIdGenerator === "function") {
11254
- return customIdGenerator;
11262
+ return () => String(customIdGenerator());
11255
11263
  }
11256
11264
  if (typeof customIdGenerator === "number" && customIdGenerator > 0) {
11257
11265
  return nanoid.customAlphabet(nanoid.urlAlphabet, customIdGenerator);
@@ -11261,6 +11269,19 @@ class Resource extends EventEmitter {
11261
11269
  }
11262
11270
  return idGenerator;
11263
11271
  }
11272
+ /**
11273
+ * Get a serializable representation of the ID generator type
11274
+ * @param {Function|number} customIdGenerator - Custom ID generator function or size
11275
+ * @param {number} idSize - Size for auto-generated IDs
11276
+ * @returns {string|number} Serializable ID generator type
11277
+ * @private
11278
+ */
11279
+ getIdGeneratorType(customIdGenerator, idSize) {
11280
+ if (typeof customIdGenerator === "function") {
11281
+ return "custom_function";
11282
+ }
11283
+ return idSize;
11284
+ }
11264
11285
  /**
11265
11286
  * Get resource options (for backward compatibility with tests)
11266
11287
  */
@@ -13380,6 +13401,18 @@ class Database extends EventEmitter {
13380
13401
  const currentVersion = resourceMetadata.currentVersion || "v0";
13381
13402
  const versionData = resourceMetadata.versions?.[currentVersion];
13382
13403
  if (versionData) {
13404
+ let restoredIdGenerator, restoredIdSize;
13405
+ if (versionData.idGenerator !== void 0) {
13406
+ if (versionData.idGenerator === "custom_function") {
13407
+ restoredIdGenerator = void 0;
13408
+ restoredIdSize = versionData.idSize || 22;
13409
+ } else if (typeof versionData.idGenerator === "number") {
13410
+ restoredIdGenerator = versionData.idGenerator;
13411
+ restoredIdSize = versionData.idSize || versionData.idGenerator;
13412
+ }
13413
+ } else {
13414
+ restoredIdSize = versionData.idSize || 22;
13415
+ }
13383
13416
  this.resources[name] = new resource_class_default({
13384
13417
  name,
13385
13418
  client: this.client,
@@ -13399,7 +13432,9 @@ class Database extends EventEmitter {
13399
13432
  autoDecrypt: versionData.autoDecrypt !== void 0 ? versionData.autoDecrypt : true,
13400
13433
  hooks: versionData.hooks || {},
13401
13434
  versioningEnabled: this.versioningEnabled,
13402
- map: versionData.map
13435
+ map: versionData.map,
13436
+ idGenerator: restoredIdGenerator,
13437
+ idSize: restoredIdSize
13403
13438
  });
13404
13439
  }
13405
13440
  }
@@ -13560,6 +13595,8 @@ class Database extends EventEmitter {
13560
13595
  autoDecrypt: resource.config.autoDecrypt,
13561
13596
  cache: resource.config.cache,
13562
13597
  hooks: resource.config.hooks,
13598
+ idSize: resource.idSize,
13599
+ idGenerator: resource.idGeneratorType,
13563
13600
  createdAt: isNewVersion ? (/* @__PURE__ */ new Date()).toISOString() : existingVersionData?.createdAt
13564
13601
  }
13565
13602
  }