@vibeorm/extensions 2.0.0-alpha.1

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/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # @vibeorm/extensions
2
+
3
+ > A type-safe TypeScript ORM for Bun and Node. Prisma-schema or TypeScript-DSL input, a canonical schema IR, a generated client that your editor never re-infers, and a dialect-aware SQL layer over PostgreSQL, PGlite, SQLite and MySQL.
4
+
5
+ ```bash
6
+ bun add @vibeorm/extensions@alpha
7
+ ```
8
+
9
+ > **Pre-release.** `2.0.0-alpha.x`, published under the `alpha` dist-tag. `npm i vibeorm` still resolves to the stable v1 line, which has a different API — see the migration guide below.
10
+
11
+ ## What it provides
12
+
13
+ Three extensions, each a factory returning a `VibeExtension` that you pass to `vibeorm.config.ts` (so `generate`, `db push`, `migrate` and `doctor` see it) and to `VibeClient` (so the runtime mounts it).
14
+
15
+ | Import | Factory | Databases |
16
+ |---|---|---|
17
+ | `@vibeorm/extensions/search` | `search(options?)` | PostgreSQL, PGlite, SQLite, MySQL |
18
+ | `@vibeorm/extensions/vector` | `vector(options?)` | PostgreSQL, PGlite (pgvector) |
19
+ | `@vibeorm/extensions/trgm` | `trgm(options?)` | PostgreSQL, PGlite (pg_trgm) |
20
+
21
+ The package root (`@vibeorm/extensions`) re-exports all three for convenience.
22
+
23
+ ```ts
24
+ // vibeorm.config.ts
25
+ import { search } from "@vibeorm/extensions/search";
26
+ import { trgm } from "@vibeorm/extensions/trgm";
27
+ import { vector } from "@vibeorm/extensions/vector";
28
+
29
+ export default {
30
+ schema: "./prisma/schema.prisma",
31
+ output: "./generated/vibeorm",
32
+ extensions: [search(), trgm({ threshold: 0.3 }), vector()],
33
+ };
34
+ ```
35
+
36
+ Each extension declares its schema attributes, the DDL artifacts `db push` / `migrate` apply, and the surface the generator writes into the client's `.d.ts`. You declare usage in the schema; the client method or namespace appears only on the models that declare it.
37
+
38
+ ## Search
39
+
40
+ Declare the searched fields with `@@search`. Optional named arguments: `name` (artifact base name, a plain identifier), `weights` (one number per field), `language` (a text-search config name, tsvector engine only).
41
+
42
+ ```prisma
43
+ model Post {
44
+ id Int @id @default(autoincrement())
45
+ title String
46
+ body String
47
+ published Boolean @default(true)
48
+
49
+ @@search([title, body], weights: [2, 1])
50
+ }
51
+ ```
52
+
53
+ ```ts
54
+ import { VibeClient } from "./generated/vibeorm/index.js";
55
+ import { search } from "@vibeorm/extensions/search";
56
+
57
+ const db = VibeClient({ adapter, extensions: [search()] });
58
+
59
+ const hits = await db.post.search({
60
+ query: "database indexes",
61
+ where: { published: true },
62
+ take: 10,
63
+ skip: 0,
64
+ minScore: 0.1,
65
+ highlight: { field: "body" },
66
+ });
67
+ // hits: SearchHit<Post>[] — { row, score, highlights }
68
+ ```
69
+
70
+ `highlights` is `readonly string[] | null`; it is `null` when no highlight was requested and on engines without highlighting.
71
+
72
+ ### Engines per dialect
73
+
74
+ `engine: "auto"` (the default) picks the dialect's native engine. `resolveSearchEngine({ dialect, provider, requested })` is the exported resolution rule.
75
+
76
+ | Dialect | Engine | SQL used | Highlights |
77
+ |---|---|---|---|
78
+ | postgres / pglite | `tsvector` | generated `STORED` tsvector column + GIN index, `websearch_to_tsquery` / `ts_rank_cd` / `ts_headline` | yes |
79
+ | postgres (ParadeDB `pg_search`, opt in with `search({ engine: "bm25" })`) | `bm25` | bm25 index, `@@@`, `paradedb.score` / `paradedb.snippet` | yes |
80
+ | sqlite | `fts5` | external-content virtual table + sync triggers, `MATCH` / `bm25()` / `snippet()` | yes |
81
+ | mysql | `fulltext` | `FULLTEXT` index, `MATCH … AGAINST` in natural language mode | no, typed `null` |
82
+
83
+ Two gates worth knowing before you pick a dialect:
84
+
85
+ - `engine: "bm25"` is refused on `pglite` (it does not bundle `pg_search`) and on non-postgres dialects. `"auto"` never selects it, because ParadeDB availability is not knowable at generate time.
86
+ - The `fts5` engine requires the searched model to have a single `Int` or `BigInt` `@id`. That is the only primary key that aliases and pins the SQLite rowid the external-content table keys on; anything else is refused at generate time.
87
+
88
+ `createSearchDelegate(config)` is the runtime glue the generator emits into the client. You do not call it by hand.
89
+
90
+ ## Vector
91
+
92
+ pgvector similarity search, on PostgreSQL and PGlite only. Declare a `Vector(n)` field and an index with `@@vector`. Named arguments: `metric` (`"cosine"` default, `"l2"`, `"ip"`), `index` (`"hnsw"` default or `"ivfflat"`), plus `m` / `efConstruction` for hnsw and `lists` for ivfflat.
93
+
94
+ ```prisma
95
+ model Doc {
96
+ id Int @id @default(autoincrement())
97
+ tenantId String
98
+ embedding Vector(3)?
99
+
100
+ @@vector([embedding], metric: "cosine", index: "hnsw")
101
+ }
102
+ ```
103
+
104
+ ```ts
105
+ import { vector } from "@vibeorm/extensions/vector";
106
+
107
+ const db = VibeClient({ adapter, extensions: [vector()] });
108
+
109
+ await db.doc.vector.set({ where: { id: 1 }, by: "embedding", to: [1, 0, 0] });
110
+
111
+ const near = await db.doc.vector.nearest({
112
+ by: "embedding",
113
+ to: [1, 0, 0],
114
+ take: 10,
115
+ where: { tenantId: "t2" },
116
+ maxDistance: 0.4,
117
+ });
118
+ // near: VectorHit<Doc>[] — { row, distance }, smaller distance is closer
119
+ ```
120
+
121
+ `set` returns the number of updated rows. `nearest` takes an optional `metric` that overrides the schema's default per query. A `to` array whose length does not match the column's declared dimensions is a `VibeError` with code `VIBE_VALIDATION`. `createVectorNamespace(config)` is the generated glue; `VectorMetric` and `VectorHit` are the exported types the client's `.d.ts` imports.
122
+
123
+ ## Trgm
124
+
125
+ pg_trgm fuzzy matching, on PostgreSQL and PGlite only. It claims no client surface: it adds the `similarTo` where-operator and `gin_trgm_ops` indexes over the fields listed in `@@trgm`.
126
+
127
+ ```prisma
128
+ model User {
129
+ id Int @id @default(autoincrement())
130
+ name String
131
+
132
+ @@trgm([name])
133
+ }
134
+ ```
135
+
136
+ ```ts
137
+ import { trgm } from "@vibeorm/extensions/trgm";
138
+
139
+ const db = VibeClient({ adapter, extensions: [trgm({ threshold: 0.3 })] });
140
+
141
+ await db.user.findMany({ where: { name: { similarTo: "jonatan" } } });
142
+ await db.user.findMany({ where: { name: { similarTo: { text: "jonatan", threshold: 0.95 } } } });
143
+ ```
144
+
145
+ The operand is a `SimilarToOperand`: a string, or `{ text, threshold? }` for a per-use threshold. `threshold` in `TrgmOptions` sets the default (0.3) and is applied to the session's `pg_trgm.similarity_threshold` on connect.
146
+
147
+ The compiled predicate has two forms. When the effective threshold is at least `max(configured, 0.3)` it emits `col % $q AND similarity(col, $q) >= $t`, so the trigram index prunes. Below that floor it emits `similarity(col, $q) >= $t` alone, which is a full scan but returns every row the caller asked for, because a pooled connection may still carry the server's 0.3 default. `vibeorm doctor` reports whether the server's `pg_trgm.similarity_threshold` sits above the gate floor.
148
+
149
+ ## Capability gating
150
+
151
+ A feature a dialect cannot express throws a `VibeError` with code `VIBE_UNSUPPORTED_CAPABILITY` at the earliest knowable moment: generate or migrate time when the schema alone decides it, execute time otherwise. Nothing degrades silently.
152
+
153
+ - `vector()` on sqlite or mysql fails when artifacts are built and when the client is generated, before any DDL reaches the database.
154
+ - `trgm()` fails the same way, and `similarTo` refuses to compile on a non-postgres dialect.
155
+ - `search({ engine })` fails at engine resolution when the requested engine is not the dialect's native one (and is not `bm25` on a non-pglite postgres).
156
+
157
+ `vibeorm doctor` reports per-extension checks: `pg_search`, `vector` and `pg_trgm` availability from `pg_available_extensions`, FTS5 compilation on SQLite, and the trgm threshold check described above.
158
+
159
+ ## Links
160
+
161
+ - [Documentation](https://github.com/vibeorm/vibeorm/tree/master/docs)
162
+ - [Getting started](https://github.com/vibeorm/vibeorm/blob/master/docs/getting-started.md)
163
+ - [Query API](https://github.com/vibeorm/vibeorm/blob/master/docs/queries.md)
164
+ - [Coming from Prisma](https://github.com/vibeorm/vibeorm/blob/master/docs/from-prisma.md)
165
+ - [Upgrading from VibeORM v1](https://github.com/vibeorm/vibeorm/blob/master/docs/migrating-v1-v2.md)
166
+ - [Repository and issues](https://github.com/vibeorm/vibeorm)
167
+ - MIT licensed
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @vibeorm/extensions — tier-1 VibeORM extensions (plan §10, extensions.md).
3
+ *
4
+ * Import from the subpaths in app code (`@vibeorm/extensions/search`, …, D6);
5
+ * this root re-exports everything for convenience and for the CLI/tests.
6
+ */
7
+ export { createSearchDelegate, resolveSearchEngine, search } from "./search/index.ts";
8
+ export type { SearchArgs, SearchDelegateConfig, SearchEngine, SearchHit, SearchMethod, SearchOptions, } from "./search/index.ts";
9
+ export { createVectorNamespace, vector } from "./vector/index.ts";
10
+ export type { VectorHit, VectorMetric, VectorNamespace, VectorNamespaceConfig, VectorNearestArgs, VectorOptions, VectorSetArgs, } from "./vector/index.ts";
11
+ export { trgm } from "./trgm/index.ts";
12
+ export type { SimilarToOperand, TrgmOptions } from "./trgm/index.ts";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACtF,YAAY,EACV,UAAU,EACV,oBAAoB,EACpB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAClE,YAAY,EACV,SAAS,EACT,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,aAAa,EACb,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}