effect-app 3.0.2 → 3.0.4
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 +12 -0
- package/dist/Context.d.ts +23 -2
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +6 -1
- package/dist/Layer.d.ts +35 -0
- package/dist/Layer.d.ts.map +1 -0
- package/dist/Layer.js +16 -0
- package/dist/NonEmptySet.d.ts +1 -1
- package/dist/client/apiClientFactory.d.ts +2 -18
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/makeClient.d.ts +58 -0
- package/dist/client/makeClient.d.ts.map +1 -0
- package/dist/client/makeClient.js +36 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -2
- package/dist/internal/Prelude.d.ts +2 -2
- package/dist/internal/Prelude.js +1 -1
- package/dist/{rpc/middleware-native.d.ts → middleware.d.ts} +5 -4
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +17 -0
- package/dist/rpc/{middleware-api.d.ts → MiddlewareMaker.d.ts} +64 -45
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -0
- package/dist/rpc/MiddlewareMaker.js +99 -0
- package/dist/rpc/RpcContextMap.d.ts +73 -0
- package/dist/rpc/RpcContextMap.d.ts.map +1 -0
- package/dist/rpc/RpcContextMap.js +33 -0
- package/dist/rpc/RpcMiddleware.d.ts +30 -37
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js +2 -2
- package/dist/rpc.d.ts +2 -4
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +3 -5
- package/dist/utils/gen.d.ts +8 -0
- package/dist/utils/gen.d.ts.map +1 -0
- package/dist/utils/gen.js +2 -0
- package/dist/utils.d.ts +0 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +30 -24
- package/src/Context.ts +56 -0
- package/src/Layer.ts +60 -0
- package/src/client/makeClient.ts +150 -0
- package/src/client.ts +1 -1
- package/src/internal/Prelude.d.ts +2 -2
- package/src/internal/Prelude.js +1 -1
- package/src/{rpc/middleware-native.ts → middleware.ts} +4 -4
- package/src/rpc/{middleware-api.ts → MiddlewareMaker.ts} +170 -139
- package/src/rpc/README.md +41 -0
- package/src/rpc/RpcContextMap.ts +163 -0
- package/src/rpc/RpcMiddleware.ts +83 -43
- package/src/rpc.ts +2 -4
- package/src/utils/gen.ts +22 -0
- package/src/utils.ts +0 -2
- package/test/rpc.test.ts +1 -1
- package/dist/client/req.d.ts +0 -120
- package/dist/client/req.d.ts.map +0 -1
- package/dist/client/req.js +0 -56
- package/dist/rpc/RpcMiddlewareX.d.ts +0 -24
- package/dist/rpc/RpcMiddlewareX.d.ts.map +0 -1
- package/dist/rpc/RpcMiddlewareX.js +0 -16
- package/dist/rpc/generic-middleware.d.ts +0 -51
- package/dist/rpc/generic-middleware.d.ts.map +0 -1
- package/dist/rpc/generic-middleware.js +0 -24
- package/dist/rpc/middleware-api.d.ts.map +0 -1
- package/dist/rpc/middleware-api.js +0 -88
- package/dist/rpc/middleware-native.d.ts.map +0 -1
- package/dist/rpc/middleware-native.js +0 -17
- package/src/client/req.ts +0 -288
- package/src/rpc/RpcMiddlewareX.ts +0 -65
- package/src/rpc/generic-middleware.ts +0 -128
- package/wallaby.cjs +0 -1
|
@@ -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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0IsQ0FBQyxDQUFBO0lBQ3ZFLE9BQU8sTUFBTSxDQUFDLE1BQU0sQ0FBQyxnQkFBZ0IsRUFBRTtRQUNyQyxjQUFjLEVBQUUsQ0FLZCxLQUVtQyxFQU1uQyxFQUFFO1lBQ0YsT0FBTyxlQUFlLENBQUMsS0FBWSxDQUFRLENBQUEsQ0FBQyxLQUFLO1FBQ25ELENBQUM7S0FDRixDQUFDLENBQUE7QUFDSixDQUFDLENBQUEifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware-native.d.ts","sourceRoot":"","sources":["../../src/rpc/middleware-native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;;AAGpC,qBAAa,OAAQ,SAAQ,YAAsE;CAAG;;;;;AAEtG,qBAAa,sBAAuB,SAAQ,2BAA2D;CAAG;;;;;AAE1G,qBAAa,mCACX,SAAQ,wCAAqF;CAC7F;;;;;AAEF,qBAAa,gBAAiB,SAAQ,qBAA+C;CAAG;AAExF,eAAO,MAAM,yBAAyB,+GAI5B,CAAA"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { Context } from "effect-app";
|
|
3
|
-
import { Tag } from "./RpcMiddleware.js";
|
|
4
|
-
export class DevMode extends Context.Reference()("DevMode", { defaultValue: () => false }) {
|
|
5
|
-
}
|
|
6
|
-
export class RequestCacheMiddleware extends Tag()("RequestCacheMiddleware", {}) {
|
|
7
|
-
}
|
|
8
|
-
export class ConfigureInterruptibilityMiddleware extends Tag()("ConfigureInterruptibilityMiddleware", {}) {
|
|
9
|
-
}
|
|
10
|
-
export class LoggerMiddleware extends Tag()("LoggerMiddleware", {}) {
|
|
11
|
-
}
|
|
12
|
-
export const DefaultGenericMiddlewares = [
|
|
13
|
-
RequestCacheMiddleware,
|
|
14
|
-
ConfigureInterruptibilityMiddleware,
|
|
15
|
-
LoggerMiddleware
|
|
16
|
-
];
|
|
17
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlkZGxld2FyZS1uYXRpdmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcnBjL21pZGRsZXdhcmUtbmF0aXZlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLHVEQUF1RDtBQUN2RCxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sWUFBWSxDQUFBO0FBQ3BDLE9BQU8sRUFBRSxHQUFHLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQTtBQUV4QyxNQUFNLE9BQU8sT0FBUSxTQUFRLE9BQU8sQ0FBQyxTQUFTLEVBQVcsQ0FBQyxTQUFTLEVBQUUsRUFBRSxZQUFZLEVBQUUsR0FBRyxFQUFFLENBQUMsS0FBSyxFQUFFLENBQUM7Q0FBRztBQUV0RyxNQUFNLE9BQU8sc0JBQXVCLFNBQVEsR0FBRyxFQUEwQixDQUFDLHdCQUF3QixFQUFFLEVBQUUsQ0FBQztDQUFHO0FBRTFHLE1BQU0sT0FBTyxtQ0FDWCxTQUFRLEdBQUcsRUFBdUMsQ0FBQyxxQ0FBcUMsRUFBRSxFQUFFLENBQUM7Q0FDN0Y7QUFFRixNQUFNLE9BQU8sZ0JBQWlCLFNBQVEsR0FBRyxFQUFvQixDQUFDLGtCQUFrQixFQUFFLEVBQUUsQ0FBQztDQUFHO0FBRXhGLE1BQU0sQ0FBQyxNQUFNLHlCQUF5QixHQUFHO0lBQ3ZDLHNCQUFzQjtJQUN0QixtQ0FBbUM7SUFDbkMsZ0JBQWdCO0NBQ1IsQ0FBQSJ9
|
package/src/client/req.ts
DELETED
|
@@ -1,288 +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
|
-
|
|
5
|
-
import { type Tag } from "../Context.js"
|
|
6
|
-
import { type Context, type NonEmptyReadonlyArray, S } from "../internal/lib.js"
|
|
7
|
-
import { type Values } from "../utils.js"
|
|
8
|
-
|
|
9
|
-
/** @deprecated just use Service Identifier Union */
|
|
10
|
-
export type ContextTagArray = NonEmptyReadonlyArray<Context.Tag<any, any>>
|
|
11
|
-
|
|
12
|
-
/** @deprecated just use Service Identifier Union */
|
|
13
|
-
export namespace ContextTagArray {
|
|
14
|
-
export type Identifier<A> = A extends ContextTagArray ? Tag.Identifier<A[number]> : never
|
|
15
|
-
export type Service<A> = A extends ContextTagArray ? Tag.Service<A[number]> : never
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** @deprecated just use Service Identifier Union */
|
|
19
|
-
export type AnyService = Context.Tag<any, any> | ContextTagArray
|
|
20
|
-
/** @deprecated just use Service Identifier Union */
|
|
21
|
-
export namespace AnyService {
|
|
22
|
-
export type Bla<A> = A extends ContextTagArray ? Context.Context<ContextTagArray.Identifier<A>>
|
|
23
|
-
: A extends Context.Tag<any, any> ? Tag.Service<A>
|
|
24
|
-
: never
|
|
25
|
-
export type Identifier<A> = A extends ContextTagArray ? ContextTagArray.Identifier<A>
|
|
26
|
-
: A extends Context.Tag<any, any> ? Tag.Identifier<A>
|
|
27
|
-
: never
|
|
28
|
-
export type Service<A> = A extends ContextTagArray ? ContextTagArray.Service<A>
|
|
29
|
-
: A extends Context.Tag<any, any> ? Tag.Service<A>
|
|
30
|
-
: never
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export namespace RPCContextMap {
|
|
34
|
-
/**
|
|
35
|
-
* Middleware is inactivate by default, the Key is optional in route context, and the service is optionally provided as Effect Context.
|
|
36
|
-
* Unless explicitly configured as `true`.
|
|
37
|
-
*/
|
|
38
|
-
export type RPCContextMap<Service, E> = {
|
|
39
|
-
service: Service
|
|
40
|
-
error: E
|
|
41
|
-
contextActivation: true
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Middleware is active by default, and provides the Service at Key in route context, and the Service is provided as Effect Context.
|
|
46
|
-
* Unless explicitly omitted.
|
|
47
|
-
*/
|
|
48
|
-
export type Inverted<Service extends AnyService, E> = {
|
|
49
|
-
service: Service
|
|
50
|
-
error: E
|
|
51
|
-
contextActivation: false
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type Custom<Service extends AnyService, E, C> = {
|
|
55
|
-
service: Service
|
|
56
|
-
error: E
|
|
57
|
-
contextActivation: C
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export type Any = {
|
|
61
|
-
service: AnyService
|
|
62
|
-
error: S.Schema.All
|
|
63
|
-
contextActivation: any
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const make = <Service extends AnyService, E>(
|
|
67
|
-
service: Service,
|
|
68
|
-
error: E
|
|
69
|
-
): RPCContextMap<Service, E> => ({
|
|
70
|
-
service,
|
|
71
|
-
error,
|
|
72
|
-
contextActivation: true
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
export const makeInverted = <Service extends AnyService, E>(
|
|
76
|
-
service: Service,
|
|
77
|
-
error: E
|
|
78
|
-
): Inverted<Service, E> => ({
|
|
79
|
-
service,
|
|
80
|
-
error,
|
|
81
|
-
contextActivation: false
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
export const makeCustom = <Service extends AnyService, E, C>(
|
|
85
|
-
service: Service,
|
|
86
|
-
error: E,
|
|
87
|
-
contextActivation: C
|
|
88
|
-
): Custom<Service, E, C> => ({
|
|
89
|
-
service,
|
|
90
|
-
error,
|
|
91
|
-
contextActivation
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export type GetContextConfig<RequestContextMap extends Record<string, RPCContextMap.Any>> = {
|
|
96
|
-
[K in keyof RequestContextMap]?: RequestContextMap[K]["contextActivation"] extends true ? false
|
|
97
|
-
: RequestContextMap[K]["contextActivation"] extends false ? true
|
|
98
|
-
: RequestContextMap[K]["contextActivation"]
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export type GetEffectContext<RequestContextMap extends Record<string, RPCContextMap.Any>, T> = Values<
|
|
102
|
-
// inverted: contextActivation is false => remove if explicitly set to true (like allowAnonymous: true disables auth and auth service and related errors)
|
|
103
|
-
& {
|
|
104
|
-
[
|
|
105
|
-
key in keyof RequestContextMap as RequestContextMap[key]["contextActivation"] extends true ? never
|
|
106
|
-
: key extends keyof T ? T[key] extends true ? never : key
|
|
107
|
-
: key
|
|
108
|
-
]: // TODO: or as an Optional available?
|
|
109
|
-
AnyService.Identifier<RequestContextMap[key]["service"]>
|
|
110
|
-
}
|
|
111
|
-
// normal: contextActivation is true => add if explicitly set to true
|
|
112
|
-
& {
|
|
113
|
-
[
|
|
114
|
-
key in keyof RequestContextMap as RequestContextMap[key]["contextActivation"] extends false ? never
|
|
115
|
-
: key extends keyof T ? T[key] extends true ? key : never
|
|
116
|
-
: never
|
|
117
|
-
]: // TODO: or as an Optional available?
|
|
118
|
-
AnyService.Identifier<RequestContextMap[key]["service"]>
|
|
119
|
-
}
|
|
120
|
-
>
|
|
121
|
-
|
|
122
|
-
export type GetEffectError<RequestContextMap extends Record<string, RPCContextMap.Any>, T> = Values<
|
|
123
|
-
// inverted: contextActivation is false => remove if explicitly set to true (like allowAnonymous: true disables auth and auth service and related errors)
|
|
124
|
-
& {
|
|
125
|
-
[
|
|
126
|
-
key in keyof RequestContextMap as RequestContextMap[key]["contextActivation"] extends true ? never
|
|
127
|
-
: key extends keyof T ? T[key] extends true ? never : key
|
|
128
|
-
: key
|
|
129
|
-
]: // TODO: or as an Optional available?
|
|
130
|
-
RequestContextMap[key]["error"]
|
|
131
|
-
}
|
|
132
|
-
// normal: contextActivation is true => add if explicitly set to true
|
|
133
|
-
& {
|
|
134
|
-
[
|
|
135
|
-
key in keyof RequestContextMap as RequestContextMap[key]["contextActivation"] extends false ? never
|
|
136
|
-
: key extends keyof T ? T[key] extends true ? key : never
|
|
137
|
-
: never
|
|
138
|
-
]: // TODO: or as an Optional available?
|
|
139
|
-
RequestContextMap[key]["error"]
|
|
140
|
-
}
|
|
141
|
-
>
|
|
142
|
-
|
|
143
|
-
// TODO: Fix error types... (?)
|
|
144
|
-
type JoinSchema<T> = T extends ReadonlyArray<S.Schema.All> ? S.Union<T> : typeof S.Never
|
|
145
|
-
|
|
146
|
-
const merge = (a: any, b: Array<any>) =>
|
|
147
|
-
a !== undefined && b.length ? S.Union(a, ...b) : a !== undefined ? a : b.length ? S.Union(...b) : S.Never
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Converts struct fields to TypeLiteral schema, or returns existing schema.
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```typescript
|
|
154
|
-
* type Fields = { name: S.String; age: S.Number }
|
|
155
|
-
* type Schema = SchemaOrFields<Fields>
|
|
156
|
-
* // Result: S.TypeLiteral<Fields, []>
|
|
157
|
-
*
|
|
158
|
-
* type Existing = S.String
|
|
159
|
-
* type Same = SchemaOrFields<Existing>
|
|
160
|
-
* // Result: S.String
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
type SchemaOrFields<T> = T extends S.Struct.Fields ? S.TypeLiteral<T, []> : T extends S.Schema.Any ? T : never
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Whatever the input, we will only decode or encode to void
|
|
167
|
-
*/
|
|
168
|
-
const ForceVoid: S.Schema<void> = S.transform(S.Any, S.Void, { decode: () => void 0, encode: () => void 0 })
|
|
169
|
-
|
|
170
|
-
export const makeRpcClient = <
|
|
171
|
-
RequestConfig extends object,
|
|
172
|
-
RequestContextMap extends Record<string, RPCContextMap.Any>,
|
|
173
|
-
GeneralErrors extends S.Schema.All = never
|
|
174
|
-
>(
|
|
175
|
-
errors: { [K in keyof RequestContextMap]: RequestContextMap[K]["error"] },
|
|
176
|
-
generalErrors?: GeneralErrors
|
|
177
|
-
) => {
|
|
178
|
-
// Long way around Context/C extends etc to support actual jsdoc from passed in RequestConfig etc... (??)
|
|
179
|
-
type Context = {
|
|
180
|
-
success: S.Schema.Any | S.Struct.Fields // SchemaOrFields will make a Schema type out of Struct.Fields
|
|
181
|
-
failure: S.Schema.Any | S.Struct.Fields // SchemaOrFields will make a Schema type out of Struct.Fields
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function TaggedRequest<Self>(): {
|
|
185
|
-
<Tag extends string, Payload extends S.Struct.Fields, C extends Context>(
|
|
186
|
-
tag: Tag,
|
|
187
|
-
fields: Payload,
|
|
188
|
-
config: RequestConfig & C
|
|
189
|
-
):
|
|
190
|
-
& S.TaggedRequestClass<
|
|
191
|
-
Self,
|
|
192
|
-
Tag,
|
|
193
|
-
{ readonly _tag: S.tag<Tag> } & Payload,
|
|
194
|
-
SchemaOrFields<typeof config["success"]>,
|
|
195
|
-
JoinSchema<
|
|
196
|
-
[SchemaOrFields<typeof config["failure"]> | GetEffectError<RequestContextMap, C> | GeneralErrors]
|
|
197
|
-
>
|
|
198
|
-
>
|
|
199
|
-
& { config: Omit<C, "success" | "failure"> }
|
|
200
|
-
<Tag extends string, Payload extends S.Struct.Fields, C extends Pick<Context, "success">>(
|
|
201
|
-
tag: Tag,
|
|
202
|
-
fields: Payload,
|
|
203
|
-
config: RequestConfig & C
|
|
204
|
-
):
|
|
205
|
-
& S.TaggedRequestClass<
|
|
206
|
-
Self,
|
|
207
|
-
Tag,
|
|
208
|
-
{ readonly _tag: S.tag<Tag> } & Payload,
|
|
209
|
-
SchemaOrFields<typeof config["success"]>,
|
|
210
|
-
JoinSchema<[GetEffectError<RequestContextMap, C> | GeneralErrors]>
|
|
211
|
-
>
|
|
212
|
-
& { config: Omit<C, "success" | "failure"> }
|
|
213
|
-
<Tag extends string, Payload extends S.Struct.Fields, C extends Pick<Context, "failure">>(
|
|
214
|
-
tag: Tag,
|
|
215
|
-
fields: Payload,
|
|
216
|
-
config: RequestConfig & C
|
|
217
|
-
):
|
|
218
|
-
& S.TaggedRequestClass<
|
|
219
|
-
Self,
|
|
220
|
-
Tag,
|
|
221
|
-
{ readonly _tag: S.tag<Tag> } & Payload,
|
|
222
|
-
typeof S.Void,
|
|
223
|
-
JoinSchema<
|
|
224
|
-
[SchemaOrFields<typeof config["failure"]> | GetEffectError<RequestContextMap, C> | GeneralErrors]
|
|
225
|
-
>
|
|
226
|
-
>
|
|
227
|
-
& { config: Omit<C, "success" | "failure"> }
|
|
228
|
-
<Tag extends string, Payload extends S.Struct.Fields, C extends Record<string, any>>(
|
|
229
|
-
tag: Tag,
|
|
230
|
-
fields: Payload,
|
|
231
|
-
config: C & RequestConfig
|
|
232
|
-
):
|
|
233
|
-
& S.TaggedRequestClass<
|
|
234
|
-
Self,
|
|
235
|
-
Tag,
|
|
236
|
-
{ readonly _tag: S.tag<Tag> } & Payload,
|
|
237
|
-
typeof S.Void,
|
|
238
|
-
JoinSchema<[GetEffectError<RequestContextMap, C> | GeneralErrors]>
|
|
239
|
-
>
|
|
240
|
-
& { config: Omit<C, "success" | "failure"> }
|
|
241
|
-
<Tag extends string, Payload extends S.Struct.Fields>(
|
|
242
|
-
tag: Tag,
|
|
243
|
-
fields: Payload
|
|
244
|
-
):
|
|
245
|
-
& S.TaggedRequestClass<
|
|
246
|
-
Self,
|
|
247
|
-
Tag,
|
|
248
|
-
{ readonly _tag: S.tag<Tag> } & Payload,
|
|
249
|
-
typeof S.Void,
|
|
250
|
-
GeneralErrors extends never ? typeof S.Never : GeneralErrors
|
|
251
|
-
>
|
|
252
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
253
|
-
& { config: {} }
|
|
254
|
-
} {
|
|
255
|
-
// TODO: filter errors based on config + take care of inversion
|
|
256
|
-
const errorSchemas = Object.values(errors)
|
|
257
|
-
return (<Tag extends string, Fields extends S.Struct.Fields, C extends Context>(
|
|
258
|
-
tag: Tag,
|
|
259
|
-
fields: Fields,
|
|
260
|
-
config?: C
|
|
261
|
-
) => {
|
|
262
|
-
// S.TaggedRequest is a factory function that creates a TaggedRequest class
|
|
263
|
-
const req = S.TaggedRequest<Self>()(tag, {
|
|
264
|
-
payload: fields,
|
|
265
|
-
// ensure both failure and success are schemas
|
|
266
|
-
failure: merge(
|
|
267
|
-
config?.failure ? S.isSchema(config.failure) ? config.failure : S.Struct(config.failure) : undefined,
|
|
268
|
-
[...errorSchemas, generalErrors].filter(Boolean)
|
|
269
|
-
),
|
|
270
|
-
success: config?.success
|
|
271
|
-
? S.isSchema(config.success)
|
|
272
|
-
? S.AST.isVoidKeyword(config.success.ast) ? ForceVoid : config.success
|
|
273
|
-
: S.Struct(config.success)
|
|
274
|
-
: ForceVoid
|
|
275
|
-
})
|
|
276
|
-
return class extends (Object.assign(req, { config }) as any) {
|
|
277
|
-
constructor(payload: any, disableValidation: any = true) {
|
|
278
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
279
|
-
super(payload, disableValidation)
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}) as any
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return {
|
|
286
|
-
TaggedRequest
|
|
287
|
-
}
|
|
288
|
-
}
|
|
@@ -1,65 +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 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 = <
|
|
14
|
-
Self,
|
|
15
|
-
Config extends {
|
|
16
|
-
requires?: any
|
|
17
|
-
provides?: any
|
|
18
|
-
} = { requires: never; provides: never }
|
|
19
|
-
>() =>
|
|
20
|
-
<
|
|
21
|
-
const Name extends string,
|
|
22
|
-
const Options extends RpcOptionsOriginal | RpcOptionsDynamic<any, any>
|
|
23
|
-
>(
|
|
24
|
-
id: Name,
|
|
25
|
-
options?: Options | undefined
|
|
26
|
-
) =>
|
|
27
|
-
<
|
|
28
|
-
LayerOpts extends {
|
|
29
|
-
effect: Effect.Effect<
|
|
30
|
-
Options extends RpcOptionsDynamic<any, any> ? RpcMiddlewareDynamicWrap<
|
|
31
|
-
TagClass.FailureService<Options>,
|
|
32
|
-
"requires" extends keyof Config ? Config["requires"] : never,
|
|
33
|
-
{ [K in Options["dynamic"]["key"]]?: Options["dynamic"]["settings"]["contextActivation"] }
|
|
34
|
-
>
|
|
35
|
-
: RpcMiddlewareWrap<
|
|
36
|
-
"provides" extends keyof Config ? Config["provides"] : never,
|
|
37
|
-
TagClass.Failure<Options>,
|
|
38
|
-
"requires" extends keyof Config ? Config["requires"] : never
|
|
39
|
-
>,
|
|
40
|
-
any,
|
|
41
|
-
any
|
|
42
|
-
>
|
|
43
|
-
dependencies?: NonEmptyReadonlyArray<Layer.Layer.Any>
|
|
44
|
-
}
|
|
45
|
-
>(opts: LayerOpts): TagClass<Self, Name, Options, Config> & {
|
|
46
|
-
Default: Layer.Layer<
|
|
47
|
-
Self,
|
|
48
|
-
| (LayerOpts extends { effect: Effect<infer _A, infer _E, infer _R> } ? _E
|
|
49
|
-
: never)
|
|
50
|
-
| Service.MakeDepsE<LayerOpts>,
|
|
51
|
-
| Exclude<
|
|
52
|
-
LayerOpts extends { effect: Effect<infer _A, infer _E, infer _R> } ? _R : never,
|
|
53
|
-
Service.MakeDepsOut<LayerOpts>
|
|
54
|
-
>
|
|
55
|
-
| Service.MakeDepsIn<LayerOpts>
|
|
56
|
-
>
|
|
57
|
-
} =>
|
|
58
|
-
class extends Tag<Self>()(id, options as any) {
|
|
59
|
-
static readonly Default = Layer.scoped(this, opts.effect as any).pipe(
|
|
60
|
-
Layer.provide([Layer.empty, ...opts.dependencies ?? []])
|
|
61
|
-
)
|
|
62
|
-
static override [Unify.typeSymbol]?: unknown
|
|
63
|
-
static override [Unify.unifySymbol]?: TagUnify<typeof this>
|
|
64
|
-
static override [Unify.ignoreSymbol]?: TagUnifyIgnore
|
|
65
|
-
} as any
|
|
@@ -1,128 +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, type S } from "effect-app"
|
|
4
|
-
import { type GetContextConfig, type RPCContextMap } from "effect-app/client"
|
|
5
|
-
import { type Tag } from "effect/Context"
|
|
6
|
-
import { type Simplify } from "effect/Types"
|
|
7
|
-
import { PreludeLogger } 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 ? T extends { provides: infer _P } ? _P
|
|
71
|
-
: never
|
|
72
|
-
: never
|
|
73
|
-
|
|
74
|
-
export type Errors<T> = T extends TagClassAny ? T extends { failure: S.Schema.Any } ? S.Schema.Type<T["failure"]>
|
|
75
|
-
: never
|
|
76
|
-
: never
|
|
77
|
-
|
|
78
|
-
export type Required<T> = T extends TagClassAny ? T extends { requires: infer _R } ? _R
|
|
79
|
-
: never
|
|
80
|
-
: never
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export const middlewareMaker = <
|
|
84
|
-
MiddlewareProviders extends ReadonlyArray<MiddlewareMaker.Any>
|
|
85
|
-
>(middlewares: MiddlewareProviders): Effect.Effect<
|
|
86
|
-
RpcMiddlewareWrap<
|
|
87
|
-
MiddlewareMaker.ManyProvided<MiddlewareProviders>,
|
|
88
|
-
MiddlewareMaker.ManyErrors<MiddlewareProviders>,
|
|
89
|
-
Exclude<
|
|
90
|
-
MiddlewareMaker.ManyRequired<MiddlewareProviders>,
|
|
91
|
-
MiddlewareMaker.ManyProvided<MiddlewareProviders>
|
|
92
|
-
> extends never ? never
|
|
93
|
-
: Exclude<MiddlewareMaker.ManyRequired<MiddlewareProviders>, MiddlewareMaker.ManyProvided<MiddlewareProviders>>
|
|
94
|
-
>
|
|
95
|
-
> => {
|
|
96
|
-
// we want to run them in reverse order because latter middlewares will provide context to former ones
|
|
97
|
-
middlewares = middlewares.toReversed() as any
|
|
98
|
-
|
|
99
|
-
return Effect.gen(function*() {
|
|
100
|
-
const context = yield* Effect.context()
|
|
101
|
-
|
|
102
|
-
// returns a Effect/RpcMiddlewareWrap with Scope in requirements
|
|
103
|
-
return (
|
|
104
|
-
_options: Parameters<
|
|
105
|
-
RpcMiddleware.RpcMiddlewareWrap<
|
|
106
|
-
MiddlewareMaker.ManyProvided<MiddlewareProviders>,
|
|
107
|
-
never
|
|
108
|
-
>
|
|
109
|
-
>[0]
|
|
110
|
-
) => {
|
|
111
|
-
const { next, ...options } = _options
|
|
112
|
-
// we start with the actual handler
|
|
113
|
-
let handler = next
|
|
114
|
-
|
|
115
|
-
// inspired from Effect/RpcMiddleware
|
|
116
|
-
for (const tag of middlewares) {
|
|
117
|
-
// use the tag to get the middleware from context
|
|
118
|
-
const middleware = Context.unsafeGet(context, tag)
|
|
119
|
-
|
|
120
|
-
// wrap the current handler, allowing the middleware to run before and after it
|
|
121
|
-
handler = PreludeLogger.logDebug("Applying middleware wrap " + tag.key).pipe(
|
|
122
|
-
Effect.zipRight(middleware(handler, options))
|
|
123
|
-
) as any
|
|
124
|
-
}
|
|
125
|
-
return handler
|
|
126
|
-
}
|
|
127
|
-
}) as any
|
|
128
|
-
}
|
package/wallaby.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("../../wallaby.base.cjs")
|