@forinda/kickjs-db 7.4.0 → 8.1.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.
Files changed (61) hide show
  1. package/README.md +16 -45
  2. package/dist/cli.d.mts +16 -2
  3. package/dist/cli.d.mts.map +1 -1
  4. package/dist/cli.mjs +4 -3
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/create-CwuC1odW.mjs +29 -0
  7. package/dist/create-CwuC1odW.mjs.map +1 -0
  8. package/dist/custom-type-DeGuRFuz.mjs +12 -0
  9. package/dist/custom-type-DeGuRFuz.mjs.map +1 -0
  10. package/dist/devtools-events.d.mts +1 -1
  11. package/dist/devtools-events.mjs +1 -1
  12. package/dist/{index-DF69HndC.d.mts → index-2fEnHqpn.d.mts} +814 -156
  13. package/dist/index-2fEnHqpn.d.mts.map +1 -0
  14. package/dist/index.d.mts +6 -4
  15. package/dist/index.mjs +2 -2
  16. package/dist/mysql.d.mts +41 -37
  17. package/dist/mysql.d.mts.map +1 -1
  18. package/dist/mysql.mjs +8 -8
  19. package/dist/mysql.mjs.map +1 -1
  20. package/dist/pg-CsmRByEZ.mjs +12 -0
  21. package/dist/pg-CsmRByEZ.mjs.map +1 -0
  22. package/dist/pg.d.mts +74 -8
  23. package/dist/pg.d.mts.map +1 -1
  24. package/dist/pg.mjs +8 -7
  25. package/dist/pg.mjs.map +1 -1
  26. package/dist/schema-BjGAg-s1.d.mts +95 -0
  27. package/dist/schema-BjGAg-s1.d.mts.map +1 -0
  28. package/dist/schema-types-DH-d43Pf.d.mts +51 -0
  29. package/dist/schema-types-DH-d43Pf.d.mts.map +1 -0
  30. package/dist/schema.d.mts +2 -87
  31. package/dist/schema.mjs +2 -2
  32. package/dist/schema.mjs.map +1 -1
  33. package/dist/split-statements-BPCw9cII.mjs +14 -0
  34. package/dist/split-statements-BPCw9cII.mjs.map +1 -0
  35. package/dist/sqlite.d.mts +86 -6
  36. package/dist/sqlite.d.mts.map +1 -1
  37. package/dist/sqlite.mjs +13 -7
  38. package/dist/sqlite.mjs.map +1 -1
  39. package/dist/src-DUtVGG2c.mjs +199 -0
  40. package/dist/src-DUtVGG2c.mjs.map +1 -0
  41. package/dist/table-CGPsm5i7.d.mts +221 -0
  42. package/dist/table-CGPsm5i7.d.mts.map +1 -0
  43. package/dist/testing.d.mts +53 -0
  44. package/dist/testing.d.mts.map +1 -0
  45. package/dist/testing.mjs +12 -0
  46. package/dist/testing.mjs.map +1 -0
  47. package/dist/{types-DtvYnaXL.d.mts → types-BZoTujcR.d.mts} +346 -9
  48. package/dist/types-BZoTujcR.d.mts.map +1 -0
  49. package/dist/{table-Bl5SbKRg.d.mts → types-DNAKmwPO.d.mts} +186 -64
  50. package/dist/types-DNAKmwPO.d.mts.map +1 -0
  51. package/package.json +14 -4
  52. package/dist/custom-type-j8k__3sL.mjs +0 -12
  53. package/dist/custom-type-j8k__3sL.mjs.map +0 -1
  54. package/dist/index-DF69HndC.d.mts.map +0 -1
  55. package/dist/pg-BJmYKLhI.mjs +0 -12
  56. package/dist/pg-BJmYKLhI.mjs.map +0 -1
  57. package/dist/schema.d.mts.map +0 -1
  58. package/dist/src-BnHTLx5l.mjs +0 -166
  59. package/dist/src-BnHTLx5l.mjs.map +0 -1
  60. package/dist/table-Bl5SbKRg.d.mts.map +0 -1
  61. package/dist/types-DtvYnaXL.d.mts.map +0 -1
@@ -8,11 +8,31 @@ interface ColumnSnapshot {
8
8
  nullable: boolean;
9
9
  default: string | null;
10
10
  primaryKey: boolean;
11
+ /** A column the database computes from others: `GENERATED ALWAYS AS (expression)`. */
12
+ generated?: {
13
+ expression: string;
14
+ stored: boolean;
15
+ };
16
+ /** An identity column (Postgres): `GENERATED ALWAYS | BY DEFAULT AS IDENTITY`. */
17
+ identity?: 'always' | 'byDefault';
18
+ /** The column's comment in the database (Postgres, MySQL). */
19
+ comment?: string;
11
20
  }
12
21
  interface IndexSnapshot {
13
22
  name: string;
23
+ /** Key parts in order: a column name, or an SQL expression wrapped in parentheses. */
14
24
  columns: string[];
15
25
  unique: boolean;
26
+ /** Partial index predicate (Postgres, SQLite), as SQL. */
27
+ where?: string;
28
+ /** Index method, e.g. `gin`, `gist`, `hnsw` (Postgres) or `hash` (MySQL). Absent means the default. */
29
+ using?: string;
30
+ /** Non-key columns stored in the index (Postgres `INCLUDE`). */
31
+ include?: string[];
32
+ /** Operator class per key part, keyed by the entry in `columns` (Postgres). */
33
+ opclasses?: Record<string, string>;
34
+ /** Build and drop without locking writes (Postgres). Doesn't change the index itself. */
35
+ concurrently?: boolean;
16
36
  }
17
37
  interface ForeignKeySnapshot {
18
38
  name: string;
@@ -43,6 +63,24 @@ interface TableSnapshot {
43
63
  indexes: IndexSnapshot[];
44
64
  foreignKeys: ForeignKeySnapshot[];
45
65
  checks: CheckSnapshot[];
66
+ /**
67
+ * The key declared with `primaryKey(name?).on(...)`: its name and column
68
+ * order. The columns also carry `primaryKey: true`. Absent for a key
69
+ * declared on columns, so those snapshots — and migration hashes — stay
70
+ * as they were.
71
+ */
72
+ primaryKey?: {
73
+ name?: string;
74
+ columns: string[];
75
+ };
76
+ /** The table's comment in the database (Postgres, MySQL). */
77
+ comment?: string;
78
+ /** Row-level security is on (Postgres); `force` applies it to the table's owner too. */
79
+ rls?: {
80
+ force?: true;
81
+ };
82
+ /** Row-level security policies (Postgres). */
83
+ policies?: PolicySnapshot[];
46
84
  }
47
85
  /**
48
86
  * PostgreSQL ENUM type declaration. Currently PG-only; the field is
@@ -79,6 +117,49 @@ interface RelationSnapshot {
79
117
  * the relation. Disambiguates multi-FK schemas.
80
118
  */
81
119
  relationName?: string;
120
+ /**
121
+ * For a many-to-many: the junction table, and its columns that hold the
122
+ * source's `sourceColumns` and the target's `targetColumns`.
123
+ */
124
+ through?: {
125
+ table: string;
126
+ sourceColumns: readonly string[];
127
+ targetColumns: readonly string[];
128
+ };
129
+ }
130
+ /** A row-level security policy (Postgres). */
131
+ interface PolicySnapshot {
132
+ name: string;
133
+ as: 'permissive' | 'restrictive';
134
+ command: 'all' | 'select' | 'insert' | 'update' | 'delete';
135
+ /** Role names; `public` is everyone. */
136
+ to: string[];
137
+ using?: string;
138
+ withCheck?: string;
139
+ }
140
+ /** A Postgres role the schema declares (created if missing, never dropped). */
141
+ interface RoleSnapshot {
142
+ name: string;
143
+ login?: boolean;
144
+ createDb?: boolean;
145
+ createRole?: boolean;
146
+ /** Default true: privileges of roles it's a member of apply to it. */
147
+ inherit?: boolean;
148
+ bypassRls?: boolean;
149
+ }
150
+ interface ViewSnapshot {
151
+ name: string;
152
+ /** The `SELECT`, as declared (or as the database reports it, when introspected). */
153
+ definition: string;
154
+ /** A materialized view (Postgres). */
155
+ materialized?: true;
156
+ /** Indexes on a materialized view. */
157
+ indexes?: IndexSnapshot[];
158
+ /**
159
+ * The columns, when introspected — for `kick db introspect` to render.
160
+ * Not compared: the definition decides what a view returns.
161
+ */
162
+ columns?: Record<string, ColumnSnapshot>;
82
163
  }
83
164
  interface SchemaSnapshot {
84
165
  version: 1;
@@ -99,6 +180,13 @@ interface SchemaSnapshot {
99
180
  schemas?: readonly string[];
100
181
  /** ENUM types declared via `pgEnum()`. PG-only; absent on other dialects. */
101
182
  enums?: Record<string, EnumSnapshot>;
183
+ /**
184
+ * Views, in declaration order — the order they're created in, so a view can
185
+ * select from one declared before it. Absent when there are none.
186
+ */
187
+ views?: Record<string, ViewSnapshot>;
188
+ /** Roles declared with `pgRole()` (Postgres). Absent when none. */
189
+ roles?: Record<string, RoleSnapshot>;
102
190
  /**
103
191
  * Optional relation sidecar populated when the schema includes
104
192
  * `relations()` declarations. Absent when no relations are
@@ -142,6 +230,16 @@ interface ColumnRef {
142
230
  * inside its own initializer. Storing the thunk and resolving on read
143
231
  * (extract / render / emit) defers until after the const binding lands.
144
232
  */
233
+ /**
234
+ * A column ref that knows its column's value type — what lets a foreign key
235
+ * be checked against the column it points at (`fk()`). Assignable to
236
+ * `ColumnRef`, so every existing ref-taking API keeps working.
237
+ */
238
+ type TypedColumnRef<T> = ColumnRef & {
239
+ readonly __valueType?: T;
240
+ };
241
+ /** Typed refs for a column record — one per column. */
242
+ type TypedColumnRefs<C> = { [K in keyof C]: TypedColumnRef<C[K] extends ColumnBuilder<infer T> ? T : never>; };
145
243
  interface FkSpec {
146
244
  thunk: () => ColumnRef;
147
245
  onDelete: FkAction;
@@ -165,6 +263,34 @@ interface ColumnState {
165
263
  primaryKey: boolean;
166
264
  unique: boolean;
167
265
  references: FkSpec | null;
266
+ /**
267
+ * A column kick/db maintains itself: `'updatedAt'` (set on every update),
268
+ * `'version'` (incremented on every update), `'softDelete'` (rows with it
269
+ * set are skipped by relational reads). Never part of the snapshot — it
270
+ * changes queries, not the schema.
271
+ */
272
+ managed?: 'updatedAt' | 'version' | 'softDelete';
273
+ generated?: {
274
+ expression: string;
275
+ stored: boolean;
276
+ };
277
+ identity?: 'always' | 'byDefault';
278
+ /**
279
+ * How a bigint / numeric value is read back (`bigint({ mode })`,
280
+ * `numeric(p, s, { mode })`). Unset, the driver's own value is returned.
281
+ */
282
+ mode?: 'bigint' | 'number' | 'string';
283
+ /** `.comment()`: stored in the database on Postgres and MySQL. */
284
+ comment?: string;
285
+ /** `tenantKey(tenancy)`: this is the table's tenant column. */
286
+ tenancy?: {
287
+ strategy: string;
288
+ setting: string;
289
+ };
290
+ /** `$defaultFn`: computed in JS for each inserted row that doesn't set it. */
291
+ defaultFn?: () => unknown;
292
+ /** `$onUpdate`: computed in JS for each update that doesn't set it. */
293
+ onUpdateFn?: () => unknown;
168
294
  }
169
295
  /**
170
296
  * Type-only brand attached to a column when it's auto-assigned by the
@@ -180,6 +306,15 @@ declare const KICK_GENERATED: unique symbol;
180
306
  type GeneratedBrand = {
181
307
  readonly [KICK_GENERATED]?: true;
182
308
  };
309
+ /**
310
+ * Type-only brand for a column the database always computes — a generated
311
+ * column, or an identity `GENERATED ALWAYS`. `SchemaToTypes<S>` wraps it in
312
+ * Kysely's `GeneratedAlways<T>`, so it can't be inserted or updated.
313
+ */
314
+ declare const KICK_GENERATED_ALWAYS: unique symbol;
315
+ type GeneratedAlwaysBrand = {
316
+ readonly [KICK_GENERATED_ALWAYS]?: true;
317
+ };
183
318
  /**
184
319
  * Type-only brand attached to a column when `.notNull()` or `.primaryKey()`
185
320
  * is called. `SchemaToTypes<S>` reads this brand to decide whether the
@@ -204,7 +339,7 @@ type NotNullBrand = {
204
339
  * Uses the same `extends` checks as `SchemaToTypes` (client/schema-types.ts)
205
340
  * so detection stays consistent in both directions.
206
341
  */
207
- type PreserveBrands<Self, Out> = Out & (Self extends NotNullBrand ? NotNullBrand : unknown) & (Self extends GeneratedBrand ? GeneratedBrand : unknown);
342
+ type PreserveBrands<Self, Out> = Out & (Self extends NotNullBrand ? NotNullBrand : unknown) & (Self extends GeneratedBrand ? GeneratedBrand : unknown) & (Self extends GeneratedAlwaysBrand ? GeneratedAlwaysBrand : unknown);
208
343
  /**
209
344
  * Phantom-typed column builder. The `T` generic carries the column's TS
210
345
  * value type (number / string / Date / etc.); nullability is tracked via
@@ -240,70 +375,57 @@ declare class ColumnBuilder<T = unknown> {
240
375
  * itself (`'active'`); booleans/numbers emit bare (`false`, `0`).
241
376
  */
242
377
  default(value: string | number | boolean): this & GeneratedBrand;
243
- toJSON(name: string): ColumnSnapshot;
244
- __state(): Readonly<ColumnState>;
245
- }
246
- //#endregion
247
- //#region src/dsl/constraints.d.ts
248
- interface IndexDecl {
249
- name: string;
250
- columns: string[];
251
- unique: boolean;
252
- }
253
- interface ColRef {
254
- __name: string;
255
- }
256
- declare function index(name: string): {
257
- on(...cols: ColRef[]): IndexDecl;
258
- };
259
- declare function unique(name: string): {
260
- on(...cols: ColRef[]): IndexDecl;
261
- };
262
- //#endregion
263
- //#region src/dsl/table.d.ts
264
- interface TableDecl<TName extends string = string, C extends Record<string, ColumnBuilder> = Record<string, ColumnBuilder>, TSchema extends string | undefined = string | undefined> {
265
- __isTable: true;
266
- __name: TName;
267
- __columns: C;
268
- __indexes: IndexDecl[];
269
378
  /**
270
- * Named SQL schema this table lives in, from `pgSchema('x').table(...)`.
271
- * `undefined` means the connection's default search_path (`public` on PG),
272
- * which is every table declared through the bare `table()` factory.
273
- *
274
- * PostgreSQL only — `assertSchemasSupported()` rejects a declared schema
275
- * on MySQL/SQLite at snapshot time rather than emitting subtly wrong DDL.
379
+ * A default computed in JS for each inserted row that doesn't set this
380
+ * column — an id generator, a slug, a value from config:
381
+ * `id: text().primaryKey().$defaultFn(() => ulid())`. Not part of the
382
+ * schema: the database has no default, so raw SQL inserts must set it.
383
+ */
384
+ $defaultFn(fn: () => T): this & GeneratedBrand;
385
+ /**
386
+ * A value computed in JS for each update (and an upsert's update branch)
387
+ * that doesn't set this column: `revisedBy: text().$onUpdate(() => currentUser())`.
388
+ * Like `onUpdateNow()`, with your own value. Inserts don't call it.
389
+ */
390
+ $onUpdate(fn: () => T): this;
391
+ /**
392
+ * Set this column to the current time on every update that doesn't set it
393
+ * itself — `updatedAt: timestamp().notNull().defaultNow().onUpdateNow()`.
394
+ */
395
+ onUpdateNow(): this;
396
+ /**
397
+ * Mark this column — a nullable timestamp — as the soft-delete marker:
398
+ * relational reads (`db.query`) skip rows where it's set, at every level,
399
+ * unless asked `withDeleted: true`. Soft-delete by setting it.
400
+ */
401
+ softDelete(): this;
402
+ /**
403
+ * Computed by the database from other columns, on every write:
404
+ * `total: numeric(12, 2).generatedAlwaysAs('price * quantity')`. The SQL is
405
+ * passed through as written. Stored by default; `{ stored: false }` makes
406
+ * it virtual, computed on read (MySQL, SQLite, Postgres 18+). It can't be
407
+ * inserted or updated.
408
+ */
409
+ generatedAlwaysAs(expression: string, options?: {
410
+ stored?: boolean;
411
+ }): this & GeneratedAlwaysBrand;
412
+ /**
413
+ * An identity column the database numbers and won't let you set (Postgres)
414
+ * — the SQL-standard successor to `serial`.
415
+ */
416
+ generatedAlwaysAsIdentity(): this & NotNullBrand & GeneratedAlwaysBrand;
417
+ /** An identity column the database numbers unless a value is given (Postgres). */
418
+ generatedByDefaultAsIdentity(): this & NotNullBrand & GeneratedBrand;
419
+ /**
420
+ * A comment stored with the column in the database, for whoever reads the
421
+ * schema there (Postgres, MySQL; SQLite has none). Changing it migrates.
276
422
  */
277
- __schema?: TSchema;
423
+ comment(text: string): this;
424
+ /** The role kick/db maintains this column in, if any. */
425
+ managedAs(): ColumnState['managed'];
426
+ toJSON(name: string): ColumnSnapshot;
427
+ __state(): Readonly<ColumnState>;
278
428
  }
279
- /**
280
- * Fully-qualified name used as the snapshot key, the Kysely table key, and
281
- * the emitted identifier. `quoteIdent` splits on `.`, so `billing.invoices`
282
- * renders as `"billing"."invoices"` with no further work.
283
- *
284
- * Unqualified tables keep their bare name, so every pre-schema snapshot,
285
- * migration hash, and `KickDbSchema` key is byte-identical to before.
286
- */
287
- type QualifiedName<TName extends string, TSchema extends string | undefined> = TSchema extends string ? `${TSchema}.${TName}` : TName;
288
- /** Runtime counterpart of {@link QualifiedName}. */
289
- declare function qualifiedTableName(decl: {
290
- __name: string;
291
- __schema?: string | undefined;
292
- }): string;
293
- type TableRefs<TName extends string, C extends Record<string, ColumnBuilder>, TSchema extends string | undefined = undefined> = TableDecl<TName, C, TSchema> & { [K in keyof C]: ColumnRef; };
294
- type ConstraintBuilder<C extends Record<string, ColumnBuilder>> = (refs: { [K in keyof C]: ColumnRef; }) => Record<string, IndexDecl>;
295
- /**
296
- * Declare a typed table. The `TName extends string` generic narrows to the
297
- * literal table name so `SchemaToTypes<S>` can index by it without losing
298
- * the constant — `table('users', …)` widens to `TableDecl<'users', …>`,
299
- * not `TableDecl<string, …>`.
300
- */
301
- declare function table<TName extends string, C extends Record<string, ColumnBuilder>>(name: TName, columns: C, constraints?: ConstraintBuilder<C>): TableRefs<TName, C>;
302
- /**
303
- * Shared table constructor. `table()` passes `schema: undefined`;
304
- * `pgSchema('x').table()` passes the schema name through.
305
- */
306
- declare function buildTable<TName extends string, C extends Record<string, ColumnBuilder>, TSchema extends string | undefined>(name: TName, columns: C, constraints: ConstraintBuilder<C> | undefined, schema: TSchema): TableRefs<TName, C, TSchema>;
307
429
  //#endregion
308
- export { IndexSnapshot as C, TableSnapshot as E, ForeignKeySnapshot as S, SchemaSnapshot as T, CheckSnapshot as _, table as a, EnumSnapshot as b, unique as c, ColumnState as d, FkSpec as f, NotNullBrand as g, KICK_NOT_NULL as h, qualifiedTableName as i, ColumnBuilder as l, KICK_GENERATED as m, TableDecl as n, IndexDecl as o, GeneratedBrand as p, buildTable as r, index as s, QualifiedName as t, ColumnRef as u, ColumnSnapshot as v, RelationSnapshot as w, FkAction as x, Dialect as y };
309
- //# sourceMappingURL=table-Bl5SbKRg.d.mts.map
430
+ 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 };
431
+ //# sourceMappingURL=types-DNAKmwPO.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DNAKmwPO.d.mts","names":[],"sources":["../src/snapshot/types.ts","../src/dsl/columns/types.ts"],"mappings":";;KAAY;KAEA;UAEK;EACf;EACA;EACA;EACA;EACA;;EAEA;IAAc;IAAoB;;;EAElC;;EAEA;;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;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EAWlD,WAAW,UAAU,WAAW;;;;;;EAUhC,UAAU,UAAU;;;;;EASpB;;;;;;EAUA;;;;;;;;EAYA,kBACE,oBACA;IAAW;aACH;;;;;EASV,oCAAoC,eAAe;;EAOnD,uCAAuC,eAAe;;;;;EAUtD,QAAQ;;EAMR,aAAa;EAIb,OAAO,eAAe;EAetB,WAAW,SAAS"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forinda/kickjs-db",
3
- "version": "7.4.0",
3
+ "version": "8.1.0",
4
4
  "description": "KickJS-native ORM — code-first schema, reversible migrations, multi-dialect SQL builder",
5
5
  "keywords": [
6
6
  "kickjs",
@@ -37,6 +37,10 @@
37
37
  "import": "./dist/mysql.mjs",
38
38
  "types": "./dist/mysql.d.mts"
39
39
  },
40
+ "./testing": {
41
+ "import": "./dist/testing.mjs",
42
+ "types": "./dist/testing.d.mts"
43
+ },
40
44
  "./schema": {
41
45
  "import": "./dist/schema.mjs",
42
46
  "types": "./dist/schema.d.mts"
@@ -64,7 +68,7 @@
64
68
  "@forinda/kickjs-cli-kit": "0.1.2"
65
69
  },
66
70
  "peerDependencies": {
67
- "@forinda/kickjs": ">=5.18.0",
71
+ "@forinda/kickjs": ">=8.8.0",
68
72
  "@forinda/kickjs-devtools-kit": ">=7.0.0",
69
73
  "better-sqlite3": ">=12.0.0",
70
74
  "mysql2": ">=3.0.0",
@@ -85,17 +89,23 @@
85
89
  }
86
90
  },
87
91
  "devDependencies": {
92
+ "@libsql/client": "^0.18.0",
93
+ "@libsql/kysely-libsql": "^0.4.1",
94
+ "@testcontainers/mysql": "^12.2.0",
88
95
  "@testcontainers/postgresql": "^12.1.0",
89
96
  "@types/better-sqlite3": "^9.6.0",
90
97
  "@types/node": "^26.6.2",
91
98
  "@types/pg": "^8.23.1",
92
99
  "better-sqlite3": "^13.0.3",
93
100
  "kysely": "^0.29.6",
101
+ "kysely-d1": "^0.4.0",
102
+ "miniflare": "^4.20260730.0",
94
103
  "mysql2": "^3.24.4",
95
104
  "pg": "^8.23.0",
105
+ "pg-cursor": "^2.22.1",
96
106
  "typescript": "^7.0.2",
97
- "@forinda/kickjs": "8.7.0",
98
- "@forinda/kickjs-devtools-kit": "7.0.2",
107
+ "@forinda/kickjs": "9.0.0",
108
+ "@forinda/kickjs-devtools-kit": "7.1.0",
99
109
  "@forinda/kickjs-schema": "0.2.0"
100
110
  },
101
111
  "publishConfig": {
@@ -1,12 +0,0 @@
1
- /**
2
- * @forinda/kickjs-db v7.4.0
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}}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}toJSON(name){return{name,type:this.state.type,nullable:this.state.nullable,default:this.state.default,primaryKey:this.state.primaryKey}}__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-j8k__3sL.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"custom-type-j8k__3sL.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 */\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 primaryKey: boolean\n unique: boolean\n references: FkSpec | null\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 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\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 }\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 return this as this & GeneratedBrand\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 primaryKey: this.state.primaryKey,\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":";;;;;;;;;;AAwEA,MAAa,eAAiB,OAAO,IAAI,8BAA8B,EAc1D,cAAgB,OAAO,IAAI,4BAA4B,EAyBpE,IAAa,cAAb,KAAwC,CAKtC,MAEA,YAAY,KAAc,SAAiC,CAAC,EAAG,CAC7D,KAAK,MAAQ,CACX,KACA,SAAU,SAAS,UAAY,GAC/B,QAAS,SAAS,SAAW,KAC7B,WAAY,SAAS,YAAc,GACnC,OAAQ,SAAS,QAAU,GAC3B,WAAY,SAAS,YAAc,IACrC,CACF,CAEA,SAA+B,CAE7B,MADA,MAAK,MAAM,SAAW,GACf,IACT,CAEA,YAAkC,CAGhC,MAFA,MAAK,MAAM,WAAa,GACxB,KAAK,MAAM,SAAW,GACf,IACT,CAEA,QAAe,CAEb,MADA,MAAK,MAAM,OAAS,GACb,IACT,CAEA,OAAkD,CAEhD,MADA,MAAK,MAAM,KAAO,GAAG,KAAK,MAAM,KAAK,IAC9B,IACT,CAEA,WACE,OACA,KAAoE,CAAC,EAC/D,CAYN,MATA,MAAK,MAAM,WAAa,CACtB,MAAO,OACP,SAAU,KAAK,UAAY,YAC3B,SAAU,KAAK,UAAY,YAI3B,GAAI,KAAK,OAAS,IAAA,GAAY,CAAC,EAAI,CAAE,KAAM,KAAK,IAAK,CACvD,EACO,IACT,CAcA,QAAQ,MAAyD,CAE/D,MADA,MAAK,MAAM,QAAU,OAAO,OAAU,SAAW,MAAQ,OAAO,KAAK,EAC9D,IACT,CAEA,OAAO,KAA8B,CACnC,MAAO,CACL,KACA,KAAM,KAAK,MAAM,KACjB,SAAU,KAAK,MAAM,SACrB,QAAS,KAAK,MAAM,QACpB,WAAY,KAAK,MAAM,UACzB,CACF,CAGA,SAAiC,CAC/B,OAAO,KAAK,KACd,CACF,ECtJa,oBAAb,cAA8C,aAAmB,CAE/D,SAEA,WAEA,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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-DF69HndC.d.mts","names":[],"sources":["../src/snapshot/extract.ts","../src/snapshot/name.ts","../src/snapshot/render.ts","../src/diff/types.ts","../src/diff/engine.ts","../src/diff/invert.ts","../src/errors.ts","../src/diff/composite-detect.ts","../src/migrate/errors.ts","../src/migrate/enum-drop-gate.ts","../src/migrate/journal.ts","../src/migrate/adapter.ts","../src/migrate/schema.ts","../src/migrate/memory-adapter.ts","../src/migrate/introspect-types.ts","../src/migrate/introspect-pg.ts","../src/migrate/introspect-sqlite.ts","../src/migrate/introspect-mysql.ts","../src/migrate/drift.ts","../src/adapter.ts","../src/tokens.ts","../src/client/schema-types.ts","../src/client/create.ts","../src/client/plugins.ts","../src/migrate/runner.ts","../src/migrate/review.ts","../src/emit/pg.ts","../src/emit/sqlite.ts","../src/emit/mysql.ts","../src/cli/config.ts","../src/cli/generate.ts","../src/dsl/columns/builders.ts","../src/dsl/relations.ts","../src/custom-type.ts","../src/query/relations.ts","../src/query/schema-relations-types.ts","../src/query/errors.ts","../src/query/like.ts","../src/dialect-marker.ts"],"mappings":";;;;;;;iBAiEgB,gBAAgB,QAAQ,yBAAyB,SAAS,YAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCfpE,cAAc;;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IhD;;;;;;KAQL,iBAAiB,UAAU,eAAe,gBAC5C,WAAW;EACV,MAAM,EAAE;EACR,QAAQ,EAAE,qBAAqB,gBAAgB,GAAG,eAAe,kBAC7D,mBACE;;;;;;;KAWL,cAAc;EAAY;EAAgB,WAAW,eAAe;QACtE,UAAU,cAAc,QAAQ;EAAK,QAAQ;;;;;;;;cCxDnC,4CAA4C;WAC9C;WACA;EACT,YAAY,qBAAqB;;;;;;;cAgBtB,kCAAkC;WACpC;WACA;EACT,YAAY,kBAAkB;;;;;;;;cAiBnB,2CAA2C;WAC7C;WACA;EACT,YAAY,qBAAqB;;;;;;;;;;;cAoBtB,sCAAsC;WACxC;EAET,YAAY;;;;;;;cA0BD,yCAAyC;WAC3C;EACT,YAAY;;;;;;;;;cAiBD,kDAAkD;WACpD;WACA;WACA;;WAEA;EACT,YACE,qBACA,qBACA,sBACA;;;;;;;;;cAwBS,2CAA2C;WAC7C;WACA;WACA;EACT,YAAY,qBAAqB,sBAAsB;;;;;;;;;;;;;;;;;;;;KC/I7C;;;;;;;;;;iBAWI,WAAW,eAAe;;;;;;;;;;;;iBA4B1B,YACd,eACA,OAAM,eACN;;;;;;;;;;;;;;;;;;;;cCpCW;KAED;;iBAKI,aAAa,iBAAiB,SAAS;;iBAKvC,YAAY,kBAAkB,SAAS,GAAG,KAAK,aAAa;;;;;;;iBAgB5D,gBAAgB,kBAAkB"}
@@ -1,12 +0,0 @@
1
- /**
2
- * @forinda/kickjs-db v7.4.0
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
- import{r as ColumnBuilder}from"./custom-type-j8k__3sL.mjs";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`)}export{money as a,vector as c,inet as i,xml as l,cidr as n,pgEnum as o,citext as r,tsvector as s,PgEnumColumnBuilder as t};
12
- //# sourceMappingURL=pg-BJmYKLhI.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pg-BJmYKLhI.mjs","names":[],"sources":["../src/dsl/columns/pg.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"],"mappings":";;;;;;;;;;2DAsCA,IAAa,oBAAb,cAGU,aAA+B,CAEvC,SAEA,OAEA,YAAY,SAAiB,OAAiB,CAG5C,MAAM,QAAQ,EACd,KAAK,SAAW,SAChB,KAA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