@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/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -341,13 +341,9 @@ const FILTER_OPERATORS = {
|
|
|
341
341
|
};
|
|
342
342
|
},
|
|
343
343
|
$exists: (key, paramIndex, value) => {
|
|
344
|
-
const
|
|
345
|
-
if (value === false) return {
|
|
346
|
-
sql: `NOT (metadata ? '${jsonPathKey}')`,
|
|
347
|
-
needsValue: false
|
|
348
|
-
};
|
|
344
|
+
const existsSql = key.includes(".") ? `${getJsonExtractExpr(key)} IS NOT NULL` : `metadata ? '${parseJsonPathKey(key)}'`;
|
|
349
345
|
return {
|
|
350
|
-
sql:
|
|
346
|
+
sql: value === false ? `NOT (${existsSql})` : existsSql,
|
|
351
347
|
needsValue: false
|
|
352
348
|
};
|
|
353
349
|
},
|
|
@@ -730,17 +726,25 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
730
726
|
await client.query(`SET search_path TO ${[...schemas].map((s) => `"${s}"`).join(", ")}`);
|
|
731
727
|
}
|
|
732
728
|
}
|
|
733
|
-
/**
|
|
734
|
-
|
|
735
|
-
* halfvec was introduced in pgvector 0.7.0.
|
|
736
|
-
*/
|
|
737
|
-
supportsHalfvec() {
|
|
729
|
+
/** Checks if the installed pgvector version is at least the given major.minor version. */
|
|
730
|
+
isVectorExtensionAtLeast(minMajor, minMinor) {
|
|
738
731
|
if (!this.vectorExtensionVersion) return false;
|
|
739
732
|
const parts = this.vectorExtensionVersion.split(".");
|
|
740
733
|
const major = parseInt(parts[0] ?? "", 10);
|
|
741
734
|
const minor = parseInt(parts[1] ?? "", 10);
|
|
742
735
|
if (isNaN(major) || isNaN(minor)) return false;
|
|
743
|
-
return major >
|
|
736
|
+
return major > minMajor || major === minMajor && minor >= minMinor;
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Checks if the installed pgvector version supports halfvec type.
|
|
740
|
+
* halfvec was introduced in pgvector 0.7.0.
|
|
741
|
+
*/
|
|
742
|
+
supportsHalfvec() {
|
|
743
|
+
return this.isVectorExtensionAtLeast(0, 7);
|
|
744
|
+
}
|
|
745
|
+
/** Checks if pgvector >= 0.8.0 (required for the hnsw.iterative_scan setting). */
|
|
746
|
+
supportsIterativeScan() {
|
|
747
|
+
return this.isVectorExtensionAtLeast(0, 8);
|
|
744
748
|
}
|
|
745
749
|
/** Checks if pgvector >= 0.7.0 (required for bit type). */
|
|
746
750
|
supportsBit() {
|
|
@@ -1059,7 +1063,7 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1059
1063
|
const calculatedEf = ef ?? Math.max(topK, (indexInfo?.config?.m ?? 16) * topK);
|
|
1060
1064
|
const searchEf = Math.min(1e3, Math.max(1, calculatedEf));
|
|
1061
1065
|
await client.query(`SET LOCAL hnsw.ef_search = ${searchEf}`);
|
|
1062
|
-
await client.query(`SET LOCAL hnsw.iterative_scan = strict_order`);
|
|
1066
|
+
if (this.supportsIterativeScan()) await client.query(`SET LOCAL hnsw.iterative_scan = strict_order`);
|
|
1063
1067
|
}
|
|
1064
1068
|
if (indexInfo.type === "ivfflat" && probes) await client.query(`SET LOCAL ivfflat.probes = ${probes}`);
|
|
1065
1069
|
const { tableName } = this.getTableName(indexName);
|
|
@@ -2569,10 +2573,13 @@ function resolvePgConfig(config) {
|
|
|
2569
2573
|
};
|
|
2570
2574
|
}
|
|
2571
2575
|
let pool;
|
|
2572
|
-
if ("connectionString" in config) pool = new pg.Pool({
|
|
2576
|
+
if ("connectionString" in config) pool = new pg.Pool(buildConnectionStringPoolConfig({
|
|
2573
2577
|
connectionString: config.connectionString,
|
|
2574
2578
|
ssl: config.ssl
|
|
2575
|
-
}
|
|
2579
|
+
}, {
|
|
2580
|
+
max: 10,
|
|
2581
|
+
idleTimeoutMillis: 1e4
|
|
2582
|
+
}));
|
|
2576
2583
|
else pool = new pg.Pool({
|
|
2577
2584
|
host: config.host,
|
|
2578
2585
|
port: config.port,
|
|
@@ -2784,7 +2791,15 @@ BEGIN
|
|
|
2784
2791
|
END
|
|
2785
2792
|
$mastra_timestamps_trigger$;`;
|
|
2786
2793
|
}
|
|
2787
|
-
const schemaSetupRegistry = /* @__PURE__ */ new
|
|
2794
|
+
const schemaSetupRegistry = /* @__PURE__ */ new WeakMap();
|
|
2795
|
+
function getSchemaSetupRegistry(pool) {
|
|
2796
|
+
let registry = schemaSetupRegistry.get(pool);
|
|
2797
|
+
if (!registry) {
|
|
2798
|
+
registry = /* @__PURE__ */ new Map();
|
|
2799
|
+
schemaSetupRegistry.set(pool, registry);
|
|
2800
|
+
}
|
|
2801
|
+
return registry;
|
|
2802
|
+
}
|
|
2788
2803
|
/**
|
|
2789
2804
|
* Guard prune batch limits: a non-positive limit deletes nothing while callers'
|
|
2790
2805
|
* drain checks (`affected < limit`) never fire, which turns the prune loop into
|
|
@@ -3023,11 +3038,12 @@ var PgDB = class extends _mastra_core_base.MastraBase {
|
|
|
3023
3038
|
}
|
|
3024
3039
|
async setupSchema() {
|
|
3025
3040
|
if (!this.schemaName) return;
|
|
3026
|
-
|
|
3041
|
+
const registry = getSchemaSetupRegistry(this.client.$pool);
|
|
3042
|
+
let registryEntry = registry.get(this.schemaName);
|
|
3027
3043
|
if (registryEntry?.complete) return;
|
|
3028
3044
|
const snapshot = this.schemaSnapshot;
|
|
3029
3045
|
if (snapshot && snapshot.tables.size > 0) {
|
|
3030
|
-
|
|
3046
|
+
registry.set(this.schemaName, {
|
|
3031
3047
|
promise: null,
|
|
3032
3048
|
complete: true
|
|
3033
3049
|
});
|
|
@@ -3053,19 +3069,19 @@ var PgDB = class extends _mastra_core_base.MastraBase {
|
|
|
3053
3069
|
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.`);
|
|
3054
3070
|
}
|
|
3055
3071
|
}
|
|
3056
|
-
const entry =
|
|
3072
|
+
const entry = registry.get(schemaNameCapture);
|
|
3057
3073
|
if (entry) entry.complete = true;
|
|
3058
3074
|
this.logger.debug(`Schema "${quotedSchemaName}" is ready for use`);
|
|
3059
3075
|
} catch (error) {
|
|
3060
|
-
|
|
3076
|
+
registry.delete(schemaNameCapture);
|
|
3061
3077
|
throw error;
|
|
3062
3078
|
}
|
|
3063
3079
|
})();
|
|
3064
|
-
|
|
3080
|
+
registry.set(this.schemaName, {
|
|
3065
3081
|
promise: setupPromise,
|
|
3066
3082
|
complete: false
|
|
3067
3083
|
});
|
|
3068
|
-
registryEntry =
|
|
3084
|
+
registryEntry = registry.get(this.schemaName);
|
|
3069
3085
|
}
|
|
3070
3086
|
await registryEntry.promise;
|
|
3071
3087
|
}
|