@rexezuge/tooling 0.0.0-stage → 1.0.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.
- package/LICENSE +21 -0
- package/README.md +297 -2
- package/dist/eslint-boundaries.d.ts +75 -0
- package/dist/eslint-boundaries.d.ts.map +1 -0
- package/dist/eslint-boundaries.js +138 -0
- package/dist/eslint-boundaries.js.map +1 -0
- package/dist/eslint-rules.d.ts +41 -0
- package/dist/eslint-rules.d.ts.map +1 -0
- package/dist/eslint-rules.js +273 -0
- package/dist/eslint-rules.js.map +1 -0
- package/dist/eslint.d.ts +96 -0
- package/dist/eslint.d.ts.map +1 -0
- package/dist/eslint.js +189 -0
- package/dist/eslint.js.map +1 -0
- package/dist/functions/pages-proxy.d.ts +113 -0
- package/dist/functions/pages-proxy.d.ts.map +1 -0
- package/dist/functions/pages-proxy.js +131 -0
- package/dist/functions/pages-proxy.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/scripts/backup/d1-target.d.ts +35 -0
- package/dist/scripts/backup/d1-target.d.ts.map +1 -0
- package/dist/scripts/backup/d1-target.js +31 -0
- package/dist/scripts/backup/d1-target.js.map +1 -0
- package/dist/scripts/backup/destination-config.d.ts +61 -0
- package/dist/scripts/backup/destination-config.d.ts.map +1 -0
- package/dist/scripts/backup/destination-config.js +57 -0
- package/dist/scripts/backup/destination-config.js.map +1 -0
- package/dist/scripts/backup/encrypt-backup.d.ts +35 -0
- package/dist/scripts/backup/encrypt-backup.d.ts.map +1 -0
- package/dist/scripts/backup/encrypt-backup.js +98 -0
- package/dist/scripts/backup/encrypt-backup.js.map +1 -0
- package/dist/scripts/backup/naming.d.ts +44 -0
- package/dist/scripts/backup/naming.d.ts.map +1 -0
- package/dist/scripts/backup/naming.js +58 -0
- package/dist/scripts/backup/naming.js.map +1 -0
- package/dist/scripts/check-god-files.d.ts +164 -0
- package/dist/scripts/check-god-files.d.ts.map +1 -0
- package/dist/scripts/check-god-files.js +271 -0
- package/dist/scripts/check-god-files.js.map +1 -0
- package/dist/scripts/ensure-spa-shell-stub.d.ts +3 -0
- package/dist/scripts/ensure-spa-shell-stub.d.ts.map +1 -0
- package/dist/scripts/ensure-spa-shell-stub.js +30 -0
- package/dist/scripts/ensure-spa-shell-stub.js.map +1 -0
- package/dist/scripts/init-secrets.d.ts +63 -0
- package/dist/scripts/init-secrets.d.ts.map +1 -0
- package/dist/scripts/init-secrets.js +240 -0
- package/dist/scripts/init-secrets.js.map +1 -0
- package/dist/scripts/lib/cli-args.d.ts +78 -0
- package/dist/scripts/lib/cli-args.d.ts.map +1 -0
- package/dist/scripts/lib/cli-args.js +116 -0
- package/dist/scripts/lib/cli-args.js.map +1 -0
- package/dist/scripts/lib/github-actions.d.ts +26 -0
- package/dist/scripts/lib/github-actions.d.ts.map +1 -0
- package/dist/scripts/lib/github-actions.js +38 -0
- package/dist/scripts/lib/github-actions.js.map +1 -0
- package/dist/scripts/lib/wrangler-table.d.ts +46 -0
- package/dist/scripts/lib/wrangler-table.d.ts.map +1 -0
- package/dist/scripts/lib/wrangler-table.js +99 -0
- package/dist/scripts/lib/wrangler-table.js.map +1 -0
- package/dist/scripts/migrations-lock.d.ts +3 -0
- package/dist/scripts/migrations-lock.d.ts.map +1 -0
- package/dist/scripts/migrations-lock.js +46 -0
- package/dist/scripts/migrations-lock.js.map +1 -0
- package/dist/scripts/prepare-wrangler-config.d.ts +3 -0
- package/dist/scripts/prepare-wrangler-config.d.ts.map +1 -0
- package/dist/scripts/prepare-wrangler-config.js +50 -0
- package/dist/scripts/prepare-wrangler-config.js.map +1 -0
- package/dist/scripts/spa-shell.d.ts +41 -0
- package/dist/scripts/spa-shell.d.ts.map +1 -0
- package/dist/scripts/spa-shell.js +155 -0
- package/dist/scripts/spa-shell.js.map +1 -0
- package/dist/scripts/validate-locales.d.ts +26 -0
- package/dist/scripts/validate-locales.d.ts.map +1 -0
- package/dist/scripts/validate-locales.js +350 -0
- package/dist/scripts/validate-locales.js.map +1 -0
- package/dist/scripts/verify-migrations.d.ts +62 -0
- package/dist/scripts/verify-migrations.d.ts.map +1 -0
- package/dist/scripts/verify-migrations.js +302 -0
- package/dist/scripts/verify-migrations.js.map +1 -0
- package/dist/scripts/verify-spa-shell.d.ts +3 -0
- package/dist/scripts/verify-spa-shell.d.ts.map +1 -0
- package/dist/scripts/verify-spa-shell.js +53 -0
- package/dist/scripts/verify-spa-shell.js.map +1 -0
- package/dist/scripts/wrangler-config/cli.d.ts +22 -0
- package/dist/scripts/wrangler-config/cli.d.ts.map +1 -0
- package/dist/scripts/wrangler-config/cli.js +51 -0
- package/dist/scripts/wrangler-config/cli.js.map +1 -0
- package/dist/scripts/wrangler-config/patches.d.ts +51 -0
- package/dist/scripts/wrangler-config/patches.d.ts.map +1 -0
- package/dist/scripts/wrangler-config/patches.js +140 -0
- package/dist/scripts/wrangler-config/patches.js.map +1 -0
- package/dist/scripts/wrangler-config/resources.d.ts +70 -0
- package/dist/scripts/wrangler-config/resources.d.ts.map +1 -0
- package/dist/scripts/wrangler-config/resources.js +290 -0
- package/dist/scripts/wrangler-config/resources.js.map +1 -0
- package/dist/scripts/wrangler-config/types.d.ts +103 -0
- package/dist/scripts/wrangler-config/types.d.ts.map +1 -0
- package/dist/scripts/wrangler-config/types.js +49 -0
- package/dist/scripts/wrangler-config/types.js.map +1 -0
- package/dist/test/integration-migrations.d.ts +167 -0
- package/dist/test/integration-migrations.d.ts.map +1 -0
- package/dist/test/integration-migrations.js +171 -0
- package/dist/test/integration-migrations.js.map +1 -0
- package/dist/test/mocks/cloudflare-workers.d.ts +106 -0
- package/dist/test/mocks/cloudflare-workers.d.ts.map +1 -0
- package/dist/test/mocks/cloudflare-workers.js +90 -0
- package/dist/test/mocks/cloudflare-workers.js.map +1 -0
- package/dist/vite.d.ts +117 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +125 -0
- package/dist/vite.js.map +1 -0
- package/dist/vitest-web.d.ts +73 -0
- package/dist/vitest-web.d.ts.map +1 -0
- package/dist/vitest-web.js +72 -0
- package/dist/vitest-web.js.map +1 -0
- package/dist/vitest.d.ts +92 -0
- package/dist/vitest.d.ts.map +1 -0
- package/dist/vitest.js +128 -0
- package/dist/vitest.js.map +1 -0
- package/package.json +58 -3
- package/src/eslint-boundaries.ts +169 -0
- package/src/eslint-rules.ts +276 -0
- package/src/eslint.test.ts +175 -0
- package/src/eslint.ts +257 -0
- package/src/functions/pages-proxy.test.ts +72 -0
- package/src/functions/pages-proxy.ts +187 -0
- package/src/github/actions/retry-step/action.yml +39 -0
- package/src/github/actions/setup-env/action.yml +20 -0
- package/src/github/dependabot.yml +30 -0
- package/src/github/workflows/backup-main.yml +46 -0
- package/src/github/workflows/continuous-deployment.yml +188 -0
- package/src/github/workflows/continuous-integration.yml +259 -0
- package/src/github/workflows/scheduled-version-update.yml +38 -0
- package/src/github/workflows/upstream-sync.yml +56 -0
- package/src/index.ts +42 -0
- package/src/scripts/backup/backup-rules.test.ts +105 -0
- package/src/scripts/backup/d1-target.ts +54 -0
- package/src/scripts/backup/destination-config.ts +92 -0
- package/src/scripts/backup/encrypt-backup.ts +107 -0
- package/src/scripts/backup/naming.ts +62 -0
- package/src/scripts/check-god-files.test.ts +131 -0
- package/src/scripts/check-god-files.ts +327 -0
- package/src/scripts/ensure-spa-shell-stub.ts +34 -0
- package/src/scripts/init-secrets.ts +265 -0
- package/src/scripts/lib/cli-args.ts +154 -0
- package/src/scripts/lib/github-actions.ts +41 -0
- package/src/scripts/lib/wrangler-table.ts +105 -0
- package/src/scripts/migrations-lock.ts +52 -0
- package/src/scripts/prepare-wrangler-config.ts +51 -0
- package/src/scripts/spa-shell.test.ts +91 -0
- package/src/scripts/spa-shell.ts +179 -0
- package/src/scripts/validate-locales.test.ts +89 -0
- package/src/scripts/validate-locales.ts +380 -0
- package/src/scripts/verify-migrations.test.ts +71 -0
- package/src/scripts/verify-migrations.ts +364 -0
- package/src/scripts/verify-spa-shell.ts +56 -0
- package/src/scripts/wrangler-config/cli.ts +51 -0
- package/src/scripts/wrangler-config/patches.ts +157 -0
- package/src/scripts/wrangler-config/resources.ts +330 -0
- package/src/scripts/wrangler-config/types.ts +113 -0
- package/src/test/integration-migrations.test.ts +169 -0
- package/src/test/integration-migrations.ts +267 -0
- package/src/test/mocks/cloudflare-workers.ts +115 -0
- package/src/vite.test.ts +83 -0
- package/src/vite.ts +202 -0
- package/src/vitest-web.ts +109 -0
- package/src/vitest.ts +185 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading, writing and patching `wrangler.jsonc`.
|
|
3
|
+
*
|
|
4
|
+
* Provenance: ported from Edge-Sonic's `scripts/lib/wrangler-config/patches.ts`.
|
|
5
|
+
*
|
|
6
|
+
* The config is JSONC — `//` comments and trailing commas — so it is edited
|
|
7
|
+
* through jsonc-parser's `modify`/`applyEdits` rather than parsed and re-serialized.
|
|
8
|
+
* A round trip through `JSON.parse` would drop every comment and reformat the
|
|
9
|
+
* file, which is a diff nobody can review and a reason to regenerate the config by
|
|
10
|
+
* hand instead.
|
|
11
|
+
*/
|
|
12
|
+
import { copyFileSync, readFileSync, writeFileSync } from 'node:fs';
|
|
13
|
+
import { applyEdits, modify, parse } from 'jsonc-parser';
|
|
14
|
+
import { CONFIG_PATH, TEMPLATE_PATH } from './types';
|
|
15
|
+
export function readConfig() {
|
|
16
|
+
const content = readFileSync(CONFIG_PATH, 'utf8');
|
|
17
|
+
return { content, config: parse(content) };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Apply one edit to the config text, preserving comments and formatting.
|
|
21
|
+
*/
|
|
22
|
+
export function writeConfigValue(content, path, value) {
|
|
23
|
+
const edits = modify(content, path, value, { formattingOptions: { insertSpaces: true, tabSize: 2, eol: '\n' } });
|
|
24
|
+
return applyEdits(content, edits);
|
|
25
|
+
}
|
|
26
|
+
/** Write the config, guaranteeing a trailing newline so Prettier sees a fixed point. */
|
|
27
|
+
export function writeConfig(content) {
|
|
28
|
+
writeFileSync(CONFIG_PATH, content.endsWith('\n') ? content : `${content}\n`);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The top-level keys a caller wants to merge into the config, from the environment.
|
|
32
|
+
*
|
|
33
|
+
* `WRANGLER_PATCH_JSON` is how a repository variable supplies per-environment
|
|
34
|
+
* settings without a second file: a repo with one worker and three environments
|
|
35
|
+
* patches the routes and the vars rather than keeping three templates in step.
|
|
36
|
+
*/
|
|
37
|
+
export function parseTopLevelPatch() {
|
|
38
|
+
return parseJsonObject(process.env['WRANGLER_PATCH_JSON'], 'WRANGLER_PATCH_JSON', 'a JSON object');
|
|
39
|
+
}
|
|
40
|
+
/** The `vars` entries a caller wants to merge, from the environment. */
|
|
41
|
+
export function parseVarsPatch() {
|
|
42
|
+
const parsed = parseJsonObject(process.env['WRANGLER_VARS_PATCH_JSON'], 'WRANGLER_VARS_PATCH_JSON', 'a JSON object of string values');
|
|
43
|
+
if (parsed === undefined) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const patch = {};
|
|
47
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
48
|
+
if (!key.trim()) {
|
|
49
|
+
throw new Error('WRANGLER_VARS_PATCH_JSON contains an empty variable name.');
|
|
50
|
+
}
|
|
51
|
+
if (typeof value !== 'string') {
|
|
52
|
+
throw new TypeError(`WRANGLER_VARS_PATCH_JSON value for ${key} must be a string.`);
|
|
53
|
+
}
|
|
54
|
+
patch[key] = value;
|
|
55
|
+
}
|
|
56
|
+
return patch;
|
|
57
|
+
}
|
|
58
|
+
function parseJsonObject(raw, name, expected) {
|
|
59
|
+
if (raw === undefined || !raw.trim()) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = JSON.parse(raw);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
throw new Error(`${name} must be ${expected}.`);
|
|
68
|
+
}
|
|
69
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
70
|
+
throw new Error(`${name} must be ${expected}.`);
|
|
71
|
+
}
|
|
72
|
+
return parsed;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Materialize the config: the repository variable when it is set, otherwise the
|
|
76
|
+
* committed template.
|
|
77
|
+
*/
|
|
78
|
+
export function prepareConfigFile() {
|
|
79
|
+
const dumpedConfig = process.env['WRANGLER_JSONC'];
|
|
80
|
+
if (dumpedConfig?.trim()) {
|
|
81
|
+
writeConfig(dumpedConfig);
|
|
82
|
+
console.log('Wrote wrangler.jsonc from WRANGLER_JSONC repository variable.');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
copyFileSync(TEMPLATE_PATH, CONFIG_PATH);
|
|
86
|
+
console.log('WRANGLER_JSONC is empty; copied apps/api/wrangler.template.jsonc to wrangler.jsonc.');
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Refuse a config older than the template requires.
|
|
90
|
+
*
|
|
91
|
+
* The template is the one file in the repo that says which wrangler behaviour the
|
|
92
|
+
* worker was written against, and a config written by an older template can name
|
|
93
|
+
* bindings the worker no longer reads. Failing here rather than at deploy time is
|
|
94
|
+
* the whole reason the check exists.
|
|
95
|
+
*/
|
|
96
|
+
export function ensureMinimumConfigVersion() {
|
|
97
|
+
const template = parse(readFileSync(TEMPLATE_PATH, 'utf8'));
|
|
98
|
+
if (typeof template.$minimumVersion !== 'number') {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const { config } = readConfig();
|
|
102
|
+
const currentVersion = config.$version;
|
|
103
|
+
if (typeof currentVersion !== 'number' || currentVersion < template.$minimumVersion) {
|
|
104
|
+
throw new Error(`wrangler.jsonc version (${typeof currentVersion === 'number' ? currentVersion : 'missing'}) is below minimum template version (${template.$minimumVersion}). Regenerate it from apps/api/wrangler.template.jsonc.`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export function applyTopLevelPatch() {
|
|
108
|
+
const patch = parseTopLevelPatch();
|
|
109
|
+
const entries = Object.entries(patch ?? {});
|
|
110
|
+
if (entries.length === 0) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
let { content } = readConfig();
|
|
114
|
+
for (const [key, value] of entries) {
|
|
115
|
+
content = writeConfigValue(content, [key], value);
|
|
116
|
+
}
|
|
117
|
+
writeConfig(content);
|
|
118
|
+
console.log(`Applied ${entries.length} Wrangler top-level patch entr${entries.length === 1 ? 'y' : 'ies'}.`);
|
|
119
|
+
}
|
|
120
|
+
export function applyVarsPatch() {
|
|
121
|
+
const patch = parseVarsPatch();
|
|
122
|
+
const entries = Object.entries(patch ?? {});
|
|
123
|
+
if (entries.length === 0) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const prepared = readConfig();
|
|
127
|
+
let content = prepared.content;
|
|
128
|
+
if (prepared.config.vars !== undefined && (prepared.config.vars === null || typeof prepared.config.vars !== 'object' || Array.isArray(prepared.config.vars))) {
|
|
129
|
+
throw new Error('wrangler.jsonc vars must be an object before applying WRANGLER_VARS_PATCH_JSON.');
|
|
130
|
+
}
|
|
131
|
+
if (prepared.config.vars === undefined || prepared.config.vars === null) {
|
|
132
|
+
content = writeConfigValue(content, ['vars'], {});
|
|
133
|
+
}
|
|
134
|
+
for (const [key, value] of entries) {
|
|
135
|
+
content = writeConfigValue(content, ['vars', key], value);
|
|
136
|
+
}
|
|
137
|
+
writeConfig(content);
|
|
138
|
+
console.log(`Applied ${entries.length} Wrangler vars patch entr${entries.length === 1 ? 'y' : 'ies'}.`);
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=patches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patches.js","sourceRoot":"","sources":["../../../src/scripts/wrangler-config/patches.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAU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,IAAI,OAAO,EAAE,CAAC;QACnC,OAAO,GAAG,gBAAgB,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC;IACD,WAAW,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,CAAC,GAAG,CAAC,WAAW,OAAO,CAAC,MAAM,4BAA4B,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;AAC1G,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creating the resources `wrangler.jsonc` names, and writing their real ids over
|
|
3
|
+
* the placeholders.
|
|
4
|
+
*
|
|
5
|
+
* Provenance: ported from Edge-Sonic's `scripts/lib/wrangler-config/resources.ts`.
|
|
6
|
+
*
|
|
7
|
+
* The placeholder rule: a template carries an all-zero id meaning "resolve me",
|
|
8
|
+
* and a config carrying one cannot be deployed. So provisioning walks the config,
|
|
9
|
+
* creates what is missing, and patches the id in place. A placeholder with nothing
|
|
10
|
+
* to create it *under* — a KV id with no binding, a D1 id with no name — is
|
|
11
|
+
* refused rather than skipped, because a silently skipped placeholder is a deploy
|
|
12
|
+
* that fails later with no link back to the reason.
|
|
13
|
+
*/
|
|
14
|
+
import { type D1Database, type KVNamespace, type SecretStore, type WranglerConfig } from './types';
|
|
15
|
+
/** What `ensure*` did, so a caller can act on the difference. */
|
|
16
|
+
export interface Provisioned {
|
|
17
|
+
id: string;
|
|
18
|
+
created: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** The id a D1 database is reported under, whichever key the CLI used. */
|
|
21
|
+
export declare function getD1Id(database: D1Database): string | undefined;
|
|
22
|
+
export declare function listD1Databases(): D1Database[];
|
|
23
|
+
/**
|
|
24
|
+
* The D1 database `binding` names, created when it does not exist.
|
|
25
|
+
*
|
|
26
|
+
* Whether it was created is reported, not inferred: a database created moments ago
|
|
27
|
+
* holds no user data, so a backup workflow must refuse to upload its empty dump.
|
|
28
|
+
* The caller cannot re-derive that from the config, because this very function
|
|
29
|
+
* patches the placeholder away before the reader ever runs.
|
|
30
|
+
*/
|
|
31
|
+
export declare function ensureD1Database(databaseName: string): Provisioned;
|
|
32
|
+
export declare function listKVNamespaces(): KVNamespace[];
|
|
33
|
+
/** The namespace name a binding's namespace is created under. */
|
|
34
|
+
export declare function getKVNamespaceName(config: WranglerConfig, binding: string): string;
|
|
35
|
+
export declare function ensureKVNamespace(config: WranglerConfig, binding: string): Provisioned;
|
|
36
|
+
/** The bindings a deployment always needs, whether or not a custom config lists them. */
|
|
37
|
+
export declare function getRequiredKvBindings(): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Add the always-needed KV bindings a hand-written config left out.
|
|
40
|
+
*
|
|
41
|
+
* A config supplied through `WRANGLER_JSONC` is edited by hand and drifts; without
|
|
42
|
+
* this the worker starts with an unbound `CACHE` and fails on the first read.
|
|
43
|
+
*/
|
|
44
|
+
export declare function ensureRequiredKvBindings(content: string, config: WranglerConfig): string;
|
|
45
|
+
/** The stores in a `secrets-store store list` table. */
|
|
46
|
+
export declare function parseSecretStoresTable(output: string): SecretStore[];
|
|
47
|
+
export declare function listSecretStores(): SecretStore[];
|
|
48
|
+
export declare function ensureSecretStore(): string;
|
|
49
|
+
/** Create a queue when it is absent, reporting whether it had to be created. */
|
|
50
|
+
export declare function ensureQueue(queueName: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Queue names a deployment needs, in first-seen order.
|
|
53
|
+
*
|
|
54
|
+
* Producers and consumers name the same queue twice — one queue, two roles — and a
|
|
55
|
+
* name appearing in both must be created once. Pure so it is testable without
|
|
56
|
+
* wrangler.
|
|
57
|
+
*/
|
|
58
|
+
export declare function queueNamesIn(config: WranglerConfig): string[];
|
|
59
|
+
export declare function ensureVectorizeIndex(indexName: string, dimensions: number): void;
|
|
60
|
+
/**
|
|
61
|
+
* Create every resource the config names, and write the real ids over the
|
|
62
|
+
* placeholders.
|
|
63
|
+
*
|
|
64
|
+
* Returns what it had to create, as `<kind>:<name>` — returned rather than logged,
|
|
65
|
+
* because a caller acts on it: the backup workflow refuses to export a D1 database
|
|
66
|
+
* that appears here, since one created moments ago holds no user data and an empty
|
|
67
|
+
* dump uploaded on schedule is a false sense of safety.
|
|
68
|
+
*/
|
|
69
|
+
export declare function provisionWranglerResources(): string[];
|
|
70
|
+
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/scripts/wrangler-config/resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAQL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAIjB,iEAAiE;AACjE,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,0EAA0E;AAC1E,wBAAgB,OAAO,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAEhE;AAED,wBAAgB,eAAe,IAAI,UAAU,EAAE,CAE9C;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,WAAW,CAclE;AAED,wBAAgB,gBAAgB,IAAI,WAAW,EAAE,CAEhD;AAED,iEAAiE;AACjE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAElF;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GAAG,WAAW,CAoBtF;AAED,yFAAyF;AACzF,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,MAAM,CAYxF;AAED,wDAAwD;AACxD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,EAAE,CAiBpE;AAED,wBAAgB,gBAAgB,IAAI,WAAW,EAAE,CAQhD;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAmB1C;AAED,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAUtD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,EAAE,CAc7D;AAED,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAQhF;AA4DD;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,EAAE,CAqCrD"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creating the resources `wrangler.jsonc` names, and writing their real ids over
|
|
3
|
+
* the placeholders.
|
|
4
|
+
*
|
|
5
|
+
* Provenance: ported from Edge-Sonic's `scripts/lib/wrangler-config/resources.ts`.
|
|
6
|
+
*
|
|
7
|
+
* The placeholder rule: a template carries an all-zero id meaning "resolve me",
|
|
8
|
+
* and a config carrying one cannot be deployed. So provisioning walks the config,
|
|
9
|
+
* creates what is missing, and patches the id in place. A placeholder with nothing
|
|
10
|
+
* to create it *under* — a KV id with no binding, a D1 id with no name — is
|
|
11
|
+
* refused rather than skipped, because a silently skipped placeholder is a deploy
|
|
12
|
+
* that fails later with no link back to the reason.
|
|
13
|
+
*/
|
|
14
|
+
import { parse } from 'jsonc-parser';
|
|
15
|
+
import { parseWranglerTableRows } from '../lib/wrangler-table';
|
|
16
|
+
import { DEFAULT_HEX_ID, DEFAULT_KV_NAMESPACE_NAMES, DEFAULT_SECRET_STORE_NAME, DEFAULT_UUID, DEFAULT_WORKER_NAME, VECTORIZE_DIMENSIONS, } from './types';
|
|
17
|
+
import { parseJsonArray, runWrangler } from './cli';
|
|
18
|
+
import { readConfig, writeConfig, writeConfigValue } from './patches';
|
|
19
|
+
/** The id a D1 database is reported under, whichever key the CLI used. */
|
|
20
|
+
export function getD1Id(database) {
|
|
21
|
+
return database.uuid ?? database.database_id ?? database.id;
|
|
22
|
+
}
|
|
23
|
+
export function listD1Databases() {
|
|
24
|
+
return parseJsonArray(runWrangler(['d1', 'list', '--json']), 'wrangler d1 list --json');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The D1 database `binding` names, created when it does not exist.
|
|
28
|
+
*
|
|
29
|
+
* Whether it was created is reported, not inferred: a database created moments ago
|
|
30
|
+
* holds no user data, so a backup workflow must refuse to upload its empty dump.
|
|
31
|
+
* The caller cannot re-derive that from the config, because this very function
|
|
32
|
+
* patches the placeholder away before the reader ever runs.
|
|
33
|
+
*/
|
|
34
|
+
export function ensureD1Database(databaseName) {
|
|
35
|
+
let database = listD1Databases().find((candidate) => candidate.name === databaseName);
|
|
36
|
+
let created = false;
|
|
37
|
+
if (database === undefined) {
|
|
38
|
+
console.log(`Creating D1 database: ${databaseName}`);
|
|
39
|
+
runWrangler(['d1', 'create', databaseName]);
|
|
40
|
+
database = listD1Databases().find((candidate) => candidate.name === databaseName);
|
|
41
|
+
created = true;
|
|
42
|
+
}
|
|
43
|
+
const databaseId = database === undefined ? undefined : getD1Id(database);
|
|
44
|
+
if (databaseId === undefined || databaseId === '') {
|
|
45
|
+
throw new Error(`Unable to discover D1 database ID for ${databaseName}.`);
|
|
46
|
+
}
|
|
47
|
+
return { id: databaseId, created };
|
|
48
|
+
}
|
|
49
|
+
export function listKVNamespaces() {
|
|
50
|
+
return parseJsonArray(runWrangler(['kv', 'namespace', 'list']), 'wrangler kv namespace list');
|
|
51
|
+
}
|
|
52
|
+
/** The namespace name a binding's namespace is created under. */
|
|
53
|
+
export function getKVNamespaceName(config, binding) {
|
|
54
|
+
return DEFAULT_KV_NAMESPACE_NAMES[binding] ?? `${config.name ?? DEFAULT_WORKER_NAME}-${binding.toLowerCase()}`;
|
|
55
|
+
}
|
|
56
|
+
export function ensureKVNamespace(config, binding) {
|
|
57
|
+
const namespaceName = getKVNamespaceName(config, binding);
|
|
58
|
+
const candidateNames = new Set([namespaceName, `${config.name ?? DEFAULT_WORKER_NAME}-${binding}`, binding]);
|
|
59
|
+
let namespace = listKVNamespaces().find((candidate) => {
|
|
60
|
+
const candidateName = candidate.title ?? candidate.name;
|
|
61
|
+
return candidate.id !== undefined && candidateName !== undefined && candidateNames.has(candidateName);
|
|
62
|
+
});
|
|
63
|
+
let created = false;
|
|
64
|
+
if (namespace === undefined) {
|
|
65
|
+
console.log(`Creating KV namespace: ${namespaceName}`);
|
|
66
|
+
runWrangler(['kv', 'namespace', 'create', namespaceName]);
|
|
67
|
+
namespace = listKVNamespaces().find((candidate) => candidate.id !== undefined && (candidate.title ?? candidate.name) === namespaceName);
|
|
68
|
+
created = true;
|
|
69
|
+
}
|
|
70
|
+
if (namespace?.id === undefined) {
|
|
71
|
+
throw new Error(`Unable to discover KV namespace ID for ${namespaceName}.`);
|
|
72
|
+
}
|
|
73
|
+
return { id: namespace.id, created };
|
|
74
|
+
}
|
|
75
|
+
/** The bindings a deployment always needs, whether or not a custom config lists them. */
|
|
76
|
+
export function getRequiredKvBindings() {
|
|
77
|
+
return Object.keys(DEFAULT_KV_NAMESPACE_NAMES);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Add the always-needed KV bindings a hand-written config left out.
|
|
81
|
+
*
|
|
82
|
+
* A config supplied through `WRANGLER_JSONC` is edited by hand and drifts; without
|
|
83
|
+
* this the worker starts with an unbound `CACHE` and fails on the first read.
|
|
84
|
+
*/
|
|
85
|
+
export function ensureRequiredKvBindings(content, config) {
|
|
86
|
+
const existing = new Set((config.kv_namespaces ?? []).map((namespace) => namespace.binding).filter((binding) => binding !== undefined));
|
|
87
|
+
const missing = getRequiredKvBindings().filter((binding) => !existing.has(binding));
|
|
88
|
+
if (missing.length === 0) {
|
|
89
|
+
return content;
|
|
90
|
+
}
|
|
91
|
+
const next = [...(config.kv_namespaces ?? [])];
|
|
92
|
+
for (const binding of missing) {
|
|
93
|
+
console.log(`Adding missing KV namespace binding: ${binding}`);
|
|
94
|
+
next.push({ binding, id: DEFAULT_HEX_ID });
|
|
95
|
+
}
|
|
96
|
+
return writeConfigValue(content, ['kv_namespaces'], next);
|
|
97
|
+
}
|
|
98
|
+
/** The stores in a `secrets-store store list` table. */
|
|
99
|
+
export function parseSecretStoresTable(output) {
|
|
100
|
+
const stores = [];
|
|
101
|
+
// Through the shared table parser rather than a second inline split: `wrangler`
|
|
102
|
+
// renders through `cli-table3`, whose cells are separated by U+2502 and are *not*
|
|
103
|
+
// space-aligned, so a parser written for aligned output silently matches nothing
|
|
104
|
+
// — which reads as "the store does not exist" and makes provisioning create a
|
|
105
|
+
// duplicate.
|
|
106
|
+
for (const row of parseWranglerTableRows(output)) {
|
|
107
|
+
const name = row[0];
|
|
108
|
+
const id = row[1];
|
|
109
|
+
// Store ids are 32 hex characters; a row without one is a header, a border, or
|
|
110
|
+
// an unrelated column, and is skipped rather than stored with an undefined id.
|
|
111
|
+
if (name !== undefined && id !== undefined && /^[a-f0-9]{32}$/i.test(id)) {
|
|
112
|
+
stores.push({ name, id });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return stores;
|
|
116
|
+
}
|
|
117
|
+
export function listSecretStores() {
|
|
118
|
+
const output = runWrangler(['secrets-store', 'store', 'list', '--remote']);
|
|
119
|
+
try {
|
|
120
|
+
return parseJsonArray(output, 'wrangler secrets-store store list --remote');
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// The subcommand prints a table rather than JSON on some versions.
|
|
124
|
+
return parseSecretStoresTable(output);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export function ensureSecretStore() {
|
|
128
|
+
const stores = listSecretStores();
|
|
129
|
+
const existing = stores.find((candidate) => candidate.name === DEFAULT_SECRET_STORE_NAME) ?? stores[0];
|
|
130
|
+
if (existing !== undefined) {
|
|
131
|
+
return existing.id;
|
|
132
|
+
}
|
|
133
|
+
console.log(`Creating Secrets Store: ${DEFAULT_SECRET_STORE_NAME}`);
|
|
134
|
+
const output = runWrangler(['secrets-store', 'store', 'create', DEFAULT_SECRET_STORE_NAME, '--remote']);
|
|
135
|
+
const createdStoreId = /ID:\s*([a-f0-9]{32})/i.exec(output)?.[1];
|
|
136
|
+
if (createdStoreId !== undefined) {
|
|
137
|
+
return createdStoreId;
|
|
138
|
+
}
|
|
139
|
+
// The create output did not name the id, so read it back rather than guessing.
|
|
140
|
+
const refreshed = listSecretStores();
|
|
141
|
+
const store = refreshed.find((candidate) => candidate.name === DEFAULT_SECRET_STORE_NAME) ?? refreshed[0];
|
|
142
|
+
if (store?.id === undefined) {
|
|
143
|
+
throw new Error(`Unable to discover Secrets Store ID for ${DEFAULT_SECRET_STORE_NAME}.`);
|
|
144
|
+
}
|
|
145
|
+
return store.id;
|
|
146
|
+
}
|
|
147
|
+
/** Create a queue when it is absent, reporting whether it had to be created. */
|
|
148
|
+
export function ensureQueue(queueName) {
|
|
149
|
+
try {
|
|
150
|
+
runWrangler(['queues', 'info', queueName]);
|
|
151
|
+
console.log(`Queue ${queueName} already exists.`);
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
console.log(`Creating queue: ${queueName}`);
|
|
156
|
+
runWrangler(['queues', 'create', queueName]);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Queue names a deployment needs, in first-seen order.
|
|
162
|
+
*
|
|
163
|
+
* Producers and consumers name the same queue twice — one queue, two roles — and a
|
|
164
|
+
* name appearing in both must be created once. Pure so it is testable without
|
|
165
|
+
* wrangler.
|
|
166
|
+
*/
|
|
167
|
+
export function queueNamesIn(config) {
|
|
168
|
+
const names = [];
|
|
169
|
+
const seen = new Set();
|
|
170
|
+
for (const producer of config.queues?.producers ?? []) {
|
|
171
|
+
if (producer.queue === '' || seen.has(producer.queue))
|
|
172
|
+
continue;
|
|
173
|
+
seen.add(producer.queue);
|
|
174
|
+
names.push(producer.queue);
|
|
175
|
+
}
|
|
176
|
+
for (const consumer of config.queues?.consumers ?? []) {
|
|
177
|
+
if (consumer.queue === '' || seen.has(consumer.queue))
|
|
178
|
+
continue;
|
|
179
|
+
seen.add(consumer.queue);
|
|
180
|
+
names.push(consumer.queue);
|
|
181
|
+
}
|
|
182
|
+
return names;
|
|
183
|
+
}
|
|
184
|
+
export function ensureVectorizeIndex(indexName, dimensions) {
|
|
185
|
+
try {
|
|
186
|
+
runWrangler(['vectorize', 'info', indexName]);
|
|
187
|
+
console.log(`Vectorize index ${indexName} already exists.`);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
console.log(`Creating Vectorize index: ${indexName} with ${dimensions} dimensions`);
|
|
191
|
+
runWrangler(['vectorize', 'create', indexName, `--dimensions=${dimensions}`, '--metric=cosine']);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** Replace each placeholder D1 `database_id` with a real one. */
|
|
195
|
+
function provisionD1Databases(content, config, created) {
|
|
196
|
+
let patched = content;
|
|
197
|
+
for (const [index, database] of config.d1_databases?.entries() ?? []) {
|
|
198
|
+
if (database.database_id !== DEFAULT_UUID)
|
|
199
|
+
continue;
|
|
200
|
+
if (database.database_name === undefined || database.database_name === '') {
|
|
201
|
+
throw new Error(`D1 database binding ${database.binding ?? index} has a placeholder database_id but no database_name.`);
|
|
202
|
+
}
|
|
203
|
+
const resolved = ensureD1Database(database.database_name);
|
|
204
|
+
if (resolved.created) {
|
|
205
|
+
created.push(`d1:${database.database_name}`);
|
|
206
|
+
}
|
|
207
|
+
console.log(`Using D1 database ${database.database_name}: ${resolved.id}`);
|
|
208
|
+
patched = writeConfigValue(patched, ['d1_databases', index, 'database_id'], resolved.id);
|
|
209
|
+
}
|
|
210
|
+
return patched;
|
|
211
|
+
}
|
|
212
|
+
/** Replace each placeholder KV namespace id with a real one. */
|
|
213
|
+
function provisionKvNamespaces(content, config, created) {
|
|
214
|
+
let patched = content;
|
|
215
|
+
for (const [index, namespace] of config.kv_namespaces?.entries() ?? []) {
|
|
216
|
+
if (namespace.id !== DEFAULT_HEX_ID)
|
|
217
|
+
continue;
|
|
218
|
+
if (namespace.binding === undefined || namespace.binding === '') {
|
|
219
|
+
throw new Error(`KV namespace at index ${index} has a placeholder id but no binding.`);
|
|
220
|
+
}
|
|
221
|
+
const resolved = ensureKVNamespace(config, namespace.binding);
|
|
222
|
+
const namespaceName = getKVNamespaceName(config, namespace.binding);
|
|
223
|
+
if (resolved.created) {
|
|
224
|
+
created.push(`kv:${namespaceName}`);
|
|
225
|
+
}
|
|
226
|
+
console.log(`Using KV namespace ${namespaceName}: ${resolved.id}`);
|
|
227
|
+
patched = writeConfigValue(patched, ['kv_namespaces', index, 'id'], resolved.id);
|
|
228
|
+
}
|
|
229
|
+
return patched;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Point every placeholder Secrets Store `store_id` at one store, creating it if
|
|
233
|
+
* absent. `existed` is read **before** the create, because whether the store was
|
|
234
|
+
* created is what the caller reports.
|
|
235
|
+
*/
|
|
236
|
+
function provisionSecretStore(content, config, created) {
|
|
237
|
+
const placeholders = (config.secrets_store_secrets ?? [])
|
|
238
|
+
.map((secret, index) => ({ secret, index }))
|
|
239
|
+
.filter(({ secret }) => secret.store_id === DEFAULT_HEX_ID);
|
|
240
|
+
if (placeholders.length === 0) {
|
|
241
|
+
return content;
|
|
242
|
+
}
|
|
243
|
+
const existed = listSecretStores().some((store) => store.name === DEFAULT_SECRET_STORE_NAME);
|
|
244
|
+
const storeId = ensureSecretStore();
|
|
245
|
+
if (!existed) {
|
|
246
|
+
created.push(`secrets-store:${DEFAULT_SECRET_STORE_NAME}`);
|
|
247
|
+
}
|
|
248
|
+
console.log(`Using Secrets Store: ${storeId}`);
|
|
249
|
+
return placeholders.reduce((patched, { index }) => writeConfigValue(patched, ['secrets_store_secrets', index, 'store_id'], storeId), content);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Create every resource the config names, and write the real ids over the
|
|
253
|
+
* placeholders.
|
|
254
|
+
*
|
|
255
|
+
* Returns what it had to create, as `<kind>:<name>` — returned rather than logged,
|
|
256
|
+
* because a caller acts on it: the backup workflow refuses to export a D1 database
|
|
257
|
+
* that appears here, since one created moments ago holds no user data and an empty
|
|
258
|
+
* dump uploaded on schedule is a false sense of safety.
|
|
259
|
+
*/
|
|
260
|
+
export function provisionWranglerResources() {
|
|
261
|
+
const created = [];
|
|
262
|
+
let { content, config } = readConfig();
|
|
263
|
+
content = ensureRequiredKvBindings(content, config);
|
|
264
|
+
config = parse(content);
|
|
265
|
+
// Each of the three below re-parses before it patches, because each writes into
|
|
266
|
+
// the config text the previous one produced. They are separate functions because
|
|
267
|
+
// they are separate resources with separate rules, and one loop holding all
|
|
268
|
+
// three would read as a single resource list with the differences hidden in the
|
|
269
|
+
// bodies.
|
|
270
|
+
content = provisionD1Databases(content, config, created);
|
|
271
|
+
config = parse(content);
|
|
272
|
+
content = provisionKvNamespaces(content, config, created);
|
|
273
|
+
config = parse(content);
|
|
274
|
+
content = provisionSecretStore(content, config, created);
|
|
275
|
+
writeConfig(content);
|
|
276
|
+
config = parse(content);
|
|
277
|
+
for (const queueName of queueNamesIn(config)) {
|
|
278
|
+
if (ensureQueue(queueName)) {
|
|
279
|
+
created.push(`queue:${queueName}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// Vectorize indexes are name-based, so nothing in the file is patched — but the
|
|
283
|
+
// created names are still reported like every other resource, so a deploy log
|
|
284
|
+
// shows what appeared.
|
|
285
|
+
for (const binding of config.vectorize ?? []) {
|
|
286
|
+
ensureVectorizeIndex(binding.index_name, VECTORIZE_DIMENSIONS);
|
|
287
|
+
}
|
|
288
|
+
return created;
|
|
289
|
+
}
|
|
290
|
+
//# sourceM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/wrangler-config/types.ts`.
|
|
5
|
+
* Every script that reads or writes `wrangler.jsonc` resolves it here, so the
|
|
6
|
+
* backup workflow cannot end up inspecting a different file than the deploy
|
|
7
|
+
* materialized.
|
|
8
|
+
*
|
|
9
|
+
* The paths default to `process.cwd()`, which is the repo root in every consumer:
|
|
10
|
+
* the scripts run as `pnpm exec tsx scripts/deploy/…` from there. `WRANGLER_CONFIG_PATH`
|
|
11
|
+
* / `WRANGLER_TEMPLATE_PATH` override them for a caller that is not in the repo
|
|
12
|
+
* root, which is the one case the cwd default gets wrong.
|
|
13
|
+
*/
|
|
14
|
+
/** The config the deploy targets. */
|
|
15
|
+
export declare const CONFIG_PATH: string;
|
|
16
|
+
/** The committed template the config is materialized from. */
|
|
17
|
+
export declare const TEMPLATE_PATH: string;
|
|
18
|
+
/**
|
|
19
|
+
* The id a template carries for a D1 database that does not exist yet.
|
|
20
|
+
*
|
|
21
|
+
* `provisionWranglerResources` replaces it with a real id; the backup scripts
|
|
22
|
+
* refuse to export while it is still in place, because a database that was just
|
|
23
|
+
* created holds no user data.
|
|
24
|
+
*/
|
|
25
|
+
export declare const DEFAULT_UUID = "00000000-0000-0000-0000-000000000000";
|
|
26
|
+
/** The placeholder for a KV namespace id and for a Secrets Store id. */
|
|
27
|
+
export declare const DEFAULT_HEX_ID = "00000000000000000000000000000000";
|
|
28
|
+
/** The Secrets Store name a deployment uses. */
|
|
29
|
+
export declare const DEFAULT_SECRET_STORE_NAME = "default";
|
|
30
|
+
/**
|
|
31
|
+
* Fallback when the config declares no `name`, used to derive resource names.
|
|
32
|
+
*
|
|
33
|
+
* Overridable per consumer with `WRANGLER_WORKER_NAME`, which keeps the default
|
|
34
|
+
* honest rather than baking one repo's name into the kit.
|
|
35
|
+
*/
|
|
36
|
+
export declare const DEFAULT_WORKER_NAME: string;
|
|
37
|
+
/**
|
|
38
|
+
* KV bindings a deployment always needs, and the namespace each maps to.
|
|
39
|
+
*
|
|
40
|
+
* A consumer whose worker has no cache binding passes an empty map; a consumer
|
|
41
|
+
* with one names it here or leaves the derived `<worker>-<BINDING>` convention.
|
|
42
|
+
*/
|
|
43
|
+
export declare const DEFAULT_KV_NAMESPACE_NAMES: Record<string, string>;
|
|
44
|
+
/** Dimensions of a Vectorize index this kit provisions. */
|
|
45
|
+
export declare const VECTORIZE_DIMENSIONS = 1024;
|
|
46
|
+
/**
|
|
47
|
+
* The parsed shape of a wrangler config.
|
|
48
|
+
*
|
|
49
|
+
* `vars` is widened with `null` on purpose: jsonc-parser yields `null` for an
|
|
50
|
+
* explicit `vars: null`, and the vars-patch path must be able to reject that
|
|
51
|
+
* rather than treat the field as absent.
|
|
52
|
+
*/
|
|
53
|
+
export interface WranglerConfig {
|
|
54
|
+
name?: string;
|
|
55
|
+
$version?: number;
|
|
56
|
+
vars?: Record<string, unknown> | null;
|
|
57
|
+
d1_databases?: Array<{
|
|
58
|
+
binding?: string;
|
|
59
|
+
database_id?: string;
|
|
60
|
+
database_name?: string;
|
|
61
|
+
}>;
|
|
62
|
+
kv_namespaces?: Array<{
|
|
63
|
+
binding?: string;
|
|
64
|
+
id?: string;
|
|
65
|
+
}>;
|
|
66
|
+
secrets_store_secrets?: Array<{
|
|
67
|
+
binding?: string;
|
|
68
|
+
store_id?: string;
|
|
69
|
+
secret_name?: string;
|
|
70
|
+
}>;
|
|
71
|
+
queues?: {
|
|
72
|
+
producers?: Array<{
|
|
73
|
+
binding: string;
|
|
74
|
+
queue: string;
|
|
75
|
+
}>;
|
|
76
|
+
consumers?: Array<{
|
|
77
|
+
queue: string;
|
|
78
|
+
}>;
|
|
79
|
+
};
|
|
80
|
+
vectorize?: Array<{
|
|
81
|
+
binding: string;
|
|
82
|
+
index_name: string;
|
|
83
|
+
}>;
|
|
84
|
+
}
|
|
85
|
+
/** A D1 database as `wrangler d1 list --json` reports one. */
|
|
86
|
+
export interface D1Database {
|
|
87
|
+
name?: string;
|
|
88
|
+
uuid?: string;
|
|
89
|
+
id?: string;
|
|
90
|
+
database_id?: string;
|
|
91
|
+
}
|
|
92
|
+
/** A KV namespace as `wrangler kv namespace list` reports one. */
|
|
93
|
+
export interface KVNamespace {
|
|
94
|
+
title?: string;
|
|
95
|
+
name?: string;
|
|
96
|
+
id?: string;
|
|
97
|
+
}
|
|
98
|
+
/** A Secrets Store as `wrangler secrets-store store list` reports one. */
|
|
99
|
+
export interface SecretStore {
|
|
100
|
+
name: string;
|
|
101
|
+
id: string;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/scripts/wrangler-config/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,qCAAqC;AACrC,eAAO,MAAM,WAAW,QAAoF,CAAC;AAE7G,8DAA8D;AAC9D,eAAO,MAAM,aAAa,QAAwG,CAAC;AAEnI;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,yCAAyC,CAAC;AAEnE,wEAAwE;AACxE,eAAO,MAAM,cAAc,qCAAqC,CAAC;AAEjE,gDAAgD;AAChD,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,QAAqD,CAAC;AAEtF;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAE7D,CAAC;AAEF,2DAA2D;AAC3D,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACtC,YAAY,CAAC,EAAE,KAAK,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;QAC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