@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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/pg@0.3.1-alpha.2 build /home/runner/work/mastra/mastra/stores/pg
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
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.4.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 9212ms
9
+ TSC ⚡️ Build success in 11190ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.2
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.2
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 11600ms
16
+ DTS ⚡️ Build success in 11666ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- CJS dist/index.cjs 48.63 KB
21
- CJS ⚡️ Build success in 1328ms
22
- ESM dist/index.js 48.21 KB
23
- ESM ⚡️ Build success in 1328ms
20
+ ESM dist/index.js 48.40 KB
21
+ ESM ⚡️ Build success in 1450ms
22
+ CJS dist/index.cjs 48.82 KB
23
+ CJS ⚡️ Build success in 1450ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 0.3.1-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 6a76949: add PgVector pgPoolOptions constructor parameter
8
+ - Updated dependencies [6262bd5]
9
+ - @mastra/core@0.9.1-alpha.3
10
+
3
11
  ## 0.3.1-alpha.2
4
12
 
5
13
  ### Patch Changes
@@ -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
- const connectionString = typeof config === "string" ? config : config.connectionString;
346
- if (!connectionString || typeof connectionString !== "string" || connectionString.trim() === "") {
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 = typeof config === "string" ? void 0 : config.schemaName;
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
- const connectionString = typeof config === "string" ? config : config.connectionString;
338
- if (!connectionString || typeof connectionString !== "string" || connectionString.trim() === "") {
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 = typeof config === "string" ? void 0 : config.schemaName;
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.2",
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.2"
27
+ "@mastra/core": "^0.9.1-alpha.3"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@microsoft/api-extractor": "^7.52.1",
@@ -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
  });
@@ -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: { connectionString: string; schemaName?: string });
75
- constructor(config: string | { connectionString: string; schemaName?: string }) {
76
- const connectionString = typeof config === 'string' ? config : config.connectionString;
77
- if (!connectionString || typeof connectionString !== 'string' || connectionString.trim() === '') {
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 = typeof config === 'string' ? undefined : config.schemaName;
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();