toiljs 0.0.115 → 0.0.117
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 +10 -0
- package/README.md +16 -7
- package/TYPESCRIPT_LAW.md +1946 -2073
- 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/dev/devtools.js +1 -1
- package/build/client/dev/error-overlay.js +1 -1
- 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 +25 -4
- 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 +6 -5
- package/build/compiler/vite.js +3 -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/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/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/test/auth-emails.test.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The built-in auth email OVERRIDE codegen (src/compiler/auth-emails.ts): the
|
|
3
|
-
* pure fold (a rendered emails/auth-*.tsx over the default) and the AssemblyScript
|
|
4
|
-
* `AuthEmail` module it bakes. The Vite-render + file IO in `renderAuthEmails` is
|
|
5
|
-
* covered by the example build; here we test the string transforms in isolation.
|
|
6
|
-
*/
|
|
7
|
-
import { describe, expect, it } from 'vitest';
|
|
8
|
-
|
|
9
|
-
import { __test } from '../src/compiler/auth-emails';
|
|
10
|
-
import type { RenderedEmail } from '../src/compiler/emails';
|
|
11
|
-
|
|
12
|
-
const { moduleSource, effectiveFromOverride, SPECS } = __test;
|
|
13
|
-
|
|
14
|
-
/** A defaults-only parts map (what a project with no overrides generates). */
|
|
15
|
-
function defaultParts(): Record<string, { subject: string; text: string; html: string }> {
|
|
16
|
-
const parts: Record<string, { subject: string; text: string; html: string }> = {};
|
|
17
|
-
for (const [name, spec] of Object.entries(SPECS))
|
|
18
|
-
parts[name] = {
|
|
19
|
-
subject: spec.defaultSubject,
|
|
20
|
-
text: spec.defaultText,
|
|
21
|
-
html: spec.defaultHtml,
|
|
22
|
-
};
|
|
23
|
-
return parts;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function rendered(name: string, over: Partial<RenderedEmail>): RenderedEmail {
|
|
27
|
-
return {
|
|
28
|
-
name,
|
|
29
|
-
subject: over.subject ?? name,
|
|
30
|
-
html: over.html ?? '',
|
|
31
|
-
text: over.text ?? '',
|
|
32
|
-
tokens: over.tokens ?? [],
|
|
33
|
-
purpose: over.purpose ?? name.toLowerCase(),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe('AuthEmail module codegen', () => {
|
|
38
|
-
it('emits confirm/reset/twofa, each through the DETACHED send with its purpose', () => {
|
|
39
|
-
const src = moduleSource(defaultParts());
|
|
40
|
-
expect(src).toContain('export namespace AuthEmail {');
|
|
41
|
-
expect(src).toContain('export function confirm(to: string, link: string): void');
|
|
42
|
-
expect(src).toContain('export function reset(to: string, link: string): void');
|
|
43
|
-
// twofa takes the subject as a runtime arg (login vs setup), not baked.
|
|
44
|
-
expect(src).toContain(
|
|
45
|
-
'export function twofa(to: string, code: string, subject: string, action: string): void',
|
|
46
|
-
);
|
|
47
|
-
// Every send is detached (the anti-enumeration property), never the suspending send.
|
|
48
|
-
expect(src.match(/\.sendDetached\(/g)).toHaveLength(3);
|
|
49
|
-
expect(src).not.toContain('.send(to');
|
|
50
|
-
expect(src).toContain('"verify"');
|
|
51
|
-
expect(src).toContain('"reset"');
|
|
52
|
-
expect(src).toContain('"2fa"');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('bakes the default subject for confirm/reset but passes `subject` through for twofa', () => {
|
|
56
|
-
const src = moduleSource(defaultParts());
|
|
57
|
-
expect(src).toContain('new EmailTemplate("Confirm your account"');
|
|
58
|
-
expect(src).toContain('new EmailTemplate("Reset your password"');
|
|
59
|
-
expect(src).toContain('new EmailTemplate(subject,'); // twofa uses the arg
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('interpolates the right token per email (link for confirm/reset, code + action for twofa)', () => {
|
|
63
|
-
const src = moduleSource(defaultParts());
|
|
64
|
-
expect(src).toContain('v.set("link", link)');
|
|
65
|
-
expect(src).toContain('v.set("code", code)');
|
|
66
|
-
expect(src).toContain('v.set("action", action)');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('escapes baked HTML into a valid string literal', () => {
|
|
70
|
-
const parts = defaultParts();
|
|
71
|
-
parts.AuthConfirm = {
|
|
72
|
-
subject: 'Hi "there"',
|
|
73
|
-
text: 'a\nb',
|
|
74
|
-
html: '<a href="x">c</a>',
|
|
75
|
-
};
|
|
76
|
-
const src = moduleSource(parts);
|
|
77
|
-
// JSON.stringify escaping keeps the emitted AS parseable (quotes/newlines escaped).
|
|
78
|
-
expect(src).toContain('"Hi \\"there\\""');
|
|
79
|
-
expect(src).toContain('"<a href=\\"x\\">c</a>"');
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe('effectiveFromOverride', () => {
|
|
84
|
-
it('uses the override subject/text/html when the template sets a subject', () => {
|
|
85
|
-
const eff = effectiveFromOverride(
|
|
86
|
-
'AuthConfirm',
|
|
87
|
-
SPECS.AuthConfirm,
|
|
88
|
-
rendered('AuthConfirm', {
|
|
89
|
-
subject: 'Verify your Acme account',
|
|
90
|
-
html: '<p>{{link}}</p>',
|
|
91
|
-
text: '{{link}}',
|
|
92
|
-
tokens: ['link'],
|
|
93
|
-
}),
|
|
94
|
-
);
|
|
95
|
-
expect(eff.subject).toBe('Verify your Acme account');
|
|
96
|
-
expect(eff.html).toBe('<p>{{link}}</p>');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('falls back to the default subject when the template did not set one', () => {
|
|
100
|
-
// renderModule defaults `subject` to the module name when no `export const subject`.
|
|
101
|
-
const eff = effectiveFromOverride(
|
|
102
|
-
'AuthConfirm',
|
|
103
|
-
SPECS.AuthConfirm,
|
|
104
|
-
rendered('AuthConfirm', { subject: 'AuthConfirm', html: '<p>{{link}}</p>', tokens: ['link'] }),
|
|
105
|
-
);
|
|
106
|
-
expect(eff.subject).toBe('Confirm your account');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('ignores an override subject for twofa (login/setup subject is contextual)', () => {
|
|
110
|
-
const eff = effectiveFromOverride(
|
|
111
|
-
'Auth2fa',
|
|
112
|
-
SPECS.Auth2fa,
|
|
113
|
-
rendered('Auth2fa', { subject: 'ignored', html: '<b>{{code}}</b>', tokens: ['code'] }),
|
|
114
|
-
);
|
|
115
|
-
expect(eff.subject).toBe(''); // subjectFromArg: baked subject stays empty (the arg wins at runtime)
|
|
116
|
-
expect(eff.html).toBe('<b>{{code}}</b>');
|
|
117
|
-
});
|
|
118
|
-
});
|
package/test/built-ssr.test.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
import { describe, expect, it } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import { loadBuiltSsrTemplates } from '../src/devserver/production';
|
|
8
|
-
import { assembleSsr, type SsrRoute } from '../src/devserver/ssr';
|
|
9
|
-
|
|
10
|
-
function slotsManifest(tmplLen: number, hash: Buffer): Buffer {
|
|
11
|
-
const buf = Buffer.alloc(46 + 8);
|
|
12
|
-
let o = 0;
|
|
13
|
-
buf.write('TSLT', o, 'ascii');
|
|
14
|
-
o += 4;
|
|
15
|
-
buf.writeUInt16LE(1, o);
|
|
16
|
-
o += 2;
|
|
17
|
-
buf.writeUInt16LE(0, o);
|
|
18
|
-
o += 2;
|
|
19
|
-
buf.writeUInt32LE(tmplLen, o);
|
|
20
|
-
o += 4;
|
|
21
|
-
hash.copy(buf, o);
|
|
22
|
-
o += 32;
|
|
23
|
-
buf.writeUInt16LE(1, o);
|
|
24
|
-
o += 2;
|
|
25
|
-
buf.writeUInt32LE(1, o); // insert after the first byte
|
|
26
|
-
o += 4;
|
|
27
|
-
buf.writeUInt16LE(0, o);
|
|
28
|
-
o += 2;
|
|
29
|
-
buf.writeUInt8(0, o); // text
|
|
30
|
-
o += 1;
|
|
31
|
-
buf.writeUInt8(0, o);
|
|
32
|
-
return buf;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function valuesEnvelope(hash: Buffer, value: string): Buffer {
|
|
36
|
-
const valueBytes = Buffer.from(value);
|
|
37
|
-
const buf = Buffer.alloc(2 + 32 + 2 + 2 + 2 + 1 + 4 + valueBytes.length);
|
|
38
|
-
let o = 0;
|
|
39
|
-
buf.writeUInt16LE(200, o);
|
|
40
|
-
o += 2;
|
|
41
|
-
hash.copy(buf, o);
|
|
42
|
-
o += 32;
|
|
43
|
-
buf.writeUInt16LE(0, o); // headers
|
|
44
|
-
o += 2;
|
|
45
|
-
buf.writeUInt16LE(1, o); // slots
|
|
46
|
-
o += 2;
|
|
47
|
-
buf.writeUInt16LE(0, o);
|
|
48
|
-
o += 2;
|
|
49
|
-
buf.writeUInt8(0, o);
|
|
50
|
-
o += 1;
|
|
51
|
-
buf.writeUInt32LE(valueBytes.length, o);
|
|
52
|
-
o += 4;
|
|
53
|
-
valueBytes.copy(buf, o);
|
|
54
|
-
return buf;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** An envelope with one header (the internal SSR-title header) plus one text slot. */
|
|
58
|
-
function envelopeWithTitle(hash: Buffer, value: string, title: string): Buffer {
|
|
59
|
-
const name = Buffer.from('x-toil-ssr-title');
|
|
60
|
-
const titleBytes = Buffer.from(title);
|
|
61
|
-
const valueBytes = Buffer.from(value);
|
|
62
|
-
const buf = Buffer.alloc(
|
|
63
|
-
2 + 32 + 2 + (2 + 2 + name.length + titleBytes.length) + 2 + (2 + 1 + 4 + valueBytes.length),
|
|
64
|
-
);
|
|
65
|
-
let o = 0;
|
|
66
|
-
buf.writeUInt16LE(200, o);
|
|
67
|
-
o += 2;
|
|
68
|
-
hash.copy(buf, o);
|
|
69
|
-
o += 32;
|
|
70
|
-
buf.writeUInt16LE(1, o); // 1 header
|
|
71
|
-
o += 2;
|
|
72
|
-
buf.writeUInt16LE(name.length, o);
|
|
73
|
-
o += 2;
|
|
74
|
-
buf.writeUInt16LE(titleBytes.length, o);
|
|
75
|
-
o += 2;
|
|
76
|
-
name.copy(buf, o);
|
|
77
|
-
o += name.length;
|
|
78
|
-
titleBytes.copy(buf, o);
|
|
79
|
-
o += titleBytes.length;
|
|
80
|
-
buf.writeUInt16LE(1, o); // 1 slot
|
|
81
|
-
o += 2;
|
|
82
|
-
buf.writeUInt16LE(0, o); // slot id 0
|
|
83
|
-
o += 2;
|
|
84
|
-
buf.writeUInt8(0, o); // text kind
|
|
85
|
-
o += 1;
|
|
86
|
-
buf.writeUInt32LE(valueBytes.length, o);
|
|
87
|
-
o += 4;
|
|
88
|
-
valueBytes.copy(buf, o);
|
|
89
|
-
return buf;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
describe('built SSR templates', () => {
|
|
93
|
-
it('loads the built shell, including production CSS links, from _ssr artifacts', () => {
|
|
94
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'toil-built-ssr-'));
|
|
95
|
-
try {
|
|
96
|
-
const dir = path.join(root, '_ssr');
|
|
97
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
98
|
-
const tmpl = Buffer.from(
|
|
99
|
-
'<!doctype html><html><head><link rel="stylesheet" href="/css/style.css"></head><body>A</body></html>',
|
|
100
|
-
);
|
|
101
|
-
const hash = Buffer.alloc(32, 7);
|
|
102
|
-
fs.writeFileSync(
|
|
103
|
-
path.join(dir, 'templates.json'),
|
|
104
|
-
JSON.stringify([{ route: '/x', name: 'x', hash: hash.toString('hex') }]),
|
|
105
|
-
);
|
|
106
|
-
fs.writeFileSync(path.join(dir, 'x.tmpl'), tmpl);
|
|
107
|
-
fs.writeFileSync(path.join(dir, 'x.slots'), slotsManifest(tmpl.length, hash));
|
|
108
|
-
|
|
109
|
-
const templates = loadBuiltSsrTemplates(root);
|
|
110
|
-
expect(templates).toHaveLength(1);
|
|
111
|
-
expect(Buffer.from(templates[0]!.tmpl).toString('utf8')).toContain('/css/style.css');
|
|
112
|
-
expect(Buffer.from(templates[0]!.hash!).equals(hash)).toBe(true);
|
|
113
|
-
expect(templates[0]!.entries).toEqual([{ id: 0, offset: 1 }]);
|
|
114
|
-
} finally {
|
|
115
|
-
fs.rmSync(root, { recursive: true, force: true });
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('checks the deployed template hash before splicing production SSR values', () => {
|
|
120
|
-
const hash = Buffer.alloc(32, 1);
|
|
121
|
-
const route: SsrRoute = {
|
|
122
|
-
test: () => true,
|
|
123
|
-
tmpl: Buffer.from('ab'),
|
|
124
|
-
entries: [{ id: 0, offset: 1 }],
|
|
125
|
-
hash,
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
expect(Buffer.from(assembleSsr(route, valuesEnvelope(hash, 'X'))!.html).toString()).toBe(
|
|
129
|
-
'aXb',
|
|
130
|
-
);
|
|
131
|
-
expect(assembleSsr(route, valuesEnvelope(Buffer.alloc(32, 2), 'X'))).toBeNull();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('replaces the <title> from a guest setTitle header, then strips the internal header', () => {
|
|
135
|
-
const hash = Buffer.alloc(32, 1);
|
|
136
|
-
const route: SsrRoute = {
|
|
137
|
-
test: () => true,
|
|
138
|
-
tmpl: Buffer.from('<title>Static</title>ab'),
|
|
139
|
-
entries: [{ id: 0, offset: 22 }],
|
|
140
|
-
hash,
|
|
141
|
-
};
|
|
142
|
-
const out = assembleSsr(route, envelopeWithTitle(hash, 'X', 'Dynamic'))!;
|
|
143
|
-
// the body slot is spliced AND the <title> is replaced with the guest's per-request value
|
|
144
|
-
expect(Buffer.from(out.html).toString()).toBe('<title>Dynamic</title>aXb');
|
|
145
|
-
// the internal header never reaches the client
|
|
146
|
-
expect(out.headers.some(([k]) => k.toLowerCase() === 'x-toil-ssr-title')).toBe(false);
|
|
147
|
-
});
|
|
148
|
-
});
|
package/test/channel.test.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { resolveChannelUrl } from '../src/client/channel/channel';
|
|
4
|
-
|
|
5
|
-
describe('resolveChannelUrl', () => {
|
|
6
|
-
it('uses ws:// over http and the default /_toil path', () => {
|
|
7
|
-
expect(resolveChannelUrl(undefined, { protocol: 'http:', host: 'localhost:3000' })).toBe(
|
|
8
|
-
'ws://localhost:3000/_toil',
|
|
9
|
-
);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('uses wss:// over https', () => {
|
|
13
|
-
expect(resolveChannelUrl('/_toil', { protocol: 'https:', host: 'app.example.com' })).toBe(
|
|
14
|
-
'wss://app.example.com/_toil',
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('normalizes a path without a leading slash', () => {
|
|
19
|
-
expect(resolveChannelUrl('live', { protocol: 'http:', host: 'h:1' })).toBe('ws://h:1/live');
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* loadConfig host/port resolution: the dev server AND the self-host (`toiljs start`)
|
|
3
|
-
* bind to a host+port resolved with the precedence CLI flag > env (PORT/HOST) >
|
|
4
|
-
* config (client.host/port) > default (127.0.0.1:3000). These lock that precedence
|
|
5
|
-
* and the env parsing (a blank/garbage PORT must fall through, never bind to 0).
|
|
6
|
-
*/
|
|
7
|
-
import fs from 'node:fs';
|
|
8
|
-
import os from 'node:os';
|
|
9
|
-
import path from 'node:path';
|
|
10
|
-
|
|
11
|
-
import { afterEach, describe, expect, it } from 'vitest';
|
|
12
|
-
|
|
13
|
-
import { loadConfig } from '../src/compiler/config.js';
|
|
14
|
-
|
|
15
|
-
// An empty dir with no toil.config so loadConfig exercises the env/opts/default path.
|
|
16
|
-
const emptyRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'toil-cfg-'));
|
|
17
|
-
|
|
18
|
-
describe('loadConfig host/port precedence', () => {
|
|
19
|
-
const savedPort = process.env.PORT;
|
|
20
|
-
const savedHost = process.env.HOST;
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
if (savedPort === undefined) delete process.env.PORT;
|
|
23
|
-
else process.env.PORT = savedPort;
|
|
24
|
-
if (savedHost === undefined) delete process.env.HOST;
|
|
25
|
-
else process.env.HOST = savedHost;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('defaults to 127.0.0.1:3000 with no flag / env / config', async () => {
|
|
29
|
-
delete process.env.PORT;
|
|
30
|
-
delete process.env.HOST;
|
|
31
|
-
const cfg = await loadConfig({ root: emptyRoot });
|
|
32
|
-
expect(cfg.port).toBe(3000);
|
|
33
|
-
expect(cfg.host).toBe('127.0.0.1');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('reads the PORT / HOST env vars', async () => {
|
|
37
|
-
process.env.PORT = '8080';
|
|
38
|
-
process.env.HOST = '0.0.0.0';
|
|
39
|
-
const cfg = await loadConfig({ root: emptyRoot });
|
|
40
|
-
expect(cfg.port).toBe(8080);
|
|
41
|
-
expect(cfg.host).toBe('0.0.0.0');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('CLI opts win over env (CLI > env)', async () => {
|
|
45
|
-
process.env.PORT = '8080';
|
|
46
|
-
process.env.HOST = '0.0.0.0';
|
|
47
|
-
const cfg = await loadConfig({ root: emptyRoot, port: 4321, host: '192.168.1.5' });
|
|
48
|
-
expect(cfg.port).toBe(4321);
|
|
49
|
-
expect(cfg.host).toBe('192.168.1.5');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('a blank / non-numeric PORT env falls through to the default (never binds to 0)', async () => {
|
|
53
|
-
process.env.PORT = '';
|
|
54
|
-
delete process.env.HOST;
|
|
55
|
-
expect((await loadConfig({ root: emptyRoot })).port).toBe(3000);
|
|
56
|
-
process.env.PORT = 'not-a-number';
|
|
57
|
-
expect((await loadConfig({ root: emptyRoot })).port).toBe(3000);
|
|
58
|
-
});
|
|
59
|
-
});
|
package/test/configure.test.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import { applyConfigure } from '../src/cli/configure';
|
|
8
|
-
import type { StyleFeatures } from '../src/cli/features';
|
|
9
|
-
|
|
10
|
-
const CSS: StyleFeatures = { preprocessor: 'css', tailwind: false };
|
|
11
|
-
const SASS_TW: StyleFeatures = { preprocessor: 'sass', tailwind: true };
|
|
12
|
-
|
|
13
|
-
const ENTRY = [
|
|
14
|
-
"import { routes, layout, notFound } from 'toiljs/routes';",
|
|
15
|
-
'',
|
|
16
|
-
"import './styles/main.css';",
|
|
17
|
-
'',
|
|
18
|
-
'Toil.mount(routes, layout, notFound);',
|
|
19
|
-
'',
|
|
20
|
-
].join('\n');
|
|
21
|
-
|
|
22
|
-
let dir: string;
|
|
23
|
-
let clientDir: string;
|
|
24
|
-
let pkgPath: string;
|
|
25
|
-
|
|
26
|
-
async function readJson(p: string): Promise<{ devDependencies?: Record<string, string> }> {
|
|
27
|
-
return JSON.parse(await fs.readFile(p, 'utf8')) as { devDependencies?: Record<string, string> };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function exists(p: string): Promise<boolean> {
|
|
31
|
-
try {
|
|
32
|
-
await fs.access(p);
|
|
33
|
-
return true;
|
|
34
|
-
} catch {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
beforeEach(async () => {
|
|
40
|
-
dir = await fs.mkdtemp(path.join(os.tmpdir(), 'toil-cfg-'));
|
|
41
|
-
clientDir = path.join(dir, 'client');
|
|
42
|
-
pkgPath = path.join(dir, 'package.json');
|
|
43
|
-
await fs.mkdir(path.join(clientDir, 'styles'), { recursive: true });
|
|
44
|
-
await fs.writeFile(path.join(clientDir, 'toil.tsx'), ENTRY, 'utf8');
|
|
45
|
-
await fs.writeFile(path.join(clientDir, 'styles/main.css'), 'body { margin: 0; }\n', 'utf8');
|
|
46
|
-
await fs.writeFile(
|
|
47
|
-
pkgPath,
|
|
48
|
-
JSON.stringify({ devDependencies: { typescript: '^6' } }, null, 4),
|
|
49
|
-
'utf8',
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
afterEach(async () => {
|
|
54
|
-
await fs.rm(dir, { recursive: true, force: true });
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('applyConfigure', () => {
|
|
58
|
-
it('adds Sass + Tailwind: renames stylesheet, adds entry + imports + deps', async () => {
|
|
59
|
-
const pkg = await readJson(pkgPath);
|
|
60
|
-
await applyConfigure(clientDir, pkgPath, pkg, CSS, SASS_TW);
|
|
61
|
-
|
|
62
|
-
expect(await exists(path.join(clientDir, 'styles/main.scss'))).toBe(true);
|
|
63
|
-
expect(await exists(path.join(clientDir, 'styles/main.css'))).toBe(false);
|
|
64
|
-
expect(await exists(path.join(clientDir, 'styles/tailwind.css'))).toBe(true);
|
|
65
|
-
|
|
66
|
-
const entry = await fs.readFile(path.join(clientDir, 'toil.tsx'), 'utf8');
|
|
67
|
-
expect(entry).toContain("import './styles/tailwind.css';");
|
|
68
|
-
expect(entry).toContain("import './styles/main.scss';");
|
|
69
|
-
expect(entry).not.toContain('main.css');
|
|
70
|
-
expect(entry).toContain('Toil.mount(routes, layout, notFound);');
|
|
71
|
-
|
|
72
|
-
const deps = (await readJson(pkgPath)).devDependencies ?? {};
|
|
73
|
-
expect(deps).toHaveProperty('sass');
|
|
74
|
-
expect(deps).toHaveProperty('tailwindcss');
|
|
75
|
-
expect(deps).toHaveProperty('@tailwindcss/vite');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('removes everything cleanly when switching back to plain CSS', async () => {
|
|
79
|
-
const pkg = await readJson(pkgPath);
|
|
80
|
-
await applyConfigure(clientDir, pkgPath, pkg, CSS, SASS_TW);
|
|
81
|
-
const mid = await readJson(pkgPath);
|
|
82
|
-
await applyConfigure(clientDir, pkgPath, mid, SASS_TW, CSS);
|
|
83
|
-
|
|
84
|
-
expect(await exists(path.join(clientDir, 'styles/main.css'))).toBe(true);
|
|
85
|
-
expect(await exists(path.join(clientDir, 'styles/main.scss'))).toBe(false);
|
|
86
|
-
expect(await exists(path.join(clientDir, 'styles/tailwind.css'))).toBe(false);
|
|
87
|
-
|
|
88
|
-
const deps = (await readJson(pkgPath)).devDependencies ?? {};
|
|
89
|
-
expect(deps).not.toHaveProperty('sass');
|
|
90
|
-
expect(deps).not.toHaveProperty('tailwindcss');
|
|
91
|
-
expect(deps).not.toHaveProperty('@tailwindcss/vite');
|
|
92
|
-
expect(deps).toHaveProperty('typescript');
|
|
93
|
-
});
|
|
94
|
-
});
|