@mastra/pg 0.1.0-alpha.9 → 0.1.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,276 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c87eb4e: Combine PostgreSQL packages into `@mastra/pg`.
8
+
9
+ - Move and combine packages to `stores/pg`
10
+ - Reorganize source files into `src/vector` and `src/store`
11
+ - Add deprecation notices to old packages
12
+ - Update documentation and examples
13
+ - No breaking changes in functionality
14
+
15
+ - 8b416d9: Breaking changes
16
+
17
+ ### Patch Changes
18
+
19
+ - b97ca96: Tracing into default storage
20
+ - 07c069d: Update build script
21
+ - 9c10484: update all packages
22
+ - 70dabd9: Fix broken publish
23
+ - 4f1d1a1: Enforce types ann cleanup package.json
24
+ - Updated dependencies [f537e33]
25
+ - Updated dependencies [6f2c0f5]
26
+ - Updated dependencies [e4d4ede]
27
+ - Updated dependencies [0be7181]
28
+ - Updated dependencies [dd6d87f]
29
+ - Updated dependencies [9029796]
30
+ - Updated dependencies [6fa4bd2]
31
+ - Updated dependencies [f031a1f]
32
+ - Updated dependencies [8151f44]
33
+ - Updated dependencies [d7d465a]
34
+ - Updated dependencies [4d4f6b6]
35
+ - Updated dependencies [73d112c]
36
+ - Updated dependencies [592e3cf]
37
+ - Updated dependencies [9d1796d]
38
+ - Updated dependencies [e897f1c]
39
+ - Updated dependencies [4a54c82]
40
+ - Updated dependencies [3967e69]
41
+ - Updated dependencies [8ae2bbc]
42
+ - Updated dependencies [e9d1b47]
43
+ - Updated dependencies [016493a]
44
+ - Updated dependencies [bc40916]
45
+ - Updated dependencies [93a3719]
46
+ - Updated dependencies [7d83b92]
47
+ - Updated dependencies [9fb3039]
48
+ - Updated dependencies [d5e12de]
49
+ - Updated dependencies [e1dd94a]
50
+ - Updated dependencies [07c069d]
51
+ - Updated dependencies [5cdfb88]
52
+ - Updated dependencies [837a288]
53
+ - Updated dependencies [685108a]
54
+ - Updated dependencies [c8ff2f5]
55
+ - Updated dependencies [5fdc87c]
56
+ - Updated dependencies [ae7bf94]
57
+ - Updated dependencies [8e7814f]
58
+ - Updated dependencies [66a03ec]
59
+ - Updated dependencies [7d87a15]
60
+ - Updated dependencies [b97ca96]
61
+ - Updated dependencies [23dcb23]
62
+ - Updated dependencies [033eda6]
63
+ - Updated dependencies [8105fae]
64
+ - Updated dependencies [e097800]
65
+ - Updated dependencies [1944807]
66
+ - Updated dependencies [30322ce]
67
+ - Updated dependencies [1874f40]
68
+ - Updated dependencies [685108a]
69
+ - Updated dependencies [f7d1131]
70
+ - Updated dependencies [79acad0]
71
+ - Updated dependencies [7a19083]
72
+ - Updated dependencies [382f4dc]
73
+ - Updated dependencies [1ebd071]
74
+ - Updated dependencies [0b74006]
75
+ - Updated dependencies [2f17a5f]
76
+ - Updated dependencies [f368477]
77
+ - Updated dependencies [7892533]
78
+ - Updated dependencies [9c10484]
79
+ - Updated dependencies [b726bf5]
80
+ - Updated dependencies [70dabd9]
81
+ - Updated dependencies [21fe536]
82
+ - Updated dependencies [176bc42]
83
+ - Updated dependencies [401a4d9]
84
+ - Updated dependencies [2e099d2]
85
+ - Updated dependencies [0b826f6]
86
+ - Updated dependencies [d68b532]
87
+ - Updated dependencies [75bf3f0]
88
+ - Updated dependencies [e6d8055]
89
+ - Updated dependencies [e2e76de]
90
+ - Updated dependencies [ccbc581]
91
+ - Updated dependencies [5950de5]
92
+ - Updated dependencies [fe3dcb0]
93
+ - Updated dependencies [78eec7c]
94
+ - Updated dependencies [a8a459a]
95
+ - Updated dependencies [0be7181]
96
+ - Updated dependencies [7b87567]
97
+ - Updated dependencies [b524c22]
98
+ - Updated dependencies [d7d465a]
99
+ - Updated dependencies [df843d3]
100
+ - Updated dependencies [4534e77]
101
+ - Updated dependencies [d6d8159]
102
+ - Updated dependencies [0bd142c]
103
+ - Updated dependencies [9625602]
104
+ - Updated dependencies [72d1990]
105
+ - Updated dependencies [f6ba259]
106
+ - Updated dependencies [2712098]
107
+ - Updated dependencies [eedb829]
108
+ - Updated dependencies [5285356]
109
+ - Updated dependencies [74b3078]
110
+ - Updated dependencies [cb290ee]
111
+ - Updated dependencies [b4d7416]
112
+ - Updated dependencies [e608d8c]
113
+ - Updated dependencies [06b2c0a]
114
+ - Updated dependencies [002d6d8]
115
+ - Updated dependencies [e448a26]
116
+ - Updated dependencies [8b416d9]
117
+ - Updated dependencies [fd494a3]
118
+ - Updated dependencies [dc90663]
119
+ - Updated dependencies [c872875]
120
+ - Updated dependencies [3c4488b]
121
+ - Updated dependencies [a7b016d]
122
+ - Updated dependencies [fd75f3c]
123
+ - Updated dependencies [7f24c29]
124
+ - Updated dependencies [2017553]
125
+ - Updated dependencies [a10b7a3]
126
+ - Updated dependencies [cf6d825]
127
+ - Updated dependencies [963c15a]
128
+ - Updated dependencies [7365b6c]
129
+ - Updated dependencies [5ee67d3]
130
+ - Updated dependencies [d38f7a6]
131
+ - Updated dependencies [38b7f66]
132
+ - Updated dependencies [2fa7f53]
133
+ - Updated dependencies [1420ae2]
134
+ - Updated dependencies [f6da688]
135
+ - Updated dependencies [3700be1]
136
+ - Updated dependencies [9ade36e]
137
+ - Updated dependencies [10870bc]
138
+ - Updated dependencies [2b01511]
139
+ - Updated dependencies [a870123]
140
+ - Updated dependencies [ccf115c]
141
+ - Updated dependencies [04434b6]
142
+ - Updated dependencies [5811de6]
143
+ - Updated dependencies [9f3ab05]
144
+ - Updated dependencies [66a5392]
145
+ - Updated dependencies [4b1ce2c]
146
+ - Updated dependencies [14064f2]
147
+ - Updated dependencies [f5dfa20]
148
+ - Updated dependencies [327ece7]
149
+ - Updated dependencies [da2e8d3]
150
+ - Updated dependencies [95a4697]
151
+ - Updated dependencies [d5fccfb]
152
+ - Updated dependencies [3427b95]
153
+ - Updated dependencies [538a136]
154
+ - Updated dependencies [e66643a]
155
+ - Updated dependencies [b5393f1]
156
+ - Updated dependencies [d2cd535]
157
+ - Updated dependencies [c2dd6b5]
158
+ - Updated dependencies [67637ba]
159
+ - Updated dependencies [836f4e3]
160
+ - Updated dependencies [5ee2e78]
161
+ - Updated dependencies [cd02c56]
162
+ - Updated dependencies [01502b0]
163
+ - Updated dependencies [16e5b04]
164
+ - Updated dependencies [d9c8dd0]
165
+ - Updated dependencies [9fb59d6]
166
+ - Updated dependencies [a9345f9]
167
+ - Updated dependencies [99f1847]
168
+ - Updated dependencies [04f3171]
169
+ - Updated dependencies [8769a62]
170
+ - Updated dependencies [d5ec619]
171
+ - Updated dependencies [27275c9]
172
+ - Updated dependencies [ae7bf94]
173
+ - Updated dependencies [4f1d1a1]
174
+ - Updated dependencies [ee4de15]
175
+ - Updated dependencies [202d404]
176
+ - Updated dependencies [a221426]
177
+ - @mastra/core@0.2.0
178
+
179
+ ## 0.1.0-alpha.20
180
+
181
+ ### Patch Changes
182
+
183
+ - Updated dependencies [016493a]
184
+ - Updated dependencies [382f4dc]
185
+ - Updated dependencies [176bc42]
186
+ - Updated dependencies [d68b532]
187
+ - Updated dependencies [fe3dcb0]
188
+ - Updated dependencies [e448a26]
189
+ - Updated dependencies [fd75f3c]
190
+ - Updated dependencies [ccf115c]
191
+ - Updated dependencies [a221426]
192
+ - @mastra/core@0.2.0-alpha.110
193
+
194
+ ## 0.1.0-alpha.19
195
+
196
+ ### Patch Changes
197
+
198
+ - Updated dependencies [d5fccfb]
199
+ - @mastra/core@0.2.0-alpha.109
200
+
201
+ ## 0.1.0-alpha.18
202
+
203
+ ### Patch Changes
204
+
205
+ - Updated dependencies [5ee67d3]
206
+ - Updated dependencies [95a4697]
207
+ - @mastra/core@0.2.0-alpha.108
208
+
209
+ ## 0.1.0-alpha.17
210
+
211
+ ### Patch Changes
212
+
213
+ - Updated dependencies [66a5392]
214
+ - @mastra/core@0.2.0-alpha.107
215
+
216
+ ## 0.1.0-alpha.16
217
+
218
+ ### Patch Changes
219
+
220
+ - Updated dependencies [6f2c0f5]
221
+ - Updated dependencies [a8a459a]
222
+ - @mastra/core@0.2.0-alpha.106
223
+
224
+ ## 0.1.0-alpha.15
225
+
226
+ ### Patch Changes
227
+
228
+ - Updated dependencies [1420ae2]
229
+ - Updated dependencies [99f1847]
230
+ - @mastra/core@0.2.0-alpha.105
231
+
232
+ ## 0.1.0-alpha.14
233
+
234
+ ### Patch Changes
235
+
236
+ - b97ca96: Tracing into default storage
237
+ - Updated dependencies [5fdc87c]
238
+ - Updated dependencies [b97ca96]
239
+ - Updated dependencies [72d1990]
240
+ - Updated dependencies [cf6d825]
241
+ - Updated dependencies [10870bc]
242
+ - @mastra/core@0.2.0-alpha.104
243
+
244
+ ## 0.1.0-alpha.13
245
+
246
+ ### Patch Changes
247
+
248
+ - Updated dependencies [4534e77]
249
+ - @mastra/core@0.2.0-alpha.103
250
+
251
+ ## 0.1.0-alpha.12
252
+
253
+ ### Patch Changes
254
+
255
+ - Updated dependencies [a9345f9]
256
+ - @mastra/core@0.2.0-alpha.102
257
+
258
+ ## 0.1.0-alpha.11
259
+
260
+ ### Patch Changes
261
+
262
+ - 4f1d1a1: Enforce types ann cleanup package.json
263
+ - Updated dependencies [66a03ec]
264
+ - Updated dependencies [4f1d1a1]
265
+ - @mastra/core@0.2.0-alpha.101
266
+
267
+ ## 0.1.0-alpha.10
268
+
269
+ ### Patch Changes
270
+
271
+ - Updated dependencies [9d1796d]
272
+ - @mastra/core@0.2.0-alpha.100
273
+
3
274
  ## 0.1.0-alpha.9
4
275
 
5
276
  ### 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.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.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
  }