s3db.js 7.2.0 → 7.2.1
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/PLUGINS.md +200 -10
- package/dist/s3db.cjs.js +61 -30
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.d.ts +14 -15
- package/dist/s3db.es.js +61 -30
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +61 -30
- package/dist/s3db.iife.min.js +1 -1
- package/package.json +5 -1
- package/src/plugins/replicators/bigquery-replicator.class.js +102 -68
- package/src/plugins/replicators/postgres-replicator.class.js +19 -109
- package/src/plugins/replicators/s3db-replicator.class.js +21 -49
- package/src/plugins/replicators/sqs-replicator.class.js +17 -116
- package/src/s3db.d.ts +14 -15
|
@@ -1,129 +1,30 @@
|
|
|
1
|
+
import tryFn from "#src/concerns/try-fn.js";
|
|
2
|
+
import BaseReplicator from './base-replicator.class.js';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* SQS Replicator
|
|
3
|
-
*
|
|
4
|
-
* This replicator sends replicator events to Amazon SQS queues. It supports both
|
|
5
|
-
* resource-specific queues and a single queue for all events, with a flexible message
|
|
6
|
-
* structure that includes operation details and data.
|
|
7
|
-
*
|
|
8
|
-
* ⚠️ REQUIRED DEPENDENCY: You must install the AWS SQS SDK to use this replicator:
|
|
5
|
+
* SQS Replicator - Send data changes to AWS SQS queues
|
|
9
6
|
*
|
|
7
|
+
* ⚠️ REQUIRED DEPENDENCY: You must install the AWS SQS SDK:
|
|
10
8
|
* ```bash
|
|
11
|
-
* npm install @aws-sdk/client-sqs
|
|
12
|
-
* # or
|
|
13
|
-
* yarn add @aws-sdk/client-sqs
|
|
14
|
-
* # or
|
|
15
9
|
* pnpm add @aws-sdk/client-sqs
|
|
16
10
|
* ```
|
|
17
11
|
*
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
20
|
-
* @
|
|
21
|
-
* @
|
|
22
|
-
* @
|
|
23
|
-
* @
|
|
24
|
-
* @
|
|
25
|
-
*
|
|
26
|
-
* - Value: SQS queue URL (e.g., 'https://sqs.us-east-1.amazonaws.com/123456789012/users-queue')
|
|
27
|
-
* - If not provided, defaultQueueUrl is used for all resources
|
|
28
|
-
* @property {number} [maxRetries=3] - Maximum number of retry attempts for failed message sends
|
|
29
|
-
* @property {number} [retryDelay=1000] - Delay in milliseconds between retry attempts
|
|
30
|
-
* @property {boolean} [logMessages=false] - Whether to log message details to console for debugging
|
|
31
|
-
* @property {number} [messageDelaySeconds=0] - Delay in seconds before messages become visible in queue
|
|
32
|
-
* @property {Object} [messageAttributes] - Additional attributes to include with every SQS message
|
|
33
|
-
* - Key: attribute name (e.g., 'environment', 'version')
|
|
34
|
-
* - Value: attribute value (e.g., 'production', '1.0.0')
|
|
35
|
-
* @property {string} [messageGroupId] - Message group ID for FIFO queues (required for FIFO queues)
|
|
36
|
-
* @property {boolean} [useFIFO=false] - Whether the target queues are FIFO queues
|
|
37
|
-
* @property {number} [batchSize=10] - Number of messages to send in a single batch (for batch operations)
|
|
38
|
-
* @property {boolean} [compressMessages=false] - Whether to compress message bodies using gzip
|
|
39
|
-
* @property {string} [messageFormat='json'] - Format for message body: 'json' or 'stringified'
|
|
40
|
-
* @property {Object} [sqsClientOptions] - Additional options to pass to the SQS client constructor
|
|
12
|
+
* Configuration:
|
|
13
|
+
* @param {string} region - AWS region (required)
|
|
14
|
+
* @param {string} queueUrl - Single queue URL for all resources
|
|
15
|
+
* @param {Object} queues - Resource-specific queue mapping { resource: queueUrl }
|
|
16
|
+
* @param {string} defaultQueueUrl - Fallback queue URL
|
|
17
|
+
* @param {string} messageGroupId - Message group ID for FIFO queues
|
|
18
|
+
* @param {boolean} deduplicationId - Enable deduplication for FIFO queues
|
|
19
|
+
* @param {Object} credentials - AWS credentials (optional, uses default if omitted)
|
|
41
20
|
*
|
|
42
21
|
* @example
|
|
43
|
-
*
|
|
44
|
-
* {
|
|
22
|
+
* new SqsReplicator({
|
|
45
23
|
* region: 'us-east-1',
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* resourceQueues: {
|
|
49
|
-
* 'users': 'https://sqs.us-east-1.amazonaws.com/123456789012/users-events',
|
|
50
|
-
* 'orders': 'https://sqs.us-east-1.amazonaws.com/123456789012/orders-events',
|
|
51
|
-
* 'products': 'https://sqs.us-east-1.amazonaws.com/123456789012/products-events'
|
|
52
|
-
* },
|
|
53
|
-
* logMessages: true,
|
|
54
|
-
* messageAttributes: {
|
|
55
|
-
* 'environment': 'production',
|
|
56
|
-
* 'source': 's3db-replicator'
|
|
57
|
-
* }
|
|
58
|
-
* }
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* // Configuration with single default queue
|
|
62
|
-
* {
|
|
63
|
-
* region: 'us-west-2',
|
|
64
|
-
* defaultQueueUrl: 'https://sqs.us-west-2.amazonaws.com/123456789012/all-events',
|
|
65
|
-
* maxRetries: 5,
|
|
66
|
-
* retryDelay: 2000,
|
|
67
|
-
* compressMessages: true
|
|
68
|
-
* }
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* // FIFO queue configuration
|
|
72
|
-
* {
|
|
73
|
-
* region: 'eu-west-1',
|
|
74
|
-
* defaultQueueUrl: 'https://sqs.eu-west-1.amazonaws.com/123456789012/events.fifo',
|
|
75
|
-
* useFIFO: true,
|
|
76
|
-
* messageGroupId: 's3db-events',
|
|
77
|
-
* messageDelaySeconds: 5
|
|
78
|
-
* }
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* // Minimal configuration using IAM roles
|
|
82
|
-
* {
|
|
83
|
-
* region: 'us-east-1',
|
|
84
|
-
* defaultQueueUrl: 'https://sqs.us-east-1.amazonaws.com/123456789012/my-queue'
|
|
85
|
-
* }
|
|
86
|
-
*
|
|
87
|
-
* @notes
|
|
88
|
-
* - Requires AWS credentials with SQS SendMessage permissions
|
|
89
|
-
* - Resource-specific queues take precedence over defaultQueueUrl
|
|
90
|
-
* - Message structure includes: resource, action, data, before (for updates), timestamp, source
|
|
91
|
-
* - FIFO queues require messageGroupId and ensure strict ordering
|
|
92
|
-
* - Message compression reduces bandwidth but increases CPU usage
|
|
93
|
-
* - Batch operations improve performance but may fail if any message in batch fails
|
|
94
|
-
* - Retry mechanism uses exponential backoff for failed sends
|
|
95
|
-
* - Message attributes are useful for filtering and routing in SQS
|
|
96
|
-
* - Message delay is useful for implementing eventual consistency patterns
|
|
97
|
-
* - SQS client options allow for custom endpoint, credentials, etc.
|
|
98
|
-
*/
|
|
99
|
-
import BaseReplicator from './base-replicator.class.js';
|
|
100
|
-
import tryFn from "../../concerns/try-fn.js";
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* SQS Replicator - Sends data to AWS SQS queues with support for resource-specific queues
|
|
104
|
-
*
|
|
105
|
-
* Configuration options:
|
|
106
|
-
* - queueUrl: Single queue URL for all resources
|
|
107
|
-
* - queues: Object mapping resource names to specific queue URLs
|
|
108
|
-
* - defaultQueueUrl: Fallback queue URL when resource-specific queue is not found
|
|
109
|
-
* - messageGroupId: For FIFO queues
|
|
110
|
-
* - deduplicationId: For FIFO queues
|
|
111
|
-
*
|
|
112
|
-
* Example configurations:
|
|
113
|
-
*
|
|
114
|
-
* // Single queue for all resources
|
|
115
|
-
* {
|
|
116
|
-
* queueUrl: 'https://sqs.us-east-1.amazonaws.com/123456789012/my-queue'
|
|
117
|
-
* }
|
|
24
|
+
* queueUrl: 'https://sqs.us-east-1.amazonaws.com/123456789012/events-queue'
|
|
25
|
+
* }, ['users', 'orders'])
|
|
118
26
|
*
|
|
119
|
-
*
|
|
120
|
-
* {
|
|
121
|
-
* queues: {
|
|
122
|
-
* users: 'https://sqs.us-east-1.amazonaws.com/123456789012/users-queue',
|
|
123
|
-
* orders: 'https://sqs.us-east-1.amazonaws.com/123456789012/orders-queue'
|
|
124
|
-
* },
|
|
125
|
-
* defaultQueueUrl: 'https://sqs.us-east-1.amazonaws.com/123456789012/default-queue'
|
|
126
|
-
* }
|
|
27
|
+
* See PLUGINS.md for comprehensive configuration documentation.
|
|
127
28
|
*/
|
|
128
29
|
class SqsReplicator extends BaseReplicator {
|
|
129
30
|
constructor(config = {}, resources = [], client = null) {
|
package/src/s3db.d.ts
CHANGED
|
@@ -418,23 +418,22 @@ declare module 's3db.js' {
|
|
|
418
418
|
export interface BigQueryReplicatorConfig {
|
|
419
419
|
projectId: string;
|
|
420
420
|
datasetId: string;
|
|
421
|
-
keyFilename?: string;
|
|
422
421
|
credentials?: Record<string, any>;
|
|
423
|
-
|
|
424
|
-
|
|
422
|
+
location?: string;
|
|
423
|
+
logTable?: string;
|
|
425
424
|
batchSize?: number;
|
|
426
425
|
maxRetries?: number;
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
426
|
+
writeDisposition?: string;
|
|
427
|
+
createDisposition?: string;
|
|
428
|
+
tableMapping?: Record<string, string>;
|
|
429
|
+
logOperations?: boolean;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** BigQuery Resource Configuration */
|
|
433
|
+
export interface BigQueryResourceConfig {
|
|
434
|
+
table: string;
|
|
435
|
+
actions?: ('insert' | 'update' | 'delete')[];
|
|
436
|
+
transform?: (data: any) => any;
|
|
438
437
|
}
|
|
439
438
|
|
|
440
439
|
/** Postgres Replicator config */
|
|
@@ -1041,7 +1040,7 @@ declare module 's3db.js' {
|
|
|
1041
1040
|
|
|
1042
1041
|
/** BigQuery Replicator class */
|
|
1043
1042
|
export class BigqueryReplicator extends BaseReplicator {
|
|
1044
|
-
constructor(config: BigQueryReplicatorConfig);
|
|
1043
|
+
constructor(config: BigQueryReplicatorConfig, resources: Record<string, string | BigQueryResourceConfig | BigQueryResourceConfig[]>);
|
|
1045
1044
|
}
|
|
1046
1045
|
|
|
1047
1046
|
/** Postgres Replicator class */
|