devflare 1.0.0-next.5 → 1.0.0-next.7

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 (37) hide show
  1. package/LLM.md +7 -2
  2. package/README.md +4 -2
  3. package/dist/browser.d.ts +50 -0
  4. package/dist/browser.d.ts.map +1 -0
  5. package/dist/browser.js +149 -0
  6. package/dist/{build-mnf6v8gd.js → build-9myaxf07.js} +22 -5
  7. package/dist/cli/commands/build.d.ts.map +1 -1
  8. package/dist/cli/commands/deploy.d.ts.map +1 -1
  9. package/dist/cli/commands/types.d.ts.map +1 -1
  10. package/dist/{deploy-nhceck39.js → deploy-h1wz5p7m.js} +29 -13
  11. package/dist/{dev-b9dmrj7b.js → dev-rsdssknb.js} +381 -91
  12. package/dist/dev-server/server.d.ts.map +1 -1
  13. package/dist/index-62b3gt2g.js +12 -0
  14. package/dist/index-9ats0s83.js +70 -0
  15. package/dist/index-a0fjkq68.js +198 -0
  16. package/dist/{index-pf5s73n9.js → index-ccrh4w3t.js} +1 -281
  17. package/dist/{index-ep3445yc.js → index-f8qh2tyh.js} +34 -107
  18. package/dist/index-k7r18na8.js +0 -0
  19. package/dist/{index-m2q41jwa.js → index-n3np2d6t.js} +1 -1
  20. package/dist/index-npc1c8jx.js +44 -0
  21. package/dist/index-p7g30wd2.js +281 -0
  22. package/dist/{index-07q6yxyc.js → index-v8vvsn9x.js} +1 -0
  23. package/dist/index.js +25 -26
  24. package/dist/runtime/index.d.ts +2 -0
  25. package/dist/runtime/index.d.ts.map +1 -1
  26. package/dist/runtime/index.js +73 -0
  27. package/dist/sveltekit/index.js +5 -3
  28. package/dist/test/index.js +10 -5
  29. package/dist/test/simple-context.d.ts +1 -1
  30. package/dist/test/simple-context.d.ts.map +1 -1
  31. package/dist/{types-5nyrz1sz.js → types-wdcpnfvy.js} +44 -11
  32. package/dist/vite/index.js +118 -50
  33. package/dist/vite/plugin.d.ts.map +1 -1
  34. package/dist/worker-entry/composed-worker.d.ts +10 -0
  35. package/dist/worker-entry/composed-worker.d.ts.map +1 -0
  36. package/package.json +3 -2
  37. package/dist/{doctor-fmgb3d28.js → doctor-v7jy4s3r.js} +3 -3
@@ -1,3 +1,7 @@
1
+ import {
2
+ getRemoteModeStatus,
3
+ isRemoteModeActive
4
+ } from "./index-d8bdkx2h.js";
1
5
  import {
2
6
  transformWorkerEntrypoint
3
7
  } from "./index-z14anrqp.js";
@@ -6,9 +10,12 @@ import {
6
10
  resolvePackageSpecifier
7
11
  } from "./index-tk6ej9dj.js";
8
12
  import {
9
- getRemoteModeStatus,
10
- isRemoteModeActive
11
- } from "./index-d8bdkx2h.js";
13
+ __clearTestContext,
14
+ __setTestContext
15
+ } from "./index-9ats0s83.js";
16
+ import {
17
+ runWithContext
18
+ } from "./index-npc1c8jx.js";
12
19
  import {
13
20
  DEFAULT_DO_PATTERN,
14
21
  findFiles,
@@ -18,16 +25,18 @@ import {
18
25
  findDurableObjectClasses
19
26
  } from "./index-gz1gndna.js";
20
27
  import {
21
- BridgeClient,
22
- bridgeEnv,
23
- createEnvProxy,
24
- setBindingHints,
25
28
  startMiniflare,
26
29
  startMiniflareFromConfig
27
- } from "./index-pf5s73n9.js";
30
+ } from "./index-p7g30wd2.js";
31
+ import {
32
+ BridgeClient,
33
+ createEnvProxy,
34
+ setBindingHints
35
+ } from "./index-ccrh4w3t.js";
28
36
  import {
29
37
  loadConfig,
30
- normalizeDOBinding
38
+ normalizeDOBinding,
39
+ resolveConfigPath
31
40
  } from "./index-hcex3rgh.js";
32
41
  import {
33
42
  canProceedWithTest,
@@ -574,86 +583,6 @@ export default {
574
583
  }
575
584
  }
576
585
 
577
- // src/runtime/context.ts
578
- import { AsyncLocalStorage } from "node:async_hooks";
579
- var storage = new AsyncLocalStorage;
580
- function runWithContext(env, ctx, request, fn, type = "fetch") {
581
- const context = {
582
- env,
583
- ctx,
584
- request,
585
- locals: {},
586
- type
587
- };
588
- return storage.run(context, fn);
589
- }
590
- function getContextOrNull() {
591
- const context = storage.getStore();
592
- return context ?? null;
593
- }
594
-
595
- // src/env.ts
596
- var testContextEnv = null;
597
- var testContextDispose = null;
598
- function __setTestContext(envBindings, dispose) {
599
- testContextEnv = envBindings;
600
- testContextDispose = dispose;
601
- }
602
- function __clearTestContext() {
603
- testContextEnv = null;
604
- testContextDispose = null;
605
- }
606
- var env = new Proxy({}, {
607
- get(_target, prop) {
608
- if (prop === "dispose") {
609
- return async () => {
610
- if (testContextDispose) {
611
- await testContextDispose();
612
- __clearTestContext();
613
- }
614
- };
615
- }
616
- const ctx = getContextOrNull();
617
- if (ctx?.env) {
618
- return ctx.env[prop];
619
- }
620
- if (testContextEnv) {
621
- return testContextEnv[prop];
622
- }
623
- return bridgeEnv[prop];
624
- },
625
- has(_target, prop) {
626
- if (prop === "dispose")
627
- return true;
628
- const ctx = getContextOrNull();
629
- if (ctx?.env) {
630
- return prop in ctx.env;
631
- }
632
- if (testContextEnv) {
633
- return prop in testContextEnv;
634
- }
635
- return prop in bridgeEnv;
636
- },
637
- ownKeys(_target) {
638
- const ctx = getContextOrNull();
639
- if (ctx?.env) {
640
- return Reflect.ownKeys(ctx.env);
641
- }
642
- if (testContextEnv) {
643
- return Reflect.ownKeys(testContextEnv);
644
- }
645
- return Reflect.ownKeys(bridgeEnv);
646
- },
647
- getOwnPropertyDescriptor(_target, prop) {
648
- if (prop === "dispose") {
649
- return { configurable: true, enumerable: false, writable: false };
650
- }
651
- const ctx = getContextOrNull();
652
- const source = ctx?.env ?? testContextEnv ?? bridgeEnv;
653
- return Reflect.getOwnPropertyDescriptor(source, prop);
654
- }
655
- });
656
-
657
586
  // src/test/queue.ts
658
587
  import { join as join2 } from "path";
659
588
  var queueHandlerPath = null;
@@ -740,8 +669,8 @@ Or: export async function queue(batch, env, ctx) { ... }`);
740
669
  passThroughOnException() {},
741
670
  props: {}
742
671
  };
743
- const env2 = testEnvGetter();
744
- await queueHandler(batch, env2, ctx);
672
+ const env = testEnvGetter();
673
+ await queueHandler(batch, env, ctx);
745
674
  await Promise.all(waitUntilPromises);
746
675
  const acked = [];
747
676
  const retried = [];
@@ -820,9 +749,9 @@ Or: export async function scheduled(controller, env, ctx) { ... }`);
820
749
  passThroughOnException() {},
821
750
  props: {}
822
751
  };
823
- const env2 = testEnvGetter2();
752
+ const env = testEnvGetter2();
824
753
  try {
825
- await scheduledHandler(controller, env2, ctx);
754
+ await scheduledHandler(controller, env, ctx);
826
755
  await Promise.all(waitUntilPromises);
827
756
  return {
828
757
  success: true,
@@ -903,8 +832,8 @@ Or: export async function fetch(request, env, ctx) { ... }`);
903
832
  passThroughOnException() {},
904
833
  props: {}
905
834
  };
906
- const env2 = testEnvGetter3();
907
- const response = await fetchHandler(req, env2, ctx);
835
+ const env = testEnvGetter3();
836
+ const response = await fetchHandler(req, env, ctx);
908
837
  return response;
909
838
  }
910
839
  async function get(path, headers) {
@@ -994,9 +923,9 @@ Or: export async function tail(events, env, ctx) { ... }`);
994
923
  passThroughOnException() {},
995
924
  props: {}
996
925
  };
997
- const env2 = testEnvGetter4();
926
+ const env = testEnvGetter4();
998
927
  try {
999
- await tailHandler(traceItems, env2, ctx);
928
+ await tailHandler(traceItems, env, ctx);
1000
929
  await Promise.all(waitUntilPromises);
1001
930
  return {
1002
931
  success: true,
@@ -1134,15 +1063,12 @@ function getCallerDirectory() {
1134
1063
  }
1135
1064
  return process.cwd();
1136
1065
  }
1137
- function findNearestConfig(startDir) {
1138
- const configNames = ["devflare.config.ts", "devflare.config.js"];
1066
+ async function findNearestConfig(startDir) {
1139
1067
  let currentDir = startDir;
1140
1068
  while (true) {
1141
- for (const name of configNames) {
1142
- const configPath = join6(currentDir, name);
1143
- if (existsSync2(configPath)) {
1144
- return configPath;
1145
- }
1069
+ const configPath = await resolveConfigPath(currentDir);
1070
+ if (configPath) {
1071
+ return configPath;
1146
1072
  }
1147
1073
  const parentDir = dirname2(currentDir);
1148
1074
  if (parentDir === currentDir) {
@@ -1157,9 +1083,10 @@ async function createTestContext(configPath) {
1157
1083
  if (configPath) {
1158
1084
  absolutePath = resolve2(callerDir, configPath);
1159
1085
  } else {
1160
- const found = findNearestConfig(callerDir);
1086
+ const found = await findNearestConfig(callerDir);
1161
1087
  if (!found) {
1162
- throw new Error(`Could not find devflare.config.ts. Searched upward from: ${callerDir}
1088
+ throw new Error(`Could not find a devflare config file. Searched upward from: ${callerDir}
1089
+ ` + `Expected one of: devflare.config.ts, devflare.config.mts, devflare.config.js, devflare.config.mjs
1163
1090
  ` + `Either create a config file or provide an explicit path: createTestContext('./path/to/config.ts')`);
1164
1091
  }
1165
1092
  absolutePath = found;
@@ -2222,4 +2149,4 @@ var testEnv = new Proxy({}, {
2222
2149
  function isKVNamespace(binding) {
2223
2150
  return typeof binding === "object" && binding !== null && "get" in binding && "put" in binding && "delete" in binding && "list" in binding;
2224
2151
  }
2225
- export { env, clearBundleCache, hasServiceBindings, resolveServiceBindings, hasCrossWorkerDOs, resolveDOBindings, queue, scheduled, worker, tail, email, createTestContext, cf, createMultiWorkerContext, createEntrypointScript, isRemoteModeEnabled, shouldSkip, createMockTestContext, withTestContext, createMockKV, createMockD1, createMockR2, createMockQueue, createMockEnv, createBridgeTestContext, stopBridgeTestContext, getBridgeTestContext, testEnv };
2152
+ export { clearBundleCache, hasServiceBindings, resolveServiceBindings, hasCrossWorkerDOs, resolveDOBindings, queue, scheduled, worker, tail, email, createTestContext, cf, createMultiWorkerContext, createEntrypointScript, isRemoteModeEnabled, shouldSkip, createMockTestContext, withTestContext, createMockKV, createMockD1, createMockR2, createMockQueue, createMockEnv, createBridgeTestContext, stopBridgeTestContext, getBridgeTestContext, testEnv };
File without changes
@@ -9,7 +9,7 @@ import {
9
9
  parseJsonMsg,
10
10
  serializeValue,
11
11
  stringifyJsonMsg
12
- } from "./index-pf5s73n9.js";
12
+ } from "./index-ccrh4w3t.js";
13
13
 
14
14
  // src/bridge/server.ts
15
15
  var server_default = {
@@ -0,0 +1,44 @@
1
+ // src/runtime/context.ts
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ var storage = new AsyncLocalStorage;
4
+ function runWithContext(env, ctx, request, fn, type = "fetch") {
5
+ const context = {
6
+ env,
7
+ ctx,
8
+ request,
9
+ locals: {},
10
+ type
11
+ };
12
+ return storage.run(context, fn);
13
+ }
14
+ function getContext() {
15
+ const context = storage.getStore();
16
+ if (!context) {
17
+ throw new ContextUnavailableError;
18
+ }
19
+ return context;
20
+ }
21
+ function getContextOrNull() {
22
+ const context = storage.getStore();
23
+ return context ?? null;
24
+ }
25
+ function hasContext() {
26
+ return storage.getStore() !== undefined;
27
+ }
28
+
29
+ class ContextUnavailableError extends Error {
30
+ code = "CONTEXT_UNAVAILABLE";
31
+ constructor() {
32
+ super(`Context not available. This usually means one of:
33
+
34
+ ` + `1. Accessing context at module top-level (runs at cold start, not per-request)
35
+ ` + `2. Accessing context in setTimeout/setInterval callbacks
36
+ ` + `3. Missing 'nodejs_compat' compatibility flag in your worker config
37
+
38
+ ` + `Fix: Move the access inside your fetch handler or middleware.
39
+ ` + `Learn more: https://devflare.dev/docs/context-errors`);
40
+ this.name = "ContextUnavailableError";
41
+ }
42
+ }
43
+
44
+ export { runWithContext, getContext, getContextOrNull, hasContext, ContextUnavailableError };
@@ -0,0 +1,281 @@
1
+ import {
2
+ normalizeDOBinding
3
+ } from "./index-hcex3rgh.js";
4
+ import {
5
+ __require
6
+ } from "./index-37x76zdn.js";
7
+
8
+ // src/bridge/miniflare.ts
9
+ function generateGatewayScript() {
10
+ return `
11
+ // Gateway Worker — Provides RPC access to all bindings
12
+ export default {
13
+ async fetch(request, env, ctx) {
14
+ const url = new URL(request.url)
15
+
16
+ // Health check
17
+ if (url.pathname === '/_devflare/health') {
18
+ return new Response(JSON.stringify({ status: 'ok', bindings: Object.keys(env) }), {
19
+ headers: { 'Content-Type': 'application/json' }
20
+ })
21
+ }
22
+
23
+ // RPC endpoint
24
+ if (url.pathname === '/_devflare/rpc' && request.method === 'POST') {
25
+ try {
26
+ const { method, params } = await request.json()
27
+ const result = await executeRpc(env, method, params)
28
+ return new Response(JSON.stringify({ ok: true, result }), {
29
+ headers: { 'Content-Type': 'application/json' }
30
+ })
31
+ } catch (error) {
32
+ return new Response(JSON.stringify({
33
+ ok: false,
34
+ error: { code: 'RPC_ERROR', message: error.message }
35
+ }), {
36
+ status: 500,
37
+ headers: { 'Content-Type': 'application/json' }
38
+ })
39
+ }
40
+ }
41
+
42
+ return new Response('Devflare Gateway', { status: 200 })
43
+ }
44
+ }
45
+
46
+ async function executeRpc(env, method, params) {
47
+ const [bindingName, ...methodPath] = method.split('.')
48
+ const binding = env[bindingName]
49
+
50
+ if (!binding) {
51
+ throw new Error(\`Binding "\${bindingName}" not found\`)
52
+ }
53
+
54
+ const methodName = methodPath.join('.')
55
+
56
+ // KV operations
57
+ if (methodName === 'get') return binding.get(params[0], params[1])
58
+ if (methodName === 'put') return binding.put(params[0], params[1], params[2])
59
+ if (methodName === 'delete') return binding.delete(params[0])
60
+ if (methodName === 'list') return binding.list(params[0])
61
+ if (methodName === 'getWithMetadata') return binding.getWithMetadata(params[0], params[1])
62
+
63
+ // R2 operations
64
+ if (methodName === 'head') return binding.head(params[0])
65
+ if (methodName === 'r2.get') return serializeR2Object(await binding.get(params[0], params[1]))
66
+ if (methodName === 'r2.put') return serializeR2Object(await binding.put(params[0], params[1], params[2]))
67
+ if (methodName === 'r2.delete') return binding.delete(params[0])
68
+ if (methodName === 'r2.list') return serializeR2Objects(await binding.list(params[0]))
69
+
70
+ // D1 operations
71
+ if (methodName === 'exec') return binding.exec(params[0])
72
+ if (methodName === 'batch') {
73
+ const statements = params[0].map(s => binding.prepare(s.sql).bind(...(s.bindings || [])))
74
+ return binding.batch(statements)
75
+ }
76
+ if (methodName.startsWith('stmt.')) {
77
+ const [, stmtMethod] = methodName.split('.')
78
+ const [sql, ...bindings] = params
79
+ const stmt = binding.prepare(sql).bind(...bindings.slice(0, -1))
80
+
81
+ if (stmtMethod === 'first') return stmt.first(bindings[bindings.length - 1])
82
+ if (stmtMethod === 'all') return stmt.all()
83
+ if (stmtMethod === 'run') return stmt.run()
84
+ if (stmtMethod === 'raw') return stmt.raw(bindings[bindings.length - 1])
85
+ }
86
+
87
+ // DO operations
88
+ if (methodName === 'idFromName') {
89
+ const id = binding.idFromName(params[0])
90
+ return { __type: 'DOId', hex: id.toString() }
91
+ }
92
+ if (methodName === 'idFromString') {
93
+ const id = binding.idFromString(params[0])
94
+ return { __type: 'DOId', hex: id.toString() }
95
+ }
96
+ if (methodName === 'newUniqueId') {
97
+ const id = binding.newUniqueId(params[0])
98
+ return { __type: 'DOId', hex: id.toString() }
99
+ }
100
+ if (methodName === 'stub.fetch') {
101
+ const [, doId, serializedReq] = params
102
+ const id = binding.idFromString(doId.hex)
103
+ const stub = binding.get(id)
104
+ const response = await stub.fetch(new Request(serializedReq.url, {
105
+ method: serializedReq.method,
106
+ headers: serializedReq.headers,
107
+ body: serializedReq.body?.type === 'bytes' ? atob(serializedReq.body.data) : undefined
108
+ }))
109
+ return serializeResponse(response)
110
+ }
111
+ if (methodName === 'stub.rpc') {
112
+ // DO RPC: Call a method on the DO instance
113
+ const [, doId, rpcMethod, rpcParams] = params
114
+ const id = binding.idFromString(doId.hex)
115
+ const stub = binding.get(id)
116
+
117
+ // Use fetch to call the RPC endpoint
118
+ const response = await stub.fetch(new Request('http://do/_rpc', {
119
+ method: 'POST',
120
+ headers: { 'Content-Type': 'application/json' },
121
+ body: JSON.stringify({ method: rpcMethod, params: rpcParams })
122
+ }))
123
+
124
+ const result = await response.json()
125
+ if (!result.ok) throw new Error(result.error?.message || 'RPC failed')
126
+ return result.result
127
+ }
128
+
129
+ // Queue operations
130
+ if (methodName === 'send') return binding.send(params[0], params[1])
131
+ if (methodName === 'sendBatch') return binding.sendBatch(params[0], params[1])
132
+
133
+ // Generic fallback
134
+ if (typeof binding[methodName] === 'function') {
135
+ return binding[methodName](...params)
136
+ }
137
+
138
+ throw new Error(\`Unknown method: \${method}\`)
139
+ }
140
+
141
+ function serializeResponse(response) {
142
+ return {
143
+ status: response.status,
144
+ statusText: response.statusText,
145
+ headers: [...response.headers.entries()],
146
+ body: null // Will be streamed separately for large bodies
147
+ }
148
+ }
149
+
150
+ function serializeR2Object(obj) {
151
+ if (!obj) return null
152
+ return {
153
+ key: obj.key,
154
+ version: obj.version,
155
+ size: obj.size,
156
+ etag: obj.etag,
157
+ httpEtag: obj.httpEtag,
158
+ uploaded: obj.uploaded?.toISOString(),
159
+ httpMetadata: obj.httpMetadata,
160
+ customMetadata: obj.customMetadata
161
+ }
162
+ }
163
+
164
+ function serializeR2Objects(result) {
165
+ if (!result) return null
166
+ return {
167
+ objects: result.objects.map(serializeR2Object),
168
+ truncated: result.truncated,
169
+ cursor: result.cursor,
170
+ delimitedPrefixes: result.delimitedPrefixes
171
+ }
172
+ }
173
+ `;
174
+ }
175
+ async function startMiniflare(options = {}) {
176
+ const { Miniflare, Log, LogLevel } = await import("miniflare");
177
+ const port = options.port ?? 8787;
178
+ const persistPath = options.persistPath ?? ".devflare/data";
179
+ const mfConfig = {
180
+ modules: true,
181
+ script: generateGatewayScript(),
182
+ port,
183
+ host: "127.0.0.1",
184
+ log: options.verbose ? new Log(LogLevel.DEBUG) : new Log(LogLevel.WARN),
185
+ compatibilityDate: options.compatibilityDate ?? "2024-01-01",
186
+ compatibilityFlags: options.compatibilityFlags ?? []
187
+ };
188
+ const hasBindings = (val) => {
189
+ if (!val)
190
+ return false;
191
+ if (Array.isArray(val))
192
+ return val.length > 0;
193
+ return Object.keys(val).length > 0;
194
+ };
195
+ if (hasBindings(options.kvNamespaces)) {
196
+ mfConfig.kvNamespaces = options.kvNamespaces;
197
+ if (options.persist) {
198
+ mfConfig.kvPersist = `${persistPath}/kv`;
199
+ }
200
+ }
201
+ if (hasBindings(options.r2Buckets)) {
202
+ mfConfig.r2Buckets = options.r2Buckets;
203
+ if (options.persist) {
204
+ mfConfig.r2Persist = `${persistPath}/r2`;
205
+ }
206
+ }
207
+ if (hasBindings(options.d1Databases)) {
208
+ mfConfig.d1Databases = options.d1Databases;
209
+ if (options.persist) {
210
+ mfConfig.d1Persist = `${persistPath}/d1`;
211
+ }
212
+ }
213
+ if (options.durableObjects) {
214
+ mfConfig.durableObjects = options.durableObjects;
215
+ if (options.persist) {
216
+ mfConfig.durableObjectsPersist = `${persistPath}/do`;
217
+ }
218
+ }
219
+ if (options.bindings) {
220
+ mfConfig.bindings = options.bindings;
221
+ }
222
+ if (options.queues?.length) {
223
+ mfConfig.queueProducers = Object.fromEntries(options.queues.map((q) => [q, { queueName: q }]));
224
+ }
225
+ const mf = new Miniflare(mfConfig);
226
+ await mf.ready;
227
+ return {
228
+ ready: Promise.resolve(),
229
+ async dispose() {
230
+ await mf.dispose();
231
+ },
232
+ async getBindings() {
233
+ return mf.getBindings();
234
+ },
235
+ getKVNamespace: mf.getKVNamespace.bind(mf),
236
+ getR2Bucket: mf.getR2Bucket.bind(mf),
237
+ getD1Database: mf.getD1Database.bind(mf),
238
+ getDurableObjectNamespace: mf.getDurableObjectNamespace.bind(mf),
239
+ dispatchFetch: mf.dispatchFetch.bind(mf),
240
+ _mf: mf
241
+ };
242
+ }
243
+ async function startMiniflareFromConfig(config, options = {}) {
244
+ const bindings = config.bindings ?? {};
245
+ const mfOptions = {
246
+ ...options,
247
+ compatibilityDate: config.compatibilityDate,
248
+ compatibilityFlags: config.compatibilityFlags,
249
+ kvNamespaces: bindings.kv ? bindings.kv : undefined,
250
+ r2Buckets: bindings.r2 ? bindings.r2 : undefined,
251
+ d1Databases: bindings.d1 ? bindings.d1 : undefined,
252
+ queues: bindings.queues?.consumers?.map((c) => c.queue),
253
+ bindings: config.vars,
254
+ durableObjects: bindings.durableObjects ? Object.fromEntries(Object.entries(bindings.durableObjects).map(([bindingName, doConfig]) => {
255
+ const normalized = normalizeDOBinding(doConfig);
256
+ return [
257
+ bindingName,
258
+ {
259
+ className: normalized.className,
260
+ scriptPath: normalized.scriptName
261
+ }
262
+ ];
263
+ })) : undefined
264
+ };
265
+ return startMiniflare(mfOptions);
266
+ }
267
+ var globalMiniflare = null;
268
+ async function getMiniflare(options) {
269
+ if (!globalMiniflare) {
270
+ globalMiniflare = await startMiniflare(options);
271
+ }
272
+ return globalMiniflare;
273
+ }
274
+ async function stopMiniflare() {
275
+ if (globalMiniflare) {
276
+ await globalMiniflare.dispose();
277
+ globalMiniflare = null;
278
+ }
279
+ }
280
+
281
+ export { startMiniflare, startMiniflareFromConfig, getMiniflare, stopMiniflare };
@@ -165,4 +165,5 @@ function serviceBinding(refOrLegacy, options) {
165
165
  __ref: refOrLegacy
166
166
  };
167
167
  }
168
+
168
169
  export { defineConfig, ref, resolveRef, serviceBinding };
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ import {
2
+ workerName
3
+ } from "./index-62b3gt2g.js";
1
4
  import {
2
5
  createBridgeTestContext,
3
6
  createMockD1,
@@ -7,12 +10,12 @@ import {
7
10
  createMockR2,
8
11
  createMockTestContext,
9
12
  createTestContext,
10
- env,
11
13
  getBridgeTestContext,
12
14
  stopBridgeTestContext,
13
15
  testEnv,
14
16
  withTestContext
15
- } from "./index-ep3445yc.js";
17
+ } from "./index-f8qh2tyh.js";
18
+ import"./index-d8bdkx2h.js";
16
19
  import {
17
20
  findExportedFunctions,
18
21
  generateRpcInterface,
@@ -20,7 +23,10 @@ import {
20
23
  transformWorkerEntrypoint
21
24
  } from "./index-z14anrqp.js";
22
25
  import"./index-tk6ej9dj.js";
23
- import"./index-d8bdkx2h.js";
26
+ import {
27
+ env
28
+ } from "./index-9ats0s83.js";
29
+ import"./index-npc1c8jx.js";
24
30
  import"./index-rbht7m9r.js";
25
31
  import {
26
32
  findDurableObjectClasses,
@@ -30,24 +36,27 @@ import {
30
36
  } from "./index-gz1gndna.js";
31
37
  import {
32
38
  server_default
33
- } from "./index-m2q41jwa.js";
39
+ } from "./index-n3np2d6t.js";
34
40
  import {
35
- BridgeClient,
36
- createEnvProxy,
37
- getClient,
38
41
  getMiniflare,
39
- initEnv,
40
- setBindingHints,
41
42
  startMiniflare,
42
43
  startMiniflareFromConfig,
43
44
  stopMiniflare
44
- } from "./index-pf5s73n9.js";
45
+ } from "./index-p7g30wd2.js";
46
+ import"./index-k7r18na8.js";
47
+ import {
48
+ BridgeClient,
49
+ createEnvProxy,
50
+ getClient,
51
+ initEnv,
52
+ setBindingHints
53
+ } from "./index-ccrh4w3t.js";
45
54
  import {
46
55
  defineConfig,
47
56
  ref,
48
57
  resolveRef,
49
58
  serviceBinding
50
- } from "./index-07q6yxyc.js";
59
+ } from "./index-v8vvsn9x.js";
51
60
  import {
52
61
  compileConfig,
53
62
  stringifyConfig
@@ -66,16 +75,6 @@ import {
66
75
  import {
67
76
  __require
68
77
  } from "./index-37x76zdn.js";
69
- // src/workerName.ts
70
- var workerName = (() => {
71
- if (typeof __DEVFLARE_WORKER_NAME__ !== "undefined") {
72
- return __DEVFLARE_WORKER_NAME__;
73
- }
74
- if (typeof process !== "undefined" && process.env?.DEVFLARE_WORKER_NAME) {
75
- return process.env.DEVFLARE_WORKER_NAME;
76
- }
77
- return "unknown";
78
- })();
79
78
  // src/cli/index.ts
80
79
  import { createConsola } from "consola";
81
80
  var COMMANDS = ["init", "dev", "build", "deploy", "types", "doctor", "account", "ai", "remote", "help", "version"];
@@ -216,23 +215,23 @@ async function runInit(parsed, logger, options) {
216
215
  return runInitCommand(parsed, logger, options);
217
216
  }
218
217
  async function runDev(parsed, logger, options) {
219
- const { runDevCommand } = await import("./dev-b9dmrj7b.js");
218
+ const { runDevCommand } = await import("./dev-rsdssknb.js");
220
219
  return runDevCommand(parsed, logger, options);
221
220
  }
222
221
  async function runBuild(parsed, logger, options) {
223
- const { runBuildCommand } = await import("./build-mnf6v8gd.js");
222
+ const { runBuildCommand } = await import("./build-9myaxf07.js");
224
223
  return runBuildCommand(parsed, logger, options);
225
224
  }
226
225
  async function runDeploy(parsed, logger, options) {
227
- const { runDeployCommand } = await import("./deploy-nhceck39.js");
226
+ const { runDeployCommand } = await import("./deploy-h1wz5p7m.js");
228
227
  return runDeployCommand(parsed, logger, options);
229
228
  }
230
229
  async function runTypes(parsed, logger, options) {
231
- const { runTypesCommand } = await import("./types-5nyrz1sz.js");
230
+ const { runTypesCommand } = await import("./types-wdcpnfvy.js");
232
231
  return runTypesCommand(parsed, logger, options);
233
232
  }
234
233
  async function runDoctor(parsed, logger, options) {
235
- const { runDoctorCommand } = await import("./doctor-fmgb3d28.js");
234
+ const { runDoctorCommand } = await import("./doctor-v7jy4s3r.js");
236
235
  return runDoctorCommand(parsed, logger, options);
237
236
  }
238
237
  async function runAccount(parsed, logger, options) {
@@ -1,3 +1,5 @@
1
+ export { env, ctx, event, locals, type EventContext } from './exports';
2
+ export { runWithContext, getContext, getContextOrNull, hasContext, ContextUnavailableError, type RequestContext } from './context';
1
3
  export { createContextProxy, ContextAccessError } from './validation';
2
4
  export { sequence, resolve, pipe, type Middleware, type Handler } from './middleware';
3
5
  export { durableObject, getDurableObjectOptions, type DurableObjectOptions } from '../decorators';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAGrE,OAAO,EACN,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,MAAM,cAAc,CAAA;AAGrB,OAAO,EACN,aAAa,EACb,uBAAuB,EACvB,KAAK,oBAAoB,EACzB,MAAM,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACN,GAAG,EACH,GAAG,EACH,KAAK,EACL,MAAM,EACN,KAAK,YAAY,EACjB,MAAM,WAAW,CAAA;AAGlB,OAAO,EACN,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,uBAAuB,EACvB,KAAK,cAAc,EACnB,MAAM,WAAW,CAAA;AAGlB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAGrE,OAAO,EACN,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,MAAM,cAAc,CAAA;AAGrB,OAAO,EACN,aAAa,EACb,uBAAuB,EACvB,KAAK,oBAAoB,EACzB,MAAM,eAAe,CAAA"}