@vibeorm/extensions 4.0.0 → 4.1.0
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 +35 -25
- package/dist/index.js.map +6 -6
- package/dist/search/index.js +25 -17
- package/dist/search/index.js.map +4 -4
- package/dist/shared.d.ts +6 -0
- package/dist/trgm/index.js +10 -4
- package/dist/trgm/index.js.map +4 -4
- package/dist/vector/index.js +16 -8
- package/dist/vector/index.js.map +4 -4
- package/package.json +4 -4
package/dist/shared.d.ts
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
* userland extensions can do everything these do with the same public hooks.
|
|
4
4
|
*/
|
|
5
5
|
import type { ExtensionDoctorCheck, ExtensionSqlExecutor, ModelIR } from "@vibeorm/schema";
|
|
6
|
+
import type { SqlDialect } from "@vibeorm/sql";
|
|
7
|
+
/** Quote a built-in's physical target; PostgreSQL ownership is always public. */
|
|
8
|
+
export declare function extensionSqlName(params: {
|
|
9
|
+
dialect: SqlDialect;
|
|
10
|
+
name: string;
|
|
11
|
+
}): string;
|
|
6
12
|
/** Refuse non-finite extension arguments before compilation or execution. */
|
|
7
13
|
export declare function finiteNumber(params: {
|
|
8
14
|
value: unknown;
|
package/dist/trgm/index.js
CHANGED
|
@@ -4,7 +4,12 @@ import { VibeError as VibeError2, defineExtension, fitDefaultName, unsupportedCa
|
|
|
4
4
|
import { getSqlDialect } from "@vibeorm/sql";
|
|
5
5
|
|
|
6
6
|
// packages/extensions/src/shared.ts
|
|
7
|
-
import { VibeError } from "@vibeorm/schema";
|
|
7
|
+
import { VibeError, assertExtensionModelPlacement, qualifiedSqlName } from "@vibeorm/schema";
|
|
8
|
+
function extensionSqlName(params) {
|
|
9
|
+
const { dialect, name } = params;
|
|
10
|
+
const physical = qualifiedSqlName({ name });
|
|
11
|
+
return dialect.name === "postgres" ? `${dialect.quoteIdent({ name: physical.namespace })}.${dialect.quoteIdent({ name: physical.name })}` : dialect.quoteIdent({ name });
|
|
12
|
+
}
|
|
8
13
|
function finiteNumber(params) {
|
|
9
14
|
const { value, name, integer, min } = params;
|
|
10
15
|
if (typeof value !== "number" || !Number.isFinite(value) || integer === true && !Number.isSafeInteger(value) || min !== undefined && value < min) {
|
|
@@ -17,6 +22,7 @@ function finiteNumber(params) {
|
|
|
17
22
|
return value;
|
|
18
23
|
}
|
|
19
24
|
function tableNameOf(params) {
|
|
25
|
+
assertExtensionModelPlacement({ namespace: params.model.namespace });
|
|
20
26
|
return params.model.dbName ?? params.model.name;
|
|
21
27
|
}
|
|
22
28
|
function columnNameOf(params) {
|
|
@@ -120,9 +126,9 @@ function trgmArtifacts(ctx) {
|
|
|
120
126
|
id: `trgm:${modelName}:${field}`,
|
|
121
127
|
owns: { kind: "index", table, name: indexName },
|
|
122
128
|
create: [
|
|
123
|
-
`CREATE INDEX IF NOT EXISTS ${quote(indexName)} ON ${
|
|
129
|
+
`CREATE INDEX IF NOT EXISTS ${quote(indexName)} ON ${extensionSqlName({ dialect, name: table })} USING gin (${quote(column)} gin_trgm_ops);`
|
|
124
130
|
],
|
|
125
|
-
drop: [`DROP INDEX IF EXISTS ${
|
|
131
|
+
drop: [`DROP INDEX IF EXISTS ${extensionSqlName({ dialect, name: indexName })};`]
|
|
126
132
|
});
|
|
127
133
|
}
|
|
128
134
|
}
|
|
@@ -265,4 +271,4 @@ export {
|
|
|
265
271
|
trgm
|
|
266
272
|
};
|
|
267
273
|
|
|
268
|
-
//# debugId=
|
|
274
|
+
//# debugId=B6DB83AEA289F10C64756E2164756E21
|
package/dist/trgm/index.js.map
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/trgm/index.ts", "../src/shared.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * `trgm` — pg_trgm fuzzy matching (extensions.md §6). Operators-only: it\n * claims NO client surface. `where: { name: { similarTo: \"jon\" } }` compiles\n * to a bound predicate plus `gin_trgm_ops` indexes over the fields declared\n * in `@@trgm([...])`. Postgres/pglite only; anywhere else →\n * VIBE_UNSUPPORTED_CAPABILITY.\n *\n * INDEXABILITY (SQL review M8 + PG-1): a bare `similarity(col, $q) >= $t` is\n * a guaranteed full scan — GIN/GiST trigram indexes serve the `%` operator,\n * not the function. The predicate compiles as\n * `(col % $q AND similarity(col, $q) >= $t)` only when the effective\n * threshold is ≥ max(configured threshold, 0.3): `%` prunes at the\n * CONNECTION's `pg_trgm.similarity_threshold`, and pooled connections that\n * `onConnect` never touched keep the server default 0.3 — so the gate floor\n * must assume 0.3 even when a lower threshold was configured. Below the\n * floor, the predicate falls back to the full-scan form — correct on every\n * connection. A postgresql.conf value raised ABOVE the floor can still\n * prune; the doctor's similarity_threshold check surfaces it.\n */\n\nimport { VibeError, defineExtension, fitDefaultName, unsupportedCapability } from \"@vibeorm/schema\";\nimport type {\n ExtensionArtifact,\n ExtensionSchemaContext,\n VibeExtension,\n} from \"@vibeorm/schema\";\nimport { getSqlDialect } from \"@vibeorm/sql\";\nimport { columnNameOf, declStringArray, pgExtensionCheck, tableNameOf } from \"../shared.ts\";\n\n// ─── Options ──────────────────────────────────────────────────────\n\nexport type TrgmOptions = {\n /**\n * Similarity threshold for `similarTo` (default 0.3). Also applied to the\n * session's `pg_trgm.similarity_threshold` on `$connect()` so raw `%`\n * queries agree with the operator.\n */\n readonly threshold?: number;\n};\n\n/** Operand of `similarTo`: the text, or text plus a per-use threshold. */\nexport type SimilarToOperand = string | { readonly text: string; readonly threshold?: number };\n\nconst DEFAULT_THRESHOLD = 0.3;\nconst VERSION = \"2.0.0-alpha.0\";\n\nfunction validThreshold(value: unknown): value is number {\n return typeof value === \"number\" && Number.isFinite(value) && value >= 0 && value <= 1;\n}\n\n// ─── Artifacts ────────────────────────────────────────────────────\n\nfunction trgmArtifacts(ctx: ExtensionSchemaContext): readonly ExtensionArtifact[] {\n if (ctx.dialect !== \"postgres\") {\n throw unsupportedCapability({\n dialect: ctx.dialect,\n feature: \"the trgm extension (pg_trgm)\",\n hint: \"pg_trgm exists on postgres/pglite only\",\n });\n }\n const dialect = getSqlDialect({ dialect: ctx.dialect });\n const quote = (name: string): string => dialect.quoteIdent({ name });\n\n const artifacts: ExtensionArtifact[] = [\n {\n id: \"trgm:extension\",\n owns: { kind: \"postgresExtension\", name: \"pg_trgm\" },\n create: [\"CREATE EXTENSION IF NOT EXISTS pg_trgm;\"],\n drop: [\"DROP EXTENSION IF EXISTS pg_trgm;\"],\n },\n ];\n\n for (const [modelName, declaration] of Object.entries(ctx.declarations)) {\n const model = ctx.schema.models.find((candidate) => candidate.name === modelName);\n if (model === undefined) continue;\n const table = tableNameOf({ model });\n for (const field of declStringArray(declaration, \"fields\") ?? []) {\n const column = columnNameOf({ model, field });\n const indexName = fitDefaultName({ prefix: `${table}_${column}_trgm`, suffix: \"_idx\", dialect: ctx.dialect });\n artifacts.push({\n id: `trgm:${modelName}:${field}`,\n owns: { kind: \"index\", table, name: indexName },\n create: [\n `CREATE INDEX IF NOT EXISTS ${quote(indexName)} ON ${quote(table)} USING gin (${quote(column)} gin_trgm_ops);`,\n ],\n drop: [`DROP INDEX IF EXISTS ${quote(indexName)};`],\n });\n }\n }\n return artifacts;\n}\n\n// ─── Factory ──────────────────────────────────────────────────────\n\n/**\n * pg_trgm fuzzy matching.\n *\n * @example vibeorm.config.ts / VibeClient\n * extensions: [trgm({ threshold: 0.3 })]\n *\n * @example schema\n * // @@trgm([name]) → gin_trgm_ops index on \"name\"\n * await db.user.findMany({ where: { name: { similarTo: \"jon\" } } });\n */\nexport function trgm(options: TrgmOptions = {}): VibeExtension {\n const threshold = options.threshold === undefined ? DEFAULT_THRESHOLD : options.threshold;\n if (!validThreshold(threshold)) {\n throw new VibeError({ code: \"VIBE_VALIDATION\", message: \"trgm threshold must be a finite number between 0 and 1\", meta: { argument: \"threshold\" } });\n }\n\n return defineExtension({\n name: \"trgm\",\n version: VERSION,\n options: { ...options },\n requires: { postgresql: { extension: \"pg_trgm\" }, pglite: { extension: \"pg_trgm\" } },\n\n schema: {\n modelAttributes: [\n {\n name: \"trgm\",\n parse: ({ args, fieldNames }) => {\n const fields = args.fields ?? [];\n if (fields.length === 0) {\n return { error: \"@@trgm requires a field list, e.g. @@trgm([name])\" };\n }\n const missing = fields.find((name) => !fieldNames.includes(name));\n if (missing !== undefined) {\n return { error: `@@trgm references unknown field \"${missing}\"` };\n }\n return { declaration: { fields } };\n },\n },\n ],\n indexKinds: [\"gin_trgm\"],\n },\n\n migrate: { artifacts: trgmArtifacts },\n\n sql: {\n whereOperators: [\n {\n name: \"similarTo\",\n compile: ({ column, operand, dialect, options: extOptions }) => {\n if (dialect !== \"postgres\") {\n throw unsupportedCapability({\n dialect,\n feature: 'the \"similarTo\" operator (pg_trgm)',\n hint: \"pg_trgm exists on postgres/pglite only\",\n });\n }\n const text =\n typeof operand === \"string\"\n ? operand\n : typeof operand === \"object\" && operand !== null && \"text\" in operand\n ? (operand as { text: unknown }).text\n : undefined;\n if (typeof text !== \"string\") {\n return { error: 'expects a string or { text, threshold? }' };\n }\n const perUse =\n typeof operand === \"object\" && operand !== null && \"threshold\" in operand\n ? (operand as { threshold: unknown }).threshold\n : undefined;\n const configured = extOptions[\"threshold\"];\n if ((configured !== undefined && !validThreshold(configured)) || (perUse !== undefined && !validThreshold(perUse))) {\n return { error: \"threshold must be a finite number between 0 and 1\" };\n }\n const sessionThreshold = typeof configured === \"number\" ? configured : DEFAULT_THRESHOLD;\n const effective = typeof perUse === \"number\" ? perUse : sessionThreshold;\n // PG-1 (SQL review round 2): `%` prunes at the CONNECTION's\n // pg_trgm.similarity_threshold. onConnect SETs the configured\n // value only on connections `$connect` touches — POOLED\n // connections keep the server default 0.3 (live-proven dropped\n // rows: configured 0.2, similarity 0.273, `%` pruned at 0.3).\n // Gate the index route on effective >= max(configured, 0.3): a\n // connection whose actual GUC is LOWER than effective only widens\n // the prefilter (safe). A postgresql.conf value RAISED above the\n // effective threshold can still prune — the doctor's\n // similarity_threshold check surfaces exactly that (documented in\n // docs/dialect-notes.md).\n if (effective >= Math.max(sessionThreshold, DEFAULT_THRESHOLD)) {\n // M8: `%` walks the gin_trgm_ops index; similarity() enforces\n // the exact bound.\n return {\n fragment: {\n parts: [\n \"(\",\n { ident: column },\n \" % \",\n { param: text },\n \" AND similarity(\",\n { ident: column },\n \", \",\n { param: text },\n \") >= \",\n { param: effective },\n \")\",\n ],\n },\n };\n }\n // Effective threshold below the `%` gate floor (max(configured,\n // 0.3)): on a pooled connection the GUC may still be 0.3, so `%`\n // would prune matches the caller asked for — honest full scan.\n return {\n fragment: {\n parts: [\n \"similarity(\",\n { ident: column },\n \", \",\n { param: text },\n \") >= \",\n { param: effective },\n ],\n },\n };\n },\n },\n ],\n },\n\n runtime: {\n onConnect: async ({ execute, dialect, options: extOptions }) => {\n // Session default for raw `%` queries; the operator itself never\n // depends on it. Only meaningful when explicitly configured.\n if (dialect !== \"postgres\" || typeof extOptions[\"threshold\"] !== \"number\") return;\n await execute({\n text: `SET pg_trgm.similarity_threshold = ${Number(threshold)}`,\n });\n },\n },\n\n doctor: async ({ execute, dialect }) => {\n if (dialect !== \"postgres\") {\n return { checks: [{ name: \"trgm dialect\", ok: false, note: \"postgres/pglite only\" }] };\n }\n const checks = [await pgExtensionCheck({ execute, name: \"pg_trgm\" })];\n // PG-1: the `%` route assumes the connection's GUC is ≤ the gate floor\n // (max(configured, 0.3)). A postgresql.conf value raised ABOVE it makes\n // `%` prune rows the similarity() bound would keep — surface it here.\n // current_setting(…, true) returns NULL instead of ERRORING when the\n // pg_trgm library is not session-loaded yet (SHOW errors there — a\n // false alarm on healthy setups, closure item 3); NULL means no value\n // is configured anywhere, so the 0.3 default (≤ floor) applies.\n const floor = Math.max(threshold, DEFAULT_THRESHOLD);\n try {\n const rows = await execute({\n text: `SELECT current_setting('pg_trgm.similarity_threshold', true) AS \"threshold\"`,\n });\n const raw = rows[0]?.[\"threshold\"];\n if (raw === undefined || raw === null || raw === \"\") {\n checks.push({\n name: \"trgm similarity_threshold\",\n ok: true,\n note: `not set in this session — the 0.3 default applies (≤ gate floor ${floor})`,\n });\n return { checks };\n }\n const server = Number(raw);\n checks.push(\n Number.isNaN(server)\n ? { name: \"trgm similarity_threshold\", ok: false, note: \"could not read pg_trgm.similarity_threshold\" }\n : server <= floor\n ? { name: \"trgm similarity_threshold\", ok: true, note: `server ${server} ≤ gate floor ${floor}` }\n : {\n name: \"trgm similarity_threshold\",\n ok: false,\n note: `server pg_trgm.similarity_threshold=${server} exceeds the %-gate floor ${floor} — indexed similarTo queries can drop rows; lower the GUC or raise the extension threshold`,\n },\n );\n } catch {\n checks.push({\n name: \"trgm similarity_threshold\",\n ok: false,\n note: \"reading pg_trgm.similarity_threshold failed\",\n });\n }\n return { checks };\n },\n });\n}\n",
|
|
6
|
-
"/**\n * Helpers shared by the tier-1 extensions. Nothing here is privileged —\n * userland extensions can do everything these do with the same public hooks.\n */\n\nimport { VibeError } from \"@vibeorm/schema\";\nimport type {\n ExtensionDoctorCheck,\n ExtensionSqlExecutor,\n ModelIR,\n} from \"@vibeorm/schema\";\n\n// ─── Numeric admission ────────────────────────────────────────────\n\n/** Refuse non-finite extension arguments before compilation or execution. */\nexport function finiteNumber(params: { value: unknown; name: string; integer?: boolean; min?: number }): number {\n const { value, name, integer, min } = params;\n if (typeof value !== \"number\" || !Number.isFinite(value) ||\n (integer === true && !Number.isSafeInteger(value)) || (min !== undefined && value < min)) {\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `${name} must be a finite ${integer === true ? \"safe integer\" : \"number\"}${min === undefined ? \"\" : ` >= ${min}`}`,\n meta: { argument: name },\n });\n }\n return value;\n}\n\n// ─── IR lookups ───────────────────────────────────────────────────\n\n/** Table name of a model (`dbName ?? name`). */\nexport function tableNameOf(params: { model: ModelIR }): string {\n return params.model.dbName ?? params.model.name;\n}\n\n/** Column name of a field (`dbName ?? name`); the field must exist. */\nexport function columnNameOf(params: { model: ModelIR; field: string }): string {\n const found = params.model.fields.find((candidate) => candidate.name === params.field);\n if (found === undefined) {\n throw new VibeError({\n code: \"VIBE_INTERNAL\",\n message: `extension referenced unknown field \"${params.field}\" on model \"${params.model.name}\"`,\n meta: { model: params.model.name, field: params.field },\n });\n }\n return found.dbName ?? found.name;\n}\n\n/** The model's single primary-key field name, for key_field-style options. */\nexport function primaryKeyFieldOf(params: { model: ModelIR }): string | null {\n const { model } = params;\n if (model.primaryKey !== undefined && model.primaryKey.fields.length === 1) {\n return model.primaryKey.fields[0] ?? null;\n }\n const idField = model.fields.find((field) => field.isId);\n return idField?.name ?? null;\n}\n\n// ─── Declaration readers (ExtensionDeclIR.options are untyped JSON) ─\n\nexport function declString(decl: Readonly<Record<string, unknown>>, key: string): string | undefined {\n const value = decl[key];\n return typeof value === \"string\" ? value : undefined;\n}\n\nexport function declStringArray(\n decl: Readonly<Record<string, unknown>>,\n key: string,\n): readonly string[] | undefined {\n const value = decl[key];\n if (!Array.isArray(value)) return undefined;\n return value.every((entry): entry is string => typeof entry === \"string\") ? value : undefined;\n}\n\nexport function declNumberArray(\n decl: Readonly<Record<string, unknown>>,\n key: string,\n): readonly number[] | undefined {\n const value = decl[key];\n if (!Array.isArray(value)) return undefined;\n return value.every((entry): entry is number => typeof entry === \"number\") ? value : undefined;\n}\n\n// ─── Identifier safety ────────────────────────────────────────────\n\nconst SQL_LITERAL_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/**\n * Names an extension splices as SQL LITERALS (regconfig names, key_field\n * options) must be plain identifiers — everything else is rejected at parse\n * time so no schema-borne text ever reaches SQL unquoted.\n */\nexport function isSafeSqlName(params: { name: string }): boolean {\n return SQL_LITERAL_NAME.test(params.name);\n}\n\n// ─── Doctor helpers ───────────────────────────────────────────────\n\n/** Availability of a postgres extension, per pg_available_extensions. */\nexport async function pgExtensionCheck(params: {\n execute: ExtensionSqlExecutor;\n name: string;\n}): Promise<ExtensionDoctorCheck> {\n const { execute, name } = params;\n try {\n const rows = await execute({\n text: \"SELECT name, default_version, installed_version FROM pg_available_extensions WHERE name = $1\",\n values: [name],\n });\n const row = rows[0];\n if (row === undefined) {\n return { name: `extension ${name}`, ok: false, note: \"not available on this server\" };\n }\n const installed = row[\"installed_version\"];\n return {\n name: `extension ${name}`,\n ok: true,\n note: installed === null || installed === undefined ? \"available, not installed\" : `installed ${String(installed)}`,\n };\n } catch (error) {\n return {\n name: `extension ${name}`,\n ok: false,\n note: `check failed: ${error instanceof Error ? error.message : String(error)}`,\n };\n }\n}\n"
|
|
5
|
+
"/**\n * `trgm` — pg_trgm fuzzy matching (extensions.md §6). Operators-only: it\n * claims NO client surface. `where: { name: { similarTo: \"jon\" } }` compiles\n * to a bound predicate plus `gin_trgm_ops` indexes over the fields declared\n * in `@@trgm([...])`. Postgres/pglite only; anywhere else →\n * VIBE_UNSUPPORTED_CAPABILITY.\n *\n * INDEXABILITY (SQL review M8 + PG-1): a bare `similarity(col, $q) >= $t` is\n * a guaranteed full scan — GIN/GiST trigram indexes serve the `%` operator,\n * not the function. The predicate compiles as\n * `(col % $q AND similarity(col, $q) >= $t)` only when the effective\n * threshold is ≥ max(configured threshold, 0.3): `%` prunes at the\n * CONNECTION's `pg_trgm.similarity_threshold`, and pooled connections that\n * `onConnect` never touched keep the server default 0.3 — so the gate floor\n * must assume 0.3 even when a lower threshold was configured. Below the\n * floor, the predicate falls back to the full-scan form — correct on every\n * connection. A postgresql.conf value raised ABOVE the floor can still\n * prune; the doctor's similarity_threshold check surfaces it.\n */\n\nimport { VibeError, defineExtension, fitDefaultName, unsupportedCapability } from \"@vibeorm/schema\";\nimport type {\n ExtensionArtifact,\n ExtensionSchemaContext,\n VibeExtension,\n} from \"@vibeorm/schema\";\nimport { getSqlDialect } from \"@vibeorm/sql\";\nimport { extensionSqlName, columnNameOf, declStringArray, pgExtensionCheck, tableNameOf } from \"../shared.ts\";\n\n// ─── Options ──────────────────────────────────────────────────────\n\nexport type TrgmOptions = {\n /**\n * Similarity threshold for `similarTo` (default 0.3). Also applied to the\n * session's `pg_trgm.similarity_threshold` on `$connect()` so raw `%`\n * queries agree with the operator.\n */\n readonly threshold?: number;\n};\n\n/** Operand of `similarTo`: the text, or text plus a per-use threshold. */\nexport type SimilarToOperand = string | { readonly text: string; readonly threshold?: number };\n\nconst DEFAULT_THRESHOLD = 0.3;\nconst VERSION = \"2.0.0-alpha.0\";\n\nfunction validThreshold(value: unknown): value is number {\n return typeof value === \"number\" && Number.isFinite(value) && value >= 0 && value <= 1;\n}\n\n// ─── Artifacts ────────────────────────────────────────────────────\n\nfunction trgmArtifacts(ctx: ExtensionSchemaContext): readonly ExtensionArtifact[] {\n if (ctx.dialect !== \"postgres\") {\n throw unsupportedCapability({\n dialect: ctx.dialect,\n feature: \"the trgm extension (pg_trgm)\",\n hint: \"pg_trgm exists on postgres/pglite only\",\n });\n }\n const dialect = getSqlDialect({ dialect: ctx.dialect });\n const quote = (name: string): string => dialect.quoteIdent({ name });\n\n const artifacts: ExtensionArtifact[] = [\n {\n id: \"trgm:extension\",\n owns: { kind: \"postgresExtension\", name: \"pg_trgm\" },\n create: [\"CREATE EXTENSION IF NOT EXISTS pg_trgm;\"],\n drop: [\"DROP EXTENSION IF EXISTS pg_trgm;\"],\n },\n ];\n\n for (const [modelName, declaration] of Object.entries(ctx.declarations)) {\n const model = ctx.schema.models.find((candidate) => candidate.name === modelName);\n if (model === undefined) continue;\n const table = tableNameOf({ model });\n for (const field of declStringArray(declaration, \"fields\") ?? []) {\n const column = columnNameOf({ model, field });\n const indexName = fitDefaultName({ prefix: `${table}_${column}_trgm`, suffix: \"_idx\", dialect: ctx.dialect });\n artifacts.push({\n id: `trgm:${modelName}:${field}`,\n owns: { kind: \"index\", table, name: indexName },\n create: [\n `CREATE INDEX IF NOT EXISTS ${quote(indexName)} ON ${extensionSqlName({ dialect, name: table })} USING gin (${quote(column)} gin_trgm_ops);`,\n ],\n drop: [`DROP INDEX IF EXISTS ${extensionSqlName({ dialect, name: indexName })};`],\n });\n }\n }\n return artifacts;\n}\n\n// ─── Factory ──────────────────────────────────────────────────────\n\n/**\n * pg_trgm fuzzy matching.\n *\n * @example vibeorm.config.ts / VibeClient\n * extensions: [trgm({ threshold: 0.3 })]\n *\n * @example schema\n * // @@trgm([name]) → gin_trgm_ops index on \"name\"\n * await db.user.findMany({ where: { name: { similarTo: \"jon\" } } });\n */\nexport function trgm(options: TrgmOptions = {}): VibeExtension {\n const threshold = options.threshold === undefined ? DEFAULT_THRESHOLD : options.threshold;\n if (!validThreshold(threshold)) {\n throw new VibeError({ code: \"VIBE_VALIDATION\", message: \"trgm threshold must be a finite number between 0 and 1\", meta: { argument: \"threshold\" } });\n }\n\n return defineExtension({\n name: \"trgm\",\n version: VERSION,\n options: { ...options },\n requires: { postgresql: { extension: \"pg_trgm\" }, pglite: { extension: \"pg_trgm\" } },\n\n schema: {\n modelAttributes: [\n {\n name: \"trgm\",\n parse: ({ args, fieldNames }) => {\n const fields = args.fields ?? [];\n if (fields.length === 0) {\n return { error: \"@@trgm requires a field list, e.g. @@trgm([name])\" };\n }\n const missing = fields.find((name) => !fieldNames.includes(name));\n if (missing !== undefined) {\n return { error: `@@trgm references unknown field \"${missing}\"` };\n }\n return { declaration: { fields } };\n },\n },\n ],\n indexKinds: [\"gin_trgm\"],\n },\n\n migrate: { artifacts: trgmArtifacts },\n\n sql: {\n whereOperators: [\n {\n name: \"similarTo\",\n compile: ({ column, operand, dialect, options: extOptions }) => {\n if (dialect !== \"postgres\") {\n throw unsupportedCapability({\n dialect,\n feature: 'the \"similarTo\" operator (pg_trgm)',\n hint: \"pg_trgm exists on postgres/pglite only\",\n });\n }\n const text =\n typeof operand === \"string\"\n ? operand\n : typeof operand === \"object\" && operand !== null && \"text\" in operand\n ? (operand as { text: unknown }).text\n : undefined;\n if (typeof text !== \"string\") {\n return { error: 'expects a string or { text, threshold? }' };\n }\n const perUse =\n typeof operand === \"object\" && operand !== null && \"threshold\" in operand\n ? (operand as { threshold: unknown }).threshold\n : undefined;\n const configured = extOptions[\"threshold\"];\n if ((configured !== undefined && !validThreshold(configured)) || (perUse !== undefined && !validThreshold(perUse))) {\n return { error: \"threshold must be a finite number between 0 and 1\" };\n }\n const sessionThreshold = typeof configured === \"number\" ? configured : DEFAULT_THRESHOLD;\n const effective = typeof perUse === \"number\" ? perUse : sessionThreshold;\n // PG-1 (SQL review round 2): `%` prunes at the CONNECTION's\n // pg_trgm.similarity_threshold. onConnect SETs the configured\n // value only on connections `$connect` touches — POOLED\n // connections keep the server default 0.3 (live-proven dropped\n // rows: configured 0.2, similarity 0.273, `%` pruned at 0.3).\n // Gate the index route on effective >= max(configured, 0.3): a\n // connection whose actual GUC is LOWER than effective only widens\n // the prefilter (safe). A postgresql.conf value RAISED above the\n // effective threshold can still prune — the doctor's\n // similarity_threshold check surfaces exactly that (documented in\n // docs/dialect-notes.md).\n if (effective >= Math.max(sessionThreshold, DEFAULT_THRESHOLD)) {\n // M8: `%` walks the gin_trgm_ops index; similarity() enforces\n // the exact bound.\n return {\n fragment: {\n parts: [\n \"(\",\n { ident: column },\n \" % \",\n { param: text },\n \" AND similarity(\",\n { ident: column },\n \", \",\n { param: text },\n \") >= \",\n { param: effective },\n \")\",\n ],\n },\n };\n }\n // Effective threshold below the `%` gate floor (max(configured,\n // 0.3)): on a pooled connection the GUC may still be 0.3, so `%`\n // would prune matches the caller asked for — honest full scan.\n return {\n fragment: {\n parts: [\n \"similarity(\",\n { ident: column },\n \", \",\n { param: text },\n \") >= \",\n { param: effective },\n ],\n },\n };\n },\n },\n ],\n },\n\n runtime: {\n onConnect: async ({ execute, dialect, options: extOptions }) => {\n // Session default for raw `%` queries; the operator itself never\n // depends on it. Only meaningful when explicitly configured.\n if (dialect !== \"postgres\" || typeof extOptions[\"threshold\"] !== \"number\") return;\n await execute({\n text: `SET pg_trgm.similarity_threshold = ${Number(threshold)}`,\n });\n },\n },\n\n doctor: async ({ execute, dialect }) => {\n if (dialect !== \"postgres\") {\n return { checks: [{ name: \"trgm dialect\", ok: false, note: \"postgres/pglite only\" }] };\n }\n const checks = [await pgExtensionCheck({ execute, name: \"pg_trgm\" })];\n // PG-1: the `%` route assumes the connection's GUC is ≤ the gate floor\n // (max(configured, 0.3)). A postgresql.conf value raised ABOVE it makes\n // `%` prune rows the similarity() bound would keep — surface it here.\n // current_setting(…, true) returns NULL instead of ERRORING when the\n // pg_trgm library is not session-loaded yet (SHOW errors there — a\n // false alarm on healthy setups, closure item 3); NULL means no value\n // is configured anywhere, so the 0.3 default (≤ floor) applies.\n const floor = Math.max(threshold, DEFAULT_THRESHOLD);\n try {\n const rows = await execute({\n text: `SELECT current_setting('pg_trgm.similarity_threshold', true) AS \"threshold\"`,\n });\n const raw = rows[0]?.[\"threshold\"];\n if (raw === undefined || raw === null || raw === \"\") {\n checks.push({\n name: \"trgm similarity_threshold\",\n ok: true,\n note: `not set in this session — the 0.3 default applies (≤ gate floor ${floor})`,\n });\n return { checks };\n }\n const server = Number(raw);\n checks.push(\n Number.isNaN(server)\n ? { name: \"trgm similarity_threshold\", ok: false, note: \"could not read pg_trgm.similarity_threshold\" }\n : server <= floor\n ? { name: \"trgm similarity_threshold\", ok: true, note: `server ${server} ≤ gate floor ${floor}` }\n : {\n name: \"trgm similarity_threshold\",\n ok: false,\n note: `server pg_trgm.similarity_threshold=${server} exceeds the %-gate floor ${floor} — indexed similarTo queries can drop rows; lower the GUC or raise the extension threshold`,\n },\n );\n } catch {\n checks.push({\n name: \"trgm similarity_threshold\",\n ok: false,\n note: \"reading pg_trgm.similarity_threshold failed\",\n });\n }\n return { checks };\n },\n });\n}\n",
|
|
6
|
+
"/**\n * Helpers shared by the tier-1 extensions. Nothing here is privileged —\n * userland extensions can do everything these do with the same public hooks.\n */\n\nimport { VibeError, assertExtensionModelPlacement, qualifiedSqlName } from \"@vibeorm/schema\";\nimport type {\n ExtensionDoctorCheck,\n ExtensionSqlExecutor,\n ModelIR,\n} from \"@vibeorm/schema\";\n\nimport type { SqlDialect } from \"@vibeorm/sql\";\n\n/** Quote a built-in's physical target; PostgreSQL ownership is always public. */\nexport function extensionSqlName(params: { dialect: SqlDialect; name: string }): string {\n const { dialect, name } = params;\n const physical = qualifiedSqlName({ name });\n return dialect.name === \"postgres\"\n ? `${dialect.quoteIdent({ name: physical.namespace })}.${dialect.quoteIdent({ name: physical.name })}`\n : dialect.quoteIdent({ name });\n}\n\n// ─── Numeric admission ────────────────────────────────────────────\n\n/** Refuse non-finite extension arguments before compilation or execution. */\nexport function finiteNumber(params: { value: unknown; name: string; integer?: boolean; min?: number }): number {\n const { value, name, integer, min } = params;\n if (typeof value !== \"number\" || !Number.isFinite(value) ||\n (integer === true && !Number.isSafeInteger(value)) || (min !== undefined && value < min)) {\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `${name} must be a finite ${integer === true ? \"safe integer\" : \"number\"}${min === undefined ? \"\" : ` >= ${min}`}`,\n meta: { argument: name },\n });\n }\n return value;\n}\n\n// ─── IR lookups ───────────────────────────────────────────────────\n\n/** Table name of a model (`dbName ?? name`). */\nexport function tableNameOf(params: { model: ModelIR }): string {\n assertExtensionModelPlacement({ namespace: params.model.namespace });\n return params.model.dbName ?? params.model.name;\n}\n\n/** Column name of a field (`dbName ?? name`); the field must exist. */\nexport function columnNameOf(params: { model: ModelIR; field: string }): string {\n const found = params.model.fields.find((candidate) => candidate.name === params.field);\n if (found === undefined) {\n throw new VibeError({\n code: \"VIBE_INTERNAL\",\n message: `extension referenced unknown field \"${params.field}\" on model \"${params.model.name}\"`,\n meta: { model: params.model.name, field: params.field },\n });\n }\n return found.dbName ?? found.name;\n}\n\n/** The model's single primary-key field name, for key_field-style options. */\nexport function primaryKeyFieldOf(params: { model: ModelIR }): string | null {\n const { model } = params;\n if (model.primaryKey !== undefined && model.primaryKey.fields.length === 1) {\n return model.primaryKey.fields[0] ?? null;\n }\n const idField = model.fields.find((field) => field.isId);\n return idField?.name ?? null;\n}\n\n// ─── Declaration readers (ExtensionDeclIR.options are untyped JSON) ─\n\nexport function declString(decl: Readonly<Record<string, unknown>>, key: string): string | undefined {\n const value = decl[key];\n return typeof value === \"string\" ? value : undefined;\n}\n\nexport function declStringArray(\n decl: Readonly<Record<string, unknown>>,\n key: string,\n): readonly string[] | undefined {\n const value = decl[key];\n if (!Array.isArray(value)) return undefined;\n return value.every((entry): entry is string => typeof entry === \"string\") ? value : undefined;\n}\n\nexport function declNumberArray(\n decl: Readonly<Record<string, unknown>>,\n key: string,\n): readonly number[] | undefined {\n const value = decl[key];\n if (!Array.isArray(value)) return undefined;\n return value.every((entry): entry is number => typeof entry === \"number\") ? value : undefined;\n}\n\n// ─── Identifier safety ────────────────────────────────────────────\n\nconst SQL_LITERAL_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/**\n * Names an extension splices as SQL LITERALS (regconfig names, key_field\n * options) must be plain identifiers — everything else is rejected at parse\n * time so no schema-borne text ever reaches SQL unquoted.\n */\nexport function isSafeSqlName(params: { name: string }): boolean {\n return SQL_LITERAL_NAME.test(params.name);\n}\n\n// ─── Doctor helpers ───────────────────────────────────────────────\n\n/** Availability of a postgres extension, per pg_available_extensions. */\nexport async function pgExtensionCheck(params: {\n execute: ExtensionSqlExecutor;\n name: string;\n}): Promise<ExtensionDoctorCheck> {\n const { execute, name } = params;\n try {\n const rows = await execute({\n text: \"SELECT name, default_version, installed_version FROM pg_available_extensions WHERE name = $1\",\n values: [name],\n });\n const row = rows[0];\n if (row === undefined) {\n return { name: `extension ${name}`, ok: false, note: \"not available on this server\" };\n }\n const installed = row[\"installed_version\"];\n return {\n name: `extension ${name}`,\n ok: true,\n note: installed === null || installed === undefined ? \"available, not installed\" : `installed ${String(installed)}`,\n };\n } catch (error) {\n return {\n name: `extension ${name}`,\n ok: false,\n note: `check failed: ${error instanceof Error ? error.message : String(error)}`,\n };\n }\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";;AAoBA,sBAAS;AAMT;;;ACrBA;AAUO,SAAS,YAAY,CAAC,QAAmF;AAAA,EAC9G,QAAQ,OAAO,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AAAA,MACnD,IAAI;AAAA,QACF,MAAM,OAAO,MAAM,QAAQ;AAAA,UACzB,MAAM;AAAA,QACR,CAAC;AAAA,QACD,MAAM,MAAM,KAAK,KAAK;AAAA,QACtB,IAAI,QAAQ,aAAa,QAAQ,QAAQ,QAAQ,IAAI;AAAA,UACnD,OAAO,KAAK;AAAA,YACV,MAAM;AAAA,YACN,IAAI;AAAA,YACJ,MAAM,6EAAmE;AAAA,UAC3E,CAAC;AAAA,UACD,OAAO,EAAE,OAAO;AAAA,QAClB;AAAA,QACA,MAAM,SAAS,OAAO,GAAG;AAAA,QACzB,OAAO,KACL,OAAO,MAAM,MAAM,IACf,EAAE,MAAM,6BAA6B,IAAI,OAAO,MAAM,8CAA8C,IACpG,UAAU,QACR,EAAE,MAAM,6BAA6B,IAAI,MAAM,MAAM,UAAU,4BAAuB,QAAQ,IAC9F;AAAA,UACE,MAAM;AAAA,UACN,IAAI;AAAA,UACJ,MAAM,uCAAuC,mCAAmC;AAAA,QAClF,CACR;AAAA,QACA,MAAM;AAAA,QACN,OAAO,KAAK;AAAA,UACV,MAAM;AAAA,UACN,IAAI;AAAA,UACJ,MAAM;AAAA,QACR,CAAC;AAAA;AAAA,MAEH,OAAO,EAAE,OAAO;AAAA;AAAA,EAEpB,CAAC;AAAA;",
|
|
9
|
+
"debugId": "B6DB83AEA289F10C64756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/dist/vector/index.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/extensions/src/vector/index.ts
|
|
3
|
-
import { VibeError as VibeError2, assertIdentifierFits, defineExtension, fitDefaultName, unsupportedCapability } from "@vibeorm/schema";
|
|
3
|
+
import { VibeError as VibeError2, assertExtensionModelPlacement as assertExtensionModelPlacement2, assertIdentifierFits, defineExtension, fitDefaultName, unsupportedCapability } from "@vibeorm/schema";
|
|
4
4
|
import { ParamCollector, getSqlDialect, renderExpr } from "@vibeorm/sql";
|
|
5
5
|
|
|
6
6
|
// packages/extensions/src/shared.ts
|
|
7
|
-
import { VibeError } from "@vibeorm/schema";
|
|
7
|
+
import { VibeError, assertExtensionModelPlacement, qualifiedSqlName } from "@vibeorm/schema";
|
|
8
|
+
function extensionSqlName(params) {
|
|
9
|
+
const { dialect, name } = params;
|
|
10
|
+
const physical = qualifiedSqlName({ name });
|
|
11
|
+
return dialect.name === "postgres" ? `${dialect.quoteIdent({ name: physical.namespace })}.${dialect.quoteIdent({ name: physical.name })}` : dialect.quoteIdent({ name });
|
|
12
|
+
}
|
|
8
13
|
function finiteNumber(params) {
|
|
9
14
|
const { value, name, integer, min } = params;
|
|
10
15
|
if (typeof value !== "number" || !Number.isFinite(value) || integer === true && !Number.isSafeInteger(value) || min !== undefined && value < min) {
|
|
@@ -17,6 +22,7 @@ function finiteNumber(params) {
|
|
|
17
22
|
return value;
|
|
18
23
|
}
|
|
19
24
|
function tableNameOf(params) {
|
|
25
|
+
assertExtensionModelPlacement({ namespace: params.model.namespace });
|
|
20
26
|
return params.model.dbName ?? params.model.name;
|
|
21
27
|
}
|
|
22
28
|
function columnNameOf(params) {
|
|
@@ -196,9 +202,9 @@ function vectorArtifacts(ctx) {
|
|
|
196
202
|
id: `vector:${modelName}:${field}`,
|
|
197
203
|
owns: { kind: "index", table, name: indexName },
|
|
198
204
|
create: [
|
|
199
|
-
`CREATE INDEX IF NOT EXISTS ${quote(indexName)} ON ${
|
|
205
|
+
`CREATE INDEX IF NOT EXISTS ${quote(indexName)} ON ${extensionSqlName({ dialect, name: table })} USING ${kindRaw} (${quote(column)} ${METRIC_OPCLASS[metric]})${withClause};`
|
|
200
206
|
],
|
|
201
|
-
drop: [`DROP INDEX IF EXISTS ${
|
|
207
|
+
drop: [`DROP INDEX IF EXISTS ${extensionSqlName({ dialect, name: indexName })};`]
|
|
202
208
|
});
|
|
203
209
|
}
|
|
204
210
|
}
|
|
@@ -232,6 +238,8 @@ function resolveColumn(params) {
|
|
|
232
238
|
}
|
|
233
239
|
function createVectorNamespace(config) {
|
|
234
240
|
return (ctx) => {
|
|
241
|
+
if (ctx.model !== null)
|
|
242
|
+
assertExtensionModelPlacement2({ namespace: ctx.model.namespace, dialect: ctx.dialect.name });
|
|
235
243
|
const dialect = ctx.dialect;
|
|
236
244
|
const quote = (name) => dialect.quoteIdent({ name });
|
|
237
245
|
const t = quote("t");
|
|
@@ -247,7 +255,7 @@ function createVectorNamespace(config) {
|
|
|
247
255
|
const collector = new ParamCollector(dialect);
|
|
248
256
|
const vector = dialect.name === "postgres" ? collector.add(literal) : undefined;
|
|
249
257
|
let text = `SELECT ${ctx.projection({ qualify: "t" })}, (${col} ${op} ${vector ?? collector.add(literal)}) AS ${quote(DISTANCE_ALIAS)}`;
|
|
250
|
-
text += ` FROM ${
|
|
258
|
+
text += ` FROM ${extensionSqlName({ dialect, name: config.table })} AS ${t}`;
|
|
251
259
|
text += ` WHERE ${col} IS NOT NULL`;
|
|
252
260
|
if (args.where !== undefined) {
|
|
253
261
|
const expr = ctx.compileWhere({ where: args.where, qualify: "t" });
|
|
@@ -271,7 +279,7 @@ function createVectorNamespace(config) {
|
|
|
271
279
|
set: async (args) => {
|
|
272
280
|
const { column, literal } = resolveColumn({ config, args });
|
|
273
281
|
const collector = new ParamCollector(dialect);
|
|
274
|
-
let text = `UPDATE ${
|
|
282
|
+
let text = `UPDATE ${extensionSqlName({ dialect, name: config.table })} SET ${quote(column)} = ${collector.add(literal)}`;
|
|
275
283
|
const expr = ctx.compileWhere({ where: args.where });
|
|
276
284
|
if (expr !== undefined)
|
|
277
285
|
text += ` WHERE ${renderExpr({ dialect, expr, collector })}`;
|
|
@@ -334,7 +342,7 @@ function vector(options = {}) {
|
|
|
334
342
|
}
|
|
335
343
|
if (fields.length !== 1) {
|
|
336
344
|
return {
|
|
337
|
-
error: `indexName needs exactly one indexed field \u2014
|
|
345
|
+
error: `indexName needs exactly one indexed field \u2014 one named index declaration per model is supported`
|
|
338
346
|
};
|
|
339
347
|
}
|
|
340
348
|
}
|
|
@@ -408,4 +416,4 @@ export {
|
|
|
408
416
|
vector
|
|
409
417
|
};
|
|
410
418
|
|
|
411
|
-
//# debugId=
|
|
419
|
+
//# debugId=ACE40E01F62FF63964756E2164756E21
|
package/dist/vector/index.js.map
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/vector/index.ts", "../src/shared.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * `vector` — pgvector similarity search (extensions.md §5).\n *\n * Schema: `embedding Vector(1536)` (field type) + `@@vector([embedding],\n * metric: \"cosine\", index: \"hnsw\")` (index declaration). Client surface is a\n * namespace (D9): `db.doc.vector.nearest({ by, to, take })` and\n * `db.doc.vector.set({ where, by, to })`. Postgres AND pglite (on pglite’s\n * current 0.5 line pgvector loads from @electric-sql/pglite-pgvector — the\n * 0.3 line bundled it as @electric-sql/pglite/vector); sqlite/mysql →\n * VIBE_UNSUPPORTED_CAPABILITY at generate time.\n */\n\nimport { VibeError, assertIdentifierFits, defineExtension, fitDefaultName, unsupportedCapability } from \"@vibeorm/schema\";\nimport type {\n ExtensionArtifact,\n ExtensionSchemaContext,\n VibeExtension,\n} from \"@vibeorm/schema\";\nimport { ParamCollector, getSqlDialect, renderExpr } from \"@vibeorm/sql\";\nimport type { ExtensionMountContext } from \"@vibeorm/runtime\";\nimport {\n finiteNumber,\n columnNameOf,\n declString,\n declStringArray,\n isSafeSqlName,\n pgExtensionCheck,\n primaryKeyFieldOf,\n tableNameOf,\n} from \"../shared.ts\";\n\n// ─── Options & types ──────────────────────────────────────────────\n\nexport type VectorOptions = Record<string, never>;\n\nexport type VectorMetric = \"cosine\" | \"l2\" | \"ip\";\n\n/** One nearest-neighbour hit. */\nexport type VectorHit<T> = {\n readonly row: T;\n /** Distance under the query's metric — smaller is closer (ip is negated inner product). */\n readonly distance: number;\n};\n\nconst VERSION = \"2.0.0-alpha.0\";\n\nconst METRIC_OPERATOR: Readonly<Record<VectorMetric, string>> = {\n cosine: \"<=>\",\n l2: \"<->\",\n ip: \"<#>\",\n};\n\nconst METRIC_OPCLASS: Readonly<Record<VectorMetric, string>> = {\n cosine: \"vector_cosine_ops\",\n l2: \"vector_l2_ops\",\n ip: \"vector_ip_ops\",\n};\n\nconst METRICS: readonly VectorMetric[] = [\"cosine\", \"l2\", \"ip\"];\nconst INDEX_KINDS: readonly string[] = [\"hnsw\", \"ivfflat\"];\nconst DISTANCE_ALIAS = \"_vibe_distance\";\n\n// pgvector v0.8.2 src/hnsw.h and src/ivfflat.h reloption bounds.\nconst INDEX_BOUNDS: Readonly<Record<string, readonly [number, number]>> = {\n m: [2, 100],\n efConstruction: [4, 1000],\n lists: [1, 32768],\n};\n\nfunction indexOptionError(params: { declaration: Readonly<Record<string, unknown>> }): string | undefined {\n for (const [key, [min, max]] of Object.entries(INDEX_BOUNDS)) {\n const value = params.declaration[key];\n if (value !== undefined && (typeof value !== \"number\" || !Number.isInteger(value) || value < min || value > max)) {\n return `${key} must be an integer between ${min} and ${max}`;\n }\n }\n return undefined;\n}\n\n// ─── Declaration helpers ──────────────────────────────────────────\n\ntype VectorColumnDecl = { readonly column: string; readonly dims: number };\n\nfunction vectorColumnsOf(params: {\n declaration: Readonly<Record<string, unknown>>;\n}): Readonly<Record<string, { readonly dims: number }>> {\n const columns = params.declaration[\"columns\"];\n if (columns === null || typeof columns !== \"object\" || Array.isArray(columns)) return {};\n const out: Record<string, { dims: number }> = {};\n for (const [field, spec] of Object.entries(columns as Record<string, unknown>)) {\n if (spec === null || typeof spec !== \"object\") continue;\n const dims = (spec as { dims?: unknown }).dims;\n if (typeof dims === \"number\") out[field] = { dims };\n }\n return out;\n}\n\n// ─── Artifacts ────────────────────────────────────────────────────\n\nfunction vectorArtifacts(ctx: ExtensionSchemaContext): readonly ExtensionArtifact[] {\n if (ctx.dialect !== \"postgres\") {\n throw unsupportedCapability({\n dialect: ctx.dialect,\n feature: \"the vector extension (pgvector)\",\n hint: \"pgvector exists on postgres/pglite only (sqlite-vec/mysql are post-2.0)\",\n });\n }\n const dialect = getSqlDialect({ dialect: ctx.dialect });\n const quote = (name: string): string => dialect.quoteIdent({ name });\n\n const artifacts: ExtensionArtifact[] = [\n {\n id: \"vector:extension\",\n owns: { kind: \"postgresExtension\", name: \"vector\" },\n create: [\"CREATE EXTENSION IF NOT EXISTS vector;\"],\n drop: [\"DROP EXTENSION IF EXISTS vector;\"],\n },\n ];\n\n for (const [modelName, declaration] of Object.entries(ctx.declarations)) {\n const model = ctx.schema.models.find((candidate) => candidate.name === modelName);\n if (model === undefined) continue;\n const invalidOption = indexOptionError({ declaration });\n if (invalidOption !== undefined) {\n throw new VibeError({ code: \"VIBE_SCHEMA_INVALID\", message: invalidOption, meta: { model: modelName } });\n }\n const table = tableNameOf({ model });\n const columns = vectorColumnsOf({ declaration });\n\n const indexFields = declStringArray(declaration, \"fields\") ?? [];\n const kindRaw = declString(declaration, \"index\") ?? \"hnsw\";\n // The parse-time attribute validation is the usual gate; a declaration\n // assembled by hand (a DSL extension declaration, a hand-written IR) must\n // not reach `USING <anything>` — the kind is spliced into DDL.\n if (!INDEX_KINDS.includes(kindRaw)) {\n throw new VibeError({\n code: \"VIBE_SCHEMA_INVALID\",\n message: `@@vector on \"${modelName}\" declares index kind \"${kindRaw}\" — expected one of ${INDEX_KINDS.join(\", \")}`,\n meta: { model: modelName, index: kindRaw },\n });\n }\n const metricRaw = declString(declaration, \"metric\") ?? \"cosine\";\n const metric = METRICS.find((candidate) => candidate === metricRaw) ?? \"cosine\";\n\n for (const field of indexFields) {\n if (columns[field] === undefined) {\n throw new VibeError({\n code: \"VIBE_SCHEMA_INVALID\",\n message: `@@vector on \"${modelName}\" indexes \"${field}\", which is not a Vector(n) column`,\n meta: { model: modelName, field },\n });\n }\n const column = columnNameOf({ model, field });\n // Adoption override (validated single-field-only at parse): consumers\n // with a live index keep its name instead of a rename migration.\n const nameOverride = indexFields.length === 1 ? declString(declaration, \"indexName\") : undefined;\n // Same identifier-limit rule as every minted index name: a truncated\n // name would miss migrate's ownership handshake and be rebuilt (HNSW!)\n // on every push.\n if (nameOverride !== undefined) assertIdentifierFits({ name: nameOverride, dialect: ctx.dialect, what: \"@@vector indexName\", remedy: \"Shorten it.\" });\n const indexName = nameOverride ?? fitDefaultName({ prefix: `${table}_${column}_${kindRaw}`, suffix: \"_idx\", dialect: ctx.dialect });\n const withOptions: string[] = [];\n const m = declaration[\"m\"];\n const efConstruction = declaration[\"efConstruction\"];\n const lists = declaration[\"lists\"];\n if (kindRaw === \"hnsw\") {\n if (typeof m === \"number\") withOptions.push(`m = ${m}`);\n if (typeof efConstruction === \"number\") withOptions.push(`ef_construction = ${efConstruction}`);\n } else if (typeof lists === \"number\") {\n withOptions.push(`lists = ${lists}`);\n }\n const withClause = withOptions.length === 0 ? \"\" : ` WITH (${withOptions.join(\", \")})`;\n artifacts.push({\n id: `vector:${modelName}:${field}`,\n owns: { kind: \"index\", table, name: indexName },\n create: [\n `CREATE INDEX IF NOT EXISTS ${quote(indexName)} ON ${quote(table)} USING ${kindRaw} (${quote(column)} ${METRIC_OPCLASS[metric]})${withClause};`,\n ],\n drop: [`DROP INDEX IF EXISTS ${quote(indexName)};`],\n });\n }\n }\n return artifacts;\n}\n\n// ─── Runtime namespace (generated-glue target) ────────────────────\n\n/** Baked per-model config the generator writes into the client. */\nexport type VectorNamespaceConfig = {\n readonly table: string;\n /** Field name → column + dims. */\n readonly columns: Readonly<Record<string, VectorColumnDecl>>;\n /** Default metric from the schema declaration. */\n readonly metric: VectorMetric;\n};\n\nexport type VectorNearestArgs = {\n readonly by: string;\n readonly to: readonly number[];\n readonly metric?: VectorMetric;\n readonly take?: number;\n readonly where?: Record<string, unknown>;\n readonly maxDistance?: number;\n};\n\nexport type VectorSetArgs = {\n readonly where: Record<string, unknown>;\n readonly by: string;\n readonly to: readonly number[];\n};\n\nexport type VectorNamespace = {\n readonly nearest: (args: VectorNearestArgs) => Promise<VectorHit<Record<string, unknown>>[]>;\n readonly set: (args: VectorSetArgs) => Promise<number>;\n};\n\nfunction resolveColumn(params: {\n config: VectorNamespaceConfig;\n args: { by: string; to: readonly number[] };\n}): { column: string; literal: string } {\n const { config, args } = params;\n const spec = config.columns[args.by];\n if (spec === undefined) {\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `\"${args.by}\" is not a Vector(n) column — declared: ${Object.keys(config.columns).join(\", \")}`,\n meta: { by: args.by },\n });\n }\n if (!Array.isArray(args.to) || args.to.some((entry) => typeof entry !== \"number\" || !Number.isFinite(entry))) {\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `vector \"to\" must be an array of finite numbers`,\n meta: { by: args.by },\n });\n }\n if (args.to.length !== spec.dims) {\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `vector \"to\" has ${args.to.length} dimensions, \"${args.by}\" expects ${spec.dims}`,\n meta: { by: args.by, dims: spec.dims },\n });\n }\n return { column: spec.column, literal: `[${args.to.join(\",\")}]` };\n}\n\n/**\n * The generated client's glue target: bakes per-model config at generate time,\n * mounts as the `vector` namespace at runtime (D9).\n */\nexport function createVectorNamespace(\n config: VectorNamespaceConfig,\n): (ctx: ExtensionMountContext) => VectorNamespace {\n return (ctx: ExtensionMountContext): VectorNamespace => {\n const dialect = ctx.dialect;\n const quote = (name: string): string => dialect.quoteIdent({ name });\n const t = quote(\"t\");\n\n return {\n nearest: async (args: VectorNearestArgs): Promise<VectorHit<Record<string, unknown>>[]> => {\n const take = finiteNumber({ value: args.take === undefined ? 10 : args.take, name: \"take\", integer: true, min: 1 });\n if (args.maxDistance !== undefined) finiteNumber({ value: args.maxDistance, name: \"maxDistance\" });\n const { column, literal } = resolveColumn({ config, args });\n const metric = args.metric ?? config.metric;\n const op = METRIC_OPERATOR[metric];\n const col = `${t}.${quote(column)}`;\n const collector = new ParamCollector(dialect);\n const vector = dialect.name === \"postgres\" ? collector.add(literal) : undefined;\n\n let text = `SELECT ${ctx.projection({ qualify: \"t\" })}, (${col} ${op} ${vector ?? collector.add(literal)}) AS ${quote(DISTANCE_ALIAS)}`;\n text += ` FROM ${quote(config.table)} AS ${t}`;\n text += ` WHERE ${col} IS NOT NULL`;\n if (args.where !== undefined) {\n const expr = ctx.compileWhere({ where: args.where, qualify: \"t\" });\n if (expr !== undefined) text += ` AND (${renderExpr({ dialect, expr, collector })})`;\n }\n if (args.maxDistance !== undefined) {\n text += ` AND (${col} ${op} ${vector ?? collector.add(literal)}) < ${collector.add(args.maxDistance)}`;\n }\n text += ` ORDER BY ${col} ${op} ${vector ?? collector.add(literal)} LIMIT ${take}`;\n\n const rows = await ctx.executeRows({\n text,\n values: collector.values,\n method: \"vector.nearest\",\n });\n return rows.map((row) => {\n const { [DISTANCE_ALIAS]: distance, ...rest } = row;\n return { row: rest, distance: Number(distance) };\n });\n },\n\n set: async (args: VectorSetArgs): Promise<number> => {\n const { column, literal } = resolveColumn({ config, args });\n const collector = new ParamCollector(dialect);\n let text = `UPDATE ${quote(config.table)} SET ${quote(column)} = ${collector.add(literal)}`;\n const expr = ctx.compileWhere({ where: args.where });\n if (expr !== undefined) text += ` WHERE ${renderExpr({ dialect, expr, collector })}`;\n text += ` RETURNING 1 AS ${quote(\"_vibe_set\")}`;\n const rows = await ctx.executeRows({ text, values: collector.values, method: \"vector.set\" });\n return rows.length;\n },\n };\n };\n}\n\n// ─── Factory ──────────────────────────────────────────────────────\n\n/**\n * pgvector similarity search.\n *\n * @example schema\n * // embedding Vector(1536)\n * // @@vector([embedding], metric: \"cosine\", index: \"hnsw\")\n * const near = await db.doc.vector.nearest({ by: \"embedding\", to: queryVec, take: 10 });\n */\nexport function vector(options: VectorOptions = {}): VibeExtension {\n return defineExtension({\n name: \"vector\",\n version: VERSION,\n options: { ...options },\n requires: { postgresql: { extension: \"vector\" }, pglite: { extension: \"vector\" } },\n\n schema: {\n fieldTypes: [\n {\n name: \"Vector\",\n lower: ({ field, args }) => {\n const dims = Number(args[0]);\n if (!Number.isInteger(dims) || dims <= 0) {\n return { error: \"Vector(n) requires a positive integer dimension, e.g. Vector(1536)\" };\n }\n return {\n nativeType: `vector(${dims})`,\n declaration: { columns: { [field]: { dims } } },\n };\n },\n },\n ],\n modelAttributes: [\n {\n name: \"vector\",\n parse: ({ args, fieldNames }) => {\n const fields = args.fields ?? [];\n if (fields.length === 0) {\n return { error: \"@@vector requires a field list, e.g. @@vector([embedding])\" };\n }\n const missing = fields.find((name) => !fieldNames.includes(name));\n if (missing !== undefined) {\n return { error: `@@vector references unknown field \"${missing}\"` };\n }\n const metric = args.named[\"metric\"];\n if (metric !== undefined && !METRICS.includes(metric as VectorMetric)) {\n return { error: `metric must be one of ${METRICS.join(\", \")}` };\n }\n const kind = args.named[\"index\"];\n if (kind !== undefined && !INDEX_KINDS.includes(String(kind))) {\n return { error: `index must be one of ${INDEX_KINDS.join(\", \")}` };\n }\n const invalidOption = indexOptionError({ declaration: args.named });\n if (invalidOption !== undefined) return { error: invalidOption };\n const indexName = args.named[\"indexName\"];\n if (indexName !== undefined) {\n if (typeof indexName !== \"string\" || !isSafeSqlName({ name: indexName })) {\n return { error: `indexName must be a plain identifier` };\n }\n if (fields.length !== 1) {\n return {\n error: `indexName needs exactly one indexed field — split @@vector declarations to name each index`,\n };\n }\n }\n return { declaration: { fields, ...args.named } };\n },\n },\n ],\n indexKinds: [\"hnsw\", \"ivfflat\"],\n },\n\n migrate: { artifacts: vectorArtifacts },\n\n client: {\n model: ({ model, dialect, declaration, typeNames }) => {\n const columns = vectorColumnsOf({ declaration });\n const fieldNames = Object.keys(columns);\n if (fieldNames.length === 0) return null;\n if (dialect !== \"postgres\") {\n throw unsupportedCapability({\n dialect,\n feature: `the vector extension (declared on model \"${model.name}\")`,\n hint: \"pgvector exists on postgres/pglite only\",\n });\n }\n const metricRaw = declString(declaration, \"metric\");\n const metric = METRICS.find((candidate) => candidate === metricRaw) ?? \"cosine\";\n const config: VectorNamespaceConfig = {\n table: tableNameOf({ model }),\n columns: Object.fromEntries(\n fieldNames.map((field) => [\n field,\n { column: columnNameOf({ model, field }), dims: columns[field]!.dims },\n ]),\n ),\n metric,\n };\n const byUnion = fieldNames.map((name) => JSON.stringify(name)).join(\" | \");\n return {\n kind: \"namespace\",\n // `nearest` reads; `set` issues an UPDATE, so it is NOT classified and\n // a $readOnly client neither declares nor forwards it.\n readOnly: [\"nearest\"],\n runtimeGlue: `createVectorNamespace(${JSON.stringify(config)})`,\n imports: [{ from: \"@vibeorm/extensions/vector\", names: [\"createVectorNamespace\"] }],\n dtsImports: [{ from: \"@vibeorm/extensions/vector\", names: [\"VectorHit\", \"VectorMetric\"] }],\n dts: [\n `readonly vector: {`,\n ` readonly nearest: (args: {`,\n ` readonly by: ${byUnion};`,\n ` readonly to: readonly number[];`,\n ` readonly metric?: VectorMetric;`,\n ` readonly take?: number;`,\n ` readonly where?: ${typeNames.whereInput};`,\n ` readonly maxDistance?: number;`,\n ` }) => Promise<VectorHit<${typeNames.payload}>[]>;`,\n ` readonly set: (args: {`,\n ` readonly where: ${typeNames.whereInput};`,\n ` readonly by: ${byUnion};`,\n ` readonly to: readonly number[];`,\n ` }) => Promise<number>;`,\n `};`,\n ],\n };\n },\n },\n\n doctor: async ({ execute, dialect }) => {\n if (dialect !== \"postgres\") {\n return { checks: [{ name: \"vector dialect\", ok: false, note: \"postgres/pglite only\" }] };\n }\n return { checks: [await pgExtensionCheck({ execute, name: \"vector\" })] };\n },\n });\n}\n",
|
|
6
|
-
"/**\n * Helpers shared by the tier-1 extensions. Nothing here is privileged —\n * userland extensions can do everything these do with the same public hooks.\n */\n\nimport { VibeError } from \"@vibeorm/schema\";\nimport type {\n ExtensionDoctorCheck,\n ExtensionSqlExecutor,\n ModelIR,\n} from \"@vibeorm/schema\";\n\n// ─── Numeric admission ────────────────────────────────────────────\n\n/** Refuse non-finite extension arguments before compilation or execution. */\nexport function finiteNumber(params: { value: unknown; name: string; integer?: boolean; min?: number }): number {\n const { value, name, integer, min } = params;\n if (typeof value !== \"number\" || !Number.isFinite(value) ||\n (integer === true && !Number.isSafeInteger(value)) || (min !== undefined && value < min)) {\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `${name} must be a finite ${integer === true ? \"safe integer\" : \"number\"}${min === undefined ? \"\" : ` >= ${min}`}`,\n meta: { argument: name },\n });\n }\n return value;\n}\n\n// ─── IR lookups ───────────────────────────────────────────────────\n\n/** Table name of a model (`dbName ?? name`). */\nexport function tableNameOf(params: { model: ModelIR }): string {\n return params.model.dbName ?? params.model.name;\n}\n\n/** Column name of a field (`dbName ?? name`); the field must exist. */\nexport function columnNameOf(params: { model: ModelIR; field: string }): string {\n const found = params.model.fields.find((candidate) => candidate.name === params.field);\n if (found === undefined) {\n throw new VibeError({\n code: \"VIBE_INTERNAL\",\n message: `extension referenced unknown field \"${params.field}\" on model \"${params.model.name}\"`,\n meta: { model: params.model.name, field: params.field },\n });\n }\n return found.dbName ?? found.name;\n}\n\n/** The model's single primary-key field name, for key_field-style options. */\nexport function primaryKeyFieldOf(params: { model: ModelIR }): string | null {\n const { model } = params;\n if (model.primaryKey !== undefined && model.primaryKey.fields.length === 1) {\n return model.primaryKey.fields[0] ?? null;\n }\n const idField = model.fields.find((field) => field.isId);\n return idField?.name ?? null;\n}\n\n// ─── Declaration readers (ExtensionDeclIR.options are untyped JSON) ─\n\nexport function declString(decl: Readonly<Record<string, unknown>>, key: string): string | undefined {\n const value = decl[key];\n return typeof value === \"string\" ? value : undefined;\n}\n\nexport function declStringArray(\n decl: Readonly<Record<string, unknown>>,\n key: string,\n): readonly string[] | undefined {\n const value = decl[key];\n if (!Array.isArray(value)) return undefined;\n return value.every((entry): entry is string => typeof entry === \"string\") ? value : undefined;\n}\n\nexport function declNumberArray(\n decl: Readonly<Record<string, unknown>>,\n key: string,\n): readonly number[] | undefined {\n const value = decl[key];\n if (!Array.isArray(value)) return undefined;\n return value.every((entry): entry is number => typeof entry === \"number\") ? value : undefined;\n}\n\n// ─── Identifier safety ────────────────────────────────────────────\n\nconst SQL_LITERAL_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/**\n * Names an extension splices as SQL LITERALS (regconfig names, key_field\n * options) must be plain identifiers — everything else is rejected at parse\n * time so no schema-borne text ever reaches SQL unquoted.\n */\nexport function isSafeSqlName(params: { name: string }): boolean {\n return SQL_LITERAL_NAME.test(params.name);\n}\n\n// ─── Doctor helpers ───────────────────────────────────────────────\n\n/** Availability of a postgres extension, per pg_available_extensions. */\nexport async function pgExtensionCheck(params: {\n execute: ExtensionSqlExecutor;\n name: string;\n}): Promise<ExtensionDoctorCheck> {\n const { execute, name } = params;\n try {\n const rows = await execute({\n text: \"SELECT name, default_version, installed_version FROM pg_available_extensions WHERE name = $1\",\n values: [name],\n });\n const row = rows[0];\n if (row === undefined) {\n return { name: `extension ${name}`, ok: false, note: \"not available on this server\" };\n }\n const installed = row[\"installed_version\"];\n return {\n name: `extension ${name}`,\n ok: true,\n note: installed === null || installed === undefined ? \"available, not installed\" : `installed ${String(installed)}`,\n };\n } catch (error) {\n return {\n name: `extension ${name}`,\n ok: false,\n note: `check failed: ${error instanceof Error ? error.message : String(error)}`,\n };\n }\n}\n"
|
|
5
|
+
"/**\n * `vector` — pgvector similarity search (extensions.md §5).\n *\n * Schema: `embedding Vector(1536)` (field type) + `@@vector([embedding],\n * metric: \"cosine\", index: \"hnsw\")` (index declaration). Client surface is a\n * namespace (D9): `db.doc.vector.nearest({ by, to, take })` and\n * `db.doc.vector.set({ where, by, to })`. Postgres AND pglite (on pglite’s\n * current 0.5 line pgvector loads from @electric-sql/pglite-pgvector — the\n * 0.3 line bundled it as @electric-sql/pglite/vector); sqlite/mysql →\n * VIBE_UNSUPPORTED_CAPABILITY at generate time.\n */\n\nimport { VibeError, assertExtensionModelPlacement, assertIdentifierFits, defineExtension, fitDefaultName, unsupportedCapability } from \"@vibeorm/schema\";\nimport type {\n ExtensionArtifact,\n ExtensionSchemaContext,\n VibeExtension,\n} from \"@vibeorm/schema\";\nimport { ParamCollector, getSqlDialect, renderExpr } from \"@vibeorm/sql\";\nimport type { ExtensionMountContext } from \"@vibeorm/runtime\";\nimport {\n finiteNumber,\n columnNameOf,\n declString,\n declStringArray,\n isSafeSqlName,\n pgExtensionCheck,\n primaryKeyFieldOf,\n tableNameOf,\n extensionSqlName,\n} from \"../shared.ts\";\n\n// ─── Options & types ──────────────────────────────────────────────\n\nexport type VectorOptions = Record<string, never>;\n\nexport type VectorMetric = \"cosine\" | \"l2\" | \"ip\";\n\n/** One nearest-neighbour hit. */\nexport type VectorHit<T> = {\n readonly row: T;\n /** Distance under the query's metric — smaller is closer (ip is negated inner product). */\n readonly distance: number;\n};\n\nconst VERSION = \"2.0.0-alpha.0\";\n\nconst METRIC_OPERATOR: Readonly<Record<VectorMetric, string>> = {\n cosine: \"<=>\",\n l2: \"<->\",\n ip: \"<#>\",\n};\n\nconst METRIC_OPCLASS: Readonly<Record<VectorMetric, string>> = {\n cosine: \"vector_cosine_ops\",\n l2: \"vector_l2_ops\",\n ip: \"vector_ip_ops\",\n};\n\nconst METRICS: readonly VectorMetric[] = [\"cosine\", \"l2\", \"ip\"];\nconst INDEX_KINDS: readonly string[] = [\"hnsw\", \"ivfflat\"];\nconst DISTANCE_ALIAS = \"_vibe_distance\";\n\n// pgvector v0.8.2 src/hnsw.h and src/ivfflat.h reloption bounds.\nconst INDEX_BOUNDS: Readonly<Record<string, readonly [number, number]>> = {\n m: [2, 100],\n efConstruction: [4, 1000],\n lists: [1, 32768],\n};\n\nfunction indexOptionError(params: { declaration: Readonly<Record<string, unknown>> }): string | undefined {\n for (const [key, [min, max]] of Object.entries(INDEX_BOUNDS)) {\n const value = params.declaration[key];\n if (value !== undefined && (typeof value !== \"number\" || !Number.isInteger(value) || value < min || value > max)) {\n return `${key} must be an integer between ${min} and ${max}`;\n }\n }\n return undefined;\n}\n\n// ─── Declaration helpers ──────────────────────────────────────────\n\ntype VectorColumnDecl = { readonly column: string; readonly dims: number };\n\nfunction vectorColumnsOf(params: {\n declaration: Readonly<Record<string, unknown>>;\n}): Readonly<Record<string, { readonly dims: number }>> {\n const columns = params.declaration[\"columns\"];\n if (columns === null || typeof columns !== \"object\" || Array.isArray(columns)) return {};\n const out: Record<string, { dims: number }> = {};\n for (const [field, spec] of Object.entries(columns as Record<string, unknown>)) {\n if (spec === null || typeof spec !== \"object\") continue;\n const dims = (spec as { dims?: unknown }).dims;\n if (typeof dims === \"number\") out[field] = { dims };\n }\n return out;\n}\n\n// ─── Artifacts ────────────────────────────────────────────────────\n\nfunction vectorArtifacts(ctx: ExtensionSchemaContext): readonly ExtensionArtifact[] {\n if (ctx.dialect !== \"postgres\") {\n throw unsupportedCapability({\n dialect: ctx.dialect,\n feature: \"the vector extension (pgvector)\",\n hint: \"pgvector exists on postgres/pglite only (sqlite-vec/mysql are post-2.0)\",\n });\n }\n const dialect = getSqlDialect({ dialect: ctx.dialect });\n const quote = (name: string): string => dialect.quoteIdent({ name });\n\n const artifacts: ExtensionArtifact[] = [\n {\n id: \"vector:extension\",\n owns: { kind: \"postgresExtension\", name: \"vector\" },\n create: [\"CREATE EXTENSION IF NOT EXISTS vector;\"],\n drop: [\"DROP EXTENSION IF EXISTS vector;\"],\n },\n ];\n\n for (const [modelName, declaration] of Object.entries(ctx.declarations)) {\n const model = ctx.schema.models.find((candidate) => candidate.name === modelName);\n if (model === undefined) continue;\n const invalidOption = indexOptionError({ declaration });\n if (invalidOption !== undefined) {\n throw new VibeError({ code: \"VIBE_SCHEMA_INVALID\", message: invalidOption, meta: { model: modelName } });\n }\n const table = tableNameOf({ model });\n const columns = vectorColumnsOf({ declaration });\n\n const indexFields = declStringArray(declaration, \"fields\") ?? [];\n const kindRaw = declString(declaration, \"index\") ?? \"hnsw\";\n // The parse-time attribute validation is the usual gate; a declaration\n // assembled by hand (a DSL extension declaration, a hand-written IR) must\n // not reach `USING <anything>` — the kind is spliced into DDL.\n if (!INDEX_KINDS.includes(kindRaw)) {\n throw new VibeError({\n code: \"VIBE_SCHEMA_INVALID\",\n message: `@@vector on \"${modelName}\" declares index kind \"${kindRaw}\" — expected one of ${INDEX_KINDS.join(\", \")}`,\n meta: { model: modelName, index: kindRaw },\n });\n }\n const metricRaw = declString(declaration, \"metric\") ?? \"cosine\";\n const metric = METRICS.find((candidate) => candidate === metricRaw) ?? \"cosine\";\n\n for (const field of indexFields) {\n if (columns[field] === undefined) {\n throw new VibeError({\n code: \"VIBE_SCHEMA_INVALID\",\n message: `@@vector on \"${modelName}\" indexes \"${field}\", which is not a Vector(n) column`,\n meta: { model: modelName, field },\n });\n }\n const column = columnNameOf({ model, field });\n // Adoption override (validated single-field-only at parse): consumers\n // with a live index keep its name instead of a rename migration.\n const nameOverride = indexFields.length === 1 ? declString(declaration, \"indexName\") : undefined;\n // Same identifier-limit rule as every minted index name: a truncated\n // name would miss migrate's ownership handshake and be rebuilt (HNSW!)\n // on every push.\n if (nameOverride !== undefined) assertIdentifierFits({ name: nameOverride, dialect: ctx.dialect, what: \"@@vector indexName\", remedy: \"Shorten it.\" });\n const indexName = nameOverride ?? fitDefaultName({ prefix: `${table}_${column}_${kindRaw}`, suffix: \"_idx\", dialect: ctx.dialect });\n const withOptions: string[] = [];\n const m = declaration[\"m\"];\n const efConstruction = declaration[\"efConstruction\"];\n const lists = declaration[\"lists\"];\n if (kindRaw === \"hnsw\") {\n if (typeof m === \"number\") withOptions.push(`m = ${m}`);\n if (typeof efConstruction === \"number\") withOptions.push(`ef_construction = ${efConstruction}`);\n } else if (typeof lists === \"number\") {\n withOptions.push(`lists = ${lists}`);\n }\n const withClause = withOptions.length === 0 ? \"\" : ` WITH (${withOptions.join(\", \")})`;\n artifacts.push({\n id: `vector:${modelName}:${field}`,\n owns: { kind: \"index\", table, name: indexName },\n create: [\n `CREATE INDEX IF NOT EXISTS ${quote(indexName)} ON ${extensionSqlName({ dialect, name: table })} USING ${kindRaw} (${quote(column)} ${METRIC_OPCLASS[metric]})${withClause};`,\n ],\n drop: [`DROP INDEX IF EXISTS ${extensionSqlName({ dialect, name: indexName })};`],\n });\n }\n }\n return artifacts;\n}\n\n// ─── Runtime namespace (generated-glue target) ────────────────────\n\n/** Baked per-model config the generator writes into the client. */\nexport type VectorNamespaceConfig = {\n readonly table: string;\n /** Field name → column + dims. */\n readonly columns: Readonly<Record<string, VectorColumnDecl>>;\n /** Default metric from the schema declaration. */\n readonly metric: VectorMetric;\n};\n\nexport type VectorNearestArgs = {\n readonly by: string;\n readonly to: readonly number[];\n readonly metric?: VectorMetric;\n readonly take?: number;\n readonly where?: Record<string, unknown>;\n readonly maxDistance?: number;\n};\n\nexport type VectorSetArgs = {\n readonly where: Record<string, unknown>;\n readonly by: string;\n readonly to: readonly number[];\n};\n\nexport type VectorNamespace = {\n readonly nearest: (args: VectorNearestArgs) => Promise<VectorHit<Record<string, unknown>>[]>;\n readonly set: (args: VectorSetArgs) => Promise<number>;\n};\n\nfunction resolveColumn(params: {\n config: VectorNamespaceConfig;\n args: { by: string; to: readonly number[] };\n}): { column: string; literal: string } {\n const { config, args } = params;\n const spec = config.columns[args.by];\n if (spec === undefined) {\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `\"${args.by}\" is not a Vector(n) column — declared: ${Object.keys(config.columns).join(\", \")}`,\n meta: { by: args.by },\n });\n }\n if (!Array.isArray(args.to) || args.to.some((entry) => typeof entry !== \"number\" || !Number.isFinite(entry))) {\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `vector \"to\" must be an array of finite numbers`,\n meta: { by: args.by },\n });\n }\n if (args.to.length !== spec.dims) {\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `vector \"to\" has ${args.to.length} dimensions, \"${args.by}\" expects ${spec.dims}`,\n meta: { by: args.by, dims: spec.dims },\n });\n }\n return { column: spec.column, literal: `[${args.to.join(\",\")}]` };\n}\n\n/**\n * The generated client's glue target: bakes per-model config at generate time,\n * mounts as the `vector` namespace at runtime (D9).\n */\nexport function createVectorNamespace(\n config: VectorNamespaceConfig,\n): (ctx: ExtensionMountContext) => VectorNamespace {\n return (ctx: ExtensionMountContext): VectorNamespace => {\n if (ctx.model !== null) assertExtensionModelPlacement({ namespace: ctx.model.namespace, dialect: ctx.dialect.name });\n const dialect = ctx.dialect;\n const quote = (name: string): string => dialect.quoteIdent({ name });\n const t = quote(\"t\");\n\n return {\n nearest: async (args: VectorNearestArgs): Promise<VectorHit<Record<string, unknown>>[]> => {\n const take = finiteNumber({ value: args.take === undefined ? 10 : args.take, name: \"take\", integer: true, min: 1 });\n if (args.maxDistance !== undefined) finiteNumber({ value: args.maxDistance, name: \"maxDistance\" });\n const { column, literal } = resolveColumn({ config, args });\n const metric = args.metric ?? config.metric;\n const op = METRIC_OPERATOR[metric];\n const col = `${t}.${quote(column)}`;\n const collector = new ParamCollector(dialect);\n const vector = dialect.name === \"postgres\" ? collector.add(literal) : undefined;\n\n let text = `SELECT ${ctx.projection({ qualify: \"t\" })}, (${col} ${op} ${vector ?? collector.add(literal)}) AS ${quote(DISTANCE_ALIAS)}`;\n text += ` FROM ${extensionSqlName({ dialect, name: config.table })} AS ${t}`;\n text += ` WHERE ${col} IS NOT NULL`;\n if (args.where !== undefined) {\n const expr = ctx.compileWhere({ where: args.where, qualify: \"t\" });\n if (expr !== undefined) text += ` AND (${renderExpr({ dialect, expr, collector })})`;\n }\n if (args.maxDistance !== undefined) {\n text += ` AND (${col} ${op} ${vector ?? collector.add(literal)}) < ${collector.add(args.maxDistance)}`;\n }\n text += ` ORDER BY ${col} ${op} ${vector ?? collector.add(literal)} LIMIT ${take}`;\n\n const rows = await ctx.executeRows({\n text,\n values: collector.values,\n method: \"vector.nearest\",\n });\n return rows.map((row) => {\n const { [DISTANCE_ALIAS]: distance, ...rest } = row;\n return { row: rest, distance: Number(distance) };\n });\n },\n\n set: async (args: VectorSetArgs): Promise<number> => {\n const { column, literal } = resolveColumn({ config, args });\n const collector = new ParamCollector(dialect);\n let text = `UPDATE ${extensionSqlName({ dialect, name: config.table })} SET ${quote(column)} = ${collector.add(literal)}`;\n const expr = ctx.compileWhere({ where: args.where });\n if (expr !== undefined) text += ` WHERE ${renderExpr({ dialect, expr, collector })}`;\n text += ` RETURNING 1 AS ${quote(\"_vibe_set\")}`;\n const rows = await ctx.executeRows({ text, values: collector.values, method: \"vector.set\" });\n return rows.length;\n },\n };\n };\n}\n\n// ─── Factory ──────────────────────────────────────────────────────\n\n/**\n * pgvector similarity search.\n *\n * @example schema\n * // embedding Vector(1536)\n * // @@vector([embedding], metric: \"cosine\", index: \"hnsw\")\n * const near = await db.doc.vector.nearest({ by: \"embedding\", to: queryVec, take: 10 });\n */\nexport function vector(options: VectorOptions = {}): VibeExtension {\n return defineExtension({\n name: \"vector\",\n version: VERSION,\n options: { ...options },\n requires: { postgresql: { extension: \"vector\" }, pglite: { extension: \"vector\" } },\n\n schema: {\n fieldTypes: [\n {\n name: \"Vector\",\n lower: ({ field, args }) => {\n const dims = Number(args[0]);\n if (!Number.isInteger(dims) || dims <= 0) {\n return { error: \"Vector(n) requires a positive integer dimension, e.g. Vector(1536)\" };\n }\n return {\n nativeType: `vector(${dims})`,\n declaration: { columns: { [field]: { dims } } },\n };\n },\n },\n ],\n modelAttributes: [\n {\n name: \"vector\",\n parse: ({ args, fieldNames }) => {\n const fields = args.fields ?? [];\n if (fields.length === 0) {\n return { error: \"@@vector requires a field list, e.g. @@vector([embedding])\" };\n }\n const missing = fields.find((name) => !fieldNames.includes(name));\n if (missing !== undefined) {\n return { error: `@@vector references unknown field \"${missing}\"` };\n }\n const metric = args.named[\"metric\"];\n if (metric !== undefined && !METRICS.includes(metric as VectorMetric)) {\n return { error: `metric must be one of ${METRICS.join(\", \")}` };\n }\n const kind = args.named[\"index\"];\n if (kind !== undefined && !INDEX_KINDS.includes(String(kind))) {\n return { error: `index must be one of ${INDEX_KINDS.join(\", \")}` };\n }\n const invalidOption = indexOptionError({ declaration: args.named });\n if (invalidOption !== undefined) return { error: invalidOption };\n const indexName = args.named[\"indexName\"];\n if (indexName !== undefined) {\n if (typeof indexName !== \"string\" || !isSafeSqlName({ name: indexName })) {\n return { error: `indexName must be a plain identifier` };\n }\n if (fields.length !== 1) {\n return {\n error: `indexName needs exactly one indexed field — one named index declaration per model is supported`,\n };\n }\n }\n return { declaration: { fields, ...args.named } };\n },\n },\n ],\n indexKinds: [\"hnsw\", \"ivfflat\"],\n },\n\n migrate: { artifacts: vectorArtifacts },\n\n client: {\n model: ({ model, dialect, declaration, typeNames }) => {\n const columns = vectorColumnsOf({ declaration });\n const fieldNames = Object.keys(columns);\n if (fieldNames.length === 0) return null;\n if (dialect !== \"postgres\") {\n throw unsupportedCapability({\n dialect,\n feature: `the vector extension (declared on model \"${model.name}\")`,\n hint: \"pgvector exists on postgres/pglite only\",\n });\n }\n const metricRaw = declString(declaration, \"metric\");\n const metric = METRICS.find((candidate) => candidate === metricRaw) ?? \"cosine\";\n const config: VectorNamespaceConfig = {\n table: tableNameOf({ model }),\n columns: Object.fromEntries(\n fieldNames.map((field) => [\n field,\n { column: columnNameOf({ model, field }), dims: columns[field]!.dims },\n ]),\n ),\n metric,\n };\n const byUnion = fieldNames.map((name) => JSON.stringify(name)).join(\" | \");\n return {\n kind: \"namespace\",\n // `nearest` reads; `set` issues an UPDATE, so it is NOT classified and\n // a $readOnly client neither declares nor forwards it.\n readOnly: [\"nearest\"],\n runtimeGlue: `createVectorNamespace(${JSON.stringify(config)})`,\n imports: [{ from: \"@vibeorm/extensions/vector\", names: [\"createVectorNamespace\"] }],\n dtsImports: [{ from: \"@vibeorm/extensions/vector\", names: [\"VectorHit\", \"VectorMetric\"] }],\n dts: [\n `readonly vector: {`,\n ` readonly nearest: (args: {`,\n ` readonly by: ${byUnion};`,\n ` readonly to: readonly number[];`,\n ` readonly metric?: VectorMetric;`,\n ` readonly take?: number;`,\n ` readonly where?: ${typeNames.whereInput};`,\n ` readonly maxDistance?: number;`,\n ` }) => Promise<VectorHit<${typeNames.payload}>[]>;`,\n ` readonly set: (args: {`,\n ` readonly where: ${typeNames.whereInput};`,\n ` readonly by: ${byUnion};`,\n ` readonly to: readonly number[];`,\n ` }) => Promise<number>;`,\n `};`,\n ],\n };\n },\n },\n\n doctor: async ({ execute, dialect }) => {\n if (dialect !== \"postgres\") {\n return { checks: [{ name: \"vector dialect\", ok: false, note: \"postgres/pglite only\" }] };\n }\n return { checks: [await pgExtensionCheck({ execute, name: \"vector\" })] };\n },\n });\n}\n",
|
|
6
|
+
"/**\n * Helpers shared by the tier-1 extensions. Nothing here is privileged —\n * userland extensions can do everything these do with the same public hooks.\n */\n\nimport { VibeError, assertExtensionModelPlacement, qualifiedSqlName } from \"@vibeorm/schema\";\nimport type {\n ExtensionDoctorCheck,\n ExtensionSqlExecutor,\n ModelIR,\n} from \"@vibeorm/schema\";\n\nimport type { SqlDialect } from \"@vibeorm/sql\";\n\n/** Quote a built-in's physical target; PostgreSQL ownership is always public. */\nexport function extensionSqlName(params: { dialect: SqlDialect; name: string }): string {\n const { dialect, name } = params;\n const physical = qualifiedSqlName({ name });\n return dialect.name === \"postgres\"\n ? `${dialect.quoteIdent({ name: physical.namespace })}.${dialect.quoteIdent({ name: physical.name })}`\n : dialect.quoteIdent({ name });\n}\n\n// ─── Numeric admission ────────────────────────────────────────────\n\n/** Refuse non-finite extension arguments before compilation or execution. */\nexport function finiteNumber(params: { value: unknown; name: string; integer?: boolean; min?: number }): number {\n const { value, name, integer, min } = params;\n if (typeof value !== \"number\" || !Number.isFinite(value) ||\n (integer === true && !Number.isSafeInteger(value)) || (min !== undefined && value < min)) {\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `${name} must be a finite ${integer === true ? \"safe integer\" : \"number\"}${min === undefined ? \"\" : ` >= ${min}`}`,\n meta: { argument: name },\n });\n }\n return value;\n}\n\n// ─── IR lookups ───────────────────────────────────────────────────\n\n/** Table name of a model (`dbName ?? name`). */\nexport function tableNameOf(params: { model: ModelIR }): string {\n assertExtensionModelPlacement({ namespace: params.model.namespace });\n return params.model.dbName ?? params.model.name;\n}\n\n/** Column name of a field (`dbName ?? name`); the field must exist. */\nexport function columnNameOf(params: { model: ModelIR; field: string }): string {\n const found = params.model.fields.find((candidate) => candidate.name === params.field);\n if (found === undefined) {\n throw new VibeError({\n code: \"VIBE_INTERNAL\",\n message: `extension referenced unknown field \"${params.field}\" on model \"${params.model.name}\"`,\n meta: { model: params.model.name, field: params.field },\n });\n }\n return found.dbName ?? found.name;\n}\n\n/** The model's single primary-key field name, for key_field-style options. */\nexport function primaryKeyFieldOf(params: { model: ModelIR }): string | null {\n const { model } = params;\n if (model.primaryKey !== undefined && model.primaryKey.fields.length === 1) {\n return model.primaryKey.fields[0] ?? null;\n }\n const idField = model.fields.find((field) => field.isId);\n return idField?.name ?? null;\n}\n\n// ─── Declaration readers (ExtensionDeclIR.options are untyped JSON) ─\n\nexport function declString(decl: Readonly<Record<string, unknown>>, key: string): string | undefined {\n const value = decl[key];\n return typeof value === \"string\" ? value : undefined;\n}\n\nexport function declStringArray(\n decl: Readonly<Record<string, unknown>>,\n key: string,\n): readonly string[] | undefined {\n const value = decl[key];\n if (!Array.isArray(value)) return undefined;\n return value.every((entry): entry is string => typeof entry === \"string\") ? value : undefined;\n}\n\nexport function declNumberArray(\n decl: Readonly<Record<string, unknown>>,\n key: string,\n): readonly number[] | undefined {\n const value = decl[key];\n if (!Array.isArray(value)) return undefined;\n return value.every((entry): entry is number => typeof entry === \"number\") ? value : undefined;\n}\n\n// ─── Identifier safety ────────────────────────────────────────────\n\nconst SQL_LITERAL_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/**\n * Names an extension splices as SQL LITERALS (regconfig names, key_field\n * options) must be plain identifiers — everything else is rejected at parse\n * time so no schema-borne text ever reaches SQL unquoted.\n */\nexport function isSafeSqlName(params: { name: string }): boolean {\n return SQL_LITERAL_NAME.test(params.name);\n}\n\n// ─── Doctor helpers ───────────────────────────────────────────────\n\n/** Availability of a postgres extension, per pg_available_extensions. */\nexport async function pgExtensionCheck(params: {\n execute: ExtensionSqlExecutor;\n name: string;\n}): Promise<ExtensionDoctorCheck> {\n const { execute, name } = params;\n try {\n const rows = await execute({\n text: \"SELECT name, default_version, installed_version FROM pg_available_extensions WHERE name = $1\",\n values: [name],\n });\n const row = rows[0];\n if (row === undefined) {\n return { name: `extension ${name}`, ok: false, note: \"not available on this server\" };\n }\n const installed = row[\"installed_version\"];\n return {\n name: `extension ${name}`,\n ok: true,\n note: installed === null || installed === undefined ? \"available, not installed\" : `installed ${String(installed)}`,\n };\n } catch (error) {\n return {\n name: `extension ${name}`,\n ok: false,\n note: `check failed: ${error instanceof Error ? error.message : String(error)}`,\n };\n }\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";;AAYA,sBAAS;AAMT;;;ACbA;AAUO,SAAS,YAAY,CAAC,QAAmF;AAAA,EAC9G,QAAQ,OAAO,MAAM,SAAS,QAAQ;AAAA,EACtC,IAAI,OAAO,UAAU,YAAY,CAAC,OAAO,SAAS,KAAK,KAClD,YAAY,QAAQ,CAAC,OAAO,cAAc,KAAK,KAAO,QAAQ,aAAa,QAAQ,KAAM;AAAA,IAC5F,MAAM,IAAI,UAAU;AAAA,MAClB,MAAM;AAAA,MACN,SAAS,GAAG,yBAAyB,YAAY,OAAO,iBAAiB,WAAW,QAAQ,YAAY,KAAK,OAAO;AAAA,MACpH,MAAM,EAAE,UAAU,KAAK;AAAA,IACzB,CAAC;AAAA,EACH;AAAA,EACA,OAAO;AAAA;AAMF,SAAS,WAAW,CAAC,QAAoC;AAAA,EAC9D,OAAO,OAAO,MAAM,UAAU,OAAO,MAAM;AAAA;AAItC,SAAS,YAAY,CAAC,QAAmD;AAAA,EAC9E,MAAM,QAAQ,OAAO,MAAM,OAAO,KAAK,CAAC,cAAc,UAAU,SAAS,OAAO,KAAK;AAAA,EACrF,IAAI,UAAU,WAAW;AAAA,IACvB,MAAM,IAAI,UAAU;AAAA,MAClB,MAAM;AAAA,MACN,SAAS,uCAAuC,OAAO,oBAAoB,OAAO,MAAM;AAAA,MACxF,MAAM,EAAE,OAAO,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C,uBAAuB,EAAE,CAAC;AAAA,UAClF,YAAY,CAAC,EAAE,MAAM,8BAA8B,OAAO,CAAC,aAAa,cAAc,EAAE,CAAC;AAAA,UACzF,KAAK;AAAA,YACH;AAAA,YACA;AAAA,YACA,oBAAoB;AAAA,YACpB;AAAA,YACA;AAAA,YACA;AAAA,YACA,wBAAwB,UAAU;AAAA,YAClC;AAAA,YACA,6BAA6B,UAAU;AAAA,YACvC;AAAA,YACA,uBAAuB,UAAU;AAAA,YACjC,oBAAoB;AAAA,YACpB;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA;AAAA,IAEJ;AAAA,IAEA,QAAQ,SAAS,SAAS,cAAc;AAAA,MACtC,IAAI,YAAY,YAAY;AAAA,QAC1B,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,kBAAkB,IAAI,OAAO,MAAM,uBAAuB,CAAC,EAAE;AAAA,MACzF;AAAA,MACA,OAAO,EAAE,QAAQ,CAAC,MAAM,iBAAiB,EAAE,SAAS,MAAM,SAAS,CAAC,CAAC,EAAE;AAAA;AAAA,EAE3E,CAAC;AAAA;",
|
|
9
|
+
"debugId": "ACE40E01F62FF63964756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeorm/extensions",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Tier-1 VibeORM extensions — full-text search, pgvector similarity and pg_trgm fuzzy matching",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"orm",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"bun": ">=1.2.0"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@vibeorm/runtime": "4.
|
|
60
|
-
"@vibeorm/schema": "4.
|
|
61
|
-
"@vibeorm/sql": "4.
|
|
59
|
+
"@vibeorm/runtime": "4.1.0",
|
|
60
|
+
"@vibeorm/schema": "4.1.0",
|
|
61
|
+
"@vibeorm/sql": "4.1.0"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|