@mastra/pg 0.1.0-alpha.2 → 0.1.0-alpha.20

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 CHANGED
@@ -1,5 +1,163 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 0.1.0-alpha.20
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [016493a]
8
+ - Updated dependencies [382f4dc]
9
+ - Updated dependencies [176bc42]
10
+ - Updated dependencies [d68b532]
11
+ - Updated dependencies [fe3dcb0]
12
+ - Updated dependencies [e448a26]
13
+ - Updated dependencies [fd75f3c]
14
+ - Updated dependencies [ccf115c]
15
+ - Updated dependencies [a221426]
16
+ - @mastra/core@0.2.0-alpha.110
17
+
18
+ ## 0.1.0-alpha.19
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [d5fccfb]
23
+ - @mastra/core@0.2.0-alpha.109
24
+
25
+ ## 0.1.0-alpha.18
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [5ee67d3]
30
+ - Updated dependencies [95a4697]
31
+ - @mastra/core@0.2.0-alpha.108
32
+
33
+ ## 0.1.0-alpha.17
34
+
35
+ ### Patch Changes
36
+
37
+ - Updated dependencies [66a5392]
38
+ - @mastra/core@0.2.0-alpha.107
39
+
40
+ ## 0.1.0-alpha.16
41
+
42
+ ### Patch Changes
43
+
44
+ - Updated dependencies [6f2c0f5]
45
+ - Updated dependencies [a8a459a]
46
+ - @mastra/core@0.2.0-alpha.106
47
+
48
+ ## 0.1.0-alpha.15
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies [1420ae2]
53
+ - Updated dependencies [99f1847]
54
+ - @mastra/core@0.2.0-alpha.105
55
+
56
+ ## 0.1.0-alpha.14
57
+
58
+ ### Patch Changes
59
+
60
+ - b97ca96: Tracing into default storage
61
+ - Updated dependencies [5fdc87c]
62
+ - Updated dependencies [b97ca96]
63
+ - Updated dependencies [72d1990]
64
+ - Updated dependencies [cf6d825]
65
+ - Updated dependencies [10870bc]
66
+ - @mastra/core@0.2.0-alpha.104
67
+
68
+ ## 0.1.0-alpha.13
69
+
70
+ ### Patch Changes
71
+
72
+ - Updated dependencies [4534e77]
73
+ - @mastra/core@0.2.0-alpha.103
74
+
75
+ ## 0.1.0-alpha.12
76
+
77
+ ### Patch Changes
78
+
79
+ - Updated dependencies [a9345f9]
80
+ - @mastra/core@0.2.0-alpha.102
81
+
82
+ ## 0.1.0-alpha.11
83
+
84
+ ### Patch Changes
85
+
86
+ - 4f1d1a1: Enforce types ann cleanup package.json
87
+ - Updated dependencies [66a03ec]
88
+ - Updated dependencies [4f1d1a1]
89
+ - @mastra/core@0.2.0-alpha.101
90
+
91
+ ## 0.1.0-alpha.10
92
+
93
+ ### Patch Changes
94
+
95
+ - Updated dependencies [9d1796d]
96
+ - @mastra/core@0.2.0-alpha.100
97
+
98
+ ## 0.1.0-alpha.9
99
+
100
+ ### Patch Changes
101
+
102
+ - Updated dependencies [7d83b92]
103
+ - @mastra/core@0.2.0-alpha.99
104
+
105
+ ## 0.1.0-alpha.8
106
+
107
+ ### Patch Changes
108
+
109
+ - 70dabd9: Fix broken publish
110
+ - Updated dependencies [70dabd9]
111
+ - Updated dependencies [202d404]
112
+ - @mastra/core@0.2.0-alpha.98
113
+
114
+ ## 0.1.0-alpha.7
115
+
116
+ ### Patch Changes
117
+
118
+ - 07c069d: Update build script
119
+ - Updated dependencies [07c069d]
120
+ - Updated dependencies [7892533]
121
+ - Updated dependencies [e6d8055]
122
+ - Updated dependencies [5950de5]
123
+ - Updated dependencies [df843d3]
124
+ - Updated dependencies [a870123]
125
+ - @mastra/core@0.2.0-alpha.97
126
+
127
+ ## 0.1.0-alpha.6
128
+
129
+ ### Patch Changes
130
+
131
+ - Updated dependencies [74b3078]
132
+ - @mastra/core@0.2.0-alpha.96
133
+
134
+ ## 0.1.0-alpha.5
135
+
136
+ ### Patch Changes
137
+
138
+ - Updated dependencies [9fb59d6]
139
+ - @mastra/core@0.2.0-alpha.95
140
+
141
+ ## 0.1.0-alpha.4
142
+
143
+ ### Minor Changes
144
+
145
+ - 8b416d9: Breaking changes
146
+
147
+ ### Patch Changes
148
+
149
+ - 9c10484: update all packages
150
+ - Updated dependencies [9c10484]
151
+ - Updated dependencies [8b416d9]
152
+ - @mastra/core@0.2.0-alpha.94
153
+
154
+ ## 0.1.0-alpha.3
155
+
156
+ ### Patch Changes
157
+
158
+ - Updated dependencies [5285356]
159
+ - @mastra/core@0.2.0-alpha.93
160
+
3
161
  ## 0.1.0-alpha.2
4
162
 
5
163
  ### Minor 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.2",
3
+ "version": "0.1.0-alpha.20",
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,18 +17,19 @@
17
17
  "dependencies": {
18
18
  "pg": "^8.13.1",
19
19
  "pg-promise": "^11.5.4",
20
- "@mastra/core": "^0.2.0-alpha.92"
20
+ "@mastra/core": "^0.2.0-alpha.110"
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-node src/index.ts --format esm --dts --clean --treeshake",
31
- "dev": "tsup-node src/index.ts --format esm --dts --clean --treeshake --watch",
31
+ "build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
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",
34
35
  "posttest": "docker compose down -v",
@@ -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
  }