@fncts/http 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Body/api.d.ts +63 -0
- package/Body/definition.d.ts +53 -0
- package/Body.d.ts +2 -0
- package/BodyError.d.ts +30 -0
- package/Headers.d.ts +42 -0
- package/HttpApp.d.ts +46 -0
- package/IncomingMessage/api.d.ts +19 -0
- package/IncomingMessage/definition.d.ts +21 -0
- package/IncomingMessage.d.ts +2 -0
- package/Method.d.ts +2 -0
- package/Middleware.d.ts +24 -0
- package/QueryParams.d.ts +7 -0
- package/RequestError.d.ts +10 -0
- package/ResponseError.d.ts +14 -0
- package/Route/api.d.ts +37 -0
- package/Route/definition.d.ts +35 -0
- package/Route/internal.d.ts +17 -0
- package/Route.d.ts +2 -0
- package/RouteNotFound.d.ts +8 -0
- package/Router/api.d.ts +96 -0
- package/Router/definition.d.ts +28 -0
- package/Router/internal.d.ts +26 -0
- package/Router.d.ts +2 -0
- package/Server.d.ts +53 -0
- package/ServerError.d.ts +9 -0
- package/ServerRequest/api.d.ts +6 -0
- package/ServerRequest/definition.d.ts +30 -0
- package/ServerRequest/internal.d.ts +33 -0
- package/ServerRequest.d.ts +2 -0
- package/ServerResponse/api.d.ts +69 -0
- package/ServerResponse/definition.d.ts +30 -0
- package/ServerResponse.d.ts +2 -0
- package/Socket.d.ts +107 -0
- package/UrlParams.d.ts +21 -0
- package/_cjs/Body/api.cjs +93 -0
- package/_cjs/Body/api.cjs.map +1 -0
- package/_cjs/Body/definition.cjs +71 -0
- package/_cjs/Body/definition.cjs.map +1 -0
- package/_cjs/Body.cjs +28 -0
- package/_cjs/Body.cjs.map +1 -0
- package/_cjs/BodyError.cjs +43 -0
- package/_cjs/BodyError.cjs.map +1 -0
- package/_cjs/Headers.cjs +87 -0
- package/_cjs/Headers.cjs.map +1 -0
- package/_cjs/HttpApp.cjs +109 -0
- package/_cjs/HttpApp.cjs.map +1 -0
- package/_cjs/IncomingMessage/api.cjs +35 -0
- package/_cjs/IncomingMessage/api.cjs.map +1 -0
- package/_cjs/IncomingMessage/definition.cjs +20 -0
- package/_cjs/IncomingMessage/definition.cjs.map +1 -0
- package/_cjs/IncomingMessage.cjs +28 -0
- package/_cjs/IncomingMessage.cjs.map +1 -0
- package/_cjs/Method.cjs +10 -0
- package/_cjs/Method.cjs.map +1 -0
- package/_cjs/Middleware.cjs +16 -0
- package/_cjs/Middleware.cjs.map +1 -0
- package/_cjs/QueryParams.cjs +6 -0
- package/_cjs/QueryParams.cjs.map +1 -0
- package/_cjs/RequestError.cjs +19 -0
- package/_cjs/RequestError.cjs.map +1 -0
- package/_cjs/ResponseError.cjs +27 -0
- package/_cjs/ResponseError.cjs.map +1 -0
- package/_cjs/Route/api.cjs +61 -0
- package/_cjs/Route/api.cjs.map +1 -0
- package/_cjs/Route/definition.cjs +35 -0
- package/_cjs/Route/definition.cjs.map +1 -0
- package/_cjs/Route/internal.cjs +31 -0
- package/_cjs/Route/internal.cjs.map +1 -0
- package/_cjs/Route.cjs +28 -0
- package/_cjs/Route.cjs.map +1 -0
- package/_cjs/RouteNotFound.cjs +18 -0
- package/_cjs/RouteNotFound.cjs.map +1 -0
- package/_cjs/Router/api.cjs +141 -0
- package/_cjs/Router/api.cjs.map +1 -0
- package/_cjs/Router/definition.cjs +22 -0
- package/_cjs/Router/definition.cjs.map +1 -0
- package/_cjs/Router/internal.cjs +85 -0
- package/_cjs/Router/internal.cjs.map +1 -0
- package/_cjs/Router.cjs +28 -0
- package/_cjs/Router.cjs.map +1 -0
- package/_cjs/Server.cjs +53 -0
- package/_cjs/Server.cjs.map +1 -0
- package/_cjs/ServerError.cjs +21 -0
- package/_cjs/ServerError.cjs.map +1 -0
- package/_cjs/ServerRequest/api.cjs +14 -0
- package/_cjs/ServerRequest/api.cjs.map +1 -0
- package/_cjs/ServerRequest/definition.cjs +29 -0
- package/_cjs/ServerRequest/definition.cjs.map +1 -0
- package/_cjs/ServerRequest/internal.cjs +77 -0
- package/_cjs/ServerRequest/internal.cjs.map +1 -0
- package/_cjs/ServerRequest.cjs +28 -0
- package/_cjs/ServerRequest.cjs.map +1 -0
- package/_cjs/ServerResponse/api.cjs +157 -0
- package/_cjs/ServerResponse/api.cjs.map +1 -0
- package/_cjs/ServerResponse/definition.cjs +44 -0
- package/_cjs/ServerResponse/definition.cjs.map +1 -0
- package/_cjs/ServerResponse.cjs +28 -0
- package/_cjs/ServerResponse.cjs.map +1 -0
- package/_cjs/Socket.cjs +221 -0
- package/_cjs/Socket.cjs.map +1 -0
- package/_cjs/UrlParams.cjs +34 -0
- package/_cjs/UrlParams.cjs.map +1 -0
- package/_cjs/global.cjs +6 -0
- package/_cjs/global.cjs.map +1 -0
- package/_mjs/Body/api.mjs +78 -0
- package/_mjs/Body/api.mjs.map +1 -0
- package/_mjs/Body/definition.mjs +58 -0
- package/_mjs/Body/definition.mjs.map +1 -0
- package/_mjs/Body.mjs +5 -0
- package/_mjs/Body.mjs.map +1 -0
- package/_mjs/BodyError.mjs +33 -0
- package/_mjs/BodyError.mjs.map +1 -0
- package/_mjs/Headers.mjs +75 -0
- package/_mjs/Headers.mjs.map +1 -0
- package/_mjs/HttpApp.mjs +96 -0
- package/_mjs/HttpApp.mjs.map +1 -0
- package/_mjs/IncomingMessage/api.mjs +25 -0
- package/_mjs/IncomingMessage/api.mjs.map +1 -0
- package/_mjs/IncomingMessage/definition.mjs +13 -0
- package/_mjs/IncomingMessage/definition.mjs.map +1 -0
- package/_mjs/IncomingMessage.mjs +5 -0
- package/_mjs/IncomingMessage.mjs.map +1 -0
- package/_mjs/Method.mjs +4 -0
- package/_mjs/Method.mjs.map +1 -0
- package/_mjs/Middleware.mjs +9 -0
- package/_mjs/Middleware.mjs.map +1 -0
- package/_mjs/QueryParams.mjs +2 -0
- package/_mjs/QueryParams.mjs.map +1 -0
- package/_mjs/RequestError.mjs +12 -0
- package/_mjs/RequestError.mjs.map +1 -0
- package/_mjs/ResponseError.mjs +20 -0
- package/_mjs/ResponseError.mjs.map +1 -0
- package/_mjs/Route/api.mjs +48 -0
- package/_mjs/Route/api.mjs.map +1 -0
- package/_mjs/Route/definition.mjs +25 -0
- package/_mjs/Route/definition.mjs.map +1 -0
- package/_mjs/Route/internal.mjs +21 -0
- package/_mjs/Route/internal.mjs.map +1 -0
- package/_mjs/Route.mjs +5 -0
- package/_mjs/Route.mjs.map +1 -0
- package/_mjs/RouteNotFound.mjs +11 -0
- package/_mjs/RouteNotFound.mjs.map +1 -0
- package/_mjs/Router/api.mjs +123 -0
- package/_mjs/Router/api.mjs.map +1 -0
- package/_mjs/Router/definition.mjs +15 -0
- package/_mjs/Router/definition.mjs.map +1 -0
- package/_mjs/Router/internal.mjs +76 -0
- package/_mjs/Router/internal.mjs.map +1 -0
- package/_mjs/Router.mjs +5 -0
- package/_mjs/Router.mjs.map +1 -0
- package/_mjs/Server.mjs +41 -0
- package/_mjs/Server.mjs.map +1 -0
- package/_mjs/ServerError.mjs +14 -0
- package/_mjs/ServerError.mjs.map +1 -0
- package/_mjs/ServerRequest/api.mjs +8 -0
- package/_mjs/ServerRequest/api.mjs.map +1 -0
- package/_mjs/ServerRequest/definition.mjs +20 -0
- package/_mjs/ServerRequest/definition.mjs.map +1 -0
- package/_mjs/ServerRequest/internal.mjs +68 -0
- package/_mjs/ServerRequest/internal.mjs.map +1 -0
- package/_mjs/ServerRequest.mjs +5 -0
- package/_mjs/ServerRequest.mjs.map +1 -0
- package/_mjs/ServerResponse/api.mjs +138 -0
- package/_mjs/ServerResponse/api.mjs.map +1 -0
- package/_mjs/ServerResponse/definition.mjs +34 -0
- package/_mjs/ServerResponse/definition.mjs.map +1 -0
- package/_mjs/ServerResponse.mjs +5 -0
- package/_mjs/ServerResponse.mjs.map +1 -0
- package/_mjs/Socket.mjs +202 -0
- package/_mjs/Socket.mjs.map +1 -0
- package/_mjs/UrlParams.mjs +25 -0
- package/_mjs/UrlParams.mjs.map +1 -0
- package/_mjs/global.mjs +2 -0
- package/_mjs/global.mjs.map +1 -0
- package/_src/Body/api.ts +106 -0
- package/_src/Body/definition.ts +74 -0
- package/_src/Body.ts +5 -0
- package/_src/BodyError.ts +38 -0
- package/_src/Headers.ts +84 -0
- package/_src/HttpApp.ts +129 -0
- package/_src/IncomingMessage/api.ts +25 -0
- package/_src/IncomingMessage/definition.ts +20 -0
- package/_src/IncomingMessage.ts +5 -0
- package/_src/Method.ts +5 -0
- package/_src/Middleware.ts +29 -0
- package/_src/QueryParams.ts +7 -0
- package/_src/RequestError.ts +13 -0
- package/_src/ResponseError.ts +25 -0
- package/_src/Route/api.ts +53 -0
- package/_src/Route/definition.ts +40 -0
- package/_src/Route/internal.ts +25 -0
- package/_src/Route.ts +5 -0
- package/_src/RouteNotFound.ts +14 -0
- package/_src/Router/api.ts +161 -0
- package/_src/Router/definition.ts +29 -0
- package/_src/Router/internal.ts +95 -0
- package/_src/Router.ts +5 -0
- package/_src/Server.ts +88 -0
- package/_src/ServerError.ts +14 -0
- package/_src/ServerRequest/api.ts +10 -0
- package/_src/ServerRequest/definition.ts +33 -0
- package/_src/ServerRequest/internal.ts +106 -0
- package/_src/ServerRequest.ts +5 -0
- package/_src/ServerResponse/api.ts +177 -0
- package/_src/ServerResponse/definition.ts +51 -0
- package/_src/ServerResponse.ts +5 -0
- package/_src/Socket.ts +294 -0
- package/_src/UrlParams.ts +28 -0
- package/_src/global.ts +2 -0
- package/global.d.ts +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const fileName_1 = "(@fncts/http) src/Router/api.ts";
|
|
2
|
+
import * as tsplus_module_1 from "@fncts/base/collection/immutable/Conc/api/empty";
|
|
3
|
+
import * as tsplus_module_2 from "@fncts/base/collection/immutable/Conc/api";
|
|
4
|
+
import * as tsplus_module_3 from "@fncts/base/collection/immutable/Conc/constructors";
|
|
5
|
+
import * as tsplus_module_4 from "@fncts/base/data/Maybe/constructors";
|
|
6
|
+
import * as tsplus_module_5 from "@fncts/base/data/Maybe/api";
|
|
7
|
+
import * as tsplus_module_6 from "@fncts/io/IO/api";
|
|
8
|
+
import * as tsplus_module_7 from "@fncts/io/IO/api/environment";
|
|
9
|
+
export const use = use_1;
|
|
10
|
+
export const concat = concat_1;
|
|
11
|
+
export const prefixAll = prefixAll_1;
|
|
12
|
+
import { RouteImpl } from "../Route/internal.mjs";
|
|
13
|
+
import { RouterInternal } from "./internal.mjs";
|
|
14
|
+
/**
|
|
15
|
+
* @tsplus static fncts.http.RouterOps empty
|
|
16
|
+
*/
|
|
17
|
+
export const empty = /*#__PURE__*/new RouterInternal( /*#__PURE__*/tsplus_module_1.empty(), /*#__PURE__*/tsplus_module_1.empty());
|
|
18
|
+
export function route(method) {
|
|
19
|
+
return (path, handler) => self => new RouterInternal(tsplus_module_2.append(new RouteImpl(method, path, handler))(self.routes), self.mounts);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @tsplus pipeable fncts.http.Router get
|
|
23
|
+
* @tsplus static fncts.http.RouterOps get
|
|
24
|
+
*/
|
|
25
|
+
export const get = /*#__PURE__*/route("GET");
|
|
26
|
+
/**
|
|
27
|
+
* @tsplus pipeable fncts.http.Router post
|
|
28
|
+
* @tsplus static fncts.http.RouterOps post
|
|
29
|
+
*/
|
|
30
|
+
export const post = /*#__PURE__*/route("POST");
|
|
31
|
+
/**
|
|
32
|
+
* @tsplus pipeable fncts.http.Router put
|
|
33
|
+
* @tsplus static fncts.http.RouterOps put
|
|
34
|
+
*/
|
|
35
|
+
export const put = /*#__PURE__*/route("PUT");
|
|
36
|
+
/**
|
|
37
|
+
* @tsplus pipeable fncts.http.Router patch
|
|
38
|
+
* @tsplus static fncts.http.RouterOps patch
|
|
39
|
+
*/
|
|
40
|
+
export const patch = /*#__PURE__*/route("PATCH");
|
|
41
|
+
/**
|
|
42
|
+
* @tsplus pipeable fncts.http.Router del
|
|
43
|
+
* @tsplus static fncts.http.RouterOps del
|
|
44
|
+
*/
|
|
45
|
+
export const del = /*#__PURE__*/route("DELETE");
|
|
46
|
+
/**
|
|
47
|
+
* @tsplus pipeable fncts.http.Router head
|
|
48
|
+
* @tsplus static fncts.http.RouterOps head
|
|
49
|
+
*/
|
|
50
|
+
export const head = /*#__PURE__*/route("HEAD");
|
|
51
|
+
/**
|
|
52
|
+
* @tsplus pipeable fncts.http.Router options
|
|
53
|
+
* @tsplus static fncts.http.RouterOps options
|
|
54
|
+
*/
|
|
55
|
+
export const options = /*#__PURE__*/route("OPTIONS");
|
|
56
|
+
/**
|
|
57
|
+
* @tsplus pipeable fncts.http.Router use
|
|
58
|
+
* @tsplus static fncts.http.RouterOps use
|
|
59
|
+
*/
|
|
60
|
+
function use_1(f, __tsplusTrace) {
|
|
61
|
+
return self => new RouterInternal(tsplus_module_2.map(route => new RouteImpl(route.method, route.path, f(route.handler), route.prefix))(self.routes), tsplus_module_2.map(({
|
|
62
|
+
prefix,
|
|
63
|
+
httpApp
|
|
64
|
+
}) => ({
|
|
65
|
+
prefix,
|
|
66
|
+
httpApp: f(httpApp)
|
|
67
|
+
}))(self.mounts));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @tsplus static fncts.http.RouterOps from
|
|
71
|
+
*/
|
|
72
|
+
export function from(routes) {
|
|
73
|
+
return new RouterInternal(tsplus_module_3.from(routes), tsplus_module_1.empty());
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @tsplus pipeable fncts.http.Router concat
|
|
77
|
+
*/
|
|
78
|
+
function concat_1(that) {
|
|
79
|
+
return self => new RouterInternal(tsplus_module_2.concat(that.routes)(self.routes), self.mounts);
|
|
80
|
+
}
|
|
81
|
+
function removeTrailingSlash(path) {
|
|
82
|
+
return path.endsWith("/") ? path.slice(0, -1) : path;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @tsplus pipeable fncts.http.Router prefixAll
|
|
86
|
+
*/
|
|
87
|
+
function prefixAll_1(prefix) {
|
|
88
|
+
return self => {
|
|
89
|
+
prefix = removeTrailingSlash(prefix);
|
|
90
|
+
return new RouterInternal(tsplus_module_2.map(route => new RouteImpl(route.method, route.path === "/" ? prefix : prefix + route.path, route.handler, tsplus_module_5.orElse(() => tsplus_module_4.just(prefix, fileName_1 + ":124:60"))(tsplus_module_5.map(_ => prefix + _)(route.prefix))))(self.routes), tsplus_module_2.map(({
|
|
91
|
+
prefix: path,
|
|
92
|
+
httpApp
|
|
93
|
+
}) => ({
|
|
94
|
+
prefix: path === "/" ? prefix : prefix + path,
|
|
95
|
+
httpApp
|
|
96
|
+
}))(self.mounts));
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @tsplus pipeable fncts.http.Router mount
|
|
101
|
+
*/
|
|
102
|
+
export function mount(path, that) {
|
|
103
|
+
return self => concat_1(prefixAll_1(path)(that))(self);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @tsplus pipeable fncts.http.Router catchAll
|
|
107
|
+
*/
|
|
108
|
+
export function catchAll(f, __tsplusTrace) {
|
|
109
|
+
return self => use_1(handler => tsplus_module_6.catchAll(f, __tsplusTrace)(handler), __tsplusTrace)(self);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @tsplus pipeable fncts.http.Router catchAllCause
|
|
113
|
+
*/
|
|
114
|
+
export function catchAllCause(f, __tsplusTrace) {
|
|
115
|
+
return self => use_1(handler => tsplus_module_6.catchAllCause(f, __tsplusTrace)(handler), __tsplusTrace)(self);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* @tsplus pipeable fncts.http.Router provideService
|
|
119
|
+
*/
|
|
120
|
+
export function provideService(service, tag, __tsplusTrace) {
|
|
121
|
+
return self => use_1(handler => tsplus_module_7.provideSomeService(service, tag, __tsplusTrace)(handler), __tsplusTrace)(self);
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=api.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.mjs","names":["use","use_1","concat","concat_1","prefixAll","prefixAll_1","RouteImpl","RouterInternal","empty","tsplus_module_1","route","method","path","handler","self","tsplus_module_2","append","routes","mounts","get","post","put","patch","del","head","options","f","__tsplusTrace","map","prefix","httpApp","from","tsplus_module_3","that","removeTrailingSlash","endsWith","slice","tsplus_module_5","orElse","tsplus_module_4","just","fileName_1","_","mount","catchAll","tsplus_module_6","catchAllCause","provideService","service","tag","tsplus_module_7","provideSomeService"],"sources":["../../_src/Router/api.ts"],"sourcesContent":[null],"mappings":";;;;;;;;aAiFgBA,GAAG,GAAAC,KAAA;aAoBHC,MAAM,GAAAC,QAAA;aAYNC,SAAS,GAAAC,WAAA;AA5GzB,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gBAAe;AAE9C;;;AAGA,OAAO,MAAMC,KAAK,gBAAyB,IAAID,cAAc,eAACE,eAAA,CAAAD,KAAA,EAAY,eAAEC,eAAA,CAAAD,KAAA,EAAY,CAAC;AAEzF,OAAM,SAAUE,KAAKA,CAACC,MAAoB;EACxC,OAAO,CAASC,IAAe,EAAEC,OAA8B,KACtDC,IAAkB,IACvB,IAAIP,cAAc,CAAWQ,eAAA,CAAAC,MAAA,CAAmB,IAAIV,SAAS,CAACK,MAAM,EAAEC,IAAI,EAAEC,OAAO,CAAC,EAAvDC,IAAI,CAACG,MAAM,CAA6C,EAAEH,IAAI,CAACI,MAAM,CAAC;AACzG;AAEA;;;;AAIA,OAAO,MAAMC,GAAG,gBAGoET,KAAK,CAAC,KAAK,CAAC;AAEhG;;;;AAIA,OAAO,MAAMU,IAAI,gBAGmEV,KAAK,CAAC,MAAM,CAAC;AACjG;;;;AAIA,OAAO,MAAMW,GAAG,gBAGoEX,KAAK,CAAC,KAAK,CAAC;AAChG;;;;AAIA,OAAO,MAAMY,KAAK,gBAGkEZ,KAAK,CAAC,OAAO,CAAC;AAClG;;;;AAIA,OAAO,MAAMa,GAAG,gBAGoEb,KAAK,CAAC,QAAQ,CAAC;AACnG;;;;AAIA,OAA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AaA,CAAYpB,CAAyC,EAAEC,aAAsB;EACxG,OAAWb,IAAkB,IAC3Bb,KAAA,CAAUY,OAAO,IAAKgC,eAAA,CAAAC,aAAA,CAAsBpB,CAAC,EAFmCC,aAAA,EAE1Dd,OAAO,CAAiB,EAFkCc,aAAA,EAEhFb,IAAI,CAA2C;AACnD;AAEA;;;AAGA,OAAM,SAAUiC,cAAcA,CAAIC,OAAU,EAAEC,GAAW,EAAEtB,aAAsB;EAC/E,OAAcb,IAAkB,IAC9Bb,KAAA,CAAUY,OAAO,IAAKqC,eAAA,CAAAC,kBAAA,CAA2BH,OAAO,EAAEC,GAAG,EAFNtB,aAAA,EAEjCd,OAAO,CAAiC,EAFPc,aAAA,EAEvDb,IAAI,CAA2D;AACnE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { External } from "@fncts/io/IO";
|
|
3
|
+
export const RouterTypeId = /*#__PURE__*/Symbol.for("fncts.http.Router");
|
|
4
|
+
/**
|
|
5
|
+
* @tsplus type fncts.http.Router
|
|
6
|
+
* @tsplus companion fncts.http.RouterOps
|
|
7
|
+
*/
|
|
8
|
+
export class Router extends External {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this[_a] = RouterTypeId;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
_a = RouterTypeId;
|
|
15
|
+
//# sourceMappingURL=definition.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.mjs","names":["External","RouterTypeId","Symbol","for","Router","constructor","_a"],"sources":["../../_src/Router/definition.ts"],"sourcesContent":[null],"mappings":";AAMA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,OAAO,MAAMC,YAAY,gBAAGC,MAAM,CAACC,GAAG,CAAC,mBAAmB,CAAC;AAG3D;;;;AAIA,OAAM,MAAgBC,MACpB,SAAQJ,QAAqE;EAD/EK,YAAA;;IAIW,KAAAC,EAAA,CAAc,GAAiBL,YAAY;EAKtD;;KALYA,YAAY"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const fileName_1 = "(@fncts/http) src/Router/internal.ts";
|
|
2
|
+
import * as tsplus_module_1 from "@fncts/base/data/Maybe/constructors";
|
|
3
|
+
import * as tsplus_module_2 from "@fncts/base/collection/immutable/Conc/api";
|
|
4
|
+
import * as tsplus_module_3 from "@fncts/io/FiberRef/unsafe";
|
|
5
|
+
import * as tsplus_module_4 from "@fncts/http/ServerRequest/definition";
|
|
6
|
+
import * as tsplus_module_5 from "@fncts/base/data/Environment/api";
|
|
7
|
+
import * as tsplus_module_6 from "@fncts/http/Route/definition";
|
|
8
|
+
import * as tsplus_module_7 from "@fncts/io/FiberRef/operations";
|
|
9
|
+
import * as tsplus_module_8 from "@fncts/io/IO/api";
|
|
10
|
+
import * as tsplus_module_9 from "@fncts/base/data/Maybe/definition";
|
|
11
|
+
import * as FindMyWay from "find-my-way-ts";
|
|
12
|
+
import { RouteContextImpl, RouteImpl } from "../Route/internal.mjs";
|
|
13
|
+
import { RouteNotFound } from "../RouteNotFound.mjs";
|
|
14
|
+
import { Router } from "./definition.mjs";
|
|
15
|
+
export class RouterInternal extends Router {
|
|
16
|
+
constructor(routes, mounts) {
|
|
17
|
+
super();
|
|
18
|
+
this.routes = routes;
|
|
19
|
+
this.mounts = mounts;
|
|
20
|
+
this.httpApp = toHttpApp(this);
|
|
21
|
+
}
|
|
22
|
+
get toIO() {
|
|
23
|
+
return this.httpApp;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function toHttpApp(self) {
|
|
27
|
+
const router = FindMyWay.make();
|
|
28
|
+
const mounts = tsplus_module_2.map(({
|
|
29
|
+
prefix,
|
|
30
|
+
httpApp,
|
|
31
|
+
options
|
|
32
|
+
}) => [prefix, new RouteContextImpl(new RouteImpl("*", options?.inclduePrefix ? `${prefix}/*` : "/*", httpApp, options?.inclduePrefix ? tsplus_module_1.nothing(fileName_1 + ":43:45") : tsplus_module_1.just(prefix, fileName_1 + ":43:54")), {}, {}), options])(self.mounts);
|
|
33
|
+
const mountsLen = mounts.length;
|
|
34
|
+
tsplus_module_2.forEach(route => {
|
|
35
|
+
if (route.method === "*") {
|
|
36
|
+
router.all(route.path, route);
|
|
37
|
+
} else {
|
|
38
|
+
router.on(route.method, route.path, route);
|
|
39
|
+
}
|
|
40
|
+
})(self.routes);
|
|
41
|
+
return tsplus_module_8.withFiberRuntime(fiber => {
|
|
42
|
+
let context = fiber.getFiberRef(tsplus_module_3.currentEnvironment);
|
|
43
|
+
const request = tsplus_module_5.unsafeGet(tsplus_module_4.ServerRequestTag)(context);
|
|
44
|
+
if (mountsLen > 0) {
|
|
45
|
+
for (let i = 0; i < mountsLen; i++) {
|
|
46
|
+
const [path, routeContext, options] = tsplus_module_2.unsafeGet(i)(mounts);
|
|
47
|
+
if (request.url.startsWith(path)) {
|
|
48
|
+
context = tsplus_module_5.add(routeContext, tsplus_module_6.RouteContextTag)(context);
|
|
49
|
+
if (options?.inclduePrefix !== true) {
|
|
50
|
+
context = tsplus_module_5.add(sliceRequestUrl(request, path), tsplus_module_4.ServerRequestTag)(context);
|
|
51
|
+
}
|
|
52
|
+
return tsplus_module_7.locally(tsplus_module_3.currentEnvironment, context, fileName_1 + ":70:53")(routeContext.route.handler);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let result = router.find(request.method, request.url);
|
|
57
|
+
if (result === undefined && request.method === "HEAD") {
|
|
58
|
+
result = router.find("GET", request.url);
|
|
59
|
+
}
|
|
60
|
+
if (result === undefined) {
|
|
61
|
+
return tsplus_module_8.failNow(new RouteNotFound(request), fileName_1 + ":80:24");
|
|
62
|
+
}
|
|
63
|
+
const route = result.handler;
|
|
64
|
+
if (tsplus_module_9.isJust(route.prefix)) {
|
|
65
|
+
context = tsplus_module_5.add(sliceRequestUrl(request, route.prefix.value), tsplus_module_4.ServerRequestTag)(context);
|
|
66
|
+
}
|
|
67
|
+
return tsplus_module_7.locally(tsplus_module_3.currentEnvironment, context, fileName_1 + ":86:47")(route.handler);
|
|
68
|
+
}, fileName_1 + ":59:29");
|
|
69
|
+
}
|
|
70
|
+
function sliceRequestUrl(request, prefix) {
|
|
71
|
+
const prefixLen = prefix.length;
|
|
72
|
+
return request.modify({
|
|
73
|
+
url: request.url.length <= prefixLen ? "/" : request.url.slice(prefixLen)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=internal.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.mjs","names":["FindMyWay","RouteContextImpl","RouteImpl","RouteNotFound","Router","RouterInternal","constructor","routes","mounts","httpApp","toHttpApp","toIO","self","router","make","tsplus_module_2","map","prefix","options","inclduePrefix","tsplus_module_1","nothing","fileName_1","just","mountsLen","length","forEach","route","method","all","path","on","tsplus_module_8","withFiberRuntime","fiber","context","getFiberRef","tsplus_module_3","currentEnvironment","request","tsplus_module_5","unsafeGet","tsplus_module_4","ServerRequestTag","i","routeContext","url","startsWith","add","tsplus_module_6","RouteContextTag","sliceRequestUrl","tsplus_module_7","locally","handler","result","find","undefined","failNow","tsplus_module_9","isJust","value","prefixLen","modify","slice"],"sources":["../../_src/Router/internal.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;AAIA,OAAO,KAAKA,SAAS,MAAM,gBAAgB;AAG3C,SAASC,gBAAgB,EAAEC,SAAS,QAAQ,uBAAsB;AAClE,SAASC,aAAa,QAAQ,sBAAqB;AAEnD,SAASC,MAAM,QAAQ,kBAAiB;AAExC,OAAM,MAAOC,cAAqB,SAAQD,MAAY;EAGpDE,YACWC,MAAyB,EACzBC,MAER;IAED,KAAK,EAAE;IALE,KAAAD,MAAM,GAANA,MAAM;IACN,KAAAC,MAAM,GAANA,MAAM;IAKf,IAAI,CAACC,OAAO,GAAGC,SAAS,CAAC,IAAI,CAAQ;EACvC;EAEA,IAAIC,IAAIA,CAAA;IACN,OAAO,IAAI,CAACF,OA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AAS,EAAE;MACzBkB,OAAO,GAAGK,eAAA,CAAAQ,GAAA,CAAYG,eAAe,CAACZ,OAAO,EAAEZ,KAAK,CAACV,MAAM,CAAC4C,KAAK,CAAC,EAAAnB,eAAA,CAAAC,gBAAA,EAAxDR,OAAO,CAAqE;IACxF;IACA,OAAOiB,eAAA,CAAAC,OAAA,CAAAhB,eAAA,CAAAC,kBAAA,EAAoCH,OAAO,EAAAb,UAAA,YAAC,CACjDK,KAAK,CAAC2B,OAA2D,CAClE;EACH,CAAC,EAAAhC,UAAA,YAAC;AACJ;AAEA,SAAS6B,eAAeA,CAACZ,OAAsB,EAAEtB,MAAc;EAC7D,MAAM6C,SAAS,GAAG7C,MAAM,CAACQ,MAAM;EAC/B,OAAOc,OAAO,CAACwB,MAAM,CAAC;IAAEjB,GAAG,EAAEP,OAAO,CAACO,GAAG,CAACrB,MAAM,IAAIqC,SAAS,GAAG,GAAG,GAAGvB,OAAO,CAACO,GAAG,CAACkB,KAAK,CAACF,SAAS;EAAC,CAAE,CAAC;AACtG"}
|
package/_mjs/Router.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.mjs","names":[],"sources":["../_src/Router.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA;AACA,cAAc,yBAAwB;AACtC,cAAc,kBAAiB"}
|
package/_mjs/Server.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
const fileName_1 = "(@fncts/http) src/Server.ts";
|
|
3
|
+
import * as tsplus_module_1 from "@fncts/base/data/Tag/constructors";
|
|
4
|
+
import * as tsplus_module_2 from "@fncts/io/IO/api/environment";
|
|
5
|
+
import * as tsplus_module_3 from "@fncts/io/IO/api";
|
|
6
|
+
import * as tsplus_module_4 from "@fncts/io/Layer/api";
|
|
7
|
+
export const ServerTypeId = /*#__PURE__*/Symbol.for("fncts.http.Server");
|
|
8
|
+
/**
|
|
9
|
+
* @tsplus type fncts.http.Server
|
|
10
|
+
* @tsplus companion fncts.http.ServerOps
|
|
11
|
+
*/
|
|
12
|
+
export class Server {
|
|
13
|
+
constructor() {
|
|
14
|
+
this[_a] = ServerTypeId;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
_a = ServerTypeId;
|
|
18
|
+
/**
|
|
19
|
+
* @tsplus static fncts.http.ServerOps Tag
|
|
20
|
+
*/
|
|
21
|
+
const ServerTag_1 = /*#__PURE__*/tsplus_module_1.makeTag();
|
|
22
|
+
export const ServerTag = ServerTag_1;
|
|
23
|
+
/**
|
|
24
|
+
* @tsplus static fncts.http.ServerOps __call
|
|
25
|
+
*/
|
|
26
|
+
export function make(options) {
|
|
27
|
+
return new class extends Server {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
this.serve = options.serve;
|
|
31
|
+
this.address = options.address;
|
|
32
|
+
}
|
|
33
|
+
}();
|
|
34
|
+
}
|
|
35
|
+
export function serve(middleware) {
|
|
36
|
+
return httpApp => tsplus_module_4.scopedDiscard(() => tsplus_module_3.flatMap(server => server.serve(httpApp, middleware), fileName_1 + ":69:55")(tsplus_module_2.service(ServerTag_1, fileName_1 + ":69:35")), fileName_1 + ":69:24");
|
|
37
|
+
}
|
|
38
|
+
export function serveIO(middleware) {
|
|
39
|
+
return httpApp => tsplus_module_3.flatMap(server => server.serve(httpApp, middleware), fileName_1 + ":87:53")(tsplus_module_2.service(ServerTag_1, fileName_1 + ":87:33"));
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=Server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Server.mjs","names":["ServerTypeId","Symbol","for","Server","constructor","_a","ServerTag_1","tsplus_module_1","makeTag","ServerTag","make","options","serve","address","middleware","httpApp","tsplus_module_4","scopedDiscard","tsplus_module_3","flatMap","server","fileName_1","tsplus_module_2","service","serveIO"],"sources":["../_src/Server.ts"],"sourcesContent":[null],"mappings":";;;;;;AAIA,OAAO,MAAMA,YAAY,gBAAGC,MAAM,CAACC,GAAG,CAAC,mBAAmB,CAAC;AAG3D;;;;AAIA,OAAM,MAAgBC,MAAM;EAA5BC,YAAA;IACW,KAAAC,EAAA,CAAc,GAAiBL,YAAY;EAOtD;;KAPYA,YAAY;AASxB;;;AAGO,MAAMM,WAAA,gBAAYC,eAAA,CAAAC,OAAA,EAAa;aAAzBC,SAAS,GAAAH,WAAA;AAetB;;;AAGA,OAAM,SAAUI,IAAIA,CAACC,OAGpB;EACC,OAAO,IAAK,cAAcR,MAAM;IAApBC,YAAA;;MACV,KAAAQ,KAAK,GAAGD,OAAO,CAACC,KAAK;MACrB,KAAAC,OAAO,GAAGF,OAAO,CAACE,OAAO;IAC3B;GAAC,CAAC,CAAE;AACN;AAcA,OAAM,SAAUD,KAAKA,CACnBE,UAA0C;EAE1C,OAAQC,OAAO,IACbC,eAAA,CAAAC,aAAA,OAAoBC,eAAA,CAAAC,OAAA,CAAgCC,MAAM,IAAKA,MAAM,CAACR,KAAK,CAACG,OAAO,EAAED,UAAW,CAAC,EAAAO,UAAA,aAA7EC,eAAA,CAAAC,OAAA,CAAAjB,WAAA,EAAAe,UAAA,YAAsB,CAAwD,EAAAA,UAAA,YAAQ;AAC9G;AAcA,OAAM,SAAUG,OAAOA,CACrBV,UAA0C;EAE1C,OAAQC,OAAO,IAAKG,eAAA,CAAAC,OAAA,CAAgCC,MAAM,IAAKA,MAAM,CAACR,KAAK,CAACG,OAAO,EAAED,UAAW,CAAC,EAAAO,UAAA,aAA7EC,eAAA,CAAAC,OAAA,CAAAjB,WAAA,EAAAe,UAAA,YAAsB,CAA+D;AAC3G"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { Runtime } from "@fncts/base/data/FiberId";
|
|
3
|
+
import { globalValue } from "@fncts/base/data/Global";
|
|
4
|
+
export const clientAbortFiberId = /*#__PURE__*/globalValue("fncts.http.ServerError.clientAbortFiberId", () => new Runtime(-499, 0));
|
|
5
|
+
export const ServeErrorTypeId = /*#__PURE__*/Symbol.for("fncts.http.ServeError");
|
|
6
|
+
export class ServeError extends Error {
|
|
7
|
+
constructor(error) {
|
|
8
|
+
super();
|
|
9
|
+
this.error = error;
|
|
10
|
+
this[_a] = ServeErrorTypeId;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
_a = ServeErrorTypeId;
|
|
14
|
+
//# sourceMappingURL=ServerError.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerError.mjs","names":["Runtime","globalValue","clientAbortFiberId","ServeErrorTypeId","Symbol","for","ServeError","Error","constructor","error","_a"],"sources":["../_src/ServerError.ts"],"sourcesContent":[null],"mappings":";AAAA,SAASA,OAAO,QAAQ,0BAA0B;AAClD,SAASC,WAAW,QAAQ,yBAAyB;AAErD,OAAO,MAAMC,kBAAkB,gBAAGD,WAAW,CAAC,2CAA2C,EAAE,MAAM,IAAID,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AAEtH,OAAO,MAAMG,gBAAgB,gBAAGC,MAAM,CAACC,GAAG,CAAC,uBAAuB,CAAC;AAGnE,OAAM,MAAOC,UAAW,SAAQC,KAAK;EAEnCC,YAAqBC,KAAe;IAClC,KAAK,EAAE;IADY,KAAAA,KAAK,GAALA,KAAK;IADjB,KAAAC,EAAA,CAAkB,GAAqBP,gBAAgB;EAGhE;;KAHUA,gBAAgB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.mjs","names":["ServerRequestImpl","fromWeb","request","url"],"sources":["../../_src/ServerRequest/api.ts"],"sourcesContent":[null],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,gBAAe;AAEjD;;;AAGA,OAAM,SAAUC,OAAOA,CAACC,OAA2B;EACjD,OAAO,IAAIF,iBAAiB,CAACE,OAAO,EAAEA,OAAO,CAACC,GAAG,CAAC;AACpD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import * as tsplus_module_1 from "@fncts/base/data/Tag/constructors";
|
|
3
|
+
import { IncomingMessage } from "../IncomingMessage/definition.mjs";
|
|
4
|
+
export const ServerRequestTypeId = /*#__PURE__*/Symbol.for("fncts.http.ServerRequest");
|
|
5
|
+
/**
|
|
6
|
+
* @tsplus type fncts.http.ServerRequest
|
|
7
|
+
* @tsplus companion fncts.http.ServerRequestOps
|
|
8
|
+
*/
|
|
9
|
+
export class ServerRequest extends IncomingMessage {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this[_a] = ServerRequestTypeId;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
_a = ServerRequestTypeId;
|
|
16
|
+
/**
|
|
17
|
+
* @tsplus static fncts.http.ServerRequestOps Tag
|
|
18
|
+
*/
|
|
19
|
+
export const ServerRequestTag = /*#__PURE__*/tsplus_module_1.makeTag();
|
|
20
|
+
//# sourceMappingURL=definition.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.mjs","names":["IncomingMessage","ServerRequestTypeId","Symbol","for","ServerRequest","constructor","_a","ServerRequestTag","tsplus_module_1","makeTag"],"sources":["../../_src/ServerRequest/definition.ts"],"sourcesContent":[null],"mappings":";;AAKA,SAASA,eAAe,QAAQ,mCAAkC;AAElE,OAAO,MAAMC,mBAAmB,gBAAGC,MAAM,CAACC,GAAG,CAAC,0BAA0B,CAAC;AAGzE;;;;AAIA,OAAM,MAAgBC,aAAc,SAAQJ,eAA6B;EAAzEK,YAAA;;IACW,KAAAC,EAAA,CAAqB,GAAwBL,mBAAmB;EAY3E;;KAZYA,mBAAmB;AAc/B;;;AAGA,OAAO,MAAMM,gBAAgB,gBAAGC,eAAA,CAAAC,OAAA,EAAoB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const fileName_1 = "(@fncts/http) src/ServerRequest/internal.ts";
|
|
2
|
+
import * as tsplus_module_1 from "@fncts/base/data/Maybe/constructors";
|
|
3
|
+
import * as tsplus_module_2 from "@fncts/http/Headers";
|
|
4
|
+
import * as tsplus_module_3 from "@fncts/io/IO/api";
|
|
5
|
+
import * as tsplus_module_4 from "@fncts/io/IO/api/memoize";
|
|
6
|
+
import * as tsplus_module_5 from "@fncts/io/IO/runtime";
|
|
7
|
+
import * as tsplus_module_6 from "@fncts/base/data/Exit/api";
|
|
8
|
+
import * as tsplus_module_7 from "@fncts/http/UrlParams";
|
|
9
|
+
import * as tsplus_module_8 from "@fncts/io/Stream/api";
|
|
10
|
+
import { RequestError } from "../RequestError.mjs";
|
|
11
|
+
import { UrlParams } from "../UrlParams.mjs";
|
|
12
|
+
import { ServerRequest } from "./definition.mjs";
|
|
13
|
+
export class ServerRequestImpl extends ServerRequest {
|
|
14
|
+
constructor(source, url, headersOverride, remoteAddressOverride) {
|
|
15
|
+
super();
|
|
16
|
+
this.source = source;
|
|
17
|
+
this.url = url;
|
|
18
|
+
this.headersOverride = headersOverride;
|
|
19
|
+
this.remoteAddressOverride = remoteAddressOverride;
|
|
20
|
+
}
|
|
21
|
+
get method() {
|
|
22
|
+
return this.source.method.toUpperCase();
|
|
23
|
+
}
|
|
24
|
+
get originalUrl() {
|
|
25
|
+
return this.source.url;
|
|
26
|
+
}
|
|
27
|
+
get remoteAddress() {
|
|
28
|
+
return tsplus_module_1.fromNullable(this.remoteAddressOverride);
|
|
29
|
+
}
|
|
30
|
+
get headers() {
|
|
31
|
+
this.headersOverride ?? (this.headersOverride = tsplus_module_2.fromHeaders(this.source.headers));
|
|
32
|
+
return this.headersOverride;
|
|
33
|
+
}
|
|
34
|
+
get text() {
|
|
35
|
+
if (this.textIO) {
|
|
36
|
+
return this.textIO;
|
|
37
|
+
}
|
|
38
|
+
this.textIO = tsplus_module_6.getOrThrow(tsplus_module_5.unsafeRun(tsplus_module_4.memoize(tsplus_module_3.fromPromiseCatch(() => this.source.text(), error => new RequestError(this, "Decode", error), fileName_1 + ":42:38"), fileName_1 + ":45:6")));
|
|
39
|
+
return this.textIO;
|
|
40
|
+
}
|
|
41
|
+
get json() {
|
|
42
|
+
return tsplus_module_3.flatMap(text => tsplus_module_3.tryCatch(() => JSON.parse(text), error => new RequestError(this, "Decode", error), fileName_1 + ":52:18"), fileName_1 + ":51:29")(this.text);
|
|
43
|
+
}
|
|
44
|
+
get urlParamsBody() {
|
|
45
|
+
return tsplus_module_3.flatMap(text => tsplus_module_3.tryCatch(() => tsplus_module_7.make(new URLSearchParams(text)), error => new RequestError(this, "Decode", error), fileName_1 + ":61:18"), fileName_1 + ":60:29")(this.text);
|
|
46
|
+
}
|
|
47
|
+
get arrayBuffer() {
|
|
48
|
+
if (this.arrayBufferIO) {
|
|
49
|
+
return this.arrayBufferIO;
|
|
50
|
+
}
|
|
51
|
+
this.arrayBufferIO = tsplus_module_6.getOrThrow(tsplus_module_5.unsafeRun(tsplus_module_4.memoize(tsplus_module_3.fromPromiseCatch(() => this.source.arrayBuffer(), error => new RequestError(this, "Decode", error), fileName_1 + ":74:45"), fileName_1 + ":77:6")));
|
|
52
|
+
return this.arrayBufferIO;
|
|
53
|
+
}
|
|
54
|
+
get stream() {
|
|
55
|
+
if (this.source.body) {
|
|
56
|
+
return tsplus_module_8.fromReadableStream(() => this.source.body, error => new RequestError(this, "Decode", error));
|
|
57
|
+
} else {
|
|
58
|
+
return tsplus_module_8.failNow(new RequestError(this, "Decode", "cannot create stream from empty body"), fileName_1 + ":86:28");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
modify(options) {
|
|
62
|
+
return new ServerRequestImpl(this.source, options.url ?? this.url, options.headers ?? this.headers, options.remoteAddress ?? this.remoteAddressOverride);
|
|
63
|
+
}
|
|
64
|
+
get upgrade() {
|
|
65
|
+
return tsplus_module_3.failNow(new RequestError(this, "Decode", "Not an upgradeable ServerRequest"), fileName_1 + ":104:22");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=internal.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.mjs","names":["RequestError","UrlParams","ServerRequest","ServerRequestImpl","constructor","source","url","headersOverride","remoteAddressOverride","method","toUpperCase","originalUrl","remoteAddress","tsplus_module_1","fromNullable","headers","tsplus_module_2","fromHeaders","text","textIO","tsplus_module_6","getOrThrow","tsplus_module_5","unsafeRun","tsplus_module_4","memoize","tsplus_module_3","fromPromiseCatch","error","fileName_1","json","flatMap","tryCatch","JSON","parse","urlParamsBody","tsplus_module_7","make","URLSearchParams","arrayBuffer","arrayBufferIO","stream","body","tsplus_module_8","fromReadableStream","failNow","modify","options","upgrade"],"sources":["../../_src/ServerRequest/internal.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;AAIA,SAASA,YAAY,QAAQ,qBAAoB;AACjD,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,aAAa,QAAQ,kBAAiB;AAE/C,OAAM,MAAOC,iBAAkB,SAAQD,aAAa;EAClDE,YACWC,MAAe,EACfC,GAAW,EACbC,eAAyB,EACxBC,qBAA8B;IAEtC,KAAK,EAAE;IALE,KAAAH,MAAM,GAANA,MAAM;IACN,KAAAC,GAAG,GAAHA,GAAG;IACL,KAAAC,eAAe,GAAfA,eAAe;IACd,KAAAC,qBAAqB,GAArBA,qBAAqB;EAG/B;EAEA,IAAIC,MAAMA,CAAA;IACR,OAAO,IAAI,CAACJ,MAAM,CAACI,MAAM,CAACC,WAAW,EAAY;EACnD;EAEA,IAAIC,WAAWA,CAAA;IACb,OAAO,IAAI,CAACN,MAAM,CAACC,GAAG;EACxB;EAEA,IAAIM,aAAaA,CAAA;IACf,OAAOC,eAAA,CAAAC,YAAA,CAAmB,IAAI,CAACN,qBAAqB,CAAC;EACvD;EAEA,IAAIO,OAAOA,CAAA;IACT,IAAI,CAACR,eAAe,KAApB,IAAI,CAACA,eAAe,GAAKS,eAAA,CAAAC,WAAA,CAAoB,IAAI,CAACZ,MAAM,CAACU,OAAO,CAAC;IACjE,OAAO,IAAI,CAACR,eA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SAAA,CAAAC,eAAA,CAAAC,OAAA,CAAGC,eAAA,CAAAC,gBAAA,OACnB,IAAI,CAACtB,MAAM,CAACkC,WAAW,EAAE,EACxBX,KAAK,IAAK,IAAI5B,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE4B,KAAK,CAAC,EAAAC,UAAA,YACnD,EAAAA,UAAA,aAA6B;IAE9B,OAAO,IAAI,CAACW,aAAa;EAC3B;EAEA,IAAIC,MAAMA,CAAA;IACR,IAAI,IAAI,CAACpC,MAAM,CAACqC,IAAI,EAAE;MACpB,OAAOC,eAAA,CAAAC,kBAAA,OAA0B,IAAI,CAACvC,MAAM,CAACqC,IAAI,EAAGd,KAAK,IAAK,IAAI5B,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE4B,KAAK,CAAC,CAAC;IACxG,CAAC,MAAM;MACL,OAAOe,eAAA,CAAAE,OAAA,CAAe,IAAI7C,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,sCAAsC,CAAC,EAAA6B,UAAA,YAAC;IACjG;EACF;EAEAiB,MAAMA,CAACC,OAIN;IACC,OAAO,IAAI5C,iBAAiB,CAC1B,IAAI,CAACE,MAAM,EACX0C,OAAO,CAACzC,GAAG,IAAI,IAAI,CAACA,GAAG,EACvByC,OAAO,CAAChC,OAAO,IAAI,IAAI,CAACA,OAAO,EAC/BgC,OAAO,CAACnC,aAAa,IAAI,IAAI,CAACJ,qBAAqB,CACpD;EACH;EAEA,IAAIwC,OAAOA,CAAA;IACT,OAAOtB,eAAA,CAAAmB,OAAA,CAAW,IAAI7C,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,kCAAkC,CAAC,EAAA6B,UAAA,aAAC;EACzF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/* eslint-disable simple-import-sort/exports */
|
|
2
|
+
// codegen:start { preset: barrel, include: ./ServerRequest/*.ts, exclude: ServerRequest/*(*internal).ts }
|
|
3
|
+
export * from "./ServerRequest/definition.mjs";
|
|
4
|
+
export * from "./ServerRequest/api.mjs";
|
|
5
|
+
//# sourceMappingURL=ServerRequest.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerRequest.mjs","names":[],"sources":["../_src/ServerRequest.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA;AACA,cAAc,gCAA+B;AAC7C,cAAc,yBAAwB"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const fileName_1 = "(@fncts/http) src/ServerResponse/api.ts";
|
|
2
|
+
import * as tsplus_module_1 from "@fncts/http/Headers";
|
|
3
|
+
import * as tsplus_module_2 from "@fncts/http/Body/api";
|
|
4
|
+
import * as tsplus_module_3 from "@fncts/io/IO/api";
|
|
5
|
+
import * as tsplus_module_4 from "@fncts/http/UrlParams";
|
|
6
|
+
import * as tsplus_module_5 from "@fncts/http/Body/definition";
|
|
7
|
+
import * as tsplus_module_6 from "@fncts/io/Stream/api";
|
|
8
|
+
import { UrlParams } from "../UrlParams.mjs";
|
|
9
|
+
import { ServerResponse } from "./definition.mjs";
|
|
10
|
+
/**
|
|
11
|
+
* @tsplus static fncts.http.ServerResponseOps empty
|
|
12
|
+
*/
|
|
13
|
+
export function empty(options) {
|
|
14
|
+
return new ServerResponse(options?.status ?? 204, options?.statusText, options?.headers ?? tsplus_module_1.empty, tsplus_module_2.empty);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @tsplus static fncts.http.ServerResponseOps uint8Array
|
|
18
|
+
*/
|
|
19
|
+
export function uint8Array(body, options) {
|
|
20
|
+
return new ServerResponse(options?.status ?? 200, options?.statusText, options?.headers ?? tsplus_module_1.empty, tsplus_module_2.uint8Array(body, getContentType(options)));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @tsplus static fncts.http.ServerResponseOps text
|
|
24
|
+
*/
|
|
25
|
+
export function text(body, options) {
|
|
26
|
+
return new ServerResponse(options?.status ?? 200, options?.statusText, options?.headers ?? tsplus_module_1.empty, tsplus_module_2.text(body, getContentType(options)));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @tsplus static fncts.http.ServerResponseOps json
|
|
30
|
+
*/
|
|
31
|
+
export function json(body, options) {
|
|
32
|
+
return tsplus_module_3.map(body => new ServerResponse(options?.status ?? 200, options?.statusText, options?.headers ?? tsplus_module_1.empty, body), fileName_1 + ":44:29")(tsplus_module_2.json(body));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @tsplus static fncts.http.ServerResponseOps schemaJson
|
|
36
|
+
*/
|
|
37
|
+
export function schemaJson(schema) {
|
|
38
|
+
const encode = tsplus_module_2.jsonSchema(schema);
|
|
39
|
+
return (body, options) => tsplus_module_3.map(body => new ServerResponse(options?.status ?? 200, options?.statusText, options?.headers ?? tsplus_module_1.empty, body), fileName_1 + ":55:21")(encode(body));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @tsplus static fncts.http.ServerResponseOps urlParams
|
|
43
|
+
*/
|
|
44
|
+
export function urlParams(body, options) {
|
|
45
|
+
return new ServerResponse(options?.status ?? 200, options?.statusText, options?.headers ?? tsplus_module_1.empty, tsplus_module_2.text(tsplus_module_4.toString(tsplus_module_4.make(body)), "application/x-www-form-urlencoded"));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @tsplus static fncts.http.ServerResponseOps stream
|
|
49
|
+
*/
|
|
50
|
+
export function stream(body, options) {
|
|
51
|
+
return new ServerResponse(options?.status ?? 200, options?.statusText, options?.headers ?? tsplus_module_1.empty, tsplus_module_2.stream(body, {
|
|
52
|
+
contentType: getContentType(options),
|
|
53
|
+
contentLength: options?.contentLength
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @tsplus pipeable fncts.http.ServerResponse setHeader
|
|
58
|
+
*/
|
|
59
|
+
export function setHeader(key, value) {
|
|
60
|
+
return self => new ServerResponse(self.status, self.statusText, self.headers.set(key, value), self.body);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @tsplus pipeable fncts.http.ServerResponse setHeaders
|
|
64
|
+
*/
|
|
65
|
+
export function setHeaders(headers) {
|
|
66
|
+
return self => new ServerResponse(self.status, self.statusText, self.headers.setAll(headers), self.body);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @tsplus pipeable fncts.http.ServerResponse setStatus
|
|
70
|
+
*/
|
|
71
|
+
export function setStatus(status, statusText) {
|
|
72
|
+
return self => new ServerResponse(status, statusText, self.headers, self.body);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @tsplus pipeable fncts.http.ServerResponse setBody
|
|
76
|
+
*/
|
|
77
|
+
export function setBody(body) {
|
|
78
|
+
return self => {
|
|
79
|
+
let headers = self.headers;
|
|
80
|
+
tsplus_module_5.concrete(body);
|
|
81
|
+
if (body._tag === 0 /* BodyTag.Empty */) {
|
|
82
|
+
headers = self.headers.remove("content-type").remove("content-length");
|
|
83
|
+
}
|
|
84
|
+
return new ServerResponse(self.status, self.statusText, headers, body);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @tsplus pipeable fncts.http.ServerResponse toWeb
|
|
89
|
+
*/
|
|
90
|
+
export function toWeb(withoutBody = false) {
|
|
91
|
+
return self => {
|
|
92
|
+
if (withoutBody) {
|
|
93
|
+
return new Response(undefined, {
|
|
94
|
+
status: self.status,
|
|
95
|
+
statusText: self.statusText,
|
|
96
|
+
headers: self.headers.toHeadersInit()
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
tsplus_module_5.concrete(self.body);
|
|
100
|
+
switch (self.body._tag) {
|
|
101
|
+
case 0 /* BodyTag.Empty */:
|
|
102
|
+
return new Response(undefined, {
|
|
103
|
+
status: self.status,
|
|
104
|
+
statusText: self.statusText,
|
|
105
|
+
headers: self.headers.toHeadersInit()
|
|
106
|
+
});
|
|
107
|
+
case 2 /* BodyTag.Uint8Array */:
|
|
108
|
+
case 1 /* BodyTag.Raw */:
|
|
109
|
+
return new Response(self.body.body, {
|
|
110
|
+
status: self.status,
|
|
111
|
+
statusText: self.statusText,
|
|
112
|
+
headers: self.headers.toHeadersInit()
|
|
113
|
+
});
|
|
114
|
+
case 3 /* BodyTag.FormData */:
|
|
115
|
+
return new Response(self.body.formData, {
|
|
116
|
+
status: self.status,
|
|
117
|
+
statusText: self.statusText,
|
|
118
|
+
headers: self.headers.toHeadersInit()
|
|
119
|
+
});
|
|
120
|
+
case 4 /* BodyTag.Stream */:
|
|
121
|
+
return new Response(tsplus_module_6.toReadableStream(self.body.stream, fileName_1 + ":160:45"), {
|
|
122
|
+
status: self.status,
|
|
123
|
+
statusText: self.statusText,
|
|
124
|
+
headers: self.headers.toHeadersInit()
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function getContentType(options) {
|
|
130
|
+
if (options?.contentType) {
|
|
131
|
+
return options.contentType;
|
|
132
|
+
} else if (options?.headers) {
|
|
133
|
+
return options.headers.unsafeGet("content-type");
|
|
134
|
+
} else {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=api.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.mjs","names":["UrlParams","ServerResponse","empty","options","status","statusText","headers","tsplus_module_1","tsplus_module_2","uint8Array","body","getContentType","text","json","tsplus_module_3","map","fileName_1","schemaJson","schema","encode","jsonSchema","urlParams","tsplus_module_4","toString","make","stream","contentType","contentLength","setHeader","key","value","self","set","setHeaders","setAll","setStatus","setBody","tsplus_module_5","concrete","_tag","remove","toWeb","withoutBody","Response","undefined","toHeadersInit","formData","tsplus_module_6","toReadableStream","unsafeGet"],"sources":["../../_src/ServerResponse/api.ts"],"sourcesContent":[null],"mappings":";;;;;;;AAKA,SAASA,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,cAAc,QAAQ,kBAAiB;AAEhD;;;AAGA,OAA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AC5B,CAAC,MAAM,IAAIvB,OAAO,EAAEG,OAAO,EAAE;IAC3B,OAAOH,OAAO,CAACG,OAAO,CAAC2C,SAAS,CAAC,cAAc,CAAC;EAClD,CAAC,MAAM;IACL;EACF;AACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import * as tsplus_module_1 from "@fncts/base/collection/immutable/HashMap/api";
|
|
3
|
+
import * as tsplus_module_2 from "@fncts/base/util/predicates";
|
|
4
|
+
import { Headers } from "../Headers.mjs";
|
|
5
|
+
export const ServerResponseTypeId = /*#__PURE__*/Symbol.for("fncts.http.ServerResponse");
|
|
6
|
+
/**
|
|
7
|
+
* @tsplus type fncts.http.ServerResponse
|
|
8
|
+
* @tsplus companion fncts.http.ServerResponseOps
|
|
9
|
+
*/
|
|
10
|
+
export class ServerResponse {
|
|
11
|
+
constructor(status, statusText, headers, body) {
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.statusText = statusText;
|
|
14
|
+
this.body = body;
|
|
15
|
+
this[_a] = ServerResponseTypeId;
|
|
16
|
+
if (body.contentType || body.contentLength) {
|
|
17
|
+
const newHeaders = tsplus_module_1.beginMutation(headers.backing);
|
|
18
|
+
if (body.contentType) {
|
|
19
|
+
tsplus_module_1.set("content-type", body.contentType)(newHeaders);
|
|
20
|
+
}
|
|
21
|
+
if (body.contentLength) {
|
|
22
|
+
tsplus_module_1.set("content-length", body.contentLength.toString())(newHeaders);
|
|
23
|
+
}
|
|
24
|
+
this.headers = new Headers(tsplus_module_1.endMutation(newHeaders));
|
|
25
|
+
} else {
|
|
26
|
+
this.headers = headers;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
_a = ServerResponseTypeId;
|
|
31
|
+
export function isServerResponse(u) {
|
|
32
|
+
return tsplus_module_2.isObject(u) && ServerResponseTypeId in u;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=definition.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.mjs","names":["Headers","ServerResponseTypeId","Symbol","for","ServerResponse","constructor","status","statusText","headers","body","_a","contentType","contentLength","newHeaders","tsplus_module_1","beginMutation","backing","set","toString","endMutation","isServerResponse","u","tsplus_module_2","isObject"],"sources":["../../_src/ServerResponse/definition.ts"],"sourcesContent":[null],"mappings":";;;AAEA,SAASA,OAAO,QAAQ,gBAAe;AAEvC,OAAO,MAAMC,oBAAoB,gBAAGC,MAAM,CAACC,GAAG,CAAC,2BAA2B,CAAC;AAG3E;;;;AAIA,OAAM,MAAOC,cAAc;EAGzBC,YACWC,MAAc,EACdC,UAA8B,EACvCC,OAAgB,EACPC,IAAU;IAHV,KAAAH,MAAM,GAANA,MAAM;IACN,KAAAC,UAAU,GAAVA,UAAU;IAEV,KAAAE,IAAI,GAAJA,IAAI;IANN,KAAAC,EAAA,CAAsB,GAAyBT,oBAAoB;IAQ1E,IAAIQ,IAAI,CAACE,WAAW,IAAIF,IAAI,CAACG,aAAa,EAAE;MAC1C,MAAMC,UAAU,GAAAC,eAAA,CAAAC,aAAA,CAAGP,OAAO,CAACQ,OAAO,CAAc;MAChD,IAAIP,IAAI,CAACE,WAAW,EAAE;QACpBG,eAAA,CAAAG,GAAA,CAAe,cAAc,EAAER,IAAI,CAACE,WAAW,EAA/CE,UAAU,CAAsC;MAClD;MACA,IAAIJ,IAAI,CAACG,aAAa,EAAE;QACtBE,eAAA,CAAAG,GAAA,CAAe,gBAAgB,EAAER,IAAI,CAACG,aAAa,CAACM,QAAQ,EAAE,EAA9DL,UAAU,CAAqD;MACjE;MACA,IAAI,CAACL,OAAO,GAAG,IAAIR,OAAO,CAAAc,eAAA,CAAAK,WAAA,CAACN,UAAU,EAAa;IACpD,CAAC,MAAM;MACL,IAAI,CAACL,OAAO,GAAGA,OAAO;IACxB;EACF;;KApBUP,oBAAoB;AAoChC,OAAM,SAAUmB,gBAAgBA,CAACC,CAAU;EACzC,OAAOC,eAAA,CAAAC,QAAQ,CAACF,CAAC,CAAC,IAAIpB,oBAAoB,IAAIoB,CAAC;AACjD"}
|