@mastra/pg 0.2.11-alpha.1 → 0.3.0-alpha.3
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/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +18 -0
- package/package.json +2 -2
- package/src/storage/index.test.ts +46 -46
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pg@0.
|
|
2
|
+
> @mastra/pg@0.3.0-alpha.3 build /home/runner/work/mastra/mastra/stores/pg
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 10982ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.2
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.2
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 12779ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
20
|
[32mESM[39m [1mdist/index.js [22m[32m45.68 KB[39m
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 1276ms
|
|
22
22
|
[32mCJS[39m [1mdist/index.cjs [22m[32m46.10 KB[39m
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 1276ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.3.0-alpha.3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- fe3ae4d: Remove \_\_ functions in storage and move to storage proxy to make sure init is called
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [fe3ae4d]
|
|
12
|
+
- @mastra/core@0.9.0-alpha.3
|
|
13
|
+
|
|
14
|
+
## 0.2.11-alpha.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [9ee4293]
|
|
19
|
+
- @mastra/core@0.8.4-alpha.2
|
|
20
|
+
|
|
3
21
|
## 0.2.11-alpha.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pg",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha.3",
|
|
4
4
|
"description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"pg": "^8.13.3",
|
|
25
25
|
"pg-promise": "^11.11.0",
|
|
26
26
|
"xxhash-wasm": "^1.1.0",
|
|
27
|
-
"@mastra/core": "^0.
|
|
27
|
+
"@mastra/core": "^0.9.0-alpha.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@microsoft/api-extractor": "^7.52.1",
|
|
@@ -109,16 +109,16 @@ describe('PostgresStore', () => {
|
|
|
109
109
|
const thread = createSampleThread();
|
|
110
110
|
|
|
111
111
|
// Save thread
|
|
112
|
-
const savedThread = await store.
|
|
112
|
+
const savedThread = await store.saveThread({ thread });
|
|
113
113
|
expect(savedThread).toEqual(thread);
|
|
114
114
|
|
|
115
115
|
// Retrieve thread
|
|
116
|
-
const retrievedThread = await store.
|
|
116
|
+
const retrievedThread = await store.getThreadById({ threadId: thread.id });
|
|
117
117
|
expect(retrievedThread?.title).toEqual(thread.title);
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
it('should return null for non-existent thread', async () => {
|
|
121
|
-
const result = await store.
|
|
121
|
+
const result = await store.getThreadById({ threadId: 'non-existent' });
|
|
122
122
|
expect(result).toBeNull();
|
|
123
123
|
});
|
|
124
124
|
|
|
@@ -126,20 +126,20 @@ describe('PostgresStore', () => {
|
|
|
126
126
|
const thread1 = createSampleThread();
|
|
127
127
|
const thread2 = { ...createSampleThread(), resourceId: thread1.resourceId };
|
|
128
128
|
|
|
129
|
-
await store.
|
|
130
|
-
await store.
|
|
129
|
+
await store.saveThread({ thread: thread1 });
|
|
130
|
+
await store.saveThread({ thread: thread2 });
|
|
131
131
|
|
|
132
|
-
const threads = await store.
|
|
132
|
+
const threads = await store.getThreadsByResourceId({ resourceId: thread1.resourceId });
|
|
133
133
|
expect(threads).toHaveLength(2);
|
|
134
134
|
expect(threads.map(t => t.id)).toEqual(expect.arrayContaining([thread1.id, thread2.id]));
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
it('should update thread title and metadata', async () => {
|
|
138
138
|
const thread = createSampleThread();
|
|
139
|
-
await store.
|
|
139
|
+
await store.saveThread({ thread });
|
|
140
140
|
|
|
141
141
|
const newMetadata = { newKey: 'newValue' };
|
|
142
|
-
const updatedThread = await store.
|
|
142
|
+
const updatedThread = await store.updateThread({
|
|
143
143
|
id: thread.id,
|
|
144
144
|
title: 'Updated Title',
|
|
145
145
|
metadata: newMetadata,
|
|
@@ -152,25 +152,25 @@ describe('PostgresStore', () => {
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
// Verify persistence
|
|
155
|
-
const retrievedThread = await store.
|
|
155
|
+
const retrievedThread = await store.getThreadById({ threadId: thread.id });
|
|
156
156
|
expect(retrievedThread).toEqual(updatedThread);
|
|
157
157
|
});
|
|
158
158
|
|
|
159
159
|
it('should delete thread and its messages', async () => {
|
|
160
160
|
const thread = createSampleThread();
|
|
161
|
-
await store.
|
|
161
|
+
await store.saveThread({ thread });
|
|
162
162
|
|
|
163
163
|
// Add some messages
|
|
164
164
|
const messages = [createSampleMessage(thread.id), createSampleMessage(thread.id)];
|
|
165
|
-
await store.
|
|
165
|
+
await store.saveMessages({ messages });
|
|
166
166
|
|
|
167
|
-
await store.
|
|
167
|
+
await store.deleteThread({ threadId: thread.id });
|
|
168
168
|
|
|
169
|
-
const retrievedThread = await store.
|
|
169
|
+
const retrievedThread = await store.getThreadById({ threadId: thread.id });
|
|
170
170
|
expect(retrievedThread).toBeNull();
|
|
171
171
|
|
|
172
172
|
// Verify messages were also deleted
|
|
173
|
-
const retrievedMessages = await store.
|
|
173
|
+
const retrievedMessages = await store.getMessages({ threadId: thread.id });
|
|
174
174
|
expect(retrievedMessages).toHaveLength(0);
|
|
175
175
|
});
|
|
176
176
|
});
|
|
@@ -178,28 +178,28 @@ describe('PostgresStore', () => {
|
|
|
178
178
|
describe('Message Operations', () => {
|
|
179
179
|
it('should save and retrieve messages', async () => {
|
|
180
180
|
const thread = createSampleThread();
|
|
181
|
-
await store.
|
|
181
|
+
await store.saveThread({ thread });
|
|
182
182
|
|
|
183
183
|
const messages = [createSampleMessage(thread.id), createSampleMessage(thread.id)];
|
|
184
184
|
|
|
185
185
|
// Save messages
|
|
186
|
-
const savedMessages = await store.
|
|
186
|
+
const savedMessages = await store.saveMessages({ messages });
|
|
187
187
|
expect(savedMessages).toEqual(messages);
|
|
188
188
|
|
|
189
189
|
// Retrieve messages
|
|
190
|
-
const retrievedMessages = await store.
|
|
190
|
+
const retrievedMessages = await store.getMessages({ threadId: thread.id });
|
|
191
191
|
expect(retrievedMessages).toHaveLength(2);
|
|
192
192
|
expect(retrievedMessages).toEqual(expect.arrayContaining(messages));
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
it('should handle empty message array', async () => {
|
|
196
|
-
const result = await store.
|
|
196
|
+
const result = await store.saveMessages({ messages: [] });
|
|
197
197
|
expect(result).toEqual([]);
|
|
198
198
|
});
|
|
199
199
|
|
|
200
200
|
it('should maintain message order', async () => {
|
|
201
201
|
const thread = createSampleThread();
|
|
202
|
-
await store.
|
|
202
|
+
await store.saveThread({ thread });
|
|
203
203
|
|
|
204
204
|
const messages = [
|
|
205
205
|
{ ...createSampleMessage(thread.id), content: [{ type: 'text', text: 'First' }] as MessageType['content'] },
|
|
@@ -207,9 +207,9 @@ describe('PostgresStore', () => {
|
|
|
207
207
|
{ ...createSampleMessage(thread.id), content: [{ type: 'text', text: 'Third' }] as MessageType['content'] },
|
|
208
208
|
];
|
|
209
209
|
|
|
210
|
-
await store.
|
|
210
|
+
await store.saveMessages({ messages });
|
|
211
211
|
|
|
212
|
-
const retrievedMessages = await store.
|
|
212
|
+
const retrievedMessages = await store.getMessages({ threadId: thread.id });
|
|
213
213
|
expect(retrievedMessages).toHaveLength(3);
|
|
214
214
|
|
|
215
215
|
// Verify order is maintained
|
|
@@ -220,17 +220,17 @@ describe('PostgresStore', () => {
|
|
|
220
220
|
|
|
221
221
|
it('should rollback on error during message save', async () => {
|
|
222
222
|
const thread = createSampleThread();
|
|
223
|
-
await store.
|
|
223
|
+
await store.saveThread({ thread });
|
|
224
224
|
|
|
225
225
|
const messages = [
|
|
226
226
|
createSampleMessage(thread.id),
|
|
227
227
|
{ ...createSampleMessage(thread.id), id: null } as any, // This will cause an error
|
|
228
228
|
];
|
|
229
229
|
|
|
230
|
-
await expect(store.
|
|
230
|
+
await expect(store.saveMessages({ messages })).rejects.toThrow();
|
|
231
231
|
|
|
232
232
|
// Verify no messages were saved
|
|
233
|
-
const savedMessages = await store.
|
|
233
|
+
const savedMessages = await store.getMessages({ threadId: thread.id });
|
|
234
234
|
expect(savedMessages).toHaveLength(0);
|
|
235
235
|
});
|
|
236
236
|
});
|
|
@@ -248,8 +248,8 @@ describe('PostgresStore', () => {
|
|
|
248
248
|
metadata: largeMetadata,
|
|
249
249
|
};
|
|
250
250
|
|
|
251
|
-
await store.
|
|
252
|
-
const retrieved = await store.
|
|
251
|
+
await store.saveThread({ thread: threadWithLargeMetadata });
|
|
252
|
+
const retrieved = await store.getThreadById({ threadId: thread.id });
|
|
253
253
|
|
|
254
254
|
expect(retrieved?.metadata).toEqual(largeMetadata);
|
|
255
255
|
});
|
|
@@ -260,19 +260,19 @@ describe('PostgresStore', () => {
|
|
|
260
260
|
title: 'Special \'quotes\' and "double quotes" and emoji 🎉',
|
|
261
261
|
};
|
|
262
262
|
|
|
263
|
-
await store.
|
|
264
|
-
const retrieved = await store.
|
|
263
|
+
await store.saveThread({ thread });
|
|
264
|
+
const retrieved = await store.getThreadById({ threadId: thread.id });
|
|
265
265
|
|
|
266
266
|
expect(retrieved?.title).toBe(thread.title);
|
|
267
267
|
});
|
|
268
268
|
|
|
269
269
|
it('should handle concurrent thread updates', async () => {
|
|
270
270
|
const thread = createSampleThread();
|
|
271
|
-
await store.
|
|
271
|
+
await store.saveThread({ thread });
|
|
272
272
|
|
|
273
273
|
// Perform multiple updates concurrently
|
|
274
274
|
const updates = Array.from({ length: 5 }, (_, i) =>
|
|
275
|
-
store.
|
|
275
|
+
store.updateThread({
|
|
276
276
|
id: thread.id,
|
|
277
277
|
title: `Update ${i}`,
|
|
278
278
|
metadata: { update: i },
|
|
@@ -282,7 +282,7 @@ describe('PostgresStore', () => {
|
|
|
282
282
|
await expect(Promise.all(updates)).resolves.toBeDefined();
|
|
283
283
|
|
|
284
284
|
// Verify final state
|
|
285
|
-
const finalThread = await store.
|
|
285
|
+
const finalThread = await store.getThreadById({ threadId: thread.id });
|
|
286
286
|
expect(finalThread).toBeDefined();
|
|
287
287
|
});
|
|
288
288
|
});
|
|
@@ -433,7 +433,7 @@ describe('PostgresStore', () => {
|
|
|
433
433
|
await store.clearTable({ tableName: TABLE_WORKFLOW_SNAPSHOT });
|
|
434
434
|
});
|
|
435
435
|
it('returns empty array when no workflows exist', async () => {
|
|
436
|
-
const { runs, total } = await store.
|
|
436
|
+
const { runs, total } = await store.getWorkflowRuns();
|
|
437
437
|
expect(runs).toEqual([]);
|
|
438
438
|
expect(total).toBe(0);
|
|
439
439
|
});
|
|
@@ -449,7 +449,7 @@ describe('PostgresStore', () => {
|
|
|
449
449
|
await new Promise(resolve => setTimeout(resolve, 10)); // Small delay to ensure different timestamps
|
|
450
450
|
await store.persistWorkflowSnapshot({ workflowName: workflowName2, runId: runId2, snapshot: workflow2 });
|
|
451
451
|
|
|
452
|
-
const { runs, total } = await store.
|
|
452
|
+
const { runs, total } = await store.getWorkflowRuns();
|
|
453
453
|
expect(runs).toHaveLength(2);
|
|
454
454
|
expect(total).toBe(2);
|
|
455
455
|
expect(runs[0]!.workflowName).toBe(workflowName2); // Most recent first
|
|
@@ -471,7 +471,7 @@ describe('PostgresStore', () => {
|
|
|
471
471
|
await new Promise(resolve => setTimeout(resolve, 10)); // Small delay to ensure different timestamps
|
|
472
472
|
await store.persistWorkflowSnapshot({ workflowName: workflowName2, runId: runId2, snapshot: workflow2 });
|
|
473
473
|
|
|
474
|
-
const { runs, total } = await store.
|
|
474
|
+
const { runs, total } = await store.getWorkflowRuns({ workflowName: workflowName1 });
|
|
475
475
|
expect(runs).toHaveLength(1);
|
|
476
476
|
expect(total).toBe(1);
|
|
477
477
|
expect(runs[0]!.workflowName).toBe(workflowName1);
|
|
@@ -522,7 +522,7 @@ describe('PostgresStore', () => {
|
|
|
522
522
|
},
|
|
523
523
|
});
|
|
524
524
|
|
|
525
|
-
const { runs } = await store.
|
|
525
|
+
const { runs } = await store.getWorkflowRuns({
|
|
526
526
|
fromDate: yesterday,
|
|
527
527
|
toDate: now,
|
|
528
528
|
});
|
|
@@ -552,7 +552,7 @@ describe('PostgresStore', () => {
|
|
|
552
552
|
await store.persistWorkflowSnapshot({ workflowName: workflowName3, runId: runId3, snapshot: workflow3 });
|
|
553
553
|
|
|
554
554
|
// Get first page
|
|
555
|
-
const page1 = await store.
|
|
555
|
+
const page1 = await store.getWorkflowRuns({ limit: 2, offset: 0 });
|
|
556
556
|
expect(page1.runs).toHaveLength(2);
|
|
557
557
|
expect(page1.total).toBe(3); // Total count of all records
|
|
558
558
|
expect(page1.runs[0]!.workflowName).toBe(workflowName3);
|
|
@@ -563,7 +563,7 @@ describe('PostgresStore', () => {
|
|
|
563
563
|
expect(secondSnapshot.context?.steps[stepId2]?.status).toBe('running');
|
|
564
564
|
|
|
565
565
|
// Get second page
|
|
566
|
-
const page2 = await store.
|
|
566
|
+
const page2 = await store.getWorkflowRuns({ limit: 2, offset: 2 });
|
|
567
567
|
expect(page2.runs).toHaveLength(1);
|
|
568
568
|
expect(page2.total).toBe(3);
|
|
569
569
|
expect(page2.runs[0]!.workflowName).toBe(workflowName1);
|
|
@@ -691,10 +691,10 @@ describe('PostgresStore', () => {
|
|
|
691
691
|
it('should create and query tables in custom schema', async () => {
|
|
692
692
|
// Create thread in custom schema
|
|
693
693
|
const thread = createSampleThread();
|
|
694
|
-
await customSchemaStore.
|
|
694
|
+
await customSchemaStore.saveThread({ thread });
|
|
695
695
|
|
|
696
696
|
// Verify thread exists in custom schema
|
|
697
|
-
const retrieved = await customSchemaStore.
|
|
697
|
+
const retrieved = await customSchemaStore.getThreadById({ threadId: thread.id });
|
|
698
698
|
expect(retrieved?.title).toBe(thread.title);
|
|
699
699
|
});
|
|
700
700
|
|
|
@@ -703,19 +703,19 @@ describe('PostgresStore', () => {
|
|
|
703
703
|
const defaultThread = createSampleThread();
|
|
704
704
|
const customThread = createSampleThread();
|
|
705
705
|
|
|
706
|
-
await store.
|
|
707
|
-
await customSchemaStore.
|
|
706
|
+
await store.saveThread({ thread: defaultThread });
|
|
707
|
+
await customSchemaStore.saveThread({ thread: customThread });
|
|
708
708
|
|
|
709
709
|
// Verify threads exist in respective schemas
|
|
710
|
-
const defaultResult = await store.
|
|
711
|
-
const customResult = await customSchemaStore.
|
|
710
|
+
const defaultResult = await store.getThreadById({ threadId: defaultThread.id });
|
|
711
|
+
const customResult = await customSchemaStore.getThreadById({ threadId: customThread.id });
|
|
712
712
|
|
|
713
713
|
expect(defaultResult?.id).toBe(defaultThread.id);
|
|
714
714
|
expect(customResult?.id).toBe(customThread.id);
|
|
715
715
|
|
|
716
716
|
// Verify cross-schema isolation
|
|
717
|
-
const defaultInCustom = await customSchemaStore.
|
|
718
|
-
const customInDefault = await store.
|
|
717
|
+
const defaultInCustom = await customSchemaStore.getThreadById({ threadId: defaultThread.id });
|
|
718
|
+
const customInDefault = await store.getThreadById({ threadId: customThread.id });
|
|
719
719
|
|
|
720
720
|
expect(defaultInCustom).toBeNull();
|
|
721
721
|
expect(customInDefault).toBeNull();
|
|
@@ -887,7 +887,7 @@ describe('PostgresStore', () => {
|
|
|
887
887
|
await expect(async () => {
|
|
888
888
|
await restrictedDB.init();
|
|
889
889
|
const thread = createSampleThread();
|
|
890
|
-
await restrictedDB.
|
|
890
|
+
await restrictedDB.saveThread({ thread });
|
|
891
891
|
}).rejects.toThrow(
|
|
892
892
|
`Unable to create schema "${testSchema}". This requires CREATE privilege on the database.`,
|
|
893
893
|
);
|