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