s3db.js 7.3.4 → 7.3.5
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 +26 -36
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +26 -36
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +27 -37
- package/dist/s3db.iife.min.js +1 -1
- package/package.json +24 -24
- package/src/database.class.js +10 -8
- package/src/plugins/metrics.plugin.js +18 -8
- package/src/plugins/replicator.plugin.js +0 -26
- package/src/plugins/replicators/s3db-replicator.class.js +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "s3db.js",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.5",
|
|
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",
|
|
@@ -43,27 +43,6 @@
|
|
|
43
43
|
"PLUGINS.md",
|
|
44
44
|
"UNLICENSE"
|
|
45
45
|
],
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "rollup -c",
|
|
48
|
-
"dev": "rollup -c -w",
|
|
49
|
-
"test": "npm run test:js && npm run test:ts",
|
|
50
|
-
"test:js": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand",
|
|
51
|
-
"test:ts": "tsc --noEmit --project tests/typescript/tsconfig.json",
|
|
52
|
-
"test:js-converage": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --detectOpenHandles --coverage --runInBand",
|
|
53
|
-
"test:js-ai": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --detectOpenHandles --runInBand",
|
|
54
|
-
"test:full": "npm run test:js && npm run test:ts",
|
|
55
|
-
"test:cache": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/plugin-cache*.test.js --runInBand",
|
|
56
|
-
"test:quick": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --testTimeout=10000",
|
|
57
|
-
"test:batch": "./test-batch.sh",
|
|
58
|
-
"test:plugins": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/ --runInBand --testTimeout=60000",
|
|
59
|
-
"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'",
|
|
60
|
-
"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",
|
|
61
|
-
"test:types": "tsc --noEmit --project tests/typescript/tsconfig.json",
|
|
62
|
-
"test:types:basic": "tsc --noEmit tests/typescript/basic-usage.test.ts",
|
|
63
|
-
"test:types:direct": "tsc --noEmit tests/typescript/direct-type-test.ts",
|
|
64
|
-
"test:types:watch": "tsc --noEmit --watch --project tests/typescript/tsconfig.json",
|
|
65
|
-
"validate:types": "npm run test:types && echo 'TypeScript definitions are valid!'"
|
|
66
|
-
},
|
|
67
46
|
"dependencies": {
|
|
68
47
|
"@aws-sdk/client-s3": "^3.848.0",
|
|
69
48
|
"@supercharge/promise-pool": "^3.2.0",
|
|
@@ -115,5 +94,26 @@
|
|
|
115
94
|
},
|
|
116
95
|
"funding": [
|
|
117
96
|
"https://github.com/sponsors/forattini-dev"
|
|
118
|
-
]
|
|
119
|
-
|
|
97
|
+
],
|
|
98
|
+
"scripts": {
|
|
99
|
+
"build": "rollup -c",
|
|
100
|
+
"dev": "rollup -c -w",
|
|
101
|
+
"test": "npm run test:js && npm run test:ts",
|
|
102
|
+
"test:js": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand",
|
|
103
|
+
"test:ts": "tsc --noEmit --project tests/typescript/tsconfig.json",
|
|
104
|
+
"test:js-converage": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --detectOpenHandles --coverage --runInBand",
|
|
105
|
+
"test:js-ai": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --detectOpenHandles --runInBand",
|
|
106
|
+
"test:full": "npm run test:js && npm run test:ts",
|
|
107
|
+
"test:cache": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/plugin-cache*.test.js --runInBand",
|
|
108
|
+
"test:quick": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --testTimeout=10000",
|
|
109
|
+
"test:batch": "./test-batch.sh",
|
|
110
|
+
"test:plugins": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js tests/plugins/ --runInBand --testTimeout=60000",
|
|
111
|
+
"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'",
|
|
112
|
+
"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",
|
|
113
|
+
"test:types": "tsc --noEmit --project tests/typescript/tsconfig.json",
|
|
114
|
+
"test:types:basic": "tsc --noEmit tests/typescript/basic-usage.test.ts",
|
|
115
|
+
"test:types:direct": "tsc --noEmit tests/typescript/direct-type-test.ts",
|
|
116
|
+
"test:types:watch": "tsc --noEmit --watch --project tests/typescript/tsconfig.json",
|
|
117
|
+
"validate:types": "npm run test:types && echo 'TypeScript definitions are valid!'"
|
|
118
|
+
}
|
|
119
|
+
}
|
package/src/database.class.js
CHANGED
|
@@ -74,15 +74,17 @@ export class Database extends EventEmitter {
|
|
|
74
74
|
// Add process exit listener for cleanup
|
|
75
75
|
if (!this._exitListenerRegistered) {
|
|
76
76
|
this._exitListenerRegistered = true;
|
|
77
|
-
process
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
if (typeof process !== 'undefined') {
|
|
78
|
+
process.on('exit', async () => {
|
|
79
|
+
if (this.isConnected()) {
|
|
80
|
+
try {
|
|
81
|
+
await this.disconnect();
|
|
82
|
+
} catch (err) {
|
|
83
|
+
// Silently ignore errors on exit
|
|
84
|
+
}
|
|
83
85
|
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
|
|
@@ -33,7 +33,7 @@ export class MetricsPlugin extends Plugin {
|
|
|
33
33
|
|
|
34
34
|
async setup(database) {
|
|
35
35
|
this.database = database;
|
|
36
|
-
if (process.env.NODE_ENV === 'test') return;
|
|
36
|
+
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') return;
|
|
37
37
|
|
|
38
38
|
const [ok, err] = await tryFn(async () => {
|
|
39
39
|
const [ok1, err1, metricsResource] = await tryFn(() => database.createResource({
|
|
@@ -90,7 +90,7 @@ export class MetricsPlugin extends Plugin {
|
|
|
90
90
|
this.installMetricsHooks();
|
|
91
91
|
|
|
92
92
|
// Disable flush timer during tests to avoid side effects
|
|
93
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
93
|
+
if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'test') {
|
|
94
94
|
this.startFlushTimer();
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -107,7 +107,7 @@ export class MetricsPlugin extends Plugin {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// Don't flush metrics during tests
|
|
110
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
110
|
+
if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'test') {
|
|
111
111
|
await this.flushMetrics();
|
|
112
112
|
}
|
|
113
113
|
}
|
|
@@ -328,11 +328,21 @@ export class MetricsPlugin extends Plugin {
|
|
|
328
328
|
if (!this.metricsResource) return;
|
|
329
329
|
|
|
330
330
|
const [ok, err] = await tryFn(async () => {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
331
|
+
let metadata, perfMetadata, errorMetadata, resourceMetadata;
|
|
332
|
+
|
|
333
|
+
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
|
|
334
|
+
// Use empty metadata during tests to avoid header issues
|
|
335
|
+
metadata = {};
|
|
336
|
+
perfMetadata = {};
|
|
337
|
+
errorMetadata = {};
|
|
338
|
+
resourceMetadata = {};
|
|
339
|
+
} else {
|
|
340
|
+
// Use empty metadata during tests to avoid header issues
|
|
341
|
+
metadata = { global: 'true' };
|
|
342
|
+
perfMetadata = { perf: 'true' };
|
|
343
|
+
errorMetadata = { error: 'true' };
|
|
344
|
+
resourceMetadata = { resource: 'true' };
|
|
345
|
+
}
|
|
336
346
|
|
|
337
347
|
// Flush operation metrics
|
|
338
348
|
for (const [operation, data] of Object.entries(this.metrics.operations)) {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { isPlainObject } from 'lodash-es';
|
|
2
|
-
|
|
3
1
|
import Plugin from "./plugin.class.js";
|
|
4
2
|
import tryFn from "../concerns/try-fn.js";
|
|
5
3
|
import { createReplicator, validateReplicatorConfig } from "./replicators/index.js";
|
|
@@ -300,36 +298,12 @@ export class ReplicatorPlugin extends Plugin {
|
|
|
300
298
|
// await this.processQueue(); // Removed as per edit hint
|
|
301
299
|
}
|
|
302
300
|
|
|
303
|
-
filterInternalFields(data) {
|
|
304
|
-
if (!data || typeof data !== 'object') return data;
|
|
305
|
-
const filtered = {};
|
|
306
|
-
for (const [key, value] of Object.entries(data)) {
|
|
307
|
-
// Filter out internal fields that start with _ or $
|
|
308
|
-
if (!key.startsWith('_') && !key.startsWith('$')) {
|
|
309
|
-
filtered[key] = value;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return filtered;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
301
|
async uploadMetadataFile(database) {
|
|
316
302
|
if (typeof database.uploadMetadataFile === 'function') {
|
|
317
303
|
await database.uploadMetadataFile();
|
|
318
304
|
}
|
|
319
305
|
}
|
|
320
306
|
|
|
321
|
-
async getCompleteData(resource, data) {
|
|
322
|
-
try {
|
|
323
|
-
const [ok, err, record] = await tryFn(() => resource.get(data.id));
|
|
324
|
-
if (ok && record) {
|
|
325
|
-
return record;
|
|
326
|
-
}
|
|
327
|
-
} catch (error) {
|
|
328
|
-
// Fallback to provided data
|
|
329
|
-
}
|
|
330
|
-
return data;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
307
|
async retryWithBackoff(operation, maxRetries = 3) {
|
|
334
308
|
let lastError;
|
|
335
309
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
@@ -209,9 +209,9 @@ class S3dbReplicator extends BaseReplicator {
|
|
|
209
209
|
}
|
|
210
210
|
// String mapping
|
|
211
211
|
if (typeof entry === 'string') return entry;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
// Mapping function - when there's only transformer, use original resource
|
|
213
|
+
if (typeof entry === 'function') return resource;
|
|
214
|
+
// Object: { resource, transform }
|
|
215
215
|
if (typeof entry === 'object' && entry.resource) return entry.resource;
|
|
216
216
|
return resource;
|
|
217
217
|
}
|