toiljs 0.0.37 → 0.0.38
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/CHANGELOG.md +9 -0
- package/build/cli/.tsbuildinfo +1 -1
- package/build/cli/index.js +40 -91
- package/build/compiler/.tsbuildinfo +1 -1
- package/build/compiler/generate.d.ts +1 -0
- package/build/compiler/generate.js +21 -0
- package/build/compiler/index.d.ts +1 -1
- package/build/compiler/index.js +10 -2
- package/examples/basic/server/routes/PqDemo.ts +2 -5
- package/examples/basic/server/routes/Session.ts +12 -3
- package/package.json +1 -1
- package/src/cli/create.ts +25 -90
- package/src/cli/doctor.ts +27 -1
- package/src/compiler/generate.ts +33 -0
- package/src/compiler/index.ts +15 -2
- package/examples/basic/server/toil-server-env.d.ts +0 -94
package/src/cli/create.ts
CHANGED
|
@@ -270,96 +270,31 @@ function scaffold(
|
|
|
270
270
|
* editor their shapes. Auto-included via the server tsconfig and ignored by the
|
|
271
271
|
* compiler. Keep in sync with `toiljs/server/runtime/http/*`.
|
|
272
272
|
*/
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
declare
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
declare
|
|
297
|
-
|
|
298
|
-
Secure = 1,
|
|
299
|
-
Host = 2,
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
declare class CookieValidation {
|
|
303
|
-
valid: bool;
|
|
304
|
-
errors: Array<string>;
|
|
305
|
-
fail(msg: string): void;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
declare class Cookie {
|
|
309
|
-
name: string;
|
|
310
|
-
value: string;
|
|
311
|
-
encoding: CookieEncoding;
|
|
312
|
-
constructor(name: string, value: string);
|
|
313
|
-
static create(name: string, value: string): Cookie;
|
|
314
|
-
domain(v: string): Cookie;
|
|
315
|
-
path(v: string): Cookie;
|
|
316
|
-
maxAge(seconds: i64): Cookie;
|
|
317
|
-
expires(epochSeconds: i64): Cookie;
|
|
318
|
-
expiresRaw(date: string): Cookie;
|
|
319
|
-
secure(on?: bool): Cookie;
|
|
320
|
-
httpOnly(on?: bool): Cookie;
|
|
321
|
-
sameSite(s: SameSite): Cookie;
|
|
322
|
-
partitioned(on?: bool): Cookie;
|
|
323
|
-
priority(p: string): Cookie;
|
|
324
|
-
extension(av: string): Cookie;
|
|
325
|
-
withEncoding(e: CookieEncoding): Cookie;
|
|
326
|
-
asSecurePrefixed(): Cookie;
|
|
327
|
-
asHostPrefixed(): Cookie;
|
|
328
|
-
detectedPrefix(): CookiePrefix;
|
|
329
|
-
encodedValue(): string;
|
|
330
|
-
validate(): CookieValidation;
|
|
331
|
-
serialize(strict?: bool): string;
|
|
332
|
-
toString(): string;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
declare class CookieMap {
|
|
336
|
-
set(name: string, value: string): void;
|
|
337
|
-
get(name: string): string | null;
|
|
338
|
-
has(name: string): bool;
|
|
339
|
-
names(): Array<string>;
|
|
340
|
-
readonly size: i32;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
declare class Cookies {
|
|
344
|
-
static parse(cookieHeader: string): CookieMap;
|
|
345
|
-
static get(cookieHeader: string, name: string): string | null;
|
|
346
|
-
static serialize(name: string, value: string): string;
|
|
347
|
-
static parseSetCookie(setCookie: string): Cookie;
|
|
348
|
-
static encodeValue(raw: string): string;
|
|
349
|
-
static decodeValue(enc: string): string;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
declare class SecureCookies {
|
|
353
|
-
static signed(key: Uint8Array): SecureCookies;
|
|
354
|
-
static encrypted(key: Uint8Array): SecureCookies;
|
|
355
|
-
addKey(key: Uint8Array): SecureCookies;
|
|
356
|
-
sign(name: string, value: string): string;
|
|
357
|
-
unsign(name: string, sealed: string): string | null;
|
|
358
|
-
encrypt(name: string, value: string): string;
|
|
359
|
-
decrypt(name: string, sealed: string): string | null;
|
|
360
|
-
seal(cookie: Cookie): Cookie;
|
|
361
|
-
open(jar: CookieMap, name: string): string | null;
|
|
362
|
-
}
|
|
273
|
+
// Editor-only ambient declarations for the server-runtime globals, scaffolded
|
|
274
|
+
// into the server dir. Kept BYTE-IDENTICAL to `TOIL_SERVER_ENV_DTS` in
|
|
275
|
+
// src/compiler/generate.ts (which `toiljs build`/`dev` regenerate, and `doctor
|
|
276
|
+
// --fix` rewrites), so create / build / doctor never disagree and flip-flop.
|
|
277
|
+
export const TOIL_SERVER_ENV_DTS = `// AUTO-GENERATED by toil, do not edit. Editor-only ambient declarations for
|
|
278
|
+
// the toiljs server-runtime globals (Cookie, Cookies, SecureCookies, the
|
|
279
|
+
// cookie enums): @global in the runtime, used with no import. These alias the
|
|
280
|
+
// real runtime types so a global-built Cookie is exactly what Response.setCookie
|
|
281
|
+
// / SecureCookies.seal expect. The toilscript compiler registers them itself.
|
|
282
|
+
declare const SameSite: typeof import('toiljs/server/runtime/http/cookie').SameSite;
|
|
283
|
+
type SameSite = import('toiljs/server/runtime/http/cookie').SameSite;
|
|
284
|
+
declare const CookieEncoding: typeof import('toiljs/server/runtime/http/cookie').CookieEncoding;
|
|
285
|
+
type CookieEncoding = import('toiljs/server/runtime/http/cookie').CookieEncoding;
|
|
286
|
+
declare const CookiePrefix: typeof import('toiljs/server/runtime/http/cookie').CookiePrefix;
|
|
287
|
+
type CookiePrefix = import('toiljs/server/runtime/http/cookie').CookiePrefix;
|
|
288
|
+
declare const CookieValidation: typeof import('toiljs/server/runtime/http/cookie').CookieValidation;
|
|
289
|
+
type CookieValidation = import('toiljs/server/runtime/http/cookie').CookieValidation;
|
|
290
|
+
declare const Cookie: typeof import('toiljs/server/runtime/http/cookie').Cookie;
|
|
291
|
+
type Cookie = import('toiljs/server/runtime/http/cookie').Cookie;
|
|
292
|
+
declare const CookieMap: typeof import('toiljs/server/runtime/http/cookies').CookieMap;
|
|
293
|
+
type CookieMap = import('toiljs/server/runtime/http/cookies').CookieMap;
|
|
294
|
+
declare const Cookies: typeof import('toiljs/server/runtime/http/cookies').Cookies;
|
|
295
|
+
type Cookies = import('toiljs/server/runtime/http/cookies').Cookies;
|
|
296
|
+
declare const SecureCookies: typeof import('toiljs/server/runtime/http/securecookies').SecureCookies;
|
|
297
|
+
type SecureCookies = import('toiljs/server/runtime/http/securecookies').SecureCookies;
|
|
363
298
|
`;
|
|
364
299
|
|
|
365
300
|
/**
|
package/src/cli/doctor.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { createRequire } from 'node:module';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import { fileURLToPath } from 'node:url';
|
|
12
12
|
|
|
13
|
-
import { loadConfig, type ResolvedToilConfig, scanRoutes } from 'toiljs/compiler';
|
|
13
|
+
import { loadConfig, type ResolvedToilConfig, scanRoutes, TOIL_SERVER_ENV_DTS } from 'toiljs/compiler';
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
16
|
type Check,
|
|
@@ -330,6 +330,32 @@ function applyRpcFix(root: string): RpcFixResult {
|
|
|
330
330
|
changed.push('.gitignore');
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
+
// Migrate the editor-only server-globals d.ts to the current shapes (the
|
|
334
|
+
// exact content `toiljs build`/`dev` regenerate), in each server source dir.
|
|
335
|
+
// This is what fixes a stale, scaffolded `toil-server-env.d.ts` whose
|
|
336
|
+
// standalone class decls made a second, incompatible `Cookie`.
|
|
337
|
+
const serverToilconfig = readJsonObject(path.join(root, 'toilconfig.json'));
|
|
338
|
+
if (serverToilconfig !== null) {
|
|
339
|
+
const entries = Array.isArray(serverToilconfig.entries)
|
|
340
|
+
? (serverToilconfig.entries as unknown[]).filter((e): e is string => typeof e === 'string')
|
|
341
|
+
: [];
|
|
342
|
+
const dirs = new Set<string>();
|
|
343
|
+
for (const e of entries) dirs.add(path.dirname(path.resolve(root, e)));
|
|
344
|
+
if (dirs.size === 0) dirs.add(path.join(root, 'server'));
|
|
345
|
+
for (const dir of dirs) {
|
|
346
|
+
const envPath = path.join(dir, 'toil-server-env.d.ts');
|
|
347
|
+
if (readFile(envPath) !== TOIL_SERVER_ENV_DTS) {
|
|
348
|
+
try {
|
|
349
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
350
|
+
writeFile(envPath, TOIL_SERVER_ENV_DTS);
|
|
351
|
+
changed.push(path.relative(root, envPath));
|
|
352
|
+
} catch {
|
|
353
|
+
// editor-only; ignore write failures
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
333
359
|
return { changed, skipped };
|
|
334
360
|
}
|
|
335
361
|
|
package/src/compiler/generate.ts
CHANGED
|
@@ -76,6 +76,39 @@ export const TOIL_ENV_DTS =
|
|
|
76
76
|
` export const pages: import('toiljs/client').PageMeta[];\n` +
|
|
77
77
|
`}\n`;
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Contents of `<serverDir>/toil-server-env.d.ts`: editor-only ambient
|
|
81
|
+
* declarations for the toiljs server-runtime globals. ALIASES the real runtime
|
|
82
|
+
* types (the same trick the IO globals use above), so a global-built `Cookie`
|
|
83
|
+
* is the exact type the runtime APIs (`Response.setCookie`, `SecureCookies.seal`)
|
|
84
|
+
* expect; redeclaring them as standalone classes makes a second, nominally-
|
|
85
|
+
* incompatible `Cookie` (private fields). Regenerated by `buildServer` on every
|
|
86
|
+
* build/dev so existing projects auto-migrate. Keep the declarations in sync
|
|
87
|
+
* with the `toiljs create` scaffold (`src/cli/create.ts`).
|
|
88
|
+
*/
|
|
89
|
+
export const TOIL_SERVER_ENV_DTS =
|
|
90
|
+
`// AUTO-GENERATED by toil, do not edit. Editor-only ambient declarations for\n` +
|
|
91
|
+
`// the toiljs server-runtime globals (Cookie, Cookies, SecureCookies, the\n` +
|
|
92
|
+
`// cookie enums): @global in the runtime, used with no import. These alias the\n` +
|
|
93
|
+
`// real runtime types so a global-built Cookie is exactly what Response.setCookie\n` +
|
|
94
|
+
`// / SecureCookies.seal expect. The toilscript compiler registers them itself.\n` +
|
|
95
|
+
`declare const SameSite: typeof import('toiljs/server/runtime/http/cookie').SameSite;\n` +
|
|
96
|
+
`type SameSite = import('toiljs/server/runtime/http/cookie').SameSite;\n` +
|
|
97
|
+
`declare const CookieEncoding: typeof import('toiljs/server/runtime/http/cookie').CookieEncoding;\n` +
|
|
98
|
+
`type CookieEncoding = import('toiljs/server/runtime/http/cookie').CookieEncoding;\n` +
|
|
99
|
+
`declare const CookiePrefix: typeof import('toiljs/server/runtime/http/cookie').CookiePrefix;\n` +
|
|
100
|
+
`type CookiePrefix = import('toiljs/server/runtime/http/cookie').CookiePrefix;\n` +
|
|
101
|
+
`declare const CookieValidation: typeof import('toiljs/server/runtime/http/cookie').CookieValidation;\n` +
|
|
102
|
+
`type CookieValidation = import('toiljs/server/runtime/http/cookie').CookieValidation;\n` +
|
|
103
|
+
`declare const Cookie: typeof import('toiljs/server/runtime/http/cookie').Cookie;\n` +
|
|
104
|
+
`type Cookie = import('toiljs/server/runtime/http/cookie').Cookie;\n` +
|
|
105
|
+
`declare const CookieMap: typeof import('toiljs/server/runtime/http/cookies').CookieMap;\n` +
|
|
106
|
+
`type CookieMap = import('toiljs/server/runtime/http/cookies').CookieMap;\n` +
|
|
107
|
+
`declare const Cookies: typeof import('toiljs/server/runtime/http/cookies').Cookies;\n` +
|
|
108
|
+
`type Cookies = import('toiljs/server/runtime/http/cookies').Cookies;\n` +
|
|
109
|
+
`declare const SecureCookies: typeof import('toiljs/server/runtime/http/securecookies').SecureCookies;\n` +
|
|
110
|
+
`type SecureCookies = import('toiljs/server/runtime/http/securecookies').SecureCookies;\n`;
|
|
111
|
+
|
|
79
112
|
/**
|
|
80
113
|
* Returns a `./`-prefixed, **extensionless** POSIX module specifier from `.toil` to `abs`, for use
|
|
81
114
|
* in generated `import(...)` calls. Extensionless so TypeScript doesn't demand
|
package/src/compiler/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { build as viteBuild, createServer, mergeConfig, type ViteDevServer } fro
|
|
|
12
12
|
import type { RunningBackend } from 'toiljs/backend';
|
|
13
13
|
|
|
14
14
|
import { loadConfig } from './config.js';
|
|
15
|
-
import { generate } from './generate.js';
|
|
15
|
+
import { generate, TOIL_SERVER_ENV_DTS } from './generate.js';
|
|
16
16
|
import { prerenderStaticParams } from './ssg.js';
|
|
17
17
|
import { extractTemplates } from './template-build.js';
|
|
18
18
|
import { createViteConfig } from './vite.js';
|
|
@@ -109,6 +109,19 @@ function serverEntryFiles(root: string): string[] {
|
|
|
109
109
|
async function buildServer(root: string): Promise<void> {
|
|
110
110
|
if (!fs.existsSync(path.join(root, 'toilconfig.json'))) return;
|
|
111
111
|
|
|
112
|
+
// Regenerate the editor-only server-globals d.ts each build (the same way
|
|
113
|
+
// `generate` rewrites `toil-env.d.ts`), so an existing project auto-migrates
|
|
114
|
+
// to the current shapes without re-scaffolding or running doctor. Best
|
|
115
|
+
// effort; an unwritable dir never blocks the build.
|
|
116
|
+
for (const dir of serverDirs(root)) {
|
|
117
|
+
try {
|
|
118
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
119
|
+
fs.writeFileSync(path.join(dir, 'toil-server-env.d.ts'), TOIL_SERVER_ENV_DTS);
|
|
120
|
+
} catch {
|
|
121
|
+
// editor-only; ignore write failures
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
112
125
|
const require = createRequire(path.join(root, 'package.json'));
|
|
113
126
|
let binJs: string;
|
|
114
127
|
try {
|
|
@@ -337,7 +350,7 @@ export async function start(opts: ToilCommandOptions = {}): Promise<RunningBacke
|
|
|
337
350
|
export { defineConfig, loadConfig, AiProvider } from './config.js';
|
|
338
351
|
export { scanRoutes } from './routes.js';
|
|
339
352
|
export type { ScannedRoute } from './routes.js';
|
|
340
|
-
export { TOIL_ENV_DTS } from './generate.js';
|
|
353
|
+
export { TOIL_ENV_DTS, TOIL_SERVER_ENV_DTS } from './generate.js';
|
|
341
354
|
export { AI_HELPERS, AI_HELPER_IDS, aiHelperFiles, TOIL_DOCS } from './docs.js';
|
|
342
355
|
export type { AiHelper } from './docs.js';
|
|
343
356
|
export type {
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Editor-only ambient declarations for the toiljs cookie globals.
|
|
3
|
-
*
|
|
4
|
-
* `Cookie`, `Cookies`, `SecureCookies`, and the `SameSite` / `CookieEncoding` /
|
|
5
|
-
* `CookiePrefix` enums are `@global` in the toiljs server runtime, so a handler
|
|
6
|
-
* uses them with no import (exactly like `crypto`). The toilscript compiler
|
|
7
|
-
* registers them from the runtime; this file just gives the editor their shapes
|
|
8
|
-
* so it does not flag the unimported names. It is auto-included by the server
|
|
9
|
-
* `tsconfig.json` (`include: ["./**/*.ts"]`) and ignored by the compiler.
|
|
10
|
-
*
|
|
11
|
-
* `toiljs create` scaffolds this file; keep it in sync with
|
|
12
|
-
* `toiljs/server/runtime/http/*`.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
declare enum SameSite {
|
|
16
|
-
Default = 0,
|
|
17
|
-
None = 1,
|
|
18
|
-
Lax = 2,
|
|
19
|
-
Strict = 3,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
declare enum CookieEncoding {
|
|
23
|
-
Percent = 0,
|
|
24
|
-
Raw = 1,
|
|
25
|
-
Base64Url = 2,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
declare enum CookiePrefix {
|
|
29
|
-
None = 0,
|
|
30
|
-
Secure = 1,
|
|
31
|
-
Host = 2,
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
declare class CookieValidation {
|
|
35
|
-
valid: bool;
|
|
36
|
-
errors: Array<string>;
|
|
37
|
-
fail(msg: string): void;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
declare class Cookie {
|
|
41
|
-
name: string;
|
|
42
|
-
value: string;
|
|
43
|
-
encoding: CookieEncoding;
|
|
44
|
-
constructor(name: string, value: string);
|
|
45
|
-
static create(name: string, value: string): Cookie;
|
|
46
|
-
domain(v: string): Cookie;
|
|
47
|
-
path(v: string): Cookie;
|
|
48
|
-
maxAge(seconds: i64): Cookie;
|
|
49
|
-
expires(epochSeconds: i64): Cookie;
|
|
50
|
-
expiresRaw(date: string): Cookie;
|
|
51
|
-
secure(on?: bool): Cookie;
|
|
52
|
-
httpOnly(on?: bool): Cookie;
|
|
53
|
-
sameSite(s: SameSite): Cookie;
|
|
54
|
-
partitioned(on?: bool): Cookie;
|
|
55
|
-
priority(p: string): Cookie;
|
|
56
|
-
extension(av: string): Cookie;
|
|
57
|
-
withEncoding(e: CookieEncoding): Cookie;
|
|
58
|
-
asSecurePrefixed(): Cookie;
|
|
59
|
-
asHostPrefixed(): Cookie;
|
|
60
|
-
detectedPrefix(): CookiePrefix;
|
|
61
|
-
encodedValue(): string;
|
|
62
|
-
validate(): CookieValidation;
|
|
63
|
-
serialize(strict?: bool): string;
|
|
64
|
-
toString(): string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
declare class CookieMap {
|
|
68
|
-
set(name: string, value: string): void;
|
|
69
|
-
get(name: string): string | null;
|
|
70
|
-
has(name: string): bool;
|
|
71
|
-
names(): Array<string>;
|
|
72
|
-
readonly size: i32;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
declare class Cookies {
|
|
76
|
-
static parse(cookieHeader: string): CookieMap;
|
|
77
|
-
static get(cookieHeader: string, name: string): string | null;
|
|
78
|
-
static serialize(name: string, value: string): string;
|
|
79
|
-
static parseSetCookie(setCookie: string): Cookie;
|
|
80
|
-
static encodeValue(raw: string): string;
|
|
81
|
-
static decodeValue(enc: string): string;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
declare class SecureCookies {
|
|
85
|
-
static signed(key: Uint8Array): SecureCookies;
|
|
86
|
-
static encrypted(key: Uint8Array): SecureCookies;
|
|
87
|
-
addKey(key: Uint8Array): SecureCookies;
|
|
88
|
-
sign(name: string, value: string): string;
|
|
89
|
-
unsign(name: string, sealed: string): string | null;
|
|
90
|
-
encrypt(name: string, value: string): string;
|
|
91
|
-
decrypt(name: string, sealed: string): string | null;
|
|
92
|
-
seal(cookie: Cookie): Cookie;
|
|
93
|
-
open(jar: CookieMap, name: string): string | null;
|
|
94
|
-
}
|