s3db.js 7.4.1 → 7.5.0

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
@@ -7597,11 +7597,11 @@ ${JSON.stringify(validation, null, 2)}`,
7597
7597
  await super.setup(database);
7598
7598
  }
7599
7599
  async onSetup() {
7600
- if (this.config.driver) {
7600
+ if (this.config.driver && typeof this.config.driver === "object") {
7601
7601
  this.driver = this.config.driver;
7602
- } else if (this.config.driverType === "memory") {
7602
+ } else if (this.config.driver === "memory") {
7603
7603
  this.driver = new memory_cache_class_default(this.config.memoryOptions || {});
7604
- } else if (this.config.driverType === "filesystem") {
7604
+ } else if (this.config.driver === "filesystem") {
7605
7605
  if (this.config.partitionAware) {
7606
7606
  this.driver = new PartitionAwareFilesystemCache({
7607
7607
  partitionStrategy: this.config.partitionStrategy,
@@ -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
  */
@@ -13296,7 +13317,7 @@ ${JSON.stringify(validation, null, 2)}`,
13296
13317
  super();
13297
13318
  this.version = "1";
13298
13319
  this.s3dbVersion = (() => {
13299
- const [ok, err, version] = try_fn_default(() => true ? "7.4.1" : "latest");
13320
+ const [ok, err, version] = try_fn_default(() => true ? "7.5.0" : "latest");
13300
13321
  return ok ? version : "latest";
13301
13322
  })();
13302
13323
  this.resources = {};
@@ -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
  }
@@ -14502,6 +14539,10 @@ ${JSON.stringify(validation, null, 2)}`,
14502
14539
  }
14503
14540
  return filtered;
14504
14541
  }
14542
+ async getCompleteData(resource, data) {
14543
+ const [ok, err, completeRecord] = await try_fn_default(() => resource.get(data.id));
14544
+ return ok ? completeRecord : data;
14545
+ }
14505
14546
  installEventListeners(resource, database, plugin) {
14506
14547
  if (!resource || this.eventListenersInstalled.has(resource.name) || resource.name === this.config.replicatorLogResource) {
14507
14548
  return;
@@ -14520,8 +14561,9 @@ ${JSON.stringify(validation, null, 2)}`,
14520
14561
  });
14521
14562
  resource.on("update", async (data, beforeData) => {
14522
14563
  const [ok, error] = await try_fn_default(async () => {
14523
- const completeData = { ...data, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
14524
- await plugin.processReplicatorEvent("update", resource.name, completeData.id, completeData, beforeData);
14564
+ const completeData = await plugin.getCompleteData(resource, data);
14565
+ const dataWithTimestamp = { ...completeData, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
14566
+ await plugin.processReplicatorEvent("update", resource.name, completeData.id, dataWithTimestamp, beforeData);
14525
14567
  });
14526
14568
  if (!ok) {
14527
14569
  if (this.config.verbose) {
@@ -14543,14 +14585,6 @@ ${JSON.stringify(validation, null, 2)}`,
14543
14585
  });
14544
14586
  this.eventListenersInstalled.add(resource.name);
14545
14587
  }
14546
- /**
14547
- * Get complete data by always fetching the full record from the resource
14548
- * This ensures we always have the complete data regardless of behavior or data size
14549
- */
14550
- async getCompleteData(resource, data) {
14551
- const [ok, err, completeRecord] = await try_fn_default(() => resource.get(data.id));
14552
- return ok ? completeRecord : data;
14553
- }
14554
14588
  async setup(database) {
14555
14589
  this.database = database;
14556
14590
  const [initOk, initError] = await try_fn_default(async () => {
@@ -14564,7 +14598,7 @@ ${JSON.stringify(validation, null, 2)}`,
14564
14598
  throw initError;
14565
14599
  }
14566
14600
  const [logOk, logError] = await try_fn_default(async () => {
14567
- if (this.config.replicatorLogResource) {
14601
+ if (this.config.persistReplicatorLog) {
14568
14602
  const logRes = await database.createResource({
14569
14603
  name: this.config.replicatorLogResource,
14570
14604
  behavior: "body-overflow",
@@ -14591,6 +14625,10 @@ ${JSON.stringify(validation, null, 2)}`,
14591
14625
  });
14592
14626
  }
14593
14627
  await this.uploadMetadataFile(database);
14628
+ for (const resourceName in database.resources) {
14629
+ const resource = database.resources[resourceName];
14630
+ this.installEventListeners(resource, database, this);
14631
+ }
14594
14632
  const originalCreateResource = database.createResource.bind(database);
14595
14633
  database.createResource = async (config) => {
14596
14634
  const resource = await originalCreateResource(config);
@@ -14599,10 +14637,6 @@ ${JSON.stringify(validation, null, 2)}`,
14599
14637
  }
14600
14638
  return resource;
14601
14639
  };
14602
- for (const resourceName in database.resources) {
14603
- const resource = database.resources[resourceName];
14604
- this.installEventListeners(resource, database, this);
14605
- }
14606
14640
  }
14607
14641
  createReplicator(driver, config, resources, client) {
14608
14642
  return createReplicator(driver, config, resources, client);