@mastra/pg 1.30.0-alpha.4 → 1.30.0-alpha.6

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/dist/index.js CHANGED
@@ -702,17 +702,25 @@ var PgVector = class extends MastraVector {
702
702
  await client.query(`SET search_path TO ${[...schemas].map((s) => `"${s}"`).join(", ")}`);
703
703
  }
704
704
  }
705
- /**
706
- * Checks if the installed pgvector version supports halfvec type.
707
- * halfvec was introduced in pgvector 0.7.0.
708
- */
709
- supportsHalfvec() {
705
+ /** Checks if the installed pgvector version is at least the given major.minor version. */
706
+ isVectorExtensionAtLeast(minMajor, minMinor) {
710
707
  if (!this.vectorExtensionVersion) return false;
711
708
  const parts = this.vectorExtensionVersion.split(".");
712
709
  const major = parseInt(parts[0] ?? "", 10);
713
710
  const minor = parseInt(parts[1] ?? "", 10);
714
711
  if (isNaN(major) || isNaN(minor)) return false;
715
- return major > 0 || major === 0 && minor >= 7;
712
+ return major > minMajor || major === minMajor && minor >= minMinor;
713
+ }
714
+ /**
715
+ * Checks if the installed pgvector version supports halfvec type.
716
+ * halfvec was introduced in pgvector 0.7.0.
717
+ */
718
+ supportsHalfvec() {
719
+ return this.isVectorExtensionAtLeast(0, 7);
720
+ }
721
+ /** Checks if pgvector >= 0.8.0 (required for the hnsw.iterative_scan setting). */
722
+ supportsIterativeScan() {
723
+ return this.isVectorExtensionAtLeast(0, 8);
716
724
  }
717
725
  /** Checks if pgvector >= 0.7.0 (required for bit type). */
718
726
  supportsBit() {
@@ -1031,7 +1039,7 @@ var PgVector = class extends MastraVector {
1031
1039
  const calculatedEf = ef ?? Math.max(topK, (indexInfo?.config?.m ?? 16) * topK);
1032
1040
  const searchEf = Math.min(1e3, Math.max(1, calculatedEf));
1033
1041
  await client.query(`SET LOCAL hnsw.ef_search = ${searchEf}`);
1034
- await client.query(`SET LOCAL hnsw.iterative_scan = strict_order`);
1042
+ if (this.supportsIterativeScan()) await client.query(`SET LOCAL hnsw.iterative_scan = strict_order`);
1035
1043
  }
1036
1044
  if (indexInfo.type === "ivfflat" && probes) await client.query(`SET LOCAL ivfflat.probes = ${probes}`);
1037
1045
  const { tableName } = this.getTableName(indexName);
@@ -2541,10 +2549,13 @@ function resolvePgConfig(config) {
2541
2549
  };
2542
2550
  }
2543
2551
  let pool;
2544
- if ("connectionString" in config) pool = new Pool({
2552
+ if ("connectionString" in config) pool = new Pool(buildConnectionStringPoolConfig({
2545
2553
  connectionString: config.connectionString,
2546
2554
  ssl: config.ssl
2547
- });
2555
+ }, {
2556
+ max: 10,
2557
+ idleTimeoutMillis: 1e4
2558
+ }));
2548
2559
  else pool = new Pool({
2549
2560
  host: config.host,
2550
2561
  port: config.port,
@@ -2756,7 +2767,15 @@ BEGIN
2756
2767
  END
2757
2768
  $mastra_timestamps_trigger$;`;
2758
2769
  }
2759
- const schemaSetupRegistry = /* @__PURE__ */ new Map();
2770
+ const schemaSetupRegistry = /* @__PURE__ */ new WeakMap();
2771
+ function getSchemaSetupRegistry(pool) {
2772
+ let registry = schemaSetupRegistry.get(pool);
2773
+ if (!registry) {
2774
+ registry = /* @__PURE__ */ new Map();
2775
+ schemaSetupRegistry.set(pool, registry);
2776
+ }
2777
+ return registry;
2778
+ }
2760
2779
  /**
2761
2780
  * Guard prune batch limits: a non-positive limit deletes nothing while callers'
2762
2781
  * drain checks (`affected < limit`) never fire, which turns the prune loop into
@@ -2995,11 +3014,12 @@ var PgDB = class extends MastraBase {
2995
3014
  }
2996
3015
  async setupSchema() {
2997
3016
  if (!this.schemaName) return;
2998
- let registryEntry = schemaSetupRegistry.get(this.schemaName);
3017
+ const registry = getSchemaSetupRegistry(this.client.$pool);
3018
+ let registryEntry = registry.get(this.schemaName);
2999
3019
  if (registryEntry?.complete) return;
3000
3020
  const snapshot = this.schemaSnapshot;
3001
3021
  if (snapshot && snapshot.tables.size > 0) {
3002
- schemaSetupRegistry.set(this.schemaName, {
3022
+ registry.set(this.schemaName, {
3003
3023
  promise: null,
3004
3024
  complete: true
3005
3025
  });
@@ -3025,19 +3045,19 @@ var PgDB = class extends MastraBase {
3025
3045
  throw new Error(`Unable to create schema "${schemaNameCapture}". This requires CREATE privilege on the database. Either create the schema manually or grant CREATE privilege to the user.`);
3026
3046
  }
3027
3047
  }
3028
- const entry = schemaSetupRegistry.get(schemaNameCapture);
3048
+ const entry = registry.get(schemaNameCapture);
3029
3049
  if (entry) entry.complete = true;
3030
3050
  this.logger.debug(`Schema "${quotedSchemaName}" is ready for use`);
3031
3051
  } catch (error) {
3032
- schemaSetupRegistry.delete(schemaNameCapture);
3052
+ registry.delete(schemaNameCapture);
3033
3053
  throw error;
3034
3054
  }
3035
3055
  })();
3036
- schemaSetupRegistry.set(this.schemaName, {
3056
+ registry.set(this.schemaName, {
3037
3057
  promise: setupPromise,
3038
3058
  complete: false
3039
3059
  });
3040
- registryEntry = schemaSetupRegistry.get(this.schemaName);
3060
+ registryEntry = registry.get(this.schemaName);
3041
3061
  }
3042
3062
  await registryEntry.promise;
3043
3063
  }