@powerlines/plugin-cloudflare 0.6.32 → 0.6.33
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/components/cloudflare-builtin.cjs +846 -792
- package/dist/components/cloudflare-builtin.d.cts +1 -2
- package/dist/components/cloudflare-builtin.d.cts.map +1 -1
- package/dist/components/cloudflare-builtin.d.mts +1 -2
- package/dist/components/cloudflare-builtin.d.mts.map +1 -1
- package/dist/components/cloudflare-builtin.mjs +846 -792
- package/dist/components/cloudflare-builtin.mjs.map +1 -1
- package/dist/components/env-builtin.cjs +14 -10
- package/dist/components/env-builtin.d.cts +1 -2
- package/dist/components/env-builtin.d.cts.map +1 -1
- package/dist/components/env-builtin.d.mts +1 -2
- package/dist/components/env-builtin.d.mts.map +1 -1
- package/dist/components/env-builtin.mjs +14 -10
- package/dist/components/env-builtin.mjs.map +1 -1
- package/dist/components/worker-entry.cjs +142 -118
- package/dist/components/worker-entry.d.cts +1 -2
- package/dist/components/worker-entry.d.cts.map +1 -1
- package/dist/components/worker-entry.d.mts +1 -2
- package/dist/components/worker-entry.d.mts.map +1 -1
- package/dist/components/worker-entry.mjs +142 -118
- package/dist/components/worker-entry.mjs.map +1 -1
- package/dist/helpers/wrangler.mjs.map +1 -1
- package/dist/index.cjs +8 -5
- package/dist/index.mjs +8 -5
- package/dist/index.mjs.map +1 -1
- package/dist/types/wrangler.cjs +19 -0
- package/dist/types/wrangler.mjs +19 -0
- package/dist/types/wrangler.mjs.map +1 -1
- package/package.json +11 -11
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createComponent, createIntrinsic, mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
1
2
|
import { Show, code, splitProps } from "@alloy-js/core";
|
|
2
3
|
import defu from "defu";
|
|
3
4
|
import { FunctionDeclaration, VarDeclaration } from "@alloy-js/typescript";
|
|
@@ -5,7 +6,6 @@ import { Spacing } from "@powerlines/plugin-alloy/core/components";
|
|
|
5
6
|
import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
|
|
6
7
|
import { InterfaceDeclaration, InterfaceMember } from "@powerlines/plugin-alloy/typescript/components/interface-declaration";
|
|
7
8
|
import { TSDoc, TSDocParam, TSDocReturns } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
|
|
8
|
-
import { jsx, jsxs } from "@alloy-js/core/jsx-runtime";
|
|
9
9
|
|
|
10
10
|
//#region src/components/cloudflare-builtin.tsx
|
|
11
11
|
/**
|
|
@@ -13,847 +13,901 @@ import { jsx, jsxs } from "@alloy-js/core/jsx-runtime";
|
|
|
13
13
|
*/
|
|
14
14
|
function CloudflareBuiltin(props) {
|
|
15
15
|
const [{ imports, children }, rest] = splitProps(props, ["imports", "children"]);
|
|
16
|
-
return
|
|
16
|
+
return createComponent(BuiltinFile, mergeProps({
|
|
17
17
|
id: "cloudflare",
|
|
18
|
-
description: "A set of helpful runtime utilities for integrating Cloudflare services."
|
|
19
|
-
|
|
20
|
-
imports
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}, imports ?? {}),
|
|
73
|
-
children: [
|
|
74
|
-
/* @__PURE__ */ jsx(VarDeclaration, {
|
|
75
|
-
const: true,
|
|
76
|
-
name: "globalContextStorage",
|
|
77
|
-
initializer: code`globalThis as unknown as Record<PropertyKey, unknown>; `
|
|
78
|
-
}),
|
|
79
|
-
/* @__PURE__ */ jsx(Spacing, {}),
|
|
80
|
-
/* @__PURE__ */ jsx(Spacing, {}),
|
|
81
|
-
/* @__PURE__ */ jsxs(InterfaceDeclaration, {
|
|
82
|
-
export: true,
|
|
83
|
-
name: "CloudflareFetchContext",
|
|
84
|
-
typeParameters: [{
|
|
85
|
-
name: "Env",
|
|
86
|
-
default: "CloudflareBindings"
|
|
87
|
-
}, {
|
|
88
|
-
name: "CfHostMetadata",
|
|
89
|
-
default: "unknown"
|
|
90
|
-
}],
|
|
91
|
-
doc: "An interface representing the runtime context for Cloudflare operations, containing relevant information and utilities for performing actions within the Cloudflare environment.",
|
|
92
|
-
children: [
|
|
93
|
-
/* @__PURE__ */ jsx(InterfaceMember, {
|
|
94
|
-
name: "request",
|
|
95
|
-
type: "Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>",
|
|
96
|
-
doc: "The incoming Cloudflare request."
|
|
97
|
-
}),
|
|
98
|
-
/* @__PURE__ */ jsx(InterfaceMember, {
|
|
99
|
-
name: "env",
|
|
100
|
-
type: "Env",
|
|
101
|
-
doc: "The Cloudflare environment bindings available during runtime."
|
|
102
|
-
}),
|
|
103
|
-
/* @__PURE__ */ jsx(InterfaceMember, {
|
|
104
|
-
name: "ctx",
|
|
105
|
-
type: "ExecutionContext",
|
|
106
|
-
doc: "The Cloudflare execution context for the incoming request."
|
|
107
|
-
})
|
|
18
|
+
description: "A set of helpful runtime utilities for integrating Cloudflare services."
|
|
19
|
+
}, rest, {
|
|
20
|
+
get imports() {
|
|
21
|
+
return defu({
|
|
22
|
+
"node:async_hooks": ["AsyncLocalStorage"],
|
|
23
|
+
"@cloudflare/workers-types": [
|
|
24
|
+
{
|
|
25
|
+
name: "Request",
|
|
26
|
+
type: true
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "Response",
|
|
30
|
+
type: true
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "ExecutionContext",
|
|
34
|
+
type: true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "IncomingRequestCfProperties",
|
|
38
|
+
type: true
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "ScheduledController",
|
|
42
|
+
type: true
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "ForwardableEmailMessage",
|
|
46
|
+
type: true
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "MessageBatch",
|
|
50
|
+
type: true
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "TailStream",
|
|
54
|
+
type: true
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "TraceItem",
|
|
58
|
+
type: true
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "TailStream.TailEvent",
|
|
62
|
+
type: true
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "TailStream.Onset",
|
|
66
|
+
type: true
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "TailStream.TailEventHandlerType",
|
|
70
|
+
type: true
|
|
71
|
+
}
|
|
108
72
|
]
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
73
|
+
}, imports ?? {});
|
|
74
|
+
},
|
|
75
|
+
get children() {
|
|
76
|
+
return [
|
|
77
|
+
createComponent(VarDeclaration, {
|
|
78
|
+
"const": true,
|
|
79
|
+
name: "globalContextStorage",
|
|
80
|
+
initializer: code`globalThis as unknown as Record<PropertyKey, unknown>; `
|
|
81
|
+
}),
|
|
82
|
+
createComponent(Spacing, {}),
|
|
83
|
+
createComponent(Spacing, {}),
|
|
84
|
+
createComponent(InterfaceDeclaration, {
|
|
85
|
+
"export": true,
|
|
86
|
+
name: "CloudflareFetchContext",
|
|
87
|
+
typeParameters: [{
|
|
88
|
+
name: "Env",
|
|
89
|
+
default: "CloudflareBindings"
|
|
90
|
+
}, {
|
|
91
|
+
name: "CfHostMetadata",
|
|
92
|
+
default: "unknown"
|
|
93
|
+
}],
|
|
94
|
+
doc: "An interface representing the runtime context for Cloudflare operations, containing relevant information and utilities for performing actions within the Cloudflare environment.",
|
|
95
|
+
get children() {
|
|
96
|
+
return [
|
|
97
|
+
createComponent(InterfaceMember, {
|
|
98
|
+
name: "request",
|
|
99
|
+
type: "Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>",
|
|
100
|
+
doc: "The incoming Cloudflare request."
|
|
101
|
+
}),
|
|
102
|
+
createComponent(InterfaceMember, {
|
|
103
|
+
name: "env",
|
|
104
|
+
type: "Env",
|
|
105
|
+
doc: "The Cloudflare environment bindings available during runtime."
|
|
106
|
+
}),
|
|
107
|
+
createComponent(InterfaceMember, {
|
|
108
|
+
name: "ctx",
|
|
109
|
+
type: "ExecutionContext",
|
|
110
|
+
doc: "The Cloudflare execution context for the incoming request."
|
|
111
|
+
})
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
createIntrinsic("hbr", {}),
|
|
116
|
+
createComponent(VarDeclaration, {
|
|
117
|
+
"const": true,
|
|
118
|
+
name: "CLOUDFLARE_FETCH_CONTEXT_KEY",
|
|
119
|
+
initializer: code`Symbol.for("powerlines-cloudflare-fetch"); `
|
|
120
|
+
}),
|
|
121
|
+
createIntrinsic("hbr", {}),
|
|
122
|
+
createComponent(VarDeclaration, {
|
|
123
|
+
"export": true,
|
|
124
|
+
"const": true,
|
|
125
|
+
name: "fetchContextStorage",
|
|
126
|
+
doc: "An AsyncLocalStorage instance for managing the Cloudflare fetch context.",
|
|
127
|
+
initializer: code`(globalContextStorage[CLOUDFLARE_FETCH_CONTEXT_KEY] ??= new AsyncLocalStorage<CloudflareFetchContext>()) as AsyncLocalStorage<CloudflareFetchContext>; `
|
|
128
|
+
}),
|
|
129
|
+
createIntrinsic("hbr", {}),
|
|
130
|
+
createComponent(TSDoc, {
|
|
131
|
+
heading: "Retrieves the current Cloudflare fetch context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
132
|
+
get children() {
|
|
133
|
+
return createComponent(TSDocReturns, { children: code`The current Cloudflare fetch context.` });
|
|
134
|
+
}
|
|
135
|
+
}),
|
|
136
|
+
createComponent(FunctionDeclaration, {
|
|
137
|
+
"export": true,
|
|
138
|
+
name: "getFetchContext",
|
|
139
|
+
typeParameters: [{
|
|
140
|
+
name: "Env",
|
|
141
|
+
default: "CloudflareBindings"
|
|
142
|
+
}, {
|
|
143
|
+
name: "CfHostMetadata",
|
|
144
|
+
default: "unknown"
|
|
145
|
+
}],
|
|
146
|
+
parameters: [],
|
|
147
|
+
returnType: "CloudflareFetchContext<Env, CfHostMetadata>",
|
|
148
|
+
children: code`const context = fetchContextStorage.getStore();
|
|
142
149
|
if (!context) {
|
|
143
150
|
throw new Error("Cloudflare fetch context is not available. Ensure that you are calling this function within the scope of a Cloudflare fetch request.");
|
|
144
151
|
}
|
|
145
152
|
return context as CloudflareFetchContext<Env, CfHostMetadata>; `
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
153
|
+
}),
|
|
154
|
+
createIntrinsic("hbr", {}),
|
|
155
|
+
createComponent(TSDoc, {
|
|
156
|
+
heading: "Runs a given function within the scope of a Cloudflare fetch context. This is typically used to set up the context for handling a Cloudflare fetch request, ensuring that any code executed within the function has access to the relevant Cloudflare environment information and utilities. The provided context will be available through the `getFetchContext` function for any code executed within the callback.",
|
|
157
|
+
get children() {
|
|
158
|
+
return [
|
|
159
|
+
createComponent(TSDocParam, {
|
|
160
|
+
name: "context",
|
|
161
|
+
children: code`The Cloudflare fetch context to run the function with.`
|
|
162
|
+
}),
|
|
163
|
+
createComponent(TSDocParam, {
|
|
164
|
+
name: "callback",
|
|
165
|
+
children: code`The function to execute within the scope of the provided context.`
|
|
166
|
+
}),
|
|
167
|
+
createComponent(TSDocReturns, { children: code`The result of the executed function.` })
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
}),
|
|
171
|
+
createComponent(FunctionDeclaration, {
|
|
172
|
+
"export": true,
|
|
173
|
+
name: "withFetchContext",
|
|
174
|
+
typeParameters: [{
|
|
175
|
+
name: "Env",
|
|
176
|
+
default: "CloudflareBindings"
|
|
177
|
+
}, {
|
|
178
|
+
name: "CfHostMetadata",
|
|
179
|
+
default: "unknown"
|
|
180
|
+
}],
|
|
181
|
+
parameters: [{
|
|
152
182
|
name: "context",
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
/* @__PURE__ */ jsx(TSDocParam, {
|
|
183
|
+
type: "CloudflareFetchContext<Env, CfHostMetadata>"
|
|
184
|
+
}, {
|
|
156
185
|
name: "callback",
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
name: "
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}),
|
|
224
|
-
/* @__PURE__ */ jsx("hbr", {}),
|
|
225
|
-
/* @__PURE__ */ jsx(TSDoc, {
|
|
226
|
-
heading: "Retrieves the current Cloudflare scheduled runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
227
|
-
children: /* @__PURE__ */ jsx(TSDocReturns, { children: code`The current Cloudflare scheduled runtime context.` })
|
|
228
|
-
}),
|
|
229
|
-
/* @__PURE__ */ jsx(FunctionDeclaration, {
|
|
230
|
-
export: true,
|
|
231
|
-
name: "getScheduledContext",
|
|
232
|
-
typeParameters: [{
|
|
233
|
-
name: "Env",
|
|
234
|
-
default: "CloudflareBindings"
|
|
235
|
-
}],
|
|
236
|
-
parameters: [],
|
|
237
|
-
returnType: "CloudflareScheduledContext<Env>",
|
|
238
|
-
children: code`const context = scheduledContextStorage.getStore();
|
|
186
|
+
type: "(request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, env: Env, ctx: ExecutionContext) => Promise<Response>"
|
|
187
|
+
}],
|
|
188
|
+
returnType: "Promise<Response>",
|
|
189
|
+
children: code`return fetchContextStorage.run(context, () => callback(context.request, context.env, context.ctx)); `
|
|
190
|
+
}),
|
|
191
|
+
createComponent(Spacing, {}),
|
|
192
|
+
createComponent(Spacing, {}),
|
|
193
|
+
createComponent(InterfaceDeclaration, {
|
|
194
|
+
"export": true,
|
|
195
|
+
name: "CloudflareScheduledContext",
|
|
196
|
+
typeParameters: [{
|
|
197
|
+
name: "Env",
|
|
198
|
+
default: "CloudflareBindings"
|
|
199
|
+
}],
|
|
200
|
+
doc: "An interface representing the runtime context for Cloudflare scheduled operations, containing relevant information and utilities for performing actions within the Cloudflare environment.",
|
|
201
|
+
get children() {
|
|
202
|
+
return [
|
|
203
|
+
createComponent(InterfaceMember, {
|
|
204
|
+
name: "controller",
|
|
205
|
+
type: "ScheduledController",
|
|
206
|
+
doc: "The Cloudflare scheduled controller for the scheduled operation."
|
|
207
|
+
}),
|
|
208
|
+
createComponent(InterfaceMember, {
|
|
209
|
+
name: "env",
|
|
210
|
+
type: "Env",
|
|
211
|
+
doc: "The Cloudflare environment bindings available during runtime."
|
|
212
|
+
}),
|
|
213
|
+
createComponent(InterfaceMember, {
|
|
214
|
+
name: "ctx",
|
|
215
|
+
type: "ExecutionContext",
|
|
216
|
+
doc: "The Cloudflare execution context for the scheduled operation."
|
|
217
|
+
})
|
|
218
|
+
];
|
|
219
|
+
}
|
|
220
|
+
}),
|
|
221
|
+
createIntrinsic("hbr", {}),
|
|
222
|
+
createComponent(VarDeclaration, {
|
|
223
|
+
"const": true,
|
|
224
|
+
name: "CLOUDFLARE_SCHEDULED_CONTEXT_KEY",
|
|
225
|
+
initializer: code`Symbol.for("powerlines-cloudflare-scheduled"); `
|
|
226
|
+
}),
|
|
227
|
+
createIntrinsic("hbr", {}),
|
|
228
|
+
createComponent(VarDeclaration, {
|
|
229
|
+
"export": true,
|
|
230
|
+
"const": true,
|
|
231
|
+
name: "scheduledContextStorage",
|
|
232
|
+
doc: "An AsyncLocalStorage instance for managing the Cloudflare scheduled runtime context.",
|
|
233
|
+
initializer: code`(globalContextStorage[CLOUDFLARE_SCHEDULED_CONTEXT_KEY] ??= new AsyncLocalStorage<CloudflareScheduledContext>()) as AsyncLocalStorage<CloudflareScheduledContext>; `
|
|
234
|
+
}),
|
|
235
|
+
createIntrinsic("hbr", {}),
|
|
236
|
+
createComponent(TSDoc, {
|
|
237
|
+
heading: "Retrieves the current Cloudflare scheduled runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
238
|
+
get children() {
|
|
239
|
+
return createComponent(TSDocReturns, { children: code`The current Cloudflare scheduled runtime context.` });
|
|
240
|
+
}
|
|
241
|
+
}),
|
|
242
|
+
createComponent(FunctionDeclaration, {
|
|
243
|
+
"export": true,
|
|
244
|
+
name: "getScheduledContext",
|
|
245
|
+
typeParameters: [{
|
|
246
|
+
name: "Env",
|
|
247
|
+
default: "CloudflareBindings"
|
|
248
|
+
}],
|
|
249
|
+
parameters: [],
|
|
250
|
+
returnType: "CloudflareScheduledContext<Env>",
|
|
251
|
+
children: code`const context = scheduledContextStorage.getStore();
|
|
239
252
|
if (!context) {
|
|
240
253
|
throw new Error("Cloudflare scheduled context is not available. Ensure that you are calling this function within the scope of a Cloudflare scheduled operation.");
|
|
241
254
|
}
|
|
242
255
|
return context as CloudflareScheduledContext<Env>; `
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
256
|
+
}),
|
|
257
|
+
createIntrinsic("hbr", {}),
|
|
258
|
+
createComponent(TSDoc, {
|
|
259
|
+
heading: "Runs a given function within the scope of a Cloudflare scheduled context. This is typically used to set up the context for handling a Cloudflare scheduled operation, ensuring that any code executed within the function has access to the relevant Cloudflare environment information and utilities. The provided context will be available through the `getScheduledContext` function for any code executed within the callback.",
|
|
260
|
+
get children() {
|
|
261
|
+
return [
|
|
262
|
+
createComponent(TSDocParam, {
|
|
263
|
+
name: "context",
|
|
264
|
+
children: code`The Cloudflare scheduled context to run the function with.`
|
|
265
|
+
}),
|
|
266
|
+
createComponent(TSDocParam, {
|
|
267
|
+
name: "callback",
|
|
268
|
+
children: code`The function to execute within the scope of the provided context.`
|
|
269
|
+
}),
|
|
270
|
+
createComponent(TSDocReturns, { children: code`The result of the executed function.` })
|
|
271
|
+
];
|
|
272
|
+
}
|
|
273
|
+
}),
|
|
274
|
+
createComponent(FunctionDeclaration, {
|
|
275
|
+
"export": true,
|
|
276
|
+
name: "withScheduledContext",
|
|
277
|
+
typeParameters: [{
|
|
278
|
+
name: "Env",
|
|
279
|
+
default: "CloudflareBindings"
|
|
280
|
+
}],
|
|
281
|
+
parameters: [{
|
|
249
282
|
name: "context",
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
/* @__PURE__ */ jsx(TSDocParam, {
|
|
283
|
+
type: "CloudflareScheduledContext<Env>"
|
|
284
|
+
}, {
|
|
253
285
|
name: "callback",
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
name: "
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
heading: "Retrieves the current Cloudflare email runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
321
|
-
children: /* @__PURE__ */ jsx(TSDocReturns, { children: code`The current Cloudflare email runtime context.` })
|
|
322
|
-
}),
|
|
323
|
-
/* @__PURE__ */ jsx(FunctionDeclaration, {
|
|
324
|
-
export: true,
|
|
325
|
-
name: "getEmailContext",
|
|
326
|
-
typeParameters: [{
|
|
327
|
-
name: "Env",
|
|
328
|
-
default: "CloudflareBindings"
|
|
329
|
-
}],
|
|
330
|
-
parameters: [],
|
|
331
|
-
returnType: "CloudflareEmailContext<Env>",
|
|
332
|
-
children: code`const context = emailContextStorage.getStore();
|
|
286
|
+
type: "(ctx: CloudflareScheduledContext<Env>) => Promise<void>"
|
|
287
|
+
}],
|
|
288
|
+
returnType: "Promise<void>",
|
|
289
|
+
children: code`return scheduledContextStorage.run(context, () => callback(context)); `
|
|
290
|
+
}),
|
|
291
|
+
createComponent(Spacing, {}),
|
|
292
|
+
createComponent(Spacing, {}),
|
|
293
|
+
createComponent(InterfaceDeclaration, {
|
|
294
|
+
"export": true,
|
|
295
|
+
name: "CloudflareEmailContext",
|
|
296
|
+
typeParameters: [{
|
|
297
|
+
name: "Env",
|
|
298
|
+
default: "CloudflareBindings"
|
|
299
|
+
}],
|
|
300
|
+
doc: "An interface representing the runtime context for Cloudflare email operations, containing relevant information and utilities for performing actions within the Cloudflare environment.",
|
|
301
|
+
get children() {
|
|
302
|
+
return [
|
|
303
|
+
createComponent(InterfaceMember, {
|
|
304
|
+
name: "message",
|
|
305
|
+
type: "ForwardableEmailMessage",
|
|
306
|
+
doc: "The Cloudflare email instance for the email operation."
|
|
307
|
+
}),
|
|
308
|
+
createComponent(InterfaceMember, {
|
|
309
|
+
name: "env",
|
|
310
|
+
type: "Env",
|
|
311
|
+
doc: "The Cloudflare environment bindings available during runtime."
|
|
312
|
+
}),
|
|
313
|
+
createComponent(InterfaceMember, {
|
|
314
|
+
name: "ctx",
|
|
315
|
+
type: "ExecutionContext",
|
|
316
|
+
doc: "The Cloudflare execution context for the email operation."
|
|
317
|
+
})
|
|
318
|
+
];
|
|
319
|
+
}
|
|
320
|
+
}),
|
|
321
|
+
createIntrinsic("hbr", {}),
|
|
322
|
+
createComponent(VarDeclaration, {
|
|
323
|
+
"const": true,
|
|
324
|
+
name: "CLOUDFLARE_EMAIL_CONTEXT_KEY",
|
|
325
|
+
initializer: code`Symbol.for("powerlines-cloudflare-email"); `
|
|
326
|
+
}),
|
|
327
|
+
createIntrinsic("hbr", {}),
|
|
328
|
+
createComponent(VarDeclaration, {
|
|
329
|
+
"export": true,
|
|
330
|
+
"const": true,
|
|
331
|
+
name: "emailContextStorage",
|
|
332
|
+
doc: "An AsyncLocalStorage instance for managing the Cloudflare email runtime context.",
|
|
333
|
+
initializer: code`(globalContextStorage[CLOUDFLARE_EMAIL_CONTEXT_KEY] ??= new AsyncLocalStorage<CloudflareEmailContext>()) as AsyncLocalStorage<CloudflareEmailContext>; `
|
|
334
|
+
}),
|
|
335
|
+
createIntrinsic("hbr", {}),
|
|
336
|
+
createComponent(TSDoc, {
|
|
337
|
+
heading: "Retrieves the current Cloudflare email runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
338
|
+
get children() {
|
|
339
|
+
return createComponent(TSDocReturns, { children: code`The current Cloudflare email runtime context.` });
|
|
340
|
+
}
|
|
341
|
+
}),
|
|
342
|
+
createComponent(FunctionDeclaration, {
|
|
343
|
+
"export": true,
|
|
344
|
+
name: "getEmailContext",
|
|
345
|
+
typeParameters: [{
|
|
346
|
+
name: "Env",
|
|
347
|
+
default: "CloudflareBindings"
|
|
348
|
+
}],
|
|
349
|
+
parameters: [],
|
|
350
|
+
returnType: "CloudflareEmailContext<Env>",
|
|
351
|
+
children: code`const context = emailContextStorage.getStore();
|
|
333
352
|
if (!context) {
|
|
334
353
|
throw new Error("Cloudflare email context is not available. Ensure that you are calling this function within the scope of a Cloudflare email operation.");
|
|
335
354
|
}
|
|
336
355
|
return context as CloudflareEmailContext<Env>; `
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
356
|
+
}),
|
|
357
|
+
createIntrinsic("hbr", {}),
|
|
358
|
+
createComponent(TSDoc, {
|
|
359
|
+
heading: "Runs a given function within the scope of a Cloudflare email context. This is typically used to set up the context for handling a Cloudflare email operation, ensuring that any code executed within the function has access to the relevant Cloudflare environment information and utilities. The provided context will be available through the `getEmailContext` function for any code executed within the callback.",
|
|
360
|
+
get children() {
|
|
361
|
+
return [
|
|
362
|
+
createComponent(TSDocParam, {
|
|
363
|
+
name: "context",
|
|
364
|
+
children: code`The Cloudflare email context to run the function with.`
|
|
365
|
+
}),
|
|
366
|
+
createComponent(TSDocParam, {
|
|
367
|
+
name: "callback",
|
|
368
|
+
children: code`The function to execute within the scope of the provided context.`
|
|
369
|
+
}),
|
|
370
|
+
createComponent(TSDocReturns, { children: code`A promise that resolves with the result of the executed function.` })
|
|
371
|
+
];
|
|
372
|
+
}
|
|
373
|
+
}),
|
|
374
|
+
createComponent(FunctionDeclaration, {
|
|
375
|
+
"export": true,
|
|
376
|
+
name: "withEmailContext",
|
|
377
|
+
typeParameters: [{
|
|
378
|
+
name: "Env",
|
|
379
|
+
default: "CloudflareBindings"
|
|
380
|
+
}],
|
|
381
|
+
parameters: [{
|
|
343
382
|
name: "context",
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
/* @__PURE__ */ jsx(TSDocParam, {
|
|
383
|
+
type: "CloudflareEmailContext<Env>"
|
|
384
|
+
}, {
|
|
347
385
|
name: "callback",
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
name: "
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
/* @__PURE__ */ jsx(FunctionDeclaration, {
|
|
421
|
-
export: true,
|
|
422
|
-
name: "getQueueContext",
|
|
423
|
-
typeParameters: [{
|
|
424
|
-
name: "Message",
|
|
425
|
-
default: "unknown"
|
|
426
|
-
}, {
|
|
427
|
-
name: "Env",
|
|
428
|
-
default: "CloudflareBindings"
|
|
429
|
-
}],
|
|
430
|
-
parameters: [],
|
|
431
|
-
returnType: "CloudflareQueueContext<Message, Env>",
|
|
432
|
-
children: code`const context = queueContextStorage.getStore();
|
|
386
|
+
type: "(ctx: CloudflareEmailContext<Env>) => Promise<void>"
|
|
387
|
+
}],
|
|
388
|
+
returnType: "Promise<void>",
|
|
389
|
+
children: code`return emailContextStorage.run(context, () => callback(context)); `
|
|
390
|
+
}),
|
|
391
|
+
createComponent(Spacing, {}),
|
|
392
|
+
createComponent(Spacing, {}),
|
|
393
|
+
createComponent(InterfaceDeclaration, {
|
|
394
|
+
"export": true,
|
|
395
|
+
name: "CloudflareQueueContext",
|
|
396
|
+
typeParameters: [{
|
|
397
|
+
name: "Message",
|
|
398
|
+
default: "unknown"
|
|
399
|
+
}, {
|
|
400
|
+
name: "Env",
|
|
401
|
+
default: "CloudflareBindings"
|
|
402
|
+
}],
|
|
403
|
+
doc: "An interface representing the runtime context for Cloudflare queue operations, containing relevant information and utilities for performing actions within the Cloudflare environment.",
|
|
404
|
+
get children() {
|
|
405
|
+
return [
|
|
406
|
+
createComponent(InterfaceMember, {
|
|
407
|
+
name: "batch",
|
|
408
|
+
type: "MessageBatch<Message>",
|
|
409
|
+
doc: "The Cloudflare queue event instance for the queue operation."
|
|
410
|
+
}),
|
|
411
|
+
createComponent(InterfaceMember, {
|
|
412
|
+
name: "env",
|
|
413
|
+
type: "Env",
|
|
414
|
+
doc: "The Cloudflare environment bindings available during runtime."
|
|
415
|
+
}),
|
|
416
|
+
createComponent(InterfaceMember, {
|
|
417
|
+
name: "ctx",
|
|
418
|
+
type: "ExecutionContext",
|
|
419
|
+
doc: "The Cloudflare execution context for the queue operation."
|
|
420
|
+
})
|
|
421
|
+
];
|
|
422
|
+
}
|
|
423
|
+
}),
|
|
424
|
+
createIntrinsic("hbr", {}),
|
|
425
|
+
createComponent(VarDeclaration, {
|
|
426
|
+
"const": true,
|
|
427
|
+
name: "CLOUDFLARE_QUEUE_CONTEXT_KEY",
|
|
428
|
+
initializer: code`Symbol.for("powerlines-cloudflare-queue"); `
|
|
429
|
+
}),
|
|
430
|
+
createIntrinsic("hbr", {}),
|
|
431
|
+
createComponent(VarDeclaration, {
|
|
432
|
+
"export": true,
|
|
433
|
+
"const": true,
|
|
434
|
+
name: "queueContextStorage",
|
|
435
|
+
doc: "An AsyncLocalStorage instance for managing the Cloudflare queue runtime context.",
|
|
436
|
+
initializer: code`(globalContextStorage[CLOUDFLARE_QUEUE_CONTEXT_KEY] ??= new AsyncLocalStorage<CloudflareQueueContext>()) as AsyncLocalStorage<CloudflareQueueContext>; `
|
|
437
|
+
}),
|
|
438
|
+
createIntrinsic("hbr", {}),
|
|
439
|
+
createComponent(TSDoc, {
|
|
440
|
+
heading: "Retrieves the current Cloudflare queue runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
441
|
+
get children() {
|
|
442
|
+
return createComponent(TSDocReturns, { children: code`The current Cloudflare queue runtime context.` });
|
|
443
|
+
}
|
|
444
|
+
}),
|
|
445
|
+
createComponent(FunctionDeclaration, {
|
|
446
|
+
"export": true,
|
|
447
|
+
name: "getQueueContext",
|
|
448
|
+
typeParameters: [{
|
|
449
|
+
name: "Message",
|
|
450
|
+
default: "unknown"
|
|
451
|
+
}, {
|
|
452
|
+
name: "Env",
|
|
453
|
+
default: "CloudflareBindings"
|
|
454
|
+
}],
|
|
455
|
+
parameters: [],
|
|
456
|
+
returnType: "CloudflareQueueContext<Message, Env>",
|
|
457
|
+
children: code`const context = queueContextStorage.getStore();
|
|
433
458
|
if (!context) {
|
|
434
459
|
throw new Error("Cloudflare queue context is not available. Ensure that you are calling this function within the scope of a Cloudflare queue operation.");
|
|
435
460
|
}
|
|
436
461
|
return context as CloudflareQueueContext<Message, Env>; `
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
462
|
+
}),
|
|
463
|
+
createIntrinsic("hbr", {}),
|
|
464
|
+
createComponent(TSDoc, {
|
|
465
|
+
heading: "Runs a given function within the scope of a Cloudflare queue context. This is typically used to set up the context for handling a Cloudflare queue operation, ensuring that any code executed within the function has access to the relevant Cloudflare environment information and utilities. The provided context will be available through the `getQueueContext` function for any code executed within the callback.",
|
|
466
|
+
get children() {
|
|
467
|
+
return [
|
|
468
|
+
createComponent(TSDocParam, {
|
|
469
|
+
name: "context",
|
|
470
|
+
children: code`The Cloudflare queue context to run the function with.`
|
|
471
|
+
}),
|
|
472
|
+
createComponent(TSDocParam, {
|
|
473
|
+
name: "callback",
|
|
474
|
+
children: code`The function to execute within the scope of the provided context.`
|
|
475
|
+
}),
|
|
476
|
+
createComponent(TSDocReturns, { children: code`The result of the executed function.` })
|
|
477
|
+
];
|
|
478
|
+
}
|
|
479
|
+
}),
|
|
480
|
+
createComponent(FunctionDeclaration, {
|
|
481
|
+
"export": true,
|
|
482
|
+
name: "withQueueContext",
|
|
483
|
+
typeParameters: [{
|
|
484
|
+
name: "Message",
|
|
485
|
+
default: "unknown"
|
|
486
|
+
}, {
|
|
487
|
+
name: "Env",
|
|
488
|
+
default: "CloudflareBindings"
|
|
489
|
+
}],
|
|
490
|
+
parameters: [{
|
|
443
491
|
name: "context",
|
|
444
|
-
|
|
445
|
-
}
|
|
446
|
-
/* @__PURE__ */ jsx(TSDocParam, {
|
|
492
|
+
type: "CloudflareQueueContext<Message, Env>"
|
|
493
|
+
}, {
|
|
447
494
|
name: "callback",
|
|
448
|
-
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
name: "
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
}),
|
|
515
|
-
/* @__PURE__ */ jsx("hbr", {}),
|
|
516
|
-
/* @__PURE__ */ jsx(TSDoc, {
|
|
517
|
-
heading: "Retrieves the current Cloudflare tail runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
518
|
-
children: /* @__PURE__ */ jsx(TSDocReturns, { children: code`The current Cloudflare tail runtime context.` })
|
|
519
|
-
}),
|
|
520
|
-
/* @__PURE__ */ jsx(FunctionDeclaration, {
|
|
521
|
-
export: true,
|
|
522
|
-
name: "getTailContext",
|
|
523
|
-
typeParameters: [{
|
|
524
|
-
name: "Env",
|
|
525
|
-
default: "CloudflareBindings"
|
|
526
|
-
}],
|
|
527
|
-
parameters: [],
|
|
528
|
-
returnType: "CloudflareTailContext<Env>",
|
|
529
|
-
children: code`const context = tailContextStorage.getStore();
|
|
495
|
+
type: "(ctx: CloudflareQueueContext<Message, Env>) => Promise<void>"
|
|
496
|
+
}],
|
|
497
|
+
returnType: "Promise<void>",
|
|
498
|
+
children: code`return queueContextStorage.run(context, () => callback(context)); `
|
|
499
|
+
}),
|
|
500
|
+
createComponent(Spacing, {}),
|
|
501
|
+
createComponent(Spacing, {}),
|
|
502
|
+
createComponent(InterfaceDeclaration, {
|
|
503
|
+
"export": true,
|
|
504
|
+
name: "CloudflareTailContext",
|
|
505
|
+
typeParameters: [{
|
|
506
|
+
name: "Env",
|
|
507
|
+
default: "CloudflareBindings"
|
|
508
|
+
}],
|
|
509
|
+
doc: "An interface representing the tail context for Cloudflare tail operations, containing relevant information and utilities for performing actions within the Cloudflare environment.",
|
|
510
|
+
get children() {
|
|
511
|
+
return [
|
|
512
|
+
createComponent(InterfaceMember, {
|
|
513
|
+
name: "events",
|
|
514
|
+
type: "TraceItem[]",
|
|
515
|
+
doc: "An array of trace items representing the events in the Cloudflare tail context."
|
|
516
|
+
}),
|
|
517
|
+
createComponent(InterfaceMember, {
|
|
518
|
+
name: "env",
|
|
519
|
+
type: "Env",
|
|
520
|
+
doc: "The Cloudflare environment bindings available during runtime."
|
|
521
|
+
}),
|
|
522
|
+
createComponent(InterfaceMember, {
|
|
523
|
+
name: "ctx",
|
|
524
|
+
type: "ExecutionContext",
|
|
525
|
+
doc: "The Cloudflare execution context for the tail operation."
|
|
526
|
+
})
|
|
527
|
+
];
|
|
528
|
+
}
|
|
529
|
+
}),
|
|
530
|
+
createIntrinsic("hbr", {}),
|
|
531
|
+
createComponent(VarDeclaration, {
|
|
532
|
+
"const": true,
|
|
533
|
+
name: "CLOUDFLARE_TAIL_CONTEXT_KEY",
|
|
534
|
+
initializer: code`Symbol.for("powerlines-cloudflare-tail"); `
|
|
535
|
+
}),
|
|
536
|
+
createIntrinsic("hbr", {}),
|
|
537
|
+
createComponent(VarDeclaration, {
|
|
538
|
+
"export": true,
|
|
539
|
+
"const": true,
|
|
540
|
+
name: "tailContextStorage",
|
|
541
|
+
doc: "An AsyncLocalStorage instance for managing the Cloudflare tail runtime context.",
|
|
542
|
+
initializer: code`(globalContextStorage[CLOUDFLARE_TAIL_CONTEXT_KEY] ??= new AsyncLocalStorage<CloudflareTailContext>()) as AsyncLocalStorage<CloudflareTailContext>; `
|
|
543
|
+
}),
|
|
544
|
+
createIntrinsic("hbr", {}),
|
|
545
|
+
createComponent(TSDoc, {
|
|
546
|
+
heading: "Retrieves the current Cloudflare tail runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
547
|
+
get children() {
|
|
548
|
+
return createComponent(TSDocReturns, { children: code`The current Cloudflare tail runtime context.` });
|
|
549
|
+
}
|
|
550
|
+
}),
|
|
551
|
+
createComponent(FunctionDeclaration, {
|
|
552
|
+
"export": true,
|
|
553
|
+
name: "getTailContext",
|
|
554
|
+
typeParameters: [{
|
|
555
|
+
name: "Env",
|
|
556
|
+
default: "CloudflareBindings"
|
|
557
|
+
}],
|
|
558
|
+
parameters: [],
|
|
559
|
+
returnType: "CloudflareTailContext<Env>",
|
|
560
|
+
children: code`const context = tailContextStorage.getStore();
|
|
530
561
|
if (!context) {
|
|
531
562
|
throw new Error("Cloudflare tail context is not available. Ensure that you are calling this function within the scope of a Cloudflare tail operation.");
|
|
532
563
|
}
|
|
533
564
|
return context as CloudflareTailContext<Env>; `
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
565
|
+
}),
|
|
566
|
+
createIntrinsic("hbr", {}),
|
|
567
|
+
createComponent(TSDoc, {
|
|
568
|
+
heading: "Runs a given function within the scope of a Cloudflare tail context. This is typically used to set up the context for handling a Cloudflare tail operation, ensuring that any code executed within the function has access to the relevant Cloudflare environment information and utilities. The provided context will be available through the `getTailContext` function for any code executed within the callback.",
|
|
569
|
+
get children() {
|
|
570
|
+
return [
|
|
571
|
+
createComponent(TSDocParam, {
|
|
572
|
+
name: "context",
|
|
573
|
+
children: code`The Cloudflare tail context to run the function with.`
|
|
574
|
+
}),
|
|
575
|
+
createComponent(TSDocParam, {
|
|
576
|
+
name: "callback",
|
|
577
|
+
children: code`The function to execute within the scope of the provided context.`
|
|
578
|
+
}),
|
|
579
|
+
createComponent(TSDocReturns, { children: code`The result of the executed function.` })
|
|
580
|
+
];
|
|
581
|
+
}
|
|
582
|
+
}),
|
|
583
|
+
createComponent(FunctionDeclaration, {
|
|
584
|
+
"export": true,
|
|
585
|
+
name: "withTailContext",
|
|
586
|
+
typeParameters: [{
|
|
587
|
+
name: "Env",
|
|
588
|
+
default: "CloudflareBindings"
|
|
589
|
+
}],
|
|
590
|
+
parameters: [{
|
|
540
591
|
name: "context",
|
|
541
|
-
|
|
542
|
-
}
|
|
543
|
-
/* @__PURE__ */ jsx(TSDocParam, {
|
|
592
|
+
type: "CloudflareTailContext<Env>"
|
|
593
|
+
}, {
|
|
544
594
|
name: "callback",
|
|
545
|
-
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
name: "
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
heading: "Retrieves the current Cloudflare tail stream runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
612
|
-
children: /* @__PURE__ */ jsx(TSDocReturns, { children: code`The current Cloudflare tail stream runtime context.` })
|
|
613
|
-
}),
|
|
614
|
-
/* @__PURE__ */ jsx(FunctionDeclaration, {
|
|
615
|
-
export: true,
|
|
616
|
-
name: "getTailStreamContext",
|
|
617
|
-
typeParameters: [{
|
|
618
|
-
name: "Env",
|
|
619
|
-
default: "CloudflareBindings"
|
|
620
|
-
}],
|
|
621
|
-
parameters: [],
|
|
622
|
-
returnType: "CloudflareTailStreamContext<Env>",
|
|
623
|
-
children: code`const context = tailStreamContextStorage.getStore();
|
|
595
|
+
type: "(ctx: CloudflareTailContext<Env>) => Promise<void>"
|
|
596
|
+
}],
|
|
597
|
+
returnType: "T",
|
|
598
|
+
children: code`return tailContextStorage.run(context, () => callback(context)); `
|
|
599
|
+
}),
|
|
600
|
+
createComponent(Spacing, {}),
|
|
601
|
+
createComponent(Spacing, {}),
|
|
602
|
+
createComponent(InterfaceDeclaration, {
|
|
603
|
+
"export": true,
|
|
604
|
+
name: "CloudflareTailStreamContext",
|
|
605
|
+
typeParameters: [{
|
|
606
|
+
name: "Env",
|
|
607
|
+
default: "CloudflareBindings"
|
|
608
|
+
}],
|
|
609
|
+
doc: "An interface representing the tail context for Cloudflare tail stream operations, containing relevant information and utilities for performing actions within the Cloudflare environment.",
|
|
610
|
+
get children() {
|
|
611
|
+
return [
|
|
612
|
+
createComponent(InterfaceMember, {
|
|
613
|
+
name: "event",
|
|
614
|
+
type: "TailStream.TailEvent<TailStream.Onset>",
|
|
615
|
+
doc: "The tail event associated with the Cloudflare tail stream context."
|
|
616
|
+
}),
|
|
617
|
+
createComponent(InterfaceMember, {
|
|
618
|
+
name: "env",
|
|
619
|
+
type: "Env",
|
|
620
|
+
doc: "The Cloudflare environment bindings available during runtime."
|
|
621
|
+
}),
|
|
622
|
+
createComponent(InterfaceMember, {
|
|
623
|
+
name: "ctx",
|
|
624
|
+
type: "ExecutionContext",
|
|
625
|
+
doc: "The Cloudflare execution context for the tail stream operation."
|
|
626
|
+
})
|
|
627
|
+
];
|
|
628
|
+
}
|
|
629
|
+
}),
|
|
630
|
+
createIntrinsic("hbr", {}),
|
|
631
|
+
createComponent(VarDeclaration, {
|
|
632
|
+
"const": true,
|
|
633
|
+
name: "CLOUDFLARE_TAIL_STREAM_CONTEXT_KEY",
|
|
634
|
+
initializer: code`Symbol.for("powerlines-cloudflare-tail-stream"); `
|
|
635
|
+
}),
|
|
636
|
+
createIntrinsic("hbr", {}),
|
|
637
|
+
createComponent(VarDeclaration, {
|
|
638
|
+
"export": true,
|
|
639
|
+
"const": true,
|
|
640
|
+
name: "tailStreamContextStorage",
|
|
641
|
+
doc: "An AsyncLocalStorage instance for managing the Cloudflare tail stream runtime context.",
|
|
642
|
+
initializer: code`(globalContextStorage[CLOUDFLARE_TAIL_STREAM_CONTEXT_KEY] ??= new AsyncLocalStorage<CloudflareTailStreamContext>()) as AsyncLocalStorage<CloudflareTailStreamContext>; `
|
|
643
|
+
}),
|
|
644
|
+
createIntrinsic("hbr", {}),
|
|
645
|
+
createComponent(TSDoc, {
|
|
646
|
+
heading: "Retrieves the current Cloudflare tail stream runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
647
|
+
get children() {
|
|
648
|
+
return createComponent(TSDocReturns, { children: code`The current Cloudflare tail stream runtime context.` });
|
|
649
|
+
}
|
|
650
|
+
}),
|
|
651
|
+
createComponent(FunctionDeclaration, {
|
|
652
|
+
"export": true,
|
|
653
|
+
name: "getTailStreamContext",
|
|
654
|
+
typeParameters: [{
|
|
655
|
+
name: "Env",
|
|
656
|
+
default: "CloudflareBindings"
|
|
657
|
+
}],
|
|
658
|
+
parameters: [],
|
|
659
|
+
returnType: "CloudflareTailStreamContext<Env>",
|
|
660
|
+
children: code`const context = tailStreamContextStorage.getStore();
|
|
624
661
|
if (!context) {
|
|
625
662
|
throw new Error("Cloudflare tail stream context is not available. Ensure that you are calling this function within the scope of a Cloudflare tail stream operation.");
|
|
626
663
|
}
|
|
627
664
|
return context as CloudflareTailStreamContext<Env>; `
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
665
|
+
}),
|
|
666
|
+
createIntrinsic("hbr", {}),
|
|
667
|
+
createComponent(TSDoc, {
|
|
668
|
+
heading: "Runs a given function within the scope of a Cloudflare tail stream context. This is typically used to set up the context for handling a Cloudflare tail stream operation, ensuring that any code executed within the function has access to the relevant Cloudflare environment information and utilities. The provided context will be available through the `getTailStreamContext` function for any code executed within the callback.",
|
|
669
|
+
get children() {
|
|
670
|
+
return [
|
|
671
|
+
createComponent(TSDocParam, {
|
|
672
|
+
name: "context",
|
|
673
|
+
children: code`The Cloudflare tail stream context to run the function with.`
|
|
674
|
+
}),
|
|
675
|
+
createComponent(TSDocParam, {
|
|
676
|
+
name: "callback",
|
|
677
|
+
children: code`The function to execute within the scope of the provided context.`
|
|
678
|
+
}),
|
|
679
|
+
createComponent(TSDocReturns, { children: code`The result of the executed function.` })
|
|
680
|
+
];
|
|
681
|
+
}
|
|
682
|
+
}),
|
|
683
|
+
createComponent(FunctionDeclaration, {
|
|
684
|
+
"export": true,
|
|
685
|
+
name: "withTailStreamContext",
|
|
686
|
+
typeParameters: [{
|
|
687
|
+
name: "Env",
|
|
688
|
+
default: "CloudflareBindings"
|
|
689
|
+
}],
|
|
690
|
+
parameters: [{
|
|
634
691
|
name: "context",
|
|
635
|
-
|
|
636
|
-
}
|
|
637
|
-
/* @__PURE__ */ jsx(TSDocParam, {
|
|
692
|
+
type: "CloudflareTailStreamContext<Env>"
|
|
693
|
+
}, {
|
|
638
694
|
name: "callback",
|
|
639
|
-
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
name: "
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
heading: "Retrieves the current Cloudflare trace runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
706
|
-
children: /* @__PURE__ */ jsx(TSDocReturns, { children: code`The current Cloudflare trace runtime context.` })
|
|
707
|
-
}),
|
|
708
|
-
/* @__PURE__ */ jsx(FunctionDeclaration, {
|
|
709
|
-
export: true,
|
|
710
|
-
name: "getTraceContext",
|
|
711
|
-
typeParameters: [{
|
|
712
|
-
name: "Env",
|
|
713
|
-
default: "CloudflareBindings"
|
|
714
|
-
}],
|
|
715
|
-
parameters: [],
|
|
716
|
-
returnType: "CloudflareTraceContext<Env>",
|
|
717
|
-
children: code`const context = traceContextStorage.getStore();
|
|
695
|
+
type: "(ctx: CloudflareTailStreamContext<Env>) => Promise<TailStream.TailEventHandlerType>"
|
|
696
|
+
}],
|
|
697
|
+
returnType: "Promise<TailStream.TailEventHandlerType>",
|
|
698
|
+
children: code`return tailStreamContextStorage.run(context, () => callback(context)); `
|
|
699
|
+
}),
|
|
700
|
+
createComponent(Spacing, {}),
|
|
701
|
+
createComponent(Spacing, {}),
|
|
702
|
+
createComponent(InterfaceDeclaration, {
|
|
703
|
+
"export": true,
|
|
704
|
+
name: "CloudflareTraceContext",
|
|
705
|
+
typeParameters: [{
|
|
706
|
+
name: "Env",
|
|
707
|
+
default: "CloudflareBindings"
|
|
708
|
+
}],
|
|
709
|
+
doc: "An interface representing the trace context for Cloudflare trace operations, containing relevant information and utilities for performing actions within the Cloudflare environment.",
|
|
710
|
+
get children() {
|
|
711
|
+
return [
|
|
712
|
+
createComponent(InterfaceMember, {
|
|
713
|
+
name: "traces",
|
|
714
|
+
type: "TraceItem[]",
|
|
715
|
+
doc: "An array of trace items associated with the Cloudflare trace context."
|
|
716
|
+
}),
|
|
717
|
+
createComponent(InterfaceMember, {
|
|
718
|
+
name: "env",
|
|
719
|
+
type: "Env",
|
|
720
|
+
doc: "The Cloudflare environment bindings available during runtime."
|
|
721
|
+
}),
|
|
722
|
+
createComponent(InterfaceMember, {
|
|
723
|
+
name: "ctx",
|
|
724
|
+
type: "ExecutionContext",
|
|
725
|
+
doc: "The Cloudflare execution context for the trace operation."
|
|
726
|
+
})
|
|
727
|
+
];
|
|
728
|
+
}
|
|
729
|
+
}),
|
|
730
|
+
createIntrinsic("hbr", {}),
|
|
731
|
+
createComponent(VarDeclaration, {
|
|
732
|
+
"const": true,
|
|
733
|
+
name: "CLOUDFLARE_TRACE_CONTEXT_KEY",
|
|
734
|
+
initializer: code`Symbol.for("powerlines-cloudflare-trace"); `
|
|
735
|
+
}),
|
|
736
|
+
createIntrinsic("hbr", {}),
|
|
737
|
+
createComponent(VarDeclaration, {
|
|
738
|
+
"export": true,
|
|
739
|
+
"const": true,
|
|
740
|
+
name: "traceContextStorage",
|
|
741
|
+
doc: "An AsyncLocalStorage instance for managing the Cloudflare trace runtime context.",
|
|
742
|
+
initializer: code`(globalContextStorage[CLOUDFLARE_TRACE_CONTEXT_KEY] ??= new AsyncLocalStorage<CloudflareTraceContext>()) as AsyncLocalStorage<CloudflareTraceContext>; `
|
|
743
|
+
}),
|
|
744
|
+
createIntrinsic("hbr", {}),
|
|
745
|
+
createComponent(TSDoc, {
|
|
746
|
+
heading: "Retrieves the current Cloudflare trace runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
747
|
+
get children() {
|
|
748
|
+
return createComponent(TSDocReturns, { children: code`The current Cloudflare trace runtime context.` });
|
|
749
|
+
}
|
|
750
|
+
}),
|
|
751
|
+
createComponent(FunctionDeclaration, {
|
|
752
|
+
"export": true,
|
|
753
|
+
name: "getTraceContext",
|
|
754
|
+
typeParameters: [{
|
|
755
|
+
name: "Env",
|
|
756
|
+
default: "CloudflareBindings"
|
|
757
|
+
}],
|
|
758
|
+
parameters: [],
|
|
759
|
+
returnType: "CloudflareTraceContext<Env>",
|
|
760
|
+
children: code`const context = traceContextStorage.getStore();
|
|
718
761
|
if (!context) {
|
|
719
762
|
throw new Error("Cloudflare trace context is not available. Ensure that you are calling this function within the scope of a Cloudflare trace operation.");
|
|
720
763
|
}
|
|
721
764
|
return context as CloudflareTraceContext<Env>; `
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
765
|
+
}),
|
|
766
|
+
createIntrinsic("hbr", {}),
|
|
767
|
+
createComponent(TSDoc, {
|
|
768
|
+
heading: "Runs a given function within the scope of a Cloudflare trace context. This is typically used to set up the context for handling a Cloudflare trace operation, ensuring that any code executed within the function has access to the relevant Cloudflare environment information and utilities. The provided context will be available through the `getTraceContext` function for any code executed within the callback.",
|
|
769
|
+
get children() {
|
|
770
|
+
return [
|
|
771
|
+
createComponent(TSDocParam, {
|
|
772
|
+
name: "context",
|
|
773
|
+
children: code`The Cloudflare trace context to run the function with.`
|
|
774
|
+
}),
|
|
775
|
+
createComponent(TSDocParam, {
|
|
776
|
+
name: "callback",
|
|
777
|
+
children: code`The function to execute within the scope of the provided context.`
|
|
778
|
+
}),
|
|
779
|
+
createComponent(TSDocReturns, { children: code`The result of the executed function.` })
|
|
780
|
+
];
|
|
781
|
+
}
|
|
782
|
+
}),
|
|
783
|
+
createComponent(FunctionDeclaration, {
|
|
784
|
+
"export": true,
|
|
785
|
+
name: "withTraceContext",
|
|
786
|
+
typeParameters: [{
|
|
787
|
+
name: "Env",
|
|
788
|
+
default: "CloudflareBindings"
|
|
789
|
+
}],
|
|
790
|
+
parameters: [{
|
|
728
791
|
name: "context",
|
|
729
|
-
|
|
730
|
-
}
|
|
731
|
-
/* @__PURE__ */ jsx(TSDocParam, {
|
|
792
|
+
type: "CloudflareTraceContext<Env>"
|
|
793
|
+
}, {
|
|
732
794
|
name: "callback",
|
|
733
|
-
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
name: "
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
heading: "Retrieves the current Cloudflare test runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
800
|
-
children: /* @__PURE__ */ jsx(TSDocReturns, { children: code`The current Cloudflare test runtime context.` })
|
|
801
|
-
}),
|
|
802
|
-
/* @__PURE__ */ jsx(FunctionDeclaration, {
|
|
803
|
-
export: true,
|
|
804
|
-
name: "getTestContext",
|
|
805
|
-
typeParameters: [{
|
|
806
|
-
name: "Env",
|
|
807
|
-
default: "CloudflareBindings"
|
|
808
|
-
}],
|
|
809
|
-
parameters: [],
|
|
810
|
-
returnType: "CloudflareTestContext<Env>",
|
|
811
|
-
children: code`const context = testContextStorage.getStore();
|
|
795
|
+
type: "(ctx: CloudflareTraceContext<Env>) => Promise<void>"
|
|
796
|
+
}],
|
|
797
|
+
returnType: "Promise<void>",
|
|
798
|
+
children: code`return traceContextStorage.run(context, () => callback(context)); `
|
|
799
|
+
}),
|
|
800
|
+
createComponent(Spacing, {}),
|
|
801
|
+
createComponent(Spacing, {}),
|
|
802
|
+
createComponent(InterfaceDeclaration, {
|
|
803
|
+
"export": true,
|
|
804
|
+
name: "CloudflareTestContext",
|
|
805
|
+
typeParameters: [{
|
|
806
|
+
name: "Env",
|
|
807
|
+
default: "CloudflareBindings"
|
|
808
|
+
}],
|
|
809
|
+
doc: "An interface representing the test context for Cloudflare trace operations, containing relevant information and utilities for performing actions within the Cloudflare environment.",
|
|
810
|
+
get children() {
|
|
811
|
+
return [
|
|
812
|
+
createComponent(InterfaceMember, {
|
|
813
|
+
name: "controller",
|
|
814
|
+
type: "TestController",
|
|
815
|
+
doc: "The test controller associated with the Cloudflare test context."
|
|
816
|
+
}),
|
|
817
|
+
createComponent(InterfaceMember, {
|
|
818
|
+
name: "env",
|
|
819
|
+
type: "Env",
|
|
820
|
+
doc: "The Cloudflare environment bindings available during runtime."
|
|
821
|
+
}),
|
|
822
|
+
createComponent(InterfaceMember, {
|
|
823
|
+
name: "ctx",
|
|
824
|
+
type: "ExecutionContext",
|
|
825
|
+
doc: "The Cloudflare execution context for the test operation."
|
|
826
|
+
})
|
|
827
|
+
];
|
|
828
|
+
}
|
|
829
|
+
}),
|
|
830
|
+
createIntrinsic("hbr", {}),
|
|
831
|
+
createComponent(VarDeclaration, {
|
|
832
|
+
"const": true,
|
|
833
|
+
name: "CLOUDFLARE_TEST_CONTEXT_KEY",
|
|
834
|
+
initializer: code`Symbol.for("powerlines-cloudflare-test"); `
|
|
835
|
+
}),
|
|
836
|
+
createIntrinsic("hbr", {}),
|
|
837
|
+
createComponent(VarDeclaration, {
|
|
838
|
+
"export": true,
|
|
839
|
+
"const": true,
|
|
840
|
+
name: "testContextStorage",
|
|
841
|
+
doc: "An AsyncLocalStorage instance for managing the Cloudflare test runtime context.",
|
|
842
|
+
initializer: code`(globalContextStorage[CLOUDFLARE_TEST_CONTEXT_KEY] ??= new AsyncLocalStorage<CloudflareTestContext>()) as AsyncLocalStorage<CloudflareTestContext>; `
|
|
843
|
+
}),
|
|
844
|
+
createIntrinsic("hbr", {}),
|
|
845
|
+
createComponent(TSDoc, {
|
|
846
|
+
heading: "Retrieves the current Cloudflare test runtime context from the AsyncLocalStorage. This context contains relevant information and utilities for performing actions within the Cloudflare environment. If no context is currently set, this function will throw an error.",
|
|
847
|
+
get children() {
|
|
848
|
+
return createComponent(TSDocReturns, { children: code`The current Cloudflare test runtime context.` });
|
|
849
|
+
}
|
|
850
|
+
}),
|
|
851
|
+
createComponent(FunctionDeclaration, {
|
|
852
|
+
"export": true,
|
|
853
|
+
name: "getTestContext",
|
|
854
|
+
typeParameters: [{
|
|
855
|
+
name: "Env",
|
|
856
|
+
default: "CloudflareBindings"
|
|
857
|
+
}],
|
|
858
|
+
parameters: [],
|
|
859
|
+
returnType: "CloudflareTestContext<Env>",
|
|
860
|
+
children: code`const context = testContextStorage.getStore();
|
|
812
861
|
if (!context) {
|
|
813
862
|
throw new Error("Cloudflare test context is not available. Ensure that you are calling this function within the scope of a Cloudflare test operation.");
|
|
814
863
|
}
|
|
815
864
|
return context as CloudflareTestContext<Env>; `
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
865
|
+
}),
|
|
866
|
+
createIntrinsic("hbr", {}),
|
|
867
|
+
createComponent(TSDoc, {
|
|
868
|
+
heading: "Runs a given function within the scope of a Cloudflare test context. This is typically used to set up the context for handling a Cloudflare test operation, ensuring that any code executed within the function has access to the relevant Cloudflare environment information and utilities. The provided context will be available through the `getTestContext` function for any code executed within the callback.",
|
|
869
|
+
get children() {
|
|
870
|
+
return [
|
|
871
|
+
createComponent(TSDocParam, {
|
|
872
|
+
name: "context",
|
|
873
|
+
children: code`The Cloudflare test context to run the function with.`
|
|
874
|
+
}),
|
|
875
|
+
createComponent(TSDocParam, {
|
|
876
|
+
name: "callback",
|
|
877
|
+
children: code`The function to execute within the scope of the provided context.`
|
|
878
|
+
}),
|
|
879
|
+
createComponent(TSDocReturns, { children: code`The result of the executed function.` })
|
|
880
|
+
];
|
|
881
|
+
}
|
|
882
|
+
}),
|
|
883
|
+
createComponent(FunctionDeclaration, {
|
|
884
|
+
"export": true,
|
|
885
|
+
name: "withTestContext",
|
|
886
|
+
typeParameters: [{
|
|
887
|
+
name: "Env",
|
|
888
|
+
default: "CloudflareBindings"
|
|
889
|
+
}],
|
|
890
|
+
parameters: [{
|
|
822
891
|
name: "context",
|
|
823
|
-
|
|
824
|
-
}
|
|
825
|
-
/* @__PURE__ */ jsx(TSDocParam, {
|
|
892
|
+
type: "CloudflareTestContext<Env>"
|
|
893
|
+
}, {
|
|
826
894
|
name: "callback",
|
|
827
|
-
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
name: "callback",
|
|
844
|
-
type: "(ctx: CloudflareTestContext<Env>) => Promise<void>"
|
|
845
|
-
}],
|
|
846
|
-
returnType: "Promise<void>",
|
|
847
|
-
children: code`return testContextStorage.run(context, () => callback(context)); `
|
|
848
|
-
}),
|
|
849
|
-
/* @__PURE__ */ jsx(Spacing, {}),
|
|
850
|
-
/* @__PURE__ */ jsx(Spacing, {}),
|
|
851
|
-
/* @__PURE__ */ jsx(Show, {
|
|
852
|
-
when: Boolean(children),
|
|
853
|
-
children
|
|
854
|
-
})
|
|
855
|
-
]
|
|
856
|
-
});
|
|
895
|
+
type: "(ctx: CloudflareTestContext<Env>) => Promise<void>"
|
|
896
|
+
}],
|
|
897
|
+
returnType: "Promise<void>",
|
|
898
|
+
children: code`return testContextStorage.run(context, () => callback(context)); `
|
|
899
|
+
}),
|
|
900
|
+
createComponent(Spacing, {}),
|
|
901
|
+
createComponent(Spacing, {}),
|
|
902
|
+
createComponent(Show, {
|
|
903
|
+
get when() {
|
|
904
|
+
return Boolean(children);
|
|
905
|
+
},
|
|
906
|
+
children
|
|
907
|
+
})
|
|
908
|
+
];
|
|
909
|
+
}
|
|
910
|
+
}));
|
|
857
911
|
}
|
|
858
912
|
|
|
859
913
|
//#endregion
|