@mastra/pg 1.0.0-beta.1 → 1.0.0-beta.11
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 +548 -0
- package/README.md +3 -0
- package/dist/index.cjs +3239 -2110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3232 -2108
- package/dist/index.js.map +1 -1
- package/dist/shared/config.d.ts +121 -31
- package/dist/shared/config.d.ts.map +1 -1
- package/dist/storage/client.d.ts +91 -0
- package/dist/storage/client.d.ts.map +1 -0
- package/dist/storage/db/index.d.ts +170 -0
- package/dist/storage/db/index.d.ts.map +1 -0
- package/dist/storage/domains/agents/index.d.ts +39 -0
- package/dist/storage/domains/agents/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +30 -11
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +29 -36
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +26 -29
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/utils.d.ts +1 -5
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +30 -19
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +51 -195
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/performance-indexes/performance-test.d.ts +3 -1
- package/dist/storage/performance-indexes/performance-test.d.ts.map +1 -1
- package/dist/storage/test-utils.d.ts.map +1 -1
- package/dist/vector/index.d.ts +42 -6
- package/dist/vector/index.d.ts.map +1 -1
- package/dist/vector/sql-builder.d.ts +4 -0
- package/dist/vector/sql-builder.d.ts.map +1 -1
- package/dist/vector/types.d.ts +10 -0
- package/dist/vector/types.d.ts.map +1 -1
- package/package.json +6 -8
- package/dist/storage/domains/operations/index.d.ts +0 -119
- package/dist/storage/domains/operations/index.d.ts.map +0 -1
package/dist/shared/config.d.ts
CHANGED
|
@@ -1,49 +1,139 @@
|
|
|
1
|
-
import type { ConnectionOptions } from 'tls';
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
4
|
-
import type { ISSLConfig } from 'pg-promise/typescript/pg-subset';
|
|
1
|
+
import type { ConnectionOptions } from 'node:tls';
|
|
2
|
+
import type { CreateIndexOptions } from '@mastra/core/storage';
|
|
3
|
+
import type { ClientConfig, Pool, PoolConfig } from 'pg';
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @template SSLType - The SSL configuration type (ISSLConfig for pg-promise, ConnectionOptions for pg)
|
|
5
|
+
* Base configuration options shared across PostgreSQL configs.
|
|
8
6
|
*/
|
|
9
|
-
export
|
|
7
|
+
export interface PostgresBaseConfig {
|
|
10
8
|
id: string;
|
|
11
9
|
schemaName?: string;
|
|
10
|
+
/**
|
|
11
|
+
* When true, automatic initialization (table creation/migrations) is disabled.
|
|
12
|
+
* This is useful for CI/CD pipelines where you want to:
|
|
13
|
+
* 1. Run migrations explicitly during deployment (not at runtime)
|
|
14
|
+
* 2. Use different credentials for schema changes vs runtime operations
|
|
15
|
+
*
|
|
16
|
+
* When disableInit is true:
|
|
17
|
+
* - The storage will not automatically create/alter tables on first use
|
|
18
|
+
* - You must call `storage.init()` explicitly in your CI/CD scripts
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // In CI/CD script:
|
|
22
|
+
* const storage = new PostgresStore({ ...config, disableInit: false });
|
|
23
|
+
* await storage.init(); // Explicitly run migrations
|
|
24
|
+
*
|
|
25
|
+
* // In runtime application:
|
|
26
|
+
* const storage = new PostgresStore({ ...config, disableInit: true });
|
|
27
|
+
* // No auto-init, tables must already exist
|
|
28
|
+
*/
|
|
29
|
+
disableInit?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* When true, default indexes will not be created during initialization.
|
|
32
|
+
* This is useful when:
|
|
33
|
+
* 1. You want to manage indexes separately or use custom indexes only
|
|
34
|
+
* 2. Default indexes don't match your query patterns
|
|
35
|
+
* 3. You want to reduce initialization time in development
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
skipDefaultIndexes?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Custom indexes to create during initialization.
|
|
42
|
+
* These indexes are created in addition to default indexes (unless skipDefaultIndexes is true).
|
|
43
|
+
*
|
|
44
|
+
* Each index must specify which table it belongs to. The store will route each index
|
|
45
|
+
* to the appropriate domain based on the table name.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const store = new PostgresStore({
|
|
50
|
+
* connectionString: '...',
|
|
51
|
+
* indexes: [
|
|
52
|
+
* { name: 'my_threads_type_idx', table: 'mastra_threads', columns: ['metadata->>\'type\''] },
|
|
53
|
+
* { name: 'my_messages_status_idx', table: 'mastra_messages', columns: ['metadata->>\'status\''] },
|
|
54
|
+
* ],
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
indexes?: CreateIndexOptions[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Connection string configuration.
|
|
62
|
+
*/
|
|
63
|
+
export interface ConnectionStringConfig extends PostgresBaseConfig {
|
|
64
|
+
connectionString: string;
|
|
65
|
+
ssl?: boolean | ConnectionOptions;
|
|
12
66
|
max?: number;
|
|
13
67
|
idleTimeoutMillis?: number;
|
|
14
|
-
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Host-based configuration.
|
|
71
|
+
*/
|
|
72
|
+
export interface HostConfig extends PostgresBaseConfig {
|
|
15
73
|
host: string;
|
|
16
74
|
port: number;
|
|
17
75
|
database: string;
|
|
18
76
|
user: string;
|
|
19
77
|
password: string;
|
|
20
|
-
ssl?: boolean |
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
78
|
+
ssl?: boolean | ConnectionOptions;
|
|
79
|
+
max?: number;
|
|
80
|
+
idleTimeoutMillis?: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Pre-configured pg.Pool configuration.
|
|
84
|
+
*/
|
|
85
|
+
export interface PoolInstanceConfig extends PostgresBaseConfig {
|
|
86
|
+
/**
|
|
87
|
+
* Pre-configured pg.Pool instance.
|
|
88
|
+
* Use this for direct control over the connection pool, or for
|
|
89
|
+
* integration with libraries that expect a pg.Pool.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { Pool } from 'pg';
|
|
94
|
+
*
|
|
95
|
+
* const pool = new Pool({ connectionString: '...' });
|
|
96
|
+
* const store = new PostgresStore({ id: 'my-store', pool });
|
|
97
|
+
*
|
|
98
|
+
* // Use store.pool for other libraries that need a pg.Pool
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
pool: Pool;
|
|
102
|
+
}
|
|
25
103
|
/**
|
|
26
|
-
* PostgreSQL configuration for PostgresStore
|
|
104
|
+
* PostgreSQL configuration for PostgresStore.
|
|
105
|
+
*
|
|
106
|
+
* Accepts either:
|
|
107
|
+
* - A pre-configured pg.Pool: `{ id, pool, schemaName? }`
|
|
108
|
+
* - Connection string: `{ id, connectionString, ... }`
|
|
109
|
+
* - Host/port config: `{ id, host, port, database, user, password, ... }`
|
|
110
|
+
* - Cloud SQL connector config: `{ id, stream, ... }` (via pg.ClientConfig)
|
|
27
111
|
*/
|
|
28
|
-
export type PostgresStoreConfig =
|
|
112
|
+
export type PostgresStoreConfig = PoolInstanceConfig | ConnectionStringConfig | HostConfig | (PostgresBaseConfig & ClientConfig);
|
|
29
113
|
/**
|
|
30
114
|
* PostgreSQL configuration for PgVector (uses pg with ConnectionOptions)
|
|
31
115
|
*/
|
|
32
|
-
export type PgVectorConfig =
|
|
33
|
-
pgPoolOptions?: Omit<
|
|
34
|
-
};
|
|
35
|
-
export declare const isConnectionStringConfig: <SSLType>(cfg: PostgresConfig<SSLType>) => cfg is PostgresConfig<SSLType> & {
|
|
36
|
-
connectionString: string;
|
|
37
|
-
ssl?: boolean | SSLType;
|
|
38
|
-
};
|
|
39
|
-
export declare const isHostConfig: <SSLType>(cfg: PostgresConfig<SSLType>) => cfg is PostgresConfig<SSLType> & {
|
|
40
|
-
host: string;
|
|
41
|
-
port: number;
|
|
42
|
-
database: string;
|
|
43
|
-
user: string;
|
|
44
|
-
password: string;
|
|
45
|
-
ssl?: boolean | SSLType;
|
|
116
|
+
export type PgVectorConfig = (ConnectionStringConfig | HostConfig | (PostgresBaseConfig & ClientConfig)) & {
|
|
117
|
+
pgPoolOptions?: Omit<PoolConfig, 'connectionString'>;
|
|
46
118
|
};
|
|
47
|
-
|
|
48
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Type guard for pre-configured pg.Pool config
|
|
121
|
+
*/
|
|
122
|
+
export declare const isPoolConfig: (cfg: PostgresStoreConfig) => cfg is PoolInstanceConfig;
|
|
123
|
+
/**
|
|
124
|
+
* Type guard for connection string config
|
|
125
|
+
*/
|
|
126
|
+
export declare const isConnectionStringConfig: (cfg: PostgresStoreConfig) => cfg is ConnectionStringConfig;
|
|
127
|
+
/**
|
|
128
|
+
* Type guard for host-based config
|
|
129
|
+
*/
|
|
130
|
+
export declare const isHostConfig: (cfg: PostgresStoreConfig) => cfg is HostConfig;
|
|
131
|
+
/**
|
|
132
|
+
* Type guard for Cloud SQL connector config
|
|
133
|
+
*/
|
|
134
|
+
export declare const isCloudSqlConfig: (cfg: PostgresStoreConfig) => cfg is PostgresBaseConfig & ClientConfig;
|
|
135
|
+
/**
|
|
136
|
+
* Validate PostgresStore configuration.
|
|
137
|
+
*/
|
|
138
|
+
export declare const validateConfig: (name: string, config: PostgresStoreConfig) => void;
|
|
49
139
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/shared/config.ts"],"names":[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kBAAkB;IAC5D;;;;;;;;;;;;;;OAcG;IACH,IAAI,EAAE,IAAI,CAAC;CACZ;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,mBAAmB,GAC3B,kBAAkB,GAClB,sBAAsB,GACtB,UAAU,GACV,CAAC,kBAAkB,GAAG,YAAY,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,sBAAsB,GAAG,UAAU,GAAG,CAAC,kBAAkB,GAAG,YAAY,CAAC,CAAC,GAAG;IACzG,aAAa,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;CACtD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,mBAAmB,KAAG,GAAG,IAAI,kBAE9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,KAAK,mBAAmB,KAAG,GAAG,IAAI,sBAE1E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,mBAAmB,KAAG,GAAG,IAAI,UAE9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,mBAAmB,KAAG,GAAG,IAAI,kBAAkB,GAAG,YAEvF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,QAAQ,mBAAmB,SAuCvE,CAAC"}
|
|
@@ -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
|
+
* PoolAdapter 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
|
|
@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AAG,OAAO,CAAC,CAAC,CAAC;CAoB/D"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { ConnectionOptions } from 'node:tls';
|
|
2
|
+
import { MastraBase } from '@mastra/core/base';
|
|
3
|
+
import type { StorageColumn, TABLE_NAMES, CreateIndexOptions, IndexInfo, StorageIndexStats } from '@mastra/core/storage';
|
|
4
|
+
import { Pool } from 'pg';
|
|
5
|
+
import type { DbClient } from '../client.js';
|
|
6
|
+
export type { DbClient } from '../client.js';
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for standalone domain usage.
|
|
9
|
+
* Accepts either:
|
|
10
|
+
* 1. An existing database client (Pool or PoolAdapter)
|
|
11
|
+
* 2. Config to create a new pool internally
|
|
12
|
+
*/
|
|
13
|
+
export type PgDomainConfig = PgDomainClientConfig | PgDomainPoolConfig | PgDomainRestConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Pass an existing database client (DbClient)
|
|
16
|
+
*/
|
|
17
|
+
export interface PgDomainClientConfig {
|
|
18
|
+
/** The database client */
|
|
19
|
+
client: DbClient;
|
|
20
|
+
/** Optional schema name (defaults to 'public') */
|
|
21
|
+
schemaName?: string;
|
|
22
|
+
/** When true, default indexes will not be created during initialization */
|
|
23
|
+
skipDefaultIndexes?: boolean;
|
|
24
|
+
/** Custom indexes to create for this domain's tables */
|
|
25
|
+
indexes?: CreateIndexOptions[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Pass an existing pg.Pool
|
|
29
|
+
*/
|
|
30
|
+
export interface PgDomainPoolConfig {
|
|
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 PgDomainRestConfig = {
|
|
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
|
+
port: number;
|
|
53
|
+
database: string;
|
|
54
|
+
user: string;
|
|
55
|
+
password: string;
|
|
56
|
+
ssl?: boolean | ConnectionOptions;
|
|
57
|
+
} | {
|
|
58
|
+
connectionString: string;
|
|
59
|
+
ssl?: boolean | ConnectionOptions;
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* Resolves PgDomainConfig to a database client and schema.
|
|
63
|
+
* Handles creating a new pool if config is provided.
|
|
64
|
+
*/
|
|
65
|
+
export declare function resolvePgConfig(config: PgDomainConfig): {
|
|
66
|
+
client: DbClient;
|
|
67
|
+
schemaName?: string;
|
|
68
|
+
skipDefaultIndexes?: boolean;
|
|
69
|
+
indexes?: CreateIndexOptions[];
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Exports the Mastra database schema as SQL DDL statements.
|
|
73
|
+
* Does not require a database connection.
|
|
74
|
+
*/
|
|
75
|
+
export declare function exportSchemas(schemaName?: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Internal config for PgDB - accepts already-resolved client
|
|
78
|
+
*/
|
|
79
|
+
export interface PgDBInternalConfig {
|
|
80
|
+
client: DbClient;
|
|
81
|
+
schemaName?: string;
|
|
82
|
+
skipDefaultIndexes?: boolean;
|
|
83
|
+
}
|
|
84
|
+
export declare class PgDB extends MastraBase {
|
|
85
|
+
client: DbClient;
|
|
86
|
+
schemaName?: string;
|
|
87
|
+
skipDefaultIndexes?: boolean;
|
|
88
|
+
constructor(config: PgDBInternalConfig);
|
|
89
|
+
hasColumn(table: string, column: string): Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* Prepares values for insertion, handling JSONB columns by stringifying them
|
|
92
|
+
*/
|
|
93
|
+
private prepareValuesForInsert;
|
|
94
|
+
/**
|
|
95
|
+
* Adds timestamp Z columns to a record if timestamp columns exist
|
|
96
|
+
*/
|
|
97
|
+
private addTimestampZColumns;
|
|
98
|
+
/**
|
|
99
|
+
* Prepares a value for database operations
|
|
100
|
+
*/
|
|
101
|
+
private prepareValue;
|
|
102
|
+
private setupSchema;
|
|
103
|
+
protected getDefaultValue(type: StorageColumn['type']): string;
|
|
104
|
+
insert({ tableName, record }: {
|
|
105
|
+
tableName: TABLE_NAMES;
|
|
106
|
+
record: Record<string, any>;
|
|
107
|
+
}): Promise<void>;
|
|
108
|
+
clearTable({ tableName }: {
|
|
109
|
+
tableName: TABLE_NAMES;
|
|
110
|
+
}): Promise<void>;
|
|
111
|
+
createTable({ tableName, schema, }: {
|
|
112
|
+
tableName: TABLE_NAMES;
|
|
113
|
+
schema: Record<string, StorageColumn>;
|
|
114
|
+
}): Promise<void>;
|
|
115
|
+
private setupTimestampTriggers;
|
|
116
|
+
/**
|
|
117
|
+
* Migrates the spans table schema from OLD_SPAN_SCHEMA to current SPAN_SCHEMA.
|
|
118
|
+
* This adds new columns that don't exist in old schema.
|
|
119
|
+
*/
|
|
120
|
+
private migrateSpansTable;
|
|
121
|
+
/**
|
|
122
|
+
* Alters table schema to add columns if they don't exist
|
|
123
|
+
* @param tableName Name of the table
|
|
124
|
+
* @param schema Schema of the table
|
|
125
|
+
* @param ifNotExists Array of column names to add if they don't exist
|
|
126
|
+
*/
|
|
127
|
+
alterTable({ tableName, schema, ifNotExists, }: {
|
|
128
|
+
tableName: TABLE_NAMES;
|
|
129
|
+
schema: Record<string, StorageColumn>;
|
|
130
|
+
ifNotExists: string[];
|
|
131
|
+
}): Promise<void>;
|
|
132
|
+
load<R>({ tableName, keys }: {
|
|
133
|
+
tableName: TABLE_NAMES;
|
|
134
|
+
keys: Record<string, string>;
|
|
135
|
+
}): Promise<R | null>;
|
|
136
|
+
batchInsert({ tableName, records }: {
|
|
137
|
+
tableName: TABLE_NAMES;
|
|
138
|
+
records: Record<string, any>[];
|
|
139
|
+
}): Promise<void>;
|
|
140
|
+
dropTable({ tableName }: {
|
|
141
|
+
tableName: TABLE_NAMES;
|
|
142
|
+
}): Promise<void>;
|
|
143
|
+
createIndex(options: CreateIndexOptions): Promise<void>;
|
|
144
|
+
dropIndex(indexName: string): Promise<void>;
|
|
145
|
+
listIndexes(tableName?: string): Promise<IndexInfo[]>;
|
|
146
|
+
describeIndex(indexName: string): Promise<StorageIndexStats>;
|
|
147
|
+
update({ tableName, keys, data, }: {
|
|
148
|
+
tableName: TABLE_NAMES;
|
|
149
|
+
keys: Record<string, any>;
|
|
150
|
+
data: Record<string, any>;
|
|
151
|
+
}): Promise<void>;
|
|
152
|
+
batchUpdate({ tableName, updates, }: {
|
|
153
|
+
tableName: TABLE_NAMES;
|
|
154
|
+
updates: Array<{
|
|
155
|
+
keys: Record<string, any>;
|
|
156
|
+
data: Record<string, any>;
|
|
157
|
+
}>;
|
|
158
|
+
}): Promise<void>;
|
|
159
|
+
batchDelete({ tableName, keys }: {
|
|
160
|
+
tableName: TABLE_NAMES;
|
|
161
|
+
keys: Record<string, any>[];
|
|
162
|
+
}): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Delete all data from a table (alias for clearTable for consistency with other stores)
|
|
165
|
+
*/
|
|
166
|
+
deleteData({ tableName }: {
|
|
167
|
+
tableName: TABLE_NAMES;
|
|
168
|
+
}): Promise<void>;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/db/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAA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gentInput, StorageListAgentsInput, StorageListAgentsOutput, CreateIndexOptions } from '@mastra/core/storage';
|
|
3
|
+
import type { PgDomainConfig } from '../../db/index.js';
|
|
4
|
+
export declare class AgentsPG extends AgentsStorage {
|
|
5
|
+
#private;
|
|
6
|
+
/** Tables managed by this domain */
|
|
7
|
+
static readonly MANAGED_TABLES: readonly ["mastra_agents"];
|
|
8
|
+
constructor(config: PgDomainConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Returns default index definitions for the agents domain tables.
|
|
11
|
+
* Currently no default indexes are defined for agents.
|
|
12
|
+
*/
|
|
13
|
+
getDefaultIndexDefinitions(): CreateIndexOptions[];
|
|
14
|
+
/**
|
|
15
|
+
* Creates default indexes for optimal query performance.
|
|
16
|
+
* Currently no default indexes are defined for agents.
|
|
17
|
+
*/
|
|
18
|
+
createDefaultIndexes(): Promise<void>;
|
|
19
|
+
init(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Creates custom user-defined indexes for this domain's tables.
|
|
22
|
+
*/
|
|
23
|
+
createCustomIndexes(): Promise<void>;
|
|
24
|
+
dangerouslyClearAll(): Promise<void>;
|
|
25
|
+
private parseJson;
|
|
26
|
+
private parseRow;
|
|
27
|
+
getAgentById({ id }: {
|
|
28
|
+
id: string;
|
|
29
|
+
}): Promise<StorageAgentType | null>;
|
|
30
|
+
createAgent({ agent }: {
|
|
31
|
+
agent: StorageCreateAgentInput;
|
|
32
|
+
}): Promise<StorageAgentType>;
|
|
33
|
+
updateAgent({ id, ...updates }: StorageUpdateAgentInput): Promise<StorageAgentType>;
|
|
34
|
+
deleteAgent({ id }: {
|
|
35
|
+
id: string;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
listAgents(args?: StorageListAgentsInput): Promise<StorageListAgentsOutput>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/dom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
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import type { MastraMessageContentV2 } from '@mastra/core/agent';
|
|
2
2
|
import type { MastraDBMessage, StorageThreadType } from '@mastra/core/memory';
|
|
3
3
|
import { MemoryStorage } from '@mastra/core/storage';
|
|
4
|
-
import type { StorageResourceType, StorageListMessagesInput, StorageListMessagesOutput, StorageListThreadsByResourceIdInput, StorageListThreadsByResourceIdOutput } from '@mastra/core/storage';
|
|
5
|
-
import type {
|
|
6
|
-
import type { StoreOperationsPG } from '../operations/index.js';
|
|
4
|
+
import type { StorageResourceType, StorageListMessagesInput, StorageListMessagesOutput, StorageListThreadsByResourceIdInput, StorageListThreadsByResourceIdOutput, CreateIndexOptions } from '@mastra/core/storage';
|
|
5
|
+
import type { PgDomainConfig } from '../../db/index.js';
|
|
7
6
|
export declare class MemoryPG extends MemoryStorage {
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
#private;
|
|
8
|
+
/** Tables managed by this domain */
|
|
9
|
+
static readonly MANAGED_TABLES: readonly ["mastra_threads", "mastra_messages", "mastra_resources"];
|
|
10
|
+
constructor(config: PgDomainConfig);
|
|
11
|
+
init(): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Returns default index definitions for the memory domain tables.
|
|
14
|
+
*/
|
|
15
|
+
getDefaultIndexDefinitions(): CreateIndexOptions[];
|
|
16
|
+
/**
|
|
17
|
+
* Creates default indexes for optimal query performance.
|
|
18
|
+
*/
|
|
19
|
+
createDefaultIndexes(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Creates custom user-defined indexes for this domain's tables.
|
|
22
|
+
*/
|
|
23
|
+
createCustomIndexes(): Promise<void>;
|
|
24
|
+
dangerouslyClearAll(): Promise<void>;
|
|
16
25
|
/**
|
|
17
26
|
* Normalizes message row from database by applying createdAtZ fallback
|
|
18
27
|
*/
|
|
@@ -32,6 +41,16 @@ export declare class MemoryPG extends MemoryStorage {
|
|
|
32
41
|
deleteThread({ threadId }: {
|
|
33
42
|
threadId: string;
|
|
34
43
|
}): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Fetches messages around target messages using cursor-based pagination.
|
|
46
|
+
*
|
|
47
|
+
* This replaces the previous ROW_NUMBER() approach which caused severe performance
|
|
48
|
+
* issues on large tables (see GitHub issue #11150). The old approach required
|
|
49
|
+
* scanning and sorting ALL messages in a thread to assign row numbers.
|
|
50
|
+
*
|
|
51
|
+
* The new approach uses the existing (thread_id, createdAt) index to efficiently
|
|
52
|
+
* fetch only the messages needed by using createdAt as a cursor.
|
|
53
|
+
*/
|
|
35
54
|
private _getIncludedMessages;
|
|
36
55
|
private parseRow;
|
|
37
56
|
listMessagesById({ messageIds }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/memory/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,KAAK,EAAmB,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EACL,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/memory/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,KAAK,EAAmB,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EACL,aAAa,EAQd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,mCAAmC,EACnC,oCAAoC,EACpC,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;A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-1,44 +1,37 @@
|
|
|
1
|
-
import type { TracingStorageStrategy } from '@mastra/core/observability';
|
|
2
1
|
import { ObservabilityStorage } from '@mastra/core/storage';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type { StoreOperationsPG } from '../operations/index.js';
|
|
2
|
+
import type { TracingStorageStrategy, ListTracesArgs, UpdateSpanArgs, BatchDeleteTracesArgs, BatchUpdateSpansArgs, BatchCreateSpansArgs, CreateSpanArgs, GetSpanArgs, GetSpanResponse, GetRootSpanArgs, GetRootSpanResponse, GetTraceArgs, GetTraceResponse, ListTracesResponse, CreateIndexOptions } from '@mastra/core/storage';
|
|
3
|
+
import type { PgDomainConfig } from '../../db/index.js';
|
|
6
4
|
export declare class ObservabilityPG extends ObservabilityStorage {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
constructor(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
#private;
|
|
6
|
+
/** Tables managed by this domain */
|
|
7
|
+
static readonly MANAGED_TABLES: readonly ["mastra_ai_spans"];
|
|
8
|
+
constructor(config: PgDomainConfig);
|
|
9
|
+
init(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns default index definitions for the observability domain tables.
|
|
12
|
+
*/
|
|
13
|
+
getDefaultIndexDefinitions(): CreateIndexOptions[];
|
|
14
|
+
/**
|
|
15
|
+
* Creates default indexes for optimal query performance.
|
|
16
|
+
*/
|
|
17
|
+
createDefaultIndexes(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates custom user-defined indexes for this domain's tables.
|
|
20
|
+
*/
|
|
21
|
+
createCustomIndexes(): Promise<void>;
|
|
22
|
+
dangerouslyClearAll(): Promise<void>;
|
|
15
23
|
get tracingStrategy(): {
|
|
16
24
|
preferred: TracingStorageStrategy;
|
|
17
25
|
supported: TracingStorageStrategy[];
|
|
18
26
|
};
|
|
19
|
-
createSpan(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
spans: SpanRecord[];
|
|
29
|
-
}>;
|
|
30
|
-
batchCreateSpans(args: {
|
|
31
|
-
records: CreateSpanRecord[];
|
|
32
|
-
}): Promise<void>;
|
|
33
|
-
batchUpdateSpans(args: {
|
|
34
|
-
records: {
|
|
35
|
-
traceId: string;
|
|
36
|
-
spanId: string;
|
|
37
|
-
updates: Partial<UpdateSpanRecord>;
|
|
38
|
-
}[];
|
|
39
|
-
}): Promise<void>;
|
|
40
|
-
batchDeleteTraces(args: {
|
|
41
|
-
traceIds: string[];
|
|
42
|
-
}): Promise<void>;
|
|
27
|
+
createSpan(args: CreateSpanArgs): Promise<void>;
|
|
28
|
+
getSpan(args: GetSpanArgs): Promise<GetSpanResponse | null>;
|
|
29
|
+
getRootSpan(args: GetRootSpanArgs): Promise<GetRootSpanResponse | null>;
|
|
30
|
+
getTrace(args: GetTraceArgs): Promise<GetTraceResponse | null>;
|
|
31
|
+
updateSpan(args: UpdateSpanArgs): Promise<void>;
|
|
32
|
+
listTraces(args: ListTracesArgs): Promise<ListTracesResponse>;
|
|
33
|
+
batchCreateSpans(args: BatchCreateSpansArgs): Promise<void>;
|
|
34
|
+
batchUpdateSpans(args: BatchUpdateSpansArgs): Promise<void>;
|
|
35
|
+
batchDeleteTraces(args: BatchDeleteTracesArgs): Promise<void>;
|
|
43
36
|
}
|
|
44
37
|
//# sourceMappingURL=index.d.ts.map
|