@react-consulting/rc-kit 0.0.0-stage → 0.13.0
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/LICENSE +21 -0
- package/README.md +94 -2
- package/devkit/README.md +301 -0
- package/devkit/cli.test.ts +211 -0
- package/devkit/cli.ts +120 -0
- package/devkit/commands/build.ts +127 -0
- package/devkit/commands/checks.ts +123 -0
- package/devkit/commands/context.ts +47 -0
- package/devkit/commands/db.ts +154 -0
- package/devkit/commands/deploy.ts +46 -0
- package/devkit/commands/dev.ts +191 -0
- package/devkit/commands/doctor.ts +25 -0
- package/devkit/commands/kit.ts +45 -0
- package/devkit/commands/new.ts +81 -0
- package/devkit/commands/registry.ts +20 -0
- package/devkit/commands/secrets.ts +254 -0
- package/devkit/lib/args.ts +65 -0
- package/devkit/lib/audit.test.ts +405 -0
- package/devkit/lib/audit.ts +813 -0
- package/devkit/lib/config.test.ts +203 -0
- package/devkit/lib/config.ts +417 -0
- package/devkit/lib/database/index.test.ts +223 -0
- package/devkit/lib/database/index.ts +314 -0
- package/devkit/lib/database/neon.test.ts +233 -0
- package/devkit/lib/database/neon.ts +357 -0
- package/devkit/lib/database/prepare.ts +54 -0
- package/devkit/lib/deploy-config.test.ts +217 -0
- package/devkit/lib/deploy-config.ts +133 -0
- package/devkit/lib/deploy.test.ts +275 -0
- package/devkit/lib/deploy.ts +177 -0
- package/devkit/lib/dev-gateway.test.ts +128 -0
- package/devkit/lib/dev-gateway.ts +162 -0
- package/devkit/lib/dev-menu.test.ts +114 -0
- package/devkit/lib/dev-menu.ts +332 -0
- package/devkit/lib/dev-secrets.test.ts +156 -0
- package/devkit/lib/dev-secrets.ts +97 -0
- package/devkit/lib/dev.test.ts +194 -0
- package/devkit/lib/dev.ts +119 -0
- package/devkit/lib/doctor.test.ts +144 -0
- package/devkit/lib/doctor.ts +264 -0
- package/devkit/lib/env-file.test.ts +102 -0
- package/devkit/lib/env-file.ts +96 -0
- package/devkit/lib/glob.ts +31 -0
- package/devkit/lib/infisical.test.ts +208 -0
- package/devkit/lib/infisical.ts +139 -0
- package/devkit/lib/json-schema.ts +220 -0
- package/devkit/lib/jsonc.test.ts +53 -0
- package/devkit/lib/jsonc.ts +93 -0
- package/devkit/lib/kit-migrate.test.ts +212 -0
- package/devkit/lib/kit-migrate.ts +617 -0
- package/devkit/lib/kit-package.test.ts +83 -0
- package/devkit/lib/kit-package.ts +57 -0
- package/devkit/lib/kit-version.ts +22 -0
- package/devkit/lib/naming.test.ts +547 -0
- package/devkit/lib/naming.ts +796 -0
- package/devkit/lib/paths.ts +7 -0
- package/devkit/lib/process.ts +78 -0
- package/devkit/lib/project-checks.ts +86 -0
- package/devkit/lib/scaffold.test.ts +302 -0
- package/devkit/lib/scaffold.ts +315 -0
- package/devkit/lib/secrets.test.ts +101 -0
- package/devkit/lib/secrets.ts +125 -0
- package/devkit/lib/sourcemaps.test.ts +86 -0
- package/devkit/lib/sourcemaps.ts +98 -0
- package/devkit/lib/test-utils.ts +68 -0
- package/devkit/lib/workspace.ts +87 -0
- package/devkit/lib/wrangler.ts +231 -0
- package/docs/rc-config.md +93 -0
- package/package.json +86 -4
- package/presets/build.d.ts +15 -0
- package/presets/build.js +53 -0
- package/presets/vite-plus.d.ts +28 -0
- package/presets/vite-plus.js +153 -0
- package/registry/README.md +294 -0
- package/registry/public/r/avatar-stack.json +18 -0
- package/registry/public/r/avatar.json +20 -0
- package/registry/public/r/back-link.json +21 -0
- package/registry/public/r/badge.json +17 -0
- package/registry/public/r/button.json +18 -0
- package/registry/public/r/calendar-days.json +14 -0
- package/registry/public/r/calendar-popover.json +24 -0
- package/registry/public/r/calendar.json +23 -0
- package/registry/public/r/callout.json +20 -0
- package/registry/public/r/card.json +18 -0
- package/registry/public/r/character-counter.json +17 -0
- package/registry/public/r/checkbox.json +22 -0
- package/registry/public/r/choice-cards.json +22 -0
- package/registry/public/r/color-tag.json +17 -0
- package/registry/public/r/combobox.json +24 -0
- package/registry/public/r/confirm-button.json +24 -0
- package/registry/public/r/confirm-dialog.json +23 -0
- package/registry/public/r/copy-button.json +24 -0
- package/registry/public/r/date-picker.json +24 -0
- package/registry/public/r/date-range-picker.json +28 -0
- package/registry/public/r/detail-header.json +17 -0
- package/registry/public/r/detail-row.json +17 -0
- package/registry/public/r/dev-inbox-api.json +33 -0
- package/registry/public/r/dev-toolbar.json +109 -0
- package/registry/public/r/dev-tools-contract.json +15 -0
- package/registry/public/r/dialog.json +23 -0
- package/registry/public/r/empty-state.json +20 -0
- package/registry/public/r/error-state.json +23 -0
- package/registry/public/r/eyebrow.json +17 -0
- package/registry/public/r/fab.json +20 -0
- package/registry/public/r/field-error.json +17 -0
- package/registry/public/r/field-grid.json +17 -0
- package/registry/public/r/field.json +19 -0
- package/registry/public/r/file-picker.json +22 -0
- package/registry/public/r/filter-chips.json +17 -0
- package/registry/public/r/form-section.json +17 -0
- package/registry/public/r/form-sheet.json +22 -0
- package/registry/public/r/icon-button.json +23 -0
- package/registry/public/r/input.json +18 -0
- package/registry/public/r/label.json +18 -0
- package/registry/public/r/list-row.json +17 -0
- package/registry/public/r/loading-state.json +18 -0
- package/registry/public/r/localized-field.json +23 -0
- package/registry/public/r/markdown-text.json +17 -0
- package/registry/public/r/menu.json +21 -0
- package/registry/public/r/money-input.json +17 -0
- package/registry/public/r/month-day-select.json +18 -0
- package/registry/public/r/numbered-step.json +20 -0
- package/registry/public/r/page-actions.json +14 -0
- package/registry/public/r/page-header.json +17 -0
- package/registry/public/r/pending.json +17 -0
- package/registry/public/r/person-option.json +21 -0
- package/registry/public/r/popover.json +20 -0
- package/registry/public/r/progress-bar.json +17 -0
- package/registry/public/r/query-view.json +22 -0
- package/registry/public/r/registry.json +1352 -0
- package/registry/public/r/retry-button.json +21 -0
- package/registry/public/r/rich-text-editor.json +32 -0
- package/registry/public/r/save-bar.json +22 -0
- package/registry/public/r/search-input.json +23 -0
- package/registry/public/r/search-select.json +24 -0
- package/registry/public/r/section-tabs.json +17 -0
- package/registry/public/r/segmented.json +18 -0
- package/registry/public/r/select.json +23 -0
- package/registry/public/r/sheet.json +24 -0
- package/registry/public/r/skeleton.json +17 -0
- package/registry/public/r/spinner.json +20 -0
- package/registry/public/r/stale-notice.json +23 -0
- package/registry/public/r/stat-tile.json +23 -0
- package/registry/public/r/stepper.json +23 -0
- package/registry/public/r/suggestion-strip.json +21 -0
- package/registry/public/r/swatch-picker.json +22 -0
- package/registry/public/r/switch.json +21 -0
- package/registry/public/r/tabs.json +20 -0
- package/registry/public/r/textarea.json +18 -0
- package/registry/public/r/theme.json +15 -0
- package/registry/public/r/timezone-select.json +19 -0
- package/registry/public/r/toaster.json +21 -0
- package/registry/public/r/tooltip.json +17 -0
- package/registry/public/r/ui-labels.json +14 -0
- package/registry/public/r/use-copy-to-clipboard.json +20 -0
- package/registry/public/r/use-online.json +14 -0
- package/registry/public/r/use-stale-queries.json +17 -0
- package/registry/public/r/utils.json +18 -0
- package/registry/public/r/weekday-picker.json +19 -0
- package/registry/public/r/yes-no.json +20 -0
- package/registry/serve.ts +29 -0
- package/rules/architecture.md +47 -0
- package/rules/cloudflare.md +74 -0
- package/rules/code.md +12 -0
- package/rules/git.md +10 -0
- package/rules/index.md +14 -0
- package/rules/observability.md +13 -0
- package/rules/performance.md +39 -0
- package/rules/runtime.md +9 -0
- package/rules/secrets.md +11 -0
- package/rules/stack.md +33 -0
- package/rules/ui.md +23 -0
- package/runtime/ai.test.ts +106 -0
- package/runtime/ai.ts +125 -0
- package/runtime/observability/allowlists.ts +42 -0
- package/runtime/observability/anonymize.test.ts +111 -0
- package/runtime/observability/anonymize.ts +249 -0
- package/runtime/observability/browser.test.ts +46 -0
- package/runtime/observability/browser.ts +126 -0
- package/runtime/observability/server.test.ts +84 -0
- package/runtime/observability/server.ts +152 -0
- package/runtime/observability/tunnel.test.ts +276 -0
- package/runtime/observability/tunnel.ts +360 -0
- package/runtime/observability/user-agent.ts +51 -0
- package/schema/rc.config.schema.json +333 -0
- package/template/.gitattributes +1 -0
- package/template/.github/workflows/ci.yml +64 -0
- package/template/CLAUDE.md +48 -0
- package/template/README.md +50 -0
- package/template/apps/admin/.dev.vars.example +5 -0
- package/template/apps/admin/components.json +24 -0
- package/template/apps/admin/package.json +48 -0
- package/template/apps/admin/public/favicon.svg +1 -0
- package/template/apps/admin/src/components/app-shell.tsx +41 -0
- package/template/apps/admin/src/components/dev-sign-in-links.tsx +57 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-context.ts +13 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-environment-panel.tsx +105 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-list.tsx +54 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-message.tsx +104 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-panel.tsx +130 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-launcher.tsx +45 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-panel.tsx +90 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-types.ts +11 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar.tsx +61 -0
- package/template/apps/admin/src/components/dev-toolbar/development-devtools.tsx +32 -0
- package/template/apps/admin/src/components/login-form.tsx +115 -0
- package/template/apps/admin/src/components/login-sent.tsx +23 -0
- package/template/apps/admin/src/components/message-list.tsx +44 -0
- package/template/apps/admin/src/components/turnstile-challenge.tsx +140 -0
- package/template/apps/admin/src/components/ui/button.tsx +87 -0
- package/template/apps/admin/src/components/ui/callout.tsx +84 -0
- package/template/apps/admin/src/components/ui/card.tsx +48 -0
- package/template/apps/admin/src/components/ui/eyebrow.tsx +33 -0
- package/template/apps/admin/src/components/ui/field-error.tsx +24 -0
- package/template/apps/admin/src/components/ui/field.tsx +100 -0
- package/template/apps/admin/src/components/ui/input.tsx +73 -0
- package/template/apps/admin/src/components/ui/label.tsx +39 -0
- package/template/apps/admin/src/components/ui/skeleton.tsx +225 -0
- package/template/apps/admin/src/components/ui/spinner.tsx +12 -0
- package/template/apps/admin/src/components/ui/toaster.tsx +33 -0
- package/template/apps/admin/src/components/ui/tooltip.tsx +51 -0
- package/template/apps/admin/src/hooks/use-dev-inbox.ts +25 -0
- package/template/apps/admin/src/hooks/use-dev-toolbar-state.ts +48 -0
- package/template/apps/admin/src/lib/api.ts +39 -0
- package/template/apps/admin/src/lib/auth-client.ts +7 -0
- package/template/apps/admin/src/lib/dev-inbox-links.ts +66 -0
- package/template/apps/admin/src/lib/dev-tools-client.ts +54 -0
- package/template/apps/admin/src/lib/dev-tools-contract.ts +52 -0
- package/template/apps/admin/src/lib/messages.ts +5 -0
- package/template/apps/admin/src/lib/query-keys.ts +3 -0
- package/template/apps/admin/src/lib/security-headers.ts +18 -0
- package/template/apps/admin/src/lib/session.ts +27 -0
- package/template/apps/admin/src/lib/site-url.ts +7 -0
- package/template/apps/admin/src/lib/turnstile.ts +70 -0
- package/template/apps/admin/src/lib/ui-labels.tsx +182 -0
- package/template/apps/admin/src/lib/utils.ts +6 -0
- package/template/apps/admin/src/routeTree.gen.ts +109 -0
- package/template/apps/admin/src/router.tsx +29 -0
- package/template/apps/admin/src/routes/__root.tsx +56 -0
- package/template/apps/admin/src/routes/_app/index.tsx +38 -0
- package/template/apps/admin/src/routes/_app.tsx +26 -0
- package/template/apps/admin/src/routes/login.tsx +48 -0
- package/template/apps/admin/src/styles/app.css +11 -0
- package/template/apps/admin/src/worker.ts +88 -0
- package/template/apps/admin/tsconfig.json +19 -0
- package/template/apps/admin/vite.config.ts +69 -0
- package/template/apps/admin/wrangler.jsonc +92 -0
- package/template/apps/web/.env.example +1 -0
- package/template/apps/web/astro.config.ts +46 -0
- package/template/apps/web/package.json +33 -0
- package/template/apps/web/public/favicon.svg +1 -0
- package/template/apps/web/src/components/ContactForm.astro +78 -0
- package/template/apps/web/src/env.d.ts +11 -0
- package/template/apps/web/src/layouts/BaseLayout.astro +32 -0
- package/template/apps/web/src/lib/api.ts +8 -0
- package/template/apps/web/src/pages/api/messages.ts +32 -0
- package/template/apps/web/src/pages/index.astro +26 -0
- package/template/apps/web/src/pages/media/[...key].ts +4 -0
- package/template/apps/web/src/scripts/contact-form.ts +105 -0
- package/template/apps/web/src/scripts/error-reporting.ts +4 -0
- package/template/apps/web/src/scripts/turnstile.ts +177 -0
- package/template/apps/web/src/styles/global.css +11 -0
- package/template/apps/web/src/worker.ts +34 -0
- package/template/apps/web/tsconfig.json +11 -0
- package/template/apps/web/wrangler.jsonc +45 -0
- package/template/bun.lock +1925 -0
- package/template/bunfig.toml +2 -0
- package/template/gitignore +23 -0
- package/template/package.json +74 -0
- package/template/packages/api/components.json +21 -0
- package/template/packages/api/package.json +30 -0
- package/template/packages/api/src/client.ts +13 -0
- package/template/packages/api/src/cloudflare-env.d.ts +26 -0
- package/template/packages/api/src/emails/escape-html.ts +13 -0
- package/template/packages/api/src/emails/layout.ts +22 -0
- package/template/packages/api/src/emails/magic-link.ts +32 -0
- package/template/packages/api/src/emails/new-message.ts +32 -0
- package/template/packages/api/src/emails/send.ts +14 -0
- package/template/packages/api/src/lib/auth-guard.ts +16 -0
- package/template/packages/api/src/lib/auth.ts +108 -0
- package/template/packages/api/src/lib/context.ts +7 -0
- package/template/packages/api/src/lib/dev-inbox/routes.ts +77 -0
- package/template/packages/api/src/lib/dev-inbox/send.ts +57 -0
- package/template/packages/api/src/lib/dev-inbox/store.ts +185 -0
- package/template/packages/api/src/lib/dev-inbox.ts +6 -0
- package/template/packages/api/src/lib/dev-tools-contract.ts +52 -0
- package/template/packages/api/src/lib/environment.ts +17 -0
- package/template/packages/api/src/lib/turnstile.ts +33 -0
- package/template/packages/api/src/media.ts +45 -0
- package/template/packages/api/src/routes/admin-messages.ts +21 -0
- package/template/packages/api/src/routes/dev.ts +31 -0
- package/template/packages/api/src/routes/health.ts +7 -0
- package/template/packages/api/src/routes/messages.ts +58 -0
- package/template/packages/api/src/schemas.ts +18 -0
- package/template/packages/api/src/server.ts +29 -0
- package/template/packages/api/tsconfig.json +10 -0
- package/template/packages/db/migrations/0001_init.sql +79 -0
- package/template/packages/db/package.json +34 -0
- package/template/packages/db/prisma/schema.prisma +95 -0
- package/template/packages/db/prisma.config.ts +9 -0
- package/template/packages/db/scripts/migrate.ts +15 -0
- package/template/packages/db/scripts/new-migration.ts +185 -0
- package/template/packages/db/scripts/reset.ts +54 -0
- package/template/packages/db/scripts/seed.ts +44 -0
- package/template/packages/db/scripts/wrangler.ts +35 -0
- package/template/packages/db/src/d1.ts +7 -0
- package/template/packages/db/src/migration-guard.test.ts +43 -0
- package/template/packages/db/src/migration-guard.ts +51 -0
- package/template/packages/db/src/new-migration.test.ts +16 -0
- package/template/packages/db/src/scope.ts +38 -0
- package/template/packages/db/src/seed.ts +30 -0
- package/template/packages/db/src/sql.ts +42 -0
- package/template/packages/db/tsconfig.json +8 -0
- package/template/packages/shared/components.json +21 -0
- package/template/packages/shared/package.json +33 -0
- package/template/packages/shared/src/edge/origins.ts +20 -0
- package/template/packages/shared/src/edge/turnstile.ts +11 -0
- package/template/packages/shared/src/locales.ts +13 -0
- package/template/packages/shared/src/message-rules.ts +16 -0
- package/template/packages/shared/src/messages.test.ts +26 -0
- package/template/packages/shared/src/messages.ts +30 -0
- package/template/packages/shared/src/observability/build-release.ts +9 -0
- package/template/packages/shared/src/observability/error-reporting.ts +31 -0
- package/template/packages/shared/src/observability/error-tunnel.ts +20 -0
- package/template/packages/shared/src/observability/sentry-browser.ts +1 -0
- package/template/packages/shared/src/observability/server-errors.ts +74 -0
- package/template/packages/shared/src/project.ts +1 -0
- package/template/packages/shared/src/styles/rc-theme.css +138 -0
- package/template/packages/shared/src/styles/theme.css +9 -0
- package/template/packages/shared/tsconfig.json +10 -0
- package/template/rc.config.json +25 -0
- package/template/scripts/bootstrap-local.ts +42 -0
- package/template/tsconfig.base.json +20 -0
- package/template/tsconfig.json +8 -0
- package/template/tsconfig.worker.json +7 -0
- package/template/turbo.json +40 -0
- package/template/vite.config.ts +8 -0
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
import type { LevelRef, WranglerConfig, WranglerLevel } from "./wrangler"
|
|
2
|
+
import { bindingsOf, levelsOf } from "./wrangler"
|
|
3
|
+
|
|
4
|
+
export type Account = string
|
|
5
|
+
|
|
6
|
+
const ACCOUNT_RE = /^[a-z][a-z0-9-]*$/
|
|
7
|
+
|
|
8
|
+
export const WORKER_ROLES = [
|
|
9
|
+
"web",
|
|
10
|
+
"admin",
|
|
11
|
+
"app",
|
|
12
|
+
"api",
|
|
13
|
+
"site",
|
|
14
|
+
"jobs",
|
|
15
|
+
"mail",
|
|
16
|
+
"realtime",
|
|
17
|
+
"pos",
|
|
18
|
+
"studio",
|
|
19
|
+
] as const
|
|
20
|
+
|
|
21
|
+
export const ENVIRONMENTS = ["local", "dev", "staging", "prod"] as const
|
|
22
|
+
|
|
23
|
+
export type Environment = (typeof ENVIRONMENTS)[number]
|
|
24
|
+
|
|
25
|
+
export type ResourceKind =
|
|
26
|
+
| "d1"
|
|
27
|
+
| "kv"
|
|
28
|
+
| "r2"
|
|
29
|
+
| "queue"
|
|
30
|
+
| "workflow"
|
|
31
|
+
| "hyperdrive"
|
|
32
|
+
| "vectorize"
|
|
33
|
+
| "ai_gateway"
|
|
34
|
+
|
|
35
|
+
interface ResourceRule {
|
|
36
|
+
token: string
|
|
37
|
+
usage: "none" | "optional" | "required"
|
|
38
|
+
synonyms: string[]
|
|
39
|
+
label: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const RESOURCE_RULES: Record<ResourceKind, ResourceRule> = {
|
|
43
|
+
d1: {
|
|
44
|
+
token: "d1",
|
|
45
|
+
usage: "optional",
|
|
46
|
+
synonyms: ["d1", "db", "database"],
|
|
47
|
+
label: "D1",
|
|
48
|
+
},
|
|
49
|
+
kv: { token: "kv", usage: "optional", synonyms: ["kv"], label: "KV" },
|
|
50
|
+
r2: {
|
|
51
|
+
token: "",
|
|
52
|
+
usage: "required",
|
|
53
|
+
synonyms: ["r2", "bucket"],
|
|
54
|
+
label: "R2",
|
|
55
|
+
},
|
|
56
|
+
queue: {
|
|
57
|
+
token: "queue",
|
|
58
|
+
usage: "required",
|
|
59
|
+
synonyms: ["queue", "q"],
|
|
60
|
+
label: "Queue",
|
|
61
|
+
},
|
|
62
|
+
workflow: {
|
|
63
|
+
token: "wf",
|
|
64
|
+
usage: "required",
|
|
65
|
+
synonyms: ["wf", "workflow"],
|
|
66
|
+
label: "Workflow",
|
|
67
|
+
},
|
|
68
|
+
hyperdrive: {
|
|
69
|
+
token: "hyperdrive",
|
|
70
|
+
usage: "optional",
|
|
71
|
+
synonyms: ["hyperdrive"],
|
|
72
|
+
label: "Hyperdrive",
|
|
73
|
+
},
|
|
74
|
+
vectorize: {
|
|
75
|
+
token: "vec",
|
|
76
|
+
usage: "required",
|
|
77
|
+
synonyms: ["vec", "vectorize", "index"],
|
|
78
|
+
label: "Vectorize",
|
|
79
|
+
},
|
|
80
|
+
ai_gateway: {
|
|
81
|
+
token: "ai-gateway",
|
|
82
|
+
usage: "none",
|
|
83
|
+
synonyms: ["ai", "gateway"],
|
|
84
|
+
label: "AI Gateway",
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const PREFIX_RE = /^[a-z]{3}$/
|
|
89
|
+
const UPPER_SNAKE_RE = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/
|
|
90
|
+
const PASCAL_CASE_RE = /^[A-Z][A-Za-z0-9]*$/
|
|
91
|
+
const UUID_RE =
|
|
92
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
93
|
+
const KV_ID_RE = /^[0-9a-f]{32}$/i
|
|
94
|
+
const USAGE = "[a-z0-9]+(?:-[a-z0-9]+)*"
|
|
95
|
+
const GATEWAY_VAR_RE = /(?:^|_)GATEWAY(?:_ID|_NAME)?$/
|
|
96
|
+
const BUCKET_VAR_RE = /_BUCKET(?:_NAME)?$/
|
|
97
|
+
const ENV_WORDS = new Set([
|
|
98
|
+
"local",
|
|
99
|
+
"dev",
|
|
100
|
+
"staging",
|
|
101
|
+
"prod",
|
|
102
|
+
"production",
|
|
103
|
+
"preview",
|
|
104
|
+
])
|
|
105
|
+
const ACCOUNT_ID_RE = /^[0-9a-f]{32}$/
|
|
106
|
+
|
|
107
|
+
export function isAccount(value: unknown): value is Account {
|
|
108
|
+
return typeof value === "string" && ACCOUNT_RE.test(value)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function isAccountId(value: string): boolean {
|
|
112
|
+
return ACCOUNT_ID_RE.test(value)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function isValidPrefix(value: string): boolean {
|
|
116
|
+
return PREFIX_RE.test(value)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function isWorkerRole(value: string): boolean {
|
|
120
|
+
return (WORKER_ROLES as readonly string[]).includes(value)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function isUpperSnake(value: string): boolean {
|
|
124
|
+
return UPPER_SNAKE_RE.test(value)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function environmentOfKey(key: string | null): Environment | null {
|
|
128
|
+
if (key === null) {
|
|
129
|
+
return "local"
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (key === "production") {
|
|
133
|
+
return "prod"
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (key === "staging" || key === "dev") {
|
|
137
|
+
return key
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return null
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function escape(value: string): string {
|
|
144
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function envAlternation(envs: readonly string[]): string {
|
|
148
|
+
return `(?:${envs.map(escape).join("|")})`
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function resourceHead(rule: ResourceRule, prefix: string): string {
|
|
152
|
+
return rule.token ? `${prefix}-${rule.token}` : prefix
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function resourcePattern(
|
|
156
|
+
kind: ResourceKind,
|
|
157
|
+
prefix: string,
|
|
158
|
+
envs: readonly string[]
|
|
159
|
+
): RegExp {
|
|
160
|
+
const rule = RESOURCE_RULES[kind]
|
|
161
|
+
const head = escape(resourceHead(rule, prefix))
|
|
162
|
+
const bannedLead = rule.token ? "" : `(?!(?:${rule.synonyms.join("|")})-)`
|
|
163
|
+
const usage =
|
|
164
|
+
rule.usage === "none"
|
|
165
|
+
? ""
|
|
166
|
+
: rule.usage === "optional"
|
|
167
|
+
? `(?:-${USAGE})?`
|
|
168
|
+
: `-${bannedLead}${USAGE}`
|
|
169
|
+
|
|
170
|
+
return new RegExp(`^${head}${usage}-${envAlternation(envs)}$`)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function workerPattern(prefix: string, envs: readonly string[]): RegExp {
|
|
174
|
+
return new RegExp(
|
|
175
|
+
`^${escape(prefix)}-${envAlternation(WORKER_ROLES)}-${envAlternation(envs)}$`
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function expectedWorkerName(
|
|
180
|
+
prefix: string,
|
|
181
|
+
role: string,
|
|
182
|
+
env: string
|
|
183
|
+
): string {
|
|
184
|
+
return `${prefix}-${role}-${env}`
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function resourceForm(
|
|
188
|
+
kind: ResourceKind,
|
|
189
|
+
prefix: string,
|
|
190
|
+
env: string
|
|
191
|
+
): string {
|
|
192
|
+
const rule = RESOURCE_RULES[kind]
|
|
193
|
+
const usage =
|
|
194
|
+
rule.usage === "none"
|
|
195
|
+
? ""
|
|
196
|
+
: rule.usage === "optional"
|
|
197
|
+
? "[-<usage>]"
|
|
198
|
+
: "-<usage>"
|
|
199
|
+
|
|
200
|
+
return `${resourceHead(rule, prefix)}${usage}-${env}`
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function suggestResourceName(
|
|
204
|
+
kind: ResourceKind,
|
|
205
|
+
value: string,
|
|
206
|
+
context: { prefix: string; env: string; project?: string }
|
|
207
|
+
): string {
|
|
208
|
+
const rule = RESOURCE_RULES[kind]
|
|
209
|
+
const head = resourceHead(rule, context.prefix)
|
|
210
|
+
|
|
211
|
+
if (rule.usage === "none") {
|
|
212
|
+
return `${head}-${context.env}`
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const leadingNoise = new Set([
|
|
216
|
+
context.prefix,
|
|
217
|
+
...(context.project?.split("-") ?? []),
|
|
218
|
+
...rule.synonyms,
|
|
219
|
+
...WORKER_ROLES,
|
|
220
|
+
])
|
|
221
|
+
const words = value
|
|
222
|
+
.toLowerCase()
|
|
223
|
+
.split(/[^a-z0-9]+/)
|
|
224
|
+
.filter((token) => token && !ENV_WORDS.has(token))
|
|
225
|
+
const foreignPrefix = words.length > 1 && PREFIX_RE.test(words[0] ?? "")
|
|
226
|
+
const tokens = foreignPrefix ? words.slice(1) : words
|
|
227
|
+
const firstUsage = tokens.findIndex((token) => !leadingNoise.has(token))
|
|
228
|
+
const usage = (firstUsage === -1 ? [] : tokens.slice(firstUsage))
|
|
229
|
+
.filter((token) => !rule.synonyms.includes(token))
|
|
230
|
+
.join("-")
|
|
231
|
+
|
|
232
|
+
if (usage) {
|
|
233
|
+
return `${head}-${usage}-${context.env}`
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return rule.usage === "optional"
|
|
237
|
+
? `${head}-${context.env}`
|
|
238
|
+
: `${head}-<usage>-${context.env}`
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface NamingOptions {
|
|
242
|
+
prefix: string
|
|
243
|
+
accountId?: string
|
|
244
|
+
role: string
|
|
245
|
+
project?: string
|
|
246
|
+
legacy?: readonly string[]
|
|
247
|
+
externalWorkers?: readonly string[]
|
|
248
|
+
clients?: Readonly<Record<string, string>>
|
|
249
|
+
file?: string
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface NamingViolation {
|
|
253
|
+
file: string
|
|
254
|
+
level: string
|
|
255
|
+
subject: string
|
|
256
|
+
value: string
|
|
257
|
+
message: string
|
|
258
|
+
suggestion?: string
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export interface NamingResult {
|
|
262
|
+
violations: NamingViolation[]
|
|
263
|
+
tolerated: NamingViolation[]
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
interface LevelContext {
|
|
267
|
+
ref: LevelRef
|
|
268
|
+
prefix: string
|
|
269
|
+
env: Environment
|
|
270
|
+
referenceEnvs: readonly string[]
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function singleLevelEnvironment(name: string | undefined): Environment {
|
|
274
|
+
const suffix = name?.split("-").at(-1)
|
|
275
|
+
|
|
276
|
+
return ENVIRONMENTS.find((env) => env === suffix) ?? "prod"
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function clientPrefix(
|
|
280
|
+
key: string,
|
|
281
|
+
level: WranglerLevel,
|
|
282
|
+
options: NamingOptions
|
|
283
|
+
): string | null {
|
|
284
|
+
const declared = options.clients?.[key]
|
|
285
|
+
|
|
286
|
+
if (declared) {
|
|
287
|
+
return declared
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const inferred = level.name?.match(/^([a-z]{3})-/)?.[1]
|
|
291
|
+
|
|
292
|
+
return inferred && inferred !== options.prefix ? inferred : null
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
class Collector {
|
|
296
|
+
readonly violations: NamingViolation[] = []
|
|
297
|
+
|
|
298
|
+
constructor(private readonly file: string) {}
|
|
299
|
+
|
|
300
|
+
add(
|
|
301
|
+
level: string,
|
|
302
|
+
subject: string,
|
|
303
|
+
value: string,
|
|
304
|
+
message: string,
|
|
305
|
+
suggestion?: string
|
|
306
|
+
): void {
|
|
307
|
+
this.violations.push({
|
|
308
|
+
file: this.file,
|
|
309
|
+
level,
|
|
310
|
+
subject,
|
|
311
|
+
value,
|
|
312
|
+
message,
|
|
313
|
+
...(suggestion ? { suggestion } : {}),
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function checkResource(
|
|
319
|
+
collector: Collector,
|
|
320
|
+
context: LevelContext,
|
|
321
|
+
kind: ResourceKind,
|
|
322
|
+
subject: string,
|
|
323
|
+
value: string | undefined,
|
|
324
|
+
options: NamingOptions,
|
|
325
|
+
envs: readonly string[] = [context.env]
|
|
326
|
+
): void {
|
|
327
|
+
if (!value || resourcePattern(kind, context.prefix, envs).test(value)) {
|
|
328
|
+
return
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
collector.add(
|
|
332
|
+
context.ref.label,
|
|
333
|
+
subject,
|
|
334
|
+
value,
|
|
335
|
+
`${subject} « ${value} » ne suit pas ${resourceForm(kind, context.prefix, envs.length === 1 ? context.env : "<env>")}`,
|
|
336
|
+
suggestResourceName(kind, value, {
|
|
337
|
+
prefix: context.prefix,
|
|
338
|
+
env: context.env,
|
|
339
|
+
project: options.project,
|
|
340
|
+
})
|
|
341
|
+
)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function checkWorkerReference(
|
|
345
|
+
collector: Collector,
|
|
346
|
+
context: LevelContext,
|
|
347
|
+
subject: string,
|
|
348
|
+
value: string | undefined
|
|
349
|
+
): void {
|
|
350
|
+
if (!value || workerPattern(context.prefix, [context.env]).test(value)) {
|
|
351
|
+
return
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
collector.add(
|
|
355
|
+
context.ref.label,
|
|
356
|
+
subject,
|
|
357
|
+
value,
|
|
358
|
+
`${subject} « ${value} » doit viser un Worker ${context.prefix}-<rôle>-${context.env} du même environnement`
|
|
359
|
+
)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function checkBindingName(
|
|
363
|
+
collector: Collector,
|
|
364
|
+
context: LevelContext,
|
|
365
|
+
subject: string,
|
|
366
|
+
name: string,
|
|
367
|
+
suffix?: string
|
|
368
|
+
): void {
|
|
369
|
+
if (!isUpperSnake(name)) {
|
|
370
|
+
collector.add(
|
|
371
|
+
context.ref.label,
|
|
372
|
+
subject,
|
|
373
|
+
name,
|
|
374
|
+
`${subject} « ${name} » doit être en UPPER_SNAKE_CASE`,
|
|
375
|
+
name
|
|
376
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
377
|
+
.replace(/[^A-Za-z0-9]+/g, "_")
|
|
378
|
+
.toUpperCase()
|
|
379
|
+
)
|
|
380
|
+
return
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (suffix && !name.endsWith(suffix)) {
|
|
384
|
+
const stem = name.replace(
|
|
385
|
+
/_(RATE_LIMIT|RATELIMIT|LIMITER|LIMIT|WORKFLOW|WF|QUEUE|Q)$/,
|
|
386
|
+
""
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
collector.add(
|
|
390
|
+
context.ref.label,
|
|
391
|
+
subject,
|
|
392
|
+
name,
|
|
393
|
+
`${subject} « ${name} » doit finir par ${suffix}`,
|
|
394
|
+
`${stem}${suffix}`
|
|
395
|
+
)
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function checkWorkerName(
|
|
400
|
+
collector: Collector,
|
|
401
|
+
context: LevelContext,
|
|
402
|
+
options: NamingOptions
|
|
403
|
+
): void {
|
|
404
|
+
const { level, label, key } = context.ref
|
|
405
|
+
|
|
406
|
+
if (!level.name) {
|
|
407
|
+
collector.add(
|
|
408
|
+
label,
|
|
409
|
+
"Worker",
|
|
410
|
+
"",
|
|
411
|
+
key === null
|
|
412
|
+
? "le niveau haut ne déclare pas de name"
|
|
413
|
+
: `env.${key} ne déclare pas de name (Wrangler en déduirait un nom hors convention)`,
|
|
414
|
+
expectedWorkerName(context.prefix, options.role, context.env)
|
|
415
|
+
)
|
|
416
|
+
return
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const expected = expectedWorkerName(context.prefix, options.role, context.env)
|
|
420
|
+
|
|
421
|
+
if (level.name !== expected) {
|
|
422
|
+
collector.add(
|
|
423
|
+
label,
|
|
424
|
+
"Worker",
|
|
425
|
+
level.name,
|
|
426
|
+
`Worker « ${level.name} » : attendu ${expected} (<pfx>-<rôle>-<env>)`,
|
|
427
|
+
expected
|
|
428
|
+
)
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function checkAccount(
|
|
433
|
+
collector: Collector,
|
|
434
|
+
context: LevelContext,
|
|
435
|
+
options: NamingOptions
|
|
436
|
+
): void {
|
|
437
|
+
const expected = options.accountId
|
|
438
|
+
const actual = context.ref.level.account_id
|
|
439
|
+
|
|
440
|
+
if (context.ref.key === null && !actual) {
|
|
441
|
+
collector.add(
|
|
442
|
+
context.ref.label,
|
|
443
|
+
"account_id",
|
|
444
|
+
"",
|
|
445
|
+
"account_id absent : chaque wrangler.jsonc déclare le compte Cloudflare du projet",
|
|
446
|
+
expected
|
|
447
|
+
)
|
|
448
|
+
return
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (!actual) {
|
|
452
|
+
return
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (!isAccountId(actual)) {
|
|
456
|
+
collector.add(
|
|
457
|
+
context.ref.label,
|
|
458
|
+
"account_id",
|
|
459
|
+
actual,
|
|
460
|
+
`account_id « ${actual} » : 32 caractères hexadécimaux attendus`
|
|
461
|
+
)
|
|
462
|
+
return
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (expected && actual !== expected) {
|
|
466
|
+
collector.add(
|
|
467
|
+
context.ref.label,
|
|
468
|
+
"account_id",
|
|
469
|
+
actual,
|
|
470
|
+
`account_id « ${actual} » diffère de celui des autres Workers du projet`,
|
|
471
|
+
expected
|
|
472
|
+
)
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
function checkVars(
|
|
477
|
+
collector: Collector,
|
|
478
|
+
context: LevelContext,
|
|
479
|
+
options: NamingOptions
|
|
480
|
+
): void {
|
|
481
|
+
for (const [key, value] of Object.entries(context.ref.level.vars ?? {})) {
|
|
482
|
+
checkBindingName(collector, context, "var", key)
|
|
483
|
+
|
|
484
|
+
if (
|
|
485
|
+
typeof value !== "string" ||
|
|
486
|
+
value.trim() === "" ||
|
|
487
|
+
value.includes("/")
|
|
488
|
+
) {
|
|
489
|
+
continue
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (GATEWAY_VAR_RE.test(key)) {
|
|
493
|
+
checkResource(
|
|
494
|
+
collector,
|
|
495
|
+
context,
|
|
496
|
+
"ai_gateway",
|
|
497
|
+
`AI Gateway (${key})`,
|
|
498
|
+
value,
|
|
499
|
+
options,
|
|
500
|
+
context.referenceEnvs
|
|
501
|
+
)
|
|
502
|
+
} else if (BUCKET_VAR_RE.test(key)) {
|
|
503
|
+
checkResource(
|
|
504
|
+
collector,
|
|
505
|
+
context,
|
|
506
|
+
"r2",
|
|
507
|
+
`R2 (${key})`,
|
|
508
|
+
value,
|
|
509
|
+
options,
|
|
510
|
+
context.referenceEnvs
|
|
511
|
+
)
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
for (const secret of context.ref.level.secrets?.required ?? []) {
|
|
516
|
+
checkBindingName(collector, context, "secret", secret)
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function checkResources(
|
|
521
|
+
collector: Collector,
|
|
522
|
+
context: LevelContext,
|
|
523
|
+
options: NamingOptions
|
|
524
|
+
): void {
|
|
525
|
+
const { level } = context.ref
|
|
526
|
+
const isLocal = context.env === "local"
|
|
527
|
+
|
|
528
|
+
for (const database of level.d1_databases ?? []) {
|
|
529
|
+
checkResource(
|
|
530
|
+
collector,
|
|
531
|
+
context,
|
|
532
|
+
"d1",
|
|
533
|
+
"D1 database_name",
|
|
534
|
+
database.database_name,
|
|
535
|
+
options
|
|
536
|
+
)
|
|
537
|
+
|
|
538
|
+
if (
|
|
539
|
+
isLocal &&
|
|
540
|
+
database.database_id &&
|
|
541
|
+
!UUID_RE.test(database.database_id)
|
|
542
|
+
) {
|
|
543
|
+
checkResource(
|
|
544
|
+
collector,
|
|
545
|
+
context,
|
|
546
|
+
"d1",
|
|
547
|
+
"D1 database_id local",
|
|
548
|
+
database.database_id,
|
|
549
|
+
options
|
|
550
|
+
)
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
for (const bucket of level.r2_buckets ?? []) {
|
|
555
|
+
checkResource(
|
|
556
|
+
collector,
|
|
557
|
+
context,
|
|
558
|
+
"r2",
|
|
559
|
+
"R2 bucket_name",
|
|
560
|
+
bucket.bucket_name,
|
|
561
|
+
options
|
|
562
|
+
)
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
for (const namespace of level.kv_namespaces ?? []) {
|
|
566
|
+
if (namespace.id && !KV_ID_RE.test(namespace.id)) {
|
|
567
|
+
checkResource(
|
|
568
|
+
collector,
|
|
569
|
+
context,
|
|
570
|
+
"kv",
|
|
571
|
+
"KV id local",
|
|
572
|
+
namespace.id,
|
|
573
|
+
options
|
|
574
|
+
)
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
for (const producer of level.queues?.producers ?? []) {
|
|
579
|
+
checkResource(collector, context, "queue", "Queue", producer.queue, options)
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
for (const consumer of level.queues?.consumers ?? []) {
|
|
583
|
+
checkResource(
|
|
584
|
+
collector,
|
|
585
|
+
context,
|
|
586
|
+
"queue",
|
|
587
|
+
"Queue (consumer)",
|
|
588
|
+
consumer.queue,
|
|
589
|
+
options
|
|
590
|
+
)
|
|
591
|
+
checkResource(
|
|
592
|
+
collector,
|
|
593
|
+
context,
|
|
594
|
+
"queue",
|
|
595
|
+
"Queue (dead_letter_queue)",
|
|
596
|
+
consumer.dead_letter_queue,
|
|
597
|
+
options
|
|
598
|
+
)
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
for (const workflow of level.workflows ?? []) {
|
|
602
|
+
checkResource(
|
|
603
|
+
collector,
|
|
604
|
+
context,
|
|
605
|
+
"workflow",
|
|
606
|
+
"Workflow",
|
|
607
|
+
workflow.name,
|
|
608
|
+
options
|
|
609
|
+
)
|
|
610
|
+
checkWorkerReference(
|
|
611
|
+
collector,
|
|
612
|
+
context,
|
|
613
|
+
"Workflow script_name",
|
|
614
|
+
workflow.script_name
|
|
615
|
+
)
|
|
616
|
+
|
|
617
|
+
if (workflow.class_name && !PASCAL_CASE_RE.test(workflow.class_name)) {
|
|
618
|
+
collector.add(
|
|
619
|
+
context.ref.label,
|
|
620
|
+
"classe de Workflow",
|
|
621
|
+
workflow.class_name,
|
|
622
|
+
`classe « ${workflow.class_name} » : PascalCase attendu`
|
|
623
|
+
)
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
for (const index of level.vectorize ?? []) {
|
|
628
|
+
checkResource(
|
|
629
|
+
collector,
|
|
630
|
+
context,
|
|
631
|
+
"vectorize",
|
|
632
|
+
"Vectorize index_name",
|
|
633
|
+
index.index_name,
|
|
634
|
+
options
|
|
635
|
+
)
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
for (const service of level.services ?? []) {
|
|
639
|
+
if (service.service && options.externalWorkers?.includes(service.service)) {
|
|
640
|
+
continue
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
checkWorkerReference(
|
|
644
|
+
collector,
|
|
645
|
+
context,
|
|
646
|
+
"binding de service",
|
|
647
|
+
service.service
|
|
648
|
+
)
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
for (const object of level.durable_objects?.bindings ?? []) {
|
|
652
|
+
checkWorkerReference(
|
|
653
|
+
collector,
|
|
654
|
+
context,
|
|
655
|
+
"Durable Object script_name",
|
|
656
|
+
object.script_name
|
|
657
|
+
)
|
|
658
|
+
|
|
659
|
+
if (object.class_name && !PASCAL_CASE_RE.test(object.class_name)) {
|
|
660
|
+
collector.add(
|
|
661
|
+
context.ref.label,
|
|
662
|
+
"classe de Durable Object",
|
|
663
|
+
object.class_name,
|
|
664
|
+
`classe « ${object.class_name} » : PascalCase attendu`
|
|
665
|
+
)
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const BINDING_SUFFIXES: Partial<Record<string, string>> = {
|
|
671
|
+
ratelimit: "_RATE_LIMITER",
|
|
672
|
+
workflow: "_WORKFLOW",
|
|
673
|
+
queue: "_QUEUE",
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function checkBindings(collector: Collector, context: LevelContext): void {
|
|
677
|
+
for (const binding of bindingsOf(context.ref.level)) {
|
|
678
|
+
checkBindingName(
|
|
679
|
+
collector,
|
|
680
|
+
context,
|
|
681
|
+
`binding ${binding.kind}`,
|
|
682
|
+
binding.name,
|
|
683
|
+
BINDING_SUFFIXES[binding.kind]
|
|
684
|
+
)
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function levelContext(
|
|
689
|
+
ref: LevelRef,
|
|
690
|
+
config: WranglerConfig,
|
|
691
|
+
options: NamingOptions,
|
|
692
|
+
collector: Collector
|
|
693
|
+
): LevelContext | null {
|
|
694
|
+
if (ref.key === null) {
|
|
695
|
+
const env = config.env ? "local" : singleLevelEnvironment(config.name)
|
|
696
|
+
|
|
697
|
+
return {
|
|
698
|
+
ref,
|
|
699
|
+
prefix: options.prefix,
|
|
700
|
+
env,
|
|
701
|
+
referenceEnvs: env === "local" ? ENVIRONMENTS : [env],
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
const env = environmentOfKey(ref.key)
|
|
706
|
+
|
|
707
|
+
if (env) {
|
|
708
|
+
return { ref, prefix: options.prefix, env, referenceEnvs: [env] }
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
const prefix = clientPrefix(ref.key, ref.level, options)
|
|
712
|
+
|
|
713
|
+
if (!prefix) {
|
|
714
|
+
collector.add(
|
|
715
|
+
ref.label,
|
|
716
|
+
"préfixe client",
|
|
717
|
+
ref.key,
|
|
718
|
+
`env.${ref.key} est un déploiement client : il lui faut son propre préfixe, déclaré dans naming.clients de rc.config.json`
|
|
719
|
+
)
|
|
720
|
+
return null
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (!isValidPrefix(prefix)) {
|
|
724
|
+
collector.add(
|
|
725
|
+
ref.label,
|
|
726
|
+
"préfixe client",
|
|
727
|
+
prefix,
|
|
728
|
+
`préfixe client « ${prefix} » : trois lettres minuscules attendues`
|
|
729
|
+
)
|
|
730
|
+
return null
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
return { ref, prefix, env: "prod", referenceEnvs: ["prod"] }
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
export function checkWranglerNaming(
|
|
737
|
+
config: WranglerConfig,
|
|
738
|
+
options: NamingOptions
|
|
739
|
+
): NamingResult {
|
|
740
|
+
const collector = new Collector(options.file ?? "wrangler.jsonc")
|
|
741
|
+
const legacy = new Set(options.legacy ?? [])
|
|
742
|
+
|
|
743
|
+
if (!isWorkerRole(options.role)) {
|
|
744
|
+
collector.add(
|
|
745
|
+
"rc.config.json",
|
|
746
|
+
"rôle",
|
|
747
|
+
options.role,
|
|
748
|
+
`rôle « ${options.role} » hors liste (${WORKER_ROLES.join(", ")}) : renomme la clé de l'app dans rc.config.json`
|
|
749
|
+
)
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
for (const ref of levelsOf(config)) {
|
|
753
|
+
const context = levelContext(ref, config, options, collector)
|
|
754
|
+
|
|
755
|
+
if (!context) {
|
|
756
|
+
continue
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
checkWorkerName(collector, context, options)
|
|
760
|
+
checkAccount(collector, context, options)
|
|
761
|
+
checkResources(collector, context, options)
|
|
762
|
+
checkBindings(collector, context)
|
|
763
|
+
checkVars(collector, context, options)
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
return {
|
|
767
|
+
violations: collector.violations.filter(
|
|
768
|
+
(violation) => !legacy.has(violation.value)
|
|
769
|
+
),
|
|
770
|
+
tolerated: collector.violations.filter((violation) =>
|
|
771
|
+
legacy.has(violation.value)
|
|
772
|
+
),
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
export function formatNamingViolation(violation: NamingViolation): string {
|
|
777
|
+
const hint = violation.suggestion ? ` → ${violation.suggestion}` : ""
|
|
778
|
+
|
|
779
|
+
return `${violation.file} [${violation.level}] ${violation.message}${hint}`
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
export function formatNamingReport(result: NamingResult): string {
|
|
783
|
+
const lines = result.violations.map(formatNamingViolation)
|
|
784
|
+
|
|
785
|
+
if (result.tolerated.length > 0) {
|
|
786
|
+
lines.push(
|
|
787
|
+
`${result.tolerated.length} nom(s) hérité(s) toléré(s) par naming.legacy : ${[...new Set(result.tolerated.map((violation) => violation.value))].join(", ")}`
|
|
788
|
+
)
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
if (result.violations.length === 0) {
|
|
792
|
+
lines.unshift("Nommage Cloudflare conforme.")
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return lines.join("\n")
|
|
796
|
+
}
|