@mastra/pg 1.30.0-alpha.3 → 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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +38 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -22
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts +4 -0
- package/dist/vector/index.d.ts.map +1 -1
- package/dist/vector/sql-builder.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -317,13 +317,9 @@ const FILTER_OPERATORS = {
|
|
|
317
317
|
};
|
|
318
318
|
},
|
|
319
319
|
$exists: (key, paramIndex, value) => {
|
|
320
|
-
const
|
|
321
|
-
if (value === false) return {
|
|
322
|
-
sql: `NOT (metadata ? '${jsonPathKey}')`,
|
|
323
|
-
needsValue: false
|
|
324
|
-
};
|
|
320
|
+
const existsSql = key.includes(".") ? `${getJsonExtractExpr(key)} IS NOT NULL` : `metadata ? '${parseJsonPathKey(key)}'`;
|
|
325
321
|
return {
|
|
326
|
-
sql:
|
|
322
|
+
sql: value === false ? `NOT (${existsSql})` : existsSql,
|
|
327
323
|
needsValue: false
|
|
328
324
|
};
|
|
329
325
|
},
|
|
@@ -706,17 +702,25 @@ var PgVector = class extends MastraVector {
|
|
|
706
702
|
await client.query(`SET search_path TO ${[...schemas].map((s) => `"${s}"`).join(", ")}`);
|
|
707
703
|
}
|
|
708
704
|
}
|
|
709
|
-
/**
|
|
710
|
-
|
|
711
|
-
* halfvec was introduced in pgvector 0.7.0.
|
|
712
|
-
*/
|
|
713
|
-
supportsHalfvec() {
|
|
705
|
+
/** Checks if the installed pgvector version is at least the given major.minor version. */
|
|
706
|
+
isVectorExtensionAtLeast(minMajor, minMinor) {
|
|
714
707
|
if (!this.vectorExtensionVersion) return false;
|
|
715
708
|
const parts = this.vectorExtensionVersion.split(".");
|
|
716
709
|
const major = parseInt(parts[0] ?? "", 10);
|
|
717
710
|
const minor = parseInt(parts[1] ?? "", 10);
|
|
718
711
|
if (isNaN(major) || isNaN(minor)) return false;
|
|
719
|
-
return major >
|
|
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);
|
|
720
724
|
}
|
|
721
725
|
/** Checks if pgvector >= 0.7.0 (required for bit type). */
|
|
722
726
|
supportsBit() {
|
|
@@ -1035,7 +1039,7 @@ var PgVector = class extends MastraVector {
|
|
|
1035
1039
|
const calculatedEf = ef ?? Math.max(topK, (indexInfo?.config?.m ?? 16) * topK);
|
|
1036
1040
|
const searchEf = Math.min(1e3, Math.max(1, calculatedEf));
|
|
1037
1041
|
await client.query(`SET LOCAL hnsw.ef_search = ${searchEf}`);
|
|
1038
|
-
await client.query(`SET LOCAL hnsw.iterative_scan = strict_order`);
|
|
1042
|
+
if (this.supportsIterativeScan()) await client.query(`SET LOCAL hnsw.iterative_scan = strict_order`);
|
|
1039
1043
|
}
|
|
1040
1044
|
if (indexInfo.type === "ivfflat" && probes) await client.query(`SET LOCAL ivfflat.probes = ${probes}`);
|
|
1041
1045
|
const { tableName } = this.getTableName(indexName);
|
|
@@ -2545,10 +2549,13 @@ function resolvePgConfig(config) {
|
|
|
2545
2549
|
};
|
|
2546
2550
|
}
|
|
2547
2551
|
let pool;
|
|
2548
|
-
if ("connectionString" in config) pool = new Pool({
|
|
2552
|
+
if ("connectionString" in config) pool = new Pool(buildConnectionStringPoolConfig({
|
|
2549
2553
|
connectionString: config.connectionString,
|
|
2550
2554
|
ssl: config.ssl
|
|
2551
|
-
}
|
|
2555
|
+
}, {
|
|
2556
|
+
max: 10,
|
|
2557
|
+
idleTimeoutMillis: 1e4
|
|
2558
|
+
}));
|
|
2552
2559
|
else pool = new Pool({
|
|
2553
2560
|
host: config.host,
|
|
2554
2561
|
port: config.port,
|
|
@@ -2760,7 +2767,15 @@ BEGIN
|
|
|
2760
2767
|
END
|
|
2761
2768
|
$mastra_timestamps_trigger$;`;
|
|
2762
2769
|
}
|
|
2763
|
-
const schemaSetupRegistry = /* @__PURE__ */ new
|
|
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
|
+
}
|
|
2764
2779
|
/**
|
|
2765
2780
|
* Guard prune batch limits: a non-positive limit deletes nothing while callers'
|
|
2766
2781
|
* drain checks (`affected < limit`) never fire, which turns the prune loop into
|
|
@@ -2999,11 +3014,12 @@ var PgDB = class extends MastraBase {
|
|
|
2999
3014
|
}
|
|
3000
3015
|
async setupSchema() {
|
|
3001
3016
|
if (!this.schemaName) return;
|
|
3002
|
-
|
|
3017
|
+
const registry = getSchemaSetupRegistry(this.client.$pool);
|
|
3018
|
+
let registryEntry = registry.get(this.schemaName);
|
|
3003
3019
|
if (registryEntry?.complete) return;
|
|
3004
3020
|
const snapshot = this.schemaSnapshot;
|
|
3005
3021
|
if (snapshot && snapshot.tables.size > 0) {
|
|
3006
|
-
|
|
3022
|
+
registry.set(this.schemaName, {
|
|
3007
3023
|
promise: null,
|
|
3008
3024
|
complete: true
|
|
3009
3025
|
});
|
|
@@ -3029,19 +3045,19 @@ var PgDB = class extends MastraBase {
|
|
|
3029
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.`);
|
|
3030
3046
|
}
|
|
3031
3047
|
}
|
|
3032
|
-
const entry =
|
|
3048
|
+
const entry = registry.get(schemaNameCapture);
|
|
3033
3049
|
if (entry) entry.complete = true;
|
|
3034
3050
|
this.logger.debug(`Schema "${quotedSchemaName}" is ready for use`);
|
|
3035
3051
|
} catch (error) {
|
|
3036
|
-
|
|
3052
|
+
registry.delete(schemaNameCapture);
|
|
3037
3053
|
throw error;
|
|
3038
3054
|
}
|
|
3039
3055
|
})();
|
|
3040
|
-
|
|
3056
|
+
registry.set(this.schemaName, {
|
|
3041
3057
|
promise: setupPromise,
|
|
3042
3058
|
complete: false
|
|
3043
3059
|
});
|
|
3044
|
-
registryEntry =
|
|
3060
|
+
registryEntry = registry.get(this.schemaName);
|
|
3045
3061
|
}
|
|
3046
3062
|
await registryEntry.promise;
|
|
3047
3063
|
}
|