@adonix.org/cloud-spark 0.0.37 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ declare enum Method {
18
18
  OPTIONS = "OPTIONS"
19
19
  }
20
20
  declare function isMethod(value: string): value is Method;
21
+ declare function ensure<K, V>(map: Map<K, V>, key: K, factory: () => V): V;
21
22
  declare function getContentType(type: MimeType): string;
22
23
  declare enum MimeType {
23
24
  PLAIN_TEXT = "text/plain",
@@ -157,8 +158,8 @@ declare abstract class BasicWorker implements CorsProvider {
157
158
  protected get requestUrl(): URL;
158
159
  protected get env(): Env;
159
160
  protected get ctx(): ExecutionContext | undefined;
160
- protected dispatch(request?: Request): Promise<Response>;
161
161
  fetch(): Promise<Response>;
162
+ protected dispatch(request: Request): Promise<Response>;
162
163
  protected get(): Response | Promise<Response>;
163
164
  protected put(): Response | Promise<Response>;
164
165
  protected post(): Response | Promise<Response>;
@@ -175,13 +176,27 @@ declare abstract class BasicWorker implements CorsProvider {
175
176
  getOrigin(): string | null;
176
177
  }
177
178
 
179
+ type RouteCallback = (...matches: string[]) => Response | Promise<Response>;
180
+ type RouteInit = [Method, string, RouteCallback];
181
+ declare class Route {
182
+ callback: RouteCallback;
183
+ readonly pattern: RegExp;
184
+ constructor(pattern: RegExp | string, callback: RouteCallback);
185
+ }
186
+ declare class Routes {
187
+ private readonly worker;
188
+ private routes;
189
+ constructor(worker: RoutedWorker);
190
+ append(method: Method, route: Route): this;
191
+ get(method: Method, url: string): Route | undefined;
192
+ }
193
+
178
194
  declare abstract class RoutedWorker extends BasicWorker {
179
195
  private readonly routes;
180
196
  constructor(request: Request, env?: Env, ctx?: ExecutionContext);
181
- protected abstract addRoutes(): void;
182
- protected addRoute(route: string | RegExp, callback: (...matches: string[]) => Response | Promise<Response>, method?: Method): void;
183
- protected dispatch(request?: Request): Promise<Response>;
184
- private search;
197
+ protected initialize(routes: RouteInit[]): void;
198
+ protected addRoute(route: RouteInit): this;
199
+ protected dispatch(request: Request): Promise<Response>;
185
200
  protected get(): Response | Promise<Response>;
186
201
  protected put(): Response | Promise<Response>;
187
202
  protected post(): Response | Promise<Response>;
@@ -189,4 +204,4 @@ declare abstract class RoutedWorker extends BasicWorker {
189
204
  protected delete(): Response | Promise<Response>;
190
205
  }
191
206
 
192
- export { BadRequest, BasicWorker, type CorsProvider, type ErrorJson, ErrorResponse, Forbidden, Head, HtmlResponse, InternalServerError, JsonResponse, Method, MethodNotAllowed, MimeType, NotFound, NotImplemented, Options, RoutedWorker, TextResponse, Time, Unauthorized, WorkerResponse, getContentType, isMethod };
207
+ export { BadRequest, BasicWorker, type CorsProvider, type ErrorJson, ErrorResponse, Forbidden, Head, HtmlResponse, InternalServerError, JsonResponse, Method, MethodNotAllowed, MimeType, NotFound, NotImplemented, Options, Route, type RouteCallback, type RouteInit, RoutedWorker, Routes, TextResponse, Time, Unauthorized, WorkerResponse, ensure, getContentType, isMethod };
package/dist/index.js CHANGED
@@ -9,20 +9,28 @@ var Time = {
9
9
  Day: 60 * 60 * 24,
10
10
  Week: 60 * 60 * 24 * 7
11
11
  };
12
- var Method = /* @__PURE__ */ ((Method3) => {
13
- Method3["GET"] = "GET";
14
- Method3["PUT"] = "PUT";
15
- Method3["POST"] = "POST";
16
- Method3["PATCH"] = "PATCH";
17
- Method3["DELETE"] = "DELETE";
18
- Method3["HEAD"] = "HEAD";
19
- Method3["OPTIONS"] = "OPTIONS";
20
- return Method3;
12
+ var Method = /* @__PURE__ */ ((Method4) => {
13
+ Method4["GET"] = "GET";
14
+ Method4["PUT"] = "PUT";
15
+ Method4["POST"] = "POST";
16
+ Method4["PATCH"] = "PATCH";
17
+ Method4["DELETE"] = "DELETE";
18
+ Method4["HEAD"] = "HEAD";
19
+ Method4["OPTIONS"] = "OPTIONS";
20
+ return Method4;
21
21
  })(Method || {});
22
22
  var METHOD_SET = new Set(Object.values(Method));
23
23
  function isMethod(value) {
24
24
  return METHOD_SET.has(value);
25
25
  }
26
+ function ensure(map, key, factory) {
27
+ let value = map.get(key);
28
+ if (value === void 0) {
29
+ value = factory();
30
+ map.set(key, value);
31
+ }
32
+ return value;
33
+ }
26
34
  function getContentType(type) {
27
35
  if (ADD_CHARSET.has(type)) {
28
36
  return `${type}; charset=utf-8`;
@@ -277,8 +285,17 @@ var BasicWorker = class {
277
285
  get ctx() {
278
286
  return this._ctx;
279
287
  }
288
+ async fetch() {
289
+ if (!this.isAllowed(this.request.method)) {
290
+ return this.getResponse(MethodNotAllowed, this.request.method);
291
+ }
292
+ try {
293
+ return this.dispatch(this.request);
294
+ } catch (error) {
295
+ return this.getResponse(InternalServerError, String(error));
296
+ }
297
+ }
280
298
  async dispatch(request) {
281
- request ??= this.request;
282
299
  const method = request.method;
283
300
  switch (method) {
284
301
  case "GET" /* GET */:
@@ -299,16 +316,6 @@ var BasicWorker = class {
299
316
  return this.getResponse(MethodNotAllowed, method);
300
317
  }
301
318
  }
302
- async fetch() {
303
- if (!this.isAllowed(this.request.method)) {
304
- return this.getResponse(MethodNotAllowed, this.request.method);
305
- }
306
- try {
307
- return this.dispatch(this.request);
308
- } catch (error) {
309
- return this.getResponse(InternalServerError, String(error));
310
- }
311
- }
312
319
  get() {
313
320
  return this.getResponse(NotImplemented);
314
321
  }
@@ -330,7 +337,9 @@ var BasicWorker = class {
330
337
  async head() {
331
338
  return this.getResponse(
332
339
  Head,
333
- await this.dispatch(new Request(this.request, { method: "GET" /* GET */ }))
340
+ await this.dispatch(
341
+ new Request(this.request, { method: "GET" /* GET */ })
342
+ )
334
343
  );
335
344
  }
336
345
  getResponse(ResponseClass, ...args) {
@@ -349,51 +358,58 @@ var BasicWorker = class {
349
358
  return ["Content-Type"];
350
359
  }
351
360
  getMaxAge() {
352
- return Time.Day;
361
+ return Time.Week;
353
362
  }
354
363
  getOrigin() {
355
364
  return this.request.headers.get("Origin");
356
365
  }
357
366
  };
358
367
 
368
+ // src/route.ts
369
+ var Route = class {
370
+ constructor(pattern, callback) {
371
+ this.callback = callback;
372
+ this.pattern = new RegExp(pattern);
373
+ }
374
+ pattern;
375
+ };
376
+ var Routes = class {
377
+ constructor(worker) {
378
+ this.worker = worker;
379
+ }
380
+ routes = /* @__PURE__ */ new Map();
381
+ append(method, route) {
382
+ const boundRoute = new Route(route.pattern, route.callback.bind(this.worker));
383
+ ensure(this.routes, method, () => []).push(boundRoute);
384
+ return this;
385
+ }
386
+ get(method, url) {
387
+ const array = this.routes.get(method);
388
+ if (!array) return void 0;
389
+ return array.find(({ pattern }) => pattern.test(new URL(url).pathname));
390
+ }
391
+ };
392
+
359
393
  // src/routed-worker.ts
360
394
  var RoutedWorker = class extends BasicWorker {
361
- routes = /* @__PURE__ */ new Map();
395
+ routes = new Routes(this);
362
396
  constructor(request, env = {}, ctx) {
363
397
  super(request, env, ctx);
364
- this.addRoutes();
365
398
  }
366
- addRoute(route, callback, method = "GET" /* GET */) {
367
- if (!this.isAllowed(method)) {
368
- throw new Error(
369
- `${method} is not currently allowed. Update or override getAllowedMethods()`
370
- );
371
- }
372
- const bound = callback.bind(this);
373
- const handlers = this.routes.get(method) ?? [];
374
- handlers.push({ route, callback: bound });
375
- this.routes.set(method, handlers);
399
+ initialize(routes) {
400
+ routes.forEach((route) => {
401
+ this.addRoute(route);
402
+ });
376
403
  }
377
- async dispatch(request) {
378
- request ??= this.request;
379
- return await this.search(request) ?? super.dispatch(request);
404
+ addRoute(route) {
405
+ this.routes.append(route[0], new Route(route[1], route[2]));
406
+ return this;
380
407
  }
381
- async search(request) {
382
- const method = request.method;
383
- const url = new URL(request.url);
384
- const handlers = this.routes.get(method) ?? [];
385
- const handler = handlers.find(
386
- ({ route }) => route instanceof RegExp ? route.test(url.pathname) : route === url.pathname
387
- );
388
- if (handler) {
389
- if (handler.route instanceof RegExp) {
390
- const match = url.pathname.match(handler.route);
391
- return await handler.callback(...match ?? []);
392
- } else {
393
- return await handler.callback();
394
- }
395
- }
396
- return void 0;
408
+ async dispatch(request) {
409
+ const route = this.routes.get(request.method, request.url);
410
+ if (!route) return await super.dispatch(request);
411
+ const match = this.requestUrl.pathname.match(route.pattern);
412
+ return await route.callback(...match ?? []);
397
413
  }
398
414
  get() {
399
415
  return this.getResponse(NotFound);
@@ -426,12 +442,15 @@ export {
426
442
  NotFound,
427
443
  NotImplemented,
428
444
  Options,
445
+ Route,
429
446
  RoutedWorker,
447
+ Routes,
430
448
  StatusCodes2 as StatusCodes,
431
449
  TextResponse,
432
450
  Time,
433
451
  Unauthorized,
434
452
  WorkerResponse,
453
+ ensure,
435
454
  getContentType,
436
455
  isMethod
437
456
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/common.ts","../src/response.ts","../src/basic-worker.ts","../src/routed-worker.ts"],"sourcesContent":["/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { StatusCodes } from \"http-status-codes\";\n\nexport * from \"./common\";\nexport * from \"./response\";\nexport * from \"./basic-worker\";\nexport * from \"./routed-worker\";\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const Time = {\n Second: 1,\n Minute: 60,\n Hour: 60 * 60,\n Day: 60 * 60 * 24,\n Week: 60 * 60 * 24 * 7,\n} as const;\n\nexport enum Method {\n GET = \"GET\",\n PUT = \"PUT\",\n POST = \"POST\",\n PATCH = \"PATCH\",\n DELETE = \"DELETE\",\n HEAD = \"HEAD\",\n OPTIONS = \"OPTIONS\",\n}\n\nconst METHOD_SET: Set<string> = new Set(Object.values(Method));\n\nexport function isMethod(value: string): value is Method {\n return METHOD_SET.has(value);\n}\n\nexport function getContentType(type: MimeType): string {\n if (ADD_CHARSET.has(type)) {\n return `${type}; charset=utf-8`;\n }\n return type;\n}\n\nexport enum MimeType {\n PLAIN_TEXT = \"text/plain\",\n HTML = \"text/html\",\n CSS = \"text/css\",\n CSV = \"text/csv\",\n XML = \"text/xml\",\n MARKDOWN = \"text/markdown\",\n RICH_TEXT = \"text/richtext\",\n JSON = \"application/json\",\n XML_APP = \"application/xml\",\n YAML = \"application/x-yaml\",\n FORM_URLENCODED = \"application/x-www-form-urlencoded\",\n NDJSON = \"application/x-ndjson\",\n MSGPACK = \"application/x-msgpack\",\n PROTOBUF = \"application/x-protobuf\",\n MULTIPART_FORM_DATA = \"multipart/form-data\",\n MULTIPART_MIXED = \"multipart/mixed\",\n MULTIPART_ALTERNATIVE = \"multipart/alternative\",\n MULTIPART_DIGEST = \"multipart/digest\",\n MULTIPART_RELATED = \"multipart/related\",\n MULTIPART_SIGNED = \"multipart/signed\",\n MULTIPART_ENCRYPTED = \"multipart/encrypted\",\n OCTET_STREAM = \"application/octet-stream\",\n PDF = \"application/pdf\",\n ZIP = \"application/zip\",\n GZIP = \"application/gzip\",\n MSWORD = \"application/msword\",\n DOCX = \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n EXCEL = \"application/vnd.ms-excel\",\n XLSX = \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n POWERPOINT = \"application/vnd.ms-powerpoint\",\n PPTX = \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n ICO = \"image/x-icon\",\n ICO_MS = \"image/vnd.microsoft.icon\",\n GIF = \"image/gif\",\n PNG = \"image/png\",\n JPEG = \"image/jpeg\",\n WEBP = \"image/webp\",\n SVG = \"image/svg+xml\",\n HEIF = \"image/heif\",\n AVIF = \"image/avif\",\n EVENT_STREAM = \"text/event-stream\",\n TAR = \"application/x-tar\",\n BZIP2 = \"application/x-bzip2\",\n}\n\nconst ADD_CHARSET: Set<MimeType> = new Set([\n MimeType.PLAIN_TEXT,\n MimeType.HTML,\n MimeType.CSS,\n MimeType.CSV,\n MimeType.MARKDOWN,\n MimeType.XML,\n MimeType.JSON,\n MimeType.XML_APP,\n MimeType.FORM_URLENCODED,\n MimeType.NDJSON,\n MimeType.RICH_TEXT,\n MimeType.SVG,\n]);\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getReasonPhrase, StatusCodes } from \"http-status-codes\";\nimport { getContentType, Method, MimeType } from \"./common\";\n\nexport interface CorsProvider {\n getOrigin(): string | null;\n getAllowOrigins(): string[];\n getAllowMethods(): Method[];\n getAllowHeaders(): string[];\n getMaxAge(): number;\n}\n\nexport interface ErrorJson {\n code: number;\n error: string;\n details: string;\n}\n\nexport class WorkerResponse {\n private _headers: Headers = new Headers();\n private _body: BodyInit | null;\n\n constructor(\n protected readonly cors: CorsProvider,\n content: string | null = null,\n protected readonly code: StatusCodes = StatusCodes.OK,\n protected readonly mimeType: MimeType = MimeType.JSON\n ) {\n this._body = this.code === StatusCodes.NO_CONTENT ? null : content;\n }\n\n public createResponse(): Response {\n this.addCorsHeaders();\n if (this.body) {\n this.headers.set(\"Content-Type\", getContentType(this.mimeType));\n }\n return new Response(this.body, this.responseInit);\n }\n\n protected get responseInit(): ResponseInit {\n return {\n headers: this.headers,\n status: this.code,\n statusText: getReasonPhrase(this.code),\n };\n }\n\n protected get body(): BodyInit | null {\n return this._body;\n }\n\n protected get headers(): Headers {\n return this._headers;\n }\n\n protected set headers(headers: Headers) {\n this._headers = headers;\n }\n\n protected addCorsHeaders(): void {\n const origin = this.cors.getOrigin();\n if (!origin) return; // no Origin, skip CORS\n\n if (this.getAllowOrigins().includes(\"*\")) {\n this.headers.set(\"Access-Control-Allow-Origin\", \"*\");\n } else if (this.getAllowOrigins().includes(origin)) {\n this.headers.set(\"Access-Control-Allow-Origin\", origin);\n this.headers.set(\"Access-Control-Allow-Credentials\", \"true\");\n this.headers.set(\"Vary\", \"Origin\");\n }\n this.headers.set(\n \"Access-Control-Allow-Headers\",\n this.getAllowHeaders()\n );\n this.headers.set(\n \"Access-Control-Allow-Methods\",\n this.getAllowMethods()\n );\n this.headers.set(\"Access-Control-Max-Age\", this.getMaxAge());\n this.headers.set(\"X-Content-Type-Options\", \"nosniff\");\n }\n\n protected getAllowMethods(): string {\n return this.cors.getAllowMethods().join(\", \");\n }\n\n protected getAllowHeaders(): string {\n return this.cors.getAllowHeaders().join(\", \");\n }\n\n protected getAllowOrigins(): string[] {\n return this.cors.getAllowOrigins();\n }\n\n protected getMaxAge(): string {\n return String(this.cors.getMaxAge());\n }\n}\n\nexport class JsonResponse extends WorkerResponse {\n private _json: object;\n constructor(\n cors: CorsProvider,\n content: object = {},\n code: StatusCodes = StatusCodes.OK\n ) {\n super(cors, null, code, MimeType.JSON);\n this._json = content;\n }\n\n public get json(): object {\n return this._json;\n }\n\n public set json(json: object) {\n this._json = json;\n }\n\n protected override get body(): string {\n return JSON.stringify(this.json);\n }\n}\n\nexport class HtmlResponse extends WorkerResponse {\n constructor(\n cors: CorsProvider,\n content: string,\n code: StatusCodes = StatusCodes.OK,\n type: MimeType = MimeType.HTML\n ) {\n super(cors, content, code, type);\n }\n}\n\nexport class TextResponse extends WorkerResponse {\n constructor(\n cors: CorsProvider,\n content: string,\n code: StatusCodes = StatusCodes.OK,\n type: MimeType = MimeType.PLAIN_TEXT\n ) {\n super(cors, content, code, type);\n }\n}\n\n/**\n * Remove the body from a GET response.\n */\nexport class Head extends WorkerResponse {\n constructor(cors: CorsProvider, response: Response) {\n super(cors, null, response.status);\n this.headers = new Headers(response.headers);\n }\n}\n\nexport class Options extends WorkerResponse {\n constructor(cors: CorsProvider) {\n super(cors, null, StatusCodes.NO_CONTENT);\n this.headers.set(\"Allow\", this.getAllowMethods());\n }\n}\n\nexport class ErrorResponse extends JsonResponse {\n constructor(\n cors: CorsProvider,\n code: StatusCodes,\n protected details?: string\n ) {\n super(cors, {}, code);\n }\n\n public override get json(): ErrorJson {\n return {\n code: this.code,\n error: getReasonPhrase(this.code),\n details: this.details ?? getReasonPhrase(this.code),\n };\n }\n}\n\nexport class BadRequest extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.BAD_REQUEST, detail);\n }\n}\n\nexport class Unauthorized extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.UNAUTHORIZED, detail);\n }\n}\n\nexport class Forbidden extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.FORBIDDEN, detail);\n }\n}\n\nexport class NotFound extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.NOT_FOUND, detail);\n }\n}\n\nexport class MethodNotAllowed extends ErrorResponse {\n constructor(cors: CorsProvider, method: string) {\n super(\n cors,\n StatusCodes.METHOD_NOT_ALLOWED,\n `${method} method not allowed.`\n );\n this.headers.set(\"Allow\", this.getAllowMethods());\n }\n\n public override get json(): ErrorJson & { allowed: Method[] } {\n return {\n ...super.json,\n allowed: this.cors.getAllowMethods(),\n };\n }\n}\n\nexport class InternalServerError extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.INTERNAL_SERVER_ERROR, detail);\n }\n}\n\nexport class NotImplemented extends ErrorResponse {\n constructor(cors: CorsProvider) {\n super(cors, StatusCodes.NOT_IMPLEMENTED);\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { isMethod, Method, Time } from \"./common\";\nimport {\n CorsProvider,\n Head,\n InternalServerError,\n MethodNotAllowed,\n NotImplemented,\n Options,\n WorkerResponse,\n} from \"./response\";\n\nexport abstract class BasicWorker implements CorsProvider {\n private readonly _requestUrl: URL;\n\n constructor(\n private readonly _request: Request,\n private readonly _env: Env = {},\n private readonly _ctx?: ExecutionContext\n ) {\n this._requestUrl = new URL(this.request.url);\n }\n\n protected get request(): Request {\n return this._request;\n }\n\n protected get requestUrl(): URL {\n return this._requestUrl;\n }\n\n protected get env(): Env {\n return this._env;\n }\n\n protected get ctx(): ExecutionContext | undefined {\n return this._ctx;\n }\n\n protected async dispatch(request?: Request): Promise<Response> {\n request ??= this.request;\n const method = request.method as Method;\n switch (method) {\n case Method.GET:\n return await this.get();\n case Method.PUT:\n return await this.put();\n case Method.POST:\n return await this.post();\n case Method.PATCH:\n return await this.patch();\n case Method.DELETE:\n return await this.delete();\n case Method.HEAD:\n return await this.head();\n case Method.OPTIONS:\n return await this.options();\n default:\n return this.getResponse(MethodNotAllowed, method);\n }\n }\n\n public async fetch(): Promise<Response> {\n if (!this.isAllowed(this.request.method)) {\n return this.getResponse(MethodNotAllowed, this.request.method);\n }\n\n try {\n return this.dispatch(this.request);\n } catch (error) {\n return this.getResponse(InternalServerError, String(error));\n }\n }\n\n protected get(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected put(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected post(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected patch(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected delete(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected options(): Response | Promise<Response> {\n return this.getResponse(Options);\n }\n\n protected async head(): Promise<Response> {\n // For HEAD method, we need to create a new GET request and\n // pass through normal processing. Body is then removed from\n // the GET response and passed back.\n return this.getResponse(\n Head,\n await this.dispatch(new Request(this.request, { method: Method.GET }))\n );\n }\n\n protected getResponse<\n T extends WorkerResponse,\n Ctor extends new (cors: CorsProvider, ...args: any[]) => T\n >(\n ResponseClass: Ctor,\n ...args: ConstructorParameters<Ctor> extends [any, ...infer R]\n ? R\n : never\n ): Response {\n return new ResponseClass(this, ...args).createResponse();\n }\n\n public getAllowOrigins(): string[] {\n return [\"*\"];\n }\n\n public getAllowMethods(): Method[] {\n return [Method.GET, Method.OPTIONS, Method.HEAD];\n }\n\n public isAllowed(method: string): boolean {\n return isMethod(method) && this.getAllowMethods().includes(method);\n }\n\n public getAllowHeaders(): string[] {\n return [\"Content-Type\"];\n }\n\n public getMaxAge(): number {\n return Time.Day;\n }\n\n public getOrigin(): string | null {\n return this.request.headers.get(\"Origin\");\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BasicWorker } from \"./basic-worker\";\nimport { Method } from \"./common\";\nimport { NotFound } from \"./response\";\n\ninterface RouteHandler {\n route: string | RegExp;\n callback: (...matches: string[]) => Response | Promise<Response>;\n}\n\nexport abstract class RoutedWorker extends BasicWorker {\n private readonly routes: Map<Method, RouteHandler[]> = new Map();\n\n constructor(request: Request, env: Env = {}, ctx?: ExecutionContext) {\n super(request, env, ctx);\n this.addRoutes();\n }\n\n protected abstract addRoutes(): void;\n\n protected addRoute(\n route: string | RegExp,\n callback: (...matches: string[]) => Response | Promise<Response>,\n method: Method = Method.GET\n ): void {\n if (!this.isAllowed(method)) {\n throw new Error(\n `${method} is not currently allowed. Update or override getAllowedMethods()`\n );\n }\n\n const bound = callback.bind(this);\n const handlers = this.routes.get(method) ?? [];\n handlers.push({ route, callback: bound });\n this.routes.set(method, handlers);\n }\n\n protected async dispatch(request?: Request): Promise<Response> {\n request ??= this.request;\n return (await this.search(request)) ?? super.dispatch(request);\n }\n\n private async search(request: Request): Promise<Response | undefined> {\n const method = request.method as Method;\n const url = new URL(request.url);\n const handlers = this.routes.get(method) ?? [];\n const handler = handlers.find(({ route }) =>\n route instanceof RegExp\n ? route.test(url.pathname)\n : route === url.pathname\n );\n if (handler) {\n if (handler.route instanceof RegExp) {\n const match = url.pathname.match(handler.route);\n return await handler.callback(...(match ?? []));\n } else {\n return await handler.callback();\n }\n }\n return undefined;\n }\n\n protected override get(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override put(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override post(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override patch(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override delete(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n}\n"],"mappings":";AAgBA,SAAS,eAAAA,oBAAmB;;;ACArB,IAAM,OAAO;AAAA,EAChB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM,KAAK;AAAA,EACX,KAAK,KAAK,KAAK;AAAA,EACf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,OAAO,SAAiD;AAClE,UAAM,SAAS,QAAQ;AACvB,UAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,UAAM,WAAW,KAAK,OAAO,IAAI,MAAM,KAAK,CAAC;AAC7C,UAAM,UAAU,SAAS;AAAA,MAAK,CAAC,EAAE,MAAM,MACnC,iBAAiB,SACX,MAAM,KAAK,IAAI,QAAQ,IACvB,UAAU,IAAI;AAAA,IACxB;AACA,QAAI,SAAS;AACT,UAAI,QAAQ,iBAAiB,QAAQ;AACjC,cAAM,QAAQ,IAAI,SAAS,MAAM,QAAQ,KAAK;AAC9C,eAAO,MAAM,QAAQ,SAAS,GAAI,SAAS,CAAC,CAAE;AAAA,MAClD,OAAO;AACH,eAAO,MAAM,QAAQ,SAAS;AAAA,MAClC;AAAA,IACJ;AACA,WAAO;AAAA,EACX;AAAA,EAEmB,MAAoC;AACnD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,MAAoC;AACnD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,OAAqC;AACpD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,QAAsC;AACrD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,SAAuC;AACtD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AACJ;","names":["StatusCodes","Method","MimeType"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/common.ts","../src/response.ts","../src/basic-worker.ts","../src/route.ts","../src/routed-worker.ts"],"sourcesContent":["/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { StatusCodes } from \"http-status-codes\";\n\nexport * from \"./common\";\nexport * from \"./response\";\nexport * from \"./basic-worker\";\nexport * from \"./routed-worker\";\nexport * from \"./route\";\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const Time = {\n Second: 1,\n Minute: 60,\n Hour: 60 * 60,\n Day: 60 * 60 * 24,\n Week: 60 * 60 * 24 * 7,\n} as const;\n\nexport enum Method {\n GET = \"GET\",\n PUT = \"PUT\",\n POST = \"POST\",\n PATCH = \"PATCH\",\n DELETE = \"DELETE\",\n HEAD = \"HEAD\",\n OPTIONS = \"OPTIONS\",\n}\n\nconst METHOD_SET: Set<string> = new Set(Object.values(Method));\n\nexport function isMethod(value: string): value is Method {\n return METHOD_SET.has(value);\n}\n\nexport function ensure<K, V>(map: Map<K, V>, key: K, factory: () => V): V {\n let value = map.get(key);\n if (value === undefined) {\n value = factory();\n map.set(key, value);\n }\n return value;\n}\n\nexport function getContentType(type: MimeType): string {\n if (ADD_CHARSET.has(type)) {\n return `${type}; charset=utf-8`;\n }\n return type;\n}\n\nexport enum MimeType {\n PLAIN_TEXT = \"text/plain\",\n HTML = \"text/html\",\n CSS = \"text/css\",\n CSV = \"text/csv\",\n XML = \"text/xml\",\n MARKDOWN = \"text/markdown\",\n RICH_TEXT = \"text/richtext\",\n JSON = \"application/json\",\n XML_APP = \"application/xml\",\n YAML = \"application/x-yaml\",\n FORM_URLENCODED = \"application/x-www-form-urlencoded\",\n NDJSON = \"application/x-ndjson\",\n MSGPACK = \"application/x-msgpack\",\n PROTOBUF = \"application/x-protobuf\",\n MULTIPART_FORM_DATA = \"multipart/form-data\",\n MULTIPART_MIXED = \"multipart/mixed\",\n MULTIPART_ALTERNATIVE = \"multipart/alternative\",\n MULTIPART_DIGEST = \"multipart/digest\",\n MULTIPART_RELATED = \"multipart/related\",\n MULTIPART_SIGNED = \"multipart/signed\",\n MULTIPART_ENCRYPTED = \"multipart/encrypted\",\n OCTET_STREAM = \"application/octet-stream\",\n PDF = \"application/pdf\",\n ZIP = \"application/zip\",\n GZIP = \"application/gzip\",\n MSWORD = \"application/msword\",\n DOCX = \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n EXCEL = \"application/vnd.ms-excel\",\n XLSX = \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n POWERPOINT = \"application/vnd.ms-powerpoint\",\n PPTX = \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n ICO = \"image/x-icon\",\n ICO_MS = \"image/vnd.microsoft.icon\",\n GIF = \"image/gif\",\n PNG = \"image/png\",\n JPEG = \"image/jpeg\",\n WEBP = \"image/webp\",\n SVG = \"image/svg+xml\",\n HEIF = \"image/heif\",\n AVIF = \"image/avif\",\n EVENT_STREAM = \"text/event-stream\",\n TAR = \"application/x-tar\",\n BZIP2 = \"application/x-bzip2\",\n}\n\nconst ADD_CHARSET: Set<MimeType> = new Set([\n MimeType.PLAIN_TEXT,\n MimeType.HTML,\n MimeType.CSS,\n MimeType.CSV,\n MimeType.MARKDOWN,\n MimeType.XML,\n MimeType.JSON,\n MimeType.XML_APP,\n MimeType.FORM_URLENCODED,\n MimeType.NDJSON,\n MimeType.RICH_TEXT,\n MimeType.SVG,\n]);\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getReasonPhrase, StatusCodes } from \"http-status-codes\";\nimport { getContentType, Method, MimeType } from \"./common\";\n\nexport interface CorsProvider {\n getOrigin(): string | null;\n getAllowOrigins(): string[];\n getAllowMethods(): Method[];\n getAllowHeaders(): string[];\n getMaxAge(): number;\n}\n\nexport interface ErrorJson {\n code: number;\n error: string;\n details: string;\n}\n\nexport class WorkerResponse {\n private _headers: Headers = new Headers();\n private _body: BodyInit | null;\n\n constructor(\n protected readonly cors: CorsProvider,\n content: string | null = null,\n protected readonly code: StatusCodes = StatusCodes.OK,\n protected readonly mimeType: MimeType = MimeType.JSON\n ) {\n this._body = this.code === StatusCodes.NO_CONTENT ? null : content;\n }\n\n public createResponse(): Response {\n this.addCorsHeaders();\n if (this.body) {\n this.headers.set(\"Content-Type\", getContentType(this.mimeType));\n }\n return new Response(this.body, this.responseInit);\n }\n\n protected get responseInit(): ResponseInit {\n return {\n headers: this.headers,\n status: this.code,\n statusText: getReasonPhrase(this.code),\n };\n }\n\n protected get body(): BodyInit | null {\n return this._body;\n }\n\n protected get headers(): Headers {\n return this._headers;\n }\n\n protected set headers(headers: Headers) {\n this._headers = headers;\n }\n\n protected addCorsHeaders(): void {\n const origin = this.cors.getOrigin();\n if (!origin) return; // no Origin, skip CORS\n\n if (this.getAllowOrigins().includes(\"*\")) {\n this.headers.set(\"Access-Control-Allow-Origin\", \"*\");\n } else if (this.getAllowOrigins().includes(origin)) {\n this.headers.set(\"Access-Control-Allow-Origin\", origin);\n this.headers.set(\"Access-Control-Allow-Credentials\", \"true\");\n this.headers.set(\"Vary\", \"Origin\");\n }\n this.headers.set(\n \"Access-Control-Allow-Headers\",\n this.getAllowHeaders()\n );\n this.headers.set(\n \"Access-Control-Allow-Methods\",\n this.getAllowMethods()\n );\n this.headers.set(\"Access-Control-Max-Age\", this.getMaxAge());\n this.headers.set(\"X-Content-Type-Options\", \"nosniff\");\n }\n\n protected getAllowMethods(): string {\n return this.cors.getAllowMethods().join(\", \");\n }\n\n protected getAllowHeaders(): string {\n return this.cors.getAllowHeaders().join(\", \");\n }\n\n protected getAllowOrigins(): string[] {\n return this.cors.getAllowOrigins();\n }\n\n protected getMaxAge(): string {\n return String(this.cors.getMaxAge());\n }\n}\n\nexport class JsonResponse extends WorkerResponse {\n private _json: object;\n constructor(\n cors: CorsProvider,\n content: object = {},\n code: StatusCodes = StatusCodes.OK\n ) {\n super(cors, null, code, MimeType.JSON);\n this._json = content;\n }\n\n public get json(): object {\n return this._json;\n }\n\n public set json(json: object) {\n this._json = json;\n }\n\n protected override get body(): string {\n return JSON.stringify(this.json);\n }\n}\n\nexport class HtmlResponse extends WorkerResponse {\n constructor(\n cors: CorsProvider,\n content: string,\n code: StatusCodes = StatusCodes.OK,\n type: MimeType = MimeType.HTML\n ) {\n super(cors, content, code, type);\n }\n}\n\nexport class TextResponse extends WorkerResponse {\n constructor(\n cors: CorsProvider,\n content: string,\n code: StatusCodes = StatusCodes.OK,\n type: MimeType = MimeType.PLAIN_TEXT\n ) {\n super(cors, content, code, type);\n }\n}\n\n/**\n * Remove the body from a GET response.\n */\nexport class Head extends WorkerResponse {\n constructor(cors: CorsProvider, response: Response) {\n super(cors, null, response.status);\n this.headers = new Headers(response.headers);\n }\n}\n\nexport class Options extends WorkerResponse {\n constructor(cors: CorsProvider) {\n super(cors, null, StatusCodes.NO_CONTENT);\n this.headers.set(\"Allow\", this.getAllowMethods());\n }\n}\n\nexport class ErrorResponse extends JsonResponse {\n constructor(\n cors: CorsProvider,\n code: StatusCodes,\n protected details?: string\n ) {\n super(cors, {}, code);\n }\n\n public override get json(): ErrorJson {\n return {\n code: this.code,\n error: getReasonPhrase(this.code),\n details: this.details ?? getReasonPhrase(this.code),\n };\n }\n}\n\nexport class BadRequest extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.BAD_REQUEST, detail);\n }\n}\n\nexport class Unauthorized extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.UNAUTHORIZED, detail);\n }\n}\n\nexport class Forbidden extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.FORBIDDEN, detail);\n }\n}\n\nexport class NotFound extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.NOT_FOUND, detail);\n }\n}\n\nexport class MethodNotAllowed extends ErrorResponse {\n constructor(cors: CorsProvider, method: string) {\n super(\n cors,\n StatusCodes.METHOD_NOT_ALLOWED,\n `${method} method not allowed.`\n );\n this.headers.set(\"Allow\", this.getAllowMethods());\n }\n\n public override get json(): ErrorJson & { allowed: Method[] } {\n return {\n ...super.json,\n allowed: this.cors.getAllowMethods(),\n };\n }\n}\n\nexport class InternalServerError extends ErrorResponse {\n constructor(cors: CorsProvider, detail?: string) {\n super(cors, StatusCodes.INTERNAL_SERVER_ERROR, detail);\n }\n}\n\nexport class NotImplemented extends ErrorResponse {\n constructor(cors: CorsProvider) {\n super(cors, StatusCodes.NOT_IMPLEMENTED);\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { isMethod, Method, Time } from \"./common\";\nimport {\n CorsProvider,\n Head,\n InternalServerError,\n MethodNotAllowed,\n NotImplemented,\n Options,\n WorkerResponse,\n} from \"./response\";\n\nexport abstract class BasicWorker implements CorsProvider {\n private readonly _requestUrl: URL;\n\n constructor(\n private readonly _request: Request,\n private readonly _env: Env = {},\n private readonly _ctx?: ExecutionContext\n ) {\n this._requestUrl = new URL(this.request.url);\n }\n\n protected get request(): Request {\n return this._request;\n }\n\n protected get requestUrl(): URL {\n return this._requestUrl;\n }\n\n protected get env(): Env {\n return this._env;\n }\n\n protected get ctx(): ExecutionContext | undefined {\n return this._ctx;\n }\n\n public async fetch(): Promise<Response> {\n if (!this.isAllowed(this.request.method)) {\n return this.getResponse(MethodNotAllowed, this.request.method);\n }\n\n try {\n return this.dispatch(this.request);\n } catch (error) {\n return this.getResponse(InternalServerError, String(error));\n }\n }\n\n protected async dispatch(request: Request): Promise<Response> {\n // Instead of using this.request, always pass in the request.\n // This enables creation of special reqeusts, for example for\n // HEAD requests.\n const method = request.method as Method;\n switch (method) {\n case Method.GET:\n return await this.get();\n case Method.PUT:\n return await this.put();\n case Method.POST:\n return await this.post();\n case Method.PATCH:\n return await this.patch();\n case Method.DELETE:\n return await this.delete();\n case Method.HEAD:\n return await this.head();\n case Method.OPTIONS:\n return await this.options();\n default:\n return this.getResponse(MethodNotAllowed, method);\n }\n }\n\n protected get(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected put(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected post(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected patch(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected delete(): Response | Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected options(): Response | Promise<Response> {\n return this.getResponse(Options);\n }\n\n protected async head(): Promise<Response> {\n // For HEAD method, we need to create a new GET request and\n // pass that through normal processing. Body is then removed\n // from the GET response and passed back as the HEAD response.\n return this.getResponse(\n Head,\n await this.dispatch(\n new Request(this.request, { method: Method.GET })\n )\n );\n }\n\n protected getResponse<\n T extends WorkerResponse,\n Ctor extends new (cors: CorsProvider, ...args: any[]) => T\n >(\n ResponseClass: Ctor,\n ...args: ConstructorParameters<Ctor> extends [any, ...infer R]\n ? R\n : never\n ): Response {\n return new ResponseClass(this, ...args).createResponse();\n }\n\n public getAllowOrigins(): string[] {\n return [\"*\"];\n }\n\n public getAllowMethods(): Method[] {\n return [Method.GET, Method.OPTIONS, Method.HEAD];\n }\n\n public isAllowed(method: string): boolean {\n return isMethod(method) && this.getAllowMethods().includes(method);\n }\n\n public getAllowHeaders(): string[] {\n return [\"Content-Type\"];\n }\n\n public getMaxAge(): number {\n return Time.Week;\n }\n\n public getOrigin(): string | null {\n return this.request.headers.get(\"Origin\");\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ensure, Method } from \"./common\";\nimport { RoutedWorker } from \"./routed-worker\";\n\nexport type RouteCallback = (...matches: string[]) => Response | Promise<Response>;\n\nexport type RouteInit = [Method, string, RouteCallback];\n\nexport class Route {\n public readonly pattern: RegExp;\n\n constructor(pattern: RegExp | string, public callback: RouteCallback) {\n this.pattern = new RegExp(pattern);\n }\n}\n\nexport class Routes {\n private routes = new Map<Method, Route[]>();\n\n constructor(private readonly worker: RoutedWorker) {}\n\n public append(method: Method, route: Route) {\n const boundRoute = new Route(route.pattern, route.callback.bind(this.worker));\n\n ensure(this.routes, method, () => []).push(boundRoute);\n\n return this;\n }\n\n public get(method: Method, url: string): Route | undefined {\n const array = this.routes.get(method);\n if (!array) return undefined;\n\n return array.find(({ pattern }) => pattern.test(new URL(url).pathname));\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BasicWorker } from \"./basic-worker\";\nimport { Method } from \"./common\";\nimport { NotFound } from \"./response\";\nimport { Route, Routes, RouteInit } from \"./route\";\n\nexport abstract class RoutedWorker extends BasicWorker {\n private readonly routes: Routes = new Routes(this);\n\n constructor(request: Request, env: Env = {}, ctx?: ExecutionContext) {\n super(request, env, ctx);\n }\n\n protected initialize(routes: RouteInit[]) {\n routes.forEach((route) => {\n this.addRoute(route);\n });\n }\n\n protected addRoute(route: RouteInit) {\n this.routes.append(route[0], new Route(route[1], route[2]));\n return this;\n }\n\n protected async dispatch(request: Request): Promise<Response> {\n const route = this.routes.get(request.method as Method, request.url);\n if (!route) return await super.dispatch(request);\n\n const match = this.requestUrl.pathname.match(route.pattern);\n return await route.callback(...(match ?? []));\n }\n\n protected override get(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override put(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override post(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override patch(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override delete(): Response | Promise<Response> {\n return this.getResponse(NotFound);\n }\n}\n"],"mappings":";AAgBA,SAAS,eAAAA,oBAAmB;;;ACArB,IAAM,OAAO;AAAA,EAChB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM,KAAK;AAAA,EACX,KAAK,KAAK,KAAK;AAAA,EACf,MAAM,KAAK,KAAK,KAAK;AACzB;AAEO,IAAK,SAAL,kBAAKC,YAAL;AACH,EAAAA,QAAA,SAAM;AACN,EAAAA,QAAA,SAAM;AACN,EAAAA,QAAA,UAAO;AACP,EAAAA,QAAA,WAAQ;AACR,EAAAA,QAAA,YAAS;AACT,EAAAA,QAAA,UAA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Af,cAAoC,YAAY;AAAA,EAClC,SAAiB,IAAI,OAAO,IAAI;AAAA,EAEjD,YAAY,SAAkB,MAAW,CAAC,GAAG,KAAwB;AACjE,UAAM,SAAS,KAAK,GAAG;AAAA,EAC3B;AAAA,EAEU,WAAW,QAAqB;AACtC,WAAO,QAAQ,CAAC,UAAU;AACtB,WAAK,SAAS,KAAK;AAAA,IACvB,CAAC;AAAA,EACL;AAAA,EAEU,SAAS,OAAkB;AACjC,SAAK,OAAO,OAAO,MAAM,CAAC,GAAG,IAAI,MAAM,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AAC1D,WAAO;AAAA,EACX;AAAA,EAEA,MAAgB,SAAS,SAAqC;AAC1D,UAAM,QAAQ,KAAK,OAAO,IAAI,QAAQ,QAAkB,QAAQ,GAAG;AACnE,QAAI,CAAC,MAAO,QAAO,MAAM,MAAM,SAAS,OAAO;AAE/C,UAAM,QAAQ,KAAK,WAAW,SAAS,MAAM,MAAM,OAAO;AAC1D,WAAO,MAAM,MAAM,SAAS,GAAI,SAAS,CAAC,CAAE;AAAA,EAChD;AAAA,EAEmB,MAAoC;AACnD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,MAAoC;AACnD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,OAAqC;AACpD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,QAAsC;AACrD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEmB,SAAuC;AACtD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AACJ;","names":["StatusCodes","Method","MimeType"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonix.org/cloud-spark",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "description": "Ignite your Cloudflare Workers with a type-safe library for rapid development.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",