@vibeorm/extensions 2.2.1 → 2.2.2
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 +24 -10
- package/dist/index.js.map +5 -5
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +11 -6
- package/dist/search/index.js.map +3 -3
- package/dist/trgm/index.js +3 -3
- package/dist/trgm/index.js.map +3 -3
- package/dist/vector/index.d.ts.map +1 -1
- package/dist/vector/index.js +12 -3
- package/dist/vector/index.js.map +3 -3
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/extensions/src/search/index.ts
|
|
3
|
-
import { VibeError as VibeError2, defineExtension, unsupportedCapability } from "@vibeorm/schema";
|
|
3
|
+
import { VibeError as VibeError2, assertIdentifierFits, defineExtension, fitDefaultName, unsupportedCapability } from "@vibeorm/schema";
|
|
4
4
|
|
|
5
5
|
// packages/extensions/src/shared.ts
|
|
6
6
|
import { VibeError } from "@vibeorm/schema";
|
|
@@ -156,9 +156,14 @@ function resolveArtifactNames(params) {
|
|
|
156
156
|
hint: "only the tsvector engine materializes a generated column \u2014 drop columnName or target tsvector"
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
|
+
const remedy = "Shorten it, or set a shorter `name:` on the @@search declaration.";
|
|
160
|
+
if (decl.columnName !== undefined)
|
|
161
|
+
assertIdentifierFits({ name: decl.columnName, dialect, what: "@@search columnName", remedy });
|
|
162
|
+
if (decl.indexName !== undefined)
|
|
163
|
+
assertIdentifierFits({ name: decl.indexName, dialect, what: "@@search indexName", remedy });
|
|
159
164
|
return {
|
|
160
|
-
tsvColumn: decl.columnName ??
|
|
161
|
-
indexName: decl.indexName ??
|
|
165
|
+
tsvColumn: decl.columnName ?? fitDefaultName({ prefix: decl.base, suffix: "_tsv", dialect }),
|
|
166
|
+
indexName: decl.indexName ?? fitDefaultName({ prefix: decl.base, suffix: "_idx", dialect })
|
|
162
167
|
};
|
|
163
168
|
}
|
|
164
169
|
function resolveRank(params) {
|
|
@@ -252,7 +257,7 @@ function searchArtifacts(ctx) {
|
|
|
252
257
|
id: `search:${modelName}:index`,
|
|
253
258
|
owns: { kind: "index", table, name: bm25Names.indexName },
|
|
254
259
|
create: [
|
|
255
|
-
`CREATE INDEX IF NOT EXISTS ${quote(bm25Names.indexName)} ON ${quote(table)} USING bm25 (${[pkColumn, ...columns].map((column) => quote(column)).join(", ")}) WITH (key_field
|
|
260
|
+
`CREATE INDEX IF NOT EXISTS ${quote(bm25Names.indexName)} ON ${quote(table)} USING bm25 (${[pkColumn, ...columns].map((column) => quote(column)).join(", ")}) WITH (key_field=${dialect.quoteStringLiteral({ value: pkColumn })});`
|
|
256
261
|
],
|
|
257
262
|
drop: [`DROP INDEX IF EXISTS ${quote(bm25Names.indexName)};`]
|
|
258
263
|
});
|
|
@@ -282,7 +287,7 @@ function searchArtifacts(ctx) {
|
|
|
282
287
|
auxiliaryPrefixes: [`${fts}_`]
|
|
283
288
|
},
|
|
284
289
|
create: [
|
|
285
|
-
`CREATE VIRTUAL TABLE IF NOT EXISTS ${quote(fts)} USING fts5(${columnList}, content
|
|
290
|
+
`CREATE VIRTUAL TABLE IF NOT EXISTS ${quote(fts)} USING fts5(${columnList}, content=${dialect.quoteStringLiteral({ value: table })});`
|
|
286
291
|
],
|
|
287
292
|
drop: [`DROP TABLE IF EXISTS ${quote(fts)};`]
|
|
288
293
|
}, {
|
|
@@ -628,7 +633,7 @@ function search(options = {}) {
|
|
|
628
633
|
});
|
|
629
634
|
}
|
|
630
635
|
// packages/extensions/src/vector/index.ts
|
|
631
|
-
import { VibeError as VibeError3, defineExtension as defineExtension2, unsupportedCapability as unsupportedCapability2 } from "@vibeorm/schema";
|
|
636
|
+
import { VibeError as VibeError3, assertIdentifierFits as assertIdentifierFits2, defineExtension as defineExtension2, fitDefaultName as fitDefaultName2, unsupportedCapability as unsupportedCapability2 } from "@vibeorm/schema";
|
|
632
637
|
import { ParamCollector as ParamCollector2, getSqlDialect as getSqlDialect2, renderExpr as renderExpr2 } from "@vibeorm/sql";
|
|
633
638
|
var VERSION2 = "2.0.0-alpha.0";
|
|
634
639
|
var METRIC_OPERATOR = {
|
|
@@ -702,6 +707,13 @@ function vectorArtifacts(ctx) {
|
|
|
702
707
|
const columns = vectorColumnsOf({ declaration });
|
|
703
708
|
const indexFields = declStringArray(declaration, "fields") ?? [];
|
|
704
709
|
const kindRaw = declString(declaration, "index") ?? "hnsw";
|
|
710
|
+
if (!INDEX_KINDS.includes(kindRaw)) {
|
|
711
|
+
throw new VibeError3({
|
|
712
|
+
code: "VIBE_SCHEMA_INVALID",
|
|
713
|
+
message: `@@vector on "${modelName}" declares index kind "${kindRaw}" \u2014 expected one of ${INDEX_KINDS.join(", ")}`,
|
|
714
|
+
meta: { model: modelName, index: kindRaw }
|
|
715
|
+
});
|
|
716
|
+
}
|
|
705
717
|
const metricRaw = declString(declaration, "metric") ?? "cosine";
|
|
706
718
|
const metric = METRICS.find((candidate) => candidate === metricRaw) ?? "cosine";
|
|
707
719
|
for (const field of indexFields) {
|
|
@@ -714,7 +726,9 @@ function vectorArtifacts(ctx) {
|
|
|
714
726
|
}
|
|
715
727
|
const column = columnNameOf({ model, field });
|
|
716
728
|
const nameOverride = indexFields.length === 1 ? declString(declaration, "indexName") : undefined;
|
|
717
|
-
|
|
729
|
+
if (nameOverride !== undefined)
|
|
730
|
+
assertIdentifierFits2({ name: nameOverride, dialect: ctx.dialect, what: "@@vector indexName", remedy: "Shorten it." });
|
|
731
|
+
const indexName = nameOverride ?? fitDefaultName2({ prefix: `${table}_${column}_${kindRaw}`, suffix: "_idx", dialect: ctx.dialect });
|
|
718
732
|
const withOptions = [];
|
|
719
733
|
const m = declaration["m"];
|
|
720
734
|
const efConstruction = declaration["efConstruction"];
|
|
@@ -939,7 +953,7 @@ function vector(options = {}) {
|
|
|
939
953
|
});
|
|
940
954
|
}
|
|
941
955
|
// packages/extensions/src/trgm/index.ts
|
|
942
|
-
import { VibeError as VibeError4, defineExtension as defineExtension3, unsupportedCapability as unsupportedCapability3 } from "@vibeorm/schema";
|
|
956
|
+
import { VibeError as VibeError4, defineExtension as defineExtension3, fitDefaultName as fitDefaultName3, unsupportedCapability as unsupportedCapability3 } from "@vibeorm/schema";
|
|
943
957
|
import { getSqlDialect as getSqlDialect3 } from "@vibeorm/sql";
|
|
944
958
|
var DEFAULT_THRESHOLD = 0.3;
|
|
945
959
|
var VERSION3 = "2.0.0-alpha.0";
|
|
@@ -971,7 +985,7 @@ function trgmArtifacts(ctx) {
|
|
|
971
985
|
const table = tableNameOf({ model });
|
|
972
986
|
for (const field of declStringArray(declaration, "fields") ?? []) {
|
|
973
987
|
const column = columnNameOf({ model, field });
|
|
974
|
-
const indexName = `${table}_${column}
|
|
988
|
+
const indexName = fitDefaultName3({ prefix: `${table}_${column}_trgm`, suffix: "_idx", dialect: ctx.dialect });
|
|
975
989
|
artifacts.push({
|
|
976
990
|
id: `trgm:${modelName}:${field}`,
|
|
977
991
|
owns: { kind: "index", table, name: indexName },
|
|
@@ -1126,4 +1140,4 @@ export {
|
|
|
1126
1140
|
vector
|
|
1127
1141
|
};
|
|
1128
1142
|
|
|
1129
|
-
//# debugId=
|
|
1143
|
+
//# debugId=22E4747EF131DCA564756E2164756E21
|