s3db.js 19.2.4 → 19.3.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.
@@ -0,0 +1,3493 @@
1
+ import EventEmitter, { EventEmitter as EventEmitter$1 } from 'events';
2
+ import { Logger as Logger$2, TransportSingleOptions } from 'pino';
3
+ import * as FastestValidatorModule from 'fastest-validator';
4
+ import { ValidatorConstructorOptions } from 'fastest-validator';
5
+ import { Transform, TransformCallback, Writable, Readable } from 'stream';
6
+ import { ReadableStream as ReadableStream$1, ReadableStreamDefaultController, ReadableStreamDefaultReader } from 'node:stream/web';
7
+ import { S3Client as S3Client$4 } from '@aws-sdk/client-s3';
8
+
9
+ interface ValidatorCacheStats {
10
+ size: number;
11
+ totalReferences: number;
12
+ zeroRefValidators: number;
13
+ cacheHits: number;
14
+ cacheMisses: number;
15
+ hitRate: number;
16
+ }
17
+ interface CacheMemoryUsage {
18
+ estimatedKB: number;
19
+ estimatedMB: number;
20
+ validatorCount: number;
21
+ }
22
+ declare function getCacheStats(): ValidatorCacheStats;
23
+ declare function getCacheMemoryUsage(): CacheMemoryUsage;
24
+
25
+ type AttributeValue$1 = string | number | boolean | null | undefined | Record<string, unknown> | unknown[];
26
+ interface SchemaAttributes {
27
+ [key: string]: AttributeValue$1 | SchemaAttributes;
28
+ }
29
+ interface AttributeMapping {
30
+ [key: string]: string;
31
+ }
32
+ interface PluginAttributeMetadata {
33
+ [key: string]: {
34
+ __plugin__: string;
35
+ [key: string]: unknown;
36
+ };
37
+ }
38
+ interface PluginAttributes {
39
+ [pluginName: string]: string[];
40
+ }
41
+ interface HookEntry {
42
+ action: string;
43
+ params: Record<string, unknown>;
44
+ }
45
+ interface SchemaHooks {
46
+ beforeMap: Record<string, (string | HookEntry)[]>;
47
+ afterMap: Record<string, (string | HookEntry)[]>;
48
+ beforeUnmap: Record<string, (string | HookEntry)[]>;
49
+ afterUnmap: Record<string, (string | HookEntry)[]>;
50
+ }
51
+ interface SchemaOptions {
52
+ autoEncrypt?: boolean;
53
+ autoDecrypt?: boolean;
54
+ arraySeparator?: string;
55
+ generateAutoHooks?: boolean;
56
+ allNestedObjectsOptional?: boolean;
57
+ hooks?: SchemaHooks;
58
+ }
59
+ interface SchemaConstructorArgs {
60
+ map?: AttributeMapping;
61
+ pluginMap?: AttributeMapping;
62
+ name: string;
63
+ attributes?: SchemaAttributes;
64
+ passphrase?: string;
65
+ bcryptRounds?: number;
66
+ version?: number;
67
+ options?: SchemaOptions;
68
+ _pluginAttributeMetadata?: PluginAttributeMetadata;
69
+ _pluginAttributes?: PluginAttributes;
70
+ /** Existing schema registry from s3db.json - if provided, indices are preserved */
71
+ schemaRegistry?: SchemaRegistry;
72
+ /** Existing plugin schema registry from s3db.json (accepts both legacy numeric and new string-key formats) */
73
+ pluginSchemaRegistry?: Record<string, PluginSchemaRegistry | SchemaRegistry>;
74
+ }
75
+ interface SchemaExport {
76
+ version: number;
77
+ name: string;
78
+ options: SchemaOptions;
79
+ attributes: SchemaAttributes;
80
+ map: AttributeMapping;
81
+ pluginMap: AttributeMapping;
82
+ _pluginAttributeMetadata: PluginAttributeMetadata;
83
+ _pluginAttributes: PluginAttributes;
84
+ }
85
+ /**
86
+ * Schema Registry - Persistent attribute index mapping (Protocol Buffers style).
87
+ * Prevents data corruption when adding/removing attributes by assigning
88
+ * permanent indices that never change once assigned.
89
+ */
90
+ interface SchemaRegistry {
91
+ /** Next available index for new attributes */
92
+ nextIndex: number;
93
+ /** Permanent mapping of attribute path to numeric index */
94
+ mapping: Record<string, number>;
95
+ /** Indices that were used but attribute was removed - never reused */
96
+ burned: Array<{
97
+ index: number;
98
+ attribute: string;
99
+ burnedAt: string;
100
+ reason?: string;
101
+ }>;
102
+ }
103
+ /**
104
+ * Plugin Schema Registry - Stores actual key strings for plugin attributes.
105
+ * Unlike user attributes (which use numeric indices → base62), plugin attributes
106
+ * use SHA256 hash-based keys that must be preserved exactly.
107
+ */
108
+ interface PluginSchemaRegistry {
109
+ /** Permanent mapping of attribute name to full key string (e.g., "_createdAt" → "p1a2") */
110
+ mapping: Record<string, string>;
111
+ /** Keys that were used but attribute was removed - never reused */
112
+ burned: Array<{
113
+ key: string;
114
+ attribute: string;
115
+ burnedAt: string;
116
+ reason?: string;
117
+ }>;
118
+ }
119
+ type ValidatorFunction = (data: Record<string, unknown>) => Promise<true | Record<string, unknown>[]> | true | Record<string, unknown>[];
120
+ declare class Schema {
121
+ name: string;
122
+ version: number;
123
+ attributes: SchemaAttributes;
124
+ passphrase: string;
125
+ bcryptRounds: number;
126
+ options: SchemaOptions;
127
+ allNestedObjectsOptional: boolean;
128
+ _pluginAttributeMetadata: PluginAttributeMetadata;
129
+ _pluginAttributes: PluginAttributes;
130
+ _schemaFingerprint: string;
131
+ validator: ValidatorFunction;
132
+ map: AttributeMapping;
133
+ reversedMap: AttributeMapping;
134
+ pluginMap: AttributeMapping;
135
+ reversedPluginMap: AttributeMapping;
136
+ /** Updated schema registry - should be persisted to s3db.json */
137
+ _schemaRegistry?: SchemaRegistry;
138
+ /** Updated plugin schema registries - should be persisted to s3db.json */
139
+ _pluginSchemaRegistry?: Record<string, PluginSchemaRegistry>;
140
+ /** Whether the registry was modified and needs persistence */
141
+ _registryChanged: boolean;
142
+ constructor(args: SchemaConstructorArgs);
143
+ defaultOptions(): SchemaOptions;
144
+ private _buildRegistryFromMap;
145
+ /**
146
+ * Generate initial schema registry from current mapping.
147
+ * Used for migrating existing databases that don't have a registry yet.
148
+ * This "freezes" the current mapping as the source of truth.
149
+ */
150
+ generateInitialRegistry(): {
151
+ schemaRegistry: SchemaRegistry;
152
+ pluginSchemaRegistry: Record<string, PluginSchemaRegistry>;
153
+ };
154
+ /**
155
+ * Check if the schema registry needs to be persisted.
156
+ */
157
+ needsRegistryPersistence(): boolean;
158
+ /**
159
+ * Get the updated schema registry for persistence.
160
+ */
161
+ getSchemaRegistry(): SchemaRegistry | undefined;
162
+ /**
163
+ * Get the updated plugin schema registries for persistence.
164
+ */
165
+ getPluginSchemaRegistry(): Record<string, PluginSchemaRegistry> | undefined;
166
+ addHook(hook: keyof SchemaHooks, attribute: string, action: string, params?: Record<string, unknown>): void;
167
+ extractObjectKeys(obj: Record<string, unknown>, prefix?: string): string[];
168
+ _generateHooksFromOriginalAttributes(attributes: Record<string, unknown>, prefix?: string): void;
169
+ generateAutoHooks(): void;
170
+ static import(data: string | SchemaExport): Schema;
171
+ static _importAttributes(attrs: unknown): unknown;
172
+ export(): SchemaExport;
173
+ _exportAttributes(attrs: unknown): SchemaAttributes;
174
+ applyHooksActions(resourceItem: Record<string, unknown>, hook: keyof SchemaHooks): Promise<Record<string, unknown>>;
175
+ validate(resourceItem: Record<string, unknown>, { mutateOriginal }?: {
176
+ mutateOriginal?: boolean | undefined;
177
+ }): Promise<true | Record<string, unknown>[]>;
178
+ mapper(resourceItem: Record<string, unknown>): Promise<Record<string, unknown>>;
179
+ unmapper(mappedResourceItem: Record<string, unknown>, mapOverride?: AttributeMapping, pluginMapOverride?: AttributeMapping): Promise<Record<string, unknown>>;
180
+ getAttributeDefinition(key: string): unknown;
181
+ regeneratePluginMapping(): void;
182
+ preprocessAttributesForValidation(attributes: SchemaAttributes): Record<string, unknown>;
183
+ dispose(): void;
184
+ static getValidatorCacheStats(): ReturnType<typeof getCacheStats>;
185
+ static getValidatorCacheMemoryUsage(): ReturnType<typeof getCacheMemoryUsage>;
186
+ static evictUnusedValidators(maxAgeMs?: number): number;
187
+ }
188
+
189
+ type LogLevel$1 = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'silent';
190
+ type LogFormat = 'json' | 'pretty';
191
+ interface LoggerOptions {
192
+ level?: LogLevel$1;
193
+ name?: string;
194
+ format?: LogFormat;
195
+ transport?: TransportSingleOptions;
196
+ bindings?: Record<string, unknown>;
197
+ redactPatterns?: RegExp[];
198
+ maxPayloadBytes?: number;
199
+ }
200
+ interface S3DBLogger extends Logger$2 {
201
+ _maxPayloadBytes?: number;
202
+ }
203
+ type Logger$1 = S3DBLogger;
204
+ declare function createLogger(options?: LoggerOptions): S3DBLogger;
205
+
206
+ interface AsyncEventEmitterOptions {
207
+ logLevel?: LogLevel$1;
208
+ logger?: S3DBLogger;
209
+ }
210
+ declare class AsyncEventEmitter extends EventEmitter {
211
+ private _asyncMode;
212
+ logLevel: LogLevel$1;
213
+ logger: S3DBLogger;
214
+ constructor(options?: AsyncEventEmitterOptions);
215
+ emit(event: string | symbol, ...args: unknown[]): boolean;
216
+ emitSync(event: string | symbol, ...args: unknown[]): boolean;
217
+ setAsyncMode(enabled: boolean): void;
218
+ }
219
+
220
+ declare const FastestValidator: new (opts?: ValidatorConstructorOptions) => FastestValidatorModule.default;
221
+ interface ValidatorOptions {
222
+ options?: Record<string, unknown>;
223
+ passphrase?: string;
224
+ bcryptRounds?: number;
225
+ autoEncrypt?: boolean;
226
+ autoHash?: boolean;
227
+ }
228
+ declare class Validator extends FastestValidator {
229
+ passphrase?: string;
230
+ bcryptRounds: number;
231
+ autoEncrypt: boolean;
232
+ autoHash: boolean;
233
+ constructor({ options, passphrase, bcryptRounds, autoEncrypt, autoHash }?: ValidatorOptions);
234
+ }
235
+ declare const ValidatorManager: typeof Validator;
236
+
237
+ /** Log levels supported by the logger */
238
+ type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'silent';
239
+ /** Record with string keys */
240
+ type StringRecord$1<T = unknown> = Record<string, T>;
241
+ /** Event handler type */
242
+ type EventHandler<T = unknown> = (data: T) => void | Promise<void>;
243
+ /** Disposable interface for cleanup */
244
+ interface Disposable {
245
+ dispose(): void | Promise<void>;
246
+ }
247
+
248
+ interface ValidatorConfig {
249
+ type?: string;
250
+ optional?: boolean;
251
+ min?: number;
252
+ max?: number;
253
+ properties?: AttributesSchema;
254
+ props?: AttributesSchema;
255
+ items?: string | ValidatorConfig;
256
+ strict?: boolean | 'remove';
257
+ [key: string]: unknown;
258
+ }
259
+ type AttributeValue = string | boolean | undefined | ValidatorConfig | AttributesSchema;
260
+ interface AttributesSchema {
261
+ [key: string]: AttributeValue | 'remove';
262
+ $$async?: boolean;
263
+ $$strict?: boolean | 'remove';
264
+ $$type?: string;
265
+ }
266
+ interface ResourceValidatorConfig {
267
+ attributes?: AttributesSchema;
268
+ strictValidation?: boolean;
269
+ allNestedObjectsOptional?: boolean;
270
+ passphrase?: string;
271
+ bcryptRounds?: number;
272
+ autoEncrypt?: boolean;
273
+ autoDecrypt?: boolean;
274
+ }
275
+ interface ValidationResult {
276
+ isValid: boolean;
277
+ errors: ValidationErrorItem[];
278
+ data: StringRecord$1;
279
+ }
280
+ interface ValidationErrorItem {
281
+ message?: string;
282
+ error?: Error;
283
+ field?: string;
284
+ type?: string;
285
+ [key: string]: unknown;
286
+ }
287
+ interface ValidationOptions {
288
+ throwOnError?: boolean;
289
+ includeId?: boolean;
290
+ mutateOriginal?: boolean;
291
+ }
292
+ type ValidateFn = (data: StringRecord$1) => Promise<true | ValidationErrorItem[]>;
293
+ declare class ResourceValidator {
294
+ attributes: AttributesSchema;
295
+ strictValidation: boolean;
296
+ allNestedObjectsOptional: boolean;
297
+ passphrase?: string;
298
+ bcryptRounds?: number;
299
+ autoEncrypt: boolean;
300
+ autoDecrypt: boolean;
301
+ validatorManager: InstanceType<typeof ValidatorManager>;
302
+ validateFn: ValidateFn;
303
+ constructor(config?: ResourceValidatorConfig);
304
+ compileValidator(): void;
305
+ updateSchema(newAttributes: AttributesSchema): void;
306
+ validate(data: StringRecord$1, options?: ValidationOptions): Promise<ValidationResult>;
307
+ preprocessAttributesForValidation(attributes: AttributesSchema): AttributesSchema;
308
+ applyDefaults(data: StringRecord$1): StringRecord$1;
309
+ }
310
+
311
+ interface S3Object$1 {
312
+ Key: string;
313
+ }
314
+ interface ListObjectsResponse$1 {
315
+ Contents: S3Object$1[];
316
+ NextContinuationToken?: string;
317
+ IsTruncated: boolean;
318
+ }
319
+ interface S3ClientConfig$1 {
320
+ keyPrefix: string;
321
+ }
322
+ interface S3Client$3 {
323
+ parallelism: number;
324
+ config: S3ClientConfig$1;
325
+ listObjects(options: {
326
+ prefix: string;
327
+ continuationToken: string | null;
328
+ }): Promise<ListObjectsResponse$1>;
329
+ }
330
+ interface Resource$5 {
331
+ name: string;
332
+ client: S3Client$3;
333
+ }
334
+ interface ResourceIdsReaderOptions {
335
+ resource: Resource$5;
336
+ }
337
+ declare class ResourceIdsReader extends EventEmitter {
338
+ resource: Resource$5;
339
+ client: S3Client$3;
340
+ stream: ReadableStream$1<string | string[]>;
341
+ controller: ReadableStreamDefaultController<string | string[]>;
342
+ continuationToken: string | null;
343
+ closeNextIteration: boolean;
344
+ constructor({ resource }: ResourceIdsReaderOptions);
345
+ build(): ReadableStreamDefaultReader<string | string[]>;
346
+ _start(controller: ReadableStreamDefaultController<string | string[]>): Promise<void>;
347
+ _pull(_controller: ReadableStreamDefaultController<string | string[]>): Promise<void>;
348
+ enqueue(ids: string[]): void;
349
+ _cancel(_reason?: unknown): void;
350
+ }
351
+
352
+ declare class ResourceIdsPageReader extends ResourceIdsReader {
353
+ enqueue(ids: string[]): void;
354
+ }
355
+
356
+ interface S3Client$2 {
357
+ parallelism: number;
358
+ config: {
359
+ keyPrefix: string;
360
+ };
361
+ listObjects(options: {
362
+ prefix: string;
363
+ continuationToken: string | null;
364
+ }): Promise<unknown>;
365
+ }
366
+ interface Resource$4 {
367
+ name: string;
368
+ client: S3Client$2;
369
+ get(id: string): Promise<Record<string, unknown>>;
370
+ }
371
+ interface ResourceReaderOptions {
372
+ resource: Resource$4;
373
+ batchSize?: number;
374
+ concurrency?: number;
375
+ }
376
+ declare class ResourceReader extends EventEmitter {
377
+ resource: Resource$4;
378
+ client: S3Client$2;
379
+ batchSize: number;
380
+ concurrency: number;
381
+ input: ResourceIdsPageReader;
382
+ transform: Transform;
383
+ constructor({ resource, batchSize, concurrency }: ResourceReaderOptions);
384
+ build(): this;
385
+ _transform(chunk: string[], _encoding: BufferEncoding, callback: TransformCallback): Promise<void>;
386
+ resume(): void;
387
+ }
388
+
389
+ interface S3Client$1 {
390
+ parallelism: number;
391
+ config: {
392
+ keyPrefix: string;
393
+ };
394
+ }
395
+ interface Resource$3 {
396
+ name: string;
397
+ client: S3Client$1;
398
+ insert(data: Record<string, unknown>): Promise<Record<string, unknown>>;
399
+ }
400
+ interface ResourceWriterOptions {
401
+ resource: Resource$3;
402
+ batchSize?: number;
403
+ concurrency?: number;
404
+ }
405
+ declare class ResourceWriter extends EventEmitter {
406
+ resource: Resource$3;
407
+ client: S3Client$1;
408
+ batchSize: number;
409
+ concurrency: number;
410
+ buffer: Record<string, unknown>[];
411
+ writing: boolean;
412
+ ended: boolean;
413
+ writable: Writable;
414
+ constructor({ resource, batchSize, concurrency }: ResourceWriterOptions);
415
+ build(): this;
416
+ write(chunk: Record<string, unknown>): boolean;
417
+ end(): void;
418
+ _maybeWrite(): Promise<void>;
419
+ _write(_chunk: unknown, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
420
+ }
421
+
422
+ declare function streamToString(stream: Readable): Promise<string>;
423
+
424
+ interface S3ClientConfig {
425
+ logLevel?: string;
426
+ logger?: Logger | null;
427
+ id?: string | null;
428
+ AwsS3Client?: unknown;
429
+ connectionString: string;
430
+ httpClientOptions?: HttpClientOptions;
431
+ taskExecutor?: boolean | TaskExecutorConfig;
432
+ executorPool?: boolean | TaskExecutorConfig | null;
433
+ }
434
+ interface HttpClientOptions {
435
+ keepAlive?: boolean;
436
+ keepAliveMsecs?: number;
437
+ maxSockets?: number;
438
+ maxFreeSockets?: number;
439
+ timeout?: number;
440
+ [key: string]: unknown;
441
+ }
442
+ interface TaskExecutorConfig {
443
+ enabled?: boolean;
444
+ concurrency?: number | 'auto';
445
+ retries?: number;
446
+ retryDelay?: number;
447
+ timeout?: number;
448
+ retryableErrors?: string[];
449
+ autotune?: AutotuneConfig$1 | null;
450
+ monitoring?: MonitoringConfig$1;
451
+ }
452
+ interface AutotuneConfig$1 {
453
+ initialConcurrency?: number;
454
+ minConcurrency?: number;
455
+ maxConcurrency?: number;
456
+ targetLatencyMs?: number;
457
+ adjustmentInterval?: number;
458
+ [key: string]: unknown;
459
+ }
460
+ interface MonitoringConfig$1 {
461
+ collectMetrics?: boolean;
462
+ [key: string]: unknown;
463
+ }
464
+ interface Logger {
465
+ debug: (obj: unknown, msg?: string) => void;
466
+ info: (obj: unknown, msg?: string) => void;
467
+ warn: (obj: unknown, msg?: string) => void;
468
+ error: (obj: unknown, msg?: string) => void;
469
+ trace?: (obj: unknown, msg?: string) => void;
470
+ }
471
+ interface MemoryClientConfig {
472
+ id?: string;
473
+ logLevel?: string;
474
+ logger?: Logger;
475
+ concurrency?: number;
476
+ retries?: number;
477
+ retryDelay?: number;
478
+ timeout?: number;
479
+ retryableErrors?: string[];
480
+ taskExecutor?: TaskManager;
481
+ taskExecutorMonitoring?: MonitoringConfig$1 | null;
482
+ bucket?: string;
483
+ keyPrefix?: string;
484
+ region?: string;
485
+ enforceLimits?: boolean;
486
+ metadataLimit?: number;
487
+ maxObjectSize?: number;
488
+ persistPath?: string;
489
+ autoPersist?: boolean;
490
+ maxMemoryMB?: number;
491
+ evictionEnabled?: boolean;
492
+ }
493
+ interface FileSystemClientConfig {
494
+ id?: string;
495
+ logLevel?: string;
496
+ logger?: Logger;
497
+ taskExecutor?: TaskManager;
498
+ taskExecutorMonitoring?: MonitoringConfig$1 | null;
499
+ concurrency?: number;
500
+ retries?: number;
501
+ retryDelay?: number;
502
+ timeout?: number;
503
+ retryableErrors?: string[];
504
+ basePath?: string;
505
+ bucket?: string;
506
+ keyPrefix?: string;
507
+ region?: string;
508
+ enforceLimits?: boolean;
509
+ metadataLimit?: number;
510
+ maxObjectSize?: number;
511
+ compression?: CompressionConfig;
512
+ ttl?: TTLConfig;
513
+ locking?: LockingConfig;
514
+ backup?: BackupConfig;
515
+ journal?: JournalConfig;
516
+ stats?: StatsConfig;
517
+ }
518
+ interface CompressionConfig {
519
+ enabled?: boolean;
520
+ threshold?: number;
521
+ level?: number;
522
+ }
523
+ interface TTLConfig {
524
+ enabled?: boolean;
525
+ defaultTTL?: number;
526
+ cleanupInterval?: number;
527
+ }
528
+ interface LockingConfig {
529
+ enabled?: boolean;
530
+ timeout?: number;
531
+ }
532
+ interface BackupConfig {
533
+ enabled?: boolean;
534
+ suffix?: string;
535
+ }
536
+ interface JournalConfig {
537
+ enabled?: boolean;
538
+ file?: string;
539
+ }
540
+ interface StatsConfig {
541
+ enabled?: boolean;
542
+ }
543
+ interface ClientConfig {
544
+ bucket: string;
545
+ keyPrefix: string;
546
+ region: string;
547
+ endpoint?: string;
548
+ basePath?: string;
549
+ forcePathStyle?: boolean;
550
+ accessKeyId?: string;
551
+ secretAccessKey?: string;
552
+ }
553
+ interface TaskManager {
554
+ concurrency?: number;
555
+ process: <T, R>(items: T[], fn: (item: T) => Promise<R>) => Promise<ProcessResult$2<R>>;
556
+ getStats?: () => QueueStats | null;
557
+ getAggregateMetrics?: (since?: number) => unknown | null;
558
+ }
559
+ interface ProcessResult$2<T> {
560
+ results: T[];
561
+ errors: Array<{
562
+ error: Error;
563
+ index: number;
564
+ item?: unknown;
565
+ }>;
566
+ }
567
+ interface QueueStats {
568
+ queueSize?: number;
569
+ activeCount?: number;
570
+ effectiveConcurrency?: number;
571
+ [key: string]: unknown;
572
+ }
573
+ interface PutObjectParams {
574
+ key: string;
575
+ metadata?: Record<string, unknown>;
576
+ contentType?: string;
577
+ body?: Buffer | string | Readable;
578
+ contentEncoding?: string;
579
+ contentLength?: number;
580
+ ifMatch?: string;
581
+ ifNoneMatch?: string;
582
+ }
583
+ interface CopyObjectParams {
584
+ from: string;
585
+ to: string;
586
+ metadata?: Record<string, unknown>;
587
+ metadataDirective?: 'COPY' | 'REPLACE';
588
+ contentType?: string;
589
+ }
590
+ interface ListObjectsParams {
591
+ prefix?: string;
592
+ delimiter?: string | null;
593
+ maxKeys?: number;
594
+ continuationToken?: string | null;
595
+ startAfter?: string | null;
596
+ }
597
+ interface GetKeysPageParams {
598
+ prefix?: string;
599
+ offset?: number;
600
+ amount?: number;
601
+ }
602
+ interface S3Object {
603
+ Body?: Readable & {
604
+ transformToString?: (encoding?: string) => Promise<string>;
605
+ transformToByteArray?: () => Promise<Uint8Array>;
606
+ transformToWebStream?: () => ReadableStream;
607
+ };
608
+ Metadata: Record<string, string>;
609
+ ContentType?: string;
610
+ ContentLength?: number;
611
+ ETag?: string;
612
+ LastModified?: Date;
613
+ ContentEncoding?: string;
614
+ }
615
+ interface ListObjectsResponse {
616
+ Contents: S3ObjectInfo[];
617
+ CommonPrefixes: Array<{
618
+ Prefix: string;
619
+ }>;
620
+ IsTruncated: boolean;
621
+ ContinuationToken?: string;
622
+ NextContinuationToken?: string | null;
623
+ KeyCount: number;
624
+ MaxKeys: number;
625
+ Prefix?: string;
626
+ Delimiter?: string | null;
627
+ StartAfter?: string;
628
+ }
629
+ interface S3ObjectInfo {
630
+ Key: string;
631
+ Size: number;
632
+ LastModified: Date;
633
+ ETag: string;
634
+ StorageClass?: string;
635
+ }
636
+ interface PutObjectResponse {
637
+ ETag: string;
638
+ VersionId: string | null;
639
+ ServerSideEncryption: string | null;
640
+ Location: string;
641
+ }
642
+ interface CopyObjectResponse {
643
+ CopyObjectResult: {
644
+ ETag: string;
645
+ LastModified: string;
646
+ };
647
+ BucketKeyEnabled: boolean;
648
+ VersionId: string | null;
649
+ ServerSideEncryption: string | null;
650
+ }
651
+ interface DeleteObjectResponse {
652
+ DeleteMarker: boolean;
653
+ VersionId: string | null;
654
+ }
655
+ interface DeleteObjectsResponse {
656
+ Deleted: Array<{
657
+ Key: string;
658
+ }>;
659
+ Errors: Array<{
660
+ Key: string;
661
+ Code: string;
662
+ Message: string;
663
+ }>;
664
+ }
665
+ interface StoragePutParams {
666
+ body?: Buffer | string | unknown;
667
+ metadata?: Record<string, string>;
668
+ contentType?: string;
669
+ contentEncoding?: string;
670
+ contentLength?: number;
671
+ ifMatch?: string;
672
+ ifNoneMatch?: string;
673
+ ttl?: number;
674
+ }
675
+ interface StorageCopyParams {
676
+ metadata?: Record<string, string>;
677
+ metadataDirective?: 'COPY' | 'REPLACE';
678
+ contentType?: string;
679
+ }
680
+ interface StorageListParams {
681
+ prefix?: string;
682
+ delimiter?: string | null;
683
+ maxKeys?: number;
684
+ continuationToken?: string | null;
685
+ startAfter?: string | null;
686
+ }
687
+ interface MemoryStorageConfig {
688
+ bucket?: string;
689
+ enforceLimits?: boolean;
690
+ metadataLimit?: number;
691
+ maxObjectSize?: number;
692
+ persistPath?: string;
693
+ autoPersist?: boolean;
694
+ logLevel?: string;
695
+ logger?: Logger;
696
+ maxMemoryMB?: number;
697
+ evictionEnabled?: boolean;
698
+ }
699
+ interface FileSystemStorageConfig {
700
+ basePath?: string;
701
+ bucket?: string;
702
+ enforceLimits?: boolean;
703
+ metadataLimit?: number;
704
+ maxObjectSize?: number;
705
+ logLevel?: string;
706
+ logger?: Logger;
707
+ compression?: CompressionConfig;
708
+ ttl?: TTLConfig;
709
+ locking?: LockingConfig;
710
+ backup?: BackupConfig;
711
+ journal?: JournalConfig;
712
+ stats?: StatsConfig;
713
+ }
714
+ interface MemoryStorageStats {
715
+ objectCount: number;
716
+ totalSize: number;
717
+ totalSizeFormatted: string;
718
+ keys: string[];
719
+ bucket: string;
720
+ maxMemoryMB: number;
721
+ memoryUsagePercent: number;
722
+ evictions: number;
723
+ evictedBytes: number;
724
+ peakMemoryBytes: number;
725
+ }
726
+ interface FileSystemStorageStats {
727
+ gets: number;
728
+ puts: number;
729
+ deletes: number;
730
+ errors: number;
731
+ compressionSaved: number;
732
+ totalCompressed: number;
733
+ totalUncompressed: number;
734
+ avgCompressionRatio: string | number;
735
+ features: {
736
+ compression: boolean;
737
+ ttl: boolean;
738
+ locking: boolean;
739
+ backup: boolean;
740
+ journal: boolean;
741
+ stats: boolean;
742
+ };
743
+ }
744
+ interface StorageSnapshot {
745
+ timestamp: string;
746
+ bucket: string;
747
+ objectCount: number;
748
+ objects: Record<string, {
749
+ body: string;
750
+ metadata: Record<string, string>;
751
+ contentType: string;
752
+ etag: string;
753
+ lastModified: string;
754
+ size: number;
755
+ contentEncoding?: string;
756
+ contentLength: number;
757
+ }>;
758
+ }
759
+ interface Client extends EventEmitter {
760
+ id: string;
761
+ config: ClientConfig;
762
+ connectionString: string;
763
+ putObject(params: PutObjectParams): Promise<PutObjectResponse>;
764
+ getObject(key: string): Promise<S3Object>;
765
+ headObject(key: string): Promise<S3Object>;
766
+ copyObject(params: CopyObjectParams): Promise<CopyObjectResponse>;
767
+ exists(key: string): Promise<boolean>;
768
+ deleteObject(key: string): Promise<DeleteObjectResponse>;
769
+ deleteObjects(keys: string[]): Promise<DeleteObjectsResponse>;
770
+ listObjects(params?: ListObjectsParams): Promise<ListObjectsResponse>;
771
+ getKeysPage(params?: GetKeysPageParams): Promise<string[]>;
772
+ getAllKeys(params?: {
773
+ prefix?: string;
774
+ }): Promise<string[]>;
775
+ count(params?: {
776
+ prefix?: string;
777
+ }): Promise<number>;
778
+ deleteAll(params?: {
779
+ prefix?: string;
780
+ }): Promise<number>;
781
+ getContinuationTokenAfterOffset(params?: {
782
+ prefix?: string;
783
+ offset?: number;
784
+ }): Promise<string | null>;
785
+ moveObject(params: {
786
+ from: string;
787
+ to: string;
788
+ }): Promise<boolean>;
789
+ moveAllObjects(params: {
790
+ prefixFrom: string;
791
+ prefixTo: string;
792
+ }): Promise<Array<{
793
+ from: string;
794
+ to: string;
795
+ }>>;
796
+ getQueueStats(): QueueStats | null;
797
+ getAggregateMetrics(since?: number): unknown | null;
798
+ destroy(): void;
799
+ }
800
+
801
+ interface SchemaInfo {
802
+ map?: StringRecord$1;
803
+ pluginMap?: StringRecord$1;
804
+ }
805
+ interface ResourceConfig$1 {
806
+ timestamps?: boolean;
807
+ }
808
+ interface Resource$2 {
809
+ name: string;
810
+ version: string;
811
+ config: ResourceConfig$1;
812
+ schema?: SchemaInfo;
813
+ emit(event: string, payload: unknown): void;
814
+ }
815
+ interface BehaviorHandleInsertParams {
816
+ resource: Resource$2;
817
+ data: StringRecord$1;
818
+ mappedData: StringRecord$1<string>;
819
+ originalData?: StringRecord$1;
820
+ }
821
+ interface BehaviorHandleUpdateParams {
822
+ resource: Resource$2;
823
+ id: string;
824
+ data: StringRecord$1;
825
+ mappedData: StringRecord$1<string>;
826
+ originalData?: StringRecord$1;
827
+ }
828
+ interface BehaviorHandleUpsertParams {
829
+ resource: Resource$2;
830
+ id: string;
831
+ data: StringRecord$1;
832
+ mappedData: StringRecord$1<string>;
833
+ }
834
+ interface BehaviorHandleGetParams {
835
+ resource: Resource$2;
836
+ metadata: StringRecord$1<string>;
837
+ body: string;
838
+ }
839
+ interface BehaviorResult {
840
+ mappedData: StringRecord$1<string>;
841
+ body: string;
842
+ }
843
+ interface BehaviorGetResult {
844
+ metadata: StringRecord$1<string>;
845
+ body: string;
846
+ }
847
+ interface Behavior {
848
+ handleInsert(params: BehaviorHandleInsertParams): Promise<BehaviorResult>;
849
+ handleUpdate(params: BehaviorHandleUpdateParams): Promise<BehaviorResult>;
850
+ handleUpsert?(params: BehaviorHandleUpsertParams): Promise<BehaviorResult>;
851
+ handleGet(params: BehaviorHandleGetParams): Promise<BehaviorGetResult>;
852
+ }
853
+ type BehaviorName = 'user-managed' | 'enforce-limits' | 'truncate-data' | 'body-overflow' | 'body-only';
854
+ type BehaviorType = BehaviorName;
855
+
856
+ type HookFunction<T = unknown> = (data: T) => T | Promise<T>;
857
+ type BoundHookFunction<T = unknown> = HookFunction<T> & {
858
+ __s3db_original?: HookFunction<T>;
859
+ };
860
+ interface HooksCollection {
861
+ beforeInsert: BoundHookFunction[];
862
+ afterInsert: BoundHookFunction[];
863
+ beforeUpdate: BoundHookFunction[];
864
+ afterUpdate: BoundHookFunction[];
865
+ beforeDelete: BoundHookFunction[];
866
+ afterDelete: BoundHookFunction[];
867
+ beforeGet: BoundHookFunction[];
868
+ afterGet: BoundHookFunction[];
869
+ beforeList: BoundHookFunction[];
870
+ afterList: BoundHookFunction[];
871
+ beforeQuery: BoundHookFunction[];
872
+ afterQuery: BoundHookFunction[];
873
+ beforePatch: BoundHookFunction[];
874
+ afterPatch: BoundHookFunction[];
875
+ beforeReplace: BoundHookFunction[];
876
+ afterReplace: BoundHookFunction[];
877
+ beforeExists: BoundHookFunction[];
878
+ afterExists: BoundHookFunction[];
879
+ beforeCount: BoundHookFunction[];
880
+ afterCount: BoundHookFunction[];
881
+ beforeGetMany: BoundHookFunction[];
882
+ afterGetMany: BoundHookFunction[];
883
+ beforeDeleteMany: BoundHookFunction[];
884
+ afterDeleteMany: BoundHookFunction[];
885
+ [event: string]: BoundHookFunction[];
886
+ }
887
+ type HookEvent = 'beforeInsert' | 'afterInsert' | 'beforeUpdate' | 'afterUpdate' | 'beforeDelete' | 'afterDelete' | 'beforeGet' | 'afterGet' | 'beforeList' | 'afterList' | 'beforeQuery' | 'afterQuery' | 'beforePatch' | 'afterPatch' | 'beforeReplace' | 'afterReplace' | 'beforeExists' | 'afterExists' | 'beforeCount' | 'afterCount' | 'beforeGetMany' | 'afterGetMany' | 'beforeDeleteMany' | 'afterDeleteMany';
888
+
889
+ interface JWTUser {
890
+ scope?: string;
891
+ azp?: string;
892
+ resource_access?: {
893
+ [clientId: string]: {
894
+ roles?: string[];
895
+ };
896
+ };
897
+ realm_access?: {
898
+ roles?: string[];
899
+ };
900
+ roles?: string[];
901
+ [key: string]: unknown;
902
+ }
903
+ interface GuardContext {
904
+ user?: JWTUser;
905
+ params?: StringRecord$1;
906
+ body?: unknown;
907
+ query?: StringRecord$1;
908
+ headers?: StringRecord$1;
909
+ setPartition?: (partition: string, values?: StringRecord$1) => void;
910
+ }
911
+ type GuardFunction = (context: GuardContext, record?: unknown) => boolean | Promise<boolean>;
912
+ type GuardValue = boolean | string[] | GuardFunction;
913
+ interface GuardConfig {
914
+ [operation: string]: GuardValue;
915
+ }
916
+
917
+ type SupportedMethod = 'get' | 'list' | 'listIds' | 'getAll' | 'count' | 'page' | 'insert' | 'update' | 'delete' | 'deleteMany' | 'exists' | 'getMany' | 'content' | 'hasContent' | 'query' | 'getFromPartition' | 'setContent' | 'deleteContent' | 'replace';
918
+ interface MiddlewareContext {
919
+ resource: Resource$1;
920
+ args: unknown[];
921
+ method: string;
922
+ }
923
+ type NextFunction = () => Promise<unknown>;
924
+ type MiddlewareFunction = (ctx: MiddlewareContext, next: NextFunction) => Promise<unknown>;
925
+ interface Resource$1 {
926
+ name: string;
927
+ [method: string]: unknown;
928
+ }
929
+
930
+ interface PartitionFields$1 {
931
+ [fieldName: string]: string;
932
+ }
933
+ interface PartitionDefinition$1 {
934
+ fields: PartitionFields$1;
935
+ }
936
+ interface PartitionsConfig {
937
+ [partitionName: string]: PartitionDefinition$1;
938
+ }
939
+
940
+ interface PartitionFields {
941
+ [fieldName: string]: string;
942
+ }
943
+ interface PartitionDefinition {
944
+ fields: PartitionFields;
945
+ }
946
+ interface OrphanedPartition {
947
+ missingFields: string[];
948
+ definition: PartitionDefinition;
949
+ allFields: string[];
950
+ }
951
+ interface OrphanedPartitions {
952
+ [partitionName: string]: OrphanedPartition;
953
+ }
954
+
955
+ type EventListener = (...args: unknown[]) => void | Promise<void>;
956
+ interface EventListeners {
957
+ [eventName: string]: EventListener | EventListener[];
958
+ }
959
+
960
+ interface IncrementalConfig {
961
+ type: 'incremental';
962
+ start?: number;
963
+ prefix?: string;
964
+ mode?: 'fast' | 'normal';
965
+ [key: string]: unknown;
966
+ }
967
+ type IdGeneratorConfig = ((data?: unknown) => string) | number | string | IncrementalConfig;
968
+ interface SequenceInterface {
969
+ getValue(fieldName: string): Promise<number>;
970
+ reset(fieldName: string, value: number): Promise<boolean>;
971
+ list(): Promise<SequenceInfo[]>;
972
+ reserveBatch(fieldName: string, count: number): Promise<BatchInfo>;
973
+ getBatchStatus(fieldName: string): BatchStatus | null;
974
+ releaseBatch(fieldName: string): void;
975
+ }
976
+ interface SequenceInfo {
977
+ fieldName: string;
978
+ currentValue: number;
979
+ }
980
+ interface BatchInfo {
981
+ start: number;
982
+ end: number;
983
+ current: number;
984
+ }
985
+ interface BatchStatus {
986
+ start: number;
987
+ end: number;
988
+ current: number;
989
+ remaining: number;
990
+ [key: string]: unknown;
991
+ }
992
+ type IdGeneratorFunction = (() => string) | (() => Promise<string>);
993
+ type IncrementalGenerator = IdGeneratorFunction & {
994
+ _sequence?: SequenceInterface;
995
+ };
996
+
997
+ interface ResourceConfig {
998
+ name: string;
999
+ client: Client;
1000
+ database?: Database$1;
1001
+ version?: string;
1002
+ attributes?: AttributesSchema;
1003
+ behavior?: BehaviorType;
1004
+ passphrase?: string;
1005
+ bcryptRounds?: number;
1006
+ observers?: Database$1[];
1007
+ cache?: boolean;
1008
+ autoEncrypt?: boolean;
1009
+ autoDecrypt?: boolean;
1010
+ timestamps?: boolean;
1011
+ partitions?: PartitionsConfig | string[];
1012
+ paranoid?: boolean;
1013
+ allNestedObjectsOptional?: boolean;
1014
+ hooks?: Partial<HooksCollection>;
1015
+ idGenerator?: IdGeneratorFunction | number | string;
1016
+ idSize?: number;
1017
+ versioningEnabled?: boolean;
1018
+ strictValidation?: boolean;
1019
+ events?: EventListeners;
1020
+ asyncEvents?: boolean;
1021
+ asyncPartitions?: boolean;
1022
+ strictPartitions?: boolean;
1023
+ createdBy?: string;
1024
+ guard?: GuardConfig;
1025
+ logLevel?: LogLevel;
1026
+ map?: StringRecord$1<string>;
1027
+ disableEvents?: boolean;
1028
+ disableResourceEvents?: boolean;
1029
+ api?: ResourceApiConfig$1;
1030
+ description?: string;
1031
+ /** Schema registry for stable attribute indices - loaded from s3db.json */
1032
+ schemaRegistry?: SchemaRegistry;
1033
+ /** Plugin schema registries for stable plugin attribute indices */
1034
+ pluginSchemaRegistry?: Record<string, PluginSchemaRegistry | SchemaRegistry>;
1035
+ }
1036
+ interface ResourceApiConfig$1 {
1037
+ enabled?: boolean;
1038
+ path?: string;
1039
+ operations?: {
1040
+ list?: boolean;
1041
+ get?: boolean;
1042
+ insert?: boolean;
1043
+ update?: boolean;
1044
+ delete?: boolean;
1045
+ query?: boolean;
1046
+ };
1047
+ middleware?: MiddlewareFunction[];
1048
+ }
1049
+ interface ResourceInternalConfig {
1050
+ cache: boolean;
1051
+ hooks: Partial<HooksCollection>;
1052
+ paranoid: boolean;
1053
+ timestamps: boolean;
1054
+ partitions: PartitionsConfig;
1055
+ autoEncrypt: boolean;
1056
+ autoDecrypt: boolean;
1057
+ allNestedObjectsOptional: boolean;
1058
+ asyncEvents: boolean;
1059
+ asyncPartitions: boolean;
1060
+ strictPartitions: boolean;
1061
+ createdBy: string;
1062
+ }
1063
+ interface ResourceExport {
1064
+ name: string;
1065
+ attributes: AttributesSchema;
1066
+ behavior: BehaviorType;
1067
+ timestamps: boolean;
1068
+ partitions: PartitionsConfig;
1069
+ paranoid: boolean;
1070
+ allNestedObjectsOptional: boolean;
1071
+ autoDecrypt: boolean;
1072
+ cache: boolean;
1073
+ asyncEvents?: boolean;
1074
+ asyncPartitions?: boolean;
1075
+ hooks: Partial<HooksCollection>;
1076
+ map?: StringRecord$1<string>;
1077
+ }
1078
+ interface ResourceData {
1079
+ id: string;
1080
+ [key: string]: unknown;
1081
+ }
1082
+ interface ContentResult {
1083
+ buffer: Buffer | null;
1084
+ contentType: string | null;
1085
+ }
1086
+ interface SetContentParams {
1087
+ id: string;
1088
+ buffer: Buffer | string;
1089
+ contentType?: string;
1090
+ }
1091
+ interface PageResult {
1092
+ items: ResourceData[];
1093
+ total: number;
1094
+ offset: number;
1095
+ size: number;
1096
+ hasMore: boolean;
1097
+ }
1098
+ interface QueryFilter {
1099
+ [key: string]: unknown;
1100
+ }
1101
+ interface QueryOptions {
1102
+ limit?: number;
1103
+ offset?: number;
1104
+ partition?: string | null;
1105
+ partitionValues?: StringRecord$1;
1106
+ }
1107
+ interface ListOptions {
1108
+ partition?: string | null;
1109
+ partitionValues?: StringRecord$1;
1110
+ limit?: number;
1111
+ offset?: number;
1112
+ }
1113
+ interface CountOptions {
1114
+ partition?: string | null;
1115
+ partitionValues?: StringRecord$1;
1116
+ }
1117
+ interface DeleteManyResult {
1118
+ deleted: number;
1119
+ failed: number;
1120
+ errors?: unknown[];
1121
+ }
1122
+ interface PageOptions {
1123
+ offset?: number;
1124
+ size?: number;
1125
+ partition?: string | null;
1126
+ partitionValues?: StringRecord$1;
1127
+ skipCount?: boolean;
1128
+ }
1129
+ interface UpdateConditionalResult {
1130
+ success: boolean;
1131
+ data?: ResourceData;
1132
+ error?: string;
1133
+ currentETag?: string;
1134
+ }
1135
+ interface UpdateConditionalResult {
1136
+ success: boolean;
1137
+ data?: ResourceData;
1138
+ etag?: string;
1139
+ error?: string;
1140
+ }
1141
+ interface ComposeFullObjectParams {
1142
+ id: string;
1143
+ metadata: StringRecord$1;
1144
+ body: string;
1145
+ behavior: BehaviorType;
1146
+ }
1147
+ interface GetFromPartitionParams {
1148
+ id: string;
1149
+ partitionName: string;
1150
+ partitionValues?: StringRecord$1;
1151
+ }
1152
+ interface Database$1 {
1153
+ id: string;
1154
+ logger: Logger$1;
1155
+ getChildLogger(name: string, bindings?: Record<string, unknown>): Logger$1;
1156
+ emit(event: string, data: unknown): void;
1157
+ savedMetadata?: SavedMetadata$1 | null;
1158
+ }
1159
+ interface SavedMetadata$1 {
1160
+ resources?: StringRecord$1<ResourceMetadata$1>;
1161
+ }
1162
+ interface ResourceMetadata$1 {
1163
+ currentVersion?: string;
1164
+ versions?: StringRecord$1<VersionData$1>;
1165
+ }
1166
+ interface VersionData$1 {
1167
+ hash?: string;
1168
+ attributes?: AttributesSchema;
1169
+ }
1170
+ declare class Resource extends AsyncEventEmitter implements Disposable {
1171
+ name: string;
1172
+ client: Client;
1173
+ version: string;
1174
+ logLevel: LogLevel$1;
1175
+ logger: Logger$1;
1176
+ behavior: BehaviorType;
1177
+ private _resourceAsyncEvents;
1178
+ observers: Database$1[];
1179
+ passphrase: string;
1180
+ bcryptRounds: number;
1181
+ versioningEnabled: boolean;
1182
+ strictValidation: boolean;
1183
+ asyncEvents: boolean;
1184
+ idGenerator: IdGeneratorFunction | IncrementalGenerator | null;
1185
+ idSize: number;
1186
+ idGeneratorType: IdGeneratorConfig | undefined;
1187
+ config: ResourceInternalConfig;
1188
+ validator: ResourceValidator;
1189
+ schema: Schema;
1190
+ $schema: Readonly<Omit<ResourceConfig, 'database' | 'observers' | 'client'>>;
1191
+ hooks: HooksCollection;
1192
+ attributes: AttributesSchema;
1193
+ guard: GuardConfig | null;
1194
+ eventsDisabled: boolean;
1195
+ database?: Database$1;
1196
+ map?: StringRecord$1<string>;
1197
+ private _schemaRegistry?;
1198
+ private _pluginSchemaRegistry?;
1199
+ private _instanceId;
1200
+ private _idGenerator;
1201
+ private _hooksModule;
1202
+ private _partitions;
1203
+ private _eventsModule;
1204
+ private _guards;
1205
+ private _middleware;
1206
+ private _query;
1207
+ private _content;
1208
+ private _streams;
1209
+ private _persistence;
1210
+ constructor(config?: ResourceConfig);
1211
+ private _normalizePartitionsInput;
1212
+ configureIdGenerator(customIdGenerator: IdGeneratorFunction | number | string | undefined, idSize: number): IdGeneratorFunction | IncrementalGenerator | null;
1213
+ private _initIncrementalIdGenerator;
1214
+ hasAsyncIdGenerator(): boolean;
1215
+ getIdGeneratorType(customIdGenerator: IdGeneratorFunction | number | undefined, idSize: number): IdGeneratorConfig | undefined;
1216
+ export(): ResourceExport;
1217
+ applyConfiguration({ map }?: {
1218
+ map?: StringRecord$1<string>;
1219
+ }): void;
1220
+ updateAttributes(newAttributes: AttributesSchema): {
1221
+ oldAttributes: AttributesSchema;
1222
+ newAttributes: AttributesSchema;
1223
+ };
1224
+ addPluginAttribute(name: string, definition: string | Record<string, unknown>, pluginName: string): void;
1225
+ removePluginAttribute(name: string, pluginName?: string | null): boolean;
1226
+ addHook(event: HookEvent, fn: HookFunction): void;
1227
+ executeHooks(event: HookEvent, data: unknown): Promise<unknown>;
1228
+ _bindHook(fn: HookFunction): BoundHookFunction<unknown> | null;
1229
+ setupPartitionHooks(): void;
1230
+ validate(data: Record<string, unknown>, options?: ValidationOptions): Promise<ValidationResult>;
1231
+ validatePartitions(): void;
1232
+ fieldExistsInAttributes(fieldName: string): boolean;
1233
+ findOrphanedPartitions(): OrphanedPartitions;
1234
+ removeOrphanedPartitions({ dryRun }?: {
1235
+ dryRun?: boolean | undefined;
1236
+ }): OrphanedPartitions;
1237
+ applyPartitionRule(value: unknown, rule: string): unknown;
1238
+ getResourceKey(id: string): string;
1239
+ getPartitionKey({ partitionName, id, data }: {
1240
+ partitionName: string;
1241
+ id: string;
1242
+ data: Record<string, unknown>;
1243
+ }): string | null;
1244
+ getNestedFieldValue(data: Record<string, unknown>, fieldPath: string): unknown;
1245
+ calculateContentLength(body: string | Buffer | object | null | undefined): number;
1246
+ _emitStandardized(event: string, payload: unknown, id?: string | null): void;
1247
+ _ensureEventsWired(): void;
1248
+ on(eventName: string, listener: EventHandler): this;
1249
+ addListener(eventName: string, listener: EventHandler): this;
1250
+ once(eventName: string, listener: EventHandler): this;
1251
+ emit(eventName: string, ...args: unknown[]): boolean;
1252
+ insert({ id, ...attributes }: {
1253
+ id?: string;
1254
+ } & Record<string, unknown>): Promise<ResourceData>;
1255
+ get(id: string): Promise<ResourceData>;
1256
+ getOrNull(id: string): Promise<ResourceData | null>;
1257
+ getOrThrow(id: string): Promise<ResourceData>;
1258
+ exists(id: string): Promise<boolean>;
1259
+ update(id: string, attributes: Record<string, unknown>): Promise<ResourceData>;
1260
+ patch(id: string, fields: Record<string, unknown>, options?: {
1261
+ partition?: string;
1262
+ partitionValues?: StringRecord$1;
1263
+ }): Promise<ResourceData>;
1264
+ _patchViaCopyObject(id: string, fields: Record<string, unknown>, options?: Record<string, unknown>): Promise<ResourceData>;
1265
+ replace(id: string, fullData: Record<string, unknown>, options?: {
1266
+ partition?: string;
1267
+ partitionValues?: StringRecord$1;
1268
+ }): Promise<ResourceData>;
1269
+ updateConditional(id: string, attributes: Record<string, unknown>, options?: {
1270
+ ifMatch?: string;
1271
+ }): Promise<UpdateConditionalResult>;
1272
+ delete(id: string): Promise<unknown>;
1273
+ upsert({ id, ...attributes }: {
1274
+ id: string;
1275
+ } & Record<string, unknown>): Promise<ResourceData>;
1276
+ count({ partition, partitionValues }?: CountOptions): Promise<number>;
1277
+ insertMany(objects: Record<string, unknown>[]): Promise<ResourceData[]>;
1278
+ _executeBatchHelper(operations: unknown[], options?: Record<string, unknown>): Promise<unknown>;
1279
+ deleteMany(ids: string[]): Promise<DeleteManyResult>;
1280
+ deleteAll(): Promise<{
1281
+ deletedCount: number;
1282
+ }>;
1283
+ deleteAllData(): Promise<{
1284
+ deletedCount: number;
1285
+ }>;
1286
+ listIds({ partition, partitionValues, limit, offset }?: ListOptions): Promise<string[]>;
1287
+ list({ partition, partitionValues, limit, offset }?: ListOptions): Promise<ResourceData[]>;
1288
+ listMain({ limit, offset }: {
1289
+ limit?: number;
1290
+ offset?: number;
1291
+ }): Promise<ResourceData[]>;
1292
+ listPartition({ partition, partitionValues, limit, offset }: {
1293
+ partition: string;
1294
+ partitionValues: StringRecord$1;
1295
+ limit?: number;
1296
+ offset?: number;
1297
+ }): Promise<ResourceData[]>;
1298
+ buildPartitionPrefix(partition: string, partitionDef: PartitionDefinition$1, partitionValues: StringRecord$1): string;
1299
+ extractIdsFromKeys(keys: string[]): string[];
1300
+ processListResults(ids: string[], context?: string): Promise<ResourceData[]>;
1301
+ processPartitionResults(ids: string[], partition: string, partitionDef: PartitionDefinition$1, keys: string[]): Promise<ResourceData[]>;
1302
+ extractPartitionValuesFromKey(id: string, keys: string[], sortedFields: string[]): StringRecord$1;
1303
+ handleResourceError(error: Error, id: string, context: string): ResourceData;
1304
+ handleListError(error: Error, { partition, partitionValues }: {
1305
+ partition: string | null;
1306
+ partitionValues: StringRecord$1;
1307
+ }): ResourceData[];
1308
+ getMany(ids: string[]): Promise<ResourceData[]>;
1309
+ getAll(): Promise<ResourceData[]>;
1310
+ page({ offset, size, partition, partitionValues, skipCount }?: PageOptions): Promise<PageResult>;
1311
+ readable(): ResourceReader;
1312
+ writable(): ResourceWriter;
1313
+ setContent({ id, buffer, contentType }: SetContentParams): Promise<ResourceData>;
1314
+ content(id: string): Promise<ContentResult>;
1315
+ hasContent(id: string): Promise<boolean>;
1316
+ deleteContent(id: string): Promise<unknown>;
1317
+ getDefinitionHash(): string;
1318
+ extractVersionFromKey(key: string): string | null;
1319
+ getSchemaForVersion(version: string): Promise<Schema>;
1320
+ createPartitionReferences(data: ResourceData): Promise<void>;
1321
+ deletePartitionReferences(data: ResourceData): Promise<void>;
1322
+ query(filter?: QueryFilter, { limit, offset, partition, partitionValues }?: QueryOptions): Promise<ResourceData[]>;
1323
+ handlePartitionReferenceUpdates(oldData: ResourceData, newData: ResourceData): Promise<void>;
1324
+ handlePartitionReferenceUpdate(partitionName: string, partition: PartitionDefinition$1, oldData: ResourceData, newData: ResourceData): Promise<void>;
1325
+ updatePartitionReferences(data: ResourceData): Promise<void>;
1326
+ getFromPartition({ id, partitionName, partitionValues }: GetFromPartitionParams): Promise<ResourceData>;
1327
+ createHistoricalVersion(id: string, data: ResourceData): Promise<void>;
1328
+ applyVersionMapping(data: ResourceData, fromVersion: string, toVersion: string): Promise<ResourceData>;
1329
+ composeFullObjectFromWrite({ id, metadata, body, behavior }: ComposeFullObjectParams): Promise<ResourceData>;
1330
+ _normalizeGuard(guard: GuardConfig): GuardConfig | null;
1331
+ executeGuard(operation: string, context: GuardContext, resource?: ResourceData | null): Promise<boolean>;
1332
+ _checkRolesScopes(requiredRolesScopes: string[], user: JWTUser): boolean;
1333
+ _initMiddleware(): void;
1334
+ useMiddleware(method: SupportedMethod, fn: MiddlewareFunction): void;
1335
+ applyDefaults(data: Record<string, unknown>): Record<string, unknown>;
1336
+ getSequenceValue(fieldName?: string): Promise<number | null>;
1337
+ resetSequence(fieldName: string, value: number): Promise<boolean>;
1338
+ listSequences(): Promise<SequenceInfo[] | null>;
1339
+ reserveIdBatch(count?: number): Promise<{
1340
+ start: number;
1341
+ end: number;
1342
+ current: number;
1343
+ } | null>;
1344
+ getBatchStatus(fieldName?: string): {
1345
+ start: number;
1346
+ end: number;
1347
+ current: number;
1348
+ remaining: number;
1349
+ } | null;
1350
+ releaseBatch(fieldName?: string): void;
1351
+ dispose(): void;
1352
+ }
1353
+
1354
+ interface ProcessManagerOptions {
1355
+ logLevel?: LogLevel$1;
1356
+ shutdownTimeout?: number;
1357
+ exitOnSignal?: boolean;
1358
+ logger?: S3DBLogger;
1359
+ }
1360
+ type CleanupFn = () => Promise<void> | void;
1361
+ interface ProcessManagerStatus {
1362
+ isShuttingDown: boolean;
1363
+ intervals: string[];
1364
+ timeouts: string[];
1365
+ cleanups: string[];
1366
+ counts: {
1367
+ intervals: number;
1368
+ timeouts: number;
1369
+ cleanups: number;
1370
+ };
1371
+ }
1372
+ interface ShutdownOptions {
1373
+ timeout?: number;
1374
+ }
1375
+ declare class ProcessManager {
1376
+ private options;
1377
+ private logger;
1378
+ private intervals;
1379
+ private timeouts;
1380
+ private cleanups;
1381
+ private isShuttingDown;
1382
+ private shutdownPromise;
1383
+ private _boundSignalHandler;
1384
+ private _signalHandlersSetup;
1385
+ constructor(options?: ProcessManagerOptions);
1386
+ setInterval(fn: () => void, interval: number, name: string): ReturnType<typeof setTimeout>;
1387
+ clearInterval(name: string): void;
1388
+ setTimeout(fn: () => void, delay: number, name: string): ReturnType<typeof setTimeout>;
1389
+ clearTimeout(name: string): void;
1390
+ registerCleanup(cleanupFn: CleanupFn, name: string): void;
1391
+ unregisterCleanup(name: string): void;
1392
+ private _setupSignalHandlers;
1393
+ private _handleSignal;
1394
+ shutdown(options?: ShutdownOptions): Promise<void>;
1395
+ private _performShutdown;
1396
+ getStatus(): ProcessManagerStatus;
1397
+ removeSignalHandlers(): void;
1398
+ }
1399
+ declare function getProcessManager(options?: ProcessManagerOptions): ProcessManager;
1400
+ declare function resetProcessManager(): void;
1401
+
1402
+ interface SafeEventEmitterOptions {
1403
+ logLevel?: LogLevel$1;
1404
+ logger?: S3DBLogger;
1405
+ autoCleanup?: boolean;
1406
+ maxListeners?: number;
1407
+ }
1408
+ interface ListenerStats {
1409
+ [eventName: string]: number;
1410
+ }
1411
+ declare class SafeEventEmitter extends EventEmitter {
1412
+ options: Required<Omit<SafeEventEmitterOptions, 'logger'>> & {
1413
+ logger?: S3DBLogger;
1414
+ };
1415
+ logger: S3DBLogger;
1416
+ private _signalHandlersSetup;
1417
+ private _isDestroyed;
1418
+ private _boundCleanupHandler?;
1419
+ constructor(options?: SafeEventEmitterOptions);
1420
+ private _setupSignalHandlers;
1421
+ private _handleCleanup;
1422
+ on(eventName: string | symbol, listener: (...args: unknown[]) => void): this;
1423
+ once(eventName: string | symbol, listener: (...args: unknown[]) => void): this;
1424
+ emit(eventName: string | symbol, ...args: unknown[]): boolean;
1425
+ private handleError;
1426
+ getListenerStats(): ListenerStats;
1427
+ getTotalListenerCount(): number;
1428
+ destroy(): void;
1429
+ isDestroyed(): boolean;
1430
+ removeSignalHandlers(): void;
1431
+ }
1432
+ declare function createSafeEventEmitter(options?: SafeEventEmitterOptions): SafeEventEmitter;
1433
+
1434
+ interface CronManagerOptions {
1435
+ logLevel?: LogLevel$1;
1436
+ shutdownTimeout?: number;
1437
+ exitOnSignal?: boolean;
1438
+ disabled?: boolean;
1439
+ logger?: S3DBLogger;
1440
+ }
1441
+ interface CronTask {
1442
+ start(): void;
1443
+ stop(): void;
1444
+ destroy?(): void;
1445
+ run?(...args: unknown[]): Promise<void>;
1446
+ }
1447
+ interface ScheduleOptions {
1448
+ scheduled?: boolean;
1449
+ timezone?: string;
1450
+ recoverMissedExecutions?: boolean;
1451
+ replace?: boolean;
1452
+ }
1453
+ interface JobStats {
1454
+ name: string;
1455
+ expression: string;
1456
+ createdAt: number;
1457
+ uptime: number;
1458
+ }
1459
+ interface CronStats {
1460
+ totalJobs: number;
1461
+ jobs: JobStats[];
1462
+ isDestroyed: boolean;
1463
+ }
1464
+ interface CronShutdownOptions {
1465
+ timeout?: number;
1466
+ signal?: string;
1467
+ error?: Error;
1468
+ }
1469
+ declare class CronManager {
1470
+ private options;
1471
+ private logger;
1472
+ private jobs;
1473
+ private _cron;
1474
+ private _destroyed;
1475
+ private _signalHandlersSetup;
1476
+ private _boundShutdownHandler?;
1477
+ private _boundErrorHandler?;
1478
+ disabled: boolean;
1479
+ constructor(options?: CronManagerOptions);
1480
+ private _setupSignalHandlers;
1481
+ removeSignalHandlers(): void;
1482
+ private _handleShutdown;
1483
+ private _handleError;
1484
+ private _loadCron;
1485
+ schedule(expression: string, fn: () => void | Promise<void>, name: string, options?: ScheduleOptions): Promise<CronTask | null>;
1486
+ scheduleInterval(ms: number, fn: () => void | Promise<void>, name: string, options?: ScheduleOptions): Promise<CronTask | null>;
1487
+ stop(name: string): boolean;
1488
+ getStats(): CronStats;
1489
+ isDestroyed(): boolean;
1490
+ shutdown(options?: CronShutdownOptions): Promise<void>;
1491
+ private _createStubTask;
1492
+ private _inferIntervalFromExpression;
1493
+ private _createTestCronStub;
1494
+ }
1495
+
1496
+ type StringRecord<T = unknown> = StringRecord$1<T>;
1497
+ interface ExecutorPoolConfig {
1498
+ enabled?: boolean;
1499
+ concurrency?: number;
1500
+ retries?: number;
1501
+ retryDelay?: number;
1502
+ timeout?: number;
1503
+ retryableErrors?: string[];
1504
+ autotune?: AutotuneConfig | null;
1505
+ monitoring?: MonitoringConfig;
1506
+ }
1507
+ interface AutotuneConfig {
1508
+ enabled?: boolean;
1509
+ targetLatency?: number;
1510
+ minConcurrency?: number;
1511
+ maxConcurrency?: number;
1512
+ }
1513
+ interface MonitoringConfig {
1514
+ collectMetrics?: boolean;
1515
+ [key: string]: unknown;
1516
+ }
1517
+ interface TaskExecutorMonitoringConfig {
1518
+ enabled?: boolean;
1519
+ metricsInterval?: number;
1520
+ }
1521
+ interface LoggerConfig {
1522
+ level?: LogLevel;
1523
+ pretty?: boolean;
1524
+ destination?: string;
1525
+ childLevels?: StringRecord<LogLevel>;
1526
+ }
1527
+ interface ClientOptions$1 {
1528
+ compression?: {
1529
+ enabled?: boolean;
1530
+ };
1531
+ retries?: number;
1532
+ timeout?: number;
1533
+ [key: string]: unknown;
1534
+ }
1535
+ interface CacheConfig {
1536
+ enabled?: boolean;
1537
+ ttl?: number;
1538
+ maxSize?: number;
1539
+ }
1540
+ interface SavedMetadata {
1541
+ version: string;
1542
+ s3dbVersion: string;
1543
+ lastUpdated: string;
1544
+ resources: StringRecord<ResourceMetadata>;
1545
+ }
1546
+ interface ResourceMetadata {
1547
+ currentVersion: string;
1548
+ partitions: PartitionsConfig;
1549
+ createdBy?: string;
1550
+ versions: StringRecord<VersionData>;
1551
+ /** Persistent attribute index mapping - prevents data corruption on schema changes */
1552
+ schemaRegistry?: SchemaRegistry;
1553
+ /** Persistent plugin attribute index mapping - per plugin namespace (supports both legacy numeric and new string-based formats) */
1554
+ pluginSchemaRegistry?: StringRecord<PluginSchemaRegistry | SchemaRegistry>;
1555
+ }
1556
+ interface VersionData {
1557
+ hash: string;
1558
+ attributes: AttributesSchema;
1559
+ behavior: BehaviorType;
1560
+ timestamps?: boolean;
1561
+ partitions?: PartitionsConfig;
1562
+ paranoid?: boolean;
1563
+ allNestedObjectsOptional?: boolean;
1564
+ autoDecrypt?: boolean;
1565
+ cache?: boolean;
1566
+ asyncEvents?: boolean;
1567
+ asyncPartitions?: boolean;
1568
+ hooks?: StringRecord<HookSummary>;
1569
+ idSize?: number;
1570
+ idGenerator?: string | number | Record<string, unknown>;
1571
+ createdAt?: string;
1572
+ map?: StringRecord<string>;
1573
+ }
1574
+ interface HookSummary {
1575
+ count: number;
1576
+ handlers: Array<{
1577
+ name: string | null;
1578
+ length: number | null;
1579
+ type: string;
1580
+ }>;
1581
+ }
1582
+ interface DefinitionChange {
1583
+ type: 'new' | 'changed' | 'deleted';
1584
+ resourceName: string;
1585
+ currentHash: string | null;
1586
+ savedHash: string | null;
1587
+ fromVersion?: string;
1588
+ toVersion?: string;
1589
+ deletedVersion?: string;
1590
+ }
1591
+ interface GlobalCoordinatorOptions {
1592
+ autoStart?: boolean;
1593
+ config?: GlobalCoordinatorConfig;
1594
+ }
1595
+ interface GlobalCoordinatorConfig {
1596
+ heartbeatInterval?: number;
1597
+ heartbeatJitter?: number;
1598
+ leaseTimeout?: number;
1599
+ workerTimeout?: number;
1600
+ diagnosticsEnabled?: boolean;
1601
+ circuitBreaker?: {
1602
+ failureThreshold?: number;
1603
+ resetTimeout?: number;
1604
+ };
1605
+ }
1606
+ interface GlobalCoordinatorService {
1607
+ start: () => Promise<void>;
1608
+ stop: () => Promise<void>;
1609
+ getLeader: () => Promise<string | null>;
1610
+ getCircuitBreakerStatus: () => {
1611
+ state: string;
1612
+ failures: number;
1613
+ };
1614
+ on: (event: string, handler: EventHandler) => void;
1615
+ }
1616
+ type HookEventName = 'beforeConnect' | 'afterConnect' | 'beforeCreateResource' | 'afterCreateResource' | 'beforeUploadMetadata' | 'afterUploadMetadata' | 'beforeDisconnect' | 'afterDisconnect' | 'resourceCreated' | 'resourceUpdated';
1617
+ type DatabaseHookFunction = (context: {
1618
+ database: DatabaseRef;
1619
+ [key: string]: unknown;
1620
+ }) => void | Promise<void>;
1621
+ interface DatabaseRef {
1622
+ id: string;
1623
+ version: string;
1624
+ s3dbVersion: string;
1625
+ client: Client;
1626
+ logger: Logger$1;
1627
+ savedMetadata: SavedMetadata | null;
1628
+ _resourcesMap: StringRecord<Resource>;
1629
+ resources: StringRecord<Resource>;
1630
+ passphrase: string;
1631
+ bcryptRounds: number;
1632
+ versioningEnabled: boolean;
1633
+ strictValidation: boolean;
1634
+ strictHooks: boolean;
1635
+ disableResourceEvents: boolean;
1636
+ deferMetadataWrites: boolean;
1637
+ metadataWriteDelay: number;
1638
+ cache: CacheConfig | boolean | undefined;
1639
+ processManager: ProcessManager;
1640
+ cronManager: CronManager;
1641
+ executorPool: ExecutorPoolConfig;
1642
+ pluginList: PluginConstructor[];
1643
+ pluginRegistry: StringRecord<Plugin>;
1644
+ plugins: StringRecord<Plugin>;
1645
+ bucket: string;
1646
+ keyPrefix: string;
1647
+ emit: (event: string, data?: unknown) => void | Promise<void>;
1648
+ isConnected: () => boolean;
1649
+ getChildLogger: (name: string, bindings?: Record<string, unknown>) => Logger$1;
1650
+ generateDefinitionHash: (definition: ResourceExport, behavior?: BehaviorType) => string;
1651
+ getNextVersion: (versions?: StringRecord<VersionData>) => string;
1652
+ blankMetadataStructure: () => SavedMetadata;
1653
+ }
1654
+ interface Plugin {
1655
+ name?: string;
1656
+ instanceName?: string;
1657
+ processManager?: ProcessManager;
1658
+ cronManager?: CronManager;
1659
+ logger?: Logger$1;
1660
+ setInstanceName?: (name: string) => void;
1661
+ install: (db: DatabaseRef) => Promise<void>;
1662
+ start: () => Promise<void>;
1663
+ stop?: () => Promise<void>;
1664
+ uninstall?: (options?: {
1665
+ purgeData?: boolean;
1666
+ }) => Promise<void>;
1667
+ removeAllListeners?: () => void;
1668
+ }
1669
+ type PluginConstructor = (new (db: DatabaseRef) => Plugin) | Plugin;
1670
+
1671
+ interface ResourceApiConfig {
1672
+ enabled?: boolean;
1673
+ path?: string;
1674
+ operations?: {
1675
+ list?: boolean;
1676
+ get?: boolean;
1677
+ insert?: boolean;
1678
+ update?: boolean;
1679
+ delete?: boolean;
1680
+ query?: boolean;
1681
+ };
1682
+ middleware?: MiddlewareFunction[];
1683
+ }
1684
+ interface CreateResourceConfig {
1685
+ name: string;
1686
+ attributes: AttributesSchema;
1687
+ behavior?: BehaviorType;
1688
+ hooks?: Partial<HooksCollection>;
1689
+ middlewares?: MiddlewareFunction[] | StringRecord$1<MiddlewareFunction | MiddlewareFunction[]>;
1690
+ timestamps?: boolean;
1691
+ partitions?: PartitionsConfig | string[];
1692
+ paranoid?: boolean;
1693
+ cache?: boolean;
1694
+ autoDecrypt?: boolean;
1695
+ asyncEvents?: boolean;
1696
+ asyncPartitions?: boolean;
1697
+ strictValidation?: boolean;
1698
+ passphrase?: string;
1699
+ bcryptRounds?: number;
1700
+ idGenerator?: ((size?: number) => string) | number | string;
1701
+ idSize?: number;
1702
+ map?: StringRecord$1<string>;
1703
+ events?: StringRecord$1<EventHandler | EventHandler[]>;
1704
+ disableEvents?: boolean;
1705
+ createdBy?: string;
1706
+ version?: string;
1707
+ allNestedObjectsOptional?: boolean;
1708
+ api?: ResourceApiConfig;
1709
+ description?: string;
1710
+ }
1711
+ interface HashExistsResult {
1712
+ exists: boolean;
1713
+ sameHash: boolean;
1714
+ hash: string | null;
1715
+ existingHash?: string;
1716
+ }
1717
+
1718
+ interface DatabaseOptions {
1719
+ connectionString?: string;
1720
+ bucket?: string;
1721
+ region?: string;
1722
+ accessKeyId?: string;
1723
+ secretAccessKey?: string;
1724
+ endpoint?: string;
1725
+ forcePathStyle?: boolean;
1726
+ client?: Client;
1727
+ clientOptions?: ClientOptions$1;
1728
+ plugins?: PluginConstructor[];
1729
+ cache?: CacheConfig | boolean;
1730
+ passphrase?: string;
1731
+ bcryptRounds?: number;
1732
+ versioningEnabled?: boolean;
1733
+ strictValidation?: boolean;
1734
+ strictHooks?: boolean;
1735
+ disableResourceEvents?: boolean;
1736
+ deferMetadataWrites?: boolean;
1737
+ metadataWriteDelay?: number;
1738
+ parallelism?: number | string;
1739
+ executorPool?: ExecutorPoolConfig | false;
1740
+ operationsPool?: ExecutorPoolConfig | false;
1741
+ taskExecutorMonitoring?: TaskExecutorMonitoringConfig;
1742
+ logLevel?: LogLevel;
1743
+ loggerOptions?: LoggerConfig;
1744
+ logger?: Logger$1;
1745
+ processManager?: ProcessManager;
1746
+ cronManager?: CronManager;
1747
+ exitOnSignal?: boolean;
1748
+ autoCleanup?: boolean;
1749
+ }
1750
+ declare class Database extends SafeEventEmitter {
1751
+ id: string;
1752
+ version: string;
1753
+ s3dbVersion: string;
1754
+ resources: StringRecord$1<Resource>;
1755
+ savedMetadata: SavedMetadata | null;
1756
+ databaseOptions: DatabaseOptions;
1757
+ executorPool: ExecutorPoolConfig;
1758
+ taskExecutor: ExecutorPoolConfig;
1759
+ pluginList: PluginConstructor[];
1760
+ pluginRegistry: StringRecord$1<Plugin>;
1761
+ plugins: StringRecord$1<Plugin>;
1762
+ cache: CacheConfig | boolean | undefined;
1763
+ passphrase: string;
1764
+ bcryptRounds: number;
1765
+ versioningEnabled: boolean;
1766
+ strictValidation: boolean;
1767
+ strictHooks: boolean;
1768
+ disableResourceEvents: boolean;
1769
+ deferMetadataWrites: boolean;
1770
+ metadataWriteDelay: number;
1771
+ processManager: ProcessManager;
1772
+ cronManager: CronManager;
1773
+ logLevel: string;
1774
+ logger: Logger$1;
1775
+ client: Client;
1776
+ connectionString: string | undefined;
1777
+ bucket: string;
1778
+ keyPrefix: string;
1779
+ _resourcesMap: StringRecord$1<Resource>;
1780
+ private _parallelism;
1781
+ private _childLoggerLevels;
1782
+ private _hooksModule;
1783
+ private _coordinatorsModule;
1784
+ private _recoveryModule;
1785
+ private _metadataModule;
1786
+ private _pluginsModule;
1787
+ private _resourcesModule;
1788
+ private _connectionModule;
1789
+ constructor(options: DatabaseOptions);
1790
+ private _initializeClient;
1791
+ get parallelism(): number;
1792
+ set parallelism(value: number | string);
1793
+ setConcurrency(value: number | string): void;
1794
+ get operationsPool(): ExecutorPoolConfig;
1795
+ get config(): {
1796
+ version: string;
1797
+ s3dbVersion: string;
1798
+ bucket: string;
1799
+ keyPrefix: string;
1800
+ taskExecutor: ExecutorPoolConfig;
1801
+ logLevel: string;
1802
+ };
1803
+ getChildLogger(name: string, bindings?: Record<string, unknown>): Logger$1;
1804
+ setChildLevel(name: string, level: LogLevel): void;
1805
+ connect(): Promise<void>;
1806
+ disconnect(): Promise<void>;
1807
+ isConnected(): boolean;
1808
+ startPlugins(): Promise<void>;
1809
+ usePlugin(plugin: Plugin, name?: string | null): Promise<Plugin>;
1810
+ uninstallPlugin(name: string, options?: {
1811
+ purgeData?: boolean;
1812
+ }): Promise<void>;
1813
+ getGlobalCoordinator(namespace: string, options?: GlobalCoordinatorOptions): Promise<GlobalCoordinatorService>;
1814
+ createResource(config: CreateResourceConfig): Promise<Resource>;
1815
+ listResources(): Promise<ResourceExport[]>;
1816
+ getResource(name: string): Promise<Resource>;
1817
+ resourceExists(name: string): boolean;
1818
+ resourceExistsWithSameHash(params: {
1819
+ name: string;
1820
+ attributes: AttributesSchema;
1821
+ behavior?: BehaviorType;
1822
+ partitions?: PartitionsConfig;
1823
+ }): HashExistsResult;
1824
+ uploadMetadataFile(): Promise<void>;
1825
+ flushMetadata(): Promise<void>;
1826
+ blankMetadataStructure(): SavedMetadata;
1827
+ detectDefinitionChanges(savedMetadata: SavedMetadata): DefinitionChange[];
1828
+ generateDefinitionHash(definition: ResourceExport, behavior?: BehaviorType): string;
1829
+ getNextVersion(versions?: StringRecord$1<VersionData>): string;
1830
+ addHook(event: HookEventName, fn: DatabaseHookFunction): void;
1831
+ removeHook(event: HookEventName, fn: DatabaseHookFunction): void;
1832
+ getHooks(event: HookEventName): DatabaseHookFunction[];
1833
+ clearHooks(event: HookEventName): void;
1834
+ private _deepMerge;
1835
+ private _applyTaskExecutorMonitoring;
1836
+ private _normalizeParallelism;
1837
+ private _normalizeOperationsPool;
1838
+ private _inferConnectionStringFromClient;
1839
+ }
1840
+ declare class S3db extends Database {
1841
+ }
1842
+
1843
+ type ClientType = 'filesystem' | 'memory' | 's3' | 'custom';
1844
+ interface ClientOptions {
1845
+ [key: string]: unknown;
1846
+ }
1847
+ declare class ConnectionString {
1848
+ region: string;
1849
+ bucket: string;
1850
+ accessKeyId: string | undefined;
1851
+ secretAccessKey: string | undefined;
1852
+ endpoint: string;
1853
+ keyPrefix: string;
1854
+ forcePathStyle?: boolean;
1855
+ clientType?: ClientType;
1856
+ basePath?: string;
1857
+ clientOptions: ClientOptions;
1858
+ constructor(connectionString: string);
1859
+ private _parseQueryParams;
1860
+ private _coerceValue;
1861
+ private defineFromS3;
1862
+ private defineFromCustomUri;
1863
+ private defineFromFileUri;
1864
+ private defineFromMemoryUri;
1865
+ }
1866
+
1867
+ interface AwsCommand {
1868
+ constructor: {
1869
+ name: string;
1870
+ };
1871
+ input?: any;
1872
+ }
1873
+ declare class S3Client extends EventEmitter {
1874
+ id: string;
1875
+ logLevel: string;
1876
+ private logger;
1877
+ config: ConnectionString;
1878
+ connectionString: string;
1879
+ httpClientOptions: HttpClientOptions;
1880
+ client: S3Client$4;
1881
+ private _inflightCoalescing;
1882
+ private taskExecutorConfig;
1883
+ private taskExecutor;
1884
+ constructor({ logLevel, logger, id, AwsS3Client: providedClient, connectionString, httpClientOptions, taskExecutor, executorPool, }: S3ClientConfig);
1885
+ private _coalesce;
1886
+ private _normalizeTaskExecutorConfig;
1887
+ private _createTasksPool;
1888
+ private _executeOperation;
1889
+ private _executeBatch;
1890
+ getQueueStats(): QueueStats | null;
1891
+ getAggregateMetrics(since?: number): unknown | null;
1892
+ pausePool(): Promise<void | null>;
1893
+ resumePool(): void | null;
1894
+ drainPool(): Promise<void | null>;
1895
+ stopPool(): void;
1896
+ destroy(): void;
1897
+ createClient(): S3Client$4;
1898
+ sendCommand(command: AwsCommand): Promise<unknown>;
1899
+ putObject(params: PutObjectParams): Promise<unknown>;
1900
+ getObject(key: string): Promise<unknown>;
1901
+ headObject(key: string): Promise<unknown>;
1902
+ copyObject(params: CopyObjectParams): Promise<unknown>;
1903
+ exists(key: string): Promise<boolean>;
1904
+ deleteObject(key: string): Promise<unknown>;
1905
+ deleteObjects(keys: string[]): Promise<{
1906
+ deleted: unknown[];
1907
+ notFound: Array<{
1908
+ message: string;
1909
+ raw: Error;
1910
+ }>;
1911
+ }>;
1912
+ deleteAll({ prefix }?: {
1913
+ prefix?: string;
1914
+ }): Promise<number>;
1915
+ moveObject({ from, to }: {
1916
+ from: string;
1917
+ to: string;
1918
+ }): Promise<boolean>;
1919
+ listObjects(params?: ListObjectsParams): Promise<unknown>;
1920
+ count({ prefix }?: {
1921
+ prefix?: string;
1922
+ }): Promise<number>;
1923
+ getAllKeys({ prefix }?: {
1924
+ prefix?: string;
1925
+ }): Promise<string[]>;
1926
+ getContinuationTokenAfterOffset(params?: {
1927
+ prefix?: string;
1928
+ offset?: number;
1929
+ }): Promise<string | null>;
1930
+ getKeysPage(params?: GetKeysPageParams): Promise<string[]>;
1931
+ moveAllObjects({ prefixFrom, prefixTo }: {
1932
+ prefixFrom: string;
1933
+ prefixTo: string;
1934
+ }): Promise<string[]>;
1935
+ }
1936
+
1937
+ declare class MemoryStorage {
1938
+ private objects;
1939
+ private bucket;
1940
+ private enforceLimits;
1941
+ private metadataLimit;
1942
+ private maxObjectSize;
1943
+ private persistPath?;
1944
+ private autoPersist;
1945
+ private logLevel;
1946
+ private maxMemoryMB;
1947
+ private maxMemoryBytes;
1948
+ private currentMemoryBytes;
1949
+ private evictionEnabled;
1950
+ private _stats;
1951
+ private logger;
1952
+ constructor(config?: MemoryStorageConfig);
1953
+ private _generateETag;
1954
+ private _toBuffer;
1955
+ private _formatEtag;
1956
+ private _normalizeEtagHeader;
1957
+ private _encodeContinuationToken;
1958
+ private _decodeContinuationToken;
1959
+ private _extractCommonPrefix;
1960
+ private _calculateMetadataSize;
1961
+ private _validateLimits;
1962
+ put(key: string, params: StoragePutParams): Promise<PutObjectResponse>;
1963
+ get(key: string): Promise<S3Object>;
1964
+ head(key: string): Promise<Omit<S3Object, 'Body'>>;
1965
+ copy(from: string, to: string, params: StorageCopyParams): Promise<CopyObjectResponse>;
1966
+ exists(key: string): boolean;
1967
+ delete(key: string): Promise<DeleteObjectResponse>;
1968
+ deleteMultiple(keys: string[]): Promise<DeleteObjectsResponse>;
1969
+ list(params: StorageListParams): Promise<ListObjectsResponse>;
1970
+ snapshot(): StorageSnapshot;
1971
+ restore(snapshot: StorageSnapshot): void;
1972
+ saveToDisk(customPath?: string): Promise<string>;
1973
+ loadFromDisk(customPath?: string): Promise<StorageSnapshot>;
1974
+ getStats(): MemoryStorageStats;
1975
+ getKeys(): string[];
1976
+ private _formatBytes;
1977
+ private _trackMemory;
1978
+ private _touchKey;
1979
+ private _evictIfNeeded;
1980
+ clear(): void;
1981
+ resetStats(): void;
1982
+ }
1983
+
1984
+ interface CommandInput$1 {
1985
+ Key?: string;
1986
+ Prefix?: string;
1987
+ Metadata?: Record<string, unknown>;
1988
+ ContentType?: string;
1989
+ Body?: unknown;
1990
+ ContentEncoding?: string;
1991
+ ContentLength?: number;
1992
+ IfMatch?: string;
1993
+ IfNoneMatch?: string;
1994
+ CopySource?: string;
1995
+ MetadataDirective?: 'COPY' | 'REPLACE';
1996
+ Delimiter?: string | null;
1997
+ MaxKeys?: number;
1998
+ ContinuationToken?: string | null;
1999
+ StartAfter?: string | null;
2000
+ Delete?: {
2001
+ Objects?: Array<{
2002
+ Key: string;
2003
+ }>;
2004
+ };
2005
+ }
2006
+ interface Command$1 {
2007
+ constructor: {
2008
+ name: string;
2009
+ };
2010
+ input?: CommandInput$1;
2011
+ }
2012
+ declare class MemoryClient extends EventEmitter {
2013
+ id: string;
2014
+ logLevel: string;
2015
+ private logger;
2016
+ private taskExecutorMonitoring;
2017
+ private taskManager;
2018
+ storage: MemoryStorage;
2019
+ bucket: string;
2020
+ private keyPrefix;
2021
+ private region;
2022
+ private _keyPrefixForStrip;
2023
+ connectionString: string;
2024
+ config: ClientConfig;
2025
+ constructor(config?: MemoryClientConfig);
2026
+ getQueueStats(): QueueStats | null;
2027
+ getAggregateMetrics(since?: number): unknown | null;
2028
+ sendCommand(command: Command$1): Promise<unknown>;
2029
+ private _handlePutObject;
2030
+ private _handleGetObject;
2031
+ private _handleHeadObject;
2032
+ private _handleCopyObject;
2033
+ private _handleDeleteObject;
2034
+ private _handleDeleteObjects;
2035
+ private _handleListObjects;
2036
+ putObject(params: PutObjectParams): Promise<PutObjectResponse>;
2037
+ getObject(key: string): Promise<S3Object>;
2038
+ headObject(key: string): Promise<S3Object>;
2039
+ copyObject(params: CopyObjectParams): Promise<CopyObjectResponse>;
2040
+ exists(key: string): Promise<boolean>;
2041
+ deleteObject(key: string): Promise<DeleteObjectResponse>;
2042
+ deleteObjects(keys: string[]): Promise<DeleteObjectsResponse>;
2043
+ listObjects(params?: ListObjectsParams): Promise<ListObjectsResponse>;
2044
+ getKeysPage(params?: GetKeysPageParams): Promise<string[]>;
2045
+ getAllKeys(params?: {
2046
+ prefix?: string;
2047
+ }): Promise<string[]>;
2048
+ count(params?: {
2049
+ prefix?: string;
2050
+ }): Promise<number>;
2051
+ deleteAll(params?: {
2052
+ prefix?: string;
2053
+ }): Promise<number>;
2054
+ getContinuationTokenAfterOffset(params?: {
2055
+ prefix?: string;
2056
+ offset?: number;
2057
+ }): Promise<string | null>;
2058
+ moveObject(params: {
2059
+ from: string;
2060
+ to: string;
2061
+ }): Promise<boolean>;
2062
+ moveAllObjects(params: {
2063
+ prefixFrom: string;
2064
+ prefixTo: string;
2065
+ }): Promise<Array<{
2066
+ from: string;
2067
+ to: string;
2068
+ }>>;
2069
+ snapshot(): StorageSnapshot;
2070
+ restore(snapshot: StorageSnapshot): void;
2071
+ clear(): Promise<void>;
2072
+ getStats(): ReturnType<MemoryStorage['getStats']>;
2073
+ destroy(): void;
2074
+ private _encodeMetadata;
2075
+ private _decodeMetadataResponse;
2076
+ private _applyKeyPrefix;
2077
+ private _stripKeyPrefix;
2078
+ private _encodeContinuationTokenKey;
2079
+ private _parseCopySource;
2080
+ private _normalizeListResponse;
2081
+ static clearBucketStorage(bucket: string): void;
2082
+ static clearAllStorage(): void;
2083
+ }
2084
+
2085
+ declare class FileSystemStorage {
2086
+ private basePath;
2087
+ private bucket;
2088
+ private enforceLimits;
2089
+ private metadataLimit;
2090
+ private maxObjectSize;
2091
+ private logLevel;
2092
+ private enableCompression;
2093
+ private compressionThreshold;
2094
+ private compressionLevel;
2095
+ private enableTTL;
2096
+ private defaultTTL;
2097
+ private cleanupInterval;
2098
+ private enableLocking;
2099
+ private lockTimeout;
2100
+ private enableBackup;
2101
+ private backupSuffix;
2102
+ private enableJournal;
2103
+ private journalFile;
2104
+ private enableStats;
2105
+ private isWindows;
2106
+ private locks;
2107
+ private stats;
2108
+ private logger;
2109
+ private cronManager;
2110
+ private cleanupJobName;
2111
+ constructor(config?: FileSystemStorageConfig);
2112
+ private _keyToPath;
2113
+ private _pathToKey;
2114
+ private _getObjectPath;
2115
+ private _getMetadataPath;
2116
+ private _ensureDirectory;
2117
+ private _generateETag;
2118
+ private _toBuffer;
2119
+ private _formatEtag;
2120
+ private _normalizeEtagHeader;
2121
+ private _encodeContinuationToken;
2122
+ private _decodeContinuationToken;
2123
+ private _extractCommonPrefix;
2124
+ private _calculateMetadataSize;
2125
+ private _validateLimits;
2126
+ private _writeAtomic;
2127
+ private _readMetadata;
2128
+ private _writeMetadata;
2129
+ private _initCleanup;
2130
+ private _runCleanup;
2131
+ private _acquireLock;
2132
+ private _releaseLock;
2133
+ private _journalOperation;
2134
+ private _createBackup;
2135
+ private _compressBody;
2136
+ private _decompressBody;
2137
+ getStats(): FileSystemStorageStats | null;
2138
+ private _mapFilesystemError;
2139
+ put(key: string, params: StoragePutParams & {
2140
+ ttl?: number;
2141
+ }): Promise<PutObjectResponse>;
2142
+ get(key: string): Promise<S3Object>;
2143
+ head(key: string): Promise<Omit<S3Object, 'Body'>>;
2144
+ copy(from: string, to: string, params: StorageCopyParams): Promise<CopyObjectResponse>;
2145
+ delete(key: string): Promise<DeleteObjectResponse>;
2146
+ deleteMultiple(keys: string[]): Promise<DeleteObjectsResponse>;
2147
+ private _walkDirectory;
2148
+ list(params: StorageListParams): Promise<ListObjectsResponse>;
2149
+ exists(key: string): boolean;
2150
+ clear(): Promise<void>;
2151
+ destroy(): void;
2152
+ }
2153
+
2154
+ interface CommandInput {
2155
+ Key?: string;
2156
+ Prefix?: string;
2157
+ Metadata?: Record<string, unknown>;
2158
+ ContentType?: string;
2159
+ Body?: unknown;
2160
+ ContentEncoding?: string;
2161
+ ContentLength?: number;
2162
+ IfMatch?: string;
2163
+ IfNoneMatch?: string;
2164
+ CopySource?: string;
2165
+ MetadataDirective?: 'COPY' | 'REPLACE';
2166
+ Delimiter?: string | null;
2167
+ MaxKeys?: number;
2168
+ ContinuationToken?: string | null;
2169
+ StartAfter?: string | null;
2170
+ Delete?: {
2171
+ Objects?: Array<{
2172
+ Key: string;
2173
+ }>;
2174
+ };
2175
+ }
2176
+ interface Command {
2177
+ constructor: {
2178
+ name: string;
2179
+ };
2180
+ input?: CommandInput;
2181
+ }
2182
+ declare class FileSystemClient extends EventEmitter {
2183
+ id: string;
2184
+ logLevel: string;
2185
+ private logger;
2186
+ private taskExecutorMonitoring;
2187
+ private taskManager;
2188
+ storage: FileSystemStorage;
2189
+ private basePath;
2190
+ bucket: string;
2191
+ private keyPrefix;
2192
+ private region;
2193
+ private _keyPrefixForStrip;
2194
+ connectionString: string;
2195
+ config: ClientConfig;
2196
+ constructor(config?: FileSystemClientConfig);
2197
+ getQueueStats(): QueueStats | null;
2198
+ getAggregateMetrics(since?: number): unknown | null;
2199
+ sendCommand(command: Command): Promise<unknown>;
2200
+ private _handlePutObject;
2201
+ private _handleGetObject;
2202
+ private _handleHeadObject;
2203
+ private _handleCopyObject;
2204
+ private _handleDeleteObject;
2205
+ private _handleDeleteObjects;
2206
+ private _handleListObjects;
2207
+ putObject(params: PutObjectParams): Promise<PutObjectResponse>;
2208
+ getObject(key: string): Promise<S3Object>;
2209
+ headObject(key: string): Promise<S3Object>;
2210
+ copyObject(params: CopyObjectParams): Promise<CopyObjectResponse>;
2211
+ exists(key: string): Promise<boolean>;
2212
+ deleteObject(key: string): Promise<DeleteObjectResponse>;
2213
+ deleteObjects(keys: string[]): Promise<DeleteObjectsResponse>;
2214
+ listObjects(params?: ListObjectsParams): Promise<ListObjectsResponse>;
2215
+ getKeysPage(params?: GetKeysPageParams): Promise<string[]>;
2216
+ getAllKeys(params?: {
2217
+ prefix?: string;
2218
+ }): Promise<string[]>;
2219
+ count(params?: {
2220
+ prefix?: string;
2221
+ }): Promise<number>;
2222
+ deleteAll(params?: {
2223
+ prefix?: string;
2224
+ }): Promise<number>;
2225
+ getContinuationTokenAfterOffset(params?: {
2226
+ prefix?: string;
2227
+ offset?: number;
2228
+ }): Promise<string | null>;
2229
+ moveObject(params: {
2230
+ from: string;
2231
+ to: string;
2232
+ }): Promise<boolean>;
2233
+ moveAllObjects(params: {
2234
+ prefixFrom: string;
2235
+ prefixTo: string;
2236
+ }): Promise<Array<{
2237
+ from: string;
2238
+ to: string;
2239
+ }>>;
2240
+ clear(): Promise<void>;
2241
+ private _encodeMetadata;
2242
+ private _decodeMetadataResponse;
2243
+ private _applyKeyPrefix;
2244
+ private _stripKeyPrefix;
2245
+ private _encodeContinuationTokenKey;
2246
+ private _parseCopySource;
2247
+ private _normalizeListResponse;
2248
+ getStats(): FileSystemStorageStats | null;
2249
+ destroy(): void;
2250
+ static clearPathStorage(basePath: string): void;
2251
+ static clearAllStorage(): void;
2252
+ }
2253
+
2254
+ /**
2255
+ * S3DB Error Classes
2256
+ *
2257
+ * Typed error hierarchy for s3db.js operations.
2258
+ */
2259
+
2260
+ /** Base error context for all S3DB errors */
2261
+ interface BaseErrorContext {
2262
+ verbose?: boolean;
2263
+ bucket?: string;
2264
+ key?: string;
2265
+ message?: string;
2266
+ code?: string;
2267
+ statusCode?: number;
2268
+ requestId?: string;
2269
+ awsMessage?: string;
2270
+ original?: Error | unknown;
2271
+ commandName?: string;
2272
+ commandInput?: unknown;
2273
+ metadata?: StringRecord$1;
2274
+ description?: string;
2275
+ suggestion?: string;
2276
+ retriable?: boolean;
2277
+ docs?: string;
2278
+ title?: string;
2279
+ hint?: string;
2280
+ [key: string]: unknown;
2281
+ }
2282
+ /** Serialized error format */
2283
+ interface SerializedError {
2284
+ name: string;
2285
+ message: string;
2286
+ code?: string;
2287
+ statusCode?: number;
2288
+ requestId?: string;
2289
+ awsMessage?: string;
2290
+ bucket?: string;
2291
+ key?: string;
2292
+ thrownAt?: Date;
2293
+ retriable?: boolean;
2294
+ suggestion?: string;
2295
+ docs?: string;
2296
+ title?: string;
2297
+ hint?: string;
2298
+ commandName?: string;
2299
+ commandInput?: unknown;
2300
+ metadata?: StringRecord$1;
2301
+ description?: string;
2302
+ data?: StringRecord$1;
2303
+ original?: unknown;
2304
+ stack?: string;
2305
+ }
2306
+ declare class BaseError extends Error {
2307
+ bucket?: string;
2308
+ key?: string;
2309
+ thrownAt: Date;
2310
+ code?: string;
2311
+ statusCode: number;
2312
+ requestId?: string;
2313
+ awsMessage?: string;
2314
+ original?: Error | unknown;
2315
+ commandName?: string;
2316
+ commandInput?: unknown;
2317
+ metadata?: StringRecord$1;
2318
+ description?: string;
2319
+ suggestion?: string;
2320
+ retriable: boolean;
2321
+ docs?: string;
2322
+ title: string;
2323
+ hint?: string;
2324
+ data: StringRecord$1;
2325
+ constructor(context: BaseErrorContext);
2326
+ toJSON(): SerializedError;
2327
+ toString(): string;
2328
+ }
2329
+ /** AWS Error with $metadata */
2330
+ interface AwsErrorLike {
2331
+ code?: string;
2332
+ Code?: string;
2333
+ name?: string;
2334
+ message?: string;
2335
+ statusCode?: number;
2336
+ requestId?: string;
2337
+ stack?: string;
2338
+ $metadata?: {
2339
+ httpStatusCode?: number;
2340
+ requestId?: string;
2341
+ [key: string]: unknown;
2342
+ };
2343
+ }
2344
+ /** S3DB Error details */
2345
+ interface S3dbErrorDetails {
2346
+ bucket?: string;
2347
+ key?: string;
2348
+ original?: AwsErrorLike | Error | unknown;
2349
+ statusCode?: number;
2350
+ retriable?: boolean;
2351
+ suggestion?: string;
2352
+ description?: string;
2353
+ [key: string]: unknown;
2354
+ }
2355
+ declare class S3dbError extends BaseError {
2356
+ constructor(message: string, details?: S3dbErrorDetails);
2357
+ }
2358
+ declare class DatabaseError extends S3dbError {
2359
+ constructor(message: string, details?: S3dbErrorDetails);
2360
+ }
2361
+ declare class ValidationError extends S3dbError {
2362
+ field?: string;
2363
+ value?: unknown;
2364
+ constraint?: string;
2365
+ constructor(message: string, details?: S3dbErrorDetails & {
2366
+ field?: string;
2367
+ value?: unknown;
2368
+ constraint?: string;
2369
+ });
2370
+ }
2371
+ declare class AuthenticationError extends S3dbError {
2372
+ constructor(message: string, details?: S3dbErrorDetails);
2373
+ }
2374
+ declare class PermissionError extends S3dbError {
2375
+ constructor(message: string, details?: S3dbErrorDetails);
2376
+ }
2377
+ declare class EncryptionError extends S3dbError {
2378
+ constructor(message: string, details?: S3dbErrorDetails);
2379
+ }
2380
+ interface ResourceNotFoundDetails extends S3dbErrorDetails {
2381
+ bucket: string;
2382
+ resourceName: string;
2383
+ id: string;
2384
+ }
2385
+ declare class ResourceNotFound extends S3dbError {
2386
+ resourceName: string;
2387
+ id: string;
2388
+ constructor(details: ResourceNotFoundDetails);
2389
+ }
2390
+ interface NoSuchBucketDetails extends S3dbErrorDetails {
2391
+ bucket: string;
2392
+ }
2393
+ declare class NoSuchBucket extends S3dbError {
2394
+ constructor(details: NoSuchBucketDetails);
2395
+ }
2396
+ interface NoSuchKeyDetails extends S3dbErrorDetails {
2397
+ bucket: string;
2398
+ key: string;
2399
+ resourceName?: string;
2400
+ id?: string;
2401
+ }
2402
+ declare class NoSuchKey extends S3dbError {
2403
+ resourceName?: string;
2404
+ id?: string;
2405
+ constructor(details: NoSuchKeyDetails);
2406
+ }
2407
+ declare class NotFound extends S3dbError {
2408
+ resourceName?: string;
2409
+ id?: string;
2410
+ constructor(details: NoSuchKeyDetails);
2411
+ }
2412
+ declare class MissingMetadata extends S3dbError {
2413
+ constructor(details: NoSuchBucketDetails);
2414
+ }
2415
+ interface InvalidResourceItemDetails extends S3dbErrorDetails {
2416
+ bucket: string;
2417
+ resourceName: string;
2418
+ attributes?: unknown;
2419
+ validation?: unknown;
2420
+ message?: string;
2421
+ }
2422
+ declare class InvalidResourceItem extends S3dbError {
2423
+ constructor(details: InvalidResourceItemDetails);
2424
+ }
2425
+ declare class UnknownError extends S3dbError {
2426
+ }
2427
+ declare const ErrorMap: {
2428
+ readonly NotFound: typeof NotFound;
2429
+ readonly NoSuchKey: typeof NoSuchKey;
2430
+ readonly UnknownError: typeof UnknownError;
2431
+ readonly NoSuchBucket: typeof NoSuchBucket;
2432
+ readonly MissingMetadata: typeof MissingMetadata;
2433
+ readonly InvalidResourceItem: typeof InvalidResourceItem;
2434
+ };
2435
+ interface MapAwsErrorContext {
2436
+ bucket?: string;
2437
+ key?: string;
2438
+ resourceName?: string;
2439
+ id?: string;
2440
+ operation?: string;
2441
+ commandName?: string;
2442
+ commandInput?: unknown;
2443
+ retriable?: boolean;
2444
+ }
2445
+ declare function mapAwsError(err: AwsErrorLike | Error, context?: MapAwsErrorContext): S3dbError;
2446
+ declare class ConnectionStringError extends S3dbError {
2447
+ constructor(message: string, details?: S3dbErrorDetails);
2448
+ }
2449
+ declare class CryptoError extends S3dbError {
2450
+ constructor(message: string, details?: S3dbErrorDetails);
2451
+ }
2452
+ declare class SchemaError extends S3dbError {
2453
+ constructor(message: string, details?: S3dbErrorDetails);
2454
+ }
2455
+ declare class ResourceError extends S3dbError {
2456
+ constructor(message: string, details?: S3dbErrorDetails);
2457
+ }
2458
+ interface PartitionErrorDetails extends S3dbErrorDetails {
2459
+ resourceName?: string;
2460
+ partitionName?: string;
2461
+ fieldName?: string;
2462
+ availableFields?: string[];
2463
+ strictValidation?: boolean;
2464
+ }
2465
+ declare class PartitionError extends S3dbError {
2466
+ constructor(message: string, details?: PartitionErrorDetails);
2467
+ }
2468
+ interface PluginErrorDetails extends S3dbErrorDetails {
2469
+ pluginName?: string;
2470
+ operation?: string;
2471
+ }
2472
+ declare class PluginError extends S3dbError {
2473
+ pluginName: string;
2474
+ operation: string;
2475
+ constructor(message: string, details?: PluginErrorDetails);
2476
+ }
2477
+ interface PluginStorageErrorDetails extends S3dbErrorDetails {
2478
+ pluginSlug?: string;
2479
+ key?: string;
2480
+ operation?: string;
2481
+ }
2482
+ declare class PluginStorageError extends S3dbError {
2483
+ constructor(message: string, details?: PluginStorageErrorDetails);
2484
+ }
2485
+ interface PartitionDriverErrorDetails extends S3dbErrorDetails {
2486
+ driver?: string;
2487
+ operation?: string;
2488
+ queueSize?: number;
2489
+ maxQueueSize?: number;
2490
+ }
2491
+ declare class PartitionDriverError extends S3dbError {
2492
+ constructor(message: string, details?: PartitionDriverErrorDetails);
2493
+ }
2494
+ interface BehaviorErrorDetails extends S3dbErrorDetails {
2495
+ behavior?: string;
2496
+ availableBehaviors?: string[];
2497
+ }
2498
+ declare class BehaviorError extends S3dbError {
2499
+ constructor(message: string, details?: BehaviorErrorDetails);
2500
+ }
2501
+ interface StreamErrorDetails extends S3dbErrorDetails {
2502
+ operation?: string;
2503
+ resource?: string;
2504
+ }
2505
+ declare class StreamError extends S3dbError {
2506
+ constructor(message: string, details?: StreamErrorDetails);
2507
+ }
2508
+ interface MetadataLimitErrorDetails extends S3dbErrorDetails {
2509
+ totalSize?: number;
2510
+ effectiveLimit?: number;
2511
+ absoluteLimit?: number;
2512
+ excess?: number;
2513
+ resourceName?: string;
2514
+ operation?: string;
2515
+ }
2516
+ declare class MetadataLimitError extends S3dbError {
2517
+ constructor(message: string, details?: MetadataLimitErrorDetails);
2518
+ }
2519
+ interface AnalyticsNotEnabledErrorDetails extends S3dbErrorDetails {
2520
+ pluginName?: string;
2521
+ resourceName?: string;
2522
+ field?: string;
2523
+ configuredResources?: string[];
2524
+ registeredResources?: string[];
2525
+ pluginInitialized?: boolean;
2526
+ }
2527
+ declare class AnalyticsNotEnabledError extends S3dbError {
2528
+ constructor(details?: AnalyticsNotEnabledErrorDetails);
2529
+ }
2530
+
2531
+ /** Result tuple type for tryFn */
2532
+ type TryResult<T> = [ok: true, err: null, data: T] | [ok: false, err: Error, data: undefined];
2533
+ /**
2534
+ * tryFn - A robust error handling utility for JavaScript functions and values.
2535
+ *
2536
+ * This utility provides a consistent way to handle errors and return values across different types:
2537
+ * - Synchronous functions
2538
+ * - Asynchronous functions (Promises)
2539
+ * - Direct values
2540
+ * - Promises
2541
+ * - null/undefined values
2542
+ */
2543
+ declare function tryFn<T>(fnOrPromise: null | undefined): TryResult<T>;
2544
+ declare function tryFn<T>(fnOrPromise: () => Promise<T>): Promise<TryResult<Awaited<T>>>;
2545
+ declare function tryFn<T>(fnOrPromise: Promise<T>): Promise<TryResult<Awaited<T>>>;
2546
+ declare function tryFn<T>(fnOrPromise: () => T): TryResult<T>;
2547
+ declare function tryFn<T>(fnOrPromise: T): TryResult<T>;
2548
+ /**
2549
+ * Synchronous version of tryFn for cases where you know the function is synchronous
2550
+ */
2551
+ declare function tryFnSync<T>(fn: () => T): TryResult<T>;
2552
+
2553
+ declare function encrypt(content: string, passphrase: string): Promise<string>;
2554
+ declare function decrypt(encryptedBase64: string, passphrase: string): Promise<string>;
2555
+
2556
+ declare function initializeNanoid(): Promise<void>;
2557
+ declare const idGenerator: (size?: number) => string;
2558
+ declare const passwordGenerator: (size?: number) => string;
2559
+ declare const createCustomGenerator: (alphabet: string, size: number) => ((size?: number) => string);
2560
+
2561
+ declare const encode: (n: number) => string;
2562
+ declare const decode: (s: string) => number;
2563
+ declare const encodeDecimal: (n: number) => string;
2564
+ declare const decodeDecimal: (s: string) => number;
2565
+
2566
+ /**
2567
+ * Encode Buffer to Base64 string
2568
+ */
2569
+ declare function encodeBuffer(buffer: Buffer | Uint8Array | null | undefined): string | null;
2570
+ /**
2571
+ * Decode Base64 string back to Buffer
2572
+ */
2573
+ declare function decodeBuffer(encoded: string | null | undefined): Buffer | null;
2574
+ /**
2575
+ * Encode a bitmap (Buffer) with optional size validation
2576
+ */
2577
+ declare function encodeBits(buffer: Buffer | Uint8Array | null | undefined, expectedBits?: number | null, skipValidation?: boolean): string | null;
2578
+ /**
2579
+ * Decode Base64 string back to bitmap Buffer
2580
+ */
2581
+ declare function decodeBits(encoded: string | null | undefined, expectedBits?: number | null, skipValidation?: boolean): Buffer | null;
2582
+
2583
+ interface MapWithConcurrencyOptions<T> {
2584
+ concurrency?: number;
2585
+ onError?: ((error: Error, item: T) => void | Promise<void>) | null;
2586
+ }
2587
+ interface MapWithConcurrencyError<T> {
2588
+ item: T;
2589
+ index: number;
2590
+ message: string;
2591
+ raw: Error;
2592
+ }
2593
+ interface MapWithConcurrencyResult<T, R> {
2594
+ results: R[];
2595
+ errors: MapWithConcurrencyError<T>[];
2596
+ }
2597
+ declare function mapWithConcurrency<T, R>(items: T[], fn: (item: T, index: number) => Promise<R>, options?: MapWithConcurrencyOptions<T>): Promise<MapWithConcurrencyResult<T, R>>;
2598
+
2599
+ declare const behaviors: Record<BehaviorName, Behavior>;
2600
+ declare function getBehavior(behaviorName: string): Behavior;
2601
+ declare const AVAILABLE_BEHAVIORS: BehaviorName[];
2602
+ declare const DEFAULT_BEHAVIOR: BehaviorName;
2603
+
2604
+ type TaskFunction$1<T> = () => Promise<T>;
2605
+ interface EnqueueOptions$2 {
2606
+ priority?: number;
2607
+ retries?: number;
2608
+ timeout?: number;
2609
+ metadata?: Record<string, unknown>;
2610
+ }
2611
+ interface ProcessOptions$1<T = unknown> {
2612
+ onSuccess?: (item: T, result: unknown) => void;
2613
+ onError?: (item: T, error: Error) => void;
2614
+ priority?: number;
2615
+ retries?: number;
2616
+ timeout?: number;
2617
+ totalCount?: number;
2618
+ [key: string]: unknown;
2619
+ }
2620
+ interface ProcessResult$1<T> {
2621
+ results: T[];
2622
+ errors: (Error | {
2623
+ item?: unknown;
2624
+ error?: Error;
2625
+ index?: number;
2626
+ })[];
2627
+ }
2628
+ declare abstract class TaskExecutor {
2629
+ abstract setConcurrency(concurrency: number): void;
2630
+ abstract getConcurrency(): number | 'auto';
2631
+ abstract enqueue<T>(fn: TaskFunction$1<T>, options?: EnqueueOptions$2): Promise<T>;
2632
+ abstract process<T, R>(items: T[], processor: (item: T, index?: number, executor?: unknown) => Promise<R>, options?: ProcessOptions$1<T>): Promise<ProcessResult$1<R>>;
2633
+ abstract pause(): void;
2634
+ abstract resume(): void;
2635
+ abstract stop(): void;
2636
+ abstract destroy(): Promise<void>;
2637
+ abstract getStats(): Record<string, unknown>;
2638
+ }
2639
+
2640
+ interface AdaptiveTuningOptions {
2641
+ minConcurrency?: number;
2642
+ maxConcurrency?: number;
2643
+ targetLatency?: number;
2644
+ targetMemoryPercent?: number;
2645
+ adjustmentInterval?: number;
2646
+ }
2647
+ interface TaskMetrics {
2648
+ latency: number;
2649
+ queueWait: number;
2650
+ success: boolean;
2651
+ retries: number;
2652
+ heapDelta: number;
2653
+ }
2654
+ interface ConcurrencyAdjustment {
2655
+ timestamp: number;
2656
+ old: number;
2657
+ new: number;
2658
+ reason: string;
2659
+ metrics: {
2660
+ avgLatency: number;
2661
+ avgMemory: number;
2662
+ avgThroughput: number;
2663
+ };
2664
+ }
2665
+ interface AdaptiveMetrics {
2666
+ latencies: number[];
2667
+ throughputs: number[];
2668
+ memoryUsages: number[];
2669
+ errorRates: number[];
2670
+ concurrencyHistory: ConcurrencyAdjustment[];
2671
+ }
2672
+ interface MetricsSummary {
2673
+ current: number;
2674
+ avgLatency: number;
2675
+ avgMemory: number;
2676
+ avgThroughput: number;
2677
+ history: ConcurrencyAdjustment[];
2678
+ }
2679
+ declare class AdaptiveTuning {
2680
+ minConcurrency: number;
2681
+ maxConcurrency: number;
2682
+ targetLatency: number;
2683
+ targetMemoryPercent: number;
2684
+ adjustmentInterval: number;
2685
+ metrics: AdaptiveMetrics;
2686
+ currentConcurrency: number;
2687
+ lastAdjustment: number;
2688
+ intervalId: ReturnType<typeof setInterval> | null;
2689
+ constructor(options?: AdaptiveTuningOptions);
2690
+ suggestInitial(): number;
2691
+ recordTaskMetrics(task: TaskMetrics): void;
2692
+ startMonitoring(): void;
2693
+ adjust(): number | null;
2694
+ getConcurrency(): number;
2695
+ getMetrics(): MetricsSummary;
2696
+ stop(): void;
2697
+ private _avg;
2698
+ }
2699
+
2700
+ interface SignatureStatsOptions {
2701
+ alpha?: number;
2702
+ maxEntries?: number;
2703
+ }
2704
+ interface SignatureEntry {
2705
+ signature: string;
2706
+ count: number;
2707
+ avgQueueWait: number;
2708
+ avgExecution: number;
2709
+ successRate: number;
2710
+ }
2711
+ interface SignatureMetrics {
2712
+ queueWait?: number;
2713
+ execution?: number;
2714
+ success?: boolean;
2715
+ }
2716
+ interface SignatureSnapshot {
2717
+ signature: string;
2718
+ count: number;
2719
+ avgQueueWait: number;
2720
+ avgExecution: number;
2721
+ successRate: number;
2722
+ }
2723
+ declare class SignatureStats {
2724
+ alpha: number;
2725
+ maxEntries: number;
2726
+ entries: Map<string, SignatureEntry>;
2727
+ constructor(options?: SignatureStatsOptions);
2728
+ record(signature: string, metrics?: SignatureMetrics): void;
2729
+ snapshot(limit?: number): SignatureSnapshot[];
2730
+ reset(): void;
2731
+ private _mix;
2732
+ }
2733
+
2734
+ declare class FifoTaskQueue<T = unknown> {
2735
+ buffer: Array<T | undefined>;
2736
+ mask: number;
2737
+ head: number;
2738
+ tail: number;
2739
+ constructor(capacity?: number);
2740
+ get length(): number;
2741
+ enqueue(value: T): void;
2742
+ dequeue(): T | null;
2743
+ flush(callback?: (item: T) => void): void;
2744
+ clear(): void;
2745
+ setAgingMultiplier(_multiplier?: number): void;
2746
+ toArray(): T[];
2747
+ private _grow;
2748
+ private _normalizeCapacity;
2749
+ }
2750
+
2751
+ interface PriorityTaskQueueOptions {
2752
+ agingMs?: number;
2753
+ maxAgingBoost?: number;
2754
+ }
2755
+ interface PriorityNode<T = unknown> {
2756
+ task: T;
2757
+ priority: number;
2758
+ order: number;
2759
+ enqueuedAt?: number;
2760
+ }
2761
+ interface TaskWithPriority {
2762
+ priority?: number;
2763
+ }
2764
+ declare class PriorityTaskQueue<T extends TaskWithPriority = TaskWithPriority> {
2765
+ heap: PriorityNode<T>[];
2766
+ counter: number;
2767
+ agingMs: number;
2768
+ maxAgingBoost: number;
2769
+ agingMultiplier: number;
2770
+ private _agingEnabled;
2771
+ constructor(options?: PriorityTaskQueueOptions);
2772
+ get length(): number;
2773
+ enqueue(task: T): void;
2774
+ dequeue(): T | null;
2775
+ flush(callback?: (task: T) => void): void;
2776
+ clear(): void;
2777
+ setAgingMultiplier(multiplier: number): void;
2778
+ private _bubbleUp;
2779
+ private _bubbleDown;
2780
+ private _isHigherPriority;
2781
+ private _priorityValue;
2782
+ private _swap;
2783
+ private _agingTimestamp;
2784
+ private _agingBase;
2785
+ }
2786
+
2787
+ interface TaskContext {
2788
+ id: string;
2789
+ attempt: number;
2790
+ retries: number;
2791
+ metadata: Record<string, unknown>;
2792
+ signal?: AbortSignal;
2793
+ }
2794
+ type TaskFunction<T = unknown> = (context: TaskContext) => Promise<T>;
2795
+ interface TaskPoolOptions {
2796
+ concurrency?: number | 'auto';
2797
+ retries?: number;
2798
+ retryDelay?: number;
2799
+ timeout?: number;
2800
+ retryableErrors?: string[];
2801
+ autoTuning?: {
2802
+ enabled?: boolean;
2803
+ instance?: AdaptiveTuning;
2804
+ targetLatency?: number;
2805
+ [key: string]: unknown;
2806
+ };
2807
+ monitoring?: {
2808
+ enabled?: boolean;
2809
+ collectMetrics?: boolean;
2810
+ sampleRate?: number;
2811
+ telemetrySampleRate?: number;
2812
+ sampleInterval?: number;
2813
+ rollingWindowMs?: number;
2814
+ reportInterval?: number;
2815
+ signatureSampleLimit?: number;
2816
+ signatureAlpha?: number;
2817
+ signatureMaxEntries?: number;
2818
+ mode?: 'light' | 'passive' | 'detailed' | 'full' | 'balanced';
2819
+ exporter?: (snapshot: MonitoringSnapshot$1) => void;
2820
+ };
2821
+ features?: {
2822
+ profile?: 'bare' | 'light' | 'balanced';
2823
+ emitEvents?: boolean;
2824
+ signatureInsights?: boolean;
2825
+ };
2826
+ retryStrategy?: {
2827
+ jitter?: boolean;
2828
+ minDelay?: number;
2829
+ maxDelay?: number;
2830
+ clampDelay?: number;
2831
+ pressureClampThreshold?: number;
2832
+ pressureSkipThreshold?: number;
2833
+ latencyTarget?: number;
2834
+ };
2835
+ queue?: {
2836
+ agingMs?: number;
2837
+ maxAgingBoost?: number;
2838
+ latencyTarget?: number;
2839
+ };
2840
+ }
2841
+ interface EnqueueOptions$1 {
2842
+ priority?: number;
2843
+ retries?: number;
2844
+ timeout?: number;
2845
+ metadata?: Record<string, unknown>;
2846
+ signature?: string;
2847
+ [key: string]: unknown;
2848
+ }
2849
+ interface BatchOptions extends EnqueueOptions$1 {
2850
+ onItemComplete?: (result: unknown, index: number) => void;
2851
+ onItemError?: (error: Error, index: number) => void;
2852
+ }
2853
+ interface BatchResult<T = unknown> {
2854
+ results: (T | null)[];
2855
+ errors: Array<{
2856
+ error: Error;
2857
+ index: number;
2858
+ }>;
2859
+ batchId: string;
2860
+ }
2861
+ interface TaskTimings {
2862
+ queueWait: number | null;
2863
+ execution: number | null;
2864
+ retryDelays: number[] | null;
2865
+ retryDelayTotal: number;
2866
+ total: number | null;
2867
+ failedAttempts: Array<{
2868
+ attempt: number;
2869
+ duration: number;
2870
+ error: string;
2871
+ }> | null;
2872
+ overhead?: number;
2873
+ }
2874
+ interface TaskPerformance {
2875
+ heapUsedBefore: number | null;
2876
+ heapUsedAfter: number | null;
2877
+ heapDelta: number | null;
2878
+ }
2879
+ interface PoolTask<T = unknown> {
2880
+ id: string;
2881
+ fn: TaskFunction<T>;
2882
+ priority: number;
2883
+ retries: number;
2884
+ timeout: number;
2885
+ metadata: Record<string, unknown>;
2886
+ attemptCount: number;
2887
+ createdAt: number;
2888
+ startedAt: number | null;
2889
+ completedAt: number | null;
2890
+ collectMetrics: boolean;
2891
+ timings: TaskTimings;
2892
+ controller: AbortController | null;
2893
+ delayController?: AbortController | null;
2894
+ performance: TaskPerformance;
2895
+ signature: string;
2896
+ promise: Promise<T>;
2897
+ resolve: (result: T) => void;
2898
+ reject: (error: Error) => void;
2899
+ }
2900
+ interface PoolStats {
2901
+ queueSize: number;
2902
+ activeCount: number;
2903
+ processedCount: number;
2904
+ errorCount: number;
2905
+ retryCount: number;
2906
+ }
2907
+ interface RollingMetricsSnapshot$1 {
2908
+ sampleSize: number;
2909
+ avgQueueWait: number;
2910
+ avgExecution: number;
2911
+ avgRetries: number;
2912
+ errorRate: number;
2913
+ }
2914
+ interface ThroughputSnapshot {
2915
+ windowMs: number;
2916
+ throughputPerSec: number;
2917
+ successRate: number;
2918
+ }
2919
+ interface RollingMetricsResult {
2920
+ samples: RollingMetricsSnapshot$1 | null;
2921
+ throughput: ThroughputSnapshot | null;
2922
+ }
2923
+ interface AggregateMetrics$1 {
2924
+ count: number;
2925
+ avgQueueWait: number;
2926
+ avgExecution: number;
2927
+ avgTotal: number;
2928
+ p50Execution: number;
2929
+ p95Execution: number;
2930
+ p99Execution: number;
2931
+ avgHeapDelta: number;
2932
+ errorRate: number;
2933
+ avgRetries: number;
2934
+ autoTuning: unknown;
2935
+ }
2936
+ interface MonitoringSnapshot$1 {
2937
+ timestamp: number;
2938
+ stage: string;
2939
+ profile: string;
2940
+ queueSize: number;
2941
+ activeCount: number;
2942
+ processed: number;
2943
+ errors: number;
2944
+ retries: number;
2945
+ throughput: number;
2946
+ signatureInsights: unknown[];
2947
+ }
2948
+ interface TaskMetricsEntry {
2949
+ id: string;
2950
+ metadata: Record<string, unknown>;
2951
+ timings: TaskTimings;
2952
+ performance: TaskPerformance;
2953
+ attemptCount: number;
2954
+ createdAt: number;
2955
+ startedAt: number | null;
2956
+ completedAt: number | null;
2957
+ success: boolean;
2958
+ }
2959
+ interface RollingMetricsEntry {
2960
+ queueWait: number;
2961
+ execution: number;
2962
+ retries: number;
2963
+ success: boolean;
2964
+ }
2965
+ declare class MemorySampler {
2966
+ interval: number;
2967
+ lastSampleTime: number;
2968
+ lastSample: {
2969
+ heapUsed: number;
2970
+ };
2971
+ constructor(interval?: number);
2972
+ snapshot(): number;
2973
+ maybeSample(): number;
2974
+ sampleNow(): number;
2975
+ }
2976
+ declare class RollingMetrics {
2977
+ size: number;
2978
+ entries: Array<RollingMetricsEntry | undefined>;
2979
+ index: number;
2980
+ length: number;
2981
+ sums: {
2982
+ queueWait: number;
2983
+ execution: number;
2984
+ retries: number;
2985
+ };
2986
+ errorCount: number;
2987
+ constructor(size?: number);
2988
+ push(entry: RollingMetricsEntry): void;
2989
+ snapshot(): RollingMetricsSnapshot$1;
2990
+ }
2991
+ declare class RollingWindow {
2992
+ windowMs: number;
2993
+ events: Array<{
2994
+ timestamp: number;
2995
+ success: boolean;
2996
+ }>;
2997
+ constructor(windowMs?: number);
2998
+ record(timestamp?: number, success?: boolean): void;
2999
+ snapshot(): ThroughputSnapshot;
3000
+ private _prune;
3001
+ }
3002
+ declare class TasksPool extends EventEmitter$1 implements TaskExecutor {
3003
+ features: {
3004
+ profile: string;
3005
+ emitEvents: boolean;
3006
+ signatureInsights: boolean;
3007
+ };
3008
+ lightMode: boolean;
3009
+ bareMode: boolean;
3010
+ autoConcurrency: boolean;
3011
+ retries: number;
3012
+ retryDelay: number;
3013
+ timeout: number;
3014
+ retryableErrors: string[];
3015
+ retryStrategy: {
3016
+ jitter: boolean;
3017
+ minDelay: number;
3018
+ maxDelay: number;
3019
+ clampDelay: number;
3020
+ pressureClampThreshold: number;
3021
+ pressureSkipThreshold: number;
3022
+ latencyTarget: number;
3023
+ };
3024
+ priorityConfig: {
3025
+ agingMs: number;
3026
+ maxAgingBoost: number;
3027
+ latencyTarget: number;
3028
+ };
3029
+ queue: FifoTaskQueue<PoolTask> | PriorityTaskQueue<PoolTask>;
3030
+ active: Map<Promise<unknown>, PoolTask>;
3031
+ paused: boolean;
3032
+ stopped: boolean;
3033
+ stats: PoolStats;
3034
+ rollingMetrics: RollingMetrics;
3035
+ monitoring: {
3036
+ enabled: boolean;
3037
+ mode: string;
3038
+ collectMetrics: boolean;
3039
+ sampleRate: number;
3040
+ telemetryRate: number;
3041
+ sampleInterval: number;
3042
+ rollingWindowMs: number;
3043
+ reportInterval: number;
3044
+ signatureSampleLimit: number;
3045
+ exporter: ((snapshot: MonitoringSnapshot$1) => void) | null;
3046
+ };
3047
+ taskMetrics: Map<string, TaskMetricsEntry>;
3048
+ memorySampler: MemorySampler | null;
3049
+ rollingWindow: RollingWindow | null;
3050
+ signatureStats: SignatureStats | null;
3051
+ tuner: AdaptiveTuning | null;
3052
+ autoTuningConfig?: Record<string, unknown>;
3053
+ private _configuredConcurrency;
3054
+ private _effectiveConcurrency;
3055
+ private _drainInProgress;
3056
+ private _pendingDrain;
3057
+ private _activeWaiters;
3058
+ private _lightActiveTasks;
3059
+ private _monitoringState;
3060
+ private _lastTunedConcurrency;
3061
+ constructor(options?: TaskPoolOptions);
3062
+ private _normalizeConcurrency;
3063
+ get concurrency(): number | 'auto';
3064
+ get effectiveConcurrency(): number;
3065
+ private _defaultAutoConcurrency;
3066
+ private _normalizeSampleRate;
3067
+ private _shouldSampleMetrics;
3068
+ private _shouldCaptureAttemptTimeline;
3069
+ setTuner(tuner: AdaptiveTuning): void;
3070
+ enqueue<T = unknown>(fn: TaskFunction<T>, options?: EnqueueOptions$1): Promise<T>;
3071
+ addBatch<T = unknown>(fns: Array<TaskFunction<T>>, options?: BatchOptions): Promise<BatchResult<T>>;
3072
+ /**
3073
+ * Process an array of items with controlled concurrency.
3074
+ * This is a convenience method that mimics PromisePool.for().process() API.
3075
+ *
3076
+ * @example
3077
+ * const { results, errors } = await TasksPool.map(
3078
+ * users,
3079
+ * async (user) => fetchUserData(user.id),
3080
+ * { concurrency: 10 }
3081
+ * );
3082
+ */
3083
+ static map<T, R>(items: T[], processor: (item: T, index: number) => Promise<R>, options?: {
3084
+ concurrency?: number;
3085
+ onItemComplete?: (result: R, index: number) => void;
3086
+ onItemError?: (error: Error, item: T, index: number) => void;
3087
+ }): Promise<{
3088
+ results: R[];
3089
+ errors: Array<{
3090
+ error: Error;
3091
+ item: T;
3092
+ index: number;
3093
+ }>;
3094
+ }>;
3095
+ processNext(): void;
3096
+ private _drainQueue;
3097
+ private _canProcessNext;
3098
+ private _processLightQueue;
3099
+ private _processBareQueue;
3100
+ private _executeTaskWithRetry;
3101
+ private _runSingleAttempt;
3102
+ private _executeBareTask;
3103
+ private _executeWithTimeout;
3104
+ private _isErrorRetryable;
3105
+ private _insertByPriority;
3106
+ private _recordTaskCompletion;
3107
+ private _storeTaskMetrics;
3108
+ private _recordRollingMetrics;
3109
+ pause(): Promise<void>;
3110
+ resume(): void;
3111
+ stop(): void;
3112
+ drain(): Promise<void>;
3113
+ private _waitForActive;
3114
+ private _notifyActiveWaiters;
3115
+ setConcurrency(n: number | 'auto'): void;
3116
+ getConcurrency(): number | 'auto';
3117
+ getStats(): Record<string, unknown>;
3118
+ getTaskMetrics(taskId: string): TaskMetricsEntry | undefined;
3119
+ getRollingMetrics(): RollingMetricsResult;
3120
+ getSignatureInsights(limit?: number): unknown[];
3121
+ getAggregateMetrics(since?: number): AggregateMetrics$1 | null;
3122
+ private _avg;
3123
+ private _percentile;
3124
+ private _sleep;
3125
+ private _buildTaskContext;
3126
+ private _readHeapUsage;
3127
+ private _computeHeapDelta;
3128
+ private _shouldEnforceTimeout;
3129
+ private _computeRetryDelay;
3130
+ private _isTransientNetworkError;
3131
+ private _latencyTargetMs;
3132
+ private _syncQueueAging;
3133
+ private _safeEmit;
3134
+ private _currentActiveCount;
3135
+ private _maybeExportMonitoringSample;
3136
+ private _applyTunedConcurrency;
3137
+ process<T, R>(items: T[], processor: (item: T, index?: number, executor?: unknown) => Promise<R>, options?: {
3138
+ onSuccess?: (item: T, result: R) => void;
3139
+ onError?: (item: T, error: Error) => void;
3140
+ priority?: number;
3141
+ retries?: number;
3142
+ timeout?: number;
3143
+ totalCount?: number;
3144
+ [key: string]: unknown;
3145
+ }): Promise<{
3146
+ results: R[];
3147
+ errors: (Error | {
3148
+ item?: T;
3149
+ error?: Error;
3150
+ index?: number;
3151
+ })[];
3152
+ }>;
3153
+ destroy(): Promise<void>;
3154
+ }
3155
+
3156
+ interface RunnerOptions {
3157
+ concurrency?: number;
3158
+ retries?: number;
3159
+ retryDelay?: number;
3160
+ timeout?: number;
3161
+ retryableErrors?: string[];
3162
+ priority?: boolean;
3163
+ autoTuning?: {
3164
+ enabled?: boolean;
3165
+ instance?: AdaptiveTuning;
3166
+ [key: string]: unknown;
3167
+ };
3168
+ monitoring?: {
3169
+ enabled?: boolean;
3170
+ collectMetrics?: boolean;
3171
+ sampleRate?: number;
3172
+ maxSamples?: number;
3173
+ rollingWindowMs?: number;
3174
+ reportInterval?: number;
3175
+ telemetrySampleRate?: number;
3176
+ signatureSampleLimit?: number;
3177
+ signatureAlpha?: number;
3178
+ signatureMaxEntries?: number;
3179
+ mode?: 'light' | 'passive' | 'detailed';
3180
+ exporter?: (snapshot: MonitoringSnapshot) => void;
3181
+ };
3182
+ features?: {
3183
+ profile?: 'bare' | 'light' | 'balanced';
3184
+ emitEvents?: boolean;
3185
+ trackProcessedItems?: boolean;
3186
+ signatureInsights?: boolean;
3187
+ };
3188
+ }
3189
+ interface EnqueueOptions {
3190
+ priority?: number;
3191
+ retries?: number;
3192
+ timeout?: number;
3193
+ metadata?: Record<string, unknown>;
3194
+ signature?: string;
3195
+ }
3196
+ interface ProcessOptions<T = unknown> extends EnqueueOptions {
3197
+ onProgress?: (item: T, stats: ProgressStats) => void;
3198
+ onItemComplete?: (item: T, result: unknown) => void;
3199
+ onItemError?: (item: T, error: Error) => void;
3200
+ totalCount?: number;
3201
+ }
3202
+ interface ProgressStats {
3203
+ processedCount: number;
3204
+ totalCount: number | null;
3205
+ percentage: string | null;
3206
+ }
3207
+ interface ProcessResult<T = unknown> {
3208
+ results: T[];
3209
+ errors: Array<{
3210
+ item: unknown;
3211
+ error: Error;
3212
+ index: number;
3213
+ }>;
3214
+ }
3215
+ interface RunnerStats {
3216
+ queueSize: number;
3217
+ activeCount: number;
3218
+ processedCount: number;
3219
+ errorCount: number;
3220
+ retryCount: number;
3221
+ }
3222
+ interface RollingMetricsSnapshot {
3223
+ sampleSize: number;
3224
+ avgQueueWait: number;
3225
+ avgExecution: number;
3226
+ avgRetries: number;
3227
+ errorRate: number;
3228
+ }
3229
+ interface AggregateMetrics {
3230
+ count: number;
3231
+ avgQueueWait: number;
3232
+ avgExecution: number;
3233
+ avgTotal: number;
3234
+ p50Execution: number;
3235
+ p95Execution: number;
3236
+ p99Execution: number;
3237
+ errorRate: number;
3238
+ avgRetries: number;
3239
+ }
3240
+ interface ProgressInfo {
3241
+ total: number;
3242
+ completed: number;
3243
+ pending: number;
3244
+ active: number;
3245
+ percentage: string | number;
3246
+ }
3247
+ interface MonitoringSnapshot {
3248
+ timestamp: number;
3249
+ stage: string;
3250
+ profile: string;
3251
+ queueSize: number;
3252
+ activeCount: number;
3253
+ processed: number;
3254
+ errors: number;
3255
+ retries: number;
3256
+ throughput: number;
3257
+ signatureInsights: unknown[];
3258
+ }
3259
+ interface TaskTelemetry {
3260
+ enqueuedAt: number;
3261
+ startedAt?: number;
3262
+ failedAttempts: Array<{
3263
+ attempt: number;
3264
+ duration: number;
3265
+ errorName: string;
3266
+ errorMessage: string;
3267
+ }>;
3268
+ }
3269
+ interface TaskMetricEntry {
3270
+ id: string;
3271
+ completedAt: number;
3272
+ success: boolean;
3273
+ attemptCount: number;
3274
+ timings: {
3275
+ queueWait: number;
3276
+ execution: number;
3277
+ total: number;
3278
+ failedAttempts: Array<{
3279
+ attempt: number;
3280
+ duration: number;
3281
+ errorName: string;
3282
+ errorMessage: string;
3283
+ }>;
3284
+ };
3285
+ performance: Record<string, unknown>;
3286
+ error: {
3287
+ name: string;
3288
+ message: string;
3289
+ } | null;
3290
+ }
3291
+ interface RunnerTask<T = unknown> {
3292
+ id: string;
3293
+ fn: () => Promise<T>;
3294
+ priority: number;
3295
+ retries: number;
3296
+ timeout: number;
3297
+ metadata: Record<string, unknown>;
3298
+ attemptCount: number;
3299
+ createdAt: number;
3300
+ signature: string;
3301
+ promise: Promise<T>;
3302
+ resolve: (result: T) => void;
3303
+ reject: (error: Error) => void;
3304
+ telemetry?: TaskTelemetry;
3305
+ }
3306
+ declare class TasksRunner extends EventEmitter$1 implements TaskExecutor {
3307
+ static notRun: symbol;
3308
+ static failed: symbol;
3309
+ features: {
3310
+ profile: string;
3311
+ emitEvents: boolean;
3312
+ trackProcessedItems: boolean;
3313
+ signatureInsights: boolean;
3314
+ };
3315
+ lightMode: boolean;
3316
+ bareMode: boolean;
3317
+ concurrency: number;
3318
+ retries: number;
3319
+ retryDelay: number;
3320
+ timeout: number;
3321
+ retryableErrors: string[];
3322
+ active: Set<Promise<unknown>>;
3323
+ paused: boolean;
3324
+ stopped: boolean;
3325
+ stats: RunnerStats;
3326
+ processedItems: unknown[] | null;
3327
+ taskMetrics: Map<string, TaskMetricEntry>;
3328
+ monitoring: {
3329
+ enabled: boolean;
3330
+ mode: string;
3331
+ collectMetrics: boolean;
3332
+ sampleRate: number;
3333
+ maxSamples: number;
3334
+ rollingWindowMs: number;
3335
+ reportInterval: number;
3336
+ telemetryRate: number;
3337
+ signatureSampleLimit: number;
3338
+ exporter: ((snapshot: MonitoringSnapshot) => void) | null;
3339
+ };
3340
+ signatureStats: SignatureStats | null;
3341
+ tuner: AdaptiveTuning | null;
3342
+ autoTuningConfig?: Record<string, unknown>;
3343
+ private _queue;
3344
+ private _activeWaiters;
3345
+ private _activeLightTasks;
3346
+ private _taskMetricsOrder;
3347
+ private _monitoringState;
3348
+ private _lastTunedConcurrency;
3349
+ constructor(options?: RunnerOptions);
3350
+ get queue(): RunnerTask[];
3351
+ process<T, R>(items: T[], processor: (item: T, index?: number, executor?: unknown) => Promise<R>, options?: ProcessOptions<T>): Promise<ProcessResult<R>>;
3352
+ enqueue<T = unknown>(fn: () => Promise<T>, options?: EnqueueOptions): Promise<T>;
3353
+ processIterable<T, R>(iterable: Iterable<T> | AsyncIterable<T>, processor: (item: T, index: number, runner: TasksRunner) => Promise<R>, options?: ProcessOptions<T>): Promise<ProcessResult<R>>;
3354
+ processCorresponding<T, R>(items: T[], processor: (item: T, index: number, runner: TasksRunner) => Promise<R>, options?: ProcessOptions<T>): Promise<Array<R | typeof TasksRunner.failed | typeof TasksRunner.notRun>>;
3355
+ processNext(): void;
3356
+ private _processLightQueue;
3357
+ private _processBareQueue;
3358
+ private _currentActiveCount;
3359
+ private _maybeExportMonitoringSample;
3360
+ private _executeTaskWithRetry;
3361
+ private _runSingleAttempt;
3362
+ private _executeBareTask;
3363
+ private _shouldEnforceTimeout;
3364
+ private _executeWithTimeout;
3365
+ private _isErrorRetryable;
3366
+ private _insertByPriority;
3367
+ private _waitForSlot;
3368
+ private _waitForActive;
3369
+ private _notifyActiveWaiters;
3370
+ private _sleep;
3371
+ private _primeTaskTelemetry;
3372
+ private _markTaskDequeued;
3373
+ private _shouldSampleMetrics;
3374
+ private _shouldTrackTelemetry;
3375
+ private _storeTaskMetric;
3376
+ private _recordTaskMetrics;
3377
+ pause(): Promise<void>;
3378
+ resume(): void;
3379
+ stop(): void;
3380
+ drain(): Promise<void>;
3381
+ setConcurrency(n: number): void;
3382
+ getConcurrency(): number;
3383
+ getStats(): Record<string, unknown>;
3384
+ getRollingMetrics(): RollingMetricsSnapshot | null;
3385
+ getSignatureInsights(limit?: number): unknown[];
3386
+ getAggregateMetrics(since?: number): AggregateMetrics | null;
3387
+ getProgress(): ProgressInfo;
3388
+ reset(): void;
3389
+ destroy(): Promise<void>;
3390
+ private _safeEmit;
3391
+ private _applyTunedConcurrency;
3392
+ private _normalizeSampleRate;
3393
+ private _avg;
3394
+ private _percentile;
3395
+ static process<T, R>(items: T[], processor: (item: T, index?: number, executor?: unknown) => Promise<R>, options?: RunnerOptions & ProcessOptions<T>): Promise<ProcessResult<R>>;
3396
+ static withConcurrency(concurrency: number): TasksRunner;
3397
+ }
3398
+
3399
+ interface BenchmarkResult {
3400
+ duration: number;
3401
+ timestamp: number;
3402
+ }
3403
+ interface BenchmarkStats {
3404
+ iterations: number;
3405
+ results: number[];
3406
+ avg: number;
3407
+ min: number;
3408
+ max: number;
3409
+ p50: number;
3410
+ p95: number;
3411
+ p99: number;
3412
+ }
3413
+ declare class Benchmark {
3414
+ name: string;
3415
+ startTime: number | null;
3416
+ endTime: number | null;
3417
+ results: BenchmarkResult[];
3418
+ constructor(name: string);
3419
+ start(): void;
3420
+ end(): number;
3421
+ elapsed(): number;
3422
+ measure<T>(fn: () => Promise<T>): Promise<T>;
3423
+ measureRepeated(fn: () => Promise<unknown>, iterations?: number): Promise<BenchmarkStats>;
3424
+ percentile(arr: number[], p: number): number;
3425
+ report(): void;
3426
+ }
3427
+ declare function benchmark(name: string, fn: () => Promise<unknown>): Promise<Benchmark>;
3428
+
3429
+ interface TaskQueueStats {
3430
+ queueSize: number;
3431
+ activeCount: number;
3432
+ processedCount: number;
3433
+ errorCount: number;
3434
+ concurrency?: number;
3435
+ effectiveConcurrency?: number;
3436
+ }
3437
+ interface PerformanceMetrics {
3438
+ avgExecution: number;
3439
+ p95Execution: number;
3440
+ }
3441
+ interface SystemMetrics {
3442
+ memoryUsage: NodeJS.MemoryUsage;
3443
+ cpuUsage: NodeJS.CpuUsage;
3444
+ uptime: number;
3445
+ }
3446
+ interface Snapshot {
3447
+ timestamp: number;
3448
+ taskQueue: TaskQueueStats | null;
3449
+ performance: PerformanceMetrics | null;
3450
+ system: SystemMetrics;
3451
+ }
3452
+ interface TaskQueueReport {
3453
+ totalProcessed: number;
3454
+ totalErrors: number;
3455
+ avgQueueSize: number;
3456
+ avgConcurrency: number;
3457
+ }
3458
+ interface PerformanceReport {
3459
+ avgLatency: number;
3460
+ p95Latency: number;
3461
+ }
3462
+ interface SystemReport {
3463
+ avgMemoryMB: number;
3464
+ peakMemoryMB: number;
3465
+ }
3466
+ interface MonitorReport {
3467
+ duration: number;
3468
+ snapshots: number;
3469
+ taskQueue: TaskQueueReport | null;
3470
+ performance: PerformanceReport | null;
3471
+ system: SystemReport;
3472
+ }
3473
+ interface DatabaseClient {
3474
+ getQueueStats?: () => TaskQueueStats;
3475
+ getAggregateMetrics?: () => PerformanceMetrics;
3476
+ }
3477
+ interface DatabaseLike {
3478
+ client?: DatabaseClient;
3479
+ }
3480
+ declare class PerformanceMonitor {
3481
+ db: DatabaseLike;
3482
+ snapshots: Snapshot[];
3483
+ intervalId: ReturnType<typeof setInterval> | null;
3484
+ constructor(database: DatabaseLike);
3485
+ start(intervalMs?: number): void;
3486
+ stop(): void;
3487
+ takeSnapshot(): Snapshot;
3488
+ getReport(): MonitorReport | null;
3489
+ private _avg;
3490
+ }
3491
+
3492
+ export { AVAILABLE_BEHAVIORS, AdaptiveTuning, AnalyticsNotEnabledError, AuthenticationError, BaseError, BehaviorError, Benchmark, S3Client as Client, ConnectionString, ConnectionStringError, CryptoError, DEFAULT_BEHAVIOR, Database, DatabaseError, EncryptionError, ErrorMap, FileSystemClient, InvalidResourceItem, MemoryClient, MetadataLimitError, MissingMetadata, NoSuchBucket, NoSuchKey, NotFound, PartitionDriverError, PartitionError, PerformanceMonitor, PermissionError, PluginError, PluginStorageError, ProcessManager, Resource, ResourceError, ResourceIdsPageReader, ResourceIdsReader, ResourceNotFound, ResourceReader, ResourceWriter, S3Client, Database as S3db, S3dbError, SafeEventEmitter, Schema, SchemaError, StreamError, TaskExecutor, TasksPool, TasksRunner, UnknownError, ValidationError, Validator, behaviors, benchmark, createCustomGenerator, createLogger, createSafeEventEmitter, decode, decodeBits, decodeBuffer, decodeDecimal, decrypt, S3db as default, encode, encodeBits, encodeBuffer, encodeDecimal, encrypt, getBehavior, getProcessManager, idGenerator, initializeNanoid, mapAwsError, mapWithConcurrency, passwordGenerator, resetProcessManager, streamToString, tryFn, tryFnSync };
3493
+ export type { AnalyticsNotEnabledErrorDetails, BaseErrorContext, BehaviorErrorDetails, InvalidResourceItemDetails, LogLevel$1 as LogLevel, MapAwsErrorContext, MetadataLimitErrorDetails, NoSuchBucketDetails, NoSuchKeyDetails, PartitionDriverErrorDetails, PartitionErrorDetails, PluginErrorDetails, PluginStorageErrorDetails, ResourceNotFoundDetails, S3dbErrorDetails, SchemaRegistry, SerializedError, StreamErrorDetails, TryResult };