devflare 1.0.0-next.34 → 1.0.0-next.36

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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/LLM.md +2 -0
  3. package/README.md +5 -4
  4. package/bin/devflare.js +1 -1
  5. package/dist/{account-p9eywryw.js → account-4tgh03a8.js} +4 -6
  6. package/dist/bridge/client.d.ts +1 -1
  7. package/dist/bridge/v2/control-messages.d.ts +1 -6
  8. package/dist/bridge/v2/control-messages.d.ts.map +1 -1
  9. package/dist/bridge/v2/wire.d.ts +4 -4
  10. package/dist/bridge/v2/wire.d.ts.map +1 -1
  11. package/dist/browser.js +2340 -19
  12. package/dist/{build-8bn7frg8.js → build-rh7ghrgw.js} +7 -10
  13. package/dist/cli/index.js +1377 -6
  14. package/dist/cloudflare/index.js +2 -3
  15. package/dist/config-entry.js +1 -9
  16. package/dist/{config-gphd6wx7.js → config-ghk2bxj3.js} +3 -6
  17. package/dist/{deploy-vpcp41fw.js → deploy-6hzv76sh.js} +13 -17
  18. package/dist/{dev-9scy9gap.js → dev-mkhjdwh7.js} +971 -73
  19. package/dist/{doctor-swfeeqny.js → doctor-0ng5qrr1.js} +2 -3
  20. package/dist/{index-e7xn30bh.js → index-0cc05hzv.js} +1 -1
  21. package/dist/{index-t0r7evpw.js → index-293aqfy4.js} +7 -9
  22. package/dist/{index-3t0e51a0.js → index-2yv7w548.js} +1 -1
  23. package/dist/{index-ksqth51q.js → index-a8pnvg3r.js} +1 -1
  24. package/dist/{index-bhxj7ff6.js → index-e251zhns.js} +943 -117
  25. package/dist/{index-2xz4etye.js → index-hvtd936d.js} +3 -0
  26. package/dist/{index-13sfensw.js → index-kcp7y951.js} +2 -13
  27. package/dist/{index-w8c8tjc5.js → index-mek9msfv.js} +1 -4
  28. package/dist/{index-dem45895.js → index-mjvybn39.js} +1 -1
  29. package/dist/{index-x0wpeb3x.js → index-phcrvs6d.js} +112 -2
  30. package/dist/{index-b20xx2vk.js → index-se4kw8tm.js} +4 -6
  31. package/dist/{index-pd97hk2j.js → index-x8s9rwfh.js} +466 -19
  32. package/dist/index.js +1 -42
  33. package/dist/{login-7vyzeqy4.js → login-4h1sfsed.js} +4 -6
  34. package/dist/{previews-jfbectpc.js → previews-qr7c5j8h.js} +10 -14
  35. package/dist/{productions-49ct4kjm.js → productions-xpmd6bw8.js} +6 -9
  36. package/dist/{remote-6876k6mz.js → remote-kqcvhnfx.js} +100 -5
  37. package/dist/runtime/index.js +0 -63
  38. package/dist/{secrets-9ne7armr.js → secrets-6wbdsdek.js} +3 -5
  39. package/dist/sveltekit/index.js +0 -263
  40. package/dist/test/index.js +2 -4626
  41. package/dist/{types-zekmbebk.js → types-ahnnpphq.js} +6 -8
  42. package/dist/vite/index.js +7 -9
  43. package/dist/{worker-706g8qeh.js → worker-1yg72jxg.js} +6 -9
  44. package/package.json +5 -3
  45. package/dist/index-1trss579.js +0 -2299
  46. package/dist/index-34dejneh.js +0 -214
  47. package/dist/index-3z20d3kd.js +0 -1380
  48. package/dist/index-4xmtkg9g.js +0 -109
  49. package/dist/index-62b3gt2g.js +0 -12
  50. package/dist/index-97rfy7n2.js +0 -413
  51. package/dist/index-c4zd39tc.js +0 -155
  52. package/dist/index-dgx495pv.js +0 -1036
  53. package/dist/index-dm9q84c7.js +0 -360
  54. package/dist/index-pmnb7eke.js +0 -109
  55. package/dist/index-t23wq5js.js +0 -111
  56. package/dist/index-wxdcrzcp.js +0 -475
  57. package/dist/index-x2fd1361.js +0 -133
  58. package/dist/index-za0r01bx.js +0 -588
@@ -1,360 +0,0 @@
1
- // src/shims/local-media-bindings.ts
2
- function emptyNodeStream() {
3
- return new ReadableStream({
4
- start(controller) {
5
- controller.close();
6
- }
7
- });
8
- }
9
- function normalizeNodeContentType(value, fallback) {
10
- if (!value)
11
- return fallback;
12
- if (value.includes("/"))
13
- return value;
14
- if (value === "jpg" || value === "jpeg")
15
- return "image/jpeg";
16
- if (value === "png")
17
- return "image/png";
18
- if (value === "webp")
19
- return "image/webp";
20
- if (value === "avif")
21
- return "image/avif";
22
- if (value === "mp4")
23
- return "video/mp4";
24
- return value;
25
- }
26
- async function readNodeBytes(stream) {
27
- const buffer = await new Response(stream ?? emptyNodeStream()).arrayBuffer();
28
- return new Uint8Array(buffer);
29
- }
30
- function streamFromNodeBytes(bytes) {
31
- const copy = new Uint8Array(bytes.byteLength);
32
- copy.set(bytes);
33
- return new Response(copy).body ?? emptyNodeStream();
34
- }
35
- function createUnsupportedHostedImagesBinding() {
36
- const unsupported = () => {
37
- throw new Error("Devflare local Images hosted API is not implemented. Use transform/info APIs locally, or connect to Cloudflare for hosted image storage.");
38
- };
39
- return {
40
- image(_imageId) {
41
- return {
42
- details: unsupported,
43
- bytes: unsupported,
44
- update: unsupported,
45
- delete: unsupported
46
- };
47
- },
48
- upload: unsupported,
49
- list: unsupported
50
- };
51
- }
52
- function createNodeImageResult(bytes, contentType) {
53
- return {
54
- response() {
55
- return new Response(streamFromNodeBytes(bytes), {
56
- headers: { "Content-Type": contentType }
57
- });
58
- },
59
- contentType() {
60
- return contentType;
61
- },
62
- image() {
63
- return streamFromNodeBytes(bytes);
64
- }
65
- };
66
- }
67
- function createNodeImageTransformer(bytesPromise) {
68
- const transformer = {
69
- transform(_transform) {
70
- return transformer;
71
- },
72
- draw(_image, _options) {
73
- return transformer;
74
- },
75
- async output(options) {
76
- return createNodeImageResult(await bytesPromise, normalizeNodeContentType(options?.format, "image/png"));
77
- }
78
- };
79
- return transformer;
80
- }
81
- function createLocalImagesBinding() {
82
- return {
83
- async info(stream) {
84
- const bytes = await readNodeBytes(stream);
85
- return {
86
- format: "image/png",
87
- fileSize: bytes.byteLength,
88
- width: 1,
89
- height: 1
90
- };
91
- },
92
- input(stream) {
93
- return createNodeImageTransformer(readNodeBytes(stream));
94
- },
95
- hosted: createUnsupportedHostedImagesBinding()
96
- };
97
- }
98
- function createNodeMediaResult(bytesPromise, contentType) {
99
- return {
100
- async media() {
101
- return streamFromNodeBytes(await bytesPromise);
102
- },
103
- async response() {
104
- return new Response(streamFromNodeBytes(await bytesPromise), {
105
- headers: { "Content-Type": contentType }
106
- });
107
- },
108
- async contentType() {
109
- return contentType;
110
- }
111
- };
112
- }
113
- function createNodeMediaTransformer(bytesPromise) {
114
- const output = (options = {}) => createNodeMediaResult(bytesPromise, normalizeNodeContentType(options.format, "video/mp4"));
115
- return {
116
- transform(_transform) {
117
- return {
118
- output(options) {
119
- return output(options);
120
- }
121
- };
122
- },
123
- output(options) {
124
- return output(options);
125
- }
126
- };
127
- }
128
- function createLocalMediaBinding() {
129
- return {
130
- input(stream) {
131
- return createNodeMediaTransformer(readNodeBytes(stream));
132
- }
133
- };
134
- }
135
- var LOCAL_MEDIA_BINDING_SCRIPT = `
136
- import { RpcTarget, WorkerEntrypoint } from 'cloudflare:workers'
137
-
138
- function emptyStream() {
139
- return new ReadableStream({
140
- start(controller) {
141
- controller.close()
142
- }
143
- })
144
- }
145
-
146
- function normalizeContentType(value, fallback) {
147
- if (typeof value !== 'string' || value.length === 0) return fallback
148
- if (value.includes('/')) return value
149
- if (value === 'jpg') return 'image/jpeg'
150
- if (value === 'jpeg') return 'image/jpeg'
151
- if (value === 'png') return 'image/png'
152
- if (value === 'webp') return 'image/webp'
153
- if (value === 'avif') return 'image/avif'
154
- if (value === 'mp4') return 'video/mp4'
155
- return value
156
- }
157
-
158
- async function readBytes(stream) {
159
- return await new Response(stream || emptyStream()).arrayBuffer()
160
- }
161
-
162
- function streamFromBytes(bytes) {
163
- return new Response(bytes.slice(0)).body || emptyStream()
164
- }
165
-
166
- function createBodyReader(bytes) {
167
- return function takeBody() {
168
- return streamFromBytes(bytes)
169
- }
170
- }
171
-
172
- class LocalImageResult extends RpcTarget {
173
- constructor(takeBody, contentType) {
174
- super()
175
- this.takeBody = takeBody
176
- this.contentTypeValue = contentType
177
- }
178
-
179
- response() {
180
- return new Response(this.takeBody(), {
181
- headers: { 'Content-Type': this.contentTypeValue }
182
- })
183
- }
184
-
185
- contentType() {
186
- return this.contentTypeValue
187
- }
188
-
189
- image() {
190
- return this.takeBody()
191
- }
192
- }
193
-
194
- class LocalImageTransformer extends RpcTarget {
195
- constructor(bytes) {
196
- super()
197
- this.takeBody = createBodyReader(bytes)
198
- }
199
-
200
- transform() {
201
- return this
202
- }
203
-
204
- draw() {
205
- return this
206
- }
207
-
208
- async output(options = {}) {
209
- return new LocalImageResult(
210
- this.takeBody,
211
- normalizeContentType(options.format, 'image/png')
212
- )
213
- }
214
- }
215
-
216
- function createHostedImagesBinding() {
217
- const unsupported = () => {
218
- throw new Error('Devflare local Images hosted API is not implemented. Use the transform/info APIs locally, or connect to Cloudflare for hosted image storage.')
219
- }
220
- return {
221
- image() {
222
- return {
223
- details: unsupported,
224
- bytes: unsupported,
225
- update: unsupported,
226
- delete: unsupported
227
- }
228
- },
229
- upload: unsupported,
230
- list: unsupported
231
- }
232
- }
233
-
234
- export class LocalImagesBinding extends WorkerEntrypoint {
235
- async info(stream) {
236
- const bytes = await readBytes(stream)
237
- return {
238
- format: 'image/png',
239
- fileSize: bytes.byteLength,
240
- width: 1,
241
- height: 1
242
- }
243
- }
244
-
245
- async input(stream) {
246
- return new LocalImageTransformer(await readBytes(stream))
247
- }
248
-
249
- get hosted() {
250
- return createHostedImagesBinding()
251
- }
252
- }
253
-
254
- class LocalMediaResult extends RpcTarget {
255
- constructor(takeBody, contentType) {
256
- super()
257
- this.takeBody = takeBody
258
- this.contentTypeValue = contentType
259
- }
260
-
261
- async media() {
262
- return this.takeBody()
263
- }
264
-
265
- async response() {
266
- return new Response(this.takeBody(), {
267
- headers: { 'Content-Type': this.contentTypeValue }
268
- })
269
- }
270
-
271
- async contentType() {
272
- return this.contentTypeValue
273
- }
274
- }
275
-
276
- class LocalMediaTransformationGenerator extends RpcTarget {
277
- constructor(takeBody) {
278
- super()
279
- this.takeBody = takeBody
280
- }
281
-
282
- output(options = {}) {
283
- return new LocalMediaResult(
284
- this.takeBody,
285
- normalizeContentType(options.format, 'video/mp4')
286
- )
287
- }
288
- }
289
-
290
- class LocalMediaTransformer extends RpcTarget {
291
- constructor(bytes) {
292
- super()
293
- this.takeBody = createBodyReader(bytes)
294
- }
295
-
296
- transform() {
297
- return new LocalMediaTransformationGenerator(this.takeBody)
298
- }
299
-
300
- output(options = {}) {
301
- return new LocalMediaResult(
302
- this.takeBody,
303
- normalizeContentType(options.format, 'video/mp4')
304
- )
305
- }
306
- }
307
-
308
- export class LocalMediaBinding extends WorkerEntrypoint {
309
- async input(stream) {
310
- return new LocalMediaTransformer(await readBytes(stream))
311
- }
312
- }
313
-
314
- export default {
315
- fetch() {
316
- return new Response('Devflare local Images/Media binding')
317
- }
318
- }
319
- `;
320
- function toLocalShimWorkerName(kind, bindingName, index) {
321
- const slug = bindingName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || kind;
322
- return `devflare-local-${kind}-${index}-${slug}`;
323
- }
324
- function getEntrypoint(kind) {
325
- return kind === "images" ? "LocalImagesBinding" : "LocalMediaBinding";
326
- }
327
- function buildLocalBindingShimServiceConfig(config) {
328
- const entries = [
329
- ...Object.keys(config.bindings?.images ?? {}).map((bindingName) => ({
330
- bindingName,
331
- kind: "images"
332
- })),
333
- ...Object.keys(config.bindings?.media ?? {}).map((bindingName) => ({
334
- bindingName,
335
- kind: "media"
336
- }))
337
- ];
338
- return {
339
- localBindingNames: entries.map((entry) => entry.bindingName),
340
- serviceBindings: Object.fromEntries(entries.map((entry, index) => {
341
- const workerName = toLocalShimWorkerName(entry.kind, entry.bindingName, index);
342
- return [
343
- entry.bindingName,
344
- {
345
- name: workerName,
346
- entrypoint: getEntrypoint(entry.kind)
347
- }
348
- ];
349
- })),
350
- workers: entries.map((entry, index) => ({
351
- name: toLocalShimWorkerName(entry.kind, entry.bindingName, index),
352
- modules: true,
353
- script: LOCAL_MEDIA_BINDING_SCRIPT,
354
- compatibilityDate: config.compatibilityDate ?? "2025-01-01",
355
- ...config.compatibilityFlags && { compatibilityFlags: config.compatibilityFlags }
356
- }))
357
- };
358
- }
359
-
360
- export { createLocalImagesBinding, createLocalMediaBinding, buildLocalBindingShimServiceConfig };
@@ -1,109 +0,0 @@
1
- import {
2
- bundleWorkerEntry
3
- } from "./index-dem45895.js";
4
- import {
5
- DEFAULT_WORKFLOW_PATTERN,
6
- findFiles
7
- } from "./index-5dkjffqz.js";
8
- import {
9
- normalizeWorkflowBinding
10
- } from "./index-pd97hk2j.js";
11
-
12
- // src/workflows/local-workflow-entrypoints.ts
13
- import { mkdir, readFile, writeFile } from "node:fs/promises";
14
- import { join, relative, resolve } from "pathe";
15
- function findExportedClasses(code) {
16
- const classes = [];
17
- const classPattern = /export\s+class\s+(\w+)/g;
18
- let match;
19
- while ((match = classPattern.exec(code)) !== null) {
20
- classes.push(match[1]);
21
- }
22
- return classes;
23
- }
24
- function toImportSpecifier(fromDir, filePath) {
25
- const relativePath = relative(fromDir, filePath).replace(/\\/g, "/");
26
- return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
27
- }
28
- async function discoverWorkflowClasses(config, configDir) {
29
- const classToFilePath = new Map;
30
- const workflowPatternConfig = config.files?.workflows;
31
- const workflowPattern = typeof workflowPatternConfig === "string" ? workflowPatternConfig : DEFAULT_WORKFLOW_PATTERN;
32
- if (workflowPatternConfig === false) {
33
- return classToFilePath;
34
- }
35
- const files = await findFiles(workflowPattern, { cwd: configDir });
36
- for (const filePath of files) {
37
- try {
38
- const code = await readFile(filePath, "utf-8");
39
- for (const className of findExportedClasses(code)) {
40
- classToFilePath.set(className, filePath);
41
- }
42
- } catch {}
43
- }
44
- return classToFilePath;
45
- }
46
- async function resolveLocalWorkflowEntrypoints(config, configDir) {
47
- const workflows = config.bindings?.workflows;
48
- if (!workflows || Object.keys(workflows).length === 0) {
49
- return [];
50
- }
51
- const classToFilePath = await discoverWorkflowClasses(config, configDir);
52
- const entrypoints = [];
53
- for (const [bindingName, binding] of Object.entries(workflows)) {
54
- const normalized = normalizeWorkflowBinding(binding);
55
- if (normalized.scriptName) {
56
- continue;
57
- }
58
- const scriptPath = classToFilePath.get(normalized.className);
59
- if (!scriptPath) {
60
- throw new Error(`Workflow binding ${bindingName} (className: '${normalized.className}') not found.
61
- ` + `Either set files.workflows to match the workflow source file, or set scriptName when the workflow lives in another worker.`);
62
- }
63
- entrypoints.push({
64
- bindingName,
65
- className: normalized.className,
66
- scriptPath
67
- });
68
- }
69
- return entrypoints;
70
- }
71
- function buildWorkflowVirtualEntry(entrypoints, entryDir) {
72
- const imports = entrypoints.map((entrypoint, index) => {
73
- const importName = `__DevflareWorkflow${index}`;
74
- const importPath = toImportSpecifier(entryDir, entrypoint.scriptPath);
75
- return {
76
- importName,
77
- className: entrypoint.className,
78
- line: `import { ${entrypoint.className} as ${importName} } from '${importPath}'`
79
- };
80
- });
81
- const exports = imports.map((entrypoint) => {
82
- return `export { ${entrypoint.importName} as ${entrypoint.className} }`;
83
- });
84
- return [...imports.map((entrypoint) => entrypoint.line), "", ...exports].join(`
85
- `);
86
- }
87
- async function bundleWorkflowEntrypointScript(config, configDir, options = {}) {
88
- const entrypoints = await resolveLocalWorkflowEntrypoints(config, configDir);
89
- if (entrypoints.length === 0) {
90
- return "";
91
- }
92
- const entryDir = resolve(configDir, ".devflare", "workflow-entrypoints");
93
- const entryPath = join(entryDir, "__entry.ts");
94
- const outFile = join(entryDir, "index.js");
95
- await mkdir(entryDir, { recursive: true });
96
- await writeFile(entryPath, buildWorkflowVirtualEntry(entrypoints, entryDir));
97
- await bundleWorkerEntry({
98
- cwd: configDir,
99
- inputFile: entryPath,
100
- outFile,
101
- rolldownOptions: config.rolldown?.options,
102
- sourcemap: config.rolldown?.sourcemap,
103
- minify: config.rolldown?.minify,
104
- logger: options.logger
105
- });
106
- return await readFile(outFile, "utf-8");
107
- }
108
-
109
- export { bundleWorkflowEntrypointScript };
@@ -1,111 +0,0 @@
1
- import {
2
- bridgeEnv,
3
- getContextOrNull
4
- } from "./index-1trss579.js";
5
-
6
- // src/env.ts
7
- var testContextEnv = null;
8
- var testContextDispose = null;
9
- function __setTestContext(envBindings, dispose) {
10
- testContextEnv = envBindings;
11
- testContextDispose = dispose;
12
- }
13
- function __clearTestContext() {
14
- testContextEnv = null;
15
- testContextDispose = null;
16
- }
17
- var env = new Proxy({}, {
18
- get(_target, prop) {
19
- if (prop === "dispose") {
20
- return async () => {
21
- if (testContextDispose) {
22
- await testContextDispose();
23
- __clearTestContext();
24
- }
25
- };
26
- }
27
- const ctx = getContextOrNull();
28
- if (ctx?.env) {
29
- return ctx.env[prop];
30
- }
31
- if (testContextEnv) {
32
- return testContextEnv[prop];
33
- }
34
- return bridgeEnv[prop];
35
- },
36
- has(_target, prop) {
37
- if (prop === "dispose")
38
- return true;
39
- const ctx = getContextOrNull();
40
- if (ctx?.env) {
41
- return prop in ctx.env;
42
- }
43
- if (testContextEnv) {
44
- return prop in testContextEnv;
45
- }
46
- return prop in bridgeEnv;
47
- },
48
- ownKeys(_target) {
49
- const ctx = getContextOrNull();
50
- if (ctx?.env) {
51
- return Reflect.ownKeys(ctx.env);
52
- }
53
- if (testContextEnv) {
54
- return Reflect.ownKeys(testContextEnv);
55
- }
56
- return Reflect.ownKeys(bridgeEnv);
57
- },
58
- getOwnPropertyDescriptor(_target, prop) {
59
- if (prop === "dispose") {
60
- return { configurable: true, enumerable: false, writable: false };
61
- }
62
- const ctx = getContextOrNull();
63
- const source = ctx?.env ?? testContextEnv ?? bridgeEnv;
64
- return Reflect.getOwnPropertyDescriptor(source, prop);
65
- }
66
- });
67
- var vars = new Proxy({}, {
68
- get(_target, prop) {
69
- const ctx = getContextOrNull();
70
- if (ctx?.env) {
71
- return ctx.env[prop];
72
- }
73
- if (testContextEnv) {
74
- return testContextEnv[prop];
75
- }
76
- return bridgeEnv[prop];
77
- },
78
- has(_target, prop) {
79
- const ctx = getContextOrNull();
80
- if (ctx?.env) {
81
- return prop in ctx.env;
82
- }
83
- if (testContextEnv) {
84
- return prop in testContextEnv;
85
- }
86
- return prop in bridgeEnv;
87
- },
88
- ownKeys(_target) {
89
- const ctx = getContextOrNull();
90
- if (ctx?.env) {
91
- return Reflect.ownKeys(ctx.env);
92
- }
93
- if (testContextEnv) {
94
- return Reflect.ownKeys(testContextEnv);
95
- }
96
- return Reflect.ownKeys(bridgeEnv);
97
- },
98
- getOwnPropertyDescriptor(_target, prop) {
99
- const ctx = getContextOrNull();
100
- const source = ctx?.env ?? testContextEnv ?? bridgeEnv;
101
- return Reflect.getOwnPropertyDescriptor(source, prop);
102
- },
103
- set(_target, prop) {
104
- throw new TypeError(`Cannot assign to '${String(prop)}' on 'vars' because it is read-only.`);
105
- },
106
- deleteProperty(_target, prop) {
107
- throw new TypeError(`Cannot delete property '${String(prop)}' from 'vars' because it is read-only.`);
108
- }
109
- });
110
-
111
- export { __setTestContext, __clearTestContext, env, vars };