@powerlines/plugin-cloudflare 0.2.0

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