s3db.js 13.0.0 → 13.1.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.cjs.js +2681 -43
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.es.js +2681 -43
- package/dist/s3db.es.js.map +1 -1
- package/package.json +1 -1
- package/src/plugins/api/index.js +1 -7
- package/src/plugins/api/routes/resource-routes.js +3 -3
- package/src/plugins/api/server.js +29 -9
- package/src/plugins/audit.plugin.js +2 -4
- package/src/plugins/backup.plugin.js +2 -4
- package/src/plugins/cache.plugin.js +1 -3
- package/src/plugins/costs.plugin.js +0 -2
- package/src/plugins/eventual-consistency/index.js +1 -3
- package/src/plugins/fulltext.plugin.js +2 -4
- package/src/plugins/geo.plugin.js +1 -3
- package/src/plugins/importer/index.js +0 -2
- package/src/plugins/index.js +0 -1
- package/src/plugins/metrics.plugin.js +2 -4
- package/src/plugins/ml.plugin.js +794 -32
- package/src/plugins/plugin.class.js +1 -3
- package/src/plugins/queue-consumer.plugin.js +1 -3
- package/src/plugins/relation.plugin.js +1 -3
- package/src/plugins/replicator.plugin.js +2 -4
- package/src/plugins/s3-queue.plugin.js +1 -3
- package/src/plugins/scheduler.plugin.js +2 -4
- package/src/plugins/state-machine.plugin.js +2 -4
- package/src/plugins/tfstate/index.js +0 -2
- package/src/plugins/ttl.plugin.js +36 -21
- package/src/plugins/vector.plugin.js +0 -2
package/package.json
CHANGED
package/src/plugins/api/index.js
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
import { Plugin } from '../plugin.class.js';
|
|
36
36
|
import { requirePluginDependency } from '../concerns/plugin-dependencies.js';
|
|
37
37
|
import tryFn from '../../concerns/try-fn.js';
|
|
38
|
+
import { ApiServer } from './server.js';
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* API Plugin class
|
|
@@ -460,11 +461,6 @@ export class ApiPlugin extends Plugin {
|
|
|
460
461
|
console.log('[API Plugin] Starting server...');
|
|
461
462
|
}
|
|
462
463
|
|
|
463
|
-
// Dynamic import with path manipulation to prevent Rollup from inlining
|
|
464
|
-
// This ensures hono is only loaded when ApiPlugin is actually used
|
|
465
|
-
const serverPath = './server' + '.js';
|
|
466
|
-
const { ApiServer } = await import(/* @vite-ignore */ serverPath);
|
|
467
|
-
|
|
468
464
|
// Create server instance
|
|
469
465
|
this.server = new ApiServer({
|
|
470
466
|
port: this.config.port,
|
|
@@ -546,5 +542,3 @@ export class ApiPlugin extends Plugin {
|
|
|
546
542
|
return this.server ? this.server.getApp() : null;
|
|
547
543
|
}
|
|
548
544
|
}
|
|
549
|
-
|
|
550
|
-
export default ApiPlugin;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Automatically generates REST endpoints for each resource
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { Hono } from 'hono';
|
|
8
7
|
import { asyncHandler } from '../utils/error-handler.js';
|
|
9
8
|
import * as formatter from '../utils/response-formatter.js';
|
|
10
9
|
|
|
@@ -51,9 +50,10 @@ function parseCustomRoute(routeDef) {
|
|
|
51
50
|
* @param {Object} resource - s3db.js Resource instance
|
|
52
51
|
* @param {string} version - Resource version (e.g., 'v1', 'v1')
|
|
53
52
|
* @param {Object} config - Route configuration
|
|
53
|
+
* @param {Function} Hono - Hono constructor (passed from server.js)
|
|
54
54
|
* @returns {Hono} Hono app with resource routes
|
|
55
55
|
*/
|
|
56
|
-
export function createResourceRoutes(resource, version, config = {}) {
|
|
56
|
+
export function createResourceRoutes(resource, version, config = {}, Hono) {
|
|
57
57
|
const app = new Hono();
|
|
58
58
|
const {
|
|
59
59
|
methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'],
|
|
@@ -385,7 +385,7 @@ export function createResourceRoutes(resource, version, config = {}) {
|
|
|
385
385
|
* @param {string} version - Resource version (e.g., 'v1')
|
|
386
386
|
* @returns {Hono} Hono app with relational routes
|
|
387
387
|
*/
|
|
388
|
-
export function createRelationalRoutes(sourceResource, relationName, relationConfig, version) {
|
|
388
|
+
export function createRelationalRoutes(sourceResource, relationName, relationConfig, version, Hono) {
|
|
389
389
|
const app = new Hono();
|
|
390
390
|
const resourceName = sourceResource.name;
|
|
391
391
|
const relatedResourceName = relationConfig.resource;
|
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
* Manages HTTP server lifecycle and routing
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { Hono } from 'hono';
|
|
8
|
-
import { serve } from '@hono/node-server';
|
|
9
|
-
import { swaggerUI } from '@hono/swagger-ui';
|
|
10
7
|
import { createResourceRoutes, createRelationalRoutes } from './routes/resource-routes.js';
|
|
11
8
|
import { errorHandler } from './utils/error-handler.js';
|
|
12
9
|
import * as formatter from './utils/response-formatter.js';
|
|
@@ -46,17 +43,18 @@ export class ApiServer {
|
|
|
46
43
|
}
|
|
47
44
|
};
|
|
48
45
|
|
|
49
|
-
this.app =
|
|
46
|
+
this.app = null; // Will be initialized in start() with dynamic import
|
|
50
47
|
this.server = null;
|
|
51
48
|
this.isRunning = false;
|
|
52
49
|
this.openAPISpec = null;
|
|
50
|
+
this.initialized = false;
|
|
53
51
|
|
|
54
52
|
// Detect if RelationPlugin is installed
|
|
55
53
|
this.relationsPlugin = this.options.database?.plugins?.relation ||
|
|
56
54
|
this.options.database?.plugins?.RelationPlugin ||
|
|
57
55
|
null;
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
// Routes will be setup in start() after dynamic import
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
/**
|
|
@@ -170,7 +168,7 @@ export class ApiServer {
|
|
|
170
168
|
|
|
171
169
|
// API Documentation UI endpoint
|
|
172
170
|
if (this.options.docsUI === 'swagger') {
|
|
173
|
-
this.app.get('/docs', swaggerUI({
|
|
171
|
+
this.app.get('/docs', this.swaggerUI({
|
|
174
172
|
url: '/openapi.json'
|
|
175
173
|
}));
|
|
176
174
|
} else {
|
|
@@ -254,7 +252,7 @@ export class ApiServer {
|
|
|
254
252
|
methods: config.methods,
|
|
255
253
|
customMiddleware: config.customMiddleware || [],
|
|
256
254
|
enableValidation: config.validation !== false
|
|
257
|
-
});
|
|
255
|
+
}, this.Hono);
|
|
258
256
|
|
|
259
257
|
// Mount resource routes
|
|
260
258
|
this.app.route(`/${version}/${name}`, resourceApp);
|
|
@@ -317,7 +315,8 @@ export class ApiServer {
|
|
|
317
315
|
resource,
|
|
318
316
|
relationName,
|
|
319
317
|
relationConfig,
|
|
320
|
-
version
|
|
318
|
+
version,
|
|
319
|
+
this.Hono
|
|
321
320
|
);
|
|
322
321
|
|
|
323
322
|
// Mount relational routes at /{version}/{resource}/:id/{relation}
|
|
@@ -343,11 +342,32 @@ export class ApiServer {
|
|
|
343
342
|
return;
|
|
344
343
|
}
|
|
345
344
|
|
|
345
|
+
// Dynamic import of Hono dependencies (peer dependencies)
|
|
346
|
+
// This ensures hono is only loaded when server actually starts
|
|
347
|
+
if (!this.initialized) {
|
|
348
|
+
const { Hono } = await import('hono');
|
|
349
|
+
const { serve } = await import('@hono/node-server');
|
|
350
|
+
const { swaggerUI } = await import('@hono/swagger-ui');
|
|
351
|
+
|
|
352
|
+
// Store for use in _setupRoutes
|
|
353
|
+
this.Hono = Hono;
|
|
354
|
+
this.serve = serve;
|
|
355
|
+
this.swaggerUI = swaggerUI;
|
|
356
|
+
|
|
357
|
+
// Initialize app
|
|
358
|
+
this.app = new Hono();
|
|
359
|
+
|
|
360
|
+
// Setup all routes
|
|
361
|
+
this._setupRoutes();
|
|
362
|
+
|
|
363
|
+
this.initialized = true;
|
|
364
|
+
}
|
|
365
|
+
|
|
346
366
|
const { port, host } = this.options;
|
|
347
367
|
|
|
348
368
|
return new Promise((resolve, reject) => {
|
|
349
369
|
try {
|
|
350
|
-
this.server = serve({
|
|
370
|
+
this.server = this.serve({
|
|
351
371
|
fetch: this.app.fetch,
|
|
352
372
|
port,
|
|
353
373
|
hostname: host
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Plugin from "./plugin.class.js";
|
|
1
|
+
import { Plugin } from "./plugin.class.js";
|
|
2
2
|
import tryFn from "../concerns/try-fn.js";
|
|
3
3
|
|
|
4
4
|
export class AuditPlugin extends Plugin {
|
|
@@ -420,6 +420,4 @@ export class AuditPlugin extends Plugin {
|
|
|
420
420
|
|
|
421
421
|
return deletedCount;
|
|
422
422
|
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
export default AuditPlugin;
|
|
423
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Plugin from "./plugin.class.js";
|
|
1
|
+
import { Plugin } from "./plugin.class.js";
|
|
2
2
|
import tryFn from "../concerns/try-fn.js";
|
|
3
3
|
import { createBackupDriver, validateBackupConfig } from "./backup/index.js";
|
|
4
4
|
import { StreamingExporter } from "./backup/streaming-exporter.js";
|
|
@@ -982,6 +982,4 @@ export class BackupPlugin extends Plugin {
|
|
|
982
982
|
await this.driver.cleanup();
|
|
983
983
|
}
|
|
984
984
|
}
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
export default BackupPlugin;
|
|
985
|
+
}
|
|
@@ -2,7 +2,7 @@ import { join } from "path";
|
|
|
2
2
|
import jsonStableStringify from "json-stable-stringify";
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
|
|
5
|
-
import Plugin from "./plugin.class.js";
|
|
5
|
+
import { Plugin } from "./plugin.class.js";
|
|
6
6
|
import S3Cache from "./cache/s3-cache.class.js";
|
|
7
7
|
import MemoryCache from "./cache/memory-cache.class.js";
|
|
8
8
|
import { FilesystemCache } from "./cache/filesystem-cache.class.js";
|
|
@@ -781,5 +781,3 @@ export class CachePlugin extends Plugin {
|
|
|
781
781
|
return parts.join(' ');
|
|
782
782
|
}
|
|
783
783
|
}
|
|
784
|
-
|
|
785
|
-
export default CachePlugin;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module eventual-consistency
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import Plugin from "../plugin.class.js";
|
|
7
|
+
import { Plugin } from "../plugin.class.js";
|
|
8
8
|
import { createConfig, validateResourcesConfig, logConfigWarnings, logInitialization } from "./config.js";
|
|
9
9
|
import { detectTimezone, getCohortInfo, createFieldHandler } from "./utils.js";
|
|
10
10
|
import { createPartitionConfig } from "./partitions.js";
|
|
@@ -733,5 +733,3 @@ export class EventualConsistencyPlugin extends Plugin {
|
|
|
733
733
|
return diagnostics;
|
|
734
734
|
}
|
|
735
735
|
}
|
|
736
|
-
|
|
737
|
-
export default EventualConsistencyPlugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Plugin from "./plugin.class.js";
|
|
1
|
+
import { Plugin } from "./plugin.class.js";
|
|
2
2
|
import tryFn from "../concerns/try-fn.js";
|
|
3
3
|
import { FulltextError } from "./fulltext.errors.js";
|
|
4
4
|
|
|
@@ -554,6 +554,4 @@ export class FullTextPlugin extends Plugin {
|
|
|
554
554
|
// Save changes
|
|
555
555
|
await this.saveIndexes();
|
|
556
556
|
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
export default FullTextPlugin;
|
|
557
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Plugin from "./plugin.class.js";
|
|
1
|
+
import { Plugin } from "./plugin.class.js";
|
|
2
2
|
import tryFn from "../concerns/try-fn.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -868,5 +868,3 @@ export class GeoPlugin extends Plugin {
|
|
|
868
868
|
await super.uninstall();
|
|
869
869
|
}
|
|
870
870
|
}
|
|
871
|
-
|
|
872
|
-
export default GeoPlugin;
|
package/src/plugins/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Plugin from "./plugin.class.js";
|
|
1
|
+
import { Plugin } from "./plugin.class.js";
|
|
2
2
|
import tryFn from "../concerns/try-fn.js";
|
|
3
3
|
|
|
4
4
|
export class MetricsPlugin extends Plugin {
|
|
@@ -831,6 +831,4 @@ export class MetricsPlugin extends Plugin {
|
|
|
831
831
|
console.error('[Metrics Plugin] Standalone metrics server error:', err);
|
|
832
832
|
});
|
|
833
833
|
}
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
export default MetricsPlugin;
|
|
834
|
+
}
|