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/mcp/server.js
CHANGED
package/package.json
CHANGED
|
@@ -28,12 +28,12 @@ export class CachePlugin extends Plugin {
|
|
|
28
28
|
|
|
29
29
|
async onSetup() {
|
|
30
30
|
// Initialize cache driver
|
|
31
|
-
if (this.config.driver) {
|
|
32
|
-
// Use custom driver if provided
|
|
31
|
+
if (this.config.driver && typeof this.config.driver === 'object') {
|
|
32
|
+
// Use custom driver instance if provided
|
|
33
33
|
this.driver = this.config.driver;
|
|
34
|
-
} else if (this.config.
|
|
34
|
+
} else if (this.config.driver === 'memory') {
|
|
35
35
|
this.driver = new MemoryCache(this.config.memoryOptions || {});
|
|
36
|
-
} else if (this.config.
|
|
36
|
+
} else if (this.config.driver === 'filesystem') {
|
|
37
37
|
// Use partition-aware filesystem cache if enabled
|
|
38
38
|
if (this.config.partitionAware) {
|
|
39
39
|
this.driver = new PartitionAwareFilesystemCache({
|
|
@@ -164,6 +164,13 @@ export class ReplicatorPlugin extends Plugin {
|
|
|
164
164
|
return filtered;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
async getCompleteData(resource, data) {
|
|
168
|
+
// Always get the complete record from the resource to ensure we have all data
|
|
169
|
+
// This handles all behaviors: body-overflow, truncate-data, body-only, etc.
|
|
170
|
+
const [ok, err, completeRecord] = await tryFn(() => resource.get(data.id));
|
|
171
|
+
return ok ? completeRecord : data;
|
|
172
|
+
}
|
|
173
|
+
|
|
167
174
|
installEventListeners(resource, database, plugin) {
|
|
168
175
|
if (!resource || this.eventListenersInstalled.has(resource.name) ||
|
|
169
176
|
resource.name === this.config.replicatorLogResource) {
|
|
@@ -186,8 +193,10 @@ export class ReplicatorPlugin extends Plugin {
|
|
|
186
193
|
|
|
187
194
|
resource.on('update', async (data, beforeData) => {
|
|
188
195
|
const [ok, error] = await tryFn(async () => {
|
|
189
|
-
|
|
190
|
-
await plugin.
|
|
196
|
+
// For updates, we need to get the complete updated record, not just the changed fields
|
|
197
|
+
const completeData = await plugin.getCompleteData(resource, data);
|
|
198
|
+
const dataWithTimestamp = { ...completeData, updatedAt: new Date().toISOString() };
|
|
199
|
+
await plugin.processReplicatorEvent('update', resource.name, completeData.id, dataWithTimestamp, beforeData);
|
|
191
200
|
});
|
|
192
201
|
|
|
193
202
|
if (!ok) {
|
|
@@ -214,17 +223,6 @@ export class ReplicatorPlugin extends Plugin {
|
|
|
214
223
|
this.eventListenersInstalled.add(resource.name);
|
|
215
224
|
}
|
|
216
225
|
|
|
217
|
-
/**
|
|
218
|
-
* Get complete data by always fetching the full record from the resource
|
|
219
|
-
* This ensures we always have the complete data regardless of behavior or data size
|
|
220
|
-
*/
|
|
221
|
-
async getCompleteData(resource, data) {
|
|
222
|
-
// Always get the complete record from the resource to ensure we have all data
|
|
223
|
-
// This handles all behaviors: body-overflow, truncate-data, body-only, etc.
|
|
224
|
-
const [ok, err, completeRecord] = await tryFn(() => resource.get(data.id));
|
|
225
|
-
return ok ? completeRecord : data;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
226
|
async setup(database) {
|
|
229
227
|
this.database = database;
|
|
230
228
|
|
|
@@ -241,7 +239,7 @@ export class ReplicatorPlugin extends Plugin {
|
|
|
241
239
|
}
|
|
242
240
|
|
|
243
241
|
const [logOk, logError] = await tryFn(async () => {
|
|
244
|
-
if (this.config.
|
|
242
|
+
if (this.config.persistReplicatorLog) {
|
|
245
243
|
const logRes = await database.createResource({
|
|
246
244
|
name: this.config.replicatorLogResource,
|
|
247
245
|
behavior: 'body-overflow',
|
|
@@ -271,6 +269,13 @@ export class ReplicatorPlugin extends Plugin {
|
|
|
271
269
|
|
|
272
270
|
await this.uploadMetadataFile(database);
|
|
273
271
|
|
|
272
|
+
// Install event listeners for existing resources
|
|
273
|
+
for (const resourceName in database.resources) {
|
|
274
|
+
const resource = database.resources[resourceName];
|
|
275
|
+
this.installEventListeners(resource, database, this);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Override createResource to install listeners for new resources
|
|
274
279
|
const originalCreateResource = database.createResource.bind(database);
|
|
275
280
|
database.createResource = async (config) => {
|
|
276
281
|
const resource = await originalCreateResource(config);
|
|
@@ -279,11 +284,6 @@ export class ReplicatorPlugin extends Plugin {
|
|
|
279
284
|
}
|
|
280
285
|
return resource;
|
|
281
286
|
};
|
|
282
|
-
|
|
283
|
-
for (const resourceName in database.resources) {
|
|
284
|
-
const resource = database.resources[resourceName];
|
|
285
|
-
this.installEventListeners(resource, database, this);
|
|
286
|
-
}
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
createReplicator(driver, config, resources, client) {
|