@forinda/kickjs-db 8.11.1 → 8.11.2
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/{adapter-BdIVxVEo.d.mts → adapter-BlQK8hnm.d.mts} +2 -2
- package/dist/{adapter-BdIVxVEo.d.mts.map → adapter-BlQK8hnm.d.mts.map} +1 -1
- package/dist/cli.d.mts +2 -2
- package/dist/cli.mjs +2 -2
- package/dist/{create-DBqcBxOD.mjs → create-B1cXCImA.mjs} +3 -3
- package/dist/{create-DBqcBxOD.mjs.map → create-B1cXCImA.mjs.map} +1 -1
- package/dist/custom-type-B7IYj_Yr.mjs +12 -0
- package/dist/custom-type-B7IYj_Yr.mjs.map +1 -0
- package/dist/devtools-events.d.mts +1 -1
- package/dist/devtools-events.mjs +1 -1
- package/dist/{index-B1-D9uXB.d.mts → index-CgxPt0RM.d.mts} +6 -6
- package/dist/{index-B1-D9uXB.d.mts.map → index-CgxPt0RM.d.mts.map} +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +2 -2
- package/dist/mysql.d.mts +2 -2
- package/dist/mysql.mjs +2 -2
- package/dist/{pg-CKei1EsF.mjs → pg-DDrv2Nj1.mjs} +3 -3
- package/dist/{pg-CKei1EsF.mjs.map → pg-DDrv2Nj1.mjs.map} +1 -1
- package/dist/pg.d.mts +4 -4
- package/dist/pg.mjs +2 -2
- package/dist/pglite.d.mts +1 -1
- package/dist/pglite.mjs +1 -1
- package/dist/{schema-BYhjkNjL.d.mts → schema-Bb_HCpN5.d.mts} +3 -3
- package/dist/{schema-BYhjkNjL.d.mts.map → schema-Bb_HCpN5.d.mts.map} +1 -1
- package/dist/{schema-types-DxKLouYj.d.mts → schema-types-wgjWxE6P.d.mts} +3 -3
- package/dist/{schema-types-DxKLouYj.d.mts.map → schema-types-wgjWxE6P.d.mts.map} +1 -1
- package/dist/schema.d.mts +1 -1
- package/dist/schema.mjs +2 -2
- package/dist/{split-statements-CGxxCO7-.mjs → split-statements-BXJkTF5e.mjs} +2 -2
- package/dist/{split-statements-CGxxCO7-.mjs.map → split-statements-BXJkTF5e.mjs.map} +1 -1
- package/dist/sqlite.d.mts +1 -1
- package/dist/sqlite.mjs +2 -2
- package/dist/{src-CWbbuTIh.mjs → src-Bg9CeRAf.mjs} +3 -3
- package/dist/{src-CWbbuTIh.mjs.map → src-Bg9CeRAf.mjs.map} +1 -1
- package/dist/{table-B2HY_SQD.d.mts → table-B_04Qz0C.d.mts} +2 -2
- package/dist/{table-B2HY_SQD.d.mts.map → table-B_04Qz0C.d.mts.map} +1 -1
- package/dist/testing.d.mts +2 -2
- package/dist/testing.mjs +2 -2
- package/dist/{types-BRgtaCZf.d.mts → types-DEVOTVGx.d.mts} +6 -3
- package/dist/{types-BRgtaCZf.d.mts.map → types-DEVOTVGx.d.mts.map} +1 -1
- package/dist/{types-C_53X_tW.d.mts → types-DTWrY_KF.d.mts} +2 -2
- package/dist/{types-C_53X_tW.d.mts.map → types-DTWrY_KF.d.mts.map} +1 -1
- package/package.json +3 -3
- package/dist/custom-type-Bku-7SqA.mjs +0 -12
- package/dist/custom-type-Bku-7SqA.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { d as TypedColumnRefs, t as ColumnBuilder, v as IndexSnapshot, x as RoleSnapshot, y as PolicySnapshot } from "./types-
|
|
2
|
+
import { d as TypedColumnRefs, t as ColumnBuilder, v as IndexSnapshot, x as RoleSnapshot, y as PolicySnapshot } from "./types-DEVOTVGx.mjs";
|
|
3
3
|
//#region src/dsl/rls.d.ts
|
|
4
4
|
/** A database role, for `policy().to(...)` — created by migrations unless `.existing()`. */
|
|
5
5
|
declare class RoleDecl {
|
|
@@ -218,4 +218,4 @@ declare function buildTable<TName extends string, C extends Record<string, Colum
|
|
|
218
218
|
declare function unwrapTable(value: unknown): TableDecl | undefined;
|
|
219
219
|
//#endregion
|
|
220
220
|
export { PolicyDecl as _, qualifiedTableName as a, pgRole as b, CheckDecl as c, PrimaryKeyDecl as d, TableConstraint as f, unique as g, primaryKey as h, buildTable as i, IndexDecl as l, index as m, TableDecl as n, table as o, check as p, TableOptions as r, unwrapTable as s, QualifiedName as t, IndexKey as u, RoleDecl as v, policy as x, isRole as y };
|
|
221
|
-
//# sourceMappingURL=table-
|
|
221
|
+
//# sourceMappingURL=table-B_04Qz0C.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-
|
|
1
|
+
{"version":3,"file":"table-B_04Qz0C.d.mts","names":[],"sources":["../src/dsl/rls.ts","../src/dsl/constraints.ts","../src/dsl/table.ts"],"mappings":";;;;cAGa;WACF;WACA,QAAQ;;EAEjB;EAEA,YAAY,cAAc,UAAS,KAAK;;EAKxC;;;;;;;;;;;iBAec,OAAO,cAAc,UAAS,KAAK,wBAA6B;iBAIhE,OAAO,iBAAiB,SAAS;KAI5C,UAAU;;cAGF;WACF;WACA,UAAU;EAEnB,YAAY;;EAKZ,IAAI,SAAS;;EAMb,MAAM,OAAO,eAAe;;;;;EAS5B,GAAG;;EAMH,MAAM;;EAMN,UAAU;;;;;;;;;;;;;;;;;iBAqBI,OAAO,eAAe;;;UC9F5B;EACR;;;KAIU,WAAW;;;;;;;;;;cAeV;;WAEF,SAAS;EAElB,YAAY,cAAc,MAAM,YAAY;;EAK5C,MAAM;;EAMN,MAAM;;EAMN,WAAW,MAAM;;EAMjB,GAAG,KAAK,UAAU;;;;;;EAclB;;iBAMc,MAAM;EAElB,MAAE,MAAU,aAAa;;iBAMb,OAAO;EAEnB,MAAE,MAAU,aAAa;;;UAOZ;EACf;;EAEA;EACA;;;UAIe;EACf;EACA;;EAEA;;;KAIU,kBAAkB,YAAY,iBAAiB,YAAY;;;;;;;;;;iBAWvD,WAAW;EAEvB,MAAE,MAAU,WAAW;;;;;;iBAYX,MAAM,cAAc,qBAAqB;;;UCxHxC,UACf,+BACA,UAAU,eAAe,iBAAiB,eAAe,gBACzD;EAEA;EACA,QAAQ;EACR,WAAW;EACX,WAAW;;EAEX,eAAe;EACf,WAAW;;EAEX;;EAEA;IAAU;;EACV,aAAa;;;;;;;;;EASb,WAAW;;;;;WAKF,UAAU,SAAS;;;;;;;;;;KAWlB,cACV,sBACA,sCACE,4BAA4B,WAAW,UAAU;;iBAGrC,mBAAmB;EACjC;EACA;;KAKG,UACH,sBACA,UAAU,eAAe,gBACzB,kDACE,UAAU,OAAO,GAAG,WAAW,gBAAgB;KAE9C,kBAAkB,UAAU,eAAe,mBAC9C,MAAM,gBAAgB,OACnB,eAAe;;;;;KAMR,aAAa,UAAU,eAAe,kBAC9C,kBAAkB;EAEhB,cAAc,kBAAkB;EAChC;;;;;;;EAOA;IAAkB;;;;;;;;;iBASR,MAAM,sBAAsB,UAAU,eAAe,gBACnE,MAAM,OACN,SAAS,GACT,UAAU,aAAa,KACtB,UAAU,OAAO;;;;;iBAQJ,WACd,sBACA,UAAU,eAAe,gBACzB,oCAEA,MAAM,OACN,UAAU,GACV,SAAS,aAAa,gBACtB,QAAQ,UACP,UAAU,OAAO,GAAG;;;;;;;iBA6EP,YAAY,iBAAiB"}
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import { r as KickDbClient, s as QueryEvent } from "./types-
|
|
3
|
-
import { t as SchemaToTypes } from "./schema-types-
|
|
2
|
+
import { r as KickDbClient, s as QueryEvent } from "./types-DTWrY_KF.mjs";
|
|
3
|
+
import { t as SchemaToTypes } from "./schema-types-wgjWxE6P.mjs";
|
|
4
4
|
//#region src/testing.d.ts
|
|
5
5
|
export interface TestDbOptions<S> {
|
|
6
6
|
schema: S;
|
package/dist/testing.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs-db v8.11.
|
|
2
|
+
* @forinda/kickjs-db v8.11.2
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import{O as emitPg,Q as extractSnapshot,Y as diff,d as migrateLatest,t as createDbClient,y as emitSqlite,z as EVENTS_ENABLED}from"./create-
|
|
11
|
+
import{O as emitPg,Q as extractSnapshot,Y as diff,d as migrateLatest,t as createDbClient,y as emitSqlite,z as EVENTS_ENABLED}from"./create-B1cXCImA.mjs";import{randomBytes}from"node:crypto";async function createTestDb(opts){let{default:Database}=await import(`better-sqlite3`),{sqliteAdapter,sqliteDialect}=await import(`./sqlite.mjs`),database=new Database(`:memory:`);if(database.pragma(`foreign_keys = ON`),opts.migrationsDir)await migrateLatest({adapter:sqliteAdapter({database}),migrationsDir:opts.migrationsDir,requireReviewed:!1,driftCheck:`ignore`});else{let empty={version:1,dialect:`sqlite`,tables:{}},target=extractSnapshot(opts.schema,`sqlite`,{casing:opts.casing});database.exec(emitSqlite(diff(empty,target),{from:empty,to:target}))}return createDbClient({schema:opts.schema,dialect:sqliteDialect({database}),casing:opts.casing,events:!0})}async function createPgTestDb(opts){let{default:pg}=await import(`pg`),{pgAdapter,pgDialect}=await import(`./pg.mjs`),name=`kick_test_${randomBytes(6).toString(`hex`)}`,admin=new pg.Client({connectionString:opts.connectionString});await admin.connect();try{await admin.query(`CREATE DATABASE "${name}"`)}finally{await admin.end()}let url=new URL(opts.connectionString);url.pathname=`/${name}`;let connectionString=url.toString(),pool=new pg.Pool({connectionString});pool.on(`error`,()=>{}),pool.on(`connect`,client=>client.on(`error`,()=>{})),opts.migrationsDir?await migrateLatest({adapter:pgAdapter({pool}),migrationsDir:opts.migrationsDir,requireReviewed:!1,driftCheck:`ignore`}):await pool.query(emitPg(diff({version:1,dialect:`postgres`,tables:{}},extractSnapshot(opts.schema,`postgres`,{casing:opts.casing}))));let db=createDbClient({schema:opts.schema,dialect:pgDialect({pool}),casing:opts.casing,events:!0});return{db,connectionString,async drop(){await db.destroy();let admin=new pg.Client({connectionString:opts.connectionString});await admin.connect();try{await admin.query(`DROP DATABASE IF EXISTS "${name}" WITH (FORCE)`)}finally{await admin.end()}}}}const ROLLBACK=Symbol(`kickjs-db rolled back`);async function rolledBack(db,fn){let result;return await db.transaction(async()=>{throw result=await fn(),ROLLBACK}).catch(err=>{if(err!==ROLLBACK)throw err}),result}async function captureQueries(db,fn){if(db[EVENTS_ENABLED]===!1)throw Error("captureQueries: this client was created without events, so no query is reported and every count would be 0. Create it with `events: true`.");let queries=[],listener=event=>void queries.push(event);db.on(`query`,listener);try{return{result:await fn(),queries}}finally{db.off(`query`,listener)}}async function expectQueries(db,count,fn){let{result,queries}=await captureQueries(db,fn);if(queries.length!==count){let list=queries.map((q,i)=>` ${i+1}. ${q.sql}`).join(`
|
|
12
12
|
`);throw Error(`Expected ${count} quer${count===1?`y`:`ies`}, ran ${queries.length}:\n${list||` (none)`}`)}return result}export{captureQueries,createPgTestDb,createTestDb,expectQueries,rolledBack};
|
|
13
13
|
//# sourceMappingURL=testing.mjs.map
|
|
@@ -410,9 +410,12 @@ declare class ColumnBuilder<T = unknown> {
|
|
|
410
410
|
* literals are normalised to their SQL-literal text so the snapshot
|
|
411
411
|
* (`ColumnSnapshot.default: string | null`) and migration emitter stay
|
|
412
412
|
* string-only. For a quoted string default the text is the value
|
|
413
|
-
* itself (`'active'`); booleans/numbers emit bare (`false`, `0`).
|
|
413
|
+
* itself (`'active'`); booleans/numbers emit bare (`false`, `0`). A JSON
|
|
414
|
+
* column takes its value (`jsonb().default({})` stores `{}`), an array
|
|
415
|
+
* column its array literal (`integer().array().default([1, 2])` stores
|
|
416
|
+
* `{1,2}`), and a `Date` its UTC time (`2026-01-02 03:04:05.000+00:00`).
|
|
414
417
|
*/
|
|
415
|
-
default(value: string | number | boolean): this & GeneratedBrand;
|
|
418
|
+
default(value: string | number | boolean | T): this & GeneratedBrand;
|
|
416
419
|
/**
|
|
417
420
|
* A default that is SQL, evaluated by the database for each new row —
|
|
418
421
|
* `id: text().primaryKey().defaultSql('gen_random_uuid()::text')`,
|
|
@@ -480,4 +483,4 @@ declare class ColumnBuilder<T = unknown> {
|
|
|
480
483
|
}
|
|
481
484
|
//#endregion
|
|
482
485
|
export { TableSnapshot as C, SchemaSnapshot as S, ForeignKeySnapshot as _, GeneratedAlwaysBrand as a, RelationSnapshot as b, KICK_NOT_NULL as c, TypedColumnRefs as d, CheckSnapshot as f, FkAction as g, EnumSnapshot as h, FkSpec as i, NotNullBrand as l, Dialect as m, ColumnRef as n, GeneratedBrand as o, ColumnSnapshot as p, ColumnState as r, KICK_GENERATED as s, ColumnBuilder as t, TypedColumnRef as u, IndexSnapshot as v, ViewSnapshot as w, RoleSnapshot as x, PolicySnapshot as y };
|
|
483
|
-
//# sourceMappingURL=types-
|
|
486
|
+
//# sourceMappingURL=types-DEVOTVGx.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-DEVOTVGx.d.mts","names":[],"sources":["../src/snapshot/types.ts","../src/dsl/columns/types.ts"],"mappings":";;KAAY;KAEA;UAEK;EACf;EACA;EACA;EACA;;EAEA;;;;;;EAMA;EACA;;EAEA;IAAc;IAAoB;;;EAElC;;EAEA;;;;;EAKA;;UAGe;EACf;;EAEA;EACA;;EAEA;;EAEA;;EAEA;;EAEA,YAAY;;EAEZ;;UAGe;EACf;EACA;EACA;EACA;EACA,UAAU;EACV,UAAU;;UAGK;EACf;EACA;;UAGe;;;;;;EAMf;;;;;;EAMA;EACA,SAAS,eAAe;EACxB,SAAS;EACT,aAAa;EACb,QAAQ;;;;;;;EAOR;IAAe;IAAe;;;EAE9B;;EAEA;IAAQ;;;EAER,WAAW;;;;;;;UAQI;EACf;;EAEA;;;;;;;;;;;;;;UAee;EACf;;EAEA;;EAEA;;EAEA;;;;;EAKA;;;;;EAKA;IAAY;IAAe;IAAkC;;;;;;EAK7D;IAAU;IAAgB;;;;;;;EAM1B;IACE;IACA,SAAS;MAAgB;M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EAUhC,UAAU,UAAU;;;;;EASpB;;;;;;EAUA;;;;;;;;EAYA,kBACE,oBACA;IAAW;aACH;;;;;EASV,oCAAoC,eAAe;;EAOnD,uCAAuC,eAAe;;;;;EAUtD,QAAQ;;;;;;EAUR,QAAQ;;EAMR,aAAa;EAIb,OAAO,eAAe;EAgBtB,WAAW,SAAS"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { l as NotNullBrand, o as GeneratedBrand, t as ColumnBuilder } from "./types-
|
|
2
|
+
import { l as NotNullBrand, o as GeneratedBrand, t as ColumnBuilder } from "./types-DEVOTVGx.mjs";
|
|
3
3
|
import { CommonTableExpression, Dialect, Expression, ExpressionBuilder, Insertable, Kysely, KyselyPlugin, SelectQueryBuilder, SelectType, Selectable, SqlBool, UpdateObject } from "kysely";
|
|
4
4
|
//#region src/client/insert-many.d.ts
|
|
5
5
|
interface InsertManyOptions {
|
|
@@ -955,4 +955,4 @@ interface CreateDbClientOptions<TSchema, _DB = unknown> {
|
|
|
955
955
|
}
|
|
956
956
|
//#endregion
|
|
957
957
|
export { TenancyStrategy as A, WithClause as C, BypassOptions as D, BypassInfo as E, ExtensionDefinition as F, ModelExtensions as I, FindOrCreateOptions as L, defineTenancy as M, tenantKey as N, Tenancy as O, ExtendedClient as P, UpsertOptions as R, TableRelations as S, RegisteredDB as T, KickDbRelationsRegister as _, ManualTransaction as a, RelationMapEntry as b, ReadRoute as c, TransactionEvent as d, TransactionOptions as f, FindManyRow as g, FindManyOptions as h, KickDbClientEvents as i, TenantRequiredError as j, TenancyOptions as k, ReadRouter as l, TransactionRollbackEvent as m, CreateDbClientOptions as n, QueryErrorEvent as o, TransactionRetryEvent as p, KickDbClient as r, QueryEvent as s, BeforeQueryEvent as t, SlowQueryEvent as u, QueryNamespace as v, KickDbRegister as w, TableQueryNamespace as x, RegisteredRelations as y, InsertManyOptions as z };
|
|
958
|
-
//# sourceMappingURL=types-
|
|
958
|
+
//# sourceMappingURL=types-DTWrY_KF.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-DTWrY_KF.d.mts","names":["_$__upsert0.UpsertOptions","_$__insert_many0.InsertManyOptions","_$__upsert0.FindOrCreateOptions","_$___extend_types0.ExtensionDefinition","_$___extend_types0.ExtendedClient","KyselyDialect","_$___tenancy0.Tenancy"],"sources":["../src/client/insert-many.ts","../src/client/upsert.ts","../src/extend/types.ts","../src/tenancy.ts","../src/client/register.ts","../src/query/types.ts","../src/client/types.ts"],"mappings":";;;;UAiBiB;;;;;EAKf;;;;;;EAMA;;;;UCTe,cAAc,IAAI,gBAAgB,qBAAqB;;;;;EAKtE,QAAQ,WAAW,GAAG,MAAM,cAAc,WAAW,GAAG;;;;;;EAMxD,QAAQ,oBAAoB,GAAG;;;;;;;;EAQ/B,SAAS,oBAAoB,GAAG,eAAe,aAAa,IAAI;;;;;;EAMhE,SAAS,IAAI,kBAAkB,IAAI,OAAO,WAAW;;;KAIlD,YAAY,QAAQ,WAAW,iBAAiB,KAAK,GAAG,aAAa,WAAU;;KAG/E,WAAW,IAAI,gBAAgB,IAAI,KAAK,KAAK,WAAW,GAAG,KAAK,YAAY,MAC/E,QAAQ,WAAW,GAAG;KAEZ,oBACV,IACA,gBAAgB,aAChB,UAAU,QAAQ,WAAW,GAAG,OAAO,QAAQ,WAAW,GAAG;;EAG7D,OAAO,IAAI,OAAO,cAAc,SAAS,WAAW,GAAG;gBACzC,WAAW,IAAI,GAAG;EAE5B,SAAS,WAAW,IAAI,GAAG;;EAC3B,QAAQ,WAAW,IAAI,GAAG;;;;;;;;;;;KCrBpB,gBAAgB,SACzB,eAAe,eAAe,mBAAmB;;;;;;;UASnC,gBAAgB;;EAE/B,OAAO,QAAQ,aAAa;;EAE5B,UAAU,KAAK;;;;;;KAOL,iBAAiB,SAC1B,eAAe,eAAe,eAAe,gBAAgB,GAAG;;UAIlD,oBAAoB;EACnC,QAAQ,gBAAgB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T;;;;;EAKA,UAXSC;;;;;;;EAkBT,UAAUD,mBAAyBA;;;;;;;;;;;EAWnC,QAAQ;;;;;;;EAOR;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BA,iDAAiD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCjD,UAAU;;;;;;EAMV"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forinda/kickjs-db",
|
|
3
|
-
"version": "8.11.
|
|
3
|
+
"version": "8.11.2",
|
|
4
4
|
"description": "KickJS-native ORM — code-first schema, reversible migrations, multi-dialect SQL builder",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kickjs",
|
|
@@ -113,9 +113,9 @@
|
|
|
113
113
|
"pg": "^8.23.1",
|
|
114
114
|
"pg-cursor": "^2.22.1",
|
|
115
115
|
"typescript": "^7.0.2",
|
|
116
|
+
"@forinda/kickjs": "10.12.0",
|
|
116
117
|
"@forinda/kickjs-devtools-kit": "7.3.0",
|
|
117
|
-
"@forinda/kickjs-schema": "0.2.4"
|
|
118
|
-
"@forinda/kickjs": "10.10.0"
|
|
118
|
+
"@forinda/kickjs-schema": "0.2.4"
|
|
119
119
|
},
|
|
120
120
|
"publishConfig": {
|
|
121
121
|
"access": "public"
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @forinda/kickjs-db v8.11.1
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Felix Orinda
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
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={}){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: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-Bku-7SqA.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom-type-Bku-7SqA.mjs","names":[],"sources":["../src/dsl/columns/types.ts","../src/custom-type.ts"],"sourcesContent":["import type { ColumnSnapshot, 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\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\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')\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')\nexport type NotNullBrand = { readonly [KICK_NOT_NULL]?: true }\n\n/**\n * Re-attach the nullability / generated 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\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 notNull(): this & NotNullBrand {\n this.state.nullable = false\n return this as this & NotNullBrand\n }\n\n primaryKey(): this & NotNullBrand {\n this.state.primaryKey = true\n this.state.nullable = false\n return this as this & NotNullBrand\n }\n\n unique(): this {\n this.state.unique = true\n return this\n }\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 references(\n target: () => ColumnRef,\n opts: { onDelete?: FkAction; onUpdate?: FkAction; name?: string } = {},\n ): this {\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`).\n */\n default(value: string | number | boolean): this & GeneratedBrand {\n this.state.default = typeof value === 'string' ? value : 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 — `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 asked `withDeleted: true`. Soft-delete by setting it.\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\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":";;;;;;;;;;AA8GA,MAAa,eAAiB,OAAO,IAAI,8BAA8B,EAsB1D,cAAgB,OAAO,IA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