effect-app 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.
- package/CHANGELOG.md +6 -0
- package/dist/TypeTest.d.ts +3 -0
- package/dist/TypeTest.d.ts.map +1 -0
- package/dist/TypeTest.js +7 -0
- package/dist/rpc/RpcMiddleware.d.ts +188 -0
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -0
- package/dist/rpc/RpcMiddleware.js +13 -0
- package/dist/rpc/RpcMiddlewareX.d.ts +18 -0
- package/dist/rpc/RpcMiddlewareX.d.ts.map +1 -0
- package/dist/rpc/RpcMiddlewareX.js +16 -0
- package/dist/rpc/generic-middleware.d.ts +55 -0
- package/dist/rpc/generic-middleware.d.ts.map +1 -0
- package/dist/rpc/generic-middleware.js +67 -0
- package/dist/rpc/middleware-api.d.ts +107 -0
- package/dist/rpc/middleware-api.d.ts.map +1 -0
- package/dist/rpc/middleware-api.js +88 -0
- package/dist/rpc/middleware-native.d.ts +23 -0
- package/dist/rpc/middleware-native.d.ts.map +1 -0
- package/dist/rpc/middleware-native.js +19 -0
- package/dist/rpc.d.ts +7 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +9 -0
- package/package.json +29 -1
- package/src/TypeTest.ts +7 -0
- package/src/rpc/RpcMiddleware.ts +254 -0
- package/src/rpc/RpcMiddlewareX.ts +70 -0
- package/src/rpc/generic-middleware.ts +198 -0
- package/src/rpc/middleware-api.ts +404 -0
- package/src/rpc/middleware-native.ts +23 -0
- package/src/rpc.ts +9 -0
|
@@ -0,0 +1,88 @@
|
|
|
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
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LFVBQVUsQ0FBQyxVQUFVLENBQXFDLENBQUE7SUFDekYsTUFBTSxlQUFlLEdBQUcsZ0JBQWdCLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFBO0lBQ3ZFLE9BQU8sTUFBTSxDQUFDLE1BQU0sQ0FBQyxnQkFBZ0IsRUFBRTtRQUNyQyxjQUFjLEVBQUUsQ0FLZCxLQUVtQyxFQU1uQyxFQUFFO1lBQ0YsT0FBTyxlQUFlLENBQUMsS0FBWSxDQUFRLENBQUEsQ0FBQyxLQUFLO1FBQ25ELENBQUM7S0FDRixDQUFDLENBQUE7QUFDSixDQUFDLENBQUEifQ==
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-native.d.ts","sourceRoot":"","sources":["../../src/rpc/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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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=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-middleware.js";
|
|
2
|
+
export * from "./rpc/middleware-api.js";
|
|
3
|
+
export * from "./rpc/middleware-native.js";
|
|
4
|
+
export * from "./rpc/RpcMiddleware.js";
|
|
5
|
+
export * from "./rpc/RpcMiddlewareX.js";
|
|
6
|
+
export * as Middleware from "./rpc.js";
|
|
7
|
+
//# sourceMappingURL=rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AACA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,yBAAyB,CAAA;AACvC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AAGvC,OAAO,KAAK,UAAU,MAAM,UAAU,CAAA"}
|
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// codegen:start {preset: barrel, include: ./rpc/*.ts, nodir: false }
|
|
2
|
+
export * from "./rpc/generic-middleware.js";
|
|
3
|
+
export * from "./rpc/middleware-api.js";
|
|
4
|
+
export * from "./rpc/middleware-native.js";
|
|
5
|
+
export * from "./rpc/RpcMiddleware.js";
|
|
6
|
+
export * from "./rpc/RpcMiddlewareX.js";
|
|
7
|
+
// codegen:end
|
|
8
|
+
export * as Middleware from "./rpc.js";
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicnBjLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3JwYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxxRUFBcUU7QUFDckUsY0FBYyw2QkFBNkIsQ0FBQTtBQUMzQyxjQUFjLHlCQUF5QixDQUFBO0FBQ3ZDLGNBQWMsNEJBQTRCLENBQUE7QUFDMUMsY0FBYyx3QkFBd0IsQ0FBQTtBQUN0QyxjQUFjLHlCQUF5QixDQUFBO0FBQ3ZDLGNBQWM7QUFFZCxPQUFPLEtBQUssVUFBVSxNQUFNLFVBQVUsQ0FBQSJ9
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-app",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
@@ -144,6 +144,10 @@
|
|
|
144
144
|
"types": "./dist/Tag.d.ts",
|
|
145
145
|
"default": "./dist/Tag.js"
|
|
146
146
|
},
|
|
147
|
+
"./TypeTest": {
|
|
148
|
+
"types": "./dist/TypeTest.d.ts",
|
|
149
|
+
"default": "./dist/TypeTest.js"
|
|
150
|
+
},
|
|
147
151
|
"./Types": {
|
|
148
152
|
"types": "./dist/Types.d.ts",
|
|
149
153
|
"default": "./dist/Types.js"
|
|
@@ -216,6 +220,30 @@
|
|
|
216
220
|
"types": "./dist/logger.d.ts",
|
|
217
221
|
"default": "./dist/logger.js"
|
|
218
222
|
},
|
|
223
|
+
"./rpc": {
|
|
224
|
+
"types": "./dist/rpc.d.ts",
|
|
225
|
+
"default": "./dist/rpc.js"
|
|
226
|
+
},
|
|
227
|
+
"./rpc/RpcMiddleware": {
|
|
228
|
+
"types": "./dist/rpc/RpcMiddleware.d.ts",
|
|
229
|
+
"default": "./dist/rpc/RpcMiddleware.js"
|
|
230
|
+
},
|
|
231
|
+
"./rpc/RpcMiddlewareX": {
|
|
232
|
+
"types": "./dist/rpc/RpcMiddlewareX.d.ts",
|
|
233
|
+
"default": "./dist/rpc/RpcMiddlewareX.js"
|
|
234
|
+
},
|
|
235
|
+
"./rpc/generic-middleware": {
|
|
236
|
+
"types": "./dist/rpc/generic-middleware.d.ts",
|
|
237
|
+
"default": "./dist/rpc/generic-middleware.js"
|
|
238
|
+
},
|
|
239
|
+
"./rpc/middleware-api": {
|
|
240
|
+
"types": "./dist/rpc/middleware-api.d.ts",
|
|
241
|
+
"default": "./dist/rpc/middleware-api.js"
|
|
242
|
+
},
|
|
243
|
+
"./rpc/middleware-native": {
|
|
244
|
+
"types": "./dist/rpc/middleware-native.d.ts",
|
|
245
|
+
"default": "./dist/rpc/middleware-native.js"
|
|
246
|
+
},
|
|
219
247
|
"./transform": {
|
|
220
248
|
"types": "./dist/transform.d.ts",
|
|
221
249
|
"default": "./dist/transform.js"
|
package/src/TypeTest.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Nice way to underline types that are only there for type testing, not for production use
|
|
2
|
+
// sadly with unique symbols we get weird issues in app projects.
|
|
3
|
+
// api/src/X/PackList.Controllers.ts:21:1 - error TS4082: Default export of the module has or is using private name 'TypeTestId'
|
|
4
|
+
// export const TypeTestId: unique symbol = Symbol.for("@effect/infra/type-test")
|
|
5
|
+
// export type TypeTestId = typeof TypeTestId
|
|
6
|
+
export const TypeTestId = "effect-app/type-test" as const
|
|
7
|
+
export type TypeTestId = typeof TypeTestId
|
|
@@ -0,0 +1,254 @@
|
|
|
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
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|