rwsdk 1.0.0-beta.27 → 1.0.0-beta.27-test.20251111115809

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.
@@ -31,14 +31,14 @@ export interface AlterTableBuilder<TName extends string, TOps extends AlterOpera
31
31
  readonly __renamedFrom: TName;
32
32
  };
33
33
  setSchema(newSchema: string): AlterTableBuilder<TName, TOps>;
34
- addColumn<K extends string, T extends DataTypeExpression>(name: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): AlterTableBuilder<TName, [...TOps, AddColumnOp<K, T>]>;
34
+ addColumn<K extends string, T extends DataTypeExpression, TNullable extends boolean = true>(name: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>, TNullable>): AlterTableBuilder<TName, [...TOps, AddColumnOp<K, T, TNullable>]>;
35
35
  dropColumn<K extends string>(name: K): AlterTableBuilder<TName, [...TOps, DropColumnOp<K>]>;
36
36
  renameColumn<KFrom extends string, KTo extends string>(from: KFrom, to: KTo): AlterTableBuilder<TName, [...TOps, RenameColumnOp<KFrom, KTo>]>;
37
37
  alterColumn<K extends string, const TCallback extends AlterColumnBuilderCallback>(column: K, alteration: TCallback): AlterTableBuilder<TName, [
38
38
  ...TOps,
39
39
  AlterColumnOp<K, ReturnType<TCallback>["__alteration"]>
40
40
  ]>;
41
- modifyColumn<K extends string, T extends DataTypeExpression>(column: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): AlterTableBuilder<TName, [...TOps, ModifyColumnOp<K, T>]>;
41
+ modifyColumn<K extends string, T extends DataTypeExpression, TNullable extends boolean = true>(column: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>, TNullable>): AlterTableBuilder<TName, [...TOps, ModifyColumnOp<K, T, TNullable>]>;
42
42
  addUniqueConstraint(constraintName: string, columns: string[], build?: (builder: UniqueConstraintBuilder) => UniqueConstraintBuilder): AlterTableBuilder<TName, TOps>;
43
43
  addPrimaryKeyConstraint(constraintName: string, columns: string[], build?: (builder: PrimaryKeyConstraintBuilder) => PrimaryKeyConstraintBuilder): AlterTableBuilder<TName, TOps>;
44
44
  addCheckConstraint(constraintName: string, checkExpression: Expression<any>, build?: (builder: CheckConstraintBuilder) => CheckConstraintBuilder): AlterTableBuilder<TName, TOps>;
@@ -1,25 +1,25 @@
1
1
  import { ColumnDefinitionNode, Expression, sql } from "kysely";
2
2
  type DefaultValueExpression = string | number | boolean | null | ReturnType<typeof sql>;
3
- export interface ColumnDefinitionBuilder<TType> {
4
- autoIncrement(): ColumnDefinitionBuilder<TType>;
5
- identity(): ColumnDefinitionBuilder<TType>;
6
- primaryKey(): ColumnDefinitionBuilder<TType>;
7
- references(ref: string): ColumnDefinitionBuilder<TType>;
8
- onDelete(onDelete: "no action" | "restrict" | "cascade" | "set null" | "set default"): ColumnDefinitionBuilder<TType>;
9
- onUpdate(onUpdate: "no action" | "restrict" | "cascade" | "set null" | "set default"): ColumnDefinitionBuilder<TType>;
10
- unique(): ColumnDefinitionBuilder<TType>;
11
- notNull(): ColumnDefinitionBuilder<TType>;
12
- unsigned(): ColumnDefinitionBuilder<TType>;
13
- defaultTo(value: DefaultValueExpression): ColumnDefinitionBuilder<TType>;
14
- check(expression: Expression<any>): ColumnDefinitionBuilder<TType>;
15
- generatedAlwaysAs(expression: Expression<any>): ColumnDefinitionBuilder<TType>;
16
- generatedAlwaysAsIdentity(): ColumnDefinitionBuilder<TType>;
17
- generatedByDefaultAsIdentity(): ColumnDefinitionBuilder<TType>;
18
- stored(): ColumnDefinitionBuilder<TType>;
19
- modifyFront(modifier: Expression<any>): ColumnDefinitionBuilder<TType>;
20
- nullsNotDistinct(): ColumnDefinitionBuilder<TType>;
21
- ifNotExists(): ColumnDefinitionBuilder<TType>;
22
- modifyEnd(modifier: Expression<any>): ColumnDefinitionBuilder<TType>;
3
+ export interface ColumnDefinitionBuilder<TType, TNullable extends boolean = true> {
4
+ autoIncrement(): ColumnDefinitionBuilder<TType, TNullable>;
5
+ identity(): ColumnDefinitionBuilder<TType, TNullable>;
6
+ primaryKey(): ColumnDefinitionBuilder<TType, false>;
7
+ references(ref: string): ColumnDefinitionBuilder<TType, TNullable>;
8
+ onDelete(onDelete: "no action" | "restrict" | "cascade" | "set null" | "set default"): ColumnDefinitionBuilder<TType, TNullable>;
9
+ onUpdate(onUpdate: "no action" | "restrict" | "cascade" | "set null" | "set default"): ColumnDefinitionBuilder<TType, TNullable>;
10
+ unique(): ColumnDefinitionBuilder<TType, TNullable>;
11
+ notNull(): ColumnDefinitionBuilder<TType, false>;
12
+ unsigned(): ColumnDefinitionBuilder<TType, TNullable>;
13
+ defaultTo(value: DefaultValueExpression): ColumnDefinitionBuilder<TType, false>;
14
+ check(expression: Expression<any>): ColumnDefinitionBuilder<TType, TNullable>;
15
+ generatedAlwaysAs(expression: Expression<any>): ColumnDefinitionBuilder<TType, TNullable>;
16
+ generatedAlwaysAsIdentity(): ColumnDefinitionBuilder<TType, TNullable>;
17
+ generatedByDefaultAsIdentity(): ColumnDefinitionBuilder<TType, TNullable>;
18
+ stored(): ColumnDefinitionBuilder<TType, TNullable>;
19
+ modifyFront(modifier: Expression<any>): ColumnDefinitionBuilder<TType, TNullable>;
20
+ nullsNotDistinct(): ColumnDefinitionBuilder<TType, TNullable>;
21
+ ifNotExists(): ColumnDefinitionBuilder<TType, TNullable>;
22
+ modifyEnd(modifier: Expression<any>): ColumnDefinitionBuilder<TType, TNullable>;
23
23
  $call<T>(func: (qb: this) => T): T;
24
24
  toOperationNode(): ColumnDefinitionNode;
25
25
  }
@@ -28,7 +28,8 @@ export interface CreateTableBuilder<TName extends string, TSchema extends Record
28
28
  temporary(): CreateTableBuilder<TName, TSchema>;
29
29
  onCommit(onCommit: "preserve rows" | "delete rows" | "drop"): CreateTableBuilder<TName, TSchema>;
30
30
  ifNotExists(): CreateTableBuilder<TName, TSchema>;
31
- addColumn<K extends string, T extends string>(name: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): CreateTableBuilder<TName, Prettify<(TSchema extends Record<string, any> ? TSchema : {}) & Record<K, SqlToTsType<T>>>>;
31
+ addColumn<K extends string, T extends string>(name: K, type: T): CreateTableBuilder<TName, Prettify<(TSchema extends Record<string, any> ? TSchema : {}) & Record<K, SqlToTsType<T> | null>>>;
32
+ addColumn<K extends string, T extends string, TNullable extends boolean>(name: K, type: T, build: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>, TNullable>): CreateTableBuilder<TName, Prettify<(TSchema extends Record<string, any> ? TSchema : {}) & Record<K, TNullable extends true ? SqlToTsType<T> | null : SqlToTsType<T>>>>;
32
33
  addUniqueConstraint(constraintName: string, columns: (keyof TSchema)[], build?: (builder: UniqueConstraintBuilder) => UniqueConstraintBuilder): CreateTableBuilder<TName, TSchema>;
33
34
  addPrimaryKeyConstraint(constraintName: string, columns: (keyof TSchema)[], build?: (builder: PrimaryKeyConstraintBuilder) => PrimaryKeyConstraintBuilder): CreateTableBuilder<TName, TSchema>;
34
35
  addCheckConstraint(constraintName: string, checkExpression: Expression<any>, build?: (builder: CheckConstraintBuilder) => CheckConstraintBuilder): CreateTableBuilder<TName, TSchema>;
@@ -153,7 +153,7 @@
153
153
  up: async (db) => [
154
154
  await db.schema
155
155
  .createTable("users")
156
- .addColumn("id", "integer")
156
+ .addColumn("id", "integer", (c) => c.primaryKey().autoIncrement())
157
157
  .execute(),
158
158
  ],
159
159
  },
@@ -242,7 +242,7 @@
242
242
  return [
243
243
  await db.schema
244
244
  .createTable("users")
245
- .addColumn("id", "integer")
245
+ .addColumn("id", "integer", (col) => col.notNull())
246
246
  .execute(),
247
247
  ];
248
248
  },
@@ -271,7 +271,7 @@
271
271
  return [
272
272
  await db.schema
273
273
  .createTable("users")
274
- .addColumn("id", "integer")
274
+ .addColumn("id", "integer", (col) => col.primaryKey().autoIncrement())
275
275
  .execute(),
276
276
  ];
277
277
  },
@@ -357,4 +357,79 @@
357
357
  };
358
358
  (_test) => { };
359
359
  };
360
+ (_it = "alterTable addColumn with notNull") => {
361
+ const migrations = {
362
+ "0": {
363
+ async up(db) {
364
+ return [
365
+ await db.schema
366
+ .createTable("users")
367
+ .addColumn("id", "integer", (col) => col.primaryKey())
368
+ .execute(),
369
+ ];
370
+ },
371
+ },
372
+ "1": {
373
+ async up(db) {
374
+ return [
375
+ await db.schema
376
+ .alterTable("users")
377
+ .addColumn("email", "text", (col) => col.notNull())
378
+ .execute(),
379
+ ];
380
+ },
381
+ },
382
+ };
383
+ (_test) => { };
384
+ };
385
+ (_it = "alterTable modifyColumn with notNull") => {
386
+ const migrations = {
387
+ "0": {
388
+ async up(db) {
389
+ return [
390
+ await db.schema
391
+ .createTable("products")
392
+ .addColumn("price", "real")
393
+ .execute(),
394
+ ];
395
+ },
396
+ },
397
+ "1": {
398
+ async up(db) {
399
+ return [
400
+ await db.schema
401
+ .alterTable("products")
402
+ .modifyColumn("price", "real", (col) => col.notNull())
403
+ .execute(),
404
+ ];
405
+ },
406
+ },
407
+ };
408
+ (_test) => { };
409
+ };
410
+ (_it = "alterTable modifyColumn nullable to non-nullable") => {
411
+ const migrations = {
412
+ "0": {
413
+ async up(db) {
414
+ return [
415
+ await db.schema
416
+ .createTable("orders")
417
+ .addColumn("status", "text")
418
+ .execute(),
419
+ ];
420
+ },
421
+ },
422
+ "1": {
423
+ async up(db) {
424
+ return [
425
+ await db.schema
426
+ .alterTable("orders")
427
+ .modifyColumn("status", "text", (col) => col.notNull().defaultTo("pending"))
428
+ .execute(),
429
+ ];
430
+ },
431
+ },
432
+ };
433
+ (_test) => { };
434
+ };
360
435
  export {};
@@ -22,9 +22,59 @@ import { sql } from "kysely";
22
22
  await db.schema
23
23
  .createTable("users")
24
24
  .addColumn("username", "text", (col) => col.notNull())
25
- .addColumn("age", "integer", (col) => col.defaultTo(18))
26
25
  .addColumn("active", "boolean", (col) => col.defaultTo(true))
27
26
  .addColumn("anotherBoolean", "boolean", (col) => col.defaultTo(sql `true`))
27
+ .addColumn("email", "text", (col) => col)
28
+ .addColumn("favoriteColor", "text", (col) => col.unique())
29
+ .addColumn("name", "text", (col) => col.defaultTo("John Doe"))
30
+ .execute(),
31
+ ];
32
+ },
33
+ },
34
+ };
35
+ (_test) => { };
36
+ };
37
+ (_it = "createTable column without callback is nullable") => {
38
+ const migrations = {
39
+ "001_init": {
40
+ async up(db) {
41
+ return [
42
+ await db.schema
43
+ .createTable("posts")
44
+ .addColumn("title", "text")
45
+ .addColumn("body", "text")
46
+ .execute(),
47
+ ];
48
+ },
49
+ },
50
+ };
51
+ (_test) => { };
52
+ };
53
+ (_it = "createTable with primaryKey is non-nullable") => {
54
+ const migrations = {
55
+ "001_init": {
56
+ async up(db) {
57
+ return [
58
+ await db.schema
59
+ .createTable("users")
60
+ .addColumn("id", "integer", (col) => col.primaryKey())
61
+ .addColumn("email", "text", (col) => col.notNull())
62
+ .execute(),
63
+ ];
64
+ },
65
+ },
66
+ };
67
+ (_test) => { };
68
+ };
69
+ (_it = "createTable with unique but no notNull is nullable") => {
70
+ const migrations = {
71
+ "001_init": {
72
+ async up(db) {
73
+ return [
74
+ await db.schema
75
+ .createTable("products")
76
+ .addColumn("sku", "text", (col) => col.unique())
77
+ .addColumn("name", "text", (col) => col)
28
78
  .execute(),
29
79
  ];
30
80
  },
@@ -1,9 +1,10 @@
1
1
  import { sql } from "kysely";
2
2
  type DataTypeExpression = string | typeof sql;
3
- export type AddColumnOp<K extends string, T extends DataTypeExpression> = {
3
+ export type AddColumnOp<K extends string, T extends DataTypeExpression, TNullable extends boolean = true> = {
4
4
  op: "addColumn";
5
5
  name: K;
6
6
  type: T;
7
+ nullable: TNullable;
7
8
  };
8
9
  export type DropColumnOp<K extends string> = {
9
10
  op: "dropColumn";
@@ -14,10 +15,11 @@ export type RenameColumnOp<KFrom extends string, KTo extends string> = {
14
15
  from: KFrom;
15
16
  to: KTo;
16
17
  };
17
- export type ModifyColumnOp<K extends string, T extends DataTypeExpression> = {
18
+ export type ModifyColumnOp<K extends string, T extends DataTypeExpression, TNullable extends boolean = true> = {
18
19
  op: "modifyColumn";
19
20
  name: K;
20
21
  type: T;
22
+ nullable: TNullable;
21
23
  };
22
24
  export type Alteration = {
23
25
  kind: "setDataType";
@@ -37,7 +39,7 @@ export type AlterColumnOp<K extends string, TAlteration extends Alteration> = {
37
39
  name: K;
38
40
  alteration: TAlteration;
39
41
  };
40
- export type AlterOperation = AddColumnOp<any, any> | DropColumnOp<any> | RenameColumnOp<any, any> | AlterColumnOp<any, any> | ModifyColumnOp<any, any>;
42
+ export type AlterOperation = AddColumnOp<any, any, any> | DropColumnOp<any> | RenameColumnOp<any, any> | AlterColumnOp<any, any> | ModifyColumnOp<any, any, any>;
41
43
  export type SqlToTsType<T extends string | typeof sql> = T extends "text" ? string : T extends "integer" ? number : T extends "blob" ? Uint8Array : T extends "real" ? number : T extends "boolean" ? boolean : T extends typeof sql ? any : never;
42
44
  export type Prettify<T> = {
43
45
  [K in keyof T]: T[K];
@@ -57,8 +59,8 @@ export type Cast<A, B> = A extends B ? A : B;
57
59
  /**
58
60
  * Applies a single alteration operation to a schema.
59
61
  */
60
- type ApplyOp<TSchema, THeadOp> = THeadOp extends AddColumnOp<infer K, infer T> ? Prettify<TSchema & {
61
- [P in K]: SqlToTsType<T>;
62
+ type ApplyOp<TSchema, THeadOp> = THeadOp extends AddColumnOp<infer K, infer T, infer TNullable> ? Prettify<TSchema & {
63
+ [P in K]: TNullable extends true ? SqlToTsType<T> | null : SqlToTsType<T>;
62
64
  }> : THeadOp extends DropColumnOp<infer K> ? Omit<TSchema, K> : THeadOp extends RenameColumnOp<infer KFrom, infer KTo> ? KFrom extends keyof TSchema ? Prettify<Omit<TSchema, KFrom> & {
63
65
  [P in KTo]: TSchema[KFrom];
64
66
  }> : TSchema : THeadOp extends AlterColumnOp<infer K, infer TAlt> ? TAlt extends {
@@ -66,8 +68,8 @@ type ApplyOp<TSchema, THeadOp> = THeadOp extends AddColumnOp<infer K, infer T> ?
66
68
  dataType: infer DT extends string;
67
69
  } ? Prettify<Omit<TSchema, K> & {
68
70
  [P in K]: SqlToTsType<DT>;
69
- }> : TSchema : THeadOp extends ModifyColumnOp<infer K, infer T> ? Prettify<Omit<TSchema, K> & {
70
- [P in K]: SqlToTsType<T>;
71
+ }> : TSchema : THeadOp extends ModifyColumnOp<infer K, infer T, infer TNullable> ? Prettify<Omit<TSchema, K> & {
72
+ [P in K]: TNullable extends true ? SqlToTsType<T> | null : SqlToTsType<T>;
71
73
  }> : TSchema;
72
74
  /**
73
75
  * Recursively processes a list of alteration operations (AST)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "1.0.0-beta.27",
3
+ "version": "1.0.0-beta.27-test.20251111115809",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {