@mastra/pg 0.1.0-alpha.10 → 0.1.0-alpha.12
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 +16 -0
- package/dist/_tsup-dts-rollup.d.ts +141 -0
- package/dist/index.d.ts +3 -82
- package/dist/index.js +3 -0
- package/package.json +5 -5
- package/src/vector/filter.ts +1 -1
- package/src/vector/sql-builder.ts +7 -7
- package/tsconfig.json +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.1.0-alpha.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [a9345f9]
|
|
8
|
+
- @mastra/core@0.2.0-alpha.102
|
|
9
|
+
|
|
10
|
+
## 0.1.0-alpha.11
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 4f1d1a1: Enforce types ann cleanup package.json
|
|
15
|
+
- Updated dependencies [66a03ec]
|
|
16
|
+
- Updated dependencies [4f1d1a1]
|
|
17
|
+
- @mastra/core@0.2.0-alpha.101
|
|
18
|
+
|
|
3
19
|
## 0.1.0-alpha.10
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -0,0 +1,141 @@
|
|
|
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 { Filter } from '@mastra/core/filter';
|
|
6
|
+
import { IndexStats } from '@mastra/core/vector';
|
|
7
|
+
import { LogicalOperator } from '@mastra/core/filter';
|
|
8
|
+
import { MastraStorage } from '@mastra/core/storage';
|
|
9
|
+
import { MastraVector } from '@mastra/core/vector';
|
|
10
|
+
import { MessageType } from '@mastra/core/memory';
|
|
11
|
+
import { NumericOperator } from '@mastra/core/filter';
|
|
12
|
+
import { OperatorSupport } from '@mastra/core/filter';
|
|
13
|
+
import { QueryResult } from '@mastra/core/vector';
|
|
14
|
+
import { RegexOperator } from '@mastra/core/filter';
|
|
15
|
+
import { StorageColumn } from '@mastra/core/storage';
|
|
16
|
+
import { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
17
|
+
import { StorageThreadType } from '@mastra/core/memory';
|
|
18
|
+
import { TABLE_NAMES } from '@mastra/core/storage';
|
|
19
|
+
import { WorkflowRunState } from '@mastra/core/workflows';
|
|
20
|
+
|
|
21
|
+
export declare function buildFilterQuery(filter: Filter, minScore: number): FilterResult;
|
|
22
|
+
|
|
23
|
+
export declare const FILTER_OPERATORS: Record<string, OperatorFn>;
|
|
24
|
+
|
|
25
|
+
declare type FilterOperator = {
|
|
26
|
+
sql: string;
|
|
27
|
+
needsValue: boolean;
|
|
28
|
+
transformValue?: (value: any) => any;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export declare interface FilterResult {
|
|
32
|
+
sql: string;
|
|
33
|
+
values: any[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare const handleKey: (key: string) => string;
|
|
37
|
+
|
|
38
|
+
declare type OperatorFn = (key: string, paramIndex: number, value?: any) => FilterOperator;
|
|
39
|
+
|
|
40
|
+
export declare type OperatorType = BasicOperator | NumericOperator | ArrayOperator | ElementOperator | LogicalOperator | '$contains' | Exclude<RegexOperator, '$options'>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Translates MongoDB-style filters to PG compatible filters.
|
|
44
|
+
*
|
|
45
|
+
* Key differences from MongoDB:
|
|
46
|
+
*
|
|
47
|
+
* Logical Operators ($and, $or, $nor):
|
|
48
|
+
* - Can be used at the top level or nested within fields
|
|
49
|
+
* - Can take either a single condition or an array of conditions
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
export declare class PGFilterTranslator extends BaseFilterTranslator {
|
|
53
|
+
protected getSupportedOperators(): OperatorSupport;
|
|
54
|
+
translate(filter: Filter): Filter;
|
|
55
|
+
private translateNode;
|
|
56
|
+
private translateRegexPattern;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare class PgVector extends MastraVector {
|
|
60
|
+
private pool;
|
|
61
|
+
constructor(connectionString: string);
|
|
62
|
+
transformFilter(filter?: Filter): Filter;
|
|
63
|
+
query(indexName: string, queryVector: number[], topK?: number, filter?: Filter, includeVector?: boolean, minScore?: number): Promise<QueryResult[]>;
|
|
64
|
+
upsert(indexName: string, vectors: number[][], metadata?: Record<string, any>[], ids?: string[]): Promise<string[]>;
|
|
65
|
+
createIndex(indexName: string, dimension: number, metric?: 'cosine' | 'euclidean' | 'dotproduct'): Promise<void>;
|
|
66
|
+
listIndexes(): Promise<string[]>;
|
|
67
|
+
describeIndex(indexName: string): Promise<IndexStats>;
|
|
68
|
+
deleteIndex(indexName: string): Promise<void>;
|
|
69
|
+
truncateIndex(indexName: string): Promise<void>;
|
|
70
|
+
disconnect(): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
export { PgVector }
|
|
73
|
+
export { PgVector as PgVector_alias_1 }
|
|
74
|
+
|
|
75
|
+
declare type PostgresConfig = {
|
|
76
|
+
host: string;
|
|
77
|
+
port: number;
|
|
78
|
+
database: string;
|
|
79
|
+
user: string;
|
|
80
|
+
password: string;
|
|
81
|
+
} | {
|
|
82
|
+
connectionString: string;
|
|
83
|
+
};
|
|
84
|
+
export { PostgresConfig }
|
|
85
|
+
export { PostgresConfig as PostgresConfig_alias_1 }
|
|
86
|
+
|
|
87
|
+
declare class PostgresStore extends MastraStorage {
|
|
88
|
+
private db;
|
|
89
|
+
private pgp;
|
|
90
|
+
constructor(config: PostgresConfig);
|
|
91
|
+
createTable({ tableName, schema, }: {
|
|
92
|
+
tableName: TABLE_NAMES;
|
|
93
|
+
schema: Record<string, StorageColumn>;
|
|
94
|
+
}): Promise<void>;
|
|
95
|
+
clearTable({ tableName }: {
|
|
96
|
+
tableName: TABLE_NAMES;
|
|
97
|
+
}): Promise<void>;
|
|
98
|
+
insert({ tableName, record }: {
|
|
99
|
+
tableName: TABLE_NAMES;
|
|
100
|
+
record: Record<string, any>;
|
|
101
|
+
}): Promise<void>;
|
|
102
|
+
load<R>({ tableName, keys }: {
|
|
103
|
+
tableName: TABLE_NAMES;
|
|
104
|
+
keys: Record<string, string>;
|
|
105
|
+
}): Promise<R | null>;
|
|
106
|
+
getThreadById({ threadId }: {
|
|
107
|
+
threadId: string;
|
|
108
|
+
}): Promise<StorageThreadType | null>;
|
|
109
|
+
getThreadsByResourceId({ resourceId }: {
|
|
110
|
+
resourceId: string;
|
|
111
|
+
}): Promise<StorageThreadType[]>;
|
|
112
|
+
saveThread({ thread }: {
|
|
113
|
+
thread: StorageThreadType;
|
|
114
|
+
}): Promise<StorageThreadType>;
|
|
115
|
+
updateThread({ id, title, metadata, }: {
|
|
116
|
+
id: string;
|
|
117
|
+
title: string;
|
|
118
|
+
metadata: Record<string, unknown>;
|
|
119
|
+
}): Promise<StorageThreadType>;
|
|
120
|
+
deleteThread({ threadId }: {
|
|
121
|
+
threadId: string;
|
|
122
|
+
}): Promise<void>;
|
|
123
|
+
getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
|
|
124
|
+
saveMessages({ messages }: {
|
|
125
|
+
messages: MessageType[];
|
|
126
|
+
}): Promise<MessageType[]>;
|
|
127
|
+
persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
|
|
128
|
+
workflowName: string;
|
|
129
|
+
runId: string;
|
|
130
|
+
snapshot: WorkflowRunState;
|
|
131
|
+
}): Promise<void>;
|
|
132
|
+
loadWorkflowSnapshot({ workflowName, runId, }: {
|
|
133
|
+
workflowName: string;
|
|
134
|
+
runId: string;
|
|
135
|
+
}): Promise<WorkflowRunState | null>;
|
|
136
|
+
close(): Promise<void>;
|
|
137
|
+
}
|
|
138
|
+
export { PostgresStore }
|
|
139
|
+
export { PostgresStore as PostgresStore_alias_1 }
|
|
140
|
+
|
|
141
|
+
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -1,82 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pg",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.12",
|
|
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,17 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"pg": "^8.13.1",
|
|
19
19
|
"pg-promise": "^11.5.4",
|
|
20
|
-
"@mastra/core": "^0.2.0-alpha.
|
|
20
|
+
"@mastra/core": "^0.2.0-alpha.102"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"@types/node": "^22.
|
|
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
27
|
"vitest": "^3.0.4"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "tsup src/index.ts --format esm --dts --clean --treeshake",
|
|
30
|
+
"build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
|
|
31
31
|
"build:watch": "pnpm build --watch",
|
|
32
32
|
"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
33
|
"test": "vitest run",
|
package/src/vector/filter.ts
CHANGED
|
@@ -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
|
}
|