@wirecat/cli-core 0.432.0 → 0.434.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cli/messenger/store-maintenance-command.js +5 -2
  3. package/dist/cli/upgrade-command.js +1 -1
  4. package/dist/entities/index.d.ts +10 -3
  5. package/dist/entities/store-maintenance.d.ts +10 -3
  6. package/dist/entities/store-maintenance.js +10 -1
  7. package/dist/errors/reasons.js +7 -0
  8. package/dist/models/anthropic.js +2 -4
  9. package/dist/store/drivers/bun-sqlite.d.ts +6 -0
  10. package/dist/store/drivers/bun-sqlite.js +16 -1
  11. package/dist/store/drivers/node-sqlite.d.ts +5 -1
  12. package/dist/store/drivers/node-sqlite.js +16 -1
  13. package/dist/store/exports.d.ts +1 -0
  14. package/dist/store/exports.js +1 -0
  15. package/dist/store/sqlite/document-pictures.js +4 -1
  16. package/dist/store/sqlite/drizzle/bun.js +58 -14
  17. package/dist/store/sqlite/drizzle/bun.js.map +3 -3
  18. package/dist/store/sqlite/drizzle/core.js +173 -7
  19. package/dist/store/sqlite/drizzle/core.js.map +4 -4
  20. package/dist/store/sqlite/drizzle/node.js +57 -13
  21. package/dist/store/sqlite/drizzle/node.js.map +3 -3
  22. package/dist/store/sqlite/drizzle/shared-55XJMTPA.js +6514 -0
  23. package/dist/store/sqlite/drizzle/shared-55XJMTPA.js.map +7 -0
  24. package/dist/store/sqlite/image-chunks.d.ts +1 -1
  25. package/dist/store/sqlite/image-chunks.js +46 -13
  26. package/dist/store/sqlite/manifest.js +2 -0
  27. package/dist/store/sqlite/message-chunks.d.ts +5 -2
  28. package/dist/store/sqlite/message-chunks.js +42 -13
  29. package/dist/store/sqlite/migrations.generated.js +22 -0
  30. package/dist/store/sqlite/open-store.js +4 -0
  31. package/dist/store/sqlite/open.js +5 -6
  32. package/dist/store/sqlite/schema/canonical-tags.d.ts +1 -0
  33. package/dist/store/sqlite/schema/document-index-pending.d.ts +1 -0
  34. package/dist/store/sqlite/schema/document-transfers.d.ts +1 -0
  35. package/dist/store/sqlite/schema/tag-consolidations.d.ts +2 -0
  36. package/dist/store/sqlite/schema.d.ts +214 -0
  37. package/dist/store/sqlite/schema.js +17 -0
  38. package/dist/store/sqlite/vector-index.d.ts +67 -0
  39. package/dist/store/sqlite/vector-index.js +180 -0
  40. package/dist/store/sqlite/vectors.d.ts +6 -3
  41. package/dist/store/sqlite/vectors.js +71 -31
  42. package/dist/store/vector-extension.d.ts +10 -0
  43. package/dist/store/vector-extension.js +53 -0
  44. package/package.json +24 -25
  45. package/dist/store/sqlite/drizzle/shared-HKXF6HKX.js +0 -4846
  46. package/dist/store/sqlite/drizzle/shared-HKXF6HKX.js.map +0 -7
package/CHANGELOG.md CHANGED
@@ -5,6 +5,31 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
5
5
  minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
6
6
  shape of this file.
7
7
 
8
+ ## Unreleased
9
+
10
+ ## 0.434.0 — 25.10.2026
11
+
12
+ ### Changed — may break callers
13
+
14
+ - **Search by meaning ranks by a sqlite-vec index in the store (store version 34), and every store connection loads the extension.** Each embedding model gets a `vec0` table, `vector_index_<id>`, listed in the new `vector_indexes`; triggers on `chunks`, `embeddings` and `messages` keep it in step inside each write's own transaction. `nearestMessages`, `nearestImages` and conversation search (without a person, project, scope or conversation list) take candidates from it, check them with the scan's own SQL and score them as before, so they answer exactly what the scan answers; the scan stays for the filters the index cannot express. A store that held vectors is indexed on its first open by this version, in short batches. **Version 34 raises `minCompatible` to 34**: a build without the extension cannot write chunks to a store with these triggers, so older CLIs refuse the file and ask to be upgraded. The extension ships in `@wirecat/cli-core-sqlite` 1.1.0 (now a required runtime piece on every platform, Windows included); when it is missing or does not load, opening the store fails with `store.vector-extension-missing` or `store.vector-extension-failed` and says to reinstall. Under Node the store is opened with `allowExtension`, and SQL's `load_extension()` is switched off again right after.
15
+ - **`store check` reports `vector_indexes`** — per model, the rows its index holds and the rows it should, and how many differ either way (`missing`, `extra`), compared whole — and fails `checks.vector_indexes` when a ready index is off.
16
+ - **Vectors are stored at length one.** `saveVectors` and a document picture's vector are scaled to unit length before they are kept, so search by dot product and by the index rank alike; a vector with a non-finite value is refused (`store.vector-invalid`). Vectors stored before keep their length. The `not_applicable.extensions` field ("SQLite needs none") is gone.
17
+
18
+ ## 0.433.0 — 25.10.2026
19
+
20
+ ### Changed — may break callers
21
+
22
+ - **`upgrade`'s help shows only `<cli> upgrade --check` as an example.** The bare `<cli> upgrade` example is gone
23
+ from it: copied and run, it upgraded. A CLI that keeps help or `commands --json` snapshots refreshes them once;
24
+ in tg, max and wa only this example changes. A CLI that sets its own `examples` on the shared command overrides
25
+ these, and cli-core's shared-command check then refuses its program when the two differ.
26
+ - **The Anthropic adapter takes only `stop_sequences` as an option.** `@anthropic-ai/sdk` 1.x sends API version
27
+ 2026-10-21, which refuses `temperature`, `top_p` and `top_k` on every model, so the adapter now refuses them
28
+ before any request. The SDK also sends the key as `Authorization: Bearer` instead of `X-Api-Key`: a custom
29
+ Anthropic base URL whose gateway reads `X-Api-Key` must read `Authorization` instead.
30
+ - **`@modelcontextprotocol/server` is `^2.4.0`** (was exactly 2.3.0), so a CLI on server 2.4.x shares one copy with cli-core.
31
+ - **Dependencies moved to their latest majors:** `@anthropic-ai/sdk` 1.3, `sherpa-onnx` 2.0, `drizzle-orm` 1.0.0-rc.5.
32
+
8
33
  ## 0.432.0 — 25.10.2026
9
34
 
10
35
  ### Added
@@ -12,7 +12,7 @@ import { migrate } from "../../store/migrations.js";
12
12
  import { openCache } from "../../store/open.js";
13
13
  import { storePath } from "../../store/path.js";
14
14
  import { deleteCopy, repairStore } from "../../store/repair.js";
15
- import { drainNoteIndex, fillSearchIndex, fillStems, involvementStoreOver, noteIndexState, openSqlite, openStore, orphanPointers, pendingNormalization, resetAttachmentWords, resetNoteIndex, resetSearchIndex, resetStems, searchIndexState, stemmerCache, stemsState, } from "../../store/store.js";
15
+ import { drainNoteIndex, fillSearchIndex, fillStems, involvementStoreOver, noteIndexState, openSqlite, openStore, orphanPointers, pendingNormalization, resetAttachmentWords, resetNoteIndex, resetSearchIndex, resetStems, searchIndexState, stemmerCache, stemsState, vectorIndexCounts, } from "../../store/store.js";
16
16
  import { environmentOf, outputFor } from "../context.js";
17
17
  import { destroysNothing, LOCAL_READ, LOCAL_WRITE } from "../effects.js";
18
18
  import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
@@ -241,11 +241,14 @@ const inspect = (path) => reading(path, (database) => {
241
241
  const { bavail, bsize } = statfsSync(dirname(path));
242
242
  const free = Number(bavail) * Number(bsize);
243
243
  const behind = schema.version > 0 ? chatsBehind(database) : [];
244
+ const vectorIndexes = schema.version >= 34 ? vectorIndexCounts(database) : [];
244
245
  const checks = {
245
246
  schema: schema.version >= SPEAKS && schema.writable,
246
247
  integrity: integrity.length === 1 && integrity[0] === "ok",
247
248
  foreignKeys: foreignKeys === 0,
248
249
  searchIndexes: Object.values(searchIndexes).every((state) => state === "ok"),
250
+ // One that is still filling is short by design; a ready one must hold exactly the rows its sources give.
251
+ vectorIndexes: vectorIndexes.every(({ ready, missing, extra }) => !ready || missing + extra === 0),
249
252
  // A backup or a VACUUM needs about as much again.
250
253
  disk: free >= size,
251
254
  };
@@ -268,7 +271,7 @@ const inspect = (path) => reading(path, (database) => {
268
271
  orphanPointers: schema.version > 0 ? orphanPointers(database) : [],
269
272
  conversations: conversationsBuilt(database),
270
273
  vectors: vectorsHeld(database),
271
- notApplicable: { extensions: "SQLite needs none" },
274
+ vectorIndexes,
272
275
  };
273
276
  });
274
277
  /** `rank = 1` compares the index with its table; without it a stale external-content index passes. */
@@ -33,7 +33,7 @@ export const restartServers = (app, script, env, spawn) => {
33
33
  export const upgradeCommand = (app, packageName, contextFor) => grantsAuthority(annotate(new Command("upgrade"), {
34
34
  effects: LOCAL_WRITE,
35
35
  offline: false,
36
- examples: [`${app.command} upgrade --check`, `${app.command} upgrade`],
36
+ examples: [`${app.command} upgrade --check`],
37
37
  }), { unless: "check" })
38
38
  .description(`upgrade ${app.command} with the package manager that installed it; --check only looks`)
39
39
  .option("--check", "say whether a newer version exists, and install nothing")
@@ -9690,6 +9690,7 @@ export declare const ENTITIES: {
9690
9690
  readonly integrity: v.BooleanSchema<undefined>;
9691
9691
  readonly foreign_keys: v.BooleanSchema<undefined>;
9692
9692
  readonly search_indexes: v.BooleanSchema<undefined>;
9693
+ readonly vector_indexes: v.BooleanSchema<undefined>;
9693
9694
  readonly disk: v.BooleanSchema<undefined>;
9694
9695
  }, undefined>;
9695
9696
  readonly schema: v.StrictObjectSchema<{
@@ -9756,9 +9757,15 @@ export declare const ENTITIES: {
9756
9757
  readonly models: v.RecordSchema<v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
9757
9758
  readonly unused: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
9758
9759
  }, undefined>, undefined>;
9759
- readonly not_applicable: v.StrictObjectSchema<{
9760
- readonly extensions: v.StringSchema<undefined>;
9761
- }, undefined>;
9760
+ readonly vector_indexes: v.ArraySchema<v.StrictObjectSchema<{
9761
+ readonly model: v.StringSchema<undefined>;
9762
+ readonly dims: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
9763
+ readonly ready: v.BooleanSchema<undefined>;
9764
+ readonly indexed: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
9765
+ readonly expected: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
9766
+ readonly missing: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
9767
+ readonly extra: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
9768
+ }, undefined>, undefined>;
9762
9769
  }, undefined>], undefined>;
9763
9770
  readonly store_migration: v.UnionSchema<[v.StrictObjectSchema<{
9764
9771
  readonly path: v.StringSchema<undefined>;
@@ -222,6 +222,7 @@ export declare const storeCheck: v.UnionSchema<[v.StrictObjectSchema<{
222
222
  readonly integrity: v.BooleanSchema<undefined>;
223
223
  readonly foreign_keys: v.BooleanSchema<undefined>;
224
224
  readonly search_indexes: v.BooleanSchema<undefined>;
225
+ readonly vector_indexes: v.BooleanSchema<undefined>;
225
226
  readonly disk: v.BooleanSchema<undefined>;
226
227
  }, undefined>;
227
228
  readonly schema: v.StrictObjectSchema<{
@@ -288,9 +289,15 @@ export declare const storeCheck: v.UnionSchema<[v.StrictObjectSchema<{
288
289
  readonly models: v.RecordSchema<v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
289
290
  readonly unused: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
290
291
  }, undefined>, undefined>;
291
- readonly not_applicable: v.StrictObjectSchema<{
292
- readonly extensions: v.StringSchema<undefined>;
293
- }, undefined>;
292
+ readonly vector_indexes: v.ArraySchema<v.StrictObjectSchema<{
293
+ readonly model: v.StringSchema<undefined>;
294
+ readonly dims: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
295
+ readonly ready: v.BooleanSchema<undefined>;
296
+ readonly indexed: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
297
+ readonly expected: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
298
+ readonly missing: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
299
+ readonly extra: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
300
+ }, undefined>, undefined>;
294
301
  }, undefined>], undefined>;
295
302
  export declare const storeMigration: v.UnionSchema<[v.StrictObjectSchema<{
296
303
  readonly path: v.StringSchema<undefined>;
@@ -87,6 +87,7 @@ export const storeCheck = v.union([
87
87
  integrity: v.boolean(),
88
88
  foreign_keys: v.boolean(),
89
89
  search_indexes: v.boolean(),
90
+ vector_indexes: v.boolean(),
90
91
  disk: v.boolean(),
91
92
  }),
92
93
  schema,
@@ -118,7 +119,15 @@ export const storeCheck = v.union([
118
119
  stale_agent_links: count,
119
120
  })),
120
121
  vectors: v.nullable(v.strictObject({ models: v.record(text, count), unused: count })),
121
- not_applicable: v.strictObject({ extensions: text }),
122
+ vector_indexes: v.array(v.strictObject({
123
+ model: text,
124
+ dims: count,
125
+ ready: v.boolean(),
126
+ indexed: count,
127
+ expected: count,
128
+ missing: count,
129
+ extra: count,
130
+ })),
122
131
  }),
123
132
  ]);
124
133
  const indexed = { normalized: count, indexed: count, terms: count, stemmed: count, notes_indexed: count };
@@ -55,6 +55,13 @@ const OTHERS = [
55
55
  ["state.invalid", "configuration_error", "the saved sync state is unreadable or invalid; it is kept, not reset"],
56
56
  validation("store.refused", "the local store refused the document text"),
57
57
  ["store.not-writable", "permission_error", "the message store cannot be written from this process"],
58
+ [
59
+ "store.vector-extension-missing",
60
+ "configuration_error",
61
+ "the install has no sqlite-vec extension for this platform; reinstall the CLI",
62
+ ],
63
+ ["store.vector-extension-failed", "configuration_error", "the sqlite-vec extension did not load; reinstall the CLI"],
64
+ validation("store.vector-invalid", "a vector to store had a non-finite value"),
58
65
  validation("catalog.scope-limit", "the selected catalog exceeds its entry limit"),
59
66
  validation("evidence.row-too-large", "one evidence row is over its size limit"),
60
67
  validation("index.not-ready", "the search index is still being built"),
@@ -1,11 +1,9 @@
1
1
  import Anthropic from "@anthropic-ai/sdk";
2
2
  import * as v from "valibot";
3
- import { checkedOptions, range } from "./options.js";
3
+ import { checkedOptions } from "./options.js";
4
4
  import { messagesFor, systemFor } from "./types.js";
5
+ // API version 2026-10-21 refuses temperature, top_p and top_k on every model.
5
6
  const options = v.strictObject({
6
- temperature: range(0, 1),
7
- top_p: range(0, 1),
8
- top_k: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))),
9
7
  stop_sequences: v.optional(v.array(v.string())),
10
8
  });
11
9
  export const anthropic = {
@@ -9,6 +9,7 @@ interface BunStatement {
9
9
  export interface BunDatabase {
10
10
  exec(sql: string): void;
11
11
  query(sql: string): BunStatement;
12
+ loadExtension(path: string): void;
12
13
  close(): void;
13
14
  }
14
15
  export interface BunDatabaseClass {
@@ -25,5 +26,10 @@ export interface BunDatabaseClass {
25
26
  */
26
27
  export declare const bunDatabase: () => Promise<BunDatabaseClass>;
27
28
  export declare const openWithBunSqlite: (path: string) => Promise<CacheDatabase>;
29
+ /** A connection with the vector extension loaded; it closes again when the extension does not load. */
30
+ export declare const bunClient: (path: string, options?: {
31
+ readonly?: boolean;
32
+ create?: boolean;
33
+ }) => Promise<BunDatabase>;
28
34
  export declare const cacheOverBunSqlite: (database: BunDatabase) => CacheDatabase;
29
35
  export {};
@@ -1,3 +1,4 @@
1
+ import { loadVectorExtension, vectorExtension } from "../vector-extension.js";
1
2
  let customised = false;
2
3
  /**
3
4
  * Bun on macOS takes the system's SQLite, which can be older than the store needs, so it always
@@ -29,7 +30,21 @@ export const bunDatabase = async () => {
29
30
  }
30
31
  return Database;
31
32
  };
32
- export const openWithBunSqlite = async (path) => cacheOverBunSqlite(new (await bunDatabase())(path));
33
+ export const openWithBunSqlite = async (path) => cacheOverBunSqlite(await bunClient(path));
34
+ /** A connection with the vector extension loaded; it closes again when the extension does not load. */
35
+ export const bunClient = async (path, options) => {
36
+ const Database = await bunDatabase();
37
+ const extension = await vectorExtension();
38
+ const client = options ? new Database(path, options) : new Database(path);
39
+ try {
40
+ loadVectorExtension(client, extension);
41
+ return client;
42
+ }
43
+ catch (error) {
44
+ client.close();
45
+ throw error;
46
+ }
47
+ };
33
48
  export const cacheOverBunSqlite = (database) => {
34
49
  return {
35
50
  exec: (sql) => database.exec(sql),
@@ -4,5 +4,9 @@ import type { CacheDatabase } from "../driver.js";
4
4
  * Import this module only through a dynamic import that follows `quietSqliteWarning()`: a static import loads
5
5
  * `node:sqlite`, and on Node 22 its ExperimentalWarning, before the filter can run.
6
6
  */
7
- export declare const openWithNodeSqlite: (path: string) => CacheDatabase;
7
+ export declare const openWithNodeSqlite: (path: string) => Promise<CacheDatabase>;
8
+ /** A connection with the vector extension loaded; it closes again when the extension does not load. */
9
+ export declare const nodeClient: (path: string, { readOnly }?: {
10
+ readOnly?: boolean;
11
+ }) => Promise<DatabaseSync>;
8
12
  export declare const cacheOverNodeSqlite: (database: DatabaseSync) => CacheDatabase;
@@ -1,9 +1,24 @@
1
+ // biome-ignore-all lint/plugin/no-sqlite-driver: cli-core owns the store, so it opens the driver itself
1
2
  import { DatabaseSync } from "node:sqlite";
3
+ import { loadVectorExtension, vectorExtension } from "../vector-extension.js";
2
4
  /**
3
5
  * Import this module only through a dynamic import that follows `quietSqliteWarning()`: a static import loads
4
6
  * `node:sqlite`, and on Node 22 its ExperimentalWarning, before the filter can run.
5
7
  */
6
- export const openWithNodeSqlite = (path) => cacheOverNodeSqlite(new DatabaseSync(path));
8
+ export const openWithNodeSqlite = async (path) => cacheOverNodeSqlite(await nodeClient(path));
9
+ /** A connection with the vector extension loaded; it closes again when the extension does not load. */
10
+ export const nodeClient = async (path, { readOnly = false } = {}) => {
11
+ const extension = await vectorExtension();
12
+ const client = new DatabaseSync(path, { readOnly, allowExtension: true });
13
+ try {
14
+ loadVectorExtension(client, extension);
15
+ return client;
16
+ }
17
+ catch (error) {
18
+ client.close();
19
+ throw error;
20
+ }
21
+ };
7
22
  export const cacheOverNodeSqlite = (database) => {
8
23
  return {
9
24
  exec: (sql) => database.exec(sql),
@@ -54,6 +54,7 @@ export { savedTaskCategories } from "./sqlite/task-category-settings.js";
54
54
  export { DEFAULT_AGENT_CLOSE, savedAgentClose } from "./sqlite/task-close.js";
55
55
  export { DEFAULT_FIRST_PASS_PER_CHAT, firstPassPerChatOf, savedFirstPassPerChat } from "./sqlite/task-first-pass.js";
56
56
  export { inboxKey } from "./sqlite/tasks.js";
57
+ export { vectorIndexCounts } from "./sqlite/vector-index.js";
57
58
  export type { MatchPlace, ScoredHit } from "./sqlite/words.js";
58
59
  export type { TaskDetails } from "./sqlite/work-tasks.js";
59
60
  export type { SyncStore } from "./sync.js";
@@ -24,3 +24,4 @@ export { savedTaskCategories } from "./sqlite/task-category-settings.js";
24
24
  export { DEFAULT_AGENT_CLOSE, savedAgentClose } from "./sqlite/task-close.js";
25
25
  export { DEFAULT_FIRST_PASS_PER_CHAT, firstPassPerChatOf, savedFirstPassPerChat } from "./sqlite/task-first-pass.js";
26
26
  export { inboxKey } from "./sqlite/tasks.js";
27
+ export { vectorIndexCounts } from "./sqlite/vector-index.js";
@@ -1,5 +1,6 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { write } from "./transaction.js";
3
+ import { ensureVectorIndex, unitVector } from "./vector-index.js";
3
4
  import { dot } from "./vectors.js";
4
5
  /** A document's picture is one chunk of this type at position 0; its vector is the picture's, not text's. */
5
6
  export const DOCUMENT_PICTURE = "document_picture";
@@ -44,10 +45,12 @@ export const documentPicturesOver = ({ database, now }) => ({
44
45
  throw new CliError("not_found", `no document ${ref} in the local store`);
45
46
  const at = now();
46
47
  dropDocumentPicture(database, id);
48
+ ensureVectorIndex(database, model, dims);
49
+ const unit = unitVector(vector);
47
50
  database
48
51
  .prepare(`INSERT INTO embeddings (model, content_hash, dims, vector, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)
49
52
  ON CONFLICT DO NOTHING`)
50
- .run(model, hash, dims, Buffer.from(vector.buffer, vector.byteOffset, vector.byteLength), at, at);
53
+ .run(model, hash, dims, Buffer.from(unit.buffer, unit.byteOffset, unit.byteLength), at, at);
51
54
  database
52
55
  .prepare(`INSERT INTO chunks (chunkable_type, chunkable_id, position, start_offset, end_offset, content_hash, scope,
53
56
  account_id, occurred_at, created_at, updated_at) VALUES (?, ?, 0, 0, ?, ?, ?, ?, ?, ?, ?)`)
@@ -7,13 +7,48 @@ import {
7
7
  SQLiteAsyncSession,
8
8
  SQLiteAsyncTransaction,
9
9
  SQLiteDialect,
10
+ booleanFromInteger,
11
+ bufferFromBytes,
12
+ castToText,
13
+ dateFromStoredMilliseconds,
14
+ dateFromStoredSeconds,
10
15
  entityKind,
11
16
  jitCompatCheck,
17
+ refineSqliteCodecs,
12
18
  sql
13
- } from "./shared-HKXF6HKX.js";
19
+ } from "./shared-55XJMTPA.js";
14
20
 
15
- // node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.7/node_modules/drizzle-orm/bun-sqlite/session.js
21
+ // node_modules/.pnpm/drizzle-orm@1.0.0-rc.5_@opentelemetry+api@1.10.0_valibot@1.5.0_typescript@7.0.2__zod@4.6.7/node_modules/drizzle-orm/bun-sqlite/codecs.js
22
+ var bunSQLiteCodecs = refineSqliteCodecs({
23
+ "integer:boolean": { normalize: booleanFromInteger },
24
+ "integer:timestamp": { normalize: dateFromStoredSeconds },
25
+ "integer:timestamp_ms": { normalize: dateFromStoredMilliseconds },
26
+ "text:json": { normalize: JSON.parse },
27
+ blob: { normalize: bufferFromBytes },
28
+ "blob:json": {
29
+ cast: castToText,
30
+ normalize: JSON.parse
31
+ },
32
+ "blob:bigint": {
33
+ cast: castToText,
34
+ normalize: BigInt
35
+ },
36
+ numeric: {
37
+ cast: castToText,
38
+ normalize: String
39
+ },
40
+ "numeric:number": { normalize: Number },
41
+ "numeric:bigint": {
42
+ cast: castToText,
43
+ normalize: BigInt
44
+ }
45
+ });
46
+
47
+ // node_modules/.pnpm/drizzle-orm@1.0.0-rc.5_@opentelemetry+api@1.10.0_valibot@1.5.0_typescript@7.0.2__zod@4.6.7/node_modules/drizzle-orm/bun-sqlite/session.js
16
48
  var SQLiteBunSession = class extends SQLiteAsyncSession {
49
+ client;
50
+ relations;
51
+ options;
17
52
  static [entityKind] = "SQLiteBunSession";
18
53
  logger;
19
54
  constructor(client, dialect, relations, options = {}) {
@@ -31,7 +66,7 @@ var SQLiteBunSession = class extends SQLiteAsyncSession {
31
66
  try {
32
67
  stmt = this.client.query(query.sql);
33
68
  } catch (e) {
34
- throw new DrizzleQueryError(query.sql, query.params, e);
69
+ throw new DrizzleQueryError(query.sql, this.options.paramsInErrors ? query.params : void 0, e);
35
70
  }
36
71
  return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
37
72
  all: (params) => {
@@ -44,18 +79,17 @@ var SQLiteBunSession = class extends SQLiteAsyncSession {
44
79
  },
45
80
  run: (params) => {
46
81
  return stmt.run(...params);
47
- },
48
- values: (params) => {
49
- return stmt.values(...params);
50
82
  }
51
- }, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
83
+ }, query, mapper, mode, this.logger, void 0, queryMetadata, void 0, this.options.paramsInErrors);
52
84
  }
53
85
  transaction(transaction, config = {}) {
54
86
  const tx = new SQLiteBunTransaction("sync", this.dialect, this, this.relations);
55
87
  let result;
56
- this.client.transaction(() => {
88
+ const nativeTx = this.client.transaction(() => {
57
89
  result = transaction(tx);
58
- })[config.behavior ?? "deferred"]();
90
+ });
91
+ if (config.behavior === "concurrent") throw new Error("Concurrent transactions are not supported by driver");
92
+ nativeTx[config.behavior ?? "deferred"]();
59
93
  return result;
60
94
  }
61
95
  };
@@ -70,24 +104,33 @@ var SQLiteBunTransaction = class SQLiteBunTransaction2 extends SQLiteAsyncTransa
70
104
  this.session.run(sql.raw(`release savepoint ${savepointName}`));
71
105
  return result;
72
106
  } catch (err) {
73
- this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));
107
+ try {
108
+ this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));
109
+ } catch {
110
+ }
74
111
  throw err;
75
112
  }
76
113
  }
77
114
  };
78
115
 
79
- // node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.7/node_modules/drizzle-orm/bun-sqlite/driver.js
116
+ // node_modules/.pnpm/drizzle-orm@1.0.0-rc.5_@opentelemetry+api@1.10.0_valibot@1.5.0_typescript@7.0.2__zod@4.6.7/node_modules/drizzle-orm/bun-sqlite/driver.js
80
117
  import { Database } from "bun:sqlite";
81
118
  var SQLiteBunDatabase = class extends SQLiteAsyncDatabase {
82
119
  static [entityKind] = "SQLiteBunDatabase";
83
120
  };
84
121
  function construct(client, config = {}) {
85
- const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config.jit) });
122
+ const dialect = new SQLiteDialect({
123
+ codecs: config.codecs ?? bunSQLiteCodecs,
124
+ useJitMappers: jitCompatCheck(config.jit)
125
+ });
86
126
  let logger;
87
127
  if (config.logger === true) logger = new DefaultLogger();
88
128
  else if (config.logger !== false) logger = config.logger;
89
129
  const relations = config.relations ?? {};
90
- const db = new SQLiteBunDatabase("sync", dialect, new SQLiteBunSession(client, dialect, relations, { logger }), relations);
130
+ const db = new SQLiteBunDatabase("sync", dialect, new SQLiteBunSession(client, dialect, relations, {
131
+ logger,
132
+ paramsInErrors: config.paramsInErrors
133
+ }), relations);
91
134
  db.$client = client;
92
135
  return db;
93
136
  }
@@ -97,7 +140,8 @@ function drizzle(...params) {
97
140
  if (client) return construct(client, DrizzleSQLiteConfig);
98
141
  if (typeof connection === "object") {
99
142
  const { source, ...opts } = connection;
100
- return construct(new Database(source, Object.values(opts).filter((v) => v !== void 0).length ? opts : void 0), DrizzleSQLiteConfig);
143
+ const options = Object.values(opts).filter((v) => v !== void 0).length ? opts : void 0;
144
+ return construct(new Database(source, options), DrizzleSQLiteConfig);
101
145
  }
102
146
  return construct(new Database(connection), DrizzleSQLiteConfig);
103
147
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.7/node_modules/src/bun-sqlite/session.ts", "../../../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_valibot@1.5.0_typescript@7.0.2__zod@4.6.7/node_modules/src/bun-sqlite/driver.ts"],
4
- "sourcesContent": ["/// <reference types=\"bun-types\" />\n\nimport type { Changes, Database } from 'bun:sqlite';\nimport { entityKind } from '~/entity.ts';\nimport { DrizzleQueryError } from '~/errors.ts';\nimport type { Logger } from '~/logger.ts';\nimport { NoopLogger } from '~/logger.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport { type Query, sql } from '~/sql/sql.ts';\nimport {\n\tSQLiteAsyncPreparedQuery,\n\ttype SQLiteAsyncPreparedQueryConfig as PreparedQueryConfigBase,\n\tSQLiteAsyncSession,\n\tSQLiteAsyncTransaction,\n\ttype SQLiteQueryExecutors,\n} from '~/sqlite-core/async/session.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { SQLiteExecuteMethod, SQLiteTransactionConfig } from '~/sqlite-core/session.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\n\nexport interface SQLiteBunSessionOptions {\n\tlogger?: Logger;\n\tcache?: Cache;\n}\n\nexport type SQLiteBunRunResult = Changes;\n\ntype PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;\n\nexport class SQLiteBunSession<TRelations extends AnyRelations>\n\textends SQLiteAsyncSession<'sync', SQLiteBunRunResult, TRelations>\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteBunSession';\n\n\tprivate logger: Logger;\n\n\tconstructor(\n\t\tprivate client: Database,\n\t\tdialect: SQLiteDialect,\n\t\tprivate relations: TRelations,\n\t\tprivate options: SQLiteBunSessionOptions = {},\n\t) {\n\t\tsuper(dialect, 'sync');\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t}\n\n\texec(query: string): void {\n\t\tthis.client.exec(query);\n\t}\n\n\tprepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(\n\t\tquery: Query,\n\t\tmode: 'arrays' | 'objects' | 'raw',\n\t\t_prepare: boolean,\n\t\texecuteMethod?: SQLiteExecuteMethod,\n\t\tmapper?: (rows: any[]) => any,\n\t\tqueryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t},\n\t): SQLiteAsyncPreparedQuery<T & { run: SQLiteBunRunResult }> {\n\t\tlet stmt: ReturnType<typeof this.client.query>;\n\t\ttry {\n\t\t\tstmt = this.client.query(query.sql);\n\t\t} catch (e) {\n\t\t\tthrow new DrizzleQueryError(query.sql, query.params, e as Error);\n\t\t}\n\t\tconst executors: SQLiteQueryExecutors<'sync'> = {\n\t\t\tall: (params) => {\n\t\t\t\tif (mode === 'arrays') return stmt.values(...params as any[]);\n\t\t\t\treturn stmt.all(...params as any[]);\n\t\t\t},\n\t\t\tget: (params) => {\n\t\t\t\tif (mode === 'arrays') return stmt.values(...params as any[])[0];\n\t\t\t\treturn stmt.get(...params as any[]);\n\t\t\t},\n\t\t\trun: (params) => {\n\t\t\t\treturn stmt.run(...params as any[]);\n\t\t\t},\n\t\t\tvalues: (params) => {\n\t\t\t\treturn stmt.values(...params as any[]);\n\t\t\t},\n\t\t};\n\n\t\treturn new SQLiteAsyncPreparedQuery(\n\t\t\t'sync',\n\t\t\texecuteMethod,\n\t\t\texecutors,\n\t\t\tquery,\n\t\t\tmapper,\n\t\t\tmode,\n\t\t\tthis.logger,\n\t\t\tundefined,\n\t\t\tqueryMetadata,\n\t\t\tundefined,\n\t\t);\n\t}\n\n\toverride transaction<T>(\n\t\ttransaction: (tx: SQLiteBunTransaction<TRelations>) => T,\n\t\tconfig: SQLiteTransactionConfig = {},\n\t): T {\n\t\tconst tx = new SQLiteBunTransaction('sync', this.dialect, this, this.relations);\n\t\tlet result: T | undefined;\n\t\tconst nativeTx = this.client.transaction(() => {\n\t\t\tresult = transaction(tx);\n\t\t});\n\t\tnativeTx[config.behavior ?? 'deferred']();\n\t\treturn result!;\n\t}\n}\n\nexport class SQLiteBunTransaction<\n\tTRelations extends AnyRelations,\n> extends SQLiteAsyncTransaction<'sync', SQLiteBunRunResult, TRelations> {\n\tstatic override readonly [entityKind]: string = 'SQLiteBunTransaction';\n\n\toverride transaction<T>(\n\t\ttransaction: (\n\t\t\ttx: SQLiteBunTransaction<TRelations>,\n\t\t) => T extends Promise<any> ? DrizzleTypeError<\"Sync drivers can't use async functions in transactions!\">\n\t\t\t: T,\n\t): T {\n\t\tconst savepointName = `sp${this.nestedIndex}`;\n\t\tconst tx = new SQLiteBunTransaction(\n\t\t\t'sync',\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tthis._.relations,\n\t\t\tthis.nestedIndex + 1,\n\t\t);\n\t\tthis.session.run(sql.raw(`savepoint ${savepointName}`));\n\t\ttry {\n\t\t\tconst result = transaction(tx);\n\t\t\tthis.session.run(sql.raw(`release savepoint ${savepointName}`));\n\t\t\treturn result as T;\n\t\t} catch (err) {\n\t\t\tthis.session.run(sql.raw(`rollback to savepoint ${savepointName}`));\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n", "/// <reference types=\"bun-types\" />\n\nimport { Database } from 'bun:sqlite';\nimport { entityKind } from '~/entity.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport type { AnyRelations, EmptyRelations } from '~/relations.ts';\nimport { SQLiteAsyncDatabase } from '~/sqlite-core/async/db.ts';\nimport { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { DrizzleSQLiteConfig } from '~/sqlite-core/utils.ts';\nimport { jitCompatCheck } from '~/utils.ts';\nimport { type SQLiteBunRunResult, SQLiteBunSession } from './session.ts';\n\nexport class SQLiteBunDatabase<\n\tTRelations extends AnyRelations = EmptyRelations,\n> extends SQLiteAsyncDatabase<'sync', SQLiteBunRunResult, TRelations> {\n\tstatic override readonly [entityKind]: string = 'SQLiteBunDatabase';\n}\n\ntype DrizzleSqliteBunDatabaseOptions = {\n\t/**\n\t * Open the database as read-only (no write operations, no create).\n\t *\n\t * Equivalent to {@link constants.SQLITE_OPEN_READONLY}\n\t */\n\treadonly?: boolean;\n\t/**\n\t * Allow creating a new database\n\t *\n\t * Equivalent to {@link constants.SQLITE_OPEN_CREATE}\n\t */\n\tcreate?: boolean;\n\t/**\n\t * Open the database as read-write\n\t *\n\t * Equivalent to {@link constants.SQLITE_OPEN_READWRITE}\n\t */\n\treadwrite?: boolean;\n};\n\nexport type DrizzleBunSqliteDatabaseConfig =\n\t| ({\n\t\tsource?: string;\n\t} & DrizzleSqliteBunDatabaseOptions)\n\t| string\n\t| undefined;\n\nfunction construct<\n\tTRelations extends AnyRelations = EmptyRelations,\n>(\n\tclient: Database,\n\tconfig: DrizzleSQLiteConfig<TRelations> = {},\n): SQLiteBunDatabase<TRelations> & {\n\t$client: Database;\n} {\n\tconst dialect = new SQLiteDialect({\n\t\tuseJitMappers: jitCompatCheck(config.jit),\n\t});\n\tlet logger;\n\tif (config.logger === true) {\n\t\tlogger = new DefaultLogger();\n\t} else if (config.logger !== false) {\n\t\tlogger = config.logger;\n\t}\n\n\tconst relations = config.relations ?? {} as TRelations;\n\tconst session = new SQLiteBunSession<TRelations>(\n\t\tclient,\n\t\tdialect,\n\t\trelations,\n\t\t{\n\t\t\tlogger,\n\t\t},\n\t);\n\tconst db = new SQLiteBunDatabase('sync', dialect, session, relations);\n\t(<any> db).$client = client;\n\n\treturn db as any;\n}\n\nexport function drizzle<\n\tTRelations extends AnyRelations = EmptyRelations,\n\tTClient extends Database = Database,\n>(\n\t...params:\n\t\t| []\n\t\t| [\n\t\t\tstring,\n\t\t]\n\t\t| [\n\t\t\tstring,\n\t\t\tDrizzleSQLiteConfig<TRelations>,\n\t\t]\n\t\t| [\n\t\t\t(\n\t\t\t\t& DrizzleSQLiteConfig<TRelations>\n\t\t\t\t& ({\n\t\t\t\t\tconnection?: DrizzleBunSqliteDatabaseConfig;\n\t\t\t\t} | {\n\t\t\t\t\tclient: TClient;\n\t\t\t\t})\n\t\t\t),\n\t\t]\n): SQLiteBunDatabase<TRelations> & {\n\t$client: TClient;\n} {\n\tif (params[0] === undefined || typeof params[0] === 'string') {\n\t\tconst instance = params[0] === undefined ? new Database() : new Database(params[0]);\n\n\t\treturn construct(instance, params[1]) as any;\n\t}\n\n\tconst { connection, client, ...DrizzleSQLiteConfig } = params[0] as\n\t\t& ({\n\t\t\tconnection?: DrizzleBunSqliteDatabaseConfig | string;\n\t\t\tclient?: TClient;\n\t\t})\n\t\t& DrizzleSQLiteConfig<TRelations>;\n\n\tif (client) return construct(client, DrizzleSQLiteConfig) as any;\n\n\tif (typeof connection === 'object') {\n\t\tconst { source, ...opts } = connection;\n\n\t\tconst options = Object.values(opts).filter((v) => v !== undefined).length ? opts : undefined;\n\n\t\tconst instance = new Database(source, options);\n\n\t\treturn construct(instance, DrizzleSQLiteConfig) as any;\n\t}\n\n\tconst instance = new Database(connection);\n\n\treturn construct(instance, DrizzleSQLiteConfig) as any;\n}\n\nexport namespace drizzle {\n\texport function mock<TRelations extends AnyRelations = EmptyRelations>(\n\t\tconfig?: DrizzleSQLiteConfig<TRelations>,\n\t): SQLiteBunDatabase<TRelations> & {\n\t\t$client: '$client is not available on drizzle.mock()';\n\t} {\n\t\treturn construct({} as any, config) as any;\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;AA6BA,IAAa,mBAAb,cACS,mBACT;EACC,QAA0B,UAAA,IAAsB;EAExC;EAER,YACS,QACR,SACQ,WACA,UAAmC,CAAA,GAC1C;AACD,UAAM,SAAS,MAAA;AALP,SAAA,SAAA;AAEA,SAAA,YAAA;AAC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AAA,GAEH,mBAAA;;;AAIpB,WAAS,KACf,QAGC;AACD,WAAO,UAAU,CAAA,GAAW,MAAA;;;;",
3
+ "sources": ["../../../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.5_@opentelemetry+api@1.10.0_valibot@1.5.0_typescript@7.0.2__zod@4.6.7/node_modules/src/bun-sqlite/codecs.ts", "../../../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.5_@opentelemetry+api@1.10.0_valibot@1.5.0_typescript@7.0.2__zod@4.6.7/node_modules/src/bun-sqlite/session.ts", "../../../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.5_@opentelemetry+api@1.10.0_valibot@1.5.0_typescript@7.0.2__zod@4.6.7/node_modules/src/bun-sqlite/driver.ts"],
4
+ "sourcesContent": ["import {\n\tbooleanFromInteger,\n\tbufferFromBytes,\n\tcastToText,\n\tdateFromStoredMilliseconds,\n\tdateFromStoredSeconds,\n\trefineSqliteCodecs,\n} from '~/sqlite-core/codecs.ts';\n\nexport const bunSQLiteCodecs = refineSqliteCodecs({\n\t'integer:boolean': {\n\t\tnormalize: booleanFromInteger,\n\t},\n\t'integer:timestamp': {\n\t\tnormalize: dateFromStoredSeconds,\n\t},\n\t'integer:timestamp_ms': {\n\t\tnormalize: dateFromStoredMilliseconds,\n\t},\n\t'text:json': {\n\t\tnormalize: JSON.parse,\n\t},\n\tblob: {\n\t\tnormalize: bufferFromBytes,\n\t},\n\t'blob:json': {\n\t\tcast: castToText,\n\t\tnormalize: JSON.parse,\n\t},\n\t'blob:bigint': {\n\t\tcast: castToText,\n\t\tnormalize: BigInt,\n\t},\n\tnumeric: {\n\t\tcast: castToText,\n\t\tnormalize: String,\n\t},\n\t'numeric:number': {\n\t\tnormalize: Number,\n\t},\n\t'numeric:bigint': {\n\t\tcast: castToText,\n\t\tnormalize: BigInt,\n\t},\n});\n", "/// <reference types=\"bun-types\" />\n\nimport type { Changes, Database } from 'bun:sqlite';\nimport type { QueryMetadata } from '~/cache/core/types.ts';\nimport { entityKind } from '~/entity.ts';\nimport { DrizzleQueryError } from '~/errors.ts';\nimport type { Logger } from '~/logger.ts';\nimport { NoopLogger } from '~/logger.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport { type Query, sql } from '~/sql/sql.ts';\nimport {\n\tSQLiteAsyncPreparedQuery,\n\ttype SQLiteAsyncPreparedQueryConfig as PreparedQueryConfigBase,\n\tSQLiteAsyncSession,\n\tSQLiteAsyncTransaction,\n\ttype SQLiteQueryExecutors,\n} from '~/sqlite-core/async/session.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { SQLiteExecuteMethod, SQLiteTransactionConfig } from '~/sqlite-core/session.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\n\nexport interface SQLiteBunSessionOptions {\n\tlogger?: Logger;\n\tcache?: Cache;\n\tparamsInErrors?: boolean;\n}\n\nexport type SQLiteBunRunResult = Changes;\n\ntype PreparedQueryConfig = Omit<PreparedQueryConfigBase, 'statement' | 'run'>;\n\nexport class SQLiteBunSession<TRelations extends AnyRelations>\n\textends SQLiteAsyncSession<'sync', SQLiteBunRunResult, TRelations>\n{\n\tstatic override readonly [entityKind]: string = 'SQLiteBunSession';\n\n\tprivate logger: Logger;\n\n\tconstructor(\n\t\tprivate client: Database,\n\t\tdialect: SQLiteDialect,\n\t\tprivate relations: TRelations,\n\t\tprivate options: SQLiteBunSessionOptions = {},\n\t) {\n\t\tsuper(dialect, 'sync');\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t}\n\n\texec(query: string): void {\n\t\tthis.client.exec(query);\n\t}\n\n\tprepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(\n\t\tquery: Query,\n\t\tmode: 'arrays' | 'objects' | 'raw',\n\t\t_prepare: boolean,\n\t\texecuteMethod?: SQLiteExecuteMethod,\n\t\tmapper?: (rows: any[]) => any,\n\t\tqueryMetadata?: QueryMetadata,\n\t): SQLiteAsyncPreparedQuery<T & { run: SQLiteBunRunResult }> {\n\t\tlet stmt: ReturnType<typeof this.client.query>;\n\t\ttry {\n\t\t\tstmt = this.client.query(query.sql);\n\t\t} catch (e) {\n\t\t\tthrow new DrizzleQueryError(query.sql, this.options.paramsInErrors ? query.params : undefined, e as Error);\n\t\t}\n\t\tconst executors: SQLiteQueryExecutors<'sync'> = {\n\t\t\tall: (params) => {\n\t\t\t\tif (mode === 'arrays') return stmt.values(...params as any[]);\n\t\t\t\treturn stmt.all(...params as any[]);\n\t\t\t},\n\t\t\tget: (params) => {\n\t\t\t\tif (mode === 'arrays') return stmt.values(...params as any[])[0];\n\t\t\t\treturn stmt.get(...params as any[]);\n\t\t\t},\n\t\t\trun: (params) => {\n\t\t\t\treturn stmt.run(...params as any[]);\n\t\t\t},\n\t\t};\n\n\t\treturn new SQLiteAsyncPreparedQuery(\n\t\t\t'sync',\n\t\t\texecuteMethod,\n\t\t\texecutors,\n\t\t\tquery,\n\t\t\tmapper,\n\t\t\tmode,\n\t\t\tthis.logger,\n\t\t\tundefined,\n\t\t\tqueryMetadata,\n\t\t\tundefined,\n\t\t\tthis.options.paramsInErrors,\n\t\t);\n\t}\n\n\toverride transaction<T>(\n\t\ttransaction: (tx: SQLiteBunTransaction<TRelations>) => T,\n\t\tconfig: SQLiteTransactionConfig = {},\n\t): T {\n\t\tconst tx = new SQLiteBunTransaction('sync', this.dialect, this, this.relations);\n\t\tlet result: T | undefined;\n\t\tconst nativeTx = this.client.transaction(() => {\n\t\t\tresult = transaction(tx);\n\t\t});\n\t\tif (config.behavior === 'concurrent') throw new Error('Concurrent transactions are not supported by driver');\n\t\tnativeTx[config.behavior ?? 'deferred']();\n\t\treturn result!;\n\t}\n}\n\nexport class SQLiteBunTransaction<\n\tTRelations extends AnyRelations,\n> extends SQLiteAsyncTransaction<'sync', SQLiteBunRunResult, TRelations> {\n\tstatic override readonly [entityKind]: string = 'SQLiteBunTransaction';\n\n\toverride transaction<T>(\n\t\ttransaction: (\n\t\t\ttx: SQLiteBunTransaction<TRelations>,\n\t\t) => T extends Promise<any> ? DrizzleTypeError<\"Sync drivers can't use async functions in transactions!\">\n\t\t\t: T,\n\t): T {\n\t\tconst savepointName = `sp${this.nestedIndex}`;\n\t\tconst tx = new SQLiteBunTransaction(\n\t\t\t'sync',\n\t\t\tthis.dialect,\n\t\t\tthis.session,\n\t\t\tthis._.relations,\n\t\t\tthis.nestedIndex + 1,\n\t\t);\n\t\tthis.session.run(sql.raw(`savepoint ${savepointName}`));\n\t\ttry {\n\t\t\tconst result = transaction(tx);\n\t\t\tthis.session.run(sql.raw(`release savepoint ${savepointName}`));\n\t\t\treturn result as T;\n\t\t} catch (err) {\n\t\t\ttry {\n\t\t\t\tthis.session.run(sql.raw(`rollback to savepoint ${savepointName}`));\n\t\t\t} catch {\n\t\t\t\t// original error takes priority\n\t\t\t}\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n", "/// <reference types=\"bun-types\" />\n\nimport { Database } from 'bun:sqlite';\nimport { entityKind } from '~/entity.ts';\nimport { DefaultLogger } from '~/logger.ts';\nimport type { AnyRelations, EmptyRelations } from '~/relations.ts';\nimport { SQLiteAsyncDatabase } from '~/sqlite-core/async/db.ts';\nimport { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { DrizzleSQLiteConfig } from '~/sqlite-core/utils.ts';\nimport { jitCompatCheck } from '~/utils.ts';\nimport { bunSQLiteCodecs } from './codecs.ts';\nimport { type SQLiteBunRunResult, SQLiteBunSession } from './session.ts';\n\nexport class SQLiteBunDatabase<\n\tTRelations extends AnyRelations = EmptyRelations,\n> extends SQLiteAsyncDatabase<'sync', SQLiteBunRunResult, TRelations> {\n\tstatic override readonly [entityKind]: string = 'SQLiteBunDatabase';\n}\n\ntype DrizzleSqliteBunDatabaseOptions = {\n\t/**\n\t * Open the database as read-only (no write operations, no create).\n\t *\n\t * Equivalent to {@link constants.SQLITE_OPEN_READONLY}\n\t */\n\treadonly?: boolean;\n\t/**\n\t * Allow creating a new database\n\t *\n\t * Equivalent to {@link constants.SQLITE_OPEN_CREATE}\n\t */\n\tcreate?: boolean;\n\t/**\n\t * Open the database as read-write\n\t *\n\t * Equivalent to {@link constants.SQLITE_OPEN_READWRITE}\n\t */\n\treadwrite?: boolean;\n};\n\nexport type DrizzleBunSqliteDatabaseConfig =\n\t| ({\n\t\tsource?: string;\n\t} & DrizzleSqliteBunDatabaseOptions)\n\t| string\n\t| undefined;\n\nfunction construct<\n\tTRelations extends AnyRelations = EmptyRelations,\n>(\n\tclient: Database,\n\tconfig: DrizzleSQLiteConfig<TRelations> = {},\n): SQLiteBunDatabase<TRelations> & {\n\t$client: Database;\n} {\n\tconst dialect = new SQLiteDialect({\n\t\tcodecs: config.codecs ?? bunSQLiteCodecs,\n\t\tuseJitMappers: jitCompatCheck(config.jit),\n\t});\n\tlet logger;\n\tif (config.logger === true) {\n\t\tlogger = new DefaultLogger();\n\t} else if (config.logger !== false) {\n\t\tlogger = config.logger;\n\t}\n\n\tconst relations = config.relations ?? {} as TRelations;\n\tconst session = new SQLiteBunSession<TRelations>(\n\t\tclient,\n\t\tdialect,\n\t\trelations,\n\t\t{\n\t\t\tlogger,\n\t\t\tparamsInErrors: config.paramsInErrors,\n\t\t},\n\t);\n\tconst db = new SQLiteBunDatabase('sync', dialect, session, relations);\n\t(<any> db).$client = client;\n\n\treturn db as any;\n}\n\nexport function drizzle<\n\tTRelations extends AnyRelations = EmptyRelations,\n\tTClient extends Database = Database,\n>(\n\t...params:\n\t\t| []\n\t\t| [\n\t\t\tstring,\n\t\t]\n\t\t| [\n\t\t\tstring,\n\t\t\tDrizzleSQLiteConfig<TRelations>,\n\t\t]\n\t\t| [\n\t\t\t(\n\t\t\t\t& DrizzleSQLiteConfig<TRelations>\n\t\t\t\t& ({\n\t\t\t\t\tconnection?: DrizzleBunSqliteDatabaseConfig;\n\t\t\t\t} | {\n\t\t\t\t\tclient: TClient;\n\t\t\t\t})\n\t\t\t),\n\t\t]\n): SQLiteBunDatabase<TRelations> & {\n\t$client: TClient;\n} {\n\tif (params[0] === undefined || typeof params[0] === 'string') {\n\t\tconst instance = params[0] === undefined ? new Database() : new Database(params[0]);\n\n\t\treturn construct(instance, params[1]) as any;\n\t}\n\n\tconst { connection, client, ...DrizzleSQLiteConfig } = params[0] as\n\t\t& ({\n\t\t\tconnection?: DrizzleBunSqliteDatabaseConfig | string;\n\t\t\tclient?: TClient;\n\t\t})\n\t\t& DrizzleSQLiteConfig<TRelations>;\n\n\tif (client) return construct(client, DrizzleSQLiteConfig) as any;\n\n\tif (typeof connection === 'object') {\n\t\tconst { source, ...opts } = connection;\n\n\t\tconst options = Object.values(opts).filter((v) => v !== undefined).length ? opts : undefined;\n\n\t\tconst instance = new Database(source, options);\n\n\t\treturn construct(instance, DrizzleSQLiteConfig) as any;\n\t}\n\n\tconst instance = new Database(connection);\n\n\treturn construct(instance, DrizzleSQLiteConfig) as any;\n}\n\nexport namespace drizzle {\n\texport function mock<TRelations extends AnyRelations = EmptyRelations>(\n\t\tconfig?: DrizzleSQLiteConfig<TRelations>,\n\t): SQLiteBunDatabase<TRelations> & {\n\t\t$client: '$client is not available on drizzle.mock()';\n\t} {\n\t\treturn construct({} as any, config) as any;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AASA,IAAa,kBAAkB,mBAAmB;EACjD,mBAAmB,EAClB,WAAW,mBACZ;EACA,qBAAqB,EACpB,WAAW,sBACZ;EACA,wBAAwB,EACvB,WAAW,2BACZ;EACA,aAAa,EACZ,WAAW,KAAK,MACjB;EACA,MAAM,EACL,WAAW,gBACZ;EACA,aAAa;IACZ,MAAM;IACN,WAAW,KAAK;EACjB;EACA,eAAe;IACd,MAAM;IACN,WAAW;EACZ;EACA,SAAS;IACR,MAAM;IACN,WAAW;EACZ;EACA,kBAAkB,EACjB,WAAW,OACZ;EACA,kBAAkB;IACjB,MAAM;IACN,WAAW;EACZ;AACD,CAAC;;;ACbD,IAAa,mBAAb,cACS,mBACT;EAMU;EAEA;EACA;EART,QAA0B,UAAA,IAAs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