@powerlines/plugin-cloudflare 0.6.81 → 0.6.83

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.
@@ -1,34 +1,201 @@
1
- import{createComponent as e,createIntrinsic as t,mergeProps as n}from"@alloy-js/core/jsx-runtime";import{Show as r,code as i,computed as a,splitProps as o}from"@alloy-js/core";import s from"defu";import{Spacing as c}from"@powerlines/plugin-alloy/core/components";import{usePowerlines as l}from"@powerlines/plugin-alloy/core/contexts";import{EntryFile as u}from"@powerlines/plugin-alloy/typescript/components/entry-file";import{murmurhash as d}from"@stryke/hash";import{relativePath as f}from"@stryke/path/find";import{replaceExtension as p}from"@stryke/path/replace";function m(m){let[{worker:h,children:g,imports:_,builtinImports:v},y]=o(m,[`worker`,`children`,`imports`,`builtinImports`]),b=l(),x=a(()=>`./${p(f(b.entryPath,h.metadata.entry.input?.file||h.metadata.entry.file))}`);return e(u,n({get path(){return`worker-${d(h.metadata.entry,{maxLength:8})}-entry.ts`}},y,{get imports(){return s({"@cloudflare/workers-types":[{name:`Request`,type:!0},{name:`Response`,type:!0},{name:`ExecutionContext`,type:!0},{name:`IncomingRequestCfProperties`,type:!0},{name:`ScheduledController`,type:!0},{name:`ForwardableEmailMessage`,type:!0},{name:`MessageBatch`,type:!0},{name:`TailStream`,type:!0},{name:`TraceItem`,type:!0},{name:`TailStream.TailEvent`,type:!0},{name:`TailStream.Onset`,type:!0},{name:`TailStream.TailEventHandlerType`,type:!0}],[x.value]:`worker`},_??{})},get builtinImports(){return s({cloudflare:[`withFetchContext`,`withTailContext`,`withTraceContext`,`withTailStreamContext`,`withScheduledContext`,`withTestContext`,`withEmailContext`,`withQueueContext`]},v??{})},get children(){return[i`export default { `,t(`hbr`,{}),e(r,{get when(){return h.fetch},children:i` async fetch(request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, env: CloudflareBindings, ctx: ExecutionContext): Promise<Response> {
1
+ import { createComponent, createIntrinsic, mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { Show, code, computed, splitProps } from "@alloy-js/core";
3
+ import defu from "defu";
4
+ import { Spacing } from "@powerlines/plugin-alloy/core/components";
5
+ import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts";
6
+ import { EntryFile } from "@powerlines/plugin-alloy/typescript/components/entry-file";
7
+ import { murmurhash } from "@stryke/hash";
8
+ import { relativePath } from "@stryke/path/find";
9
+ import { replaceExtension } from "@stryke/path/replace";
10
+
11
+ //#region src/components/worker-entry.tsx
12
+ /**
13
+ * Generates a [Cloudflare Worker](https://developers.cloudflare.com/workers/runtime-apis/handlers/) entry module for the Powerlines project, providing a runtime context and utilities for integrating with Cloudflare services. This module defines a `CloudflareContext` interface, an `AsyncLocalStorage` instance for managing the context, and helper functions for retrieving and running code within the context. The generated module is designed to be used as a built-in file within the Powerlines environment, allowing developers to easily access Cloudflare-specific functionality in their applications.
14
+ */
15
+ function WorkerEntry(props) {
16
+ const [{ worker, children, imports, builtinImports }, rest] = splitProps(props, [
17
+ "worker",
18
+ "children",
19
+ "imports",
20
+ "builtinImports"
21
+ ]);
22
+ const context = usePowerlines();
23
+ const entryPath = computed(() => `./${replaceExtension(relativePath(context.entryPath, worker.metadata.entry.input?.file || worker.metadata.entry.file))}`);
24
+ return createComponent(EntryFile, mergeProps({ get path() {
25
+ return `worker-${murmurhash(worker.metadata.entry, { maxLength: 8 })}-entry.ts`;
26
+ } }, rest, {
27
+ get imports() {
28
+ return defu({
29
+ "@cloudflare/workers-types": [
30
+ {
31
+ name: "Request",
32
+ type: true
33
+ },
34
+ {
35
+ name: "Response",
36
+ type: true
37
+ },
38
+ {
39
+ name: "ExecutionContext",
40
+ type: true
41
+ },
42
+ {
43
+ name: "IncomingRequestCfProperties",
44
+ type: true
45
+ },
46
+ {
47
+ name: "ScheduledController",
48
+ type: true
49
+ },
50
+ {
51
+ name: "ForwardableEmailMessage",
52
+ type: true
53
+ },
54
+ {
55
+ name: "MessageBatch",
56
+ type: true
57
+ },
58
+ {
59
+ name: "TailStream",
60
+ type: true
61
+ },
62
+ {
63
+ name: "TraceItem",
64
+ type: true
65
+ },
66
+ {
67
+ name: "TailStream.TailEvent",
68
+ type: true
69
+ },
70
+ {
71
+ name: "TailStream.Onset",
72
+ type: true
73
+ },
74
+ {
75
+ name: "TailStream.TailEventHandlerType",
76
+ type: true
77
+ }
78
+ ],
79
+ [entryPath.value]: "worker"
80
+ }, imports ?? {});
81
+ },
82
+ get builtinImports() {
83
+ return defu({ cloudflare: [
84
+ "withFetchContext",
85
+ "withTailContext",
86
+ "withTraceContext",
87
+ "withTailStreamContext",
88
+ "withScheduledContext",
89
+ "withTestContext",
90
+ "withEmailContext",
91
+ "withQueueContext"
92
+ ] }, builtinImports ?? {});
93
+ },
94
+ get children() {
95
+ return [
96
+ code`export default { `,
97
+ createIntrinsic("hbr", {}),
98
+ createComponent(Show, {
99
+ get when() {
100
+ return worker.fetch;
101
+ },
102
+ children: code` async fetch(request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, env: CloudflareBindings, ctx: ExecutionContext): Promise<Response> {
2
103
  return await withFetchContext({ request, env, ctx }, async (context) => {
3
104
  return worker.fetch(context.request, context.env, context.ctx);
4
105
  });
5
- }, `}),t(`hbr`,{}),e(r,{get when(){return h.tail},children:i` async tail(events: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
106
+ }, `
107
+ }),
108
+ createIntrinsic("hbr", {}),
109
+ createComponent(Show, {
110
+ get when() {
111
+ return worker.tail;
112
+ },
113
+ children: code` async tail(events: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
6
114
  return withTailContext({ events, env, ctx }, async (context) => {
7
115
  return worker.tail(context.events, context.env, context.ctx);
8
116
  });
9
- }, `}),t(`hbr`,{}),e(r,{get when(){return h.trace},children:i` async trace(traces: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
117
+ }, `
118
+ }),
119
+ createIntrinsic("hbr", {}),
120
+ createComponent(Show, {
121
+ get when() {
122
+ return worker.trace;
123
+ },
124
+ children: code` async trace(traces: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
10
125
  return withTraceContext({ traces, env, ctx }, async (context) => {
11
126
  return worker.trace(context.traces, context.env, context.ctx);
12
127
  });
13
- }, `}),t(`hbr`,{}),e(r,{get when(){return h.tailStream},children:i` async tailStream(event: TailStream.TailEvent<TailStream.Onset>, env: CloudflareBindings, ctx: ExecutionContext): Promise<ReadableStream> {
128
+ }, `
129
+ }),
130
+ createIntrinsic("hbr", {}),
131
+ createComponent(Show, {
132
+ get when() {
133
+ return worker.tailStream;
134
+ },
135
+ children: code` async tailStream(event: TailStream.TailEvent<TailStream.Onset>, env: CloudflareBindings, ctx: ExecutionContext): Promise<ReadableStream> {
14
136
  return await withTailStreamContext({ event, env, ctx }, async (context) => {
15
137
  return await worker.tailStream(context.event, context.env, context.ctx);
16
138
  });
17
- }, `}),t(`hbr`,{}),e(r,{get when(){return h.scheduled},children:i` async scheduled(controller: ScheduledController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
139
+ }, `
140
+ }),
141
+ createIntrinsic("hbr", {}),
142
+ createComponent(Show, {
143
+ get when() {
144
+ return worker.scheduled;
145
+ },
146
+ children: code` async scheduled(controller: ScheduledController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
18
147
  return withScheduledContext({ controller, env, ctx }, async (context) => {
19
148
  return worker.scheduled(context.controller, context.env, context.ctx);
20
149
  });
21
- }, `}),t(`hbr`,{}),e(r,{get when(){return h.test},children:i` async test(controller: TestController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
150
+ }, `
151
+ }),
152
+ createIntrinsic("hbr", {}),
153
+ createComponent(Show, {
154
+ get when() {
155
+ return worker.test;
156
+ },
157
+ children: code` async test(controller: TestController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
22
158
  return withTestContext({ controller, env, ctx }, async (context) => {
23
159
  return worker.test(context.controller, context.env, context.ctx);
24
160
  });
25
- }, `}),t(`hbr`,{}),e(r,{get when(){return h.email},children:i` async email(message: ForwardableEmailMessage, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
161
+ }, `
162
+ }),
163
+ createIntrinsic("hbr", {}),
164
+ createComponent(Show, {
165
+ get when() {
166
+ return worker.email;
167
+ },
168
+ children: code` async email(message: ForwardableEmailMessage, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
26
169
  return withEmailContext({ message, env, ctx }, async (context) => {
27
170
  return worker.email(context.message, context.env, context.ctx);
28
171
  });
29
- }, `}),t(`hbr`,{}),e(r,{get when(){return h.queue},children:i` async queue(batch: MessageBatch, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
172
+ }, `
173
+ }),
174
+ createIntrinsic("hbr", {}),
175
+ createComponent(Show, {
176
+ get when() {
177
+ return worker.queue;
178
+ },
179
+ children: code` async queue(batch: MessageBatch, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {
30
180
  return withQueueContext({ batch, env, ctx }, async (context) => {
31
181
  return worker.queue(context.batch, context.env, context.ctx);
32
182
  });
33
- }, `}),t(`hbr`,{}),i` } satisfies ExportedHandler<CloudflareBindings>; `,e(c,{}),e(r,{get when(){return!!g},children:g})]}}))}export{m as WorkerEntry};
183
+ }, `
184
+ }),
185
+ createIntrinsic("hbr", {}),
186
+ code` } satisfies ExportedHandler<CloudflareBindings>; `,
187
+ createComponent(Spacing, {}),
188
+ createComponent(Show, {
189
+ get when() {
190
+ return Boolean(children);
191
+ },
192
+ children
193
+ })
194
+ ];
195
+ }
196
+ }));
197
+ }
198
+
199
+ //#endregion
200
+ export { WorkerEntry };
34
201
  //# sourceMappingURL=worker-entry.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-entry.mjs","names":[],"sources":["../../src/components/worker-entry.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, computed, Show, splitProps } from \"@alloy-js/core\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts\";\nimport {\n EntryFile,\n EntryFileProps\n} from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { relativePath } from \"@stryke/path/find\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport defu from \"defu\";\nimport { CloudflarePluginContext, CloudflareWorkerEntryModule } from \"../types\";\n\nexport type WorkerEntryProps = Partial<EntryFileProps> &\n Omit<EntryFileProps, \"path\"> & {\n worker: CloudflareWorkerEntryModule;\n };\n\n/**\n * Generates a [Cloudflare Worker](https://developers.cloudflare.com/workers/runtime-apis/handlers/) entry module for the Powerlines project, providing a runtime context and utilities for integrating with Cloudflare services. This module defines a `CloudflareContext` interface, an `AsyncLocalStorage` instance for managing the context, and helper functions for retrieving and running code within the context. The generated module is designed to be used as a built-in file within the Powerlines environment, allowing developers to easily access Cloudflare-specific functionality in their applications.\n */\nexport function WorkerEntry(props: WorkerEntryProps) {\n const [{ worker, children, imports, builtinImports }, rest] = splitProps(\n props,\n [\"worker\", \"children\", \"imports\", \"builtinImports\"]\n );\n\n const context = usePowerlines<CloudflarePluginContext>();\n const entryPath = computed(\n () =>\n `./${replaceExtension(\n relativePath(\n context.entryPath,\n worker.metadata.entry.input?.file || worker.metadata.entry.file\n )\n )}`\n );\n\n return (\n <EntryFile\n path={`worker-${murmurhash(worker.metadata.entry, {\n maxLength: 8\n })}-entry.ts`}\n {...rest}\n imports={defu(\n {\n \"@cloudflare/workers-types\": [\n { name: \"Request\", type: true },\n { name: \"Response\", type: true },\n { name: \"ExecutionContext\", type: true },\n { name: \"IncomingRequestCfProperties\", type: true },\n { name: \"ScheduledController\", type: true },\n { name: \"ForwardableEmailMessage\", type: true },\n { name: \"MessageBatch\", type: true },\n { name: \"TailStream\", type: true },\n { name: \"TraceItem\", type: true },\n { name: \"TailStream.TailEvent\", type: true },\n { name: \"TailStream.Onset\", type: true },\n { name: \"TailStream.TailEventHandlerType\", type: true }\n ],\n [entryPath.value]: \"worker\"\n },\n imports ?? {}\n )}\n builtinImports={defu(\n {\n cloudflare: [\n \"withFetchContext\",\n \"withTailContext\",\n \"withTraceContext\",\n \"withTailStreamContext\",\n \"withScheduledContext\",\n \"withTestContext\",\n \"withEmailContext\",\n \"withQueueContext\"\n ]\n },\n builtinImports ?? {}\n )}>\n {code`export default { `}\n <hbr />\n <Show when={worker.fetch}>\n {code` async fetch(request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, env: CloudflareBindings, ctx: ExecutionContext): Promise<Response> {\n return await withFetchContext({ request, env, ctx }, async (context) => {\n return worker.fetch(context.request, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.tail}>\n {code` async tail(events: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTailContext({ events, env, ctx }, async (context) => {\n return worker.tail(context.events, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.trace}>\n {code` async trace(traces: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTraceContext({ traces, env, ctx }, async (context) => {\n return worker.trace(context.traces, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.tailStream}>\n {code` async tailStream(event: TailStream.TailEvent<TailStream.Onset>, env: CloudflareBindings, ctx: ExecutionContext): Promise<ReadableStream> {\n return await withTailStreamContext({ event, env, ctx }, async (context) => {\n return await worker.tailStream(context.event, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.scheduled}>\n {code` async scheduled(controller: ScheduledController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withScheduledContext({ controller, env, ctx }, async (context) => {\n return worker.scheduled(context.controller, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.test}>\n {code` async test(controller: TestController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTestContext({ controller, env, ctx }, async (context) => {\n return worker.test(context.controller, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.email}>\n {code` async email(message: ForwardableEmailMessage, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withEmailContext({ message, env, ctx }, async (context) => {\n return worker.email(context.message, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.queue}>\n {code` async queue(batch: MessageBatch, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withQueueContext({ batch, env, ctx }, async (context) => {\n return worker.queue(context.batch, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n {code` } satisfies ExportedHandler<CloudflareBindings>; `}\n <Spacing />\n <Show when={Boolean(children)}>{children}</Show>\n </EntryFile>\n );\n}\n"],"mappings":"ujBA+BA,SAAY,EAAgB,EAAG,CAC7B,GAAK,CAAA,CACH,SACD,WAAA,UAED,kBACC,GAAU,EAAG,EAAW,CAAA,SAAe,WAAY,UAAW,iBAAY,CAAA,CAC3E,EAAA,GAAA,CACK,EAAS,MAAmB,KAAA,EAAkB,EAAA,EAAA,UAAA,EAAA,SAAA,MAAA,OAAA,MAAA,EAAA,SAAA,MAAA,KAAA,CAAA,GAAA,CACnD,OAAO,EAAkB,EAAW,EAAA,CAClC,IAAA,MAAK,CACH,MAAO,UAAG,EAAY,EAAW,SAAA,MAAe,CACnD,UAAA,EAAA,CAAA,CAAA,YAGD,CAAA,EAAM,CACJ,IAAI,SAAA,CACF,OAAK,EAAA,CACH,4BAAY,CAAA,CACV,KAAA,UACA,KAAM,GACR,CAAA,CACA,KAAA,WACL,KAAA,KAEM,KAAA,mBACJ,KAAA,GACC,CAAK,CACH,KAAA,8BACE,KAAM,GACP,CAAC,CACJ,KAAS,sBACP,KAAA,GACC,CAAE,CACD,KAAI,0BACJ,KAAI,GACL,CAAE,CACD,KAAI,eACJ,KAAI,GACL,CAAE,CACD,KAAI,aACJ,KAAI,GACL,CAAE,CACD,KAAI,YACJ,KAAI,GACL,CAAE,CACD,KAAC,uBACD,KAAC,GACF,CAAA,CACD,KAAQ,mBACT,KAAA,GACD,CAAA,CACE,KAAA,kCACE,KAAA,GACD,CAAC,EACD,EAAI,OAAA,SACN,CAAE,GAAI,EAAA,CAAA,EAET,IAAI,gBAAK,CACP,OAAO,EAAA,CACL,WAAK,CAAA,mBAAiB,kBAAA,mBAAA,wBAAA,uBAAA,kBAAA,mBAAA,mBAAA,CACvB,CAAE,GAAI,EAAgB,CAAA,EAEzB,IAAI,UAAC,CACH,MAAE,CAAA,CAAA,oBAAmB,EAAA,MAAA,EAAA,CAAA,CAAA,EAAA,EAAA,CACnB,IAAA,MAAA,CACD,OAAK,EAAO,OAEZ,SAAW,CAAA;;;;WAKX,CAAC,CAAE,EAAA,MAAA,EAAA,CAAA,CAAA,EAAA,EAAA,CACF,IAAI,MAAA,CACF,OAAE,EAAA,MAEJ,SAAO,CAAM;;;;WAKd,CAAC,CAAA,EAAI,MAAA,EAAA,CAAA,CAAA,EAAA,EAAA,CACL,IAAK,MAAA,CACL,OAAU,EAAO,OAEhB,SAAO,CAAA;;;;WAKR,CAAA,CAAG,EAAE,MAAA,EAAA,CAAA,CAAA,EAAA,EAAA,CACL,IAAK,MAAM,CACT,OAAM,EAAM,YAEb,SAAS,CAAK;;;;WAKf,CAAA,CAAA,EAAkB,MAAU,EAAA,CAAA,CAAA,EAAA,EAAA,CAC3B,IAAC,MAAM,CACP,OAAO,EAAA,WAEP,SAAE,CAAA;;;;WAKH,CAAC,CAAC,EAAiB,MAAA,EAAW,CAAC,CAAA,EAAoB,EAAC,CACnD,IAAA,MAAO,CACL,OAAO,EAAO,MAEhB,SAAE,CAAA;;;;WAKH,CAAC,CAAA,EAAO,MAAmB,EAAA,CAAA,CAAA,EAAqB,EAAO,CACtD,IAAE,MAAO,CACP,OAAA,EAAA,OAEF,SAAI,CAAA;;;;WAKL,CAAC,CAAE,EAAc,MAAM,EAAO,CAAC,CAAA,EAAoB,EAAA,CAClD,IAAE,MAAA,CACA,OAAA,EAAA,OAEH,SAAK,CAAA;;;;WAKT,CAAA,CAAA,EAAA,MAAA,EAAA,CAAA,CAAA,CAAA,qDAAA,EAAA,EAAA,EAAA,CAAA,CAAA,EAAA,EAAA,CACH,IAAA,MAAA"}
1
+ {"version":3,"file":"worker-entry.mjs","names":[],"sources":["../../src/components/worker-entry.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, computed, Show, splitProps } from \"@alloy-js/core\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts\";\nimport {\n EntryFile,\n EntryFileProps\n} from \"@powerlines/plugin-alloy/typescript/components/entry-file\";\nimport { murmurhash } from \"@stryke/hash\";\nimport { relativePath } from \"@stryke/path/find\";\nimport { replaceExtension } from \"@stryke/path/replace\";\nimport defu from \"defu\";\nimport { CloudflarePluginContext, CloudflareWorkerEntryModule } from \"../types\";\n\nexport type WorkerEntryProps = Partial<EntryFileProps> &\n Omit<EntryFileProps, \"path\"> & {\n worker: CloudflareWorkerEntryModule;\n };\n\n/**\n * Generates a [Cloudflare Worker](https://developers.cloudflare.com/workers/runtime-apis/handlers/) entry module for the Powerlines project, providing a runtime context and utilities for integrating with Cloudflare services. This module defines a `CloudflareContext` interface, an `AsyncLocalStorage` instance for managing the context, and helper functions for retrieving and running code within the context. The generated module is designed to be used as a built-in file within the Powerlines environment, allowing developers to easily access Cloudflare-specific functionality in their applications.\n */\nexport function WorkerEntry(props: WorkerEntryProps) {\n const [{ worker, children, imports, builtinImports }, rest] = splitProps(\n props,\n [\"worker\", \"children\", \"imports\", \"builtinImports\"]\n );\n\n const context = usePowerlines<CloudflarePluginContext>();\n const entryPath = computed(\n () =>\n `./${replaceExtension(\n relativePath(\n context.entryPath,\n worker.metadata.entry.input?.file || worker.metadata.entry.file\n )\n )}`\n );\n\n return (\n <EntryFile\n path={`worker-${murmurhash(worker.metadata.entry, {\n maxLength: 8\n })}-entry.ts`}\n {...rest}\n imports={defu(\n {\n \"@cloudflare/workers-types\": [\n { name: \"Request\", type: true },\n { name: \"Response\", type: true },\n { name: \"ExecutionContext\", type: true },\n { name: \"IncomingRequestCfProperties\", type: true },\n { name: \"ScheduledController\", type: true },\n { name: \"ForwardableEmailMessage\", type: true },\n { name: \"MessageBatch\", type: true },\n { name: \"TailStream\", type: true },\n { name: \"TraceItem\", type: true },\n { name: \"TailStream.TailEvent\", type: true },\n { name: \"TailStream.Onset\", type: true },\n { name: \"TailStream.TailEventHandlerType\", type: true }\n ],\n [entryPath.value]: \"worker\"\n },\n imports ?? {}\n )}\n builtinImports={defu(\n {\n cloudflare: [\n \"withFetchContext\",\n \"withTailContext\",\n \"withTraceContext\",\n \"withTailStreamContext\",\n \"withScheduledContext\",\n \"withTestContext\",\n \"withEmailContext\",\n \"withQueueContext\"\n ]\n },\n builtinImports ?? {}\n )}>\n {code`export default { `}\n <hbr />\n <Show when={worker.fetch}>\n {code` async fetch(request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, env: CloudflareBindings, ctx: ExecutionContext): Promise<Response> {\n return await withFetchContext({ request, env, ctx }, async (context) => {\n return worker.fetch(context.request, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.tail}>\n {code` async tail(events: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTailContext({ events, env, ctx }, async (context) => {\n return worker.tail(context.events, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.trace}>\n {code` async trace(traces: TraceItem[], env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTraceContext({ traces, env, ctx }, async (context) => {\n return worker.trace(context.traces, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.tailStream}>\n {code` async tailStream(event: TailStream.TailEvent<TailStream.Onset>, env: CloudflareBindings, ctx: ExecutionContext): Promise<ReadableStream> {\n return await withTailStreamContext({ event, env, ctx }, async (context) => {\n return await worker.tailStream(context.event, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.scheduled}>\n {code` async scheduled(controller: ScheduledController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withScheduledContext({ controller, env, ctx }, async (context) => {\n return worker.scheduled(context.controller, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.test}>\n {code` async test(controller: TestController, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withTestContext({ controller, env, ctx }, async (context) => {\n return worker.test(context.controller, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.email}>\n {code` async email(message: ForwardableEmailMessage, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withEmailContext({ message, env, ctx }, async (context) => {\n return worker.email(context.message, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n <Show when={worker.queue}>\n {code` async queue(batch: MessageBatch, env: CloudflareBindings, ctx: ExecutionContext): Promise<void> {\n return withQueueContext({ batch, env, ctx }, async (context) => {\n return worker.queue(context.batch, context.env, context.ctx);\n });\n }, `}\n </Show>\n <hbr />\n {code` } satisfies ExportedHandler<CloudflareBindings>; `}\n <Spacing />\n <Show when={Boolean(children)}>{children}</Show>\n </EntryFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAY,YAAgB,OAAG;CAC7B,MAAK,CAAA,EACH,QACD,mBAED,kBACC,QAAU,WAAG,OAAW;EAAA;EAAe;EAAY;EAAW;EAAY,CAAA;CAC3E,MAAA,UAAA,eAAA;CACF,MAAO,YAAS,eAAmB,KAAA,iBAAkB,aAAA,QAAA,WAAA,OAAA,SAAA,MAAA,OAAA,QAAA,OAAA,SAAA,MAAA,KAAA,CAAA,GAAA;AACnD,QAAO,gBAAkB,WAAW,WAAA,EAClC,IAAA,OAAK;AACH,SAAO,UAAG,WAAY,OAAW,SAAA,OAAe,EACnD,WAAA;IAGD,EAAA,MAAM;EACJ,IAAI,UAAA;AACF,UAAK,KAAA;IACH,6BAAY;KAAA;MACV,MAAA;MACA,MAAM;MACR;KAAA;MACA,MAAA;MACL,MAAA;;;MAEM,MAAA;MACJ,MAAA;MACC;KAAK;MACH,MAAA;MACE,MAAM;MACP;KAAC;MACJ,MAAS;MACP,MAAA;MACC;KAAE;MACD,MAAI;MACJ,MAAI;MACL;KAAE;MACD,MAAI;MACJ,MAAI;MACL;KAAE;MACD,MAAI;MACJ,MAAI;MACL;KAAE;MACD,MAAI;MACJ,MAAI;MACL;KAAE;MACD,MAAC;MACD,MAAC;MACF;KAAA;MACD,MAAQ;MACT,MAAA;MACD;KAAA;MACE,MAAA;MACE,MAAA;MACD;KAAC;KACD,UAAI,QAAA;IACN,EAAE,WAAI,EAAA,CAAA;;EAET,IAAI,iBAAK;AACP,UAAO,KAAA,EACL,YAAK;IAAA;IAAiB;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA,EACvB,EAAE,kBAAI,EAAgB,CAAA;;EAEzB,IAAI,WAAC;AACH,UAAE;IAAA,IAAA;IAAmB,gBAAA,OAAA,EAAA,CAAA;IAAA,gBAAA,MAAA;KACnB,IAAA,OAAA;AACD,aAAK,OAAO;;KAEZ,UAAW,IAAA;;;;;KAKX,CAAC;IAAE,gBAAA,OAAA,EAAA,CAAA;IAAA,gBAAA,MAAA;KACF,IAAI,OAAA;AACF,aAAE,OAAA;;KAEJ,UAAO,IAAM;;;;;KAKd,CAAC;IAAA,gBAAI,OAAA,EAAA,CAAA;IAAA,gBAAA,MAAA;KACL,IAAK,OAAA;AACL,aAAU,OAAO;;KAEhB,UAAO,IAAA;;;;;KAKR,CAAA;IAAG,gBAAE,OAAA,EAAA,CAAA;IAAA,gBAAA,MAAA;KACL,IAAK,OAAM;AACT,aAAM,OAAM;;KAEb,UAAS,IAAK;;;;;KAKf,CAAA;IAAA,gBAAkB,OAAU,EAAA,CAAA;IAAA,gBAAA,MAAA;KAC3B,IAAC,OAAM;AACP,aAAO,OAAA;;KAEP,UAAE,IAAA;;;;;KAKH,CAAC;IAAC,gBAAiB,OAAA,EAAW,CAAC;IAAA,gBAAoB,MAAC;KACnD,IAAA,OAAO;AACL,aAAO,OAAO;;KAEhB,UAAE,IAAA;;;;;KAKH,CAAC;IAAA,gBAAO,OAAmB,EAAA,CAAA;IAAA,gBAAqB,MAAO;KACtD,IAAE,OAAO;AACP,aAAA,OAAA;;KAEF,UAAI,IAAA;;;;;KAKL,CAAC;IAAE,gBAAc,OAAM,EAAO,CAAC;IAAA,gBAAoB,MAAA;KAClD,IAAE,OAAA;AACA,aAAA,OAAA;;KAEH,UAAK,IAAA;;;;;KAKT,CAAA;IAAA,gBAAA,OAAA,EAAA,CAAA;IAAA,IAAA;IAAA,gBAAA,SAAA,EAAA,CAAA;IAAA,gBAAA,MAAA;KACH,IAAA,OAAA"}
@@ -1 +1,7 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),exports.PATH_TO_DEPLOY_CONFIG=`.wrangler/deploy/config.json`;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/helpers/constants.ts
4
+ const PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
5
+
6
+ //#endregion
7
+ exports.PATH_TO_DEPLOY_CONFIG = PATH_TO_DEPLOY_CONFIG;
@@ -1,2 +1,6 @@
1
- const e=`.wrangler/deploy/config.json`;export{e as PATH_TO_DEPLOY_CONFIG};
1
+ //#region src/helpers/constants.ts
2
+ const PATH_TO_DEPLOY_CONFIG = ".wrangler/deploy/config.json";
3
+
4
+ //#endregion
5
+ export { PATH_TO_DEPLOY_CONFIG };
2
6
  //# sourceMappingURL=constants.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","names":[],"sources":["../../src/helpers/constants.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nexport const PATH_TO_DEPLOY_CONFIG = \".wrangler/deploy/config.json\";\n"],"mappings":"AAkBA,MAAa,EAAwB"}
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../../src/helpers/constants.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nexport const PATH_TO_DEPLOY_CONFIG = \".wrangler/deploy/config.json\";\n"],"mappings":";AAkBA,MAAa,wBAAwB"}
@@ -1 +1,21 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`@stryke/path`);function t(t){for(let n of[`jsonc`,`json`,`toml`])if(t.fs.existsSync((0,e.joinPaths)(t.config.root,`wrangler.${n}`)))return(0,e.joinPaths)(t.config.root,`wrangler.${n}`)}exports.resolveWranglerConfigPath=t;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ let _stryke_path = require("@stryke/path");
4
+
5
+ //#region src/helpers/wrangler.ts
6
+ /**
7
+ * Resolves the Wrangler configuration file path by checking for allowed extensions in the specified root directory.
8
+ *
9
+ * @param context - The Cloudflare plugin context containing the configuration and file system access.
10
+ * @returns The absolute path to the found configuration file, or undefined if no file is found.
11
+ */
12
+ function resolveWranglerConfigPath(context) {
13
+ for (const extension of [
14
+ "jsonc",
15
+ "json",
16
+ "toml"
17
+ ]) if (context.fs.existsSync((0, _stryke_path.joinPaths)(context.config.root, `wrangler.${extension}`))) return (0, _stryke_path.joinPaths)(context.config.root, `wrangler.${extension}`);
18
+ }
19
+
20
+ //#endregion
21
+ exports.resolveWranglerConfigPath = resolveWranglerConfigPath;
@@ -1,2 +1,20 @@
1
- import{joinPaths as e}from"@stryke/path";function t(t){for(let n of[`jsonc`,`json`,`toml`])if(t.fs.existsSync(e(t.config.root,`wrangler.${n}`)))return e(t.config.root,`wrangler.${n}`)}export{t as resolveWranglerConfigPath};
1
+ import { joinPaths } from "@stryke/path";
2
+
3
+ //#region src/helpers/wrangler.ts
4
+ /**
5
+ * Resolves the Wrangler configuration file path by checking for allowed extensions in the specified root directory.
6
+ *
7
+ * @param context - The Cloudflare plugin context containing the configuration and file system access.
8
+ * @returns The absolute path to the found configuration file, or undefined if no file is found.
9
+ */
10
+ function resolveWranglerConfigPath(context) {
11
+ for (const extension of [
12
+ "jsonc",
13
+ "json",
14
+ "toml"
15
+ ]) if (context.fs.existsSync(joinPaths(context.config.root, `wrangler.${extension}`))) return joinPaths(context.config.root, `wrangler.${extension}`);
16
+ }
17
+
18
+ //#endregion
19
+ export { resolveWranglerConfigPath };
2
20
  //# sourceMappingURL=wrangler.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"wrangler.mjs","names":[],"sources":["../../src/helpers/wrangler.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { joinPaths } from \"@stryke/path\";\nimport { UnresolvedContext } from \"powerlines\";\n\nexport interface ResolveConfigPathOptions {\n useRedirectIfAvailable?: boolean;\n}\n\nexport interface ConfigPaths {\n /**\n * Absolute path to the actual configuration being used (possibly redirected from the user's config).\n */\n configPath: string | undefined;\n /**\n * Absolute path to the user's configuration, which may not be the same as `configPath` if it was redirected.\n */\n userConfigPath: string | undefined;\n /**\n * Absolute path to the deploy config path used\n */\n deployConfigPath: string | undefined;\n /**\n * Was a redirected config file read?\n */\n redirected: boolean;\n}\n\n/**\n * Resolves the Wrangler configuration file path by checking for allowed extensions in the specified root directory.\n *\n * @param context - The Cloudflare plugin context containing the configuration and file system access.\n * @returns The absolute path to the found configuration file, or undefined if no file is found.\n */\nexport function resolveWranglerConfigPath(\n context: UnresolvedContext\n): string | undefined {\n for (const extension of [\"jsonc\", \"json\", \"toml\"]) {\n if (\n context.fs.existsSync(\n joinPaths(context.config.root, `wrangler.${extension}`)\n )\n ) {\n return joinPaths(context.config.root, `wrangler.${extension}`);\n }\n }\n\n return undefined;\n}\n"],"mappings":"yCA0BA,SAAI,EAAA,EAAA,CACF,IAAG,IAAQ,IAAa,CAAA,QAAO,OAAA,OAAc,CAC3C,GAAA,EAAA,GAAA,WAAA,EAAA,EAAA,OAAA,KAAA,YAAA,IAAA,CAAA,CACF,OAAW,EAAU,EAAA,OAAS,KAAA,YAAA,IAAA"}
1
+ {"version":3,"file":"wrangler.mjs","names":[],"sources":["../../src/helpers/wrangler.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { joinPaths } from \"@stryke/path\";\nimport { UnresolvedContext } from \"powerlines\";\n\nexport interface ResolveConfigPathOptions {\n useRedirectIfAvailable?: boolean;\n}\n\nexport interface ConfigPaths {\n /**\n * Absolute path to the actual configuration being used (possibly redirected from the user's config).\n */\n configPath: string | undefined;\n /**\n * Absolute path to the user's configuration, which may not be the same as `configPath` if it was redirected.\n */\n userConfigPath: string | undefined;\n /**\n * Absolute path to the deploy config path used\n */\n deployConfigPath: string | undefined;\n /**\n * Was a redirected config file read?\n */\n redirected: boolean;\n}\n\n/**\n * Resolves the Wrangler configuration file path by checking for allowed extensions in the specified root directory.\n *\n * @param context - The Cloudflare plugin context containing the configuration and file system access.\n * @returns The absolute path to the found configuration file, or undefined if no file is found.\n */\nexport function resolveWranglerConfigPath(\n context: UnresolvedContext\n): string | undefined {\n for (const extension of [\"jsonc\", \"json\", \"toml\"]) {\n if (\n context.fs.existsSync(\n joinPaths(context.config.root, `wrangler.${extension}`)\n )\n ) {\n return joinPaths(context.config.root, `wrangler.${extension}`);\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAI,0BAAA,SAAA;AACF,MAAG,MAAQ,aAAa;EAAA;EAAO;EAAA;EAAc,CAC3C,KAAA,QAAA,GAAA,WAAA,UAAA,QAAA,OAAA,MAAA,YAAA,YAAA,CAAA,CACF,QAAW,UAAU,QAAA,OAAS,MAAA,YAAA,YAAA"}
package/dist/index.cjs CHANGED
@@ -1 +1,190 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./_virtual/_rolldown/runtime.cjs`),t=require(`./components/cloudflare-builtin.cjs`),n=require(`./components/env-builtin.cjs`),r=require(`./components/worker-entry.cjs`);require(`./components/index.cjs`);const i=require(`./helpers/wrangler.cjs`);let a=require(`@alloy-js/core/jsx-runtime`),o=require(`@alloy-js/core`),s=require(`@cloudflare/unenv-preset`),c=require(`@powerlines/plugin-alloy/render`),l=require(`@powerlines/plugin-env/helpers`),u=require(`@powerlines/plugin-esbuild/helpers/resolve`),d=require(`@powerlines/plugin-pulumi`);d=e.__toESM(d);let f=require(`@powerlines/plugin-unenv`);f=e.__toESM(f);let p=require(`@pulumi/cloudflare`);p=e.__toESM(p);let m=require(`@stryke/helpers/omit`),h=require(`@stryke/path`),g=require(`@stryke/string-format/kebab-case`),_=require(`@stryke/type-checks/is-function`),v=require(`defu`);v=e.__toESM(v);let y=require(`wrangler`);function b(e={}){return[(0,f.default)(e.unenv),...(0,d.default)(e.pulumi),{name:`cloudflare`,config(){return{cloudflare:(0,v.default)((0,m.omit)(e,[`unenv`,`pulumi`]),{configPath:i.resolveWranglerConfigPath(this)}),resolve:{skipNodeModulesBundle:!1},unenv:{presets:[(0,s.getCloudflarePreset)({compatibilityDate:this.config.compatibilityDate?.toString(),compatibilityFlags:[`nodejs_als`]})]}}},configResolved(){this.devDependencies[`@cloudflare/workers-types`]=`^4.20240616.0`;let e=(0,y.unstable_readConfig)({config:this.config.cloudflare?.configPath},{preserveOriginalMain:!0,hideWarnings:!0});this.cloudflare.wrangler=structuredClone(e)},async prepare(){let e=await(0,l.readEnvTypeReflection)(this,`env`);return(0,c.render)(this,[(0,a.createComponent)(t.CloudflareBuiltin,{}),(0,a.createComponent)(n.CloudflareEnvBuiltin,{reflection:e})])},build:{order:`pre`,async handler(){let e=this;return this.cloudflare??={workers:[]},this.cloudflare.workers=await Promise.all(this.entry.map(async(e,t,n)=>{if(!e.input)throw Error(`Cloudflare Worker entry "${e.file}" is missing an input file.`);let r=await(0,u.resolveModule)(this,e.input);if(!r?.default)throw Error(`Cloudflare Worker entry "${e.file}" does not export a default handler. The Powerlines Cloudflare plugin expects each Worker entry module to export a default object matching the \`ExportedHandler\` interface from "@cloudflare/workers-types".`);let i=r.metadata?.name||(0,h.replaceExtension)(e.input.file||e.file)||n.length>1?`${this.config.name}-${t}`:this.config.name;return{metadata:{name:i,pattern:`${i}.{domain}`,entry:e},fetch:(0,_.isFunction)(r.default.fetch),tail:(0,_.isFunction)(r.default.tail),trace:(0,_.isFunction)(r.default.trace),tailStream:(0,_.isFunction)(r.default.tailStream),scheduled:(0,_.isFunction)(r.default.scheduled),test:(0,_.isFunction)(r.default.test),email:(0,_.isFunction)(r.default.email),queue:(0,_.isFunction)(r.default.queue)}})),(0,c.render)(this,(0,a.createComponent)(o.For,{get each(){return e.cloudflare.workers},children:e=>(0,a.createComponent)(r.WorkerEntry,{worker:e})}))}},async deploy(){let e=process.env.CLOUDFLARE_API_TOKEN;if(!e)if(e=this.config.cloudflare.apiToken,e)this.warn("If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.");else throw Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.")},pulumi:{async deploy(){let e=process.env.CLOUDFLARE_API_TOKEN;if(!e)if(e=this.config.cloudflare.apiToken,e)this.warn("If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.");else throw Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.");await this.pulumi.setConfig(`cloudflare:apiToken`,{value:e});let t=new p.Provider(`cloudflare-provider`,{apiToken:e}),n=await p.getZone({filter:{account:{id:this.config.cloudflare.accountId},name:this.config.cloudflare.domain}},{provider:t}),r=[],i=[],a=[],o=[],s=[];for(let e of this.cloudflare.workers){let c=new p.Worker(`${this.config.organization?`${this.config.organization}.`:``}${(0,g.kebabCase)(this.config.name)===(0,g.kebabCase)(e.metadata.name)?(0,g.kebabCase)(this.config.name):`${(0,g.kebabCase)(this.config.name)}.${(0,g.kebabCase)(e.metadata.name)}`}.${(0,g.kebabCase)(this.config.mode)}.worker`,(0,v.default)({accountId:this.config.cloudflare.accountId,name:e.metadata.name,tags:[`project:${(0,g.kebabCase)(this.config.name)}`,this.config.organization?`organization:${(0,g.kebabCase)(this.config.organization)}`:void 0,this.config.mode?`mode:${(0,g.kebabCase)(this.config.mode)}`:void 0].filter(Boolean)},e.metadata),{provider:t});r.push(c);let l=new p.WorkerVersion(`${this.config.organization?`${this.config.organization}.`:``}${(0,g.kebabCase)(this.config.name)===(0,g.kebabCase)(e.metadata.name)?(0,g.kebabCase)(this.config.name):`${(0,g.kebabCase)(this.config.name)}.${(0,g.kebabCase)(e.metadata.name)}`}.${(0,g.kebabCase)(this.config.mode)}.worker-version`,(0,v.default)({accountId:this.config.cloudflare.accountId,workerId:c.id,mainModule:(0,h.joinPaths)(this.config.output.path,`index.mjs`),modules:[{name:(0,h.joinPaths)(this.config.output.path,`index.mjs`),contentType:`application/javascript+module`,contentFile:(0,h.joinPaths)(this.config.output.path,`index.mjs`)}]},e.metadata,{compatibilityDate:this.config.compatibilityDate?.cloudflare?.toString(),compatibilityFlags:[`nodejs_als`]}),{provider:t});i.push(l);let u=new p.WorkersDeployment(`${this.config.organization?`${this.config.organization}.`:``}${(0,g.kebabCase)(this.config.name)===(0,g.kebabCase)(e.metadata.name)?(0,g.kebabCase)(this.config.name):`${(0,g.kebabCase)(this.config.name)}-${(0,g.kebabCase)(e.metadata.name)}`}.${(0,g.kebabCase)(this.config.mode)}.workers-deployment`,(0,v.default)({accountId:this.config.cloudflare.accountId,zoneId:n.id,strategy:`percentage`,scriptName:c.name,versions:[{percentage:100,versionId:l.id}]}),{provider:t});a.push(u);let d=new p.WorkersRoute(`${this.config.organization?`${this.config.organization}.`:``}${(0,g.kebabCase)(this.config.name)===(0,g.kebabCase)(e.metadata.name)?(0,g.kebabCase)(this.config.name):`${(0,g.kebabCase)(this.config.name)}-${(0,g.kebabCase)(e.metadata.name)}`}.${(0,g.kebabCase)(this.config.mode)}.workers-route`,(0,v.default)({accountId:this.config.cloudflare.accountId,zoneId:n.id,pattern:e.metadata.pattern.replace(`{domain}`,this.config.cloudflare.domain).replace(`{scriptName}`,e.metadata.name).replace(`{mode}`,this.config.mode),script:c.name}),{provider:t});o.push(d);let f=new p.DnsRecord(`${this.config.organization?`${this.config.organization}.`:``}${(0,g.kebabCase)(this.config.name)===(0,g.kebabCase)(e.metadata.name)?(0,g.kebabCase)(this.config.name):`${(0,g.kebabCase)(this.config.name)}-${(0,g.kebabCase)(e.metadata.name)}`}.${(0,g.kebabCase)(this.config.mode)}.dns-record`,{name:d.pattern,type:`A`,content:`192.0.2.1`,zoneId:n.id,proxied:!0,ttl:1},{provider:t});s.push(f)}return{workers:r,workerVersions:i,workersDeployments:a,workersRoutes:o,dnsRecords:s}}}}]}exports.CloudflareBuiltin=t.CloudflareBuiltin,exports.CloudflareEnvBuiltin=n.CloudflareEnvBuiltin,exports.WorkerEntry=r.WorkerEntry,exports.default=b,exports.plugin=b;
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_components_cloudflare_builtin = require('./components/cloudflare-builtin.cjs');
4
+ const require_components_env_builtin = require('./components/env-builtin.cjs');
5
+ const require_components_worker_entry = require('./components/worker-entry.cjs');
6
+ require('./components/index.cjs');
7
+ const require_helpers_wrangler = require('./helpers/wrangler.cjs');
8
+ let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
9
+ let _alloy_js_core = require("@alloy-js/core");
10
+ let _cloudflare_unenv_preset = require("@cloudflare/unenv-preset");
11
+ let _powerlines_plugin_alloy_render = require("@powerlines/plugin-alloy/render");
12
+ let _powerlines_plugin_env_helpers = require("@powerlines/plugin-env/helpers");
13
+ let _powerlines_plugin_esbuild_helpers_resolve = require("@powerlines/plugin-esbuild/helpers/resolve");
14
+ let _powerlines_plugin_pulumi = require("@powerlines/plugin-pulumi");
15
+ _powerlines_plugin_pulumi = require_runtime.__toESM(_powerlines_plugin_pulumi);
16
+ let _powerlines_plugin_unenv = require("@powerlines/plugin-unenv");
17
+ _powerlines_plugin_unenv = require_runtime.__toESM(_powerlines_plugin_unenv);
18
+ let _pulumi_cloudflare = require("@pulumi/cloudflare");
19
+ _pulumi_cloudflare = require_runtime.__toESM(_pulumi_cloudflare);
20
+ let _stryke_helpers_omit = require("@stryke/helpers/omit");
21
+ let _stryke_path = require("@stryke/path");
22
+ let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
23
+ let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
24
+ let defu = require("defu");
25
+ defu = require_runtime.__toESM(defu);
26
+ let wrangler = require("wrangler");
27
+
28
+ //#region src/index.tsx
29
+ /**
30
+ * A Powerlines plugin to assist in developing other Powerlines plugins.
31
+ */
32
+ function plugin(options = {}) {
33
+ return [
34
+ (0, _powerlines_plugin_unenv.default)(options.unenv),
35
+ ...(0, _powerlines_plugin_pulumi.default)(options.pulumi),
36
+ {
37
+ name: "cloudflare",
38
+ config() {
39
+ return {
40
+ cloudflare: (0, defu.default)((0, _stryke_helpers_omit.omit)(options, ["unenv", "pulumi"]), { configPath: require_helpers_wrangler.resolveWranglerConfigPath(this) }),
41
+ resolve: { skipNodeModulesBundle: false },
42
+ unenv: { presets: [(0, _cloudflare_unenv_preset.getCloudflarePreset)({
43
+ compatibilityDate: this.config.compatibilityDate?.toString(),
44
+ compatibilityFlags: ["nodejs_als"]
45
+ })] }
46
+ };
47
+ },
48
+ configResolved() {
49
+ this.devDependencies["@cloudflare/workers-types"] = "^4.20240616.0";
50
+ const config = (0, wrangler.unstable_readConfig)({ config: this.config.cloudflare?.configPath }, {
51
+ preserveOriginalMain: true,
52
+ hideWarnings: true
53
+ });
54
+ this.cloudflare.wrangler = structuredClone(config);
55
+ },
56
+ async prepare() {
57
+ const result = await (0, _powerlines_plugin_env_helpers.readEnvTypeReflection)(this, "env");
58
+ return (0, _powerlines_plugin_alloy_render.render)(this, [(0, _alloy_js_core_jsx_runtime.createComponent)(require_components_cloudflare_builtin.CloudflareBuiltin, {}), (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_env_builtin.CloudflareEnvBuiltin, { reflection: result })]);
59
+ },
60
+ build: {
61
+ order: "pre",
62
+ async handler() {
63
+ const _self$ = this;
64
+ this.cloudflare ??= { workers: [] };
65
+ this.cloudflare.workers = await Promise.all(this.entry.map(async (entry, i, arr) => {
66
+ if (!entry.input) throw new Error(`Cloudflare Worker entry "${entry.file}" is missing an input file.`);
67
+ const workerModule = await (0, _powerlines_plugin_esbuild_helpers_resolve.resolveModule)(this, entry.input);
68
+ if (!workerModule?.default) throw new Error(`Cloudflare Worker entry "${entry.file}" does not export a default handler. The Powerlines Cloudflare plugin expects each Worker entry module to export a default object matching the \`ExportedHandler\` interface from "@cloudflare/workers-types".`);
69
+ const name = workerModule.metadata?.name || (0, _stryke_path.replaceExtension)(entry.input.file || entry.file) || arr.length > 1 ? `${this.config.name}-${i}` : this.config.name;
70
+ return {
71
+ metadata: {
72
+ name,
73
+ pattern: `${name}.{domain}`,
74
+ entry
75
+ },
76
+ fetch: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.fetch),
77
+ tail: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.tail),
78
+ trace: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.trace),
79
+ tailStream: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.tailStream),
80
+ scheduled: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.scheduled),
81
+ test: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.test),
82
+ email: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.email),
83
+ queue: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.queue)
84
+ };
85
+ }));
86
+ return (0, _powerlines_plugin_alloy_render.render)(this, (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.For, {
87
+ get each() {
88
+ return _self$.cloudflare.workers;
89
+ },
90
+ children: (worker) => (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_worker_entry.WorkerEntry, { worker })
91
+ }));
92
+ }
93
+ },
94
+ async deploy() {
95
+ let apiToken = process.env.CLOUDFLARE_API_TOKEN;
96
+ if (!apiToken) {
97
+ apiToken = this.config.cloudflare.apiToken;
98
+ if (apiToken) this.warn("If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.");
99
+ else throw new Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.");
100
+ }
101
+ },
102
+ pulumi: { async deploy() {
103
+ let apiToken = process.env.CLOUDFLARE_API_TOKEN;
104
+ if (!apiToken) {
105
+ apiToken = this.config.cloudflare.apiToken;
106
+ if (apiToken) this.warn("If possible, please use the `CLOUDFLARE_API_TOKEN` environment variable instead of using the `apiToken` option directly. The `apiToken` option will work; however, this is a less secure method of configuration.");
107
+ else throw new Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.");
108
+ }
109
+ await this.pulumi.setConfig("cloudflare:apiToken", { value: apiToken });
110
+ const provider = new _pulumi_cloudflare.Provider("cloudflare-provider", { apiToken });
111
+ const zone = await _pulumi_cloudflare.getZone({ filter: {
112
+ account: { id: this.config.cloudflare.accountId },
113
+ name: this.config.cloudflare.domain
114
+ } }, { provider });
115
+ const workers = [];
116
+ const workerVersions = [];
117
+ const workersDeployments = [];
118
+ const workersRoutes = [];
119
+ const dnsRecords = [];
120
+ for (const worker of this.cloudflare.workers) {
121
+ const resource = new _pulumi_cloudflare.Worker(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}.${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.worker`, (0, defu.default)({
122
+ accountId: this.config.cloudflare.accountId,
123
+ name: worker.metadata.name,
124
+ tags: [
125
+ `project:${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}`,
126
+ this.config.organization ? `organization:${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.organization)}` : void 0,
127
+ this.config.mode ? `mode:${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}` : void 0
128
+ ].filter(Boolean)
129
+ }, worker.metadata), { provider });
130
+ workers.push(resource);
131
+ const workerVersion = new _pulumi_cloudflare.WorkerVersion(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}.${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.worker-version`, (0, defu.default)({
132
+ accountId: this.config.cloudflare.accountId,
133
+ workerId: resource.id,
134
+ mainModule: (0, _stryke_path.joinPaths)(this.config.output.path, "index.mjs"),
135
+ modules: [{
136
+ name: (0, _stryke_path.joinPaths)(this.config.output.path, "index.mjs"),
137
+ contentType: "application/javascript+module",
138
+ contentFile: (0, _stryke_path.joinPaths)(this.config.output.path, "index.mjs")
139
+ }]
140
+ }, worker.metadata, {
141
+ compatibilityDate: this.config.compatibilityDate?.cloudflare?.toString(),
142
+ compatibilityFlags: ["nodejs_als"]
143
+ }), { provider });
144
+ workerVersions.push(workerVersion);
145
+ const workersDeployment = new _pulumi_cloudflare.WorkersDeployment(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}-${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.workers-deployment`, (0, defu.default)({
146
+ accountId: this.config.cloudflare.accountId,
147
+ zoneId: zone.id,
148
+ strategy: "percentage",
149
+ scriptName: resource.name,
150
+ versions: [{
151
+ percentage: 100,
152
+ versionId: workerVersion.id
153
+ }]
154
+ }), { provider });
155
+ workersDeployments.push(workersDeployment);
156
+ const workersRoute = new _pulumi_cloudflare.WorkersRoute(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}-${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.workers-route`, (0, defu.default)({
157
+ accountId: this.config.cloudflare.accountId,
158
+ zoneId: zone.id,
159
+ pattern: worker.metadata.pattern.replace("{domain}", this.config.cloudflare.domain).replace("{scriptName}", worker.metadata.name).replace("{mode}", this.config.mode),
160
+ script: resource.name
161
+ }), { provider });
162
+ workersRoutes.push(workersRoute);
163
+ const dnsRecord = new _pulumi_cloudflare.DnsRecord(`${this.config.organization ? `${this.config.organization}.` : ""}${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) === (0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name) ? (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name) : `${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.name)}-${(0, _stryke_string_format_kebab_case.kebabCase)(worker.metadata.name)}`}.${(0, _stryke_string_format_kebab_case.kebabCase)(this.config.mode)}.dns-record`, {
164
+ name: workersRoute.pattern,
165
+ type: "A",
166
+ content: "192.0.2.1",
167
+ zoneId: zone.id,
168
+ proxied: true,
169
+ ttl: 1
170
+ }, { provider });
171
+ dnsRecords.push(dnsRecord);
172
+ }
173
+ return {
174
+ workers,
175
+ workerVersions,
176
+ workersDeployments,
177
+ workersRoutes,
178
+ dnsRecords
179
+ };
180
+ } }
181
+ }
182
+ ];
183
+ }
184
+
185
+ //#endregion
186
+ exports.CloudflareBuiltin = require_components_cloudflare_builtin.CloudflareBuiltin;
187
+ exports.CloudflareEnvBuiltin = require_components_env_builtin.CloudflareEnvBuiltin;
188
+ exports.WorkerEntry = require_components_worker_entry.WorkerEntry;
189
+ exports.default = plugin;
190
+ exports.plugin = plugin;