@sdxc/kit 2026.10.16 → 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 +391 -20
- package/changelog.jsonl +1160 -1035
- package/config.schema.json +47 -1
- package/dist/author.d.ts +36 -0
- package/dist/author.js +107 -0
- package/dist/cli.js +12 -0
- package/dist/commands/create.js +9 -4
- 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 +18 -2
- package/dist/commands/run.js +35 -12
- 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.d.ts +8 -1
- package/dist/create/templates.js +26 -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/init.d.ts +5 -3
- package/dist/init.js +15 -7
- 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 +32 -4
- package/dist/make/declare.js +405 -27
- 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 +43 -14
- 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 -25
- package/dist/make/kinds.d.ts +31 -3
- package/dist/make/kinds.js +82 -9
- 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/testing.d.ts +12 -2
- package/dist/testing.js +22 -3
- 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/command.stub +4 -0
- package/stubs/command.test.stub +3 -0
- package/stubs/controller.api.resource.stub +23 -0
- package/stubs/controller.api.stub +21 -0
- package/stubs/controller.api.test.stub +18 -0
- package/stubs/controller.form.stub +40 -10
- package/stubs/controller.form.test.stub +61 -0
- package/stubs/controller.resource.form.stub +67 -0
- package/stubs/controller.resource.stub +28 -0
- package/stubs/controller.stub +15 -8
- package/stubs/controller.test.stub +3 -0
- package/stubs/email.stub +15 -38
- package/stubs/email.test.stub +12 -7
- package/stubs/factory.stub +4 -1
- package/stubs/initializer.stub +2 -0
- package/stubs/initializer.test.stub +3 -0
- package/stubs/job.cron.stub +4 -0
- package/stubs/job.stub +4 -0
- package/stubs/job.test.stub +3 -0
- package/stubs/mcp.resource.stub +3 -0
- package/stubs/mcp.stub +3 -0
- package/stubs/mcp.test.stub +3 -0
- package/stubs/middleware.stub +6 -1
- package/stubs/middleware.test.stub +3 -0
- package/stubs/model.stub +12 -3
- package/stubs/model.test.stub +3 -0
- package/stubs/policy.test.stub +36 -7
- 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/stubs/service.stub +4 -0
- package/stubs/service.test.stub +3 -0
- package/stubs/validator.stub +3 -0
- package/stubs/validator.test.stub +3 -0
- package/templates/app/.env.example +16 -0
- package/templates/app/AGENTS.md +163 -0
- package/templates/app/CLAUDE.md +1 -0
- package/templates/app/README.md +79 -37
- package/templates/app/app/commands/about.test.ts +1 -1
- 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/console.ts +6 -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 +46 -0
- package/templates/app/app/commands/db/migrate.ts +88 -0
- 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 +72 -1
- package/templates/app/app/commands/typegen.test.ts +17 -0
- package/templates/app/app/commands/typegen.ts +16 -0
- package/templates/app/app/emails/index.ts +10 -0
- package/templates/app/app/http/controllers/api/health.tsx +15 -0
- package/templates/app/app/http/controllers/api/not-found.tsx +16 -0
- package/templates/app/app/http/controllers/api/openapi.tsx +17 -0
- package/templates/app/app/http/controllers/home.tsx +21 -13
- package/templates/app/app/http/controllers/mcp.tsx +16 -0
- package/templates/app/app/http/controllers/not-found.tsx +23 -18
- package/templates/app/app/http/controllers/robots.test.ts +18 -0
- package/templates/app/app/http/controllers/robots.ts +24 -0
- package/templates/app/app/http/controllers/sitemap.test.ts +28 -0
- package/templates/app/app/http/controllers/sitemap.ts +25 -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 +19 -0
- package/templates/app/app/http/middleware/page.test.ts +43 -0
- package/templates/app/app/http/middleware/page.ts +51 -0
- package/templates/app/app/http/middleware/server-timing.test.ts +15 -0
- package/templates/app/app/http/middleware/server-timing.ts +42 -0
- package/templates/app/app/initializers/assets.ts +1 -1
- package/templates/app/app/initializers/captcha.ts +11 -0
- package/templates/app/app/initializers/cli.ts +68 -2
- package/templates/app/app/initializers/database.test.ts +18 -0
- package/templates/app/app/initializers/database.ts +18 -0
- package/templates/app/app/initializers/dispatcher.ts +26 -0
- package/templates/app/app/initializers/honeypot.ts +11 -0
- package/templates/app/app/initializers/i18n.test.ts +16 -0
- package/templates/app/app/initializers/i18n.ts +28 -0
- package/templates/app/app/initializers/local-database.test.ts +33 -0
- package/templates/app/app/initializers/local-database.ts +53 -0
- 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 +27 -0
- package/templates/app/app/initializers/mail.ts +19 -0
- package/templates/app/app/initializers/mcp.ts +1 -1
- package/templates/app/app/initializers/openapi.ts +21 -0
- package/templates/app/app/initializers/router.test.ts +68 -0
- package/templates/app/app/initializers/router.tsx +81 -25
- package/templates/app/app/initializers/seo.ts +15 -0
- package/templates/app/app/initializers/session.test.ts +34 -0
- package/templates/app/app/initializers/session.ts +29 -0
- package/templates/app/app/initializers/spam.ts +10 -0
- 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/models/index.ts +10 -0
- 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 +92 -0
- package/templates/app/app/services/migrations.ts +117 -0
- package/templates/app/app/test/cloudflare-workers.ts +25 -0
- package/templates/app/app/test/local-database.ts +67 -0
- package/templates/app/app/test/session.ts +28 -0
- package/templates/app/bootstrap/cli.ts +1 -1
- package/templates/app/bootstrap/console.ts +13 -0
- package/templates/app/bootstrap/worker.ts +4 -4
- package/templates/app/cloudflare.config.ts +30 -2
- package/templates/app/config/constants.ts +19 -0
- package/templates/app/config/problems.ts +24 -0
- package/templates/app/config/security-policy.ts +34 -0
- package/templates/app/config/security-txt.ts +28 -0
- package/templates/app/database/migrations/.gitkeep +0 -0
- package/templates/app/database/seed.ts +12 -0
- package/templates/app/package.json +37 -6
- package/templates/app/resources/layouts/document.tsx +28 -7
- package/templates/app/resources/locales/en.json +10 -0
- package/templates/app/routes/api.ts +29 -0
- package/templates/app/routes/web.ts +6 -4
- package/templates/app/vite.config.ts +4 -0
- package/stubs/policy.stub +0 -13
- package/templates/app/config/router-context.d.ts +0 -20
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The {{title}} page, for a visitor `{{ability}}` admits: describe what they find here and why
|
|
3
|
+
* the route exists.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/wire-the-router}
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createAction } from "remix/router";
|
|
10
|
+
|
|
11
|
+
import page from "~/app/http/middleware/page";
|
|
12
|
+
import abilities from "~/app/policies/abilities";
|
|
13
|
+
import DocumentLayout from "~/resources/layouts/document";
|
|
14
|
+
import routes from "{{routes}}";
|
|
15
|
+
|
|
16
|
+
export default createAction(routes.{{path}}, {
|
|
17
|
+
middleware: page,
|
|
18
|
+
/** Renders the {{title}} page once `ctx.access` admits `{{ability}}`. */
|
|
19
|
+
async handler(ctx) {
|
|
20
|
+
{{pageAccess}}
|
|
21
|
+
return ctx.render(
|
|
22
|
+
<DocumentLayout assets={ctx.assets} intl={ctx.intl} url={ctx.url} title="{{title}}">
|
|
23
|
+
<h1>{{title}}</h1>
|
|
24
|
+
{/* TODO: render the page */}
|
|
25
|
+
</DocumentLayout>,
|
|
26
|
+
);
|
|
27
|
+
},
|
|
28
|
+
});
|
package/stubs/controller.stub
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} page: describe what a visitor finds here and why the route exists.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/wire-the-router}
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/interface-with-remix-ui}{{header}}
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
import { createAction } from "remix/router";
|
|
6
9
|
|
|
10
|
+
import page from "~/app/http/middleware/page";
|
|
7
11
|
import DocumentLayout from "~/resources/layouts/document";
|
|
8
12
|
import routes from "{{routes}}";
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
export default createAction(routes.{{path}}, {
|
|
15
|
+
middleware: page,
|
|
16
|
+
/** Renders the {{title}} page. */
|
|
17
|
+
handler: (ctx) =>
|
|
18
|
+
ctx.render(
|
|
19
|
+
<DocumentLayout assets={ctx.assets} intl={ctx.intl} url={ctx.url} title="{{title}}">
|
|
20
|
+
<h1>{{title}}</h1>
|
|
21
|
+
{/* TODO: render the page */}
|
|
22
|
+
</DocumentLayout>,
|
|
23
|
+
),
|
|
24
|
+
});
|
package/stubs/email.stub
CHANGED
|
@@ -1,44 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The {{title}} email: describe who receives it and what it tells them.
|
|
2
|
+
* The {{title}} email: describe who receives it and what it tells them. Its props are declared
|
|
3
|
+
* in `app/emails/index.ts`; translate copy with `handle.props.t`, in `handle.props.locale`.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/send-email}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/mail}{{header}}
|
|
3
7
|
*/
|
|
4
8
|
|
|
5
|
-
import
|
|
6
|
-
import type { Email as EmailContract } from "@sdxc/mail";
|
|
9
|
+
import { createEmail, Email } from "@sdxc/mail";
|
|
7
10
|
|
|
8
|
-
import
|
|
11
|
+
import emails from "~/app/emails";
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** Renders the email's body from copy the caller wrote. */
|
|
17
|
-
function {{Name}}Body(handle: Handle<{{Name}}Copy>) {
|
|
18
|
-
return () => (
|
|
19
|
-
<Email.Layout preview={handle.props.heading} title={handle.props.heading}>
|
|
20
|
-
<Email.Heading>{handle.props.heading}</Email.Heading>
|
|
21
|
-
<Email.Text>{handle.props.body}</Email.Text>
|
|
13
|
+
export default createEmail(emails.{{path}}, {
|
|
14
|
+
subject: {{subject}},
|
|
15
|
+
body: (handle) => () => (
|
|
16
|
+
<Email.Layout lang={handle.props.locale} title={{layoutTitle}}>
|
|
17
|
+
{{body}}
|
|
22
18
|
</Email.Layout>
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** The {{title}} email, addressed to one recipient. */
|
|
27
|
-
export class {{Name}}Email implements EmailContract {
|
|
28
|
-
constructor(
|
|
29
|
-
private recipient: string,
|
|
30
|
-
private copy: {{Name}}Copy,
|
|
31
|
-
) {}
|
|
32
|
-
|
|
33
|
-
get to() {
|
|
34
|
-
return { email: this.recipient };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get subject() {
|
|
38
|
-
return this.copy.heading;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
body() {
|
|
42
|
-
return <{{Name}}Body {...this.copy} />;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
19
|
+
),
|
|
20
|
+
preview: () => ({{preview}}),
|
|
21
|
+
});
|
package/stubs/email.test.stub
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The {{title}} email.
|
|
2
|
+
* The {{title}} email, rendered through the app's email registry.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/send-email}
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
3
6
|
*/
|
|
4
7
|
|
|
8
|
+
import { unwrap } from "@sdxc/result";
|
|
5
9
|
import { describe, expect, test } from "vitest";
|
|
6
10
|
|
|
7
|
-
import
|
|
11
|
+
import emails from "~/app/emails";
|
|
12
|
+
import { mail } from "~/app/initializers/mail";
|
|
8
13
|
|
|
9
|
-
describe("{{
|
|
10
|
-
test("
|
|
11
|
-
let
|
|
14
|
+
describe("{{title}} email", () => {
|
|
15
|
+
test("renders its props into the subject and both body parts", async () => {
|
|
16
|
+
let rendered = unwrap(await mail.render(emails.{{path}}, { props: {{sample}} }));
|
|
12
17
|
|
|
13
|
-
expect(
|
|
14
|
-
expect(
|
|
18
|
+
expect(rendered.subject).toBe({{subjectSample}});
|
|
19
|
+
expect(rendered.text).toContain({{textSample}});
|
|
15
20
|
});
|
|
16
21
|
});
|
package/stubs/factory.stub
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} factory tests seed rows with, through the same model the app writes with.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/data-models}
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/test-data}{{header}}
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
import { defineFactory } from "@sdxc/data-model/testing";
|
|
@@ -7,4 +10,4 @@ import { defineFactory } from "@sdxc/data-model/testing";
|
|
|
7
10
|
import { {{Name}} } from "{{model}}";
|
|
8
11
|
|
|
9
12
|
/** A complete {{title}} row; a test overrides only the fields it is about. */
|
|
10
|
-
export const {{Name}}Factory = defineFactory({{Name}}, {});
|
|
13
|
+
export const {{Name}}Factory = defineFactory({{Name}}, {{{attributes}}});
|
package/stubs/initializer.stub
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The app's one {{title}}: describe what it is configured with and who reads it. Build it
|
|
3
3
|
* here, once, so every caller shares the same instance.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/wire-the-router}{{header}}
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
8
|
/** The {{title}} every caller imports. */
|
package/stubs/job.cron.stub
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The scheduled {{title}} job: describe what each run sweeps or reports, and why on this
|
|
3
3
|
* schedule.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/jobs-and-cron}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/jobs}{{header}}
|
|
4
7
|
*/
|
|
5
8
|
|
|
6
9
|
import { createJobHandler } from "@sdxc/jobs";
|
|
@@ -9,4 +12,5 @@ import jobs from "~/app/jobs";
|
|
|
9
12
|
|
|
10
13
|
export default createJobHandler(jobs.{{path}}, async (ctx) => {
|
|
11
14
|
ctx.log.set({ job: { name: "{{name}}" } });
|
|
15
|
+
// TODO: do the work, through the services on `ctx`
|
|
12
16
|
});
|
package/stubs/job.stub
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} job: describe what it changes and why it runs off the request.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/jobs-and-cron}
|
|
5
|
+
* @see {@link https://sdxc.dev/api/jobs}{{header}}
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
import { createJobHandler } from "@sdxc/jobs";
|
|
@@ -8,4 +11,5 @@ import jobs from "~/app/jobs";
|
|
|
8
11
|
|
|
9
12
|
export default createJobHandler(jobs.{{path}}, async (ctx) => {
|
|
10
13
|
ctx.log.set({ job: { name: "{{name}}" } });
|
|
14
|
+
// TODO: do the work, through the services on `ctx`
|
|
11
15
|
});
|
package/stubs/job.test.stub
CHANGED
package/stubs/mcp.resource.stub
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Answers the `{{uri}}` resource: describe what a read returns, and `null` for one that does
|
|
3
3
|
* not exist.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/mcp}{{header}}
|
|
4
7
|
*/
|
|
5
8
|
|
|
6
9
|
import { createResource } from "@sdxc/mcp";
|
package/stubs/mcp.stub
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Answers the `{{tool}}` tool: describe what it returns, and what a model should do when it
|
|
3
3
|
* finds nothing.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/mcp}{{header}}
|
|
4
7
|
*/
|
|
5
8
|
|
|
6
9
|
import { createTool } from "@sdxc/mcp";
|
package/stubs/mcp.test.stub
CHANGED
package/stubs/middleware.stub
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} middleware: describe what it publishes on the context or which requests it
|
|
3
3
|
* answers before the handler runs.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/wire-the-router}{{header}}
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
8
|
import type { Middleware } from "remix/router";
|
|
7
9
|
|
|
8
10
|
/** Creates the middleware; add it to a router's chain or to a route's `lazy()` guards. */
|
|
9
11
|
export default function {{key}}(): Middleware {
|
|
10
|
-
return (_context, next) =>
|
|
12
|
+
return (_context, next) => {
|
|
13
|
+
// TODO: publish on the context, or answer before the handler runs
|
|
14
|
+
return next();
|
|
15
|
+
};
|
|
11
16
|
}
|
package/stubs/model.stub
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} model and its table: describe what a row records and the rules that keep it
|
|
3
3
|
* consistent. Keep the columns in step with the migration that creates the table.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/data-models}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/data-model}{{header}}
|
|
4
7
|
*/
|
|
5
8
|
|
|
6
9
|
import type { TableRow } from "remix/data-table";
|
|
7
10
|
|
|
8
11
|
import { column as c, table } from "remix/data-table";
|
|
9
12
|
import { createModel } from "@sdxc/data-model";
|
|
13
|
+
import { generateUUID } from "@sdxc/uuid/v7";
|
|
10
14
|
|
|
11
|
-
/** The `{{
|
|
15
|
+
/** The `{{table}}` table, as its migration creates it. */
|
|
12
16
|
export const {{key}}Table = table({
|
|
13
|
-
name: "{{
|
|
17
|
+
name: "{{table}}",
|
|
14
18
|
columns: {
|
|
15
19
|
id: c.text().primaryKey(),
|
|
20
|
+
{{columns}}
|
|
16
21
|
created_at: c.integer(),
|
|
17
22
|
updated_at: c.integer(),
|
|
18
23
|
},
|
|
24
|
+
/** `create` and `update` stamp `created_at` and `updated_at` with the database's clock. */
|
|
25
|
+
timestamps: true,
|
|
19
26
|
});
|
|
20
27
|
|
|
21
28
|
/** One {{title}} row as it reads back from the database. */
|
|
22
29
|
export type {{Name}}Row = TableRow<typeof {{key}}Table>;
|
|
23
30
|
|
|
24
|
-
export const {{Name}} = createModel({{key}}Table, {});
|
|
31
|
+
export const {{Name}} = createModel({{key}}Table, { generateId: generateUUID });
|
|
32
|
+
|
|
33
|
+
export default {{Name}};
|
package/stubs/model.test.stub
CHANGED
package/stubs/policy.test.stub
CHANGED
|
@@ -1,17 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Who may do what with `{{path}}`: anyone reads one, and a signed-in member creates, updates and
|
|
3
|
+
* deletes one. Change its grants in `app/policies/policy.ts` and keep these cases in step.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/identity-and-security/authorization}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/authz}{{header}}
|
|
3
7
|
*/
|
|
4
8
|
|
|
9
|
+
import type { ContextOf } from "@sdxc/authz";
|
|
10
|
+
|
|
11
|
+
import { testAccess } from "@sdxc/authz/testing";
|
|
5
12
|
import { describe, expect, test } from "vitest";
|
|
6
13
|
|
|
7
|
-
import
|
|
14
|
+
import abilities from "~/app/policies/abilities";
|
|
15
|
+
import policy from "~/app/policies/policy";
|
|
16
|
+
|
|
17
|
+
/** The record each check passes; no grant reads its fields until one gains a condition. */
|
|
18
|
+
const RECORD = { id: "1" } as ContextOf<typeof abilities.{{path}}.read>["{{key}}"];
|
|
8
19
|
|
|
9
|
-
describe("{{
|
|
10
|
-
test("
|
|
11
|
-
|
|
20
|
+
describe("{{path}}", () => {
|
|
21
|
+
test("lets a guest read one", () => {
|
|
22
|
+
let guest = testAccess(policy, { roles: [] });
|
|
23
|
+
|
|
24
|
+
expect(guest.can(abilities.{{path}}.read, { {{key}}: RECORD })).toBe(true);
|
|
12
25
|
});
|
|
13
26
|
|
|
14
|
-
test("
|
|
15
|
-
|
|
27
|
+
test("lets a member create, update and delete one", () => {
|
|
28
|
+
let member = testAccess(policy, { roles: ["member"], facts: { actor: { id: "1" } } });
|
|
29
|
+
|
|
30
|
+
expect(member.can(abilities.{{path}}.create)).toBe(true);
|
|
31
|
+
expect(member.can(abilities.{{path}}.update, { {{key}}: RECORD })).toBe(true);
|
|
32
|
+
expect(member.can(abilities.{{path}}.delete, { {{key}}: RECORD })).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("refuses a guest every write", () => {
|
|
36
|
+
let guest = testAccess(policy, { roles: [] });
|
|
37
|
+
|
|
38
|
+
expect(guest.check(abilities.{{path}}.create)).toMatchObject({ allowed: false });
|
|
39
|
+
expect(guest.check(abilities.{{path}}.update, { {{key}}: RECORD })).toMatchObject({
|
|
40
|
+
allowed: false,
|
|
41
|
+
});
|
|
42
|
+
expect(guest.check(abilities.{{path}}.delete, { {{key}}: RECORD })).toMatchObject({
|
|
43
|
+
allowed: false,
|
|
44
|
+
});
|
|
16
45
|
});
|
|
17
46
|
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `POST /api/{{plural}}`: creates a {{words}} from the JSON body the `{{CONSTANT}}_CREATE`
|
|
3
|
+
* operation in `routes/api.ts` types. A body the operation or the model refuses is the
|
|
4
|
+
* `validationError` problem, and a caller `{{path}}.create` refuses gets a 403.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/http-apis/json-apis}
|
|
7
|
+
* @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { issuesFrom } from "@sdxc/problem";
|
|
11
|
+
import { isFailure } from "@sdxc/result";
|
|
12
|
+
import { createAction } from "remix/router";
|
|
13
|
+
|
|
14
|
+
import api from "~/app/http/middleware/api";
|
|
15
|
+
import abilities from "~/app/policies/abilities";
|
|
16
|
+
import problems from "~/config/problems";
|
|
17
|
+
import routes, { {{CONSTANT}}_CREATE } from "~/routes/api";
|
|
18
|
+
|
|
19
|
+
export default createAction(routes.api.{{pluralKey}}.create, {
|
|
20
|
+
middleware: api,
|
|
21
|
+
/** Answers the created {{words}} as `data` with a 201. */
|
|
22
|
+
async handler(ctx) {
|
|
23
|
+
if (!ctx.access.can(abilities.{{path}}.create)) return new Response(null, { status: 403 });
|
|
24
|
+
let input = await {{CONSTANT}}_CREATE.parse(ctx.request, ctx.params);
|
|
25
|
+
if (isFailure(input)) {
|
|
26
|
+
return problems.validationError({ extensions: { errors: issuesFrom(input.error) } });
|
|
27
|
+
}
|
|
28
|
+
let created = await ctx.models.{{key}}.create(input.data.body);
|
|
29
|
+
if (isFailure(created)) {
|
|
30
|
+
return problems.validationError({ extensions: { errors: issuesFrom(created.error) } });
|
|
31
|
+
}
|
|
32
|
+
return Response.json({ data: created.data }, { status: 201 });
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `POST /api/{{plural}}` through the app's router. The API binds every caller as a guest until
|
|
3
|
+
* it authenticates them, and the policy grants a guest reads alone, so the write answers 403.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/http-apis/json-apis}
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { beforeAll, describe, expect, test } from "vitest";
|
|
10
|
+
|
|
11
|
+
import "~/app/http/controllers/api/{{plural}}/create";
|
|
12
|
+
import { createWebRouter } from "~/app/initializers/router";
|
|
13
|
+
import { migrate } from "~/app/test/database";
|
|
14
|
+
import routes from "~/routes/api";
|
|
15
|
+
|
|
16
|
+
beforeAll(migrate);
|
|
17
|
+
|
|
18
|
+
/** Posts `body` as JSON to the endpoint. */
|
|
19
|
+
function submit(body: Record<string, unknown>) {
|
|
20
|
+
return createWebRouter().fetch(
|
|
21
|
+
new Request(new URL(routes.api.{{pluralKey}}.create.href(), "https://example.com"), {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: { "content-type": "application/json" },
|
|
24
|
+
body: JSON.stringify(body),
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("api/{{plural}}/create", () => {
|
|
30
|
+
test("answers 403 to a guest, who may only read", async () => {
|
|
31
|
+
let response = await submit({ {{jsonSample}} });
|
|
32
|
+
|
|
33
|
+
expect(response.status).toBe(403);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test.todo("creates the {{words}} for a caller {{path}}.create admits");
|
|
37
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `DELETE /api/{{plural}}/:id`: deletes the {{words}} and answers 204, as the
|
|
3
|
+
* `{{CONSTANT}}_DESTROY` operation in `routes/api.ts` documents it. An id no {{words}} has, or
|
|
4
|
+
* one `{{path}}.read` hides, is the `notFound` problem; a caller `{{path}}.delete` refuses gets
|
|
5
|
+
* a 403.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://sdxc.dev/docs/http-apis/json-apis}
|
|
8
|
+
* @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { isFailure } from "@sdxc/result";
|
|
12
|
+
import { createAction } from "remix/router";
|
|
13
|
+
|
|
14
|
+
import api from "~/app/http/middleware/api";
|
|
15
|
+
import abilities from "~/app/policies/abilities";
|
|
16
|
+
import problems from "~/config/problems";
|
|
17
|
+
import routes from "~/routes/api";
|
|
18
|
+
|
|
19
|
+
export default createAction(routes.api.{{pluralKey}}.destroy, {
|
|
20
|
+
middleware: api,
|
|
21
|
+
/** Answers an empty 204 once the {{words}} is gone. */
|
|
22
|
+
async handler(ctx) {
|
|
23
|
+
let row = await ctx.models.{{key}}.find(ctx.params.id);
|
|
24
|
+
if (row === null || !ctx.access.can(abilities.{{path}}.read, { {{key}}: row })) {
|
|
25
|
+
return problems.notFound();
|
|
26
|
+
}
|
|
27
|
+
if (!ctx.access.can(abilities.{{path}}.delete, { {{key}}: row })) {
|
|
28
|
+
return new Response(null, { status: 403 });
|
|
29
|
+
}
|
|
30
|
+
let deleted = await ctx.models.{{key}}.delete(ctx.params.id);
|
|
31
|
+
if (isFailure(deleted)) return problems.notFound();
|
|
32
|
+
return new Response(null, { status: 204 });
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `DELETE /api/{{plural}}/:id` through the app's router. The API binds every caller as a guest
|
|
3
|
+
* until it authenticates them, and the policy grants a guest reads alone, so the write answers 403.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/http-apis/json-apis}
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { beforeAll, describe, expect, test } from "vitest";
|
|
10
|
+
|
|
11
|
+
import "~/app/http/controllers/api/{{plural}}/destroy";
|
|
12
|
+
import { createWebRouter } from "~/app/initializers/router";
|
|
13
|
+
import { factories, migrate } from "~/app/test/database";
|
|
14
|
+
import { {{Name}}Factory } from "~/database/factories/{{name}}";
|
|
15
|
+
import routes from "~/routes/api";
|
|
16
|
+
|
|
17
|
+
beforeAll(migrate);
|
|
18
|
+
|
|
19
|
+
/** Sends a DELETE for the {{words}} with `id`. */
|
|
20
|
+
function destroy(id: string) {
|
|
21
|
+
return createWebRouter().fetch(
|
|
22
|
+
new Request(new URL(routes.api.{{pluralKey}}.destroy.href({ id }), "https://example.com"), {
|
|
23
|
+
method: "DELETE",
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe("api/{{plural}}/destroy", () => {
|
|
29
|
+
test("answers 403 to a guest, who may only read", async () => {
|
|
30
|
+
let row = await factories().create({{Name}}Factory);
|
|
31
|
+
|
|
32
|
+
let response = await destroy(row.id);
|
|
33
|
+
|
|
34
|
+
expect(response.status).toBe(403);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("answers the notFound problem for an id no {{words}} has", async () => {
|
|
38
|
+
let response = await destroy("missing");
|
|
39
|
+
|
|
40
|
+
expect(response.status).toBe(404);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test.todo("deletes the {{words}} for a caller {{path}}.delete admits");
|
|
44
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `GET /api/{{plural}}`: every {{words}} `{{path}}.read` admits, newest first, as the
|
|
3
|
+
* `{{PLURAL_CONSTANT}}_INDEX` operation in `routes/api.ts` documents it.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/http-apis/json-apis}
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createAction } from "remix/router";
|
|
10
|
+
|
|
11
|
+
import api from "~/app/http/middleware/api";
|
|
12
|
+
import abilities from "~/app/policies/abilities";
|
|
13
|
+
import routes from "~/routes/api";
|
|
14
|
+
|
|
15
|
+
export default createAction(routes.api.{{pluralKey}}.index, {
|
|
16
|
+
middleware: api,
|
|
17
|
+
/** Lists the {{pluralWords}} the caller may read, so a hidden one is left out of `data`. */
|
|
18
|
+
async handler(ctx) {
|
|
19
|
+
let all = await ctx.models.{{key}}.query().orderBy("created_at", "desc").all();
|
|
20
|
+
let data = all.filter((row) => ctx.access.can(abilities.{{path}}.read, { {{key}}: row }));
|
|
21
|
+
return Response.json({ data });
|
|
22
|
+
},
|
|
23
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `GET /api/{{plural}}` through the app's router, so the API chain and its access checks run as
|
|
3
|
+
* they do in the Worker.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/http-apis/json-apis}
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { beforeAll, describe, expect, test } from "vitest";
|
|
10
|
+
|
|
11
|
+
import "~/app/http/controllers/api/{{plural}}/index";
|
|
12
|
+
import { createWebRouter } from "~/app/initializers/router";
|
|
13
|
+
import { factories, migrate } from "~/app/test/database";
|
|
14
|
+
import { {{Name}}Factory } from "~/database/factories/{{name}}";
|
|
15
|
+
import routes from "~/routes/api";
|
|
16
|
+
|
|
17
|
+
beforeAll(migrate);
|
|
18
|
+
|
|
19
|
+
describe("api/{{plural}}/index", () => {
|
|
20
|
+
test("answers every {{words}} the caller may read as data", async () => {
|
|
21
|
+
let row = await factories().create({{Name}}Factory);
|
|
22
|
+
|
|
23
|
+
let response = await createWebRouter().fetch(
|
|
24
|
+
new URL(routes.api.{{pluralKey}}.index.href(), "https://example.com"),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(response.status).toBe(200);
|
|
28
|
+
let body = (await response.json()) as { data: Array<{ id: string }> };
|
|
29
|
+
expect(body.data.map((item) => item.id)).toContain(row.id);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `GET /api/{{plural}}/:id`: one {{words}}, as the `{{CONSTANT}}_SHOW` operation in
|
|
3
|
+
* `routes/api.ts` documents it. An id no {{words}} has, and one `{{path}}.read` hides, is the
|
|
4
|
+
* `notFound` problem.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/http-apis/json-apis}
|
|
7
|
+
* @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { createAction } from "remix/router";
|
|
11
|
+
|
|
12
|
+
import api from "~/app/http/middleware/api";
|
|
13
|
+
import abilities from "~/app/policies/abilities";
|
|
14
|
+
import problems from "~/config/problems";
|
|
15
|
+
import routes from "~/routes/api";
|
|
16
|
+
|
|
17
|
+
export default createAction(routes.api.{{pluralKey}}.show, {
|
|
18
|
+
middleware: api,
|
|
19
|
+
/** Answers the {{words}} as `data`. */
|
|
20
|
+
async handler(ctx) {
|
|
21
|
+
let row = await ctx.models.{{key}}.find(ctx.params.id);
|
|
22
|
+
if (row === null || !ctx.access.can(abilities.{{path}}.read, { {{key}}: row })) {
|
|
23
|
+
return problems.notFound();
|
|
24
|
+
}
|
|
25
|
+
return Response.json({ data: row });
|
|
26
|
+
},
|
|
27
|
+
});
|