s3db.js 6.2.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/PLUGINS.md +2724 -0
  2. package/README.md +372 -469
  3. package/UNLICENSE +24 -0
  4. package/dist/s3db.cjs.js +30057 -18387
  5. package/dist/s3db.cjs.min.js +1 -1
  6. package/dist/s3db.d.ts +373 -72
  7. package/dist/s3db.es.js +30043 -18384
  8. package/dist/s3db.es.min.js +1 -1
  9. package/dist/s3db.iife.js +29730 -18061
  10. package/dist/s3db.iife.min.js +1 -1
  11. package/package.json +44 -69
  12. package/src/behaviors/body-only.js +110 -0
  13. package/src/behaviors/body-overflow.js +153 -0
  14. package/src/behaviors/enforce-limits.js +195 -0
  15. package/src/behaviors/index.js +39 -0
  16. package/src/behaviors/truncate-data.js +204 -0
  17. package/src/behaviors/user-managed.js +147 -0
  18. package/src/client.class.js +515 -0
  19. package/src/concerns/base62.js +61 -0
  20. package/src/concerns/calculator.js +204 -0
  21. package/src/concerns/crypto.js +142 -0
  22. package/src/concerns/id.js +8 -0
  23. package/src/concerns/index.js +5 -0
  24. package/src/concerns/try-fn.js +151 -0
  25. package/src/connection-string.class.js +75 -0
  26. package/src/database.class.js +599 -0
  27. package/src/errors.js +261 -0
  28. package/src/index.js +17 -0
  29. package/src/plugins/audit.plugin.js +442 -0
  30. package/src/plugins/cache/cache.class.js +53 -0
  31. package/src/plugins/cache/index.js +6 -0
  32. package/src/plugins/cache/memory-cache.class.js +164 -0
  33. package/src/plugins/cache/s3-cache.class.js +189 -0
  34. package/src/plugins/cache.plugin.js +275 -0
  35. package/src/plugins/consumers/index.js +24 -0
  36. package/src/plugins/consumers/rabbitmq-consumer.js +56 -0
  37. package/src/plugins/consumers/sqs-consumer.js +102 -0
  38. package/src/plugins/costs.plugin.js +81 -0
  39. package/src/plugins/fulltext.plugin.js +473 -0
  40. package/src/plugins/index.js +12 -0
  41. package/src/plugins/metrics.plugin.js +603 -0
  42. package/src/plugins/plugin.class.js +210 -0
  43. package/src/plugins/plugin.obj.js +13 -0
  44. package/src/plugins/queue-consumer.plugin.js +134 -0
  45. package/src/plugins/replicator.plugin.js +769 -0
  46. package/src/plugins/replicators/base-replicator.class.js +85 -0
  47. package/src/plugins/replicators/bigquery-replicator.class.js +328 -0
  48. package/src/plugins/replicators/index.js +44 -0
  49. package/src/plugins/replicators/postgres-replicator.class.js +427 -0
  50. package/src/plugins/replicators/s3db-replicator.class.js +352 -0
  51. package/src/plugins/replicators/sqs-replicator.class.js +427 -0
  52. package/src/resource.class.js +2626 -0
  53. package/src/s3db.d.ts +1263 -0
  54. package/src/schema.class.js +706 -0
  55. package/src/stream/index.js +16 -0
  56. package/src/stream/resource-ids-page-reader.class.js +10 -0
  57. package/src/stream/resource-ids-reader.class.js +63 -0
  58. package/src/stream/resource-reader.class.js +81 -0
  59. package/src/stream/resource-writer.class.js +92 -0
  60. package/src/validator.class.js +97 -0
package/dist/s3db.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  declare module 's3db.js' {
2
+ import { EventEmitter } from 'events';
3
+ import { Readable, Writable } from 'stream';
4
+
2
5
  // ============================================================================
3
6
  // CORE TYPES
4
7
  // ============================================================================
@@ -17,8 +20,8 @@ declare module 's3db.js' {
17
20
  parallelism?: number | string;
18
21
  passphrase?: string;
19
22
  versioningEnabled?: boolean;
20
- cache?: CacheConfig;
21
- plugins?: Plugin[] | PluginFunction[];
23
+ cache?: CacheConfig | boolean;
24
+ plugins?: (PluginInterface | PluginFunction)[];
22
25
  client?: Client;
23
26
  }
24
27
 
@@ -26,8 +29,9 @@ declare module 's3db.js' {
26
29
  export interface ResourceConfig {
27
30
  name: string;
28
31
  client: Client;
32
+ database?: Database;
29
33
  version?: string;
30
- attributes?: Record<string, any>;
34
+ attributes: Record<string, any>;
31
35
  behavior?: BehaviorName;
32
36
  passphrase?: string;
33
37
  parallelism?: number;
@@ -42,6 +46,7 @@ declare module 's3db.js' {
42
46
  idGenerator?: Function | number;
43
47
  idSize?: number;
44
48
  versioningEnabled?: boolean;
49
+ map?: any;
45
50
  }
46
51
 
47
52
  /** Partition configuration */
@@ -52,11 +57,11 @@ declare module 's3db.js' {
52
57
 
53
58
  /** Hook configuration */
54
59
  export interface HookConfig {
55
- preInsert?: Function[];
60
+ beforeInsert?: Function[];
56
61
  afterInsert?: Function[];
57
- preUpdate?: Function[];
62
+ beforeUpdate?: Function[];
58
63
  afterUpdate?: Function[];
59
- preDelete?: Function[];
64
+ beforeDelete?: Function[];
60
65
  afterDelete?: Function[];
61
66
  }
62
67
 
@@ -114,7 +119,7 @@ declare module 's3db.js' {
114
119
  export type BehaviorName =
115
120
  | 'user-managed'
116
121
  | 'enforce-limits'
117
- | 'data-truncate'
122
+ | 'truncate-data'
118
123
  | 'body-overflow'
119
124
  | 'body-only';
120
125
 
@@ -158,9 +163,11 @@ declare module 's3db.js' {
158
163
  /** Data Truncate Behavior config */
159
164
  export interface DataTruncateBehaviorConfig {
160
165
  enabled?: boolean;
166
+ truncateIndicator?: string;
167
+ priorityFields?: string[];
168
+ preserveStructure?: boolean;
161
169
  fieldLimits?: Record<string, number>;
162
170
  defaultLimit?: number;
163
- truncateIndicator?: string;
164
171
  truncateMode?: 'end' | 'start' | 'middle';
165
172
  preserveWords?: boolean;
166
173
  preserveSentences?: boolean;
@@ -184,12 +191,14 @@ declare module 's3db.js' {
184
191
  /** Body Overflow Behavior config */
185
192
  export interface BodyOverflowBehaviorConfig {
186
193
  enabled?: boolean;
194
+ metadataReserve?: number;
195
+ priorityFields?: string[];
196
+ preserveOrder?: boolean;
187
197
  maxBodySize?: number;
188
198
  overflowStrategy?: 'truncate' | 'split' | 'reject';
189
199
  truncateMode?: 'end' | 'start' | 'middle';
190
200
  truncateIndicator?: string;
191
201
  preserveStructure?: boolean;
192
- priorityFields?: string[];
193
202
  overflowFields?: string[];
194
203
  overflowStorage?: {
195
204
  type?: 's3' | 'local' | 'memory';
@@ -229,10 +238,10 @@ declare module 's3db.js' {
229
238
  // ============================================================================
230
239
 
231
240
  /** Plugin function type */
232
- export type PluginFunction = (database: Database) => Plugin;
241
+ export type PluginFunction = (database: Database) => PluginInterface;
233
242
 
234
243
  /** Plugin base interface */
235
- export interface Plugin {
244
+ export interface PluginInterface {
236
245
  name?: string;
237
246
  setup?: (database: Database) => Promise<void> | void;
238
247
  start?: () => Promise<void> | void;
@@ -297,11 +306,61 @@ declare module 's3db.js' {
297
306
  exportToCloudWatch?: boolean;
298
307
  }
299
308
 
300
- /** Replication Plugin config */
301
- export interface ReplicationPluginConfig extends PluginConfig {
309
+ /** Queue Consumer Plugin config */
310
+ export interface QueueConsumerPluginConfig extends PluginConfig {
311
+ consumers?: QueueConsumerConfig[];
312
+ }
313
+
314
+ /** Replicator Plugin config */
315
+ export interface ReplicatorPluginConfig extends PluginConfig {
302
316
  replicators?: ReplicatorConfig[];
303
317
  }
304
318
 
319
+ // ============================================================================
320
+ // QUEUE CONSUMER TYPES
321
+ // ============================================================================
322
+
323
+ /** Queue Consumer configuration */
324
+ export interface QueueConsumerConfig {
325
+ driver: 'sqs' | 'rabbitmq';
326
+ config: SQSConsumerConfig | RabbitMQConsumerConfig;
327
+ resources?: string[];
328
+ }
329
+
330
+ /** SQS Consumer config */
331
+ export interface SQSConsumerConfig {
332
+ region: string;
333
+ accessKeyId?: string;
334
+ secretAccessKey?: string;
335
+ sessionToken?: string;
336
+ queueUrl: string;
337
+ maxNumberOfMessages?: number;
338
+ waitTimeSeconds?: number;
339
+ visibilityTimeout?: number;
340
+ messageRetentionPeriod?: number;
341
+ maxReceiveCount?: number;
342
+ deadLetterQueueUrl?: string;
343
+ logMessages?: boolean;
344
+ autoDeleteMessages?: boolean;
345
+ sqsClientOptions?: Record<string, any>;
346
+ }
347
+
348
+ /** RabbitMQ Consumer config */
349
+ export interface RabbitMQConsumerConfig {
350
+ connectionUrl: string;
351
+ queueName: string;
352
+ exchangeName?: string;
353
+ routingKey?: string;
354
+ durable?: boolean;
355
+ autoDelete?: boolean;
356
+ exclusive?: boolean;
357
+ arguments?: Record<string, any>;
358
+ prefetch?: number;
359
+ autoAck?: boolean;
360
+ logMessages?: boolean;
361
+ connectionOptions?: Record<string, any>;
362
+ }
363
+
305
364
  // ============================================================================
306
365
  // REPLICATOR TYPES
307
366
  // ============================================================================
@@ -518,9 +577,9 @@ declare module 's3db.js' {
518
577
  options: DatabaseConfig;
519
578
  verbose: boolean;
520
579
  parallelism: number;
521
- plugins: Plugin[];
522
- pluginList: Plugin[];
523
- cache: CacheConfig;
580
+ plugins: Record<string, PluginInterface>;
581
+ pluginList: PluginInterface[];
582
+ cache: CacheConfig | boolean;
524
583
  passphrase: string;
525
584
  versioningEnabled: boolean;
526
585
  client: Client;
@@ -529,33 +588,51 @@ declare module 's3db.js' {
529
588
 
530
589
  // Connection methods
531
590
  connect(): Promise<void>;
591
+ disconnect(): Promise<void>;
532
592
  isConnected(): boolean;
533
593
 
534
594
  // Resource methods
535
595
  createResource(config: ResourceConfig): Promise<Resource>;
536
596
  resource(name: string): Resource;
537
- getResource(name: string): Resource;
538
- listResources(): Promise<string[]>;
597
+ getResource(name: string): Promise<Resource>;
598
+ listResources(): Promise<Array<{ name: string }>>;
599
+ resourceExists(name: string): boolean;
600
+ resourceExistsWithSameHash(config: {
601
+ name: string;
602
+ attributes: any;
603
+ behavior?: string;
604
+ partitions?: Record<string, PartitionConfig>;
605
+ options?: any;
606
+ }): { exists: boolean; sameHash: boolean; hash: string | null; existingHash?: string };
539
607
 
540
608
  // Plugin methods
541
609
  startPlugins(): Promise<void>;
542
- usePlugin(plugin: Plugin | PluginFunction, name?: string): Promise<void>;
610
+ usePlugin(plugin: PluginInterface | PluginFunction, name?: string): Promise<PluginInterface>;
543
611
 
544
612
  // Utility methods
545
613
  generateDefinitionHash(definition: any, behavior?: string): string;
546
614
  getNextVersion(versions?: Record<string, any>): string;
547
615
  detectDefinitionChanges(savedMetadata: any): DefinitionChangeEvent[];
548
- resourceExists(name: string): boolean;
549
- resourceExistsWithSameHash(config: { name: string; attributes: any; behavior?: string; options?: any }): boolean;
550
616
  uploadMetadataFile(): Promise<void>;
551
617
  blankMetadataStructure(): any;
552
618
 
553
619
  // Configuration
554
- get config(): DatabaseConfig;
620
+ get config(): {
621
+ version: string;
622
+ s3dbVersion: string;
623
+ bucket: string;
624
+ keyPrefix: string;
625
+ parallelism: number;
626
+ verbose: boolean;
627
+ };
555
628
 
556
629
  // Events
557
630
  on(event: 'connected', handler: (date: Date) => void): this;
631
+ on(event: 'disconnected', handler: (date: Date) => void): this;
632
+ on(event: 'metadataUploaded', handler: (metadata: any) => void): this;
558
633
  on(event: 'resourceDefinitionsChanged', handler: (data: { changes: DefinitionChangeEvent[]; metadata: any }) => void): this;
634
+ on(event: 's3db.resourceCreated', handler: (name: string) => void): this;
635
+ on(event: 's3db.resourceUpdated', handler: (name: string) => void): this;
559
636
  on(event: string, handler: (...args: any[]) => void): this;
560
637
  }
561
638
 
@@ -569,6 +646,7 @@ declare module 's3db.js' {
569
646
  // Properties
570
647
  name: string;
571
648
  client: Client;
649
+ database?: Database;
572
650
  version: string;
573
651
  behavior: BehaviorName;
574
652
  observers: any[];
@@ -586,17 +664,19 @@ declare module 's3db.js' {
586
664
  allNestedObjectsOptional: boolean;
587
665
  };
588
666
  hooks: {
589
- preInsert: Function[];
667
+ beforeInsert: Function[];
590
668
  afterInsert: Function[];
591
- preUpdate: Function[];
669
+ beforeUpdate: Function[];
592
670
  afterUpdate: Function[];
593
- preDelete: Function[];
671
+ beforeDelete: Function[];
594
672
  afterDelete: Function[];
595
673
  };
596
674
  attributes: Record<string, any>;
675
+ schema: Schema;
676
+ map: any;
597
677
 
598
678
  // CRUD operations
599
- insert(data: any, options?: InsertOptions): Promise<any>;
679
+ insert(data: any): Promise<any>;
600
680
  insertMany(objects: any[]): Promise<any[]>;
601
681
  get(id: string): Promise<any>;
602
682
  exists(id: string): Promise<boolean>;
@@ -619,11 +699,26 @@ declare module 's3db.js' {
619
699
  getAll(): Promise<any[]>;
620
700
 
621
701
  // Pagination
622
- page(options?: PageOptions): Promise<{ data: any[]; total?: number; offset: number; size: number; hasMore: boolean }>;
702
+ page(options?: PageOptions): Promise<{
703
+ items: any[];
704
+ totalItems?: number;
705
+ page: number;
706
+ pageSize: number;
707
+ totalPages?: number;
708
+ hasMore: boolean;
709
+ _debug: {
710
+ requestedSize: number;
711
+ requestedOffset: number;
712
+ actualItemsReturned: number;
713
+ skipCount: boolean;
714
+ hasTotalItems: boolean;
715
+ error?: string;
716
+ };
717
+ }>;
623
718
 
624
719
  // Stream operations
625
- readable(): Promise<NodeJS.ReadableStream>;
626
- writable(): Promise<NodeJS.WritableStream>;
720
+ readable(): Promise<Readable>;
721
+ writable(): Promise<Writable>;
627
722
 
628
723
  // Content operations
629
724
  setContent(options: { id: string; buffer: Buffer; contentType?: string }): Promise<void>;
@@ -632,8 +727,13 @@ declare module 's3db.js' {
632
727
  deleteContent(id: string): Promise<void>;
633
728
 
634
729
  // Schema and validation
635
- updateAttributes(newAttributes: Record<string, any>): void;
636
- validate(data: any): Promise<boolean>;
730
+ updateAttributes(newAttributes: Record<string, any>): { oldAttributes: Record<string, any>; newAttributes: Record<string, any> };
731
+ validate(data: any): Promise<{
732
+ original: any;
733
+ isValid: boolean;
734
+ errors: any[];
735
+ data: any;
736
+ }>;
637
737
  validatePartitions(): void;
638
738
 
639
739
  // Partition operations
@@ -646,6 +746,7 @@ declare module 's3db.js' {
646
746
  // Versioning operations
647
747
  createHistoricalVersion(id: string, data: any): Promise<void>;
648
748
  applyVersionMapping(data: any, fromVersion: string, toVersion: string): any;
749
+ getSchemaForVersion(version: string): Promise<Schema>;
649
750
 
650
751
  // Hook operations
651
752
  addHook(event: string, fn: Function): void;
@@ -656,11 +757,15 @@ declare module 's3db.js' {
656
757
  getDefinitionHash(): string;
657
758
  export(): any;
658
759
  get options(): any;
760
+ applyDefaults(data: any): any;
659
761
 
660
762
  // Events
661
763
  on(event: 'exceedsLimit', handler: (event: ExceedsLimitEvent) => void): this;
662
764
  on(event: 'truncate', handler: (event: TruncateEvent) => void): this;
663
765
  on(event: 'overflow', handler: (event: OverflowEvent) => void): this;
766
+ on(event: 'versionUpdated', handler: (event: { oldVersion: string; newVersion: string }) => void): this;
767
+ on(event: 'get', handler: (data: any) => void): this;
768
+ on(event: 'page', handler: (result: any) => void): this;
664
769
  on(event: string, handler: (...args: any[]) => void): this;
665
770
  }
666
771
 
@@ -682,28 +787,47 @@ declare module 's3db.js' {
682
787
  client: any;
683
788
 
684
789
  // S3 operations
685
- putObject(options: { key: string; metadata?: Record<string, any>; contentType?: string; body?: Buffer; contentEncoding?: string; contentLength?: number }): Promise<any>;
790
+ putObject(options: {
791
+ key: string;
792
+ metadata?: Record<string, any>;
793
+ contentType?: string;
794
+ body?: Buffer;
795
+ contentEncoding?: string;
796
+ contentLength?: number;
797
+ }): Promise<any>;
686
798
  getObject(key: string): Promise<any>;
687
799
  headObject(key: string): Promise<any>;
688
800
  copyObject(options: { from: string; to: string }): Promise<any>;
689
801
  exists(key: string): Promise<boolean>;
690
802
  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>;
803
+ deleteObjects(keys: string[]): Promise<{ deleted: any[]; notFound: any[] }>;
804
+ deleteAll(options?: { prefix?: string }): Promise<number>;
805
+ moveObject(options: { from: string; to: string }): Promise<boolean>;
806
+ moveAllObjects(options: { prefixFrom: string; prefixTo: string }): Promise<string[]>;
695
807
 
696
808
  // List operations
697
- listObjects(options?: { prefix?: string; maxKeys?: number; continuationToken?: string }): Promise<any>;
809
+ listObjects(options?: {
810
+ prefix?: string;
811
+ maxKeys?: number;
812
+ continuationToken?: string;
813
+ }): Promise<any>;
698
814
  count(options?: { prefix?: string }): Promise<number>;
699
815
  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 }>;
816
+ getContinuationTokenAfterOffset(params?: {
817
+ prefix?: string;
818
+ offset?: number;
819
+ maxKeys?: number;
820
+ continuationToken?: string;
821
+ }): Promise<string | null>;
822
+ getKeysPage(params?: {
823
+ prefix?: string;
824
+ offset?: number;
825
+ amount?: number;
826
+ }): Promise<string[]>;
702
827
 
703
828
  // Utility methods
704
829
  createClient(): any;
705
830
  sendCommand(command: any): Promise<any>;
706
- errorProxy(error: any, data: any): Error;
707
831
 
708
832
  // Events
709
833
  on(event: 'command.request', handler: (commandName: string, input: any) => void): this;
@@ -712,6 +836,15 @@ declare module 's3db.js' {
712
836
  on(event: 'getObject', handler: (response: any, options: any) => void): this;
713
837
  on(event: 'headObject', handler: (response: any, options: any) => void): this;
714
838
  on(event: 'copyObject', handler: (response: any, options: any) => void): this;
839
+ on(event: 'deleteObjects', handler: (report: any, keys: string[]) => void): this;
840
+ on(event: 'deleteAll', handler: (data: { prefix?: string; batch: number; total: number }) => void): this;
841
+ on(event: 'deleteAllComplete', handler: (data: { prefix?: string; totalDeleted: number }) => void): this;
842
+ on(event: 'listObjects', handler: (response: any, options: any) => void): this;
843
+ on(event: 'count', handler: (count: number, options: any) => void): this;
844
+ on(event: 'getAllKeys', handler: (keys: string[], options: any) => void): this;
845
+ on(event: 'getContinuationTokenAfterOffset', handler: (token: string | null, params: any) => void): this;
846
+ on(event: 'getKeysPage', handler: (keys: string[], params: any) => void): this;
847
+ on(event: 'moveAllObjects', handler: (result: { results: string[]; errors: any[] }, options: any) => void): this;
715
848
  on(event: string, handler: (...args: any[]) => void): this;
716
849
  }
717
850
 
@@ -732,8 +865,16 @@ declare module 's3db.js' {
732
865
 
733
866
  /** Schema class */
734
867
  export class Schema {
735
- constructor(attributes?: Record<string, any>, options?: any);
736
- validate(data: any, options?: any): boolean;
868
+ constructor(config: {
869
+ name?: string;
870
+ attributes?: Record<string, any>;
871
+ passphrase?: string;
872
+ version?: string;
873
+ options?: any;
874
+ map?: any;
875
+ });
876
+
877
+ validate(data: any, options?: any): Promise<boolean | any[]>;
737
878
  migrate(data: any, fromVersion: string, toVersion: string): any;
738
879
  export(): any;
739
880
  import(data: any): void;
@@ -747,6 +888,8 @@ declare module 's3db.js' {
747
888
  toBool(value: any): boolean;
748
889
  fromBool(value: any): boolean;
749
890
  extractObjectKeys(obj: any): string[];
891
+ unmapper(metadata: any): Promise<any>;
892
+ map: any;
750
893
  }
751
894
 
752
895
  /** Validator class */
@@ -756,6 +899,10 @@ declare module 's3db.js' {
756
899
  getErrors(): string[];
757
900
  }
758
901
 
902
+ // ============================================================================
903
+ // CACHE CLASSES
904
+ // ============================================================================
905
+
759
906
  /** Cache base class */
760
907
  export class Cache {
761
908
  constructor(config?: any);
@@ -773,7 +920,7 @@ declare module 's3db.js' {
773
920
 
774
921
  /** S3 Cache class */
775
922
  export class S3Cache extends Cache {
776
- constructor(config?: S3CacheConfig);
923
+ constructor(config: S3CacheConfig);
777
924
  }
778
925
 
779
926
  // ============================================================================
@@ -781,7 +928,7 @@ declare module 's3db.js' {
781
928
  // ============================================================================
782
929
 
783
930
  /** Plugin base class */
784
- export class PluginBase extends EventEmitter implements Plugin {
931
+ export class Plugin extends EventEmitter implements PluginInterface {
785
932
  constructor(options?: any);
786
933
  name: string;
787
934
  options: any;
@@ -806,7 +953,7 @@ declare module 's3db.js' {
806
953
  }
807
954
 
808
955
  /** Audit Plugin */
809
- export class AuditPlugin extends PluginBase {
956
+ export class AuditPlugin extends Plugin {
810
957
  constructor(config?: AuditPluginConfig);
811
958
  logAudit(operation: string, resourceName: string, recordId: string, data?: any, oldData?: any): Promise<void>;
812
959
  getAuditLogs(filters?: any): Promise<any[]>;
@@ -814,7 +961,7 @@ declare module 's3db.js' {
814
961
  }
815
962
 
816
963
  /** Cache Plugin */
817
- export class CachePlugin extends PluginBase {
964
+ export class CachePlugin extends Plugin {
818
965
  constructor(config?: CachePluginConfig);
819
966
  cacheKeyFor(action: string, params?: any): string;
820
967
  getCacheStats(): any;
@@ -823,7 +970,7 @@ declare module 's3db.js' {
823
970
  }
824
971
 
825
972
  /** Costs Plugin */
826
- export class CostsPlugin extends PluginBase {
973
+ export class CostsPlugin extends Plugin {
827
974
  constructor(config?: CostsPluginConfig);
828
975
  trackOperation(operation: string, size: number, metadata?: any): void;
829
976
  getCosts(): any;
@@ -831,7 +978,7 @@ declare module 's3db.js' {
831
978
  }
832
979
 
833
980
  /** Fulltext Plugin */
834
- export class FulltextPlugin extends PluginBase {
981
+ export class FullTextPlugin extends Plugin {
835
982
  constructor(config?: FulltextPluginConfig);
836
983
  search(query: string, options?: any): Promise<any[]>;
837
984
  indexResource(resourceName: string): Promise<void>;
@@ -840,7 +987,7 @@ declare module 's3db.js' {
840
987
  }
841
988
 
842
989
  /** Metrics Plugin */
843
- export class MetricsPlugin extends PluginBase {
990
+ export class MetricsPlugin extends Plugin {
844
991
  constructor(config?: MetricsPluginConfig);
845
992
  trackOperation(operation: string, duration: number, success: boolean): void;
846
993
  getMetrics(): any;
@@ -849,38 +996,85 @@ declare module 's3db.js' {
849
996
  getStats(): any;
850
997
  }
851
998
 
852
- /** Replication Plugin */
853
- export class ReplicationPlugin extends PluginBase {
854
- constructor(config?: ReplicationPluginConfig);
999
+ /** Queue Consumer Plugin */
1000
+ export class QueueConsumerPlugin {
1001
+ constructor(config?: QueueConsumerPluginConfig);
1002
+ setup(database: Database): Promise<void>;
1003
+ start(): Promise<void>;
1004
+ stop(): Promise<void>;
1005
+ getConsumerStats(): any;
1006
+ getConsumerLogs(filters?: any): Promise<any[]>;
1007
+ }
1008
+
1009
+ /** Replicator Plugin */
1010
+ export class ReplicatorPlugin extends Plugin {
1011
+ constructor(config?: ReplicatorPluginConfig);
855
1012
  replicate(operation: string, resourceName: string, data: any, oldData?: any): Promise<void>;
856
- getReplicationStats(): any;
857
- getReplicationLogs(filters?: any): Promise<any[]>;
1013
+ getReplicatorStats(): any;
1014
+ getReplicatorLogs(filters?: any): Promise<any[]>;
858
1015
  retryFailedReplications(): Promise<void>;
859
1016
  syncAllData(targetName: string): Promise<void>;
860
1017
  }
861
1018
 
1019
+ // ============================================================================
1020
+ // REPLICATOR CLASSES
1021
+ // ============================================================================
1022
+
1023
+ /** Base Replicator class */
1024
+ export class BaseReplicator {
1025
+ constructor(config: any);
1026
+ replicate(operation: string, resourceName: string, data: any, oldData?: any): Promise<void>;
1027
+ syncData(resourceName: string, data: any[]): Promise<void>;
1028
+ getStats(): any;
1029
+ getLogs(filters?: any): Promise<any[]>;
1030
+ }
1031
+
1032
+ /** S3DB Replicator class */
1033
+ export class S3dbReplicator extends BaseReplicator {
1034
+ constructor(config: S3dbReplicatorConfig);
1035
+ }
1036
+
1037
+ /** SQS Replicator class */
1038
+ export class SqsReplicator extends BaseReplicator {
1039
+ constructor(config: SQSReplicatorConfig);
1040
+ }
1041
+
1042
+ /** BigQuery Replicator class */
1043
+ export class BigqueryReplicator extends BaseReplicator {
1044
+ constructor(config: BigQueryReplicatorConfig);
1045
+ }
1046
+
1047
+ /** Postgres Replicator class */
1048
+ export class PostgresReplicator extends BaseReplicator {
1049
+ constructor(config: PostgresReplicatorConfig);
1050
+ }
1051
+
862
1052
  // ============================================================================
863
1053
  // STREAM CLASSES
864
1054
  // ============================================================================
865
1055
 
866
1056
  /** Resource Reader Stream */
867
- export class ResourceReader extends NodeJS.ReadableStream {
868
- constructor(resource: Resource, options?: any);
1057
+ export class ResourceReader extends Readable {
1058
+ constructor(config: { resource: Resource; options?: any });
1059
+ build(): Promise<Readable>;
869
1060
  }
870
1061
 
871
1062
  /** Resource Writer Stream */
872
- export class ResourceWriter extends NodeJS.WritableStream {
873
- constructor(resource: Resource, options?: any);
1063
+ export class ResourceWriter extends Writable {
1064
+ constructor(config: { resource: Resource; options?: any });
1065
+ build(): Promise<Writable>;
874
1066
  }
875
1067
 
876
1068
  /** Resource IDs Reader Stream */
877
- export class ResourceIdsReader extends NodeJS.ReadableStream {
878
- constructor(resource: Resource, options?: any);
1069
+ export class ResourceIdsReader extends Readable {
1070
+ constructor(config: { resource: Resource; options?: any });
1071
+ build(): Promise<Readable>;
879
1072
  }
880
1073
 
881
1074
  /** Resource IDs Page Reader Stream */
882
- export class ResourceIdsPageReader extends NodeJS.ReadableStream {
883
- constructor(resource: Resource, options?: any);
1075
+ export class ResourceIdsPageReader extends Readable {
1076
+ constructor(config: { resource: Resource; options?: any });
1077
+ build(): Promise<Readable>;
884
1078
  }
885
1079
 
886
1080
  // ============================================================================
@@ -889,37 +1083,88 @@ declare module 's3db.js' {
889
1083
 
890
1084
  /** Base S3db error */
891
1085
  export class BaseError extends Error {
892
- constructor(message: string, code?: string);
1086
+ constructor(config: {
1087
+ verbose?: boolean;
1088
+ bucket?: string;
1089
+ key?: string;
1090
+ message: string;
1091
+ code?: string;
1092
+ statusCode?: number;
1093
+ requestId?: string;
1094
+ awsMessage?: string;
1095
+ original?: Error;
1096
+ commandName?: string;
1097
+ commandInput?: any;
1098
+ metadata?: any;
1099
+ suggestion?: string;
1100
+ [key: string]: any;
1101
+ });
1102
+
1103
+ bucket?: string;
1104
+ key?: string;
1105
+ thrownAt: Date;
1106
+ code?: string;
1107
+ statusCode?: number;
1108
+ requestId?: string;
1109
+ awsMessage?: string;
1110
+ original?: Error;
1111
+ commandName?: string;
1112
+ commandInput?: any;
1113
+ metadata?: any;
1114
+ suggestion?: string;
1115
+ data: any;
1116
+
1117
+ toJson(): any;
893
1118
  }
894
1119
 
895
1120
  /** Not Found error */
896
1121
  export class NotFound extends BaseError {
897
- constructor(message: string);
1122
+ constructor(config: any);
898
1123
  }
899
1124
 
900
1125
  /** No Such Key error */
901
1126
  export class NoSuchKey extends BaseError {
902
- constructor(message: string);
1127
+ constructor(config: any);
903
1128
  }
904
1129
 
905
1130
  /** No Such Bucket error */
906
1131
  export class NoSuchBucket extends BaseError {
907
- constructor(message: string);
1132
+ constructor(config: any);
908
1133
  }
909
1134
 
910
1135
  /** Unknown Error */
911
1136
  export class UnknownError extends BaseError {
912
- constructor(message: string);
1137
+ constructor(message: string, config?: any);
913
1138
  }
914
1139
 
915
1140
  /** Missing Metadata error */
916
1141
  export class MissingMetadata extends BaseError {
917
- constructor(message: string);
1142
+ constructor(config: any);
918
1143
  }
919
1144
 
920
1145
  /** Invalid Resource Item error */
921
1146
  export class InvalidResourceItem extends BaseError {
922
- constructor(message: string);
1147
+ constructor(config: any);
1148
+ }
1149
+
1150
+ /** Resource Error */
1151
+ export class ResourceError extends BaseError {
1152
+ constructor(message: string, config?: any);
1153
+ }
1154
+
1155
+ /** Resource Not Found error */
1156
+ export class ResourceNotFound extends BaseError {
1157
+ constructor(config: any);
1158
+ }
1159
+
1160
+ /** Partition Error */
1161
+ export class PartitionError extends BaseError {
1162
+ constructor(config: any);
1163
+ }
1164
+
1165
+ /** Crypto Error */
1166
+ export class CryptoError extends BaseError {
1167
+ constructor(message: string, config?: any);
923
1168
  }
924
1169
 
925
1170
  // ============================================================================
@@ -927,7 +1172,7 @@ declare module 's3db.js' {
927
1172
  // ============================================================================
928
1173
 
929
1174
  /** Convert stream to string */
930
- export function streamToString(stream: NodeJS.ReadableStream): Promise<string>;
1175
+ export function streamToString(stream: Readable): Promise<string>;
931
1176
 
932
1177
  /** Encrypt data */
933
1178
  export function encrypt(data: any, passphrase: string): Promise<string>;
@@ -935,14 +1180,47 @@ declare module 's3db.js' {
935
1180
  /** Decrypt data */
936
1181
  export function decrypt(encryptedData: string, passphrase: string): Promise<any>;
937
1182
 
1183
+ /** SHA256 hash function */
1184
+ export function sha256(message: string): Promise<ArrayBuffer>;
1185
+
938
1186
  /** Generate ID */
939
1187
  export function idGenerator(): string;
940
1188
 
941
1189
  /** Generate password */
942
1190
  export function passwordGenerator(length?: number): string;
943
1191
 
1192
+ /** Try function wrapper */
1193
+ export function tryFn<T>(fn: () => Promise<T>): Promise<[boolean, Error | null, T | null]>;
1194
+ export function tryFnSync<T>(fn: () => T): [boolean, Error | null, T | null];
1195
+
1196
+ /** Calculate total size in bytes */
1197
+ export function calculateTotalSize(data: any): number;
1198
+
1199
+ /** Calculate effective limit */
1200
+ export function calculateEffectiveLimit(config: {
1201
+ s3Limit: number;
1202
+ systemConfig: {
1203
+ version?: string;
1204
+ timestamps?: boolean;
1205
+ id?: string;
1206
+ };
1207
+ }): number;
1208
+
1209
+ /** Calculate attribute sizes */
1210
+ export function calculateAttributeSizes(data: any): Record<string, number>;
1211
+
1212
+ /** Calculate UTF-8 bytes */
1213
+ export function calculateUTF8Bytes(str: string): number;
1214
+
1215
+ /** Map AWS error to s3db error */
1216
+ export function mapAwsError(error: Error, context: any): Error;
1217
+
1218
+ /** Base62 encoding */
1219
+ export function base62Encode(num: number): string;
1220
+ export function base62Decode(str: string): number;
1221
+
944
1222
  // ============================================================================
945
- // CONSTANTS
1223
+ // BEHAVIOR FUNCTIONS
946
1224
  // ============================================================================
947
1225
 
948
1226
  /** Available behavior names */
@@ -952,7 +1230,30 @@ declare module 's3db.js' {
952
1230
  export const DEFAULT_BEHAVIOR: BehaviorName;
953
1231
 
954
1232
  /** Get behavior implementation */
955
- export function getBehavior(behaviorName: BehaviorName): any;
1233
+ export function getBehavior(behaviorName: BehaviorName): {
1234
+ handleInsert: (params: { resource: Resource; data: any; mappedData: any; originalData?: any }) => Promise<{ mappedData: any; body: string }>;
1235
+ handleUpdate: (params: { resource: Resource; id: string; data: any; mappedData: any; originalData?: any }) => Promise<{ mappedData: any; body: string }>;
1236
+ handleUpsert: (params: { resource: Resource; id: string; data: any; mappedData: any; originalData?: any }) => Promise<{ mappedData: any; body: string }>;
1237
+ handleGet: (params: { resource: Resource; metadata: any; body: string }) => Promise<{ metadata: any; body: string }>;
1238
+ };
1239
+
1240
+ /** Available behaviors object */
1241
+ export const behaviors: Record<BehaviorName, any>;
1242
+
1243
+ // ============================================================================
1244
+ // REPLICATOR CONSTANTS
1245
+ // ============================================================================
1246
+
1247
+ /** Available replicator drivers */
1248
+ export const REPLICATOR_DRIVERS: {
1249
+ s3db: typeof S3dbReplicator;
1250
+ sqs: typeof SqsReplicator;
1251
+ bigquery: typeof BigqueryReplicator;
1252
+ postgres: typeof PostgresReplicator;
1253
+ };
1254
+
1255
+ /** Create replicator instance */
1256
+ export function createReplicator(driver: string, config: any): BaseReplicator;
956
1257
 
957
1258
  // ============================================================================
958
1259
  // DEFAULT EXPORT