s3db.js 10.0.17 → 10.0.18
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
CHANGED
|
@@ -4308,10 +4308,19 @@ const CostsPlugin = {
|
|
|
4308
4308
|
};
|
|
4309
4309
|
|
|
4310
4310
|
function createConfig(options, detectedTimezone) {
|
|
4311
|
+
const consolidation = options.consolidation || {};
|
|
4312
|
+
const locks = options.locks || {};
|
|
4313
|
+
const gc = options.garbageCollection || {};
|
|
4314
|
+
const analytics = options.analytics || {};
|
|
4315
|
+
const batch = options.batch || {};
|
|
4316
|
+
const lateArrivals = options.lateArrivals || {};
|
|
4317
|
+
const checkpoints = options.checkpoints || {};
|
|
4311
4318
|
return {
|
|
4319
|
+
// Cohort (timezone)
|
|
4312
4320
|
cohort: {
|
|
4313
4321
|
timezone: options.cohort?.timezone || detectedTimezone
|
|
4314
4322
|
},
|
|
4323
|
+
// Reducer function
|
|
4315
4324
|
reducer: options.reducer || ((transactions) => {
|
|
4316
4325
|
let baseValue = 0;
|
|
4317
4326
|
for (const t of transactions) {
|
|
@@ -4325,38 +4334,39 @@ function createConfig(options, detectedTimezone) {
|
|
|
4325
4334
|
}
|
|
4326
4335
|
return baseValue;
|
|
4327
4336
|
}),
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4337
|
+
// Consolidation settings
|
|
4338
|
+
consolidationInterval: consolidation.interval ?? 300,
|
|
4339
|
+
consolidationConcurrency: consolidation.concurrency ?? 5,
|
|
4340
|
+
consolidationWindow: consolidation.window ?? 24,
|
|
4341
|
+
autoConsolidate: consolidation.auto !== false,
|
|
4342
|
+
mode: consolidation.mode || "async",
|
|
4343
|
+
// Late arrivals
|
|
4344
|
+
lateArrivalStrategy: lateArrivals.strategy || "warn",
|
|
4345
|
+
// Batch transactions
|
|
4346
|
+
batchTransactions: batch.enabled || false,
|
|
4347
|
+
batchSize: batch.size || 100,
|
|
4348
|
+
// Locks
|
|
4349
|
+
lockTimeout: locks.timeout || 300,
|
|
4350
|
+
// Garbage collection
|
|
4351
|
+
transactionRetention: gc.retention ?? 30,
|
|
4352
|
+
gcInterval: gc.interval ?? 86400,
|
|
4353
|
+
// Analytics
|
|
4354
|
+
enableAnalytics: analytics.enabled || false,
|
|
4341
4355
|
analyticsConfig: {
|
|
4342
|
-
periods:
|
|
4343
|
-
metrics:
|
|
4344
|
-
rollupStrategy:
|
|
4345
|
-
retentionDays:
|
|
4356
|
+
periods: analytics.periods || ["hour", "day", "month"],
|
|
4357
|
+
metrics: analytics.metrics || ["count", "sum", "avg", "min", "max"],
|
|
4358
|
+
rollupStrategy: analytics.rollupStrategy || "incremental",
|
|
4359
|
+
retentionDays: analytics.retentionDays ?? 365
|
|
4346
4360
|
},
|
|
4347
|
-
//
|
|
4348
|
-
enableCheckpoints:
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
deleteConsolidatedTransactions: options.deleteConsolidatedTransactions !== false,
|
|
4357
|
-
// Delete transactions after checkpoint
|
|
4358
|
-
autoCheckpoint: options.autoCheckpoint !== false
|
|
4359
|
-
// Auto-create checkpoints for old cohorts
|
|
4361
|
+
// Checkpoints
|
|
4362
|
+
enableCheckpoints: checkpoints.enabled !== false,
|
|
4363
|
+
checkpointStrategy: checkpoints.strategy || "hourly",
|
|
4364
|
+
checkpointRetention: checkpoints.retention ?? 90,
|
|
4365
|
+
checkpointThreshold: checkpoints.threshold ?? 1e3,
|
|
4366
|
+
deleteConsolidatedTransactions: checkpoints.deleteConsolidated !== false,
|
|
4367
|
+
autoCheckpoint: checkpoints.auto !== false,
|
|
4368
|
+
// Debug
|
|
4369
|
+
verbose: options.verbose || false
|
|
4360
4370
|
};
|
|
4361
4371
|
}
|
|
4362
4372
|
function validateResourcesConfig(resources) {
|
|
@@ -4376,7 +4386,12 @@ function validateResourcesConfig(resources) {
|
|
|
4376
4386
|
function logConfigWarnings(config) {
|
|
4377
4387
|
if (config.batchTransactions && !config.verbose) {
|
|
4378
4388
|
console.warn(
|
|
4379
|
-
`[EventualConsistency] WARNING:
|
|
4389
|
+
`[EventualConsistency] WARNING: batch.enabled is true. This stores transactions in memory and will lose data if container crashes. Not recommended for distributed/production environments.`
|
|
4390
|
+
);
|
|
4391
|
+
}
|
|
4392
|
+
if (!config.enableCheckpoints && !config.verbose) {
|
|
4393
|
+
console.warn(
|
|
4394
|
+
`[EventualConsistency] INFO: checkpoints.enabled is false. Checkpoints improve performance in high-volume scenarios by creating snapshots. Consider enabling for production use.`
|
|
4380
4395
|
);
|
|
4381
4396
|
}
|
|
4382
4397
|
}
|
|
@@ -4388,7 +4403,7 @@ function logInitialization(config, fieldHandlers, timezoneAutoDetected) {
|
|
|
4388
4403
|
);
|
|
4389
4404
|
if (timezoneAutoDetected) {
|
|
4390
4405
|
console.log(
|
|
4391
|
-
`[EventualConsistency]
|
|
4406
|
+
`[EventualConsistency] Using timezone: ${config.cohort.timezone} (${process.env.TZ ? "from TZ env var" : "default UTC"})`
|
|
4392
4407
|
);
|
|
4393
4408
|
}
|
|
4394
4409
|
}
|
|
@@ -4397,13 +4412,6 @@ function detectTimezone() {
|
|
|
4397
4412
|
if (process.env.TZ) {
|
|
4398
4413
|
return process.env.TZ;
|
|
4399
4414
|
}
|
|
4400
|
-
try {
|
|
4401
|
-
const systemTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
4402
|
-
if (systemTimezone) {
|
|
4403
|
-
return systemTimezone;
|
|
4404
|
-
}
|
|
4405
|
-
} catch (err) {
|
|
4406
|
-
}
|
|
4407
4415
|
return "UTC";
|
|
4408
4416
|
}
|
|
4409
4417
|
function getTimezoneOffset(timezone, verbose = false) {
|
|
@@ -12344,7 +12352,7 @@ class Database extends EventEmitter {
|
|
|
12344
12352
|
this.id = idGenerator(7);
|
|
12345
12353
|
this.version = "1";
|
|
12346
12354
|
this.s3dbVersion = (() => {
|
|
12347
|
-
const [ok, err, version] = tryFn(() => true ? "10.0.
|
|
12355
|
+
const [ok, err, version] = tryFn(() => true ? "10.0.18" : "latest");
|
|
12348
12356
|
return ok ? version : "latest";
|
|
12349
12357
|
})();
|
|
12350
12358
|
this.resources = {};
|