viborm 1.4.1 → 1.4.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/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-sqlite.d.mts +1 -1
- package/dist/bun-sqlite.mjs +1 -1
- package/dist/cache/cloudflare-kv.d.mts +1 -1
- package/dist/cache/memory.d.mts +1 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{client-3FqgR4eS.d.mts → client-D-XiaClb.d.mts} +1 -1
- package/dist/{client-DUulrWw5.mjs → client-DACEO6tS.mjs} +2 -2
- package/dist/client-DACEO6tS.mjs.map +1 -0
- package/dist/{client-sAey5P-I.mjs → client-LCeQ2fk4.mjs} +2 -2
- package/dist/{client-sAey5P-I.mjs.map → client-LCeQ2fk4.mjs.map} +1 -1
- package/dist/client.d.mts +1 -1
- package/dist/config.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.d.mts +1 -1
- package/dist/every-BHjQdTDc.mjs +2 -0
- package/dist/{every-CEQMQEdt.mjs.map → every-BHjQdTDc.mjs.map} +1 -1
- package/dist/{index-oVv9RLt5.d.mts → index-Ci8b13Lm.d.mts} +18 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/instrumentation.d.mts +1 -1
- package/dist/instrumentation.mjs +1 -1
- package/dist/{libsql-DPrXWc_J.mjs → libsql-hJdKb24B.mjs} +2 -2
- package/dist/{libsql-DPrXWc_J.mjs.map → libsql-hJdKb24B.mjs.map} +1 -1
- package/dist/libsql.d.mts +1 -1
- package/dist/libsql.mjs +1 -1
- package/dist/{memory-DiTWROVS.mjs → memory-DDOrEvz9.mjs} +2 -2
- package/dist/{memory-DiTWROVS.mjs.map → memory-DDOrEvz9.mjs.map} +1 -1
- package/dist/migrations/mysql.d.mts +4 -4
- package/dist/migrations/mysql.mjs +1 -1
- package/dist/migrations/postgres.d.mts +4 -4
- package/dist/migrations/postgres.mjs +1 -1
- package/dist/migrations/sqlite.d.mts +4 -4
- package/dist/migrations/sqlite.mjs +1 -1
- package/dist/migrations/tenant.d.mts +2 -2
- package/dist/migrations/tenant.mjs +1 -1
- package/dist/migrations.d.mts +4 -4
- package/dist/migrations.mjs +1 -1
- package/dist/{mysql-fJlFIW7m.mjs → mysql-DkYmF0W9.mjs} +2 -2
- package/dist/{mysql-fJlFIW7m.mjs.map → mysql-DkYmF0W9.mjs.map} +1 -1
- package/dist/mysql2.d.mts +1 -1
- package/dist/mysql2.mjs +1 -1
- package/dist/neon-http.d.mts +1 -1
- package/dist/neon-http.mjs +1 -1
- package/dist/{object-store-C56-FLkl.d.mts → object-store-H7fJwgPR.d.mts} +3 -3
- package/dist/permissions.d.mts +1 -1
- package/dist/pg.d.mts +1 -1
- package/dist/pg.mjs +1 -1
- package/dist/pglite.d.mts +1 -1
- package/dist/pglite.mjs +1 -1
- package/dist/planetscale.d.mts +1 -1
- package/dist/planetscale.mjs +1 -1
- package/dist/{planner-C3KX6S85.d.mts → planner-CUcPdJwD.d.mts} +1 -1
- package/dist/{postgres-DD92WdFu.mjs → postgres-CmAdDKYn.mjs} +2 -2
- package/dist/{postgres-DD92WdFu.mjs.map → postgres-CmAdDKYn.mjs.map} +1 -1
- package/dist/postgres.d.mts +1 -1
- package/dist/postgres.mjs +1 -1
- package/dist/schema/json.d.mts +1 -1
- package/dist/schema.d.mts +1 -1
- package/dist/soft-delete.d.mts +1 -1
- package/dist/{sqlite-adapter-B3dRr5fl.mjs → sqlite-adapter-CLWY4B8w.mjs} +2 -2
- package/dist/sqlite-adapter-CLWY4B8w.mjs.map +1 -0
- package/dist/sqlite3.d.mts +1 -1
- package/dist/sqlite3.mjs +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/version-Cea9UfBO.mjs +2 -0
- package/dist/{version-B9azgPiR.mjs.map → version-Cea9UfBO.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/client-DUulrWw5.mjs.map +0 -1
- package/dist/every-CEQMQEdt.mjs +0 -2
- package/dist/sqlite-adapter-B3dRr5fl.mjs.map +0 -1
- package/dist/version-B9azgPiR.mjs +0 -2
package/dist/adapters.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as PostgresAdapter, i as SQLiteAdapter, n as postgresAdapter, o as MySQLAdapter, r as sqliteAdapter, s as DatabaseAdapter, t as mysqlAdapter } from "./index-
|
|
1
|
+
import { a as PostgresAdapter, i as SQLiteAdapter, n as postgresAdapter, o as MySQLAdapter, r as sqliteAdapter, s as DatabaseAdapter, t as mysqlAdapter } from "./index-Ci8b13Lm.mjs";
|
|
2
2
|
export { type DatabaseAdapter, MySQLAdapter, PostgresAdapter, SQLiteAdapter, mysqlAdapter, postgresAdapter, sqliteAdapter };
|
package/dist/adapters.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./postgres-adapter-CJmoxTW7.mjs";import{t}from"./mysql-adapter-B1U35CJn.mjs";import{t as n}from"./sqlite-adapter-
|
|
1
|
+
import{t as e}from"./postgres-adapter-CJmoxTW7.mjs";import{t}from"./mysql-adapter-B1U35CJn.mjs";import{t as n}from"./sqlite-adapter-CLWY4B8w.mjs";const r=new t,i=new e,a=new n;export{t as MySQLAdapter,e as PostgresAdapter,n as SQLiteAdapter,r as mysqlAdapter,i as postgresAdapter,a as sqliteAdapter};
|
|
2
2
|
//# sourceMappingURL=adapters.mjs.map
|
package/dist/bun-sql.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Schema, At as DriverConfig, F as LinkedClientConfig, Ft as VibORMClient, Nn as QueryExecutionContext, Pn as QueryResult, Pt as NoExtraDriverConfigKeys, d as MigrationSessionAttestation, h as DriverResultParser, kn as TransactionOptionSupport, m as PinnedSessionReservation, s as DatabaseAdapter, u as Driver } from "./index-
|
|
1
|
+
import { A as Schema, At as DriverConfig, F as LinkedClientConfig, Ft as VibORMClient, Nn as QueryExecutionContext, Pn as QueryResult, Pt as NoExtraDriverConfigKeys, d as MigrationSessionAttestation, h as DriverResultParser, kn as TransactionOptionSupport, m as PinnedSessionReservation, s as DatabaseAdapter, u as Driver } from "./index-Ci8b13Lm.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/drivers/bun-sql/index.d.ts
|
|
4
4
|
|
package/dist/bun-sql.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e}from"./chunk-BuuaeEvq.mjs";import{o as t}from"./normalized-result-BF7gr4_b.mjs";import{d as n,l as r}from"./error-mapping-6op318w6.mjs";import{c as i}from"./execution-context-asSCmyas.mjs";import{n as a}from"./client-
|
|
1
|
+
import{n as e}from"./chunk-BuuaeEvq.mjs";import{o as t}from"./normalized-result-BF7gr4_b.mjs";import{d as n,l as r}from"./error-mapping-6op318w6.mjs";import{c as i}from"./execution-context-asSCmyas.mjs";import{n as a}from"./client-DACEO6tS.mjs";import{i as o,t as s}from"./pinned-session-FYOFV_gB.mjs";import{c,d as l,o as u,t as d,u as f}from"./driver-DseQwbsu.mjs";import{t as p}from"./postgres-adapter-B7hzWhky.mjs";import{n as m}from"./relation-bound-BrZLsSke.mjs";function normalizeBunSQLParams(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 h={parseField:(e,t,n)=>t===`int`&&e instanceof Int32Array?n(Array.from(e),t):n(e,t)},g={client:!0,databaseUrl:!0,options:!0,pgvector:!0,postgis:!0,sharedRelationBodies:!0,relationsPerStatement:!0,namespace:!0,migrationSessionAttestation:!0};var BunSQLDriver=class extends d{result=h;maxBindParametersPerStatement=65535;driverOptions;suppliedClient;constructor(e={}){super(`postgresql`,`bun-sql`);let t=l(e);this.driverOptions=e,this.suppliedClient=e.client,this.suppliedClient&&(this.client=this.suppliedClient),p(this,t,e),u(this,`migrationSessionAttestation`,f(e))}migrationSessionEndpoints(){let{databaseUrl:e,options:t}=this.driverOptions,n=this.suppliedClient?.options;return[e,t?.hostname,n?.hostname,n?.url]}async initClient(){if(this.suppliedClient!==void 0)return this.suppliedClient;let{SQL:e}=await import(`bun`);return this.driverOptions.databaseUrl?new e({...this.driverOptions.options,url:this.driverOptions.databaseUrl}):new e(this.driverOptions.options??{})}async closeClient(e){e!==this.suppliedClient&&await e.close()}async execute(e,n,r,i){let a=i?.operation??`execute`,o=await e.unsafe(n,normalizeBunSQLParams(e,r)).catch(e=>{throw m(this.adapter,e),e});return{rows:o,rowCount:t(o.count,{provider:`bun-sql`,operation:a})}}async executeRaw(e,n,r,i){let a=i?.operation??`executeRaw`,o=await e.unsafe(n,r);return{rows:o,rowCount:t(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(e,t,a){if(`savepoint`in e)throw r(this.driverName);return n({run:t=>e.begin(t),callback:t,phases:i(a),close:async()=>void 0})}async pinnedSession(){let e=await this.getClient({operation:`pinnedSession`});if(`savepoint`in e)throw r(this.driverName);let t=await e.reserve();return{session:t,release:(n,r)=>o({driverName:this.driverName,discard:n,lost:r,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({timeout:s/1e3})}})}}};function createClient(e){c(e,`bun-sql`,g);let{client:t,databaseUrl:n,options:r,pgvector:i,postgis:o}=e,s=l(e),u=f(e);return a(e,new BunSQLDriver({client:t,databaseUrl:n,options:r,pgvector:i,postgis:o,sharedRelationBodies:e.sharedRelationBodies,relationsPerStatement:e.relationsPerStatement,namespace:s,migrationSessionAttestation:u}))}export{BunSQLDriver,createClient};
|
|
2
2
|
//# sourceMappingURL=bun-sql.mjs.map
|
package/dist/bun-sqlite.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Schema, At as DriverConfig, F as LinkedClientConfig, Ft as VibORMClient, Nn as QueryExecutionContext, Pn as QueryResult, Pt as NoExtraDriverConfigKeys, h as DriverResultParser, kn as TransactionOptionSupport, p as SqliteMigrationCapability, s as DatabaseAdapter, u as Driver } from "./index-
|
|
1
|
+
import { A as Schema, At as DriverConfig, F as LinkedClientConfig, Ft as VibORMClient, Nn as QueryExecutionContext, Pn as QueryResult, Pt as NoExtraDriverConfigKeys, h as DriverResultParser, kn as TransactionOptionSupport, p as SqliteMigrationCapability, s as DatabaseAdapter, u as Driver } from "./index-Ci8b13Lm.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/drivers/bun-sqlite/index.d.ts
|
|
4
4
|
|
package/dist/bun-sqlite.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e}from"./chunk-BuuaeEvq.mjs";import{a as t,r as n}from"./validation-gwZYm3Yn.mjs";import{n as r}from"./client-
|
|
1
|
+
import{n as e}from"./chunk-BuuaeEvq.mjs";import{a as t,r as n}from"./validation-gwZYm3Yn.mjs";import{n as r}from"./client-DACEO6tS.mjs";import{c as i,n as a,r as o,t as s}from"./driver-DseQwbsu.mjs";import{a as c,c as l,i as u,l as d,n as f,s as p,t as m}from"./sqlite-utils-C5_KQPZn.mjs";import{t as h}from"./sqlite-adapter-CLWY4B8w.mjs";function requireSafeIntegers(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 reusesStatements(e){let t;for(let n=Object.getPrototypeOf(e);n;n=Object.getPrototypeOf(n))Object.hasOwn(n,`prepare`)&&(t=n.prepare);return e.prepare===t}const g=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u;function convertValuesForBunSQLite(e){return e.map(e=>{let t=f(e);if(typeof t==`string`&&g.test(t))throw TypeError(`bun:sqlite cannot preserve unpaired UTF-16 surrogates; the parameter was refused before dispatch.`);return t instanceof Uint8Array||!u(t)?t:l(t)})}const _={client:!0,dataDir:!0,options:!0};var BunSQLiteDriver=class extends s{adapter=new h;maxBindParametersPerStatement=32766;result=d;sqliteMigrationCapability=a;serializeTransactions=!0;driverOptions;suppliedClient;busyTimeout;constructor(e={}){if(super(`sqlite`,`bun-sqlite`),this.driverOptions=e,this.busyTimeout=e.options?.timeout??5e3,!Number.isSafeInteger(this.busyTimeout)||this.busyTimeout<0)throw new n(`The bun-sqlite "timeout" option must be a non-negative integer number of milliseconds.`,{meta:{driver:`bun-sqlite`,operation:`configuration`}});if(this.suppliedClient=e.client,this.suppliedClient){let e=this.suppliedClient.query(`PRAGMA foreign_keys`).get();if(!e||typeof e!=`object`||Reflect.get(e,`foreign_keys`)!==1)throw new n(`A supplied bun:sqlite Database must enable PRAGMA foreign_keys = ON before wrapping.`,{meta:{driver:`bun-sqlite`}});this.client=this.suppliedClient,Object.defineProperty(this,`connectionQueue`,{value:o(this.suppliedClient)})}}async initClient(){if(this.suppliedClient)return this.suppliedClient;let{Database:e}=await import(`bun:sqlite`),t=this.driverOptions.dataDir??`:memory:`,{timeout:n,...r}=this.driverOptions.options??{},i=Object.keys(r).length===0?new e(t):new e(t,r);return i.exec(`PRAGMA foreign_keys = ON`),i.exec(`PRAGMA busy_timeout = ${this.busyTimeout}`),i}async closeClient(e){e!==this.suppliedClient&&e.close()}async execute(e,t,n,r){let i=convertValuesForBunSQLite(n);return this.runStatement(e,t,i,r?.model!==`$raw`)}async executeRaw(e,t,n){let r=n?convertValuesForBunSQLite(n):void 0;return this.runStatement(e,t,r,!1)}runStatement(e,t,n,r){let i=r&&reusesStatements(e)?e.query(t):e.prepare(t);if(i.columnNames.length>0){requireSafeIntegers(i).safeIntegers(!0);let e=n?i.all(...n):i.all();return{rows:r?e:c(e),rowCount:e.length}}return{rows:[],rowCount:(n?i.run(...n):i.run()).changes}}transactionOptionSupport(){return m}async transaction(e,t,n){return p(e,t,n)}};function createClient(e){i(e,`bun-sqlite`,_,{databaseUrl:`pass the database file as dataDir`});let{client:t,dataDir:n,options:a}=e;return r(e,new BunSQLiteDriver({client:t,dataDir:n,options:a}))}export{BunSQLiteDriver,createClient};
|
|
2
2
|
//# sourceMappingURL=bun-sqlite.mjs.map
|
package/dist/cache/memory.d.mts
CHANGED
package/dist/cache.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cn as WaitUntilFn, Sn as CacheSetOptions, Tn as WithCacheOptions, bn as CacheDriver, wn as CacheInvalidationOptions, xn as CacheEntry, zt as OfficialCacheExtension } from "./index-
|
|
1
|
+
import { Cn as WaitUntilFn, Sn as CacheSetOptions, Tn as WithCacheOptions, bn as CacheDriver, wn as CacheInvalidationOptions, xn as CacheEntry, zt as OfficialCacheExtension } from "./index-Ci8b13Lm.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/cache/extension.d.ts
|
|
4
4
|
interface CacheExtensionConfig {
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{n as e}from"./chunk-BuuaeEvq.mjs";import{t}from"./hydration-Az2rjp5a.mjs";import{i as n}from"./validator-yrGnrsAo.mjs";import{a as r,n as i,o as a,s as o,t as s}from"./client-
|
|
2
|
+
import{n as e}from"./chunk-BuuaeEvq.mjs";import{t}from"./hydration-Az2rjp5a.mjs";import{i as n}from"./validator-yrGnrsAo.mjs";import{a as r,n as i,o as a,s as o,t as s}from"./client-LCeQ2fk4.mjs";import{a as c}from"./identity-CmRos0Yf.mjs";import{t as l}from"./every-BHjQdTDc.mjs";import{t as u}from"./version-Cea9UfBO.mjs";import{i as d,n as f,r as p}from"./utils-CQ2nQwwO.mjs";import{t as m}from"./fs-estate-N_F2YqYa.mjs";import{Command as h,InvalidArgumentError as g}from"commander";import{resolve as _}from"node:path";import{writeFile as v}from"node:fs/promises";import{cancel as y,confirm as b,isCancel as x,note as S,outro as C}from"@clack/prompts";const needsRepair=e=>e.type===`decimal`?!e.checked:e.noncanonical!==0,describeAudit=e=>{let t=`[storage] "${e.table}"."${e.column}"`;if((e.type===`decimal`?e.declared:e.noncanonical)===null)return`${t}: the column is missing; typed queries that use it fail.\n Create it through viborm push or migrate.`;if(e.type===`decimal`)return`${t}: declared ${e.declared}, not the checked scaled-integer decimal storage VibORM writes; typed reads, filters and writes are not checked against it.\n Adopt the table through viborm push, migrate or baseline: https://viborm.dev/docs/migration/drivers/sqlite#adopting-decimal-columns-from-another-tool`;let n=e.type===`time`?`Time`:`DateTime`,r=e.list?"Rewrite each row through the typed client (`update`), which stores canonical members":`Repair with sqliteCanonical${n}Expression from viborm/migrations`;return`${t}: ${e.noncanonical} row(s) of noncanonical ${n} text compare and sort wrongly.\n ${r}: https://viborm.dev/docs/migration/drivers/sqlite#repairing-foreign-timestamp-and-time-text`},describe=e=>[`[${e.code}] ${e.message}`,e.repair].filter(Boolean).join(`
|
|
3
3
|
`);async function runCheck(e){await d({config:e.config,skipValidation:!0},e.json,async r=>{let{models:i}=r;t(i);let a=n(i),s=e.db?await o({$driver:r.driver,$schema:i}):void 0,c=s?.filter(needsRepair)??[];if(e.json)process.stdout.write(`${JSON.stringify(s?{...a,storage:s}:a,null,2)}\n`);else{for(let e of a.errors)process.stderr.write(`error ${describe(e)}\n`);for(let e of a.warnings)process.stderr.write(`warning ${describe(e)}\n`);for(let e of c)process.stderr.write(`error ${describeAudit(e)}\n`);process.stdout.write(a.valid?`Schema valid (${Object.keys(i).length} models).\n`:`Schema invalid: ${a.errors.length} error(s).\n`),s&&process.stdout.write(`Storage audited: ${s.length} column(s), ${c.length} need repair.\n`)}(!a.valid||c.length>0)&&(process.exitCode=1)})}function createCheckCommand(){return new h(`check`).description(`Validate the schema, so clients can be created with skipSchemaValidation`).option(`--config <path>`,`Path to viborm.config.ts`).option(`--json`,`Print machine-readable JSON`).option(`--db`,`Also audit SQLite storage: DateTime/Time text and decimal columns`).action(runCheck)}const w=createCheckCommand(),T=/^[0-9a-f]{8,63}$/;function positiveInteger(e){let t=Number(e);if(!Number.isSafeInteger(t)||t<=0)throw new g(`must be a positive safe integer`);return t}function selector(e){if(e)return c(e)?{id:e}:T.test(e)?{prefix:e}:{name:e}}const approveDestructive=e=>e.type===`destructive`?e.proceed():void 0,confirmDestructive=async e=>{if(e.type!==`destructive`)return;let t=await b({message:`${e.description} — approve?`,initialValue:!1});return!x(t)&&t?e.proceed():e.reject()};function generateResolver(e,t){if(e.migrations?.resolve)return e.migrations.resolve;if(t.acceptDataLoss)return approveDestructive;if(!(t.dryRun||t.json||!process.stdin.isTTY))return confirmDestructive}async function withMigrations(e,t,n){await d({config:e.opts().config},t.json,async e=>{let r=_(t.dir??e.migrations?.dir??`./migrations`),i=e.migrations?.storage??m(r);await n(s(e.client,{storage:i,...e.migrations?.tables===void 0?{}:{tables:e.migrations.tables}}),e,i)})}function createMigrateCommand(){let e=new h(`migrate`).description(`Manage the authenticated migration estate`).option(`--config <path>`,`Path to viborm.config.ts`);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(`--custom <path>`,`Compile a TypeScript manual migration author`).option(`--review <path>`,`Write labelled forward/check/rollback review SQL`).option(`--dry-run`,`Preview without publishing`).option(`--low-lock`,`PostgreSQL: publish index builds and foreign keys on existing tables as recoverable steps`).option(`--accept-data-loss`,`Approve destructive changes (drops, type changes) for this generate`).option(`--json`,`Print machine-readable output`).action(async t=>{await withMigrations(e,t,async(e,n)=>{let i=t.from===void 0?void 0:t.from===``||t.from===`empty`?null:c(t.from)?t.from:(await e.show(selector(t.from))).stateId,a;if(t.custom){let n=await f(_(t.custom)),r=(Object.hasOwn(n,`default`)?n.default:void 0)??n.migration;if(!r)throw Error(`A custom migration module must export a default migration or author function`);let o=await e.graph(),s=Object.freeze(i===void 0?o.leaves.length===0?[null]:[...o.leaves]:[i]);a=typeof r==`function`?await r(s):r}let o=generateResolver(n,t),s=await e.generate({name:t.name,from:i,dryRun:t.dryRun,...t.lowLock?{lowLock:!0}:{},...o?{resolve:o}:{},...a?{manualMigration:a}:{}});if(t.json)p(s,!0);else{process.stdout.write(`${s.outcome}: ${s.name??`No schema changes`}${s.stateId?` (${s.stateId})`:``}\n`);for(let e of s.operationsByParent??[])process.stdout.write(`Parent ${e.fromState??`empty`}:\n${e.operations.map(r).join(`
|
|
4
4
|
`)}\n`);for(let e of s.warnings??[])process.stderr.write(`warning: ${e}\n`);(s.reviewSql||s.sql)&&process.stdout.write(`${s.reviewSql||s.sql}\n`)}t.review&&s.reviewSql&&await v(_(t.review),s.reviewSql,`utf8`)})}),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 t=>{await withMigrations(e,t,async e=>{let n=await e.check();p(n,!!t.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 t=>{await withMigrations(e,t,async e=>{p(await e.list(),!!t.json)})}),e.command(`show`).description(`Show one estate state`).argument(`<state>`,`State id, unambiguous prefix, or name`).option(`-d, --dir <dir>`,`Estate directory`).option(`--sql`,`Print labelled forward/check/rollback review SQL`).option(`--review <path>`,`Write review SQL to this file`).option(`--json`,`Print machine-readable output`).action(async(t,n)=>{await withMigrations(e,n,async(e,r,o)=>{let s=await e.show(selector(t));if(!(n.sql||n.review)){p(s,!!n.json);return}let c=await a(o),l=c.states.get(s.stateId),u=l&&c.sql.get(l.sqlHash);if(!(l&&u))throw Error(`The authenticated state SQL is unavailable`);let d=i(l.parents,l.destinationChecks,u);n.json?p({...s,reviewSql:d},!0):(p(s,!1),process.stdout.write(d)),n.review&&await v(_(n.review),d,`utf8`)})}),e.command(`graph`).description(`Print estate roots and leaves`).option(`-d, --dir <dir>`,`Estate directory`).option(`--json`,`Print machine-readable output`).action(async t=>{await withMigrations(e,t,async e=>{p(await e.graph(),!!t.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 t=>{await withMigrations(e,t,async e=>{p(await e.status(),!!t.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 t=>{await withMigrations(e,t,async e=>{let n=await e.verify();p(n,!!t.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`,positiveInteger).option(`--json`,`Print machine-readable output`).action(async t=>{await withMigrations(e,t,async e=>{let n=await e.log();p(t.limit?n.slice(-t.limit):n,!!t.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 t=>{await withMigrations(e,t,async e=>{p(await e.apply({to:selector(t.to),via:t.via,dryRun:t.dryRun}),!!t.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`,positiveInteger).option(`--accept-data-loss`,`Approve destructive changes the rollback makes to populated tables`).option(`--expect-revision <n>`,`Refuse unless the marker is at this revision`,positiveInteger).option(`--dry-run`,`Plan without executing`).option(`--json`,`Print machine-readable output`).action(async t=>{await withMigrations(e,t,async(e,n)=>{if(t.to!==void 0&&t.steps!==void 0)throw Error(`down accepts --to or --steps, not both`);let r=generateResolver(n,t),i={dryRun:t.dryRun,...r?{resolve:r}:{},...t.expectRevision===void 0?{}:{expectRevision:t.expectRevision}},a=await e.down(t.to?{to:selector(t.to),...i}:{steps:t.steps,...i});if(!a.preview||t.json)p(a,!!t.json);else{for(let e of a.edges)process.stdout.write(e.sql);a.refusal&&process.stderr.write(`down would refuse: ${a.refusal.code}: ${a.refusal.message}\n`)}a.preview&&a.refusal&&(process.exitCode=1)})}),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 t=>{await withMigrations(e,t,async e=>{p(await e.baseline({to:selector(t.to),via:t.via}),!!t.json)})}),e.command(`reanchor`).description(`After a restore left the history older than the database, move the marker to the state the live schema matches`).option(`--to <selector>`,`Adopt this state as the new baseline`).option(`--via <stateId...>`,`Force the recorded root path`).option(`-d, --dir <dir>`,`Estate directory`).option(`--json`,`Print machine-readable output`).action(async t=>{await withMigrations(e,t,async e=>{p(await e.reanchor({to:selector(t.to),via:t.via}),!!t.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 t=>{await withMigrations(e,t,async e=>{if([t.complete,t.rolledBack,t.retry].filter(Boolean).length!==1)throw Error(`resolve requires exactly one of --complete, --rolled-back, or --retry`);let n=t.complete?`complete`:t.rolledBack?`rolled-back`:`retry`;p(await e.resolve({outcome:n}),!!t.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`).option(`--confirm`,`Confirm destructive reset (not required for dry-run)`).option(`--dry-run`,`Plan without executing`).option(`--json`,`Print machine-readable output`).action(async t=>{await withMigrations(e,t,async e=>{if(!(t.dryRun||t.confirm))throw Error(`Reset requires --confirm; inspect --dry-run first`);p(await e.reset({to:selector(t.to),via:t.via,dryRun:t.dryRun}),!!t.json)})}),e}const E=createMigrateCommand();function printPlan(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)}`}`);S([`Target: ${JSON.stringify(e.target)}`,`Plan: ${e.planHash}`,...t,...n.length===0?[]:[``,`SQL:`,...n]].join(`
|
|
5
5
|
`),`Push plan`)}async function runPush(e){await d({config:e.config},e.json,async t=>{let n=t.migrations?.tables===void 0?s(t.client):s(t.client,{tables:t.migrations.tables}),r=await n.push({dryRun:!0,...e.forceReset===!0?{forceReset:!0}:{},...t.migrations?.resolve?{resolve:t.migrations.resolve}:{}});if(!e.json&&t.driver?.dialect===`sqlite`&&[`sqlite3`,`bun-sqlite`,`bun-sql`].includes(t.driver.driverName)&&(await t.driver._executeRaw(`PRAGMA database_list`)).rows.some(e=>e.name===`main`&&e.file===``)&&process.stderr.write(`warning: SQLite reports an in-memory main database. Use a persistent target for durable schema changes.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as Sql } from "./sql-Q_twK-wW.mjs";
|
|
2
|
-
import { i as ResolveCallback, n as DiffOperation, r as MigrationTarget, s as MigrationLimits, t as MigrationClient } from "./planner-
|
|
2
|
+
import { i as ResolveCallback, n as DiffOperation, r as MigrationTarget, s as MigrationLimits, t as MigrationClient } from "./planner-CUcPdJwD.mjs";
|
|
3
3
|
import { i as Sha256, n as MigrationStorageWriter, t as MigrationStorageReader } from "./contract-Dw0FR78e.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/migrations/v1-types.d.ts
|