@effect-app/infra 3.0.0 → 3.0.1

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 (48) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/QueueMaker/errors.d.ts +1 -1
  3. package/dist/QueueMaker/errors.d.ts.map +1 -1
  4. package/dist/api/routing/middleware/RouterMiddleware.d.ts +1 -1
  5. package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +1 -1
  6. package/dist/api/routing/middleware/middleware.d.ts +1 -2
  7. package/dist/api/routing/middleware/middleware.d.ts.map +1 -1
  8. package/dist/api/routing/middleware/middleware.js +2 -3
  9. package/dist/api/routing/middleware.d.ts +0 -4
  10. package/dist/api/routing/middleware.d.ts.map +1 -1
  11. package/dist/api/routing/middleware.js +1 -5
  12. package/dist/api/routing.d.ts +1 -2
  13. package/dist/api/routing.d.ts.map +1 -1
  14. package/dist/api/routing.js +2 -8
  15. package/package.json +2 -22
  16. package/src/api/routing/middleware/RouterMiddleware.ts +1 -1
  17. package/src/api/routing/middleware/middleware.ts +1 -3
  18. package/src/api/routing/middleware.ts +0 -4
  19. package/src/api/routing.ts +3 -9
  20. package/test/controller.test.ts +13 -14
  21. package/test/dist/controller.test.d.ts.map +1 -1
  22. package/test/dist/fixtures.d.ts +9 -9
  23. package/test/dist/fixtures.js +2 -2
  24. package/test/dist/requires.test.d.ts.map +1 -1
  25. package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
  26. package/test/fixtures.ts +1 -1
  27. package/test/requires.test.ts +2 -2
  28. package/test/rpc-multi-middleware.test.ts +2 -2
  29. package/dist/api/routing/middleware/RpcMiddleware.d.ts +0 -188
  30. package/dist/api/routing/middleware/RpcMiddleware.d.ts.map +0 -1
  31. package/dist/api/routing/middleware/RpcMiddleware.js +0 -13
  32. package/dist/api/routing/middleware/RpcMiddlewareX.d.ts +0 -18
  33. package/dist/api/routing/middleware/RpcMiddlewareX.d.ts.map +0 -1
  34. package/dist/api/routing/middleware/RpcMiddlewareX.js +0 -16
  35. package/dist/api/routing/middleware/generic-middleware.d.ts +0 -55
  36. package/dist/api/routing/middleware/generic-middleware.d.ts.map +0 -1
  37. package/dist/api/routing/middleware/generic-middleware.js +0 -67
  38. package/dist/api/routing/middleware/middleware-api.d.ts +0 -107
  39. package/dist/api/routing/middleware/middleware-api.d.ts.map +0 -1
  40. package/dist/api/routing/middleware/middleware-api.js +0 -88
  41. package/dist/api/routing/middleware/middleware-native.d.ts +0 -23
  42. package/dist/api/routing/middleware/middleware-native.d.ts.map +0 -1
  43. package/dist/api/routing/middleware/middleware-native.js +0 -19
  44. package/src/api/routing/middleware/RpcMiddleware.ts +0 -254
  45. package/src/api/routing/middleware/RpcMiddlewareX.ts +0 -70
  46. package/src/api/routing/middleware/generic-middleware.ts +0 -198
  47. package/src/api/routing/middleware/middleware-api.ts +0 -404
  48. package/src/api/routing/middleware/middleware-native.ts +0 -23
@@ -1,88 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Rpc } from "@effect/rpc";
3
- import { Tag } from "@effect/rpc/RpcMiddleware";
4
- import { Context, Layer, S } from "effect-app";
5
- import { typedValuesOf } from "effect-app/utils";
6
- import { middlewareMaker } from "./generic-middleware.js";
7
- /** Adapter used when setting the dynamic prop on a middleware implementation */
8
- export const contextMap = (rcm, key) => ({
9
- key,
10
- settings: { service: rcm[key]["service"] }
11
- });
12
- const tag = Context.GenericTag("RequestContextConfig");
13
- /** Retrieves RequestContextConfig out of the RPC annotations */
14
- export const getConfig = () => (rpc) => {
15
- return Context.getOrElse(rpc.annotations, tag, () => ({}));
16
- };
17
- const makeMiddlewareBasic =
18
- // by setting RequestContextMap beforehand, execute contextual typing does not fuck up itself to anys
19
- (rcm, ...make) => {
20
- // reverse middlewares and wrap one after the other
21
- const middleware = middlewareMaker(make);
22
- const failures = make.map((_) => _.failure).filter(Boolean);
23
- const provides = make.flatMap((_) => !_.provides ? [] : Array.isArray(_.provides) ? _.provides : [_.provides]);
24
- const requires = make
25
- .flatMap((_) => !_.requires ? [] : Array.isArray(_.requires) ? _.requires : [_.requires])
26
- .filter((_) => !provides.includes(_));
27
- const MiddlewareMaker = Tag()("MiddlewareMaker", {
28
- failure: (failures.length > 0
29
- ? S.Union(...failures)
30
- : S.Never),
31
- requires: (requires.length > 0
32
- ? requires
33
- : undefined),
34
- provides: (provides.length > 0
35
- ? provides
36
- : undefined),
37
- wrap: true
38
- });
39
- const layer = Layer
40
- .scoped(MiddlewareMaker, middleware);
41
- // add to the tag a default implementation
42
- return Object.assign(MiddlewareMaker, {
43
- layer,
44
- // tag to be used to retrieve the RequestContextConfig from RPC annotations
45
- requestContext: Context.GenericTag("RequestContextConfig"),
46
- requestContextMap: rcm
47
- });
48
- };
49
- export const makeMiddleware = (rcm) => {
50
- let allMiddleware = [];
51
- const requestContext = Context.GenericTag("RequestContextConfig");
52
- const it = {
53
- // rpc with config
54
- rpc: (tag, options) => {
55
- const config = options?.config ?? {};
56
- // based on the config, we must enhance (union) or set failures.
57
- // TODO: we should only include errors that are relevant based on the middleware config.ks
58
- const error = options?.error;
59
- const errors = typedValuesOf(rcm).map((_) => _.error).filter((_) => _ && _ !== S.Never); // TODO: only the errors relevant based on config
60
- const newError = error ? S.Union(error, ...errors) : S.Union(...errors);
61
- const rpc = Rpc.make(tag, { ...options, error: newError });
62
- return Object.assign(rpc.annotate(requestContext, config), { config });
63
- },
64
- middleware: (...middlewares) => {
65
- for (const mw of middlewares) {
66
- // recall that we run middlewares in reverse order
67
- allMiddleware = [mw, ...allMiddleware];
68
- }
69
- return allMiddleware.filter((m) => !!m.dynamic).length !== Object.keys(rcm).length
70
- // for sure, until all the dynamic middlewares are provided it's non sensical to call makeMiddlewareBasic
71
- ? it
72
- // actually, we don't know yet if MiddlewareR is never, but we can't easily check it at runtime
73
- : Object.assign(makeMiddlewareBasic(rcm, ...allMiddleware), it);
74
- }
75
- };
76
- return it;
77
- };
78
- // alternatively consider group.serverMiddleware? hmmm
79
- export const middlewareGroup = (middleware) => (group) => {
80
- const middlewaredGroup = group.middleware(middleware);
81
- const toLayerOriginal = middlewaredGroup.toLayer.bind(middlewaredGroup);
82
- return Object.assign(middlewaredGroup, {
83
- toLayerDynamic: (build) => {
84
- return toLayerOriginal(build); // ??
85
- }
86
- });
87
- };
88
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlkZGxld2FyZS1hcGkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvYXBpL3JvdXRpbmcvbWlkZGxld2FyZS9taWRkbGV3YXJlLWFwaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSx1REFBdUQ7QUFDdkQsT0FBTyxFQUFFLEdBQUcsRUFBcUQsTUFBTSxhQUFhLENBQUE7QUFHcEYsT0FBTyxFQUFFLEdBQUcsRUFBRSxNQUFNLDJCQUEyQixDQUFBO0FBQy9DLE9BQU8sRUFBRSxPQUFPLEVBQWUsS0FBSyxFQUFrRCxDQUFDLEVBQXdDLE1BQU0sWUFBWSxDQUFBO0FBRWpKLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQTtBQUdoRCxPQUFPLEVBQXdCLGVBQWUsRUFBMEIsTUFBTSx5QkFBeUIsQ0FBQTtBQUd2RyxnRkFBZ0Y7QUFDaEYsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHLENBR3hCLEdBQXNCLEVBQUUsR0FBUSxFQUEyQyxFQUFFLENBQUMsQ0FBQztJQUMvRSxHQUFHO0lBQ0gsUUFBUSxFQUFFLEVBQUUsT0FBTyxFQUFFLEdBQUcsQ0FBQyxHQUFHLENBQUUsQ0FBQyxTQUFTLENBQUMsRUFBNEI7Q0FDdEUsQ0FBQyxDQUFBO0FBRUYsTUFBTSxHQUFHLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxzQkFB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BQUMsTUFBTSxlQUFlLEdBQUcsQ0FPN0IsVUFBc0IsRUFDdEIsRUFBRSxDQUNKLENBQW9CLEtBQTJCLEVBQUUsRUFBRTtJQUVqRCxNQUFNLGdCQUFnQixHQUFHLEtBQUssQ0FBQyxVQUFVLENBQUMsVUFBVSxDQUFxQyxDQUFBO0lBQ3pGLE1BQU0sZUFBZSxHQUFHLGdCQUFnQixDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsQ0FBQTtJQUN2RSxPQUFPLE1BQU0sQ0FBQyxNQUFNLENBQUMsZ0JBQWdCLEVBQUU7UUFDckMsY0FBYyxFQUFFLENBS2QsS0FFbUMsRUFNbkMsRUFBRTtZQUNGLE9BQU8sZUFBZSxDQUFDLEtBQVksQ0FBUSxDQUFBLENBQUMsS0FBSztRQUNuRCxDQUFDO0tBQ0YsQ0FBQyxDQUFBO0FBQ0osQ0FBQyxDQUFBIn0=
@@ -1,23 +0,0 @@
1
- import { RpcMiddleware } from "@effect/rpc";
2
- import { Context } from "effect-app";
3
- declare const DevMode_base: Context.ReferenceClass<DevMode, "DevMode", boolean>;
4
- export declare class DevMode extends DevMode_base {
5
- }
6
- declare const RequestCacheMiddleware_base: RpcMiddleware.TagClass<RequestCacheMiddleware, "RequestCacheMiddleware", {
7
- readonly wrap: true;
8
- }>;
9
- export declare class RequestCacheMiddleware extends RequestCacheMiddleware_base {
10
- }
11
- declare const ConfigureInterruptibilityMiddleware_base: RpcMiddleware.TagClass<ConfigureInterruptibilityMiddleware, "ConfigureInterruptibilityMiddleware", {
12
- readonly wrap: true;
13
- }>;
14
- export declare class ConfigureInterruptibilityMiddleware extends ConfigureInterruptibilityMiddleware_base {
15
- }
16
- declare const LoggerMiddleware_base: RpcMiddleware.TagClass<LoggerMiddleware, "LoggerMiddleware", {
17
- readonly wrap: true;
18
- }>;
19
- export declare class LoggerMiddleware extends LoggerMiddleware_base {
20
- }
21
- export declare const DefaultGenericMiddlewares: readonly [typeof RequestCacheMiddleware, typeof ConfigureInterruptibilityMiddleware, typeof LoggerMiddleware];
22
- export {};
23
- //# sourceMappingURL=middleware-native.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"middleware-native.d.ts","sourceRoot":"","sources":["../../../../src/api/routing/middleware/middleware-native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;;AAEpC,qBAAa,OAAQ,SAAQ,YAAsE;CAAG;;;;AAEtG,qBAAa,sBACX,SAAQ,2BAAqF;CAC7F;;;;AAEF,qBAAa,mCACX,SAAQ,wCAEN;CACF;;;;AAEF,qBAAa,gBAAiB,SAAQ,qBAAyE;CAAG;AAElH,eAAO,MAAM,yBAAyB,+GAI5B,CAAA"}
@@ -1,19 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { RpcMiddleware } from "@effect/rpc";
3
- import { Context } from "effect-app";
4
- export class DevMode extends Context.Reference()("DevMode", { defaultValue: () => false }) {
5
- }
6
- export class RequestCacheMiddleware extends RpcMiddleware.Tag()("RequestCacheMiddleware", { wrap: true }) {
7
- }
8
- export class ConfigureInterruptibilityMiddleware extends RpcMiddleware.Tag()("ConfigureInterruptibilityMiddleware", {
9
- wrap: true
10
- }) {
11
- }
12
- export class LoggerMiddleware extends RpcMiddleware.Tag()("LoggerMiddleware", { wrap: true }) {
13
- }
14
- export const DefaultGenericMiddlewares = [
15
- RequestCacheMiddleware,
16
- ConfigureInterruptibilityMiddleware,
17
- LoggerMiddleware
18
- ];
19
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlkZGxld2FyZS1uYXRpdmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvYXBpL3JvdXRpbmcvbWlkZGxld2FyZS9taWRkbGV3YXJlLW5hdGl2ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSx1REFBdUQ7QUFDdkQsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLGFBQWEsQ0FBQTtBQUMzQyxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sWUFBWSxDQUFBO0FBRXBDLE1BQU0sT0FBTyxPQUFRLFNBQVEsT0FBTyxDQUFDLFNBQVMsRUFBVyxDQUFDLFNBQVMsRUFBRSxFQUFFLFlBQVksRUFBRSxHQUFHLEVBQUUsQ0FBQyxLQUFLLEVBQUUsQ0FBQztDQUFHO0FBRXRHLE1BQU0sT0FBTyxzQkFDWCxTQUFRLGFBQWEsQ0FBQyxHQUFHLEVBQTBCLENBQUMsd0JBQXdCLEVBQUUsRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLENBQUM7Q0FDN0Y7QUFFRixNQUFNLE9BQU8sbUNBQ1gsU0FBUSxhQUFhLENBQUMsR0FBRyxFQUF1QyxDQUFDLHFDQUFxQyxFQUFFO0lBQ3RHLElBQUksRUFBRSxJQUFJO0NBQ1gsQ0FBQztDQUNGO0FBRUYsTUFBTSxPQUFPLGdCQUFpQixTQUFRLGFBQWEsQ0FBQyxHQUFHLEVBQW9CLENBQUMsa0JBQWtCLEVBQUUsRUFBRSxJQUFJLEVBQUUsSUFBSSxFQUFFLENBQUM7Q0FBRztBQUVsSCxNQUFNLENBQUMsTUFBTSx5QkFBeUIsR0FBRztJQUN2QyxzQkFBc0I7SUFDdEIsbUNBQW1DO0lBQ25DLGdCQUFnQjtDQUNSLENBQUEifQ==
@@ -1,254 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
2
- /* eslint-disable @typescript-eslint/no-unsafe-return */
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
- import { type Rpc, RpcMiddleware } from "@effect/rpc"
5
- import { type SuccessValue, type TypeId } from "@effect/rpc/RpcMiddleware"
6
- import { type Context, type Effect, type NonEmptyReadonlyArray, type Option, type S, type Schema, type Scope, Unify } from "effect-app"
7
- import type { AnyService, ContextTagArray, RPCContextMap } from "effect-app/client/req"
8
- import { type HttpHeaders } from "effect-app/http"
9
- import { type TagUnify, type TagUnifyIgnore } from "effect/Context"
10
-
11
- // updated to support Scope.Scope and Requires
12
- export interface RpcMiddleware<Provides, E, Requires> {
13
- (options: {
14
- readonly clientId: number
15
- readonly rpc: Rpc.AnyWithProps
16
- readonly payload: unknown
17
- readonly headers: HttpHeaders.Headers
18
- }): Effect.Effect<Provides, E, Scope.Scope | Requires>
19
- }
20
- export interface RpcMiddlewareWrap<Provides, E, Requires> {
21
- (options: {
22
- readonly clientId: number
23
- readonly rpc: Rpc.AnyWithProps
24
- readonly payload: unknown
25
- readonly headers: HttpHeaders.Headers
26
- readonly next: Effect.Effect<SuccessValue, E, Provides | Scope.Scope | Requires>
27
- }): Effect.Effect<SuccessValue, E, Scope.Scope | Requires>
28
- }
29
-
30
- export type RpcOptionsOriginal = {
31
- readonly wrap?: boolean
32
- readonly optional?: boolean
33
- readonly failure?: Schema.Schema.All
34
- readonly provides?: AnyService
35
- readonly requiredForClient?: boolean
36
- }
37
-
38
- export type RpcDynamic<Key extends string, A extends RPCContextMap.Any> = {
39
- key: Key
40
- settings: A
41
- }
42
-
43
- export type AnyDynamic = { dynamic: RpcDynamic<any, any> }
44
-
45
- export type DependsOn = {
46
- readonly dependsOn: NonEmptyReadonlyArray<AnyDynamic> | undefined
47
- }
48
-
49
- export interface RpcOptionsDynamic<Key extends string, A extends RPCContextMap.Any> extends RpcOptionsOriginal {
50
- readonly dynamic: RpcDynamic<Key, A>
51
- readonly dependsOn?: NonEmptyReadonlyArray<AnyDynamic> | undefined
52
- }
53
-
54
- export type Dynamic<Options> = Options extends RpcOptionsDynamic<any, any> ? true : false
55
-
56
- export interface RpcMiddlewareDynamicWrap<E, R, _Config> {
57
- (options: {
58
- readonly next: Effect.Effect<SuccessValue, E, Scope.Scope | R>
59
- readonly clientId: number
60
- readonly rpc: Rpc.AnyWithProps // TODO & { annotations: Context.Context<RequestContextMap<Config>> }
61
- readonly payload: unknown
62
- readonly headers: HttpHeaders.Headers
63
- }): Effect.Effect<
64
- SuccessValue,
65
- E,
66
- Scope.Scope | R
67
- >
68
- }
69
-
70
- export interface RpcMiddlewareDynamicNormal<A, E, R, _Config> {
71
- (options: {
72
- readonly clientId: number
73
- readonly rpc: Rpc.AnyWithProps // TODO & { annotations: Context.Context<RequestContextMap<Config>> }
74
- readonly payload: unknown
75
- readonly headers: HttpHeaders.Headers
76
- }): Effect.Effect<
77
- Option.Option<A>,
78
- E,
79
- Scope.Scope | R
80
- >
81
- }
82
-
83
- export interface TagClassAny extends Context.Tag<any, any> {
84
- readonly [TypeId]: TypeId
85
- readonly optional: boolean
86
- readonly provides?: Context.Tag<any, any> | ContextTagArray | undefined
87
- readonly requires?: Context.Tag<any, any> | ContextTagArray | undefined
88
- readonly failure: Schema.Schema.All
89
- readonly requiredForClient: boolean
90
- readonly wrap: boolean
91
- readonly dynamic?: RpcDynamic<any, any> | undefined
92
- readonly dependsOn?: NonEmptyReadonlyArray<AnyDynamic> | undefined
93
- }
94
-
95
- export declare namespace TagClass {
96
- /**
97
- * @since 1.0.0
98
- * @category models
99
- */
100
- export type Provides<Options> = Options extends {
101
- readonly provides: Context.Tag<any, any>
102
- readonly optional?: false
103
- } ? Context.Tag.Identifier<Options["provides"]>
104
- : Options extends {
105
- readonly provides: ContextTagArray
106
- readonly optional?: false
107
- } ? ContextTagArray.Identifier<Options["provides"]>
108
- : never
109
-
110
- /**
111
- * @since 1.0.0
112
- * @category models
113
- */
114
- export type Requires<Options> = Options extends {
115
- readonly requires: Context.Tag<any, any>
116
- } ? Context.Tag.Identifier<Options["requires"]>
117
- : Options extends {
118
- readonly requires: ContextTagArray
119
- } ? ContextTagArray.Identifier<Options["requires"]>
120
- : never
121
-
122
- /**
123
- * @since 1.0.0
124
- * @category models
125
- */
126
- export type Service<Options> = Options extends { readonly provides: Context.Tag<any, any> }
127
- ? Context.Tag.Service<Options["provides"]>
128
- : Options extends { readonly dynamic: RpcDynamic<any, infer A> }
129
- ? Options extends { wrap: true } ? void : AnyService.Bla<A["service"]>
130
- : Options extends { readonly provides: ContextTagArray }
131
- ? Context.Context<ContextTagArray.Identifier<Options["provides"]>>
132
- : void
133
-
134
- /**
135
- * @since 1.0.0
136
- * @category models
137
- */
138
- export type FailureSchema<Options> = Options extends
139
- { readonly failure: Schema.Schema.All; readonly optional?: false } ? Options["failure"]
140
- // actually not, the Failure depends on Dynamic Middleware Configuration!
141
- // : Options extends { readonly dynamic: RpcDynamic<any, infer A> } ? A["error"]
142
- : typeof Schema.Never
143
-
144
- /**
145
- * @since 1.0.0
146
- * @category models
147
- */
148
- export type Failure<Options> = Options extends
149
- { readonly failure: Schema.Schema<infer _A, infer _I, infer _R>; readonly optional?: false } ? _A
150
- // actually not, the Failure depends on Dynamic Middleware Configuration!
151
- : Options extends { readonly dynamic: RpcDynamic<any, infer A> } ? S.Schema.Type<A["error"]>
152
- : never
153
-
154
- /**
155
- * @since 1.0.0
156
- * @category models
157
- */
158
- export type FailureContext<Options> = Schema.Schema.Context<FailureSchema<Options>>
159
-
160
- /**
161
- * @since 1.0.0
162
- * @category models
163
- */
164
- export type FailureService<Options> = Optional<Options> extends true ? unknown : Failure<Options>
165
-
166
- /**
167
- * @since 1.0.0
168
- * @category models
169
- */
170
- export type Optional<Options> = Options extends { readonly optional: true } ? true : false
171
-
172
- /**
173
- * @since 1.0.0
174
- * @category models
175
- */
176
- export type RequiredForClient<Options> = Options extends { readonly requiredForClient: true } ? true : false
177
-
178
- /**
179
- * @since 1.0.0
180
- * @category models
181
- */
182
- export type Wrap<Options> = Options extends { readonly wrap: true } ? true : false
183
-
184
- /**
185
- * @since 1.0.0
186
- * @category models
187
- */
188
- export interface Base<Self, Name extends string, Options, Service> extends Context.Tag<Self, Service> {
189
- new(_: never): Context.TagClassShape<Name, Service>
190
- readonly [TypeId]: TypeId
191
- readonly optional: Optional<Options>
192
- readonly failure: FailureSchema<Options>
193
- readonly provides: Options extends { readonly provides: Context.Tag<any, any> } ? Options["provides"]
194
- : Options extends { readonly provides: ContextTagArray } ? Options["provides"]
195
- : undefined
196
- readonly requires: Options extends { readonly requires: Context.Tag<any, any> } ? Options["requires"]
197
- : Options extends { readonly requires: ContextTagArray } ? Options["requires"]
198
- : undefined
199
- readonly dynamic: Options extends RpcOptionsDynamic<any, any> ? Options["dynamic"]
200
- : undefined
201
- readonly dependsOn: Options extends DependsOn ? Options["dependsOn"] : undefined
202
- readonly requiredForClient: RequiredForClient<Options>
203
- readonly wrap: Wrap<Options>
204
- }
205
- }
206
-
207
- export interface TagClass<
208
- Self,
209
- Name extends string,
210
- Options
211
- > extends
212
- TagClass.Base<
213
- Self,
214
- Name,
215
- Options,
216
- Options extends RpcOptionsDynamic<any, any> ? TagClass.Wrap<Options> extends true ? RpcMiddlewareDynamicWrap<
217
- TagClass.FailureService<Options>,
218
- TagClass.Requires<Options>,
219
- { [K in Options["dynamic"]["key"]]?: Options["dynamic"]["settings"]["contextActivation"] }
220
- >
221
- : RpcMiddlewareDynamicNormal<
222
- TagClass.Service<Options>,
223
- TagClass.FailureService<Options>,
224
- TagClass.Requires<Options>,
225
- { [K in Options["dynamic"]["key"]]?: Options["dynamic"]["settings"]["contextActivation"] }
226
- >
227
- : TagClass.Wrap<Options> extends true ? RpcMiddlewareWrap<
228
- TagClass.Provides<Options>,
229
- TagClass.Failure<Options>,
230
- TagClass.Requires<Options>
231
- >
232
- : RpcMiddleware<
233
- TagClass.Service<Options>,
234
- TagClass.FailureService<Options>,
235
- TagClass.Requires<Options>
236
- >
237
- >
238
- {}
239
-
240
- export const Tag = <Self>() =>
241
- <
242
- const Name extends string,
243
- const Options extends RpcOptionsOriginal | RpcOptionsDynamic<any, any>
244
- >(
245
- id: Name,
246
- options?: Options | undefined
247
- ): TagClass<Self, Name, Options> =>
248
- class extends RpcMiddleware.Tag<Self>()(id, options as any) {
249
- static readonly dynamic = options && "dynamic" in options ? options.dynamic : undefined
250
- static readonly dependsOn = options && "dependsOn" in options ? options.dependsOn : undefined
251
- static override [Unify.typeSymbol]?: unknown
252
- static override [Unify.unifySymbol]?: TagUnify<typeof this>
253
- static override [Unify.ignoreSymbol]?: TagUnifyIgnore
254
- } as any
@@ -1,70 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
2
- /* eslint-disable @typescript-eslint/no-unsafe-return */
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
- import { type Effect, Layer, type NonEmptyReadonlyArray, Unify } from "effect-app"
5
- import { type TagUnify, type TagUnifyIgnore } from "effect/Context"
6
- import { type Service } from "effect/Effect"
7
- import { type RpcMiddleware, type RpcMiddlewareDynamicNormal, type RpcMiddlewareDynamicWrap, type RpcMiddlewareWrap, type RpcOptionsDynamic, type RpcOptionsOriginal, Tag, type TagClass } from "./RpcMiddleware.js"
8
-
9
- /**
10
- * @deprecated - RPC groups are defined centrally and re-used between server and client,
11
- * so layer implementation details should not be mixed.
12
- */
13
- export const TagService = <Self>() =>
14
- <
15
- const Name extends string,
16
- const Options extends RpcOptionsOriginal | RpcOptionsDynamic<any, any>
17
- >(
18
- id: Name,
19
- options?: Options | undefined
20
- ) =>
21
- <
22
- LayerOpts extends {
23
- effect: Effect.Effect<
24
- Options extends RpcOptionsDynamic<any, any> ? TagClass.Wrap<Options> extends true ? RpcMiddlewareDynamicWrap<
25
- TagClass.FailureService<Options>,
26
- TagClass.Requires<Options>,
27
- { [K in Options["dynamic"]["key"]]?: Options["dynamic"]["settings"]["contextActivation"] }
28
- >
29
- : RpcMiddlewareDynamicNormal<
30
- TagClass.Service<Options>,
31
- TagClass.FailureService<Options>,
32
- TagClass.Requires<Options>,
33
- { [K in Options["dynamic"]["key"]]?: Options["dynamic"]["settings"]["contextActivation"] }
34
- >
35
- : TagClass.Wrap<Options> extends true ? RpcMiddlewareWrap<
36
- TagClass.Provides<Options>,
37
- TagClass.Failure<Options>,
38
- TagClass.Requires<Options>
39
- >
40
- : RpcMiddleware<
41
- TagClass.Service<Options>,
42
- TagClass.FailureService<Options>,
43
- TagClass.Requires<Options>
44
- >,
45
- any,
46
- any
47
- >
48
- dependencies?: NonEmptyReadonlyArray<Layer.Layer.Any>
49
- }
50
- >(opts: LayerOpts): TagClass<Self, Name, Options> & {
51
- Default: Layer.Layer<
52
- Self,
53
- | (LayerOpts extends { effect: Effect<infer _A, infer _E, infer _R> } ? _E
54
- : never)
55
- | Service.MakeDepsE<LayerOpts>,
56
- | Exclude<
57
- LayerOpts extends { effect: Effect<infer _A, infer _E, infer _R> } ? _R : never,
58
- Service.MakeDepsOut<LayerOpts>
59
- >
60
- | Service.MakeDepsIn<LayerOpts>
61
- >
62
- } =>
63
- class extends Tag<Self>()(id, options as any) {
64
- static readonly Default = Layer.scoped(this, opts.effect as any).pipe(
65
- Layer.provide([Layer.empty, ...opts.dependencies ?? []])
66
- )
67
- static override [Unify.typeSymbol]?: unknown
68
- static override [Unify.unifySymbol]?: TagUnify<typeof this>
69
- static override [Unify.ignoreSymbol]?: TagUnifyIgnore
70
- } as any
@@ -1,198 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { type RpcMiddleware } from "@effect/rpc"
3
- import { Context, Effect, type Layer, type NonEmptyReadonlyArray, Option, type S, type Scope } from "effect-app"
4
- import { type ContextTagArray, type GetContextConfig, type RPCContextMap } from "effect-app/client"
5
- import { type Tag } from "effect/Context"
6
- import { type Simplify } from "effect/Types"
7
- import { InfraLogger } from "../../../logger.js"
8
- import { type MakeTags, type MiddlewareMakerId } from "./middleware-api.js"
9
- import { type RpcMiddlewareWrap, type TagClassAny } from "./RpcMiddleware.js"
10
-
11
- // Effect rpc middleware does not support changing payload or headers, but we do..
12
-
13
- export interface MiddlewareMaker<
14
- RequestContextMap extends Record<string, RPCContextMap.Any>,
15
- MiddlewareProviders extends ReadonlyArray<MiddlewareMaker.Any>
16
- > extends
17
- RpcMiddleware.TagClass<
18
- MiddlewareMakerId,
19
- "MiddlewareMaker",
20
- Simplify<
21
- & { readonly wrap: true }
22
- & (Exclude<
23
- MiddlewareMaker.ManyRequired<MiddlewareProviders>,
24
- MiddlewareMaker.ManyProvided<MiddlewareProviders>
25
- > extends never ? {} : {
26
- readonly requires: MakeTags<
27
- Exclude<
28
- MiddlewareMaker.ManyRequired<MiddlewareProviders>,
29
- MiddlewareMaker.ManyProvided<MiddlewareProviders>
30
- >
31
- >
32
- })
33
- & (MiddlewareMaker.ManyErrors<MiddlewareProviders> extends never ? {}
34
- : {
35
- readonly failure: S.Schema<MiddlewareMaker.ManyErrors<MiddlewareProviders>>
36
- })
37
- & (MiddlewareMaker.ManyProvided<MiddlewareProviders> extends never ? {}
38
- : { readonly provides: MakeTags<MiddlewareMaker.ManyProvided<MiddlewareProviders>> })
39
- >
40
- >
41
- {
42
- readonly layer: Layer.Layer<MiddlewareMakerId, never, Tag.Identifier<MiddlewareProviders[number]>>
43
- readonly requestContext: RequestContextTag<RequestContextMap>
44
- readonly requestContextMap: RequestContextMap
45
- }
46
-
47
- export interface RequestContextTag<RequestContextMap extends Record<string, RPCContextMap.Any>>
48
- extends Context.Tag<"RequestContextConfig", GetContextConfig<RequestContextMap>>
49
- {}
50
-
51
- export namespace MiddlewareMaker {
52
- export type Any = TagClassAny
53
-
54
- export type ApplyServices<A extends TagClassAny, R> = Exclude<R, Provided<A>> | Required<A>
55
-
56
- export type ApplyManyServices<A extends NonEmptyReadonlyArray<TagClassAny>, R> =
57
- | Exclude<R, { [K in keyof A]: Provided<A[K]> }[number]>
58
- | { [K in keyof A]: Required<A[K]> }[number]
59
-
60
- export type ManyProvided<A extends ReadonlyArray<TagClassAny>> = A extends NonEmptyReadonlyArray<TagClassAny>
61
- ? { [K in keyof A]: Provided<A[K]> }[number]
62
- : Provided<A[number]>
63
- export type ManyRequired<A extends ReadonlyArray<TagClassAny>> = A extends NonEmptyReadonlyArray<TagClassAny>
64
- ? { [K in keyof A]: Required<A[K]> }[number]
65
- : Required<A[number]>
66
- export type ManyErrors<A extends ReadonlyArray<TagClassAny>> = A extends NonEmptyReadonlyArray<TagClassAny>
67
- ? { [K in keyof A]: Errors<A[K]> }[number]
68
- : Errors<A[number]>
69
-
70
- export type Provided<T> = T extends TagClassAny
71
- ? T extends { provides: Context.Tag<any, any> } ? Context.Tag.Identifier<T["provides"]>
72
- : T extends { provides: ContextTagArray } ? ContextTagArray.Identifier<T["provides"]>
73
- : never
74
- : never
75
-
76
- export type Errors<T> = T extends TagClassAny ? T extends { failure: S.Schema.Any } ? S.Schema.Type<T["failure"]>
77
- : never
78
- : never
79
-
80
- export type Required<T> = T extends TagClassAny
81
- ? T extends { requires: Context.Tag<any, any> } ? Context.Tag.Identifier<T["requires"]>
82
- : T extends { requires: ContextTagArray } ? ContextTagArray.Identifier<T["requires"]>
83
- : never
84
- : never
85
- }
86
-
87
- export const middlewareMaker = <
88
- MiddlewareProviders extends ReadonlyArray<MiddlewareMaker.Any>
89
- >(middlewares: MiddlewareProviders): Effect.Effect<
90
- RpcMiddlewareWrap<
91
- MiddlewareMaker.ManyProvided<MiddlewareProviders>,
92
- MiddlewareMaker.ManyErrors<MiddlewareProviders>,
93
- Exclude<
94
- MiddlewareMaker.ManyRequired<MiddlewareProviders>,
95
- MiddlewareMaker.ManyProvided<MiddlewareProviders>
96
- > extends never ? never
97
- : Exclude<MiddlewareMaker.ManyRequired<MiddlewareProviders>, MiddlewareMaker.ManyProvided<MiddlewareProviders>>
98
- >
99
- > => {
100
- // we want to run them in reverse order because latter middlewares will provide context to former ones
101
- middlewares = middlewares.toReversed() as any
102
-
103
- return Effect.gen(function*() {
104
- const context = yield* Effect.context()
105
-
106
- // returns a Effect/RpcMiddlewareWrap with Scope in requirements
107
- return (
108
- options: Parameters<
109
- RpcMiddlewareWrap<
110
- MiddlewareMaker.ManyProvided<MiddlewareProviders>,
111
- never,
112
- Scope.Scope
113
- >
114
- >[0]
115
- ) => {
116
- // we start with the actual handler
117
- let handler = options.next
118
-
119
- // inspired from Effect/RpcMiddleware
120
- for (const tag of middlewares) {
121
- if (tag.wrap) {
122
- // use the tag to get the middleware from context
123
- const middleware = Context.unsafeGet(context, tag)
124
-
125
- // wrap the current handler, allowing the middleware to run before and after it
126
- handler = InfraLogger.logDebug("Applying middleware wrap " + tag.key).pipe(
127
- Effect.zipRight(middleware({ ...options, next: handler }))
128
- ) as any
129
- } else if (tag.optional) {
130
- // use the tag to get the middleware from context
131
- // if the middleware fails to run, we will ignore the error
132
- const middleware = Context.unsafeGet(context, tag) as RpcMiddleware.RpcMiddleware<any, any>
133
-
134
- const previous = handler
135
-
136
- // set the previous handler to run after the middleware
137
- // if the middleware is not present, we just return the previous handler
138
- // otherwise the middleware will provide some context to be provided to the previous handler
139
- handler = InfraLogger.logDebug("Applying middleware optional " + tag.key).pipe(
140
- Effect.zipRight(Effect.matchEffect(middleware(options), {
141
- onFailure: () => previous,
142
- onSuccess: tag.provides !== undefined
143
- ? (value) =>
144
- Context.isContext(value)
145
- ? Effect.provide(previous, value)
146
- : Effect.provideService(previous, tag.provides as any, value)
147
- : (_) => previous
148
- }))
149
- )
150
- } else if (tag.dynamic) {
151
- // use the tag to get the middleware from context
152
- const middleware = Context.unsafeGet(context, tag) as RpcMiddleware.RpcMiddleware<any, any>
153
-
154
- const previous = handler
155
-
156
- // set the previous handler to run after the middleware
157
- // we do expect the middleware to be present, but the context might not be available
158
- // if it is, we provide it to the previous handler
159
- handler = InfraLogger.logDebug("Applying middleware dynamic " + tag.key, tag.dynamic).pipe(
160
- Effect.zipRight(
161
- middleware(options).pipe(
162
- Effect.flatMap((o) =>
163
- Option.isSome(o)
164
- ? Context.isContext(o.value)
165
- ? Effect.provide(previous, o.value)
166
- : Effect.provideService(previous, tag.dynamic!.settings.service!, /* TODO */ o.value)
167
- : previous
168
- )
169
- )
170
- )
171
- ) as any
172
- } else {
173
- // use the tag to get the middleware from context
174
- const middleware = Context.unsafeGet(context, tag) as RpcMiddleware.RpcMiddleware<any, any>
175
-
176
- const previous = handler
177
-
178
- // set the previous handler to run after the middleware
179
- // we do expect both the middleware and the context to be present
180
- handler = InfraLogger.logDebug("Applying middleware " + tag.key).pipe(
181
- Effect.zipRight(
182
- tag.provides !== undefined
183
- ? middleware(options).pipe(
184
- Effect.flatMap((value) =>
185
- Context.isContext(value)
186
- ? Effect.provide(previous, value)
187
- : Effect.provideService(previous, tag.provides as any, value)
188
- )
189
- )
190
- : Effect.zipRight(middleware(options), previous)
191
- )
192
- ) as any
193
- }
194
- }
195
- return handler
196
- }
197
- }) as any
198
- }