@slotform/cloudflare 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,27 @@
1
+ import { SlotformError } from "@slotform/cli/errors";
2
+
3
+ // The env-name rule: docs/architecture/plugins/cloudflare.md, "Env namespace".
4
+ const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
5
+
6
+ export function assertEnvName(name: string): void {
7
+ if (!ENV_NAME.test(name)) {
8
+ throw new SlotformError(
9
+ `Invalid env var name "${name}": use letters, digits and underscores, not starting with a digit (e.g. AUTH_SECRET).`,
10
+ "INVALID_ENV_NAME",
11
+ );
12
+ }
13
+ }
14
+
15
+ function escapeRegExp(text: string): string {
16
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
17
+ }
18
+
19
+ // Whether a `.dev.vars` file already assigns `name` on a line of its own, in
20
+ // any form wrangler's dotenv parser reads: `export ` before it, blanks
21
+ // around `=`, or `NAME: value`.
22
+ export function declaresDevVar(content: string, name: string): boolean {
23
+ return new RegExp(
24
+ `^[ \\t]*(?:export[ \\t]+)?${escapeRegExp(name)}(?:[ \\t]*=|:[ \\t])`,
25
+ "m",
26
+ ).test(content);
27
+ }
package/src/types.ts ADDED
@@ -0,0 +1,56 @@
1
+ import type { EnvSpec } from "@slotform/api/types";
2
+ import { z } from "zod";
3
+
4
+ export const cloudflareOptionsSchema = z.object({}).optional();
5
+
6
+ export type WranglerBindingSpec =
7
+ | {
8
+ kind: "d1";
9
+ binding: string;
10
+ databaseName: string;
11
+ databaseId: string;
12
+ migrationsDir?: string;
13
+ }
14
+ | { kind: "kv"; binding: string; id: string }
15
+ | { kind: "r2"; binding: string; bucketName: string }
16
+ | { kind: "analytics_engine"; binding: string; dataset: string }
17
+ | {
18
+ kind: "rate_limiter";
19
+ binding: string;
20
+ simple: { limit: number; period: number };
21
+ }
22
+ | {
23
+ kind: "queue";
24
+ binding: string;
25
+ queue: string;
26
+ consumer?: {
27
+ maxBatchSize: number;
28
+ maxBatchTimeout: number;
29
+ maxRetries: number;
30
+ };
31
+ }
32
+ | { kind: "var"; name: string; value: string };
33
+
34
+ export interface CodegenWranglerPayload {
35
+ bindings: WranglerBindingSpec[];
36
+ secrets: EnvSpec[];
37
+ compatibilityDate: string;
38
+ compatibilityFlags: string[];
39
+ // The web client's build directory, relative to the project root; null
40
+ // when no plugin builds one.
41
+ clientDir: string | null;
42
+ routePrefixes: string[];
43
+ // Whether `src/worker/queue.ts` / `src/worker/scheduled.ts` exist: the root
44
+ // file's `[[queues.consumers]]` and `[triggers] crons` are checked against them.
45
+ queueHandler: boolean;
46
+ scheduledHandler: boolean;
47
+ serve?: ServeConfig;
48
+ }
49
+
50
+ // A `slotform screens serve` run's config: its own entry, its own copy of the
51
+ // client build (absolute, null without a web client), and the `/fixture`
52
+ // controls on the worker's paths.
53
+ export interface ServeConfig {
54
+ main: string;
55
+ clientDir: string | null;
56
+ }