@forinda/kickjs-db 8.12.4 → 8.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/kickjs-db.mjs +11 -27
- package/dist/{adapter-cVrkWrul.d.mts → adapter-HRQJb4xQ.d.mts} +2 -4
- package/dist/adapter-HRQJb4xQ.d.mts.map +1 -0
- package/dist/cli.d.mts +39 -9
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +4 -4
- package/dist/cli.mjs.map +1 -1
- package/dist/{create-NrvNUwZr.mjs → create-BGFj2wGn.mjs} +3 -3
- package/dist/create-BGFj2wGn.mjs.map +1 -0
- package/dist/{custom-type-CNmg8h4k.mjs → custom-type-CyQYFrA5.mjs} +2 -2
- package/dist/custom-type-CyQYFrA5.mjs.map +1 -0
- package/dist/devtools-events.d.mts +1 -3
- package/dist/devtools-events.d.mts.map +1 -1
- package/dist/devtools-events.mjs +1 -1
- package/dist/{index-Nf43jLx4.d.mts → index-AaU739CK.d.mts} +329 -135
- package/dist/index-AaU739CK.d.mts.map +1 -0
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +2 -2
- package/dist/mysql.d.mts +2 -8
- package/dist/mysql.d.mts.map +1 -1
- package/dist/mysql.mjs +2 -2
- package/dist/mysql.mjs.map +1 -1
- package/dist/{pg-lghOiA3k.mjs → pg-0Zp1q4gP.mjs} +3 -3
- package/dist/{pg-lghOiA3k.mjs.map → pg-0Zp1q4gP.mjs.map} +1 -1
- package/dist/pg.d.mts +4 -12
- package/dist/pg.d.mts.map +1 -1
- package/dist/pg.mjs +2 -2
- package/dist/pg.mjs.map +1 -1
- package/dist/pglite.d.mts +1 -3
- package/dist/pglite.d.mts.map +1 -1
- package/dist/pglite.mjs +1 -1
- package/dist/pglite.mjs.map +1 -1
- package/dist/{schema-types-CdU4u-Ow.d.mts → schema-types-CsgTPOPi.d.mts} +9 -5
- package/dist/schema-types-CsgTPOPi.d.mts.map +1 -0
- package/dist/{schema-jLdsVhUe.d.mts → schema-v6Jgocab.d.mts} +3 -5
- package/dist/schema-v6Jgocab.d.mts.map +1 -0
- package/dist/schema.d.mts +1 -1
- package/dist/schema.mjs +2 -2
- package/dist/schema.mjs.map +1 -1
- package/dist/{split-statements-cNBnqF81.mjs → split-statements-DHYNJs5X.mjs} +2 -2
- package/dist/{split-statements-cNBnqF81.mjs.map → split-statements-DHYNJs5X.mjs.map} +1 -1
- package/dist/sqlite.d.mts +1 -7
- package/dist/sqlite.d.mts.map +1 -1
- package/dist/sqlite.mjs +2 -2
- package/dist/sqlite.mjs.map +1 -1
- package/dist/{src-BkewQb59.mjs → src-CBTegE76.mjs} +4 -4
- package/dist/src-CBTegE76.mjs.map +1 -0
- package/dist/{table-BGk08X3C.d.mts → table-B8eYtdq_.d.mts} +7 -8
- package/dist/table-B8eYtdq_.d.mts.map +1 -0
- package/dist/testing.d.mts +2 -4
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +2 -2
- package/dist/testing.mjs.map +1 -1
- package/dist/{types-8xZUYm43.d.mts → types-Bmbj69hY.d.mts} +79 -17
- package/dist/types-Bmbj69hY.d.mts.map +1 -0
- package/dist/{types-DB_xyeQT.d.mts → types-D4x2u-EZ.d.mts} +22 -5
- package/dist/types-D4x2u-EZ.d.mts.map +1 -0
- package/package.json +11 -11
- package/dist/adapter-cVrkWrul.d.mts.map +0 -1
- package/dist/create-NrvNUwZr.mjs.map +0 -1
- package/dist/custom-type-CNmg8h4k.mjs.map +0 -1
- package/dist/index-Nf43jLx4.d.mts.map +0 -1
- package/dist/schema-jLdsVhUe.d.mts.map +0 -1
- package/dist/schema-types-CdU4u-Ow.d.mts.map +0 -1
- package/dist/src-BkewQb59.mjs.map +0 -1
- package/dist/table-BGk08X3C.d.mts.map +0 -1
- package/dist/types-8xZUYm43.d.mts.map +0 -1
- package/dist/types-DB_xyeQT.d.mts.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs-db v8.
|
|
2
|
+
* @forinda/kickjs-db v8.13.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
const FK_ACTION_NAMES=[`cascade`,`restrict`,`set_null`,`set_default`,`no_action`];function arrayLiteral(value){return`{${value.map(v=>v==null?`NULL`:Array.isArray(v)?arrayLiteral(v):typeof v==`string`||v instanceof Date?`"${(typeof v==`string`?v:dateLiteral(v)).replace(/["\\]/g,`\\$&`)}"`:String(v)).join(`,`)}}`}function dateLiteral(d){return d.toISOString().replace(`T`,` `).replace(`Z`,`+00:00`)}const KICK_GENERATED=Symbol.for(`@forinda/kickjs-db/Generated`),KICK_NOT_NULL=Symbol.for(`@forinda/kickjs-db/NotNull`);var ColumnBuilder=class{state;constructor(type,defaults={}){this.state={type,nullable:defaults.nullable??!0,default:defaults.default??null,primaryKey:defaults.primaryKey??!1,unique:defaults.unique??!1,references:defaults.references??null,...defaults.mode?{mode:defaults.mode}:{}}}notNull(){return this.state.nullable=!1,this}primaryKey(){return this.state.primaryKey=!0,this.state.nullable=!1,this}unique(){return this.state.unique=!0,this}array(){return this.state.type=`${this.state.type}[]`,this}references(target,opts={}){for(let key of[`onDelete`,`onUpdate`]){let action=opts[key];if(action!==void 0&&!FK_ACTION_NAMES.includes(action))throw Error(`references(): ${key} '${action}' isn't an action — use ${FK_ACTION_NAMES.map(a=>`'${a}'`).join(`, `).replace(/, ([^,]*)$/,` or $1`)}`)}return this.state.references={thunk:target,onDelete:opts.onDelete??`no_action`,onUpdate:opts.onUpdate??`no_action`,...opts.name===void 0?{}:{name:opts.name}},this}default(value){return this.state.default=typeof value==`string`?value:Array.isArray(value)&&this.state.type.endsWith(`[]`)?arrayLiteral(value):value instanceof Date?dateLiteral(value):typeof value==`object`&&value?JSON.stringify(value):String(value),this.state.defaultSql=!1,this}defaultSql(expression){return this.state.default=expression,this.state.defaultSql=!0,this}$defaultFn(fn){return this.state.defaultFn=fn,this}$onUpdate(fn){return this.state.onUpdateFn=fn,this}onUpdateNow(){return this.state.managed=`updatedAt`,this}softDelete(){return this.state.managed=`softDelete`,this}generatedAlwaysAs(expression,options={}){return this.state.generated={expression,stored:options.stored??!0},this}generatedAlwaysAsIdentity(){return this.state.identity=`always`,this.state.nullable=!1,this}generatedByDefaultAsIdentity(){return this.state.identity=`byDefault`,this.state.nullable=!1,this}comment(text){return this.state.comment=text,this}colName(name){return this.state.colName=name,this}managedAs(){return this.state.managed}toJSON(name){return{name,type:this.state.type,nullable:this.state.nullable,default:this.state.default,...this.state.defaultSql?{defaultSql:!0}:{},primaryKey:this.state.primaryKey,...this.state.generated?{generated:{...this.state.generated}}:{},...this.state.identity?{identity:this.state.identity}:{},...this.state.comment===void 0?{}:{comment:this.state.comment}}}__state(){return this.state}},CustomColumnBuilder=class extends ColumnBuilder{toDriver;fromDriver;constructor(opts){super(opts.dataType()),this.toDriver=opts.toDriver,this.fromDriver=opts.fromDriver}};function customType(opts){return()=>new CustomColumnBuilder(opts)}export{KICK_NOT_NULL as a,KICK_GENERATED as i,customType as n,ColumnBuilder as r,CustomColumnBuilder as t};
|
|
12
|
-
//# sourceMappingURL=custom-type-
|
|
12
|
+
//# sourceMappingURL=custom-type-CyQYFrA5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-type-CyQYFrA5.mjs","names":[],"sources":["../src/snapshot/types.ts","../src/dsl/columns/types.ts","../src/custom-type.ts"],"sourcesContent":["/** The SQL dialect a schema snapshot is written for. */\nexport type Dialect = 'postgres' | 'sqlite' | 'mysql'\n\n/** The foreign-key actions, in the snapshot's spelling. */\nexport const FK_ACTION_NAMES = [\n 'cascade',\n 'restrict',\n 'set_null',\n 'set_default',\n 'no_action',\n] as const\n/** A foreign key's `ON DELETE` / `ON UPDATE` action, in the snapshot's spelling. */\nexport type FkAction = (typeof FK_ACTION_NAMES)[number]\n\n/** A column in a schema snapshot. */\nexport interface ColumnSnapshot {\n name: string\n type: string\n nullable: boolean\n default: string | null\n /** `default` is SQL to evaluate (`.defaultSql()`), not a value. Absent means a value. */\n defaultSql?: true\n /**\n * Only on an introspected Postgres snapshot: `column_default` as the\n * database reports it. `default` is normalised and can't tell the literal\n * `'(f())'::text` from the expression `(f())::text`; the drift check can.\n */\n defaultRaw?: string\n primaryKey: boolean\n /** A column the database computes from others: `GENERATED ALWAYS AS (expression)`. */\n generated?: { expression: string; stored: boolean }\n /** An identity column (Postgres): `GENERATED ALWAYS | BY DEFAULT AS IDENTITY`. */\n identity?: 'always' | 'byDefault'\n /** The column's comment in the database (Postgres, MySQL). */\n comment?: string\n /**\n * Only on an introspected snapshot read back into keys: the database's own\n * name, when `casing` wouldn't give it back — rendered as `.colName()`.\n */\n colName?: string\n}\n\n/** An index in a schema snapshot. */\nexport interface IndexSnapshot {\n name: string\n /** Key parts in order: a column name, or an SQL expression wrapped in parentheses. */\n columns: string[]\n unique: boolean\n /** Partial index predicate (Postgres, SQLite), as SQL. */\n where?: string\n /** Index method, e.g. `gin`, `gist`, `hnsw` (Postgres) or `hash` (MySQL). Absent means the default. */\n using?: string\n /** Non-key columns stored in the index (Postgres `INCLUDE`). */\n include?: string[]\n /** Operator class per key part, keyed by the entry in `columns` (Postgres). */\n opclasses?: Record<string, string>\n /** Build and drop without locking writes (Postgres). Doesn't change the index itself. */\n concurrently?: boolean\n}\n\n/** A foreign-key constraint in a schema snapshot. */\nexport interface ForeignKeySnapshot {\n name: string\n columns: string[]\n refTable: string\n refColumns: string[]\n onDelete: FkAction\n onUpdate: FkAction\n}\n\n/** A `CHECK` constraint in a schema snapshot: its name and SQL expression. */\nexport interface CheckSnapshot {\n name: string\n expression: string\n}\n\n/** A table in a schema snapshot: columns, indexes, constraints, comment and row-level security. */\nexport interface TableSnapshot {\n /**\n * Bare table name, unqualified. The schema (when any) lives in\n * {@link TableSnapshot.schema}; the map key on `SchemaSnapshot.tables` is\n * the qualified form (`billing.invoices`).\n */\n name: string\n /**\n * Named SQL schema, from `pgSchema('x').table(...)`. Absent for tables in\n * the connection's default search_path, which keeps pre-schema snapshots\n * byte-identical (and their migration hashes valid).\n */\n schema?: string\n columns: Record<string, ColumnSnapshot>\n indexes: IndexSnapshot[]\n foreignKeys: ForeignKeySnapshot[]\n checks: CheckSnapshot[]\n /**\n * The key declared with `primaryKey(name?).on(...)`: its name and column\n * order. The columns also carry `primaryKey: true`. Absent for a key\n * declared on columns, so those snapshots — and migration hashes — stay\n * as they were.\n */\n primaryKey?: { name?: string; columns: string[] }\n /** The table's comment in the database (Postgres, MySQL). */\n comment?: string\n /** Row-level security is on (Postgres); `force` applies it to the table's owner too. */\n rls?: { force?: true }\n /** Row-level security policies (Postgres). */\n policies?: PolicySnapshot[]\n}\n\n/**\n * PostgreSQL ENUM type declaration. Currently PG-only; the field is\n * optional on `SchemaSnapshot` so other dialects don't have to carry\n * a phantom `enums: {}`.\n */\nexport interface EnumSnapshot {\n name: string\n /** Allowed values, in declaration order. PG preserves the order. */\n values: readonly string[]\n}\n\n/**\n * Resolved relation graph attached as a sidecar on the snapshot.\n * Lives on `SchemaSnapshot.relations` (optional). Keyed\n * sourceTable → relationName → resolved entry. Consumed by the\n * relational-query compiler in `packages/db/src/query/`. The\n * migration pipeline does not read this field — relations are\n * query-time sugar, not DDL.\n *\n * Shaped this way (rather than re-using the runtime `RelationsDecl`)\n * so the snapshot stays JSON-serializable: no function thunks, no\n * back-references to table objects.\n */\nexport interface RelationSnapshot {\n kind: 'one' | 'many'\n /** Target table name. */\n target: string\n /** Columns on the source table that participate in the join. */\n sourceColumns: readonly string[]\n /** Columns on the target table that participate in the join. */\n targetColumns: readonly string[]\n /**\n * Optional pairing tag from `relationName: 'foo'` on both sides of\n * the relation. Disambiguates multi-FK schemas.\n */\n relationName?: string\n /**\n * For a many-to-many: the junction table, and its columns that hold the\n * source's `sourceColumns` and the target's `targetColumns`.\n */\n through?: { table: string; sourceColumns: readonly string[]; targetColumns: readonly string[] }\n /**\n * For a `morphMany` / `morphOne`: the target's type column and the value it must hold\n * (bound as a parameter). There's no foreign key behind the join.\n */\n morph?: { column: string; value: string }\n /**\n * For a `morphTo`: the source's type column, and per type value the table\n * and key column the source's id column (`sourceColumns[0]`) points at.\n * `target` holds the first of those tables.\n */\n morphTo?: {\n column: string\n targets: ReadonlyArray<{ value: string; table: string; key: string }>\n }\n}\n\n/** A row-level security policy (Postgres). */\nexport interface PolicySnapshot {\n name: string\n as: 'permissive' | 'restrictive'\n command: 'all' | 'select' | 'insert' | 'update' | 'delete'\n /** Role names; `public` is everyone. */\n to: string[]\n using?: string\n withCheck?: string\n}\n\n/** A Postgres role the schema declares (created if missing, never dropped). */\nexport interface RoleSnapshot {\n name: string\n login?: boolean\n createDb?: boolean\n createRole?: boolean\n /** Default true: privileges of roles it's a member of apply to it. */\n inherit?: boolean\n bypassRls?: boolean\n}\n\nexport interface ViewSnapshot {\n name: string\n /** The `SELECT`, as declared (or as the database reports it, when introspected). */\n definition: string\n /** A materialized view (Postgres). */\n materialized?: true\n /** Indexes on a materialized view. */\n indexes?: IndexSnapshot[]\n /**\n * The columns, when introspected — for `kick db introspect` to render.\n * Not compared: the definition decides what a view returns.\n */\n columns?: Record<string, ColumnSnapshot>\n}\n\n/**\n * A JSON-serializable description of a whole schema. `diff()` compares two of\n * them, and each migration stores the one it leaves the database in (`snapshot.json`).\n *\n * @see https://kickjs.app/guide/database/concepts\n */\nexport interface SchemaSnapshot {\n version: 1\n dialect: Dialect\n /**\n * Keyed by QUALIFIED name — `billing.invoices` for a table declared through\n * `pgSchema('billing')`, the bare name otherwise. Qualifying the key is what\n * lets two schemas hold same-named tables without colliding, and it makes\n * every `table: string` field on a diff `Change` already schema-correct:\n * `quoteIdent` splits on `.`, rendering `\"billing\".\"invoices\"`.\n */\n tables: Record<string, TableSnapshot>\n /**\n * Named schemas the tables in this snapshot live in, sorted. Drives\n * `CREATE SCHEMA IF NOT EXISTS` emission. PG-only; absent when no table\n * declares a schema, so existing snapshots keep their exact shape.\n */\n schemas?: readonly string[]\n /** ENUM types declared via `pgEnum()`. PG-only; absent on other dialects. */\n enums?: Record<string, EnumSnapshot>\n /**\n * Views, in declaration order — the order they're created in, so a view can\n * select from one declared before it. Absent when there are none.\n */\n views?: Record<string, ViewSnapshot>\n /** Roles declared with `pgRole()` (Postgres). Absent when none. */\n roles?: Record<string, RoleSnapshot>\n /**\n * Optional relation sidecar populated when the schema includes\n * `relations()` declarations. Absent when no relations are\n * declared so M0/M1 callers see the same snapshot shape they\n * always did.\n */\n relations?: Record<string, Record<string, RelationSnapshot>>\n}\n","import { FK_ACTION_NAMES, type ColumnSnapshot, type FkAction } from '../../snapshot/types'\n\n/**\n * Runtime + type representation of a column reference (e.g. `users.id`).\n * Carries the parent table name, the column's own name, plus runtime\n * accessors used by FK thunks and constraint builders.\n *\n * Exported so adopters can annotate self-referencing thunks without\n * spelling the shape inline:\n *\n * parentId: uuid().references((): ColumnRef => categories.id)\n *\n * Without the annotation the initializer of a self-referencing const\n * trips TS7022 — TS needs to infer the const while the initializer\n * already references it.\n */\nexport interface ColumnRef {\n __tableName: string\n __name: string\n __builder: ColumnBuilder\n __state: () => ReturnType<ColumnBuilder['__state']>\n}\n\n/**\n * Resolved FK spec — `table` / `column` are pulled by invoking `thunk()`\n * lazily. The thunk pattern lets self-referencing tables work:\n *\n * const categories = table('categories', {\n * id: uuid().primaryKey().defaultRandom(),\n * parentId: uuid().references((): ColumnRef => categories.id),\n * })\n *\n * If we resolved at `.references()` call time, `categories` would TDZ-fail\n * inside its own initializer. Storing the thunk and resolving on read\n * (extract / render / emit) defers until after the const binding lands.\n */\n/**\n * A column ref that knows its column's value type — what lets a foreign key\n * be checked against the column it points at (`fk()`). Assignable to\n * `ColumnRef`, so every existing ref-taking API keeps working.\n */\nexport type TypedColumnRef<T> = ColumnRef & { readonly __valueType?: T }\n\n/** Typed refs for a column record — one per column. */\nexport type TypedColumnRefs<C> = {\n [K in keyof C]: TypedColumnRef<C[K] extends ColumnBuilder<infer T> ? T : never>\n}\n\ndeclare const SELF_REF: unique symbol\ndeclare const SELF_REF_TO: unique symbol\n\n/** What `selfRef('id')` returns: a target thunk that names a column of this table. */\nexport type SelfRef<K extends string> = (() => ColumnRef) & { readonly [SELF_REF]: K }\n\n/**\n * A column whose foreign key is `fk(builder, selfRef(K))`, checked by `table()`\n * against its own columns. `.references()` can't carry it: a generic or\n * overloaded `.references()` makes a plain thunk in a class field circular (TS7022).\n */\nexport type SelfRefTo<K extends string> = { readonly [SELF_REF_TO]: K }\n\ntype SelfRefTarget<B> = B extends SelfRefTo<infer K> ? K : never\ntype ValueOf<B> = B extends ColumnBuilder<infer T> ? T : never\n\n/**\n * `table()`'s check on its columns: each `selfRef(K)` names one of them, of a\n * type this column can hold. A failing column reads as the reason.\n */\nexport type CheckSelfRefs<C> = {\n [P in keyof C]: [SelfRefTarget<C[P]>] extends [never]\n ? C[P]\n : SelfRefTarget<C[P]> extends keyof C\n ? [ValueOf<C[SelfRefTarget<C[P]>]>] extends [ValueOf<C[P]>]\n ? C[P]\n : `selfRef('${SelfRefTarget<C[P]>}'): that column's type doesn't match this one`\n : `selfRef('${SelfRefTarget<C[P]>}'): this table has no such column`\n}\n\n/**\n * A column's foreign key, from `.references()`: the referenced column (as a thunk) and the actions.\n */\nexport interface FkSpec {\n thunk: () => ColumnRef\n onDelete: FkAction\n onUpdate: FkAction\n /**\n * The constraint's name in the database.\n *\n * Omitted for schemas written by hand — the name is then derived as\n * `<table>_<column>_fk`. It is set when the schema was generated by\n * `kick db introspect`, because a database names its constraints itself:\n * Postgres' own default is `<table>_<column>_fkey`, and a DBA may have\n * chosen anything. Dropping the real name would make the next diff want to\n * rename every foreign key in the schema.\n */\n name?: string\n}\n\n/** Postgres array literal text: `{1,2}`, `{\"a\",\"b c\"}`. */\nfunction arrayLiteral(value: unknown[]): string {\n const item = (v: unknown): string =>\n v === null || v === undefined\n ? 'NULL'\n : Array.isArray(v)\n ? arrayLiteral(v)\n : typeof v === 'string' || v instanceof Date\n ? `\"${(typeof v === 'string' ? v : dateLiteral(v)).replace(/[\"\\\\]/g, '\\\\$&')}\"`\n : String(v)\n return `{${value.map(item).join(',')}}`\n}\n\n/** A Date's UTC time that Postgres, MySQL and SQLite all read: no `T`, no `Z`. */\nfunction dateLiteral(d: Date): string {\n return d.toISOString().replace('T', ' ').replace('Z', '+00:00')\n}\n\n/**\n * What a column builder records about its column: type, nullability, default, keys and the rest.\n */\nexport interface ColumnState {\n type: string\n nullable: boolean\n default: string | null\n /** `default` is SQL to evaluate (`.defaultSql()`), not a value. */\n defaultSql?: boolean\n primaryKey: boolean\n unique: boolean\n references: FkSpec | null\n /**\n * A column kick/db maintains itself: `'updatedAt'` (set on every update),\n * `'version'` (incremented on every update), `'softDelete'` (rows with it\n * set are skipped by relational reads). Never part of the snapshot — it\n * changes queries, not the schema.\n */\n managed?: 'updatedAt' | 'version' | 'softDelete'\n generated?: { expression: string; stored: boolean }\n identity?: 'always' | 'byDefault'\n /**\n * How a bigint / numeric value is read back (`bigint({ mode })`,\n * `numeric(p, s, { mode })`). Unset, the driver's own value is returned.\n */\n mode?: 'bigint' | 'number' | 'string'\n /** `.comment()`: stored in the database on Postgres and MySQL. */\n comment?: string\n /** `.colName()`: the column's name in the database, when it isn't the key (or its `casing`). */\n colName?: string\n /** `tenantKey(tenancy)`: this is the table's tenant column. */\n tenancy?: { strategy: string; setting: string }\n /** `$defaultFn`: computed in JS for each inserted row that doesn't set it. */\n defaultFn?: () => unknown\n /** `$onUpdate`: computed in JS for each update that doesn't set it. */\n onUpdateFn?: () => unknown\n}\n\n/**\n * Type-only brand attached to a column when it's auto-assigned by the\n * database (serial / bigserial / smallserial), has a runtime default\n * (`.default(...)`), or carries an expression default\n * (`uuid().defaultRandom()`, `timestamp().defaultNow()`). `SchemaToTypes<S>`\n * reads this marker and wraps the column type in Kysely's `Generated<T>` so\n * adopters can omit the column on insert.\n *\n * Runtime is a no-op — the symbol never reaches a value.\n */\nexport const KICK_GENERATED = Symbol.for('@forinda/kickjs-db/Generated')\n/** Type-only marker for a column that can be omitted on insert. See `KICK_GENERATED`. */\nexport type GeneratedBrand = { readonly [KICK_GENERATED]?: true }\n\n/**\n * Type-only brand for a column the database always computes — a generated\n * column, or an identity `GENERATED ALWAYS`. `SchemaToTypes<S>` wraps it in\n * Kysely's `GeneratedAlways<T>`, so it can't be inserted or updated.\n */\nexport const KICK_GENERATED_ALWAYS = Symbol.for('@forinda/kickjs-db/GeneratedAlways')\nexport type GeneratedAlwaysBrand = { readonly [KICK_GENERATED_ALWAYS]?: true }\n\n/**\n * Type-only brand attached to a column when `.notNull()` or `.primaryKey()`\n * is called. `SchemaToTypes<S>` reads this brand to decide whether the\n * column type is `T` (NOT NULL) or `T | null` (default nullable).\n *\n * Why a brand instead of a class generic: chained methods (notNull,\n * primaryKey) can return `this & NotNullBrand` to narrow nullability while\n * preserving the subclass identity — so `uuid().primaryKey().defaultRandom()`\n * still resolves `defaultRandom()` on `UuidBuilder`. A class generic\n * `<TNullable>` would collapse the subclass back to the parent.\n */\nexport const KICK_NOT_NULL = Symbol.for('@forinda/kickjs-db/NotNull')\n/** Type-only marker for a `NOT NULL` column. See `KICK_NOT_NULL`. */\nexport type NotNullBrand = { readonly [KICK_NOT_NULL]?: true }\n\n/**\n * Re-attach the nullability / generated / selfRef brands after a transform that\n * must return a *new* builder type (e.g. `.array()` widening `T` to\n * `T[]`). Without this, `integer().notNull().array()` silently dropped\n * `NotNullBrand` and the row type regressed to `number[] | null`.\n *\n * Uses the same `extends` checks as `SchemaToTypes` (client/schema-types.ts)\n * so detection stays consistent in both directions.\n */\nexport type PreserveBrands<Self, Out> = Out &\n (Self extends NotNullBrand ? NotNullBrand : unknown) &\n (Self extends GeneratedBrand ? GeneratedBrand : unknown) &\n (Self extends GeneratedAlwaysBrand ? GeneratedAlwaysBrand : unknown) &\n (Self extends SelfRefTo<infer K> ? SelfRefTo<K> : unknown)\n\n/**\n * Phantom-typed column builder. The `T` generic carries the column's TS\n * value type (number / string / Date / etc.); nullability is tracked via\n * the `NotNullBrand` intersection rather than a class generic so chain\n * methods preserve subclass identity.\n *\n * Both `T` and the brand are erased at runtime; they exist purely so\n * `SchemaToTypes<S>` can pull them out per column.\n */\nexport class ColumnBuilder<T = unknown> {\n // Phantom param shows up in the public surface so the type system sees\n // it. Reading it at runtime is intentionally not supported.\n declare readonly __t?: T\n\n protected state: ColumnState\n\n constructor(type: string, defaults: Partial<ColumnState> = {}) {\n this.state = {\n type,\n nullable: defaults.nullable ?? true,\n default: defaults.default ?? null,\n primaryKey: defaults.primaryKey ?? false,\n unique: defaults.unique ?? false,\n references: defaults.references ?? null,\n ...(defaults.mode ? { mode: defaults.mode } : {}),\n }\n }\n\n /**\n * `NOT NULL`: drops `| null` from the column's type.\n *\n * @example\n * name: text().notNull()\n */\n notNull(): this & NotNullBrand {\n this.state.nullable = false\n return this as this & NotNullBrand\n }\n\n /**\n * `PRIMARY KEY` (implies `NOT NULL`). For a key over several columns, use\n * `primaryKey().on(...)` in the table's constraints instead.\n *\n * @example\n * id: uuid().primaryKey().defaultRandom()\n */\n primaryKey(): this & NotNullBrand {\n this.state.primaryKey = true\n this.state.nullable = false\n return this as this & NotNullBrand\n }\n\n /**\n * `UNIQUE` on this column alone. Partial or multi-column: `unique(name).on(...)`\n * in the table's constraints.\n *\n * @example\n * email: varchar(320).notNull().unique()\n */\n unique(): this {\n this.state.unique = true\n return this\n }\n\n /**\n * An array of this type (`text[]`), typed `T[]`.\n *\n * @example\n * tags: text().array().notNull().default([])\n */\n array(): PreserveBrands<this, ColumnBuilder<T[]>> {\n this.state.type = `${this.state.type}[]`\n return this as unknown as PreserveBrands<this, ColumnBuilder<T[]>>\n }\n\n /**\n * A foreign key to another table's column. The target is a thunk, so tables\n * can be declared in any order. For a column of the same table, use\n * `selfRef('id')`; for two tables that point at each other, `link()`.\n * Actions: `'cascade'`, `'restrict'`, `'set_null'`, `'set_default'`,\n * `'no_action'` (the default). `name` overrides the derived constraint name.\n *\n * @example\n * authorId: uuid().notNull().references(() => users.id, { onDelete: 'cascade' })\n * parentId: uuid().references(selfRef('id'), { onDelete: 'set_null' })\n */\n references(\n target: () => ColumnRef,\n opts: { onDelete?: FkAction; onUpdate?: FkAction; name?: string } = {},\n ): this {\n // Checked here, where it's written: the schema is loaded without a type\n // check by `kick db generate`, and an unknown action reached the SQL as `undefined`.\n for (const key of ['onDelete', 'onUpdate'] as const) {\n const action = opts[key]\n if (action !== undefined && !(FK_ACTION_NAMES as readonly string[]).includes(action))\n throw new Error(\n `references(): ${key} '${action}' isn't an action — use ${FK_ACTION_NAMES.map(\n (a) => `'${a}'`,\n )\n .join(', ')\n .replace(/, ([^,]*)$/, ' or $1')}`,\n )\n }\n // Store the thunk — do NOT invoke it here. Self-referencing tables\n // pass `() => self.id` whose binding does not exist yet.\n this.state.references = {\n thunk: target,\n onDelete: opts.onDelete ?? 'no_action',\n onUpdate: opts.onUpdate ?? 'no_action',\n // Only carried when given: an absent name means \"derive it\", and\n // storing the derived value here would make it indistinguishable from\n // an explicit one that happens to match.\n ...(opts.name === undefined ? {} : { name: opts.name }),\n }\n return this\n }\n\n /**\n * Mark the column as having a runtime / DB-assigned default. The\n * `GeneratedBrand` flows into `SchemaToTypes<S>` so the column wraps\n * in `Generated<T>` — adopters can `INSERT` without specifying it.\n *\n * Accepts the natural literal for the column type — `boolean().default(false)`,\n * `integer().default(0)`, `varchar().default('active')`. Non-string\n * literals are normalised to their SQL-literal text so the snapshot\n * (`ColumnSnapshot.default: string | null`) and migration emitter stay\n * string-only. For a quoted string default the text is the value\n * itself (`'active'`); booleans/numbers emit bare (`false`, `0`). A JSON\n * column takes its value (`jsonb().default({})` stores `{}`), an array\n * column its array literal (`integer().array().default([1, 2])` stores\n * `{1,2}`), and a `Date` its UTC time (`2026-01-02 03:04:05.000+00:00`).\n */\n default(value: string | number | boolean | T): this & GeneratedBrand {\n this.state.default =\n typeof value === 'string'\n ? value\n : Array.isArray(value) && this.state.type.endsWith('[]')\n ? arrayLiteral(value)\n : value instanceof Date\n ? dateLiteral(value)\n : typeof value === 'object' && value !== null\n ? JSON.stringify(value)\n : String(value)\n this.state.defaultSql = false\n return this as this & GeneratedBrand\n }\n\n /**\n * A default that is SQL, evaluated by the database for each new row —\n * `id: text().primaryKey().defaultSql('gen_random_uuid()::text')`,\n * `slug: text().defaultSql(\"lower(hex(randomblob(8)))\")`. `.default()` is a\n * value: on a text column `.default('now()')` stores the string `now()`.\n * Written as given, so it's your dialect's SQL.\n */\n defaultSql(expression: string): this & GeneratedBrand {\n this.state.default = expression\n this.state.defaultSql = true\n return this as this & GeneratedBrand\n }\n\n /**\n * A default computed in JS for each inserted row that doesn't set this\n * column — an id generator, a slug, a value from config:\n * `id: text().primaryKey().$defaultFn(() => ulid())`. Not part of the\n * schema: the database has no default, so raw SQL inserts must set it.\n */\n $defaultFn(fn: () => T): this & GeneratedBrand {\n this.state.defaultFn = fn\n return this as this & GeneratedBrand\n }\n\n /**\n * A value computed in JS for each update (and an upsert's update branch)\n * that doesn't set this column: `revisedBy: text().$onUpdate(() => currentUser())`.\n * Like `onUpdateNow()`, with your own value. Inserts don't call it.\n */\n $onUpdate(fn: () => T): this {\n this.state.onUpdateFn = fn\n return this\n }\n\n /**\n * Set this column to the current time on every update that doesn't set it\n * itself, and on an upsert's update branch. Your own value wins. Raw `sql`\n * updates don't maintain it.\n *\n * @example\n * updatedAt: timestamp().notNull().defaultNow().onUpdateNow()\n */\n onUpdateNow(): this {\n this.state.managed = 'updatedAt'\n return this\n }\n\n /**\n * Mark this column — a nullable timestamp — as the soft-delete marker:\n * relational reads (`db.query`) skip rows where it's set, at every level,\n * unless that level passes `withDeleted: true`. Soft-delete by setting it to\n * the current time; restore by setting it back to `null`.\n *\n * The query builder (`selectFrom`) is plain SQL and still sees deleted rows:\n * add `.where('deletedAt', 'is', null)` there yourself. No schema change.\n *\n * @example\n * deletedAt: timestamp().softDelete()\n * // delete: db.updateTable('docs').set({ deletedAt: new Date() }).where('id', '=', id)\n * // include: db.query.docs.findMany({ withDeleted: true })\n */\n softDelete(): this {\n this.state.managed = 'softDelete'\n return this\n }\n\n /**\n * Computed by the database from other columns, on every write:\n * `total: numeric(12, 2).generatedAlwaysAs('price * quantity')`. The SQL is\n * passed through as written. Stored by default; `{ stored: false }` makes\n * it virtual, computed on read (MySQL, SQLite, Postgres 18+). It can't be\n * inserted or updated.\n */\n generatedAlwaysAs(\n expression: string,\n options: { stored?: boolean } = {},\n ): this & GeneratedAlwaysBrand {\n this.state.generated = { expression, stored: options.stored ?? true }\n return this as this & GeneratedAlwaysBrand\n }\n\n /**\n * An identity column the database numbers and won't let you set (Postgres)\n * — the SQL-standard successor to `serial`.\n */\n generatedAlwaysAsIdentity(): this & NotNullBrand & GeneratedAlwaysBrand {\n this.state.identity = 'always'\n this.state.nullable = false\n return this as this & NotNullBrand & GeneratedAlwaysBrand\n }\n\n /** An identity column the database numbers unless a value is given (Postgres). */\n generatedByDefaultAsIdentity(): this & NotNullBrand & GeneratedBrand {\n this.state.identity = 'byDefault'\n this.state.nullable = false\n return this as this & NotNullBrand & GeneratedBrand\n }\n\n /**\n * A comment stored with the column in the database, for whoever reads the\n * schema there (Postgres, MySQL; SQLite has none). Changing it migrates.\n */\n comment(text: string): this {\n this.state.comment = text\n return this\n }\n\n /**\n * The column's name in the database, when it isn't the key — a legacy\n * `EMAIL_ADDR` behind an `email` key. Taken as written: `casing` doesn't\n * change it. Queries, `db.query` and migrations use it; your code keeps the key.\n */\n colName(name: string): this {\n this.state.colName = name\n return this\n }\n\n /** The role kick/db maintains this column in, if any. */\n managedAs(): ColumnState['managed'] {\n return this.state.managed\n }\n\n toJSON(name: string): ColumnSnapshot {\n return {\n name,\n type: this.state.type,\n nullable: this.state.nullable,\n default: this.state.default,\n ...(this.state.defaultSql ? { defaultSql: true as const } : {}),\n primaryKey: this.state.primaryKey,\n // Only when set, so other columns serialize as they always have.\n ...(this.state.generated ? { generated: { ...this.state.generated } } : {}),\n ...(this.state.identity ? { identity: this.state.identity } : {}),\n ...(this.state.comment !== undefined ? { comment: this.state.comment } : {}),\n }\n }\n\n // Internal accessor for table()/diff to read full state including unique/references.\n __state(): Readonly<ColumnState> {\n return this.state\n }\n}\n","// customType<T>() — adopter-defined column type with optional driver\n// codecs. Lets a project introduce a typed column that doesn't ship\n// in the built-in DSL (encrypted strings, custom JSON shapes, citext,\n// PostGIS geometry, etc.) without forking the package.\n//\n// Schema usage:\n//\n// const encrypted = customType<EncryptedString>({\n// dataType: () => 'text',\n// toDriver: (s) => encrypt(s),\n// fromDriver: (raw) => decrypt(String(raw)),\n// })\n//\n// export const secrets = table('secrets', {\n// id: serial().primaryKey(),\n// value: encrypted().notNull(),\n// })\n//\n// `SchemaToTypes<typeof schema>` reads the phantom T from the\n// CustomColumnBuilder so `db.selectFrom('secrets').select('value')`\n// types `value: EncryptedString` (not `string`). Driver codecs flow\n// through the lifecycle plugin landing in M2.F-T19; until then they\n// are stored on the builder for the runtime hookup to pick up.\n\nimport { ColumnBuilder } from './dsl/columns/types'\n\n/**\n * Options for `customType()`: the column's SQL type, and optional encode and decode hooks.\n *\n * @see https://kickjs.app/guide/db-extensions\n */\nexport interface CustomTypeOptions<TJs, TDriver = unknown> {\n /**\n * SQL data type as it would appear in `CREATE TABLE` — `'text'`,\n * `'jsonb'`, `'citext'`, `'geometry(Point, 4326)'`, etc. Returned\n * via a thunk so adopters can compute the type from runtime config\n * (e.g. dialect-specific overrides).\n */\n dataType: () => string\n /** Optional encode hook applied at insert / update time. */\n toDriver?: (value: TJs) => TDriver\n /** Optional decode hook applied to selected rows. */\n fromDriver?: (driver: TDriver) => TJs\n}\n\n/**\n * ColumnBuilder subclass produced by `customType()`. Carries the\n * driver codecs so the (future) hooks pipeline can wire them through\n * a Kysely plugin without each consumer re-declaring its mapping.\n *\n * The phantom `T` flows through `SchemaToTypes<S>` exactly like any\n * other ColumnBuilder<T>, so adopters get full row-shape inference\n * for free.\n */\nexport class CustomColumnBuilder<TJs> extends ColumnBuilder<TJs> {\n /** Encode hook — run on values heading into the database. */\n readonly toDriver?: (value: TJs) => unknown\n /** Decode hook — run on row values coming out of the database. */\n readonly fromDriver?: (driver: unknown) => TJs\n\n constructor(opts: CustomTypeOptions<TJs>) {\n super(opts.dataType())\n this.toDriver = opts.toDriver as never\n this.fromDriver = opts.fromDriver as never\n }\n}\n\n/**\n * Build a reusable column factory for a custom type. The returned\n * function is what callers use inside `table('foo', { col: factory() })`\n * — same shape as the built-in `varchar()`, `text()`, etc.\n *\n * @example\n * ```ts\n * const ulid = customType<string>({\n * dataType: () => 'char(26)',\n * toDriver: (s) => s,\n * fromDriver: (raw) => String(raw),\n * })\n *\n * const events = table('events', {\n * id: ulid().primaryKey(),\n * ts: timestamp().notNull().defaultNow(),\n * })\n * ```\n */\nexport function customType<TJs>(opts: CustomTypeOptions<TJs>): () => CustomColumnBuilder<TJs> {\n return () => new CustomColumnBuilder<TJs>(opts)\n}\n"],"mappings":";;;;;;;;;;AAIA,MAAa,gBAAkB,CAC7B,UACA,WACA,WACA,cACA,WACF,ECyFA,SAAS,aAAa,MAA0B,CAS9C,MAAO,IAAI,MAAM,IARH,GACZ,GAAM,KACF,OACA,MAAM,QAAQ,CAAC,EACb,aAAa,CAAC,EACd,OAAO,GAAM,UAAY,aAAa,KACpC,KAAK,OAAO,GAAM,SAAW,EAAI,YAAY,CAAC,EAAA,CAAG,QAAQ,SAAU,MAAM,EAAE,GAC3E,OAAO,CAAC,CACO,CAAC,CAAC,KAAK,GAAG,EAAE,EACvC,CAGA,SAAS,YAAY,EAAiB,CACpC,OAAO,EAAE,YAAY,CAAC,CAAC,QAAQ,IAAK,GAAG,CAAC,CAAC,QAAQ,IAAK,QAAQ,CAChE,CAkDA,MAAa,eAAiB,OAAO,IAAI,8BAA8B,EAuB1D,cAAgB,OAAO,IAAI,4BAA4B,EA4BpE,IAAa,cAAb,KAAwC,CAK5B,MAEV,Y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AK,MAAM,OAAQ,CACvE,CACF,CAGA,SAAiC,CAC/B,OAAO,KAAK,KACd,CACF,ECxba,oBAAb,cAA8C,aAAmB,CAEtD,SAEA,WAET,YAAY,KAA8B,CACxC,MAAM,KAAK,SAAS,CAAC,EACrB,KAAK,SAAW,KAAK,SACrB,KAAK,WAAa,KAAK,UACzB,CACF,EAqBA,SAAgB,WAAgB,KAA8D,CAC5F,UAAa,IAAI,oBAAyB,IAAI,CAChD,C"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { o as QueryErrorEvent, s as QueryEvent, u as SlowQueryEvent } from "./types-
|
|
3
|
-
//#region src/devtools-events.d.ts
|
|
2
|
+
import { o as QueryErrorEvent, s as QueryEvent, u as SlowQueryEvent } from "./types-Bmbj69hY.mjs";
|
|
4
3
|
declare module '@forinda/kickjs-devtools-kit/bus' {
|
|
5
4
|
interface KickDevtoolsEventRegistry {
|
|
6
5
|
/**
|
|
@@ -26,5 +25,4 @@ declare module '@forinda/kickjs-devtools-kit/bus' {
|
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
|
-
//#endregion
|
|
30
28
|
//# sourceMappingURL=devtools-events.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools-events.d.mts","names":[],"sources":["../src/devtools-events.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"devtools-events.d.mts","names":[],"sources":["../src/devtools-events.ts"],"mappings":";;;YAsBY;;;;;;IAMR,YAAY;MAAe;;;IAE3B,iBAAiB;;IAEjB,kBAAkB;;;;;;IAMlB;MAA0B;MAAmB"}
|
package/dist/devtools-events.mjs
CHANGED