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