@forinda/kickjs-db 7.1.1 → 7.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.d.mts +1 -2
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/devtools-events.d.mts +2 -3
- package/dist/devtools-events.d.mts.map +1 -1
- package/dist/devtools-events.mjs +1 -1
- package/dist/{index-DcuMZ9kb.d.mts → index-Ci5DXgUh.d.mts} +94 -12
- package/dist/index-Ci5DXgUh.d.mts.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/mysql.d.mts +1 -2
- package/dist/mysql.d.mts.map +1 -1
- package/dist/mysql.mjs +2 -2
- package/dist/pg.d.mts +57 -3
- package/dist/pg.d.mts.map +1 -1
- package/dist/pg.mjs +3 -3
- package/dist/pg.mjs.map +1 -1
- package/dist/sqlite.d.mts +1 -2
- package/dist/sqlite.d.mts.map +1 -1
- package/dist/sqlite.mjs +2 -2
- package/dist/{src-_M69mn2G.mjs → src-BLr8KOo1.mjs} +11 -11
- package/dist/src-BLr8KOo1.mjs.map +1 -0
- package/dist/{types-BZGFAXPN.d.mts → types-NkfgZHEN.d.mts} +9 -10
- package/dist/types-NkfgZHEN.d.mts.map +1 -0
- package/package.json +12 -12
- package/dist/index-DcuMZ9kb.d.mts.map +0 -1
- package/dist/src-_M69mn2G.mjs.map +0 -1
- package/dist/types-BZGFAXPN.d.mts.map +0 -1
package/dist/pg.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
2
|
+
import { Mt as ColumnBuilder, Nt as ColumnRef, Tt as TableDecl, kt as IndexDecl, ln as MigrationAdapter } from "./index-Ci5DXgUh.mjs";
|
|
3
3
|
import { Dialect } from "kysely";
|
|
4
|
-
|
|
5
4
|
//#region src/dsl/columns/pg.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Declare a PostgreSQL ENUM type.
|
|
@@ -50,6 +49,61 @@ declare function inet(): ColumnBuilder<string>;
|
|
|
50
49
|
declare function cidr(): ColumnBuilder<string>;
|
|
51
50
|
declare function xml(): ColumnBuilder<string>;
|
|
52
51
|
//#endregion
|
|
52
|
+
//#region src/dsl/pg-schema.d.ts
|
|
53
|
+
/**
|
|
54
|
+
* PostgreSQL named-schema namespace.
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* const billing = pgSchema('billing')
|
|
58
|
+
*
|
|
59
|
+
* const invoices = billing.table('invoices', {
|
|
60
|
+
* id: uuid().primaryKey().defaultRandom(),
|
|
61
|
+
* total: numeric().notNull(),
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* Emits `CREATE SCHEMA IF NOT EXISTS "billing"` ahead of the tables that need
|
|
66
|
+
* it, qualifies every generated statement (`"billing"."invoices"`), and keys
|
|
67
|
+
* the row type as `KickDbSchema['billing.invoices']` so Kysely resolves the
|
|
68
|
+
* qualified table without a `withSchema()` call.
|
|
69
|
+
*
|
|
70
|
+
* Tables declared through the bare `table()` factory are untouched: no schema
|
|
71
|
+
* field, bare identifiers, same snapshot bytes and migration hashes as before.
|
|
72
|
+
*
|
|
73
|
+
* PostgreSQL only. A schema is a true namespace only on PG — on MySQL the
|
|
74
|
+
* word means "database" and on SQLite it means an `ATTACH` alias, both of
|
|
75
|
+
* which have different lifecycles than `CREATE SCHEMA`. Declaring one and
|
|
76
|
+
* then diffing against MySQL/SQLite throws rather than emitting DDL that
|
|
77
|
+
* looks right and means something else.
|
|
78
|
+
*/
|
|
79
|
+
interface PgSchema<TSchema extends string | undefined = string | undefined> {
|
|
80
|
+
readonly __isPgSchema: true;
|
|
81
|
+
/** The schema name as declared, e.g. `billing`. */
|
|
82
|
+
readonly name: string;
|
|
83
|
+
table<TName extends string, C extends Record<string, ColumnBuilder>>(name: TName, columns: C, constraints?: (refs: { [K in keyof C]: ColumnRef; }) => Record<string, IndexDecl>): TableDecl<TName, C, TSchema> & { [K in keyof C]: ColumnRef; };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `public` resolves to "no schema" rather than to itself.
|
|
87
|
+
*
|
|
88
|
+
* PG creates `public` for every database and puts it on the default
|
|
89
|
+
* search_path, so `pgSchema('public').table('users', …)` and
|
|
90
|
+
* `table('users', …)` name the same physical table. If the former stamped
|
|
91
|
+
* `schema: 'public'`, its snapshot key would be `public.users` while the
|
|
92
|
+
* latter's is `users` — the diff engine would read that as "drop `users`,
|
|
93
|
+
* create `public.users`" and emit a DROP TABLE. Collapsing to `undefined`
|
|
94
|
+
* keeps the two spellings interchangeable, and the conditional return type
|
|
95
|
+
* below keeps the static key in step with the runtime one.
|
|
96
|
+
*/
|
|
97
|
+
type EffectiveSchema<TName extends string> = TName extends 'public' ? undefined : TName;
|
|
98
|
+
/**
|
|
99
|
+
* Declare a PostgreSQL schema namespace. See {@link PgSchema}.
|
|
100
|
+
*
|
|
101
|
+
* `pgSchema('public')` is accepted and collapses to "no schema" — see
|
|
102
|
+
* {@link EffectiveSchema} for why that matters.
|
|
103
|
+
*/
|
|
104
|
+
declare function pgSchema<TName extends string>(name: TName): PgSchema<EffectiveSchema<TName>>;
|
|
105
|
+
declare function isPgSchema(value: unknown): value is PgSchema<string>;
|
|
106
|
+
//#endregion
|
|
53
107
|
//#region src/adapters/pg/adapter.d.ts
|
|
54
108
|
/**
|
|
55
109
|
* Minimal client returned by PgPoolLike.connect(). Matches the shape of
|
|
@@ -131,5 +185,5 @@ interface PgDialectOptions {
|
|
|
131
185
|
*/
|
|
132
186
|
declare function pgDialect(opts: PgDialectOptions): Dialect;
|
|
133
187
|
//#endregion
|
|
134
|
-
export { PgAdapterOptions, PgClientLike, PgDialectOptions, PgEnumBuilder, PgEnumColumnBuilder, PgPoolLike, cidr, citext, inet, money, pgAdapter, pgDialect, pgEnum, tsvector, vector, xml };
|
|
188
|
+
export { PgAdapterOptions, PgClientLike, PgDialectOptions, PgEnumBuilder, PgEnumColumnBuilder, PgPoolLike, PgSchema, cidr, citext, inet, isPgSchema, money, pgAdapter, pgDialect, pgEnum, pgSchema, tsvector, vector, xml };
|
|
135
189
|
//# sourceMappingURL=pg.d.mts.map
|
package/dist/pg.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg.d.mts","names":[],"sources":["../src/dsl/columns/pg.ts","../src/adapters/pg/adapter.ts","../src/adapters/pg/dialect.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pg.d.mts","names":[],"sources":["../src/dsl/columns/pg.ts","../src/dsl/pg-schema.ts","../src/adapters/pg/adapter.ts","../src/adapters/pg/dialect.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;UA8BiB,cAAc,sBAAsB;MAC/C,oBAAoB,OAAO;;WAEtB,UAAU;;WAEV,QAAQ;;cAGN,oBACX,sBACA,2CACQ,cAAc;;WAEb,UAAU;;WAEV,QAAQ;EAEjB,YAAY,UAAU,OAAO,QAAQ;;iBAgBvB,OAAO,4BAA4B,gDACjD,MAAM,UACH,QAAQ,UACV,cAAc,OAAO;iBASR,YAAY;iBAIZ,OAAO,eAAe;iBAItB,UAAU;iBAIV,SAAS;iBAIT,QAAQ;iBAIR,QAAQ;iBAIR,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UCrEN,SAAS;WACf;;WAEA;EAET,MAAM,sBAAsB,UAAU,eAAe,gBACnD,MAAM,OACN,SAAS,GACT,eAAe,SAAS,WAAW,IAAI,iBAAgB,eAAe,aACrE,UAAU,OAAO,GAAG,cAAc,WAAW,IAAI;;;;;;;;;;;;;;KAejD,gBAAgB,wBAAwB,qCAAqC;;;;;;;iBAWlE,SAAS,sBAAsB,MAAM,QAAQ,SAAS,gBAAgB;iBA6BtE,WAAW,iBAAiB,SAAS;;;;;;;UChFpC;EACf,MAAM,aACJ,aACA,8BACC;IAAU,MAAM;IAAK;;EACxB;;;;;;;;;;;;;UAce;EACf,MAAM,aACJ,aACA,8BACC;IAAU,MAAM;IAAK;;EACxB,WAAW,QAAQ;;UAGJ;;;;;EAKf,MAAM;;EAEN;;;;;;;;;;;;iBAec,UAAU,MAAM,mBAAmB;;;UCpDlC;;;;;;EAMf,MAAM;;;;;;;;;;;;;;;;;;;;;iBAsBQ,UAAU,MAAM,mBAAmB"}
|
package/dist/pg.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs-db v7.
|
|
2
|
+
* @forinda/kickjs-db v7.2.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import{
|
|
11
|
+
import{H as ColumnBuilder,R as markDialect,Vt as buildTable,dt as migrationsTableDdl,ot as introspectPg,ut as lockTableDdl}from"./src-BLr8KOo1.mjs";import{PostgresDialect}from"kysely";var PgEnumColumnBuilder=class extends ColumnBuilder{enumName;values;constructor(enumName,values){super(enumName),this.enumName=enumName,this.values=values}};function pgEnum(name,...values){return Object.assign(()=>new PgEnumColumnBuilder(name,values),{enumName:name,values})}function tsvector(){return new ColumnBuilder(`tsvector`)}function vector(dim){return new ColumnBuilder(dim===void 0?`vector`:`vector(${dim})`)}function citext(){return new ColumnBuilder(`citext`)}function money(){return new ColumnBuilder(`money`)}function inet(){return new ColumnBuilder(`inet`)}function cidr(){return new ColumnBuilder(`cidr`)}function xml(){return new ColumnBuilder(`xml`)}const SCHEMA_NAME=/^[A-Za-z_][A-Za-z0-9_$]*$/;function pgSchema(name){if(typeof name!=`string`||!SCHEMA_NAME.test(name))throw Error(`pgSchema: invalid schema name ${JSON.stringify(name)}. Expected an unquoted PostgreSQL identifier matching ${SCHEMA_NAME.source}.`);let effective=name===`public`?void 0:name;return{__isPgSchema:!0,name,table(tableName,columns,constraints){return buildTable(tableName,columns,constraints,effective)}}}function isPgSchema(value){return typeof value==`object`&&!!value&&value.__isPgSchema===!0}const SAFE_SCHEMA_NAME=/^[a-z_][a-z0-9_]*$/i;function pgAdapter(opts){let dialect=`postgres`,{pool}=opts,schema=opts.schema??`public`;if(!SAFE_SCHEMA_NAME.test(schema))throw Error(`Invalid PG schema name: ${schema}`);return{dialect,async ensureMigrationTables(){await pool.query(migrationsTableDdl(dialect)),await pool.query(lockTableDdl(dialect))},async listApplied(){return(await pool.query(`SELECT id, name, hash, batch, applied_at, direction
|
|
12
12
|
FROM kick_migrations
|
|
13
13
|
ORDER BY applied_at ASC, id ASC`)).rows.map(row=>({id:row.id,name:row.name,hash:row.hash,batch:Number(row.batch),appliedAt:row.applied_at instanceof Date?row.applied_at.toISOString():String(row.applied_at),direction:row.direction}))},async recordApplied(row){await pool.query(`INSERT INTO kick_migrations (id, name, hash, batch, direction)
|
|
14
14
|
VALUES ($1, $2, $3, $4, $5)`,[row.id,row.name,row.hash,row.batch,row.direction])},async removeApplied(id){await pool.query(`DELETE FROM kick_migrations WHERE id = $1`,[id])},async acquireLock(owner){return(await pool.query(`UPDATE kick_migrations_lock
|
|
15
15
|
SET locked_at = CURRENT_TIMESTAMP, locked_by = $1
|
|
16
16
|
WHERE id = 1 AND locked_at IS NULL`,[owner])).rowCount===1},async releaseLock(){await pool.query(`UPDATE kick_migrations_lock
|
|
17
17
|
SET locked_at = NULL, locked_by = NULL
|
|
18
|
-
WHERE id = 1`)},async applySqlInTx(sql){let client=await pool.connect();try{await client.query(`BEGIN`),await client.query(sql),await client.query(`COMMIT`)}catch(err){throw await client.query(`ROLLBACK`).catch(()=>{}),err}finally{client.release()}},async applySqlNoTx(sql){await pool.query(sql)},async introspect(){return introspectPg(pool,{schema})},async close(){}}}function pgDialect(opts){return markDialect(new PostgresDialect({pool:opts.pool}),`postgres`)}export{PgEnumColumnBuilder,cidr,citext,inet,money,pgAdapter,pgDialect,pgEnum,tsvector,vector,xml};
|
|
18
|
+
WHERE id = 1`)},async applySqlInTx(sql){let client=await pool.connect();try{await client.query(`BEGIN`),await client.query(sql),await client.query(`COMMIT`)}catch(err){throw await client.query(`ROLLBACK`).catch(()=>{}),err}finally{client.release()}},async applySqlNoTx(sql){await pool.query(sql)},async introspect(){return introspectPg(pool,{schema})},async close(){}}}function pgDialect(opts){return markDialect(new PostgresDialect({pool:opts.pool}),`postgres`)}export{PgEnumColumnBuilder,cidr,citext,inet,isPgSchema,money,pgAdapter,pgDialect,pgEnum,pgSchema,tsvector,vector,xml};
|
|
19
19
|
//# sourceMappingURL=pg.mjs.map
|
package/dist/pg.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg.mjs","names":[],"sources":["../src/dsl/columns/pg.ts","../src/adapters/pg/adapter.ts","../src/adapters/pg/dialect.ts"],"sourcesContent":["import { ColumnBuilder } from './types'\n\n// PG-only column types. Phantom T per builder so SchemaToTypes<S> can narrow\n// each column to a useful TS shape — strings for the text-y types, number[]\n// for vector embeddings, etc.\n\n/**\n * Declare a PostgreSQL ENUM type.\n *\n * @example\n * ```ts\n * export const taskStatus = pgEnum('task_status', 'todo', 'in_progress', 'done')\n *\n * export const tasks = table('tasks', {\n * id: uuid().primaryKey().defaultRandom(),\n * status: taskStatus().notNull().default('todo'),\n * })\n * ```\n *\n * The factory returns a column builder whose phantom type narrows to\n * the union of the declared values — `db.selectFrom('tasks').select('status')`\n * types `status: 'todo' | 'in_progress' | 'done'`.\n *\n * Schema-level state (the enum name + values) is attached to every\n * column the factory produces so introspection / drift / emit can pick\n * it up. The snapshot + emit pipeline learns about enum types in the\n * follow-up commit; for now adopters must run the\n * `CREATE TYPE <name> AS ENUM (...)` DDL manually before any column\n * referencing the type is created.\n */\nexport interface PgEnumBuilder<TName extends string, TValues extends readonly string[]> {\n (): PgEnumColumnBuilder<TName, TValues>\n /** The SQL identifier — used by emit + drift detection. */\n readonly enumName: TName\n /** Allowed literal values, in declaration order. */\n readonly values: TValues\n}\n\nexport class PgEnumColumnBuilder<\n TName extends string,\n TValues extends readonly string[],\n> extends ColumnBuilder<TValues[number]> {\n /** The enum's SQL identifier — preserved for emit + drift detection. */\n readonly enumName: TName\n /** Allowed values — readonly to prevent mutation across columns. */\n readonly values: TValues\n\n constructor(enumName: TName, values: TValues) {\n // The SQL data type IS the enum identifier — `status task_status`,\n // not `status text` — so PG enforces the membership constraint.\n super(enumName)\n this.enumName = enumName\n this.values = values\n }\n}\n\n// Variadic rest forces TS to infer EACH value as its literal type, so\n// `pgEnum('s', 'todo', 'done')` resolves to\n// `PgEnumBuilder<'s', ['todo', 'done']>`. Without rest, an array\n// literal stored in a variable would widen to `string[]` and the\n// column phantom would collapse to plain `string`, defeating the\n// entire point of the helper. Adopters with a pre-existing array\n// can still spread it: `pgEnum('s', ...VALUES as const)`.\nexport function pgEnum<TName extends string, const TValues extends readonly [string, ...string[]]>(\n name: TName,\n ...values: TValues\n): PgEnumBuilder<TName, TValues> {\n const factory = (): PgEnumColumnBuilder<TName, TValues> =>\n new PgEnumColumnBuilder<TName, TValues>(name, values)\n // Attach metadata to the factory itself so introspection that walks\n // `Object.values(schema)` can discover enum declarations even when\n // they're declared standalone (without a column reference).\n return Object.assign(factory, { enumName: name, values }) as PgEnumBuilder<TName, TValues>\n}\n\nexport function tsvector(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('tsvector')\n}\n\nexport function vector(dim?: number): ColumnBuilder<number[]> {\n return new ColumnBuilder<number[]>(dim === undefined ? 'vector' : `vector(${dim})`)\n}\n\nexport function citext(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('citext')\n}\n\nexport function money(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('money')\n}\n\nexport function inet(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('inet')\n}\n\nexport function cidr(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('cidr')\n}\n\nexport function xml(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('xml')\n}\n","import {\n introspectPg,\n lockTableDdl,\n migrationsTableDdl,\n type Dialect,\n type MigrationAdapter,\n type MigrationRow,\n type SchemaSnapshot,\n} from '../../index'\n\n/**\n * Minimal client returned by PgPoolLike.connect(). Matches the shape of\n * pg.PoolClient and @neondatabase/serverless's PoolClient.\n */\nexport interface PgClientLike {\n query<R = unknown>(\n sql: string,\n params?: readonly unknown[],\n ): Promise<{ rows: R[]; rowCount: number | null }>\n release(): void\n}\n\n/**\n * Pool-shaped contract that pgAdapter consumes. Both `pg.Pool` and\n * `@neondatabase/serverless`'s Pool match this structurally — no hard\n * dependency on the `pg` package. Adopters pick whichever pg-protocol-\n * compatible client fits their runtime (node-postgres / neon-serverless /\n * pg-cloudflare / etc).\n *\n * Edge runtimes with a different surface (Neon HTTP single-shot,\n * Cloudflare D1's batch-only model) have their own adapter packages that\n * implement MigrationAdapter directly — they don't reuse this shape.\n */\nexport interface PgPoolLike {\n query<R = unknown>(\n sql: string,\n params?: readonly unknown[],\n ): Promise<{ rows: R[]; rowCount: number | null }>\n connect(): Promise<PgClientLike>\n}\n\nexport interface PgAdapterOptions {\n /**\n * A pg-protocol-compatible Pool. Concretely: pg.Pool, neon-serverless Pool,\n * any other Pool that satisfies the {@link PgPoolLike} structural shape.\n */\n pool: PgPoolLike\n /** PG schema name to scope the introspector and validate at construction. Default 'public'. */\n schema?: string\n}\n\nconst SAFE_SCHEMA_NAME = /^[a-z_][a-z0-9_]*$/i\n\n/**\n * MigrationAdapter implementation backed by node-postgres. The pool is\n * caller-owned — close() does NOT end() the pool because adopters typically\n * share a single pool across the migrationAdapter and the KickDbClient.\n *\n * Lock semantics: single-row UPDATE WHERE locked_at IS NULL on\n * kick_migrations_lock. Only the row created by ensureMigrationTables()\n * exists, so the UPDATE either flips locked_at and returns rowCount=1\n * (we won) or matches zero rows (someone else holds it).\n */\nexport function pgAdapter(opts: PgAdapterOptions): MigrationAdapter {\n const dialect: Dialect = 'postgres'\n const { pool } = opts\n const schema = opts.schema ?? 'public'\n if (!SAFE_SCHEMA_NAME.test(schema)) {\n // Schema name lands inside introspection queries unparameterised so guard\n // here rather than down at the SQL boundary.\n throw new Error(`Invalid PG schema name: ${schema}`)\n }\n\n return {\n dialect,\n\n async ensureMigrationTables() {\n await pool.query(migrationsTableDdl(dialect))\n await pool.query(lockTableDdl(dialect))\n },\n\n async listApplied(): Promise<MigrationRow[]> {\n const r = await pool.query<{\n id: string\n name: string\n hash: string\n batch: number | string\n applied_at: string | Date\n direction: 'up' | 'down'\n }>(\n `SELECT id, name, hash, batch, applied_at, direction\n FROM kick_migrations\n ORDER BY applied_at ASC, id ASC`,\n )\n return r.rows.map((row) => ({\n id: row.id,\n name: row.name,\n hash: row.hash,\n batch: Number(row.batch),\n appliedAt:\n row.applied_at instanceof Date ? row.applied_at.toISOString() : String(row.applied_at),\n direction: row.direction,\n }))\n },\n\n async recordApplied(row) {\n await pool.query(\n `INSERT INTO kick_migrations (id, name, hash, batch, direction)\n VALUES ($1, $2, $3, $4, $5)`,\n [row.id, row.name, row.hash, row.batch, row.direction],\n )\n },\n\n async removeApplied(id: string) {\n await pool.query(`DELETE FROM kick_migrations WHERE id = $1`, [id])\n },\n\n async acquireLock(owner: string): Promise<boolean> {\n const r = await pool.query(\n `UPDATE kick_migrations_lock\n SET locked_at = CURRENT_TIMESTAMP, locked_by = $1\n WHERE id = 1 AND locked_at IS NULL`,\n [owner],\n )\n return r.rowCount === 1\n },\n\n async releaseLock() {\n await pool.query(\n `UPDATE kick_migrations_lock\n SET locked_at = NULL, locked_by = NULL\n WHERE id = 1`,\n )\n },\n\n async applySqlInTx(sql: string) {\n const client = await pool.connect()\n try {\n await client.query('BEGIN')\n await client.query(sql)\n await client.query('COMMIT')\n } catch (err) {\n await client.query('ROLLBACK').catch(() => {\n /* swallow rollback errors; we're already throwing the original */\n })\n throw err\n } finally {\n client.release()\n }\n },\n\n async applySqlNoTx(sql: string) {\n await pool.query(sql)\n },\n\n async introspect(): Promise<SchemaSnapshot> {\n return introspectPg(pool, { schema })\n },\n\n async close() {\n // Caller owns the pool. kickDbAdapter's shutdown lifecycle calls this so\n // future adapter-internal teardown (e.g. cancelling pending observers)\n // has a hook, but we deliberately don't end() the shared pool.\n },\n }\n}\n","// pgDialect — thin factory over Kysely's PostgresDialect so adopters\n// never have to write `import { PostgresDialect } from 'kysely'`.\n// Kysely is a pinned internal dep of the framework; surfacing it\n// through our own export keeps the adopter import surface stable\n// even when we change query backends (or fork Kysely's internals).\n\nimport { PostgresDialect, type Dialect as KyselyDialect } from 'kysely'\nimport { markDialect } from '../../dialect-marker'\n\nimport type { PgPoolLike } from './adapter'\n\nexport interface PgDialectOptions {\n /**\n * pg-protocol-compatible pool. Both `pg.Pool` and\n * `@neondatabase/serverless`'s Pool match structurally; adopters\n * pick whichever runtime fits.\n */\n pool: PgPoolLike\n}\n\n/**\n * Construct the dialect that `createDbClient({ dialect })` consumes.\n *\n * @example\n * ```ts\n * import { createDbClient } from '@forinda/kickjs-db'\n * import { pgDialect, pgAdapter } from '@forinda/kickjs-db/pg'\n * import { Pool } from 'pg'\n *\n * const pool = new Pool({ connectionString: process.env.DATABASE_URL })\n *\n * export const db = createDbClient({\n * schema,\n * dialect: pgDialect({ pool }),\n * })\n *\n * export const migrationAdapter = pgAdapter({ pool })\n * ```\n */\nexport function pgDialect(opts: PgDialectOptions): KyselyDialect {\n // PostgresDialect's `pool` parameter is typed as `PG.Pool` in newer\n // Kysely versions; casting through `unknown` keeps adopters using\n // alternate clients (neon, pg-cloudflare) compatible without\n // pulling node-postgres' typings into our public surface.\n return markDialect(new PostgresDialect({ pool: opts.pool as unknown as never }), 'postgres')\n}\n"],"mappings":";;;;;;;;;;uKAsCA,IAAa,oBAAb,cAGU,aAA+B,CAEvC,SAEA,OAEA,YAAY,SAAiB,OAAiB,CAG5C,MAAM,QAAQ,EACd,KAAK,SAAW,SAChB,KAAK,OAAS,MAChB,CACF,EASA,SAAgB,OACd,KACA,GAAG,OAC4B,CAM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AM,IAAI,KAAM,IAAI,MAAO,IAAI,SAAS,CACvD,CACF,EAEA,MAAM,cAAc,GAAY,CAC9B,MAAM,KAAK,MAAM,4CAA6C,CAAC,EAAE,CAAC,CACpE,EAEA,MAAM,YAAY,MAAiC,CAOjD,OAAO,MANS,KAAK,MACnB;;6CAGA,CAAC,KAAK,CACR,EAAA,CACS,WAAa,CACxB,EAEA,MAAM,aAAc,CAClB,MAAM,KAAK,MACT;;sBAGF,CACF,EAEA,MAAM,aAAa,IAAa,CAC9B,IAAM,OAAS,MAAM,KAAK,QAAQ,EAClC,GAAI,CACF,MAAM,OAAO,MAAM,OAAO,EAC1B,MAAM,OAAO,MAAM,GAAG,EACtB,MAAM,OAAO,MAAM,QAAQ,CAC7B,OAAS,IAAK,CAIZ,MAHA,MAAM,OAAO,MAAM,UAAU,CAAC,CAAC,UAAY,CAE3C,CAAC,EACK,GACR,QAAU,CACR,OAAO,QAAQ,CACjB,CACF,EAEA,MAAM,aAAa,IAAa,CAC9B,MAAM,KAAK,MAAM,GAAG,CACtB,EAEA,MAAM,YAAsC,CAC1C,OAAO,aAAa,KAAM,CAAE,MAAO,CAAC,CACtC,EAEA,MAAM,OAAQ,CAId,CACF,CACF,CC9HA,SAAgB,UAAU,KAAuC,CAK/D,OAAO,YAAY,IAAI,gBAAgB,CAAE,KAAM,KAAK,IAAyB,CAAC,EAAG,UAAU,CAC7F"}
|
|
1
|
+
{"version":3,"file":"pg.mjs","names":[],"sources":["../src/dsl/columns/pg.ts","../src/dsl/pg-schema.ts","../src/adapters/pg/adapter.ts","../src/adapters/pg/dialect.ts"],"sourcesContent":["import { ColumnBuilder } from './types'\n\n// PG-only column types. Phantom T per builder so SchemaToTypes<S> can narrow\n// each column to a useful TS shape — strings for the text-y types, number[]\n// for vector embeddings, etc.\n\n/**\n * Declare a PostgreSQL ENUM type.\n *\n * @example\n * ```ts\n * export const taskStatus = pgEnum('task_status', 'todo', 'in_progress', 'done')\n *\n * export const tasks = table('tasks', {\n * id: uuid().primaryKey().defaultRandom(),\n * status: taskStatus().notNull().default('todo'),\n * })\n * ```\n *\n * The factory returns a column builder whose phantom type narrows to\n * the union of the declared values — `db.selectFrom('tasks').select('status')`\n * types `status: 'todo' | 'in_progress' | 'done'`.\n *\n * Schema-level state (the enum name + values) is attached to every\n * column the factory produces so introspection / drift / emit can pick\n * it up. The snapshot + emit pipeline learns about enum types in the\n * follow-up commit; for now adopters must run the\n * `CREATE TYPE <name> AS ENUM (...)` DDL manually before any column\n * referencing the type is created.\n */\nexport interface PgEnumBuilder<TName extends string, TValues extends readonly string[]> {\n (): PgEnumColumnBuilder<TName, TValues>\n /** The SQL identifier — used by emit + drift detection. */\n readonly enumName: TName\n /** Allowed literal values, in declaration order. */\n readonly values: TValues\n}\n\nexport class PgEnumColumnBuilder<\n TName extends string,\n TValues extends readonly string[],\n> extends ColumnBuilder<TValues[number]> {\n /** The enum's SQL identifier — preserved for emit + drift detection. */\n readonly enumName: TName\n /** Allowed values — readonly to prevent mutation across columns. */\n readonly values: TValues\n\n constructor(enumName: TName, values: TValues) {\n // The SQL data type IS the enum identifier — `status task_status`,\n // not `status text` — so PG enforces the membership constraint.\n super(enumName)\n this.enumName = enumName\n this.values = values\n }\n}\n\n// Variadic rest forces TS to infer EACH value as its literal type, so\n// `pgEnum('s', 'todo', 'done')` resolves to\n// `PgEnumBuilder<'s', ['todo', 'done']>`. Without rest, an array\n// literal stored in a variable would widen to `string[]` and the\n// column phantom would collapse to plain `string`, defeating the\n// entire point of the helper. Adopters with a pre-existing array\n// can still spread it: `pgEnum('s', ...VALUES as const)`.\nexport function pgEnum<TName extends string, const TValues extends readonly [string, ...string[]]>(\n name: TName,\n ...values: TValues\n): PgEnumBuilder<TName, TValues> {\n const factory = (): PgEnumColumnBuilder<TName, TValues> =>\n new PgEnumColumnBuilder<TName, TValues>(name, values)\n // Attach metadata to the factory itself so introspection that walks\n // `Object.values(schema)` can discover enum declarations even when\n // they're declared standalone (without a column reference).\n return Object.assign(factory, { enumName: name, values }) as PgEnumBuilder<TName, TValues>\n}\n\nexport function tsvector(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('tsvector')\n}\n\nexport function vector(dim?: number): ColumnBuilder<number[]> {\n return new ColumnBuilder<number[]>(dim === undefined ? 'vector' : `vector(${dim})`)\n}\n\nexport function citext(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('citext')\n}\n\nexport function money(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('money')\n}\n\nexport function inet(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('inet')\n}\n\nexport function cidr(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('cidr')\n}\n\nexport function xml(): ColumnBuilder<string> {\n return new ColumnBuilder<string>('xml')\n}\n","import type { ColumnBuilder, ColumnRef } from './columns/types'\nimport type { IndexDecl } from './constraints'\nimport { buildTable, type TableDecl } from './table'\n\n/**\n * PostgreSQL named-schema namespace.\n *\n * ```ts\n * const billing = pgSchema('billing')\n *\n * const invoices = billing.table('invoices', {\n * id: uuid().primaryKey().defaultRandom(),\n * total: numeric().notNull(),\n * })\n * ```\n *\n * Emits `CREATE SCHEMA IF NOT EXISTS \"billing\"` ahead of the tables that need\n * it, qualifies every generated statement (`\"billing\".\"invoices\"`), and keys\n * the row type as `KickDbSchema['billing.invoices']` so Kysely resolves the\n * qualified table without a `withSchema()` call.\n *\n * Tables declared through the bare `table()` factory are untouched: no schema\n * field, bare identifiers, same snapshot bytes and migration hashes as before.\n *\n * PostgreSQL only. A schema is a true namespace only on PG — on MySQL the\n * word means \"database\" and on SQLite it means an `ATTACH` alias, both of\n * which have different lifecycles than `CREATE SCHEMA`. Declaring one and\n * then diffing against MySQL/SQLite throws rather than emitting DDL that\n * looks right and means something else.\n */\nexport interface PgSchema<TSchema extends string | undefined = string | undefined> {\n readonly __isPgSchema: true\n /** The schema name as declared, e.g. `billing`. */\n readonly name: string\n\n table<TName extends string, C extends Record<string, ColumnBuilder>>(\n name: TName,\n columns: C,\n constraints?: (refs: { [K in keyof C]: ColumnRef }) => Record<string, IndexDecl>,\n ): TableDecl<TName, C, TSchema> & { [K in keyof C]: ColumnRef }\n}\n\n/**\n * `public` resolves to \"no schema\" rather than to itself.\n *\n * PG creates `public` for every database and puts it on the default\n * search_path, so `pgSchema('public').table('users', …)` and\n * `table('users', …)` name the same physical table. If the former stamped\n * `schema: 'public'`, its snapshot key would be `public.users` while the\n * latter's is `users` — the diff engine would read that as \"drop `users`,\n * create `public.users`\" and emit a DROP TABLE. Collapsing to `undefined`\n * keeps the two spellings interchangeable, and the conditional return type\n * below keeps the static key in step with the runtime one.\n */\ntype EffectiveSchema<TName extends string> = TName extends 'public' ? undefined : TName\n\n/** Reject names that would need quoting gymnastics or inject into DDL. */\nconst SCHEMA_NAME = /^[A-Za-z_][A-Za-z0-9_$]*$/\n\n/**\n * Declare a PostgreSQL schema namespace. See {@link PgSchema}.\n *\n * `pgSchema('public')` is accepted and collapses to \"no schema\" — see\n * {@link EffectiveSchema} for why that matters.\n */\nexport function pgSchema<TName extends string>(name: TName): PgSchema<EffectiveSchema<TName>> {\n // The typeof check is load-bearing, not belt-and-braces: `RegExp.test(x)`\n // stringifies its argument, so the regex alone accepts `undefined`\n // ('undefined'), `null` ('null'), `true` ('true') and `['a']` ('a'). Each\n // fails differently downstream — `undefined` yields a silently unqualified\n // table, `null` serializes `\"schema\": null` into the snapshot, and the\n // others key a table `\"true.x\"` / `\"a.x\"` and emit DDL creating a schema by\n // that name. TS forbids all of them; JS callers and `any` do not.\n if (typeof name !== 'string' || !SCHEMA_NAME.test(name)) {\n throw new Error(\n `pgSchema: invalid schema name ${JSON.stringify(name)}. ` +\n `Expected an unquoted PostgreSQL identifier matching ${SCHEMA_NAME.source}.`,\n )\n }\n const effective = (name === 'public' ? undefined : name) as EffectiveSchema<TName>\n\n return {\n __isPgSchema: true,\n name,\n table<TName2 extends string, C extends Record<string, ColumnBuilder>>(\n tableName: TName2,\n columns: C,\n constraints?: (refs: { [K in keyof C]: ColumnRef }) => Record<string, IndexDecl>,\n ) {\n return buildTable(tableName, columns, constraints, effective)\n },\n }\n}\n\nexport function isPgSchema(value: unknown): value is PgSchema<string> {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { __isPgSchema?: unknown }).__isPgSchema === true\n )\n}\n","import {\n introspectPg,\n lockTableDdl,\n migrationsTableDdl,\n type Dialect,\n type MigrationAdapter,\n type MigrationRow,\n type SchemaSnapshot,\n} from '../../index'\n\n/**\n * Minimal client returned by PgPoolLike.connect(). Matches the shape of\n * pg.PoolClient and @neondatabase/serverless's PoolClient.\n */\nexport interface PgClientLike {\n query<R = unknown>(\n sql: string,\n params?: readonly unknown[],\n ): Promise<{ rows: R[]; rowCount: number | null }>\n release(): void\n}\n\n/**\n * Pool-shaped contract that pgAdapter consumes. Both `pg.Pool` and\n * `@neondatabase/serverless`'s Pool match this structurally — no hard\n * dependency on the `pg` package. Adopters pick whichever pg-protocol-\n * compatible client fits their runtime (node-postgres / neon-serverless /\n * pg-cloudflare / etc).\n *\n * Edge runtimes with a different surface (Neon HTTP single-shot,\n * Cloudflare D1's batch-only model) have their own adapter packages that\n * implement MigrationAdapter directly — they don't reuse this shape.\n */\nexport interface PgPoolLike {\n query<R = unknown>(\n sql: string,\n params?: readonly unknown[],\n ): Promise<{ rows: R[]; rowCount: number | null }>\n connect(): Promise<PgClientLike>\n}\n\nexport interface PgAdapterOptions {\n /**\n * A pg-protocol-compatible Pool. Concretely: pg.Pool, neon-serverless Pool,\n * any other Pool that satisfies the {@link PgPoolLike} structural shape.\n */\n pool: PgPoolLike\n /** PG schema name to scope the introspector and validate at construction. Default 'public'. */\n schema?: string\n}\n\nconst SAFE_SCHEMA_NAME = /^[a-z_][a-z0-9_]*$/i\n\n/**\n * MigrationAdapter implementation backed by node-postgres. The pool is\n * caller-owned — close() does NOT end() the pool because adopters typically\n * share a single pool across the migrationAdapter and the KickDbClient.\n *\n * Lock semantics: single-row UPDATE WHERE locked_at IS NULL on\n * kick_migrations_lock. Only the row created by ensureMigrationTables()\n * exists, so the UPDATE either flips locked_at and returns rowCount=1\n * (we won) or matches zero rows (someone else holds it).\n */\nexport function pgAdapter(opts: PgAdapterOptions): MigrationAdapter {\n const dialect: Dialect = 'postgres'\n const { pool } = opts\n const schema = opts.schema ?? 'public'\n if (!SAFE_SCHEMA_NAME.test(schema)) {\n // Schema name lands inside introspection queries unparameterised so guard\n // here rather than down at the SQL boundary.\n throw new Error(`Invalid PG schema name: ${schema}`)\n }\n\n return {\n dialect,\n\n async ensureMigrationTables() {\n await pool.query(migrationsTableDdl(dialect))\n await pool.query(lockTableDdl(dialect))\n },\n\n async listApplied(): Promise<MigrationRow[]> {\n const r = await pool.query<{\n id: string\n name: string\n hash: string\n batch: number | string\n applied_at: string | Date\n direction: 'up' | 'down'\n }>(\n `SELECT id, name, hash, batch, applied_at, direction\n FROM kick_migrations\n ORDER BY applied_at ASC, id ASC`,\n )\n return r.rows.map((row) => ({\n id: row.id,\n name: row.name,\n hash: row.hash,\n batch: Number(row.batch),\n appliedAt:\n row.applied_at instanceof Date ? row.applied_at.toISOString() : String(row.applied_at),\n direction: row.direction,\n }))\n },\n\n async recordApplied(row) {\n await pool.query(\n `INSERT INTO kick_migrations (id, name, hash, batch, direction)\n VALUES ($1, $2, $3, $4, $5)`,\n [row.id, row.name, row.hash, row.batch, row.direction],\n )\n },\n\n async removeApplied(id: string) {\n await pool.query(`DELETE FROM kick_migrations WHERE id = $1`, [id])\n },\n\n async acquireLock(owner: string): Promise<boolean> {\n const r = await pool.query(\n `UPDATE kick_migrations_lock\n SET locked_at = CURRENT_TIMESTAMP, locked_by = $1\n WHERE id = 1 AND locked_at IS NULL`,\n [owner],\n )\n return r.rowCount === 1\n },\n\n async releaseLock() {\n await pool.query(\n `UPDATE kick_migrations_lock\n SET locked_at = NULL, locked_by = NULL\n WHERE id = 1`,\n )\n },\n\n async applySqlInTx(sql: string) {\n const client = await pool.connect()\n try {\n await client.query('BEGIN')\n await client.query(sql)\n await client.query('COMMIT')\n } catch (err) {\n await client.query('ROLLBACK').catch(() => {\n /* swallow rollback errors; we're already throwing the original */\n })\n throw err\n } finally {\n client.release()\n }\n },\n\n async applySqlNoTx(sql: string) {\n await pool.query(sql)\n },\n\n async introspect(): Promise<SchemaSnapshot> {\n return introspectPg(pool, { schema })\n },\n\n async close() {\n // Caller owns the pool. kickDbAdapter's shutdown lifecycle calls this so\n // future adapter-internal teardown (e.g. cancelling pending observers)\n // has a hook, but we deliberately don't end() the shared pool.\n },\n }\n}\n","// pgDialect — thin factory over Kysely's PostgresDialect so adopters\n// never have to write `import { PostgresDialect } from 'kysely'`.\n// Kysely is a pinned internal dep of the framework; surfacing it\n// through our own export keeps the adopter import surface stable\n// even when we change query backends (or fork Kysely's internals).\n\nimport { PostgresDialect, type Dialect as KyselyDialect } from 'kysely'\nimport { markDialect } from '../../dialect-marker'\n\nimport type { PgPoolLike } from './adapter'\n\nexport interface PgDialectOptions {\n /**\n * pg-protocol-compatible pool. Both `pg.Pool` and\n * `@neondatabase/serverless`'s Pool match structurally; adopters\n * pick whichever runtime fits.\n */\n pool: PgPoolLike\n}\n\n/**\n * Construct the dialect that `createDbClient({ dialect })` consumes.\n *\n * @example\n * ```ts\n * import { createDbClient } from '@forinda/kickjs-db'\n * import { pgDialect, pgAdapter } from '@forinda/kickjs-db/pg'\n * import { Pool } from 'pg'\n *\n * const pool = new Pool({ connectionString: process.env.DATABASE_URL })\n *\n * export const db = createDbClient({\n * schema,\n * dialect: pgDialect({ pool }),\n * })\n *\n * export const migrationAdapter = pgAdapter({ pool })\n * ```\n */\nexport function pgDialect(opts: PgDialectOptions): KyselyDialect {\n // PostgresDialect's `pool` parameter is typed as `PG.Pool` in newer\n // Kysely versions; casting through `unknown` keeps adopters using\n // alternate clients (neon, pg-cloudflare) compatible without\n // pulling node-postgres' typings into our public surface.\n return markDialect(new PostgresDialect({ pool: opts.pool as unknown as never }), 'postgres')\n}\n"],"mappings":";;;;;;;;;;wLAsCA,IAAa,oBAAb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AAM,YAAsC,CAC1C,OAAO,aAAa,KAAM,CAAE,MAAO,CAAC,CACtC,EAEA,MAAM,OAAQ,CAId,CACF,CACF,CC9HA,SAAgB,UAAU,KAAuC,CAK/D,OAAO,YAAY,IAAI,gBAAgB,CAAE,KAAM,KAAK,IAAyB,CAAC,EAAG,UAAU,CAC7F"}
|
package/dist/sqlite.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
2
|
+
import { ln as MigrationAdapter } from "./index-Ci5DXgUh.mjs";
|
|
3
3
|
import { Dialect } from "kysely";
|
|
4
|
-
|
|
5
4
|
//#region src/adapters/sqlite/adapter.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* better-sqlite3-shaped database handle that `sqliteAdapter` consumes.
|
package/dist/sqlite.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.d.mts","names":[],"sources":["../src/adapters/sqlite/adapter.ts","../src/adapters/sqlite/dialect.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlite.d.mts","names":[],"sources":["../src/adapters/sqlite/adapter.ts","../src/adapters/sqlite/dialect.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;UA0BiB;EACf,OAAO;IAA+B;IAAiB;;EACvD,OAAO;EACP,OAAO;;UAGQ;EACf,QAAQ,cAAc;EACtB,KAAK;EACL;;UAGe;;;;;;;EAOf,UAAU;;;;;;;;;;;;;;;iBAgBI,cAAc,MAAM,uBAAuB;;;UCnD1C;;;;;;;EAOf,UAAU;;;;;;;;;;;;;;;;;;;;;iBAsBI,cAAc,MAAM,uBAAuB"}
|
package/dist/sqlite.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs-db v7.
|
|
2
|
+
* @forinda/kickjs-db v7.2.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import{
|
|
11
|
+
import{R as markDialect,at as introspectSqlite,dt as migrationsTableDdl,ut as lockTableDdl}from"./src-BLr8KOo1.mjs";import{SqliteDialect}from"kysely";function sqliteAdapter(opts){let dialect=`sqlite`,{database}=opts,runBatch=sql=>database.exec(sql);return{dialect,async ensureMigrationTables(){runBatch(migrationsTableDdl(dialect)),runBatch(lockTableDdl(dialect))},async listApplied(){return database.prepare(`SELECT id, name, hash, batch, applied_at, direction
|
|
12
12
|
FROM kick_migrations
|
|
13
13
|
ORDER BY applied_at ASC, id ASC`).all().map(row=>({id:row.id,name:row.name,hash:row.hash,batch:Number(row.batch),appliedAt:row.applied_at,direction:row.direction}))},async recordApplied(row){database.prepare(`INSERT INTO kick_migrations (id, name, hash, batch, direction)
|
|
14
14
|
VALUES (?, ?, ?, ?, ?)`).run(row.id,row.name,row.hash,row.batch,row.direction)},async removeApplied(id){database.prepare(`DELETE FROM kick_migrations WHERE id = ?`).run(id)},async acquireLock(owner){return database.prepare(`UPDATE kick_migrations_lock
|