s3db.js 13.1.0 → 13.2.1
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/README.md +9 -9
- package/dist/s3db.cjs.js +1079 -271
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.es.js +1079 -271
- package/dist/s3db.es.js.map +1 -1
- package/package.json +2 -1
- package/src/clients/memory-client.class.js +16 -16
- package/src/clients/s3-client.class.js +17 -17
- package/src/concerns/error-classifier.js +204 -0
- package/src/database.class.js +9 -9
- package/src/plugins/backup.plugin.js +8 -8
- package/src/plugins/cache.plugin.js +3 -3
- package/src/plugins/concerns/plugin-dependencies.js +12 -0
- package/src/plugins/geo.plugin.js +2 -2
- package/src/plugins/ml.plugin.js +337 -137
- package/src/plugins/relation.plugin.js +1 -1
- package/src/plugins/replicator.plugin.js +16 -16
- package/src/plugins/s3-queue.plugin.js +5 -5
- package/src/plugins/scheduler.plugin.js +7 -7
- package/src/plugins/state-machine.errors.js +9 -1
- package/src/plugins/state-machine.plugin.js +603 -16
- package/src/plugins/ttl.plugin.js +4 -4
- package/src/plugins/vector.plugin.js +10 -10
- package/src/resource.class.js +58 -40
package/README.md
CHANGED
|
@@ -975,7 +975,7 @@ Intercept and transform method calls:
|
|
|
975
975
|
|
|
976
976
|
```javascript
|
|
977
977
|
// Authentication middleware
|
|
978
|
-
users.useMiddleware('
|
|
978
|
+
users.useMiddleware('inserted', async (ctx, next) => {
|
|
979
979
|
if (!ctx.args[0].userId) {
|
|
980
980
|
throw new Error('Authentication required');
|
|
981
981
|
}
|
|
@@ -983,7 +983,7 @@ users.useMiddleware('insert', async (ctx, next) => {
|
|
|
983
983
|
});
|
|
984
984
|
|
|
985
985
|
// Logging middleware
|
|
986
|
-
users.useMiddleware('
|
|
986
|
+
users.useMiddleware('updated', async (ctx, next) => {
|
|
987
987
|
const start = Date.now();
|
|
988
988
|
const result = await next();
|
|
989
989
|
console.log(`Update took ${Date.now() - start}ms`);
|
|
@@ -991,14 +991,14 @@ users.useMiddleware('update', async (ctx, next) => {
|
|
|
991
991
|
});
|
|
992
992
|
|
|
993
993
|
// Validation middleware
|
|
994
|
-
users.useMiddleware('
|
|
994
|
+
users.useMiddleware('inserted', async (ctx, next) => {
|
|
995
995
|
ctx.args[0].name = ctx.args[0].name.toUpperCase();
|
|
996
996
|
return await next();
|
|
997
997
|
});
|
|
998
998
|
```
|
|
999
999
|
|
|
1000
1000
|
**Supported methods:**
|
|
1001
|
-
`
|
|
1001
|
+
`fetched`, `list`, `inserted`, `updated`, `deleted`, `deleteMany`, `exists`, `getMany`, `count`, `page`, `listIds`, `getAll`
|
|
1002
1002
|
|
|
1003
1003
|
### Events (Real-time Notifications)
|
|
1004
1004
|
|
|
@@ -1031,13 +1031,13 @@ const users = await db.createResource({
|
|
|
1031
1031
|
});
|
|
1032
1032
|
|
|
1033
1033
|
// Programmatic listeners
|
|
1034
|
-
users.on('
|
|
1034
|
+
users.on('inserted', (event) => {
|
|
1035
1035
|
sendWelcomeEmail(event.email);
|
|
1036
1036
|
});
|
|
1037
1037
|
```
|
|
1038
1038
|
|
|
1039
1039
|
**Available events:**
|
|
1040
|
-
`
|
|
1040
|
+
`inserted`, `updated`, `deleted`, `insertMany`, `deleteMany`, `list`, `count`, `fetched`, `getMany`
|
|
1041
1041
|
|
|
1042
1042
|
### Streaming API
|
|
1043
1043
|
|
|
@@ -1221,13 +1221,13 @@ const orders = await db.createResource({
|
|
|
1221
1221
|
});
|
|
1222
1222
|
|
|
1223
1223
|
// Add middlewares for cross-cutting concerns
|
|
1224
|
-
orders.useMiddleware('
|
|
1224
|
+
orders.useMiddleware('inserted', async (ctx, next) => {
|
|
1225
1225
|
// Rate limiting
|
|
1226
1226
|
await checkRateLimit(ctx.args[0].userId);
|
|
1227
1227
|
return await next();
|
|
1228
1228
|
});
|
|
1229
1229
|
|
|
1230
|
-
orders.useMiddleware('
|
|
1230
|
+
orders.useMiddleware('updated', async (ctx, next) => {
|
|
1231
1231
|
// Audit logging
|
|
1232
1232
|
const start = Date.now();
|
|
1233
1233
|
const result = await next();
|
|
@@ -1327,7 +1327,7 @@ export class MyPlugin extends Plugin {
|
|
|
1327
1327
|
console.log('Plugin initialized!');
|
|
1328
1328
|
|
|
1329
1329
|
// Wrap methods
|
|
1330
|
-
this.wrapMethod('Resource', '
|
|
1330
|
+
this.wrapMethod('Resource', 'inserted', async (original, resource, args) => {
|
|
1331
1331
|
console.log(`Inserting into ${resource.name}`);
|
|
1332
1332
|
const result = await original(...args);
|
|
1333
1333
|
console.log(`Inserted: ${result.id}`);
|