s3db.js 8.0.0 → 8.0.2
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 +227 -0
- package/dist/s3db.cjs.js +77 -31
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.d.ts +5 -0
- package/dist/s3db.es.js +77 -31
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +77 -31
- package/dist/s3db.iife.min.js +1 -1
- package/mcp/server.js +0 -0
- package/package.json +25 -25
- package/src/client.class.js +5 -4
- package/src/plugins/cache/memory-cache.class.js +2 -2
- package/src/plugins/cache.plugin.js +75 -21
- package/src/s3db.d.ts +5 -0
- package/mcp/README.md +0 -1062
package/mcp/server.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "s3db.js",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "Use AWS S3, the world's most reliable document storage, as a database with this ORM.",
|
|
5
5
|
"main": "dist/s3db.cjs.js",
|
|
6
6
|
"module": "dist/s3db.es.js",
|
|
@@ -49,28 +49,6 @@
|
|
|
49
49
|
"PLUGINS.md",
|
|
50
50
|
"UNLICENSE"
|
|
51
51
|
],
|
|
52
|
-
"scripts": {
|
|
53
|
-
"build": "rollup -c",
|
|
54
|
-
"dev": "rollup -c -w",
|
|
55
|
-
"test": "npm run test:js && npm run test:ts",
|
|
56
|
-
"test:js": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --testPathIgnorePatterns=\"plugin-audit.test.js|tests/typescript/\" --testTimeout=10000",
|
|
57
|
-
"test:ts": "tsc --noEmit --project tests/typescript/tsconfig.json",
|
|
58
|
-
"test:js-converage": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --detectOpenHandles --coverage --runInBand",
|
|
59
|
-
"test:js-ai": "node --max-old-space-size=4096 --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --testPathIgnorePatterns=\"plugin-audit.test.js|tests/typescript/\"",
|
|
60
|
-
"test:full": "npm run test:js-ai && npm run test:ts",
|
|
61
|
-
"test:audit": "node --max-old-space-size=8192 --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/plugin-audit.test.js --runInBand --testTimeout=60000",
|
|
62
|
-
"test:cache": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/plugin-cache*.test.js --runInBand",
|
|
63
|
-
"test:quick": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --testTimeout=10000",
|
|
64
|
-
"test:batch": "./test-batch.sh",
|
|
65
|
-
"test:plugins": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/ --runInBand --testTimeout=60000",
|
|
66
|
-
"test:plugins:fast": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/ --runInBand --testTimeout=15000 --testPathIgnorePatterns='plugin-audit.test.js|plugin-replicator-s3db.test.js|plugin-fulltext.test.js'",
|
|
67
|
-
"test:slow": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/plugin-audit.test.js tests/plugins/plugin-replicator-s3db.test.js tests/plugins/plugin-fulltext.test.js --runInBand --testTimeout=120000",
|
|
68
|
-
"test:types": "tsc --noEmit --project tests/typescript/tsconfig.json",
|
|
69
|
-
"test:types:basic": "tsc --noEmit tests/typescript/basic-usage.test.ts",
|
|
70
|
-
"test:types:direct": "tsc --noEmit tests/typescript/direct-type-test.ts",
|
|
71
|
-
"test:types:watch": "tsc --noEmit --watch --project tests/typescript/tsconfig.json",
|
|
72
|
-
"validate:types": "npm run test:types && echo 'TypeScript definitions are valid!'"
|
|
73
|
-
},
|
|
74
52
|
"dependencies": {
|
|
75
53
|
"@aws-sdk/client-s3": "^3.850.0",
|
|
76
54
|
"@smithy/node-http-handler": "^4.1.0",
|
|
@@ -123,5 +101,27 @@
|
|
|
123
101
|
},
|
|
124
102
|
"funding": [
|
|
125
103
|
"https://github.com/sponsors/forattini-dev"
|
|
126
|
-
]
|
|
127
|
-
|
|
104
|
+
],
|
|
105
|
+
"scripts": {
|
|
106
|
+
"build": "rollup -c",
|
|
107
|
+
"dev": "rollup -c -w",
|
|
108
|
+
"test": "npm run test:js && npm run test:ts",
|
|
109
|
+
"test:js": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --testPathIgnorePatterns=\"plugin-audit.test.js|tests/typescript/\" --testTimeout=10000",
|
|
110
|
+
"test:ts": "tsc --noEmit --project tests/typescript/tsconfig.json",
|
|
111
|
+
"test:js-converage": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --detectOpenHandles --coverage --runInBand",
|
|
112
|
+
"test:js-ai": "node --max-old-space-size=4096 --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --testPathIgnorePatterns=\"plugin-audit.test.js|tests/typescript/\"",
|
|
113
|
+
"test:full": "npm run test:js-ai && npm run test:ts",
|
|
114
|
+
"test:audit": "node --max-old-space-size=8192 --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/plugin-audit.test.js --runInBand --testTimeout=60000",
|
|
115
|
+
"test:cache": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/plugin-cache*.test.js --runInBand",
|
|
116
|
+
"test:quick": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --testTimeout=10000",
|
|
117
|
+
"test:batch": "./test-batch.sh",
|
|
118
|
+
"test:plugins": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/ --runInBand --testTimeout=60000",
|
|
119
|
+
"test:plugins:fast": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/ --runInBand --testTimeout=15000 --testPathIgnorePatterns='plugin-audit.test.js|plugin-replicator-s3db.test.js|plugin-fulltext.test.js'",
|
|
120
|
+
"test:slow": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/plugin-audit.test.js tests/plugins/plugin-replicator-s3db.test.js tests/plugins/plugin-fulltext.test.js --runInBand --testTimeout=120000",
|
|
121
|
+
"test:types": "tsc --noEmit --project tests/typescript/tsconfig.json",
|
|
122
|
+
"test:types:basic": "tsc --noEmit tests/typescript/basic-usage.test.ts",
|
|
123
|
+
"test:types:direct": "tsc --noEmit tests/typescript/direct-type-test.ts",
|
|
124
|
+
"test:types:watch": "tsc --noEmit --watch --project tests/typescript/tsconfig.json",
|
|
125
|
+
"validate:types": "npm run test:types && echo 'TypeScript definitions are valid!'"
|
|
126
|
+
}
|
|
127
|
+
}
|
package/src/client.class.js
CHANGED
|
@@ -38,10 +38,11 @@ export class Client extends EventEmitter {
|
|
|
38
38
|
this.parallelism = parallelism;
|
|
39
39
|
this.config = new ConnectionString(connectionString);
|
|
40
40
|
this.httpClientOptions = {
|
|
41
|
-
keepAlive:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
keepAlive: true, // Enabled for better performance
|
|
42
|
+
keepAliveMsecs: 1000, // 1 second keep-alive
|
|
43
|
+
maxSockets: 50, // Balanced for most applications
|
|
44
|
+
maxFreeSockets: 10, // Good connection reuse
|
|
45
|
+
timeout: 60000, // 60 second timeout
|
|
45
46
|
...httpClientOptions,
|
|
46
47
|
};
|
|
47
48
|
this.client = AwsS3Client || this.createClient()
|
|
@@ -91,8 +91,8 @@ export class MemoryCache extends Cache {
|
|
|
91
91
|
super(config);
|
|
92
92
|
this.cache = {};
|
|
93
93
|
this.meta = {};
|
|
94
|
-
this.maxSize = config.maxSize
|
|
95
|
-
this.ttl = config.ttl
|
|
94
|
+
this.maxSize = config.maxSize !== undefined ? config.maxSize : 1000;
|
|
95
|
+
this.ttl = config.ttl !== undefined ? config.ttl : 300000;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
async _set(key, data) {
|
|
@@ -11,14 +11,26 @@ import tryFn from "../concerns/try-fn.js";
|
|
|
11
11
|
export class CachePlugin extends Plugin {
|
|
12
12
|
constructor(options = {}) {
|
|
13
13
|
super(options);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
|
|
15
|
+
// Extract primary configuration
|
|
16
|
+
this.driverName = options.driver || 's3';
|
|
17
|
+
this.ttl = options.ttl;
|
|
18
|
+
this.maxSize = options.maxSize;
|
|
19
|
+
this.config = options.config || {};
|
|
20
|
+
|
|
21
|
+
// Plugin-level settings
|
|
22
|
+
this.includePartitions = options.includePartitions !== false;
|
|
23
|
+
this.partitionStrategy = options.partitionStrategy || 'hierarchical';
|
|
24
|
+
this.partitionAware = options.partitionAware !== false;
|
|
25
|
+
this.trackUsage = options.trackUsage !== false;
|
|
26
|
+
this.preloadRelated = options.preloadRelated !== false;
|
|
27
|
+
|
|
28
|
+
// Legacy support - keep the old options for backward compatibility
|
|
29
|
+
this.legacyConfig = {
|
|
30
|
+
memoryOptions: options.memoryOptions,
|
|
31
|
+
filesystemOptions: options.filesystemOptions,
|
|
32
|
+
s3Options: options.s3Options,
|
|
33
|
+
driver: options.driver
|
|
22
34
|
};
|
|
23
35
|
}
|
|
24
36
|
|
|
@@ -28,26 +40,68 @@ export class CachePlugin extends Plugin {
|
|
|
28
40
|
|
|
29
41
|
async onSetup() {
|
|
30
42
|
// Initialize cache driver
|
|
31
|
-
if (this.
|
|
43
|
+
if (this.driverName && typeof this.driverName === 'object') {
|
|
32
44
|
// Use custom driver instance if provided
|
|
33
|
-
this.driver = this.
|
|
34
|
-
} else if (this.
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
this.driver = this.driverName;
|
|
46
|
+
} else if (this.driverName === 'memory') {
|
|
47
|
+
// Build driver configuration with proper precedence
|
|
48
|
+
const driverConfig = {
|
|
49
|
+
...this.legacyConfig.memoryOptions, // Legacy support (lowest priority)
|
|
50
|
+
...this.config, // New config format (medium priority)
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Add global settings if defined (highest priority)
|
|
54
|
+
if (this.ttl !== undefined) {
|
|
55
|
+
driverConfig.ttl = this.ttl;
|
|
56
|
+
}
|
|
57
|
+
if (this.maxSize !== undefined) {
|
|
58
|
+
driverConfig.maxSize = this.maxSize;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.driver = new MemoryCache(driverConfig);
|
|
62
|
+
} else if (this.driverName === 'filesystem') {
|
|
63
|
+
// Build driver configuration with proper precedence
|
|
64
|
+
const driverConfig = {
|
|
65
|
+
...this.legacyConfig.filesystemOptions, // Legacy support (lowest priority)
|
|
66
|
+
...this.config, // New config format (medium priority)
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Add global settings if defined (highest priority)
|
|
70
|
+
if (this.ttl !== undefined) {
|
|
71
|
+
driverConfig.ttl = this.ttl;
|
|
72
|
+
}
|
|
73
|
+
if (this.maxSize !== undefined) {
|
|
74
|
+
driverConfig.maxSize = this.maxSize;
|
|
75
|
+
}
|
|
76
|
+
|
|
37
77
|
// Use partition-aware filesystem cache if enabled
|
|
38
|
-
if (this.
|
|
78
|
+
if (this.partitionAware) {
|
|
39
79
|
this.driver = new PartitionAwareFilesystemCache({
|
|
40
|
-
partitionStrategy: this.
|
|
41
|
-
trackUsage: this.
|
|
42
|
-
preloadRelated: this.
|
|
43
|
-
...
|
|
80
|
+
partitionStrategy: this.partitionStrategy,
|
|
81
|
+
trackUsage: this.trackUsage,
|
|
82
|
+
preloadRelated: this.preloadRelated,
|
|
83
|
+
...driverConfig
|
|
44
84
|
});
|
|
45
85
|
} else {
|
|
46
|
-
this.driver = new FilesystemCache(
|
|
86
|
+
this.driver = new FilesystemCache(driverConfig);
|
|
47
87
|
}
|
|
48
88
|
} else {
|
|
49
|
-
// Default to S3Cache
|
|
50
|
-
|
|
89
|
+
// Default to S3Cache - build driver configuration with proper precedence
|
|
90
|
+
const driverConfig = {
|
|
91
|
+
client: this.database.client, // Required for S3Cache
|
|
92
|
+
...this.legacyConfig.s3Options, // Legacy support (lowest priority)
|
|
93
|
+
...this.config, // New config format (medium priority)
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// Add global settings if defined (highest priority)
|
|
97
|
+
if (this.ttl !== undefined) {
|
|
98
|
+
driverConfig.ttl = this.ttl;
|
|
99
|
+
}
|
|
100
|
+
if (this.maxSize !== undefined) {
|
|
101
|
+
driverConfig.maxSize = this.maxSize;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this.driver = new S3Cache(driverConfig);
|
|
51
105
|
}
|
|
52
106
|
|
|
53
107
|
// Use database hooks instead of method overwriting
|
package/src/s3db.d.ts
CHANGED
|
@@ -8,10 +8,15 @@ declare module 's3db.js' {
|
|
|
8
8
|
|
|
9
9
|
/** HTTP Client configuration for keep-alive and connection pooling */
|
|
10
10
|
export interface HttpClientOptions {
|
|
11
|
+
/** Enable keep-alive for better performance (default: true) */
|
|
11
12
|
keepAlive?: boolean;
|
|
13
|
+
/** Keep-alive duration in milliseconds (default: 1000) */
|
|
12
14
|
keepAliveMsecs?: number;
|
|
15
|
+
/** Maximum number of sockets (default: 50) */
|
|
13
16
|
maxSockets?: number;
|
|
17
|
+
/** Maximum number of free sockets in pool (default: 10) */
|
|
14
18
|
maxFreeSockets?: number;
|
|
19
|
+
/** Request timeout in milliseconds (default: 60000) */
|
|
15
20
|
timeout?: number;
|
|
16
21
|
}
|
|
17
22
|
|