rwsdk 1.0.0-beta.3 → 1.0.0-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/constants.d.mts +1 -0
- package/dist/lib/constants.mjs +7 -4
- package/dist/lib/e2e/browser.mjs +6 -2
- package/dist/lib/e2e/constants.d.mts +16 -0
- package/dist/lib/e2e/constants.mjs +77 -0
- package/dist/lib/e2e/dev.mjs +37 -49
- package/dist/lib/e2e/environment.d.mts +2 -0
- package/dist/lib/e2e/environment.mjs +202 -65
- package/dist/lib/e2e/index.d.mts +1 -0
- package/dist/lib/e2e/index.mjs +1 -0
- package/dist/lib/e2e/poll.d.mts +1 -1
- package/dist/lib/e2e/release.d.mts +1 -0
- package/dist/lib/e2e/release.mjs +16 -32
- package/dist/lib/e2e/tarball.mjs +2 -34
- package/dist/lib/e2e/testHarness.d.mts +36 -4
- package/dist/lib/e2e/testHarness.mjs +216 -128
- package/dist/lib/e2e/utils.d.mts +1 -0
- package/dist/lib/e2e/utils.mjs +15 -0
- package/dist/runtime/client/client.d.ts +35 -0
- package/dist/runtime/client/client.js +35 -0
- package/dist/runtime/client/navigation.d.ts +49 -0
- package/dist/runtime/client/navigation.js +80 -31
- package/dist/runtime/entries/clientSSR.d.ts +1 -0
- package/dist/runtime/entries/clientSSR.js +3 -0
- package/dist/runtime/entries/router.d.ts +1 -0
- package/dist/runtime/entries/routerClient.d.ts +1 -0
- package/dist/runtime/entries/routerClient.js +1 -0
- package/dist/runtime/entries/worker.d.ts +2 -0
- package/dist/runtime/entries/worker.js +2 -0
- package/dist/runtime/imports/__mocks__/use-client-lookup.d.ts +6 -0
- package/dist/runtime/imports/__mocks__/use-client-lookup.js +6 -0
- package/dist/runtime/lib/db/SqliteDurableObject.d.ts +2 -2
- package/dist/runtime/lib/db/SqliteDurableObject.js +2 -2
- package/dist/runtime/lib/db/createDb.d.ts +1 -2
- package/dist/runtime/lib/db/createDb.js +4 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +13 -3
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +35 -21
- package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +9 -2
- package/dist/runtime/lib/db/typeInference/database.d.ts +16 -2
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.js +80 -5
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.js +104 -2
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/utils.d.ts +59 -9
- package/dist/runtime/lib/links.d.ts +18 -7
- package/dist/runtime/lib/links.js +70 -24
- package/dist/runtime/lib/links.test.js +20 -0
- package/dist/runtime/lib/manifest.d.ts +1 -1
- package/dist/runtime/lib/manifest.js +7 -4
- package/dist/runtime/lib/realtime/client.js +8 -2
- package/dist/runtime/lib/realtime/worker.d.ts +1 -1
- package/dist/runtime/lib/router.d.ts +147 -33
- package/dist/runtime/lib/router.js +169 -20
- package/dist/runtime/lib/router.test.js +241 -0
- package/dist/runtime/lib/stitchDocumentAndAppStreams.d.ts +66 -0
- package/dist/runtime/lib/stitchDocumentAndAppStreams.js +302 -35
- package/dist/runtime/lib/stitchDocumentAndAppStreams.test.d.ts +1 -0
- package/dist/runtime/lib/stitchDocumentAndAppStreams.test.js +418 -0
- package/dist/runtime/lib/{rwContext.d.ts → types.d.ts} +1 -0
- package/dist/runtime/lib/types.js +1 -0
- package/dist/runtime/render/renderDocumentHtmlStream.d.ts +1 -1
- package/dist/runtime/render/renderToStream.d.ts +4 -2
- package/dist/runtime/render/renderToStream.js +53 -24
- package/dist/runtime/render/renderToString.d.ts +3 -1
- package/dist/runtime/requestInfo/types.d.ts +4 -1
- package/dist/runtime/requestInfo/utils.d.ts +9 -0
- package/dist/runtime/requestInfo/utils.js +44 -0
- package/dist/runtime/requestInfo/worker.js +3 -2
- package/dist/runtime/script.d.ts +1 -3
- package/dist/runtime/script.js +1 -10
- package/dist/runtime/state.d.ts +3 -0
- package/dist/runtime/state.js +13 -0
- package/dist/runtime/worker.d.ts +3 -1
- package/dist/runtime/worker.js +26 -0
- package/dist/scripts/debug-sync.mjs +18 -20
- package/dist/scripts/worker-run.d.mts +1 -1
- package/dist/scripts/worker-run.mjs +52 -113
- package/dist/use-synced-state/SyncStateServer.d.mts +20 -0
- package/dist/use-synced-state/SyncStateServer.mjs +124 -0
- package/dist/use-synced-state/__tests__/SyncStateServer.test.d.mts +1 -0
- package/dist/use-synced-state/__tests__/SyncStateServer.test.mjs +109 -0
- package/dist/use-synced-state/__tests__/useSyncState.test.d.ts +1 -0
- package/dist/use-synced-state/__tests__/useSyncState.test.js +115 -0
- package/dist/use-synced-state/__tests__/useSyncedState.test.d.ts +1 -0
- package/dist/use-synced-state/__tests__/useSyncedState.test.js +115 -0
- package/dist/use-synced-state/__tests__/worker.test.d.mts +1 -0
- package/dist/use-synced-state/__tests__/worker.test.mjs +69 -0
- package/dist/use-synced-state/client.d.ts +28 -0
- package/dist/use-synced-state/client.js +39 -0
- package/dist/use-synced-state/constants.d.mts +1 -0
- package/dist/use-synced-state/constants.mjs +1 -0
- package/dist/use-synced-state/useSyncState.d.ts +20 -0
- package/dist/use-synced-state/useSyncState.js +58 -0
- package/dist/use-synced-state/useSyncedState.d.ts +20 -0
- package/dist/use-synced-state/useSyncedState.js +58 -0
- package/dist/use-synced-state/worker.d.mts +14 -0
- package/dist/use-synced-state/worker.mjs +73 -0
- package/dist/vite/buildApp.mjs +34 -2
- package/dist/vite/configPlugin.mjs +8 -14
- package/dist/vite/constants.d.mts +1 -0
- package/dist/vite/constants.mjs +1 -0
- package/dist/vite/directiveModulesDevPlugin.mjs +1 -1
- package/dist/vite/envResolvers.d.mts +11 -0
- package/dist/vite/envResolvers.mjs +20 -0
- package/dist/vite/getViteEsbuild.mjs +2 -1
- package/dist/vite/hmrStabilityPlugin.d.mts +2 -0
- package/dist/vite/hmrStabilityPlugin.mjs +68 -0
- package/dist/vite/knownDepsResolverPlugin.d.mts +0 -6
- package/dist/vite/knownDepsResolverPlugin.mjs +1 -12
- package/dist/vite/linkerPlugin.d.mts +2 -1
- package/dist/vite/linkerPlugin.mjs +11 -3
- package/dist/vite/linkerPlugin.test.mjs +15 -0
- package/dist/vite/miniflareHMRPlugin.mjs +1 -38
- package/dist/vite/moveStaticAssetsPlugin.mjs +14 -4
- package/dist/vite/redwoodPlugin.mjs +6 -10
- package/dist/vite/runDirectivesScan.mjs +59 -14
- package/dist/vite/ssrBridgePlugin.mjs +122 -34
- package/dist/vite/ssrBridgeWrapPlugin.d.mts +2 -0
- package/dist/vite/ssrBridgeWrapPlugin.mjs +85 -0
- package/dist/vite/staleDepRetryPlugin.d.mts +2 -0
- package/dist/vite/staleDepRetryPlugin.mjs +69 -0
- package/dist/vite/statePlugin.d.mts +4 -0
- package/dist/vite/statePlugin.mjs +62 -0
- package/package.json +26 -10
- package/dist/vite/manifestPlugin.d.mts +0 -4
- package/dist/vite/manifestPlugin.mjs +0 -63
- /package/dist/runtime/lib/{rwContext.js → links.test.d.ts} +0 -0
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
},
|
|
98
98
|
},
|
|
99
99
|
};
|
|
100
|
-
//(_test:
|
|
100
|
+
//(_test: ExpectDb<Actual, Expected>) => {};
|
|
101
101
|
};
|
|
102
102
|
(_it = "alterTable addUniqueConstraint") => {
|
|
103
103
|
const migrations = {
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
},
|
|
124
124
|
},
|
|
125
125
|
};
|
|
126
|
-
//(_test:
|
|
126
|
+
//(_test: ExpectDb<Actual, Expected>) => {};
|
|
127
127
|
};
|
|
128
128
|
(_it = "alterTable drop column") => {
|
|
129
129
|
const migrations = {
|
|
@@ -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 {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
1
2
|
(_it = "createTable") => {
|
|
2
3
|
const migrations = {
|
|
3
4
|
"001_init": {
|
|
@@ -21,8 +22,11 @@
|
|
|
21
22
|
await db.schema
|
|
22
23
|
.createTable("users")
|
|
23
24
|
.addColumn("username", "text", (col) => col.notNull())
|
|
24
|
-
.addColumn("age", "integer", (col) => col.defaultTo(18))
|
|
25
25
|
.addColumn("active", "boolean", (col) => col.defaultTo(true))
|
|
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"))
|
|
26
30
|
.execute(),
|
|
27
31
|
];
|
|
28
32
|
},
|
|
@@ -30,4 +34,102 @@
|
|
|
30
34
|
};
|
|
31
35
|
(_test) => { };
|
|
32
36
|
};
|
|
33
|
-
|
|
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)
|
|
78
|
+
.execute(),
|
|
79
|
+
];
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
(_test) => { };
|
|
84
|
+
};
|
|
85
|
+
(_it = "defaultTo makes columns non-nullable in Database type") => {
|
|
86
|
+
const migrations = {
|
|
87
|
+
"001_init": {
|
|
88
|
+
async up(db) {
|
|
89
|
+
return [
|
|
90
|
+
await db.schema
|
|
91
|
+
.createTable("users")
|
|
92
|
+
.addColumn("status", "text", (col) => col.defaultTo("active"))
|
|
93
|
+
.addColumn("count", "integer", (col) => col.defaultTo(0))
|
|
94
|
+
.execute(),
|
|
95
|
+
];
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
(_test) => { };
|
|
100
|
+
};
|
|
101
|
+
// --- Insert/Update Type Tests ---
|
|
102
|
+
(_it = "makes autoIncrement columns optional on insert") => {
|
|
103
|
+
const migrations = {
|
|
104
|
+
"001_init": {
|
|
105
|
+
async up(db) {
|
|
106
|
+
return [
|
|
107
|
+
await db.schema
|
|
108
|
+
.createTable("users")
|
|
109
|
+
.addColumn("id", "integer", (col) => col.primaryKey().autoIncrement())
|
|
110
|
+
.addColumn("username", "text", (col) => col.notNull())
|
|
111
|
+
.execute(),
|
|
112
|
+
];
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
const db = {};
|
|
117
|
+
db.insertInto("users").values({ username: "test" });
|
|
118
|
+
};
|
|
119
|
+
(_it = "makes defaultTo columns optional on insert") => {
|
|
120
|
+
const migrations = {
|
|
121
|
+
"001_init": {
|
|
122
|
+
async up(db) {
|
|
123
|
+
return [
|
|
124
|
+
await db.schema
|
|
125
|
+
.createTable("users")
|
|
126
|
+
.addColumn("username", "text", (col) => col.notNull())
|
|
127
|
+
.addColumn("status", "text", (col) => col.notNull().defaultTo("active"))
|
|
128
|
+
.execute(),
|
|
129
|
+
];
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
const db = {};
|
|
134
|
+
db.insertInto("users").values({ username: "test" });
|
|
135
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { sql } from "kysely";
|
|
2
|
+
import { ColumnDescriptor } from "./builders/columnDefinition";
|
|
2
3
|
type DataTypeExpression = string | typeof sql;
|
|
3
|
-
export type AddColumnOp<K extends string, T extends DataTypeExpression> = {
|
|
4
|
+
export type AddColumnOp<K extends string, T extends DataTypeExpression, TDescriptor extends ColumnDescriptor> = {
|
|
4
5
|
op: "addColumn";
|
|
5
6
|
name: K;
|
|
6
7
|
type: T;
|
|
8
|
+
descriptor: TDescriptor;
|
|
7
9
|
};
|
|
8
10
|
export type DropColumnOp<K extends string> = {
|
|
9
11
|
op: "dropColumn";
|
|
@@ -14,10 +16,11 @@ export type RenameColumnOp<KFrom extends string, KTo extends string> = {
|
|
|
14
16
|
from: KFrom;
|
|
15
17
|
to: KTo;
|
|
16
18
|
};
|
|
17
|
-
export type ModifyColumnOp<K extends string, T extends DataTypeExpression> = {
|
|
19
|
+
export type ModifyColumnOp<K extends string, T extends DataTypeExpression, TDescriptor extends ColumnDescriptor> = {
|
|
18
20
|
op: "modifyColumn";
|
|
19
21
|
name: K;
|
|
20
22
|
type: T;
|
|
23
|
+
descriptor: TDescriptor;
|
|
21
24
|
};
|
|
22
25
|
export type Alteration = {
|
|
23
26
|
kind: "setDataType";
|
|
@@ -37,7 +40,7 @@ export type AlterColumnOp<K extends string, TAlteration extends Alteration> = {
|
|
|
37
40
|
name: K;
|
|
38
41
|
alteration: TAlteration;
|
|
39
42
|
};
|
|
40
|
-
export type AlterOperation = AddColumnOp<any, any> | DropColumnOp<any> | RenameColumnOp<any, any> | AlterColumnOp<any, any> | ModifyColumnOp<any, any>;
|
|
43
|
+
export type AlterOperation = AddColumnOp<any, any, any> | DropColumnOp<any> | RenameColumnOp<any, any> | AlterColumnOp<any, any> | ModifyColumnOp<any, any, any>;
|
|
41
44
|
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
45
|
export type Prettify<T> = {
|
|
43
46
|
[K in keyof T]: T[K];
|
|
@@ -57,17 +60,64 @@ export type Cast<A, B> = A extends B ? A : B;
|
|
|
57
60
|
/**
|
|
58
61
|
* Applies a single alteration operation to a schema.
|
|
59
62
|
*/
|
|
60
|
-
type ApplyOp<TSchema, THeadOp> = THeadOp extends AddColumnOp<infer K, infer
|
|
61
|
-
[P in K]:
|
|
63
|
+
type ApplyOp<TSchema, THeadOp> = THeadOp extends AddColumnOp<infer K, any, infer TDescriptor> ? Prettify<TSchema & {
|
|
64
|
+
[P in K]: TDescriptor;
|
|
62
65
|
}> : THeadOp extends DropColumnOp<infer K> ? Omit<TSchema, K> : THeadOp extends RenameColumnOp<infer KFrom, infer KTo> ? KFrom extends keyof TSchema ? Prettify<Omit<TSchema, KFrom> & {
|
|
63
66
|
[P in KTo]: TSchema[KFrom];
|
|
64
|
-
}> : TSchema : THeadOp extends AlterColumnOp<infer K, infer TAlt> ? TAlt extends {
|
|
67
|
+
}> : TSchema : THeadOp extends AlterColumnOp<infer K, infer TAlt> ? K extends keyof TSchema ? TAlt extends {
|
|
65
68
|
kind: "setDataType";
|
|
66
69
|
dataType: infer DT extends string;
|
|
67
70
|
} ? Prettify<Omit<TSchema, K> & {
|
|
68
|
-
[P in K]:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
[P in K]: {
|
|
72
|
+
tsType: SqlToTsType<DT>;
|
|
73
|
+
isNullable: TSchema[K] extends {
|
|
74
|
+
isNullable: infer N;
|
|
75
|
+
} ? N : true;
|
|
76
|
+
hasDefault: TSchema[K] extends {
|
|
77
|
+
hasDefault: infer D;
|
|
78
|
+
} ? D : false;
|
|
79
|
+
isAutoIncrement: TSchema[K] extends {
|
|
80
|
+
isAutoIncrement: infer A;
|
|
81
|
+
} ? A : false;
|
|
82
|
+
};
|
|
83
|
+
}> : TAlt extends {
|
|
84
|
+
kind: "setDefault";
|
|
85
|
+
} ? Prettify<Omit<TSchema, K> & {
|
|
86
|
+
[P in K]: TSchema[K] extends ColumnDescriptor ? {
|
|
87
|
+
tsType: TSchema[K]["tsType"];
|
|
88
|
+
isNullable: false;
|
|
89
|
+
hasDefault: true;
|
|
90
|
+
isAutoIncrement: TSchema[K]["isAutoIncrement"];
|
|
91
|
+
} : TSchema[K];
|
|
92
|
+
}> : TAlt extends {
|
|
93
|
+
kind: "dropDefault";
|
|
94
|
+
} ? Prettify<Omit<TSchema, K> & {
|
|
95
|
+
[P in K]: TSchema[K] extends ColumnDescriptor ? {
|
|
96
|
+
tsType: TSchema[K]["tsType"];
|
|
97
|
+
isNullable: TSchema[K]["isNullable"];
|
|
98
|
+
hasDefault: false;
|
|
99
|
+
isAutoIncrement: TSchema[K]["isAutoIncrement"];
|
|
100
|
+
} : TSchema[K];
|
|
101
|
+
}> : TAlt extends {
|
|
102
|
+
kind: "setNotNull";
|
|
103
|
+
} ? Prettify<Omit<TSchema, K> & {
|
|
104
|
+
[P in K]: TSchema[K] extends ColumnDescriptor ? {
|
|
105
|
+
tsType: TSchema[K]["tsType"];
|
|
106
|
+
isNullable: false;
|
|
107
|
+
hasDefault: TSchema[K]["hasDefault"];
|
|
108
|
+
isAutoIncrement: TSchema[K]["isAutoIncrement"];
|
|
109
|
+
} : TSchema[K];
|
|
110
|
+
}> : TAlt extends {
|
|
111
|
+
kind: "dropNotNull";
|
|
112
|
+
} ? Prettify<Omit<TSchema, K> & {
|
|
113
|
+
[P in K]: TSchema[K] extends ColumnDescriptor ? {
|
|
114
|
+
tsType: TSchema[K]["tsType"];
|
|
115
|
+
isNullable: true;
|
|
116
|
+
hasDefault: TSchema[K]["hasDefault"];
|
|
117
|
+
isAutoIncrement: TSchema[K]["isAutoIncrement"];
|
|
118
|
+
} : TSchema[K];
|
|
119
|
+
}> : TSchema : TSchema : THeadOp extends ModifyColumnOp<infer K, any, infer TDescriptor> ? Prettify<Omit<TSchema, K> & {
|
|
120
|
+
[P in K]: TDescriptor;
|
|
71
121
|
}> : TSchema;
|
|
72
122
|
/**
|
|
73
123
|
* Recursively processes a list of alteration operations (AST)
|
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
type
|
|
1
|
+
import type { RouteDefinition, RouteMiddleware } from "./router";
|
|
2
|
+
type PathParams<Path extends string> = Path extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
2
3
|
[K in Param]: string;
|
|
3
|
-
} &
|
|
4
|
+
} & PathParams<Rest> : Path extends `${string}:${infer Param}` ? {
|
|
4
5
|
[K in Param]: string;
|
|
5
|
-
} :
|
|
6
|
+
} : Path extends `${string}*${infer Rest}` ? {
|
|
6
7
|
$0: string;
|
|
7
|
-
} &
|
|
8
|
+
} & PathParams<Rest> : Path extends `${string}*` ? {
|
|
8
9
|
$0: string;
|
|
9
10
|
} : {};
|
|
10
|
-
type
|
|
11
|
-
|
|
11
|
+
type ParamsForPath<Path extends string> = PathParams<Path> extends Record<string, never> ? undefined : PathParams<Path>;
|
|
12
|
+
export type LinkFunction<Paths extends string> = {
|
|
13
|
+
<Path extends Paths>(path: Path, params?: ParamsForPath<Path>): string;
|
|
12
14
|
};
|
|
13
|
-
|
|
15
|
+
type RoutePaths<Value> = Value extends RouteDefinition<infer Path, any> ? Path : Value extends readonly (infer Item)[] ? RouteArrayPaths<Value> : Value extends RouteMiddleware<any> ? never : never;
|
|
16
|
+
type RouteArrayPaths<Routes extends readonly any[]> = number extends Routes["length"] ? RoutePaths<Routes[number]> : Routes extends readonly [infer Head, ...infer Tail] ? RoutePaths<Head> | RouteArrayPaths<Tail> : never;
|
|
17
|
+
type AppRoutes<App> = App extends {
|
|
18
|
+
__rwRoutes: infer Routes;
|
|
19
|
+
} ? Routes : never;
|
|
20
|
+
export type AppRoutePaths<App> = RoutePaths<AppRoutes<App>>;
|
|
21
|
+
export type AppLink<App> = LinkFunction<AppRoutePaths<App>>;
|
|
22
|
+
export declare function linkFor<App>(): AppLink<App>;
|
|
23
|
+
export declare function createLinks<App>(_app?: App): AppLink<App>;
|
|
24
|
+
export declare function defineLinks<const T extends readonly string[]>(routes: T): LinkFunction<T[number]>;
|
|
14
25
|
export {};
|
|
@@ -1,38 +1,84 @@
|
|
|
1
|
+
export function linkFor() {
|
|
2
|
+
return createLinkFunction();
|
|
3
|
+
}
|
|
4
|
+
export function createLinks(_app) {
|
|
5
|
+
return linkFor();
|
|
6
|
+
}
|
|
1
7
|
export function defineLinks(routes) {
|
|
2
|
-
// Validate routes at runtime
|
|
3
8
|
routes.forEach((route) => {
|
|
4
9
|
if (typeof route !== "string") {
|
|
5
10
|
throw new Error(`Invalid route: ${route}. Routes must be strings.`);
|
|
6
11
|
}
|
|
7
12
|
});
|
|
8
|
-
|
|
13
|
+
const link = createLinkFunction();
|
|
14
|
+
return ((path, params) => {
|
|
9
15
|
if (!routes.includes(path)) {
|
|
10
16
|
throw new Error(`Invalid route: ${path}`);
|
|
11
17
|
}
|
|
12
|
-
|
|
18
|
+
return link(path, params);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const TOKEN_REGEX = /:([a-zA-Z0-9_]+)|\*/g;
|
|
22
|
+
function createLinkFunction() {
|
|
23
|
+
return ((path, params) => {
|
|
24
|
+
const expectsParams = hasRouteParameters(path);
|
|
25
|
+
if (!params || Object.keys(params).length === 0) {
|
|
26
|
+
if (expectsParams) {
|
|
27
|
+
throw new Error(`Route ${path} requires an object of parameters`);
|
|
28
|
+
}
|
|
13
29
|
return path;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
}
|
|
31
|
+
return interpolate(path, params);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function hasRouteParameters(path) {
|
|
35
|
+
TOKEN_REGEX.lastIndex = 0;
|
|
36
|
+
const result = TOKEN_REGEX.test(path);
|
|
37
|
+
TOKEN_REGEX.lastIndex = 0;
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
function interpolate(template, params) {
|
|
41
|
+
let result = "";
|
|
42
|
+
let lastIndex = 0;
|
|
43
|
+
let wildcardIndex = 0;
|
|
44
|
+
const consumed = new Set();
|
|
45
|
+
TOKEN_REGEX.lastIndex = 0;
|
|
46
|
+
let match;
|
|
47
|
+
while ((match = TOKEN_REGEX.exec(template)) !== null) {
|
|
48
|
+
result += template.slice(lastIndex, match.index);
|
|
49
|
+
if (match[1]) {
|
|
50
|
+
const name = match[1];
|
|
51
|
+
const value = params[name];
|
|
52
|
+
if (value === undefined) {
|
|
53
|
+
throw new Error(`Missing parameter "${name}" for route ${template}`);
|
|
27
54
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
55
|
+
result += encodeURIComponent(value);
|
|
56
|
+
consumed.add(name);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const key = `$${wildcardIndex}`;
|
|
60
|
+
const value = params[key];
|
|
61
|
+
if (value === undefined) {
|
|
62
|
+
throw new Error(`Missing parameter "${key}" for route ${template}`);
|
|
34
63
|
}
|
|
64
|
+
result += encodeWildcardValue(value);
|
|
65
|
+
consumed.add(key);
|
|
66
|
+
wildcardIndex += 1;
|
|
67
|
+
}
|
|
68
|
+
lastIndex = TOKEN_REGEX.lastIndex;
|
|
69
|
+
}
|
|
70
|
+
result += template.slice(lastIndex);
|
|
71
|
+
for (const key of Object.keys(params)) {
|
|
72
|
+
if (!consumed.has(key)) {
|
|
73
|
+
throw new Error(`Parameter "${key}" is not used by route ${template}`);
|
|
35
74
|
}
|
|
36
|
-
|
|
37
|
-
|
|
75
|
+
}
|
|
76
|
+
TOKEN_REGEX.lastIndex = 0;
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
function encodeWildcardValue(value) {
|
|
80
|
+
return value
|
|
81
|
+
.split("/")
|
|
82
|
+
.map((segment) => encodeURIComponent(segment))
|
|
83
|
+
.join("/");
|
|
38
84
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { defineLinks } from "./links";
|
|
3
|
+
const link = defineLinks(["/", "/users/:id", "/files/*"]);
|
|
4
|
+
describe("link helpers", () => {
|
|
5
|
+
it("returns static routes without parameters", () => {
|
|
6
|
+
expect(link("/")).toBe("/");
|
|
7
|
+
});
|
|
8
|
+
it("replaces named parameters with encoded values", () => {
|
|
9
|
+
expect(link("/users/:id", { id: "user id" })).toBe("/users/user%20id");
|
|
10
|
+
});
|
|
11
|
+
it("replaces wildcard parameters preserving path segments", () => {
|
|
12
|
+
expect(link("/files/*", { $0: "docs/Guide Document.md" })).toBe("/files/docs/Guide%20Document.md");
|
|
13
|
+
});
|
|
14
|
+
it("throws when parameters are missing", () => {
|
|
15
|
+
expect(() => link("/users/:id")).toThrowError(/requires an object of parameters/i);
|
|
16
|
+
});
|
|
17
|
+
it("throws when extra parameters are supplied", () => {
|
|
18
|
+
expect(() => link("/users/:id", { id: "123", extra: "value" })).toThrowError(/is not used by route/i);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
let manifest;
|
|
2
|
-
export
|
|
2
|
+
export async function getManifest() {
|
|
3
3
|
if (manifest) {
|
|
4
4
|
return manifest;
|
|
5
5
|
}
|
|
6
6
|
if (import.meta.env.VITE_IS_DEV_SERVER) {
|
|
7
|
+
// In dev, there's no manifest, so we can use an empty object.
|
|
7
8
|
manifest = {};
|
|
8
9
|
}
|
|
9
10
|
else {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
// context(justinvdm, 2 Oct 2025): In production, the manifest is a
|
|
12
|
+
// placeholder string that will be replaced by the linker plugin with the
|
|
13
|
+
// actual manifest JSON object.
|
|
14
|
+
manifest = "__RWSDK_MANIFEST_PLACEHOLDER__";
|
|
12
15
|
}
|
|
13
16
|
return manifest;
|
|
14
|
-
}
|
|
17
|
+
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
// context(justinvdm, 14 Aug 2025): `react-server-dom-webpack` uses this globa ___webpack_require__ global,
|
|
2
|
+
// so we need to import our client entry point (which sets it), before importing
|
|
3
|
+
// prettier-ignore
|
|
2
4
|
import { initClient } from "../../client/client";
|
|
3
|
-
|
|
5
|
+
// prettier-ignore
|
|
6
|
+
import { createFromReadableStream } from "react-server-dom-webpack/client.browser";
|
|
7
|
+
// prettier-ignore
|
|
4
8
|
import { MESSAGE_TYPE } from "./shared";
|
|
9
|
+
// prettier-ignore
|
|
10
|
+
import { packMessage, unpackMessage, } from "./protocol";
|
|
5
11
|
const DEFAULT_KEY = "default";
|
|
6
12
|
export const initRealtimeClient = ({ key = DEFAULT_KEY, handleResponse, } = {}) => {
|
|
7
13
|
const transport = realtimeTransport({ key, handleResponse });
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { RealtimeDurableObject } from "./durableObject";
|
|
2
2
|
export { renderRealtimeClients } from "./renderRealtimeClients";
|
|
3
|
-
export declare const realtimeRoute: (getDurableObjectNamespace: (env: Cloudflare.Env) => DurableObjectNamespace<RealtimeDurableObject>) => import("../router").RouteDefinition<import("../../worker").RequestInfo<any, import("../../worker").DefaultAppContext>>;
|
|
3
|
+
export declare const realtimeRoute: (getDurableObjectNamespace: (env: Cloudflare.Env) => DurableObjectNamespace<RealtimeDurableObject>) => import("../router").RouteDefinition<"/__realtime", import("../../worker").RequestInfo<any, import("../../worker").DefaultAppContext>>;
|