@mastra/dsql 0.0.0-ag-example-20260516005230
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/CHANGELOG.md +60 -0
- package/LICENSE.md +30 -0
- package/README.md +357 -0
- package/dist/index.cjs +4478 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4469 -0
- package/dist/index.js.map +1 -0
- package/dist/shared/batch.d.ts +55 -0
- package/dist/shared/batch.d.ts.map +1 -0
- package/dist/shared/config.d.ts +129 -0
- package/dist/shared/config.d.ts.map +1 -0
- package/dist/shared/retry.d.ts +207 -0
- package/dist/shared/retry.d.ts.map +1 -0
- package/dist/storage/client.d.ts +91 -0
- package/dist/storage/client.d.ts.map +1 -0
- package/dist/storage/db/index.d.ts +179 -0
- package/dist/storage/db/index.d.ts.map +1 -0
- package/dist/storage/domains/agents/index.d.ts +47 -0
- package/dist/storage/domains/agents/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +80 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -0
- package/dist/storage/domains/observability/index.d.ts +37 -0
- package/dist/storage/domains/observability/index.d.ts.map +1 -0
- package/dist/storage/domains/scores/index.d.ts +53 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -0
- package/dist/storage/domains/utils.d.ts +14 -0
- package/dist/storage/domains/utils.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +61 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +46 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/performance-indexes/performance-test.d.ts +47 -0
- package/dist/storage/performance-indexes/performance-test.d.ts.map +1 -0
- package/dist/storage/test-utils.d.ts +14 -0
- package/dist/storage/test-utils.d.ts.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch utilities for Aurora DSQL.
|
|
3
|
+
*
|
|
4
|
+
* Aurora DSQL has transaction limits:
|
|
5
|
+
* - Maximum 3,000 rows per transaction
|
|
6
|
+
* - Maximum 10 MiB per transaction
|
|
7
|
+
*
|
|
8
|
+
* This utility only enforces the row-count limit.
|
|
9
|
+
* The 10 MiB limit depends on the size of each record, so please enforce it
|
|
10
|
+
* in the caller if needed.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Default maximum rows per batch.
|
|
14
|
+
* Aurora DSQL limits transactions to 3,000 rows.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFAULT_MAX_ROWS_PER_BATCH = 3000;
|
|
17
|
+
/**
|
|
18
|
+
* Options for batch splitting.
|
|
19
|
+
*/
|
|
20
|
+
export interface BatchOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Maximum number of rows per batch.
|
|
23
|
+
* @default 3000 (Aurora DSQL limit)
|
|
24
|
+
*/
|
|
25
|
+
maxRows?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Result of batch splitting.
|
|
29
|
+
*/
|
|
30
|
+
export interface BatchResult<T> {
|
|
31
|
+
/** The batched records */
|
|
32
|
+
batches: T[][];
|
|
33
|
+
/** Total number of records */
|
|
34
|
+
totalRecords: number;
|
|
35
|
+
/** Number of batches created */
|
|
36
|
+
batchCount: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Split an array of records into batches that respect Aurora DSQL's transaction limits.
|
|
40
|
+
*
|
|
41
|
+
* @param records - Array of records to split
|
|
42
|
+
* @param options - Batch splitting options
|
|
43
|
+
* @returns BatchResult containing the batched records and metadata
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const records = generateRecords(5000);
|
|
48
|
+
* const result = splitIntoBatches(records);
|
|
49
|
+
* // result.batches.length === 2
|
|
50
|
+
* // result.batches[0].length === 3000
|
|
51
|
+
* // result.batches[1].length === 2000
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function splitIntoBatches<T>(records: T[], options?: BatchOptions): BatchResult<T>;
|
|
55
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../src/shared/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;GAGG;AACH,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,0BAA0B;IAC1B,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC;IACf,8BAA8B;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,OAAO,GAAE,YAAiB,GAAG,WAAW,CAAC,CAAC,CAAC,CAyB5F"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { AwsCredentialIdentityProvider } from '@aws-sdk/types';
|
|
2
|
+
import type { CreateIndexOptions } from '@mastra/core/storage';
|
|
3
|
+
import type { Pool } from 'pg';
|
|
4
|
+
/**
|
|
5
|
+
* Default connection pool settings optimized for Aurora DSQL.
|
|
6
|
+
*
|
|
7
|
+
* Aurora DSQL has a 60-minute maximum connection duration limit,
|
|
8
|
+
* so maxLifetimeSeconds is set to 55 minutes to ensure connections
|
|
9
|
+
* are rotated before hitting that limit.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DSQL_POOL_DEFAULTS: {
|
|
12
|
+
/** Maximum connections in the pool */
|
|
13
|
+
readonly max: 10;
|
|
14
|
+
/** Minimum connections in the pool */
|
|
15
|
+
readonly min: 0;
|
|
16
|
+
/** Close idle connections after 10 minutes */
|
|
17
|
+
readonly idleTimeoutMillis: 600000;
|
|
18
|
+
/** Force connection rotation before DSQL's 60-minute limit */
|
|
19
|
+
readonly maxLifetimeSeconds: 3300;
|
|
20
|
+
/** Connection acquisition timeout */
|
|
21
|
+
readonly connectionTimeoutMillis: 5000;
|
|
22
|
+
/** Allow process to exit when idle */
|
|
23
|
+
readonly allowExitOnIdle: true;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Base configuration options shared across Aurora DSQL configs.
|
|
27
|
+
*/
|
|
28
|
+
export interface DSQLBaseConfig {
|
|
29
|
+
/** Unique identifier for this store instance */
|
|
30
|
+
id: string;
|
|
31
|
+
/** Schema name (default: "public") */
|
|
32
|
+
schemaName?: string;
|
|
33
|
+
/**
|
|
34
|
+
* If true, the store will not be initialized automatically when used with Mastra.
|
|
35
|
+
* Use this when you want to manage initialization timing yourself.
|
|
36
|
+
*/
|
|
37
|
+
disableInit?: boolean;
|
|
38
|
+
/** Skip creation of default indexes (default: false) */
|
|
39
|
+
skipDefaultIndexes?: boolean;
|
|
40
|
+
/** Custom index definitions to create */
|
|
41
|
+
indexes?: CreateIndexOptions[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Aurora DSQL host-based configuration.
|
|
45
|
+
*
|
|
46
|
+
* Aurora DSQL uses IAM authentication, so password is not required.
|
|
47
|
+
* The connector automatically generates IAM tokens for authentication.
|
|
48
|
+
*/
|
|
49
|
+
export interface HostConfig extends DSQLBaseConfig {
|
|
50
|
+
/** DSQL cluster endpoint (e.g., "abc123.dsql.us-east-1.on.aws") */
|
|
51
|
+
host: string;
|
|
52
|
+
/** Database user (default: "admin") */
|
|
53
|
+
user?: string;
|
|
54
|
+
/** Database name (default: "postgres", Aurora DSQL supports only one database per cluster) */
|
|
55
|
+
database?: string;
|
|
56
|
+
/** AWS region (auto-detected from host if not provided) */
|
|
57
|
+
region?: string;
|
|
58
|
+
/** Custom AWS credentials provider (optional, uses default credential chain if not provided) */
|
|
59
|
+
customCredentialsProvider?: AwsCredentialIdentityProvider;
|
|
60
|
+
/** Maximum number of connections in the pool (default: 10) */
|
|
61
|
+
max?: number;
|
|
62
|
+
/** Minimum number of connections in the pool (default: 0) */
|
|
63
|
+
min?: number;
|
|
64
|
+
/** Close idle connections after this many milliseconds (default: 600000 = 10 minutes) */
|
|
65
|
+
idleTimeoutMillis?: number;
|
|
66
|
+
/** Maximum connection lifetime in seconds (default: 3300 = 55 minutes, must be < 60 minutes due to DSQL limit) */
|
|
67
|
+
maxLifetimeSeconds?: number;
|
|
68
|
+
/** Connection timeout in milliseconds (default: 5000) */
|
|
69
|
+
connectionTimeoutMillis?: number;
|
|
70
|
+
/** Allow the process to exit when all connections are idle (default: true) */
|
|
71
|
+
allowExitOnIdle?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Pre-configured pg.Pool configuration for Aurora DSQL.
|
|
75
|
+
*/
|
|
76
|
+
export interface PoolInstanceConfig extends DSQLBaseConfig {
|
|
77
|
+
/**
|
|
78
|
+
* Pre-configured pg.Pool instance.
|
|
79
|
+
* Use this for direct control over the connection pool, or for
|
|
80
|
+
* integration with libraries that expect a pg.Pool.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { Pool } from 'pg';
|
|
85
|
+
* import { AuroraDSQLClient } from '@aws/aurora-dsql-node-postgres-connector';
|
|
86
|
+
*
|
|
87
|
+
* const pool = new Pool({
|
|
88
|
+
* host: 'abc123.dsql.us-east-1.on.aws',
|
|
89
|
+
* Client: AuroraDSQLClient,
|
|
90
|
+
* region: 'us-east-1',
|
|
91
|
+
* });
|
|
92
|
+
* const store = new DSQLStore({ id: 'my-store', pool });
|
|
93
|
+
*
|
|
94
|
+
* // Use store.pool for other libraries that need a pg.Pool
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
pool: Pool;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Aurora DSQL configuration type.
|
|
101
|
+
*
|
|
102
|
+
* Accepts either:
|
|
103
|
+
* - A pre-configured pg.Pool: `{ id, pool, schemaName? }`
|
|
104
|
+
* - Host-based config: `{ id, host, ... }`
|
|
105
|
+
*/
|
|
106
|
+
export type DSQLStoreConfig = PoolInstanceConfig | HostConfig | DSQLBaseConfig;
|
|
107
|
+
/**
|
|
108
|
+
* Type guard for pre-configured pg.Pool config
|
|
109
|
+
*/
|
|
110
|
+
export declare const isPoolConfig: (cfg: DSQLStoreConfig) => cfg is PoolInstanceConfig;
|
|
111
|
+
/**
|
|
112
|
+
* Type guard for host-based config
|
|
113
|
+
*/
|
|
114
|
+
export declare const isHostConfig: (cfg: DSQLStoreConfig) => cfg is HostConfig;
|
|
115
|
+
/**
|
|
116
|
+
* Validates the DSQLStoreConfig and throws an error if invalid.
|
|
117
|
+
*/
|
|
118
|
+
export declare const validateConfig: (config: DSQLStoreConfig) => void;
|
|
119
|
+
/**
|
|
120
|
+
* Extracts AWS region from DSQL host endpoint.
|
|
121
|
+
* DSQL endpoints follow the pattern: <cluster-id>.dsql.<region>.on.aws
|
|
122
|
+
*/
|
|
123
|
+
export declare const extractRegionFromHost: (host: string) => string | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Returns the effective region, either from config or extracted from host.
|
|
126
|
+
* Only applicable for host-based config (not pre-configured pool).
|
|
127
|
+
*/
|
|
128
|
+
export declare const getEffectiveRegion: (config: HostConfig) => string;
|
|
129
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/shared/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,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,CAAC;CACZ;AAED;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,kBAAkB,GAAG,UAAU,GAAG,cAAc,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,eAAe,KAAG,GAAG,IAAI,kBAE1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,eAAe,KAAG,GAAG,IAAI,UAE1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,eAAe,KAAG,IA6BxD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,SAG7D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,UAAU,KAAG,MAavD,CAAC"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retry utilities for Aurora DSQL (PostgreSQL + OCC).
|
|
3
|
+
*
|
|
4
|
+
* Aurora DSQL uses optimistic concurrency control (OCC) and may return
|
|
5
|
+
* serialization errors (SQLSTATE 40001) that require retry. This module
|
|
6
|
+
* provides utilities for handling such errors with exponential backoff
|
|
7
|
+
* and full jitter.
|
|
8
|
+
*
|
|
9
|
+
* **Scope**: By default, this utility only retries OCC-related failures
|
|
10
|
+
* identified by PostgreSQL SQLSTATE codes. Network-level or OS-level errors
|
|
11
|
+
* are out of scope for the default implementation. Callers can provide a
|
|
12
|
+
* custom `isRetriable` function to extend retriable conditions if needed.
|
|
13
|
+
*
|
|
14
|
+
* @see https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* PostgreSQL SQLSTATE codes that may be retriable.
|
|
18
|
+
*
|
|
19
|
+
* By default, `isRetriableError` only retries `SERIALIZATION_FAILURE` (40001),
|
|
20
|
+
* which is the primary OCC conflict error from Aurora DSQL.
|
|
21
|
+
*
|
|
22
|
+
* Other codes are provided for reference and can be used with a custom
|
|
23
|
+
* `isRetriable` function if needed.
|
|
24
|
+
*
|
|
25
|
+
* @see https://www.postgresql.org/docs/current/errcodes-appendix.html
|
|
26
|
+
*/
|
|
27
|
+
export declare const RETRIABLE_ERROR_CODES: {
|
|
28
|
+
/** Serialization failure - OCC conflict in Aurora DSQL (default retriable) */
|
|
29
|
+
readonly SERIALIZATION_FAILURE: "40001";
|
|
30
|
+
/** Deadlock detected (not retriable by default) */
|
|
31
|
+
readonly DEADLOCK_DETECTED: "40P01";
|
|
32
|
+
/** Connection failure - may be transient (not retriable by default) */
|
|
33
|
+
readonly CONNECTION_FAILURE: "08006";
|
|
34
|
+
/** Connection does not exist (not retriable by default) */
|
|
35
|
+
readonly CONNECTION_DOES_NOT_EXIST: "08003";
|
|
36
|
+
/** Admin shutdown - server is restarting (not retriable by default) */
|
|
37
|
+
readonly ADMIN_SHUTDOWN: "57P01";
|
|
38
|
+
/** Crash shutdown (not retriable by default) */
|
|
39
|
+
readonly CRASH_SHUTDOWN: "57P02";
|
|
40
|
+
/** Cannot connect now (not retriable by default) */
|
|
41
|
+
readonly CANNOT_CONNECT_NOW: "57P03";
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Options for retry behavior.
|
|
45
|
+
*/
|
|
46
|
+
export interface RetryOptions {
|
|
47
|
+
/**
|
|
48
|
+
* Maximum number of retry attempts (including the initial attempt).
|
|
49
|
+
* Must be >= 1.
|
|
50
|
+
* @default 5
|
|
51
|
+
*/
|
|
52
|
+
maxAttempts?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Initial delay in milliseconds before first retry.
|
|
55
|
+
* Must be >= 0.
|
|
56
|
+
* @default 100
|
|
57
|
+
*/
|
|
58
|
+
initialDelayMs?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Maximum delay in milliseconds between retries.
|
|
61
|
+
* Must be > 0 and >= initialDelayMs.
|
|
62
|
+
* @default 2000
|
|
63
|
+
*/
|
|
64
|
+
maxDelayMs?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Multiplier for exponential backoff.
|
|
67
|
+
* Must be >= 1.
|
|
68
|
+
* @default 2
|
|
69
|
+
*/
|
|
70
|
+
backoffMultiplier?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Whether to add jitter to retry delays.
|
|
73
|
+
* When true, uses "full jitter" algorithm: delay is uniformly random in [0, cappedDelay].
|
|
74
|
+
* @see https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
|
75
|
+
* @default true
|
|
76
|
+
*/
|
|
77
|
+
jitter?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Optional callback invoked before each retry.
|
|
80
|
+
* @param error - The error that triggered the retry
|
|
81
|
+
* @param attempt - The attempt number that failed (1-based)
|
|
82
|
+
* @param delayMs - The delay before the next attempt
|
|
83
|
+
*/
|
|
84
|
+
onRetry?: (error: Error, attempt: number, delayMs: number) => void;
|
|
85
|
+
/**
|
|
86
|
+
* Custom function to determine if an error is retriable.
|
|
87
|
+
* If not provided, uses the default `isRetriableError` function which only
|
|
88
|
+
* retries on SQLSTATE 40001 (OCC serialization failure).
|
|
89
|
+
*/
|
|
90
|
+
isRetriable?: (error: unknown) => boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Default retry options.
|
|
94
|
+
*
|
|
95
|
+
* Note: maxDelayMs is set to 2000ms as the standard for most operations.
|
|
96
|
+
* For batch operations that may need more recovery time, override with 5000ms.
|
|
97
|
+
*/
|
|
98
|
+
export declare const DEFAULT_RETRY_OPTIONS: Required<Omit<RetryOptions, 'onRetry' | 'isRetriable'>>;
|
|
99
|
+
/**
|
|
100
|
+
* Interface for PostgreSQL errors (from pg library).
|
|
101
|
+
*/
|
|
102
|
+
export interface PostgresError extends Error {
|
|
103
|
+
code?: string;
|
|
104
|
+
severity?: string;
|
|
105
|
+
detail?: string;
|
|
106
|
+
hint?: string;
|
|
107
|
+
position?: string;
|
|
108
|
+
internalPosition?: string;
|
|
109
|
+
internalQuery?: string;
|
|
110
|
+
where?: string;
|
|
111
|
+
schema?: string;
|
|
112
|
+
table?: string;
|
|
113
|
+
column?: string;
|
|
114
|
+
dataType?: string;
|
|
115
|
+
constraint?: string;
|
|
116
|
+
file?: string;
|
|
117
|
+
line?: string;
|
|
118
|
+
routine?: string;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Check if an error is a PostgreSQL error with a code.
|
|
122
|
+
*/
|
|
123
|
+
export declare function isPostgresError(error: unknown): error is PostgresError;
|
|
124
|
+
/**
|
|
125
|
+
* Get the PostgreSQL error code from an error, if available.
|
|
126
|
+
*/
|
|
127
|
+
export declare function getErrorCode(error: unknown): string | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Check if an error is retriable based on its PostgreSQL SQLSTATE code.
|
|
130
|
+
*
|
|
131
|
+
* This function is designed for Aurora DSQL's OCC (Optimistic Concurrency Control).
|
|
132
|
+
* By default, only SQLSTATE 40001 (serialization failure) is considered retriable.
|
|
133
|
+
*
|
|
134
|
+
* **Important**: This function does NOT retry on:
|
|
135
|
+
* - Network errors (ECONNRESET, ECONNREFUSED, etc.)
|
|
136
|
+
* - Timeout errors
|
|
137
|
+
* - Other connection-level errors
|
|
138
|
+
*
|
|
139
|
+
* If you need to retry on additional error types, provide a custom `isRetriable`
|
|
140
|
+
* function to `withRetry`.
|
|
141
|
+
*
|
|
142
|
+
* @param error - The error to check
|
|
143
|
+
* @returns True if the error has a retriable SQLSTATE code (40001 by default)
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* // Create a PostgreSQL-like error
|
|
148
|
+
* const createPgError = (code: string, message: string): PostgresError => {
|
|
149
|
+
* const err = new Error(message) as PostgresError;
|
|
150
|
+
* err.code = code;
|
|
151
|
+
* return err;
|
|
152
|
+
* };
|
|
153
|
+
*
|
|
154
|
+
* // Default: only retries on 40001
|
|
155
|
+
* isRetriableError(createPgError('40001', 'serialization failure')); // true
|
|
156
|
+
* isRetriableError(createPgError('40P01', 'deadlock detected')); // false
|
|
157
|
+
* isRetriableError(new Error('connection timeout')); // false
|
|
158
|
+
*
|
|
159
|
+
* // Custom retriable check with additional codes:
|
|
160
|
+
* const customIsRetriable = (error: unknown) => {
|
|
161
|
+
* const code = getErrorCode(error);
|
|
162
|
+
* return code === '40001' || code === '40P01';
|
|
163
|
+
* };
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export declare function isRetriableError(error: unknown): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Result of a retry operation.
|
|
169
|
+
*/
|
|
170
|
+
export interface RetryResult<T> {
|
|
171
|
+
/** The result if successful */
|
|
172
|
+
result: T;
|
|
173
|
+
/** Number of attempts made */
|
|
174
|
+
attempts: number;
|
|
175
|
+
/** Total time spent (including delays) in milliseconds */
|
|
176
|
+
totalTimeMs: number;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Execute a function with automatic retry on retriable errors.
|
|
180
|
+
*
|
|
181
|
+
* Uses exponential backoff with optional full jitter to avoid thundering herd.
|
|
182
|
+
* By default, only retries on PostgreSQL SQLSTATE 40001 (OCC serialization failure),
|
|
183
|
+
* which is the primary conflict error from Aurora DSQL.
|
|
184
|
+
*
|
|
185
|
+
* @param fn - The async function to execute
|
|
186
|
+
* @param options - Retry options
|
|
187
|
+
* @returns The result of the function along with metadata
|
|
188
|
+
* @throws The original error if all attempts fail or the error is not retriable
|
|
189
|
+
* @throws Error if retry options are invalid
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* const { result, attempts, totalTimeMs } = await withRetry(
|
|
194
|
+
* async () => {
|
|
195
|
+
* return await db.query('INSERT INTO users ...');
|
|
196
|
+
* },
|
|
197
|
+
* {
|
|
198
|
+
* maxAttempts: 3,
|
|
199
|
+
* onRetry: (error, attempt, delay) => {
|
|
200
|
+
* console.log(`Retry ${attempt} after ${delay}ms: ${error.message}`);
|
|
201
|
+
* }
|
|
202
|
+
* }
|
|
203
|
+
* );
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
export declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<RetryResult<T>>;
|
|
207
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/shared/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB;IAChC,8EAA8E;;IAE9E,mDAAmD;;IAEnD,uEAAuE;;IAEvE,2DAA2D;;IAE3D,uEAAuE;;IAEvE,gDAAgD;;IAEhD,oDAAoD;;CAE5C,CAAC;AAQX;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAEnE;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CAC3C;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,aAAa,CAAC,CAMzF,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,KAAK;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,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@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Pool, PoolClient, QueryResult } from 'pg';
|
|
2
|
+
export type { Pool, PoolClient, QueryResult } from 'pg';
|
|
3
|
+
/**
|
|
4
|
+
* Values array for parameterized queries.
|
|
5
|
+
*/
|
|
6
|
+
export type QueryValues = unknown[];
|
|
7
|
+
/**
|
|
8
|
+
* Common interface for database clients.
|
|
9
|
+
* DsqlPoolAdapter implements this interface by wrapping a pg.Pool.
|
|
10
|
+
*/
|
|
11
|
+
export interface DbClient {
|
|
12
|
+
/**
|
|
13
|
+
* The underlying connection pool.
|
|
14
|
+
*/
|
|
15
|
+
readonly $pool: Pool;
|
|
16
|
+
/**
|
|
17
|
+
* Acquire a client from the pool for manual query execution.
|
|
18
|
+
* Remember to call client.release() when done.
|
|
19
|
+
*/
|
|
20
|
+
connect(): Promise<PoolClient>;
|
|
21
|
+
/**
|
|
22
|
+
* Execute a query that returns no data.
|
|
23
|
+
* Use for INSERT, UPDATE, DELETE without RETURNING.
|
|
24
|
+
*/
|
|
25
|
+
none(query: string, values?: QueryValues): Promise<null>;
|
|
26
|
+
/**
|
|
27
|
+
* Execute a query that returns exactly one row.
|
|
28
|
+
* @throws Error if zero or more than one row is returned
|
|
29
|
+
*/
|
|
30
|
+
one<T = any>(query: string, values?: QueryValues): Promise<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Execute a query that returns zero or one row.
|
|
33
|
+
* @returns The row, or null if no rows returned
|
|
34
|
+
* @throws Error if more than one row is returned
|
|
35
|
+
*/
|
|
36
|
+
oneOrNone<T = any>(query: string, values?: QueryValues): Promise<T | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Execute a query that returns any number of rows (including zero).
|
|
39
|
+
* Alias for manyOrNone.
|
|
40
|
+
*/
|
|
41
|
+
any<T = any>(query: string, values?: QueryValues): Promise<T[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Execute a query that returns zero or more rows.
|
|
44
|
+
*/
|
|
45
|
+
manyOrNone<T = any>(query: string, values?: QueryValues): Promise<T[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Execute a query that returns at least one row.
|
|
48
|
+
* @throws Error if no rows are returned
|
|
49
|
+
*/
|
|
50
|
+
many<T = any>(query: string, values?: QueryValues): Promise<T[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Execute a raw query, returning the full result object.
|
|
53
|
+
*/
|
|
54
|
+
query(query: string, values?: QueryValues): Promise<QueryResult>;
|
|
55
|
+
/**
|
|
56
|
+
* Execute a function within a transaction.
|
|
57
|
+
* Automatically handles BEGIN, COMMIT, and ROLLBACK.
|
|
58
|
+
*/
|
|
59
|
+
tx<T>(callback: (t: TxClient) => Promise<T>): Promise<T>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Transaction client interface for executing queries within a transaction.
|
|
63
|
+
*/
|
|
64
|
+
export interface TxClient {
|
|
65
|
+
none(query: string, values?: QueryValues): Promise<null>;
|
|
66
|
+
one<T = any>(query: string, values?: QueryValues): Promise<T>;
|
|
67
|
+
oneOrNone<T = any>(query: string, values?: QueryValues): Promise<T | null>;
|
|
68
|
+
any<T = any>(query: string, values?: QueryValues): Promise<T[]>;
|
|
69
|
+
manyOrNone<T = any>(query: string, values?: QueryValues): Promise<T[]>;
|
|
70
|
+
many<T = any>(query: string, values?: QueryValues): Promise<T[]>;
|
|
71
|
+
query(query: string, values?: QueryValues): Promise<QueryResult>;
|
|
72
|
+
/** Execute multiple promises in parallel */
|
|
73
|
+
batch<T>(promises: Promise<T>[]): Promise<T[]>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Adapter that wraps a pg.Pool to implement DbClient.
|
|
77
|
+
*/
|
|
78
|
+
export declare class PoolAdapter implements DbClient {
|
|
79
|
+
readonly $pool: Pool;
|
|
80
|
+
constructor($pool: Pool);
|
|
81
|
+
connect(): Promise<PoolClient>;
|
|
82
|
+
none(query: string, values?: QueryValues): Promise<null>;
|
|
83
|
+
one<T = any>(query: string, values?: QueryValues): Promise<T>;
|
|
84
|
+
oneOrNone<T = any>(query: string, values?: QueryValues): Promise<T | null>;
|
|
85
|
+
any<T = any>(query: string, values?: QueryValues): Promise<T[]>;
|
|
86
|
+
manyOrNone<T = any>(query: string, values?: QueryValues): Promise<T[]>;
|
|
87
|
+
many<T = any>(query: string, values?: QueryValues): Promise<T[]>;
|
|
88
|
+
query(query: string, values?: QueryValues): Promise<QueryResult>;
|
|
89
|
+
tx<T>(callback: (t: TxClient) => Promise<T>): Promise<T>;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/storage/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAGxD,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,EAAE,CAAC;AAEpC;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IAErB;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAE/B;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzD;;;OAGG;IACH,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE9D;;;;OAIG;IACH,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,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W,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAItE,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAQhE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAIhE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAoB/D"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { MastraBase } from '@mastra/core/base';
|
|
2
|
+
import type { StorageColumn, TABLE_NAMES, CreateIndexOptions, IndexInfo, StorageIndexStats } from '@mastra/core/storage';
|
|
3
|
+
import { Pool } from 'pg';
|
|
4
|
+
import type { DbClient } from '../client.js';
|
|
5
|
+
export type { DbClient } from '../client.js';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for standalone domain usage.
|
|
8
|
+
* Accepts either:
|
|
9
|
+
* 1. An existing database client (Pool or PoolAdapter)
|
|
10
|
+
* 2. Config to create a new pool internally
|
|
11
|
+
*/
|
|
12
|
+
export type DsqlDomainConfig = DsqlDomainClientConfig | DsqlDomainPoolConfig | DsqlDomainRestConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for standalone domain usage.
|
|
15
|
+
* Accepts a database client instance.
|
|
16
|
+
*/
|
|
17
|
+
export interface DsqlDomainClientConfig {
|
|
18
|
+
/** The database client instance */
|
|
19
|
+
client: DbClient;
|
|
20
|
+
/** Database schema name */
|
|
21
|
+
schemaName?: string;
|
|
22
|
+
/** Skip creation of default indexes */
|
|
23
|
+
skipDefaultIndexes?: boolean;
|
|
24
|
+
/** Custom index definitions (filtered by domain's MANAGED_TABLES) */
|
|
25
|
+
indexes?: CreateIndexOptions[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Pass an existing pg.Pool
|
|
29
|
+
*/
|
|
30
|
+
export interface DsqlDomainPoolConfig {
|
|
31
|
+
/** Pre-configured pg.Pool */
|
|
32
|
+
pool: Pool;
|
|
33
|
+
/** Optional schema name (defaults to 'public') */
|
|
34
|
+
schemaName?: string;
|
|
35
|
+
/** When true, default indexes will not be created during initialization */
|
|
36
|
+
skipDefaultIndexes?: boolean;
|
|
37
|
+
/** Custom indexes to create for this domain's tables */
|
|
38
|
+
indexes?: CreateIndexOptions[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Pass config to create a new pg.Pool internally
|
|
42
|
+
*/
|
|
43
|
+
export type DsqlDomainRestConfig = {
|
|
44
|
+
/** Optional schema name (defaults to 'public') */
|
|
45
|
+
schemaName?: string;
|
|
46
|
+
/** When true, default indexes will not be created during initialization */
|
|
47
|
+
skipDefaultIndexes?: boolean;
|
|
48
|
+
/** Custom indexes to create for this domain's tables */
|
|
49
|
+
indexes?: CreateIndexOptions[];
|
|
50
|
+
} & {
|
|
51
|
+
host: string;
|
|
52
|
+
database: string;
|
|
53
|
+
user: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Resolves DsqlDomainConfi to a database client and schema.
|
|
57
|
+
* Handles creating a new pool if config is provided.
|
|
58
|
+
*/
|
|
59
|
+
export declare function resolveDsqlConfig(config: DsqlDomainConfig): {
|
|
60
|
+
client: DbClient;
|
|
61
|
+
schemaName?: string;
|
|
62
|
+
skipDefaultIndexes?: boolean;
|
|
63
|
+
indexes?: CreateIndexOptions[];
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Internal config for DsqlDB - accepts already-resolved client
|
|
67
|
+
*/
|
|
68
|
+
export interface DsqlDBInternalConfig {
|
|
69
|
+
client: DbClient;
|
|
70
|
+
schemaName?: string;
|
|
71
|
+
skipDefaultIndexes?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export declare class DsqlDB extends MastraBase {
|
|
74
|
+
client: DbClient;
|
|
75
|
+
schemaName?: string;
|
|
76
|
+
skipDefaultIndexes?: boolean;
|
|
77
|
+
constructor(config: DsqlDBInternalConfig);
|
|
78
|
+
hasColumn(table: string, column: string): Promise<boolean>;
|
|
79
|
+
/**
|
|
80
|
+
* Prepares values for insertion, handling TEXT columns storing JSON by stringifying them.
|
|
81
|
+
* Aurora DSQL does not support JSONB natively, so we store JSON as TEXT.
|
|
82
|
+
*/
|
|
83
|
+
private prepareValuesForInsert;
|
|
84
|
+
/**
|
|
85
|
+
* Adds timestamp Z columns to a record if timestamp columns exist
|
|
86
|
+
*/
|
|
87
|
+
private addTimestampZColumns;
|
|
88
|
+
/**
|
|
89
|
+
* Prepares a value for database operations, handling Date objects and JSON serialization.
|
|
90
|
+
* This is schema-aware and stringifies objects for TEXT columns storing JSON.
|
|
91
|
+
* Aurora DSQL: We use TEXT instead of JSONB and cast to ::jsonb when filtering.
|
|
92
|
+
*/
|
|
93
|
+
private prepareValue;
|
|
94
|
+
private setupSchema;
|
|
95
|
+
/**
|
|
96
|
+
* Override getSqlType to map JSONB to TEXT for Aurora DSQL compatibility.
|
|
97
|
+
* Aurora DSQL does not fully support native JSONB, so we store JSON as TEXT
|
|
98
|
+
* and cast to ::jsonb only when filtering/querying.
|
|
99
|
+
*/
|
|
100
|
+
protected getSqlType(type: StorageColumn['type']): string;
|
|
101
|
+
protected getDefaultValue(type: StorageColumn['type']): string;
|
|
102
|
+
insert({ tableName, record }: {
|
|
103
|
+
tableName: TABLE_NAMES;
|
|
104
|
+
record: Record<string, any>;
|
|
105
|
+
}): Promise<void>;
|
|
106
|
+
clearTable({ tableName }: {
|
|
107
|
+
tableName: TABLE_NAMES;
|
|
108
|
+
}): Promise<void>;
|
|
109
|
+
createTable({ tableName, schema, }: {
|
|
110
|
+
tableName: TABLE_NAMES;
|
|
111
|
+
schema: Record<string, StorageColumn>;
|
|
112
|
+
}): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Set up timestamp triggers for a table to automatically manage createdAt/updatedAt
|
|
115
|
+
* Note: Aurora DSQL doesn't support triggers, PL/pgSQL, or CREATE FUNCTION.
|
|
116
|
+
* Timestamps are managed at the application level in insert/update operations.
|
|
117
|
+
* This method is kept as a no-op for API compatibility.
|
|
118
|
+
*/
|
|
119
|
+
private setupTimestampTriggers;
|
|
120
|
+
/**
|
|
121
|
+
* Migrates the spans table schema from OLD_SPAN_SCHEMA to current SPAN_SCHEMA.
|
|
122
|
+
* This adds new columns that don't exist in old schema.
|
|
123
|
+
*/
|
|
124
|
+
private migrateSpansTable;
|
|
125
|
+
/**
|
|
126
|
+
* Alters table schema to add columns if they don't exist
|
|
127
|
+
* @param tableName Name of the table
|
|
128
|
+
* @param schema Schema of the table
|
|
129
|
+
* @param ifNotExists Array of column names to add if they don't exist
|
|
130
|
+
*/
|
|
131
|
+
alterTable({ tableName, schema, ifNotExists, }: {
|
|
132
|
+
tableName: TABLE_NAMES;
|
|
133
|
+
schema: Record<string, StorageColumn>;
|
|
134
|
+
ifNotExists: string[];
|
|
135
|
+
}): Promise<void>;
|
|
136
|
+
load<R>({ tableName, keys }: {
|
|
137
|
+
tableName: TABLE_NAMES;
|
|
138
|
+
keys: Record<string, string>;
|
|
139
|
+
}): Promise<R | null>;
|
|
140
|
+
batchInsert({ tableName, records }: {
|
|
141
|
+
tableName: TABLE_NAMES;
|
|
142
|
+
records: Record<string, any>[];
|
|
143
|
+
}): Promise<void>;
|
|
144
|
+
dropTable({ tableName }: {
|
|
145
|
+
tableName: TABLE_NAMES;
|
|
146
|
+
}): Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Wait for an asynchronous DSQL job to complete.
|
|
149
|
+
* Aurora DSQL requires CREATE INDEX ASYNC and sys.wait_for_job() to wait for completion.
|
|
150
|
+
*/
|
|
151
|
+
private waitForDSQLJob;
|
|
152
|
+
createIndex(options: CreateIndexOptions): Promise<void>;
|
|
153
|
+
dropIndex(indexName: string): Promise<void>;
|
|
154
|
+
listIndexes(tableName?: string): Promise<IndexInfo[]>;
|
|
155
|
+
describeIndex(indexName: string): Promise<StorageIndexStats>;
|
|
156
|
+
update({ tableName, keys, data, }: {
|
|
157
|
+
tableName: TABLE_NAMES;
|
|
158
|
+
keys: Record<string, any>;
|
|
159
|
+
data: Record<string, any>;
|
|
160
|
+
}): Promise<void>;
|
|
161
|
+
batchUpdate({ tableName, updates, }: {
|
|
162
|
+
tableName: TABLE_NAMES;
|
|
163
|
+
updates: Array<{
|
|
164
|
+
keys: Record<string, any>;
|
|
165
|
+
data: Record<string, any>;
|
|
166
|
+
}>;
|
|
167
|
+
}): Promise<void>;
|
|
168
|
+
batchDelete({ tableName, keys }: {
|
|
169
|
+
tableName: TABLE_NAMES;
|
|
170
|
+
keys: Record<string, any>[];
|
|
171
|
+
}): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Delete all data from a table (alias for clearTable for consistency with other stores)
|
|
174
|
+
*/
|
|
175
|
+
deleteData({ tableName }: {
|
|
176
|
+
tableName: TABLE_NAMES;
|
|
177
|
+
}): Promise<void>;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=index.d.ts.map
|