@mastra/pg 0.1.0-alpha.9 → 0.1.1-alpha.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.
@@ -0,0 +1,18 @@
1
+
2
+ > @mastra/pg@0.1.0-alpha.5 build C:\Users\Ward\projects\mastra\mastra\stores\pg
3
+ > tsup src/index.ts --format esm --experimental-dts --clean --treeshake
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.3.6
8
+ TSC Build start
9
+ TSC ⚡️ Build success in 3965ms
10
+ DTS Build start
11
+ CLI Target: es2020
12
+ Analysis will use the bundled TypeScript version 5.7.3
13
+ Writing package typings: C:\Users\Ward\projects\mastra\mastra\stores\pg\dist\_tsup-dts-rollup.d.ts
14
+ DTS ⚡️ Build success in 3335ms
15
+ CLI Cleaning output folder
16
+ ESM Build start
17
+ ESM dist\index.js 28.16 KB
18
+ ESM ⚡️ Build success in 191ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,288 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 0.1.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [d59f1a8]
8
+ - Updated dependencies [91ef439]
9
+ - Updated dependencies [4a25be4]
10
+ - Updated dependencies [bf2e88f]
11
+ - Updated dependencies [2f0d707]
12
+ - Updated dependencies [aac1667]
13
+ - @mastra/core@0.2.1-alpha.0
14
+
15
+ ## 0.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - c87eb4e: Combine PostgreSQL packages into `@mastra/pg`.
20
+
21
+ - Move and combine packages to `stores/pg`
22
+ - Reorganize source files into `src/vector` and `src/store`
23
+ - Add deprecation notices to old packages
24
+ - Update documentation and examples
25
+ - No breaking changes in functionality
26
+
27
+ - 8b416d9: Breaking changes
28
+
29
+ ### Patch Changes
30
+
31
+ - b97ca96: Tracing into default storage
32
+ - 07c069d: Update build script
33
+ - 9c10484: update all packages
34
+ - 70dabd9: Fix broken publish
35
+ - 4f1d1a1: Enforce types ann cleanup package.json
36
+ - Updated dependencies [f537e33]
37
+ - Updated dependencies [6f2c0f5]
38
+ - Updated dependencies [e4d4ede]
39
+ - Updated dependencies [0be7181]
40
+ - Updated dependencies [dd6d87f]
41
+ - Updated dependencies [9029796]
42
+ - Updated dependencies [6fa4bd2]
43
+ - Updated dependencies [f031a1f]
44
+ - Updated dependencies [8151f44]
45
+ - Updated dependencies [d7d465a]
46
+ - Updated dependencies [4d4f6b6]
47
+ - Updated dependencies [73d112c]
48
+ - Updated dependencies [592e3cf]
49
+ - Updated dependencies [9d1796d]
50
+ - Updated dependencies [e897f1c]
51
+ - Updated dependencies [4a54c82]
52
+ - Updated dependencies [3967e69]
53
+ - Updated dependencies [8ae2bbc]
54
+ - Updated dependencies [e9d1b47]
55
+ - Updated dependencies [016493a]
56
+ - Updated dependencies [bc40916]
57
+ - Updated dependencies [93a3719]
58
+ - Updated dependencies [7d83b92]
59
+ - Updated dependencies [9fb3039]
60
+ - Updated dependencies [d5e12de]
61
+ - Updated dependencies [e1dd94a]
62
+ - Updated dependencies [07c069d]
63
+ - Updated dependencies [5cdfb88]
64
+ - Updated dependencies [837a288]
65
+ - Updated dependencies [685108a]
66
+ - Updated dependencies [c8ff2f5]
67
+ - Updated dependencies [5fdc87c]
68
+ - Updated dependencies [ae7bf94]
69
+ - Updated dependencies [8e7814f]
70
+ - Updated dependencies [66a03ec]
71
+ - Updated dependencies [7d87a15]
72
+ - Updated dependencies [b97ca96]
73
+ - Updated dependencies [23dcb23]
74
+ - Updated dependencies [033eda6]
75
+ - Updated dependencies [8105fae]
76
+ - Updated dependencies [e097800]
77
+ - Updated dependencies [1944807]
78
+ - Updated dependencies [30322ce]
79
+ - Updated dependencies [1874f40]
80
+ - Updated dependencies [685108a]
81
+ - Updated dependencies [f7d1131]
82
+ - Updated dependencies [79acad0]
83
+ - Updated dependencies [7a19083]
84
+ - Updated dependencies [382f4dc]
85
+ - Updated dependencies [1ebd071]
86
+ - Updated dependencies [0b74006]
87
+ - Updated dependencies [2f17a5f]
88
+ - Updated dependencies [f368477]
89
+ - Updated dependencies [7892533]
90
+ - Updated dependencies [9c10484]
91
+ - Updated dependencies [b726bf5]
92
+ - Updated dependencies [70dabd9]
93
+ - Updated dependencies [21fe536]
94
+ - Updated dependencies [176bc42]
95
+ - Updated dependencies [401a4d9]
96
+ - Updated dependencies [2e099d2]
97
+ - Updated dependencies [0b826f6]
98
+ - Updated dependencies [d68b532]
99
+ - Updated dependencies [75bf3f0]
100
+ - Updated dependencies [e6d8055]
101
+ - Updated dependencies [e2e76de]
102
+ - Updated dependencies [ccbc581]
103
+ - Updated dependencies [5950de5]
104
+ - Updated dependencies [fe3dcb0]
105
+ - Updated dependencies [78eec7c]
106
+ - Updated dependencies [a8a459a]
107
+ - Updated dependencies [0be7181]
108
+ - Updated dependencies [7b87567]
109
+ - Updated dependencies [b524c22]
110
+ - Updated dependencies [d7d465a]
111
+ - Updated dependencies [df843d3]
112
+ - Updated dependencies [4534e77]
113
+ - Updated dependencies [d6d8159]
114
+ - Updated dependencies [0bd142c]
115
+ - Updated dependencies [9625602]
116
+ - Updated dependencies [72d1990]
117
+ - Updated dependencies [f6ba259]
118
+ - Updated dependencies [2712098]
119
+ - Updated dependencies [eedb829]
120
+ - Updated dependencies [5285356]
121
+ - Updated dependencies [74b3078]
122
+ - Updated dependencies [cb290ee]
123
+ - Updated dependencies [b4d7416]
124
+ - Updated dependencies [e608d8c]
125
+ - Updated dependencies [06b2c0a]
126
+ - Updated dependencies [002d6d8]
127
+ - Updated dependencies [e448a26]
128
+ - Updated dependencies [8b416d9]
129
+ - Updated dependencies [fd494a3]
130
+ - Updated dependencies [dc90663]
131
+ - Updated dependencies [c872875]
132
+ - Updated dependencies [3c4488b]
133
+ - Updated dependencies [a7b016d]
134
+ - Updated dependencies [fd75f3c]
135
+ - Updated dependencies [7f24c29]
136
+ - Updated dependencies [2017553]
137
+ - Updated dependencies [a10b7a3]
138
+ - Updated dependencies [cf6d825]
139
+ - Updated dependencies [963c15a]
140
+ - Updated dependencies [7365b6c]
141
+ - Updated dependencies [5ee67d3]
142
+ - Updated dependencies [d38f7a6]
143
+ - Updated dependencies [38b7f66]
144
+ - Updated dependencies [2fa7f53]
145
+ - Updated dependencies [1420ae2]
146
+ - Updated dependencies [f6da688]
147
+ - Updated dependencies [3700be1]
148
+ - Updated dependencies [9ade36e]
149
+ - Updated dependencies [10870bc]
150
+ - Updated dependencies [2b01511]
151
+ - Updated dependencies [a870123]
152
+ - Updated dependencies [ccf115c]
153
+ - Updated dependencies [04434b6]
154
+ - Updated dependencies [5811de6]
155
+ - Updated dependencies [9f3ab05]
156
+ - Updated dependencies [66a5392]
157
+ - Updated dependencies [4b1ce2c]
158
+ - Updated dependencies [14064f2]
159
+ - Updated dependencies [f5dfa20]
160
+ - Updated dependencies [327ece7]
161
+ - Updated dependencies [da2e8d3]
162
+ - Updated dependencies [95a4697]
163
+ - Updated dependencies [d5fccfb]
164
+ - Updated dependencies [3427b95]
165
+ - Updated dependencies [538a136]
166
+ - Updated dependencies [e66643a]
167
+ - Updated dependencies [b5393f1]
168
+ - Updated dependencies [d2cd535]
169
+ - Updated dependencies [c2dd6b5]
170
+ - Updated dependencies [67637ba]
171
+ - Updated dependencies [836f4e3]
172
+ - Updated dependencies [5ee2e78]
173
+ - Updated dependencies [cd02c56]
174
+ - Updated dependencies [01502b0]
175
+ - Updated dependencies [16e5b04]
176
+ - Updated dependencies [d9c8dd0]
177
+ - Updated dependencies [9fb59d6]
178
+ - Updated dependencies [a9345f9]
179
+ - Updated dependencies [99f1847]
180
+ - Updated dependencies [04f3171]
181
+ - Updated dependencies [8769a62]
182
+ - Updated dependencies [d5ec619]
183
+ - Updated dependencies [27275c9]
184
+ - Updated dependencies [ae7bf94]
185
+ - Updated dependencies [4f1d1a1]
186
+ - Updated dependencies [ee4de15]
187
+ - Updated dependencies [202d404]
188
+ - Updated dependencies [a221426]
189
+ - @mastra/core@0.2.0
190
+
191
+ ## 0.1.0-alpha.20
192
+
193
+ ### Patch Changes
194
+
195
+ - Updated dependencies [016493a]
196
+ - Updated dependencies [382f4dc]
197
+ - Updated dependencies [176bc42]
198
+ - Updated dependencies [d68b532]
199
+ - Updated dependencies [fe3dcb0]
200
+ - Updated dependencies [e448a26]
201
+ - Updated dependencies [fd75f3c]
202
+ - Updated dependencies [ccf115c]
203
+ - Updated dependencies [a221426]
204
+ - @mastra/core@0.2.0-alpha.110
205
+
206
+ ## 0.1.0-alpha.19
207
+
208
+ ### Patch Changes
209
+
210
+ - Updated dependencies [d5fccfb]
211
+ - @mastra/core@0.2.0-alpha.109
212
+
213
+ ## 0.1.0-alpha.18
214
+
215
+ ### Patch Changes
216
+
217
+ - Updated dependencies [5ee67d3]
218
+ - Updated dependencies [95a4697]
219
+ - @mastra/core@0.2.0-alpha.108
220
+
221
+ ## 0.1.0-alpha.17
222
+
223
+ ### Patch Changes
224
+
225
+ - Updated dependencies [66a5392]
226
+ - @mastra/core@0.2.0-alpha.107
227
+
228
+ ## 0.1.0-alpha.16
229
+
230
+ ### Patch Changes
231
+
232
+ - Updated dependencies [6f2c0f5]
233
+ - Updated dependencies [a8a459a]
234
+ - @mastra/core@0.2.0-alpha.106
235
+
236
+ ## 0.1.0-alpha.15
237
+
238
+ ### Patch Changes
239
+
240
+ - Updated dependencies [1420ae2]
241
+ - Updated dependencies [99f1847]
242
+ - @mastra/core@0.2.0-alpha.105
243
+
244
+ ## 0.1.0-alpha.14
245
+
246
+ ### Patch Changes
247
+
248
+ - b97ca96: Tracing into default storage
249
+ - Updated dependencies [5fdc87c]
250
+ - Updated dependencies [b97ca96]
251
+ - Updated dependencies [72d1990]
252
+ - Updated dependencies [cf6d825]
253
+ - Updated dependencies [10870bc]
254
+ - @mastra/core@0.2.0-alpha.104
255
+
256
+ ## 0.1.0-alpha.13
257
+
258
+ ### Patch Changes
259
+
260
+ - Updated dependencies [4534e77]
261
+ - @mastra/core@0.2.0-alpha.103
262
+
263
+ ## 0.1.0-alpha.12
264
+
265
+ ### Patch Changes
266
+
267
+ - Updated dependencies [a9345f9]
268
+ - @mastra/core@0.2.0-alpha.102
269
+
270
+ ## 0.1.0-alpha.11
271
+
272
+ ### Patch Changes
273
+
274
+ - 4f1d1a1: Enforce types ann cleanup package.json
275
+ - Updated dependencies [66a03ec]
276
+ - Updated dependencies [4f1d1a1]
277
+ - @mastra/core@0.2.0-alpha.101
278
+
279
+ ## 0.1.0-alpha.10
280
+
281
+ ### Patch Changes
282
+
283
+ - Updated dependencies [9d1796d]
284
+ - @mastra/core@0.2.0-alpha.100
285
+
3
286
  ## 0.1.0-alpha.9
4
287
 
5
288
  ### Patch Changes
@@ -0,0 +1,154 @@
1
+ import { ArrayOperator } from '@mastra/core/filter';
2
+ import { BaseFilterTranslator } from '@mastra/core/filter';
3
+ import { BasicOperator } from '@mastra/core/filter';
4
+ import { ElementOperator } from '@mastra/core/filter';
5
+ import { EvalRow } from '@mastra/core/storage';
6
+ import { Filter } from '@mastra/core/filter';
7
+ import { IndexStats } from '@mastra/core/vector';
8
+ import { LogicalOperator } from '@mastra/core/filter';
9
+ import { MastraStorage } from '@mastra/core/storage';
10
+ import { MastraVector } from '@mastra/core/vector';
11
+ import { MessageType } from '@mastra/core/memory';
12
+ import { NumericOperator } from '@mastra/core/filter';
13
+ import { OperatorSupport } from '@mastra/core/filter';
14
+ import { QueryResult } from '@mastra/core/vector';
15
+ import { RegexOperator } from '@mastra/core/filter';
16
+ import { StorageColumn } from '@mastra/core/storage';
17
+ import { StorageGetMessagesArg } from '@mastra/core/storage';
18
+ import { StorageThreadType } from '@mastra/core/memory';
19
+ import { TABLE_NAMES } from '@mastra/core/storage';
20
+ import { WorkflowRunState } from '@mastra/core/workflows';
21
+
22
+ export declare function buildFilterQuery(filter: Filter, minScore: number): FilterResult;
23
+
24
+ export declare const FILTER_OPERATORS: Record<string, OperatorFn>;
25
+
26
+ declare type FilterOperator = {
27
+ sql: string;
28
+ needsValue: boolean;
29
+ transformValue?: (value: any) => any;
30
+ };
31
+
32
+ export declare interface FilterResult {
33
+ sql: string;
34
+ values: any[];
35
+ }
36
+
37
+ export declare const handleKey: (key: string) => string;
38
+
39
+ declare type OperatorFn = (key: string, paramIndex: number, value?: any) => FilterOperator;
40
+
41
+ export declare type OperatorType = BasicOperator | NumericOperator | ArrayOperator | ElementOperator | LogicalOperator | '$contains' | Exclude<RegexOperator, '$options'>;
42
+
43
+ /**
44
+ * Translates MongoDB-style filters to PG compatible filters.
45
+ *
46
+ * Key differences from MongoDB:
47
+ *
48
+ * Logical Operators ($and, $or, $nor):
49
+ * - Can be used at the top level or nested within fields
50
+ * - Can take either a single condition or an array of conditions
51
+ *
52
+ */
53
+ export declare class PGFilterTranslator extends BaseFilterTranslator {
54
+ protected getSupportedOperators(): OperatorSupport;
55
+ translate(filter: Filter): Filter;
56
+ private translateNode;
57
+ private translateRegexPattern;
58
+ }
59
+
60
+ declare class PgVector extends MastraVector {
61
+ private pool;
62
+ constructor(connectionString: string);
63
+ transformFilter(filter?: Filter): Filter;
64
+ query(indexName: string, queryVector: number[], topK?: number, filter?: Filter, includeVector?: boolean, minScore?: number): Promise<QueryResult[]>;
65
+ upsert(indexName: string, vectors: number[][], metadata?: Record<string, any>[], ids?: string[]): Promise<string[]>;
66
+ createIndex(indexName: string, dimension: number, metric?: 'cosine' | 'euclidean' | 'dotproduct'): Promise<void>;
67
+ listIndexes(): Promise<string[]>;
68
+ describeIndex(indexName: string): Promise<IndexStats>;
69
+ deleteIndex(indexName: string): Promise<void>;
70
+ truncateIndex(indexName: string): Promise<void>;
71
+ disconnect(): Promise<void>;
72
+ }
73
+ export { PgVector }
74
+ export { PgVector as PgVector_alias_1 }
75
+
76
+ declare type PostgresConfig = {
77
+ host: string;
78
+ port: number;
79
+ database: string;
80
+ user: string;
81
+ password: string;
82
+ } | {
83
+ connectionString: string;
84
+ };
85
+ export { PostgresConfig }
86
+ export { PostgresConfig as PostgresConfig_alias_1 }
87
+
88
+ declare class PostgresStore extends MastraStorage {
89
+ private db;
90
+ private pgp;
91
+ constructor(config: PostgresConfig);
92
+ getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
93
+ batchInsert({ tableName, records }: {
94
+ tableName: TABLE_NAMES;
95
+ records: Record<string, any>[];
96
+ }): Promise<void>;
97
+ getTraces({ name, scope, page, perPage, attributes, }: {
98
+ name?: string;
99
+ scope?: string;
100
+ page: number;
101
+ perPage: number;
102
+ attributes?: Record<string, string>;
103
+ }): Promise<any[]>;
104
+ createTable({ tableName, schema, }: {
105
+ tableName: TABLE_NAMES;
106
+ schema: Record<string, StorageColumn>;
107
+ }): Promise<void>;
108
+ clearTable({ tableName }: {
109
+ tableName: TABLE_NAMES;
110
+ }): Promise<void>;
111
+ insert({ tableName, record }: {
112
+ tableName: TABLE_NAMES;
113
+ record: Record<string, any>;
114
+ }): Promise<void>;
115
+ load<R>({ tableName, keys }: {
116
+ tableName: TABLE_NAMES;
117
+ keys: Record<string, string>;
118
+ }): Promise<R | null>;
119
+ getThreadById({ threadId }: {
120
+ threadId: string;
121
+ }): Promise<StorageThreadType | null>;
122
+ getThreadsByResourceId({ resourceId }: {
123
+ resourceId: string;
124
+ }): Promise<StorageThreadType[]>;
125
+ saveThread({ thread }: {
126
+ thread: StorageThreadType;
127
+ }): Promise<StorageThreadType>;
128
+ updateThread({ id, title, metadata, }: {
129
+ id: string;
130
+ title: string;
131
+ metadata: Record<string, unknown>;
132
+ }): Promise<StorageThreadType>;
133
+ deleteThread({ threadId }: {
134
+ threadId: string;
135
+ }): Promise<void>;
136
+ getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
137
+ saveMessages({ messages }: {
138
+ messages: MessageType[];
139
+ }): Promise<MessageType[]>;
140
+ persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
141
+ workflowName: string;
142
+ runId: string;
143
+ snapshot: WorkflowRunState;
144
+ }): Promise<void>;
145
+ loadWorkflowSnapshot({ workflowName, runId, }: {
146
+ workflowName: string;
147
+ runId: string;
148
+ }): Promise<WorkflowRunState | null>;
149
+ close(): Promise<void>;
150
+ }
151
+ export { PostgresStore }
152
+ export { PostgresStore as PostgresStore_alias_1 }
153
+
154
+ export { }
package/dist/index.d.ts CHANGED
@@ -1,82 +1,3 @@
1
- import { Filter } from '@mastra/core/filter';
2
- import { MastraVector, QueryResult, IndexStats } from '@mastra/core/vector';
3
- import { StorageThreadType, MessageType } from '@mastra/core/memory';
4
- import { MastraStorage, TABLE_NAMES, StorageColumn, StorageGetMessagesArg } from '@mastra/core/storage';
5
- import { WorkflowRunState } from '@mastra/core/workflows';
6
-
7
- declare class PgVector extends MastraVector {
8
- private pool;
9
- constructor(connectionString: string);
10
- transformFilter(filter?: Filter): Filter;
11
- query(indexName: string, queryVector: number[], topK?: number, filter?: Filter, includeVector?: boolean, minScore?: number): Promise<QueryResult[]>;
12
- upsert(indexName: string, vectors: number[][], metadata?: Record<string, any>[], ids?: string[]): Promise<string[]>;
13
- createIndex(indexName: string, dimension: number, metric?: 'cosine' | 'euclidean' | 'dotproduct'): Promise<void>;
14
- listIndexes(): Promise<string[]>;
15
- describeIndex(indexName: string): Promise<IndexStats>;
16
- deleteIndex(indexName: string): Promise<void>;
17
- truncateIndex(indexName: string): Promise<void>;
18
- disconnect(): Promise<void>;
19
- }
20
-
21
- type PostgresConfig = {
22
- host: string;
23
- port: number;
24
- database: string;
25
- user: string;
26
- password: string;
27
- } | {
28
- connectionString: string;
29
- };
30
- declare class PostgresStore extends MastraStorage {
31
- private db;
32
- private pgp;
33
- constructor(config: PostgresConfig);
34
- createTable({ tableName, schema, }: {
35
- tableName: TABLE_NAMES;
36
- schema: Record<string, StorageColumn>;
37
- }): Promise<void>;
38
- clearTable({ tableName }: {
39
- tableName: TABLE_NAMES;
40
- }): Promise<void>;
41
- insert({ tableName, record }: {
42
- tableName: TABLE_NAMES;
43
- record: Record<string, any>;
44
- }): Promise<void>;
45
- load<R>({ tableName, keys }: {
46
- tableName: TABLE_NAMES;
47
- keys: Record<string, string>;
48
- }): Promise<R | null>;
49
- getThreadById({ threadId }: {
50
- threadId: string;
51
- }): Promise<StorageThreadType | null>;
52
- getThreadsByResourceId({ resourceId }: {
53
- resourceId: string;
54
- }): Promise<StorageThreadType[]>;
55
- saveThread({ thread }: {
56
- thread: StorageThreadType;
57
- }): Promise<StorageThreadType>;
58
- updateThread({ id, title, metadata, }: {
59
- id: string;
60
- title: string;
61
- metadata: Record<string, unknown>;
62
- }): Promise<StorageThreadType>;
63
- deleteThread({ threadId }: {
64
- threadId: string;
65
- }): Promise<void>;
66
- getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
67
- saveMessages({ messages }: {
68
- messages: MessageType[];
69
- }): Promise<MessageType[]>;
70
- persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
71
- workflowName: string;
72
- runId: string;
73
- snapshot: WorkflowRunState;
74
- }): Promise<void>;
75
- loadWorkflowSnapshot({ workflowName, runId, }: {
76
- workflowName: string;
77
- runId: string;
78
- }): Promise<WorkflowRunState | null>;
79
- close(): Promise<void>;
80
- }
81
-
82
- export { PgVector, type PostgresConfig, PostgresStore };
1
+ export { PgVector } from './_tsup-dts-rollup.js';
2
+ export { PostgresConfig } from './_tsup-dts-rollup.js';
3
+ export { PostgresStore } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -285,6 +285,7 @@ function buildFilterQuery(filter, minScore) {
285
285
 
286
286
  // src/vector/index.ts
287
287
  var PgVector = class extends MastraVector {
288
+ pool;
288
289
  constructor(connectionString) {
289
290
  super();
290
291
  const basePool = new pg.Pool({
@@ -500,6 +501,8 @@ var PgVector = class extends MastraVector {
500
501
  }
501
502
  };
502
503
  var PostgresStore = class extends MastraStorage {
504
+ db;
505
+ pgp;
503
506
  constructor(config) {
504
507
  super({ name: "PostgresStore" });
505
508
  this.pgp = pgPromise();
@@ -513,6 +516,86 @@ var PostgresStore = class extends MastraStorage {
513
516
  }
514
517
  );
515
518
  }
519
+ getEvalsByAgentName(agentName, type) {
520
+ throw new Error("Method not implemented.");
521
+ }
522
+ async batchInsert({ tableName, records }) {
523
+ try {
524
+ await this.db.query("BEGIN");
525
+ for (const record of records) {
526
+ await this.insert({ tableName, record });
527
+ }
528
+ await this.db.query("COMMIT");
529
+ } catch (error) {
530
+ console.error(`Error inserting into ${tableName}:`, error);
531
+ await this.db.query("ROLLBACK");
532
+ throw error;
533
+ }
534
+ }
535
+ async getTraces({
536
+ name,
537
+ scope,
538
+ page,
539
+ perPage,
540
+ attributes
541
+ }) {
542
+ let idx = 1;
543
+ const limit = perPage;
544
+ const offset = page * perPage;
545
+ const args = [];
546
+ const conditions = [];
547
+ if (name) {
548
+ conditions.push(`name LIKE CONCAT($${idx++}, '%')`);
549
+ }
550
+ if (scope) {
551
+ conditions.push(`scope = $${idx++}`);
552
+ }
553
+ if (attributes) {
554
+ Object.keys(attributes).forEach((key) => {
555
+ conditions.push(`attributes->>'${key}' = $${idx++}`);
556
+ });
557
+ }
558
+ const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
559
+ if (name) {
560
+ args.push(name);
561
+ }
562
+ if (scope) {
563
+ args.push(scope);
564
+ }
565
+ if (attributes) {
566
+ for (const [_key, value] of Object.entries(attributes)) {
567
+ args.push(value);
568
+ }
569
+ }
570
+ console.log(
571
+ "QUERY",
572
+ `SELECT * FROM ${MastraStorage.TABLE_TRACES} ${whereClause} ORDER BY "createdAt" DESC LIMIT ${limit} OFFSET ${offset}`,
573
+ args
574
+ );
575
+ const result = await this.db.manyOrNone(
576
+ `SELECT * FROM ${MastraStorage.TABLE_TRACES} ${whereClause} ORDER BY "createdAt" DESC LIMIT ${limit} OFFSET ${offset}`,
577
+ args
578
+ );
579
+ if (!result) {
580
+ return [];
581
+ }
582
+ return result.map((row) => ({
583
+ id: row.id,
584
+ parentSpanId: row.parentSpanId,
585
+ traceId: row.traceId,
586
+ name: row.name,
587
+ scope: row.scope,
588
+ kind: row.kind,
589
+ status: row.status,
590
+ events: row.events,
591
+ links: row.links,
592
+ attributes: row.attributes,
593
+ startTime: row.startTime,
594
+ endTime: row.endTime,
595
+ other: row.other,
596
+ createdAt: row.createdAt
597
+ }));
598
+ }
516
599
  async createTable({
517
600
  tableName,
518
601
  schema
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/pg",
3
- "version": "0.1.0-alpha.9",
3
+ "version": "0.1.1-alpha.0",
4
4
  "description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -17,17 +17,18 @@
17
17
  "dependencies": {
18
18
  "pg": "^8.13.1",
19
19
  "pg-promise": "^11.5.4",
20
- "@mastra/core": "^0.2.0-alpha.99"
20
+ "@mastra/core": "^0.2.1-alpha.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@tsconfig/recommended": "^1.0.7",
24
- "@types/node": "^22.9.0",
23
+ "@microsoft/api-extractor": "^7.49.2",
24
+ "@types/node": "^22.13.1",
25
25
  "@types/pg": "^8.11.10",
26
26
  "tsup": "^8.0.1",
27
+ "typescript": "^5.7.3",
27
28
  "vitest": "^3.0.4"
28
29
  },
29
30
  "scripts": {
30
- "build": "tsup src/index.ts --format esm --dts --clean --treeshake",
31
+ "build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
31
32
  "build:watch": "pnpm build --watch",
32
33
  "pretest": "docker compose up -d && (for i in $(seq 1 30); do docker compose exec -T db pg_isready -U postgres && break || (sleep 1; [ $i -eq 30 ] && exit 1); done)",
33
34
  "test": "vitest run",
@@ -1,8 +1,22 @@
1
1
  import { type MessageType, type StorageThreadType } from '@mastra/core/memory';
2
- import { MastraStorage, type StorageColumn, type StorageGetMessagesArg, type TABLE_NAMES } from '@mastra/core/storage';
2
+ import {
3
+ MastraStorage,
4
+ type EvalRow,
5
+ type StorageColumn,
6
+ type StorageGetMessagesArg,
7
+ type TABLE_NAMES,
8
+ } from '@mastra/core/storage';
3
9
  import { type WorkflowRunState } from '@mastra/core/workflows';
4
10
  import pgPromise from 'pg-promise';
5
11
 
12
+ function safelyParseJSON(json: string): any {
13
+ try {
14
+ return JSON.parse(json);
15
+ } catch (e) {
16
+ return {};
17
+ }
18
+ }
19
+
6
20
  export type PostgresConfig =
7
21
  | {
8
22
  host: string;
@@ -35,6 +49,120 @@ export class PostgresStore extends MastraStorage {
35
49
  );
36
50
  }
37
51
 
52
+ getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]> {
53
+ throw new Error('Method not implemented.');
54
+ }
55
+
56
+ async batchInsert({ tableName, records }: { tableName: TABLE_NAMES; records: Record<string, any>[] }): Promise<void> {
57
+ try {
58
+ await this.db.query('BEGIN');
59
+ for (const record of records) {
60
+ await this.insert({ tableName, record });
61
+ }
62
+ await this.db.query('COMMIT');
63
+ } catch (error) {
64
+ console.error(`Error inserting into ${tableName}:`, error);
65
+ await this.db.query('ROLLBACK');
66
+ throw error;
67
+ }
68
+ }
69
+
70
+ async getTraces({
71
+ name,
72
+ scope,
73
+ page,
74
+ perPage,
75
+ attributes,
76
+ }: {
77
+ name?: string;
78
+ scope?: string;
79
+ page: number;
80
+ perPage: number;
81
+ attributes?: Record<string, string>;
82
+ }): Promise<any[]> {
83
+ let idx = 1;
84
+ const limit = perPage;
85
+ const offset = page * perPage;
86
+
87
+ const args: (string | number)[] = [];
88
+
89
+ const conditions: string[] = [];
90
+ if (name) {
91
+ conditions.push(`name LIKE CONCAT(\$${idx++}, '%')`);
92
+ }
93
+ if (scope) {
94
+ conditions.push(`scope = \$${idx++}`);
95
+ }
96
+ if (attributes) {
97
+ Object.keys(attributes).forEach(key => {
98
+ conditions.push(`attributes->>'${key}' = \$${idx++}`);
99
+ });
100
+ }
101
+
102
+ const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
103
+
104
+ if (name) {
105
+ args.push(name);
106
+ }
107
+
108
+ if (scope) {
109
+ args.push(scope);
110
+ }
111
+
112
+ if (attributes) {
113
+ for (const [_key, value] of Object.entries(attributes)) {
114
+ args.push(value);
115
+ }
116
+ }
117
+
118
+ console.log(
119
+ 'QUERY',
120
+ `SELECT * FROM ${MastraStorage.TABLE_TRACES} ${whereClause} ORDER BY "createdAt" DESC LIMIT ${limit} OFFSET ${offset}`,
121
+ args,
122
+ );
123
+
124
+ const result = await this.db.manyOrNone<{
125
+ id: string;
126
+ parentSpanId: string;
127
+ traceId: string;
128
+ name: string;
129
+ scope: string;
130
+ kind: string;
131
+ events: any[];
132
+ links: any[];
133
+ status: any;
134
+ attributes: Record<string, any>;
135
+ startTime: string;
136
+ endTime: string;
137
+ other: any;
138
+ createdAt: string;
139
+ }>(
140
+ `SELECT * FROM ${MastraStorage.TABLE_TRACES} ${whereClause} ORDER BY "createdAt" DESC LIMIT ${limit} OFFSET ${offset}`,
141
+ args,
142
+ );
143
+
144
+ if (!result) {
145
+ return [];
146
+ }
147
+
148
+ return result.map(row => ({
149
+ id: row.id,
150
+ parentSpanId: row.parentSpanId,
151
+ traceId: row.traceId,
152
+ name: row.name,
153
+ scope: row.scope,
154
+ kind: row.kind,
155
+ status: row.status,
156
+ events: row.events,
157
+ links: row.links,
158
+ attributes: row.attributes,
159
+ startTime: row.startTime,
160
+ endTime: row.endTime,
161
+ other: row.other,
162
+ createdAt: row.createdAt,
163
+ })) as any;
164
+ }
165
+
38
166
  async createTable({
39
167
  tableName,
40
168
  schema,
@@ -1,4 +1,4 @@
1
- import { BaseFilterTranslator, FieldCondition, Filter, OperatorSupport } from '@mastra/core/filter';
1
+ import { BaseFilterTranslator, type FieldCondition, type Filter, type OperatorSupport } from '@mastra/core/filter';
2
2
 
3
3
  /**
4
4
  * Translates MongoDB-style filters to PG compatible filters.
@@ -1,11 +1,11 @@
1
1
  import {
2
- BasicOperator,
3
- NumericOperator,
4
- ArrayOperator,
5
- ElementOperator,
6
- LogicalOperator,
7
- RegexOperator,
8
- Filter,
2
+ type BasicOperator,
3
+ type NumericOperator,
4
+ type ArrayOperator,
5
+ type ElementOperator,
6
+ type LogicalOperator,
7
+ type RegexOperator,
8
+ type Filter,
9
9
  } from '@mastra/core/filter';
10
10
 
11
11
  export type OperatorType =
package/tsconfig.json CHANGED
@@ -1,15 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.node.json",
3
- "compilerOptions": {
4
- "moduleResolution": "bundler",
5
- "outDir": "./dist",
6
- "rootDir": "./src",
7
- "module": "ES2022",
8
- "target": "ES2020",
9
- "declaration": true,
10
- "declarationMap": true,
11
- "noEmit": false
12
- },
13
3
  "include": ["src/**/*"],
14
4
  "exclude": ["node_modules", "**/*.test.ts"]
15
5
  }