@mastra/pg 0.0.0-storage-20250225005900

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,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 { }
@@ -0,0 +1,3 @@
1
+ export { PgVector } from './_tsup-dts-rollup.js';
2
+ export { PostgresConfig } from './_tsup-dts-rollup.js';
3
+ export { PostgresStore } from './_tsup-dts-rollup.js';