toiljs 0.0.127 → 0.0.129
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 +29 -0
- package/assets/image-codec-LICENSES.txt +4599 -0
- package/assets/image-codec-build.json +10 -0
- package/assets/image-codec.wasm +0 -0
- package/build/backend/index.d.ts +1 -0
- package/build/backend/index.js +8 -3
- package/build/backend/security.d.ts +4 -0
- package/build/backend/security.js +31 -0
- package/build/cli/index.js +11 -39
- package/build/client/components/Script.js +28 -17
- package/build/client/files.d.ts +17 -0
- package/build/client/files.js +119 -0
- package/build/client/html.d.ts +1 -0
- package/build/client/html.js +8 -0
- package/build/client/index.d.ts +1 -0
- package/build/client/index.js +1 -0
- package/build/client/security.d.ts +4 -0
- package/build/client/security.js +55 -0
- package/build/client/ssr/markers.js +6 -1
- package/build/compiler/config.d.ts +2 -0
- package/build/compiler/config.js +1 -0
- package/build/compiler/generate.d.ts +1 -1
- package/build/compiler/generate.js +1 -37
- package/build/compiler/index.d.ts +1 -0
- package/build/compiler/index.js +56 -1
- package/build/compiler/security-deployment.d.ts +3 -0
- package/build/compiler/security-deployment.js +88 -0
- package/build/compiler/security.d.ts +7 -0
- package/build/compiler/security.js +74 -0
- package/build/compiler/sri.js +10 -3
- package/build/compiler/toil-docs.generated.js +35 -28
- package/build/compiler/vite.js +2 -0
- package/build/devserver/config/env.d.ts +6 -0
- package/build/devserver/config/env.js +10 -2
- package/build/devserver/daemon/catalog.d.ts +1 -0
- package/build/devserver/daemon/catalog.js +10 -4
- package/build/devserver/daemon/host.d.ts +5 -1
- package/build/devserver/daemon/host.js +8 -4
- package/build/devserver/daemon/http.d.ts +14 -0
- package/build/devserver/daemon/http.js +90 -0
- package/build/devserver/daemon/index.d.ts +21 -1
- package/build/devserver/daemon/index.js +109 -21
- package/build/devserver/db/atomic.d.ts +8 -0
- package/build/devserver/db/atomic.js +133 -0
- package/build/devserver/db/catalog.d.ts +7 -0
- package/build/devserver/db/catalog.js +17 -0
- package/build/devserver/db/changes.d.ts +5 -0
- package/build/devserver/db/changes.js +49 -0
- package/build/devserver/db/database.d.ts +7 -0
- package/build/devserver/db/database.js +251 -41
- package/build/devserver/db/derives.d.ts +4 -5
- package/build/devserver/db/derives.js +7 -76
- package/build/devserver/db/document-scan.d.ts +2 -0
- package/build/devserver/db/document-scan.js +123 -0
- package/build/devserver/db/limits.d.ts +16 -0
- package/build/devserver/db/limits.js +92 -14
- package/build/devserver/db/types.d.ts +15 -0
- package/build/devserver/db/types.js +9 -0
- package/build/devserver/files/dev.d.ts +3 -0
- package/build/devserver/files/dev.js +29 -0
- package/build/devserver/files/disk.d.ts +17 -0
- package/build/devserver/files/disk.js +369 -0
- package/build/devserver/files/signatures.d.ts +16 -0
- package/build/devserver/files/signatures.js +151 -0
- package/build/devserver/http/proxy.js +11 -3
- package/build/devserver/http/runtime.js +36 -9
- package/build/devserver/images/index.d.ts +9 -0
- package/build/devserver/images/index.js +87 -0
- package/build/devserver/images/worker.d.mts +1 -0
- package/build/devserver/images/worker.mjs +24 -0
- package/build/devserver/index.d.ts +3 -1
- package/build/devserver/production.js +5 -3
- package/build/devserver/runtime/host.d.ts +4 -0
- package/build/devserver/runtime/host.js +6 -2
- package/build/devserver/runtime/module.d.ts +15 -0
- package/build/devserver/runtime/module.js +105 -7
- package/build/devserver/server.js +13 -1
- package/build/devserver/stream/host.d.ts +2 -0
- package/build/devserver/stream/host.js +2 -1
- package/build/devserver/stream/index.js +2 -0
- package/build/io/derive-metadata.d.ts +7 -0
- package/build/io/derive-metadata.js +44 -0
- package/build/io/index.d.ts +1 -0
- package/build/io/index.js +1 -0
- package/build/shared/index.d.ts +1 -0
- package/build/shared/index.js +1 -0
- package/build/shared/security.d.ts +5 -0
- package/build/shared/security.js +80 -0
- package/docs/auth/vectors-v1.json +41 -0
- package/examples/basic/client/routes/rest.tsx +1 -1
- package/examples/basic/server/routes/Guestbook.ts +1 -1
- package/package.json +20 -7
- package/scripts/build-image-codec.mjs +79 -0
- package/scripts/gen-auth-vectors.mjs +132 -0
- package/scripts/gen-native-atomic-fixture.mjs +39 -0
- package/scripts/gen-native-blob-fixture.mjs +42 -0
- package/scripts/gen-native-image-fixture.mjs +65 -0
- package/scripts/gen-native-staging-fixture.mjs +41 -0
- package/scripts/gen-server-types.mjs +82 -0
- package/scripts/gen-toil-docs.mjs +19 -7
- package/server/auth/AuthController.ts +15 -234
- package/server/auth/AuthMaintenance.ts +177 -0
- package/server/auth/AuthStore.ts +198 -0
- package/server/auth/SessionEpochs.ts +38 -9
- package/server/globals/auth.ts +56 -0
- package/server/globals/userid.ts +4 -5
- package/server/globals.d.ts +37 -0
- package/server/runtime/envelope.ts +2 -1
- package/server/runtime/exports/index.ts +2 -1
- package/server/runtime/files/blobs.ts +341 -0
- package/server/runtime/files/images.ts +36 -0
- package/server/runtime/http/percent.ts +5 -4
- package/server/runtime/index.ts +5 -0
- package/server/runtime/response.ts +20 -0
- package/server/runtime/rest/RouteContext.ts +5 -4
- package/std/server/abort/abort.d.ts +25 -0
- package/std/server/env/Server.d.ts +47 -0
- package/std/server/envelope.d.ts +38 -0
- package/std/server/exports/index.d.ts +20 -0
- package/std/server/exports/render.d.ts +15 -0
- package/std/server/files/blobs.d.ts +50 -0
- package/std/server/files/images.d.ts +36 -0
- package/std/server/handlers/ToilHandler.d.ts +29 -0
- package/std/server/http/base64.d.ts +21 -0
- package/std/server/http/cookie.d.ts +127 -0
- package/std/server/http/cookies.d.ts +56 -0
- package/std/server/http/date.d.ts +17 -0
- package/std/server/http/percent.d.ts +19 -0
- package/std/server/http/securecookies.d.ts +55 -0
- package/std/server/index.d.ts +34 -0
- package/std/server/lang/Potential.d.ts +6 -0
- package/std/server/memory.d.ts +42 -0
- package/std/server/request.d.ts +47 -0
- package/std/server/response.d.ts +90 -0
- package/std/server/rest/Rest.d.ts +23 -0
- package/std/server/rest/RestHandler.d.ts +14 -0
- package/std/server/rest/RouteContext.d.ts +33 -0
- package/std/server/rest/match.d.ts +14 -0
- package/std/server/rpc/Rpc.d.ts +37 -0
- package/std/server/ssr/Ssr.d.ts +27 -0
- package/std/server/ssr/encode.d.ts +26 -0
- package/std/server/ssr/escape.d.ts +22 -0
- package/std/server/ssr/slots.d.ts +91 -0
- package/std/server/time.d.ts +24 -0
- package/tsconfig.json +11 -2
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
export declare class BlobField {
|
|
3
|
+
name: string;
|
|
4
|
+
value: string;
|
|
5
|
+
constructor(name?: string, value?: string);
|
|
6
|
+
}
|
|
7
|
+
/** Send these fields first and the file last as multipart/form-data. */
|
|
8
|
+
export declare class BlobUpload {
|
|
9
|
+
url: string;
|
|
10
|
+
fields: BlobField[];
|
|
11
|
+
size: f64;
|
|
12
|
+
expiresAt: f64;
|
|
13
|
+
}
|
|
14
|
+
/** Server-only credentials for a bucket endpoint supporting SigV4 POST policies.
|
|
15
|
+
* The endpoint includes the bucket, e.g. https://bucket.s3.region.amazonaws.com
|
|
16
|
+
* or https://storage.example/bucket. Use credentials limited to this bucket/prefix. */
|
|
17
|
+
export declare class BlobStorage {
|
|
18
|
+
readonly endpoint: string;
|
|
19
|
+
readonly bucket: string;
|
|
20
|
+
readonly region: string;
|
|
21
|
+
private accessKey;
|
|
22
|
+
private secretKey;
|
|
23
|
+
readonly prefix: string;
|
|
24
|
+
private sessionToken;
|
|
25
|
+
private origin;
|
|
26
|
+
private host;
|
|
27
|
+
private basePath;
|
|
28
|
+
private cachedDate;
|
|
29
|
+
private cachedKey;
|
|
30
|
+
constructor(endpoint: string, bucket: string, region: string, accessKey: string, secretKey: string, prefix?: string, sessionToken?: string);
|
|
31
|
+
static fromEnvironment(): BlobStorage;
|
|
32
|
+
private key;
|
|
33
|
+
private stamp;
|
|
34
|
+
/** Useful for server-side storage adapters; application ACLs run before signing. */
|
|
35
|
+
presign(method: string, objectKey: string, atMillis: i64, expiresSecs?: i32): string;
|
|
36
|
+
upload(objectKey: string, size: f64, contentType: string, atMillis: i64, expiresSecs?: i32): BlobUpload;
|
|
37
|
+
}
|
|
38
|
+
/** A typed file namespace. Bytes stream directly between client and storage;
|
|
39
|
+
* keys remain ordinary @data values, with access controlled by application routes. */
|
|
40
|
+
export declare class Blobs<K> {
|
|
41
|
+
private namespace;
|
|
42
|
+
private storage;
|
|
43
|
+
constructor(namespace: string, storage?: BlobStorage | null);
|
|
44
|
+
private config;
|
|
45
|
+
private objectKey;
|
|
46
|
+
upload(key: K, size: f64, contentType?: string, expiresSecs?: i32): BlobUpload;
|
|
47
|
+
downloadUrl(key: K, expiresSecs?: i32): string;
|
|
48
|
+
headUrl(key: K, expiresSecs?: i32): string;
|
|
49
|
+
deleteUrl(key: K, expiresSecs?: i32): string;
|
|
50
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
export declare enum ImageError {
|
|
3
|
+
None = 0,
|
|
4
|
+
Invalid = 2,
|
|
5
|
+
Unsupported = 3,
|
|
6
|
+
Limit = 4,
|
|
7
|
+
Busy = 5,
|
|
8
|
+
Timeout = 6,
|
|
9
|
+
Unavailable = 7,
|
|
10
|
+
Options = 8,
|
|
11
|
+
Kind = 9,
|
|
12
|
+
Quota = 10
|
|
13
|
+
}
|
|
14
|
+
export declare enum ImageFormat {
|
|
15
|
+
Png = 1,
|
|
16
|
+
Jpeg = 2
|
|
17
|
+
}
|
|
18
|
+
export declare class ImageResult {
|
|
19
|
+
error: ImageError;
|
|
20
|
+
bytes: Uint8Array;
|
|
21
|
+
width: u32;
|
|
22
|
+
height: u32;
|
|
23
|
+
format: ImageFormat;
|
|
24
|
+
get ok(): bool;
|
|
25
|
+
get contentType(): string;
|
|
26
|
+
}
|
|
27
|
+
export declare class Images {
|
|
28
|
+
private static run;
|
|
29
|
+
/** Re-encode without EXIF/XMP/IPTC/text/comments, applying orientation.
|
|
30
|
+
* Retains ICC profiles and PNG color descriptors. JPEG is re-encoded. */
|
|
31
|
+
static stripExif(input: Uint8Array, quality?: i32): ImageResult;
|
|
32
|
+
/** Fit inside the box, retaining aspect ratio and avoiding enlargement. */
|
|
33
|
+
static resize(input: Uint8Array, width: i32, height: i32, quality?: i32): ImageResult;
|
|
34
|
+
/** Center crop to the requested aspect ratio, avoiding enlargement. */
|
|
35
|
+
static thumbnail(input: Uint8Array, width: i32, height: i32, quality?: i32): ImageResult;
|
|
36
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/**
|
|
3
|
+
* Base class every toiljs server-side handler extends. Override
|
|
4
|
+
* `handle(req)` to produce the response. The framework calls
|
|
5
|
+
* `onRequestStarted` / `onRequestCompleted` around every call so the user
|
|
6
|
+
* can hook for logging or metrics without re-implementing `handle`.
|
|
7
|
+
*/
|
|
8
|
+
import { Request } from '../request';
|
|
9
|
+
import { Response } from '../response';
|
|
10
|
+
export declare class ToilHandler {
|
|
11
|
+
/**
|
|
12
|
+
* Override to declare your routes. The default implementation
|
|
13
|
+
* returns an unhandled-marked 404 so a handler that hasn't been
|
|
14
|
+
* wired up still produces a valid envelope, and the host knows it
|
|
15
|
+
* may serve the path itself.
|
|
16
|
+
*/
|
|
17
|
+
handle(_req: Request): Response;
|
|
18
|
+
/**
|
|
19
|
+
* Called before each `handle` call. Empty by default; override
|
|
20
|
+
* for per-request setup (logging, header reads, etc.).
|
|
21
|
+
*/
|
|
22
|
+
onRequestStarted(_req: Request): void;
|
|
23
|
+
/**
|
|
24
|
+
* Called after each `handle` call returns (also when it throws,
|
|
25
|
+
* after the runtime has converted the throw into a 500). Empty by
|
|
26
|
+
* default.
|
|
27
|
+
*/
|
|
28
|
+
onRequestCompleted(_req: Request, _resp: Response): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/**
|
|
3
|
+
* base64url (RFC 4648 §5), unpadded. The toilscript std ships `Encoding.Hex`
|
|
4
|
+
* and `Encoding.Varint` but no base64, and `SecureCookies` needs a compact,
|
|
5
|
+
* cookie-safe transport for raw bytes (IV ‖ ciphertext ‖ tag, or an HMAC).
|
|
6
|
+
*
|
|
7
|
+
* base64url is a deliberate fit for cookies: its alphabet
|
|
8
|
+
* (`A-Z a-z 0-9 - _`) is entirely within the RFC 6265bis `cookie-octet` set
|
|
9
|
+
* and is invariant under percent-encoding, so a sealed value round-trips
|
|
10
|
+
* cleanly through the default cookie encoder/decoder untouched.
|
|
11
|
+
*
|
|
12
|
+
* Internal to the cookie library (not a global).
|
|
13
|
+
*/
|
|
14
|
+
/** Encode `data` as unpadded base64url. */
|
|
15
|
+
export declare function base64UrlEncode(data: Uint8Array): string;
|
|
16
|
+
/**
|
|
17
|
+
* Decode unpadded (or padded) base64url/base64 into bytes, or `null` if the
|
|
18
|
+
* input contains an invalid character or has an impossible length. `=` padding
|
|
19
|
+
* and ASCII whitespace are tolerated and ignored.
|
|
20
|
+
*/
|
|
21
|
+
export declare function base64UrlDecode(s: string): Uint8Array | null;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/**
|
|
3
|
+
* `Cookie` — a fluent builder, serializer, and validator for a single
|
|
4
|
+
* `Set-Cookie`, covering the full RFC 6265bis attribute set plus the
|
|
5
|
+
* `Partitioned` (CHIPS) and `Priority` attributes.
|
|
6
|
+
*
|
|
7
|
+
* Exposed as an ambient global (`@global`, no import needed in a handler) and
|
|
8
|
+
* also exported from `toiljs/server/runtime`. Pairs with `Cookies` (parsing /
|
|
9
|
+
* the request side) and `SecureCookies` (signing / encryption).
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* resp.setCookie(
|
|
13
|
+
* Cookie.create('sid', token)
|
|
14
|
+
* .httpOnly()
|
|
15
|
+
* .secure()
|
|
16
|
+
* .sameSite(SameSite.Lax)
|
|
17
|
+
* .maxAge(3600)
|
|
18
|
+
* .asHostPrefixed(),
|
|
19
|
+
* );
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
/** `SameSite` attribute. `Default` omits the attribute (the UA applies Lax). */
|
|
23
|
+
export declare enum SameSite {
|
|
24
|
+
Default = 0,
|
|
25
|
+
None = 1,
|
|
26
|
+
Lax = 2,
|
|
27
|
+
Strict = 3
|
|
28
|
+
}
|
|
29
|
+
/** How a cookie value is encoded onto the wire. */
|
|
30
|
+
export declare enum CookieEncoding {
|
|
31
|
+
/** `encodeURIComponent`-style percent-encoding (default): arbitrary UTF-8 is safe. */
|
|
32
|
+
Percent = 0,
|
|
33
|
+
/** No transformation. The value must already be valid `cookie-octet`. */
|
|
34
|
+
Raw = 1,
|
|
35
|
+
/** UTF-8 then unpadded base64url. */
|
|
36
|
+
Base64Url = 2
|
|
37
|
+
}
|
|
38
|
+
/** Cookie name prefix with browser-enforced guarantees (RFC 6265bis §4.1.3). */
|
|
39
|
+
export declare enum CookiePrefix {
|
|
40
|
+
None = 0,
|
|
41
|
+
/** `__Secure-`: requires `Secure`. */
|
|
42
|
+
Secure = 1,
|
|
43
|
+
/** `__Host-`: requires `Secure`, `Path=/`, and no `Domain`. */
|
|
44
|
+
Host = 2
|
|
45
|
+
}
|
|
46
|
+
/** SHOULD-NOT-exceed lifetime cap from RFC 6265bis §5.5: 400 days, in seconds. */
|
|
47
|
+
export declare const MAX_LIFETIME_SECONDS: i64;
|
|
48
|
+
/** RFC 6265bis `cookie-octet`: %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E. */
|
|
49
|
+
export declare function isCookieOctet(c: i32): bool;
|
|
50
|
+
/** Result of {@link Cookie#validate}: `valid` plus the list of problems found. */
|
|
51
|
+
export declare class CookieValidation {
|
|
52
|
+
valid: bool;
|
|
53
|
+
errors: Array<string>;
|
|
54
|
+
fail(msg: string): void;
|
|
55
|
+
}
|
|
56
|
+
export declare class Cookie {
|
|
57
|
+
/** Cookie name (a token; never encoded). */
|
|
58
|
+
name: string;
|
|
59
|
+
/** Logical cookie value (encoded per {@link encoding} on serialize). */
|
|
60
|
+
value: string;
|
|
61
|
+
/** Wire encoding applied to {@link value} by {@link serialize}. */
|
|
62
|
+
encoding: CookieEncoding;
|
|
63
|
+
private _domain;
|
|
64
|
+
private _path;
|
|
65
|
+
private _maxAge;
|
|
66
|
+
private _hasMaxAge;
|
|
67
|
+
private _expires;
|
|
68
|
+
private _hasExpires;
|
|
69
|
+
private _expiresRaw;
|
|
70
|
+
private _secure;
|
|
71
|
+
private _httpOnly;
|
|
72
|
+
private _sameSite;
|
|
73
|
+
private _partitioned;
|
|
74
|
+
private _priority;
|
|
75
|
+
private _extensions;
|
|
76
|
+
constructor(name: string, value: string);
|
|
77
|
+
/** Construct a cookie. Builder-style alias for `new Cookie(name, value)`. */
|
|
78
|
+
static create(name: string, value: string): Cookie;
|
|
79
|
+
/** `Domain` attribute. */
|
|
80
|
+
domain(v: string): Cookie;
|
|
81
|
+
/** `Path` attribute (must begin with `/`). */
|
|
82
|
+
path(v: string): Cookie;
|
|
83
|
+
/** `Max-Age` in seconds. `0` / negative expire the cookie immediately. */
|
|
84
|
+
maxAge(seconds: i64): Cookie;
|
|
85
|
+
/** `Expires` from a Unix timestamp (seconds), formatted as an IMF-fixdate. */
|
|
86
|
+
expires(epochSeconds: i64): Cookie;
|
|
87
|
+
/** `Expires` as a verbatim date string (escape hatch; not validated). */
|
|
88
|
+
expiresRaw(date: string): Cookie;
|
|
89
|
+
/** `Secure` attribute. */
|
|
90
|
+
secure(on?: bool): Cookie;
|
|
91
|
+
/** `HttpOnly` attribute. */
|
|
92
|
+
httpOnly(on?: bool): Cookie;
|
|
93
|
+
/** `SameSite` attribute. */
|
|
94
|
+
sameSite(s: SameSite): Cookie;
|
|
95
|
+
/** `Partitioned` attribute (CHIPS). Implies `Secure` on serialize. */
|
|
96
|
+
partitioned(on?: bool): Cookie;
|
|
97
|
+
/** `Priority` attribute (`Low` / `Medium` / `High`). */
|
|
98
|
+
priority(p: string): Cookie;
|
|
99
|
+
/** Append a raw extension attribute verbatim, e.g. `extension('CustomFlag')`. */
|
|
100
|
+
extension(av: string): Cookie;
|
|
101
|
+
/** Choose the wire encoding for the value. */
|
|
102
|
+
withEncoding(e: CookieEncoding): Cookie;
|
|
103
|
+
/** Apply the `__Secure-` prefix and force `Secure`. */
|
|
104
|
+
asSecurePrefixed(): Cookie;
|
|
105
|
+
/** Apply the `__Host-` prefix and force `Secure`, `Path=/`, and no `Domain`. */
|
|
106
|
+
asHostPrefixed(): Cookie;
|
|
107
|
+
/** SameSite=None and Partitioned both require Secure; reflect that here. */
|
|
108
|
+
private effectiveSecure;
|
|
109
|
+
/** The name prefix detected case-insensitively (RFC 6265bis §5.4). */
|
|
110
|
+
detectedPrefix(): CookiePrefix;
|
|
111
|
+
/** The value transformed per {@link encoding}, ready for the wire. */
|
|
112
|
+
encodedValue(): string;
|
|
113
|
+
/**
|
|
114
|
+
* Validate against RFC 6265bis: name token, name+value ≤ 4096 bytes,
|
|
115
|
+
* attribute sizes, `Path` form, prefix guarantees, `SameSite=None`/
|
|
116
|
+
* `Partitioned` ⇒ `Secure`, and the 400-day lifetime cap.
|
|
117
|
+
*/
|
|
118
|
+
validate(): CookieValidation;
|
|
119
|
+
/**
|
|
120
|
+
* Serialize to a `Set-Cookie` field value. Lenient by default (always emits
|
|
121
|
+
* a best-effort cookie); pass `strict = true` to throw on a hard violation.
|
|
122
|
+
* `Secure` is emitted automatically when `SameSite=None` or `Partitioned` is
|
|
123
|
+
* set, and `Max-Age` is clamped to the 400-day cap.
|
|
124
|
+
*/
|
|
125
|
+
serialize(strict?: bool): string;
|
|
126
|
+
toString(): string;
|
|
127
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/**
|
|
3
|
+
* `Cookies` — parsing and codec helpers, and `CookieMap`, the result of parsing
|
|
4
|
+
* a request `Cookie` header. The write side (building a `Set-Cookie`) lives on
|
|
5
|
+
* the {@link Cookie} builder; this is the read side plus a one-shot serializer.
|
|
6
|
+
*
|
|
7
|
+
* Both `Cookies` and `CookieMap` are ambient globals (`@global`, no import) and
|
|
8
|
+
* are also exported from `toiljs/server/runtime`.
|
|
9
|
+
*/
|
|
10
|
+
import { Cookie } from './cookie';
|
|
11
|
+
/**
|
|
12
|
+
* An ordered, name→value view of the cookies on a request. Backed by parallel
|
|
13
|
+
* arrays (a request carries a handful of cookies; the linear scan beats hashing
|
|
14
|
+
* and keeps the codec-free runtime small, matching `RouteContext`). On a
|
|
15
|
+
* duplicate name the first occurrence wins (it is the most specific per
|
|
16
|
+
* RFC 6265bis ordering).
|
|
17
|
+
*/
|
|
18
|
+
export declare class CookieMap {
|
|
19
|
+
private keys;
|
|
20
|
+
private vals;
|
|
21
|
+
/** Insert unless `name` is already present (keep-first). */
|
|
22
|
+
set(name: string, value: string): void;
|
|
23
|
+
/** The value for `name`, or `null` if absent. */
|
|
24
|
+
get(name: string): string | null;
|
|
25
|
+
has(name: string): bool;
|
|
26
|
+
/** A copy of the cookie names, in encounter order. */
|
|
27
|
+
names(): Array<string>;
|
|
28
|
+
get size(): i32;
|
|
29
|
+
}
|
|
30
|
+
export declare class Cookies {
|
|
31
|
+
/**
|
|
32
|
+
* Parse a request `Cookie` header (`a=1; b=2`) into a {@link CookieMap}.
|
|
33
|
+
* Values are percent-decoded (the inverse of the default `Cookie` encoding)
|
|
34
|
+
* and one layer of surrounding quotes is stripped. Malformed pairs and
|
|
35
|
+
* empty names are skipped, never thrown.
|
|
36
|
+
*/
|
|
37
|
+
static parse(cookieHeader: string): CookieMap;
|
|
38
|
+
/** Shorthand: parse `cookieHeader` and return the value for `name`, or `null`. */
|
|
39
|
+
static get(cookieHeader: string, name: string): string | null;
|
|
40
|
+
/**
|
|
41
|
+
* One-shot `Set-Cookie` value for `name=value` with no attributes
|
|
42
|
+
* (percent-encoded). For attributes, build a {@link Cookie} and call
|
|
43
|
+
* `cookie.serialize()`.
|
|
44
|
+
*/
|
|
45
|
+
static serialize(name: string, value: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Parse a `Set-Cookie` field value back into a {@link Cookie} (for clients,
|
|
48
|
+
* tests, or proxies). The value is kept verbatim (`CookieEncoding.Raw`) so
|
|
49
|
+
* re-serializing reproduces the original wire form.
|
|
50
|
+
*/
|
|
51
|
+
static parseSetCookie(setCookie: string): Cookie;
|
|
52
|
+
/** Percent-encode a value as the default `Cookie` encoding would. */
|
|
53
|
+
static encodeValue(raw: string): string;
|
|
54
|
+
/** Percent-decode a value (the inverse of {@link encodeValue}). */
|
|
55
|
+
static decodeValue(enc: string): string;
|
|
56
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/**
|
|
3
|
+
* IMF-fixdate formatting for the cookie `Expires` attribute, e.g.
|
|
4
|
+
* `Sun, 06 Nov 1994 08:49:37 GMT` (RFC 9110 §5.6.7, the only date format
|
|
5
|
+
* RFC 6265bis permits a server to emit).
|
|
6
|
+
*
|
|
7
|
+
* Pure integer math (no `Date` dependency) so it is deterministic and unit
|
|
8
|
+
* testable: the civil-from-days conversion is Howard Hinnant's algorithm,
|
|
9
|
+
* valid across the whole proleptic Gregorian range. Internal to the cookie
|
|
10
|
+
* library (not a global).
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Format `epochSeconds` (Unix time, seconds since 1970-01-01T00:00:00Z) as an
|
|
14
|
+
* IMF-fixdate string in GMT. Handles negative inputs (pre-epoch) correctly via
|
|
15
|
+
* floored division.
|
|
16
|
+
*/
|
|
17
|
+
export declare function imfFixdate(epochSeconds: i64): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/**
|
|
3
|
+
* Percent-encoding for cookie values, matching `encodeURIComponent` /
|
|
4
|
+
* `decodeURIComponent` semantics (the de-facto default of Node's `cookie`
|
|
5
|
+
* package). The unreserved set (`A-Z a-z 0-9 - _ . ! ~ * ' ( )`) is a subset of
|
|
6
|
+
* the RFC 6265bis `cookie-octet` grammar, so the output is always a valid
|
|
7
|
+
* unquoted cookie value and arbitrary UTF-8 round-trips safely.
|
|
8
|
+
*
|
|
9
|
+
* Internal to the cookie library (not a global); surfaced through
|
|
10
|
+
* `Cookies.encodeValue` / `Cookies.decodeValue`.
|
|
11
|
+
*/
|
|
12
|
+
/** Percent-encode `s` (UTF-8) into a cookie-safe value. */
|
|
13
|
+
export declare function percentEncode(s: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Reverse {@link percentEncode}. A `%` not followed by two hex digits is kept
|
|
16
|
+
* literally (lenient, never throws). `+` is preserved as-is (cookies are not
|
|
17
|
+
* form-encoded, so `+` is not a space).
|
|
18
|
+
*/
|
|
19
|
+
export declare function percentDecode(s: string): string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/**
|
|
3
|
+
* `SecureCookies` — tamper-proof and confidential cookie values, built on the
|
|
4
|
+
* ambient `crypto` global (no new host functions).
|
|
5
|
+
*
|
|
6
|
+
* - `SecureCookies.signed(key)` — HMAC-SHA256. The value stays readable but is
|
|
7
|
+
* bound to the cookie name, so it cannot be tampered with or moved to another
|
|
8
|
+
* cookie. Sealed form: `base64url(value) "." base64url(mac)`.
|
|
9
|
+
* - `SecureCookies.encrypted(key)` — AES-256-GCM with a random 96-bit IV and
|
|
10
|
+
* the cookie name as AAD. The value is confidential and authenticated.
|
|
11
|
+
* Sealed form: `base64url(iv ‖ ciphertext ‖ tag)`.
|
|
12
|
+
*
|
|
13
|
+
* Keys are caller-supplied raw bytes (HMAC: any length; AES: 16 or 32 bytes).
|
|
14
|
+
* Extra keys can be added for rotation: seal with the first, open with any.
|
|
15
|
+
*
|
|
16
|
+
* Verification and decryption are panic-free against attacker input: given a
|
|
17
|
+
* valid key, a tampered or truncated sealed value yields `null`, never a trap
|
|
18
|
+
* (`decrypt` reads the host return code directly rather than letting
|
|
19
|
+
* `subtle.decrypt` throw on a bad tag, since toilscript runs with exceptions
|
|
20
|
+
* disabled). Sealing with a misconfigured key (e.g. a wrong-length AES key) is a
|
|
21
|
+
* server-side error and is rejected up front by the factory.
|
|
22
|
+
*
|
|
23
|
+
* Ambient global (`@global`) and exported from `toiljs/server/runtime`.
|
|
24
|
+
*/
|
|
25
|
+
import { Cookie } from './cookie';
|
|
26
|
+
import { CookieMap } from './cookies';
|
|
27
|
+
export declare class SecureCookies {
|
|
28
|
+
private mode;
|
|
29
|
+
private keys;
|
|
30
|
+
private constructor();
|
|
31
|
+
/** HMAC-SHA256 signer/verifier with `key` (any length). */
|
|
32
|
+
static signed(key: Uint8Array): SecureCookies;
|
|
33
|
+
/** AES-256-GCM (or AES-128-GCM) with `key` (32 or 16 bytes). */
|
|
34
|
+
static encrypted(key: Uint8Array): SecureCookies;
|
|
35
|
+
/** Add a fallback key for rotation: sealing uses the first key, opening tries all. */
|
|
36
|
+
addKey(key: Uint8Array): SecureCookies;
|
|
37
|
+
private importHmac;
|
|
38
|
+
private importAes;
|
|
39
|
+
/** Return the signed (name-bound) sealed value for `name=value`. */
|
|
40
|
+
sign(name: string, value: string): string;
|
|
41
|
+
/** Verify a signed value for `name`, returning the plaintext or `null`. */
|
|
42
|
+
unsign(name: string, sealed: string): string | null;
|
|
43
|
+
/** Return the AES-GCM-encrypted sealed value for `name` / `value`. */
|
|
44
|
+
encrypt(name: string, value: string): string;
|
|
45
|
+
/** Decrypt a sealed value for `name`, returning the plaintext or `null`. */
|
|
46
|
+
decrypt(name: string, sealed: string): string | null;
|
|
47
|
+
/**
|
|
48
|
+
* Seal `cookie`'s value in place (sign or encrypt per this instance's mode)
|
|
49
|
+
* and mark it `Raw` (the sealed value is already cookie-safe base64url).
|
|
50
|
+
* Returns the same cookie for chaining.
|
|
51
|
+
*/
|
|
52
|
+
seal(cookie: Cookie): Cookie;
|
|
53
|
+
/** Read and open cookie `name` from a parsed jar, or `null` if missing/invalid. */
|
|
54
|
+
open(jar: CookieMap, name: string): string | null;
|
|
55
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/// <reference path="../../server/globals.d.ts" />
|
|
3
|
+
/**
|
|
4
|
+
* Public surface of the toiljs server runtime. The user does
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { Server, ToilHandler, Response } from './runtime';
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* and then assigns `Server.handler = () => new MyHandler()` in their
|
|
11
|
+
* `main.ts`. The wasm `handle(i32, i32) -> i64` export comes from
|
|
12
|
+
* `./exports`, which the user re-exports with `export * from
|
|
13
|
+
* './runtime/exports'`. The `abort` runtime hook comes from
|
|
14
|
+
* `./abort/abort`, which the user re-exports as a top-level `abort`
|
|
15
|
+
* function in their `main.ts`.
|
|
16
|
+
*/
|
|
17
|
+
export { Header, Method, Request } from './request';
|
|
18
|
+
export { Response, TOIL_UNHANDLED_HEADER } from './response';
|
|
19
|
+
export { ToilHandler } from './handlers/ToilHandler';
|
|
20
|
+
export { Server, ServerEnvironment } from './env/Server';
|
|
21
|
+
export { Time } from './time';
|
|
22
|
+
export { Ssr, SsrRegistry, RenderFn } from './ssr/Ssr';
|
|
23
|
+
export { SlotValues, SlotValue, HtmlBuilder } from './ssr/slots';
|
|
24
|
+
export { Rest, RestRegistry, RouteFn } from './rest/Rest';
|
|
25
|
+
export { Rpc, RpcRegistry, RpcFn, RPC_PATH, RPC_HEADER } from './rpc/Rpc';
|
|
26
|
+
export { RouteContext } from './rest/RouteContext';
|
|
27
|
+
export { matchRoute } from './rest/match';
|
|
28
|
+
export { RestHandler } from './rest/RestHandler';
|
|
29
|
+
export { Cookie, SameSite, CookieEncoding, CookiePrefix, CookieValidation } from './http/cookie';
|
|
30
|
+
export { Cookies, CookieMap } from './http/cookies';
|
|
31
|
+
export { SecureCookies } from './http/securecookies';
|
|
32
|
+
export { base64UrlEncode, base64UrlDecode } from './http/base64';
|
|
33
|
+
export { Blobs, BlobStorage, BlobUpload, BlobField } from './files/blobs';
|
|
34
|
+
export { Images, ImageResult, ImageFormat, ImageError } from './files/images';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/**
|
|
3
|
+
* Tiny load/store wrappers around AssemblyScript's linear-memory
|
|
4
|
+
* intrinsics. The envelope codec stays readable when it calls
|
|
5
|
+
* `readU16(p)` instead of `load<u16>(p)` everywhere.
|
|
6
|
+
*
|
|
7
|
+
* All reads are little-endian (matches the wire format produced by
|
|
8
|
+
* `toil-backend/src/http/envelope.rs`).
|
|
9
|
+
*/
|
|
10
|
+
export declare function readU8(ofs: usize): u8;
|
|
11
|
+
export declare function readU16(ofs: usize): u16;
|
|
12
|
+
export declare function readU32(ofs: usize): u32;
|
|
13
|
+
export declare function writeU8(ofs: usize, v: u8): void;
|
|
14
|
+
export declare function writeU16(ofs: usize, v: u16): void;
|
|
15
|
+
export declare function writeU32(ofs: usize, v: u32): void;
|
|
16
|
+
/**
|
|
17
|
+
* Read `len` bytes starting at `ofs` and return them as a fresh
|
|
18
|
+
* `Uint8Array` (copying out of linear memory). Used for the request
|
|
19
|
+
* body so the handler can hold onto it past the call to `dispatch`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readBytes(ofs: usize, len: u32): Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* Write `bytes` into linear memory starting at `ofs`. Returns the
|
|
24
|
+
* number of bytes written.
|
|
25
|
+
*/
|
|
26
|
+
export declare function writeBytes(ofs: usize, bytes: Uint8Array): u32;
|
|
27
|
+
/**
|
|
28
|
+
* Decode `len` bytes of UTF-8 at `ofs` into a string. The bytes
|
|
29
|
+
* remain in linear memory; the returned string is a fresh AS string.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readUtf8(ofs: usize, len: u32): string;
|
|
32
|
+
/**
|
|
33
|
+
* Encode `s` as UTF-8 into linear memory starting at `ofs`. Returns
|
|
34
|
+
* the number of bytes written.
|
|
35
|
+
*/
|
|
36
|
+
export declare function writeUtf8(ofs: usize, s: string): u32;
|
|
37
|
+
/**
|
|
38
|
+
* UTF-8 byte length of `s` without actually writing it anywhere.
|
|
39
|
+
* Used by the response encoder to pre-compute total envelope size
|
|
40
|
+
* before laying out the bytes.
|
|
41
|
+
*/
|
|
42
|
+
export declare function utf8Length(s: string): u32;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/**
|
|
3
|
+
* The incoming HTTP request handed to the user's handler. Decoded
|
|
4
|
+
* from the wire envelope the host wrote at offset 0 of linear
|
|
5
|
+
* memory. See `envelope.ts`.
|
|
6
|
+
*/
|
|
7
|
+
import { CookieMap } from './http/cookies';
|
|
8
|
+
export declare enum Method {
|
|
9
|
+
GET = 0,
|
|
10
|
+
POST = 1,
|
|
11
|
+
PUT = 2,
|
|
12
|
+
DELETE = 3,
|
|
13
|
+
PATCH = 4,
|
|
14
|
+
HEAD = 5,
|
|
15
|
+
OPTIONS = 6,
|
|
16
|
+
UNKNOWN = 255
|
|
17
|
+
}
|
|
18
|
+
export declare class Header {
|
|
19
|
+
name: string;
|
|
20
|
+
value: string;
|
|
21
|
+
constructor(name: string, value: string);
|
|
22
|
+
}
|
|
23
|
+
export declare class Request {
|
|
24
|
+
method: Method;
|
|
25
|
+
path: string;
|
|
26
|
+
headers: Array<Header>;
|
|
27
|
+
body: Uint8Array;
|
|
28
|
+
__authChecked: bool;
|
|
29
|
+
__authBytes: Uint8Array | null;
|
|
30
|
+
__authExpires: u64;
|
|
31
|
+
private _cookies;
|
|
32
|
+
constructor(method: Method, path: string, headers: Array<Header>, body: Uint8Array);
|
|
33
|
+
/**
|
|
34
|
+
* Case-insensitive header lookup. Returns `null` if not present.
|
|
35
|
+
* O(n) over the header list; the request typically carries fewer
|
|
36
|
+
* than a dozen, so the linear scan is the right call.
|
|
37
|
+
*/
|
|
38
|
+
header(name: string): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* The request's cookies, parsed from the `Cookie` header (values are
|
|
41
|
+
* percent-decoded). Parsed once and cached; an empty map if there is no
|
|
42
|
+
* `Cookie` header.
|
|
43
|
+
*/
|
|
44
|
+
cookies(): CookieMap;
|
|
45
|
+
/** A single cookie value by name, or `null` if absent. */
|
|
46
|
+
cookie(name: string): string | null;
|
|
47
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/**
|
|
3
|
+
* The response the user's handler builds. Serialised into a wire
|
|
4
|
+
* envelope at a fixed offset before `handle()` returns. See
|
|
5
|
+
* `envelope.ts` and `dispatch.ts`.
|
|
6
|
+
*/
|
|
7
|
+
import { Header } from './request';
|
|
8
|
+
import { Cookie } from './http/cookie';
|
|
9
|
+
/**
|
|
10
|
+
* Marker header on the runtime's fallback 404 (no route matched, no handler
|
|
11
|
+
* wired). The host can use it to fall through to another layer, the dev
|
|
12
|
+
* server hands such requests to Vite (client routes, assets), and strips the
|
|
13
|
+
* marker before anything reaches the browser. A deliberate
|
|
14
|
+
* `Response.notFound()` does not carry it. Mirrored as `UNHANDLED_HEADER` in
|
|
15
|
+
* `src/devserver/module.ts`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const TOIL_UNHANDLED_HEADER: string;
|
|
18
|
+
export declare class Response {
|
|
19
|
+
status: u16;
|
|
20
|
+
headers: Array<Header>;
|
|
21
|
+
body: Uint8Array;
|
|
22
|
+
constructor(status: u16, body: Uint8Array, headers?: Array<Header> | null);
|
|
23
|
+
static text(body: string, status?: u16): Response;
|
|
24
|
+
static html(body: string, status?: u16): Response;
|
|
25
|
+
static json(body: string, status?: u16): Response;
|
|
26
|
+
/** A JSON @data value with an explicit HTTP status. */
|
|
27
|
+
static data<T>(value: T, status?: u16): Response;
|
|
28
|
+
/**
|
|
29
|
+
* A raw binary body, defaulting to `application/octet-stream`. Used by `@route`
|
|
30
|
+
* methods with `stream: DataStream.Binary` to ship a `@data` `encode()`.
|
|
31
|
+
*/
|
|
32
|
+
static bytes(body: Uint8Array, status?: u16, contentType?: string): Response;
|
|
33
|
+
static notFound(): Response;
|
|
34
|
+
/**
|
|
35
|
+
* The "this server has no answer for that path" 404: a `notFound()`
|
|
36
|
+
* carrying {@link TOIL_UNHANDLED_HEADER} so the host may serve the path
|
|
37
|
+
* itself (static files, the client app). Returned by the framework when
|
|
38
|
+
* dispatch misses; handlers that mean "looked it up, does not exist"
|
|
39
|
+
* should return `notFound()` instead.
|
|
40
|
+
*/
|
|
41
|
+
static unhandled(): Response;
|
|
42
|
+
static badRequest(msg?: string): Response;
|
|
43
|
+
static internalError(msg?: string): Response;
|
|
44
|
+
static empty(status: u16): Response;
|
|
45
|
+
/**
|
|
46
|
+
* Replace all headers with this name (case-insensitive). Returns `this`.
|
|
47
|
+
*/
|
|
48
|
+
setHeader(name: string, value: string): Response;
|
|
49
|
+
/**
|
|
50
|
+
* Append a `Set-Cookie` for `cookie`. Each call adds its own header entry,
|
|
51
|
+
* so multiple cookies are emitted as separate `Set-Cookie` headers (never
|
|
52
|
+
* folded). Builder-style: returns `this`.
|
|
53
|
+
*/
|
|
54
|
+
setCookie(cookie: Cookie): Response;
|
|
55
|
+
/** Shorthand for `setCookie(new Cookie(name, value))` (no attributes). */
|
|
56
|
+
setCookieKV(name: string, value: string): Response;
|
|
57
|
+
/**
|
|
58
|
+
* Append a `Set-Cookie` that deletes `name`: empty value, `Max-Age=0`, and
|
|
59
|
+
* an epoch `Expires`. `path` (default `/`) and `domain` must match the
|
|
60
|
+
* cookie being cleared for the browser to drop it. Builder-style.
|
|
61
|
+
*/
|
|
62
|
+
clearCookie(name: string, path?: string, domain?: string): Response;
|
|
63
|
+
/**
|
|
64
|
+
* Mark this response cacheable at the toil edge and/or the browser.
|
|
65
|
+
*
|
|
66
|
+
* `edgeTtlMinutes` caches the response on the edge node (per-core,
|
|
67
|
+
* keyed by host + method + path + request body) for up to that many
|
|
68
|
+
* minutes -- the ONLY way a POST response is cached. `browserTtlSeconds`
|
|
69
|
+
* emits a `Cache-Control: max-age` for the client.
|
|
70
|
+
*
|
|
71
|
+
* Host-side safety, enforced no matter what you ask for: the edge TTL
|
|
72
|
+
* is clamped to 24h, only 2xx responses are edge-cached, a response
|
|
73
|
+
* carrying a `Set-Cookie` is never edge-cached, and an AUTHENTICATED
|
|
74
|
+
* request (one with a `Cookie` or `Authorization` header) is not
|
|
75
|
+
* edge-cached unless you pass `allowAuth = true`. Only mark a response
|
|
76
|
+
* cacheable when its body is a pure function of (host, path, body) --
|
|
77
|
+
* never per-user data keyed by a cookie/header that is not in the path
|
|
78
|
+
* or body, or one user's response could be served to another.
|
|
79
|
+
*
|
|
80
|
+
* Builder-style: returns `this`.
|
|
81
|
+
*/
|
|
82
|
+
cache(edgeTtlMinutes: u16, browserTtlSeconds?: u32, privateScope?: bool, allowAuth?: bool): Response;
|
|
83
|
+
/**
|
|
84
|
+
* Shorthand for {@link cache}: edge-cache this response for `minutes`
|
|
85
|
+
* minutes (no browser caching).
|
|
86
|
+
*/
|
|
87
|
+
cacheFor(minutes: u16): Response;
|
|
88
|
+
}
|
|
89
|
+
/** Fill browser security headers at the HTTP serialization boundary. */
|
|
90
|
+
export declare function ensureSecurityHeaders(response: Response): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Generated from server/runtime by scripts/gen-server-types.mjs.
|
|
2
|
+
/**
|
|
3
|
+
* The auto-populated REST router. Every `@rest` controller self-registers a
|
|
4
|
+
* dispatcher here at module init (compiler-injected); your handler calls
|
|
5
|
+
* `Rest.dispatch(req)` to try them all. The first controller that matches the
|
|
6
|
+
* method + path wins; `null` means no route matched (fall through to your own
|
|
7
|
+
* logic / static files / 404).
|
|
8
|
+
*/
|
|
9
|
+
import { Request } from '../request';
|
|
10
|
+
import { Response } from '../response';
|
|
11
|
+
/** A controller dispatcher: returns a Response on a route hit, null on a miss. */
|
|
12
|
+
export type RouteFn = (req: Request) => Response | null;
|
|
13
|
+
export declare class RestRegistry {
|
|
14
|
+
private fns;
|
|
15
|
+
/** Compiler-injected: registers a controller's dispatcher. Not for direct use. */
|
|
16
|
+
register(fn: RouteFn): void;
|
|
17
|
+
/** Try every registered controller in registration order; first match wins. */
|
|
18
|
+
dispatch(req: Request): Response | null;
|
|
19
|
+
/** Number of registered controllers (diagnostics / tests). */
|
|
20
|
+
get size(): i32;
|
|
21
|
+
}
|
|
22
|
+
/** The process-wide REST router singleton. */
|
|
23
|
+
export declare const Rest: RestRegistry;
|