devflare 1.0.0-next.21 → 1.0.0-next.23
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/LLM.md +144 -5
- package/dist/account-j8nfggg4.js +475 -0
- package/dist/account-qhe8vtds.js +475 -0
- package/dist/bridge/gateway-runtime.d.ts +1 -1
- package/dist/bridge/gateway-runtime.d.ts.map +1 -1
- package/dist/bridge/miniflare.d.ts +1 -1
- package/dist/bridge/miniflare.d.ts.map +1 -1
- package/dist/bridge/proxy.d.ts +2 -0
- package/dist/bridge/proxy.d.ts.map +1 -1
- package/dist/bridge/server.d.ts.map +1 -1
- package/dist/browser.d.ts +13 -13
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +5 -3
- package/dist/build-qsgnme4z.js +54 -0
- package/dist/build-vy95gy3f.js +54 -0
- package/dist/build-yzx0gsaj.js +54 -0
- package/dist/cli/commands/build-artifacts.d.ts.map +1 -1
- package/dist/cli/commands/config.d.ts.map +1 -1
- package/dist/cli/commands/type-generation/generator.d.ts +4 -2
- package/dist/cli/commands/type-generation/generator.d.ts.map +1 -1
- package/dist/cli/commands/types.d.ts.map +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/config/compiler/types.d.ts +1 -1
- package/dist/config/compiler/types.d.ts.map +1 -1
- package/dist/config/define.d.ts +7 -4
- package/dist/config/define.d.ts.map +1 -1
- package/dist/config/env-vars.d.ts +309 -0
- package/dist/config/env-vars.d.ts.map +1 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/local-dev-vars.d.ts +2 -2
- package/dist/config/local-dev-vars.d.ts.map +1 -1
- package/dist/config/schema-env.d.ts +6 -6
- package/dist/config/schema-types-bindings-platform.d.ts +378 -0
- package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
- package/dist/config/schema-types-bindings-resources.d.ts +551 -0
- package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
- package/dist/config/schema-types-bindings.d.ts +254 -0
- package/dist/config/schema-types-bindings.d.ts.map +1 -0
- package/dist/config/schema-types-build.d.ts +86 -0
- package/dist/config/schema-types-build.d.ts.map +1 -0
- package/dist/config/schema-types-runtime.d.ts +882 -0
- package/dist/config/schema-types-runtime.d.ts.map +1 -0
- package/dist/config/schema-types.d.ts +377 -0
- package/dist/config/schema-types.d.ts.map +1 -0
- package/dist/config/schema.d.ts +14 -15
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config-entry.d.ts +2 -0
- package/dist/config-entry.d.ts.map +1 -1
- package/dist/config-entry.js +3 -1
- package/dist/config-gq5jh4cx.js +105 -0
- package/dist/config-vec13050.js +105 -0
- package/dist/deploy-01j0ep5n.js +1055 -0
- package/dist/deploy-nh5tbv45.js +1055 -0
- package/dist/deploy-tjypkhg7.js +1055 -0
- package/dist/dev-bh581ew3.js +2597 -0
- package/dist/dev-cme5de75.js +2551 -0
- package/dist/dev-gn5y93z9.js +2597 -0
- package/dist/dev-server/server.d.ts.map +1 -1
- package/dist/doctor-h5q28qt1.js +259 -0
- package/dist/doctor-khk550tw.js +259 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/index-0bv2qjs1.js +1555 -0
- package/dist/index-35bmgpfw.js +573 -0
- package/dist/index-3tkzn06q.js +413 -0
- package/dist/index-4se6krdj.js +574 -0
- package/dist/index-8fyz6gcm.js +699 -0
- package/dist/index-97z629zr.js +109 -0
- package/dist/index-b28c4yr4.js +1205 -0
- package/dist/index-c1cj9085.js +2250 -0
- package/dist/index-c8p4njqy.js +479 -0
- package/dist/index-cr06zrgw.js +1033 -0
- package/dist/index-cwjjdtgn.js +74 -0
- package/dist/index-dref9ecb.js +476 -0
- package/dist/index-e151t4ge.js +895 -0
- package/dist/index-e7kakw0j.js +1033 -0
- package/dist/index-f1g5jdm8.js +1426 -0
- package/dist/index-f46984zs.js +1554 -0
- package/dist/index-grk8pzhr.js +185 -0
- package/dist/index-hbxkmb1q.js +1426 -0
- package/dist/index-hzmpecq9.js +52 -0
- package/dist/index-j1csb7gb.js +581 -0
- package/dist/index-j7x7f72h.js +185 -0
- package/dist/index-jkqbjwt2.js +476 -0
- package/dist/index-jwd3fanx.js +412 -0
- package/dist/index-mh5renra.js +895 -0
- package/dist/index-p9xq83p7.js +147 -0
- package/dist/index-q15nj71j.js +52 -0
- package/dist/index-qqp65pyv.js +699 -0
- package/dist/index-s0fmwxbk.js +74 -0
- package/dist/index-s9q605sq.js +1033 -0
- package/dist/index-stzx8nc4.js +111 -0
- package/dist/index-th4vrnbk.js +1205 -0
- package/dist/index-vtcmsgaf.js +581 -0
- package/dist/index-w36q6819.js +895 -0
- package/dist/index-x2k3awjs.js +147 -0
- package/dist/index-x8x547tz.js +1426 -0
- package/dist/index-xp0qkkxf.js +68 -0
- package/dist/index-xxxd0mvw.js +109 -0
- package/dist/index-zawn5tte.js +109 -0
- package/dist/index-zpy9caxn.js +1193 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/login-280p2cm9.js +77 -0
- package/dist/login-4n266whq.js +77 -0
- package/dist/previews-3m3ffpaw.js +1337 -0
- package/dist/previews-tr8sm03d.js +1337 -0
- package/dist/productions-62y489ff.js +505 -0
- package/dist/productions-cgn3fz7d.js +505 -0
- package/dist/runtime/exports.d.ts +23 -0
- package/dist/runtime/exports.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +6 -4
- package/dist/secrets-4050kqf5.js +91 -0
- package/dist/secrets-p112cajt.js +91 -0
- package/dist/sveltekit/index.js +8 -7
- package/dist/sveltekit/local-bindings.d.ts.map +1 -1
- package/dist/test/index.js +24 -12
- package/dist/test/resolve-service-bindings.d.ts +1 -1
- package/dist/test/resolve-service-bindings.d.ts.map +1 -1
- package/dist/test/simple-context-lifecycle.d.ts.map +1 -1
- package/dist/types-apmt10yj.js +705 -0
- package/dist/types-ttrrgdfj.js +705 -0
- package/dist/vite/index.js +5 -5
- package/dist/vite/plugin-context.d.ts.map +1 -1
- package/dist/vite/plugin-programmatic.d.ts.map +1 -1
- package/dist/worker-2k1jyr6p.js +513 -0
- package/dist/worker-jqgn6jyj.js +513 -0
- package/package.json +1 -1
|
@@ -0,0 +1,705 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveConfigCandidatePath
|
|
3
|
+
} from "./index-hzmpecq9.js";
|
|
4
|
+
import {
|
|
5
|
+
getDependencies
|
|
6
|
+
} from "./index-z9gy8w6b.js";
|
|
7
|
+
import {
|
|
8
|
+
bold,
|
|
9
|
+
createCliTheme,
|
|
10
|
+
dim
|
|
11
|
+
} from "./index-stgn34cr.js";
|
|
12
|
+
import"./index-3t6rypgc.js";
|
|
13
|
+
import {
|
|
14
|
+
discoverEntrypointsAsync,
|
|
15
|
+
resolvePackageSpecifier
|
|
16
|
+
} from "./index-3edvz3hs.js";
|
|
17
|
+
import {
|
|
18
|
+
DEFAULT_DO_PATTERN,
|
|
19
|
+
DEFAULT_ENTRYPOINT_PATTERN,
|
|
20
|
+
findFiles
|
|
21
|
+
} from "./index-qwgr4q7s.js";
|
|
22
|
+
import {
|
|
23
|
+
findDurableObjectClasses
|
|
24
|
+
} from "./index-vhqww6tt.js";
|
|
25
|
+
import"./index-8fyz6gcm.js";
|
|
26
|
+
import {
|
|
27
|
+
loadConfig,
|
|
28
|
+
normalizeDOBinding
|
|
29
|
+
} from "./index-0bv2qjs1.js";
|
|
30
|
+
import"./index-1d4jg11n.js";
|
|
31
|
+
import"./index-mg8vwqxf.js";
|
|
32
|
+
import"./index-c8p4njqy.js";
|
|
33
|
+
import"./index-q8f4kawk.js";
|
|
34
|
+
import"./index-37x76zdn.js";
|
|
35
|
+
|
|
36
|
+
// src/cli/commands/types.ts
|
|
37
|
+
import { resolve } from "pathe";
|
|
38
|
+
|
|
39
|
+
// src/cli/commands/type-generation/discovery.ts
|
|
40
|
+
import { readFile } from "node:fs/promises";
|
|
41
|
+
import { dirname, relative } from "pathe";
|
|
42
|
+
var DEFAULT_INTERFACE_LOOKUP_KEYS = new Set(["Worker", "Default", "MathService"]);
|
|
43
|
+
var interfaceTypeCache = new Map;
|
|
44
|
+
async function readFileIfAvailable(filePath) {
|
|
45
|
+
try {
|
|
46
|
+
return await readFile(filePath, "utf-8");
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function getInterfaceSearchKey(searchDirs) {
|
|
52
|
+
return [...new Set(searchDirs)].sort((left, right) => left.localeCompare(right)).join("\x00");
|
|
53
|
+
}
|
|
54
|
+
function getPatternMatches(pattern, code) {
|
|
55
|
+
const matches = [];
|
|
56
|
+
pattern.lastIndex = 0;
|
|
57
|
+
let nextMatch = pattern.exec(code);
|
|
58
|
+
while (nextMatch !== null) {
|
|
59
|
+
matches.push(nextMatch);
|
|
60
|
+
nextMatch = pattern.exec(code);
|
|
61
|
+
}
|
|
62
|
+
return matches;
|
|
63
|
+
}
|
|
64
|
+
function getInterfaceBaseName(interfaceName) {
|
|
65
|
+
if (interfaceName.endsWith("Interface")) {
|
|
66
|
+
return interfaceName.slice(0, -9);
|
|
67
|
+
}
|
|
68
|
+
if (interfaceName.endsWith("Rpc")) {
|
|
69
|
+
return interfaceName.slice(0, -3);
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
function registerInterfaceType(interfaces, baseName, interfaceInfo) {
|
|
74
|
+
if (!interfaces.has(baseName)) {
|
|
75
|
+
interfaces.set(baseName, interfaceInfo);
|
|
76
|
+
}
|
|
77
|
+
if (!interfaces.has("__default__") && DEFAULT_INTERFACE_LOOKUP_KEYS.has(baseName)) {
|
|
78
|
+
interfaces.set("__default__", interfaceInfo);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function collectInterfaceTypesFromFile(interfaces, filePath) {
|
|
82
|
+
const code = await readFileIfAvailable(filePath);
|
|
83
|
+
if (!code) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const interfacePattern = /export\s+interface\s+(\w+(?:Interface|Rpc))\s*\{/g;
|
|
87
|
+
for (const match of getPatternMatches(interfacePattern, code)) {
|
|
88
|
+
const interfaceName = match[1];
|
|
89
|
+
const baseName = getInterfaceBaseName(interfaceName);
|
|
90
|
+
if (!baseName) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
registerInterfaceType(interfaces, baseName, {
|
|
94
|
+
filePath,
|
|
95
|
+
interfaceName
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function parseConfigForRefs(configPath) {
|
|
100
|
+
const refs = [];
|
|
101
|
+
const serviceBindings = [];
|
|
102
|
+
const doBindings = [];
|
|
103
|
+
const code = await readFileIfAvailable(configPath);
|
|
104
|
+
if (!code) {
|
|
105
|
+
return {
|
|
106
|
+
refs,
|
|
107
|
+
serviceBindings,
|
|
108
|
+
doBindings
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const refPattern = /const\s+(\w+)\s*=\s*ref\s*\(\s*(?:'[^']*'\s*,\s*)?(?:\(\s*\)\s*=>\s*)?import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
112
|
+
for (const match of getPatternMatches(refPattern, code)) {
|
|
113
|
+
refs.push({
|
|
114
|
+
varName: match[1],
|
|
115
|
+
importPath: match[2]
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
const servicePattern = /(\w+)\s*:\s*(\w+)\.worker(?:\s*\(\s*['"](\w+)['"]\s*\))?/g;
|
|
119
|
+
for (const match of getPatternMatches(servicePattern, code)) {
|
|
120
|
+
serviceBindings.push({
|
|
121
|
+
bindingName: match[1],
|
|
122
|
+
varName: match[2],
|
|
123
|
+
entrypoint: match[3]
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const doPattern = /(\w+)\s*:\s*(\w+)\.([A-Z][A-Z0-9_]*)\s*[,\n\r}]/g;
|
|
127
|
+
for (const match of getPatternMatches(doPattern, code)) {
|
|
128
|
+
if (match[3] === "worker") {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
doBindings.push({
|
|
132
|
+
bindingName: match[1],
|
|
133
|
+
varName: match[2],
|
|
134
|
+
doName: match[3]
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
refs,
|
|
139
|
+
serviceBindings,
|
|
140
|
+
doBindings
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
async function findInterfaceTypes(searchDirs) {
|
|
144
|
+
const interfaces = new Map;
|
|
145
|
+
for (const dir of [...new Set(searchDirs)]) {
|
|
146
|
+
const typeFiles = await findFiles("**/*.types.ts", { cwd: dir });
|
|
147
|
+
const srcFiles = await findFiles("src/**/*.ts", { cwd: dir });
|
|
148
|
+
const allFiles = [...new Set([...typeFiles, ...srcFiles])];
|
|
149
|
+
for (const filePath of allFiles) {
|
|
150
|
+
await collectInterfaceTypesFromFile(interfaces, filePath);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return interfaces;
|
|
154
|
+
}
|
|
155
|
+
async function getCachedInterfaceTypes(searchDirs) {
|
|
156
|
+
const cacheKey = getInterfaceSearchKey(searchDirs);
|
|
157
|
+
const cached = interfaceTypeCache.get(cacheKey);
|
|
158
|
+
if (cached) {
|
|
159
|
+
return cached;
|
|
160
|
+
}
|
|
161
|
+
const pending = findInterfaceTypes(searchDirs);
|
|
162
|
+
interfaceTypeCache.set(cacheKey, pending);
|
|
163
|
+
try {
|
|
164
|
+
return await pending;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
interfaceTypeCache.delete(cacheKey);
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async function discoverDurableObjects(cwd, pattern = DEFAULT_DO_PATTERN) {
|
|
171
|
+
const discovered = [];
|
|
172
|
+
const files = await findFiles(pattern, { cwd });
|
|
173
|
+
for (const filePath of files) {
|
|
174
|
+
const code = await readFileIfAvailable(filePath);
|
|
175
|
+
if (!code) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const classNames = findDurableObjectClasses(code);
|
|
179
|
+
for (const className of classNames) {
|
|
180
|
+
const bindingName = className.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toUpperCase();
|
|
181
|
+
discovered.push({
|
|
182
|
+
className,
|
|
183
|
+
filePath,
|
|
184
|
+
bindingName
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return discovered;
|
|
189
|
+
}
|
|
190
|
+
function generateImportPath(cwd, filePath) {
|
|
191
|
+
let relativePath = relative(cwd, filePath);
|
|
192
|
+
relativePath = relativePath.replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
193
|
+
if (!relativePath.startsWith(".") && !relativePath.startsWith("/")) {
|
|
194
|
+
relativePath = `./${relativePath}`;
|
|
195
|
+
}
|
|
196
|
+
return relativePath;
|
|
197
|
+
}
|
|
198
|
+
async function resolveReferencedConfigs(configPath, cwd) {
|
|
199
|
+
const referenced = [];
|
|
200
|
+
const { refs, serviceBindings, doBindings } = await parseConfigForRefs(configPath);
|
|
201
|
+
if (refs.length === 0) {
|
|
202
|
+
return referenced;
|
|
203
|
+
}
|
|
204
|
+
const configDir = dirname(configPath);
|
|
205
|
+
const referencedConfigDetailsByPath = new Map;
|
|
206
|
+
for (const ref of refs) {
|
|
207
|
+
const refImportPath = resolvePackageSpecifier(ref.importPath, configDir);
|
|
208
|
+
const refConfigPath = await resolveConfigCandidatePath(refImportPath);
|
|
209
|
+
if (!refConfigPath) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
let referencedConfigDetails = referencedConfigDetailsByPath.get(refConfigPath);
|
|
214
|
+
if (!referencedConfigDetails) {
|
|
215
|
+
referencedConfigDetails = (async () => {
|
|
216
|
+
const refDir2 = dirname(refConfigPath);
|
|
217
|
+
return {
|
|
218
|
+
refDir: refDir2,
|
|
219
|
+
entrypoints: await discoverEntrypointsAsync(refDir2, DEFAULT_ENTRYPOINT_PATTERN),
|
|
220
|
+
refDOs: await discoverDurableObjects(refDir2, DEFAULT_DO_PATTERN),
|
|
221
|
+
interfaceMap: await getCachedInterfaceTypes([configDir, refDir2])
|
|
222
|
+
};
|
|
223
|
+
})();
|
|
224
|
+
referencedConfigDetailsByPath.set(refConfigPath, referencedConfigDetails);
|
|
225
|
+
}
|
|
226
|
+
const {
|
|
227
|
+
refDir,
|
|
228
|
+
entrypoints,
|
|
229
|
+
refDOs,
|
|
230
|
+
interfaceMap
|
|
231
|
+
} = await referencedConfigDetails;
|
|
232
|
+
const bindings = serviceBindings.filter((serviceBinding) => serviceBinding.varName === ref.varName).map((serviceBinding) => {
|
|
233
|
+
const info = {
|
|
234
|
+
bindingName: serviceBinding.bindingName,
|
|
235
|
+
entrypoint: serviceBinding.entrypoint
|
|
236
|
+
};
|
|
237
|
+
const lookupKey = serviceBinding.entrypoint || "__default__";
|
|
238
|
+
const interfaceInfo = interfaceMap.get(lookupKey) || (serviceBinding.entrypoint ? interfaceMap.get(serviceBinding.entrypoint) : undefined);
|
|
239
|
+
if (interfaceInfo) {
|
|
240
|
+
info.interfaceImport = generateImportPath(cwd, interfaceInfo.filePath);
|
|
241
|
+
info.interfaceType = interfaceInfo.interfaceName;
|
|
242
|
+
}
|
|
243
|
+
return info;
|
|
244
|
+
});
|
|
245
|
+
const crossWorkerDOs = doBindings.filter((doBinding) => doBinding.varName === ref.varName).map((doBinding) => {
|
|
246
|
+
const matchingDO = refDOs.find((doInfo) => doInfo.bindingName === doBinding.doName);
|
|
247
|
+
if (!matchingDO) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
const crossWorkerDO = {
|
|
251
|
+
bindingName: doBinding.bindingName,
|
|
252
|
+
doName: doBinding.doName,
|
|
253
|
+
className: matchingDO.className,
|
|
254
|
+
filePath: matchingDO.filePath
|
|
255
|
+
};
|
|
256
|
+
return crossWorkerDO;
|
|
257
|
+
}).filter((item) => item !== null);
|
|
258
|
+
referenced.push({
|
|
259
|
+
varName: ref.varName,
|
|
260
|
+
importPath: ref.importPath,
|
|
261
|
+
refDir,
|
|
262
|
+
entrypoints,
|
|
263
|
+
serviceBindings: bindings,
|
|
264
|
+
durableObjects: crossWorkerDOs
|
|
265
|
+
});
|
|
266
|
+
} catch {}
|
|
267
|
+
}
|
|
268
|
+
return referenced;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// src/cli/commands/type-generation/generator.ts
|
|
272
|
+
function generateBindingMembers(config, doClassMap, crossWorkerDOMap, serviceBindingMap, cwd, indent, options = {}) {
|
|
273
|
+
const lines = [];
|
|
274
|
+
const imports = [];
|
|
275
|
+
if (config.bindings) {
|
|
276
|
+
if (config.bindings.kv) {
|
|
277
|
+
for (const binding of Object.keys(config.bindings.kv)) {
|
|
278
|
+
lines.push(`${indent}${binding}: KVNamespace`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (config.bindings.d1) {
|
|
282
|
+
for (const binding of Object.keys(config.bindings.d1)) {
|
|
283
|
+
lines.push(`${indent}${binding}: D1Database`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (config.bindings.r2) {
|
|
287
|
+
for (const binding of Object.keys(config.bindings.r2)) {
|
|
288
|
+
lines.push(`${indent}${binding}: R2Bucket`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (config.bindings.durableObjects) {
|
|
292
|
+
for (const [binding, doConfig] of Object.entries(config.bindings.durableObjects)) {
|
|
293
|
+
const crossWorkerDO = crossWorkerDOMap.get(binding);
|
|
294
|
+
if (crossWorkerDO) {
|
|
295
|
+
const importPath = generateImportPath(cwd, crossWorkerDO.filePath);
|
|
296
|
+
lines.push(`${indent}${binding}: DurableObjectNamespace<Rpc.DurableObjectBranded & import('${importPath}').${crossWorkerDO.className}>`);
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
const className = doConfig.className;
|
|
300
|
+
if (className) {
|
|
301
|
+
const classInfo = doClassMap.get(className);
|
|
302
|
+
if (classInfo) {
|
|
303
|
+
lines.push(`${indent}${binding}: DurableObjectNamespace<Rpc.DurableObjectBranded & import('${classInfo.importPath}').${classInfo.className}>`);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
lines.push(`${indent}${binding}: DurableObjectNamespace`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (config.bindings.queues?.producers) {
|
|
311
|
+
for (const binding of Object.keys(config.bindings.queues.producers)) {
|
|
312
|
+
lines.push(`${indent}${binding}: Queue`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (config.bindings.rateLimits) {
|
|
316
|
+
for (const binding of Object.keys(config.bindings.rateLimits)) {
|
|
317
|
+
lines.push(`${indent}${binding}: RateLimit`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (config.bindings.versionMetadata?.binding) {
|
|
321
|
+
lines.push(`${indent}${config.bindings.versionMetadata.binding}: WorkerVersionMetadata`);
|
|
322
|
+
}
|
|
323
|
+
if (config.bindings.workerLoaders) {
|
|
324
|
+
for (const binding of Object.keys(config.bindings.workerLoaders)) {
|
|
325
|
+
lines.push(`${indent}${binding}: WorkerLoader`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (config.bindings.mtlsCertificates) {
|
|
329
|
+
for (const binding of Object.keys(config.bindings.mtlsCertificates)) {
|
|
330
|
+
lines.push(`${indent}${binding}: Fetcher`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (config.bindings.dispatchNamespaces) {
|
|
334
|
+
for (const binding of Object.keys(config.bindings.dispatchNamespaces)) {
|
|
335
|
+
lines.push(`${indent}${binding}: DispatchNamespace`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (config.bindings.workflows) {
|
|
339
|
+
for (const binding of Object.keys(config.bindings.workflows)) {
|
|
340
|
+
lines.push(`${indent}${binding}: Workflow`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (config.bindings.pipelines) {
|
|
344
|
+
imports.push("import type { Pipeline } from 'cloudflare:pipelines'");
|
|
345
|
+
for (const binding of Object.keys(config.bindings.pipelines)) {
|
|
346
|
+
lines.push(`${indent}${binding}: Pipeline`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (config.bindings.images) {
|
|
350
|
+
for (const binding of Object.keys(config.bindings.images)) {
|
|
351
|
+
lines.push(`${indent}${binding}: ImagesBinding`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (config.bindings.media) {
|
|
355
|
+
for (const binding of Object.keys(config.bindings.media)) {
|
|
356
|
+
lines.push(`${indent}${binding}: MediaBinding`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (config.bindings.artifacts) {
|
|
360
|
+
for (const binding of Object.keys(config.bindings.artifacts)) {
|
|
361
|
+
lines.push(`${indent}${binding}: Artifacts`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (config.bindings.secretsStore) {
|
|
365
|
+
for (const binding of Object.keys(config.bindings.secretsStore)) {
|
|
366
|
+
lines.push(`${indent}${binding}: SecretsStoreSecret`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (config.bindings.services) {
|
|
370
|
+
for (const binding of Object.keys(config.bindings.services)) {
|
|
371
|
+
const serviceInfo = serviceBindingMap.get(binding);
|
|
372
|
+
if (serviceInfo?.interfaceType && serviceInfo.interfaceImport) {
|
|
373
|
+
imports.push(`import type { ${serviceInfo.interfaceType} } from '${serviceInfo.interfaceImport}'`);
|
|
374
|
+
lines.push(`${indent}${binding}: ${serviceInfo.interfaceType}`);
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
lines.push(`${indent}${binding}: Fetcher`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (config.bindings.ai) {
|
|
381
|
+
lines.push(`${indent}${config.bindings.ai.binding}: Ai`);
|
|
382
|
+
}
|
|
383
|
+
if (config.bindings.aiSearchNamespaces) {
|
|
384
|
+
for (const binding of Object.keys(config.bindings.aiSearchNamespaces)) {
|
|
385
|
+
lines.push(`${indent}${binding}: AiSearchNamespace`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (config.bindings.aiSearch) {
|
|
389
|
+
for (const binding of Object.keys(config.bindings.aiSearch)) {
|
|
390
|
+
lines.push(`${indent}${binding}: AiSearchInstance`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (config.bindings.vectorize) {
|
|
394
|
+
for (const binding of Object.keys(config.bindings.vectorize)) {
|
|
395
|
+
lines.push(`${indent}${binding}: VectorizeIndex`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (config.bindings.hyperdrive) {
|
|
399
|
+
for (const binding of Object.keys(config.bindings.hyperdrive)) {
|
|
400
|
+
lines.push(`${indent}${binding}: Hyperdrive`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (config.bindings.browser) {
|
|
404
|
+
for (const binding of Object.keys(config.bindings.browser)) {
|
|
405
|
+
lines.push(`${indent}${binding}: Fetcher`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (config.bindings.analyticsEngine) {
|
|
409
|
+
for (const binding of Object.keys(config.bindings.analyticsEngine)) {
|
|
410
|
+
lines.push(`${indent}${binding}: AnalyticsEngineDataset`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (config.bindings.sendEmail) {
|
|
414
|
+
for (const binding of Object.keys(config.bindings.sendEmail)) {
|
|
415
|
+
lines.push(`${indent}${binding}: SendEmail`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (options.includeVarsAsMembers !== false && config.vars) {
|
|
420
|
+
for (const key of Object.keys(config.vars)) {
|
|
421
|
+
lines.push(`${indent}${key}: string`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (config.secrets) {
|
|
425
|
+
for (const secret of Object.keys(config.secrets)) {
|
|
426
|
+
lines.push(`${indent}${secret}: string`);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return { lines, imports };
|
|
430
|
+
}
|
|
431
|
+
function normalizeModuleDeclarationGlob(glob) {
|
|
432
|
+
return glob.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\*\*\//, "");
|
|
433
|
+
}
|
|
434
|
+
function generateModuleRuleDeclarations(config) {
|
|
435
|
+
const declarations = [];
|
|
436
|
+
const seen = new Set;
|
|
437
|
+
const typeByRuleType = {
|
|
438
|
+
Text: "string",
|
|
439
|
+
Data: "ArrayBuffer",
|
|
440
|
+
CompiledWasm: "WebAssembly.Module"
|
|
441
|
+
};
|
|
442
|
+
for (const rule of config.rules ?? []) {
|
|
443
|
+
const valueType = rule.type ? typeByRuleType[rule.type] : undefined;
|
|
444
|
+
if (!valueType) {
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
for (const glob of rule.globs ?? []) {
|
|
448
|
+
const specifier = normalizeModuleDeclarationGlob(glob);
|
|
449
|
+
const key = `${specifier}:${valueType}`;
|
|
450
|
+
if (seen.has(key)) {
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
seen.add(key);
|
|
454
|
+
declarations.push(`declare module '${specifier}' {`);
|
|
455
|
+
declarations.push(` const value: ${valueType}`);
|
|
456
|
+
declarations.push("\texport default value");
|
|
457
|
+
declarations.push("}");
|
|
458
|
+
declarations.push("");
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return declarations;
|
|
462
|
+
}
|
|
463
|
+
function generateBindingTypes(config, discoveredDOs, discoveredEntrypoints, referencedConfigs, cwd, options = {}) {
|
|
464
|
+
const doClassMap = new Map;
|
|
465
|
+
for (const doInfo of discoveredDOs) {
|
|
466
|
+
doClassMap.set(doInfo.className, {
|
|
467
|
+
importPath: generateImportPath(cwd, doInfo.filePath),
|
|
468
|
+
className: doInfo.className
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
const crossWorkerDOMap = new Map;
|
|
472
|
+
for (const ref of referencedConfigs) {
|
|
473
|
+
for (const doInfo of ref.durableObjects) {
|
|
474
|
+
crossWorkerDOMap.set(doInfo.bindingName, doInfo);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
const serviceBindingMap = new Map;
|
|
478
|
+
for (const ref of referencedConfigs) {
|
|
479
|
+
for (const serviceBinding of ref.serviceBindings) {
|
|
480
|
+
serviceBindingMap.set(serviceBinding.bindingName, serviceBinding);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const usedTypes = new Set;
|
|
484
|
+
if (config.bindings) {
|
|
485
|
+
if (config.bindings.kv && Object.keys(config.bindings.kv).length > 0)
|
|
486
|
+
usedTypes.add("KVNamespace");
|
|
487
|
+
if (config.bindings.d1 && Object.keys(config.bindings.d1).length > 0)
|
|
488
|
+
usedTypes.add("D1Database");
|
|
489
|
+
if (config.bindings.r2 && Object.keys(config.bindings.r2).length > 0)
|
|
490
|
+
usedTypes.add("R2Bucket");
|
|
491
|
+
if (config.bindings.durableObjects && Object.keys(config.bindings.durableObjects).length > 0)
|
|
492
|
+
usedTypes.add("DurableObjectNamespace");
|
|
493
|
+
if (config.bindings.queues?.producers && Object.keys(config.bindings.queues.producers).length > 0)
|
|
494
|
+
usedTypes.add("Queue");
|
|
495
|
+
if (config.bindings.rateLimits && Object.keys(config.bindings.rateLimits).length > 0)
|
|
496
|
+
usedTypes.add("RateLimit");
|
|
497
|
+
if (config.bindings.versionMetadata?.binding)
|
|
498
|
+
usedTypes.add("WorkerVersionMetadata");
|
|
499
|
+
if (config.bindings.workerLoaders && Object.keys(config.bindings.workerLoaders).length > 0)
|
|
500
|
+
usedTypes.add("WorkerLoader");
|
|
501
|
+
if (config.bindings.mtlsCertificates && Object.keys(config.bindings.mtlsCertificates).length > 0)
|
|
502
|
+
usedTypes.add("Fetcher");
|
|
503
|
+
if (config.bindings.dispatchNamespaces && Object.keys(config.bindings.dispatchNamespaces).length > 0)
|
|
504
|
+
usedTypes.add("DispatchNamespace");
|
|
505
|
+
if (config.bindings.workflows && Object.keys(config.bindings.workflows).length > 0)
|
|
506
|
+
usedTypes.add("Workflow");
|
|
507
|
+
if (config.bindings.images && Object.keys(config.bindings.images).length > 0)
|
|
508
|
+
usedTypes.add("ImagesBinding");
|
|
509
|
+
if (config.bindings.media && Object.keys(config.bindings.media).length > 0)
|
|
510
|
+
usedTypes.add("MediaBinding");
|
|
511
|
+
if (config.bindings.artifacts && Object.keys(config.bindings.artifacts).length > 0)
|
|
512
|
+
usedTypes.add("Artifacts");
|
|
513
|
+
if (config.bindings.secretsStore && Object.keys(config.bindings.secretsStore).length > 0)
|
|
514
|
+
usedTypes.add("SecretsStoreSecret");
|
|
515
|
+
if (config.bindings.services) {
|
|
516
|
+
const hasUntypedServices = Object.keys(config.bindings.services).some((name) => !serviceBindingMap.get(name)?.interfaceType);
|
|
517
|
+
if (hasUntypedServices)
|
|
518
|
+
usedTypes.add("Fetcher");
|
|
519
|
+
}
|
|
520
|
+
if (config.bindings.ai)
|
|
521
|
+
usedTypes.add("Ai");
|
|
522
|
+
if (config.bindings.aiSearchNamespaces && Object.keys(config.bindings.aiSearchNamespaces).length > 0) {
|
|
523
|
+
usedTypes.add("AiSearchNamespace");
|
|
524
|
+
}
|
|
525
|
+
if (config.bindings.aiSearch && Object.keys(config.bindings.aiSearch).length > 0) {
|
|
526
|
+
usedTypes.add("AiSearchInstance");
|
|
527
|
+
}
|
|
528
|
+
if (config.bindings.vectorize && Object.keys(config.bindings.vectorize).length > 0)
|
|
529
|
+
usedTypes.add("VectorizeIndex");
|
|
530
|
+
if (config.bindings.hyperdrive && Object.keys(config.bindings.hyperdrive).length > 0)
|
|
531
|
+
usedTypes.add("Hyperdrive");
|
|
532
|
+
if (config.bindings.browser && Object.keys(config.bindings.browser).length > 0)
|
|
533
|
+
usedTypes.add("Fetcher");
|
|
534
|
+
if (config.bindings.analyticsEngine && Object.keys(config.bindings.analyticsEngine).length > 0)
|
|
535
|
+
usedTypes.add("AnalyticsEngineDataset");
|
|
536
|
+
if (config.bindings.sendEmail && Object.keys(config.bindings.sendEmail).length > 0)
|
|
537
|
+
usedTypes.add("SendEmail");
|
|
538
|
+
}
|
|
539
|
+
const lines = [
|
|
540
|
+
"// Generated by devflare - DO NOT EDIT",
|
|
541
|
+
"// Run `devflare types` to regenerate",
|
|
542
|
+
""
|
|
543
|
+
];
|
|
544
|
+
const hasConfigVars = Boolean(config.vars && Object.keys(config.vars).length > 0);
|
|
545
|
+
const hasLocalDOsWithClasses = Boolean(config.bindings?.durableObjects && Object.values(config.bindings.durableObjects).some((doConfig) => doConfig.className && doClassMap.has(doConfig.className)));
|
|
546
|
+
const hasCrossWorkerDOs = crossWorkerDOMap.size > 0;
|
|
547
|
+
const hasDOsWithClasses = hasLocalDOsWithClasses || hasCrossWorkerDOs;
|
|
548
|
+
if (usedTypes.size > 0) {
|
|
549
|
+
const sortedTypes = [...usedTypes].sort();
|
|
550
|
+
if (hasDOsWithClasses) {
|
|
551
|
+
lines.push(`import type { ${sortedTypes.join(", ")}, Rpc } from '@cloudflare/workers-types'`);
|
|
552
|
+
} else {
|
|
553
|
+
lines.push(`import type { ${sortedTypes.join(", ")} } from '@cloudflare/workers-types'`);
|
|
554
|
+
}
|
|
555
|
+
lines.push("");
|
|
556
|
+
}
|
|
557
|
+
if (hasConfigVars) {
|
|
558
|
+
const configImportPath = options.configImportPath ?? "./devflare.config";
|
|
559
|
+
lines.push("import type { InferConfigVars } from 'devflare/config'");
|
|
560
|
+
lines.push(`type __DevflareConfigVars = InferConfigVars<Awaited<typeof import('${configImportPath}').default>>`);
|
|
561
|
+
lines.push("");
|
|
562
|
+
}
|
|
563
|
+
const { lines: bindingMembers, imports: serviceImports } = generateBindingMembers(config, doClassMap, crossWorkerDOMap, serviceBindingMap, cwd, "\t\t", { includeVarsAsMembers: !hasConfigVars });
|
|
564
|
+
const uniqueImports = [...new Set(serviceImports)];
|
|
565
|
+
if (uniqueImports.length > 0) {
|
|
566
|
+
lines.push(...uniqueImports);
|
|
567
|
+
lines.push("");
|
|
568
|
+
}
|
|
569
|
+
lines.push("declare global {");
|
|
570
|
+
if (hasConfigVars) {
|
|
571
|
+
lines.push("\tinterface DevflareVars extends __DevflareConfigVars {}");
|
|
572
|
+
lines.push("\tinterface DevflareEnv extends __DevflareConfigVars {");
|
|
573
|
+
} else {
|
|
574
|
+
lines.push("\tinterface DevflareEnv {");
|
|
575
|
+
}
|
|
576
|
+
lines.push(...bindingMembers);
|
|
577
|
+
lines.push("\t}");
|
|
578
|
+
lines.push("}");
|
|
579
|
+
lines.push("");
|
|
580
|
+
lines.push(...generateModuleRuleDeclarations(config));
|
|
581
|
+
if (discoveredEntrypoints.length > 0) {
|
|
582
|
+
const entrypointNames = discoveredEntrypoints.map((entrypoint) => `'${entrypoint.className}'`).join(" | ");
|
|
583
|
+
lines.push("/**");
|
|
584
|
+
lines.push(" * Named entrypoints discovered from ep.*.ts files.");
|
|
585
|
+
lines.push(" * Use with defineConfig<Entrypoints>() for type-safe cross-worker references.");
|
|
586
|
+
lines.push(" */");
|
|
587
|
+
lines.push(`export type Entrypoints = ${entrypointNames}`);
|
|
588
|
+
} else {
|
|
589
|
+
lines.push("/**");
|
|
590
|
+
lines.push(" * Named entrypoints (none discovered - add ep.*.ts files to enable).");
|
|
591
|
+
lines.push(" * Use with defineConfig<Entrypoints>() for type-safe cross-worker references.");
|
|
592
|
+
lines.push(" */");
|
|
593
|
+
lines.push("export type Entrypoints = string");
|
|
594
|
+
}
|
|
595
|
+
lines.push("");
|
|
596
|
+
return lines.join(`
|
|
597
|
+
`);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// src/cli/commands/types.ts
|
|
601
|
+
function logTypesLine(logger, message = "") {
|
|
602
|
+
if (typeof logger.log === "function") {
|
|
603
|
+
logger.log(message);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
if (typeof logger.info === "function") {
|
|
607
|
+
logger.info(message);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
async function runTypesCommand(parsed, logger, options) {
|
|
611
|
+
const cwd = options.cwd || process.cwd();
|
|
612
|
+
const configPath = parsed.options.config;
|
|
613
|
+
const outputPath = parsed.options.output || "env.d.ts";
|
|
614
|
+
const theme = createCliTheme(parsed.options);
|
|
615
|
+
logTypesLine(logger);
|
|
616
|
+
logTypesLine(logger, `${bold("types", theme)} ${dim("Generating TypeScript bindings", theme)}`);
|
|
617
|
+
try {
|
|
618
|
+
const config = await loadConfig({ cwd, configFile: configPath });
|
|
619
|
+
const requestedConfigPath = configPath ? resolve(cwd, configPath) : cwd;
|
|
620
|
+
const actualConfigPath = await resolveConfigCandidatePath(requestedConfigPath);
|
|
621
|
+
if (!actualConfigPath) {
|
|
622
|
+
throw new Error("Could not resolve the loaded devflare config file path");
|
|
623
|
+
}
|
|
624
|
+
const doPattern = typeof config.files?.durableObjects === "string" ? config.files.durableObjects : DEFAULT_DO_PATTERN;
|
|
625
|
+
let discoveredDOs = [];
|
|
626
|
+
if (config.files?.durableObjects !== false) {
|
|
627
|
+
discoveredDOs = await discoverDurableObjects(cwd, doPattern);
|
|
628
|
+
if (discoveredDOs.length > 0) {
|
|
629
|
+
logTypesLine(logger, `Discovered ${discoveredDOs.length} Durable Object class(es):`);
|
|
630
|
+
for (const doInfo of discoveredDOs) {
|
|
631
|
+
logTypesLine(logger, ` • ${doInfo.className} → ${doInfo.bindingName}`);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (config.bindings?.durableObjects) {
|
|
636
|
+
for (const [bindingName, doConfig] of Object.entries(config.bindings.durableObjects)) {
|
|
637
|
+
const normalized = normalizeDOBinding(doConfig);
|
|
638
|
+
const className = normalized.className;
|
|
639
|
+
if (!className) {
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
642
|
+
const existing = discoveredDOs.find((doInfo) => doInfo.className === className);
|
|
643
|
+
if (existing) {
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
if (normalized.scriptName && (normalized.scriptName.endsWith(".ts") || normalized.scriptName.endsWith(".js"))) {
|
|
647
|
+
const filePath = resolve(cwd, "src", normalized.scriptName);
|
|
648
|
+
discoveredDOs.push({
|
|
649
|
+
className,
|
|
650
|
+
filePath,
|
|
651
|
+
bindingName
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
const entrypointPattern = typeof config.files?.entrypoints === "string" ? config.files.entrypoints : DEFAULT_ENTRYPOINT_PATTERN;
|
|
657
|
+
let discoveredEntrypoints = [];
|
|
658
|
+
if (config.files?.entrypoints !== false) {
|
|
659
|
+
discoveredEntrypoints = await discoverEntrypointsAsync(cwd, entrypointPattern);
|
|
660
|
+
if (discoveredEntrypoints.length > 0) {
|
|
661
|
+
logTypesLine(logger, `Discovered ${discoveredEntrypoints.length} entrypoint class(es):`);
|
|
662
|
+
for (const entrypoint of discoveredEntrypoints) {
|
|
663
|
+
logTypesLine(logger, ` • ${entrypoint.className}`);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
const referencedConfigs = await resolveReferencedConfigs(actualConfigPath, cwd);
|
|
668
|
+
if (referencedConfigs.length > 0) {
|
|
669
|
+
logTypesLine(logger, `Found ${referencedConfigs.length} referenced worker(s):`);
|
|
670
|
+
for (const ref of referencedConfigs) {
|
|
671
|
+
const typedBindings = ref.serviceBindings.filter((serviceBinding) => serviceBinding.interfaceType);
|
|
672
|
+
if (typedBindings.length > 0) {
|
|
673
|
+
logTypesLine(logger, ` • ${ref.varName}: ${typedBindings.map((serviceBinding) => `${serviceBinding.bindingName} → ${serviceBinding.interfaceType}`).join(", ")}`);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
const normalizedConfig = {
|
|
678
|
+
...config,
|
|
679
|
+
bindings: config.bindings ? {
|
|
680
|
+
...config.bindings,
|
|
681
|
+
durableObjects: config.bindings.durableObjects ? Object.fromEntries(Object.entries(config.bindings.durableObjects).map(([name, doConfig]) => {
|
|
682
|
+
const normalized = normalizeDOBinding(doConfig);
|
|
683
|
+
return [name, { className: normalized.className, scriptName: normalized.scriptName }];
|
|
684
|
+
})) : undefined
|
|
685
|
+
} : undefined
|
|
686
|
+
};
|
|
687
|
+
const types = generateBindingTypes(normalizedConfig, discoveredDOs, discoveredEntrypoints, referencedConfigs, cwd, { configImportPath: generateImportPath(cwd, actualConfigPath) });
|
|
688
|
+
const { fs } = await getDependencies();
|
|
689
|
+
const fullPath = resolve(cwd, outputPath);
|
|
690
|
+
await fs.writeFile(fullPath, types, "utf-8");
|
|
691
|
+
logger.success(`Generated types: ${outputPath}`);
|
|
692
|
+
return { exitCode: 0 };
|
|
693
|
+
} catch (error) {
|
|
694
|
+
if (error instanceof Error) {
|
|
695
|
+
logger.error("Type generation failed:", error.message);
|
|
696
|
+
if (parsed.options.debug) {
|
|
697
|
+
logger.error(error.stack);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
return { exitCode: 1 };
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
export {
|
|
704
|
+
runTypesCommand
|
|
705
|
+
};
|