s3db.js 5.2.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/s3db.d.ts CHANGED
@@ -1,133 +1,962 @@
1
1
  declare module 's3db.js' {
2
- export interface S3dbConfig {
2
+ // ============================================================================
3
+ // CORE TYPES
4
+ // ============================================================================
5
+
6
+ /** Main Database configuration */
7
+ export interface DatabaseConfig {
3
8
  connectionString?: string;
4
9
  region?: string;
5
10
  accessKeyId?: string;
6
11
  secretAccessKey?: string;
12
+ sessionToken?: string;
7
13
  bucket?: string;
8
- prefix?: string;
9
- encryption?: boolean;
10
- compression?: boolean;
11
- cache?: boolean;
12
- cacheTTL?: number;
13
- maxConcurrency?: number;
14
- retryAttempts?: number;
15
- retryDelay?: number;
14
+ endpoint?: string;
15
+ forcePathStyle?: boolean;
16
+ verbose?: boolean;
17
+ parallelism?: number | string;
18
+ passphrase?: string;
19
+ versioningEnabled?: boolean;
20
+ cache?: CacheConfig;
21
+ plugins?: Plugin[] | PluginFunction[];
22
+ client?: Client;
16
23
  }
17
24
 
25
+ /** Resource configuration */
18
26
  export interface ResourceConfig {
19
27
  name: string;
20
- schema?: any;
21
- encryption?: boolean;
22
- compression?: boolean;
23
- cache?: boolean;
24
- cacheTTL?: number;
25
- maxSize?: number;
26
- partitions?: string[];
27
- behaviors?: string[];
28
+ client: Client;
29
+ version?: string;
30
+ attributes?: Record<string, any>;
31
+ behavior?: BehaviorName;
32
+ passphrase?: string;
33
+ parallelism?: number;
34
+ observers?: any[];
35
+ cache?: boolean | CacheConfig;
36
+ autoDecrypt?: boolean;
37
+ timestamps?: boolean;
38
+ partitions?: Record<string, PartitionConfig>;
39
+ paranoid?: boolean;
40
+ allNestedObjectsOptional?: boolean;
41
+ hooks?: HookConfig;
42
+ idGenerator?: Function | number;
43
+ idSize?: number;
44
+ versioningEnabled?: boolean;
28
45
  }
29
46
 
47
+ /** Partition configuration */
48
+ export interface PartitionConfig {
49
+ fields: Record<string, string>;
50
+ description?: string;
51
+ }
52
+
53
+ /** Hook configuration */
54
+ export interface HookConfig {
55
+ preInsert?: Function[];
56
+ afterInsert?: Function[];
57
+ preUpdate?: Function[];
58
+ afterUpdate?: Function[];
59
+ preDelete?: Function[];
60
+ afterDelete?: Function[];
61
+ }
62
+
63
+ /** Query options */
30
64
  export interface QueryOptions {
31
65
  limit?: number;
32
66
  offset?: number;
33
- sort?: string;
34
- order?: 'asc' | 'desc';
35
- filter?: any;
36
- select?: string[];
67
+ partition?: string;
68
+ partitionValues?: Record<string, any>;
37
69
  }
38
70
 
71
+ /** Insert options */
39
72
  export interface InsertOptions {
40
- encryption?: boolean;
41
- compression?: boolean;
42
- cache?: boolean;
43
- cacheTTL?: number;
73
+ id?: string;
44
74
  }
45
75
 
46
- export interface UpdateOptions extends InsertOptions {
47
- upsert?: boolean;
76
+ /** Update options */
77
+ export interface UpdateOptions {
78
+ id: string;
48
79
  }
49
80
 
81
+ /** Delete options */
50
82
  export interface DeleteOptions {
51
- cascade?: boolean;
83
+ id: string;
84
+ }
85
+
86
+ /** Page options */
87
+ export interface PageOptions {
88
+ offset?: number;
89
+ size?: number;
90
+ partition?: string;
91
+ partitionValues?: Record<string, any>;
92
+ skipCount?: boolean;
93
+ }
94
+
95
+ /** List options */
96
+ export interface ListOptions {
97
+ partition?: string;
98
+ partitionValues?: Record<string, any>;
99
+ limit?: number;
100
+ offset?: number;
101
+ }
102
+
103
+ /** Count options */
104
+ export interface CountOptions {
105
+ partition?: string;
106
+ partitionValues?: Record<string, any>;
107
+ }
108
+
109
+ // ============================================================================
110
+ // BEHAVIOR TYPES
111
+ // ============================================================================
112
+
113
+ /** Names of all built-in behaviors */
114
+ export type BehaviorName =
115
+ | 'user-managed'
116
+ | 'enforce-limits'
117
+ | 'data-truncate'
118
+ | 'body-overflow'
119
+ | 'body-only';
120
+
121
+ /** User Managed Behavior config (default) */
122
+ export interface UserManagedBehaviorConfig {
123
+ enabled?: boolean;
124
+ }
125
+
126
+ /** Enforce Limits Behavior config */
127
+ export interface EnforceLimitsBehaviorConfig {
128
+ enabled?: boolean;
129
+ maxBodySize?: number;
130
+ maxMetadataSize?: number;
131
+ maxKeySize?: number;
132
+ maxValueSize?: number;
133
+ maxFields?: number;
134
+ maxNestingDepth?: number;
135
+ maxArrayLength?: number;
136
+ maxStringLength?: number;
137
+ maxNumberValue?: number;
138
+ minNumberValue?: number;
139
+ enforcementMode?: 'strict' | 'warn' | 'soft';
140
+ logViolations?: boolean;
141
+ throwOnViolation?: boolean;
142
+ customValidator?: (data: any, limits: any, context: any) => boolean;
143
+ fieldLimits?: Record<string, number>;
144
+ excludeFields?: string[];
145
+ includeFields?: string[];
146
+ applyToInsert?: boolean;
147
+ applyToUpdate?: boolean;
148
+ applyToUpsert?: boolean;
149
+ applyToRead?: boolean;
150
+ warningThreshold?: number;
151
+ context?: Record<string, any>;
152
+ validateMetadata?: boolean;
153
+ validateBody?: boolean;
154
+ validateKeys?: boolean;
155
+ validateValues?: boolean;
156
+ }
157
+
158
+ /** Data Truncate Behavior config */
159
+ export interface DataTruncateBehaviorConfig {
160
+ enabled?: boolean;
161
+ fieldLimits?: Record<string, number>;
162
+ defaultLimit?: number;
163
+ truncateIndicator?: string;
164
+ truncateMode?: 'end' | 'start' | 'middle';
165
+ preserveWords?: boolean;
166
+ preserveSentences?: boolean;
167
+ excludeFields?: string[];
168
+ includeFields?: string[];
169
+ applyToInsert?: boolean;
170
+ applyToUpdate?: boolean;
171
+ applyToUpsert?: boolean;
172
+ logTruncations?: boolean;
173
+ warnOnTruncation?: boolean;
174
+ customTruncator?: (value: string, fieldName: string, limit: number, config: any) => string;
175
+ fieldTruncators?: Record<string, (value: string, fieldName: string, limit: number, config: any) => string>;
176
+ validateOnRead?: boolean;
177
+ warningThreshold?: number;
178
+ context?: Record<string, any>;
179
+ preserveHTML?: boolean;
180
+ preserveMarkdown?: boolean;
181
+ preserveTags?: string[];
182
+ }
183
+
184
+ /** Body Overflow Behavior config */
185
+ export interface BodyOverflowBehaviorConfig {
186
+ enabled?: boolean;
187
+ maxBodySize?: number;
188
+ overflowStrategy?: 'truncate' | 'split' | 'reject';
189
+ truncateMode?: 'end' | 'start' | 'middle';
190
+ truncateIndicator?: string;
191
+ preserveStructure?: boolean;
192
+ priorityFields?: string[];
193
+ overflowFields?: string[];
194
+ overflowStorage?: {
195
+ type?: 's3' | 'local' | 'memory';
196
+ bucket?: string;
197
+ prefix?: string;
198
+ path?: string;
199
+ maxSize?: number;
200
+ compress?: boolean;
201
+ };
202
+ logOverflow?: boolean;
203
+ customTruncator?: (data: any, maxSize: number, config: any) => any;
204
+ customOverflowHandler?: (overflowData: any, originalData: any, config: any) => string;
205
+ validateOnRead?: boolean;
206
+ validateOnWrite?: boolean;
207
+ warningThreshold?: number;
208
+ context?: Record<string, any>;
209
+ }
210
+
211
+ /** Body Only Behavior config */
212
+ export interface BodyOnlyBehaviorConfig {
213
+ enabled?: boolean;
214
+ excludeFields?: string[];
215
+ includeFields?: string[];
216
+ applyToRead?: boolean;
217
+ applyToList?: boolean;
218
+ applyToFind?: boolean;
219
+ applyToStream?: boolean;
220
+ preserveArrays?: boolean;
221
+ deepFilter?: boolean;
222
+ customFilter?: (data: any, context: any) => any;
223
+ logFilteredFields?: boolean;
224
+ context?: Record<string, any>;
225
+ }
226
+
227
+ // ============================================================================
228
+ // PLUGIN TYPES
229
+ // ============================================================================
230
+
231
+ /** Plugin function type */
232
+ export type PluginFunction = (database: Database) => Plugin;
233
+
234
+ /** Plugin base interface */
235
+ export interface Plugin {
236
+ name?: string;
237
+ setup?: (database: Database) => Promise<void> | void;
238
+ start?: () => Promise<void> | void;
239
+ stop?: () => Promise<void> | void;
240
+ beforeSetup?: () => Promise<void> | void;
241
+ afterSetup?: () => Promise<void> | void;
242
+ beforeStart?: () => Promise<void> | void;
243
+ afterStart?: () => Promise<void> | void;
244
+ beforeStop?: () => Promise<void> | void;
245
+ afterStop?: () => Promise<void> | void;
246
+ }
247
+
248
+ /** Plugin configuration base */
249
+ export interface PluginConfig {
250
+ enabled?: boolean;
251
+ }
252
+
253
+ /** Audit Plugin config */
254
+ export interface AuditPluginConfig extends PluginConfig {
255
+ trackOperations?: string[];
256
+ includeData?: boolean;
257
+ retentionDays?: number;
258
+ logToConsole?: boolean;
259
+ customLogger?: (logEntry: any) => void;
260
+ }
261
+
262
+ /** Cache Plugin config */
263
+ export interface CachePluginConfig extends PluginConfig {
264
+ type?: 'memory' | 's3';
265
+ ttl?: number;
266
+ maxSize?: number;
267
+ enableCompression?: boolean;
268
+ storageClass?: string;
269
+ enableEncryption?: boolean;
270
+ }
271
+
272
+ /** Costs Plugin config */
273
+ export interface CostsPluginConfig extends PluginConfig {
274
+ trackOperations?: boolean;
275
+ trackStorage?: boolean;
276
+ trackRequests?: boolean;
277
+ costThreshold?: number;
278
+ alertOnThreshold?: boolean;
279
+ customPricing?: Record<string, number>;
280
+ }
281
+
282
+ /** Fulltext Plugin config */
283
+ export interface FulltextPluginConfig extends PluginConfig {
284
+ searchableFields?: string[];
285
+ indexOnInsert?: boolean;
286
+ indexOnUpdate?: boolean;
287
+ searchAlgorithm?: 'exact' | 'fuzzy' | 'prefix';
288
+ maxResults?: number;
289
+ }
290
+
291
+ /** Metrics Plugin config */
292
+ export interface MetricsPluginConfig extends PluginConfig {
293
+ trackLatency?: boolean;
294
+ trackThroughput?: boolean;
295
+ trackErrors?: boolean;
296
+ customMetrics?: string[];
297
+ exportToCloudWatch?: boolean;
298
+ }
299
+
300
+ /** Replication Plugin config */
301
+ export interface ReplicationPluginConfig extends PluginConfig {
302
+ replicators?: ReplicatorConfig[];
303
+ }
304
+
305
+ // ============================================================================
306
+ // REPLICATOR TYPES
307
+ // ============================================================================
308
+
309
+ /** Replicator configuration */
310
+ export interface ReplicatorConfig {
311
+ driver: 's3db' | 'sqs' | 'bigquery' | 'postgres';
312
+ config: S3dbReplicatorConfig | SQSReplicatorConfig | BigQueryReplicatorConfig | PostgresReplicatorConfig;
313
+ resources?: string[];
314
+ }
315
+
316
+ /** S3DB Replicator config */
317
+ export interface S3dbReplicatorConfig {
318
+ connectionString: string;
319
+ region?: string;
320
+ accessKeyId?: string;
321
+ secretAccessKey?: string;
322
+ sessionToken?: string;
323
+ createResources?: boolean;
324
+ overwriteExisting?: boolean;
325
+ preservePartitions?: boolean;
326
+ syncMetadata?: boolean;
327
+ batchSize?: number;
328
+ maxConcurrency?: number;
329
+ logProgress?: boolean;
330
+ targetPrefix?: string;
331
+ resourceMapping?: Record<string, string>;
332
+ validateData?: boolean;
333
+ retryAttempts?: number;
334
+ retryDelay?: number;
335
+ }
336
+
337
+ /** SQS Replicator config */
338
+ export interface SQSReplicatorConfig {
339
+ region: string;
340
+ accessKeyId?: string;
341
+ secretAccessKey?: string;
342
+ sessionToken?: string;
343
+ defaultQueueUrl?: string;
344
+ resourceQueues?: Record<string, string>;
345
+ maxRetries?: number;
346
+ retryDelay?: number;
347
+ logMessages?: boolean;
348
+ messageDelaySeconds?: number;
349
+ messageAttributes?: Record<string, any>;
350
+ messageGroupId?: string;
351
+ useFIFO?: boolean;
352
+ batchSize?: number;
353
+ compressMessages?: boolean;
354
+ messageFormat?: 'json' | 'stringified';
355
+ sqsClientOptions?: Record<string, any>;
356
+ }
357
+
358
+ /** BigQuery Replicator config */
359
+ export interface BigQueryReplicatorConfig {
360
+ projectId: string;
361
+ datasetId: string;
362
+ keyFilename?: string;
363
+ credentials?: Record<string, any>;
364
+ tableMapping?: Record<string, string>;
365
+ logOperations?: boolean;
366
+ batchSize?: number;
367
+ maxRetries?: number;
368
+ retryDelay?: number;
369
+ writeDisposition?: 'WRITE_TRUNCATE' | 'WRITE_APPEND' | 'WRITE_EMPTY';
370
+ createDisposition?: 'CREATE_IF_NEEDED' | 'CREATE_NEVER';
371
+ schema?: Record<string, any>[];
372
+ location?: string;
373
+ clustering?: string[];
374
+ partitioning?: {
375
+ type: 'DAY' | 'HOUR' | 'MONTH' | 'YEAR';
376
+ field?: string;
377
+ };
378
+ labels?: Record<string, string>;
379
+ }
380
+
381
+ /** Postgres Replicator config */
382
+ export interface PostgresReplicatorConfig {
383
+ database: string;
384
+ resourceArn: string;
385
+ secretArn: string;
386
+ region?: string;
387
+ tableMapping?: Record<string, string>;
388
+ logOperations?: boolean;
389
+ schema?: string;
390
+ maxRetries?: number;
391
+ retryDelay?: number;
392
+ useUpsert?: boolean;
393
+ conflictColumn?: string;
394
+ }
395
+
396
+ // ============================================================================
397
+ // CACHE TYPES
398
+ // ============================================================================
399
+
400
+ /** Cache configuration */
401
+ export interface CacheConfig {
402
+ type?: 'memory' | 's3';
403
+ ttl?: number;
404
+ maxSize?: number;
405
+ enableCompression?: boolean;
406
+ storageClass?: string;
407
+ enableEncryption?: boolean;
408
+ }
409
+
410
+ /** Memory Cache config */
411
+ export interface MemoryCacheConfig {
412
+ maxSize?: number;
413
+ ttl?: number;
414
+ enableStats?: boolean;
415
+ evictionPolicy?: 'lru' | 'fifo';
416
+ logEvictions?: boolean;
417
+ cleanupInterval?: number;
418
+ caseSensitive?: boolean;
419
+ serializer?: (value: any) => string;
420
+ deserializer?: (str: string) => any;
421
+ enableCompression?: boolean;
422
+ compressionThreshold?: number;
423
+ tags?: Record<string, any>;
424
+ persistent?: boolean;
425
+ persistencePath?: string;
426
+ persistenceInterval?: number;
427
+ }
428
+
429
+ /** S3 Cache config */
430
+ export interface S3CacheConfig {
431
+ bucket: string;
432
+ region?: string;
433
+ accessKeyId?: string;
434
+ secretAccessKey?: string;
435
+ sessionToken?: string;
436
+ prefix?: string;
437
+ ttl?: number;
438
+ enableCompression?: boolean;
439
+ compressionThreshold?: number;
440
+ storageClass?: string;
441
+ enableEncryption?: boolean;
442
+ encryptionAlgorithm?: string;
443
+ kmsKeyId?: string;
444
+ maxConcurrency?: number;
445
+ retryAttempts?: number;
446
+ retryDelay?: number;
447
+ logOperations?: boolean;
448
+ metadata?: Record<string, any>;
449
+ contentType?: string;
450
+ enableVersioning?: boolean;
451
+ maxKeys?: number;
452
+ enableCacheControl?: boolean;
453
+ cacheControl?: string;
454
+ s3ClientOptions?: Record<string, any>;
455
+ enableLocalCache?: boolean;
456
+ localCacheSize?: number;
457
+ localCacheTtl?: number;
458
+ }
459
+
460
+ // ============================================================================
461
+ // EVENT TYPES
462
+ // ============================================================================
463
+
464
+ /** Event payload for S3 metadata limit warnings */
465
+ export interface ExceedsLimitEvent {
466
+ operation: 'insert' | 'update' | 'upsert';
467
+ id?: string;
468
+ totalSize: number;
469
+ limit: number;
470
+ excess: number;
471
+ data: any;
52
472
  }
53
473
 
54
- export class S3db {
55
- constructor(config?: S3dbConfig);
474
+ /** Event payload for data truncation */
475
+ export interface TruncateEvent {
476
+ operation: 'insert' | 'update' | 'upsert';
477
+ id?: string;
478
+ fieldName: string;
479
+ originalLength: number;
480
+ truncatedLength: number;
481
+ data: any;
482
+ }
483
+
484
+ /** Event payload for overflow handling */
485
+ export interface OverflowEvent {
486
+ operation: 'insert' | 'update' | 'upsert';
487
+ id?: string;
488
+ strategy: 'truncate' | 'split' | 'reject';
489
+ originalSize: number;
490
+ maxSize: number;
491
+ data: any;
492
+ }
493
+
494
+ /** Definition change event */
495
+ export interface DefinitionChangeEvent {
496
+ type: 'new' | 'changed' | 'deleted';
497
+ resourceName: string;
498
+ currentHash?: string;
499
+ savedHash?: string;
500
+ fromVersion?: string;
501
+ toVersion?: string;
502
+ deletedVersion?: string;
503
+ }
504
+
505
+ // ============================================================================
506
+ // MAIN CLASSES
507
+ // ============================================================================
508
+
509
+ /** Main Database class */
510
+ export class Database extends EventEmitter {
511
+ constructor(options?: DatabaseConfig);
512
+
513
+ // Properties
514
+ version: string;
515
+ s3dbVersion: string;
516
+ resources: Record<string, Resource>;
517
+ savedMetadata: any;
518
+ options: DatabaseConfig;
519
+ verbose: boolean;
520
+ parallelism: number;
521
+ plugins: Plugin[];
522
+ pluginList: Plugin[];
523
+ cache: CacheConfig;
524
+ passphrase: string;
525
+ versioningEnabled: boolean;
526
+ client: Client;
527
+ bucket: string;
528
+ keyPrefix: string;
56
529
 
57
530
  // Connection methods
58
531
  connect(): Promise<void>;
59
- disconnect(): Promise<void>;
60
532
  isConnected(): boolean;
61
533
 
62
534
  // Resource methods
63
- resource(name: string, config?: ResourceConfig): Resource;
535
+ createResource(config: ResourceConfig): Promise<Resource>;
536
+ resource(name: string): Resource;
64
537
  getResource(name: string): Resource;
65
538
  listResources(): Promise<string[]>;
66
- deleteResource(name: string, options?: DeleteOptions): Promise<void>;
539
+
540
+ // Plugin methods
541
+ startPlugins(): Promise<void>;
542
+ usePlugin(plugin: Plugin | PluginFunction, name?: string): Promise<void>;
67
543
 
68
544
  // Utility methods
69
- getVersion(): string;
70
- getConfig(): S3dbConfig;
545
+ generateDefinitionHash(definition: any, behavior?: string): string;
546
+ getNextVersion(versions?: Record<string, any>): string;
547
+ detectDefinitionChanges(savedMetadata: any): DefinitionChangeEvent[];
548
+ resourceExists(name: string): boolean;
549
+ resourceExistsWithSameHash(config: { name: string; attributes: any; behavior?: string; options?: any }): boolean;
550
+ uploadMetadataFile(): Promise<void>;
551
+ blankMetadataStructure(): any;
552
+
553
+ // Configuration
554
+ get config(): DatabaseConfig;
555
+
556
+ // Events
557
+ on(event: 'connected', handler: (date: Date) => void): this;
558
+ on(event: 'resourceDefinitionsChanged', handler: (data: { changes: DefinitionChangeEvent[]; metadata: any }) => void): this;
559
+ on(event: string, handler: (...args: any[]) => void): this;
71
560
  }
72
561
 
73
- export class Resource {
74
- constructor(database: S3db, name: string, config?: ResourceConfig);
562
+ /** Main S3db class (alias for Database) */
563
+ export class S3db extends Database {}
564
+
565
+ /** Resource class */
566
+ export class Resource extends EventEmitter {
567
+ constructor(config: ResourceConfig);
568
+
569
+ // Properties
570
+ name: string;
571
+ client: Client;
572
+ version: string;
573
+ behavior: BehaviorName;
574
+ observers: any[];
575
+ parallelism: number;
576
+ passphrase: string;
577
+ versioningEnabled: boolean;
578
+ idGenerator: Function;
579
+ config: {
580
+ cache: boolean | CacheConfig;
581
+ hooks: HookConfig;
582
+ paranoid: boolean;
583
+ timestamps: boolean;
584
+ partitions: Record<string, PartitionConfig>;
585
+ autoDecrypt: boolean;
586
+ allNestedObjectsOptional: boolean;
587
+ };
588
+ hooks: {
589
+ preInsert: Function[];
590
+ afterInsert: Function[];
591
+ preUpdate: Function[];
592
+ afterUpdate: Function[];
593
+ preDelete: Function[];
594
+ afterDelete: Function[];
595
+ };
596
+ attributes: Record<string, any>;
75
597
 
76
598
  // CRUD operations
77
599
  insert(data: any, options?: InsertOptions): Promise<any>;
78
- insertMany(data: any[], options?: InsertOptions): Promise<any[]>;
79
- find(query?: any, options?: QueryOptions): Promise<any[]>;
80
- findOne(query?: any, options?: QueryOptions): Promise<any | null>;
81
- update(query: any, data: any, options?: UpdateOptions): Promise<number>;
82
- delete(query: any, options?: DeleteOptions): Promise<number>;
600
+ insertMany(objects: any[]): Promise<any[]>;
601
+ get(id: string): Promise<any>;
602
+ exists(id: string): Promise<boolean>;
603
+ update(id: string, attributes: any): Promise<any>;
604
+ upsert(data: any): Promise<any>;
605
+ delete(id: string): Promise<void>;
606
+ deleteMany(ids: string[]): Promise<void>;
607
+ deleteAll(): Promise<void>;
608
+ deleteAllData(): Promise<void>;
609
+
610
+ // List and count operations
611
+ listIds(options?: ListOptions): Promise<string[]>;
612
+ list(options?: ListOptions): Promise<any[]>;
613
+ listMain(options?: { limit?: number; offset?: number }): Promise<any[]>;
614
+ listPartition(options: { partition: string; partitionValues: Record<string, any>; limit?: number; offset?: number }): Promise<any[]>;
615
+ count(options?: CountOptions): Promise<number>;
616
+
617
+ // Batch operations
618
+ getMany(ids: string[]): Promise<any[]>;
619
+ getAll(): Promise<any[]>;
620
+
621
+ // Pagination
622
+ page(options?: PageOptions): Promise<{ data: any[]; total?: number; offset: number; size: number; hasMore: boolean }>;
83
623
 
84
624
  // Stream operations
85
- createReadStream(query?: any, options?: QueryOptions): NodeJS.ReadableStream;
86
- createWriteStream(options?: InsertOptions): NodeJS.WritableStream;
625
+ readable(): Promise<NodeJS.ReadableStream>;
626
+ writable(): Promise<NodeJS.WritableStream>;
87
627
 
88
- // Schema operations
89
- getSchema(): any;
90
- setSchema(schema: any): void;
91
- validate(data: any): boolean;
628
+ // Content operations
629
+ setContent(options: { id: string; buffer: Buffer; contentType?: string }): Promise<void>;
630
+ content(id: string): Promise<Buffer>;
631
+ hasContent(id: string): Promise<boolean>;
632
+ deleteContent(id: string): Promise<void>;
633
+
634
+ // Schema and validation
635
+ updateAttributes(newAttributes: Record<string, any>): void;
636
+ validate(data: any): Promise<boolean>;
637
+ validatePartitions(): void;
92
638
 
93
639
  // Partition operations
94
- getPartitions(): string[];
95
- setPartitions(partitions: string[]): void;
640
+ getPartitionKey(options: { partitionName: string; id: string; data: any }): string;
641
+ getFromPartition(options: { id: string; partitionName: string; partitionValues?: Record<string, any> }): Promise<any>;
642
+
643
+ // Query operations
644
+ query(filter?: any, options?: QueryOptions): Promise<any[]>;
645
+
646
+ // Versioning operations
647
+ createHistoricalVersion(id: string, data: any): Promise<void>;
648
+ applyVersionMapping(data: any, fromVersion: string, toVersion: string): any;
649
+
650
+ // Hook operations
651
+ addHook(event: string, fn: Function): void;
652
+ executeHooks(event: string, data: any): Promise<any>;
653
+
654
+ // Utility methods
655
+ getResourceKey(id: string): string;
656
+ getDefinitionHash(): string;
657
+ export(): any;
658
+ get options(): any;
659
+
660
+ // Events
661
+ on(event: 'exceedsLimit', handler: (event: ExceedsLimitEvent) => void): this;
662
+ on(event: 'truncate', handler: (event: TruncateEvent) => void): this;
663
+ on(event: 'overflow', handler: (event: OverflowEvent) => void): this;
664
+ on(event: string, handler: (...args: any[]) => void): this;
665
+ }
666
+
667
+ /** Client class */
668
+ export class Client extends EventEmitter {
669
+ constructor(config: {
670
+ verbose?: boolean;
671
+ id?: string;
672
+ AwsS3Client?: any;
673
+ connectionString: string;
674
+ parallelism?: number;
675
+ });
676
+
677
+ // Properties
678
+ verbose: boolean;
679
+ id: string;
680
+ parallelism: number;
681
+ config: ConnectionString;
682
+ client: any;
683
+
684
+ // S3 operations
685
+ putObject(options: { key: string; metadata?: Record<string, any>; contentType?: string; body?: Buffer; contentEncoding?: string; contentLength?: number }): Promise<any>;
686
+ getObject(key: string): Promise<any>;
687
+ headObject(key: string): Promise<any>;
688
+ copyObject(options: { from: string; to: string }): Promise<any>;
689
+ exists(key: string): Promise<boolean>;
690
+ deleteObject(key: string): Promise<any>;
691
+ deleteObjects(keys: string[]): Promise<any>;
692
+ deleteAll(options?: { prefix?: string }): Promise<any>;
693
+ moveObject(options: { from: string; to: string }): Promise<any>;
694
+ moveAllObjects(options: { prefixFrom: string; prefixTo: string }): Promise<any>;
96
695
 
97
- // Behavior operations
98
- getBehaviors(): string[];
99
- setBehaviors(behaviors: string[]): void;
696
+ // List operations
697
+ listObjects(options?: { prefix?: string; maxKeys?: number; continuationToken?: string }): Promise<any>;
698
+ count(options?: { prefix?: string }): Promise<number>;
699
+ getAllKeys(options?: { prefix?: string }): Promise<string[]>;
700
+ getContinuationTokenAfterOffset(params?: { prefix?: string; offset?: number; maxKeys?: number; continuationToken?: string }): Promise<string | null>;
701
+ getKeysPage(params?: { prefix?: string; offset?: number; amount?: number; continuationToken?: string }): Promise<{ keys: string[]; continuationToken?: string }>;
100
702
 
101
703
  // Utility methods
102
- getName(): string;
103
- getConfig(): ResourceConfig;
704
+ createClient(): any;
705
+ sendCommand(command: any): Promise<any>;
706
+ errorProxy(error: any, data: any): Error;
707
+
708
+ // Events
709
+ on(event: 'command.request', handler: (commandName: string, input: any) => void): this;
710
+ on(event: 'command.response', handler: (commandName: string, response: any, input: any) => void): this;
711
+ on(event: 'putObject', handler: (response: any, options: any) => void): this;
712
+ on(event: 'getObject', handler: (response: any, options: any) => void): this;
713
+ on(event: 'headObject', handler: (response: any, options: any) => void): this;
714
+ on(event: 'copyObject', handler: (response: any, options: any) => void): this;
715
+ on(event: string, handler: (...args: any[]) => void): this;
104
716
  }
105
717
 
718
+ /** Connection String class */
106
719
  export class ConnectionString {
107
720
  constructor(connectionString: string);
108
- parse(): S3dbConfig;
721
+ parse(): DatabaseConfig;
109
722
  toString(): string;
723
+ bucket: string;
724
+ region: string;
725
+ accessKeyId?: string;
726
+ secretAccessKey?: string;
727
+ sessionToken?: string;
728
+ endpoint?: string;
729
+ forcePathStyle?: boolean;
730
+ keyPrefix?: string;
110
731
  }
111
732
 
733
+ /** Schema class */
734
+ export class Schema {
735
+ constructor(attributes?: Record<string, any>, options?: any);
736
+ validate(data: any, options?: any): boolean;
737
+ migrate(data: any, fromVersion: string, toVersion: string): any;
738
+ export(): any;
739
+ import(data: any): void;
740
+ applyHooksActions(data: any, action: string): any;
741
+ preprocessAttributesForValidation(attributes: any, options?: any): any;
742
+ toArray(value: any): string;
743
+ fromArray(value: string): any;
744
+ toJSON(value: any): string;
745
+ fromJSON(value: string): any;
746
+ toNumber(value: any): number;
747
+ toBool(value: any): boolean;
748
+ fromBool(value: any): boolean;
749
+ extractObjectKeys(obj: any): string[];
750
+ }
751
+
752
+ /** Validator class */
112
753
  export class Validator {
113
754
  constructor(schema?: any);
114
755
  validate(data: any): boolean;
115
756
  getErrors(): string[];
116
757
  }
117
758
 
118
- // Error classes
119
- export class S3dbError extends Error {
759
+ /** Cache base class */
760
+ export class Cache {
761
+ constructor(config?: any);
762
+ get(key: string): Promise<any>;
763
+ set(key: string, value: any, ttl?: number): Promise<void>;
764
+ delete(key: string): Promise<void>;
765
+ clear(): Promise<void>;
766
+ getStats(): any;
767
+ }
768
+
769
+ /** Memory Cache class */
770
+ export class MemoryCache extends Cache {
771
+ constructor(config?: MemoryCacheConfig);
772
+ }
773
+
774
+ /** S3 Cache class */
775
+ export class S3Cache extends Cache {
776
+ constructor(config?: S3CacheConfig);
777
+ }
778
+
779
+ // ============================================================================
780
+ // PLUGIN CLASSES
781
+ // ============================================================================
782
+
783
+ /** Plugin base class */
784
+ export class PluginBase extends EventEmitter implements Plugin {
785
+ constructor(options?: any);
786
+ name: string;
787
+ options: any;
788
+ database?: Database;
789
+
790
+ setup(database: Database): Promise<void>;
791
+ start(): Promise<void>;
792
+ stop(): Promise<void>;
793
+ beforeSetup(): Promise<void>;
794
+ afterSetup(): Promise<void>;
795
+ beforeStart(): Promise<void>;
796
+ afterStart(): Promise<void>;
797
+ beforeStop(): Promise<void>;
798
+ afterStop(): Promise<void>;
799
+
800
+ addHook(resourceName: string, event: string, fn: Function): void;
801
+ removeHook(resourceName: string, event: string, fn: Function): void;
802
+ wrapResourceMethod(resourceName: string, methodName: string, wrapper: Function): void;
803
+
804
+ extractPartitionValues(data: any, resource: Resource): Record<string, any>;
805
+ getNestedFieldValue(data: any, fieldPath: string): any;
806
+ }
807
+
808
+ /** Audit Plugin */
809
+ export class AuditPlugin extends PluginBase {
810
+ constructor(config?: AuditPluginConfig);
811
+ logAudit(operation: string, resourceName: string, recordId: string, data?: any, oldData?: any): Promise<void>;
812
+ getAuditLogs(filters?: any): Promise<any[]>;
813
+ getAuditStats(filters?: any): Promise<any>;
814
+ }
815
+
816
+ /** Cache Plugin */
817
+ export class CachePlugin extends PluginBase {
818
+ constructor(config?: CachePluginConfig);
819
+ cacheKeyFor(action: string, params?: any): string;
820
+ getCacheStats(): any;
821
+ clearCache(): Promise<void>;
822
+ warmCache(resourceName: string): Promise<void>;
823
+ }
824
+
825
+ /** Costs Plugin */
826
+ export class CostsPlugin extends PluginBase {
827
+ constructor(config?: CostsPluginConfig);
828
+ trackOperation(operation: string, size: number, metadata?: any): void;
829
+ getCosts(): any;
830
+ resetCosts(): void;
831
+ }
832
+
833
+ /** Fulltext Plugin */
834
+ export class FulltextPlugin extends PluginBase {
835
+ constructor(config?: FulltextPluginConfig);
836
+ search(query: string, options?: any): Promise<any[]>;
837
+ indexResource(resourceName: string): Promise<void>;
838
+ clearIndex(resourceName?: string): Promise<void>;
839
+ getIndexStats(): any;
840
+ }
841
+
842
+ /** Metrics Plugin */
843
+ export class MetricsPlugin extends PluginBase {
844
+ constructor(config?: MetricsPluginConfig);
845
+ trackOperation(operation: string, duration: number, success: boolean): void;
846
+ getMetrics(): any;
847
+ getErrorLogs(): any[];
848
+ getPerformanceLogs(): any[];
849
+ getStats(): any;
850
+ }
851
+
852
+ /** Replication Plugin */
853
+ export class ReplicationPlugin extends PluginBase {
854
+ constructor(config?: ReplicationPluginConfig);
855
+ replicate(operation: string, resourceName: string, data: any, oldData?: any): Promise<void>;
856
+ getReplicationStats(): any;
857
+ getReplicationLogs(filters?: any): Promise<any[]>;
858
+ retryFailedReplications(): Promise<void>;
859
+ syncAllData(targetName: string): Promise<void>;
860
+ }
861
+
862
+ // ============================================================================
863
+ // STREAM CLASSES
864
+ // ============================================================================
865
+
866
+ /** Resource Reader Stream */
867
+ export class ResourceReader extends NodeJS.ReadableStream {
868
+ constructor(resource: Resource, options?: any);
869
+ }
870
+
871
+ /** Resource Writer Stream */
872
+ export class ResourceWriter extends NodeJS.WritableStream {
873
+ constructor(resource: Resource, options?: any);
874
+ }
875
+
876
+ /** Resource IDs Reader Stream */
877
+ export class ResourceIdsReader extends NodeJS.ReadableStream {
878
+ constructor(resource: Resource, options?: any);
879
+ }
880
+
881
+ /** Resource IDs Page Reader Stream */
882
+ export class ResourceIdsPageReader extends NodeJS.ReadableStream {
883
+ constructor(resource: Resource, options?: any);
884
+ }
885
+
886
+ // ============================================================================
887
+ // ERROR CLASSES
888
+ // ============================================================================
889
+
890
+ /** Base S3db error */
891
+ export class BaseError extends Error {
120
892
  constructor(message: string, code?: string);
121
893
  }
122
894
 
123
- export class ValidationError extends S3dbError {
124
- constructor(message: string, errors?: string[]);
895
+ /** Not Found error */
896
+ export class NotFound extends BaseError {
897
+ constructor(message: string);
898
+ }
899
+
900
+ /** No Such Key error */
901
+ export class NoSuchKey extends BaseError {
902
+ constructor(message: string);
903
+ }
904
+
905
+ /** No Such Bucket error */
906
+ export class NoSuchBucket extends BaseError {
907
+ constructor(message: string);
908
+ }
909
+
910
+ /** Unknown Error */
911
+ export class UnknownError extends BaseError {
912
+ constructor(message: string);
125
913
  }
126
914
 
127
- export class ConnectionError extends S3dbError {
915
+ /** Missing Metadata error */
916
+ export class MissingMetadata extends BaseError {
128
917
  constructor(message: string);
129
918
  }
130
919
 
131
- // Default export
920
+ /** Invalid Resource Item error */
921
+ export class InvalidResourceItem extends BaseError {
922
+ constructor(message: string);
923
+ }
924
+
925
+ // ============================================================================
926
+ // UTILITY FUNCTIONS
927
+ // ============================================================================
928
+
929
+ /** Convert stream to string */
930
+ export function streamToString(stream: NodeJS.ReadableStream): Promise<string>;
931
+
932
+ /** Encrypt data */
933
+ export function encrypt(data: any, passphrase: string): Promise<string>;
934
+
935
+ /** Decrypt data */
936
+ export function decrypt(encryptedData: string, passphrase: string): Promise<any>;
937
+
938
+ /** Generate ID */
939
+ export function idGenerator(): string;
940
+
941
+ /** Generate password */
942
+ export function passwordGenerator(length?: number): string;
943
+
944
+ // ============================================================================
945
+ // CONSTANTS
946
+ // ============================================================================
947
+
948
+ /** Available behavior names */
949
+ export const AVAILABLE_BEHAVIORS: BehaviorName[];
950
+
951
+ /** Default behavior name */
952
+ export const DEFAULT_BEHAVIOR: BehaviorName;
953
+
954
+ /** Get behavior implementation */
955
+ export function getBehavior(behaviorName: BehaviorName): any;
956
+
957
+ // ============================================================================
958
+ // DEFAULT EXPORT
959
+ // ============================================================================
960
+
132
961
  export default S3db;
133
962
  }