toiljs 0.0.116 → 0.0.118
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 +14 -0
- package/README.md +16 -7
- package/build/backend/.tsbuildinfo +1 -1
- package/build/cli/.tsbuildinfo +1 -1
- package/build/cli/index.js +2375 -258
- package/build/client/.tsbuildinfo +1 -1
- package/build/client/auth.d.ts +3 -0
- package/build/client/auth.js +19 -10
- package/build/client/dev/devtools.js +1 -1
- package/build/client/dev/error-overlay.js +1 -1
- package/build/client/index.d.ts +1 -1
- package/build/client/index.js +1 -1
- package/build/client/navigation/navigation.js +28 -3
- package/build/client/routing/Router.js +5 -2
- package/build/client/routing/mount.js +1 -1
- package/build/compiler/.tsbuildinfo +1 -1
- package/build/compiler/auth-emails.js +7 -3
- package/build/compiler/emails.js +1 -1
- package/build/compiler/index.d.ts +1 -0
- package/build/compiler/index.js +26 -5
- package/build/compiler/pages.js +2 -3
- package/build/compiler/prerender.d.ts +3 -8
- package/build/compiler/prerender.js +88 -127
- package/build/compiler/ssg.js +3 -4
- package/build/compiler/template-build.js +3 -4
- package/build/compiler/toil-docs.generated.js +8 -7
- package/build/compiler/vite.js +4 -6
- package/build/devserver/.tsbuildinfo +1 -1
- package/build/devserver/db/database.js +7 -3
- package/build/devserver/db/types.js +1 -1
- package/build/devserver/production.js +4 -3
- package/build/devserver/runtime/crypto.d.ts +1 -1
- package/build/io/.tsbuildinfo +1 -1
- package/build/logger/.tsbuildinfo +1 -1
- package/build/shared/.tsbuildinfo +1 -1
- package/examples/basic/client/routes/analytics.tsx +7 -5
- package/examples/basic/client/routes/pq.tsx +2 -1
- package/examples/basic/server/tsconfig.json +1 -3
- package/package.json +45 -44
- package/presets/no-uint8array-tostring.js +120 -153
- package/presets/oxlint.d.ts +5 -0
- package/presets/oxlint.js +224 -0
- package/server/auth/AuthController.ts +53 -14
- package/server/auth/FactorSettings.ts +41 -0
- package/server/auth/SessionEpochs.ts +58 -0
- package/server/auth/SessionRevocations.ts +13 -0
- package/server/globals/auth.ts +27 -2
- package/server/runtime/tsconfig.json +1 -3
- package/tsconfig.json +2 -11
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
- package/.github/ISSUE_TEMPLATE/config.yml +0 -8
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -43
- package/.github/changelog-config.json +0 -45
- package/.github/dependabot.yml +0 -27
- package/.github/workflows/ci.yml +0 -222
- package/.vscode/settings.json +0 -10
- package/docs/README.md +0 -107
- package/docs/auth/README.md +0 -104
- package/docs/auth/configuration.md +0 -105
- package/docs/auth/emails.md +0 -92
- package/docs/auth/extending.md +0 -202
- package/docs/auth/how-it-works.md +0 -138
- package/docs/auth/usage.md +0 -188
- package/docs/backend/README.md +0 -143
- package/docs/backend/data.md +0 -351
- package/docs/backend/rest.md +0 -402
- package/docs/backend/rpc.md +0 -226
- package/docs/background/README.md +0 -114
- package/docs/background/daemons.md +0 -276
- package/docs/background/derive.md +0 -179
- package/docs/cli/README.md +0 -379
- package/docs/concepts/ai-guide.md +0 -132
- package/docs/concepts/config.md +0 -416
- package/docs/concepts/decorators.md +0 -127
- package/docs/concepts/security.md +0 -108
- package/docs/concepts/tiers.md +0 -166
- package/docs/concepts/types.md +0 -216
- package/docs/database/README.md +0 -143
- package/docs/database/capacity.md +0 -350
- package/docs/database/counters.md +0 -174
- package/docs/database/documents.md +0 -277
- package/docs/database/events.md +0 -307
- package/docs/database/membership.md +0 -246
- package/docs/database/setup.md +0 -155
- package/docs/database/unique.md +0 -216
- package/docs/database/views.md +0 -246
- package/docs/frontend/README.md +0 -104
- package/docs/frontend/components.md +0 -286
- package/docs/frontend/data-fetching.md +0 -260
- package/docs/frontend/images.md +0 -148
- package/docs/frontend/metadata.md +0 -344
- package/docs/frontend/navigation.md +0 -296
- package/docs/frontend/rendering.md +0 -236
- package/docs/frontend/routing.md +0 -346
- package/docs/frontend/scripts.md +0 -118
- package/docs/frontend/search.md +0 -191
- package/docs/frontend/styling.md +0 -147
- package/docs/frontend/toil-global.md +0 -216
- package/docs/getting-started/README.md +0 -81
- package/docs/getting-started/create-project.md +0 -131
- package/docs/getting-started/deploy.md +0 -101
- package/docs/getting-started/first-app.md +0 -215
- package/docs/getting-started/installation.md +0 -124
- package/docs/getting-started/migrating.md +0 -125
- package/docs/getting-started/project-structure.md +0 -163
- package/docs/introduction/README.md +0 -66
- package/docs/introduction/design-principles.md +0 -81
- package/docs/introduction/distributed.md +0 -91
- package/docs/introduction/how-it-works.md +0 -121
- package/docs/introduction/hyperscale.md +0 -70
- package/docs/introduction/modern-stack.md +0 -85
- package/docs/introduction/vs-other-frameworks.md +0 -64
- package/docs/introduction/why-toil.md +0 -99
- package/docs/llms.txt +0 -95
- package/docs/realtime/README.md +0 -102
- package/docs/realtime/channels.md +0 -211
- package/docs/realtime/streams.md +0 -369
- package/docs/services/README.md +0 -60
- package/docs/services/analytics.md +0 -279
- package/docs/services/caching.md +0 -175
- package/docs/services/cookies.md +0 -235
- package/docs/services/crypto.md +0 -209
- package/docs/services/email.md +0 -289
- package/docs/services/environment.md +0 -141
- package/docs/services/ratelimit.md +0 -174
- package/docs/services/time.md +0 -85
- package/eslint.config.js +0 -57
- package/examples/basic/client/routes/docs/[...slug].tsx +0 -12
- package/presets/eslint.js +0 -88
- package/src/backend/index.ts +0 -204
- package/src/cli/configure.ts +0 -363
- package/src/cli/create.ts +0 -924
- package/src/cli/db.ts +0 -158
- package/src/cli/diagnostics.ts +0 -665
- package/src/cli/doctor.ts +0 -982
- package/src/cli/features.ts +0 -170
- package/src/cli/index.ts +0 -326
- package/src/cli/notify.ts +0 -120
- package/src/cli/proc.ts +0 -56
- package/src/cli/ui.ts +0 -169
- package/src/cli/update.ts +0 -248
- package/src/cli/updates.ts +0 -92
- package/src/cli/validate.ts +0 -31
- package/src/cli/version-check.ts +0 -125
- package/src/client/auth.ts +0 -869
- package/src/client/channel/channel.ts +0 -146
- package/src/client/components/Form.tsx +0 -65
- package/src/client/components/Image.tsx +0 -160
- package/src/client/components/Script.tsx +0 -113
- package/src/client/components/Slot.tsx +0 -21
- package/src/client/dev/devtools.tsx +0 -1089
- package/src/client/dev/error-overlay.tsx +0 -225
- package/src/client/errors.ts +0 -11
- package/src/client/head/head.ts +0 -182
- package/src/client/head/metadata.ts +0 -110
- package/src/client/index.ts +0 -130
- package/src/client/navigation/Link.tsx +0 -108
- package/src/client/navigation/NavLink.tsx +0 -86
- package/src/client/navigation/navigation.ts +0 -235
- package/src/client/navigation/prefetch.ts +0 -169
- package/src/client/navigation/scroll.ts +0 -53
- package/src/client/routing/Router.tsx +0 -216
- package/src/client/routing/action.ts +0 -122
- package/src/client/routing/error-boundary.tsx +0 -43
- package/src/client/routing/hooks.ts +0 -140
- package/src/client/routing/lazy.ts +0 -77
- package/src/client/routing/loader.ts +0 -381
- package/src/client/routing/match.ts +0 -47
- package/src/client/routing/mount.tsx +0 -90
- package/src/client/routing/params-context.ts +0 -10
- package/src/client/routing/slot-context.ts +0 -7
- package/src/client/rpc.ts +0 -97
- package/src/client/search/search.ts +0 -189
- package/src/client/search/use-page-search.ts +0 -73
- package/src/client/ssr/markers.tsx +0 -172
- package/src/client/stream/client.ts +0 -237
- package/src/client/types.ts +0 -73
- package/src/compiler/auth-emails.ts +0 -312
- package/src/compiler/config.ts +0 -369
- package/src/compiler/docs.ts +0 -127
- package/src/compiler/email-preview.ts +0 -314
- package/src/compiler/emails.ts +0 -404
- package/src/compiler/fonts.ts +0 -89
- package/src/compiler/generate.ts +0 -471
- package/src/compiler/image-blur.ts +0 -42
- package/src/compiler/image-report.ts +0 -88
- package/src/compiler/index.ts +0 -1362
- package/src/compiler/pages.ts +0 -49
- package/src/compiler/plugin.ts +0 -391
- package/src/compiler/prerender.ts +0 -263
- package/src/compiler/routes.ts +0 -170
- package/src/compiler/seo.ts +0 -415
- package/src/compiler/sri.ts +0 -144
- package/src/compiler/ssg.ts +0 -177
- package/src/compiler/ssr-codegen.ts +0 -85
- package/src/compiler/template-build.ts +0 -676
- package/src/compiler/template.ts +0 -262
- package/src/compiler/toil-docs.generated.ts +0 -77
- package/src/compiler/vite.ts +0 -245
- package/src/devserver/analytics/index.ts +0 -317
- package/src/devserver/config/dotenv.ts +0 -102
- package/src/devserver/config/env.ts +0 -30
- package/src/devserver/config/ratelimit.ts +0 -123
- package/src/devserver/daemon/catalog.ts +0 -120
- package/src/devserver/daemon/cron.ts +0 -87
- package/src/devserver/daemon/host.ts +0 -134
- package/src/devserver/daemon/index.ts +0 -369
- package/src/devserver/daemon/runtime.ts +0 -48
- package/src/devserver/db/catalog.ts +0 -109
- package/src/devserver/db/database.ts +0 -1834
- package/src/devserver/db/derives.ts +0 -121
- package/src/devserver/db/index.ts +0 -20
- package/src/devserver/db/routeKinds.ts +0 -191
- package/src/devserver/db/types.ts +0 -168
- package/src/devserver/email/caps.ts +0 -0
- package/src/devserver/email/config.ts +0 -141
- package/src/devserver/email/console.ts +0 -348
- package/src/devserver/email/index.ts +0 -155
- package/src/devserver/email/providers.ts +0 -131
- package/src/devserver/email/status.ts +0 -23
- package/src/devserver/email/validate.ts +0 -37
- package/src/devserver/email/wire.ts +0 -55
- package/src/devserver/http/cache.ts +0 -0
- package/src/devserver/http/envelope.ts +0 -157
- package/src/devserver/http/proxy.ts +0 -172
- package/src/devserver/http/runtime.ts +0 -387
- package/src/devserver/index.ts +0 -43
- package/src/devserver/production-ipc.ts +0 -63
- package/src/devserver/production-worker.ts +0 -83
- package/src/devserver/production.ts +0 -718
- package/src/devserver/runtime/crypto.ts +0 -587
- package/src/devserver/runtime/host.ts +0 -427
- package/src/devserver/runtime/module.ts +0 -442
- package/src/devserver/server.ts +0 -251
- package/src/devserver/ssr.ts +0 -208
- package/src/devserver/stream/catalog.ts +0 -106
- package/src/devserver/stream/host.ts +0 -42
- package/src/devserver/stream/index.ts +0 -301
- package/src/devserver/stream/manager.ts +0 -167
- package/src/devserver/stream/router.ts +0 -101
- package/src/devserver/stream/wire.ts +0 -58
- package/src/devserver/stream/ws.ts +0 -78
- package/src/devserver/wasm/sections.ts +0 -59
- package/src/devserver/wasm/surface.ts +0 -115
- package/src/io/FastMap.ts +0 -151
- package/src/io/FastSet.ts +0 -113
- package/src/io/codec.ts +0 -362
- package/src/io/index.ts +0 -10
- package/src/io/lengths.ts +0 -14
- package/src/io/types.ts +0 -19
- package/src/logger/index.ts +0 -22
- package/src/shared/index.ts +0 -46
- package/test/analytics-dev.test.ts +0 -113
- package/test/assembly/aspect-shim.ts +0 -33
- package/test/assembly/cookie.spec.ts +0 -303
- package/test/assembly/example.spec.ts +0 -22
- package/test/assembly/ssr.spec.ts +0 -95
- package/test/assembly.test.ts +0 -59
- package/test/auth-emails.test.ts +0 -118
- package/test/built-ssr.test.ts +0 -148
- package/test/channel.test.ts +0 -21
- package/test/config-host-port.test.ts +0 -59
- package/test/configure.test.ts +0 -94
- package/test/daemon-build.test.ts +0 -278
- package/test/daemon-catalog.test.ts +0 -349
- package/test/daemon-emulation.test.ts +0 -256
- package/test/db.test.ts +0 -0
- package/test/devserver-database.test.ts +0 -1102
- package/test/devserver-email.test.ts +0 -306
- package/test/devserver-pqauth.test.ts +0 -93
- package/test/devserver-secrets.test.ts +0 -63
- package/test/devserver.test.ts +0 -259
- package/test/doctor.test.ts +0 -298
- package/test/dom/Image.test.tsx +0 -144
- package/test/dom/Link.test.tsx +0 -67
- package/test/dom/NavLink.test.tsx +0 -37
- package/test/dom/Script.test.tsx +0 -48
- package/test/dom/action.test.tsx +0 -146
- package/test/dom/error-overlay.test.tsx +0 -44
- package/test/dom/loader.test.tsx +0 -121
- package/test/dom/navigation.test.ts +0 -59
- package/test/dom/revalidate.test.tsx +0 -38
- package/test/dom/route-head.test.tsx +0 -56
- package/test/dom/router-loading.test.tsx +0 -44
- package/test/dom/scroll.test.ts +0 -56
- package/test/dom/slot.test.tsx +0 -131
- package/test/dom/use-metadata.test.tsx +0 -58
- package/test/dom/view-transitions.test.tsx +0 -53
- package/test/dynamic-routing.test.ts +0 -132
- package/test/email-console.test.ts +0 -86
- package/test/email-preview.test.ts +0 -73
- package/test/emails.test.ts +0 -58
- package/test/errors.test.ts +0 -21
- package/test/example-guestbook.test.ts +0 -123
- package/test/features.test.ts +0 -149
- package/test/fixtures/bignum-wire/spec.ts +0 -25
- package/test/fixtures/daemon-app.ts +0 -65
- package/test/fixtures/stream-echo.ts +0 -26
- package/test/fixtures/stream-gate.ts +0 -28
- package/test/fixtures/stream-trap.ts +0 -18
- package/test/fixtures/stream-typed.ts +0 -41
- package/test/fonts.test.ts +0 -28
- package/test/global-setup.ts +0 -17
- package/test/head.test.ts +0 -42
- package/test/image-blur.test.ts +0 -50
- package/test/io.test.ts +0 -117
- package/test/metadata.test.ts +0 -40
- package/test/navlink.test.ts +0 -28
- package/test/pages.test.ts +0 -105
- package/test/placeholder.test.ts +0 -9
- package/test/pqauth-e2e.test.ts +0 -216
- package/test/pqauth-email.test.ts +0 -801
- package/test/prerender.test.ts +0 -116
- package/test/prettier-plugin.test.ts +0 -46
- package/test/routes.test.ts +0 -76
- package/test/rpc-bignum-wire.test.ts +0 -164
- package/test/rpc-dispatch.test.ts +0 -132
- package/test/rpc-kinds.test.ts +0 -18
- package/test/rpc.test.ts +0 -66
- package/test/search.test.ts +0 -114
- package/test/seo.test.ts +0 -175
- package/test/slot-layouts.test.ts +0 -69
- package/test/sri.test.ts +0 -129
- package/test/ssg.test.ts +0 -36
- package/test/ssr-hydration.test.tsx +0 -122
- package/test/ssr-render.test.ts +0 -197
- package/test/ssr-template.test.tsx +0 -482
- package/test/stream-emulation.test.ts +0 -479
- package/test/ui.test.ts +0 -40
- package/test/update.test.ts +0 -58
- package/test/validate.test.ts +0 -42
- package/test/version-check.test.ts +0 -130
- package/tests/data-parity/generated-parity.ts +0 -99
- package/tests/data-parity/parity.ts +0 -80
- package/tests/data-parity/spec.ts +0 -46
package/src/shared/index.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared primitives used across every toiljs target (client, compiler, cli, server tooling).
|
|
3
|
-
* Placeholder, real shared types/utilities land here.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export const FRAMEWORK_NAME = 'toiljs';
|
|
7
|
-
|
|
8
|
-
export interface ToilTarget {
|
|
9
|
-
readonly name: 'client' | 'compiler' | 'cli' | 'server';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** SMTP connection config (non-secret) for the `smtp` / `gmail` providers. */
|
|
13
|
-
export interface SmtpBackendConfig {
|
|
14
|
-
/** SMTP host. Empty + provider `gmail` defaults to `smtp.gmail.com`. */
|
|
15
|
-
readonly host?: string;
|
|
16
|
-
/** Submission port. `0`/unset defaults to 587 (STARTTLS); 465 = implicit TLS. */
|
|
17
|
-
readonly port?: number;
|
|
18
|
-
/** SMTP username. Defaults to `from`. */
|
|
19
|
-
readonly user?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The **non-secret** email backend config — the typed `email` section of
|
|
24
|
-
* `toil.config.ts` (`server.email`), consumed by the dev server and the future
|
|
25
|
-
* Node self-host. The provider API key / SMTP password is a SECRET and is NEVER
|
|
26
|
-
* here: it comes from `.env.secrets` (`TOIL_EMAIL_API_KEY`). Any `TOIL_EMAIL_*`
|
|
27
|
-
* env var overrides the matching field here.
|
|
28
|
-
*
|
|
29
|
-
* Mirrors the edge's `TOIL_EMAIL_*` keys (toil-backend `host/email.rs`
|
|
30
|
-
* `EmailSection`). Lives in `toiljs/shared` so both the compiler (config schema)
|
|
31
|
-
* and the dev server (resolver) can reference it regardless of build order.
|
|
32
|
-
*/
|
|
33
|
-
export interface EmailBackendConfig {
|
|
34
|
-
/** `"resend"` (JSON API) | `"gmail"` | `"smtp"` (SMTP). Default `"resend"`. */
|
|
35
|
-
readonly provider?: 'resend' | 'gmail' | 'smtp';
|
|
36
|
-
/** The "from" address. Validated (single address, no CRLF). */
|
|
37
|
-
readonly from?: string;
|
|
38
|
-
/** Per-process send ceiling, sends/minute (rolling). `0` = unlimited. Default 60. */
|
|
39
|
-
readonly maxPerMin?: number;
|
|
40
|
-
/** Per-process send ceiling, sends/day (rolling). `0` = unlimited. Default 0. */
|
|
41
|
-
readonly maxPerDay?: number;
|
|
42
|
-
/** Per-recipient hourly cap (anti-abuse). Default 5. */
|
|
43
|
-
readonly maxPerRecipientPerHour?: number;
|
|
44
|
-
/** SMTP connection details (the `gmail` / `smtp` providers). */
|
|
45
|
-
readonly smtp?: SmtpBackendConfig;
|
|
46
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dev-server analytics stub parity: the `env.analytics_read` / `env.analytics_series` dev imports must
|
|
3
|
-
* encode the v3 frames BYTE-FOR-BYTE like the edge (`analytics.rs`), so a guest's toilscript `Analytics`
|
|
4
|
-
* decode is identical in dev and prod. We decode the stashed frame positionally, exactly as the guest.
|
|
5
|
-
*/
|
|
6
|
-
import { describe, expect, it } from 'vitest';
|
|
7
|
-
|
|
8
|
-
import { buildAnalyticsImports } from '../src/devserver/analytics/index.js';
|
|
9
|
-
|
|
10
|
-
// Minimal fakes: domainLen 0 needs no memory; the stub stashes the frame into db.lastResult.
|
|
11
|
-
function harness() {
|
|
12
|
-
const ref = { memory: null } as unknown as Parameters<typeof buildAnalyticsImports>[0];
|
|
13
|
-
const db = { lastResult: null as Buffer | null, lastResultVersion: 0 } as unknown as Parameters<
|
|
14
|
-
typeof buildAnalyticsImports
|
|
15
|
-
>[1];
|
|
16
|
-
return { imports: buildAnalyticsImports(ref, db), db };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
describe('dev analytics stub v3 frame parity', () => {
|
|
20
|
-
it('analytics_read encodes the fixed-layout snapshot frame', () => {
|
|
21
|
-
const { imports, db } = harness();
|
|
22
|
-
const n = imports.analytics_read(0, 0);
|
|
23
|
-
const buf = db.lastResult as unknown as Buffer;
|
|
24
|
-
expect(n).toBe(buf.length);
|
|
25
|
-
|
|
26
|
-
let p = 0;
|
|
27
|
-
const u16 = () => { const v = buf.readUInt16LE(p); p += 2; return v; };
|
|
28
|
-
const u32 = () => { const v = buf.readUInt32LE(p); p += 4; return v; };
|
|
29
|
-
const u64 = () => { const v = buf.readBigUInt64LE(p); p += 8; return v; };
|
|
30
|
-
const f64 = () => { const v = buf.readDoubleLE(p); p += 8; return v; };
|
|
31
|
-
|
|
32
|
-
expect(u16()).toBe(3); // FRAME_VERSION
|
|
33
|
-
u64(); // now_ms
|
|
34
|
-
const count = u32();
|
|
35
|
-
expect(count).toBe(42); // METRIC_COUNTERS (edge N_COUNTERS; no WasmDispatches)
|
|
36
|
-
const life: bigint[] = [];
|
|
37
|
-
for (let i = 0; i < count; i++) life.push(u64()); // counters are u64 LE now
|
|
38
|
-
// Indices are the AUTHORITATIVE edge MetricId ids (metric_id.rs): a mislabel here means the dev
|
|
39
|
-
// dashboard shows the wrong metric for every id past StaticHits.
|
|
40
|
-
expect(life[0]).toBe(42n); // Requests (id 0)
|
|
41
|
-
expect(life[1]).toBe(12345n); // BytesOutL1 (id 1)
|
|
42
|
-
expect(life[11]).toBe(1_000_000n); // GasUsed (id 11, was 12 in the stale layout)
|
|
43
|
-
expect(life[40]).toBe(900n); // CacheHits (id 40, was 41)
|
|
44
|
-
expect(life[41]).toBe(100n); // CacheMisses (id 41, was 42)
|
|
45
|
-
expect(u64()).toBe(3n); // connectedStreams
|
|
46
|
-
expect(u64()).toBe(65536n); // committedMemory
|
|
47
|
-
expect(u64()).toBe(1_200n); // reqBurstUsed (current 3-min tumbling bucket)
|
|
48
|
-
expect(u64()).toBe(180_000n); // reqBurstCap (sustained 1000 rps * 180s window)
|
|
49
|
-
expect(u64()).toBe(250_000n); // req30dUsed (current 30-day bucket)
|
|
50
|
-
expect(u64()).toBe(10_000_000n); // req30dCap (30-day quota)
|
|
51
|
-
// 7 LIVE per-second rates (f64 LE), appended after the windows.
|
|
52
|
-
expect(f64()).toBeCloseTo(0.7); // rps
|
|
53
|
-
expect(f64()).toBeCloseTo(68.2); // bytesInPerSec
|
|
54
|
-
expect(f64()).toBeCloseTo(205.75); // bytesOutPerSec
|
|
55
|
-
expect(f64()).toBeCloseTo(34.1); // streamBytesInPerSec
|
|
56
|
-
expect(f64()).toBeCloseTo(136.5); // streamBytesOutPerSec
|
|
57
|
-
expect(f64()).toBeCloseTo(0.28); // dbOpsPerSec
|
|
58
|
-
expect(f64()).toBeCloseTo(16_666.67); // gasPerSec
|
|
59
|
-
expect(p).toBe(buf.length); // no trailing bytes
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('analytics_series encodes the series frame with the right shape per range', () => {
|
|
63
|
-
const { imports, db } = harness();
|
|
64
|
-
// metric 0 (Requests), range 3 (H24) -> hour ring, 24 buckets, bucketSecs 3600.
|
|
65
|
-
const n = imports.analytics_series(0, 0, 0, 3);
|
|
66
|
-
const buf = db.lastResult as unknown as Buffer;
|
|
67
|
-
expect(n).toBe(buf.length);
|
|
68
|
-
let p = 0;
|
|
69
|
-
expect(buf.readUInt16LE(p)).toBe(3); p += 2; // version
|
|
70
|
-
expect(buf.readUInt16LE(p)).toBe(0); p += 2; // metric id
|
|
71
|
-
expect(buf.readUInt32LE(p)).toBe(3600); p += 4; // bucketSecs
|
|
72
|
-
p += 8; // headMs
|
|
73
|
-
const count = buf.readUInt32LE(p); p += 4;
|
|
74
|
-
expect(count).toBe(24);
|
|
75
|
-
expect(buf.length).toBe(p + count * 8);
|
|
76
|
-
|
|
77
|
-
// range 0 (1h) -> minute ring: 60 buckets, bucketSecs 60.
|
|
78
|
-
imports.analytics_series(0, 0, 0, 0);
|
|
79
|
-
const b2 = db.lastResult as unknown as Buffer;
|
|
80
|
-
expect(b2.readUInt32LE(4)).toBe(60); // bucketSecs
|
|
81
|
-
expect(b2.readUInt32LE(16)).toBe(60); // count
|
|
82
|
-
|
|
83
|
-
// F1 guard: a minute-ring metric OTHER than Requests must ALSO get minute resolution on 1h.
|
|
84
|
-
// GasUsed(11) is in the edge minute ring; a stale dev set fell back to the hour ring here.
|
|
85
|
-
imports.analytics_series(0, 0, 11, 0); // GasUsed, 1h
|
|
86
|
-
const bGas = db.lastResult as unknown as Buffer;
|
|
87
|
-
expect(bGas.readUInt32LE(4)).toBe(60); // minute bucketSecs (was wrongly 3600 pre-fix)
|
|
88
|
-
expect(bGas.readUInt32LE(16)).toBe(60); // 60 minute buckets (was wrongly 1)
|
|
89
|
-
// A metric NOT in the minute ring (Status2xx=3) falls back to the hour ring on 1h.
|
|
90
|
-
imports.analytics_series(0, 0, 3, 0);
|
|
91
|
-
const bStat = db.lastResult as unknown as Buffer;
|
|
92
|
-
expect(bStat.readUInt32LE(4)).toBe(3600); // hour bucketSecs
|
|
93
|
-
expect(bStat.readUInt32LE(16)).toBe(1); // 1 hour bucket
|
|
94
|
-
|
|
95
|
-
// range 8 (D60) + 9 (D90) -> DAY ring: 60/90 buckets, bucketSecs 86400.
|
|
96
|
-
imports.analytics_series(0, 0, 0, 8);
|
|
97
|
-
const b60 = db.lastResult as unknown as Buffer;
|
|
98
|
-
expect(b60.readUInt32LE(4)).toBe(86_400); // bucketSecs
|
|
99
|
-
expect(b60.readUInt32LE(16)).toBe(60); // count
|
|
100
|
-
imports.analytics_series(0, 0, 0, 9);
|
|
101
|
-
const b90 = db.lastResult as unknown as Buffer;
|
|
102
|
-
expect(b90.readUInt32LE(4)).toBe(86_400); // bucketSecs
|
|
103
|
-
expect(b90.readUInt32LE(16)).toBe(90); // count
|
|
104
|
-
|
|
105
|
-
// A bad metric / range -> ABSENT (negative), no frame. Range 10 is past D90.
|
|
106
|
-
expect(imports.analytics_series(0, 0, 999, 3)).toBeLessThan(0);
|
|
107
|
-
expect(imports.analytics_series(0, 0, 0, 99)).toBeLessThan(0);
|
|
108
|
-
expect(imports.analytics_series(0, 0, 0, 10)).toBeLessThan(0);
|
|
109
|
-
// F2: valid ids are 0..=45 (gauges 42..=45); 46 is past the end and must be rejected like the edge.
|
|
110
|
-
expect(imports.analytics_series(0, 0, 46, 3)).toBeLessThan(0);
|
|
111
|
-
expect(imports.analytics_series(0, 0, 45, 3)).toBeGreaterThan(0); // gauge id 45 is valid
|
|
112
|
-
});
|
|
113
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// A minimal in-AssemblyScript test shim for this directory's assembly specs.
|
|
2
|
-
// `describe`/`it` run their bodies inline; `expect(x).toBe(y)` / `.toStrictEqual(y)` assert
|
|
3
|
-
// `x == y` (value-equality, which covers the bool / i32 / string the specs compare). A failed
|
|
4
|
-
// assertion aborts with the current test name; the vitest runner (../assembly.test.ts) compiles
|
|
5
|
-
// each spec with toilscript, runs `_start`, and surfaces the abort as a test failure.
|
|
6
|
-
|
|
7
|
-
let currentTest: string = '';
|
|
8
|
-
|
|
9
|
-
export function describe(_name: string, fn: () => void): void {
|
|
10
|
-
fn();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function it(name: string, fn: () => void): void {
|
|
14
|
-
currentTest = name;
|
|
15
|
-
fn();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class Expectation<T> {
|
|
19
|
-
private actual: T;
|
|
20
|
-
constructor(actual: T) {
|
|
21
|
-
this.actual = actual;
|
|
22
|
-
}
|
|
23
|
-
toBe(expected: T): void {
|
|
24
|
-
assert(this.actual == expected, currentTest);
|
|
25
|
-
}
|
|
26
|
-
toStrictEqual(expected: T): void {
|
|
27
|
-
assert(this.actual == expected, currentTest);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function expect<T>(actual: T): Expectation<T> {
|
|
32
|
-
return new Expectation<T>(actual);
|
|
33
|
-
}
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
// Pure cookie logic (builder, parser, codec, validation, Request/Response
|
|
2
|
-
// integration). Imports the specific modules rather than the runtime index so
|
|
3
|
-
// `securecookies.ts` is not pulled into the as-pect graph: it depends on the
|
|
4
|
-
// toilscript crypto std (`crypto` / `data` / `bindings/webcrypto`), which the
|
|
5
|
-
// as-pect compiler does not ship. `SecureCookies`
|
|
6
|
-
// is exercised end-to-end against the real toilscript-compiled wasm in
|
|
7
|
-
// `test/devserver.test.ts`.
|
|
8
|
-
import { describe, it, expect } from './aspect-shim';
|
|
9
|
-
import { Method, Request, Header } from '../../server/runtime/request';
|
|
10
|
-
import { Response } from '../../server/runtime/response';
|
|
11
|
-
import { Cookie, SameSite, CookieEncoding } from '../../server/runtime/http/cookie';
|
|
12
|
-
import { Cookies } from '../../server/runtime/http/cookies';
|
|
13
|
-
|
|
14
|
-
// --- helpers ----------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
function headerValue(r: Response, name: string): string {
|
|
17
|
-
for (let i = 0; i < r.headers.length; i++) {
|
|
18
|
-
if (r.headers[i].name == name) return r.headers[i].value;
|
|
19
|
-
}
|
|
20
|
-
return '';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function headerCount(r: Response, name: string): i32 {
|
|
24
|
-
let n = 0;
|
|
25
|
-
for (let i = 0; i < r.headers.length; i++) {
|
|
26
|
-
if (r.headers[i].name == name) n++;
|
|
27
|
-
}
|
|
28
|
-
return n;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function reqWithCookie(value: string): Request {
|
|
32
|
-
const headers = new Array<Header>();
|
|
33
|
-
headers.push(new Header('Cookie', value));
|
|
34
|
-
return new Request(Method.GET, '/', headers, new Uint8Array(0));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// --- Cookie builder / serialize --------------------------------------------
|
|
38
|
-
|
|
39
|
-
describe('Cookie.serialize', () => {
|
|
40
|
-
it('serializes a bare name=value', () => {
|
|
41
|
-
expect<string>(Cookie.create('a', 'b').serialize()).toStrictEqual('a=b');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('percent-encodes the value by default', () => {
|
|
45
|
-
expect<string>(Cookie.create('x', 'hello world').serialize()).toStrictEqual('x=hello%20world');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('leaves a Raw value untouched', () => {
|
|
49
|
-
expect<string>(
|
|
50
|
-
Cookie.create('x', 'abc').withEncoding(CookieEncoding.Raw).serialize(),
|
|
51
|
-
).toStrictEqual('x=abc');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('base64url-encodes when asked', () => {
|
|
55
|
-
expect<string>(
|
|
56
|
-
Cookie.create('x', 'hi').withEncoding(CookieEncoding.Base64Url).serialize(),
|
|
57
|
-
).toStrictEqual('x=aGk');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('emits attributes in a stable order', () => {
|
|
61
|
-
const s = Cookie.create('a', 'b')
|
|
62
|
-
.domain('example.com')
|
|
63
|
-
.path('/p')
|
|
64
|
-
.secure()
|
|
65
|
-
.httpOnly()
|
|
66
|
-
.sameSite(SameSite.Lax)
|
|
67
|
-
.maxAge(60)
|
|
68
|
-
.serialize();
|
|
69
|
-
expect<string>(s).toStrictEqual('a=b; Domain=example.com; Path=/p; Max-Age=60; SameSite=Lax; Secure; HttpOnly');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('auto-adds Secure for SameSite=None', () => {
|
|
73
|
-
expect<string>(Cookie.create('a', 'b').sameSite(SameSite.None).serialize()).toStrictEqual(
|
|
74
|
-
'a=b; SameSite=None; Secure',
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('auto-adds Secure for Partitioned (CHIPS)', () => {
|
|
79
|
-
expect<string>(Cookie.create('a', 'b').partitioned().serialize()).toStrictEqual(
|
|
80
|
-
'a=b; Secure; Partitioned',
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('formats Expires from epoch seconds as an IMF-fixdate', () => {
|
|
85
|
-
expect<string>(Cookie.create('a', 'b').expires(784111777).serialize()).toStrictEqual(
|
|
86
|
-
'a=b; Expires=Sun, 06 Nov 1994 08:49:37 GMT',
|
|
87
|
-
);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('formats the epoch as the IMF-fixdate zero point', () => {
|
|
91
|
-
expect<string>(Cookie.create('a', 'b').expires(0).serialize()).toStrictEqual(
|
|
92
|
-
'a=b; Expires=Thu, 01 Jan 1970 00:00:00 GMT',
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('clamps Max-Age to the 400-day cap', () => {
|
|
97
|
-
expect<string>(Cookie.create('a', 'b').maxAge(99999999).serialize()).toStrictEqual(
|
|
98
|
-
'a=b; Max-Age=34560000',
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('applies the __Host- prefix with its required attributes', () => {
|
|
103
|
-
expect<string>(Cookie.create('sid', 'x').asHostPrefixed().serialize()).toStrictEqual(
|
|
104
|
-
'__Host-sid=x; Path=/; Secure',
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('applies the __Secure- prefix', () => {
|
|
109
|
-
expect<string>(Cookie.create('sid', 'x').asSecurePrefixed().serialize()).toStrictEqual(
|
|
110
|
-
'__Secure-sid=x; Secure',
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('emits Priority and extension attributes', () => {
|
|
115
|
-
expect<string>(
|
|
116
|
-
Cookie.create('a', 'b').priority('High').extension('CustomFlag').serialize(),
|
|
117
|
-
).toStrictEqual('a=b; Priority=High; CustomFlag');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('percent-encodes CR/LF in a default-encoded value (no header injection)', () => {
|
|
121
|
-
expect<string>(Cookie.create('a', 'b\r\nc').serialize()).toStrictEqual('a=b%0D%0Ac');
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('strips control characters from a raw value', () => {
|
|
125
|
-
expect<string>(
|
|
126
|
-
Cookie.create('a', 'b\r\nInjected').withEncoding(CookieEncoding.Raw).serialize(),
|
|
127
|
-
).toStrictEqual('a=bInjected');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('strips control characters from the name', () => {
|
|
131
|
-
expect<string>(new Cookie('a\r\nb', 'v').serialize()).toStrictEqual('ab=v');
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('strips semicolons from a raw value (no attribute injection)', () => {
|
|
135
|
-
expect<string>(
|
|
136
|
-
Cookie.create('a', 'b; Secure').withEncoding(CookieEncoding.Raw).serialize(),
|
|
137
|
-
).toStrictEqual('a=b Secure');
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('reduces the name to token chars (no attribute injection)', () => {
|
|
141
|
-
expect<string>(new Cookie('a;Domain=evil', 'v').serialize()).toStrictEqual('aDomainevil=v');
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// --- validation -------------------------------------------------------------
|
|
146
|
-
|
|
147
|
-
describe('Cookie.validate', () => {
|
|
148
|
-
it('accepts a well-formed cookie', () => {
|
|
149
|
-
expect<bool>(Cookie.create('ok', 'v').validate().valid).toBe(true);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('rejects a name that is not a token', () => {
|
|
153
|
-
expect<bool>(Cookie.create('bad name', 'v').validate().valid).toBe(false);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('rejects an empty name', () => {
|
|
157
|
-
expect<bool>(Cookie.create('', 'v').validate().valid).toBe(false);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('rejects a Path that does not start with /', () => {
|
|
161
|
-
expect<bool>(Cookie.create('a', 'b').path('nope').validate().valid).toBe(false);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('rejects name+value over 4096 bytes', () => {
|
|
165
|
-
expect<bool>(Cookie.create('a', 'x'.repeat(5000)).validate().valid).toBe(false);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('rejects a __Host- name without its required attributes', () => {
|
|
169
|
-
const v = new Cookie('__Host-x', 'v').validate();
|
|
170
|
-
expect<bool>(v.valid).toBe(false);
|
|
171
|
-
expect<bool>(v.errors.length > 0).toBe(true);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('accepts a correctly-formed __Host- cookie', () => {
|
|
175
|
-
expect<bool>(Cookie.create('x', 'v').asHostPrefixed().validate().valid).toBe(true);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('flags a Max-Age beyond the 400-day cap', () => {
|
|
179
|
-
expect<bool>(Cookie.create('a', 'b').maxAge(99999999).validate().valid).toBe(false);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// --- Cookies.parse ----------------------------------------------------------
|
|
184
|
-
|
|
185
|
-
describe('Cookies.parse', () => {
|
|
186
|
-
it('parses multiple cookies', () => {
|
|
187
|
-
const m = Cookies.parse('a=1; b=2');
|
|
188
|
-
expect<i32>(m.size).toBe(2);
|
|
189
|
-
expect<string>(m.get('a')!).toStrictEqual('1');
|
|
190
|
-
expect<string>(m.get('b')!).toStrictEqual('2');
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('returns null for a missing cookie', () => {
|
|
194
|
-
expect<bool>(Cookies.parse('a=1').get('x') == null).toBe(true);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('keeps everything after the first = in the value', () => {
|
|
198
|
-
expect<string>(Cookies.parse('token=ab=cd').get('token')!).toStrictEqual('ab=cd');
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('trims surrounding whitespace around name and value', () => {
|
|
202
|
-
expect<string>(Cookies.parse(' a = 1 ; b=2').get('a')!).toStrictEqual('1');
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('strips one layer of surrounding quotes', () => {
|
|
206
|
-
expect<string>(Cookies.parse('a="hello"').get('a')!).toStrictEqual('hello');
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('percent-decodes values', () => {
|
|
210
|
-
expect<string>(Cookies.parse('x=hello%20world').get('x')!).toStrictEqual('hello world');
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('keeps the first occurrence of a duplicate name', () => {
|
|
214
|
-
expect<string>(Cookies.parse('a=1; a=2').get('a')!).toStrictEqual('1');
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it('handles an empty header', () => {
|
|
218
|
-
expect<i32>(Cookies.parse('').size).toBe(0);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('handles a valueless cookie', () => {
|
|
222
|
-
const m = Cookies.parse('flag');
|
|
223
|
-
expect<bool>(m.has('flag')).toBe(true);
|
|
224
|
-
expect<string>(m.get('flag')!).toStrictEqual('');
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
// --- value codec ------------------------------------------------------------
|
|
229
|
-
|
|
230
|
-
describe('Cookies value codec', () => {
|
|
231
|
-
it('percent-encodes special characters', () => {
|
|
232
|
-
expect<string>(Cookies.encodeValue('a b&c')).toStrictEqual('a%20b%26c');
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it('round-trips arbitrary UTF-8', () => {
|
|
236
|
-
const original = 'héllo, world! +/=';
|
|
237
|
-
expect<string>(Cookies.decodeValue(Cookies.encodeValue(original))).toStrictEqual(original);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// --- parseSetCookie ---------------------------------------------------------
|
|
242
|
-
|
|
243
|
-
describe('Cookies.parseSetCookie', () => {
|
|
244
|
-
it('round-trips a serialized cookie', () => {
|
|
245
|
-
const wire = Cookie.create('a', 'hello world')
|
|
246
|
-
.domain('x.com')
|
|
247
|
-
.path('/')
|
|
248
|
-
.secure()
|
|
249
|
-
.httpOnly()
|
|
250
|
-
.sameSite(SameSite.Lax)
|
|
251
|
-
.maxAge(60)
|
|
252
|
-
.serialize();
|
|
253
|
-
expect<string>(Cookies.parseSetCookie(wire).serialize()).toStrictEqual(wire);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it('parses individual attributes', () => {
|
|
257
|
-
const c = Cookies.parseSetCookie('sid=abc; Path=/; HttpOnly; SameSite=Strict');
|
|
258
|
-
expect<string>(c.name).toStrictEqual('sid');
|
|
259
|
-
expect<string>(c.value).toStrictEqual('abc');
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
// --- Request / Response integration -----------------------------------------
|
|
264
|
-
|
|
265
|
-
describe('Request cookies', () => {
|
|
266
|
-
it('reads a cookie by name', () => {
|
|
267
|
-
expect<string>(reqWithCookie('a=1; b=2').cookie('a')!).toStrictEqual('1');
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it('returns null for a missing cookie', () => {
|
|
271
|
-
expect<bool>(reqWithCookie('a=1').cookie('missing') == null).toBe(true);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it('exposes the full jar', () => {
|
|
275
|
-
expect<i32>(reqWithCookie('a=1; b=2; c=3').cookies().size).toBe(3);
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
describe('Response cookies', () => {
|
|
280
|
-
it('adds a Set-Cookie header', () => {
|
|
281
|
-
const r = Response.text('x').setCookie(Cookie.create('a', 'b'));
|
|
282
|
-
expect<string>(headerValue(r, 'set-cookie')).toStrictEqual('a=b');
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it('emits one Set-Cookie header per cookie (never folded)', () => {
|
|
286
|
-
const r = Response.empty(200)
|
|
287
|
-
.setCookie(Cookie.create('a', 'b'))
|
|
288
|
-
.setCookie(Cookie.create('c', 'd'));
|
|
289
|
-
expect<i32>(headerCount(r, 'set-cookie')).toBe(2);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it('setCookieKV is a shorthand', () => {
|
|
293
|
-
const r = Response.empty(200).setCookieKV('a', 'b');
|
|
294
|
-
expect<string>(headerValue(r, 'set-cookie')).toStrictEqual('a=b');
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
it('clearCookie emits an expired cookie', () => {
|
|
298
|
-
const r = Response.empty(200).clearCookie('a');
|
|
299
|
-
expect<string>(headerValue(r, 'set-cookie')).toStrictEqual(
|
|
300
|
-
'a=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0',
|
|
301
|
-
);
|
|
302
|
-
});
|
|
303
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Imports the specific modules rather than the runtime index: the index
|
|
2
|
-
// re-exports `SecureCookies`, which depends on the toilscript crypto std the
|
|
3
|
-
// as-pect compiler does not ship (see test/assembly/cookie.spec.ts).
|
|
4
|
-
import { describe, it, expect } from './aspect-shim';
|
|
5
|
-
import { Method } from '../../server/runtime/request';
|
|
6
|
-
import { Response } from '../../server/runtime/response';
|
|
7
|
-
|
|
8
|
-
describe('server runtime', () => {
|
|
9
|
-
it('numbers the HTTP methods per the wire contract', () => {
|
|
10
|
-
expect<i32>(<i32>Method.GET).toBe(0);
|
|
11
|
-
expect<i32>(<i32>Method.POST).toBe(1);
|
|
12
|
-
expect<i32>(<i32>Method.HEAD).toBe(5);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('builds a 200 text response by default', () => {
|
|
16
|
-
expect<i32>(<i32>Response.text('hi').status).toBe(200);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('defaults notFound() to 404', () => {
|
|
20
|
-
expect<i32>(<i32>Response.notFound().status).toBe(404);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
// Imports specific SSR modules (not the runtime index, which pulls in the
|
|
2
|
-
// crypto std the as-pect compiler does not ship). These modules are pure
|
|
3
|
-
// (escaping + buffer building + linear-memory encode), so they run under
|
|
4
|
-
// as-pect; the full `render` export is exercised via the example wasm in
|
|
5
|
-
// test/devserver.test.ts.
|
|
6
|
-
import { describe, it, expect } from './aspect-shim';
|
|
7
|
-
import { escapeHtml, escapeJsonForScript } from '../../server/runtime/ssr/escape';
|
|
8
|
-
import { HASH_LEN, HtmlBuilder, SlotKind, SlotValues } from '../../server/runtime/ssr/slots';
|
|
9
|
-
import { encodeValues } from '../../server/runtime/ssr/encode';
|
|
10
|
-
|
|
11
|
-
function bytesToStr(b: Uint8Array): string {
|
|
12
|
-
return String.UTF8.decodeUnsafe(changetype<usize>(b.dataStart), b.length);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe('ssr escape (react-dom byte-identity)', () => {
|
|
16
|
-
it('passes clean text through unchanged', () => {
|
|
17
|
-
expect<string>(escapeHtml('hello world')).toStrictEqual('hello world');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('escapes the five React characters with React entities', () => {
|
|
21
|
-
// React uses ' for the apostrophe and " for the quote.
|
|
22
|
-
expect<string>(escapeHtml('<a href="x">A&B\'s</a>')).toStrictEqual(
|
|
23
|
-
'<a href="x">A&B's</a>',
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('escapes ampersand first-class (not double-encoding)', () => {
|
|
28
|
-
expect<string>(escapeHtml('a & b')).toStrictEqual('a & b');
|
|
29
|
-
expect<string>(escapeHtml('&')).toStrictEqual('&amp;');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('escapes script-context json delimiters', () => {
|
|
33
|
-
expect<string>(escapeJsonForScript('{"x":"</script>"}')).toStrictEqual(
|
|
34
|
-
'{"x":"\\u003c/script\\u003e"}',
|
|
35
|
-
);
|
|
36
|
-
expect<string>(escapeJsonForScript('{"a":1}')).toStrictEqual('{"a":1}');
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('ssr SlotValues', () => {
|
|
41
|
-
it('escapes text holes and leaves raw holes verbatim', () => {
|
|
42
|
-
const v = new SlotValues(new StaticArray<u8>(HASH_LEN));
|
|
43
|
-
v.setText(0, '<b>');
|
|
44
|
-
v.setRaw(1, '<b>ok</b>');
|
|
45
|
-
expect<i32>(v.slots.length).toBe(2);
|
|
46
|
-
expect<i32>(<i32>v.slots[0].kind).toBe(<i32>SlotKind.TEXT);
|
|
47
|
-
expect<string>(bytesToStr(v.slots[0].bytes)).toStrictEqual('<b>');
|
|
48
|
-
expect<i32>(<i32>v.slots[1].kind).toBe(<i32>SlotKind.RAW);
|
|
49
|
-
expect<string>(bytesToStr(v.slots[1].bytes)).toStrictEqual('<b>ok</b>');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('stamps repeat rows by interleaving raw chunks and escaped values', () => {
|
|
53
|
-
const v = new SlotValues(new StaticArray<u8>(HASH_LEN));
|
|
54
|
-
const rows = new HtmlBuilder();
|
|
55
|
-
const items = ['a&b', 'c'];
|
|
56
|
-
for (let i = 0; i < items.length; i++) {
|
|
57
|
-
rows.raw('<li>').text(items[i]).raw('</li>');
|
|
58
|
-
}
|
|
59
|
-
v.setRepeat(2, rows);
|
|
60
|
-
expect<i32>(<i32>v.slots[0].kind).toBe(<i32>SlotKind.REPEAT);
|
|
61
|
-
expect<string>(bytesToStr(v.slots[0].bytes)).toStrictEqual(
|
|
62
|
-
'<li>a&b</li><li>c</li>',
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('ssr encodeValues wire format', () => {
|
|
68
|
-
it('round-trips status, hash, and one text slot', () => {
|
|
69
|
-
const hash = new StaticArray<u8>(HASH_LEN);
|
|
70
|
-
hash[0] = 0xaa;
|
|
71
|
-
hash[31] = 0xbb;
|
|
72
|
-
const v = new SlotValues(hash);
|
|
73
|
-
v.setStatus(200);
|
|
74
|
-
v.setText(7, 'hi');
|
|
75
|
-
|
|
76
|
-
const buf = new Uint8Array(128);
|
|
77
|
-
const base = changetype<usize>(buf.dataStart);
|
|
78
|
-
const n = encodeValues(v, base);
|
|
79
|
-
// status(2) + hash(32) + n_headers(2) + n_slots(2) + slot[id(2)+kind(1)+len(4)+"hi"(2)]
|
|
80
|
-
expect<i32>(<i32>n).toBe(2 + 32 + 2 + 2 + 2 + 1 + 4 + 2);
|
|
81
|
-
|
|
82
|
-
expect<i32>(<i32>load<u16>(base)).toBe(200); // status
|
|
83
|
-
expect<i32>(<i32>load<u8>(base + 2)).toBe(0xaa); // hash[0]
|
|
84
|
-
expect<i32>(<i32>load<u8>(base + 2 + 31)).toBe(0xbb); // hash[31]
|
|
85
|
-
const afterHash = base + 2 + 32;
|
|
86
|
-
expect<i32>(<i32>load<u16>(afterHash)).toBe(0); // n_headers
|
|
87
|
-
expect<i32>(<i32>load<u16>(afterHash + 2)).toBe(1); // n_slots
|
|
88
|
-
const slot = afterHash + 4;
|
|
89
|
-
expect<i32>(<i32>load<u16>(slot)).toBe(7); // slot_id
|
|
90
|
-
expect<i32>(<i32>load<u8>(slot + 2)).toBe(<i32>SlotKind.TEXT); // kind
|
|
91
|
-
expect<i32>(<i32>load<u32>(slot + 3)).toBe(2); // value_len
|
|
92
|
-
expect<i32>(<i32>load<u8>(slot + 7)).toBe(0x68); // 'h'
|
|
93
|
-
expect<i32>(<i32>load<u8>(slot + 8)).toBe(0x69); // 'i'
|
|
94
|
-
});
|
|
95
|
-
});
|
package/test/assembly.test.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// Runs the AssemblyScript specs in test/assembly/*.spec.ts by compiling each with toilscript and
|
|
2
|
-
// executing its `_start` (which runs the describe/it bodies + the shim's asserts). A failed assert
|
|
3
|
-
// aborts; this runner surfaces it as a vitest failure. Runs them via toilscript, no external runner.
|
|
4
|
-
import { describe, it } from 'vitest';
|
|
5
|
-
import { spawnSync } from 'node:child_process';
|
|
6
|
-
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
7
|
-
import { tmpdir } from 'node:os';
|
|
8
|
-
import { join, dirname } from 'node:path';
|
|
9
|
-
import { fileURLToPath } from 'node:url';
|
|
10
|
-
|
|
11
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
const TOILSCRIPT_BIN = join(here, '..', 'node_modules', 'toilscript', 'bin', 'toilscript.js');
|
|
13
|
-
const SPECS = ['example', 'cookie', 'ssr'] as const;
|
|
14
|
-
|
|
15
|
-
function liftString(ptr: number, mem: WebAssembly.Memory): string {
|
|
16
|
-
if (!ptr) return '(no message)';
|
|
17
|
-
const u32 = new Uint32Array(mem.buffer);
|
|
18
|
-
const len = (u32[(ptr - 4) >>> 2] >>> 1) >>> 0;
|
|
19
|
-
const u16 = new Uint16Array(mem.buffer);
|
|
20
|
-
let s = '';
|
|
21
|
-
const start = ptr >>> 1;
|
|
22
|
-
for (let i = 0; i < len; i++) s += String.fromCharCode(u16[start + i]);
|
|
23
|
-
return s;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe('assembly specs (toilscript-compiled)', () => {
|
|
27
|
-
for (const spec of SPECS) {
|
|
28
|
-
it(`${spec}.spec.ts passes`, async () => {
|
|
29
|
-
const tmp = mkdtempSync(join(tmpdir(), 'toiljs-asm-'));
|
|
30
|
-
try {
|
|
31
|
-
const src = join(here, 'assembly', `${spec}.spec.ts`);
|
|
32
|
-
const out = join(tmp, `${spec}.wasm`);
|
|
33
|
-
const r = spawnSync(
|
|
34
|
-
'node',
|
|
35
|
-
[TOILSCRIPT_BIN, src, '-o', out, '--exportStart', '_start', '--runtime', 'stub'],
|
|
36
|
-
{ encoding: 'utf8' },
|
|
37
|
-
);
|
|
38
|
-
if (r.status !== 0) {
|
|
39
|
-
throw new Error(`toilscript compile ${spec}.spec.ts failed:\n${r.stderr}${r.stdout}`);
|
|
40
|
-
}
|
|
41
|
-
const wasm = readFileSync(out);
|
|
42
|
-
const holder: { mem: WebAssembly.Memory | null } = { mem: null };
|
|
43
|
-
const { instance } = await WebAssembly.instantiate(wasm, {
|
|
44
|
-
env: {
|
|
45
|
-
abort(msg: number, _file: number, line: number): void {
|
|
46
|
-
const m = holder.mem ? liftString(msg >>> 0, holder.mem) : '';
|
|
47
|
-
throw new Error(`${spec}.spec.ts assertion failed: "${m}" (line ${line})`);
|
|
48
|
-
},
|
|
49
|
-
seed: () => 0,
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
holder.mem = instance.exports.memory as WebAssembly.Memory;
|
|
53
|
-
(instance.exports._start as () => void)();
|
|
54
|
-
} finally {
|
|
55
|
-
rmSync(tmp, { recursive: true, force: true });
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
});
|