@mastra/pg 0.17.2 → 0.17.3-alpha.1

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,34 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 0.17.3-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - feat(pg): add flexible PostgreSQL configuration with shared types ([#8103](https://github.com/mastra-ai/mastra/pull/8103))
8
+ - Add support for multiple connection methods: connectionString, host/port/database, and Cloud SQL
9
+ - Introduce shared PostgresConfig type with generic SSL support (ISSLConfig for pg-promise, ConnectionOptions for pg)
10
+ - Add pgPoolOptions support to PgVector for advanced pool configuration
11
+ - Create shared validation helpers to reduce code duplication
12
+ - Maintain backward compatibility with existing configurations
13
+
14
+ - Updated dependencies [[`1ed9670`](https://github.com/mastra-ai/mastra/commit/1ed9670d3ca50cb60dc2e517738c5eef3968ed27), [`158381d`](https://github.com/mastra-ai/mastra/commit/158381d39335be934b81ef8a1947bccace492c25), [`fb703b9`](https://github.com/mastra-ai/mastra/commit/fb703b9634eeaff1a6eb2b5531ce0f9e8fb04727), [`37a2314`](https://github.com/mastra-ai/mastra/commit/37a23148e0e5a3b40d4f9f098b194671a8a49faf), [`05a9dee`](https://github.com/mastra-ai/mastra/commit/05a9dee3d355694d28847bfffb6289657fcf7dfa), [`e3c1077`](https://github.com/mastra-ai/mastra/commit/e3c107763aedd1643d3def5df450c235da9ff76c), [`1bccdb3`](https://github.com/mastra-ai/mastra/commit/1bccdb33eb90cbeba2dc5ece1c2561fb774b26b6), [`5ef944a`](https://github.com/mastra-ai/mastra/commit/5ef944a3721d93105675cac2b2311432ff8cc393), [`d6b186f`](https://github.com/mastra-ai/mastra/commit/d6b186fb08f1caf1b86f73d3a5ee88fb999ca3be), [`65493b3`](https://github.com/mastra-ai/mastra/commit/65493b31c36f6fdb78f9679f7e1ecf0c250aa5ee), [`a998b8f`](https://github.com/mastra-ai/mastra/commit/a998b8f858091c2ec47683e60766cf12d03001e4), [`8a37bdd`](https://github.com/mastra-ai/mastra/commit/8a37bddb6d8614a32c5b70303d583d80c620ea61)]:
15
+ - @mastra/core@0.21.0-alpha.1
16
+
17
+ ## 0.17.3-alpha.0
18
+
19
+ ### Patch Changes
20
+
21
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8619](https://github.com/mastra-ai/mastra/pull/8619))
22
+
23
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8557](https://github.com/mastra-ai/mastra/pull/8557))
24
+
25
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8626](https://github.com/mastra-ai/mastra/pull/8626))
26
+
27
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8686](https://github.com/mastra-ai/mastra/pull/8686))
28
+
29
+ - Updated dependencies [[`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`7b1ef57`](https://github.com/mastra-ai/mastra/commit/7b1ef57fc071c2aa2a2e32905b18cd88719c5a39), [`ee68e82`](https://github.com/mastra-ai/mastra/commit/ee68e8289ea4408d29849e899bc6e78b3bd4e843), [`228228b`](https://github.com/mastra-ai/mastra/commit/228228b0b1de9291cb8887587f5cea1a8757ebad), [`ea33930`](https://github.com/mastra-ai/mastra/commit/ea339301e82d6318257720d811b043014ee44064), [`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`135d6f2`](https://github.com/mastra-ai/mastra/commit/135d6f22a326ed1dffff858700669dff09d2c9eb), [`59d036d`](https://github.com/mastra-ai/mastra/commit/59d036d4c2706b430b0e3f1f1e0ee853ce16ca04)]:
30
+ - @mastra/core@0.21.0-alpha.0
31
+
3
32
  ## 0.17.2
4
33
 
5
34
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -14,11 +14,62 @@ var scores = require('@mastra/core/scores');
14
14
 
15
15
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
16
 
17
- var pg__default = /*#__PURE__*/_interopDefault(pg);
17
+ function _interopNamespace(e) {
18
+ if (e && e.__esModule) return e;
19
+ var n = Object.create(null);
20
+ if (e) {
21
+ Object.keys(e).forEach(function (k) {
22
+ if (k !== 'default') {
23
+ var d = Object.getOwnPropertyDescriptor(e, k);
24
+ Object.defineProperty(n, k, d.get ? d : {
25
+ enumerable: true,
26
+ get: function () { return e[k]; }
27
+ });
28
+ }
29
+ });
30
+ }
31
+ n.default = e;
32
+ return Object.freeze(n);
33
+ }
34
+
35
+ var pg__namespace = /*#__PURE__*/_interopNamespace(pg);
18
36
  var xxhash__default = /*#__PURE__*/_interopDefault(xxhash);
19
37
  var pgPromise__default = /*#__PURE__*/_interopDefault(pgPromise);
20
38
 
21
39
  // src/vector/index.ts
40
+
41
+ // src/shared/config.ts
42
+ var isConnectionStringConfig = (cfg) => {
43
+ return "connectionString" in cfg;
44
+ };
45
+ var isHostConfig = (cfg) => {
46
+ return "host" in cfg && "database" in cfg && "user" in cfg && "password" in cfg;
47
+ };
48
+ var isCloudSqlConfig = (cfg) => {
49
+ return "stream" in cfg || "password" in cfg && typeof cfg.password === "function";
50
+ };
51
+ var validateConfig = (name, config) => {
52
+ if (isConnectionStringConfig(config)) {
53
+ if (!config.connectionString || typeof config.connectionString !== "string" || config.connectionString.trim() === "") {
54
+ throw new Error(
55
+ `${name}: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults.`
56
+ );
57
+ }
58
+ } else if (isCloudSqlConfig(config)) ; else if (isHostConfig(config)) {
59
+ const required = ["host", "database", "user", "password"];
60
+ for (const key of required) {
61
+ if (!config[key] || typeof config[key] !== "string" || config[key].trim() === "") {
62
+ throw new Error(
63
+ `${name}: ${key} must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults.`
64
+ );
65
+ }
66
+ }
67
+ } else {
68
+ throw new Error(
69
+ `${name}: invalid config. Provide either {connectionString}, {host,port,database,user,password}, or a pg ClientConfig (e.g., Cloud SQL connector with \`stream\`).`
70
+ );
71
+ }
72
+ };
22
73
  var PGFilterTranslator = class extends filter.BaseFilterTranslator {
23
74
  getSupportedOperators() {
24
75
  return {
@@ -375,29 +426,46 @@ var PgVector = class extends vector.MastraVector {
375
426
  vectorExtensionSchema = null;
376
427
  schemaSetupComplete = void 0;
377
428
  cacheWarmupPromise = null;
378
- constructor({
379
- connectionString,
380
- schemaName,
381
- pgPoolOptions
382
- }) {
429
+ constructor(config) {
383
430
  try {
384
- if (!connectionString || connectionString.trim() === "") {
385
- throw new Error(
386
- "PgVector: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults."
387
- );
388
- }
431
+ validateConfig("PgVector", config);
389
432
  super();
390
- this.schema = schemaName;
391
- const basePool = new pg__default.default.Pool({
392
- connectionString,
393
- max: 20,
394
- // Maximum number of clients in the pool
395
- idleTimeoutMillis: 3e4,
396
- // Close idle connections after 30 seconds
397
- connectionTimeoutMillis: 2e3,
398
- // Fail fast if can't connect
399
- ...pgPoolOptions
400
- });
433
+ this.schema = config.schemaName;
434
+ let poolConfig;
435
+ if (isConnectionStringConfig(config)) {
436
+ poolConfig = {
437
+ connectionString: config.connectionString,
438
+ ssl: config.ssl,
439
+ max: config.max ?? 20,
440
+ idleTimeoutMillis: config.idleTimeoutMillis ?? 3e4,
441
+ connectionTimeoutMillis: 2e3,
442
+ ...config.pgPoolOptions
443
+ };
444
+ } else if (isCloudSqlConfig(config)) {
445
+ poolConfig = {
446
+ ...config,
447
+ max: config.max ?? 20,
448
+ idleTimeoutMillis: config.idleTimeoutMillis ?? 3e4,
449
+ connectionTimeoutMillis: 2e3,
450
+ ...config.pgPoolOptions
451
+ };
452
+ } else if (isHostConfig(config)) {
453
+ poolConfig = {
454
+ host: config.host,
455
+ port: config.port,
456
+ database: config.database,
457
+ user: config.user,
458
+ password: config.password,
459
+ ssl: config.ssl,
460
+ max: config.max ?? 20,
461
+ idleTimeoutMillis: config.idleTimeoutMillis ?? 3e4,
462
+ connectionTimeoutMillis: 2e3,
463
+ ...config.pgPoolOptions
464
+ };
465
+ } else {
466
+ throw new Error("PgVector: invalid configuration provided");
467
+ }
468
+ const basePool = new pg__namespace.Pool(poolConfig);
401
469
  const telemetry = this.__getTelemetry();
402
470
  this.pool = telemetry?.traceClass(basePool, {
403
471
  spanNamePrefix: "pg-vector",
@@ -431,7 +499,7 @@ var PgVector = class extends vector.MastraVector {
431
499
  domain: error.ErrorDomain.MASTRA_VECTOR,
432
500
  category: error.ErrorCategory.THIRD_PARTY,
433
501
  details: {
434
- schemaName: schemaName ?? ""
502
+ schemaName: "schemaName" in config ? config.schemaName ?? "" : ""
435
503
  }
436
504
  },
437
505
  error$1
@@ -4060,36 +4128,8 @@ var PostgresStore = class extends storage.MastraStorage {
4060
4128
  isConnected = false;
4061
4129
  stores;
4062
4130
  constructor(config) {
4063
- const isConnectionStringConfig = (cfg) => {
4064
- return "connectionString" in cfg;
4065
- };
4066
- const isHostConfig = (cfg) => {
4067
- return "host" in cfg && "database" in cfg && "user" in cfg && "password" in cfg;
4068
- };
4069
- const isCloudSqlConfig = (cfg) => {
4070
- return "stream" in cfg || "password" in cfg && typeof cfg.password === "function";
4071
- };
4072
4131
  try {
4073
- if (isConnectionStringConfig(config)) {
4074
- if (!config.connectionString || typeof config.connectionString !== "string" || config.connectionString.trim() === "") {
4075
- throw new Error(
4076
- "PostgresStore: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults."
4077
- );
4078
- }
4079
- } else if (isCloudSqlConfig(config)) ; else if (isHostConfig(config)) {
4080
- const required = ["host", "database", "user", "password"];
4081
- for (const key of required) {
4082
- if (!config[key] || typeof config[key] !== "string" || config[key].trim() === "") {
4083
- throw new Error(
4084
- `PostgresStore: ${key} must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults.`
4085
- );
4086
- }
4087
- }
4088
- } else {
4089
- throw new Error(
4090
- "PostgresStore: invalid config. Provide either {connectionString}, {host,port,database,user,password}, or a pg ClientConfig (e.g., Cloud SQL connector with `stream`)."
4091
- );
4092
- }
4132
+ validateConfig("PostgresStore", config);
4093
4133
  super({ name: "PostgresStore" });
4094
4134
  this.schema = config.schemaName || "public";
4095
4135
  if (isConnectionStringConfig(config)) {