s3db.js 10.0.18 → 11.0.0
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 +606 -206
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.d.ts +198 -2
- package/dist/s3db.es.js +606 -206
- package/dist/s3db.es.js.map +1 -1
- package/package.json +4 -2
- package/src/concerns/plugin-storage.js +443 -0
- package/src/database.class.js +48 -15
- package/src/plugins/audit.plugin.js +1 -1
- package/src/plugins/backup.plugin.js +1 -1
- package/src/plugins/cache.plugin.js +2 -6
- package/src/plugins/eventual-consistency/analytics.js +16 -4
- package/src/plugins/eventual-consistency/consolidation.js +18 -1
- package/src/plugins/eventual-consistency/index.js +4 -4
- package/src/plugins/eventual-consistency/{setup.js → install.js} +7 -6
- package/src/plugins/fulltext.plugin.js +3 -4
- package/src/plugins/metrics.plugin.js +10 -11
- package/src/plugins/plugin.class.js +79 -9
- package/src/plugins/queue-consumer.plugin.js +4 -3
- package/src/plugins/replicator.plugin.js +11 -13
- package/src/plugins/s3-queue.plugin.js +1 -1
- package/src/plugins/scheduler.plugin.js +8 -9
- package/src/plugins/state-machine.plugin.js +3 -4
- package/src/s3db.d.ts +198 -2
- package/src/plugins/eventual-consistency.plugin.js +0 -2559
package/dist/s3db.d.ts
CHANGED
|
@@ -1069,11 +1069,207 @@ declare module 's3db.js' {
|
|
|
1069
1069
|
deleteBackup(backupId: string): Promise<void>;
|
|
1070
1070
|
}
|
|
1071
1071
|
|
|
1072
|
+
/** Eventual Consistency Plugin Config */
|
|
1073
|
+
export interface EventualConsistencyPluginConfig extends PluginConfig {
|
|
1074
|
+
/** Resource name to field names mapping (required) */
|
|
1075
|
+
resources: Record<string, string[]>;
|
|
1076
|
+
|
|
1077
|
+
/** Consolidation settings */
|
|
1078
|
+
consolidation?: {
|
|
1079
|
+
/** Consolidation mode: 'sync' or 'async' (default: 'async') */
|
|
1080
|
+
mode?: 'sync' | 'async';
|
|
1081
|
+
/** Consolidation interval in seconds (default: 300) */
|
|
1082
|
+
interval?: number;
|
|
1083
|
+
/** Consolidation concurrency (default: 5) */
|
|
1084
|
+
concurrency?: number;
|
|
1085
|
+
/** Consolidation window in hours (default: 24) */
|
|
1086
|
+
window?: number;
|
|
1087
|
+
/** Enable auto-consolidation (default: true) */
|
|
1088
|
+
auto?: boolean;
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
/** Lock settings */
|
|
1092
|
+
locks?: {
|
|
1093
|
+
/** Lock timeout in seconds (default: 300) */
|
|
1094
|
+
timeout?: number;
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
/** Garbage collection settings */
|
|
1098
|
+
garbageCollection?: {
|
|
1099
|
+
/** Transaction retention in days (default: 30) */
|
|
1100
|
+
retention?: number;
|
|
1101
|
+
/** GC interval in seconds (default: 86400) */
|
|
1102
|
+
interval?: number;
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1105
|
+
/** Analytics settings */
|
|
1106
|
+
analytics?: {
|
|
1107
|
+
/** Enable analytics (default: false) */
|
|
1108
|
+
enabled?: boolean;
|
|
1109
|
+
/** Time periods to track (default: ['hour', 'day', 'month']) */
|
|
1110
|
+
periods?: Array<'hour' | 'day' | 'month'>;
|
|
1111
|
+
/** Metrics to track (default: ['count', 'sum', 'avg', 'min', 'max']) */
|
|
1112
|
+
metrics?: Array<'count' | 'sum' | 'avg' | 'min' | 'max'>;
|
|
1113
|
+
/** Rollup strategy (default: 'incremental') */
|
|
1114
|
+
rollupStrategy?: 'incremental' | 'full';
|
|
1115
|
+
/** Analytics retention in days (default: 365) */
|
|
1116
|
+
retentionDays?: number;
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
/** Batch transaction settings */
|
|
1120
|
+
batch?: {
|
|
1121
|
+
/** Enable batch transactions (default: false) */
|
|
1122
|
+
enabled?: boolean;
|
|
1123
|
+
/** Batch size (default: 100) */
|
|
1124
|
+
size?: number;
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
/** Late arrivals handling */
|
|
1128
|
+
lateArrivals?: {
|
|
1129
|
+
/** Strategy for late arrivals (default: 'warn') */
|
|
1130
|
+
strategy?: 'warn' | 'ignore' | 'error';
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
/** Checkpoint settings */
|
|
1134
|
+
checkpoints?: {
|
|
1135
|
+
/** Enable checkpoints (default: true) */
|
|
1136
|
+
enabled?: boolean;
|
|
1137
|
+
/** Checkpoint strategy (default: 'hourly') */
|
|
1138
|
+
strategy?: 'hourly' | 'daily' | 'threshold';
|
|
1139
|
+
/** Checkpoint retention in days (default: 90) */
|
|
1140
|
+
retention?: number;
|
|
1141
|
+
/** Checkpoint threshold (default: 1000) */
|
|
1142
|
+
threshold?: number;
|
|
1143
|
+
/** Delete consolidated transactions (default: true) */
|
|
1144
|
+
deleteConsolidated?: boolean;
|
|
1145
|
+
/** Enable auto-checkpoint (default: true) */
|
|
1146
|
+
auto?: boolean;
|
|
1147
|
+
};
|
|
1148
|
+
|
|
1149
|
+
/** Cohort settings */
|
|
1150
|
+
cohort?: {
|
|
1151
|
+
/** Timezone for cohorts (default: UTC or TZ env var) */
|
|
1152
|
+
timezone?: string;
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
/** Custom reducer function */
|
|
1156
|
+
reducer?: (transactions: any[]) => number;
|
|
1157
|
+
|
|
1158
|
+
/** Enable verbose logging (default: false) */
|
|
1159
|
+
verbose?: boolean;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
/** Analytics query options */
|
|
1163
|
+
export interface EventualConsistencyAnalyticsOptions {
|
|
1164
|
+
/** Period to query */
|
|
1165
|
+
period?: 'hour' | 'day' | 'month';
|
|
1166
|
+
/** Start date (YYYY-MM-DD or YYYY-MM-DD HH:00) */
|
|
1167
|
+
startDate?: string;
|
|
1168
|
+
/** End date (YYYY-MM-DD or YYYY-MM-DD HH:00) */
|
|
1169
|
+
endDate?: string;
|
|
1170
|
+
/** Single date (YYYY-MM-DD) */
|
|
1171
|
+
date?: string;
|
|
1172
|
+
/** Operation breakdown */
|
|
1173
|
+
breakdown?: 'operations';
|
|
1174
|
+
/** Fill gaps with zeros for continuous data (default: false) */
|
|
1175
|
+
fillGaps?: boolean;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
/** Top records query options */
|
|
1179
|
+
export interface EventualConsistencyTopRecordsOptions {
|
|
1180
|
+
/** Period to query */
|
|
1181
|
+
period?: 'hour' | 'day' | 'month';
|
|
1182
|
+
/** Date for the query */
|
|
1183
|
+
date?: string;
|
|
1184
|
+
/** Metric to sort by: 'transactionCount' or 'totalValue' */
|
|
1185
|
+
metric?: 'transactionCount' | 'totalValue';
|
|
1186
|
+
/** Limit results (default: 10) */
|
|
1187
|
+
limit?: number;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/** Analytics result */
|
|
1191
|
+
export interface EventualConsistencyAnalyticsResult {
|
|
1192
|
+
/** Cohort identifier (date/hour/month string) */
|
|
1193
|
+
cohort: string;
|
|
1194
|
+
/** Number of transactions */
|
|
1195
|
+
count: number;
|
|
1196
|
+
/** Sum of values */
|
|
1197
|
+
sum: number;
|
|
1198
|
+
/** Average value */
|
|
1199
|
+
avg: number;
|
|
1200
|
+
/** Minimum value */
|
|
1201
|
+
min: number;
|
|
1202
|
+
/** Maximum value */
|
|
1203
|
+
max: number;
|
|
1204
|
+
/** Number of distinct records */
|
|
1205
|
+
recordCount: number;
|
|
1206
|
+
/** Breakdown by operation (if requested) */
|
|
1207
|
+
add?: { count: number; sum: number };
|
|
1208
|
+
sub?: { count: number; sum: number };
|
|
1209
|
+
set?: { count: number; sum: number };
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
/** Top record result */
|
|
1213
|
+
export interface EventualConsistencyTopRecordResult {
|
|
1214
|
+
/** Record ID */
|
|
1215
|
+
recordId: string;
|
|
1216
|
+
/** Number of transactions or total value */
|
|
1217
|
+
count: number;
|
|
1218
|
+
/** Total value */
|
|
1219
|
+
sum: number;
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
/** Cohort information */
|
|
1223
|
+
export interface EventualConsistencyCohortInfo {
|
|
1224
|
+
/** Date in YYYY-MM-DD format */
|
|
1225
|
+
date: string;
|
|
1226
|
+
/** Hour in YYYY-MM-DD HH:00 format */
|
|
1227
|
+
hour: string;
|
|
1228
|
+
/** Month in YYYY-MM format */
|
|
1229
|
+
month: string;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1072
1232
|
/** Eventual Consistency Plugin */
|
|
1073
1233
|
export class EventualConsistencyPlugin extends Plugin {
|
|
1074
|
-
constructor(config
|
|
1234
|
+
constructor(config: EventualConsistencyPluginConfig);
|
|
1235
|
+
|
|
1236
|
+
// Lifecycle methods
|
|
1075
1237
|
setup(database: Database): Promise<void>;
|
|
1076
|
-
|
|
1238
|
+
|
|
1239
|
+
// Analytics methods
|
|
1240
|
+
getAnalytics(resourceName: string, field: string, options?: EventualConsistencyAnalyticsOptions): Promise<EventualConsistencyAnalyticsResult[]>;
|
|
1241
|
+
getMonthByDay(resourceName: string, field: string, month: string, options?: EventualConsistencyAnalyticsOptions): Promise<EventualConsistencyAnalyticsResult[]>;
|
|
1242
|
+
getDayByHour(resourceName: string, field: string, date: string, options?: EventualConsistencyAnalyticsOptions): Promise<EventualConsistencyAnalyticsResult[]>;
|
|
1243
|
+
getLastNDays(resourceName: string, field: string, days?: number, options?: EventualConsistencyAnalyticsOptions): Promise<EventualConsistencyAnalyticsResult[]>;
|
|
1244
|
+
getYearByMonth(resourceName: string, field: string, year: number, options?: EventualConsistencyAnalyticsOptions): Promise<EventualConsistencyAnalyticsResult[]>;
|
|
1245
|
+
getMonthByHour(resourceName: string, field: string, month: string, options?: EventualConsistencyAnalyticsOptions): Promise<EventualConsistencyAnalyticsResult[]>;
|
|
1246
|
+
getTopRecords(resourceName: string, field: string, options?: EventualConsistencyTopRecordsOptions): Promise<EventualConsistencyTopRecordResult[]>;
|
|
1247
|
+
|
|
1248
|
+
// Utility methods
|
|
1249
|
+
getCohortInfo(date: Date): EventualConsistencyCohortInfo;
|
|
1250
|
+
createPartitionConfig(): any;
|
|
1251
|
+
createTransaction(handler: any, data: any): Promise<any>;
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/** Resource extensions added by EventualConsistencyPlugin */
|
|
1255
|
+
export interface EventualConsistencyResourceExtensions {
|
|
1256
|
+
/** Set field value (replaces current value) */
|
|
1257
|
+
set(id: string, field: string, value: number): Promise<number>;
|
|
1258
|
+
|
|
1259
|
+
/** Increment field value */
|
|
1260
|
+
add(id: string, field: string, amount: number): Promise<number>;
|
|
1261
|
+
|
|
1262
|
+
/** Decrement field value */
|
|
1263
|
+
sub(id: string, field: string, amount: number): Promise<number>;
|
|
1264
|
+
|
|
1265
|
+
/** Manually trigger consolidation */
|
|
1266
|
+
consolidate(id: string, field: string): Promise<number>;
|
|
1267
|
+
|
|
1268
|
+
/** Get consolidated value without applying */
|
|
1269
|
+
getConsolidatedValue(id: string, field: string, options?: any): Promise<number>;
|
|
1270
|
+
|
|
1271
|
+
/** Recalculate from scratch (rebuilds from transaction log) */
|
|
1272
|
+
recalculate(id: string, field: string): Promise<number>;
|
|
1077
1273
|
}
|
|
1078
1274
|
|
|
1079
1275
|
/** Scheduler Plugin */
|