viborm 1.0.0-rc.2 → 1.0.0-rc.3
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 +2 -2
- package/dist/adapters.d.mts +1 -1
- package/dist/adapters.mjs +1 -1
- package/dist/bun-sql.d.mts +1 -1
- package/dist/bun-sql.mjs +1 -1
- package/dist/bun-sql.mjs.map +1 -1
- package/dist/bun-sqlite.d.mts +1 -1
- package/dist/bun-sqlite.mjs +1 -1
- package/dist/bun-sqlite.mjs.map +1 -1
- package/dist/cache/cloudflare-kv.d.mts +1 -1
- package/dist/cache/cloudflare-kv.mjs +1 -1
- package/dist/cache/memory.d.mts +1 -1
- package/dist/cache/memory.mjs +1 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cache.mjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{client-C6g-wpU_.mjs → client-CinIwjZb.mjs} +2 -2
- package/dist/{client-C6g-wpU_.mjs.map → client-CinIwjZb.mjs.map} +1 -1
- package/dist/client.d.mts +3 -3
- package/dist/client.mjs +1 -1
- package/dist/config.d.mts +2 -2
- package/dist/{contract-jAZ95pZ5.d.mts → contract-d8tNa7GK.d.mts} +1 -1
- package/dist/d1.d.mts +1 -1
- package/dist/d1.mjs +1 -1
- package/dist/d1.mjs.map +1 -1
- package/dist/{driver-B7rrn6zq.mjs → driver-BRdxOENW.mjs} +2 -2
- package/dist/{driver-B7rrn6zq.mjs.map → driver-BRdxOENW.mjs.map} +1 -1
- package/dist/{driver-Cpluw-nE.mjs → driver-D38HdVs0.mjs} +2 -2
- package/dist/{driver-Cpluw-nE.mjs.map → driver-D38HdVs0.mjs.map} +1 -1
- package/dist/driver.d.mts +1 -2
- package/dist/driver.mjs +1 -1
- package/dist/{extension-k9VoiK58.mjs → extension-BIlBePzL.mjs} +2 -2
- package/dist/{extension-k9VoiK58.mjs.map → extension-BIlBePzL.mjs.map} +1 -1
- package/dist/{extension-B1Daewmr.mjs → extension-RO4080gs.mjs} +2 -2
- package/dist/{extension-B1Daewmr.mjs.map → extension-RO4080gs.mjs.map} +1 -1
- package/dist/{fs-estate-B4hLZOp1.d.mts → fs-estate-DsE8tYPI.d.mts} +2 -2
- package/dist/{index-ChhK6Q53.d.mts → index-C6dJH318.d.mts} +400 -3
- package/dist/{index-RtRFAdIS.d.mts → index-CjWoDLqn.d.mts} +4 -57
- package/dist/index.d.mts +4 -5
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/instrumentation.d.mts +1 -1
- package/dist/instrumentation.mjs +1 -1
- package/dist/libsql.d.mts +1 -1
- package/dist/libsql.mjs +1 -1
- package/dist/libsql.mjs.map +1 -1
- package/dist/migrations/storage/fs.d.mts +1 -1
- package/dist/migrations.d.mts +4 -59
- package/dist/mysql2.d.mts +1 -1
- package/dist/mysql2.mjs +1 -1
- package/dist/mysql2.mjs.map +1 -1
- package/dist/neon-http.d.mts +1 -1
- package/dist/neon-http.mjs +1 -1
- package/dist/neon-http.mjs.map +1 -1
- package/dist/pg.d.mts +1 -1
- package/dist/pg.mjs +1 -1
- package/dist/pg.mjs.map +1 -1
- package/dist/pglite.d.mts +1 -1
- package/dist/pglite.mjs +1 -1
- package/dist/pglite.mjs.map +1 -1
- package/dist/planetscale.d.mts +1 -1
- package/dist/planetscale.mjs +1 -1
- package/dist/planetscale.mjs.map +1 -1
- package/dist/postgres.d.mts +1 -1
- package/dist/postgres.mjs +1 -1
- package/dist/postgres.mjs.map +1 -1
- package/dist/{result-shape-CoFkQif_.mjs → result-shape-D5SRtoVx.mjs} +2 -2
- package/dist/{result-shape-CoFkQif_.mjs.map → result-shape-D5SRtoVx.mjs.map} +1 -1
- package/dist/schema/json.d.mts +2 -2
- package/dist/{schema-introspection-Chr4x7p3.mjs → schema-introspection-C-2uBrBZ.mjs} +2 -2
- package/dist/{schema-introspection-Chr4x7p3.mjs.map → schema-introspection-C-2uBrBZ.mjs.map} +1 -1
- package/dist/{schema-introspection-DPKy4QnW.d.mts → schema-introspection-CXJZi4X7.d.mts} +2 -2
- package/dist/schema.d.mts +4 -4
- package/dist/sqlite3.d.mts +1 -1
- package/dist/sqlite3.mjs +1 -1
- package/dist/sqlite3.mjs.map +1 -1
- package/dist/{string-CBx6pS96.d.mts → string-CampokWL.d.mts} +3 -3
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/dist/version-BG9YFoe_.mjs +2 -0
- package/dist/{version-Bg5wI5xl.mjs.map → version-BG9YFoe_.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/transaction-07XaHy-w.d.mts +0 -283
- package/dist/version-Bg5wI5xl.mjs +0 -2
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@ Type-safe TypeScript ORM with **zero code generation**. Types are inferred from
|
|
|
4
4
|
|
|
5
5
|
## V1 release candidate
|
|
6
6
|
|
|
7
|
-
This source prepares `1.0.0-rc.
|
|
8
|
-
The preceding `1.0.0-rc.
|
|
7
|
+
This source prepares `1.0.0-rc.3`; it does not mean that candidate is published.
|
|
8
|
+
The preceding `1.0.0-rc.2` is published. Install an exact published candidate
|
|
9
9
|
for reproducible evaluation; `next` follows the latest published RC.
|
|
10
10
|
V1 includes breaking changes. Read the [upgrade guide](docs/content/docs/getting-started/upgrading-to-v1.mdx)
|
|
11
11
|
and [changelog](CHANGELOG.md) before migrating. Node.js 22 or newer and
|
package/dist/adapters.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as MySQLAdapter, i as postgresAdapter, n as sqliteAdapter, o as mysqlAdapter, r as PostgresAdapter, s as DatabaseAdapter, t as SQLiteAdapter } from "./index-
|
|
1
|
+
import { a as MySQLAdapter, i as postgresAdapter, n as sqliteAdapter, o as mysqlAdapter, r as PostgresAdapter, s as DatabaseAdapter, t as SQLiteAdapter } from "./index-C6dJH318.mjs";
|
|
2
2
|
export { DatabaseAdapter, MySQLAdapter, PostgresAdapter, SQLiteAdapter, mysqlAdapter, postgresAdapter, sqliteAdapter };
|
package/dist/adapters.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./geo-point-codec-BTDzc-ym.mjs";import
|
|
1
|
+
import"./geo-point-codec-BTDzc-ym.mjs";import{n as e,t}from"./postgres-adapter-DDvmW2rG.mjs";import{n,t as r}from"./mysql-adapter-DfAF6Hd0.mjs";import{n as i,t as a}from"./sqlite-adapter-3v4Bg8iy.mjs";export{r as MySQLAdapter,t as PostgresAdapter,a as SQLiteAdapter,n as mysqlAdapter,e as postgresAdapter,i as sqliteAdapter};
|
package/dist/bun-sql.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { At as BunSQLDriverOptions, Mt as createClient, Ot as BunSQLClientConfig, jt as BunSQLOptions, kt as BunSQLDriver } from "./index-
|
|
1
|
+
import { At as BunSQLDriverOptions, Mt as createClient, Ot as BunSQLClientConfig, jt as BunSQLOptions, kt as BunSQLDriver } from "./index-C6dJH318.mjs";
|
|
2
2
|
export { BunSQLClientConfig, BunSQLDriver, BunSQLDriverOptions, BunSQLOptions, createClient };
|
package/dist/bun-sql.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as e}from"./clock-DHSN2GNk.mjs";import{p as t}from"./query-CRk65A10.mjs";import"./
|
|
1
|
+
import{c as e}from"./clock-DHSN2GNk.mjs";import{p as t}from"./query-CRk65A10.mjs";import"./v-DdH9EVw3.mjs";import"./geo-point-codec-BTDzc-ym.mjs";import{o as n}from"./normalized-result-DXt6rKPa.mjs";import{n as r}from"./client-CinIwjZb.mjs";import{i,t as a}from"./driver-options-C9bFmRTQ.mjs";import{a as o,o as s,r as c,t as l}from"./driver-D38HdVs0.mjs";import{t as u}from"./postgres-adapter-DDvmW2rG.mjs";function d(e,t){let n;for(let r=0;r<t.length;r+=1){let i=t[r];Array.isArray(i)&&(n??=[...t],n[r]=e.array(i,`TEXT`).serializedValues)}return n??t}const f={parseField:(e,t,n)=>t===`int`&&e instanceof Int32Array?n(Array.from(e),t):n(e,t)};var p=class extends l{result=f;maxBindParametersPerStatement=65535;driverOptions;suppliedClient;constructor(e={}){super(`postgresql`,`bun-sql`);let n=i(e);this.driverOptions=e,this.suppliedClient=e.client,this.suppliedClient&&(this.client=this.suppliedClient);let r=new u(n,e.postgis===!0);r.capabilities.supportsVector=e.pgvector===!0,e.pgvector||(r.vector=t),a(this,`adapter`,r)}async initClient(){if(this.suppliedClient!==void 0)return this.suppliedClient;let{SQL:e}=await import(`bun`);return this.driverOptions.databaseUrl?new e(this.driverOptions.databaseUrl):new e(this.driverOptions.options??{})}async closeClient(e){e!==this.suppliedClient&&await e.close()}async execute(e,t,r,i){let a=i?.operation??`execute`,o=await e.unsafe(t,d(e,r));return{rows:o,rowCount:n(o.count,{provider:`bun-sql`,operation:a})}}async executeRaw(e,t,r,i){let a=i?.operation??`executeRaw`,o=await e.unsafe(t,r);return{rows:o,rowCount:n(o.count,{provider:`bun-sql`,operation:a})}}transactionOptionSupport(){return{isolationLevel:`post-begin`,timeout:!0,maxWait:`unsupported`,maxWaitReason:`Bun SQL acquires the connection inside sql.begin(), which VibORM cannot observe or bound — the wait would be unbounded no matter what maxWait said`}}async transaction(t,n,r){if(`savepoint`in t)throw o(this.driverName);return s({run:e=>t.begin(e),callback:n,phases:e(r),close:async()=>{await this.closeClient(t),this.client=null}})}async pinnedSession(){let e=await this.getClient({operation:`pinnedSession`});if(`savepoint`in e)throw o(this.driverName);let t=await e.reserve();return{session:t,release:n=>c({driverName:this.driverName,discard:n,reset:()=>t.unsafe(`SELECT pg_advisory_unlock_all()`),release:()=>t.release(),closeOwnedTransport:e===this.suppliedClient?void 0:async()=>{this.client=null,this.initPromise=null,await e.close()}})}}};function m(e){let{client:t,databaseUrl:n,options:a,pgvector:o,postgis:s}=e;return r(e,new p({client:t,databaseUrl:n,options:a,pgvector:o,postgis:s,namespace:i(e)}))}export{p as BunSQLDriver,m as createClient};
|
|
2
2
|
//# sourceMappingURL=bun-sql.mjs.map
|
package/dist/bun-sql.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-sql.mjs","names":[],"sources":["../src/drivers/bun-sql/index.ts"],"sourcesContent":["/**\n * Bun SQL Driver\n *\n * Driver implementation for Bun's built-in PostgreSQL client.\n */\n\nimport type { DatabaseAdapter } from \"@adapters/database-adapter\";\nimport { PostgresAdapter } from \"@adapters/databases/postgres/postgres-adapter\";\nimport {\n createClientFromDriverConfig,\n type DriverConfig,\n type NoExtraDriverConfigKeys,\n type VibORMClient,\n} from \"@client/client\";\nimport type { Schema } from \"@client/types\";\nimport { unsupportedVector } from \"@errors\";\nimport {\n Driver,\n type DriverResultParser,\n type QueryExecutionContext,\n} from \"../driver\";\nimport { getExecutionTransactionPhases } from \"../execution-context\";\nimport { normalizeProviderRowCount } from \"../normalized-result\";\nimport {\n defineImmutableDriverFact,\n nestedTransactionDispatchError,\n type PinnedSessionReservation,\n releaseReservedPostgresSession,\n resolveNamespaceOption,\n runProviderManagedTransaction,\n type TransactionOptionSupport,\n} from \"../shared\";\nimport type { QueryResult } from \"../types\";\n\n// ============================================================\n// TYPE DECLARATIONS FOR BUN SQL\n// ============================================================\n\n// Bun's SQL type - we define inline to avoid requiring bun types at compile time\n// Every result is an array carrying its required provider row count.\ntype BunSQLResult<T> = T[] & { count: number };\n\ninterface BunSQL {\n (strings: TemplateStringsArray, ...values: unknown[]): Promise<unknown[]>;\n unsafe<T = unknown>(\n sql: string,\n params?: unknown[]\n ): Promise<BunSQLResult<T>>;\n array(\n values: unknown[],\n typeNameOrTypeID?: string\n ): { readonly serializedValues: string };\n begin<T>(fn: (sql: BunSQLTransaction) => Promise<T>): Promise<T>;\n close(): Promise<void>;\n reserve(): Promise<BunSQLReservedConnection>;\n}\n\ninterface BunSQLTransaction {\n (strings: TemplateStringsArray, ...values: unknown[]): Promise<unknown[]>;\n unsafe<T = unknown>(\n sql: string,\n params?: unknown[]\n ): Promise<BunSQLResult<T>>;\n array(\n values: unknown[],\n typeNameOrTypeID?: string\n ): { readonly serializedValues: string };\n savepoint<T>(fn: (sql: BunSQLTransaction) => Promise<T>): Promise<T>;\n}\n\n/**\n * Bun's `unsafe()` path does not invoke its array helper: a plain JavaScript\n * array is bound as `Array#toString()`, which is not PostgreSQL array input\n * syntax. The adapter has already validated ORM list members, so let Bun's own\n * PostgreSQL encoder escape their flat scalar text and leave the statement's\n * column context to infer the concrete array type.\n *\n * Verbatim raw execution deliberately bypasses this conversion. A verbatim\n * caller owns the provider representation and receives Bun's ordinary\n * `unsafe()` semantics; a tagged safe-raw fragment stays on typed execution.\n */\nfunction normalizeBunSQLParams(\n client: BunSQL | BunSQLTransaction,\n params: unknown[]\n): unknown[] {\n let normalized: unknown[] | undefined;\n for (let index = 0; index < params.length; index += 1) {\n const param = params[index];\n if (!Array.isArray(param)) continue;\n normalized ??= [...params];\n normalized[index] = client.array(param, \"TEXT\").serializedValues;\n }\n return normalized ?? params;\n}\n\n/** Bun decodes PostgreSQL `integer[]` as `Int32Array`, not `Array`. */\nconst bunSQLResultParser: DriverResultParser = {\n parseField: (value, scalarType, next) => {\n if (scalarType === \"int\" && value instanceof Int32Array) {\n return next(Array.from(value), scalarType);\n }\n return next(value, scalarType);\n },\n};\n\n/**\n * Bun's `ReservedSQL` is an `SQL` bound to one connection, plus `release()` —\n * not a reduced surface. Declaring it that way is both faithful and load-\n * bearing: a reserved connection is what {@link BunSQLDriver.pinnedSession}\n * hands to the pinned view as its client, and the view's transaction control\n * runs `BEGIN`/`COMMIT` on it through the same `unsafe` path every statement\n * uses.\n */\ninterface BunSQLReservedConnection extends BunSQL {\n release(): void;\n}\n\n// ============================================================\n// EXPORTED OPTIONS\n// ============================================================\n\nexport interface BunSQLOptions {\n hostname?: string;\n port?: number;\n username?: string;\n password?: string;\n database?: string;\n tls?: boolean | object;\n max?: number;\n idleTimeout?: number;\n maxLifetime?: number;\n}\n\nexport interface BunSQLDriverOptions {\n client?: BunSQL;\n databaseUrl?: string;\n options?: BunSQLOptions;\n pgvector?: boolean;\n postgis?: boolean;\n /** The PostgreSQL schema this driver's persistent objects live in. Defaults to `public`. */\n namespace?: string;\n}\n\nexport type BunSQLClientConfig<C extends DriverConfig> = BunSQLDriverOptions &\n C;\n\n// ============================================================\n// DRIVER IMPLEMENTATION\n// ============================================================\n\nexport class BunSQLDriver extends Driver<BunSQL, BunSQLTransaction> {\n declare readonly adapter: DatabaseAdapter;\n readonly result: DriverResultParser = bunSQLResultParser;\n readonly maxBindParametersPerStatement: number | undefined = 65_535;\n\n private readonly driverOptions: BunSQLDriverOptions;\n /**\n * The EXACT transport the caller supplied, or absent when this driver makes\n * its own. Identity, settled here from ONE read, is the whole ownership\n * answer: the caller's options object is theirs to change, and a `client`\n * getter answering differently on a second read used to leave this driver\n * holding the caller's transport while believing it had made its own.\n */\n private readonly suppliedClient: BunSQL | undefined;\n\n constructor(options: BunSQLDriverOptions = {}) {\n super(\"postgresql\", \"bun-sql\");\n const namespace = resolveNamespaceOption(options);\n this.driverOptions = options;\n this.suppliedClient = options.client;\n\n if (this.suppliedClient) {\n this.client = this.suppliedClient;\n }\n\n const adapter = new PostgresAdapter(namespace, options.postgis === true);\n adapter.capabilities.supportsVector = options.pgvector === true;\n if (!options.pgvector) adapter.vector = unsupportedVector;\n defineImmutableDriverFact(this, \"adapter\", adapter);\n }\n\n /**\n * The transport this driver connects through.\n *\n * A caller's transport is RETURNED rather than replaced: reconnecting after a\n * `$disconnect()` used to build a second one behind their back — a transport\n * they never asked for, pointed at whatever their options record said by\n * then, and then never closed, because the ownership question was still\n * answered \"supplied\".\n */\n protected async initClient(): Promise<BunSQL> {\n if (this.suppliedClient !== undefined) {\n return this.suppliedClient;\n }\n const { SQL } = await import(\"bun\");\n\n if (this.driverOptions.databaseUrl) {\n return new SQL(this.driverOptions.databaseUrl) as unknown as BunSQL;\n }\n\n return new SQL(this.driverOptions.options ?? {}) as unknown as BunSQL;\n }\n\n /**\n * A supplied transport belongs to the caller, who may be sharing it with\n * other clients — two schema-scoped estates over one transport is the\n * documented shape — and §5.3's rule is that VibORM never changes a caller's\n * connection state. `$disconnect()` used to close it regardless, so\n * disconnecting one client tore down every other consumer of that transport.\n *\n * The test is on the transport's IDENTITY against what construction\n * captured, so it answers for the transport actually being closed rather than\n * for whatever the caller's record says now.\n */\n protected async closeClient(sql: BunSQL): Promise<void> {\n if (sql === this.suppliedClient) {\n return;\n }\n await sql.close();\n }\n\n protected async execute<T>(\n client: BunSQL | BunSQLTransaction,\n sql: string,\n params: unknown[],\n context?: QueryExecutionContext\n ): Promise<QueryResult<T>> {\n const operation = context?.operation ?? \"execute\";\n const result = await client.unsafe<T>(\n sql,\n normalizeBunSQLParams(client, params)\n );\n return {\n rows: result,\n rowCount: normalizeProviderRowCount(result.count, {\n provider: \"bun-sql\",\n operation,\n }),\n };\n }\n\n protected async executeRaw<T>(\n client: BunSQL | BunSQLTransaction,\n sql: string,\n params: unknown[] | undefined,\n context?: QueryExecutionContext\n ): Promise<QueryResult<T>> {\n const operation = context?.operation ?? \"executeRaw\";\n const result = await client.unsafe<T>(sql, params);\n return {\n rows: result,\n rowCount: normalizeProviderRowCount(result.count, {\n provider: \"bun-sql\",\n operation,\n }),\n };\n }\n\n /**\n * Bun's `sql.begin()` owns BEGIN and connection acquisition, so the isolation\n * level goes in as the transaction's first statement and there is no\n * acquisition step VibORM can bound.\n */\n protected override transactionOptionSupport(): TransactionOptionSupport {\n return {\n isolationLevel: \"post-begin\",\n timeout: true,\n maxWait: \"unsupported\",\n maxWaitReason:\n \"Bun SQL acquires the connection inside sql.begin(), which VibORM cannot observe or bound — the wait would be unbounded no matter what maxWait said\",\n };\n }\n\n protected async transaction<T>(\n client: BunSQL | BunSQLTransaction,\n fn: (tx: BunSQLTransaction) => Promise<T>,\n context?: QueryExecutionContext\n ): Promise<T> {\n if (\"savepoint\" in client) {\n throw nestedTransactionDispatchError(this.driverName);\n }\n\n return runProviderManagedTransaction({\n run: (callback) => client.begin(callback),\n callback: fn,\n phases: getExecutionTransactionPhases(context),\n // Containment for a transaction the provider broke, through the one place\n // that decides whether a transport may be closed at all: closing the\n // caller's transport to contain VibORM's transaction would be a far\n // larger effect than the one being contained.\n close: async () => {\n await this.closeClient(client);\n this.client = null;\n },\n });\n }\n\n /**\n * One `reserve()` result — plan §3.5's pinned producer for Bun SQL, and the\n * producer its transaction control uses too, because the pinned view opens\n * `BEGIN`/`COMMIT` on this exact connection.\n *\n * Bun exposes only `release()` for a reserved connection — the same shape\n * postgres.js has — so a condemned session takes the same rule: reset with\n * `pg_advisory_unlock_all()`, and when that reset fails, abandoned rather\n * than returned to a pool with a lock state nobody can account for.\n */\n protected override async pinnedSession(): Promise<\n PinnedSessionReservation<BunSQL | BunSQLTransaction>\n > {\n const client = await this.getClient({ operation: \"pinnedSession\" });\n if (\"savepoint\" in client) {\n throw nestedTransactionDispatchError(this.driverName);\n }\n const reserved = await client.reserve();\n return {\n session: reserved,\n release: (discard) =>\n releaseReservedPostgresSession({\n driverName: this.driverName,\n discard,\n reset: () => reserved.unsafe(\"SELECT pg_advisory_unlock_all()\"),\n release: () => reserved.release(),\n // Settled at construction, never re-read: see `suppliedClient`.\n closeOwnedTransport:\n client === this.suppliedClient\n ? undefined\n : async () => {\n // Withdrawn BEFORE the close, never after it: see the\n // postgres.js driver, which has the same shape and the same\n // reason — a rejecting `close()` used to leave this condemned\n // transport installed for the next ordinary query.\n this.client = null;\n this.initPromise = null;\n await client.close();\n },\n }),\n };\n }\n}\n\n// ============================================================\n// CONVENIENCE FUNCTION\n// ============================================================\n\nexport function createClient<S extends Schema, C extends DriverConfig<S>>(\n config: BunSQLClientConfig<C> &\n DriverConfig<S> &\n NoExtraDriverConfigKeys<C, BunSQLDriverOptions, S>\n): VibORMClient<C & { driver: BunSQLDriver }> {\n const { client, databaseUrl, options, pgvector, postgis } = config;\n const namespace = resolveNamespaceOption(config);\n\n const driver = new BunSQLDriver({\n client,\n databaseUrl,\n options,\n pgvector,\n postgis,\n namespace,\n });\n\n return createClientFromD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cACA,UACA,WACA,UACA,UARgB,EAAuB,EAAO,CAS/C,CAAC,CAEiD"}
|
|
1
|
+
{"version":3,"file":"bun-sql.mjs","names":[],"sources":["../src/drivers/bun-sql/index.ts"],"sourcesContent":["/**\n * Bun SQL Driver\n *\n * Driver implementation for Bun's built-in PostgreSQL client.\n */\n\nimport type { DatabaseAdapter } from \"@adapters/database-adapter\";\nimport { PostgresAdapter } from \"@adapters/databases/postgres/postgres-adapter\";\nimport {\n createClientFromDriverConfig,\n type DriverConfig,\n type NoExtraDriverConfigKeys,\n type VibORMClient,\n} from \"@client/client\";\nimport type { Schema } from \"@client/types\";\nimport { unsupportedVector } from \"@errors\";\nimport {\n Driver,\n type DriverResultParser,\n type QueryExecutionContext,\n} from \"../driver\";\nimport { getExecutionTransactionPhases } from \"../execution-context\";\nimport { normalizeProviderRowCount } from \"../normalized-result\";\nimport {\n defineImmutableDriverFact,\n nestedTransactionDispatchError,\n type PinnedSessionReservation,\n releaseReservedPostgresSession,\n resolveNamespaceOption,\n runProviderManagedTransaction,\n type TransactionOptionSupport,\n} from \"../shared\";\nimport type { QueryResult } from \"../types\";\n\n// ============================================================\n// TYPE DECLARATIONS FOR BUN SQL\n// ============================================================\n\n// Bun's SQL type - we define inline to avoid requiring bun types at compile time\n// Every result is an array carrying its required provider row count.\ntype BunSQLResult<T> = T[] & { count: number };\n\ninterface BunSQL {\n (strings: TemplateStringsArray, ...values: unknown[]): Promise<unknown[]>;\n unsafe<T = unknown>(\n sql: string,\n params?: unknown[]\n ): Promise<BunSQLResult<T>>;\n array(\n values: unknown[],\n typeNameOrTypeID?: string\n ): { readonly serializedValues: string };\n begin<T>(fn: (sql: BunSQLTransaction) => Promise<T>): Promise<T>;\n close(): Promise<void>;\n reserve(): Promise<BunSQLReservedConnection>;\n}\n\ninterface BunSQLTransaction {\n (strings: TemplateStringsArray, ...values: unknown[]): Promise<unknown[]>;\n unsafe<T = unknown>(\n sql: string,\n params?: unknown[]\n ): Promise<BunSQLResult<T>>;\n array(\n values: unknown[],\n typeNameOrTypeID?: string\n ): { readonly serializedValues: string };\n savepoint<T>(fn: (sql: BunSQLTransaction) => Promise<T>): Promise<T>;\n}\n\n/**\n * Bun's `unsafe()` path does not invoke its array helper: a plain JavaScript\n * array is bound as `Array#toString()`, which is not PostgreSQL array input\n * syntax. The adapter has already validated ORM list members, so let Bun's own\n * PostgreSQL encoder escape their flat scalar text and leave the statement's\n * column context to infer the concrete array type.\n *\n * Verbatim raw execution deliberately bypasses this conversion. A verbatim\n * caller owns the provider representation and receives Bun's ordinary\n * `unsafe()` semantics; a tagged safe-raw fragment stays on typed execution.\n */\nfunction normalizeBunSQLParams(\n client: BunSQL | BunSQLTransaction,\n params: unknown[]\n): unknown[] {\n let normalized: unknown[] | undefined;\n for (let index = 0; index < params.length; index += 1) {\n const param = params[index];\n if (!Array.isArray(param)) continue;\n normalized ??= [...params];\n normalized[index] = client.array(param, \"TEXT\").serializedValues;\n }\n return normalized ?? params;\n}\n\n/** Bun decodes PostgreSQL `integer[]` as `Int32Array`, not `Array`. */\nconst bunSQLResultParser: DriverResultParser = {\n parseField: (value, scalarType, next) => {\n if (scalarType === \"int\" && value instanceof Int32Array) {\n return next(Array.from(value), scalarType);\n }\n return next(value, scalarType);\n },\n};\n\n/**\n * Bun's `ReservedSQL` is an `SQL` bound to one connection, plus `release()` —\n * not a reduced surface. Declaring it that way is both faithful and load-\n * bearing: a reserved connection is what {@link BunSQLDriver.pinnedSession}\n * hands to the pinned view as its client, and the view's transaction control\n * runs `BEGIN`/`COMMIT` on it through the same `unsafe` path every statement\n * uses.\n */\ninterface BunSQLReservedConnection extends BunSQL {\n release(): void;\n}\n\n// ============================================================\n// EXPORTED OPTIONS\n// ============================================================\n\nexport interface BunSQLOptions {\n hostname?: string;\n port?: number;\n username?: string;\n password?: string;\n database?: string;\n tls?: boolean | object;\n max?: number;\n idleTimeout?: number;\n maxLifetime?: number;\n}\n\nexport interface BunSQLDriverOptions {\n client?: BunSQL;\n databaseUrl?: string;\n options?: BunSQLOptions;\n pgvector?: boolean;\n postgis?: boolean;\n /** The PostgreSQL schema this driver's persistent objects live in. Defaults to `public`. */\n namespace?: string;\n}\n\nexport type BunSQLClientConfig<C extends DriverConfig> = BunSQLDriverOptions &\n C;\n\n// ============================================================\n// DRIVER IMPLEMENTATION\n// ============================================================\n\nexport class BunSQLDriver extends Driver<BunSQL, BunSQLTransaction> {\n declare readonly adapter: DatabaseAdapter;\n readonly result: DriverResultParser = bunSQLResultParser;\n readonly maxBindParametersPerStatement: number | undefined = 65_535;\n\n private readonly driverOptions: BunSQLDriverOptions;\n /**\n * The EXACT transport the caller supplied, or absent when this driver makes\n * its own. Identity, settled here from ONE read, is the whole ownership\n * answer: the caller's options object is theirs to change, and a `client`\n * getter answering differently on a second read used to leave this driver\n * holding the caller's transport while believing it had made its own.\n */\n private readonly suppliedClient: BunSQL | undefined;\n\n constructor(options: BunSQLDriverOptions = {}) {\n super(\"postgresql\", \"bun-sql\");\n const namespace = resolveNamespaceOption(options);\n this.driverOptions = options;\n this.suppliedClient = options.client;\n\n if (this.suppliedClient) {\n this.client = this.suppliedClient;\n }\n\n const adapter = new PostgresAdapter(namespace, options.postgis === true);\n adapter.capabilities.supportsVector = options.pgvector === true;\n if (!options.pgvector) adapter.vector = unsupportedVector;\n defineImmutableDriverFact(this, \"adapter\", adapter);\n }\n\n /**\n * The transport this driver connects through.\n *\n * A caller's transport is RETURNED rather than replaced: reconnecting after a\n * `$disconnect()` used to build a second one behind their back — a transport\n * they never asked for, pointed at whatever their options record said by\n * then, and then never closed, because the ownership question was still\n * answered \"supplied\".\n */\n protected async initClient(): Promise<BunSQL> {\n if (this.suppliedClient !== undefined) {\n return this.suppliedClient;\n }\n const { SQL } = await import(\"bun\");\n\n if (this.driverOptions.databaseUrl) {\n return new SQL(this.driverOptions.databaseUrl) as unknown as BunSQL;\n }\n\n return new SQL(this.driverOptions.options ?? {}) as unknown as BunSQL;\n }\n\n /**\n * A supplied transport belongs to the caller, who may be sharing it with\n * other clients — two schema-scoped estates over one transport is the\n * documented shape — and §5.3's rule is that VibORM never changes a caller's\n * connection state. `$disconnect()` used to close it regardless, so\n * disconnecting one client tore down every other consumer of that transport.\n *\n * The test is on the transport's IDENTITY against what construction\n * captured, so it answers for the transport actually being closed rather than\n * for whatever the caller's record says now.\n */\n protected async closeClient(sql: BunSQL): Promise<void> {\n if (sql === this.suppliedClient) {\n return;\n }\n await sql.close();\n }\n\n protected async execute<T>(\n client: BunSQL | BunSQLTransaction,\n sql: string,\n params: unknown[],\n context?: QueryExecutionContext\n ): Promise<QueryResult<T>> {\n const operation = context?.operation ?? \"execute\";\n const result = await client.unsafe<T>(\n sql,\n normalizeBunSQLParams(client, params)\n );\n return {\n rows: result,\n rowCount: normalizeProviderRowCount(result.count, {\n provider: \"bun-sql\",\n operation,\n }),\n };\n }\n\n protected async executeRaw<T>(\n client: BunSQL | BunSQLTransaction,\n sql: string,\n params: unknown[] | undefined,\n context?: QueryExecutionContext\n ): Promise<QueryResult<T>> {\n const operation = context?.operation ?? \"executeRaw\";\n const result = await client.unsafe<T>(sql, params);\n return {\n rows: result,\n rowCount: normalizeProviderRowCount(result.count, {\n provider: \"bun-sql\",\n operation,\n }),\n };\n }\n\n /**\n * Bun's `sql.begin()` owns BEGIN and connection acquisition, so the isolation\n * level goes in as the transaction's first statement and there is no\n * acquisition step VibORM can bound.\n */\n protected override transactionOptionSupport(): TransactionOptionSupport {\n return {\n isolationLevel: \"post-begin\",\n timeout: true,\n maxWait: \"unsupported\",\n maxWaitReason:\n \"Bun SQL acquires the connection inside sql.begin(), which VibORM cannot observe or bound — the wait would be unbounded no matter what maxWait said\",\n };\n }\n\n protected async transaction<T>(\n client: BunSQL | BunSQLTransaction,\n fn: (tx: BunSQLTransaction) => Promise<T>,\n context?: QueryExecutionContext\n ): Promise<T> {\n if (\"savepoint\" in client) {\n throw nestedTransactionDispatchError(this.driverName);\n }\n\n return runProviderManagedTransaction({\n run: (callback) => client.begin(callback),\n callback: fn,\n phases: getExecutionTransactionPhases(context),\n // Containment for a transaction the provider broke, through the one place\n // that decides whether a transport may be closed at all: closing the\n // caller's transport to contain VibORM's transaction would be a far\n // larger effect than the one being contained.\n close: async () => {\n await this.closeClient(client);\n this.client = null;\n },\n });\n }\n\n /**\n * One `reserve()` result — plan §3.5's pinned producer for Bun SQL, and the\n * producer its transaction control uses too, because the pinned view opens\n * `BEGIN`/`COMMIT` on this exact connection.\n *\n * Bun exposes only `release()` for a reserved connection — the same shape\n * postgres.js has — so a condemned session takes the same rule: reset with\n * `pg_advisory_unlock_all()`, and when that reset fails, abandoned rather\n * than returned to a pool with a lock state nobody can account for.\n */\n protected override async pinnedSession(): Promise<\n PinnedSessionReservation<BunSQL | BunSQLTransaction>\n > {\n const client = await this.getClient({ operation: \"pinnedSession\" });\n if (\"savepoint\" in client) {\n throw nestedTransactionDispatchError(this.driverName);\n }\n const reserved = await client.reserve();\n return {\n session: reserved,\n release: (discard) =>\n releaseReservedPostgresSession({\n driverName: this.driverName,\n discard,\n reset: () => reserved.unsafe(\"SELECT pg_advisory_unlock_all()\"),\n release: () => reserved.release(),\n // Settled at construction, never re-read: see `suppliedClient`.\n closeOwnedTransport:\n client === this.suppliedClient\n ? undefined\n : async () => {\n // Withdrawn BEFORE the close, never after it: see the\n // postgres.js driver, which has the same shape and the same\n // reason — a rejecting `close()` used to leave this condemned\n // transport installed for the next ordinary query.\n this.client = null;\n this.initPromise = null;\n await client.close();\n },\n }),\n };\n }\n}\n\n// ============================================================\n// CONVENIENCE FUNCTION\n// ============================================================\n\nexport function createClient<S extends Schema, C extends DriverConfig<S>>(\n config: BunSQLClientConfig<C> &\n DriverConfig<S> &\n NoExtraDriverConfigKeys<C, BunSQLDriverOptions, S>\n): VibORMClient<C & { driver: BunSQLDriver }> {\n const { client, databaseUrl, options, pgvector, postgis } = config;\n const namespace = resolveNamespaceOption(config);\n\n const driver = new BunSQLDriver({\n client,\n databaseUrl,\n options,\n pgvector,\n postgis,\n nam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I,EAAa,CAC9B,SACA,cACA,UACA,WACA,UACA,UARgB,EAAuB,EAAO,CAS/C,CAAC,CAEiD"}
|
package/dist/bun-sqlite.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Ct as BunSQLiteClientConfig, Dt as createClient, Et as BunSQLiteOptions, Tt as BunSQLiteDriverOptions, wt as BunSQLiteDriver } from "./index-
|
|
1
|
+
import { Ct as BunSQLiteClientConfig, Dt as createClient, Et as BunSQLiteOptions, Tt as BunSQLiteDriverOptions, wt as BunSQLiteDriver } from "./index-C6dJH318.mjs";
|
|
2
2
|
export { BunSQLiteClientConfig, BunSQLiteDriver, BunSQLiteDriverOptions, BunSQLiteOptions, createClient };
|
package/dist/bun-sqlite.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as e}from"./clock-DHSN2GNk.mjs";import{r as t}from"./query-CRk65A10.mjs";import"./
|
|
1
|
+
import{c as e}from"./clock-DHSN2GNk.mjs";import{r as t}from"./query-CRk65A10.mjs";import"./v-DdH9EVw3.mjs";import"./geo-point-codec-BTDzc-ym.mjs";import{n}from"./client-CinIwjZb.mjs";import{s as r,t as i}from"./driver-D38HdVs0.mjs";import{i as a,n as o,r as s,t as c}from"./sqlite-utils-B-ZXbPld.mjs";import{t as l}from"./sqlite-adapter-3v4Bg8iy.mjs";function u(e){if(typeof e.safeIntegers!=`function`)throw new t(`bun:sqlite`,`Statement.safeIntegers`,`This Bun build cannot read INTEGER columns as BigInt, so any value past 2^53 would come back silently rounded. Upgrade to Bun 1.1.14 or newer.`);return e}function d(e){return c(e).map(e=>e instanceof Uint8Array||!o(e)?e:s(e))}var f=class extends i{adapter=new l;maxBindParametersPerStatement=999;result=a;serializeTransactions=!0;driverOptions;constructor(e={}){super(`sqlite`,`bun-sqlite`),this.driverOptions=e,e.client&&(this.client=e.client)}async initClient(){let{Database:e}=await import(`bun:sqlite`),t=this.driverOptions.dataDir??`:memory:`,n=this.driverOptions.options,r=n===void 0||Object.keys(n).length===0?new e(t):new e(t,n);return r.exec(`PRAGMA foreign_keys = ON`),r}async closeClient(e){e.close()}async execute(e,t,n){let r=d(n);return this.runStatement(e,t,r,!0)}async executeRaw(e,t,n){let r=n?d(n):void 0;return this.runStatement(e,t,r,!1)}runStatement(e,t,n,r){let i=e.prepare(t);if(i.columnNames.length>0){r&&u(i).safeIntegers(!0);let e=n?i.all(...n):i.all();return{rows:e,rowCount:e.length}}return{rows:[],rowCount:(n?i.run(...n):i.run()).changes}}transactionOptionSupport(){return{isolationLevel:`serializable-only`,isolationLevelReason:`SQLite serializes transactions on a single connection and has no statement to weaken isolation, so only Serializable can be honored truthfully`,timeout:!0,maxWait:`queue`}}async transaction(t,n,i){let a=!1,o=e=>{try{t.exec(e)}catch(e){throw a=!0,e}};return r({begin:()=>o(`BEGIN`),callback:()=>n(t),commit:()=>o(`COMMIT`),rollback:()=>o(`ROLLBACK`),phases:e(i),close:()=>{a&&(t.close(),this.client=null)}})}};function p(e){let{client:t,dataDir:r,options:i}=e;return n(e,new f({client:t,dataDir:r,options:i}))}export{f as BunSQLiteDriver,p as createClient};
|
|
2
2
|
//# sourceMappingURL=bun-sqlite.mjs.map
|
package/dist/bun-sqlite.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-sqlite.mjs","names":[],"sources":["../src/drivers/bun-sqlite/index.ts"],"sourcesContent":["/**\n * Bun SQLite Driver\n *\n * Driver implementation for Bun's built-in SQLite (bun:sqlite).\n */\n\nimport type { DatabaseAdapter } from \"@adapters/database-adapter\";\nimport { SQLiteAdapter } from \"@adapters/databases/sqlite/sqlite-adapter\";\nimport {\n createClientFromDriverConfig,\n type DriverConfig,\n type NoExtraDriverConfigKeys,\n type VibORMClient,\n} from \"@client/client\";\nimport type { Schema } from \"@client/types\";\nimport { FeatureNotSupportedError } from \"@errors\";\nimport {\n Driver,\n type DriverResultParser,\n type QueryExecutionContext,\n} from \"../driver\";\nimport { getExecutionTransactionPhases } from \"../execution-context\";\nimport {\n convertValuesForSQLite,\n isSQLiteBinaryValue,\n runTransactionLifecycle,\n sqliteBinaryToUint8Array,\n sqliteResultParser,\n type TransactionOptionSupport,\n} from \"../shared\";\nimport type { QueryResult } from \"../types\";\n\n// ============================================================\n// TYPE DECLARATIONS FOR BUN:SQLITE\n// ============================================================\n\n// Bun's Database type - we define inline to avoid requiring bun types at compile time\ninterface BunSQLiteDatabase {\n query<T = unknown>(sql: string): BunSQLiteStatement<T>;\n prepare<T = unknown>(sql: string): BunSQLiteStatement<T>;\n run(sql: string, ...params: unknown[]): void;\n exec(sql: string): void;\n close(): void;\n transaction<T>(fn: () => T): () => T;\n}\n\ninterface BunSQLiteStatement<T = unknown> {\n readonly columnNames: string[];\n all(...params: unknown[]): T[];\n get(...params: unknown[]): T | null;\n run(...params: unknown[]): {\n changes: number;\n lastInsertRowid: number | bigint;\n };\n /**\n * Reads INTEGER columns as BigInt instead of lossy JS numbers. Present on\n * `bun:sqlite` statements since Bun 1.1.14; the driver refuses to read\n * rather than return corrupted values when it is missing.\n */\n safeIntegers(safe: boolean): BunSQLiteStatement<T>;\n values(...params: unknown[]): unknown[][];\n}\n\n/**\n * `safeIntegers()` is what keeps an INTEGER past 2^53 from being rounded on\n * the way out of SQLite. A `bun:sqlite` old enough to lack it cannot answer\n * the query truthfully, so the read is refused instead of silently returning\n * a corrupted number — the one outcome that must never ship.\n */\nfunction requireSafeIntegers<T>(\n stmt: BunSQLiteStatement<T>\n): BunSQLiteStatement<T> {\n if (typeof stmt.safeIntegers !== \"function\") {\n throw new FeatureNotSupportedError(\n \"bun:sqlite\",\n \"Statement.safeIntegers\",\n \"This Bun build cannot read INTEGER columns as BigInt, so any value past 2^53 would come back silently rounded. Upgrade to Bun 1.1.14 or newer.\"\n );\n }\n return stmt;\n}\n\nfunction convertValuesForBunSQLite(values: unknown[]): unknown[] {\n return convertValuesForSQLite(values).map((value) => {\n if (value instanceof Uint8Array || !isSQLiteBinaryValue(value)) {\n return value;\n }\n return sqliteBinaryToUint8Array(value);\n });\n}\n\n// ============================================================\n// EXPORTED OPTIONS\n// ============================================================\n\nexport interface BunSQLiteOptions {\n readonly?: boolean;\n create?: boolean;\n readwrite?: boolean;\n strict?: boolean;\n}\n\nexport interface BunSQLiteDriverOptions {\n client?: BunSQLiteDatabase;\n dataDir?: string;\n options?: BunSQLiteOptions;\n}\n\nexport type BunSQLiteClientConfig<C extends DriverConfig> =\n BunSQLiteDriverOptions & C;\n\n// ============================================================\n// DRIVER IMPLEMENTATION\n// ============================================================\n\nexport class BunSQLiteDriver extends Driver<\n BunSQLiteDatabase,\n BunSQLiteDatabase\n> {\n readonly adapter: DatabaseAdapter = new SQLiteAdapter();\n readonly maxBindParametersPerStatement: number | undefined = 999;\n readonly result: DriverResultParser = sqliteResultParser;\n protected override readonly serializeTransactions = true;\n\n private readonly driverOptions: BunSQLiteDriverOptions;\n\n constructor(options: BunSQLiteDriverOptions = {}) {\n super(\"sqlite\", \"bun-sqlite\");\n this.driverOptions = options;\n\n if (options.client) {\n this.client = options.client;\n }\n }\n\n protected async initClient(): Promise<BunSQLiteDatabase> {\n // Dynamic import for bun:sqlite\n const { Database } = await import(\"bun:sqlite\");\n\n const dataDir = this.driverOptions.dataDir ?? \":memory:\";\n const options = this.driverOptions.options;\n\n // bun:sqlite derives its open flags from this object and rejects one that\n // names no access mode: `new Database(path, {})` throws SQLITE_MISUSE\n // (\"flags must include SQLITE_OPEN_READONLY or SQLITE_OPEN_READWRITE\").\n // An options bag that says nothing must mean nothing, so the argument is\n // omitted entirely and Bun applies its own default (readwrite + create).\n const db = (options === undefined || Object.keys(options).length === 0\n ? new Database(dataDir)\n : new Database(dataDir, options)) as unknown as BunSQLiteDatabase;\n\n // bun:sqlite leaves SQLite's foreign_keys default (OFF), which would let a\n // dangling FK write report success while sqlite3 and libsql refuse it.\n // Enforcement is a viborm guarantee, not an inherited library default.\n db.exec(\"PRAGMA foreign_keys = ON\");\n\n return db;\n }\n\n protected async closeClient(db: BunSQLiteDatabase): Promise<void> {\n db.close();\n }\n\n protected async execute<T>(\n client: BunSQLiteDatabase,\n sql: string,\n params: unknown[]\n ): Promise<QueryResult<T>> {\n const values = convertValuesForBunSQLite(params);\n return this.runStatement<T>(client, sql, values, true);\n }\n\n protected async executeRaw<T>(\n client: BunSQLiteDatabase,\n sql: string,\n params?: unknown[]\n ): Promise<QueryResult<T>> {\n const values = params ? convertValuesForBunSQLite(params) : undefined;\n // Raw results bypass the result parser — keep bun:sqlite's plain numbers\n // instead of surfacing BigInt to raw callers, matching sqlite3\n return this.runStatement<T>(client, sql, values, false);\n }\n\n private runStatement<T>(\n db: BunSQLiteDatabase,\n sql: string,\n values: unknown[] | undefined,\n safeIntegers: boolean\n ): QueryResult<T> {\n const stmt = db.prepare(sql);\n\n if (stmt.columnNames.length > 0) {\n if (safeIntegers) {\n // INTEGER columns come back as BigInt so values >2^53 survive; the\n // result parser converts int columns back to number\n requireSafeIntegers(stmt).safeIntegers(true);\n }\n const rows = (values ? stmt.all(...values) : stmt.all()) as T[];\n return { rows, rowCount: rows.length };\n }\n\n const result = values ? stmt.run(...values) : stmt.run();\n return { rows: [] as T[], rowCount: result.changes };\n }\n\n /**\n * SQLite has no isolation-level statement: one writer at a time on one\n * connection makes every transaction serializable already. `Serializable` is\n * therefore honored by construction, with no SQL to emit; the three weaker\n * levels are refused because pretending to relax isolation we cannot relax\n * would misreport what the transaction actually guarantees.\n */\n protected override transactionOptionSupport(): TransactionOptionSupport {\n return {\n isolationLevel: \"serializable-only\",\n isolationLevelReason:\n \"SQLite serializes transactions on a single connection and has no statement to weaken isolation, so only Serializable can be honored truthfully\",\n timeout: true,\n maxWait: \"queue\",\n };\n }\n\n protected async transaction<T>(\n client: BunSQLiteDatabase,\n fn: (tx: BunSQLiteDatabase) => Promise<T>,\n context?: QueryExecutionContext\n ): Promise<T> {\n let shouldClose = false;\n const executeOrClose = (statement: string) => {\n try {\n client.exec(statement);\n } catch (error) {\n shouldClose = true;\n throw error;\n }\n };\n return runTransactionLifecycle({\n begin: () => executeOrClose(\"BEGIN\"),\n callback: () => fn(client),\n commit: () => executeOrClose(\"COMMIT\"),\n rollback: () => executeOrClose(\"ROLLBACK\"),\n phases: getExecutionTransactionPhases(context),\n close: () => {\n if (shouldClose) {\n client.close();\n this.client = null;\n }\n },\n });\n }\n}\n\n// ============================================================\n// CONVENIENCE FUNCTION\n// ============================================================\n\nexport function createClient<S extends Schema, C extends DriverConfig<S>>(\n config: BunSQLiteClientConfig<C> &\n DriverConfig<S> &\n NoExtraDriverConfigKeys<C, BunSQLiteDriverOptions, S>\n): VibORMClient<C & { driver: BunSQLiteDriver }> {\n const { client, dataDir, options } = config;\n\n const driver = new BunSQLiteDriver({ client, dataDir, options });\n\n return createClientFromDriverConfig(config, driver) as VibORMClient<\n C & { driver: BunSQLiteDriver }\n >;\n}\n"],"mappings":"maAqEA,SAAS,EACP,EACuB,CACvB,GAAI,OAAO,EAAK,cAAiB,WAC/B,MAAM,IAAI,EACR,aACA,yBACA,iJACD,CAEH,OAAO,EAGT,SAAS,EAA0B,EAA8B,CAC/D,OAAO,EAAuB,EAAO,CAAC,IAAK,GACrC,aAAiB,YAAc,CAAC,EAAoB,EAAM,CACrD,EAEF,EAAyB,EAAM,CACtC,CA2BJ,IAAa,EAAb,cAAqC,CAGnC,CACA,QAAoC,IAAI,EACxC,8BAA6D,IAC7D,OAAsC,EACtC,sBAAoD,GAEpD,cAEA,YAAY,EAAkC,EAAE,CAAE,CAChD,MAAM,SAAU,aAAa,CAC7B,KAAK,cAAgB,EAEjB,EAAQ,SACV,KAAK,OAAS,EAAQ,QAI1B,MAAgB,YAAyC,CAEvD,GAAM,CAAE,YAAa,MAAM,OAAO,cAE5B,EAAU,KAAK,cAAc,SAAW,WACxC,EAAU,KAAK,cAAc,QAO7B,EAAM,IAAY,IAAA,IAAa,OAAO,KAAK,EAAQ,CAAC,SAAW,EACjE,IAAI,EAAS,EAAQ,CACrB,IAAI,EAAS,E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A6B,EAFrB,IAAI,EAAgB,CAAE,SAAQ,UAAS,UAAS,CAAC,CAEb"}
|
|
1
|
+
{"version":3,"file":"bun-sqlite.mjs","names":[],"sources":["../src/drivers/bun-sqlite/index.ts"],"sourcesContent":["/**\n * Bun SQLite Driver\n *\n * Driver implementation for Bun's built-in SQLite (bun:sqlite).\n */\n\nimport type { DatabaseAdapter } from \"@adapters/database-adapter\";\nimport { SQLiteAdapter } from \"@adapters/databases/sqlite/sqlite-adapter\";\nimport {\n createClientFromDriverConfig,\n type DriverConfig,\n type NoExtraDriverConfigKeys,\n type VibORMClient,\n} from \"@client/client\";\nimport type { Schema } from \"@client/types\";\nimport { FeatureNotSupportedError } from \"@errors\";\nimport {\n Driver,\n type DriverResultParser,\n type QueryExecutionContext,\n} from \"../driver\";\nimport { getExecutionTransactionPhases } from \"../execution-context\";\nimport {\n convertValuesForSQLite,\n isSQLiteBinaryValue,\n runTransactionLifecycle,\n sqliteBinaryToUint8Array,\n sqliteResultParser,\n type TransactionOptionSupport,\n} from \"../shared\";\nimport type { QueryResult } from \"../types\";\n\n// ============================================================\n// TYPE DECLARATIONS FOR BUN:SQLITE\n// ============================================================\n\n// Bun's Database type - we define inline to avoid requiring bun types at compile time\ninterface BunSQLiteDatabase {\n query<T = unknown>(sql: string): BunSQLiteStatement<T>;\n prepare<T = unknown>(sql: string): BunSQLiteStatement<T>;\n run(sql: string, ...params: unknown[]): void;\n exec(sql: string): void;\n close(): void;\n transaction<T>(fn: () => T): () => T;\n}\n\ninterface BunSQLiteStatement<T = unknown> {\n readonly columnNames: string[];\n all(...params: unknown[]): T[];\n get(...params: unknown[]): T | null;\n run(...params: unknown[]): {\n changes: number;\n lastInsertRowid: number | bigint;\n };\n /**\n * Reads INTEGER columns as BigInt instead of lossy JS numbers. Present on\n * `bun:sqlite` statements since Bun 1.1.14; the driver refuses to read\n * rather than return corrupted values when it is missing.\n */\n safeIntegers(safe: boolean): BunSQLiteStatement<T>;\n values(...params: unknown[]): unknown[][];\n}\n\n/**\n * `safeIntegers()` is what keeps an INTEGER past 2^53 from being rounded on\n * the way out of SQLite. A `bun:sqlite` old enough to lack it cannot answer\n * the query truthfully, so the read is refused instead of silently returning\n * a corrupted number — the one outcome that must never ship.\n */\nfunction requireSafeIntegers<T>(\n stmt: BunSQLiteStatement<T>\n): BunSQLiteStatement<T> {\n if (typeof stmt.safeIntegers !== \"function\") {\n throw new FeatureNotSupportedError(\n \"bun:sqlite\",\n \"Statement.safeIntegers\",\n \"This Bun build cannot read INTEGER columns as BigInt, so any value past 2^53 would come back silently rounded. Upgrade to Bun 1.1.14 or newer.\"\n );\n }\n return stmt;\n}\n\nfunction convertValuesForBunSQLite(values: unknown[]): unknown[] {\n return convertValuesForSQLite(values).map((value) => {\n if (value instanceof Uint8Array || !isSQLiteBinaryValue(value)) {\n return value;\n }\n return sqliteBinaryToUint8Array(value);\n });\n}\n\n// ============================================================\n// EXPORTED OPTIONS\n// ============================================================\n\nexport interface BunSQLiteOptions {\n readonly?: boolean;\n create?: boolean;\n readwrite?: boolean;\n strict?: boolean;\n}\n\nexport interface BunSQLiteDriverOptions {\n client?: BunSQLiteDatabase;\n dataDir?: string;\n options?: BunSQLiteOptions;\n}\n\nexport type BunSQLiteClientConfig<C extends DriverConfig> =\n BunSQLiteDriverOptions & C;\n\n// ============================================================\n// DRIVER IMPLEMENTATION\n// ============================================================\n\nexport class BunSQLiteDriver extends Driver<\n BunSQLiteDatabase,\n BunSQLiteDatabase\n> {\n readonly adapter: DatabaseAdapter = new SQLiteAdapter();\n readonly maxBindParametersPerStatement: number | undefined = 999;\n readonly result: DriverResultParser = sqliteResultParser;\n protected override readonly serializeTransactions = true;\n\n private readonly driverOptions: BunSQLiteDriverOptions;\n\n constructor(options: BunSQLiteDriverOptions = {}) {\n super(\"sqlite\", \"bun-sqlite\");\n this.driverOptions = options;\n\n if (options.client) {\n this.client = options.client;\n }\n }\n\n protected async initClient(): Promise<BunSQLiteDatabase> {\n // Dynamic import for bun:sqlite\n const { Database } = await import(\"bun:sqlite\");\n\n const dataDir = this.driverOptions.dataDir ?? \":memory:\";\n const options = this.driverOptions.options;\n\n // bun:sqlite derives its open flags from this object and rejects one that\n // names no access mode: `new Database(path, {})` throws SQLITE_MISUSE\n // (\"flags must include SQLITE_OPEN_READONLY or SQLITE_OPEN_READWRITE\").\n // An options bag that says nothing must mean nothing, so the argument is\n // omitted entirely and Bun applies its own default (readwrite + create).\n const db = (options === undefined || Object.keys(options).length === 0\n ? new Database(dataDir)\n : new Database(dataDir, options)) as unknown as BunSQLiteDatabase;\n\n // bun:sqlite leaves SQLite's foreign_keys default (OFF), which would let a\n // dangling FK write report success while sqlite3 and libsql refuse it.\n // Enforcement is a viborm guarantee, not an inherited library default.\n db.exec(\"PRAGMA foreign_keys = ON\");\n\n return db;\n }\n\n protected async closeClient(db: BunSQLiteDatabase): Promise<void> {\n db.close();\n }\n\n protected async execute<T>(\n client: BunSQLiteDatabase,\n sql: string,\n params: unknown[]\n ): Promise<QueryResult<T>> {\n const values = convertValuesForBunSQLite(params);\n return this.runStatement<T>(client, sql, values, true);\n }\n\n protected async executeRaw<T>(\n client: BunSQLiteDatabase,\n sql: string,\n params?: unknown[]\n ): Promise<QueryResult<T>> {\n const values = params ? convertValuesForBunSQLite(params) : undefined;\n // Raw results bypass the result parser — keep bun:sqlite's plain numbers\n // instead of surfacing BigInt to raw callers, matching sqlite3\n return this.runStatement<T>(client, sql, values, false);\n }\n\n private runStatement<T>(\n db: BunSQLiteDatabase,\n sql: string,\n values: unknown[] | undefined,\n safeIntegers: boolean\n ): QueryResult<T> {\n const stmt = db.prepare(sql);\n\n if (stmt.columnNames.length > 0) {\n if (safeIntegers) {\n // INTEGER columns come back as BigInt so values >2^53 survive; the\n // result parser converts int columns back to number\n requireSafeIntegers(stmt).safeIntegers(true);\n }\n const rows = (values ? stmt.all(...values) : stmt.all()) as T[];\n return { rows, rowCount: rows.length };\n }\n\n const result = values ? stmt.run(...values) : stmt.run();\n return { rows: [] as T[], rowCount: result.changes };\n }\n\n /**\n * SQLite has no isolation-level statement: one writer at a time on one\n * connection makes every transaction serializable already. `Serializable` is\n * therefore honored by construction, with no SQL to emit; the three weaker\n * levels are refused because pretending to relax isolation we cannot relax\n * would misreport what the transaction actually guarantees.\n */\n protected override transactionOptionSupport(): TransactionOptionSupport {\n return {\n isolationLevel: \"serializable-only\",\n isolationLevelReason:\n \"SQLite serializes transactions on a single connection and has no statement to weaken isolation, so only Serializable can be honored truthfully\",\n timeout: true,\n maxWait: \"queue\",\n };\n }\n\n protected async transaction<T>(\n client: BunSQLiteDatabase,\n fn: (tx: BunSQLiteDatabase) => Promise<T>,\n context?: QueryExecutionContext\n ): Promise<T> {\n let shouldClose = false;\n const executeOrClose = (statement: string) => {\n try {\n client.exec(statement);\n } catch (error) {\n shouldClose = true;\n throw error;\n }\n };\n return runTransactionLifecycle({\n begin: () => executeOrClose(\"BEGIN\"),\n callback: () => fn(client),\n commit: () => executeOrClose(\"COMMIT\"),\n rollback: () => executeOrClose(\"ROLLBACK\"),\n phases: getExecutionTransactionPhases(context),\n close: () => {\n if (shouldClose) {\n client.close();\n this.client = null;\n }\n },\n });\n }\n}\n\n// ============================================================\n// CONVENIENCE FUNCTION\n// ============================================================\n\nexport function createClient<S extends Schema, C extends DriverConfig<S>>(\n config: BunSQLiteClientConfig<C> &\n DriverConfig<S> &\n NoExtraDriverConfigKeys<C, BunSQLiteDriverOptions, S>\n): VibORMClient<C & { driver: BunSQLiteDriver }> {\n const { client, dataDir, options } = config;\n\n const driver = new BunSQLiteDriver({ client, dataDir, options });\n\n return createClientFromDriverConfig(config, driver) as VibORMClient<\n C & { driver: BunSQLiteDriver }\n >;\n}\n"],"mappings":"+VAqEA,SAAS,EACP,EACuB,CACvB,GAAI,OAAO,EAAK,cAAiB,WAC/B,MAAM,IAAI,EACR,aACA,yBACA,iJACD,CAEH,OAAO,EAGT,SAAS,EAA0B,EAA8B,CAC/D,OAAO,EAAuB,EAAO,CAAC,IAAK,G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0BAAwE,CACtE,MAAO,CACL,eAAgB,oBAChB,qBACE,iJACF,QAAS,GACT,QAAS,QACV,CAGH,MAAgB,YACd,EACA,EACA,EACY,CACZ,IAAI,EAAc,GACZ,EAAkB,GAAsB,CAC5C,GAAI,CACF,EAAO,KAAK,EAAU,OACf,EAAO,CAEd,KADA,GAAc,GACR,IAGV,OAAO,EAAwB,CAC7B,UAAa,EAAe,QAAQ,CACpC,aAAgB,EAAG,EAAO,CAC1B,WAAc,EAAe,SAAS,CACtC,aAAgB,EAAe,WAAW,CAC1C,OAAQ,EAA8B,EAAQ,CAC9C,UAAa,CACP,IACF,EAAO,OAAO,CACd,KAAK,OAAS,OAGnB,CAAC,GAQN,SAAgB,EACd,EAG+C,CAC/C,GAAM,CAAE,SAAQ,UAAS,WAAY,EAIrC,OAAO,EAA6B,EAFrB,IAAI,EAAgB,CAAE,SAAQ,UAAS,UAAS,CAAC,CAEb"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $t as CloudflareKVCache } from "../index-
|
|
1
|
+
import { $t as CloudflareKVCache } from "../index-C6dJH318.mjs";
|
|
2
2
|
export { CloudflareKVCache };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"../driver-
|
|
1
|
+
import{t as e}from"../driver-BRdxOENW.mjs";import"../v-DdH9EVw3.mjs";import"../geo-point-codec-BTDzc-ym.mjs";var t=class extends e{kv;constructor(e){super(`cloudflare-kv`),this.kv=e}async get(e){return await this.kv.get(e,`json`)||null}async set(e,t,n){let r=Math.ceil(t/1e3);await this.kv.put(e,JSON.stringify(n),{expirationTtl:r})}async delete(e){await Promise.all(e.map(e=>this.kv.delete(e)))}async clear(e){let t;do{let n=await this.kv.list({prefix:e,cursor:t});await Promise.all(n.keys.map(e=>this.kv.delete(e.name))),t=n.list_complete?void 0:n.cursor}while(t)}};export{t as CloudflareKVCache};
|
|
2
2
|
//# sourceMappingURL=cloudflare-kv.mjs.map
|
package/dist/cache/memory.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Qt as MemoryCache } from "../index-
|
|
1
|
+
import { Qt as MemoryCache } from "../index-C6dJH318.mjs";
|
|
2
2
|
export { MemoryCache };
|
package/dist/cache/memory.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{u as e}from"../clock-DHSN2GNk.mjs";import{t}from"../driver-
|
|
1
|
+
import{u as e}from"../clock-DHSN2GNk.mjs";import{t}from"../driver-BRdxOENW.mjs";import"../v-DdH9EVw3.mjs";import"../geo-point-codec-BTDzc-ym.mjs";var n=class extends t{store=new Map;timers=new Map;constructor(...t){if(super(`memory`),t.length!==0)throw new e(`MemoryCache does not accept construction options.`)}async get(e){return this.store.get(e)||null}async set(e,t,n){this.clearTimer(e),this.store.set(e,n);let r=this.clock.setTimeout(()=>{this.store.delete(e),this.timers.delete(e)},t);r.unref?.(),this.timers.set(e,r)}async delete(e){for(let t of e)this.clearTimer(t),this.store.delete(t)}async clear(e){for(let t of this.store.keys())t.startsWith(e)&&(this.clearTimer(t),this.store.delete(t))}clearTimer(e){let t=this.timers.get(e);t&&(t.cancel(),this.timers.delete(e))}};export{n as MemoryCache};
|
|
2
2
|
//# sourceMappingURL=memory.mjs.map
|
package/dist/cache.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Xt as CacheExtensionConfig, Zt as cache, an as WithCacheOptions, en as CacheDriver, in as CacheInvalidationOptions, nn as CacheSetOptions, rn as WaitUntilFn, tn as CacheEntry } from "./index-
|
|
1
|
+
import { Xt as CacheExtensionConfig, Zt as cache, an as WithCacheOptions, en as CacheDriver, in as CacheInvalidationOptions, nn as CacheSetOptions, rn as WaitUntilFn, tn as CacheEntry } from "./index-C6dJH318.mjs";
|
|
2
2
|
export { CacheDriver, type CacheEntry, type CacheExtensionConfig, type CacheInvalidationOptions, type CacheSetOptions, type WaitUntilFn, type WithCacheOptions, cache };
|
package/dist/cache.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./driver-
|
|
1
|
+
import{t as e}from"./driver-BRdxOENW.mjs";import"./v-DdH9EVw3.mjs";import"./geo-point-codec-BTDzc-ym.mjs";import{r as t}from"./extension-RO4080gs.mjs";export{e as CacheDriver,t as cache};
|
package/dist/cli.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{t as e}from"./version-
|
|
2
|
+
import{t as e}from"./version-BG9YFoe_.mjs";import"./v-DdH9EVw3.mjs";import"./geo-point-codec-BTDzc-ym.mjs";import{t}from"./client-C0QaN70e.mjs";import{o as n,t as r}from"./fs-estate-v7EUeEiD.mjs";import{n as i,r as a}from"./utils-CGDt90z6.mjs";import{Command as o,InvalidArgumentError as s}from"commander";import{resolve as c}from"node:path";import{cancel as l,confirm as u,isCancel as d,note as f,outro as p}from"@clack/prompts";const m=/^[0-9a-f]{8,63}$/;function h(e){let t=Number(e);if(!Number.isSafeInteger(t)||t<=0)throw new s(`must be a positive safe integer`);return t}function g(e){if(e)return n(e)?{id:e}:m.test(e)?{prefix:e}:{name:e}}function _(e,t){process.stdout.write(`${JSON.stringify(e,t?null:void 0,t?2:0)}\n`)}async function v(e,n){let o;try{let i=await a();o=i.client;let s=c(e??i.migrations?.dir??`./migrations`),l=i.migrations?.storage??r(s);await n(t(i.client,{storage:l}))}catch(e){i(e)}finally{await o?.$disconnect()}}function y(){let e=new o(`migrate`).description(`Manage the authenticated migration estate`);return e.command(`generate`).description(`Publish a new estate state from the current schema`).option(`-n, --name <name>`,`Human-readable state label`).option(`-d, --dir <dir>`,`Estate directory`).option(`--from <stateId>`,`Parent state id, or empty for the virtual root`).option(`--dry-run`,`Preview without publishing`).option(`--json`,`Print machine-readable output`).action(async e=>{await v(e.dir,async t=>{let r=e.from===void 0?void 0:e.from===``||e.from===`empty`?null:n(e.from)?e.from:(await t.show(g(e.from))).stateId;_(await t.generate({name:e.name,from:r,dryRun:e.dryRun}),!!e.json)})}),e.command(`check`).description(`Validate estate artifacts without touching the database`).option(`-d, --dir <dir>`,`Estate directory`).option(`--json`,`Print machine-readable output`).action(async e=>{await v(e.dir,async t=>{let n=await t.check();_(n,!!e.json),n.ok||(process.exitCode=1)})}),e.command(`list`).description(`List estate states`).option(`-d, --dir <dir>`,`Estate directory`).option(`--json`,`Print machine-readable output`).action(async e=>{await v(e.dir,async t=>{_(await t.list(),!!e.json)})}),e.command(`show`).description(`Show one estate state`).argument(`<state>`,`State id, unambiguous prefix, or name`).option(`-d, --dir <dir>`,`Estate directory`).option(`--json`,`Print machine-readable output`).action(async(e,t)=>{await v(t.dir,async n=>{_(await n.show(g(e)),!!t.json)})}),e.command(`graph`).description(`Print estate roots and leaves`).option(`-d, --dir <dir>`,`Estate directory`).option(`--json`,`Print machine-readable output`).action(async e=>{await v(e.dir,async t=>{_(await t.graph(),!!e.json)})}),e.command(`status`).description(`Show marker, pending path, and unfinished attempts`).option(`-d, --dir <dir>`,`Estate directory`).option(`--json`,`Print machine-readable output`).action(async e=>{await v(e.dir,async t=>{_(await t.status(),!!e.json)})}),e.command(`verify`).description(`Lock and compare the live schema to the marker`).option(`-d, --dir <dir>`,`Estate directory`).option(`--json`,`Print machine-readable output`).action(async e=>{await v(e.dir,async t=>{let n=await t.verify();_(n,!!e.json),n.ok||(process.exitCode=1)})}),e.command(`log`).description(`Print the append-only ledger`).option(`-d, --dir <dir>`,`Estate directory`).option(`--limit <n>`,`Maximum events`,e=>Number(e)).option(`--json`,`Print machine-readable output`).action(async e=>{await v(e.dir,async t=>{let n=await t.log();_(e.limit?n.slice(-e.limit):n,!!e.json)})}),e.command(`apply`).description(`Apply estate states to the target`).option(`-d, --dir <dir>`,`Estate directory`).option(`--to <selector>`,`Target state id, prefix, or name`).option(`--via <stateId...>`,`Force a path through these states`).option(`--dry-run`,`Plan without executing`).option(`--json`,`Print machine-readable output`).action(async e=>{await v(e.dir,async t=>{_(await t.apply({to:g(e.to),via:e.via,dryRun:e.dryRun}),!!e.json)})}),e.command(`down`).description(`Roll back along the recorded arrival path`).option(`-d, --dir <dir>`,`Estate directory`).option(`--to <selector>`,`Roll back to this state`).option(`--steps <n>`,`Number of states to roll back`,h).option(`--dry-run`,`Plan without executing`).option(`--json`,`Print machine-readable output`).action(async e=>{await v(e.dir,async t=>{_(await t.down(e.to?{to:g(e.to),dryRun:e.dryRun}:{steps:e.steps,dryRun:e.dryRun}),!!e.json)})}),e.command(`baseline`).description(`Adopt an existing database as a known estate state`).requiredOption(`--to <selector>`,`Existing estate state to adopt`).option(`--via <stateId...>`,`Force the recorded root path`).option(`-d, --dir <dir>`,`Estate directory`).option(`--json`,`Print machine-readable output`).action(async e=>{await v(e.dir,async t=>{_(await t.baseline({to:g(e.to),via:e.via}),!!e.json)})}),e.command(`resolve`).description(`Resolve an unfinished attempt after live proof`).option(`-d, --dir <dir>`,`Estate directory`).option(`--complete`,`Mark complete when destination proof holds`).option(`--rolled-back`,`Mark rolled back when origin proof holds`).option(`--retry`,`Retry from the first proven incomplete step`).option(`--json`,`Print machine-readable output`).action(async e=>{let t=e.complete?`complete`:e.rolledBack?`rolled-back`:e.retry?`retry`:void 0;if(!t)throw Error(`resolve requires --complete, --rolled-back, or --retry`);await v(e.dir,async n=>{_(await n.resolve({outcome:t}),!!e.json)})}),e.command(`reset`).description(`Clear managed objects and replay from empty to a selected state`).option(`-d, --dir <dir>`,`Estate directory`).option(`--to <selector>`,`Target state after rebuild`).option(`--via <stateId...>`,`Force a rebuild path`).requiredOption(`--confirm`,`Required. Reset is destructive.`).option(`--dry-run`,`Plan without executing`).option(`--json`,`Print machine-readable output`).action(async e=>{await v(e.dir,async t=>{_(await t.reset({to:g(e.to),via:e.via,dryRun:e.dryRun}),!!e.json)})}),e}const b=y();function x(e){process.stdout.write(`${JSON.stringify(e,null,2)}\n`)}function S(e){let t=e.operations.length===0?[`No schema changes.`]:e.operations.map(e=>`[${e.risk}] ${e.label} (${e.id})`),n=e.statements.map((e,t)=>`${t+1}. ${e.sql}${e.parameters.length===0?``:`\n parameters: ${JSON.stringify(e.parameters)}`}`);f([`Target: ${JSON.stringify(e.target)}`,`Plan: ${e.planHash}`,...t,...n.length===0?[]:[``,`SQL:`,...n]].join(`
|
|
3
3
|
`),`Push plan`)}async function C(e){let n;try{let r=await a({config:e.config});n=r.client;let i=t(r.client),o=await i.push({dryRun:!0,...e.forceReset===!0?{forceReset:!0}:{}});if(e.dryRun){e.json?x(o):S(o);return}if(e.json||S(o),o.outcome!==`noop`&&!e.yes){if(e.json)throw Error(`Non-interactive push requires --yes to apply a plan`);let t=await u({message:o.destructive?`Apply this destructive push plan?`:`Apply this push plan?`,initialValue:!o.destructive});if(d(t)||!t){l(`Push cancelled.`);return}}let s=await i.push({consent:o.consent});e.json?x(s):p(s.outcome===`noop`?`Schema is up to date.`:`Push applied.`)}catch(e){i(e)}finally{await n?.$disconnect()}}function w(){return new o(`push`).description(`Synchronize the schema directly without migration history`).option(`--config <path>`,`Path to viborm.config.ts`).option(`--dry-run`,`Preview without changing the database`).option(`--force-reset`,`Plan a rebuild from an empty database`).option(`-y, --yes`,`Apply without an interactive consent prompt`).option(`--json`,`Print machine-readable JSON`).action(C)}const T=w(),E=new o;E.name(`viborm`).description(`VibORM - Type-safe ORM for PostgreSQL, MySQL and SQLite`).version(e),E.addCommand(T),E.addCommand(b),E.parse();export{};
|
|
4
4
|
//# sourceMappingURL=cli.mjs.map
|