s3db.js 8.0.1 → 8.0.3
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/PLUGINS.md +114 -39
- package/README.md +1 -25
- package/dist/s3db.cjs.js +79 -26
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +79 -26
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +79 -26
- package/dist/s3db.iife.min.js +1 -1
- package/package.json +1 -1
- package/src/client.class.js +1 -1
- package/src/database.class.js +3 -1
- package/src/plugins/cache/memory-cache.class.js +2 -2
- package/src/plugins/cache.plugin.js +75 -21
- package/src/resource.class.js +11 -5
package/dist/s3db.iife.js
CHANGED
|
@@ -6613,8 +6613,8 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
6613
6613
|
super(config);
|
|
6614
6614
|
this.cache = {};
|
|
6615
6615
|
this.meta = {};
|
|
6616
|
-
this.maxSize = config.maxSize
|
|
6617
|
-
this.ttl = config.ttl
|
|
6616
|
+
this.maxSize = config.maxSize !== void 0 ? config.maxSize : 1e3;
|
|
6617
|
+
this.ttl = config.ttl !== void 0 ? config.ttl : 3e5;
|
|
6618
6618
|
}
|
|
6619
6619
|
async _set(key, data) {
|
|
6620
6620
|
if (this.maxSize > 0 && Object.keys(this.cache).length >= this.maxSize) {
|
|
@@ -7472,37 +7472,81 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7472
7472
|
class CachePlugin extends plugin_class_default {
|
|
7473
7473
|
constructor(options = {}) {
|
|
7474
7474
|
super(options);
|
|
7475
|
-
this.
|
|
7476
|
-
this.
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7475
|
+
this.driverName = options.driver || "s3";
|
|
7476
|
+
this.ttl = options.ttl;
|
|
7477
|
+
this.maxSize = options.maxSize;
|
|
7478
|
+
this.config = options.config || {};
|
|
7479
|
+
this.includePartitions = options.includePartitions !== false;
|
|
7480
|
+
this.partitionStrategy = options.partitionStrategy || "hierarchical";
|
|
7481
|
+
this.partitionAware = options.partitionAware !== false;
|
|
7482
|
+
this.trackUsage = options.trackUsage !== false;
|
|
7483
|
+
this.preloadRelated = options.preloadRelated !== false;
|
|
7484
|
+
this.legacyConfig = {
|
|
7485
|
+
memoryOptions: options.memoryOptions,
|
|
7486
|
+
filesystemOptions: options.filesystemOptions,
|
|
7487
|
+
s3Options: options.s3Options,
|
|
7488
|
+
driver: options.driver
|
|
7483
7489
|
};
|
|
7484
7490
|
}
|
|
7485
7491
|
async setup(database) {
|
|
7486
7492
|
await super.setup(database);
|
|
7487
7493
|
}
|
|
7488
7494
|
async onSetup() {
|
|
7489
|
-
if (this.
|
|
7490
|
-
this.driver = this.
|
|
7491
|
-
} else if (this.
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
+
if (this.driverName && typeof this.driverName === "object") {
|
|
7496
|
+
this.driver = this.driverName;
|
|
7497
|
+
} else if (this.driverName === "memory") {
|
|
7498
|
+
const driverConfig = {
|
|
7499
|
+
...this.legacyConfig.memoryOptions,
|
|
7500
|
+
// Legacy support (lowest priority)
|
|
7501
|
+
...this.config
|
|
7502
|
+
// New config format (medium priority)
|
|
7503
|
+
};
|
|
7504
|
+
if (this.ttl !== void 0) {
|
|
7505
|
+
driverConfig.ttl = this.ttl;
|
|
7506
|
+
}
|
|
7507
|
+
if (this.maxSize !== void 0) {
|
|
7508
|
+
driverConfig.maxSize = this.maxSize;
|
|
7509
|
+
}
|
|
7510
|
+
this.driver = new memory_cache_class_default(driverConfig);
|
|
7511
|
+
} else if (this.driverName === "filesystem") {
|
|
7512
|
+
const driverConfig = {
|
|
7513
|
+
...this.legacyConfig.filesystemOptions,
|
|
7514
|
+
// Legacy support (lowest priority)
|
|
7515
|
+
...this.config
|
|
7516
|
+
// New config format (medium priority)
|
|
7517
|
+
};
|
|
7518
|
+
if (this.ttl !== void 0) {
|
|
7519
|
+
driverConfig.ttl = this.ttl;
|
|
7520
|
+
}
|
|
7521
|
+
if (this.maxSize !== void 0) {
|
|
7522
|
+
driverConfig.maxSize = this.maxSize;
|
|
7523
|
+
}
|
|
7524
|
+
if (this.partitionAware) {
|
|
7495
7525
|
this.driver = new PartitionAwareFilesystemCache({
|
|
7496
|
-
partitionStrategy: this.
|
|
7497
|
-
trackUsage: this.
|
|
7498
|
-
preloadRelated: this.
|
|
7499
|
-
...
|
|
7526
|
+
partitionStrategy: this.partitionStrategy,
|
|
7527
|
+
trackUsage: this.trackUsage,
|
|
7528
|
+
preloadRelated: this.preloadRelated,
|
|
7529
|
+
...driverConfig
|
|
7500
7530
|
});
|
|
7501
7531
|
} else {
|
|
7502
|
-
this.driver = new FilesystemCache(
|
|
7532
|
+
this.driver = new FilesystemCache(driverConfig);
|
|
7503
7533
|
}
|
|
7504
7534
|
} else {
|
|
7505
|
-
|
|
7535
|
+
const driverConfig = {
|
|
7536
|
+
client: this.database.client,
|
|
7537
|
+
// Required for S3Cache
|
|
7538
|
+
...this.legacyConfig.s3Options,
|
|
7539
|
+
// Legacy support (lowest priority)
|
|
7540
|
+
...this.config
|
|
7541
|
+
// New config format (medium priority)
|
|
7542
|
+
};
|
|
7543
|
+
if (this.ttl !== void 0) {
|
|
7544
|
+
driverConfig.ttl = this.ttl;
|
|
7545
|
+
}
|
|
7546
|
+
if (this.maxSize !== void 0) {
|
|
7547
|
+
driverConfig.maxSize = this.maxSize;
|
|
7548
|
+
}
|
|
7549
|
+
this.driver = new s3_cache_class_default(driverConfig);
|
|
7506
7550
|
}
|
|
7507
7551
|
this.installDatabaseHooks();
|
|
7508
7552
|
this.installResourceHooks();
|
|
@@ -9607,7 +9651,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
9607
9651
|
}) {
|
|
9608
9652
|
super();
|
|
9609
9653
|
this.verbose = verbose;
|
|
9610
|
-
this.id = id ?? idGenerator();
|
|
9654
|
+
this.id = id ?? idGenerator(77);
|
|
9611
9655
|
this.parallelism = parallelism;
|
|
9612
9656
|
this.config = new ConnectionString(connectionString);
|
|
9613
9657
|
this.httpClientOptions = {
|
|
@@ -11194,10 +11238,18 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
11194
11238
|
*/
|
|
11195
11239
|
constructor(config = {}) {
|
|
11196
11240
|
super();
|
|
11197
|
-
this._instanceId =
|
|
11241
|
+
this._instanceId = idGenerator(7);
|
|
11198
11242
|
const validation = validateResourceConfig(config);
|
|
11199
11243
|
if (!validation.isValid) {
|
|
11200
|
-
|
|
11244
|
+
const errorDetails = validation.errors.map((err) => ` \u2022 ${err}`).join("\n");
|
|
11245
|
+
throw new ResourceError(
|
|
11246
|
+
`Invalid Resource ${config.name || "[unnamed]"} configuration:
|
|
11247
|
+
${errorDetails}`,
|
|
11248
|
+
{
|
|
11249
|
+
resourceName: config.name,
|
|
11250
|
+
validation: validation.errors
|
|
11251
|
+
}
|
|
11252
|
+
);
|
|
11201
11253
|
}
|
|
11202
11254
|
const {
|
|
11203
11255
|
name,
|
|
@@ -13368,9 +13420,10 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
13368
13420
|
class Database extends EventEmitter {
|
|
13369
13421
|
constructor(options) {
|
|
13370
13422
|
super();
|
|
13423
|
+
this.id = idGenerator(7);
|
|
13371
13424
|
this.version = "1";
|
|
13372
13425
|
this.s3dbVersion = (() => {
|
|
13373
|
-
const [ok, err, version] = try_fn_default(() => true ? "8.0.
|
|
13426
|
+
const [ok, err, version] = try_fn_default(() => true ? "8.0.2" : "latest");
|
|
13374
13427
|
return ok ? version : "latest";
|
|
13375
13428
|
})();
|
|
13376
13429
|
this.resources = {};
|