acrylblends 0.11.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +131 -53
  2. package/dist/index.d.ts +29 -2
  3. package/dist/index.js +450 -69
  4. package/dist/index.js.map +1 -1
  5. package/docs/framework/README.md +5 -3
  6. package/docs/framework/agents/index.md +1 -1
  7. package/docs/framework/api/acryl.md +5 -17
  8. package/docs/framework/api/context.md +12 -61
  9. package/docs/framework/api/presets.md +1 -1
  10. package/docs/framework/api/request.md +3 -3
  11. package/docs/framework/api/summary.md +1 -1
  12. package/docs/framework/concepts/web-standard.md +6 -16
  13. package/docs/framework/cordis/acryl-in-a-cordis-app.md +13 -8
  14. package/docs/framework/cordis/migration-from-0-4.md +1 -1
  15. package/docs/framework/cordis/migration-to-1-0.md +45 -0
  16. package/docs/framework/cordis/node-server.md +2 -2
  17. package/docs/framework/getting-started/basic.md +15 -10
  18. package/docs/framework/getting-started/desktop.md +1 -1
  19. package/docs/framework/getting-started/other-runtimes.md +10 -14
  20. package/docs/framework/guides/create-acrylblends.md +4 -2
  21. package/docs/framework/guides/data.md +1 -1
  22. package/docs/framework/guides/faq.md +1 -1
  23. package/docs/framework/guides/jsx-dom.md +1 -1
  24. package/docs/framework/guides/production.md +43 -0
  25. package/docs/framework/guides/rpc.md +3 -11
  26. package/docs/framework/helpers/adapter.md +13 -43
  27. package/docs/framework/helpers/conninfo.md +1 -36
  28. package/docs/framework/helpers/streaming.md +1 -1
  29. package/docs/framework/helpers/websocket.md +4 -11
  30. package/docs/framework/middleware/builtin/basic-auth.md +1 -1
  31. package/docs/framework/middleware/builtin/cache.md +2 -22
  32. package/docs/framework/middleware/builtin/compress.md +1 -1
  33. package/docs/framework/middleware/builtin/context-storage.md +10 -14
  34. package/docs/framework/middleware/builtin/cors.md +1 -2
  35. package/docs/framework/middleware/builtin/ip-restriction.md +1 -1
  36. package/docs/framework/middleware/builtin/jsx-renderer.md +1 -1
  37. package/docs/framework/middleware/builtin/logger.md +1 -1
  38. package/docs/framework/middleware/builtin/loopback-only.md +1 -1
  39. package/docs/framework/middleware/builtin/mount.md +1 -1
  40. package/docs/framework/middleware/builtin/request-id.md +13 -20
  41. package/docs/framework/middleware/builtin/timing.md +1 -2
  42. package/lib/cordis/door.d.ts +5 -0
  43. package/lib/cordis/door.js +8 -4
  44. package/lib/cordis/inspect.js +1 -1
  45. package/lib/cordis/router-http.js +1 -1
  46. package/lib/cordis/router.d.ts +1 -2
  47. package/lib/cordis/router.js +2 -3
  48. package/lib/cordis/state.js +1 -1
  49. package/lib/door/host.js +1 -1
  50. package/lib/drivers.d.ts +66 -0
  51. package/lib/drivers.js +16 -0
  52. package/lib/index.d.ts +1 -2
  53. package/lib/index.js +1 -2
  54. package/lib/{snapshot-text-yaWlezbd.js → snapshot-text-DmE0YfeZ.js} +2 -2
  55. package/lib/{src-DNzw0Qsb.js → src-2Z4mJg0x.js} +0 -1
  56. package/package.json +5 -121
  57. package/plugins/acryl-door/src/index.ts +8 -0
  58. package/plugins/acryl-router/src/index.ts +0 -1
  59. package/plugins/agent-panel/drivers.ts +1 -16
  60. package/plugins/agent-panel/index.ts +1 -1
  61. package/plugins/agent-panel/registry.ts +16 -0
  62. package/plugins/driver-acp/README.md +53 -0
  63. package/plugins/driver-acp/chat.ts +258 -0
  64. package/plugins/driver-acp/connection.ts +239 -0
  65. package/plugins/driver-acp/index.ts +65 -0
  66. package/plugins/driver-acp/plugin.json +12 -0
  67. package/plugins/driver-acp/provenance.json +20 -0
  68. package/plugins/driver-pty/index.ts +1 -0
  69. package/shared/library-history.json +464 -0
  70. package/docs/framework/getting-started/aws-lambda.md +0 -115
  71. package/docs/framework/getting-started/cloudflare-pages.md +0 -53
  72. package/docs/framework/getting-started/cloudflare-workers.md +0 -67
  73. package/docs/framework/getting-started/lambda-edge.md +0 -41
  74. package/docs/framework/getting-started/netlify.md +0 -25
  75. package/docs/framework/getting-started/service-worker.md +0 -33
  76. package/docs/framework/getting-started/vercel.md +0 -28
  77. package/lib/aws-lambda.d.ts +0 -324
  78. package/lib/aws-lambda.js +0 -357
  79. package/lib/cloudflare-pages.d.ts +0 -58
  80. package/lib/cloudflare-pages.js +0 -78
  81. package/lib/cloudflare-workers.d.ts +0 -21
  82. package/lib/cloudflare-workers.js +0 -80
  83. package/lib/deprecated-BP4fPt38.js +0 -10
  84. package/lib/deprecated-CTy4N7ng.d.ts +0 -12
  85. package/lib/lambda-edge.d.ts +0 -92
  86. package/lib/lambda-edge.js +0 -105
  87. package/lib/netlify.d.ts +0 -29
  88. package/lib/netlify.js +0 -30
  89. package/lib/service-worker.d.ts +0 -48
  90. package/lib/service-worker.js +0 -38
  91. package/lib/vercel.d.ts +0 -10
  92. package/lib/vercel.js +0 -9
  93. package/plugins/acryl-router/src/deprecated.ts +0 -15
package/lib/aws-lambda.js DELETED
@@ -1,357 +0,0 @@
1
- import { decodeBase64, encodeBase64 } from "./utils/encode.js";
2
- import { pipeline } from "node:stream/promises";
3
- //#region ../../plugins/acryl-router/src/core/adapter/aws-lambda/handler.ts
4
- function sanitizeHeaderValue(value) {
5
- if (!/[^\x00-\x7F]/.test(value)) return value;
6
- return encodeURIComponent(value);
7
- }
8
- const getRequestContext = (event) => {
9
- return event.requestContext;
10
- };
11
- async function* readWebStream(reader) {
12
- let readResult = await reader.read();
13
- while (!readResult.done) {
14
- yield readResult.value;
15
- readResult = await reader.read();
16
- }
17
- }
18
- const streamToNodeStream = (reader, writer) => pipeline(readWebStream(reader), writer);
19
- const streamHandle = (app) => {
20
- return awslambda.streamifyResponse(async (event, responseStream, context) => {
21
- const processor = getProcessor(event);
22
- try {
23
- const req = processor.createRequest(event);
24
- const requestContext = getRequestContext(event);
25
- const res = await app.fetch(req, {
26
- event,
27
- requestContext,
28
- context
29
- });
30
- const headers = {};
31
- const cookies = [];
32
- res.headers.forEach((value, name) => {
33
- if (name === "set-cookie") cookies.push(value);
34
- else headers[name] = value;
35
- });
36
- const httpResponseMetadata = {
37
- statusCode: res.status,
38
- headers,
39
- cookies
40
- };
41
- responseStream = awslambda.HttpResponseStream.from(responseStream, httpResponseMetadata);
42
- if (res.body) await streamToNodeStream(res.body.getReader(), responseStream);
43
- else responseStream.write("");
44
- } catch (error) {
45
- console.error("Error processing request:", error);
46
- responseStream.write("Internal Server Error");
47
- } finally {
48
- responseStream.end();
49
- }
50
- });
51
- };
52
- /**
53
- * Converts a Acryl application to an AWS Lambda handler.
54
- *
55
- * Accepts events from API Gateway (v1 and v2), Application Load Balancer (ALB),
56
- * and Lambda Function URLs.
57
- *
58
- * @param app - The Acryl application instance
59
- * @param options - Optional configuration
60
- * @param options.isContentTypeBinary - A function to determine if the content type is binary.
61
- * If not provided, the default function will be used.
62
- * @returns Lambda handler function
63
- *
64
- * @example
65
- * ```js
66
- * import { Acryl } from 'acrylblends'
67
- * import { handle } from 'acrylblends/aws-lambda'
68
- *
69
- * const app = new Acryl()
70
- *
71
- * app.get('/', (c) => c.text('Hello from Lambda'))
72
- * app.get('/json', (c) => c.json({ message: 'Hello JSON' }))
73
- *
74
- * export const handler = handle(app)
75
- * ```
76
- *
77
- * @example
78
- * ```js
79
- * // With custom binary content type detection
80
- * import { handle, defaultIsContentTypeBinary } from 'acrylblends/aws-lambda'
81
- * export const handler = handle(app, {
82
- * isContentTypeBinary: (contentType) => {
83
- * if (defaultIsContentTypeBinary(contentType)) {
84
- * // default logic same as prior to v4.8.4
85
- * return true
86
- * }
87
- * return contentType.startsWith('image/') || contentType === 'application/pdf'
88
- * }
89
- * })
90
- * ```
91
- */
92
- const handle = (app, { isContentTypeBinary } = { isContentTypeBinary: void 0 }) => {
93
- return async (event, lambdaContext) => {
94
- const processor = getProcessor(event);
95
- let req, requestContext;
96
- try {
97
- req = processor.createRequest(event);
98
- requestContext = getRequestContext(event);
99
- } catch (error) {
100
- console.error("Error processing request:", error);
101
- const errorResponse = error instanceof TypeError ? new Response("Invalid request", { status: 400 }) : new Response("Internal Server Error", { status: 500 });
102
- return processor.createResult(event, errorResponse, { isContentTypeBinary });
103
- }
104
- const res = await app.fetch(req, {
105
- event,
106
- requestContext,
107
- lambdaContext
108
- });
109
- return processor.createResult(event, res, { isContentTypeBinary });
110
- };
111
- };
112
- var EventProcessor = class {
113
- getHeaderValue(headers, key) {
114
- return headers ? Array.isArray(headers[key]) ? headers[key][0] : headers[key] : void 0;
115
- }
116
- getDomainName(event) {
117
- if (event.requestContext && "domainName" in event.requestContext) return event.requestContext.domainName;
118
- const hostFromHeaders = this.getHeaderValue(event.headers, "host");
119
- if (hostFromHeaders) return hostFromHeaders;
120
- const multiValueHeaders = "multiValueHeaders" in event ? event.multiValueHeaders : {};
121
- return this.getHeaderValue(multiValueHeaders, "host");
122
- }
123
- createRequest(event) {
124
- const queryString = this.getQueryString(event);
125
- const urlPath = `https://${this.getDomainName(event)}${this.getPath(event)}`;
126
- const url = queryString ? `${urlPath}?${queryString}` : urlPath;
127
- const headers = this.getHeaders(event);
128
- const requestInit = {
129
- headers,
130
- method: this.getMethod(event)
131
- };
132
- if (event.body) {
133
- const body = event.isBase64Encoded ? decodeBase64(event.body) : new TextEncoder().encode(event.body);
134
- requestInit.body = body;
135
- headers.set("content-length", body.length.toString());
136
- }
137
- return new Request(url, requestInit);
138
- }
139
- async createResult(event, res, options) {
140
- const contentType = res.headers.get("content-type");
141
- const isContentTypeBinary = options.isContentTypeBinary ?? defaultIsContentTypeBinary;
142
- let isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
143
- if (!isBase64Encoded) {
144
- const contentEncoding = res.headers.get("content-encoding");
145
- isBase64Encoded = isContentEncodingBinary(contentEncoding);
146
- }
147
- const result = {
148
- body: isBase64Encoded ? encodeBase64(await res.arrayBuffer()) : await res.text(),
149
- statusCode: res.status,
150
- isBase64Encoded,
151
- ..."multiValueHeaders" in event && event.multiValueHeaders ? { multiValueHeaders: {} } : { headers: {} }
152
- };
153
- this.setCookies(event, res, result);
154
- if (result.multiValueHeaders) res.headers.forEach((value, key) => {
155
- result.multiValueHeaders[key] = [value];
156
- });
157
- else res.headers.forEach((value, key) => {
158
- result.headers[key] = value;
159
- });
160
- return result;
161
- }
162
- setCookies(_event, res, result) {
163
- if (res.headers.has("set-cookie")) {
164
- const cookies = res.headers.getSetCookie ? res.headers.getSetCookie() : Array.from(res.headers.entries()).filter(([k]) => k === "set-cookie").map(([, v]) => v);
165
- if (Array.isArray(cookies)) {
166
- this.setCookiesToResult(result, cookies);
167
- res.headers.delete("set-cookie");
168
- }
169
- }
170
- }
171
- };
172
- var EventV2Processor = class extends EventProcessor {
173
- getPath(event) {
174
- return event.rawPath;
175
- }
176
- getMethod(event) {
177
- return event.requestContext.http.method;
178
- }
179
- getQueryString(event) {
180
- return event.rawQueryString;
181
- }
182
- getCookies(event, headers) {
183
- if (Array.isArray(event.cookies)) headers.set("Cookie", event.cookies.join("; "));
184
- }
185
- setCookiesToResult(result, cookies) {
186
- result.cookies = cookies;
187
- }
188
- getHeaders(event) {
189
- const headers = new Headers();
190
- this.getCookies(event, headers);
191
- if (event.headers) {
192
- for (const [k, v] of Object.entries(event.headers)) if (v) headers.set(k, v);
193
- }
194
- return headers;
195
- }
196
- };
197
- const v2Processor = new EventV2Processor();
198
- var EventV1Processor = class extends EventProcessor {
199
- getPath(event) {
200
- return event.path;
201
- }
202
- getMethod(event) {
203
- return event.httpMethod;
204
- }
205
- getQueryString(event) {
206
- if (event.multiValueQueryStringParameters) return Object.entries(event.multiValueQueryStringParameters || {}).filter(([, value]) => value).map(([key, values]) => values.map((value) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join("&")).join("&");
207
- else return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value !== void 0).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value || "")}`).join("&");
208
- }
209
- getCookies(_event, _headers) {}
210
- getHeaders(event) {
211
- const headers = new Headers();
212
- this.getCookies(event, headers);
213
- if (event.multiValueHeaders) {
214
- for (const [k, values] of Object.entries(event.multiValueHeaders)) if (values) values.forEach((v) => headers.append(k, sanitizeHeaderValue(v)));
215
- }
216
- if (event.headers) {
217
- for (const [k, v] of Object.entries(event.headers)) if (v && !headers.has(k)) headers.set(k, sanitizeHeaderValue(v));
218
- }
219
- return headers;
220
- }
221
- setCookiesToResult(result, cookies) {
222
- result.multiValueHeaders = { "set-cookie": cookies };
223
- }
224
- };
225
- const v1Processor = new EventV1Processor();
226
- var ALBProcessor = class extends EventProcessor {
227
- getHeaders(event) {
228
- const headers = new Headers();
229
- if (event.multiValueHeaders) {
230
- for (const [key, values] of Object.entries(event.multiValueHeaders)) if (values && Array.isArray(values)) {
231
- const sanitizedValue = sanitizeHeaderValue(values.join("; "));
232
- headers.set(key, sanitizedValue);
233
- }
234
- } else for (const [key, value] of Object.entries(event.headers ?? {})) if (value) headers.set(key, sanitizeHeaderValue(value));
235
- return headers;
236
- }
237
- getPath(event) {
238
- return event.path;
239
- }
240
- getMethod(event) {
241
- return event.httpMethod;
242
- }
243
- getQueryString(event) {
244
- if (event.multiValueQueryStringParameters) return Object.entries(event.multiValueQueryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value.join(`&${key}=`)}`).join("&");
245
- else return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value !== void 0).map(([key, value]) => `${key}=${value}`).join("&");
246
- }
247
- getCookies(event, headers) {
248
- let cookie;
249
- if (event.multiValueHeaders) cookie = event.multiValueHeaders["cookie"]?.join("; ");
250
- else cookie = event.headers ? event.headers["cookie"] : void 0;
251
- if (cookie) headers.append("Cookie", cookie);
252
- }
253
- setCookiesToResult(result, cookies) {
254
- if (result.multiValueHeaders) result.multiValueHeaders["set-cookie"] = cookies;
255
- else result.headers["set-cookie"] = cookies[0];
256
- }
257
- };
258
- const albProcessor = new ALBProcessor();
259
- var LatticeV2Processor = class extends EventProcessor {
260
- getPath(event) {
261
- return event.path;
262
- }
263
- getMethod(event) {
264
- return event.method;
265
- }
266
- getQueryString() {
267
- return "";
268
- }
269
- getHeaders(event) {
270
- const headers = new Headers();
271
- if (event.headers) {
272
- for (const [k, values] of Object.entries(event.headers)) if (values) values.forEach((v) => headers.append(k, sanitizeHeaderValue(v)));
273
- }
274
- return headers;
275
- }
276
- getCookies() {}
277
- setCookiesToResult(result, cookies) {
278
- result.headers = {
279
- ...result.headers,
280
- "set-cookie": cookies
281
- };
282
- }
283
- };
284
- const latticeV2Processor = new LatticeV2Processor();
285
- const getProcessor = (event) => {
286
- if (isProxyEventALB(event)) return albProcessor;
287
- if (isProxyEventV2(event)) return v2Processor;
288
- if (isLatticeEventV2(event)) return latticeV2Processor;
289
- return v1Processor;
290
- };
291
- const isProxyEventALB = (event) => {
292
- if (event.requestContext) return Object.hasOwn(event.requestContext, "elb");
293
- return false;
294
- };
295
- const isProxyEventV2 = (event) => {
296
- return Object.hasOwn(event, "rawPath") && Object.hasOwn(event.requestContext ?? {}, "http");
297
- };
298
- const isLatticeEventV2 = (event) => {
299
- if (event.requestContext) return Object.hasOwn(event.requestContext, "serviceArn");
300
- return false;
301
- };
302
- /**
303
- * Check if the given content type is binary.
304
- * This is a default function and may be overwritten by the user via `isContentTypeBinary` option in handler().
305
- * @param contentType The content type to check.
306
- * @returns True if the content type is binary, false otherwise.
307
- */
308
- const defaultIsContentTypeBinary = (contentType) => {
309
- if (/^application\/vnd\.(?:apple\.installer|mozilla\.xul)\+xml\s*(?:;|$)/i.test(contentType)) return true;
310
- return !/^text\/(?:plain|html|css|javascript|csv)|(?:\/|\+)(?:json|xml)\s*(?:;|$)/i.test(contentType);
311
- };
312
- const isContentEncodingBinary = (contentEncoding) => {
313
- return !!contentEncoding && !/^identity$/i.test(contentEncoding);
314
- };
315
- //#endregion
316
- //#region ../../plugins/acryl-router/src/core/adapter/aws-lambda/conninfo.ts
317
- /**
318
- * Get connection information from AWS Lambda
319
- *
320
- * Extracts client IP from various Lambda event sources:
321
- * - API Gateway v1 (REST API): requestContext.identity.sourceIp
322
- * - API Gateway v2 (HTTP API/Function URLs): requestContext.http.sourceIp
323
- * - ALB: Falls back to x-forwarded-for header
324
- *
325
- * @param c - Context
326
- * @returns Connection information including remote address
327
- * @example
328
- * ```ts
329
- * import { Acryl } from 'acrylblends'
330
- * import { handle, getConnInfo } from 'acrylblends/aws-lambda'
331
- *
332
- * const app = new Acryl()
333
- *
334
- * app.get('/', (c) => {
335
- * const info = getConnInfo(c)
336
- * return c.text(`Your IP: ${info.remote.address}`)
337
- * })
338
- *
339
- * export const handler = handle(app)
340
- * ```
341
- */
342
- const getConnInfo = (c) => {
343
- const requestContext = c.env.requestContext;
344
- let address;
345
- if ("identity" in requestContext && requestContext.identity?.sourceIp) address = requestContext.identity.sourceIp;
346
- else if ("http" in requestContext && requestContext.http?.sourceIp) address = requestContext.http.sourceIp;
347
- else {
348
- const xff = c.req.header("x-forwarded-for");
349
- if (xff) {
350
- const ips = xff.split(",");
351
- address = ips[ips.length - 1].trim();
352
- }
353
- }
354
- return { remote: { address } };
355
- };
356
- //#endregion
357
- export { defaultIsContentTypeBinary, getConnInfo, handle, streamHandle };
@@ -1,58 +0,0 @@
1
- import { L as MiddlewareHandler, Y as Schema, g as BlankSchema, j as Input, v as Env } from "./context-DS3fYyG-.js";
2
- import { r as GetConnInfo } from "./types-Dv_nV2cv.js";
3
- import { t as Acryl } from "./app-D8riatvv.js";
4
-
5
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-pages/handler.d.ts
6
- type Params<P extends string = any> = Record<P, string | string[]>;
7
- type EventContext<Env = {}, P extends string = any, Data = Record<string, unknown>> = {
8
- request: Request;
9
- functionPath: string;
10
- waitUntil: (promise: Promise<unknown>) => void;
11
- passThroughOnException: () => void;
12
- props: any;
13
- next: (input?: Request | string, init?: RequestInit) => Promise<Response>;
14
- env: Env & {
15
- ASSETS: {
16
- fetch: typeof fetch;
17
- };
18
- };
19
- params: Params<P>;
20
- data: Data;
21
- };
22
- declare type PagesFunction<Env = unknown, Params extends string = any, Data extends Record<string, unknown> = Record<string, unknown>> = (context: EventContext<Env, Params, Data>) => Response | Promise<Response>;
23
- declare const handle: <E extends Env = Env, S extends Schema = BlankSchema, BasePath extends string = "/">(app: Acryl<E, S, BasePath>) => PagesFunction<E["Bindings"]>;
24
- declare function handleMiddleware<E extends Env = {}, P extends string = any, I extends Input = {}>(middleware: MiddlewareHandler<E & {
25
- Bindings: {
26
- eventContext: EventContext;
27
- };
28
- }, P, I>): PagesFunction<E['Bindings']>;
29
- /**
30
- *
31
- * @description `serveStatic()` is for advanced mode:
32
- * https://developers.cloudflare.com/pages/platform/functions/advanced-mode/#set-up-a-function
33
- */
34
- declare const serveStatic: () => MiddlewareHandler;
35
- //#endregion
36
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-pages/conninfo.d.ts
37
- /**
38
- * Get connection information from Cloudflare Pages
39
- * @param c - Context
40
- * @returns Connection information including remote address
41
- * @example
42
- * ```ts
43
- * import { Acryl } from 'acrylblends'
44
- * import { handle, getConnInfo } from 'acrylblends/cloudflare-pages'
45
- *
46
- * const app = new Acryl()
47
- *
48
- * app.get('/', (c) => {
49
- * const info = getConnInfo(c)
50
- * return c.text(`Your IP: ${info.remote.address}`)
51
- * })
52
- *
53
- * export const onRequest = handle(app)
54
- * ```
55
- */
56
- declare const getConnInfo: GetConnInfo;
57
- //#endregion
58
- export { type EventContext, getConnInfo, handle, handleMiddleware, serveStatic };
@@ -1,78 +0,0 @@
1
- import { HTTPException } from "./http-exception.js";
2
- import { t as Context } from "./context-DDO0cfuP.js";
3
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-pages/handler.ts
4
- const handle = (app) => (eventContext) => {
5
- return app.fetch(eventContext.request, {
6
- ...eventContext.env,
7
- eventContext
8
- }, {
9
- waitUntil: eventContext.waitUntil,
10
- passThroughOnException: eventContext.passThroughOnException,
11
- props: {}
12
- });
13
- };
14
- function handleMiddleware(middleware) {
15
- return async (executionCtx) => {
16
- const context = new Context(executionCtx.request, {
17
- env: {
18
- ...executionCtx.env,
19
- eventContext: executionCtx
20
- },
21
- executionCtx
22
- });
23
- let response = void 0;
24
- try {
25
- response = await middleware(context, async () => {
26
- try {
27
- context.res = await executionCtx.next();
28
- } catch (error) {
29
- if (error instanceof Error) context.error = error;
30
- else throw error;
31
- }
32
- });
33
- } catch (error) {
34
- if (error instanceof Error) context.error = error;
35
- else throw error;
36
- }
37
- if (response) return response;
38
- if (context.error instanceof HTTPException) return context.error.getResponse();
39
- if (context.error) throw context.error;
40
- return context.res;
41
- };
42
- }
43
- /**
44
- *
45
- * @description `serveStatic()` is for advanced mode:
46
- * https://developers.cloudflare.com/pages/platform/functions/advanced-mode/#set-up-a-function
47
- */
48
- const serveStatic = () => {
49
- return async (c) => {
50
- const res = await c.env.ASSETS.fetch(c.req.raw);
51
- if (res.status === 404) return c.notFound();
52
- return res;
53
- };
54
- };
55
- //#endregion
56
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-pages/conninfo.ts
57
- /**
58
- * Get connection information from Cloudflare Pages
59
- * @param c - Context
60
- * @returns Connection information including remote address
61
- * @example
62
- * ```ts
63
- * import { Acryl } from 'acrylblends'
64
- * import { handle, getConnInfo } from 'acrylblends/cloudflare-pages'
65
- *
66
- * const app = new Acryl()
67
- *
68
- * app.get('/', (c) => {
69
- * const info = getConnInfo(c)
70
- * return c.text(`Your IP: ${info.remote.address}`)
71
- * })
72
- *
73
- * export const onRequest = handle(app)
74
- * ```
75
- */
76
- const getConnInfo = (c) => ({ remote: { address: c.req.header("cf-connecting-ip") } });
77
- //#endregion
78
- export { getConnInfo, handle, handleMiddleware, serveStatic };
@@ -1,21 +0,0 @@
1
- import { L as MiddlewareHandler, v as Env } from "./context-DS3fYyG-.js";
2
- import { r as GetConnInfo } from "./types-Dv_nV2cv.js";
3
- import { a as WSEvents, n as UpgradeWebSocket } from "./index-C-SklY6u.js";
4
- import { t as ServeStaticOptions$1 } from "./index-CseujaYI.js";
5
-
6
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static.d.ts
7
- type ServeStaticOptions<E extends Env = Env> = ServeStaticOptions$1<E> & {
8
- namespace?: unknown;
9
- manifest?: object | string;
10
- };
11
- //#endregion
12
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static-module.d.ts
13
- declare const module: <E extends Env = Env>(options: Omit<ServeStaticOptions<E>, "namespace">) => MiddlewareHandler;
14
- //#endregion
15
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/websocket.d.ts
16
- declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, any, Omit<WSEvents<WebSocket>, 'onOpen'>>;
17
- //#endregion
18
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/conninfo.d.ts
19
- declare const getConnInfo: GetConnInfo;
20
- //#endregion
21
- export { getConnInfo, module as serveStatic, upgradeWebSocket };
@@ -1,80 +0,0 @@
1
- import { t as serveStatic$1 } from "./serve-static-Cp5adzGo.js";
2
- import { WSContext, defineWebSocketHelper } from "./ws.js";
3
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/utils.ts
4
- const getContentFromKVAsset = async (path, options) => {
5
- let ASSET_MANIFEST;
6
- if (options && options.manifest) if (typeof options.manifest === "string") ASSET_MANIFEST = JSON.parse(options.manifest);
7
- else ASSET_MANIFEST = options.manifest;
8
- else if (typeof __STATIC_CONTENT_MANIFEST === "string") ASSET_MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST);
9
- else ASSET_MANIFEST = __STATIC_CONTENT_MANIFEST;
10
- let ASSET_NAMESPACE;
11
- if (options && options.namespace) ASSET_NAMESPACE = options.namespace;
12
- else ASSET_NAMESPACE = __STATIC_CONTENT;
13
- const key = ASSET_MANIFEST[path];
14
- if (!key) return null;
15
- const content = await ASSET_NAMESPACE.get(key, { type: "stream" });
16
- if (!content) return null;
17
- return content;
18
- };
19
- //#endregion
20
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static.ts
21
- /**
22
- * @deprecated
23
- * `serveStatic` in the Cloudflare Workers adapter is deprecated.
24
- * You can serve static files directly using Cloudflare Static Assets.
25
- * @see https://developers.cloudflare.com/workers/static-assets/
26
- * Cloudflare Static Assets is currently in open beta. If this doesn't work for you,
27
- * please consider using Cloudflare Pages.
28
- */
29
- const serveStatic = (options = {}) => {
30
- return async function serveStatic(c, next) {
31
- const getContent = async (path) => {
32
- return getContentFromKVAsset(path, {
33
- manifest: options.manifest,
34
- namespace: options.namespace ? options.namespace : c.env ? c.env.__STATIC_CONTENT : void 0
35
- });
36
- };
37
- return serveStatic$1({
38
- ...options,
39
- getContent
40
- })(c, next);
41
- };
42
- };
43
- //#endregion
44
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/serve-static-module.ts
45
- const module = (options) => {
46
- return serveStatic(options);
47
- };
48
- //#endregion
49
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/websocket.ts
50
- const upgradeWebSocket = defineWebSocketHelper(async (c, events) => {
51
- if (c.req.header("Upgrade") !== "websocket") return;
52
- const webSocketPair = new WebSocketPair();
53
- const client = webSocketPair[0];
54
- const server = webSocketPair[1];
55
- const wsContext = new WSContext({
56
- close: (code, reason) => server.close(code, reason),
57
- get protocol() {
58
- return server.protocol;
59
- },
60
- raw: server,
61
- get readyState() {
62
- return server.readyState;
63
- },
64
- url: server.url ? new URL(server.url) : null,
65
- send: (source) => server.send(source)
66
- });
67
- if (events.onClose) server.addEventListener("close", (evt) => events.onClose?.(evt, wsContext));
68
- if (events.onMessage) server.addEventListener("message", (evt) => events.onMessage?.(evt, wsContext));
69
- if (events.onError) server.addEventListener("error", (evt) => events.onError?.(evt, wsContext));
70
- server.accept?.();
71
- return new Response(null, {
72
- status: 101,
73
- webSocket: client
74
- });
75
- });
76
- //#endregion
77
- //#region ../../plugins/acryl-router/src/core/adapter/cloudflare-workers/conninfo.ts
78
- const getConnInfo = (c) => ({ remote: { address: c.req.header("cf-connecting-ip") } });
79
- //#endregion
80
- export { getConnInfo, module as serveStatic, upgradeWebSocket };
@@ -1,10 +0,0 @@
1
- import { t as Acryl } from "./app-BM0rTCp7.js";
2
- //#region ../../plugins/acryl-router/src/deprecated.ts
3
- /**
4
- * The 0.4 names, kept for one release so code written against them keeps working: `App` is now `Acryl` and `AppRequest` is now `AcrylRequest`,
5
- * the upstream names with the project renamed. Not part of the ported core; both the plugin's root and the public package's root export these.
6
- */
7
- /** @deprecated Use `Acryl` (`new Acryl()`); `App` is the 0.4 name and goes away in the next release. */
8
- const App = Acryl;
9
- //#endregion
10
- export { App as t };
@@ -1,12 +0,0 @@
1
- import { Y as Schema, g as BlankSchema, j as Input, m as BlankEnv, s as AcrylRequest, v as Env } from "./context-DS3fYyG-.js";
2
- import { t as Acryl } from "./app-D8riatvv.js";
3
-
4
- //#region ../../plugins/acryl-router/src/deprecated.d.ts
5
- /** @deprecated Use `Acryl` (`new Acryl()`); `App` is the 0.4 name and goes away in the next release. */
6
- declare const App: typeof Acryl;
7
- /** @deprecated Use `Acryl`; `App` is the 0.4 name and goes away in the next release. */
8
- type App<E extends Env = BlankEnv, S extends Schema = BlankSchema, BasePath extends string = '/'> = Acryl<E, S, BasePath>;
9
- /** @deprecated Use `AcrylRequest`; `AppRequest` is the 0.4 name and goes away in the next release. */
10
- type AppRequest<P extends string = '/', I extends Input['out'] = {}> = AcrylRequest<P, I>;
11
- //#endregion
12
- export { AppRequest as n, App as t };