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/dist/s3db.es.js
CHANGED
|
@@ -3,8 +3,8 @@ import zlib from 'node:zlib';
|
|
|
3
3
|
import { PromisePool } from '@supercharge/promise-pool';
|
|
4
4
|
import { ReadableStream } from 'node:stream/web';
|
|
5
5
|
import { mkdir, writeFile, readFile, stat, unlink, readdir, rm } from 'fs/promises';
|
|
6
|
-
import { chunk, merge, isString as isString$1, isEmpty, invert, uniq, cloneDeep, get, set, isObject as isObject$1, isFunction as isFunction$1 } from 'lodash-es';
|
|
7
6
|
import { createHash } from 'crypto';
|
|
7
|
+
import { chunk, merge, isString as isString$1, isEmpty, invert, uniq, cloneDeep, get, set, isObject as isObject$1, isFunction as isFunction$1 } from 'lodash-es';
|
|
8
8
|
import jsonStableStringify from 'json-stable-stringify';
|
|
9
9
|
import { S3Client, PutObjectCommand, GetObjectCommand, HeadObjectCommand, CopyObjectCommand, DeleteObjectCommand, DeleteObjectsCommand, ListObjectsV2Command } from '@aws-sdk/client-s3';
|
|
10
10
|
import { flatten, unflatten } from 'flat';
|
|
@@ -8349,7 +8349,7 @@ class MetricsPlugin extends plugin_class_default {
|
|
|
8349
8349
|
}
|
|
8350
8350
|
async setup(database) {
|
|
8351
8351
|
this.database = database;
|
|
8352
|
-
if (process.env.NODE_ENV === "test") return;
|
|
8352
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") return;
|
|
8353
8353
|
const [ok, err] = await try_fn_default(async () => {
|
|
8354
8354
|
const [ok1, err1, metricsResource] = await try_fn_default(() => database.createResource({
|
|
8355
8355
|
name: "metrics",
|
|
@@ -8399,7 +8399,7 @@ class MetricsPlugin extends plugin_class_default {
|
|
|
8399
8399
|
this.performanceResource = database.resources.performance_logs;
|
|
8400
8400
|
}
|
|
8401
8401
|
this.installMetricsHooks();
|
|
8402
|
-
if (process.env.NODE_ENV !== "test") {
|
|
8402
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "test") {
|
|
8403
8403
|
this.startFlushTimer();
|
|
8404
8404
|
}
|
|
8405
8405
|
}
|
|
@@ -8410,7 +8410,7 @@ class MetricsPlugin extends plugin_class_default {
|
|
|
8410
8410
|
clearInterval(this.flushTimer);
|
|
8411
8411
|
this.flushTimer = null;
|
|
8412
8412
|
}
|
|
8413
|
-
if (process.env.NODE_ENV !== "test") {
|
|
8413
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "test") {
|
|
8414
8414
|
await this.flushMetrics();
|
|
8415
8415
|
}
|
|
8416
8416
|
}
|
|
@@ -8589,10 +8589,18 @@ class MetricsPlugin extends plugin_class_default {
|
|
|
8589
8589
|
async flushMetrics() {
|
|
8590
8590
|
if (!this.metricsResource) return;
|
|
8591
8591
|
const [ok, err] = await try_fn_default(async () => {
|
|
8592
|
-
|
|
8593
|
-
|
|
8594
|
-
|
|
8595
|
-
|
|
8592
|
+
let metadata, perfMetadata, errorMetadata, resourceMetadata;
|
|
8593
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "test") {
|
|
8594
|
+
metadata = {};
|
|
8595
|
+
perfMetadata = {};
|
|
8596
|
+
errorMetadata = {};
|
|
8597
|
+
resourceMetadata = {};
|
|
8598
|
+
} else {
|
|
8599
|
+
metadata = { global: "true" };
|
|
8600
|
+
perfMetadata = { perf: "true" };
|
|
8601
|
+
errorMetadata = { error: "true" };
|
|
8602
|
+
resourceMetadata = { resource: "true" };
|
|
8603
|
+
}
|
|
8596
8604
|
for (const [operation, data] of Object.entries(this.metrics.operations)) {
|
|
8597
8605
|
if (data.count > 0) {
|
|
8598
8606
|
await this.metricsResource.insert({
|
|
@@ -13168,14 +13176,16 @@ class Database extends EventEmitter {
|
|
|
13168
13176
|
this.keyPrefix = this.client.keyPrefix;
|
|
13169
13177
|
if (!this._exitListenerRegistered) {
|
|
13170
13178
|
this._exitListenerRegistered = true;
|
|
13171
|
-
process
|
|
13172
|
-
|
|
13173
|
-
|
|
13174
|
-
|
|
13175
|
-
|
|
13179
|
+
if (typeof process !== "undefined") {
|
|
13180
|
+
process.on("exit", async () => {
|
|
13181
|
+
if (this.isConnected()) {
|
|
13182
|
+
try {
|
|
13183
|
+
await this.disconnect();
|
|
13184
|
+
} catch (err) {
|
|
13185
|
+
}
|
|
13176
13186
|
}
|
|
13177
|
-
}
|
|
13178
|
-
}
|
|
13187
|
+
});
|
|
13188
|
+
}
|
|
13179
13189
|
}
|
|
13180
13190
|
}
|
|
13181
13191
|
async connect() {
|
|
@@ -13758,7 +13768,7 @@ class S3dbReplicator extends base_replicator_class_default {
|
|
|
13758
13768
|
if (typeof entry[0] === "function") return resource;
|
|
13759
13769
|
}
|
|
13760
13770
|
if (typeof entry === "string") return entry;
|
|
13761
|
-
if (
|
|
13771
|
+
if (typeof entry === "function") return resource;
|
|
13762
13772
|
if (typeof entry === "object" && entry.resource) return entry.resource;
|
|
13763
13773
|
return resource;
|
|
13764
13774
|
}
|
|
@@ -14307,31 +14317,11 @@ class ReplicatorPlugin extends plugin_class_default {
|
|
|
14307
14317
|
}
|
|
14308
14318
|
async stop() {
|
|
14309
14319
|
}
|
|
14310
|
-
filterInternalFields(data) {
|
|
14311
|
-
if (!data || typeof data !== "object") return data;
|
|
14312
|
-
const filtered = {};
|
|
14313
|
-
for (const [key, value] of Object.entries(data)) {
|
|
14314
|
-
if (!key.startsWith("_") && !key.startsWith("$")) {
|
|
14315
|
-
filtered[key] = value;
|
|
14316
|
-
}
|
|
14317
|
-
}
|
|
14318
|
-
return filtered;
|
|
14319
|
-
}
|
|
14320
14320
|
async uploadMetadataFile(database) {
|
|
14321
14321
|
if (typeof database.uploadMetadataFile === "function") {
|
|
14322
14322
|
await database.uploadMetadataFile();
|
|
14323
14323
|
}
|
|
14324
14324
|
}
|
|
14325
|
-
async getCompleteData(resource, data) {
|
|
14326
|
-
try {
|
|
14327
|
-
const [ok, err, record] = await try_fn_default(() => resource.get(data.id));
|
|
14328
|
-
if (ok && record) {
|
|
14329
|
-
return record;
|
|
14330
|
-
}
|
|
14331
|
-
} catch (error) {
|
|
14332
|
-
}
|
|
14333
|
-
return data;
|
|
14334
|
-
}
|
|
14335
14325
|
async retryWithBackoff(operation, maxRetries = 3) {
|
|
14336
14326
|
let lastError;
|
|
14337
14327
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|