devflare 1.0.0-next.4 → 1.0.0-next.6

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.
@@ -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,13 +25,14 @@ 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
38
  normalizeDOBinding
@@ -574,86 +582,6 @@ export default {
574
582
  }
575
583
  }
576
584
 
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
585
  // src/test/queue.ts
658
586
  import { join as join2 } from "path";
659
587
  var queueHandlerPath = null;
@@ -740,8 +668,8 @@ Or: export async function queue(batch, env, ctx) { ... }`);
740
668
  passThroughOnException() {},
741
669
  props: {}
742
670
  };
743
- const env2 = testEnvGetter();
744
- await queueHandler(batch, env2, ctx);
671
+ const env = testEnvGetter();
672
+ await queueHandler(batch, env, ctx);
745
673
  await Promise.all(waitUntilPromises);
746
674
  const acked = [];
747
675
  const retried = [];
@@ -820,9 +748,9 @@ Or: export async function scheduled(controller, env, ctx) { ... }`);
820
748
  passThroughOnException() {},
821
749
  props: {}
822
750
  };
823
- const env2 = testEnvGetter2();
751
+ const env = testEnvGetter2();
824
752
  try {
825
- await scheduledHandler(controller, env2, ctx);
753
+ await scheduledHandler(controller, env, ctx);
826
754
  await Promise.all(waitUntilPromises);
827
755
  return {
828
756
  success: true,
@@ -903,8 +831,8 @@ Or: export async function fetch(request, env, ctx) { ... }`);
903
831
  passThroughOnException() {},
904
832
  props: {}
905
833
  };
906
- const env2 = testEnvGetter3();
907
- const response = await fetchHandler(req, env2, ctx);
834
+ const env = testEnvGetter3();
835
+ const response = await fetchHandler(req, env, ctx);
908
836
  return response;
909
837
  }
910
838
  async function get(path, headers) {
@@ -994,9 +922,9 @@ Or: export async function tail(events, env, ctx) { ... }`);
994
922
  passThroughOnException() {},
995
923
  props: {}
996
924
  };
997
- const env2 = testEnvGetter4();
925
+ const env = testEnvGetter4();
998
926
  try {
999
- await tailHandler(traceItems, env2, ctx);
927
+ await tailHandler(traceItems, env, ctx);
1000
928
  await Promise.all(waitUntilPromises);
1001
929
  return {
1002
930
  success: true,
@@ -2222,4 +2150,4 @@ var testEnv = new Proxy({}, {
2222
2150
  function isKVNamespace(binding) {
2223
2151
  return typeof binding === "object" && binding !== null && "get" in binding && "put" in binding && "delete" in binding && "list" in binding;
2224
2152
  }
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 };
2153
+ 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 };
@@ -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-rprrn24p.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-pa8dhm20.js");
218
+ const { runDevCommand } = await import("./dev-7agn9g5s.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-nz5yrj7f.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-a5pcxd5w.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-vss6vrz7.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"}
@@ -1,3 +1,10 @@
1
+ import {
2
+ ContextUnavailableError,
3
+ getContext,
4
+ getContextOrNull,
5
+ hasContext,
6
+ runWithContext
7
+ } from "../index-npc1c8jx.js";
1
8
  import {
2
9
  durableObject,
3
10
  getDurableObjectOptions
@@ -62,6 +69,63 @@ function createContextProxy(getter, name) {
62
69
  }
63
70
  });
64
71
  }
72
+
73
+ // src/runtime/exports.ts
74
+ function createReadonlyProxy(getter, name) {
75
+ return new Proxy({}, {
76
+ get(_target, prop) {
77
+ const ctx = getter();
78
+ if (ctx === undefined) {
79
+ throw new ContextAccessError(name, String(prop));
80
+ }
81
+ return ctx[prop];
82
+ },
83
+ set(_target, prop) {
84
+ throw new TypeError(`Cannot assign to '${String(prop)}' on '${name}' because it is read-only.
85
+ ` + `Use 'locals' for mutable request-scoped data.`);
86
+ },
87
+ deleteProperty(_target, prop) {
88
+ throw new TypeError(`Cannot delete property '${String(prop)}' from '${name}' because it is read-only.`);
89
+ },
90
+ has(_target, prop) {
91
+ const ctx = getter();
92
+ if (ctx === undefined) {
93
+ return false;
94
+ }
95
+ return prop in ctx;
96
+ },
97
+ ownKeys(_target) {
98
+ const ctx = getter();
99
+ if (ctx === undefined) {
100
+ return [];
101
+ }
102
+ return Reflect.ownKeys(ctx);
103
+ },
104
+ getOwnPropertyDescriptor(_target, prop) {
105
+ const ctx = getter();
106
+ if (ctx === undefined) {
107
+ return;
108
+ }
109
+ const descriptor = Reflect.getOwnPropertyDescriptor(ctx, prop);
110
+ if (descriptor) {
111
+ return { ...descriptor, writable: false };
112
+ }
113
+ return;
114
+ }
115
+ });
116
+ }
117
+ var env = createReadonlyProxy(() => getContextOrNull()?.env, "env");
118
+ var ctx = createReadonlyProxy(() => getContextOrNull()?.ctx, "ctx");
119
+ var event = createReadonlyProxy(() => {
120
+ const context = getContextOrNull();
121
+ if (!context)
122
+ return;
123
+ return {
124
+ request: context.request,
125
+ type: context.type
126
+ };
127
+ }, "event");
128
+ var locals = createContextProxy(() => getContextOrNull()?.locals, "locals");
65
129
  // src/runtime/middleware.ts
66
130
  function sequence(...middlewares) {
67
131
  return (handler) => {
@@ -102,10 +166,19 @@ function pipe(middlewares, handlers) {
102
166
  }
103
167
  export {
104
168
  sequence,
169
+ runWithContext,
105
170
  resolve,
106
171
  pipe,
172
+ locals,
173
+ hasContext,
107
174
  getDurableObjectOptions,
175
+ getContextOrNull,
176
+ getContext,
177
+ event,
178
+ env,
108
179
  durableObject,
180
+ ctx,
109
181
  createContextProxy,
182
+ ContextUnavailableError,
110
183
  ContextAccessError
111
184
  };
@@ -1,9 +1,11 @@
1
- import"../index-m2q41jwa.js";
1
+ import"../index-n3np2d6t.js";
2
+ import"../index-p7g30wd2.js";
3
+ import"../index-k7r18na8.js";
2
4
  import {
3
5
  createEnvProxy,
4
6
  getClient
5
- } from "../index-pf5s73n9.js";
6
- import"../index-07q6yxyc.js";
7
+ } from "../index-ccrh4w3t.js";
8
+ import"../index-v8vvsn9x.js";
7
9
  import"../index-67qcae0f.js";
8
10
  import {
9
11
  loadConfig
@@ -12,7 +12,6 @@ import {
12
12
  createMultiWorkerContext,
13
13
  createTestContext,
14
14
  email,
15
- env,
16
15
  getBridgeTestContext,
17
16
  hasCrossWorkerDOs,
18
17
  hasServiceBindings,
@@ -27,14 +26,20 @@ import {
27
26
  testEnv,
28
27
  withTestContext,
29
28
  worker
30
- } from "../index-ep3445yc.js";
29
+ } from "../index-rprrn24p.js";
30
+ import"../index-d8bdkx2h.js";
31
31
  import"../index-z14anrqp.js";
32
32
  import"../index-tk6ej9dj.js";
33
- import"../index-d8bdkx2h.js";
33
+ import {
34
+ env
35
+ } from "../index-9ats0s83.js";
36
+ import"../index-npc1c8jx.js";
34
37
  import"../index-rbht7m9r.js";
35
38
  import"../index-gz1gndna.js";
36
- import"../index-pf5s73n9.js";
37
- import"../index-07q6yxyc.js";
39
+ import"../index-p7g30wd2.js";
40
+ import"../index-k7r18na8.js";
41
+ import"../index-ccrh4w3t.js";
42
+ import"../index-v8vvsn9x.js";
38
43
  import"../index-67qcae0f.js";
39
44
  import"../index-hcex3rgh.js";
40
45
  import"../index-tfyxa77h.js";
@@ -1,3 +1,6 @@
1
+ import {
2
+ getDependencies
3
+ } from "./index-1xpj0m4r.js";
1
4
  import {
2
5
  discoverEntrypointsAsync,
3
6
  resolvePackageSpecifier
@@ -10,15 +13,13 @@ import {
10
13
  import {
11
14
  findDurableObjectClasses
12
15
  } from "./index-gz1gndna.js";
13
- import"./index-07q6yxyc.js";
16
+ import"./index-k7r18na8.js";
17
+ import"./index-v8vvsn9x.js";
14
18
  import"./index-67qcae0f.js";
15
19
  import {
16
20
  loadConfig,
17
21
  normalizeDOBinding
18
22
  } from "./index-hcex3rgh.js";
19
- import {
20
- getDependencies
21
- } from "./index-1xpj0m4r.js";
22
23
  import {
23
24
  __require
24
25
  } from "./index-37x76zdn.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devflare",
3
- "version": "1.0.0-next.4",
3
+ "version": "1.0.0-next.6",
4
4
  "description": "Devflare is a developer-first toolkit for Cloudflare Workers that sits on top of Miniflare and Wrangler-compatible config",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -8,6 +8,7 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
+ "browser": "./dist/browser.js",
11
12
  "import": "./dist/index.js",
12
13
  "default": "./dist/index.js"
13
14
  },
@@ -53,7 +54,7 @@
53
54
  ],
54
55
  "scripts": {
55
56
  "prebuild": "node -e \"require('fs').rmSync('./dist', { recursive: true, force: true })\"",
56
- "build": "bun build ./src/index.ts ./src/runtime/index.ts ./src/test/index.ts ./src/vite/index.ts ./src/sveltekit/index.ts ./src/cloudflare/index.ts ./src/decorators/index.ts --outdir ./dist --splitting --target node --packages=external && tsgo --declaration --emitDeclarationOnly --noEmit false --outDir ./dist",
57
+ "build": "bun build ./src/index.ts ./src/browser.ts ./src/runtime/index.ts ./src/test/index.ts ./src/vite/index.ts ./src/sveltekit/index.ts ./src/cloudflare/index.ts ./src/decorators/index.ts --outdir ./dist --splitting --target node --packages=external && tsgo --declaration --emitDeclarationOnly --noEmit false --outDir ./dist",
57
58
  "dev": "bun --watch ./src/cli/index.ts",
58
59
  "test": "bun test",
59
60
  "test:watch": "bun test --watch",
@@ -1,3 +1,6 @@
1
+ import {
2
+ getDependencies
3
+ } from "./index-1xpj0m4r.js";
1
4
  import {
2
5
  compileConfig,
3
6
  writeWranglerConfig
@@ -5,9 +8,6 @@ import {
5
8
  import {
6
9
  loadConfig
7
10
  } from "./index-hcex3rgh.js";
8
- import {
9
- getDependencies
10
- } from "./index-1xpj0m4r.js";
11
11
  import"./index-37x76zdn.js";
12
12
 
13
13
  // src/cli/commands/build.ts
@@ -1,3 +1,6 @@
1
+ import {
2
+ getDependencies
3
+ } from "./index-1xpj0m4r.js";
1
4
  import {
2
5
  compileConfig,
3
6
  stringifyConfig,
@@ -6,9 +9,6 @@ import {
6
9
  import {
7
10
  loadConfig
8
11
  } from "./index-hcex3rgh.js";
9
- import {
10
- getDependencies
11
- } from "./index-1xpj0m4r.js";
12
12
  import"./index-37x76zdn.js";
13
13
 
14
14
  // src/cli/commands/deploy.ts
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  detectViteProject
3
3
  } from "./index-18hvb6gb.js";
4
+ import {
5
+ getDependencies
6
+ } from "./index-1xpj0m4r.js";
4
7
  import {
5
8
  loadConfig,
6
9
  resolveConfigPath
7
10
  } from "./index-hcex3rgh.js";
8
- import {
9
- getDependencies
10
- } from "./index-1xpj0m4r.js";
11
11
  import"./index-37x76zdn.js";
12
12
 
13
13
  // src/cli/commands/doctor.ts