@kuratchi/js 0.0.5 → 0.0.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.
package/dist/compiler/index.js
CHANGED
|
@@ -2609,11 +2609,10 @@ async function __runRuntimeError(ctx, error) {
|
|
|
2609
2609
|
|
|
2610
2610
|
// â"€â"€ Exported Worker entrypoint â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€â"€
|
|
2611
2611
|
|
|
2612
|
-
export default class extends WorkerEntrypoint {
|
|
2613
|
-
async fetch(request) {
|
|
2614
|
-
__setRequestContext(this.ctx, request);
|
|
2615
|
-
|
|
2616
|
-
${migrationInit ? ' await __runMigrations();\n' : ''}${authInit ? ' __initAuth(request);\n' : ''}${authPluginInit ? ' __initAuthPlugins();\n' : ''}${doResolverInit ? ' __initDoResolvers();\n' : ''}
|
|
2612
|
+
export default class extends WorkerEntrypoint {
|
|
2613
|
+
async fetch(request) {
|
|
2614
|
+
__setRequestContext(this.ctx, request, __env);
|
|
2615
|
+
${migrationInit ? ' await __runMigrations();\n' : ''}${authInit ? ' __initAuth(request);\n' : ''}${authPluginInit ? ' __initAuthPlugins();\n' : ''}${doResolverInit ? ' __initDoResolvers();\n' : ''}
|
|
2617
2616
|
const __runtimeCtx = {
|
|
2618
2617
|
request,
|
|
2619
2618
|
env: __env,
|
|
@@ -13,7 +13,7 @@ export interface BreadcrumbItem {
|
|
|
13
13
|
current?: boolean;
|
|
14
14
|
}
|
|
15
15
|
/** Called by the framework at the start of each request */
|
|
16
|
-
export declare function __setRequestContext(ctx: any, request: Request): void;
|
|
16
|
+
export declare function __setRequestContext(ctx: any, request: Request, env?: Record<string, any>): void;
|
|
17
17
|
/** Get the execution context (Worker: ExecutionContext, DO: DurableObjectState) */
|
|
18
18
|
export declare function getCtx(): any;
|
|
19
19
|
/** Get the current environment bindings */
|
package/dist/runtime/context.js
CHANGED
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
import { __getDoSelf } from './do.js';
|
|
11
11
|
let __ctx = null;
|
|
12
12
|
let __request = null;
|
|
13
|
+
let __env = null;
|
|
13
14
|
let __locals = {};
|
|
14
15
|
/** Called by the framework at the start of each request */
|
|
15
|
-
export function __setRequestContext(ctx, request) {
|
|
16
|
+
export function __setRequestContext(ctx, request, env) {
|
|
16
17
|
__ctx = ctx;
|
|
17
18
|
__request = request;
|
|
19
|
+
__env = env ?? null;
|
|
18
20
|
__locals = {};
|
|
19
21
|
// Expose context on globalThis for @kuratchi/auth and other packages
|
|
20
22
|
// Workers are single-threaded per request — this is safe
|
|
@@ -37,7 +39,9 @@ export function getEnv() {
|
|
|
37
39
|
const doSelf = __getDoSelf();
|
|
38
40
|
if (doSelf)
|
|
39
41
|
return doSelf.env;
|
|
40
|
-
|
|
42
|
+
if (!__env)
|
|
43
|
+
throw new Error('getEnv() called outside of a request context');
|
|
44
|
+
return __env;
|
|
41
45
|
}
|
|
42
46
|
/** Get the current request */
|
|
43
47
|
export function getRequest() {
|