s3db.js 7.4.2 → 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/PLUGINS.md +3 -3
- package/dist/s3db.cjs.js +16 -19
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +16 -19
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +16 -19
- package/dist/s3db.iife.min.js +1 -1
- package/mcp/server.js +1 -1
- package/package.json +1 -1
- package/src/plugins/cache.plugin.js +4 -4
- package/src/plugins/replicator.plugin.js +19 -19
package/PLUGINS.md
CHANGED
|
@@ -81,7 +81,7 @@ await users.list(); // Cached result
|
|
|
81
81
|
|
|
82
82
|
| Parameter | Type | Default | Description |
|
|
83
83
|
|-----------|------|---------|-------------|
|
|
84
|
-
| `
|
|
84
|
+
| `driver` | string | `'s3'` | Cache driver: `'memory'` or `'s3'` |
|
|
85
85
|
| `ttl` | number | `300000` | Time-to-live in milliseconds (5 minutes) |
|
|
86
86
|
| `maxSize` | number | `1000` | Maximum number of items in cache (memory driver) |
|
|
87
87
|
| `includePartitions` | boolean | `true` | Include partition values in cache keys |
|
|
@@ -113,7 +113,7 @@ import { S3db, CachePlugin } from 's3db.js';
|
|
|
113
113
|
const s3db = new S3db({
|
|
114
114
|
connectionString: "s3://ACCESS_KEY:SECRET_KEY@BUCKET_NAME/databases/myapp",
|
|
115
115
|
plugins: [new CachePlugin({
|
|
116
|
-
|
|
116
|
+
driver: 'memory',
|
|
117
117
|
ttl: 600000, // 10 minutes
|
|
118
118
|
maxSize: 500
|
|
119
119
|
})]
|
|
@@ -3887,7 +3887,7 @@ const s3db = new S3db({
|
|
|
3887
3887
|
plugins: [
|
|
3888
3888
|
// Performance optimization
|
|
3889
3889
|
new CachePlugin({
|
|
3890
|
-
|
|
3890
|
+
driver: 'memory',
|
|
3891
3891
|
ttl: 600000
|
|
3892
3892
|
}),
|
|
3893
3893
|
|
package/dist/s3db.cjs.js
CHANGED
|
@@ -7610,11 +7610,11 @@ class CachePlugin extends plugin_class_default {
|
|
|
7610
7610
|
await super.setup(database);
|
|
7611
7611
|
}
|
|
7612
7612
|
async onSetup() {
|
|
7613
|
-
if (this.config.driver) {
|
|
7613
|
+
if (this.config.driver && typeof this.config.driver === "object") {
|
|
7614
7614
|
this.driver = this.config.driver;
|
|
7615
|
-
} else if (this.config.
|
|
7615
|
+
} else if (this.config.driver === "memory") {
|
|
7616
7616
|
this.driver = new memory_cache_class_default(this.config.memoryOptions || {});
|
|
7617
|
-
} else if (this.config.
|
|
7617
|
+
} else if (this.config.driver === "filesystem") {
|
|
7618
7618
|
if (this.config.partitionAware) {
|
|
7619
7619
|
this.driver = new PartitionAwareFilesystemCache({
|
|
7620
7620
|
partitionStrategy: this.config.partitionStrategy,
|
|
@@ -13330,7 +13330,7 @@ class Database extends EventEmitter {
|
|
|
13330
13330
|
super();
|
|
13331
13331
|
this.version = "1";
|
|
13332
13332
|
this.s3dbVersion = (() => {
|
|
13333
|
-
const [ok, err, version] = try_fn_default(() => true ? "7.
|
|
13333
|
+
const [ok, err, version] = try_fn_default(() => true ? "7.5.0" : "latest");
|
|
13334
13334
|
return ok ? version : "latest";
|
|
13335
13335
|
})();
|
|
13336
13336
|
this.resources = {};
|
|
@@ -14552,6 +14552,10 @@ class ReplicatorPlugin extends plugin_class_default {
|
|
|
14552
14552
|
}
|
|
14553
14553
|
return filtered;
|
|
14554
14554
|
}
|
|
14555
|
+
async getCompleteData(resource, data) {
|
|
14556
|
+
const [ok, err, completeRecord] = await try_fn_default(() => resource.get(data.id));
|
|
14557
|
+
return ok ? completeRecord : data;
|
|
14558
|
+
}
|
|
14555
14559
|
installEventListeners(resource, database, plugin) {
|
|
14556
14560
|
if (!resource || this.eventListenersInstalled.has(resource.name) || resource.name === this.config.replicatorLogResource) {
|
|
14557
14561
|
return;
|
|
@@ -14570,8 +14574,9 @@ class ReplicatorPlugin extends plugin_class_default {
|
|
|
14570
14574
|
});
|
|
14571
14575
|
resource.on("update", async (data, beforeData) => {
|
|
14572
14576
|
const [ok, error] = await try_fn_default(async () => {
|
|
14573
|
-
const completeData =
|
|
14574
|
-
|
|
14577
|
+
const completeData = await plugin.getCompleteData(resource, data);
|
|
14578
|
+
const dataWithTimestamp = { ...completeData, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
14579
|
+
await plugin.processReplicatorEvent("update", resource.name, completeData.id, dataWithTimestamp, beforeData);
|
|
14575
14580
|
});
|
|
14576
14581
|
if (!ok) {
|
|
14577
14582
|
if (this.config.verbose) {
|
|
@@ -14593,14 +14598,6 @@ class ReplicatorPlugin extends plugin_class_default {
|
|
|
14593
14598
|
});
|
|
14594
14599
|
this.eventListenersInstalled.add(resource.name);
|
|
14595
14600
|
}
|
|
14596
|
-
/**
|
|
14597
|
-
* Get complete data by always fetching the full record from the resource
|
|
14598
|
-
* This ensures we always have the complete data regardless of behavior or data size
|
|
14599
|
-
*/
|
|
14600
|
-
async getCompleteData(resource, data) {
|
|
14601
|
-
const [ok, err, completeRecord] = await try_fn_default(() => resource.get(data.id));
|
|
14602
|
-
return ok ? completeRecord : data;
|
|
14603
|
-
}
|
|
14604
14601
|
async setup(database) {
|
|
14605
14602
|
this.database = database;
|
|
14606
14603
|
const [initOk, initError] = await try_fn_default(async () => {
|
|
@@ -14614,7 +14611,7 @@ class ReplicatorPlugin extends plugin_class_default {
|
|
|
14614
14611
|
throw initError;
|
|
14615
14612
|
}
|
|
14616
14613
|
const [logOk, logError] = await try_fn_default(async () => {
|
|
14617
|
-
if (this.config.
|
|
14614
|
+
if (this.config.persistReplicatorLog) {
|
|
14618
14615
|
const logRes = await database.createResource({
|
|
14619
14616
|
name: this.config.replicatorLogResource,
|
|
14620
14617
|
behavior: "body-overflow",
|
|
@@ -14641,6 +14638,10 @@ class ReplicatorPlugin extends plugin_class_default {
|
|
|
14641
14638
|
});
|
|
14642
14639
|
}
|
|
14643
14640
|
await this.uploadMetadataFile(database);
|
|
14641
|
+
for (const resourceName in database.resources) {
|
|
14642
|
+
const resource = database.resources[resourceName];
|
|
14643
|
+
this.installEventListeners(resource, database, this);
|
|
14644
|
+
}
|
|
14644
14645
|
const originalCreateResource = database.createResource.bind(database);
|
|
14645
14646
|
database.createResource = async (config) => {
|
|
14646
14647
|
const resource = await originalCreateResource(config);
|
|
@@ -14649,10 +14650,6 @@ class ReplicatorPlugin extends plugin_class_default {
|
|
|
14649
14650
|
}
|
|
14650
14651
|
return resource;
|
|
14651
14652
|
};
|
|
14652
|
-
for (const resourceName in database.resources) {
|
|
14653
|
-
const resource = database.resources[resourceName];
|
|
14654
|
-
this.installEventListeners(resource, database, this);
|
|
14655
|
-
}
|
|
14656
14653
|
}
|
|
14657
14654
|
createReplicator(driver, config, resources, client) {
|
|
14658
14655
|
return createReplicator(driver, config, resources, client);
|