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 +39 -2
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +39 -2
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +39 -2
- package/dist/s3db.iife.min.js +1 -1
- package/package.json +1 -1
- package/src/database.class.js +22 -1
- package/src/resource.class.js +31 -2
package/dist/s3db.es.js
CHANGED
|
@@ -11192,6 +11192,14 @@ class Resource extends EventEmitter {
|
|
|
11192
11192
|
this.passphrase = passphrase ?? "secret";
|
|
11193
11193
|
this.versioningEnabled = versioningEnabled;
|
|
11194
11194
|
this.idGenerator = this.configureIdGenerator(customIdGenerator, idSize);
|
|
11195
|
+
if (typeof customIdGenerator === "number" && customIdGenerator > 0) {
|
|
11196
|
+
this.idSize = customIdGenerator;
|
|
11197
|
+
} else if (typeof idSize === "number" && idSize > 0) {
|
|
11198
|
+
this.idSize = idSize;
|
|
11199
|
+
} else {
|
|
11200
|
+
this.idSize = 22;
|
|
11201
|
+
}
|
|
11202
|
+
this.idGeneratorType = this.getIdGeneratorType(customIdGenerator, this.idSize);
|
|
11195
11203
|
this.config = {
|
|
11196
11204
|
cache,
|
|
11197
11205
|
hooks,
|
|
@@ -11247,7 +11255,7 @@ class Resource extends EventEmitter {
|
|
|
11247
11255
|
*/
|
|
11248
11256
|
configureIdGenerator(customIdGenerator, idSize) {
|
|
11249
11257
|
if (typeof customIdGenerator === "function") {
|
|
11250
|
-
return customIdGenerator;
|
|
11258
|
+
return () => String(customIdGenerator());
|
|
11251
11259
|
}
|
|
11252
11260
|
if (typeof customIdGenerator === "number" && customIdGenerator > 0) {
|
|
11253
11261
|
return customAlphabet(urlAlphabet, customIdGenerator);
|
|
@@ -11257,6 +11265,19 @@ class Resource extends EventEmitter {
|
|
|
11257
11265
|
}
|
|
11258
11266
|
return idGenerator;
|
|
11259
11267
|
}
|
|
11268
|
+
/**
|
|
11269
|
+
* Get a serializable representation of the ID generator type
|
|
11270
|
+
* @param {Function|number} customIdGenerator - Custom ID generator function or size
|
|
11271
|
+
* @param {number} idSize - Size for auto-generated IDs
|
|
11272
|
+
* @returns {string|number} Serializable ID generator type
|
|
11273
|
+
* @private
|
|
11274
|
+
*/
|
|
11275
|
+
getIdGeneratorType(customIdGenerator, idSize) {
|
|
11276
|
+
if (typeof customIdGenerator === "function") {
|
|
11277
|
+
return "custom_function";
|
|
11278
|
+
}
|
|
11279
|
+
return idSize;
|
|
11280
|
+
}
|
|
11260
11281
|
/**
|
|
11261
11282
|
* Get resource options (for backward compatibility with tests)
|
|
11262
11283
|
*/
|
|
@@ -13376,6 +13397,18 @@ class Database extends EventEmitter {
|
|
|
13376
13397
|
const currentVersion = resourceMetadata.currentVersion || "v0";
|
|
13377
13398
|
const versionData = resourceMetadata.versions?.[currentVersion];
|
|
13378
13399
|
if (versionData) {
|
|
13400
|
+
let restoredIdGenerator, restoredIdSize;
|
|
13401
|
+
if (versionData.idGenerator !== void 0) {
|
|
13402
|
+
if (versionData.idGenerator === "custom_function") {
|
|
13403
|
+
restoredIdGenerator = void 0;
|
|
13404
|
+
restoredIdSize = versionData.idSize || 22;
|
|
13405
|
+
} else if (typeof versionData.idGenerator === "number") {
|
|
13406
|
+
restoredIdGenerator = versionData.idGenerator;
|
|
13407
|
+
restoredIdSize = versionData.idSize || versionData.idGenerator;
|
|
13408
|
+
}
|
|
13409
|
+
} else {
|
|
13410
|
+
restoredIdSize = versionData.idSize || 22;
|
|
13411
|
+
}
|
|
13379
13412
|
this.resources[name] = new resource_class_default({
|
|
13380
13413
|
name,
|
|
13381
13414
|
client: this.client,
|
|
@@ -13395,7 +13428,9 @@ class Database extends EventEmitter {
|
|
|
13395
13428
|
autoDecrypt: versionData.autoDecrypt !== void 0 ? versionData.autoDecrypt : true,
|
|
13396
13429
|
hooks: versionData.hooks || {},
|
|
13397
13430
|
versioningEnabled: this.versioningEnabled,
|
|
13398
|
-
map: versionData.map
|
|
13431
|
+
map: versionData.map,
|
|
13432
|
+
idGenerator: restoredIdGenerator,
|
|
13433
|
+
idSize: restoredIdSize
|
|
13399
13434
|
});
|
|
13400
13435
|
}
|
|
13401
13436
|
}
|
|
@@ -13556,6 +13591,8 @@ class Database extends EventEmitter {
|
|
|
13556
13591
|
autoDecrypt: resource.config.autoDecrypt,
|
|
13557
13592
|
cache: resource.config.cache,
|
|
13558
13593
|
hooks: resource.config.hooks,
|
|
13594
|
+
idSize: resource.idSize,
|
|
13595
|
+
idGenerator: resource.idGeneratorType,
|
|
13559
13596
|
createdAt: isNewVersion ? (/* @__PURE__ */ new Date()).toISOString() : existingVersionData?.createdAt
|
|
13560
13597
|
}
|
|
13561
13598
|
}
|