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