@vibeorm/extensions 2.2.0 → 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 +30 -18
- package/dist/index.js.map +5 -5
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +14 -9
- 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 +14 -5
- 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
|
}, {
|
|
@@ -493,7 +498,7 @@ function search(options = {}) {
|
|
|
493
498
|
if (fields.length === 0) {
|
|
494
499
|
return { error: "@@search requires a field list, e.g. @@search([title, body])" };
|
|
495
500
|
}
|
|
496
|
-
const missing = fields.find((
|
|
501
|
+
const missing = fields.find((name) => !fieldNames.includes(name));
|
|
497
502
|
if (missing !== undefined) {
|
|
498
503
|
return { error: `@@search references unknown field "${missing}"` };
|
|
499
504
|
}
|
|
@@ -627,9 +632,8 @@ function search(options = {}) {
|
|
|
627
632
|
}
|
|
628
633
|
});
|
|
629
634
|
}
|
|
630
|
-
|
|
631
635
|
// packages/extensions/src/vector/index.ts
|
|
632
|
-
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";
|
|
633
637
|
import { ParamCollector as ParamCollector2, getSqlDialect as getSqlDialect2, renderExpr as renderExpr2 } from "@vibeorm/sql";
|
|
634
638
|
var VERSION2 = "2.0.0-alpha.0";
|
|
635
639
|
var METRIC_OPERATOR = {
|
|
@@ -703,6 +707,13 @@ function vectorArtifacts(ctx) {
|
|
|
703
707
|
const columns = vectorColumnsOf({ declaration });
|
|
704
708
|
const indexFields = declStringArray(declaration, "fields") ?? [];
|
|
705
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
|
+
}
|
|
706
717
|
const metricRaw = declString(declaration, "metric") ?? "cosine";
|
|
707
718
|
const metric = METRICS.find((candidate) => candidate === metricRaw) ?? "cosine";
|
|
708
719
|
for (const field of indexFields) {
|
|
@@ -715,7 +726,9 @@ function vectorArtifacts(ctx) {
|
|
|
715
726
|
}
|
|
716
727
|
const column = columnNameOf({ model, field });
|
|
717
728
|
const nameOverride = indexFields.length === 1 ? declString(declaration, "indexName") : undefined;
|
|
718
|
-
|
|
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 });
|
|
719
732
|
const withOptions = [];
|
|
720
733
|
const m = declaration["m"];
|
|
721
734
|
const efConstruction = declaration["efConstruction"];
|
|
@@ -939,9 +952,8 @@ function vector(options = {}) {
|
|
|
939
952
|
}
|
|
940
953
|
});
|
|
941
954
|
}
|
|
942
|
-
|
|
943
955
|
// packages/extensions/src/trgm/index.ts
|
|
944
|
-
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";
|
|
945
957
|
import { getSqlDialect as getSqlDialect3 } from "@vibeorm/sql";
|
|
946
958
|
var DEFAULT_THRESHOLD = 0.3;
|
|
947
959
|
var VERSION3 = "2.0.0-alpha.0";
|
|
@@ -973,7 +985,7 @@ function trgmArtifacts(ctx) {
|
|
|
973
985
|
const table = tableNameOf({ model });
|
|
974
986
|
for (const field of declStringArray(declaration, "fields") ?? []) {
|
|
975
987
|
const column = columnNameOf({ model, field });
|
|
976
|
-
const indexName = `${table}_${column}
|
|
988
|
+
const indexName = fitDefaultName3({ prefix: `${table}_${column}_trgm`, suffix: "_idx", dialect: ctx.dialect });
|
|
977
989
|
artifacts.push({
|
|
978
990
|
id: `trgm:${modelName}:${field}`,
|
|
979
991
|
owns: { kind: "index", table, name: indexName },
|
|
@@ -1120,12 +1132,12 @@ function trgm(options = {}) {
|
|
|
1120
1132
|
});
|
|
1121
1133
|
}
|
|
1122
1134
|
export {
|
|
1123
|
-
|
|
1124
|
-
trgm,
|
|
1125
|
-
search,
|
|
1126
|
-
resolveSearchEngine,
|
|
1135
|
+
createSearchDelegate,
|
|
1127
1136
|
createVectorNamespace,
|
|
1128
|
-
|
|
1137
|
+
resolveSearchEngine,
|
|
1138
|
+
search,
|
|
1139
|
+
trgm,
|
|
1140
|
+
vector
|
|
1129
1141
|
};
|
|
1130
1142
|
|
|
1131
|
-
//# debugId=
|
|
1143
|
+
//# debugId=22E4747EF131DCA564756E2164756E21
|