@adonix.org/cloud-spark 0.0.158 → 0.0.160

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 response() {
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 WebSocketUpgrade = 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);
@@ -523,7 +574,7 @@ async function options(worker, cors2) {
523
574
  setAllowMethods(options2.headers, worker);
524
575
  setAllowHeaders(options2.headers, cors2);
525
576
  setMaxAge(options2.headers, cors2);
526
- return options2.getResponse();
577
+ return options2.response();
527
578
  }
528
579
  async function apply(response, worker, cors2) {
529
580
  const clone = new ClonedResponse(response);
@@ -534,7 +585,7 @@ async function apply(response, worker, cors2) {
534
585
  setAllowCredentials(clone.headers, cors2, origin);
535
586
  setExposedHeaders(clone.headers, cors2);
536
587
  }
537
- return clone.getResponse();
588
+ return clone.response();
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,296 @@ 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").response();
813
+ }
814
+ if (!hasUpgradeHeader(headers)) {
815
+ return new BadRequest("Missing or invalid Upgrade header").response();
816
+ }
817
+ if (!hasWebSocketVersion(headers)) {
818
+ return new UpgradeRequired().response();
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
+ const con = this.get(ws);
1054
+ if (con) con.close(code, reason);
1055
+ return this.unregister(ws);
1056
+ }
1057
+ *[Symbol.iterator]() {
1058
+ yield* this.values();
1059
+ }
1060
+ register(ws, con) {
1061
+ this.map.set(ws, con);
1062
+ }
1063
+ unregister(ws) {
1064
+ return this.map.delete(ws);
1065
+ }
1066
+ };
1067
+
1068
+ // src/workers/base.ts
716
1069
  var BaseWorker = class {
717
1070
  constructor(_request, _env, _ctx) {
718
1071
  this._request = _request;
@@ -731,6 +1084,16 @@ var BaseWorker = class {
731
1084
  get ctx() {
732
1085
  return this._ctx;
733
1086
  }
1087
+ /**
1088
+ * Checks if the given HTTP method is allowed for this worker.
1089
+ * @param method HTTP method string
1090
+ * @returns true if the method is allowed
1091
+ */
1092
+ isAllowed(method) {
1093
+ const methods = this.getAllowedMethods();
1094
+ assertMethods(methods);
1095
+ return isMethod(method) && methods.includes(method);
1096
+ }
734
1097
  /**
735
1098
  * Creates a new instance of the current Worker subclass.
736
1099
  *
@@ -741,6 +1104,23 @@ var BaseWorker = class {
741
1104
  const ctor = this.constructor;
742
1105
  return new ctor(request, this.env, this.ctx);
743
1106
  }
1107
+ /**
1108
+ * Simplify and standardize {@link Response} creation by extending {@link WorkerResponse}
1109
+ * or any of its subclasses and passing to this method.
1110
+ *
1111
+ * Or directly use any of the built-in classes.
1112
+ *
1113
+ * ```ts
1114
+ * this.response(TextResponse, "Hello World!")
1115
+ * ```
1116
+ *
1117
+ * @param ResponseClass The response class to instantiate
1118
+ * @param args Additional constructor arguments
1119
+ * @returns A Promise resolving to the {@link Response} object
1120
+ */
1121
+ async response(ResponseClass, ...args) {
1122
+ return new ResponseClass(...args).response();
1123
+ }
744
1124
  /**
745
1125
  * **Ignite** your `Worker` implementation into a Cloudflare handler.
746
1126
  *
@@ -764,10 +1144,16 @@ function assertMiddleware(handler) {
764
1144
  }
765
1145
  }
766
1146
 
767
- // src/workers/middleware-worker.ts
1147
+ // src/workers/middleware.ts
768
1148
  var MiddlewareWorker = class extends BaseWorker {
769
1149
  /** Middleware handlers registered for this worker. */
770
1150
  middlewares = [];
1151
+ /**
1152
+ * Hook for subclasses to perform any initialization.
1153
+ */
1154
+ init() {
1155
+ return;
1156
+ }
771
1157
  /**
772
1158
  * Add a middleware instance to this worker.
773
1159
  *
@@ -796,21 +1182,21 @@ var MiddlewareWorker = class extends BaseWorker {
796
1182
  }
797
1183
  };
798
1184
 
799
- // src/workers/basic-worker.ts
1185
+ // src/workers/basic.ts
800
1186
  var BasicWorker = class extends MiddlewareWorker {
801
1187
  /**
802
1188
  * Entry point to handle a fetch request.
803
1189
  */
804
1190
  async fetch() {
805
1191
  if (!this.isAllowed(this.request.method)) {
806
- return this.getResponse(MethodNotAllowed, this);
1192
+ return this.response(MethodNotAllowed, this);
807
1193
  }
808
1194
  try {
809
1195
  await this.init();
810
1196
  return await super.fetch();
811
1197
  } catch (error) {
812
1198
  console.error(error);
813
- return this.getResponse(InternalServerError);
1199
+ return this.response(InternalServerError);
814
1200
  }
815
1201
  }
816
1202
  /**
@@ -827,47 +1213,31 @@ var BasicWorker = class extends MiddlewareWorker {
827
1213
  DELETE: () => this.delete(),
828
1214
  OPTIONS: () => this.options()
829
1215
  };
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);
1216
+ return (handler[method] ?? (() => this.response(MethodNotAllowed, this)))();
847
1217
  }
848
1218
  /** Override and implement this method for GET requests. */
849
1219
  async get() {
850
- return this.getResponse(MethodNotImplemented, this);
1220
+ return this.response(MethodNotImplemented, this);
851
1221
  }
852
1222
  /** Override and implement this method for PUT requests. */
853
1223
  async put() {
854
- return this.getResponse(MethodNotImplemented, this);
1224
+ return this.response(MethodNotImplemented, this);
855
1225
  }
856
1226
  /** Override and implement this method for POST requests. */
857
1227
  async post() {
858
- return this.getResponse(MethodNotImplemented, this);
1228
+ return this.response(MethodNotImplemented, this);
859
1229
  }
860
1230
  /** Override and implement this method for PATCH requests. */
861
1231
  async patch() {
862
- return this.getResponse(MethodNotImplemented, this);
1232
+ return this.response(MethodNotImplemented, this);
863
1233
  }
864
1234
  /** Override and implement this method for DELETE requests. */
865
1235
  async delete() {
866
- return this.getResponse(MethodNotImplemented, this);
1236
+ return this.response(MethodNotImplemented, this);
867
1237
  }
868
1238
  /** Returns a default empty OPTIONS response. */
869
1239
  async options() {
870
- return this.getResponse(Options);
1240
+ return this.response(Options);
871
1241
  }
872
1242
  /**
873
1243
  * Default handler for HEAD requests.
@@ -880,7 +1250,7 @@ var BasicWorker = class extends MiddlewareWorker {
880
1250
  const worker = this.create(
881
1251
  new Request(this.request.url, { method: GET, headers: this.request.headers })
882
1252
  );
883
- return this.getResponse(Head, await worker.fetch());
1253
+ return this.response(Head, await worker.fetch());
884
1254
  }
885
1255
  /**
886
1256
  * DEFAULT allowed HTTP methods for subclasses.
@@ -891,23 +1261,6 @@ var BasicWorker = class extends MiddlewareWorker {
891
1261
  getAllowedMethods() {
892
1262
  return [GET, HEAD, OPTIONS];
893
1263
  }
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
1264
  };
912
1265
 
913
1266
  // src/routes.ts
@@ -953,7 +1306,7 @@ var Routes = class {
953
1306
  }
954
1307
  };
955
1308
 
956
- // src/workers/route-worker.ts
1309
+ // src/workers/route.ts
957
1310
  var RouteWorker = class _RouteWorker extends BasicWorker {
958
1311
  /** Internal table of registered routes. */
959
1312
  _routes = new Routes();
@@ -1022,19 +1375,19 @@ var RouteWorker = class _RouteWorker extends BasicWorker {
1022
1375
  return BaseWorker.prototype.isPrototypeOf(handler.prototype);
1023
1376
  }
1024
1377
  async get() {
1025
- return this.getResponse(NotFound);
1378
+ return this.response(NotFound);
1026
1379
  }
1027
1380
  async put() {
1028
- return this.getResponse(NotFound);
1381
+ return this.response(NotFound);
1029
1382
  }
1030
1383
  async post() {
1031
- return this.getResponse(NotFound);
1384
+ return this.response(NotFound);
1032
1385
  }
1033
1386
  async patch() {
1034
- return this.getResponse(NotFound);
1387
+ return this.response(NotFound);
1035
1388
  }
1036
1389
  async delete() {
1037
- return this.getResponse(NotFound);
1390
+ return this.response(NotFound);
1038
1391
  }
1039
1392
  };
1040
1393
  export {
@@ -1042,6 +1395,7 @@ export {
1042
1395
  BasicWorker,
1043
1396
  CacheControl,
1044
1397
  ClonedResponse,
1398
+ CloseCode,
1045
1399
  DELETE,
1046
1400
  Forbidden,
1047
1401
  GET,
@@ -1056,7 +1410,6 @@ export {
1056
1410
  Method,
1057
1411
  MethodNotAllowed,
1058
1412
  MethodNotImplemented,
1059
- Middleware,
1060
1413
  NotFound,
1061
1414
  NotImplemented,
1062
1415
  OPTIONS,
@@ -1071,6 +1424,15 @@ export {
1071
1424
  TextResponse,
1072
1425
  Time,
1073
1426
  Unauthorized,
1427
+ UpgradeRequired,
1428
+ WS_MAX_CLOSE_CODE,
1429
+ WS_MAX_REASON_CHARS,
1430
+ WS_RESERVED_CODES,
1431
+ WS_UPGRADE,
1432
+ WS_VERSION,
1433
+ WS_WEBSOCKET,
1434
+ WebSocketSessions,
1435
+ WebSocketUpgrade,
1074
1436
  WorkerResponse,
1075
1437
  assertMethods,
1076
1438
  cache,
@@ -1084,6 +1446,7 @@ export {
1084
1446
  mergeHeader,
1085
1447
  setHeader,
1086
1448
  sortSearchParams,
1087
- stripSearchParams
1449
+ stripSearchParams,
1450
+ websocket
1088
1451
  };
1089
1452
  //# sourceMappingURL=index.js.map