@adonix.org/cloud-spark 0.0.157 → 0.0.159

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.js CHANGED
@@ -36,6 +36,9 @@ var HttpHeader;
36
36
  HttpHeader2.ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
37
37
  HttpHeader2.ACCESS_CONTROL_MAX_AGE = "Access-Control-Max-Age";
38
38
  HttpHeader2.ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers";
39
+ HttpHeader2.SEC_WEBSOCKET_VERSION = "Sec-WebSocket-Version";
40
+ HttpHeader2.CONNECTION = "Connection";
41
+ HttpHeader2.UPGRADE = "Upgrade";
39
42
  })(HttpHeader || (HttpHeader = {}));
40
43
  var Method = /* @__PURE__ */ ((Method4) => {
41
44
  Method4["GET"] = "GET";
@@ -113,6 +116,32 @@ var Time = {
113
116
  // 60 * 60 * 24 * 365
114
117
  };
115
118
 
119
+ // src/constants/websocket.ts
120
+ var WS_UPGRADE = "upgrade";
121
+ var WS_WEBSOCKET = "websocket";
122
+ var WS_VERSION = "13";
123
+ var WS_MAX_CLOSE_CODE = 4999;
124
+ var WS_MAX_REASON_CHARS = 123;
125
+ var CloseCode = {
126
+ NORMAL: 1e3,
127
+ GOING_AWAY: 1001,
128
+ PROTOCOL_ERROR: 1002,
129
+ UNSUPPORTED_DATA: 1003,
130
+ NO_STATUS: 1005,
131
+ ABNORMAL: 1006,
132
+ INVALID_PAYLOAD: 1007,
133
+ POLICY_VIOLATION: 1008,
134
+ MESSAGE_TOO_BIG: 1009,
135
+ MISSING_EXTENSION: 1010,
136
+ INTERNAL_ERROR: 1011,
137
+ TLS_HANDSHAKE: 1015
138
+ };
139
+ var WS_RESERVED_CODES = /* @__PURE__ */ new Set([
140
+ CloseCode.NO_STATUS,
141
+ CloseCode.ABNORMAL,
142
+ CloseCode.TLS_HANDSHAKE
143
+ ]);
144
+
116
145
  // src/guards/basic.ts
117
146
  function isStringArray(value) {
118
147
  return Array.isArray(value) && value.every((item) => typeof item === "string");
@@ -404,6 +433,8 @@ var BaseResponse = class {
404
433
  status = StatusCodes2.OK;
405
434
  /** Optional status text. Defaults to standard reason phrase. */
406
435
  statusText;
436
+ /** Enable websocket responses. */
437
+ webSocket = null;
407
438
  /** Default media type of the response body. */
408
439
  mediaType = "text/plain" /* PLAIN_TEXT */;
409
440
  /** Converts current state to ResponseInit for constructing a Response. */
@@ -411,7 +442,9 @@ var BaseResponse = class {
411
442
  return {
412
443
  headers: this.headers,
413
444
  status: this.status,
414
- statusText: this.statusText ?? getReasonPhrase(this.status)
445
+ statusText: this.statusText ?? getReasonPhrase(this.status),
446
+ webSocket: this.webSocket,
447
+ encodeBody: "automatic"
415
448
  };
416
449
  }
417
450
  /** Sets a header, overwriting any existing value. */
@@ -446,8 +479,8 @@ var WorkerResponse = class extends CacheResponse {
446
479
  super(cache2);
447
480
  this.body = body;
448
481
  }
449
- /** Builds the Response object with body, headers, and status. */
450
- async getResponse() {
482
+ /** Builds the Response with body, headers, and status. */
483
+ async create() {
451
484
  this.addCacheHeader();
452
485
  const body = this.status === StatusCodes2.NO_CONTENT ? null : this.body;
453
486
  if (body) this.addContentType();
@@ -487,6 +520,13 @@ var TextResponse = class extends SuccessResponse {
487
520
  this.mediaType = "text/plain" /* PLAIN_TEXT */;
488
521
  }
489
522
  };
523
+ var WebSocketResponse = class extends WorkerResponse {
524
+ constructor(client) {
525
+ super(null);
526
+ this.status = StatusCodes2.SWITCHING_PROTOCOLS;
527
+ this.webSocket = client;
528
+ }
529
+ };
490
530
  var Head = class extends WorkerResponse {
491
531
  constructor(get) {
492
532
  super();
@@ -503,6 +543,18 @@ var Options = class extends SuccessResponse {
503
543
 
504
544
  // src/middleware/cors/constants.ts
505
545
  var ALLOW_ALL_ORIGINS = "*";
546
+ var SIMPLE_METHODS = /* @__PURE__ */ new Set([GET, HEAD, OPTIONS]);
547
+ var SKIP_CORS_STATUSES = [
548
+ StatusCodes.SWITCHING_PROTOCOLS,
549
+ StatusCodes.CONTINUE,
550
+ StatusCodes.PROCESSING,
551
+ StatusCodes.EARLY_HINTS,
552
+ StatusCodes.MOVED_PERMANENTLY,
553
+ StatusCodes.MOVED_TEMPORARILY,
554
+ StatusCodes.SEE_OTHER,
555
+ StatusCodes.TEMPORARY_REDIRECT,
556
+ StatusCodes.PERMANENT_REDIRECT
557
+ ];
506
558
  var defaultCorsConfig = {
507
559
  allowedOrigins: [ALLOW_ALL_ORIGINS],
508
560
  allowedHeaders: [HttpHeader.CONTENT_TYPE],
@@ -512,7 +564,6 @@ var defaultCorsConfig = {
512
564
  };
513
565
 
514
566
  // src/middleware/cors/utils.ts
515
- var SIMPLE_METHODS = /* @__PURE__ */ new Set([GET, HEAD, OPTIONS]);
516
567
  async function options(worker, cors2) {
517
568
  const options2 = new Options();
518
569
  const origin = getOrigin(worker.request);
@@ -521,9 +572,9 @@ async function options(worker, cors2) {
521
572
  setAllowCredentials(options2.headers, cors2, origin);
522
573
  }
523
574
  setAllowMethods(options2.headers, worker);
524
- setMaxAge(options2.headers, cors2);
525
575
  setAllowHeaders(options2.headers, cors2);
526
- return options2.getResponse();
576
+ setMaxAge(options2.headers, cors2);
577
+ return options2.create();
527
578
  }
528
579
  async function apply(response, worker, cors2) {
529
580
  const clone = new ClonedResponse(response);
@@ -532,9 +583,9 @@ async function apply(response, worker, cors2) {
532
583
  if (origin) {
533
584
  setAllowOrigin(clone.headers, cors2, origin);
534
585
  setAllowCredentials(clone.headers, cors2, origin);
586
+ setExposedHeaders(clone.headers, cors2);
535
587
  }
536
- setExposedHeaders(clone.headers, cors2);
537
- return clone.getResponse();
588
+ return clone.create();
538
589
  }
539
590
  function setAllowOrigin(headers, cors2, origin) {
540
591
  if (allowAllOrigins(cors2)) {
@@ -583,6 +634,12 @@ function deleteCorsHeaders(headers) {
583
634
  headers.delete(HttpHeader.ACCESS_CONTROL_EXPOSE_HEADERS);
584
635
  headers.delete(HttpHeader.ACCESS_CONTROL_ALLOW_CREDENTIALS);
585
636
  }
637
+ function skipCors(response) {
638
+ const { status, headers } = response;
639
+ if (SKIP_CORS_STATUSES.includes(status)) return true;
640
+ if (headers.has(HttpHeader.UPGRADE)) return true;
641
+ return false;
642
+ }
586
643
 
587
644
  // src/guards/cors.ts
588
645
  function assertCorsInit(value) {
@@ -641,6 +698,7 @@ var CorsHandler = class extends Middleware {
641
698
  return options(worker, this.config);
642
699
  }
643
700
  const response = await next();
701
+ if (skipCors(response)) return response;
644
702
  return apply(response, worker, this.config);
645
703
  }
646
704
  };
@@ -691,6 +749,12 @@ var MethodNotAllowed = class extends HttpError {
691
749
  this.setHeader(HttpHeader.ALLOW, methods);
692
750
  }
693
751
  };
752
+ var UpgradeRequired = class extends HttpError {
753
+ constructor() {
754
+ super(StatusCodes3.UPGRADE_REQUIRED);
755
+ this.headers.set(HttpHeader.SEC_WEBSOCKET_VERSION, WS_VERSION);
756
+ }
757
+ };
694
758
  var InternalServerError = class extends HttpError {
695
759
  constructor(details) {
696
760
  super(StatusCodes3.INTERNAL_SERVER_ERROR, details);
@@ -712,7 +776,295 @@ var ServiceUnavailable = class extends HttpError {
712
776
  }
713
777
  };
714
778
 
715
- // src/workers/base-worker.ts
779
+ // src/middleware/websocket/utils.ts
780
+ function hasConnectionHeader(headers) {
781
+ return getHeaderValues(headers, HttpHeader.CONNECTION).some(
782
+ (value) => value.toLowerCase() === WS_UPGRADE
783
+ );
784
+ }
785
+ function hasUpgradeHeader(headers) {
786
+ return getHeaderValues(headers, HttpHeader.UPGRADE).some(
787
+ (value) => value.toLowerCase() === WS_WEBSOCKET
788
+ );
789
+ }
790
+ function hasWebSocketVersion(headers) {
791
+ return headers.get(HttpHeader.SEC_WEBSOCKET_VERSION)?.trim() === WS_VERSION;
792
+ }
793
+
794
+ // src/middleware/websocket/handler.ts
795
+ function websocket(path = "/") {
796
+ return new WebSocketHandler(path);
797
+ }
798
+ var WebSocketHandler = class extends Middleware {
799
+ constructor(path) {
800
+ super();
801
+ this.path = path;
802
+ }
803
+ handle(worker, next) {
804
+ if (worker.request.method !== GET) {
805
+ return next();
806
+ }
807
+ if (this.getPath(worker.request) !== this.path) {
808
+ return next();
809
+ }
810
+ const headers = worker.request.headers;
811
+ if (!hasConnectionHeader(headers)) {
812
+ return new BadRequest("Missing or invalid Connection header").create();
813
+ }
814
+ if (!hasUpgradeHeader(headers)) {
815
+ return new BadRequest("Missing or invalid Upgrade header").create();
816
+ }
817
+ if (!hasWebSocketVersion(headers)) {
818
+ return new UpgradeRequired().create();
819
+ }
820
+ return next();
821
+ }
822
+ getPath(request) {
823
+ return new URL(request.url).pathname;
824
+ }
825
+ };
826
+
827
+ // src/guards/websocket.ts
828
+ function isBinary(value) {
829
+ return value instanceof ArrayBuffer || ArrayBuffer.isView(value);
830
+ }
831
+ function isSendable(value) {
832
+ if (isString(value)) return value.length > 0;
833
+ if (isBinary(value)) return value.byteLength > 0;
834
+ return false;
835
+ }
836
+ function safeCloseCode(code) {
837
+ if (!isNumber(code)) return CloseCode.NORMAL;
838
+ if (isCodeInRange(code) && !isReservedCode(code)) return code;
839
+ return CloseCode.NORMAL;
840
+ }
841
+ function isCodeInRange(code) {
842
+ return code >= CloseCode.NORMAL && code <= WS_MAX_CLOSE_CODE;
843
+ }
844
+ function isReservedCode(code) {
845
+ return WS_RESERVED_CODES.has(code);
846
+ }
847
+ function safeReason(reason) {
848
+ if (!isString(reason)) return;
849
+ return reason.replace(/[^\x20-\x7E]/g, "").slice(0, WS_MAX_REASON_CHARS);
850
+ }
851
+ function assertSerializable(value) {
852
+ if (value === null || typeof value !== "object") {
853
+ throw new TypeError("WebSocket attachment must be a non-null object");
854
+ }
855
+ try {
856
+ JSON.stringify(value);
857
+ } catch {
858
+ throw new TypeError("WebSocket attachment is non-serializable");
859
+ }
860
+ }
861
+
862
+ // src/websocket/events.ts
863
+ var WebSocketEvents = class _WebSocketEvents {
864
+ server;
865
+ static isCustomEvent(type) {
866
+ return ["open", "warn"].includes(type);
867
+ }
868
+ customListeners = {};
869
+ constructor(server) {
870
+ this.server = server;
871
+ }
872
+ addEventListener(type, listener, options2) {
873
+ if (_WebSocketEvents.isCustomEvent(type)) {
874
+ let arr = this.customListeners[type];
875
+ if (!arr) {
876
+ arr = [];
877
+ this.customListeners[type] = arr;
878
+ }
879
+ arr.push(listener);
880
+ } else {
881
+ const finalOptions = type === "close" ? { ...options2, once: true } : options2;
882
+ this.server.addEventListener(
883
+ type,
884
+ listener,
885
+ finalOptions
886
+ );
887
+ }
888
+ }
889
+ removeEventListener(type, listener) {
890
+ if (_WebSocketEvents.isCustomEvent(type)) {
891
+ const arr = this.customListeners[type];
892
+ if (arr) {
893
+ const index = arr.indexOf(listener);
894
+ if (index !== -1) arr.splice(index, 1);
895
+ }
896
+ } else {
897
+ this.server.removeEventListener(
898
+ type,
899
+ listener
900
+ );
901
+ }
902
+ }
903
+ dispatch(type, ev, once = false) {
904
+ const listeners = this.customListeners[type]?.slice() ?? [];
905
+ if (once) {
906
+ this.customListeners[type] = [];
907
+ }
908
+ listeners.forEach((listener) => listener(ev));
909
+ }
910
+ warn(msg) {
911
+ this.dispatch("warn", { type: "warn", message: msg });
912
+ }
913
+ open() {
914
+ this.dispatch("open", new Event("open"), true);
915
+ }
916
+ };
917
+
918
+ // src/websocket/base.ts
919
+ var BaseWebSocket = class extends WebSocketEvents {
920
+ accepted = false;
921
+ server;
922
+ constructor(server) {
923
+ super(server);
924
+ this.server = server;
925
+ this.server.addEventListener("close", this.onclose);
926
+ }
927
+ send(data) {
928
+ if (this.isState(WebSocket.CONNECTING, WebSocket.CLOSED)) {
929
+ this.warn("Cannot send: WebSocket not open");
930
+ return;
931
+ }
932
+ if (!isSendable(data)) {
933
+ this.warn("Cannot send: empty or invalid data");
934
+ return;
935
+ }
936
+ this.server.send(data);
937
+ }
938
+ get attachment() {
939
+ return this.server.deserializeAttachment() ?? {};
940
+ }
941
+ attach(attachment) {
942
+ if (attachment === void 0) return;
943
+ if (attachment === null) {
944
+ this.server.serializeAttachment({});
945
+ } else {
946
+ assertSerializable(attachment);
947
+ this.server.serializeAttachment(attachment);
948
+ }
949
+ }
950
+ get readyState() {
951
+ if (!this.accepted) return WebSocket.CONNECTING;
952
+ return this.server.readyState;
953
+ }
954
+ isState(...states) {
955
+ return states.includes(this.readyState);
956
+ }
957
+ close(code, reason) {
958
+ this.server.removeEventListener("close", this.onclose);
959
+ this.server.close(safeCloseCode(code), safeReason(reason));
960
+ }
961
+ onclose = (event) => {
962
+ this.close(event.code, event.reason);
963
+ };
964
+ };
965
+
966
+ // src/websocket/new.ts
967
+ var NewConnectionBase = class extends BaseWebSocket {
968
+ client;
969
+ constructor() {
970
+ const pair = new WebSocketPair();
971
+ const [client, server] = [pair[0], pair[1]];
972
+ super(server);
973
+ this.client = client;
974
+ }
975
+ acceptWebSocket(ctx, tags) {
976
+ ctx.acceptWebSocket(this.server, tags);
977
+ return this.ready();
978
+ }
979
+ accept() {
980
+ this.server.accept();
981
+ return this.ready();
982
+ }
983
+ ready() {
984
+ this.accepted = true;
985
+ this.open();
986
+ return this.client;
987
+ }
988
+ };
989
+
990
+ // src/websocket/restore.ts
991
+ var RestoredConnectionBase = class extends BaseWebSocket {
992
+ constructor(ws) {
993
+ super(ws);
994
+ this.accepted = true;
995
+ }
996
+ accept() {
997
+ throw new Error("Do not call accept() on restore");
998
+ }
999
+ acceptWebSocket() {
1000
+ throw new Error("Do not call acceptWebSocket() on restore");
1001
+ }
1002
+ };
1003
+
1004
+ // src/websocket/sessions.ts
1005
+ var WebSocketSessions = class {
1006
+ map = /* @__PURE__ */ new Map();
1007
+ create(attachment) {
1008
+ class NewConnection extends NewConnectionBase {
1009
+ constructor(sessions) {
1010
+ super();
1011
+ this.sessions = sessions;
1012
+ }
1013
+ accept() {
1014
+ this.addEventListener("close", () => this.sessions.unregister(this.server));
1015
+ this.sessions.register(this.server, this);
1016
+ return super.accept();
1017
+ }
1018
+ acceptWebSocket(ctx, tags) {
1019
+ this.sessions.register(this.server, this);
1020
+ return super.acceptWebSocket(ctx, tags);
1021
+ }
1022
+ }
1023
+ const connection = new NewConnection(this);
1024
+ connection.attach(attachment);
1025
+ return connection;
1026
+ }
1027
+ restore(ws) {
1028
+ class RestoredConnection extends RestoredConnectionBase {
1029
+ constructor(sessions, restore) {
1030
+ super(restore);
1031
+ sessions.register(this.server, this);
1032
+ }
1033
+ }
1034
+ return new RestoredConnection(this, ws);
1035
+ }
1036
+ restoreAll(all) {
1037
+ const restored = [];
1038
+ for (const ws of all) {
1039
+ restored.push(this.restore(ws));
1040
+ }
1041
+ return restored;
1042
+ }
1043
+ get(ws) {
1044
+ return this.map.get(ws);
1045
+ }
1046
+ values() {
1047
+ return this.map.values();
1048
+ }
1049
+ keys() {
1050
+ return this.map.keys();
1051
+ }
1052
+ close(ws, code, reason) {
1053
+ ws.close(safeCloseCode(code), safeReason(reason));
1054
+ return this.unregister(ws);
1055
+ }
1056
+ *[Symbol.iterator]() {
1057
+ yield* this.values();
1058
+ }
1059
+ register(ws, con) {
1060
+ this.map.set(ws, con);
1061
+ }
1062
+ unregister(ws) {
1063
+ return this.map.delete(ws);
1064
+ }
1065
+ };
1066
+
1067
+ // src/workers/base.ts
716
1068
  var BaseWorker = class {
717
1069
  constructor(_request, _env, _ctx) {
718
1070
  this._request = _request;
@@ -731,6 +1083,16 @@ var BaseWorker = class {
731
1083
  get ctx() {
732
1084
  return this._ctx;
733
1085
  }
1086
+ /**
1087
+ * Checks if the given HTTP method is allowed for this worker.
1088
+ * @param method HTTP method string
1089
+ * @returns true if the method is allowed
1090
+ */
1091
+ isAllowed(method) {
1092
+ const methods = this.getAllowedMethods();
1093
+ assertMethods(methods);
1094
+ return isMethod(method) && methods.includes(method);
1095
+ }
734
1096
  /**
735
1097
  * Creates a new instance of the current Worker subclass.
736
1098
  *
@@ -741,6 +1103,23 @@ var BaseWorker = class {
741
1103
  const ctor = this.constructor;
742
1104
  return new ctor(request, this.env, this.ctx);
743
1105
  }
1106
+ /**
1107
+ * Simplify and standardize {@link Response} creation by extending {@link WorkerResponse}
1108
+ * or any of its subclasses and passing to this method.
1109
+ *
1110
+ * Or directly use any of the built-in classes.
1111
+ *
1112
+ * ```ts
1113
+ * this.response(TextResponse, "Hello World!")
1114
+ * ```
1115
+ *
1116
+ * @param ResponseClass The response class to instantiate
1117
+ * @param args Additional constructor arguments
1118
+ * @returns A Promise resolving to the {@link Response} object
1119
+ */
1120
+ async response(ResponseClass, ...args) {
1121
+ return new ResponseClass(...args).create();
1122
+ }
744
1123
  /**
745
1124
  * **Ignite** your `Worker` implementation into a Cloudflare handler.
746
1125
  *
@@ -764,10 +1143,16 @@ function assertMiddleware(handler) {
764
1143
  }
765
1144
  }
766
1145
 
767
- // src/workers/middleware-worker.ts
1146
+ // src/workers/middleware.ts
768
1147
  var MiddlewareWorker = class extends BaseWorker {
769
1148
  /** Middleware handlers registered for this worker. */
770
1149
  middlewares = [];
1150
+ /**
1151
+ * Hook for subclasses to perform any initialization.
1152
+ */
1153
+ init() {
1154
+ return;
1155
+ }
771
1156
  /**
772
1157
  * Add a middleware instance to this worker.
773
1158
  *
@@ -796,21 +1181,21 @@ var MiddlewareWorker = class extends BaseWorker {
796
1181
  }
797
1182
  };
798
1183
 
799
- // src/workers/basic-worker.ts
1184
+ // src/workers/basic.ts
800
1185
  var BasicWorker = class extends MiddlewareWorker {
801
1186
  /**
802
1187
  * Entry point to handle a fetch request.
803
1188
  */
804
1189
  async fetch() {
805
1190
  if (!this.isAllowed(this.request.method)) {
806
- return this.getResponse(MethodNotAllowed, this);
1191
+ return this.response(MethodNotAllowed, this);
807
1192
  }
808
1193
  try {
809
1194
  await this.init();
810
1195
  return await super.fetch();
811
1196
  } catch (error) {
812
1197
  console.error(error);
813
- return this.getResponse(InternalServerError);
1198
+ return this.response(InternalServerError);
814
1199
  }
815
1200
  }
816
1201
  /**
@@ -827,47 +1212,31 @@ var BasicWorker = class extends MiddlewareWorker {
827
1212
  DELETE: () => this.delete(),
828
1213
  OPTIONS: () => this.options()
829
1214
  };
830
- return (handler[method] ?? (() => this.getResponse(MethodNotAllowed, this)))();
831
- }
832
- /**
833
- * Hook for subclasses to perform any initialization.
834
- */
835
- init() {
836
- return;
837
- }
838
- /**
839
- * Checks if the given HTTP method is allowed for this worker.
840
- * @param method HTTP method string
841
- * @returns true if the method is allowed
842
- */
843
- isAllowed(method) {
844
- const methods = this.getAllowedMethods();
845
- assertMethods(methods);
846
- return isMethod(method) && methods.includes(method);
1215
+ return (handler[method] ?? (() => this.response(MethodNotAllowed, this)))();
847
1216
  }
848
1217
  /** Override and implement this method for GET requests. */
849
1218
  async get() {
850
- return this.getResponse(MethodNotImplemented, this);
1219
+ return this.response(MethodNotImplemented, this);
851
1220
  }
852
1221
  /** Override and implement this method for PUT requests. */
853
1222
  async put() {
854
- return this.getResponse(MethodNotImplemented, this);
1223
+ return this.response(MethodNotImplemented, this);
855
1224
  }
856
1225
  /** Override and implement this method for POST requests. */
857
1226
  async post() {
858
- return this.getResponse(MethodNotImplemented, this);
1227
+ return this.response(MethodNotImplemented, this);
859
1228
  }
860
1229
  /** Override and implement this method for PATCH requests. */
861
1230
  async patch() {
862
- return this.getResponse(MethodNotImplemented, this);
1231
+ return this.response(MethodNotImplemented, this);
863
1232
  }
864
1233
  /** Override and implement this method for DELETE requests. */
865
1234
  async delete() {
866
- return this.getResponse(MethodNotImplemented, this);
1235
+ return this.response(MethodNotImplemented, this);
867
1236
  }
868
1237
  /** Returns a default empty OPTIONS response. */
869
1238
  async options() {
870
- return this.getResponse(Options);
1239
+ return this.response(Options);
871
1240
  }
872
1241
  /**
873
1242
  * Default handler for HEAD requests.
@@ -880,7 +1249,7 @@ var BasicWorker = class extends MiddlewareWorker {
880
1249
  const worker = this.create(
881
1250
  new Request(this.request.url, { method: GET, headers: this.request.headers })
882
1251
  );
883
- return this.getResponse(Head, await worker.fetch());
1252
+ return this.response(Head, await worker.fetch());
884
1253
  }
885
1254
  /**
886
1255
  * DEFAULT allowed HTTP methods for subclasses.
@@ -891,23 +1260,6 @@ var BasicWorker = class extends MiddlewareWorker {
891
1260
  getAllowedMethods() {
892
1261
  return [GET, HEAD, OPTIONS];
893
1262
  }
894
- /**
895
- * Simplify and standardize {@link Response} creation by extending {@link WorkerResponse}
896
- * or any of its subclasses and passing to this method.
897
- *
898
- * Or directly use any of the built-in classes.
899
- *
900
- * ```ts
901
- * this.getResponse(TextResponse, "Hello World!")
902
- * ```
903
- *
904
- * @param ResponseClass The response class to instantiate
905
- * @param args Additional constructor arguments
906
- * @returns A Promise resolving to the {@link Response} object
907
- */
908
- async getResponse(ResponseClass, ...args) {
909
- return new ResponseClass(...args).getResponse();
910
- }
911
1263
  };
912
1264
 
913
1265
  // src/routes.ts
@@ -953,7 +1305,7 @@ var Routes = class {
953
1305
  }
954
1306
  };
955
1307
 
956
- // src/workers/route-worker.ts
1308
+ // src/workers/route.ts
957
1309
  var RouteWorker = class _RouteWorker extends BasicWorker {
958
1310
  /** Internal table of registered routes. */
959
1311
  _routes = new Routes();
@@ -1022,19 +1374,19 @@ var RouteWorker = class _RouteWorker extends BasicWorker {
1022
1374
  return BaseWorker.prototype.isPrototypeOf(handler.prototype);
1023
1375
  }
1024
1376
  async get() {
1025
- return this.getResponse(NotFound);
1377
+ return this.response(NotFound);
1026
1378
  }
1027
1379
  async put() {
1028
- return this.getResponse(NotFound);
1380
+ return this.response(NotFound);
1029
1381
  }
1030
1382
  async post() {
1031
- return this.getResponse(NotFound);
1383
+ return this.response(NotFound);
1032
1384
  }
1033
1385
  async patch() {
1034
- return this.getResponse(NotFound);
1386
+ return this.response(NotFound);
1035
1387
  }
1036
1388
  async delete() {
1037
- return this.getResponse(NotFound);
1389
+ return this.response(NotFound);
1038
1390
  }
1039
1391
  };
1040
1392
  export {
@@ -1042,6 +1394,7 @@ export {
1042
1394
  BasicWorker,
1043
1395
  CacheControl,
1044
1396
  ClonedResponse,
1397
+ CloseCode,
1045
1398
  DELETE,
1046
1399
  Forbidden,
1047
1400
  GET,
@@ -1056,7 +1409,6 @@ export {
1056
1409
  Method,
1057
1410
  MethodNotAllowed,
1058
1411
  MethodNotImplemented,
1059
- Middleware,
1060
1412
  NotFound,
1061
1413
  NotImplemented,
1062
1414
  OPTIONS,
@@ -1071,6 +1423,15 @@ export {
1071
1423
  TextResponse,
1072
1424
  Time,
1073
1425
  Unauthorized,
1426
+ UpgradeRequired,
1427
+ WS_MAX_CLOSE_CODE,
1428
+ WS_MAX_REASON_CHARS,
1429
+ WS_RESERVED_CODES,
1430
+ WS_UPGRADE,
1431
+ WS_VERSION,
1432
+ WS_WEBSOCKET,
1433
+ WebSocketResponse,
1434
+ WebSocketSessions,
1074
1435
  WorkerResponse,
1075
1436
  assertMethods,
1076
1437
  cache,
@@ -1084,6 +1445,7 @@ export {
1084
1445
  mergeHeader,
1085
1446
  setHeader,
1086
1447
  sortSearchParams,
1087
- stripSearchParams
1448
+ stripSearchParams,
1449
+ websocket
1088
1450
  };
1089
1451
  //# sourceMappingURL=index.js.map