@powerlines/plugin-cloudflare 0.5.2 → 0.5.4
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/package.json +8 -8
- package/dist/_virtual/_rolldown/runtime.cjs +0 -29
- package/dist/_virtual/_rolldown/runtime.mjs +0 -3
- package/dist/components/cloudflare-builtin.cjs +0 -917
- package/dist/components/cloudflare-builtin.d.cts +0 -13
- package/dist/components/cloudflare-builtin.d.cts.map +0 -1
- package/dist/components/cloudflare-builtin.d.mts +0 -13
- package/dist/components/cloudflare-builtin.d.mts.map +0 -1
- package/dist/components/cloudflare-builtin.mjs +0 -915
- package/dist/components/cloudflare-builtin.mjs.map +0 -1
- package/dist/components/env-builtin.cjs +0 -32
- package/dist/components/env-builtin.d.cts +0 -13
- package/dist/components/env-builtin.d.cts.map +0 -1
- package/dist/components/env-builtin.d.mts +0 -13
- package/dist/components/env-builtin.d.mts.map +0 -1
- package/dist/components/env-builtin.mjs +0 -30
- package/dist/components/env-builtin.mjs.map +0 -1
- package/dist/components/index.cjs +0 -8
- package/dist/components/index.d.cts +0 -4
- package/dist/components/index.d.mts +0 -4
- package/dist/components/index.mjs +0 -5
- package/dist/components/worker-entry.cjs +0 -203
- package/dist/components/worker-entry.d.cts +0 -16
- package/dist/components/worker-entry.d.cts.map +0 -1
- package/dist/components/worker-entry.d.mts +0 -16
- package/dist/components/worker-entry.d.mts.map +0 -1
- package/dist/components/worker-entry.mjs +0 -201
- package/dist/components/worker-entry.mjs.map +0 -1
- package/dist/index.cjs +0 -138
- package/dist/index.d.cts +0 -20
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -20
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -130
- package/dist/index.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@cloudflare_unenv-preset@2.15.0_unenv@2.0.0-rc.24/node_modules/@cloudflare/unenv-preset/dist/index.cjs +0 -370
- package/dist/node_modules/.pnpm/@cloudflare_unenv-preset@2.15.0_unenv@2.0.0-rc.24/node_modules/@cloudflare/unenv-preset/dist/index.mjs +0 -367
- package/dist/node_modules/.pnpm/@cloudflare_unenv-preset@2.15.0_unenv@2.0.0-rc.24/node_modules/@cloudflare/unenv-preset/dist/index.mjs.map +0 -1
- package/dist/types/index.cjs +0 -0
- package/dist/types/index.d.cts +0 -3
- package/dist/types/index.d.mts +0 -3
- package/dist/types/index.mjs +0 -1
- package/dist/types/plugin.cjs +0 -0
- package/dist/types/plugin.d.cts +0 -76
- package/dist/types/plugin.d.cts.map +0 -1
- package/dist/types/plugin.d.mts +0 -76
- package/dist/types/plugin.d.mts.map +0 -1
- package/dist/types/plugin.mjs +0 -1
- package/dist/types/worker-module.cjs +0 -0
- package/dist/types/worker-module.d.cts +0 -35
- package/dist/types/worker-module.d.cts.map +0 -1
- package/dist/types/worker-module.d.mts +0 -35
- package/dist/types/worker-module.d.mts.map +0 -1
- package/dist/types/worker-module.mjs +0 -1
|
@@ -1,201 +0,0 @@
|
|
|
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.entry.input?.file || worker.entry.file))}`);
|
|
24
|
-
return createComponent(EntryFile, mergeProps({ get path() {
|
|
25
|
-
return `worker-${murmurhash(worker.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> {
|
|
103
|
-
return await withFetchContext({ request, env, ctx }, async (context) => {
|
|
104
|
-
return worker.fetch(context.request, context.env, context.ctx);
|
|
105
|
-
});
|
|
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> {
|
|
114
|
-
return withTailContext({ events, env, ctx }, async (context) => {
|
|
115
|
-
return worker.tail(context.events, context.env, context.ctx);
|
|
116
|
-
});
|
|
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> {
|
|
125
|
-
return withTraceContext({ traces, env, ctx }, async (context) => {
|
|
126
|
-
return worker.trace(context.traces, context.env, context.ctx);
|
|
127
|
-
});
|
|
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> {
|
|
136
|
-
return await withTailStreamContext({ event, env, ctx }, async (context) => {
|
|
137
|
-
return await worker.tailStream(context.event, context.env, context.ctx);
|
|
138
|
-
});
|
|
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> {
|
|
147
|
-
return withScheduledContext({ controller, env, ctx }, async (context) => {
|
|
148
|
-
return worker.scheduled(context.controller, context.env, context.ctx);
|
|
149
|
-
});
|
|
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> {
|
|
158
|
-
return withTestContext({ controller, env, ctx }, async (context) => {
|
|
159
|
-
return worker.test(context.controller, context.env, context.ctx);
|
|
160
|
-
});
|
|
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> {
|
|
169
|
-
return withEmailContext({ message, env, ctx }, async (context) => {
|
|
170
|
-
return worker.email(context.message, context.env, context.ctx);
|
|
171
|
-
});
|
|
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> {
|
|
180
|
-
return withQueueContext({ batch, env, ctx }, async (context) => {
|
|
181
|
-
return worker.queue(context.batch, context.env, context.ctx);
|
|
182
|
-
});
|
|
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 };
|
|
201
|
-
//# sourceMappingURL=worker-entry.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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.entry.input?.file || worker.entry.file\n )\n )}`\n );\n\n return (\n <EntryFile\n path={`worker-${murmurhash(worker.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":";;;;;;;;;;;;;;;CAoCE,MAAA,CAAA,EACC,QACD,UACF,SACE,kBACE,QAAK,WAAA,OAAA;EAAA;EAAA;EAAA;EAAA;EAAA,CAAA;CACP,MAAI,UAAU,eAAsC;CACpD,MAAC,YAAA,eAAA,KAAA,iBAAA,aAAA,QAAA,WAAA,OAAA,MAAA,OAAA,QAAA,OAAA,MAAA,KAAA,CAAA,GAAA;gDAED,IAAM,OAAO;AACb,SAAM,UAAY,WAAQ,OAAA,OAAA,EACpB,WAAA,GACD,CAAC,CAAC;IAEN,EAAE,MAAK;EACN,IAAI,UAAS;AACX,UAAE,KAAA;IACA,6BAAA;KAAA;MACL,MAAA;;MAEM;KAAA;MACJ,MA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A,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,OAAG;AACR,aAAS,OAAA;;KAEV,UAAS,IAAA"}
|
package/dist/index.cjs
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_index = require('./node_modules/.pnpm/@cloudflare_unenv-preset@2.15.0_unenv@2.0.0-rc.24/node_modules/@cloudflare/unenv-preset/dist/index.cjs');
|
|
4
|
-
const require_components_cloudflare_builtin = require('./components/cloudflare-builtin.cjs');
|
|
5
|
-
const require_components_env_builtin = require('./components/env-builtin.cjs');
|
|
6
|
-
const require_components_worker_entry = require('./components/worker-entry.cjs');
|
|
7
|
-
require('./components/index.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 _powerlines_plugin_alloy_render = require("@powerlines/plugin-alloy/render");
|
|
11
|
-
let _powerlines_plugin_env_helpers = require("@powerlines/plugin-env/helpers");
|
|
12
|
-
let _powerlines_plugin_esbuild_helpers_resolve = require("@powerlines/plugin-esbuild/helpers/resolve");
|
|
13
|
-
let _powerlines_plugin_unenv = require("@powerlines/plugin-unenv");
|
|
14
|
-
_powerlines_plugin_unenv = require_runtime.__toESM(_powerlines_plugin_unenv);
|
|
15
|
-
let _pulumi_cloudflare = require("@pulumi/cloudflare");
|
|
16
|
-
_pulumi_cloudflare = require_runtime.__toESM(_pulumi_cloudflare);
|
|
17
|
-
let _stryke_helpers_omit = require("@stryke/helpers/omit");
|
|
18
|
-
let _stryke_path = require("@stryke/path");
|
|
19
|
-
let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
|
|
20
|
-
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
21
|
-
let defu = require("defu");
|
|
22
|
-
defu = require_runtime.__toESM(defu);
|
|
23
|
-
|
|
24
|
-
//#region src/index.tsx
|
|
25
|
-
/**
|
|
26
|
-
* A Powerlines plugin to assist in developing other Powerlines plugins.
|
|
27
|
-
*/
|
|
28
|
-
function plugin(options = {}) {
|
|
29
|
-
return [(0, _powerlines_plugin_unenv.default)(options.unenv), {
|
|
30
|
-
name: "cloudflare",
|
|
31
|
-
config() {
|
|
32
|
-
return {
|
|
33
|
-
cloudflare: (0, defu.default)((0, _stryke_helpers_omit.omit)(options, ["unenv"]), {}),
|
|
34
|
-
resolve: { skipNodeModulesBundle: false },
|
|
35
|
-
unenv: { presets: [require_index.getCloudflarePreset({
|
|
36
|
-
compatibilityDate: this.config.compatibilityDate?.toString(),
|
|
37
|
-
compatibilityFlags: ["nodejs_als"]
|
|
38
|
-
})] }
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
configResolved() {
|
|
42
|
-
this.devDependencies["@cloudflare/workers-types"] = "^4.20240616.0";
|
|
43
|
-
},
|
|
44
|
-
async prepare() {
|
|
45
|
-
const result = await (0, _powerlines_plugin_env_helpers.readEnvTypeReflection)(this, "env");
|
|
46
|
-
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 })]);
|
|
47
|
-
},
|
|
48
|
-
build: {
|
|
49
|
-
order: "pre",
|
|
50
|
-
async handler() {
|
|
51
|
-
const _self$ = this;
|
|
52
|
-
this.workers = await Promise.all(this.entry.map(async (entry, i, arr) => {
|
|
53
|
-
if (!entry.input) throw new Error(`Cloudflare Worker entry "${entry.file}" is missing an input file.`);
|
|
54
|
-
const workerModule = await (0, _powerlines_plugin_esbuild_helpers_resolve.resolveModule)(this, entry.input);
|
|
55
|
-
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".`);
|
|
56
|
-
const name = workerModule.metadata?.name || (0, _stryke_path.replaceExtension)(entry.input.file || entry.file) || arr.length > 1 ? `${this.config.name}-${i}` : this.config.name;
|
|
57
|
-
return {
|
|
58
|
-
metadata: {
|
|
59
|
-
name,
|
|
60
|
-
pattern: `${name}.{domain}`,
|
|
61
|
-
entry
|
|
62
|
-
},
|
|
63
|
-
fetch: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.fetch),
|
|
64
|
-
tail: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.tail),
|
|
65
|
-
trace: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.trace),
|
|
66
|
-
tailStream: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.tailStream),
|
|
67
|
-
scheduled: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.scheduled),
|
|
68
|
-
test: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.test),
|
|
69
|
-
email: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.email),
|
|
70
|
-
queue: (0, _stryke_type_checks_is_function.isFunction)(workerModule.default.queue)
|
|
71
|
-
};
|
|
72
|
-
}));
|
|
73
|
-
return (0, _powerlines_plugin_alloy_render.render)(this, (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.For, {
|
|
74
|
-
get each() {
|
|
75
|
-
return _self$.workers;
|
|
76
|
-
},
|
|
77
|
-
children: (worker) => (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_worker_entry.WorkerEntry, { worker })
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
async deployPulumi() {
|
|
82
|
-
let apiToken = process.env.CLOUDFLARE_API_TOKEN;
|
|
83
|
-
if (!apiToken) {
|
|
84
|
-
apiToken = this.config.cloudflare.apiToken;
|
|
85
|
-
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.");
|
|
86
|
-
else throw new Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.");
|
|
87
|
-
}
|
|
88
|
-
await this.pulumi.setConfig("cloudflare:apiToken", { value: apiToken });
|
|
89
|
-
const provider = new _pulumi_cloudflare.Provider("cloudflare-provider", { apiToken });
|
|
90
|
-
const zone = await _pulumi_cloudflare.getZone({ filter: {
|
|
91
|
-
account: { id: this.config.cloudflare.accountId },
|
|
92
|
-
name: this.config.cloudflare.domain
|
|
93
|
-
} }, { provider });
|
|
94
|
-
const workerScripts = [];
|
|
95
|
-
const workerRoutes = [];
|
|
96
|
-
const dnsRecords = [];
|
|
97
|
-
for (const worker of this.workers) {
|
|
98
|
-
const workerScript = new _pulumi_cloudflare.WorkersScript(`${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-script`, (0, defu.default)({
|
|
99
|
-
accountId: this.config.cloudflare.accountId,
|
|
100
|
-
scriptName: worker.metadata.name,
|
|
101
|
-
contentFile: (0, _stryke_path.joinPaths)(this.config.output.publishPath, "index.js"),
|
|
102
|
-
module: true
|
|
103
|
-
}, worker.metadata, {
|
|
104
|
-
compatibilityDate: this.config.compatibilityDate?.cloudflare?.toString(),
|
|
105
|
-
compatibilityFlags: ["nodejs_als"]
|
|
106
|
-
}), { provider });
|
|
107
|
-
workerScripts.push(workerScript);
|
|
108
|
-
const workerRoute = 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)}.worker-route`, (0, defu.default)({
|
|
109
|
-
zoneId: zone.id,
|
|
110
|
-
pattern: worker.metadata.pattern.replace("{domain}", this.config.cloudflare.domain),
|
|
111
|
-
script: workerScript.scriptName
|
|
112
|
-
}, worker.metadata), { provider });
|
|
113
|
-
workerRoutes.push(workerRoute);
|
|
114
|
-
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`, {
|
|
115
|
-
name: workerRoute.pattern,
|
|
116
|
-
type: "A",
|
|
117
|
-
content: "192.0.2.1",
|
|
118
|
-
zoneId: zone.id,
|
|
119
|
-
proxied: true,
|
|
120
|
-
ttl: 1
|
|
121
|
-
}, { provider });
|
|
122
|
-
dnsRecords.push(dnsRecord);
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
workerScripts,
|
|
126
|
-
workerRoutes,
|
|
127
|
-
dnsRecords
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
}];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
//#endregion
|
|
134
|
-
exports.CloudflareBuiltin = require_components_cloudflare_builtin.CloudflareBuiltin;
|
|
135
|
-
exports.CloudflareEnvBuiltin = require_components_env_builtin.CloudflareEnvBuiltin;
|
|
136
|
-
exports.WorkerEntry = require_components_worker_entry.WorkerEntry;
|
|
137
|
-
exports.default = plugin;
|
|
138
|
-
exports.plugin = plugin;
|
package/dist/index.d.cts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { CloudflareBuiltin, CloudflareBuiltinProps, __ΩCloudflareBuiltinProps } from "./components/cloudflare-builtin.cjs";
|
|
2
|
-
import { CloudflareEnvBuiltin, CloudflareEnvBuiltinProps, __ΩCloudflareEnvBuiltinProps } from "./components/env-builtin.cjs";
|
|
3
|
-
import { WorkerModule, WorkerModuleMetadata, __ΩWorkerModule, __ΩWorkerModuleMetadata } from "./types/worker-module.cjs";
|
|
4
|
-
import { CloudflarePluginContext, CloudflarePluginOptions, CloudflarePluginResolvedConfig, CloudflarePluginUserConfig, CloudflareWorkerEntryModule, CloudflareWorkerMetadata, __ΩCloudflarePluginContext, __ΩCloudflarePluginOptions, __ΩCloudflarePluginResolvedConfig, __ΩCloudflarePluginUserConfig, __ΩCloudflareWorkerEntryModule, __ΩCloudflareWorkerMetadata } from "./types/plugin.cjs";
|
|
5
|
-
import { WorkerEntry, WorkerEntryProps, __ΩWorkerEntryProps } from "./components/worker-entry.cjs";
|
|
6
|
-
import { Plugin } from "powerlines";
|
|
7
|
-
|
|
8
|
-
//#region src/index.d.ts
|
|
9
|
-
declare module "powerlines" {
|
|
10
|
-
interface Config {
|
|
11
|
-
cloudflare?: CloudflarePluginOptions;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* A Powerlines plugin to assist in developing other Powerlines plugins.
|
|
16
|
-
*/
|
|
17
|
-
declare function plugin<TContext extends CloudflarePluginContext = CloudflarePluginContext>(options?: CloudflarePluginOptions): Plugin<TContext>[];
|
|
18
|
-
//#endregion
|
|
19
|
-
export { CloudflareBuiltin, CloudflareBuiltinProps, CloudflareEnvBuiltin, CloudflareEnvBuiltinProps, CloudflarePluginContext, CloudflarePluginOptions, CloudflarePluginResolvedConfig, CloudflarePluginUserConfig, CloudflareWorkerEntryModule, CloudflareWorkerMetadata, WorkerEntry, WorkerEntryProps, WorkerModule, WorkerModuleMetadata, __ΩCloudflareBuiltinProps, __ΩCloudflareEnvBuiltinProps, __ΩCloudflarePluginContext, __ΩCloudflarePluginOptions, __ΩCloudflarePluginResolvedConfig, __ΩCloudflarePluginUserConfig, __ΩCloudflareWorkerEntryModule, __ΩCloudflareWorkerMetadata, __ΩWorkerEntryProps, __ΩWorkerModule, __ΩWorkerModuleMetadata, plugin as default, plugin };
|
|
20
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;;;;YA6CY,MAAA;IACR,UAAA,GAAa,uBAAA;EAAA;AAAA;;AAJY;;iBAWb,MAAA,kBACG,uBAAA,GAA0B,uBAAA,CAAA,CAC3C,OAAA,GAAS,uBAAA,GAgNJ,MAAA,CAAO,QAAA"}
|
package/dist/index.d.mts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { CloudflareBuiltin, CloudflareBuiltinProps, __ΩCloudflareBuiltinProps } from "./components/cloudflare-builtin.mjs";
|
|
2
|
-
import { CloudflareEnvBuiltin, CloudflareEnvBuiltinProps, __ΩCloudflareEnvBuiltinProps } from "./components/env-builtin.mjs";
|
|
3
|
-
import { WorkerModule, WorkerModuleMetadata, __ΩWorkerModule, __ΩWorkerModuleMetadata } from "./types/worker-module.mjs";
|
|
4
|
-
import { CloudflarePluginContext, CloudflarePluginOptions, CloudflarePluginResolvedConfig, CloudflarePluginUserConfig, CloudflareWorkerEntryModule, CloudflareWorkerMetadata, __ΩCloudflarePluginContext, __ΩCloudflarePluginOptions, __ΩCloudflarePluginResolvedConfig, __ΩCloudflarePluginUserConfig, __ΩCloudflareWorkerEntryModule, __ΩCloudflareWorkerMetadata } from "./types/plugin.mjs";
|
|
5
|
-
import { WorkerEntry, WorkerEntryProps, __ΩWorkerEntryProps } from "./components/worker-entry.mjs";
|
|
6
|
-
import { Plugin } from "powerlines";
|
|
7
|
-
|
|
8
|
-
//#region src/index.d.ts
|
|
9
|
-
declare module "powerlines" {
|
|
10
|
-
interface Config {
|
|
11
|
-
cloudflare?: CloudflarePluginOptions;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* A Powerlines plugin to assist in developing other Powerlines plugins.
|
|
16
|
-
*/
|
|
17
|
-
declare function plugin<TContext extends CloudflarePluginContext = CloudflarePluginContext>(options?: CloudflarePluginOptions): Plugin<TContext>[];
|
|
18
|
-
//#endregion
|
|
19
|
-
export { CloudflareBuiltin, CloudflareBuiltinProps, CloudflareEnvBuiltin, CloudflareEnvBuiltinProps, CloudflarePluginContext, CloudflarePluginOptions, CloudflarePluginResolvedConfig, CloudflarePluginUserConfig, CloudflareWorkerEntryModule, CloudflareWorkerMetadata, WorkerEntry, WorkerEntryProps, WorkerModule, WorkerModuleMetadata, __ΩCloudflareBuiltinProps, __ΩCloudflareEnvBuiltinProps, __ΩCloudflarePluginContext, __ΩCloudflarePluginOptions, __ΩCloudflarePluginResolvedConfig, __ΩCloudflarePluginUserConfig, __ΩCloudflareWorkerEntryModule, __ΩCloudflareWorkerMetadata, __ΩWorkerEntryProps, __ΩWorkerModule, __ΩWorkerModuleMetadata, plugin as default, plugin };
|
|
20
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.tsx"],"mappings":";;;;;;;;;YA6CY,MAAA;IACR,UAAA,GAAa,uBAAA;EAAA;AAAA;;AAJY;;iBAWb,MAAA,kBACG,uBAAA,GAA0B,uBAAA,CAAA,CAC3C,OAAA,GAAS,uBAAA,GAgNJ,MAAA,CAAO,QAAA"}
|
package/dist/index.mjs
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { getCloudflarePreset } from "./node_modules/.pnpm/@cloudflare_unenv-preset@2.15.0_unenv@2.0.0-rc.24/node_modules/@cloudflare/unenv-preset/dist/index.mjs";
|
|
2
|
-
import { CloudflareBuiltin } from "./components/cloudflare-builtin.mjs";
|
|
3
|
-
import { CloudflareEnvBuiltin } from "./components/env-builtin.mjs";
|
|
4
|
-
import { WorkerEntry } from "./components/worker-entry.mjs";
|
|
5
|
-
import "./components/index.mjs";
|
|
6
|
-
import { createComponent } from "@alloy-js/core/jsx-runtime";
|
|
7
|
-
import { For } from "@alloy-js/core";
|
|
8
|
-
import { render } from "@powerlines/plugin-alloy/render";
|
|
9
|
-
import { readEnvTypeReflection } from "@powerlines/plugin-env/helpers";
|
|
10
|
-
import { resolveModule } from "@powerlines/plugin-esbuild/helpers/resolve";
|
|
11
|
-
import unenv from "@powerlines/plugin-unenv";
|
|
12
|
-
import * as pulumiCloudflare from "@pulumi/cloudflare";
|
|
13
|
-
import { omit } from "@stryke/helpers/omit";
|
|
14
|
-
import { joinPaths, replaceExtension } from "@stryke/path";
|
|
15
|
-
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
16
|
-
import { isFunction } from "@stryke/type-checks/is-function";
|
|
17
|
-
import defu from "defu";
|
|
18
|
-
|
|
19
|
-
//#region src/index.tsx
|
|
20
|
-
/**
|
|
21
|
-
* A Powerlines plugin to assist in developing other Powerlines plugins.
|
|
22
|
-
*/
|
|
23
|
-
function plugin(options = {}) {
|
|
24
|
-
return [unenv(options.unenv), {
|
|
25
|
-
name: "cloudflare",
|
|
26
|
-
config() {
|
|
27
|
-
return {
|
|
28
|
-
cloudflare: defu(omit(options, ["unenv"]), {}),
|
|
29
|
-
resolve: { skipNodeModulesBundle: false },
|
|
30
|
-
unenv: { presets: [getCloudflarePreset({
|
|
31
|
-
compatibilityDate: this.config.compatibilityDate?.toString(),
|
|
32
|
-
compatibilityFlags: ["nodejs_als"]
|
|
33
|
-
})] }
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
configResolved() {
|
|
37
|
-
this.devDependencies["@cloudflare/workers-types"] = "^4.20240616.0";
|
|
38
|
-
},
|
|
39
|
-
async prepare() {
|
|
40
|
-
const result = await readEnvTypeReflection(this, "env");
|
|
41
|
-
return render(this, [createComponent(CloudflareBuiltin, {}), createComponent(CloudflareEnvBuiltin, { reflection: result })]);
|
|
42
|
-
},
|
|
43
|
-
build: {
|
|
44
|
-
order: "pre",
|
|
45
|
-
async handler() {
|
|
46
|
-
const _self$ = this;
|
|
47
|
-
this.workers = await Promise.all(this.entry.map(async (entry, i, arr) => {
|
|
48
|
-
if (!entry.input) throw new Error(`Cloudflare Worker entry "${entry.file}" is missing an input file.`);
|
|
49
|
-
const workerModule = await resolveModule(this, entry.input);
|
|
50
|
-
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".`);
|
|
51
|
-
const name = workerModule.metadata?.name || replaceExtension(entry.input.file || entry.file) || arr.length > 1 ? `${this.config.name}-${i}` : this.config.name;
|
|
52
|
-
return {
|
|
53
|
-
metadata: {
|
|
54
|
-
name,
|
|
55
|
-
pattern: `${name}.{domain}`,
|
|
56
|
-
entry
|
|
57
|
-
},
|
|
58
|
-
fetch: isFunction(workerModule.default.fetch),
|
|
59
|
-
tail: isFunction(workerModule.default.tail),
|
|
60
|
-
trace: isFunction(workerModule.default.trace),
|
|
61
|
-
tailStream: isFunction(workerModule.default.tailStream),
|
|
62
|
-
scheduled: isFunction(workerModule.default.scheduled),
|
|
63
|
-
test: isFunction(workerModule.default.test),
|
|
64
|
-
email: isFunction(workerModule.default.email),
|
|
65
|
-
queue: isFunction(workerModule.default.queue)
|
|
66
|
-
};
|
|
67
|
-
}));
|
|
68
|
-
return render(this, createComponent(For, {
|
|
69
|
-
get each() {
|
|
70
|
-
return _self$.workers;
|
|
71
|
-
},
|
|
72
|
-
children: (worker) => createComponent(WorkerEntry, { worker })
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
async deployPulumi() {
|
|
77
|
-
let apiToken = process.env.CLOUDFLARE_API_TOKEN;
|
|
78
|
-
if (!apiToken) {
|
|
79
|
-
apiToken = this.config.cloudflare.apiToken;
|
|
80
|
-
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.");
|
|
81
|
-
else throw new Error("Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.");
|
|
82
|
-
}
|
|
83
|
-
await this.pulumi.setConfig("cloudflare:apiToken", { value: apiToken });
|
|
84
|
-
const provider = new pulumiCloudflare.Provider("cloudflare-provider", { apiToken });
|
|
85
|
-
const zone = await pulumiCloudflare.getZone({ filter: {
|
|
86
|
-
account: { id: this.config.cloudflare.accountId },
|
|
87
|
-
name: this.config.cloudflare.domain
|
|
88
|
-
} }, { provider });
|
|
89
|
-
const workerScripts = [];
|
|
90
|
-
const workerRoutes = [];
|
|
91
|
-
const dnsRecords = [];
|
|
92
|
-
for (const worker of this.workers) {
|
|
93
|
-
const workerScript = new pulumiCloudflare.WorkersScript(`${this.config.organization ? `${this.config.organization}.` : ""}${kebabCase(this.config.name) === kebabCase(worker.metadata.name) ? kebabCase(this.config.name) : `${kebabCase(this.config.name)}.${kebabCase(worker.metadata.name)}`}.${kebabCase(this.config.mode)}.worker-script`, defu({
|
|
94
|
-
accountId: this.config.cloudflare.accountId,
|
|
95
|
-
scriptName: worker.metadata.name,
|
|
96
|
-
contentFile: joinPaths(this.config.output.publishPath, "index.js"),
|
|
97
|
-
module: true
|
|
98
|
-
}, worker.metadata, {
|
|
99
|
-
compatibilityDate: this.config.compatibilityDate?.cloudflare?.toString(),
|
|
100
|
-
compatibilityFlags: ["nodejs_als"]
|
|
101
|
-
}), { provider });
|
|
102
|
-
workerScripts.push(workerScript);
|
|
103
|
-
const workerRoute = new pulumiCloudflare.WorkersRoute(`${this.config.organization ? `${this.config.organization}.` : ""}${kebabCase(this.config.name) === kebabCase(worker.metadata.name) ? kebabCase(this.config.name) : `${kebabCase(this.config.name)}-${kebabCase(worker.metadata.name)}`}.${kebabCase(this.config.mode)}.worker-route`, defu({
|
|
104
|
-
zoneId: zone.id,
|
|
105
|
-
pattern: worker.metadata.pattern.replace("{domain}", this.config.cloudflare.domain),
|
|
106
|
-
script: workerScript.scriptName
|
|
107
|
-
}, worker.metadata), { provider });
|
|
108
|
-
workerRoutes.push(workerRoute);
|
|
109
|
-
const dnsRecord = new pulumiCloudflare.DnsRecord(`${this.config.organization ? `${this.config.organization}.` : ""}${kebabCase(this.config.name) === kebabCase(worker.metadata.name) ? kebabCase(this.config.name) : `${kebabCase(this.config.name)}-${kebabCase(worker.metadata.name)}`}.${kebabCase(this.config.mode)}.dns-record`, {
|
|
110
|
-
name: workerRoute.pattern,
|
|
111
|
-
type: "A",
|
|
112
|
-
content: "192.0.2.1",
|
|
113
|
-
zoneId: zone.id,
|
|
114
|
-
proxied: true,
|
|
115
|
-
ttl: 1
|
|
116
|
-
}, { provider });
|
|
117
|
-
dnsRecords.push(dnsRecord);
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
workerScripts,
|
|
121
|
-
workerRoutes,
|
|
122
|
-
dnsRecords
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
//#endregion
|
|
129
|
-
export { CloudflareBuiltin, CloudflareEnvBuiltin, WorkerEntry, plugin as default, plugin };
|
|
130
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.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 { For } from \"@alloy-js/core\";\nimport { getCloudflarePreset } from \"@cloudflare/unenv-preset\";\nimport { render } from \"@powerlines/plugin-alloy/render\";\nimport { readEnvTypeReflection } from \"@powerlines/plugin-env/helpers\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport unenv from \"@powerlines/plugin-unenv\";\nimport * as pulumiCloudflare from \"@pulumi/cloudflare\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { joinPaths, replaceExtension } from \"@stryke/path\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport defu from \"defu\";\nimport { Plugin } from \"powerlines\";\nimport { CloudflareEnvBuiltin } from \"./components\";\nimport { CloudflareBuiltin } from \"./components/cloudflare-builtin\";\nimport { WorkerEntry } from \"./components/worker-entry\";\nimport {\n CloudflarePluginContext,\n CloudflarePluginOptions,\n CloudflareWorkerEntryModule\n} from \"./types/plugin\";\nimport { WorkerModule } from \"./types/worker-module\";\n\nexport * from \"./components\";\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n cloudflare?: CloudflarePluginOptions;\n }\n}\n\n/**\n * A Powerlines plugin to assist in developing other Powerlines plugins.\n */\nexport function plugin<\n TContext extends CloudflarePluginContext = CloudflarePluginContext\n>(options: CloudflarePluginOptions = {}) {\n return [\n unenv(options.unenv),\n {\n name: \"cloudflare\",\n config() {\n return {\n cloudflare: defu(omit(options, [\"unenv\"]), {}),\n resolve: {\n skipNodeModulesBundle: false\n },\n unenv: {\n presets: [\n getCloudflarePreset({\n compatibilityDate: this.config.compatibilityDate?.toString(),\n compatibilityFlags: [\"nodejs_als\"]\n })\n ]\n }\n };\n },\n configResolved() {\n this.devDependencies[\"@cloudflare/workers-types\"] = \"^4.20240616.0\";\n },\n async prepare() {\n const result = await readEnvTypeReflection(this, \"env\");\n\n return render(\n this,\n <>\n <CloudflareBuiltin />\n <CloudflareEnvBuiltin reflection={result} />\n </>\n );\n },\n build: {\n order: \"pre\",\n async handler() {\n this.workers = await Promise.all(\n this.entry.map(async (entry, i, arr) => {\n if (!entry.input) {\n throw new Error(\n `Cloudflare Worker entry \"${entry.file}\" is missing an input file.`\n );\n }\n\n const workerModule = await resolveModule<WorkerModule>(\n this,\n entry.input\n );\n if (!workerModule?.default) {\n throw new Error(\n `Cloudflare Worker entry \"${\n entry.file\n }\" 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\".`\n );\n }\n\n const name =\n workerModule.metadata?.name ||\n replaceExtension(entry.input.file || entry.file) ||\n arr.length > 1\n ? `${this.config.name}-${i}`\n : this.config.name;\n\n return {\n metadata: {\n name,\n pattern: `${name}.{domain}`,\n entry\n },\n fetch: isFunction(workerModule.default.fetch),\n tail: isFunction(workerModule.default.tail),\n trace: isFunction(workerModule.default.trace),\n tailStream: isFunction(workerModule.default.tailStream),\n scheduled: isFunction(workerModule.default.scheduled),\n test: isFunction(workerModule.default.test),\n email: isFunction(workerModule.default.email),\n queue: isFunction(workerModule.default.queue)\n } satisfies CloudflareWorkerEntryModule;\n })\n );\n\n return render(\n this,\n <For each={this.workers}>\n {worker => <WorkerEntry worker={worker} />}\n </For>\n );\n }\n },\n async deployPulumi() {\n let apiToken = process.env.CLOUDFLARE_API_TOKEN;\n if (!apiToken) {\n apiToken = this.config.cloudflare.apiToken;\n if (apiToken) {\n this.warn(\n \"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.\"\n );\n } else {\n throw new Error(\n \"Unable to determine the Cloudflare API token. Please set the `CLOUDFLARE_API_TOKEN` environment variable.\"\n );\n }\n }\n\n await this.pulumi.setConfig(\"cloudflare:apiToken\", {\n value: apiToken\n });\n\n const provider = new pulumiCloudflare.Provider(\"cloudflare-provider\", {\n apiToken\n });\n\n const zone = await pulumiCloudflare.getZone(\n {\n filter: {\n account: { id: this.config.cloudflare.accountId },\n name: this.config.cloudflare.domain\n }\n },\n { provider }\n );\n\n const workerScripts = [] as pulumiCloudflare.WorkersScript[];\n const workerRoutes = [] as pulumiCloudflare.WorkersRoute[];\n const dnsRecords = [] as pulumiCloudflare.DnsRecord[];\n for (const worker of this.workers) {\n const workerScript = new pulumiCloudflare.WorkersScript(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}.${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker-script`,\n defu(\n {\n accountId: this.config.cloudflare.accountId,\n scriptName: worker.metadata.name,\n contentFile: joinPaths(\n this.config.output.publishPath,\n \"index.js\"\n ),\n module: true\n },\n worker.metadata,\n {\n compatibilityDate:\n this.config.compatibilityDate?.cloudflare?.toString() as string,\n compatibilityFlags: [\"nodejs_als\"]\n }\n ) as pulumiCloudflare.WorkersScriptArgs,\n { provider }\n );\n workerScripts.push(workerScript);\n\n const workerRoute = new pulumiCloudflare.WorkersRoute(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.worker-route`,\n defu(\n {\n zoneId: zone.id,\n pattern: worker.metadata.pattern.replace(\n \"{domain}\",\n this.config.cloudflare.domain\n ),\n script: workerScript.scriptName\n },\n worker.metadata\n ),\n { provider }\n );\n workerRoutes.push(workerRoute);\n\n const dnsRecord = new pulumiCloudflare.DnsRecord(\n `${this.config.organization ? `${this.config.organization}.` : \"\"}${\n kebabCase(this.config.name) === kebabCase(worker.metadata.name)\n ? kebabCase(this.config.name)\n : `${kebabCase(this.config.name)}-${kebabCase(\n worker.metadata.name\n )}`\n }.${kebabCase(this.config.mode)}.dns-record`,\n {\n name: workerRoute.pattern,\n type: \"A\",\n content: \"192.0.2.1\",\n zoneId: zone.id,\n proxied: true,\n ttl: 1\n },\n { provider }\n );\n dnsRecords.push(dnsRecord);\n }\n\n return {\n workerScripts,\n workerRoutes,\n dnsRecords\n };\n }\n }\n ] as Plugin<TContext>[];\n}\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAA,OAAA,UAAA,EAAA,EAAA;;EAEE,MAAA;EACE,SAAC;AACH,UAAA;IACK,YAAS,KAAM,KAAA,SAAA,CAAA,QAAA,CAAA,EAAA,EAAA,CAAA;IACpB,SAAS,EACD,uBAAC,OACF;IACL,OAAM,EACN,SAAA,CAAA,oBAAA;KACQ,mBAAY,KAAA,OAAA,mBAAA,UAAA;KACZ,oBAAG,CAAA,aAAA;KACP,CAAA,CAAA,EACC;IACF;;EAEH,iBAAO;AACL,QAAI,gBAAO,+BAAA;;EAEb,MAAM,UAAI;GACR,MAAM,SAAI,MAAA,sBAA+B,MAAA,MAAA;AACzC,UAAO,OAAG,MAAA,CAAA,gBAAsB,mBAAW,EAAA,CAAA,EAAA,gBAAA,sBAAA,EACzC,Y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