@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.
Files changed (211) hide show
  1. package/Body/api.d.ts +63 -0
  2. package/Body/definition.d.ts +53 -0
  3. package/Body.d.ts +2 -0
  4. package/BodyError.d.ts +30 -0
  5. package/Headers.d.ts +42 -0
  6. package/HttpApp.d.ts +46 -0
  7. package/IncomingMessage/api.d.ts +19 -0
  8. package/IncomingMessage/definition.d.ts +21 -0
  9. package/IncomingMessage.d.ts +2 -0
  10. package/Method.d.ts +2 -0
  11. package/Middleware.d.ts +24 -0
  12. package/QueryParams.d.ts +7 -0
  13. package/RequestError.d.ts +10 -0
  14. package/ResponseError.d.ts +14 -0
  15. package/Route/api.d.ts +37 -0
  16. package/Route/definition.d.ts +35 -0
  17. package/Route/internal.d.ts +17 -0
  18. package/Route.d.ts +2 -0
  19. package/RouteNotFound.d.ts +8 -0
  20. package/Router/api.d.ts +96 -0
  21. package/Router/definition.d.ts +28 -0
  22. package/Router/internal.d.ts +26 -0
  23. package/Router.d.ts +2 -0
  24. package/Server.d.ts +53 -0
  25. package/ServerError.d.ts +9 -0
  26. package/ServerRequest/api.d.ts +6 -0
  27. package/ServerRequest/definition.d.ts +30 -0
  28. package/ServerRequest/internal.d.ts +33 -0
  29. package/ServerRequest.d.ts +2 -0
  30. package/ServerResponse/api.d.ts +69 -0
  31. package/ServerResponse/definition.d.ts +30 -0
  32. package/ServerResponse.d.ts +2 -0
  33. package/Socket.d.ts +107 -0
  34. package/UrlParams.d.ts +21 -0
  35. package/_cjs/Body/api.cjs +93 -0
  36. package/_cjs/Body/api.cjs.map +1 -0
  37. package/_cjs/Body/definition.cjs +71 -0
  38. package/_cjs/Body/definition.cjs.map +1 -0
  39. package/_cjs/Body.cjs +28 -0
  40. package/_cjs/Body.cjs.map +1 -0
  41. package/_cjs/BodyError.cjs +43 -0
  42. package/_cjs/BodyError.cjs.map +1 -0
  43. package/_cjs/Headers.cjs +87 -0
  44. package/_cjs/Headers.cjs.map +1 -0
  45. package/_cjs/HttpApp.cjs +109 -0
  46. package/_cjs/HttpApp.cjs.map +1 -0
  47. package/_cjs/IncomingMessage/api.cjs +35 -0
  48. package/_cjs/IncomingMessage/api.cjs.map +1 -0
  49. package/_cjs/IncomingMessage/definition.cjs +20 -0
  50. package/_cjs/IncomingMessage/definition.cjs.map +1 -0
  51. package/_cjs/IncomingMessage.cjs +28 -0
  52. package/_cjs/IncomingMessage.cjs.map +1 -0
  53. package/_cjs/Method.cjs +10 -0
  54. package/_cjs/Method.cjs.map +1 -0
  55. package/_cjs/Middleware.cjs +16 -0
  56. package/_cjs/Middleware.cjs.map +1 -0
  57. package/_cjs/QueryParams.cjs +6 -0
  58. package/_cjs/QueryParams.cjs.map +1 -0
  59. package/_cjs/RequestError.cjs +19 -0
  60. package/_cjs/RequestError.cjs.map +1 -0
  61. package/_cjs/ResponseError.cjs +27 -0
  62. package/_cjs/ResponseError.cjs.map +1 -0
  63. package/_cjs/Route/api.cjs +61 -0
  64. package/_cjs/Route/api.cjs.map +1 -0
  65. package/_cjs/Route/definition.cjs +35 -0
  66. package/_cjs/Route/definition.cjs.map +1 -0
  67. package/_cjs/Route/internal.cjs +31 -0
  68. package/_cjs/Route/internal.cjs.map +1 -0
  69. package/_cjs/Route.cjs +28 -0
  70. package/_cjs/Route.cjs.map +1 -0
  71. package/_cjs/RouteNotFound.cjs +18 -0
  72. package/_cjs/RouteNotFound.cjs.map +1 -0
  73. package/_cjs/Router/api.cjs +141 -0
  74. package/_cjs/Router/api.cjs.map +1 -0
  75. package/_cjs/Router/definition.cjs +22 -0
  76. package/_cjs/Router/definition.cjs.map +1 -0
  77. package/_cjs/Router/internal.cjs +85 -0
  78. package/_cjs/Router/internal.cjs.map +1 -0
  79. package/_cjs/Router.cjs +28 -0
  80. package/_cjs/Router.cjs.map +1 -0
  81. package/_cjs/Server.cjs +53 -0
  82. package/_cjs/Server.cjs.map +1 -0
  83. package/_cjs/ServerError.cjs +21 -0
  84. package/_cjs/ServerError.cjs.map +1 -0
  85. package/_cjs/ServerRequest/api.cjs +14 -0
  86. package/_cjs/ServerRequest/api.cjs.map +1 -0
  87. package/_cjs/ServerRequest/definition.cjs +29 -0
  88. package/_cjs/ServerRequest/definition.cjs.map +1 -0
  89. package/_cjs/ServerRequest/internal.cjs +77 -0
  90. package/_cjs/ServerRequest/internal.cjs.map +1 -0
  91. package/_cjs/ServerRequest.cjs +28 -0
  92. package/_cjs/ServerRequest.cjs.map +1 -0
  93. package/_cjs/ServerResponse/api.cjs +157 -0
  94. package/_cjs/ServerResponse/api.cjs.map +1 -0
  95. package/_cjs/ServerResponse/definition.cjs +44 -0
  96. package/_cjs/ServerResponse/definition.cjs.map +1 -0
  97. package/_cjs/ServerResponse.cjs +28 -0
  98. package/_cjs/ServerResponse.cjs.map +1 -0
  99. package/_cjs/Socket.cjs +221 -0
  100. package/_cjs/Socket.cjs.map +1 -0
  101. package/_cjs/UrlParams.cjs +34 -0
  102. package/_cjs/UrlParams.cjs.map +1 -0
  103. package/_cjs/global.cjs +6 -0
  104. package/_cjs/global.cjs.map +1 -0
  105. package/_mjs/Body/api.mjs +78 -0
  106. package/_mjs/Body/api.mjs.map +1 -0
  107. package/_mjs/Body/definition.mjs +58 -0
  108. package/_mjs/Body/definition.mjs.map +1 -0
  109. package/_mjs/Body.mjs +5 -0
  110. package/_mjs/Body.mjs.map +1 -0
  111. package/_mjs/BodyError.mjs +33 -0
  112. package/_mjs/BodyError.mjs.map +1 -0
  113. package/_mjs/Headers.mjs +75 -0
  114. package/_mjs/Headers.mjs.map +1 -0
  115. package/_mjs/HttpApp.mjs +96 -0
  116. package/_mjs/HttpApp.mjs.map +1 -0
  117. package/_mjs/IncomingMessage/api.mjs +25 -0
  118. package/_mjs/IncomingMessage/api.mjs.map +1 -0
  119. package/_mjs/IncomingMessage/definition.mjs +13 -0
  120. package/_mjs/IncomingMessage/definition.mjs.map +1 -0
  121. package/_mjs/IncomingMessage.mjs +5 -0
  122. package/_mjs/IncomingMessage.mjs.map +1 -0
  123. package/_mjs/Method.mjs +4 -0
  124. package/_mjs/Method.mjs.map +1 -0
  125. package/_mjs/Middleware.mjs +9 -0
  126. package/_mjs/Middleware.mjs.map +1 -0
  127. package/_mjs/QueryParams.mjs +2 -0
  128. package/_mjs/QueryParams.mjs.map +1 -0
  129. package/_mjs/RequestError.mjs +12 -0
  130. package/_mjs/RequestError.mjs.map +1 -0
  131. package/_mjs/ResponseError.mjs +20 -0
  132. package/_mjs/ResponseError.mjs.map +1 -0
  133. package/_mjs/Route/api.mjs +48 -0
  134. package/_mjs/Route/api.mjs.map +1 -0
  135. package/_mjs/Route/definition.mjs +25 -0
  136. package/_mjs/Route/definition.mjs.map +1 -0
  137. package/_mjs/Route/internal.mjs +21 -0
  138. package/_mjs/Route/internal.mjs.map +1 -0
  139. package/_mjs/Route.mjs +5 -0
  140. package/_mjs/Route.mjs.map +1 -0
  141. package/_mjs/RouteNotFound.mjs +11 -0
  142. package/_mjs/RouteNotFound.mjs.map +1 -0
  143. package/_mjs/Router/api.mjs +123 -0
  144. package/_mjs/Router/api.mjs.map +1 -0
  145. package/_mjs/Router/definition.mjs +15 -0
  146. package/_mjs/Router/definition.mjs.map +1 -0
  147. package/_mjs/Router/internal.mjs +76 -0
  148. package/_mjs/Router/internal.mjs.map +1 -0
  149. package/_mjs/Router.mjs +5 -0
  150. package/_mjs/Router.mjs.map +1 -0
  151. package/_mjs/Server.mjs +41 -0
  152. package/_mjs/Server.mjs.map +1 -0
  153. package/_mjs/ServerError.mjs +14 -0
  154. package/_mjs/ServerError.mjs.map +1 -0
  155. package/_mjs/ServerRequest/api.mjs +8 -0
  156. package/_mjs/ServerRequest/api.mjs.map +1 -0
  157. package/_mjs/ServerRequest/definition.mjs +20 -0
  158. package/_mjs/ServerRequest/definition.mjs.map +1 -0
  159. package/_mjs/ServerRequest/internal.mjs +68 -0
  160. package/_mjs/ServerRequest/internal.mjs.map +1 -0
  161. package/_mjs/ServerRequest.mjs +5 -0
  162. package/_mjs/ServerRequest.mjs.map +1 -0
  163. package/_mjs/ServerResponse/api.mjs +138 -0
  164. package/_mjs/ServerResponse/api.mjs.map +1 -0
  165. package/_mjs/ServerResponse/definition.mjs +34 -0
  166. package/_mjs/ServerResponse/definition.mjs.map +1 -0
  167. package/_mjs/ServerResponse.mjs +5 -0
  168. package/_mjs/ServerResponse.mjs.map +1 -0
  169. package/_mjs/Socket.mjs +202 -0
  170. package/_mjs/Socket.mjs.map +1 -0
  171. package/_mjs/UrlParams.mjs +25 -0
  172. package/_mjs/UrlParams.mjs.map +1 -0
  173. package/_mjs/global.mjs +2 -0
  174. package/_mjs/global.mjs.map +1 -0
  175. package/_src/Body/api.ts +106 -0
  176. package/_src/Body/definition.ts +74 -0
  177. package/_src/Body.ts +5 -0
  178. package/_src/BodyError.ts +38 -0
  179. package/_src/Headers.ts +84 -0
  180. package/_src/HttpApp.ts +129 -0
  181. package/_src/IncomingMessage/api.ts +25 -0
  182. package/_src/IncomingMessage/definition.ts +20 -0
  183. package/_src/IncomingMessage.ts +5 -0
  184. package/_src/Method.ts +5 -0
  185. package/_src/Middleware.ts +29 -0
  186. package/_src/QueryParams.ts +7 -0
  187. package/_src/RequestError.ts +13 -0
  188. package/_src/ResponseError.ts +25 -0
  189. package/_src/Route/api.ts +53 -0
  190. package/_src/Route/definition.ts +40 -0
  191. package/_src/Route/internal.ts +25 -0
  192. package/_src/Route.ts +5 -0
  193. package/_src/RouteNotFound.ts +14 -0
  194. package/_src/Router/api.ts +161 -0
  195. package/_src/Router/definition.ts +29 -0
  196. package/_src/Router/internal.ts +95 -0
  197. package/_src/Router.ts +5 -0
  198. package/_src/Server.ts +88 -0
  199. package/_src/ServerError.ts +14 -0
  200. package/_src/ServerRequest/api.ts +10 -0
  201. package/_src/ServerRequest/definition.ts +33 -0
  202. package/_src/ServerRequest/internal.ts +106 -0
  203. package/_src/ServerRequest.ts +5 -0
  204. package/_src/ServerResponse/api.ts +177 -0
  205. package/_src/ServerResponse/definition.ts +51 -0
  206. package/_src/ServerResponse.ts +5 -0
  207. package/_src/Socket.ts +294 -0
  208. package/_src/UrlParams.ts +28 -0
  209. package/_src/global.ts +2 -0
  210. package/global.d.ts +1 -0
  211. package/package.json +27 -0
package/Body/api.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ import { IO } from "@fncts/io/IO";
2
+ import { Schema } from "@fncts/schema/Schema/definition";
3
+ import type { BodyError } from "../BodyError.js";
4
+ import type * as Stream_ from "@fncts/io/Stream";
5
+ import { Body } from "./definition.js";
6
+ import { Empty, FormData, Raw, Stream, Uint8Array } from "./definition.js";
7
+ /**
8
+ * @tsplus static fncts.http.BodyOps empty
9
+ * @tsplus location "@fncts/http/Body/api"
10
+ */
11
+ export declare const empty: Empty;
12
+ /**
13
+ * @tsplus static fncts.http.BodyOps raw
14
+ * @tsplus location "@fncts/http/Body/api"
15
+ */
16
+ export declare function raw(body: unknown, options?: {
17
+ contentType?: string;
18
+ contentLength?: number;
19
+ }): Body;
20
+ /**
21
+ * @tsplus static fncts.http.BodyOps uint8Array
22
+ * @tsplus location "@fncts/http/Body/api"
23
+ */
24
+ export declare function uint8Array(body: globalThis.Uint8Array, contentType?: string): Body;
25
+ /**
26
+ * @tsplus static fncts.http.BodyOps text
27
+ * @tsplus location "@fncts/http/Body/api"
28
+ */
29
+ export declare function text(body: string, contentType?: string): Body;
30
+ /**
31
+ * @tsplus static fncts.http.BodyOps json
32
+ * @tsplus location "@fncts/http/Body/api"
33
+ */
34
+ export declare function json(body: unknown): IO<never, BodyError, Body>;
35
+ /**
36
+ * @tsplus static fncts.http.BodyOps jsonSchema
37
+ * @tsplus location "@fncts/http/Body/api"
38
+ */
39
+ export declare function jsonSchema<A>(schema: Schema<A>): (body: A) => IO<never, BodyError, Body>;
40
+ /**
41
+ * @tsplus static fncts.http.BodyOps formData
42
+ * @tsplus location "@fncts/http/Body/api"
43
+ */
44
+ export declare function formData(body: globalThis.FormData): Body;
45
+ /**
46
+ * @tsplus static fncts.http.BodyOps stream
47
+ * @tsplus location "@fncts/http/Body/api"
48
+ */
49
+ export declare function stream(body: Stream_.Stream<never, unknown, globalThis.Uint8Array>, options?: {
50
+ contentType?: string;
51
+ contentLength?: number;
52
+ }): Body;
53
+ /**
54
+ * @tsplus pipeable fncts.http.Body match
55
+ * @tsplus location "@fncts/http/Body/api"
56
+ */
57
+ export declare function match<A, B, C, D, E>(cases: {
58
+ Empty: (body: Empty) => A;
59
+ Raw: (body: Raw) => B;
60
+ Uint8Array: (body: Uint8Array) => C;
61
+ FormData: (body: FormData) => D;
62
+ Stream: (body: Stream) => E;
63
+ }): (body: Body) => A | B | C | D | E;
@@ -0,0 +1,53 @@
1
+ import type * as Stream_ from "@fncts/io/Stream";
2
+ export declare const BodyTypeId: unique symbol;
3
+ export type BodyTypeId = typeof BodyTypeId;
4
+ export declare const enum BodyTag {
5
+ Empty = 0,
6
+ Raw = 1,
7
+ Uint8Array = 2,
8
+ FormData = 3,
9
+ Stream = 4
10
+ }
11
+ /**
12
+ * @tsplus type fncts.http.Body
13
+ * @tsplus companion fncts.http.BodyOps
14
+ */
15
+ export declare abstract class Body {
16
+ readonly [BodyTypeId]: BodyTypeId;
17
+ readonly contentType?: string;
18
+ readonly contentLength?: number;
19
+ }
20
+ export declare class Empty extends Body {
21
+ readonly _tag = BodyTag.Empty;
22
+ }
23
+ export declare class Raw extends Body {
24
+ readonly body: unknown;
25
+ readonly contentType?: string | undefined;
26
+ readonly contentLength?: number | undefined;
27
+ readonly _tag = BodyTag.Raw;
28
+ constructor(body: unknown, contentType?: string | undefined, contentLength?: number | undefined);
29
+ }
30
+ export declare class Uint8Array extends Body {
31
+ readonly body: globalThis.Uint8Array;
32
+ readonly contentType: string;
33
+ readonly _tag = BodyTag.Uint8Array;
34
+ constructor(body: globalThis.Uint8Array, contentType: string);
35
+ }
36
+ export declare class FormData extends Body {
37
+ readonly formData: globalThis.FormData;
38
+ readonly _tag = BodyTag.FormData;
39
+ constructor(formData: globalThis.FormData);
40
+ }
41
+ export declare class Stream extends Body {
42
+ readonly stream: Stream_.Stream<never, unknown, globalThis.Uint8Array>;
43
+ readonly contentType: string;
44
+ readonly contentLength?: number | undefined;
45
+ readonly _tag = BodyTag.Stream;
46
+ constructor(stream: Stream_.Stream<never, unknown, globalThis.Uint8Array>, contentType: string, contentLength?: number | undefined);
47
+ }
48
+ export type ConcreteBody = Empty | Raw | Uint8Array | FormData | Stream;
49
+ /**
50
+ * @tsplus fluent fncts.http.Body concrete
51
+ * @tsplus location "@fncts/http/Body/definition"
52
+ */
53
+ export declare function concrete(self: Body): asserts self is ConcreteBody;
package/Body.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./Body/definition.js";
2
+ export * from "./Body/api.js";
package/BodyError.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { ParseFailure } from "@fncts/schema/ParseFailure";
2
+ export declare const BodyErrorTypeId: unique symbol;
3
+ export type BodyErrorTypeId = typeof BodyErrorTypeId;
4
+ export declare const enum BodyErrorTag {
5
+ JsonError = 0,
6
+ SchemaError = 1
7
+ }
8
+ /**
9
+ * @tsplus type fncts.http.BodyError
10
+ * @tsplus concrete fncts.http.BodyErrorOps
11
+ */
12
+ export declare abstract class BodyError {
13
+ readonly [BodyErrorTypeId]: BodyErrorTypeId;
14
+ }
15
+ export declare class JsonError extends BodyError {
16
+ readonly error: unknown;
17
+ readonly _tag = BodyErrorTag.JsonError;
18
+ constructor(error: unknown);
19
+ }
20
+ export declare class SchemaError extends BodyError {
21
+ readonly error: ParseFailure;
22
+ readonly _tag = BodyErrorTag.SchemaError;
23
+ constructor(error: ParseFailure);
24
+ }
25
+ export type Concrete = JsonError | SchemaError;
26
+ /**
27
+ * @tsplus fluent fncts.http.BodyError concrete
28
+ * @tsplus location "@fncts/http/BodyError"
29
+ */
30
+ export declare function concrete(self: BodyError): asserts self is Concrete;
package/Headers.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { HashMap } from "@fncts/base/collection/immutable/HashMap/definition";
2
+ import { Maybe } from "@fncts/base/data/Maybe/definition";
3
+ export declare const HeadersTypeId: unique symbol;
4
+ export type HeadersTypeId = typeof HeadersTypeId;
5
+ /**
6
+ * @tsplus type fncts.http.Headers
7
+ * @tsplus companion fncts.http.HeadersOps
8
+ */
9
+ export declare class Headers {
10
+ readonly backing: HashMap<string, string>;
11
+ readonly [HeadersTypeId]: HeadersTypeId;
12
+ constructor(backing: HashMap<string, string>);
13
+ set(key: string, value: string): Headers;
14
+ remove(key: string): Headers;
15
+ get(key: string): Maybe<string>;
16
+ unsafeGet(key: string): string | undefined;
17
+ setAll(input: Headers.Input): Headers;
18
+ toHeadersInit(): Array<[string, string]>;
19
+ }
20
+ export declare namespace Headers {
21
+ type Input = Readonly<Record<string, string>> | Iterable<readonly [string, string]>;
22
+ }
23
+ /**
24
+ * @tsplus static fncts.http.HeadersOps isHeaders
25
+ * @tsplus location "@fncts/http/Headers"
26
+ */
27
+ export declare function isHeaders(u: unknown): u is Headers;
28
+ /**
29
+ * @tsplus static fncts.http.HeadersOps empty
30
+ * @tsplus location "@fncts/http/Headers"
31
+ */
32
+ export declare const empty: Headers;
33
+ /**
34
+ * @tsplus static fncts.http.HeadersOps fromHeaders
35
+ * @tsplus location "@fncts/http/Headers"
36
+ */
37
+ export declare function fromHeaders(headers: globalThis.Headers): Headers;
38
+ /**
39
+ * @tsplus static fncts.http.HeadersOps __call
40
+ * @tsplus location "@fncts/http/Headers"
41
+ */
42
+ export declare function make(input: Headers.Input): Headers;
package/HttpApp.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { IO, FIO, UIO } from "@fncts/io/IO";
2
+ import { Exit } from "@fncts/base/data/Exit/definition";
3
+ import { Scope } from "@fncts/io/Scope/definition";
4
+ import { Maybe } from "@fncts/base/data/Maybe/definition";
5
+ import type { Middleware } from "./Middleware.js";
6
+ import type { ServerResponse } from "./ServerResponse.js";
7
+ import type { ResponseError } from "@fncts/http/ResponseError";
8
+ import { type Runtime } from "@fncts/io/IO";
9
+ import { ServerRequest } from "./ServerRequest.js";
10
+ /**
11
+ * @tsplus type fncts.http.HttpApp
12
+ */
13
+ export interface HttpApp<R, E, A> extends IO<R | ServerRequest, E, A> {
14
+ }
15
+ /**
16
+ * @tsplus type fncts.http.HttpAppOps
17
+ */
18
+ export interface HttpAppOps {
19
+ }
20
+ export declare const HttpApp: HttpAppOps;
21
+ export declare namespace HttpApp {
22
+ type Default<R, E> = HttpApp<R, E, ServerResponse>;
23
+ }
24
+ /**
25
+ * @tsplus pipeable fncts.http.HttpApp toHandled
26
+ * @tsplus location "@fncts/http/HttpApp"
27
+ */
28
+ export declare function toHandled<E, RH>(handleResponse: (request: ServerRequest, exit: Exit<E | ResponseError, ServerResponse>) => IO<RH, never, any>, middleware?: Middleware): <R>(self: HttpApp.Default<R, E>) => HttpApp.Default<Exclude<RH, import("@fncts/io/Scope.js").Scope> | Exclude<R, import("@fncts/io/Scope.js").Scope>, ResponseError | E>;
29
+ export type PreResponseHandler = (request: ServerRequest, response: ServerResponse) => FIO<ResponseError, ServerResponse>;
30
+ /**
31
+ * @tsplus static fncts.http.HttpAppOps currentPreResponseHandlers
32
+ * @tsplus location "@fncts/http/HttpApp"
33
+ */
34
+ export declare const currentPreResponseHandlers: import("@fncts/io/FiberRef.js").FiberRef.WithPatch<import("@fncts/base/data/Maybe.js").Maybe<PreResponseHandler>, (_: import("@fncts/base/data/Maybe.js").Maybe<PreResponseHandler>) => import("@fncts/base/data/Maybe.js").Maybe<PreResponseHandler>>;
35
+ /**
36
+ * @tsplus static fncts.http.HttpAppOps appendPreResponseHandler
37
+ * @tsplus location "@fncts/http/HttpApp"
38
+ */
39
+ export declare function appendPreResponseHandler(handler: PreResponseHandler): UIO<void>;
40
+ /**
41
+ * @tsplus pipeable fncts.http.HttpApp withPreResponseHandler
42
+ * @tsplus location "@fncts/http/HttpApp"
43
+ */
44
+ export declare function withPreResponseHandler(handler: PreResponseHandler): <R, E, A>(self: HttpApp<R, E, A>) => HttpApp<R, E, A>;
45
+ export declare function toWebHandlerRuntime<R>(runtime: Runtime<R>): <E>(self: HttpApp.Default<import("@fncts/io/Scope.js").Scope | R, E>) => (request: Request) => Promise<Response>;
46
+ export declare function toWebHandler<E>(self: HttpApp.Default<Scope, E>): (request: Request) => Promise<Response>;
@@ -0,0 +1,19 @@
1
+ import { Schema } from "@fncts/schema/Schema/definition";
2
+ import { IO } from "@fncts/io/IO";
3
+ import { ParseFailure } from "@fncts/schema/ParseFailure";
4
+ import type { IncomingMessage } from "./definition.js";
5
+ /**
6
+ * @tsplus pipeable fncts.http.IncomingMessage schemaBodyJson
7
+ * @tsplus location "@fncts/http/IncomingMessage/api"
8
+ */
9
+ export declare function schemaBodyJson<A>(schema: Schema<A>): <E>(self: IncomingMessage<E>) => IO<never, E | ParseFailure, A>;
10
+ /**
11
+ * @tsplus pipeable fncts.http.IncomingMessage schemaBodyUrlParams
12
+ * @tsplus location "@fncts/http/IncomingMessage/api"
13
+ */
14
+ export declare function schemaBodyUrlParams<A>(schema: Schema<A>): <E>(self: IncomingMessage<E>) => IO<never, E | ParseFailure, A>;
15
+ /**
16
+ * @tsplus pipeable fncts.http.IncomingMessage schemaHeaders
17
+ * @tsplus location "@fncts/http/IncomingMessage/api"
18
+ */
19
+ export declare function schemaHeaders<A>(schema: Schema<A>): <E>(self: IncomingMessage<E>) => IO<never, E | ParseFailure, A>;
@@ -0,0 +1,21 @@
1
+ import { Maybe } from "@fncts/base/data/Maybe/definition";
2
+ import { IO } from "@fncts/io/IO";
3
+ import { Stream } from "@fncts/io/Stream";
4
+ import type { Headers } from "../Headers.js";
5
+ import type { UrlParams } from "../UrlParams.js";
6
+ export declare const IncomingMessageTypeId: unique symbol;
7
+ export type IncomingMessageTypeId = typeof IncomingMessageTypeId;
8
+ /**
9
+ * @tsplus type fncts.http.IncomingMessage
10
+ * @tsplus companion fncts.http.IncomingMessageOps
11
+ */
12
+ export declare abstract class IncomingMessage<E> {
13
+ readonly [IncomingMessageTypeId]: IncomingMessageTypeId;
14
+ abstract readonly headers: Headers;
15
+ abstract readonly remoteAddress: Maybe<string>;
16
+ abstract readonly json: IO<never, E, unknown>;
17
+ abstract readonly text: IO<never, E, string>;
18
+ abstract readonly urlParamsBody: IO<never, E, UrlParams>;
19
+ abstract readonly arrayBuffer: IO<never, E, ArrayBuffer>;
20
+ abstract readonly stream: Stream<never, E, Uint8Array>;
21
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./IncomingMessage/definition.js";
2
+ export * from "./IncomingMessage/api.js";
package/Method.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export type Method = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
2
+ export declare function hasBody(method: Method): boolean;
@@ -0,0 +1,24 @@
1
+ import type { HttpApp } from "@fncts/http/HttpApp";
2
+ /**
3
+ * @tsplus type fncts.http.Middleware
4
+ */
5
+ export interface Middleware {
6
+ <R, E>(self: HttpApp.Default<R, E>): HttpApp.Default<any, any>;
7
+ }
8
+ /**
9
+ * @tsplus type fncts.http.MiddlewareOps
10
+ */
11
+ export interface MiddlewareOps {
12
+ }
13
+ export declare const Middleware: MiddlewareOps;
14
+ export declare namespace Middleware {
15
+ interface Applied<R, E, A extends HttpApp.Default<any, any>> {
16
+ (self: HttpApp.Default<R, E>): A;
17
+ }
18
+ }
19
+ /**
20
+ * @tsplus static fncts.http.MiddlewareOps __call
21
+ * @tsplus static fncts.http.MiddlewareOps make
22
+ * @tsplus location "@fncts/http/Middleware"
23
+ */
24
+ export declare function make<M extends Middleware>(middleware: M): M;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @tsplus type fncts.http.QueryParams
3
+ * @tsplus companion fncts.http.QueryParams
4
+ */
5
+ export interface QueryParams {
6
+ [param: string]: string;
7
+ }
@@ -0,0 +1,10 @@
1
+ import type { ServerRequest } from "./ServerRequest";
2
+ export declare const RequestErrorTypeId: unique symbol;
3
+ export type RequestErrorTypeId = typeof RequestErrorTypeId;
4
+ export declare class RequestError {
5
+ readonly request: ServerRequest;
6
+ readonly reason: "Transport" | "Decode";
7
+ readonly error: unknown;
8
+ readonly [RequestErrorTypeId]: RequestErrorTypeId;
9
+ constructor(request: ServerRequest, reason: "Transport" | "Decode", error: unknown);
10
+ }
@@ -0,0 +1,14 @@
1
+ import { ServerRequest } from "@fncts/http/ServerRequest";
2
+ import { ServerResponse } from "@fncts/http/ServerResponse";
3
+ export declare const ResponseErrorTypeId: unique symbol;
4
+ export type ResponseErrorTypeId = typeof ResponseErrorTypeId;
5
+ export declare class ResponseError extends Error {
6
+ readonly request: ServerRequest;
7
+ readonly response: ServerResponse;
8
+ readonly reason: "Decode";
9
+ readonly error: unknown;
10
+ readonly [ResponseErrorTypeId]: ResponseErrorTypeId;
11
+ constructor(request: ServerRequest, response: ServerResponse, reason: "Decode", error: unknown);
12
+ get methodAndUrl(): string;
13
+ get message(): string;
14
+ }
package/Route/api.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { Schema } from "@fncts/schema/Schema/definition";
2
+ import { IO } from "@fncts/io/IO";
3
+ import { ParseFailure } from "@fncts/schema/ParseFailure";
4
+ import { Maybe } from "@fncts/base/data/Maybe/definition";
5
+ import type { Method } from "../Method.js";
6
+ import type { PathInput, Route } from "./definition.js";
7
+ import { RouteContext } from "./definition.js";
8
+ /**
9
+ * @tsplus static fncts.http.RouteContextOps params
10
+ * @tsplus location "@fncts/http/Route/api"
11
+ */
12
+ export declare const params: import("@fncts/io/IO.js").IO<RouteContext, never, Readonly<Record<string, string | undefined>>>;
13
+ /**
14
+ * @tsplus static fncts.http.RouteContextOps searchParams
15
+ * @tsplus location "@fncts/http/Route/api"
16
+ */
17
+ export declare const searchParams: import("@fncts/io/IO.js").IO<RouteContext, never, Readonly<Record<string, string>>>;
18
+ /**
19
+ * @tsplus static fncts.http.RouteContextOps schemaParams
20
+ * @tsplus location "@fncts/http/Route/api"
21
+ */
22
+ export declare function schemaParams<A>(schema: Schema<A>): IO<RouteContext, ParseFailure, A>;
23
+ /**
24
+ * @tsplus static fncts.http.RouteContextOps schemaPathParams
25
+ * @tsplus location "@fncts/http/Route/api"
26
+ */
27
+ export declare function schemaPathParams<A>(schema: Schema<A>): IO<RouteContext, ParseFailure, A>;
28
+ /**
29
+ * @tsplus static fncts.http.RouteContextOps schemaSearchParams
30
+ * @tsplus location "@fncts/http/Route/api"
31
+ */
32
+ export declare function schemaSearchParams<A>(schema: Schema<A>): IO<RouteContext, ParseFailure, A>;
33
+ /**
34
+ * @tsplus static fncts.http.RouteOps __call
35
+ * @tsplus location "@fncts/http/Route/api"
36
+ */
37
+ export declare function make<R, E>(method: Method, path: PathInput, handler: Route.Handler<R, E>, prefix?: Maybe<string>): Route<R, E>;
@@ -0,0 +1,35 @@
1
+ import { Maybe } from "@fncts/base/data/Maybe/definition";
2
+ import { IO } from "@fncts/io/IO";
3
+ import type { Method } from "../Method.js";
4
+ import type { ServerRequest } from "../ServerRequest";
5
+ import type { ServerResponse } from "../ServerResponse.js";
6
+ export declare const RouteTypeId: unique symbol;
7
+ export type RouteTypeId = typeof RouteTypeId;
8
+ export type PathInput = `/${string}` | "*";
9
+ export declare abstract class Route<R, E> {
10
+ readonly [RouteTypeId]: RouteTypeId;
11
+ abstract readonly method: Method | "*";
12
+ abstract readonly path: PathInput;
13
+ abstract readonly handler: Route.Handler<R, E>;
14
+ abstract readonly prefix: Maybe<string>;
15
+ }
16
+ export declare namespace Route {
17
+ type Handler<R, E> = IO<R | ServerRequest | RouteContext, E, ServerResponse>;
18
+ }
19
+ export declare const RouteContextTypeId: unique symbol;
20
+ export type RouteContextTypeId = typeof RouteContextTypeId;
21
+ /**
22
+ * @tsplus type fncts.http.RouteContext
23
+ * @tsplus companion fncts.http.RouteContextOps
24
+ */
25
+ export declare abstract class RouteContext {
26
+ readonly [RouteContextTypeId]: RouteContextTypeId;
27
+ abstract readonly route: Route<unknown, unknown>;
28
+ abstract readonly params: Readonly<Record<string, string | undefined>>;
29
+ abstract readonly searchParams: Readonly<Record<string, string>>;
30
+ }
31
+ /**
32
+ * @tsplus static fncts.http.RouteContextOps Tag
33
+ * @tsplus location "@fncts/http/Route/definition"
34
+ */
35
+ export declare const RouteContextTag: import("@fncts/base/data/Tag.js").Tag<RouteContext, RouteContext>;
@@ -0,0 +1,17 @@
1
+ import { Maybe, Nothing } from "@fncts/base/data/Maybe/definition";
2
+ import type { Method } from "../Method.js";
3
+ import type { PathInput } from "./definition";
4
+ import { Route, RouteContext } from "./definition.js";
5
+ export declare class RouteImpl<R, E> extends Route<R, E> {
6
+ readonly method: Method | "*";
7
+ readonly path: PathInput;
8
+ readonly handler: Route.Handler<R, E>;
9
+ readonly prefix: Maybe<string>;
10
+ constructor(method: Method | "*", path: PathInput, handler: Route.Handler<R, E>, prefix?: Maybe<string>);
11
+ }
12
+ export declare class RouteContextImpl extends RouteContext {
13
+ readonly route: Route<unknown, unknown>;
14
+ readonly params: Readonly<Record<string, string | undefined>>;
15
+ readonly searchParams: Readonly<Record<string, string>>;
16
+ constructor(route: Route<unknown, unknown>, params: Readonly<Record<string, string | undefined>>, searchParams: Readonly<Record<string, string>>);
17
+ }
package/Route.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./Route/definition.js";
2
+ export * from "./Route/api.js";
@@ -0,0 +1,8 @@
1
+ import type { ServerRequest } from "./ServerRequest.js";
2
+ export declare const RouteNotFoundTypeId: unique symbol;
3
+ export type RouteNotFoundTypeId = typeof RouteNotFoundTypeId;
4
+ export declare class RouteNotFound extends Error {
5
+ readonly request: ServerRequest;
6
+ constructor(request: ServerRequest);
7
+ get message(): string;
8
+ }
@@ -0,0 +1,96 @@
1
+ import { Conc } from "@fncts/base/collection/immutable/Conc";
2
+ import { Cause } from "@fncts/base/data/Cause/definition";
3
+ import { Tag } from "@fncts/base/data/Tag/definition";
4
+ import type { HttpApp } from "../HttpApp.js";
5
+ import type { Method } from "../Method.js";
6
+ import type { PathInput, Route } from "../Route.js";
7
+ import type { Router } from "./definition.js";
8
+ /**
9
+ * @tsplus static fncts.http.RouterOps empty
10
+ * @tsplus location "@fncts/http/Router/api"
11
+ */
12
+ export declare const empty: Router<never, never>;
13
+ export declare function route(method: Method | "*"): <R1, E1>(path: PathInput, handler: Route.Handler<R1, E1>) => <R, E>(self: Router<R, E>) => Router<R | Router.ExcludeProvided<R1>, E | E1>;
14
+ /**
15
+ * @tsplus pipeable fncts.http.Router get
16
+ * @tsplus static fncts.http.RouterOps get
17
+ * @tsplus location "@fncts/http/Router/api"
18
+ */
19
+ export declare const get: <R1, E1>(path: PathInput, handler: Route.Handler<R1, E1>) => <R, E>(self: Router<R, E>) => Router<R | Router.ExcludeProvided<R1>, E | E1>;
20
+ /**
21
+ * @tsplus pipeable fncts.http.Router post
22
+ * @tsplus static fncts.http.RouterOps post
23
+ * @tsplus location "@fncts/http/Router/api"
24
+ */
25
+ export declare const post: <R1, E1>(path: PathInput, handler: Route.Handler<R1, E1>) => <R, E>(self: Router<R, E>) => Router<R | Router.ExcludeProvided<R1>, E | E1>;
26
+ /**
27
+ * @tsplus pipeable fncts.http.Router put
28
+ * @tsplus static fncts.http.RouterOps put
29
+ * @tsplus location "@fncts/http/Router/api"
30
+ */
31
+ export declare const put: <R1, E1>(path: PathInput, handler: Route.Handler<R1, E1>) => <R, E>(self: Router<R, E>) => Router<R | Router.ExcludeProvided<R1>, E | E1>;
32
+ /**
33
+ * @tsplus pipeable fncts.http.Router patch
34
+ * @tsplus static fncts.http.RouterOps patch
35
+ * @tsplus location "@fncts/http/Router/api"
36
+ */
37
+ export declare const patch: <R1, E1>(path: PathInput, handler: Route.Handler<R1, E1>) => <R, E>(self: Router<R, E>) => Router<R | Router.ExcludeProvided<R1>, E | E1>;
38
+ /**
39
+ * @tsplus pipeable fncts.http.Router del
40
+ * @tsplus static fncts.http.RouterOps del
41
+ * @tsplus location "@fncts/http/Router/api"
42
+ */
43
+ export declare const del: <R1, E1>(path: PathInput, handler: Route.Handler<R1, E1>) => <R, E>(self: Router<R, E>) => Router<R | Router.ExcludeProvided<R1>, E | E1>;
44
+ /**
45
+ * @tsplus pipeable fncts.http.Router head
46
+ * @tsplus static fncts.http.RouterOps head
47
+ * @tsplus location "@fncts/http/Router/api"
48
+ */
49
+ export declare const head: <R1, E1>(path: PathInput, handler: Route.Handler<R1, E1>) => <R, E>(self: Router<R, E>) => Router<R | Router.ExcludeProvided<R1>, E | E1>;
50
+ /**
51
+ * @tsplus pipeable fncts.http.Router options
52
+ * @tsplus static fncts.http.RouterOps options
53
+ * @tsplus location "@fncts/http/Router/api"
54
+ */
55
+ export declare const options: <R1, E1>(path: PathInput, handler: Route.Handler<R1, E1>) => <R, E>(self: Router<R, E>) => Router<R | Router.ExcludeProvided<R1>, E | E1>;
56
+ /**
57
+ * @tsplus pipeable fncts.http.Router use
58
+ * @tsplus static fncts.http.RouterOps use
59
+ * @tsplus location "@fncts/http/Router/api"
60
+ */
61
+ export declare function use<R, E, R1, E1>(f: (self: Route.Handler<R, E>) => HttpApp.Default<R1, E1>, __tsplusTrace?: string): (self: Router<R, E>) => Router<Router.ExcludeProvided<R1>, E1>;
62
+ /**
63
+ * @tsplus static fncts.http.RouterOps from
64
+ * @tsplus location "@fncts/http/Router/api"
65
+ */
66
+ export declare function from<R extends Route<any, any>>(routes: Iterable<R>): Router<R extends Route<infer Env, infer _> ? Env : never, R extends Route<infer _, infer E> ? E : never>;
67
+ /**
68
+ * @tsplus pipeable fncts.http.Router concat
69
+ * @tsplus location "@fncts/http/Router/api"
70
+ */
71
+ export declare function concat<R1, E1>(that: Router<R1, E1>): <R, E>(self: Router<R, E>) => Router<R | R1, E | E1>;
72
+ /**
73
+ * @tsplus pipeable fncts.http.Router prefixAll
74
+ * @tsplus location "@fncts/http/Router/api"
75
+ */
76
+ export declare function prefixAll(prefix: PathInput): <R, E>(self: Router<R, E>) => Router<R, E>;
77
+ /**
78
+ * @tsplus pipeable fncts.http.Router mount
79
+ * @tsplus location "@fncts/http/Router/api"
80
+ */
81
+ export declare function mount<R1, E1>(path: `/${string}`, that: Router<R1, E1>): <R, E>(self: Router<R, E>) => Router<R | R1, E | E1>;
82
+ /**
83
+ * @tsplus pipeable fncts.http.Router catchAll
84
+ * @tsplus location "@fncts/http/Router/api"
85
+ */
86
+ export declare function catchAll<E, R1, E1>(f: (e: E) => Route.Handler<R1, E1>, __tsplusTrace?: string): <R>(self: Router<R, E>) => Router<R | Router.ExcludeProvided<R1>, E1>;
87
+ /**
88
+ * @tsplus pipeable fncts.http.Router catchAllCause
89
+ * @tsplus location "@fncts/http/Router/api"
90
+ */
91
+ export declare function catchAllCause<E, R1, E1>(f: (e: Cause<E>) => Route.Handler<R1, E1>, __tsplusTrace?: string): <R>(self: Router<R, E>) => Router<R | Router.ExcludeProvided<R1>, E1>;
92
+ /**
93
+ * @tsplus pipeable fncts.http.Router provideService
94
+ * @tsplus location "@fncts/http/Router/api"
95
+ */
96
+ export declare function provideService<T>(service: T, tag: Tag<T>, __tsplusTrace?: string): <R, E>(self: Router<R, E>) => Router<Exclude<R, T>, E>;
@@ -0,0 +1,28 @@
1
+ import { Conc } from "@fncts/base/collection/immutable/Conc";
2
+ import { Scope } from "@fncts/io/Scope/definition";
3
+ import type { HttpApp } from "../HttpApp.js";
4
+ import type { Route, RouteContext } from "../Route.js";
5
+ import type { RouteNotFound } from "../RouteNotFound.js";
6
+ import type { ServerRequest } from "../ServerRequest.js";
7
+ import type { ServerResponse } from "@fncts/http/ServerResponse";
8
+ import { External } from "@fncts/io/IO";
9
+ export declare const RouterTypeId: unique symbol;
10
+ export type RouterTypeId = typeof RouterTypeId;
11
+ /**
12
+ * @tsplus type fncts.http.Router
13
+ * @tsplus companion fncts.http.RouterOps
14
+ */
15
+ export declare abstract class Router<R, E> extends External<Exclude<R, RouteContext>, E | RouteNotFound, ServerResponse> implements HttpApp.Default<Exclude<R, RouteContext>, E | RouteNotFound> {
16
+ readonly [RouterTypeId]: RouterTypeId;
17
+ abstract readonly routes: Conc<Route<R, E>>;
18
+ abstract readonly mounts: Conc<Readonly<{
19
+ prefix: string;
20
+ httpApp: HttpApp.Default<R, E>;
21
+ options?: {
22
+ readonly inclduePrefix?: boolean;
23
+ };
24
+ }>>;
25
+ }
26
+ export declare namespace Router {
27
+ type ExcludeProvided<A> = Exclude<A, RouteContext | ServerRequest | Scope>;
28
+ }
@@ -0,0 +1,26 @@
1
+ import { Conc } from "@fncts/base/collection/immutable/Conc";
2
+ import type { HttpApp } from "../HttpApp.js";
3
+ import type { ServerResponse } from "../ServerResponse.js";
4
+ import { IO } from "@fncts/io/IO";
5
+ import { type Route, RouteContext } from "../Route.js";
6
+ import { RouteNotFound } from "../RouteNotFound.js";
7
+ import { Router } from "./definition.js";
8
+ export declare class RouterInternal<R, E> extends Router<R, E> {
9
+ readonly routes: Conc<Route<R, E>>;
10
+ readonly mounts: Conc<Readonly<{
11
+ prefix: string;
12
+ httpApp: HttpApp.Default<R, E>;
13
+ options?: {
14
+ readonly inclduePrefix?: boolean;
15
+ };
16
+ }>>;
17
+ readonly httpApp: IO<Exclude<R, RouteContext>, E | RouteNotFound, ServerResponse>;
18
+ constructor(routes: Conc<Route<R, E>>, mounts: Conc<Readonly<{
19
+ prefix: string;
20
+ httpApp: HttpApp.Default<R, E>;
21
+ options?: {
22
+ readonly inclduePrefix?: boolean;
23
+ };
24
+ }>>);
25
+ get toIO(): IO<Exclude<R, RouteContext>, RouteNotFound | E, ServerResponse>;
26
+ }
package/Router.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./Router/definition.js";
2
+ export * from "./Router/api.js";