@effect/platform 0.18.4 → 0.18.6

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 (109) hide show
  1. package/Command/dist/effect-platform-Command.esm.js +12 -200
  2. package/CommandExecutor/dist/effect-platform-CommandExecutor.esm.js +9 -71
  3. package/Effectify/dist/effect-platform-Effectify.esm.js +2 -23
  4. package/Error/dist/effect-platform-Error.esm.js +2 -54
  5. package/FileSystem/dist/effect-platform-FileSystem.esm.js +10 -177
  6. package/Http/Body/dist/effect-platform-Http-Body.esm.js +13 -151
  7. package/Http/Client/dist/effect-platform-Http-Client.cjs.dev.js +2 -2
  8. package/Http/Client/dist/effect-platform-Http-Client.cjs.prod.js +2 -2
  9. package/Http/Client/dist/effect-platform-Http-Client.esm.js +28 -164
  10. package/Http/ClientError/dist/effect-platform-Http-ClientError.esm.js +3 -48
  11. package/Http/ClientRequest/dist/effect-platform-Http-ClientRequest.esm.js +20 -241
  12. package/Http/ClientResponse/dist/effect-platform-Http-ClientResponse.cjs.dev.js +3 -2
  13. package/Http/ClientResponse/dist/effect-platform-Http-ClientResponse.cjs.mjs +2 -1
  14. package/Http/ClientResponse/dist/effect-platform-Http-ClientResponse.cjs.prod.js +3 -2
  15. package/Http/ClientResponse/dist/effect-platform-Http-ClientResponse.esm.js +22 -35
  16. package/Http/Etag/dist/effect-platform-Http-Etag.esm.js +17 -1
  17. package/Http/FormData/dist/effect-platform-Http-FormData.esm.js +17 -155
  18. package/Http/Headers/dist/effect-platform-Http-Headers.esm.js +4 -74
  19. package/Http/IncomingMessage/dist/effect-platform-Http-IncomingMessage.esm.js +6 -1
  20. package/Http/Middleware/dist/effect-platform-Http-Middleware.cjs.dev.js +3 -3
  21. package/Http/Middleware/dist/effect-platform-Http-Middleware.cjs.prod.js +3 -3
  22. package/Http/Middleware/dist/effect-platform-Http-Middleware.esm.js +30 -52
  23. package/Http/Platform/dist/effect-platform-Http-Platform.esm.js +56 -1
  24. package/Http/Router/dist/effect-platform-Http-Router.esm.js +25 -224
  25. package/Http/Server/dist/effect-platform-Http-Server.esm.js +18 -1
  26. package/Http/ServerError/dist/effect-platform-Http-ServerError.esm.js +2 -70
  27. package/Http/ServerRequest/dist/effect-platform-Http-ServerRequest.esm.js +20 -65
  28. package/Http/ServerResponse/dist/effect-platform-Http-ServerResponse.cjs.dev.js +2 -2
  29. package/Http/ServerResponse/dist/effect-platform-Http-ServerResponse.cjs.prod.js +2 -2
  30. package/Http/ServerResponse/dist/effect-platform-Http-ServerResponse.esm.js +21 -126
  31. package/Http/UrlParams/dist/effect-platform-Http-UrlParams.esm.js +4 -101
  32. package/HttpClient/dist/effect-platform-HttpClient.cjs.dev.js +3 -3
  33. package/HttpClient/dist/effect-platform-HttpClient.cjs.prod.js +3 -3
  34. package/HttpClient/dist/effect-platform-HttpClient.esm.js +32 -18
  35. package/HttpServer/dist/effect-platform-HttpServer.cjs.dev.js +2 -3
  36. package/HttpServer/dist/effect-platform-HttpServer.cjs.prod.js +2 -3
  37. package/HttpServer/dist/effect-platform-HttpServer.esm.js +35 -24
  38. package/KeyValueStore/dist/effect-platform-KeyValueStore.esm.js +15 -78
  39. package/Path/dist/effect-platform-Path.esm.js +8 -33
  40. package/Runtime/dist/effect-platform-Runtime.esm.js +3 -26
  41. package/dist/App-687366d8.esm.js +5 -0
  42. package/dist/Body-ec1353f9.esm.js +170 -0
  43. package/dist/{Client-15671ed6.cjs.dev.js → Client-440a1019.cjs.dev.js} +1 -1
  44. package/dist/Client-4659bda7.esm.js +346 -0
  45. package/dist/{Client-6b3e3de8.cjs.prod.js → Client-7b851481.cjs.prod.js} +1 -1
  46. package/dist/ClientError-98b5da8c.esm.js +55 -0
  47. package/dist/ClientRequest-fc429335.esm.js +281 -0
  48. package/dist/{ClientResponse-a1d64ab8.cjs.dev.js → ClientResponse-1476704c.cjs.dev.js} +9 -1
  49. package/dist/ClientResponse-4524e99e.esm.js +53 -0
  50. package/dist/{ClientResponse-8f65511e.cjs.prod.js → ClientResponse-fe4e69c8.cjs.prod.js} +9 -1
  51. package/dist/Command-d8ab0c8d.esm.js +403 -0
  52. package/dist/CommandExecutor-5807b66b.esm.js +80 -0
  53. package/dist/Effectify-e5a9d266.esm.js +43 -0
  54. package/dist/Error-3099667c.esm.js +75 -0
  55. package/dist/FileSystem-7e31dccd.esm.js +271 -0
  56. package/dist/FormData-f54de878.esm.js +270 -0
  57. package/dist/Headers-58b56a08.esm.js +85 -0
  58. package/dist/{HttpClient-cefc7da9.cjs.dev.js → HttpClient-4d23b1f5.cjs.dev.js} +2 -2
  59. package/dist/{HttpClient-d3c69877.cjs.prod.js → HttpClient-88775b8e.cjs.prod.js} +2 -2
  60. package/dist/HttpClient-9ca6050c.esm.js +24 -0
  61. package/dist/{HttpServer-5b9d992e.cjs.dev.js → HttpServer-16159c3a.cjs.dev.js} +2 -2
  62. package/dist/HttpServer-50f8df76.esm.js +30 -0
  63. package/dist/{HttpServer-60325fb0.cjs.prod.js → HttpServer-93c0fbb3.cjs.prod.js} +2 -2
  64. package/{internal/keyValueStore.esm.js → dist/KeyValueStore-2f9a70bf.esm.js} +102 -15
  65. package/dist/Middleware-240f91f6.esm.js +105 -0
  66. package/dist/{Middleware-8e7cd600.cjs.dev.js → Middleware-e2edf820.cjs.dev.js} +1 -1
  67. package/dist/{Middleware-d4f1a1cd.cjs.prod.js → Middleware-f9a073d7.cjs.prod.js} +1 -1
  68. package/{internal/path.esm.js → dist/Path-46f84ba7.esm.js} +40 -4
  69. package/dist/Router-bf32317a.esm.js +454 -0
  70. package/dist/Runtime-7265fb98.esm.js +31 -0
  71. package/dist/ServerError-04ad5b57.esm.js +99 -0
  72. package/dist/ServerRequest-03161edc.esm.js +125 -0
  73. package/dist/ServerResponse-93038062.esm.js +259 -0
  74. package/dist/{ServerResponse-7d60c7d1.cjs.dev.js → ServerResponse-b63b7192.cjs.dev.js} +15 -4
  75. package/dist/{ServerResponse-830f1052.cjs.prod.js → ServerResponse-eae85b08.cjs.prod.js} +15 -4
  76. package/dist/UrlParams-1286c728.esm.js +114 -0
  77. package/{internal/http/body.esm.js → dist/body-20d78ec1.esm.js} +2 -2
  78. package/{internal/http/clientError.esm.js → dist/clientError-c4e1466c.esm.js} +1 -1
  79. package/{internal/http/clientRequest.esm.js → dist/clientRequest-1e9e0b0d.esm.js} +4 -4
  80. package/dist/{clientResponse-c58a116c.cjs.dev.js → clientResponse-79c84a64.cjs.dev.js} +10 -0
  81. package/{internal/http/clientResponse.esm.js → dist/clientResponse-8c2ec6a3.esm.js} +14 -5
  82. package/dist/{clientResponse-2c6a83f1.cjs.prod.js → clientResponse-f9c57e83.cjs.prod.js} +10 -0
  83. package/{internal/commandExecutor.esm.js → dist/commandExecutor-d6457489.esm.js} +1 -1
  84. package/dist/declarations/src/Http/ClientResponse.d.ts +8 -0
  85. package/dist/declarations/src/Http/ClientResponse.d.ts.map +1 -1
  86. package/dist/declarations/src/Http/ServerResponse.d.ts +1 -2
  87. package/dist/declarations/src/Http/ServerResponse.d.ts.map +1 -1
  88. package/dist/effect-platform.cjs.dev.js +8 -8
  89. package/dist/effect-platform.cjs.prod.js +8 -8
  90. package/dist/effect-platform.esm.js +58 -20
  91. package/package.json +1 -2
  92. package/src/Http/ClientResponse.ts +10 -0
  93. package/src/Http/ServerResponse.ts +1 -2
  94. package/src/internal/http/clientResponse.ts +16 -0
  95. package/src/internal/http/serverResponse.ts +18 -4
  96. package/internal/command.esm.js +0 -185
  97. package/internal/effectify.esm.js +0 -18
  98. package/internal/error.esm.js +0 -17
  99. package/internal/fileSystem.esm.js +0 -82
  100. package/internal/http/client.esm.js +0 -157
  101. package/internal/http/etag.esm.js +0 -19
  102. package/internal/http/formData.esm.js +0 -95
  103. package/internal/http/middleware.esm.js +0 -46
  104. package/internal/http/platform.esm.js +0 -52
  105. package/internal/http/router.esm.js +0 -199
  106. package/internal/http/server.esm.js +0 -20
  107. package/internal/http/serverError.esm.js +0 -23
  108. package/internal/http/serverRequest.esm.js +0 -50
  109. package/internal/http/serverResponse.esm.js +0 -105
@@ -1,157 +0,0 @@
1
- import * as Schema from '@effect/schema/Schema';
2
- import * as Context from 'effect/Context';
3
- import * as Effect from 'effect/Effect';
4
- import { dual, pipe } from 'effect/Function';
5
- import * as Layer from 'effect/Layer';
6
- import * as Option from 'effect/Option';
7
- import { pipeArguments } from 'effect/Pipeable';
8
- import * as Stream from 'effect/Stream';
9
- import { schemaExternalSpan } from '../../Http/Http/IncomingMessage/dist/effect-platform-Http-IncomingMessage.esm.js';
10
- import { hasBody } from '../../Http/Http/Method/dist/effect-platform-Http-Method.esm.js';
11
- import { makeUrl } from '../../Http/Http/UrlParams/dist/effect-platform-Http-UrlParams.esm.js';
12
- import { uint8Array } from './body.esm.js';
13
- import { requestError, responseError } from './clientError.esm.js';
14
- import { setHeader, setBody } from './clientRequest.esm.js';
15
- import { fromWeb } from './clientResponse.esm.js';
16
-
17
- /** @internal */
18
- const TypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/Client");
19
-
20
- /** @internal */
21
- const tag = /*#__PURE__*/Context.Tag(TypeId);
22
- const clientProto = {
23
- [TypeId]: TypeId,
24
- pipe() {
25
- return pipeArguments(this, arguments);
26
- }
27
- };
28
-
29
- /** @internal */
30
- const make = f => {
31
- Object.setPrototypeOf(f, clientProto);
32
- return f;
33
- };
34
-
35
- /** @internal */
36
- const fetch = (options = {}) => make(request => Effect.flatMap(makeUrl(request.url, request.urlParams, _ => requestError({
37
- request,
38
- reason: "InvalidUrl",
39
- error: _
40
- })), url => Effect.suspend(() => {
41
- const headers = new Headers(request.headers);
42
- const send = body => Effect.map(Effect.tryPromise({
43
- try: signal => globalThis.fetch(url, {
44
- ...options,
45
- method: request.method,
46
- headers,
47
- body,
48
- signal
49
- }),
50
- catch: _ => requestError({
51
- request,
52
- reason: "Transport",
53
- error: _
54
- })
55
- }), _ => fromWeb(request, _));
56
- if (hasBody(request.method)) {
57
- return send(convertBody(request.body));
58
- }
59
- return send(undefined);
60
- })));
61
- const convertBody = body => {
62
- switch (body._tag) {
63
- case "Empty":
64
- return undefined;
65
- case "Raw":
66
- return body.body;
67
- case "Uint8Array":
68
- return body.body;
69
- case "FormData":
70
- return body.formData;
71
- case "Stream":
72
- return Stream.toReadableStream(body.stream);
73
- }
74
- };
75
-
76
- /** @internal */
77
- const fetchOk = (options = {}) => filterStatusOk(fetch(options));
78
-
79
- /** @internal */
80
- const layer = /*#__PURE__*/Layer.succeed(tag, /*#__PURE__*/fetch());
81
-
82
- /** @internal */
83
- const transform = /*#__PURE__*/dual(2, (self, f) => make(f(self)));
84
-
85
- /** @internal */
86
- const transformResponse = /*#__PURE__*/dual(2, (self, f) => make(request => f(self(request))));
87
-
88
- /** @internal */
89
- const catchTag = /*#__PURE__*/dual(3, (self, tag, f) => make(request => Effect.catchTag(self(request), tag, f)));
90
-
91
- /** @internal */
92
- const catchTags = /*#__PURE__*/dual(2, (self, cases) => make(request => Effect.catchTags(self(request), cases)));
93
-
94
- /** @internal */
95
- const catchAll = /*#__PURE__*/dual(2, (self, f) => make(request => Effect.catchAll(self(request), f)));
96
-
97
- /** @internal */
98
- const filterOrElse = /*#__PURE__*/dual(3, (self, f, orElse) => make(request => Effect.filterOrElse(self(request), f, orElse)));
99
-
100
- /** @internal */
101
- const filterOrFail = /*#__PURE__*/dual(3, (self, f, orFailWith) => make(request => Effect.filterOrFail(self(request), f, orFailWith)));
102
-
103
- /** @internal */
104
- const filterStatus = /*#__PURE__*/dual(2, (self, f) => make(request => Effect.filterOrFail(self(request), response => f(response.status), response => responseError({
105
- request,
106
- response,
107
- reason: "StatusCode",
108
- error: "non 2xx status code"
109
- }))));
110
-
111
- /** @internal */
112
- const filterStatusOk = /*#__PURE__*/filterStatus(status => status >= 200 && status < 300);
113
-
114
- /** @internal */
115
- const map = /*#__PURE__*/dual(2, (self, f) => make(request => Effect.map(self(request), f)));
116
-
117
- /** @internal */
118
- const mapEffect = /*#__PURE__*/dual(2, (self, f) => make(request => Effect.flatMap(self(request), f)));
119
-
120
- /** @internal */
121
- const mapRequest = /*#__PURE__*/dual(2, (self, f) => make(request => self(f(request))));
122
-
123
- /** @internal */
124
- const mapRequestEffect = /*#__PURE__*/dual(2, (self, f) => make(request => Effect.flatMap(f(request), self)));
125
-
126
- /** @internal */
127
- const withB3Propagation = self => make(req => pipe(Effect.map(Effect.currentSpan, Option.match({
128
- onNone: () => req,
129
- onSome: span => {
130
- const parentId = span.parent._tag === "Some" ? `-${span.parent.value.spanId}` : "";
131
- return setHeader(req, "b3", `${span.traceId}-${span.spanId}-1${parentId}`);
132
- }
133
- })), Effect.flatMap(self), Effect.tap(res => Effect.ignore(Effect.flatMap(schemaExternalSpan(res), Effect.withParentSpanScoped)))));
134
-
135
- /** @internal */
136
- const retry = /*#__PURE__*/dual(2, (self, policy) => make(request => Effect.retry(self(request), policy)));
137
-
138
- /** @internal */
139
- const schemaFunction = /*#__PURE__*/dual(2, (self, schema) => {
140
- const encode = Schema.encode(schema);
141
- return request => a => Effect.flatMap(Effect.tryMap(encode(a), {
142
- try: body => new TextEncoder().encode(JSON.stringify(body)),
143
- catch: error => requestError({
144
- request,
145
- reason: "Encode",
146
- error
147
- })
148
- }), body => self(setBody(request, uint8Array(body, "application/json"))));
149
- });
150
-
151
- /** @internal */
152
- const tap = /*#__PURE__*/dual(2, (self, f) => make(request => Effect.tap(self(request), f)));
153
-
154
- /** @internal */
155
- const tapRequest = /*#__PURE__*/dual(2, (self, f) => make(request => Effect.zipRight(f(request), self(request))));
156
-
157
- export { TypeId, catchAll, catchTag, catchTags, fetch, fetchOk, filterOrElse, filterOrFail, filterStatus, filterStatusOk, layer, make, map, mapEffect, mapRequest, mapRequestEffect, retry, schemaFunction, tag, tap, tapRequest, transform, transformResponse, withB3Propagation };
@@ -1,19 +0,0 @@
1
- import * as Context from 'effect/Context';
2
-
3
- /** @internal */
4
- const GeneratorTypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/Etag/Generator");
5
-
6
- /** @internal */
7
- const tag = /*#__PURE__*/Context.Tag(GeneratorTypeId);
8
-
9
- /** @internal */
10
- const toString = self => {
11
- switch (self._tag) {
12
- case "Weak":
13
- return `W/"${self.value}"`;
14
- case "Strong":
15
- return `"${self.value}"`;
16
- }
17
- };
18
-
19
- export { GeneratorTypeId, tag, toString };
@@ -1,95 +0,0 @@
1
- import * as Schema from '@effect/schema/Schema';
2
- import * as Chunk from 'effect/Chunk';
3
- import * as Data from 'effect/Data';
4
- import * as Effect from 'effect/Effect';
5
- import * as FiberRef from 'effect/FiberRef';
6
- import { dual, pipe } from 'effect/Function';
7
- import { globalValue } from 'effect/GlobalValue';
8
- import * as Option from 'effect/Option';
9
- import * as Predicate from 'effect/Predicate';
10
- import * as ReadonlyArray from 'effect/ReadonlyArray';
11
- import { Size } from '../../FileSystem/dist/effect-platform-FileSystem.esm.js';
12
-
13
- /** @internal */
14
- const TypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/FormData");
15
-
16
- /** @internal */
17
- const ErrorTypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/FormData/FormDataError");
18
-
19
- /** @internal */
20
- const FormDataError = (reason, error) => Data.struct({
21
- [ErrorTypeId]: ErrorTypeId,
22
- _tag: "FormDataError",
23
- reason,
24
- error
25
- });
26
-
27
- /** @internal */
28
- const maxParts = /*#__PURE__*/globalValue("@effect/platform/Http/FormData/maxParts", () => FiberRef.unsafeMake(Option.none()));
29
-
30
- /** @internal */
31
- const withMaxParts = /*#__PURE__*/dual(2, (effect, count) => Effect.locally(effect, maxParts, count));
32
-
33
- /** @internal */
34
- const maxFieldSize = /*#__PURE__*/globalValue("@effect/platform/Http/FormData/maxFieldSize", () => FiberRef.unsafeMake(Size(10 * 1024 * 1024)));
35
-
36
- /** @internal */
37
- const withMaxFieldSize = /*#__PURE__*/dual(2, (effect, size) => Effect.locally(effect, maxFieldSize, Size(size)));
38
-
39
- /** @internal */
40
- const maxFields = /*#__PURE__*/globalValue("@effect/platform/Http/FormData/maxFields", () => FiberRef.unsafeMake(Option.none()));
41
-
42
- /** @internal */
43
- const withMaxFields = /*#__PURE__*/dual(2, (effect, count) => Effect.locally(effect, maxFields, count));
44
-
45
- /** @internal */
46
- const maxFiles = /*#__PURE__*/globalValue("@effect/platform/Http/FormData/maxFiles", () => FiberRef.unsafeMake(Option.none()));
47
-
48
- /** @internal */
49
- const withMaxFiles = /*#__PURE__*/dual(2, (effect, count) => Effect.locally(effect, maxFiles, count));
50
-
51
- /** @internal */
52
- const maxFileSize = /*#__PURE__*/globalValue("@effect/platform/Http/FormData/maxFileSize", () => FiberRef.unsafeMake(Option.none()));
53
-
54
- /** @internal */
55
- const withMaxFileSize = /*#__PURE__*/dual(2, (effect, size) => Effect.locally(effect, maxFileSize, Option.map(size, Size)));
56
-
57
- /** @internal */
58
- const fieldMimeTypes = /*#__PURE__*/globalValue("@effect/platform/Http/FormData/fieldMimeTypes", () => FiberRef.unsafeMake(Chunk.make("application/json")));
59
-
60
- /** @internal */
61
- const withFieldMimeTypes = /*#__PURE__*/dual(2, (effect, mimeTypes) => Effect.locally(effect, fieldMimeTypes, Chunk.fromIterable(mimeTypes)));
62
-
63
- /** @internal */
64
- const toRecord = formData => ReadonlyArray.reduce(formData.entries(), {}, (acc, [key, value]) => {
65
- if (Predicate.isString(value)) {
66
- acc[key] = value;
67
- } else {
68
- const existing = acc[key];
69
- if (Array.isArray(existing)) {
70
- existing.push(value);
71
- } else {
72
- acc[key] = [value];
73
- }
74
- }
75
- return acc;
76
- });
77
- /** @internal */
78
- const filesSchema = /*#__PURE__*/Schema.array( /*#__PURE__*/pipe( /*#__PURE__*/Schema.instanceOf(Blob), /*#__PURE__*/Schema.filter(blob => "name" in blob)));
79
-
80
- /** @internal */
81
- const schemaRecord = schema => {
82
- const parse = Schema.parse(schema);
83
- return formData => parse(toRecord(formData));
84
- };
85
-
86
- /** @internal */
87
- const schemaJson = schema => {
88
- const parse = Schema.parse(schema);
89
- return dual(2, (formData, field) => pipe(Effect.succeed(formData.get(field)), Effect.filterOrFail(field => Predicate.isString(field), () => FormDataError("Parse", `schemaJson: field was not a string`)), Effect.tryMap({
90
- try: field => JSON.parse(field),
91
- catch: error => FormDataError("Parse", `schemaJson: field was not valid json: ${error}`)
92
- }), Effect.flatMap(parse)));
93
- };
94
-
95
- export { ErrorTypeId, FormDataError, TypeId, fieldMimeTypes, filesSchema, maxFieldSize, maxFields, maxFileSize, maxFiles, maxParts, schemaJson, schemaRecord, toRecord, withFieldMimeTypes, withMaxFieldSize, withMaxFields, withMaxFileSize, withMaxFiles, withMaxParts };
@@ -1,46 +0,0 @@
1
- import * as Effect from 'effect/Effect';
2
- import { flow } from 'effect/Function';
3
- import { set } from '../../Http/Http/Headers/dist/effect-platform-Http-Headers.esm.js';
4
- import { schemaExternalSpan } from '../../Http/Http/IncomingMessage/dist/effect-platform-Http-IncomingMessage.esm.js';
5
- import { ServerRequest } from '../../Http/Http/ServerRequest/dist/effect-platform-Http-ServerRequest.esm.js';
6
- import { setHeader } from '../../Http/Http/ServerResponse/dist/effect-platform-Http-ServerResponse.esm.js';
7
-
8
- /** @internal */
9
- const make = middleware => middleware;
10
-
11
- /** @internal */
12
- const logger = /*#__PURE__*/make(httpApp => {
13
- let counter = 0;
14
- return Effect.flatMap(ServerRequest, request => Effect.withLogSpan(Effect.onExit(httpApp, exit => exit._tag === "Failure" ? Effect.annotateLogs(Effect.log(exit.cause), {
15
- "http.method": request.method,
16
- "http.url": request.url,
17
- "http.status": 500
18
- }) : Effect.annotateLogs(Effect.log(""), {
19
- "http.method": request.method,
20
- "http.url": request.url,
21
- "http.status": exit.value.status
22
- })), `http.span.${++counter}`));
23
- });
24
-
25
- /** @internal */
26
- const tracer = /*#__PURE__*/make(httpApp => Effect.flatMap(ServerRequest, request => Effect.flatMap(Effect.orElseSucceed(schemaExternalSpan(request), () => undefined), parent => Effect.withSpan(Effect.tap(httpApp, response => Effect.annotateCurrentSpan("http.status", response.status)), `http ${request.method}`, {
27
- attributes: {
28
- "http.method": request.method,
29
- "http.url": request.url
30
- },
31
- parent
32
- }))));
33
-
34
- /** @internal */
35
- const b3Response = /*#__PURE__*/make(httpApp => Effect.flatMap(Effect.currentSpan, span => span._tag === "Some" ? Effect.map(httpApp, res => setHeader(res, "b3", `${span.value.traceId}-${span.value.spanId}-1${span.value.parent._tag === "Some" ? `-${span.value.parent.value.spanId}` : ""}`)) : httpApp));
36
-
37
- /** @internal */
38
- const xForwardedHeaders = /*#__PURE__*/make(httpApp => Effect.updateService(httpApp, ServerRequest, request => request.headers["x-forwarded-host"] ? request.modify({
39
- headers: set(request.headers, "host", request.headers["x-forwarded-host"]),
40
- remoteAddress: request.headers["x-forwarded-for"]?.split(",")[0].trim()
41
- }) : request));
42
-
43
- /** @internal */
44
- const loggerTracer = /*#__PURE__*/flow(tracer, logger);
45
-
46
- export { b3Response, logger, loggerTracer, make, tracer, xForwardedHeaders };
@@ -1,52 +0,0 @@
1
- import * as Context from 'effect/Context';
2
- import * as Effect from 'effect/Effect';
3
- import { pipe } from 'effect/Function';
4
- import { FileSystem } from '../../FileSystem/dist/effect-platform-FileSystem.esm.js';
5
- import { Generator, toString } from '../../Http/Http/Etag/dist/effect-platform-Http-Etag.esm.js';
6
-
7
- /** @internal */
8
- const TypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/Platform");
9
-
10
- /** @internal */
11
- const tag = /*#__PURE__*/Context.Tag(TypeId);
12
-
13
- /** @internal */
14
- const make = impl => Effect.gen(function* (_) {
15
- const fs = yield* _(FileSystem);
16
- const etagGen = yield* _(Generator);
17
- return tag.of({
18
- [TypeId]: TypeId,
19
- fileResponse(path, options) {
20
- return pipe(Effect.bindTo(fs.stat(path), "info"), Effect.bind("etag", ({
21
- info
22
- }) => etagGen.fromFileInfo(info)), Effect.map(({
23
- etag,
24
- info
25
- }) => {
26
- const start = Number(options?.offset ?? 0);
27
- const end = options?.bytesToRead !== undefined ? start + Number(options.bytesToRead) : undefined;
28
- const headers = {
29
- ...(options?.headers ?? {}),
30
- etag: toString(etag)
31
- };
32
- if (info.mtime._tag === "Some") {
33
- headers["last-modified"] = info.mtime.value.toUTCString();
34
- }
35
- const contentLength = end !== undefined ? end - start : Number(info.size) - start;
36
- return impl.fileResponse(path, options?.status ?? 200, options?.statusText, headers, start, end, contentLength);
37
- }));
38
- },
39
- fileWebResponse(file, options) {
40
- return Effect.map(etagGen.fromFileWeb(file), etag => {
41
- const headers = {
42
- ...(options?.headers ?? {}),
43
- etag: toString(etag),
44
- "last-modified": new Date(file.lastModified).toUTCString()
45
- };
46
- return impl.fileWebResponse(file, options?.status ?? 200, options?.statusText, headers, options);
47
- });
48
- }
49
- });
50
- });
51
-
52
- export { TypeId, make, tag };
@@ -1,199 +0,0 @@
1
- import * as Schema from '@effect/schema/Schema';
2
- import * as Chunk from 'effect/Chunk';
3
- import * as Context from 'effect/Context';
4
- import * as Effect from 'effect/Effect';
5
- import * as Effectable from 'effect/Effectable';
6
- import { dual } from 'effect/Function';
7
- import * as Inspectable from 'effect/Inspectable';
8
- import * as Option from 'effect/Option';
9
- import FindMyWay from 'find-my-way';
10
- import { RouteNotFound } from '../../Http/Http/ServerError/dist/effect-platform-Http-ServerError.esm.js';
11
- import { ServerRequest } from '../../Http/Http/ServerRequest/dist/effect-platform-Http-ServerRequest.esm.js';
12
-
13
- /** @internal */
14
- const TypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/Router");
15
-
16
- /** @internal */
17
- const RouteTypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/Router/Route");
18
-
19
- /** @internal */
20
- const RouteContextTypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/Router/RouteContext");
21
-
22
- /** @internal */
23
- const RouteContext = /*#__PURE__*/Context.Tag("@effect/platform/Http/Router/RouteContext");
24
-
25
- /** @internal */
26
- const params = /*#__PURE__*/Effect.map(RouteContext, _ => _.params);
27
-
28
- /** @internal */
29
- const searchParams = /*#__PURE__*/Effect.map(RouteContext, _ => _.searchParams);
30
-
31
- /** @internal */
32
- const schemaParams = schema => {
33
- const parse = Schema.parse(schema);
34
- return Effect.flatMap(RouteContext, _ => parse({
35
- ..._.searchParams,
36
- ..._.params
37
- }));
38
- };
39
- class RouterImpl extends Effectable.Effectable {
40
- constructor(routes, mounts) {
41
- super();
42
- this.routes = routes;
43
- this.mounts = mounts;
44
- this[TypeId] = TypeId;
45
- }
46
- commit() {
47
- if (this.httpApp === undefined) {
48
- this.httpApp = toHttpApp(this);
49
- }
50
- return this.httpApp;
51
- }
52
- toJSON() {
53
- return {
54
- _id: "Router",
55
- routes: this.routes.toJSON(),
56
- mounts: this.mounts.toJSON()
57
- };
58
- }
59
- toString() {
60
- return Inspectable.toString(this);
61
- }
62
- [Inspectable.NodeInspectSymbol]() {
63
- return this.toJSON();
64
- }
65
- }
66
- const toHttpApp = self => {
67
- const router = FindMyWay();
68
- const mounts = Chunk.toReadonlyArray(self.mounts);
69
- const mountsLen = mounts.length;
70
- Chunk.forEach(self.routes, route => {
71
- function fn() {
72
- return route;
73
- }
74
- if (route.method === "*") {
75
- router.all(route.path, fn);
76
- } else {
77
- router.on(route.method, route.path, fn);
78
- }
79
- });
80
- return Effect.flatMap(ServerRequest, request => {
81
- if (mountsLen > 0) {
82
- for (let i = 0; i < mountsLen; i++) {
83
- const [path, app] = mounts[i];
84
- if (request.url.startsWith(path)) {
85
- return Effect.provideService(app, ServerRequest, sliceRequestUrl(request, path));
86
- }
87
- }
88
- }
89
- let result = router.find(request.method, request.url);
90
- if (result === null && request.method === "HEAD") {
91
- result = router.find("GET", request.url);
92
- }
93
- if (result === null) {
94
- return Effect.fail(RouteNotFound({
95
- request
96
- }));
97
- }
98
- const route = result.handler();
99
- if (route.prefix._tag === "Some") {
100
- request = sliceRequestUrl(request, route.prefix.value);
101
- }
102
- return Effect.mapInputContext(route.handler, context => Context.add(Context.add(context, ServerRequest, request), RouteContext, new RouteContextImpl(result.params, result.searchParams)));
103
- });
104
- };
105
- function sliceRequestUrl(request, prefix) {
106
- const prefexLen = prefix.length;
107
- return request.modify({
108
- url: request.url.length <= prefexLen ? "/" : request.url.slice(prefexLen)
109
- });
110
- }
111
- class RouteImpl {
112
- constructor(method, path, handler, prefix = Option.none()) {
113
- this.method = method;
114
- this.path = path;
115
- this.handler = handler;
116
- this.prefix = prefix;
117
- this[RouteTypeId] = RouteTypeId;
118
- }
119
- }
120
- class RouteContextImpl {
121
- constructor(params, searchParams) {
122
- this.params = params;
123
- this.searchParams = searchParams;
124
- this[RouteContextTypeId] = RouteContextTypeId;
125
- }
126
- }
127
-
128
- /** @internal */
129
- const empty = /*#__PURE__*/new RouterImpl( /*#__PURE__*/Chunk.empty(), /*#__PURE__*/Chunk.empty());
130
-
131
- /** @internal */
132
- const fromIterable = routes => new RouterImpl(Chunk.fromIterable(routes), Chunk.empty());
133
-
134
- /** @internal */
135
- const makeRoute = (method, path, handler, prefix = Option.none()) => new RouteImpl(method, path, handler, prefix);
136
-
137
- /** @internal */
138
- const concat = /*#__PURE__*/dual(2, (self, that) => new RouterImpl(Chunk.appendAll(self.routes, that.routes), self.mounts));
139
- const removeTrailingSlash = path => path.endsWith("/") ? path.slice(0, -1) : path;
140
-
141
- /** @internal */
142
- const prefixAll = /*#__PURE__*/dual(2, (self, prefix) => {
143
- prefix = removeTrailingSlash(prefix);
144
- return new RouterImpl(Chunk.map(self.routes, route => new RouteImpl(route.method, route.path === "/" ? prefix : prefix + route.path, route.handler, Option.orElse(Option.map(route.prefix, _ => prefix + _), () => Option.some(prefix)))), Chunk.map(self.mounts, ([path, app]) => [path === "/" ? prefix : prefix + path, app]));
145
- });
146
-
147
- /** @internal */
148
- const mount = /*#__PURE__*/dual(3, (self, path, that) => concat(self, prefixAll(that, path)));
149
-
150
- /** @internal */
151
- const mountApp = /*#__PURE__*/dual(3, (self, path, that) => new RouterImpl(self.routes, Chunk.append(self.mounts, [removeTrailingSlash(path), that])));
152
-
153
- /** @internal */
154
- const route = method => dual(3, (self, path, handler) => new RouterImpl(Chunk.append(self.routes, new RouteImpl(method, path, handler)), self.mounts));
155
-
156
- /** @internal */
157
- const all = /*#__PURE__*/route("*");
158
-
159
- /** @internal */
160
- const get = /*#__PURE__*/route("GET");
161
-
162
- /** @internal */
163
- const post = /*#__PURE__*/route("POST");
164
-
165
- /** @internal */
166
- const put = /*#__PURE__*/route("PUT");
167
-
168
- /** @internal */
169
- const patch = /*#__PURE__*/route("PATCH");
170
-
171
- /** @internal */
172
- const del = /*#__PURE__*/route("DELETE");
173
-
174
- /** @internal */
175
- const head = /*#__PURE__*/route("HEAD");
176
-
177
- /** @internal */
178
- const options = /*#__PURE__*/route("OPTIONS");
179
-
180
- /** @internal */
181
- const use = /*#__PURE__*/dual(2, (self, f) => new RouterImpl(Chunk.map(self.routes, route => new RouteImpl(route.method, route.path, f(route.handler), route.prefix)), Chunk.map(self.mounts, ([path, app]) => [path, f(app)])));
182
-
183
- /** @internal */
184
- const catchAll = /*#__PURE__*/dual(2, (self, f) => use(self, Effect.catchAll(f)));
185
-
186
- /** @internal */
187
- const catchAllCause = /*#__PURE__*/dual(2, (self, f) => use(self, Effect.catchAllCause(f)));
188
-
189
- /** @internal */
190
- const catchTag = /*#__PURE__*/dual(3, (self, k, f) => use(self, Effect.catchTag(k, f)));
191
-
192
- /** @internal */
193
- const catchTags = /*#__PURE__*/dual(2, (self, cases) => use(self, Effect.catchTags(cases)));
194
- const provideService = /*#__PURE__*/dual(3, (self, tag, service) => use(self, Effect.provideService(tag, service)));
195
-
196
- /* @internal */
197
- const provideServiceEffect = /*#__PURE__*/dual(3, (self, tag, effect) => use(self, Effect.provideServiceEffect(tag, effect)));
198
-
199
- export { RouteContext, RouteContextTypeId, RouteTypeId, TypeId, all, catchAll, catchAllCause, catchTag, catchTags, concat, del, empty, fromIterable, get, head, makeRoute, mount, mountApp, options, params, patch, post, prefixAll, provideService, provideServiceEffect, put, route, schemaParams, searchParams, use };
@@ -1,20 +0,0 @@
1
- import * as Context from 'effect/Context';
2
- import * as Effect from 'effect/Effect';
3
- import { dual } from 'effect/Function';
4
-
5
- /** @internal */
6
- const TypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/Server");
7
-
8
- /** @internal */
9
- const serverTag = /*#__PURE__*/Context.Tag(TypeId);
10
- const serverProto = {
11
- [TypeId]: TypeId
12
- };
13
-
14
- /** @internal */
15
- const make = options => Object.assign(Object.create(serverProto), options);
16
-
17
- /** @internal */
18
- const serve = /*#__PURE__*/dual(args => Effect.isEffect(args[0]), (httpApp, middleware) => Effect.flatMap(serverTag, server => server.serve(httpApp, middleware)));
19
-
20
- export { TypeId, make, serve, serverTag };
@@ -1,23 +0,0 @@
1
- import * as Data from 'effect/Data';
2
-
3
- /** @internal */
4
- const TypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/Error");
5
- const make = tag => props => Data.struct({
6
- [TypeId]: TypeId,
7
- _tag: tag,
8
- ...props
9
- });
10
-
11
- /** @internal */
12
- const requestError = /*#__PURE__*/make("RequestError");
13
-
14
- /** @internal */
15
- const responseError = /*#__PURE__*/make("ResponseError");
16
-
17
- /** @internal */
18
- const routeNotFound = /*#__PURE__*/make("RouteNotFound");
19
-
20
- /** @internal */
21
- const serveError = /*#__PURE__*/make("ServeError");
22
-
23
- export { TypeId, requestError, responseError, routeNotFound, serveError };
@@ -1,50 +0,0 @@
1
- import * as Context from 'effect/Context';
2
- import * as Effect from 'effect/Effect';
3
- import { toRecord, schemaRecord, schemaJson } from '../../Http/Http/FormData/dist/effect-platform-Http-FormData.esm.js';
4
- import { schemaHeaders as schemaHeaders$1, schemaBodyJson as schemaBodyJson$1, schemaBodyUrlParams as schemaBodyUrlParams$1 } from '../../Http/Http/IncomingMessage/dist/effect-platform-Http-IncomingMessage.esm.js';
5
- import { RequestError } from '../../Http/Http/ServerError/dist/effect-platform-Http-ServerError.esm.js';
6
-
7
- /** @internal */
8
- const TypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/ServerRequest");
9
-
10
- /** @internal */
11
- const serverRequestTag = /*#__PURE__*/Context.Tag(TypeId);
12
-
13
- /** @internal */
14
- const formDataRecord = /*#__PURE__*/Effect.map( /*#__PURE__*/Effect.flatMap(serverRequestTag, request => request.formData), toRecord);
15
-
16
- /** @internal */
17
- const schemaHeaders = schema => {
18
- const parse = schemaHeaders$1(schema);
19
- return Effect.flatMap(serverRequestTag, parse);
20
- };
21
-
22
- /** @internal */
23
- const schemaBodyJson = schema => {
24
- const parse = schemaBodyJson$1(schema);
25
- return Effect.flatMap(serverRequestTag, parse);
26
- };
27
-
28
- /** @internal */
29
- const schemaBodyUrlParams = schema => {
30
- const parse = schemaBodyUrlParams$1(schema);
31
- return Effect.flatMap(serverRequestTag, parse);
32
- };
33
-
34
- /** @internal */
35
- const schemaFormData = schema => {
36
- const parse = schemaRecord(schema);
37
- return Effect.flatMap(Effect.flatMap(serverRequestTag, request => request.formData), parse);
38
- };
39
-
40
- /** @internal */
41
- const schemaFormDataJson = schema => {
42
- const parse = schemaJson(schema);
43
- return field => Effect.flatMap(serverRequestTag, request => Effect.flatMap(request.formData, formData => Effect.catchTag(parse(formData, field), "FormDataError", error => Effect.fail(RequestError({
44
- reason: "Decode",
45
- request,
46
- error: error.error
47
- })))));
48
- };
49
-
50
- export { TypeId, formDataRecord, schemaBodyJson, schemaBodyUrlParams, schemaFormData, schemaFormDataJson, schemaHeaders, serverRequestTag };