@mastra/pg 0.3.1-alpha.2 → 0.3.1-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 +7 -7
- package/CHANGELOG.md +8 -0
- package/dist/_tsup-dts-rollup.d.cts +2 -0
- package/dist/_tsup-dts-rollup.d.ts +2 -0
- package/dist/index.cjs +16 -4
- package/dist/index.js +16 -4
- package/package.json +2 -2
- package/src/vector/index.test.ts +41 -0
- package/src/vector/index.ts +31 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pg@0.3.1-alpha.
|
|
2
|
+
> @mastra/pg@0.3.1-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 11190ms
|
|
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 11666ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m48.40 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 1450ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m48.82 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 1450ms
|
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,7 @@ import type { MessageType } from '@mastra/core/memory';
|
|
|
14
14
|
import type { NumericOperator } from '@mastra/core/vector/filter';
|
|
15
15
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
16
16
|
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
17
|
+
import pg from 'pg';
|
|
17
18
|
import type { QueryResult } from '@mastra/core/vector';
|
|
18
19
|
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
19
20
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
@@ -212,6 +213,7 @@ declare class PgVector extends MastraVector {
|
|
|
212
213
|
constructor(config: {
|
|
213
214
|
connectionString: string;
|
|
214
215
|
schemaName?: string;
|
|
216
|
+
pgPoolOptions?: Omit<pg.PoolConfig, 'connectionString'>;
|
|
215
217
|
});
|
|
216
218
|
private getMutexByName;
|
|
217
219
|
private getTableName;
|
|
@@ -14,6 +14,7 @@ import type { MessageType } from '@mastra/core/memory';
|
|
|
14
14
|
import type { NumericOperator } from '@mastra/core/vector/filter';
|
|
15
15
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
16
16
|
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
17
|
+
import pg from 'pg';
|
|
17
18
|
import type { QueryResult } from '@mastra/core/vector';
|
|
18
19
|
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
19
20
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
@@ -212,6 +213,7 @@ declare class PgVector extends MastraVector {
|
|
|
212
213
|
constructor(config: {
|
|
213
214
|
connectionString: string;
|
|
214
215
|
schemaName?: string;
|
|
216
|
+
pgPoolOptions?: Omit<pg.PoolConfig, 'connectionString'>;
|
|
215
217
|
});
|
|
216
218
|
private getMutexByName;
|
|
217
219
|
private getTableName;
|
package/dist/index.cjs
CHANGED
|
@@ -342,22 +342,34 @@ var PgVector = class extends vector.MastraVector {
|
|
|
342
342
|
vectorExtensionInstalled = void 0;
|
|
343
343
|
schemaSetupComplete = void 0;
|
|
344
344
|
constructor(config) {
|
|
345
|
-
|
|
346
|
-
|
|
345
|
+
let connectionString;
|
|
346
|
+
let pgPoolOptions;
|
|
347
|
+
let schemaName;
|
|
348
|
+
if (typeof config === "string") {
|
|
349
|
+
connectionString = config;
|
|
350
|
+
schemaName = void 0;
|
|
351
|
+
pgPoolOptions = void 0;
|
|
352
|
+
} else {
|
|
353
|
+
connectionString = config.connectionString;
|
|
354
|
+
schemaName = config.schemaName;
|
|
355
|
+
pgPoolOptions = config.pgPoolOptions;
|
|
356
|
+
}
|
|
357
|
+
if (!connectionString || connectionString.trim() === "") {
|
|
347
358
|
throw new Error(
|
|
348
359
|
"PgVector: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults."
|
|
349
360
|
);
|
|
350
361
|
}
|
|
351
362
|
super();
|
|
352
|
-
this.schema =
|
|
363
|
+
this.schema = schemaName;
|
|
353
364
|
const basePool = new pg__default.default.Pool({
|
|
354
365
|
connectionString,
|
|
355
366
|
max: 20,
|
|
356
367
|
// Maximum number of clients in the pool
|
|
357
368
|
idleTimeoutMillis: 3e4,
|
|
358
369
|
// Close idle connections after 30 seconds
|
|
359
|
-
connectionTimeoutMillis: 2e3
|
|
370
|
+
connectionTimeoutMillis: 2e3,
|
|
360
371
|
// Fail fast if can't connect
|
|
372
|
+
...pgPoolOptions
|
|
361
373
|
});
|
|
362
374
|
const telemetry = this.__getTelemetry();
|
|
363
375
|
this.pool = telemetry?.traceClass(basePool, {
|
package/dist/index.js
CHANGED
|
@@ -334,22 +334,34 @@ var PgVector = class extends MastraVector {
|
|
|
334
334
|
vectorExtensionInstalled = void 0;
|
|
335
335
|
schemaSetupComplete = void 0;
|
|
336
336
|
constructor(config) {
|
|
337
|
-
|
|
338
|
-
|
|
337
|
+
let connectionString;
|
|
338
|
+
let pgPoolOptions;
|
|
339
|
+
let schemaName;
|
|
340
|
+
if (typeof config === "string") {
|
|
341
|
+
connectionString = config;
|
|
342
|
+
schemaName = void 0;
|
|
343
|
+
pgPoolOptions = void 0;
|
|
344
|
+
} else {
|
|
345
|
+
connectionString = config.connectionString;
|
|
346
|
+
schemaName = config.schemaName;
|
|
347
|
+
pgPoolOptions = config.pgPoolOptions;
|
|
348
|
+
}
|
|
349
|
+
if (!connectionString || connectionString.trim() === "") {
|
|
339
350
|
throw new Error(
|
|
340
351
|
"PgVector: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults."
|
|
341
352
|
);
|
|
342
353
|
}
|
|
343
354
|
super();
|
|
344
|
-
this.schema =
|
|
355
|
+
this.schema = schemaName;
|
|
345
356
|
const basePool = new pg.Pool({
|
|
346
357
|
connectionString,
|
|
347
358
|
max: 20,
|
|
348
359
|
// Maximum number of clients in the pool
|
|
349
360
|
idleTimeoutMillis: 3e4,
|
|
350
361
|
// Close idle connections after 30 seconds
|
|
351
|
-
connectionTimeoutMillis: 2e3
|
|
362
|
+
connectionTimeoutMillis: 2e3,
|
|
352
363
|
// Fail fast if can't connect
|
|
364
|
+
...pgPoolOptions
|
|
353
365
|
});
|
|
354
366
|
const telemetry = this.__getTelemetry();
|
|
355
367
|
this.pool = telemetry?.traceClass(basePool, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pg",
|
|
3
|
-
"version": "0.3.1-alpha.
|
|
3
|
+
"version": "0.3.1-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.9.1-alpha.
|
|
27
|
+
"@mastra/core": "^0.9.1-alpha.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@microsoft/api-extractor": "^7.52.1",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -2436,4 +2436,45 @@ describe('PgVector', () => {
|
|
|
2436
2436
|
});
|
|
2437
2437
|
});
|
|
2438
2438
|
});
|
|
2439
|
+
|
|
2440
|
+
describe('PoolConfig Custom Options', () => {
|
|
2441
|
+
it('should apply custom values to properties with default values', async () => {
|
|
2442
|
+
const db = new PgVector({
|
|
2443
|
+
connectionString,
|
|
2444
|
+
pgPoolOptions: {
|
|
2445
|
+
max: 5,
|
|
2446
|
+
idleTimeoutMillis: 10000,
|
|
2447
|
+
connectionTimeoutMillis: 1000,
|
|
2448
|
+
},
|
|
2449
|
+
});
|
|
2450
|
+
|
|
2451
|
+
expect(db['pool'].options.max).toBe(5);
|
|
2452
|
+
expect(db['pool'].options.idleTimeoutMillis).toBe(10000);
|
|
2453
|
+
expect(db['pool'].options.connectionTimeoutMillis).toBe(1000);
|
|
2454
|
+
});
|
|
2455
|
+
|
|
2456
|
+
it('should pass properties with no default values', async () => {
|
|
2457
|
+
const db = new PgVector({
|
|
2458
|
+
connectionString,
|
|
2459
|
+
pgPoolOptions: {
|
|
2460
|
+
ssl: false,
|
|
2461
|
+
},
|
|
2462
|
+
});
|
|
2463
|
+
|
|
2464
|
+
expect(db['pool'].options.ssl).toBe(false);
|
|
2465
|
+
});
|
|
2466
|
+
it('should keep default values when custom values are added', async () => {
|
|
2467
|
+
const db = new PgVector({
|
|
2468
|
+
connectionString,
|
|
2469
|
+
pgPoolOptions: {
|
|
2470
|
+
ssl: false,
|
|
2471
|
+
},
|
|
2472
|
+
});
|
|
2473
|
+
|
|
2474
|
+
expect(db['pool'].options.max).toBe(20);
|
|
2475
|
+
expect(db['pool'].options.idleTimeoutMillis).toBe(30000);
|
|
2476
|
+
expect(db['pool'].options.connectionTimeoutMillis).toBe(2000);
|
|
2477
|
+
expect(db['pool'].options.ssl).toBe(false);
|
|
2478
|
+
});
|
|
2479
|
+
});
|
|
2439
2480
|
});
|
package/src/vector/index.ts
CHANGED
|
@@ -71,23 +71,49 @@ export class PgVector extends MastraVector {
|
|
|
71
71
|
private schemaSetupComplete: boolean | undefined = undefined;
|
|
72
72
|
|
|
73
73
|
constructor(connectionString: string);
|
|
74
|
-
constructor(config: {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
constructor(config: {
|
|
75
|
+
connectionString: string;
|
|
76
|
+
schemaName?: string;
|
|
77
|
+
pgPoolOptions?: Omit<pg.PoolConfig, 'connectionString'>;
|
|
78
|
+
});
|
|
79
|
+
constructor(
|
|
80
|
+
config:
|
|
81
|
+
| string
|
|
82
|
+
| {
|
|
83
|
+
connectionString: string;
|
|
84
|
+
schemaName?: string;
|
|
85
|
+
pgPoolOptions?: Omit<pg.PoolConfig, 'connectionString'>;
|
|
86
|
+
},
|
|
87
|
+
) {
|
|
88
|
+
let connectionString: string;
|
|
89
|
+
let pgPoolOptions: Omit<pg.PoolConfig, 'connectionString'> | undefined;
|
|
90
|
+
let schemaName: string | undefined;
|
|
91
|
+
|
|
92
|
+
if (typeof config === 'string') {
|
|
93
|
+
connectionString = config;
|
|
94
|
+
schemaName = undefined;
|
|
95
|
+
pgPoolOptions = undefined;
|
|
96
|
+
} else {
|
|
97
|
+
connectionString = config.connectionString;
|
|
98
|
+
schemaName = config.schemaName;
|
|
99
|
+
pgPoolOptions = config.pgPoolOptions;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!connectionString || connectionString.trim() === '') {
|
|
78
103
|
throw new Error(
|
|
79
104
|
'PgVector: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults.',
|
|
80
105
|
);
|
|
81
106
|
}
|
|
82
107
|
super();
|
|
83
108
|
|
|
84
|
-
this.schema =
|
|
109
|
+
this.schema = schemaName;
|
|
85
110
|
|
|
86
111
|
const basePool = new pg.Pool({
|
|
87
112
|
connectionString,
|
|
88
113
|
max: 20, // Maximum number of clients in the pool
|
|
89
114
|
idleTimeoutMillis: 30000, // Close idle connections after 30 seconds
|
|
90
115
|
connectionTimeoutMillis: 2000, // Fail fast if can't connect
|
|
116
|
+
...pgPoolOptions,
|
|
91
117
|
});
|
|
92
118
|
|
|
93
119
|
const telemetry = this.__getTelemetry();
|