@effect/platform 0.87.1 → 0.87.3
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/HttpLayerRouter/package.json +6 -0
- package/README.md +271 -0
- package/dist/cjs/HttpApiBuilder.js +15 -1
- package/dist/cjs/HttpApiBuilder.js.map +1 -1
- package/dist/cjs/HttpApiScalar.js +29 -11
- package/dist/cjs/HttpApiScalar.js.map +1 -1
- package/dist/cjs/HttpApiSwagger.js +32 -15
- package/dist/cjs/HttpApiSwagger.js.map +1 -1
- package/dist/cjs/HttpApp.js +41 -4
- package/dist/cjs/HttpApp.js.map +1 -1
- package/dist/cjs/HttpBody.js.map +1 -1
- package/dist/cjs/HttpLayerRouter.js +494 -0
- package/dist/cjs/HttpLayerRouter.js.map +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/internal/httpRouter.js +3 -1
- package/dist/cjs/internal/httpRouter.js.map +1 -1
- package/dist/dts/HttpApiBuilder.d.ts +6 -0
- package/dist/dts/HttpApiBuilder.d.ts.map +1 -1
- package/dist/dts/HttpApiScalar.d.ts +14 -2
- package/dist/dts/HttpApiScalar.d.ts.map +1 -1
- package/dist/dts/HttpApiSwagger.d.ts +12 -2
- package/dist/dts/HttpApiSwagger.d.ts.map +1 -1
- package/dist/dts/HttpApp.d.ts +14 -1
- package/dist/dts/HttpApp.d.ts.map +1 -1
- package/dist/dts/HttpBody.d.ts +1 -1
- package/dist/dts/HttpBody.d.ts.map +1 -1
- package/dist/dts/HttpLayerRouter.d.ts +481 -0
- package/dist/dts/HttpLayerRouter.d.ts.map +1 -0
- package/dist/dts/index.d.ts +4 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/httpRouter.d.ts.map +1 -1
- package/dist/esm/HttpApiBuilder.js +14 -0
- package/dist/esm/HttpApiBuilder.js.map +1 -1
- package/dist/esm/HttpApiScalar.js +28 -10
- package/dist/esm/HttpApiScalar.js.map +1 -1
- package/dist/esm/HttpApiSwagger.js +31 -14
- package/dist/esm/HttpApiSwagger.js.map +1 -1
- package/dist/esm/HttpApp.js +37 -2
- package/dist/esm/HttpApp.js.map +1 -1
- package/dist/esm/HttpBody.js.map +1 -1
- package/dist/esm/HttpLayerRouter.js +468 -0
- package/dist/esm/HttpLayerRouter.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/httpRouter.js +3 -1
- package/dist/esm/internal/httpRouter.js.map +1 -1
- package/package.json +10 -2
- package/src/HttpApiBuilder.ts +30 -0
- package/src/HttpApiScalar.ts +79 -41
- package/src/HttpApiSwagger.ts +49 -18
- package/src/HttpApp.ts +55 -2
- package/src/HttpBody.ts +1 -2
- package/src/HttpLayerRouter.ts +920 -0
- package/src/index.ts +5 -0
- package/src/internal/httpRouter.ts +4 -1
package/dist/cjs/HttpApp.js
CHANGED
|
@@ -3,15 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.withPreResponseHandler = exports.toWebHandlerRuntime = exports.toWebHandlerLayer = exports.toWebHandler = exports.toHandled = exports.currentPreResponseHandlers = exports.appendPreResponseHandler = void 0;
|
|
6
|
+
exports.withPreResponseHandler = exports.unsafeEjectStreamScope = exports.toWebHandlerRuntime = exports.toWebHandlerLayer = exports.toWebHandler = exports.toHandled = exports.ejectDefaultScopeClose = exports.currentPreResponseHandlers = exports.appendPreResponseHandler = void 0;
|
|
7
7
|
var Context = _interopRequireWildcard(require("effect/Context"));
|
|
8
8
|
var Effect = _interopRequireWildcard(require("effect/Effect"));
|
|
9
9
|
var Exit = _interopRequireWildcard(require("effect/Exit"));
|
|
10
|
+
var Fiber = _interopRequireWildcard(require("effect/Fiber"));
|
|
10
11
|
var FiberRef = _interopRequireWildcard(require("effect/FiberRef"));
|
|
12
|
+
var GlobalValue = _interopRequireWildcard(require("effect/GlobalValue"));
|
|
11
13
|
var Layer = _interopRequireWildcard(require("effect/Layer"));
|
|
14
|
+
var Option = _interopRequireWildcard(require("effect/Option"));
|
|
12
15
|
var Runtime = _interopRequireWildcard(require("effect/Runtime"));
|
|
13
16
|
var Scope = _interopRequireWildcard(require("effect/Scope"));
|
|
17
|
+
var Stream = _interopRequireWildcard(require("effect/Stream"));
|
|
14
18
|
var _Unify = require("effect/Unify");
|
|
19
|
+
var HttpBody = _interopRequireWildcard(require("./HttpBody.js"));
|
|
15
20
|
var ServerError = _interopRequireWildcard(require("./HttpServerError.js"));
|
|
16
21
|
var ServerRequest = _interopRequireWildcard(require("./HttpServerRequest.js"));
|
|
17
22
|
var ServerResponse = _interopRequireWildcard(require("./HttpServerResponse.js"));
|
|
@@ -74,13 +79,45 @@ const toHandled = (self, handleResponse, middleware) => {
|
|
|
74
79
|
return handledSymbol in request ? Effect.void : handleResponse(request, response);
|
|
75
80
|
})
|
|
76
81
|
}));
|
|
77
|
-
return Effect.uninterruptible(
|
|
82
|
+
return Effect.uninterruptible(scoped(withMiddleware));
|
|
78
83
|
};
|
|
79
84
|
/**
|
|
85
|
+
* If you want to finalize the http request scope elsewhere, you can use this
|
|
86
|
+
* function to eject from the default scope closure.
|
|
87
|
+
*
|
|
80
88
|
* @since 1.0.0
|
|
81
|
-
* @category
|
|
89
|
+
* @category Scope
|
|
82
90
|
*/
|
|
83
91
|
exports.toHandled = toHandled;
|
|
92
|
+
const ejectDefaultScopeClose = scope => {
|
|
93
|
+
ejectedScopes.add(scope);
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* @since 1.0.0
|
|
97
|
+
* @category Scope
|
|
98
|
+
*/
|
|
99
|
+
exports.ejectDefaultScopeClose = ejectDefaultScopeClose;
|
|
100
|
+
const unsafeEjectStreamScope = response => {
|
|
101
|
+
if (response.body._tag !== "Stream") {
|
|
102
|
+
return response;
|
|
103
|
+
}
|
|
104
|
+
const fiber = Option.getOrThrow(Fiber.getCurrentFiber());
|
|
105
|
+
const scope = Context.unsafeGet(fiber.currentContext, Scope.Scope);
|
|
106
|
+
ejectDefaultScopeClose(scope);
|
|
107
|
+
return ServerResponse.setBody(response, HttpBody.stream(Stream.ensuring(response.body.stream, Scope.close(scope, Exit.void)), response.body.contentType, response.body.contentLength));
|
|
108
|
+
};
|
|
109
|
+
exports.unsafeEjectStreamScope = unsafeEjectStreamScope;
|
|
110
|
+
const ejectedScopes = /*#__PURE__*/GlobalValue.globalValue("@effect/platform/HttpApp/ejectedScopes", () => new WeakSet());
|
|
111
|
+
const scoped = effect => Effect.flatMap(Scope.make(), scope => Effect.onExit(Scope.extend(effect, scope), exit => {
|
|
112
|
+
if (ejectedScopes.has(scope)) {
|
|
113
|
+
return Effect.void;
|
|
114
|
+
}
|
|
115
|
+
return Scope.close(scope, exit);
|
|
116
|
+
}));
|
|
117
|
+
/**
|
|
118
|
+
* @since 1.0.0
|
|
119
|
+
* @category fiber refs
|
|
120
|
+
*/
|
|
84
121
|
const currentPreResponseHandlers = exports.currentPreResponseHandlers = internal.currentPreResponseHandlers;
|
|
85
122
|
/**
|
|
86
123
|
* @since 1.0.0
|
|
@@ -101,7 +138,7 @@ const toWebHandlerRuntime = runtime => {
|
|
|
101
138
|
return (self, middleware) => {
|
|
102
139
|
const resolveSymbol = Symbol.for("@effect/platform/HttpApp/resolve");
|
|
103
140
|
const httpApp = toHandled(self, (request, response) => {
|
|
104
|
-
;
|
|
141
|
+
response = unsafeEjectStreamScope(response);
|
|
105
142
|
request[resolveSymbol](ServerResponse.toWeb(response, {
|
|
106
143
|
withoutBody: request.method === "HEAD",
|
|
107
144
|
runtime
|
package/dist/cjs/HttpApp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpApp.js","names":["Context","_interopRequireWildcard","require","Effect","Exit","FiberRef","Layer","Runtime","Scope","_Unify","ServerError","ServerRequest","ServerResponse","internal","internalMiddleware","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","handledSymbol","Symbol","for","toHandled","self","handleResponse","middleware","responded","withFiberRuntime","fiber","flatMap","response","request","unsafeGet","currentContext","HttpServerRequest","handler","getFiberRef","currentPreResponseHandlers","_tag","as","tap","value","withErrorHandling","catchAllCause","cause","causeResponse","zipRight","failCause","withMiddleware","unify","undefined","tracer","matchCauseEffect","onFailure","void","_cause","empty","status","onSuccess","uninterruptible","scoped","exports","appendPreResponseHandler","withPreResponseHandler","toWebHandlerRuntime","runtime","run","runFork","resolveSymbol","httpApp","toWeb","withoutBody","method","context","Promise","resolve","contextMap","Map","unsafeMap","isContext","key","httpServerRequest","fromWeb","locally","unsafeMake","signal","addEventListener","unsafeInterruptAsFork","clientAbortFiberId","once","toWebHandler","defaultRuntime","toWebHandlerLayer","layer","
|
|
1
|
+
{"version":3,"file":"HttpApp.js","names":["Context","_interopRequireWildcard","require","Effect","Exit","Fiber","FiberRef","GlobalValue","Layer","Option","Runtime","Scope","Stream","_Unify","HttpBody","ServerError","ServerRequest","ServerResponse","internal","internalMiddleware","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","handledSymbol","Symbol","for","toHandled","self","handleResponse","middleware","responded","withFiberRuntime","fiber","flatMap","response","request","unsafeGet","currentContext","HttpServerRequest","handler","getFiberRef","currentPreResponseHandlers","_tag","as","tap","value","withErrorHandling","catchAllCause","cause","causeResponse","zipRight","failCause","withMiddleware","unify","undefined","tracer","matchCauseEffect","onFailure","void","_cause","empty","status","onSuccess","uninterruptible","scoped","exports","ejectDefaultScopeClose","scope","ejectedScopes","add","unsafeEjectStreamScope","body","getOrThrow","getCurrentFiber","setBody","stream","ensuring","close","contentType","contentLength","globalValue","WeakSet","effect","make","onExit","extend","exit","appendPreResponseHandler","withPreResponseHandler","toWebHandlerRuntime","runtime","run","runFork","resolveSymbol","httpApp","toWeb","withoutBody","method","context","Promise","resolve","contextMap","Map","unsafeMap","isContext","key","httpServerRequest","fromWeb","locally","unsafeMake","signal","addEventListener","unsafeInterruptAsFork","clientAbortFiberId","once","toWebHandler","defaultRuntime","toWebHandlerLayer","layer","runSync","runPromise","build","map","toRuntime","_","runner","then"],"sources":["../../src/HttpApp.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,uBAAA,CAAAC,OAAA;AACA,IAAAE,IAAA,GAAAH,uBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAJ,uBAAA,CAAAC,OAAA;AACA,IAAAI,QAAA,GAAAL,uBAAA,CAAAC,OAAA;AACA,IAAAK,WAAA,GAAAN,uBAAA,CAAAC,OAAA;AACA,IAAAM,KAAA,GAAAP,uBAAA,CAAAC,OAAA;AACA,IAAAO,MAAA,GAAAR,uBAAA,CAAAC,OAAA;AACA,IAAAQ,OAAA,GAAAT,uBAAA,CAAAC,OAAA;AACA,IAAAS,KAAA,GAAAV,uBAAA,CAAAC,OAAA;AACA,IAAAU,MAAA,GAAAX,uBAAA,CAAAC,OAAA;AACA,IAAAW,MAAA,GAAAX,OAAA;AACA,IAAAY,QAAA,GAAAb,uBAAA,CAAAC,OAAA;AAEA,IAAAa,WAAA,GAAAd,uBAAA,CAAAC,OAAA;AACA,IAAAc,aAAA,GAAAf,uBAAA,CAAAC,OAAA;AACA,IAAAe,cAAA,GAAAhB,uBAAA,CAAAC,OAAA;AACA,IAAAgB,QAAA,GAAAjB,uBAAA,CAAAC,OAAA;AACA,IAAAiB,kBAAA,GAAAlB,uBAAA,CAAAC,OAAA;AAAkE,SAAAD,wBAAAmB,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAArB,uBAAA,YAAAA,CAAAmB,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAA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GA,CAC/B1F,IAAiC,EACjC2F,KAAyB,EACzBzF,UAAuC,KAIrC;EACF,MAAMsC,KAAK,GAAGhF,MAAM,CAACoI,OAAO,CAAC5H,KAAK,CAACwF,IAAI,EAAE,CAAC;EAC1C,MAAMN,KAAK,GAAGA,CAAA,KAAM1F,MAAM,CAACqI,UAAU,CAAC7H,KAAK,CAACkF,KAAK,CAACV,KAAK,EAAE/E,IAAI,CAACsE,IAAI,CAAC,CAAC;EACpE,MAAM+D,KAAK,GAAGtI,MAAM,CAACuI,GAAG,CAAClI,KAAK,CAACmI,SAAS,CAACL,KAAK,CAAC,EAAGM,CAAC,IAAKnC,mBAAmB,CAACmC,CAAC,CAAC,CAACjG,IAAI,EAAEE,UAAU,CAAC,CAAC;EACjG,MAAMgG,MAAM,GAAG1I,MAAM,CAACqI,UAAU,CAAC7H,KAAK,CAAC0F,MAAM,CAACoC,KAAK,EAAEtD,KAAK,CAAC,CAAC;EAC5D,MAAM5B,OAAO,GAAGA,CAACJ,OAAgB,EAAE+D,OAA4C,KAC7E2B,MAAM,CAACC,IAAI,CAAEvF,OAAO,IAAKA,OAAO,CAACJ,OAAO,EAAE+D,OAAO,CAAC,CAAC;EACrD,OAAO;IAAErB,KAAK;IAAEtC;EAAO,CAAW;AACpC,CAAC;AAAA0B,OAAA,CAAAoD,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
package/dist/cjs/HttpBody.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpBody.js","names":["Predicate","_interopRequireWildcard","require","internal","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","TypeId","exports","isHttpBody","u","hasProperty","ErrorTypeId","HttpBodyError","empty","raw","uint8Array","text","unsafeJson","json","jsonSchema","urlParams","formData","formDataRecord","stream","file","fileInfo","fileWeb"],"sources":["../../src/HttpBody.ts"],"sourcesContent":[null],"mappings":";;;;;;AAMA,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o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","TypeId","exports","isHttpBody","u","hasProperty","ErrorTypeId","HttpBodyError","empty","raw","uint8Array","text","unsafeJson","json","jsonSchema","urlParams","formData","formDataRecord","stream","file","fileInfo","fileWeb"],"sources":["../../src/HttpBody.ts"],"sourcesContent":[null],"mappings":";;;;;;AAMA,IAAAA,SAAA,GAAAC,uBAAA,CAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAF,uBAAA,CAAAC,OAAA;AAAkD,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAA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ACmC,QAAQ;AAclF;;;;AAIO,MAAMC,cAAc,GAAAf,OAAA,CAAAe,cAAA,GAAyCpC,QAAQ,CAACoC,cAAc;AAa3F;;;;AAIO,MAAMC,MAAM,GAAAhB,OAAA,CAAAgB,MAAA,GAILrC,QAAQ,CAACqC,MAAM;AAE7B;;;;AAIO,MAAMC,IAAI,GAAAjB,OAAA,CAAAiB,IAAA,GAGgEtC,QAAQ,CAACsC,IAAI;AAE9F;;;;AAIO,MAAMC,QAAQ,GAAAlB,OAAA,CAAAkB,QAAA,GAI4DvC,QAAQ,CAACuC,QAAQ;AAElG;;;;AAIO,MAAMC,OAAO,GAAAnB,OAAA,CAAAmB,OAAA,GAAwCxC,QAAQ,CAACwC,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MiddlewareTypeId = exports.HttpRouter = exports.FindMyWay = void 0;
|
|
7
|
+
Object.defineProperty(exports, "RouteContext", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _HttpRouter.RouteContext;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
exports.middleware = exports.make = exports.layer = exports.cors = exports.addHttpApi = exports.TypeId = exports.RouterConfig = exports.RouteTypeId = void 0;
|
|
14
|
+
Object.defineProperty(exports, "params", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return _HttpRouter.params;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
exports.route = exports.prefixRoute = exports.prefixPath = void 0;
|
|
21
|
+
Object.defineProperty(exports, "schemaJson", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _HttpRouter.schemaJson;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, "schemaNoBody", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () {
|
|
30
|
+
return _HttpRouter.schemaNoBody;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, "schemaParams", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () {
|
|
36
|
+
return _HttpRouter.schemaParams;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "schemaPathParams", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () {
|
|
42
|
+
return _HttpRouter.schemaPathParams;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
exports.use = exports.toHttpEffect = exports.serve = void 0;
|
|
46
|
+
var HttpServerRequest = _interopRequireWildcard(require("@effect/platform/HttpServerRequest"));
|
|
47
|
+
var HttpServerResponse = _interopRequireWildcard(require("@effect/platform/HttpServerResponse"));
|
|
48
|
+
var Arr = _interopRequireWildcard(require("effect/Array"));
|
|
49
|
+
var Context = _interopRequireWildcard(require("effect/Context"));
|
|
50
|
+
var Effect = _interopRequireWildcard(require("effect/Effect"));
|
|
51
|
+
var FiberRef = _interopRequireWildcard(require("effect/FiberRef"));
|
|
52
|
+
var _Function = require("effect/Function");
|
|
53
|
+
var Layer = _interopRequireWildcard(require("effect/Layer"));
|
|
54
|
+
var Option = _interopRequireWildcard(require("effect/Option"));
|
|
55
|
+
var Scope = _interopRequireWildcard(require("effect/Scope"));
|
|
56
|
+
var Tracer = _interopRequireWildcard(require("effect/Tracer"));
|
|
57
|
+
var FindMyWay = _interopRequireWildcard(require("find-my-way-ts"));
|
|
58
|
+
var _FindMyWay = FindMyWay;
|
|
59
|
+
exports.FindMyWay = FindMyWay;
|
|
60
|
+
var HttpApi = _interopRequireWildcard(require("./HttpApi.js"));
|
|
61
|
+
var HttpApiBuilder = _interopRequireWildcard(require("./HttpApiBuilder.js"));
|
|
62
|
+
var HttpMiddleware = _interopRequireWildcard(require("./HttpMiddleware.js"));
|
|
63
|
+
var _HttpRouter = require("./HttpRouter.js");
|
|
64
|
+
var HttpServer = _interopRequireWildcard(require("./HttpServer.js"));
|
|
65
|
+
var HttpServerError = _interopRequireWildcard(require("./HttpServerError.js"));
|
|
66
|
+
var OpenApi = _interopRequireWildcard(require("./OpenApi.js"));
|
|
67
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
68
|
+
/**
|
|
69
|
+
* @since 1.0.0
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @since 1.0.0
|
|
74
|
+
* @category Re-exports
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @since 1.0.0
|
|
79
|
+
* @category HttpRouter
|
|
80
|
+
*/
|
|
81
|
+
const TypeId = exports.TypeId = /*#__PURE__*/Symbol.for("@effect/platform/HttpLayerRouter/HttpRouter");
|
|
82
|
+
/**
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
* @category HttpRouter
|
|
85
|
+
*/
|
|
86
|
+
const HttpRouter = exports.HttpRouter = /*#__PURE__*/Context.GenericTag("@effect/platform/HttpLayerRouter");
|
|
87
|
+
/**
|
|
88
|
+
* @since 1.0.0
|
|
89
|
+
* @category HttpRouter
|
|
90
|
+
*/
|
|
91
|
+
const make = exports.make = /*#__PURE__*/Effect.gen(function* () {
|
|
92
|
+
const router = FindMyWay.make(yield* RouterConfig);
|
|
93
|
+
const addAll = routes => Effect.contextWith(context => {
|
|
94
|
+
const middleware = getMiddleware(context);
|
|
95
|
+
const applyMiddleware = effect => {
|
|
96
|
+
for (let i = 0; i < middleware.length; i++) {
|
|
97
|
+
effect = middleware[i](effect);
|
|
98
|
+
}
|
|
99
|
+
return effect;
|
|
100
|
+
};
|
|
101
|
+
for (let i = 0; i < routes.length; i++) {
|
|
102
|
+
const route = middleware.length === 0 ? routes[i] : makeRoute({
|
|
103
|
+
...routes[i],
|
|
104
|
+
handler: applyMiddleware(routes[i].handler)
|
|
105
|
+
});
|
|
106
|
+
if (route.method === "*") {
|
|
107
|
+
router.all(route.path, route);
|
|
108
|
+
} else {
|
|
109
|
+
router.on(route.method, route.path, route);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return HttpRouter.of({
|
|
114
|
+
[TypeId]: TypeId,
|
|
115
|
+
prefixed(prefix) {
|
|
116
|
+
return HttpRouter.of({
|
|
117
|
+
[TypeId]: TypeId,
|
|
118
|
+
asHttpEffect: this.asHttpEffect,
|
|
119
|
+
prefixed: newPrefix => this.prefixed(prefixPath(prefix, newPrefix)),
|
|
120
|
+
addAll: routes => addAll(routes.map(prefixRoute(prefix))),
|
|
121
|
+
add: (method, path, handler, options) => addAll([makeRoute({
|
|
122
|
+
method,
|
|
123
|
+
path: prefixPath(path, prefix),
|
|
124
|
+
handler: Effect.isEffect(handler) ? handler : Effect.flatMap(HttpServerRequest.HttpServerRequest, handler),
|
|
125
|
+
uninterruptible: options?.uninterruptible ?? false,
|
|
126
|
+
prefix: Option.some(prefix)
|
|
127
|
+
})])
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
addAll,
|
|
131
|
+
add: (method, path, handler, options) => addAll([route(method, path, handler, options)]),
|
|
132
|
+
asHttpEffect() {
|
|
133
|
+
return Effect.withFiberRuntime(fiber => {
|
|
134
|
+
const contextMap = new Map(fiber.currentContext.unsafeMap);
|
|
135
|
+
const request = contextMap.get(HttpServerRequest.HttpServerRequest.key);
|
|
136
|
+
let result = router.find(request.method, request.url);
|
|
137
|
+
if (result === undefined && request.method === "HEAD") {
|
|
138
|
+
result = router.find("GET", request.url);
|
|
139
|
+
}
|
|
140
|
+
if (result === undefined) {
|
|
141
|
+
return Effect.fail(new HttpServerError.RouteNotFound({
|
|
142
|
+
request
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
const route = result.handler;
|
|
146
|
+
if (route.prefix._tag === "Some") {
|
|
147
|
+
contextMap.set(HttpServerRequest.HttpServerRequest.key, sliceRequestUrl(request, route.prefix.value));
|
|
148
|
+
}
|
|
149
|
+
contextMap.set(HttpServerRequest.ParsedSearchParams.key, result.searchParams);
|
|
150
|
+
contextMap.set(_HttpRouter.RouteContext.key, {
|
|
151
|
+
[_HttpRouter.RouteContextTypeId]: _HttpRouter.RouteContextTypeId,
|
|
152
|
+
route,
|
|
153
|
+
params: result.params
|
|
154
|
+
});
|
|
155
|
+
const span = contextMap.get(Tracer.ParentSpan.key);
|
|
156
|
+
if (span && span._tag === "Span") {
|
|
157
|
+
span.attribute("http.route", route.path);
|
|
158
|
+
}
|
|
159
|
+
return Effect.locally(route.uninterruptible ? route.handler : Effect.interruptible(route.handler), FiberRef.currentContext, Context.unsafeMake(contextMap));
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
function sliceRequestUrl(request, prefix) {
|
|
165
|
+
const prefexLen = prefix.length;
|
|
166
|
+
return request.modify({
|
|
167
|
+
url: request.url.length <= prefexLen ? "/" : request.url.slice(prefexLen)
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* @since 1.0.0
|
|
172
|
+
* @category Configuration
|
|
173
|
+
*/
|
|
174
|
+
class RouterConfig extends /*#__PURE__*/Context.Reference()("@effect/platform/HttpLayerRouter/RouterConfig", {
|
|
175
|
+
defaultValue: /*#__PURE__*/(0, _Function.constant)({})
|
|
176
|
+
}) {}
|
|
177
|
+
exports.RouterConfig = RouterConfig;
|
|
178
|
+
/**
|
|
179
|
+
* A helper function that is the equivalent of:
|
|
180
|
+
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* import * as HttpLayerRouter from "@effect/platform/HttpLayerRouter"
|
|
183
|
+
* import * as Effect from "effect/Effect"
|
|
184
|
+
* import * as Layer from "effect/Layer"
|
|
185
|
+
*
|
|
186
|
+
* const MyRoute = Layer.scopedDiscard(Effect.gen(function*() {
|
|
187
|
+
* const router = yield* HttpLayerRouter.HttpRouter
|
|
188
|
+
*
|
|
189
|
+
* // then use `router.add` to add a route
|
|
190
|
+
* }))
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @since 1.0.0
|
|
194
|
+
* @category HttpRouter
|
|
195
|
+
*/
|
|
196
|
+
const use = f => Layer.scopedDiscard(Effect.flatMap(HttpRouter, f));
|
|
197
|
+
/**
|
|
198
|
+
* @since 1.0.0
|
|
199
|
+
* @category HttpRouter
|
|
200
|
+
*/
|
|
201
|
+
exports.use = use;
|
|
202
|
+
const layer = exports.layer = /*#__PURE__*/Layer.effect(HttpRouter, make);
|
|
203
|
+
/**
|
|
204
|
+
* @since 1.0.0
|
|
205
|
+
* @category HttpRouter
|
|
206
|
+
*/
|
|
207
|
+
const toHttpEffect = appLayer => Effect.gen(function* () {
|
|
208
|
+
const scope = yield* Effect.scope;
|
|
209
|
+
const memoMap = yield* Layer.CurrentMemoMap;
|
|
210
|
+
const context = yield* Layer.buildWithMemoMap(Layer.provideMerge(appLayer, layer), memoMap, scope);
|
|
211
|
+
const router = Context.get(context, HttpRouter);
|
|
212
|
+
return router.asHttpEffect();
|
|
213
|
+
});
|
|
214
|
+
/**
|
|
215
|
+
* @since 1.0.0
|
|
216
|
+
* @category Route
|
|
217
|
+
*/
|
|
218
|
+
exports.toHttpEffect = toHttpEffect;
|
|
219
|
+
const RouteTypeId = exports.RouteTypeId = /*#__PURE__*/Symbol.for("@effect/platform/HttpLayerRouter/Route");
|
|
220
|
+
const makeRoute = options => ({
|
|
221
|
+
...options,
|
|
222
|
+
uninterruptible: options.uninterruptible ?? false,
|
|
223
|
+
prefix: options.prefix ?? Option.none(),
|
|
224
|
+
[RouteTypeId]: RouteTypeId
|
|
225
|
+
});
|
|
226
|
+
/**
|
|
227
|
+
* @since 1.0.0
|
|
228
|
+
* @category Route
|
|
229
|
+
*/
|
|
230
|
+
const route = (method, path, handler, options) => makeRoute({
|
|
231
|
+
...options,
|
|
232
|
+
method,
|
|
233
|
+
path,
|
|
234
|
+
handler: Effect.isEffect(handler) ? handler : Effect.flatMap(HttpServerRequest.HttpServerRequest, handler),
|
|
235
|
+
uninterruptible: options?.uninterruptible ?? false
|
|
236
|
+
});
|
|
237
|
+
exports.route = route;
|
|
238
|
+
const removeTrailingSlash = path => path.endsWith("/") ? path.slice(0, -1) : path;
|
|
239
|
+
/**
|
|
240
|
+
* @since 1.0.0
|
|
241
|
+
* @category PathInput
|
|
242
|
+
*/
|
|
243
|
+
const prefixPath = exports.prefixPath = /*#__PURE__*/(0, _Function.dual)(2, (self, prefix) => {
|
|
244
|
+
prefix = removeTrailingSlash(prefix);
|
|
245
|
+
return self === "/" ? prefix : prefix + self;
|
|
246
|
+
});
|
|
247
|
+
/**
|
|
248
|
+
* @since 1.0.0
|
|
249
|
+
* @category Route
|
|
250
|
+
*/
|
|
251
|
+
const prefixRoute = exports.prefixRoute = /*#__PURE__*/(0, _Function.dual)(2, (self, prefix) => makeRoute({
|
|
252
|
+
...self,
|
|
253
|
+
path: prefixPath(self.path, prefix),
|
|
254
|
+
prefix: Option.match(self.prefix, {
|
|
255
|
+
onNone: () => Option.some(prefix),
|
|
256
|
+
onSome: existingPrefix => Option.some(prefixPath(existingPrefix, prefix))
|
|
257
|
+
})
|
|
258
|
+
}));
|
|
259
|
+
/**
|
|
260
|
+
* @since 1.0.0
|
|
261
|
+
* @category Middleware
|
|
262
|
+
*/
|
|
263
|
+
const MiddlewareTypeId = exports.MiddlewareTypeId = /*#__PURE__*/Symbol.for("@effect/platform/HttpLayerRouter/Middleware");
|
|
264
|
+
/**
|
|
265
|
+
* Create a middleware layer that can be used to modify requests and responses.
|
|
266
|
+
*
|
|
267
|
+
* ```ts
|
|
268
|
+
* import * as HttpLayerRouter from "@effect/platform/HttpLayerRouter"
|
|
269
|
+
* import * as HttpMiddleware from "@effect/platform/HttpMiddleware"
|
|
270
|
+
* import * as HttpServerResponse from "@effect/platform/HttpServerResponse"
|
|
271
|
+
* import * as Context from "effect/Context"
|
|
272
|
+
* import * as Effect from "effect/Effect"
|
|
273
|
+
* import * as Layer from "effect/Layer"
|
|
274
|
+
*
|
|
275
|
+
* // Here we are defining a CORS middleware
|
|
276
|
+
* const CorsMiddleware = HttpLayerRouter.middleware(HttpMiddleware.cors()).layer
|
|
277
|
+
* // You can also use HttpLayerRouter.cors() to create a CORS middleware
|
|
278
|
+
*
|
|
279
|
+
* class CurrentSession extends Context.Tag("CurrentSession")<CurrentSession, {
|
|
280
|
+
* readonly token: string
|
|
281
|
+
* }>() {}
|
|
282
|
+
*
|
|
283
|
+
* // You can create middleware that provides a service to the HTTP requests.
|
|
284
|
+
* const SessionMiddleware = HttpLayerRouter.middleware<{
|
|
285
|
+
* provides: CurrentSession
|
|
286
|
+
* }>()(
|
|
287
|
+
* Effect.gen(function*() {
|
|
288
|
+
* yield* Effect.log("SessionMiddleware initialized")
|
|
289
|
+
*
|
|
290
|
+
* return (httpEffect) =>
|
|
291
|
+
* Effect.provideService(httpEffect, CurrentSession, {
|
|
292
|
+
* token: "dummy-token"
|
|
293
|
+
* })
|
|
294
|
+
* })
|
|
295
|
+
* ).layer
|
|
296
|
+
*
|
|
297
|
+
* Effect.gen(function*() {
|
|
298
|
+
* const router = yield* HttpLayerRouter.HttpRouter
|
|
299
|
+
* yield* router.add(
|
|
300
|
+
* "GET",
|
|
301
|
+
* "/hello",
|
|
302
|
+
* Effect.gen(function*() {
|
|
303
|
+
* // Requests can now access the current session
|
|
304
|
+
* const session = yield* CurrentSession
|
|
305
|
+
* return HttpServerResponse.text(`Hello, World! Your token is ${session.token}`)
|
|
306
|
+
* })
|
|
307
|
+
* )
|
|
308
|
+
* }).pipe(
|
|
309
|
+
* Layer.effectDiscard,
|
|
310
|
+
* // Provide the SessionMiddleware & CorsMiddleware to some routes
|
|
311
|
+
* Layer.provide([SessionMiddleware, CorsMiddleware])
|
|
312
|
+
* )
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* @since 1.0.0
|
|
316
|
+
* @category Middleware
|
|
317
|
+
*/
|
|
318
|
+
const middleware = function () {
|
|
319
|
+
if (arguments.length === 0) {
|
|
320
|
+
return makeMiddleware;
|
|
321
|
+
}
|
|
322
|
+
return makeMiddleware(arguments[0]);
|
|
323
|
+
};
|
|
324
|
+
exports.middleware = middleware;
|
|
325
|
+
const makeMiddleware = middleware => new MiddlewareImpl(Effect.isEffect(middleware) ? Layer.scopedContext(Effect.map(middleware, fn => Context.unsafeMake(new Map([[fnContextKey, fn]])))) : Layer.succeedContext(Context.unsafeMake(new Map([[fnContextKey, middleware]]))));
|
|
326
|
+
let middlewareId = 0;
|
|
327
|
+
const fnContextKey = "@effect/platform/HttpLayerRouter/MiddlewareFn";
|
|
328
|
+
class MiddlewareImpl {
|
|
329
|
+
layerFn;
|
|
330
|
+
dependencies;
|
|
331
|
+
[MiddlewareTypeId] = {};
|
|
332
|
+
constructor(layerFn, dependencies) {
|
|
333
|
+
this.layerFn = layerFn;
|
|
334
|
+
this.dependencies = dependencies;
|
|
335
|
+
const contextKey = `@effect/platform/HttpLayerRouter/Middleware-${++middlewareId}`;
|
|
336
|
+
this.layer = Layer.scopedContext(Effect.gen(this, function* () {
|
|
337
|
+
const context = yield* Effect.context();
|
|
338
|
+
const stack = [context.unsafeMap.get(fnContextKey)];
|
|
339
|
+
if (this.dependencies) {
|
|
340
|
+
const memoMap = yield* Layer.CurrentMemoMap;
|
|
341
|
+
const scope = Context.get(context, Scope.Scope);
|
|
342
|
+
const depsContext = yield* Layer.buildWithMemoMap(this.dependencies, memoMap, scope);
|
|
343
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
344
|
+
stack.push(...getMiddleware(depsContext));
|
|
345
|
+
}
|
|
346
|
+
return Context.unsafeMake(new Map([[contextKey, stack]]));
|
|
347
|
+
})).pipe(Layer.provide(this.layerFn));
|
|
348
|
+
}
|
|
349
|
+
layer;
|
|
350
|
+
combine(other) {
|
|
351
|
+
return new MiddlewareImpl(this.layerFn, this.dependencies ? Layer.provideMerge(this.dependencies, other.layer) : other.layer);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const middlewareCache = /*#__PURE__*/new WeakMap();
|
|
355
|
+
const getMiddleware = context => {
|
|
356
|
+
let arr = middlewareCache.get(context);
|
|
357
|
+
if (arr) return arr;
|
|
358
|
+
const topLevel = Arr.empty();
|
|
359
|
+
let maxLength = 0;
|
|
360
|
+
for (const [key, value] of context.unsafeMap) {
|
|
361
|
+
if (key.startsWith("@effect/platform/HttpLayerRouter/Middleware-")) {
|
|
362
|
+
topLevel.push(value);
|
|
363
|
+
if (value.length > maxLength) {
|
|
364
|
+
maxLength = value.length;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (topLevel.length === 0) {
|
|
369
|
+
arr = [];
|
|
370
|
+
} else {
|
|
371
|
+
const middleware = new Set();
|
|
372
|
+
for (let i = maxLength - 1; i >= 0; i--) {
|
|
373
|
+
for (const arr of topLevel) {
|
|
374
|
+
if (i < arr.length) {
|
|
375
|
+
middleware.add(arr[i]);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
arr = Arr.fromIterable(middleware).reverse();
|
|
380
|
+
}
|
|
381
|
+
middlewareCache.set(context, arr);
|
|
382
|
+
return arr;
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* A middleware that applies CORS headers to the HTTP response.
|
|
386
|
+
*
|
|
387
|
+
* @since 1.0.0
|
|
388
|
+
* @category Middleware
|
|
389
|
+
*/
|
|
390
|
+
const cors = options => middleware(HttpMiddleware.cors(options)).layer;
|
|
391
|
+
/**
|
|
392
|
+
* ```ts
|
|
393
|
+
* import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer"
|
|
394
|
+
* import * as NodeRuntime from "@effect/platform-node/NodeRuntime"
|
|
395
|
+
* import * as HttpApi from "@effect/platform/HttpApi"
|
|
396
|
+
* import * as HttpApiBuilder from "@effect/platform/HttpApiBuilder"
|
|
397
|
+
* import * as HttpApiEndpoint from "@effect/platform/HttpApiEndpoint"
|
|
398
|
+
* import * as HttpApiGroup from "@effect/platform/HttpApiGroup"
|
|
399
|
+
* import * as HttpApiScalar from "@effect/platform/HttpApiScalar"
|
|
400
|
+
* import * as HttpLayerRouter from "@effect/platform/HttpLayerRouter"
|
|
401
|
+
* import * as HttpMiddleware from "@effect/platform/HttpMiddleware"
|
|
402
|
+
* import * as Effect from "effect/Effect"
|
|
403
|
+
* import * as Layer from "effect/Layer"
|
|
404
|
+
* import { createServer } from "http"
|
|
405
|
+
*
|
|
406
|
+
* // First, we define our HttpApi
|
|
407
|
+
* class MyApi extends HttpApi.make("api").add(
|
|
408
|
+
* HttpApiGroup.make("users").add(
|
|
409
|
+
* HttpApiEndpoint.get("me", "/me")
|
|
410
|
+
* ).prefix("/users")
|
|
411
|
+
* ) {}
|
|
412
|
+
*
|
|
413
|
+
* // Implement the handlers for the API
|
|
414
|
+
* const UsersApiLayer = HttpApiBuilder.group(MyApi, "users", (handers) => handers.handle("me", () => Effect.void))
|
|
415
|
+
*
|
|
416
|
+
* // Use `HttpLayerRouter.addHttpApi` to register the API with the router
|
|
417
|
+
* const HttpApiRoutes = HttpLayerRouter.addHttpApi(MyApi, {
|
|
418
|
+
* openapiPath: "/docs/openapi.json"
|
|
419
|
+
* }).pipe(
|
|
420
|
+
* // Provide the api handlers layer
|
|
421
|
+
* Layer.provide(UsersApiLayer)
|
|
422
|
+
* )
|
|
423
|
+
*
|
|
424
|
+
* // Create a /docs route for the API documentation
|
|
425
|
+
* const DocsRoute = HttpApiScalar.layerHttpLayerRouter({
|
|
426
|
+
* api: MyApi,
|
|
427
|
+
* path: "/docs"
|
|
428
|
+
* })
|
|
429
|
+
*
|
|
430
|
+
* const CorsMiddleware = HttpLayerRouter.middleware(HttpMiddleware.cors())
|
|
431
|
+
* // You can also use HttpLayerRouter.cors() to create a CORS middleware
|
|
432
|
+
*
|
|
433
|
+
* // Finally, we merge all routes and serve them using the Node HTTP server
|
|
434
|
+
* const AllRoutes = Layer.mergeAll(
|
|
435
|
+
* HttpApiRoutes,
|
|
436
|
+
* DocsRoute
|
|
437
|
+
* ).pipe(
|
|
438
|
+
* Layer.provide(CorsMiddleware.layer)
|
|
439
|
+
* )
|
|
440
|
+
*
|
|
441
|
+
* HttpLayerRouter.serve(AllRoutes).pipe(
|
|
442
|
+
* Layer.provide(NodeHttpServer.layer(createServer, { port: 3000 })),
|
|
443
|
+
* Layer.launch,
|
|
444
|
+
* NodeRuntime.runMain
|
|
445
|
+
* )
|
|
446
|
+
* ```
|
|
447
|
+
*
|
|
448
|
+
* @since 1.0.0
|
|
449
|
+
* @category HttpApi
|
|
450
|
+
*/
|
|
451
|
+
exports.cors = cors;
|
|
452
|
+
const addHttpApi = (api, options) => {
|
|
453
|
+
const ApiMiddleware = middleware(HttpApiBuilder.buildMiddleware(api)).layer;
|
|
454
|
+
return HttpApiBuilder.Router.unwrap(Effect.fnUntraced(function* (router_) {
|
|
455
|
+
const contextMap = new Map();
|
|
456
|
+
const router = yield* HttpRouter;
|
|
457
|
+
const routes = Arr.empty();
|
|
458
|
+
const context = yield* Effect.context();
|
|
459
|
+
contextMap.set(HttpApi.Api.key, {
|
|
460
|
+
api,
|
|
461
|
+
context
|
|
462
|
+
});
|
|
463
|
+
for (const route of router_.routes) {
|
|
464
|
+
routes.push(makeRoute(route));
|
|
465
|
+
}
|
|
466
|
+
yield* router.addAll(routes);
|
|
467
|
+
if (options?.openapiPath) {
|
|
468
|
+
const spec = OpenApi.fromApi(api);
|
|
469
|
+
yield* router.add("GET", options.openapiPath, Effect.succeed(HttpServerResponse.unsafeJson(spec)));
|
|
470
|
+
}
|
|
471
|
+
return Context.unsafeMake(contextMap);
|
|
472
|
+
}, Layer.effectContext)).pipe(Layer.provide(ApiMiddleware));
|
|
473
|
+
};
|
|
474
|
+
/**
|
|
475
|
+
* Serves the provided application layer as an HTTP server.
|
|
476
|
+
*
|
|
477
|
+
* @since 1.0.0
|
|
478
|
+
* @category Server
|
|
479
|
+
*/
|
|
480
|
+
exports.addHttpApi = addHttpApi;
|
|
481
|
+
const serve = (appLayer, options) => {
|
|
482
|
+
let middleware = options?.middleware;
|
|
483
|
+
if (options?.disableLogger !== true) {
|
|
484
|
+
middleware = middleware ? (0, _Function.compose)(middleware, HttpMiddleware.logger) : HttpMiddleware.logger;
|
|
485
|
+
}
|
|
486
|
+
const RouterLayer = options?.routerConfig ? Layer.provide(layer, Layer.succeed(RouterConfig, options.routerConfig)) : layer;
|
|
487
|
+
return Effect.gen(function* () {
|
|
488
|
+
const router = yield* HttpRouter;
|
|
489
|
+
const handler = router.asHttpEffect();
|
|
490
|
+
return middleware ? HttpServer.serve(handler, middleware) : HttpServer.serve(handler);
|
|
491
|
+
}).pipe(Layer.unwrapScoped, options?.disableListenLog ? _Function.identity : HttpServer.withLogAddress, Layer.provide(appLayer), Layer.provide(RouterLayer));
|
|
492
|
+
};
|
|
493
|
+
exports.serve = serve;
|
|
494
|
+
//# sourceMappingURL=HttpLayerRouter.js.map
|