@sdxc/kit 2026.10.17 → 2026.10.20
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/README.md +390 -20
- package/changelog.jsonl +1160 -1092
- package/config.schema.json +47 -1
- package/dist/cli.js +12 -0
- package/dist/commands/deploy.d.ts +23 -0
- package/dist/commands/deploy.js +167 -0
- package/dist/commands/destroy.d.ts +22 -0
- package/dist/commands/destroy.js +92 -0
- package/dist/commands/doctor.d.ts +26 -0
- package/dist/commands/doctor.js +65 -0
- package/dist/commands/initializers.d.ts +16 -0
- package/dist/commands/initializers.js +23 -0
- package/dist/commands/make.d.ts +72 -6
- package/dist/commands/make.js +127 -19
- package/dist/commands/middleware.d.ts +16 -0
- package/dist/commands/middleware.js +21 -0
- package/dist/commands/models.d.ts +18 -0
- package/dist/commands/models.js +29 -0
- package/dist/commands/notes.d.ts +17 -0
- package/dist/commands/notes.js +27 -0
- package/dist/commands/routes.d.ts +25 -0
- package/dist/commands/routes.js +50 -0
- package/dist/commands/run.d.ts +16 -0
- package/dist/commands/run.js +32 -11
- package/dist/commands/scaffold.d.ts +29 -0
- package/dist/commands/scaffold.js +33 -0
- package/dist/commands/schedule.d.ts +16 -0
- package/dist/commands/schedule.js +21 -0
- package/dist/commands/stats.d.ts +16 -0
- package/dist/commands/stats.js +21 -0
- package/dist/commands/ui/update.d.ts +6 -3
- package/dist/commands/ui/update.js +24 -7
- package/dist/commands/upgrade.d.ts +3 -1
- package/dist/commands/upgrade.js +88 -23
- package/dist/config.d.ts +18 -0
- package/dist/config.js +28 -1
- package/dist/contract.d.ts +97 -3
- package/dist/contract.js +360 -26
- package/dist/create/templates.js +3 -2
- package/dist/dependencies.d.ts +4 -1
- package/dist/dependencies.js +13 -1
- package/dist/deploy/plan.d.ts +49 -0
- package/dist/deploy/plan.js +68 -0
- package/dist/destroy.d.ts +40 -0
- package/dist/destroy.js +311 -0
- package/dist/doctor/check.d.ts +71 -0
- package/dist/doctor/check.js +53 -0
- package/dist/doctor/checks.d.ts +23 -0
- package/dist/doctor/checks.js +68 -0
- package/dist/doctor/define.d.ts +59 -0
- package/dist/doctor/define.js +16 -0
- package/dist/doctor/emails.d.ts +18 -0
- package/dist/doctor/emails.js +243 -0
- package/dist/doctor/env.d.ts +26 -0
- package/dist/doctor/env.js +88 -0
- package/dist/doctor/files.d.ts +14 -0
- package/dist/doctor/files.js +34 -0
- package/dist/doctor/fixture.d.ts +23 -0
- package/dist/doctor/fixture.js +46 -0
- package/dist/doctor/install.d.ts +17 -0
- package/dist/doctor/install.js +37 -0
- package/dist/doctor/installed.d.ts +11 -0
- package/dist/doctor/installed.js +79 -0
- package/dist/doctor/layout.d.ts +23 -0
- package/dist/doctor/layout.js +83 -0
- package/dist/doctor/migrations.d.ts +16 -0
- package/dist/doctor/migrations.js +96 -0
- package/dist/doctor/models.d.ts +13 -0
- package/dist/doctor/models.js +69 -0
- package/dist/doctor/pins.d.ts +15 -0
- package/dist/doctor/pins.js +79 -0
- package/dist/doctor/project.d.ts +58 -0
- package/dist/doctor/project.js +261 -0
- package/dist/doctor/remix.d.ts +14 -0
- package/dist/doctor/remix.js +44 -0
- package/dist/doctor/routes.d.ts +11 -0
- package/dist/doctor/routes.js +49 -0
- package/dist/doctor/typegen.d.ts +13 -0
- package/dist/doctor/typegen.js +57 -0
- package/dist/doctor/ui.d.ts +14 -0
- package/dist/doctor/ui.js +51 -0
- package/dist/initializers.d.ts +25 -0
- package/dist/initializers.js +89 -0
- package/dist/lock.d.ts +2 -2
- package/dist/make/actions.d.ts +23 -0
- package/dist/make/actions.js +82 -0
- package/dist/make/declare.d.ts +31 -3
- package/dist/make/declare.js +284 -9
- package/dist/make/email.d.ts +23 -0
- package/dist/make/email.js +111 -0
- package/dist/make/from-fields.d.ts +30 -0
- package/dist/make/from-fields.js +162 -0
- package/dist/make/from-model.d.ts +39 -0
- package/dist/make/from-model.js +161 -0
- package/dist/make/generate.d.ts +16 -5
- package/dist/make/generate.js +38 -15
- package/dist/make/guard.d.ts +35 -0
- package/dist/make/guard.js +73 -0
- package/dist/make/imports.d.ts +6 -0
- package/dist/make/imports.js +19 -0
- package/dist/make/index.d.ts +47 -4
- package/dist/make/index.js +287 -29
- package/dist/make/kinds.d.ts +29 -2
- package/dist/make/kinds.js +79 -7
- package/dist/make/mount.d.ts +25 -0
- package/dist/make/mount.js +135 -0
- package/dist/make/schema-diff.d.ts +58 -0
- package/dist/make/schema-diff.js +609 -0
- package/dist/make/schema.d.ts +76 -0
- package/dist/make/schema.js +206 -0
- package/dist/make/stubs.d.ts +7 -5
- package/dist/make/stubs.js +16 -5
- package/dist/make/test.d.ts +43 -0
- package/dist/make/test.js +149 -0
- package/dist/make/trigger.d.ts +31 -0
- package/dist/make/trigger.js +163 -0
- package/dist/models.d.ts +42 -0
- package/dist/models.js +149 -0
- package/dist/notes.d.ts +28 -0
- package/dist/notes.js +66 -0
- package/dist/reference.d.ts +27 -0
- package/dist/reference.js +103 -0
- package/dist/releases.d.ts +9 -0
- package/dist/releases.js +29 -8
- package/dist/routes/chains.d.ts +34 -0
- package/dist/routes/chains.js +95 -0
- package/dist/routes/filter.d.ts +53 -0
- package/dist/routes/filter.js +147 -0
- package/dist/routes/format.d.ts +23 -0
- package/dist/routes/format.js +123 -0
- package/dist/routes/helpers.d.ts +21 -0
- package/dist/routes/helpers.js +165 -0
- package/dist/routes/index.d.ts +56 -0
- package/dist/routes/index.js +167 -0
- package/dist/routes/modules.d.ts +116 -0
- package/dist/routes/modules.js +235 -0
- package/dist/routes/parse.d.ts +161 -0
- package/dist/routes/parse.js +621 -0
- package/dist/routes/routers.d.ts +69 -0
- package/dist/routes/routers.js +327 -0
- package/dist/scaffold/fields.d.ts +129 -0
- package/dist/scaffold/fields.js +421 -0
- package/dist/scaffold/index.d.ts +37 -0
- package/dist/scaffold/index.js +613 -0
- package/dist/scaffold/render.d.ts +51 -0
- package/dist/scaffold/render.js +332 -0
- package/dist/schedule.d.ts +45 -0
- package/dist/schedule.js +124 -0
- package/dist/stats.d.ts +37 -0
- package/dist/stats.js +126 -0
- package/dist/ui/commands.d.ts +10 -3
- package/dist/ui/commands.js +85 -15
- package/dist/ui/registry.d.ts +8 -8
- package/dist/upgrade/agents.d.ts +49 -0
- package/dist/upgrade/agents.js +110 -0
- package/dist/upgrade/changelog.d.ts +2 -2
- package/dist/upgrade/project.d.ts +4 -0
- package/dist/upgrade/project.js +11 -1
- package/dist/upgrade/prompt.d.ts +11 -0
- package/dist/upgrade/prompt.js +50 -7
- package/package.json +6 -4
- package/registry/ui/alert-dialog.json +2 -2
- package/registry/ui/attachment.json +2 -2
- package/registry/ui/calendar.json +2 -2
- package/registry/ui/color-picker.json +2 -2
- package/registry/ui/command.json +2 -2
- package/registry/ui/date-picker.json +2 -2
- package/registry/ui/date-range-picker.json +2 -2
- package/registry/ui/dialog.json +2 -2
- package/registry/ui/file-trigger.json +2 -2
- package/registry/ui/heading-scope.json +2 -2
- package/registry/ui/message-scroller.json +2 -2
- package/registry/ui/number-field.json +2 -2
- package/registry/ui/range-calendar.json +2 -2
- package/registry/ui/resizable.json +2 -2
- package/registry/ui/select.json +2 -2
- package/registry/ui/shared-element.json +2 -2
- package/stubs/controller.api.resource.stub +23 -0
- package/stubs/controller.form.stub +2 -2
- package/stubs/controller.form.test.stub +2 -2
- package/stubs/controller.resource.form.stub +67 -0
- package/stubs/controller.resource.stub +28 -0
- package/stubs/email.stub +9 -14
- package/stubs/email.test.stub +9 -9
- package/stubs/factory.stub +1 -1
- package/stubs/model.stub +3 -3
- package/stubs/policy.test.stub +34 -8
- package/stubs/scaffold.api.create.stub +34 -0
- package/stubs/scaffold.api.create.test.stub +37 -0
- package/stubs/scaffold.api.destroy.stub +34 -0
- package/stubs/scaffold.api.destroy.test.stub +44 -0
- package/stubs/scaffold.api.index.stub +23 -0
- package/stubs/scaffold.api.index.test.stub +31 -0
- package/stubs/scaffold.api.show.stub +27 -0
- package/stubs/scaffold.api.show.test.stub +41 -0
- package/stubs/scaffold.api.update.stub +44 -0
- package/stubs/scaffold.api.update.test.stub +46 -0
- package/stubs/scaffold.command.create.stub +22 -0
- package/stubs/scaffold.command.create.test.stub +30 -0
- package/stubs/scaffold.command.delete.stub +20 -0
- package/stubs/scaffold.command.delete.test.stub +39 -0
- package/stubs/scaffold.command.list.stub +18 -0
- package/stubs/scaffold.command.list.test.stub +31 -0
- package/stubs/scaffold.command.show.stub +19 -0
- package/stubs/scaffold.command.show.test.stub +37 -0
- package/stubs/scaffold.controller.destroy.stub +35 -0
- package/stubs/scaffold.controller.destroy.test.stub +65 -0
- package/stubs/scaffold.controller.edit.stub +97 -0
- package/stubs/scaffold.controller.edit.test.stub +91 -0
- package/stubs/scaffold.controller.index.stub +55 -0
- package/stubs/scaffold.controller.index.test.stub +32 -0
- package/stubs/scaffold.controller.new.stub +70 -0
- package/stubs/scaffold.controller.new.test.stub +81 -0
- package/stubs/scaffold.controller.show.stub +59 -0
- package/stubs/scaffold.controller.show.test.stub +43 -0
- package/stubs/scaffold.factory.stub +16 -0
- package/stubs/scaffold.form.stub +75 -0
- package/stubs/scaffold.mcp.create.stub +24 -0
- package/stubs/scaffold.mcp.create.test.stub +36 -0
- package/stubs/scaffold.mcp.delete.stub +31 -0
- package/stubs/scaffold.mcp.delete.test.stub +43 -0
- package/stubs/scaffold.mcp.get.stub +21 -0
- package/stubs/scaffold.mcp.get.test.stub +31 -0
- package/stubs/scaffold.mcp.list.stub +23 -0
- package/stubs/scaffold.mcp.list.test.stub +25 -0
- package/stubs/scaffold.mcp.update.stub +37 -0
- package/stubs/scaffold.mcp.update.test.stub +40 -0
- package/stubs/scaffold.migration.stub +2 -0
- package/stubs/scaffold.model.stub +35 -0
- package/stubs/scaffold.model.test.stub +25 -0
- package/stubs/scaffold.test-database.stub +33 -0
- package/stubs/scaffold.test-mcp.stub +92 -0
- package/stubs/scaffold.validator.stub +18 -0
- package/stubs/scaffold.validator.test.stub +26 -0
- package/templates/app/AGENTS.md +163 -0
- package/templates/app/CLAUDE.md +1 -0
- package/templates/app/README.md +28 -13
- package/templates/app/app/commands/console.test.ts +26 -0
- package/templates/app/app/commands/console.ts +19 -0
- package/templates/app/app/commands/db/fresh.test.ts +57 -0
- package/templates/app/app/commands/db/fresh.ts +37 -0
- package/templates/app/app/commands/db/migrate.test.ts +17 -1
- package/templates/app/app/commands/db/migrate.ts +51 -18
- package/templates/app/app/commands/db/prepare.test.ts +39 -0
- package/templates/app/app/commands/db/prepare.ts +35 -0
- package/templates/app/app/commands/db/seed.test.ts +38 -0
- package/templates/app/app/commands/db/seed.ts +26 -0
- package/templates/app/app/commands/deploy.test.ts +34 -0
- package/templates/app/app/commands/deploy.ts +18 -0
- package/templates/app/app/commands/emails/preview.test.tsx +63 -0
- package/templates/app/app/commands/emails/preview.ts +24 -0
- package/templates/app/app/commands/index.ts +57 -2
- package/templates/app/app/emails/index.ts +10 -0
- package/templates/app/app/http/middleware/access.test.ts +43 -0
- package/templates/app/app/http/middleware/access.ts +41 -0
- package/templates/app/app/http/middleware/api.ts +12 -3
- package/templates/app/app/http/middleware/page.test.ts +4 -1
- package/templates/app/app/http/middleware/page.ts +7 -5
- package/templates/app/app/initializers/cli.ts +28 -2
- package/templates/app/app/initializers/dispatcher.ts +9 -1
- package/templates/app/app/initializers/mail-transport.test.ts +27 -0
- package/templates/app/app/initializers/mail-transport.ts +26 -0
- package/templates/app/app/initializers/mail.test.ts +17 -17
- package/templates/app/app/initializers/mail.ts +15 -7
- package/templates/app/app/initializers/router.test.ts +7 -0
- package/templates/app/app/initializers/router.tsx +13 -3
- package/templates/app/app/jobs/email.test.tsx +70 -0
- package/templates/app/app/jobs/email.ts +16 -0
- package/templates/app/app/jobs/index.ts +6 -2
- package/templates/app/app/policies/abilities.ts +13 -0
- package/templates/app/app/policies/policy.test.ts +15 -0
- package/templates/app/app/policies/policy.ts +30 -0
- package/templates/app/app/services/commands.ts +30 -0
- package/templates/app/app/services/migrations.test.ts +48 -1
- package/templates/app/app/services/migrations.ts +66 -9
- package/templates/app/app/test/local-database.ts +67 -0
- package/templates/app/app/test/session.ts +28 -0
- package/templates/app/bootstrap/console.ts +13 -0
- package/templates/app/cloudflare.config.ts +3 -3
- package/templates/app/database/seed.ts +12 -0
- package/templates/app/package.json +2 -1
- package/stubs/policy.stub +0 -16
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* The email registry: every email `app/emails/index.ts` declares, mapped onto its template
|
|
3
|
+
* through `lazy()`, so a send imports only the template it renders. It holds no transport, so
|
|
4
|
+
* the Worker's mailers and the command line share it; `sdxc make email` adds the mapping.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { env } from "cloudflare:workers";
|
|
7
|
+
import { createMail } from "@sdxc/mail";
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
import { translate } from "~/app/initializers/i18n";
|
|
10
|
+
|
|
11
|
+
/** The registry the router, the job dispatcher and the command line hand their mailers. */
|
|
12
|
+
export const mail = createMail({ translator: translate });
|
|
13
|
+
|
|
14
|
+
declare module "@sdxc/mail" {
|
|
15
|
+
/** Types the `t()` every template receives with the keys of the app's message bundles. */
|
|
16
|
+
interface MailTypes {
|
|
17
|
+
translate: ReturnType<typeof translate>["t"];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -52,6 +52,13 @@ describe("router", () => {
|
|
|
52
52
|
expect(SECURITY_TXT.expires.getTime() - Date.now()).toBeGreaterThan(RENEWAL_WINDOW_MS);
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
+
test("previews the mapped emails at /_emails while developing", async () => {
|
|
56
|
+
let response = await createWebRouter().fetch("https://example.com/_emails");
|
|
57
|
+
|
|
58
|
+
expect(response.status).toBe(200);
|
|
59
|
+
expect(await response.text()).toContain("Email previews");
|
|
60
|
+
});
|
|
61
|
+
|
|
55
62
|
test("redirects the www. host to the apex domain", async () => {
|
|
56
63
|
let response = await createWebRouter().fetch("https://www.example.com/sitemap.xml");
|
|
57
64
|
|
|
@@ -11,7 +11,8 @@ import { database } from "@sdxc/database-middleware";
|
|
|
11
11
|
import getClientIP from "@sdxc/get-client-ip/middleware";
|
|
12
12
|
import { lazy } from "@sdxc/lazy-route";
|
|
13
13
|
import { log } from "@sdxc/logger/middleware";
|
|
14
|
-
import
|
|
14
|
+
import mailer from "@sdxc/mail/middleware";
|
|
15
|
+
import { previews } from "@sdxc/mail/previews";
|
|
15
16
|
import { noWWW } from "@sdxc/no-www-middleware";
|
|
16
17
|
import { addressKey, CloudflareAdapter } from "@sdxc/rate-limit";
|
|
17
18
|
import { rateLimit } from "@sdxc/rate-limit/middleware";
|
|
@@ -24,9 +25,12 @@ import { asyncContext } from "remix/middleware/async-context";
|
|
|
24
25
|
import { createRouter } from "remix/router";
|
|
25
26
|
|
|
26
27
|
import serverTiming from "~/app/http/middleware/server-timing";
|
|
28
|
+
import { assetResolver } from "~/app/initializers/assets";
|
|
27
29
|
import { openDatabase } from "~/app/initializers/database";
|
|
30
|
+
import { SUPPORTED_LANGUAGES } from "~/app/initializers/i18n";
|
|
28
31
|
import { logger } from "~/app/initializers/logger";
|
|
29
|
-
import {
|
|
32
|
+
import { mail } from "~/app/initializers/mail";
|
|
33
|
+
import { queue, transport } from "~/app/initializers/mail-transport";
|
|
30
34
|
import registry from "~/app/models";
|
|
31
35
|
import { MAIL_FROM } from "~/config/constants";
|
|
32
36
|
import problems from "~/config/problems";
|
|
@@ -48,6 +52,7 @@ declare module "remix/router" {
|
|
|
48
52
|
* Builds the router the Worker forwards each request to. Its middleware is what pages and
|
|
49
53
|
* endpoints both need, written inline so {@link AppContext} reads what each one publishes; a
|
|
50
54
|
* controller adds its contract's chain, `app/http/middleware/page.ts` or `api.ts`, itself.
|
|
55
|
+
* While developing, `/_emails` previews every mapped email in every supported language.
|
|
51
56
|
*/
|
|
52
57
|
export function createWebRouter() {
|
|
53
58
|
let router = createRouter({
|
|
@@ -69,7 +74,12 @@ export function createWebRouter() {
|
|
|
69
74
|
}),
|
|
70
75
|
database(openDatabase()),
|
|
71
76
|
models(registry, (ctx) => ({ db: ctx.db })),
|
|
72
|
-
mail
|
|
77
|
+
previews(mail, {
|
|
78
|
+
locales: SUPPORTED_LANGUAGES,
|
|
79
|
+
enabled: import.meta.env.DEV,
|
|
80
|
+
stylesheets: () => assetResolver.getStylesheets("resources/layouts/document.tsx"),
|
|
81
|
+
}),
|
|
82
|
+
mailer({ transport, from: MAIL_FROM, mail, queue }),
|
|
73
83
|
],
|
|
74
84
|
});
|
|
75
85
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The job that delivers queued email: it sends what `ctx.email.queue()` handed the queue, gives
|
|
3
|
+
* up on a delivery no retry can send, and asks for another try when the provider fails.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { NormalizedMessage, QueuedEmail, SentMessage, Transport } from "@sdxc/mail";
|
|
7
|
+
import type { Result } from "@sdxc/result";
|
|
8
|
+
|
|
9
|
+
import { createJobContext } from "@sdxc/jobs";
|
|
10
|
+
import { NonRetriable, Retry } from "@sdxc/jobs/errors";
|
|
11
|
+
import { createEmail, createMail, email, emails, Mailer, MailError } from "@sdxc/mail";
|
|
12
|
+
import { MemoryTransport } from "@sdxc/mail/memory";
|
|
13
|
+
import { CurrentMailer } from "@sdxc/mail/middleware/jobs";
|
|
14
|
+
import { failure } from "@sdxc/result";
|
|
15
|
+
import * as s from "remix/data-schema";
|
|
16
|
+
import { describe, expect, test } from "vitest";
|
|
17
|
+
|
|
18
|
+
import jobs from "~/app/jobs";
|
|
19
|
+
import handler from "~/app/jobs/email";
|
|
20
|
+
import { MAIL_FROM } from "~/config/constants";
|
|
21
|
+
|
|
22
|
+
/** An email declared for these tests alone. */
|
|
23
|
+
const EMAILS = emails({ greeting: email({ props: s.object({ name: s.string() }) }) });
|
|
24
|
+
|
|
25
|
+
/** A transport whose provider is down. */
|
|
26
|
+
class FailingTransport implements Transport {
|
|
27
|
+
async send(_message: NormalizedMessage): Promise<Result<SentMessage, MailError>> {
|
|
28
|
+
return failure(new MailError("The provider is down."));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Runs the job for `input` with a mailer over `transport` that sends the test email. */
|
|
33
|
+
async function run(input: QueuedEmail, transport: Transport) {
|
|
34
|
+
let mail = createMail();
|
|
35
|
+
mail.map(
|
|
36
|
+
EMAILS.greeting,
|
|
37
|
+
createEmail(EMAILS.greeting, {
|
|
38
|
+
subject: ({ name }) => `Hello, ${name}`,
|
|
39
|
+
body: (handle) => () => <p>Hello {handle.props.name}</p>,
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
let ctx = createJobContext(jobs.email, { id: "message-1", attempts: 1, input });
|
|
43
|
+
ctx.set(CurrentMailer, new Mailer({ transport, from: MAIL_FROM, mail }), { property: "email" });
|
|
44
|
+
await handler(ctx);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe("email", () => {
|
|
48
|
+
test("sends the queued email", async () => {
|
|
49
|
+
let transport = new MemoryTransport();
|
|
50
|
+
|
|
51
|
+
await run({ email: "greeting", to: "ada@example.com", props: { name: "Ada" } }, transport);
|
|
52
|
+
|
|
53
|
+
expect(transport.last?.subject).toBe("Hello, Ada");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("gives up on an email nothing maps", async () => {
|
|
57
|
+
let sent = run({ email: "missing", to: "ada@example.com", props: {} }, new MemoryTransport());
|
|
58
|
+
|
|
59
|
+
await expect(sent).rejects.toBeInstanceOf(NonRetriable);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("retries when the provider fails", async () => {
|
|
63
|
+
let sent = run(
|
|
64
|
+
{ email: "greeting", to: "ada@example.com", props: { name: "Ada" } },
|
|
65
|
+
new FailingTransport(),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
await expect(sent).rejects.toBeInstanceOf(Retry);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delivers a queued email. A delivery no retry can send (an email nothing maps, props its
|
|
3
|
+
* schema refuses) ends here; any other failure, such as the provider being down, is retried.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createJobHandler } from "@sdxc/jobs";
|
|
7
|
+
import { EmailRefusedError } from "@sdxc/mail";
|
|
8
|
+
import { isFailure } from "@sdxc/result";
|
|
9
|
+
|
|
10
|
+
import jobs from "~/app/jobs";
|
|
11
|
+
|
|
12
|
+
export default createJobHandler(jobs.email, async (ctx) => {
|
|
13
|
+
let sent = await ctx.email.deliver(ctx.input);
|
|
14
|
+
if (isFailure(sent) && sent.error instanceof EmailRefusedError) ctx.exit(sent.error.message);
|
|
15
|
+
if (isFailure(sent)) ctx.retry({ cause: sent.error });
|
|
16
|
+
});
|
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
* a job without loading the handler that runs it.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { jobs } from "@sdxc/jobs";
|
|
7
|
+
import { job, jobs } from "@sdxc/jobs";
|
|
8
|
+
import { EMAIL_DELIVERY } from "@sdxc/mail";
|
|
8
9
|
|
|
9
10
|
/** The app's jobs; `sdxc make job <name>` declares one here and maps its handler. */
|
|
10
|
-
export default jobs({
|
|
11
|
+
export default jobs({
|
|
12
|
+
/** Delivers what `ctx.email.queue()` handed the queue, for every declared email. */
|
|
13
|
+
email: job({ input: EMAIL_DELIVERY }),
|
|
14
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything a visitor can do in the app, named once so a page, an endpoint, a tool and a test
|
|
3
|
+
* all check the same ability. `sdxc make policy <resource>` adds a resource's abilities here, and
|
|
4
|
+
* importing the catalog does no work, so browser code reads it too.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { abilities } from "@sdxc/authz";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Each ability by its dot-joined keys, such as `post.update`. One declared with a `context` is
|
|
11
|
+
* checked against a record; one without is checked with nothing.
|
|
12
|
+
*/
|
|
13
|
+
export default abilities({});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The policy compiles, so every grant names an ability the catalog declares and every condition
|
|
3
|
+
* reads a fact or record it is given; `sdxc make policy` writes a test per resource beside it.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { isSuccess } from "@sdxc/result";
|
|
7
|
+
import { describe, expect, test } from "vitest";
|
|
8
|
+
|
|
9
|
+
import policy from "~/app/policies/policy";
|
|
10
|
+
|
|
11
|
+
describe("policy", () => {
|
|
12
|
+
test("compiles", () => {
|
|
13
|
+
expect(isSuccess(policy.compile())).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who may do what. `everyone` lists what any visitor may do, signed in or not, and `member` what
|
|
3
|
+
* a signed-in visitor adds; `sdxc make policy` grants a resource's reads to everyone and its
|
|
4
|
+
* writes to members. A guard under `guards` refuses whatever role is held.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { definePolicy, fact } from "@sdxc/authz";
|
|
8
|
+
|
|
9
|
+
import abilities from "~/app/policies/abilities";
|
|
10
|
+
|
|
11
|
+
/** The signed-in visitor, as a condition reads it under `actor`; absent for a guest. */
|
|
12
|
+
export interface Actor {
|
|
13
|
+
id: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The app's policy, bound to each request by `app/http/middleware/access.ts`. */
|
|
17
|
+
const policy = definePolicy(abilities, {
|
|
18
|
+
facts: { actor: fact<Actor>({ optional: true }) },
|
|
19
|
+
everyone: [],
|
|
20
|
+
roles: { member: [] },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
declare module "@sdxc/authz" {
|
|
24
|
+
/** Types `ctx.access` and every check against this policy's catalog and facts. */
|
|
25
|
+
interface AuthzTypes {
|
|
26
|
+
policy: typeof policy;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default policy;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs one of the app's own commands from inside another, as typing it would, so a command
|
|
3
|
+
* composed of others (`db prepare`, `db fresh --seed`) behaves exactly like its parts.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { AnyCommandContext, CommandResult } from "@sdxc/cli";
|
|
7
|
+
|
|
8
|
+
import { exit, success } from "@sdxc/cli";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Runs `argv` on the app's command line with the calling run's streams, directory and
|
|
12
|
+
* environment, so its output lands where the caller's would. Its failure has been printed
|
|
13
|
+
* already, so the caller fails with the same exit code and no second message.
|
|
14
|
+
*
|
|
15
|
+
* @example let migrated = await runCommand(ctx, ["db", "migrate"]);
|
|
16
|
+
*/
|
|
17
|
+
export async function runCommand(
|
|
18
|
+
ctx: AnyCommandContext,
|
|
19
|
+
argv: readonly string[],
|
|
20
|
+
): Promise<CommandResult> {
|
|
21
|
+
let { cli } = await import("~/app/initializers/cli");
|
|
22
|
+
let code = await cli.run(argv, {
|
|
23
|
+
cwd: ctx.cwd,
|
|
24
|
+
env: ctx.env,
|
|
25
|
+
stdout: { write: ctx.stdout },
|
|
26
|
+
stderr: { write: ctx.stderr },
|
|
27
|
+
signal: ctx.signal,
|
|
28
|
+
});
|
|
29
|
+
return code === 0 ? success() : exit(code);
|
|
30
|
+
}
|
|
@@ -6,7 +6,12 @@ import { openDatabase } from "@sdxc/cloudflare-mocks/sqlite";
|
|
|
6
6
|
import { isFailure, unwrap } from "@sdxc/result";
|
|
7
7
|
import { describe, expect, test } from "vitest";
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
applyMigrations,
|
|
11
|
+
dropTables,
|
|
12
|
+
hasAppliedMigrations,
|
|
13
|
+
pendingMigrations,
|
|
14
|
+
} from "~/app/services/migrations";
|
|
10
15
|
|
|
11
16
|
/** Two migrations, given out of order to show the runner sorts them. */
|
|
12
17
|
const MIGRATIONS = [
|
|
@@ -43,3 +48,45 @@ describe("applyMigrations", () => {
|
|
|
43
48
|
]);
|
|
44
49
|
});
|
|
45
50
|
});
|
|
51
|
+
|
|
52
|
+
describe("pendingMigrations", () => {
|
|
53
|
+
test("lists what applyMigrations would run, and applies nothing", () => {
|
|
54
|
+
let database = openDatabase(":memory:");
|
|
55
|
+
unwrap(applyMigrations(database, MIGRATIONS.slice(1)));
|
|
56
|
+
|
|
57
|
+
let pending = pendingMigrations(database, MIGRATIONS);
|
|
58
|
+
|
|
59
|
+
expect(pending.map((migration) => migration.name)).toEqual(["0002_AddTitle.sql"]);
|
|
60
|
+
expect(database.query("SELECT count(*) AS applied FROM d1_migrations").all()).toEqual([
|
|
61
|
+
{ applied: 1 },
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("dropTables", () => {
|
|
67
|
+
test("drops the migrations' tables and views, and the journal, so the chain runs again", () => {
|
|
68
|
+
let database = openDatabase(":memory:");
|
|
69
|
+
unwrap(applyMigrations(database, MIGRATIONS));
|
|
70
|
+
database.exec(
|
|
71
|
+
"CREATE TABLE comments (id INTEGER PRIMARY KEY AUTOINCREMENT, post_id TEXT REFERENCES posts (id)); CREATE VIEW titles AS SELECT title FROM posts;",
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
let dropped = unwrap(dropTables(database));
|
|
75
|
+
|
|
76
|
+
expect(dropped.toSorted()).toEqual(["comments", "d1_migrations", "posts"]);
|
|
77
|
+
expect(
|
|
78
|
+
database.query("SELECT name FROM sqlite_master WHERE name NOT LIKE 'sqlite_%'").all(),
|
|
79
|
+
).toEqual([]);
|
|
80
|
+
expect(unwrap(applyMigrations(database, MIGRATIONS))).toHaveLength(2);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("hasAppliedMigrations", () => {
|
|
85
|
+
test("tells a new database from one a migration ran on", () => {
|
|
86
|
+
let database = openDatabase(":memory:");
|
|
87
|
+
let before = hasAppliedMigrations(database);
|
|
88
|
+
unwrap(applyMigrations(database, MIGRATIONS));
|
|
89
|
+
|
|
90
|
+
expect([before, hasAppliedMigrations(database)]).toEqual([false, true]);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Applies a chain of SQL migrations the way `cf d1 migrations apply` does: in name order, each
|
|
3
3
|
* once, recorded in the same `d1_migrations` table, so local and remote databases agree on
|
|
4
|
-
* what ran whichever tool applied it.
|
|
4
|
+
* what ran whichever tool applied it. `dropTables` empties a database for the chain to rerun.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
|
|
7
10
|
import type { Result } from "@sdxc/result";
|
|
8
11
|
|
|
9
12
|
import { failure, success } from "@sdxc/result";
|
|
10
13
|
|
|
14
|
+
/** The migration chain `sdxc make migration` writes into, relative to the project's root. */
|
|
15
|
+
export const MIGRATIONS_DIRECTORY = "database/migrations";
|
|
16
|
+
|
|
11
17
|
/** One migration file: its name, as `0001_CreatePosts.sql`, and its SQL. */
|
|
12
18
|
export interface Migration {
|
|
13
19
|
name: string;
|
|
@@ -20,6 +26,15 @@ export interface MigrationDatabase {
|
|
|
20
26
|
query(sql: string): { all(): unknown[] };
|
|
21
27
|
}
|
|
22
28
|
|
|
29
|
+
/** Every `.sql` file in the chain under `root`, with its SQL. */
|
|
30
|
+
export async function readMigrations(root: string): Promise<Migration[]> {
|
|
31
|
+
let directory = join(root, MIGRATIONS_DIRECTORY);
|
|
32
|
+
let names = (await readdir(directory)).filter((name) => name.endsWith(".sql"));
|
|
33
|
+
return Promise.all(
|
|
34
|
+
names.map(async (name) => ({ name, sql: await readFile(join(directory, name), "utf8") })),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
23
38
|
/** The table D1 records applied migrations in, as Wrangler and `cf` create it. */
|
|
24
39
|
const JOURNAL = `CREATE TABLE IF NOT EXISTS "d1_migrations"(
|
|
25
40
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -27,6 +42,25 @@ const JOURNAL = `CREATE TABLE IF NOT EXISTS "d1_migrations"(
|
|
|
27
42
|
applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
28
43
|
)`;
|
|
29
44
|
|
|
45
|
+
/** Whether any migration ran on the database, which tells a new database from one in use. */
|
|
46
|
+
export function hasAppliedMigrations(database: MigrationDatabase): boolean {
|
|
47
|
+
database.exec(JOURNAL);
|
|
48
|
+
return database.query("SELECT 1 FROM d1_migrations LIMIT 1").all().length > 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The migrations the journal lacks, in the order `applyMigrations` runs them. */
|
|
52
|
+
export function pendingMigrations(
|
|
53
|
+
database: MigrationDatabase,
|
|
54
|
+
migrations: readonly Migration[],
|
|
55
|
+
): Migration[] {
|
|
56
|
+
database.exec(JOURNAL);
|
|
57
|
+
let rows = database.query("SELECT name FROM d1_migrations").all() as { name: string }[];
|
|
58
|
+
let applied = new Set(rows.map((row) => row.name));
|
|
59
|
+
return [...migrations]
|
|
60
|
+
.filter((migration) => !applied.has(migration.name))
|
|
61
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
62
|
+
}
|
|
63
|
+
|
|
30
64
|
/**
|
|
31
65
|
* Runs every migration the journal lacks, each in its own transaction with its journal row, so
|
|
32
66
|
* a failing migration leaves the database as the previous one left it.
|
|
@@ -37,15 +71,8 @@ export function applyMigrations(
|
|
|
37
71
|
database: MigrationDatabase,
|
|
38
72
|
migrations: readonly Migration[],
|
|
39
73
|
): Result<string[], Error> {
|
|
40
|
-
database.exec(JOURNAL);
|
|
41
|
-
let rows = database.query("SELECT name FROM d1_migrations").all() as { name: string }[];
|
|
42
|
-
let applied = new Set(rows.map((row) => row.name));
|
|
43
|
-
let pending = [...migrations]
|
|
44
|
-
.filter((migration) => !applied.has(migration.name))
|
|
45
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
|
46
|
-
|
|
47
74
|
let names: string[] = [];
|
|
48
|
-
for (let migration of
|
|
75
|
+
for (let migration of pendingMigrations(database, migrations)) {
|
|
49
76
|
try {
|
|
50
77
|
database.exec(
|
|
51
78
|
`BEGIN;\n${migration.sql}\n;INSERT INTO d1_migrations (name) VALUES ('${migration.name.replaceAll("'", "''")}');\nCOMMIT;`,
|
|
@@ -58,3 +85,33 @@ export function applyMigrations(
|
|
|
58
85
|
}
|
|
59
86
|
return success(names);
|
|
60
87
|
}
|
|
88
|
+
|
|
89
|
+
/** Tables SQLite and the local Workers runtime keep for themselves, which a reset leaves alone. */
|
|
90
|
+
const RESERVED_TABLE = /^(sqlite_|_cf_)/;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Drops every view and table the migrations made, `d1_migrations` included, so the next
|
|
94
|
+
* `applyMigrations` runs the whole chain on an empty database. Indexes and triggers go with
|
|
95
|
+
* their tables, and foreign keys are off meanwhile, so the drop order never matters.
|
|
96
|
+
*
|
|
97
|
+
* @returns The names of the tables dropped, views left out.
|
|
98
|
+
*/
|
|
99
|
+
export function dropTables(database: MigrationDatabase): Result<string[], Error> {
|
|
100
|
+
let rows = database
|
|
101
|
+
.query(
|
|
102
|
+
"SELECT type, name FROM sqlite_master WHERE type IN ('view', 'table') ORDER BY type DESC",
|
|
103
|
+
)
|
|
104
|
+
.all() as { type: "view" | "table"; name: string }[];
|
|
105
|
+
let dropped = rows.filter((row) => !RESERVED_TABLE.test(row.name));
|
|
106
|
+
let statements = dropped.map(
|
|
107
|
+
(row) => `DROP ${row.type.toUpperCase()} IF EXISTS "${row.name.replaceAll('"', '""')}";`,
|
|
108
|
+
);
|
|
109
|
+
try {
|
|
110
|
+
database.exec(
|
|
111
|
+
`PRAGMA foreign_keys = OFF;\n${statements.join("\n")}\nPRAGMA foreign_keys = ON;`,
|
|
112
|
+
);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
return failure(new Error("Dropping the tables failed", { cause: error }));
|
|
115
|
+
}
|
|
116
|
+
return success(dropped.filter((row) => row.type === "table").map((row) => row.name));
|
|
117
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A temporary project for a command test: its own migration chain and local database file,
|
|
3
|
+
* installed in place of the project's own, so `db fresh`, `db seed` and `db prepare` run for
|
|
4
|
+
* real and leave the rows `bun dev` serves untouched; `postsSeed` stands in for the app's seed.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
|
|
11
|
+
import { createModel, createModels } from "@sdxc/data-model";
|
|
12
|
+
import { defineSeed } from "@sdxc/data-model/seed";
|
|
13
|
+
import { unwrap } from "@sdxc/result";
|
|
14
|
+
import { column as c, table } from "remix/data-table";
|
|
15
|
+
import { vi } from "vitest";
|
|
16
|
+
|
|
17
|
+
/** Where the temporary project keeps its database, and the project's root. */
|
|
18
|
+
export interface TemporaryProject {
|
|
19
|
+
root: string;
|
|
20
|
+
databaseFile: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Replaces `~/app/initializers/local-database` with one rooted in a new temporary folder that
|
|
25
|
+
* holds `migrations`. Call it before importing the command line, which reads the replacement.
|
|
26
|
+
*
|
|
27
|
+
* @param migrations Each migration's SQL by file name, as `database/migrations/` would hold it.
|
|
28
|
+
* @example let project = useTemporaryProject({ "0001_CreatePosts.sql": "CREATE TABLE posts (id TEXT)" });
|
|
29
|
+
*/
|
|
30
|
+
export function useTemporaryProject(
|
|
31
|
+
migrations: Readonly<Record<string, string>>,
|
|
32
|
+
): TemporaryProject {
|
|
33
|
+
let root = mkdtempSync(join(tmpdir(), "app-"));
|
|
34
|
+
let directory = join(root, "database/migrations");
|
|
35
|
+
mkdirSync(directory, { recursive: true });
|
|
36
|
+
for (let [name, sql] of Object.entries(migrations)) writeFileSync(join(directory, name), sql);
|
|
37
|
+
let databaseFile = join(root, "local.sqlite");
|
|
38
|
+
|
|
39
|
+
vi.doMock("~/app/initializers/local-database", async (importOriginal) => {
|
|
40
|
+
let original = await importOriginal<typeof import("~/app/initializers/local-database")>();
|
|
41
|
+
return {
|
|
42
|
+
...original,
|
|
43
|
+
PROJECT_ROOT: root,
|
|
44
|
+
LOCAL_DATABASE_FILE: databaseFile,
|
|
45
|
+
openLocalDatabase: (filename = databaseFile) => original.openLocalDatabase(filename),
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
return { root, databaseFile };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A `posts` table holding only an id, as the temporary project's migration creates it. */
|
|
52
|
+
const POSTS = table({ name: "posts", columns: { id: c.text().primaryKey() } });
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A seed with one `posts` step creating a post with each id, through a model over `POSTS`.
|
|
56
|
+
*
|
|
57
|
+
* @example vi.doMock("~/database/seed", () => ({ default: postsSeed("p1") }));
|
|
58
|
+
*/
|
|
59
|
+
export function postsSeed(...ids: string[]) {
|
|
60
|
+
let Post = createModel(POSTS, {});
|
|
61
|
+
let registry = createModels({ post: Post });
|
|
62
|
+
return defineSeed(registry, {
|
|
63
|
+
posts: async ({ models }) => {
|
|
64
|
+
for (let id of ids) unwrap(await models.post.create({ id }));
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signs a visitor in for a test the way the app does: a request through the session middleware
|
|
3
|
+
* stores them under the session's `actor` key, and the cookie it answers is what a test sends
|
|
4
|
+
* back, so a request carrying it reaches every page as that `member`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { session } from "remix/middleware/session";
|
|
8
|
+
import { createRouter } from "remix/router";
|
|
9
|
+
|
|
10
|
+
import type { Actor } from "~/app/policies/policy";
|
|
11
|
+
|
|
12
|
+
import { ACTOR_KEY } from "~/app/http/middleware/access";
|
|
13
|
+
import { sessionCookie, sessionStorage } from "~/app/initializers/session";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Stores `actor` in a new session and answers its `Cookie` header.
|
|
17
|
+
*
|
|
18
|
+
* @example let cookie = await signIn(); await router.fetch(new Request(url, { headers: { cookie } }));
|
|
19
|
+
*/
|
|
20
|
+
export async function signIn(actor: Actor = { id: "1" }): Promise<string> {
|
|
21
|
+
let router = createRouter({ middleware: [session(sessionCookie, sessionStorage)] });
|
|
22
|
+
router.post("/", (ctx) => {
|
|
23
|
+
ctx.session.set(ACTOR_KEY, actor);
|
|
24
|
+
return new Response(null, { status: 204 });
|
|
25
|
+
});
|
|
26
|
+
let response = await router.fetch(new Request("https://example.com/", { method: "POST" }));
|
|
27
|
+
return response.headers.get("set-cookie")?.split(";")[0] ?? "";
|
|
28
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The REPL's entry point, preloaded into Bun's REPL by `sdxc run console`: it opens the local
|
|
3
|
+
* database `bun dev` serves and binds the app's models to it, as `db` and `models` on
|
|
4
|
+
* `globalThis`, so every line typed at the prompt reads and writes the dev server's rows.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { openLocalDatabase } from "~/app/initializers/local-database";
|
|
8
|
+
import registry from "~/app/models";
|
|
9
|
+
|
|
10
|
+
/** The local database, open for the REPL's whole session. */
|
|
11
|
+
const DATABASE = openLocalDatabase();
|
|
12
|
+
|
|
13
|
+
Object.assign(globalThis, { db: DATABASE, models: registry.bind({ db: DATABASE }) });
|
|
@@ -22,7 +22,7 @@ export default defineConfig({
|
|
|
22
22
|
triggers: [triggers.queue({ name: manifest.name })],
|
|
23
23
|
env: {
|
|
24
24
|
/**
|
|
25
|
-
* The app's database. `cf d1 create <name>` prints the id to put here, where the
|
|
25
|
+
* The app's database. `cf d1 create --name <name>` prints the id to put here, where the
|
|
26
26
|
* `sdxc run db` commands read it; until then, `bun dev` runs on a local copy.
|
|
27
27
|
*/
|
|
28
28
|
DB: bindings.d1({ name: manifest.name, id: "00000000-0000-4000-8000-000000000000" }),
|
|
@@ -31,7 +31,7 @@ export default defineConfig({
|
|
|
31
31
|
* Routing enabled, so set `MAIL_FROM` in `config/constants.ts` to one before deploying.
|
|
32
32
|
*/
|
|
33
33
|
EMAIL: bindings.sendEmail(),
|
|
34
|
-
/** Where the job dispatcher enqueues; `cf queues create <name>` before the first deploy. */
|
|
34
|
+
/** Where the job dispatcher enqueues; `cf queues create --queue-name <name>` before the first deploy. */
|
|
35
35
|
QUEUE: bindings.queue({ name: manifest.name }),
|
|
36
36
|
/**
|
|
37
37
|
* 100 requests per minute per client address, across every route. The router's
|
|
@@ -39,7 +39,7 @@ export default defineConfig({
|
|
|
39
39
|
*/
|
|
40
40
|
RATE_LIMITER: bindings.rateLimit({ namespace: "1001", simple: { limit: 100, period: 60 } }),
|
|
41
41
|
/**
|
|
42
|
-
* Visitors' sessions. `cf kv
|
|
42
|
+
* Visitors' sessions. `cf kv namespaces create --title <name>` prints the id to put here; until
|
|
43
43
|
* then, `bun dev` keeps sessions in a local copy.
|
|
44
44
|
*/
|
|
45
45
|
SESSIONS: bindings.kv({ id: "00000000000000000000000000000000" }),
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rows `sdxc run db seed` writes into the local database: named steps, run in order, each
|
|
3
|
+
* writing fixed rows through `models` or generated ones through `factories`, with the
|
|
4
|
+
* factories in `database/factories/`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { defineSeed } from "@sdxc/data-model/seed";
|
|
8
|
+
|
|
9
|
+
import registry from "~/app/models";
|
|
10
|
+
|
|
11
|
+
/** Add a step per set of rows, as `posts: ({ factories }) => factories.createMany(PostFactory, 10)`. */
|
|
12
|
+
export default defineSeed(registry, {});
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vp build",
|
|
7
|
-
"cf:deploy": "cf deploy --prebuilt",
|
|
8
7
|
"check": "vp check",
|
|
9
8
|
"cli": "bun ./bootstrap/cli.ts",
|
|
10
9
|
"dev": "vp dev",
|
|
@@ -15,6 +14,7 @@
|
|
|
15
14
|
"dependencies": {
|
|
16
15
|
"@pitlane/assets": "0.1.0",
|
|
17
16
|
"@sdxc/assets-middleware": "0.0.1",
|
|
17
|
+
"@sdxc/authz": "0.0.1",
|
|
18
18
|
"@sdxc/captcha": "0.0.1",
|
|
19
19
|
"@sdxc/cli": "0.0.1",
|
|
20
20
|
"@sdxc/data-model": "0.0.1",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@sdxc/rate-limit": "0.0.1",
|
|
37
37
|
"@sdxc/result": "0.0.1",
|
|
38
38
|
"@sdxc/robots": "0.0.1",
|
|
39
|
+
"@sdxc/sample": "0.0.1",
|
|
39
40
|
"@sdxc/security-headers": "0.0.1",
|
|
40
41
|
"@sdxc/seo": "0.0.1",
|
|
41
42
|
"@sdxc/server-timing": "0.0.1",
|
package/stubs/policy.stub
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The {{title}} policy: describe who may do what, and why the rule sits here.
|
|
3
|
-
*
|
|
4
|
-
* @see {@link https://sdxc.dev/docs/identity-and-security/authorization}
|
|
5
|
-
* @see {@link https://sdxc.dev/api/authz}{{header}}
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/** Who an authorization rule is asked about; `null` for an anonymous visitor. */
|
|
9
|
-
export interface Actor {
|
|
10
|
-
id: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Whether `actor` passes the {{title}} rule. */
|
|
14
|
-
export function {{key}}(actor: Actor | null): boolean {
|
|
15
|
-
return actor !== null;
|
|
16
|
-
}
|