@effect-app/infra 3.9.0 → 4.0.0-beta.0
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 +22 -0
- package/_check.sh +3 -0
- package/dist/CUPS.d.ts +22 -12
- package/dist/CUPS.d.ts.map +1 -1
- package/dist/CUPS.js +28 -29
- package/dist/Emailer/Sendgrid.js +13 -12
- package/dist/Emailer/service.d.ts +3 -13
- package/dist/Emailer/service.d.ts.map +1 -1
- package/dist/Emailer/service.js +3 -3
- package/dist/MainFiberSet.d.ts +18 -41
- package/dist/MainFiberSet.d.ts.map +1 -1
- package/dist/MainFiberSet.js +10 -10
- package/dist/Model/Repository/ext.d.ts.map +1 -1
- package/dist/Model/Repository/ext.js +13 -10
- package/dist/Model/Repository/internal/internal.d.ts +5 -5
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -1
- package/dist/Model/Repository/internal/internal.js +52 -42
- package/dist/Model/Repository/legacy.d.ts +9 -9
- package/dist/Model/Repository/legacy.d.ts.map +1 -1
- package/dist/Model/Repository/makeRepo.d.ts +4 -4
- package/dist/Model/Repository/makeRepo.d.ts.map +1 -1
- package/dist/Model/Repository/makeRepo.js +1 -1
- package/dist/Model/Repository/service.d.ts +11 -11
- package/dist/Model/Repository/service.d.ts.map +1 -1
- package/dist/Model/Repository/validation.d.ts +17 -47
- package/dist/Model/Repository/validation.d.ts.map +1 -1
- package/dist/Model/Repository/validation.js +2 -2
- package/dist/Model/query/dsl.d.ts +22 -22
- package/dist/Model/query/dsl.d.ts.map +1 -1
- package/dist/Model/query/dsl.js +1 -1
- package/dist/Model/query/new-kid-interpreter.d.ts +1 -1
- package/dist/Model/query/new-kid-interpreter.js +7 -7
- package/dist/Operations.d.ts +22 -63
- package/dist/Operations.d.ts.map +1 -1
- package/dist/Operations.js +14 -14
- package/dist/OperationsRepo.d.ts +23 -7
- package/dist/OperationsRepo.d.ts.map +1 -1
- package/dist/OperationsRepo.js +4 -5
- package/dist/QueueMaker/SQLQueue.d.ts +6 -8
- package/dist/QueueMaker/SQLQueue.d.ts.map +1 -1
- package/dist/QueueMaker/SQLQueue.js +20 -24
- package/dist/QueueMaker/errors.js +1 -1
- package/dist/QueueMaker/memQueue.d.ts +2 -5
- package/dist/QueueMaker/memQueue.d.ts.map +1 -1
- package/dist/QueueMaker/memQueue.js +22 -26
- package/dist/QueueMaker/sbqueue.d.ts +2 -5
- package/dist/QueueMaker/sbqueue.d.ts.map +1 -1
- package/dist/QueueMaker/sbqueue.js +24 -28
- package/dist/RequestContext.d.ts +28 -41
- package/dist/RequestContext.d.ts.map +1 -1
- package/dist/RequestContext.js +4 -4
- package/dist/RequestFiberSet.d.ts +23 -50
- package/dist/RequestFiberSet.d.ts.map +1 -1
- package/dist/RequestFiberSet.js +14 -14
- package/dist/Store/ContextMapContainer.d.ts +4 -4
- package/dist/Store/ContextMapContainer.d.ts.map +1 -1
- package/dist/Store/ContextMapContainer.js +5 -5
- package/dist/Store/Cosmos.d.ts.map +1 -1
- package/dist/Store/Cosmos.js +21 -28
- package/dist/Store/Disk.d.ts.map +1 -1
- package/dist/Store/Disk.js +12 -16
- package/dist/Store/Memory.d.ts +2 -2
- package/dist/Store/Memory.d.ts.map +1 -1
- package/dist/Store/Memory.js +25 -33
- package/dist/Store/index.js +2 -2
- package/dist/Store/service.d.ts +9 -34
- package/dist/Store/service.d.ts.map +1 -1
- package/dist/Store/service.js +4 -4
- package/dist/Store/utils.d.ts.map +1 -1
- package/dist/Store/utils.js +10 -2
- package/dist/adapters/SQL/Model.d.ts +106 -162
- package/dist/adapters/SQL/Model.d.ts.map +1 -1
- package/dist/adapters/SQL/Model.js +92 -130
- package/dist/adapters/ServiceBus.d.ts +13 -44
- package/dist/adapters/ServiceBus.d.ts.map +1 -1
- package/dist/adapters/ServiceBus.js +13 -15
- package/dist/adapters/cosmos-client.d.ts +7 -3
- package/dist/adapters/cosmos-client.d.ts.map +1 -1
- package/dist/adapters/cosmos-client.js +5 -4
- package/dist/adapters/logger.d.ts +1 -1
- package/dist/adapters/logger.d.ts.map +1 -1
- package/dist/adapters/memQueue.d.ts +8 -21
- package/dist/adapters/memQueue.d.ts.map +1 -1
- package/dist/adapters/memQueue.js +4 -4
- package/dist/adapters/mongo-client.d.ts +6 -6
- package/dist/adapters/mongo-client.d.ts.map +1 -1
- package/dist/adapters/mongo-client.js +5 -4
- package/dist/adapters/redis-client.d.ts +14 -4
- package/dist/adapters/redis-client.d.ts.map +1 -1
- package/dist/adapters/redis-client.js +19 -18
- package/dist/api/ContextProvider.d.ts +10 -15
- package/dist/api/ContextProvider.d.ts.map +1 -1
- package/dist/api/ContextProvider.js +8 -8
- package/dist/api/codec.d.ts +1 -1
- package/dist/api/codec.d.ts.map +1 -1
- package/dist/api/codec.js +1 -1
- package/dist/api/internal/RequestContextMiddleware.d.ts +1 -1
- package/dist/api/internal/RequestContextMiddleware.d.ts.map +1 -1
- package/dist/api/internal/auth.d.ts +3 -3
- package/dist/api/internal/auth.d.ts.map +1 -1
- package/dist/api/internal/auth.js +8 -8
- package/dist/api/internal/events.d.ts +2 -2
- package/dist/api/internal/events.d.ts.map +1 -1
- package/dist/api/internal/events.js +9 -9
- package/dist/api/internal/health.d.ts +1 -1
- package/dist/api/internal/health.d.ts.map +1 -1
- package/dist/api/internal/health.js +2 -2
- package/dist/api/layerUtils.d.ts +14 -14
- package/dist/api/layerUtils.d.ts.map +1 -1
- package/dist/api/layerUtils.js +5 -5
- package/dist/api/middlewares.d.ts +0 -75
- package/dist/api/middlewares.d.ts.map +1 -1
- package/dist/api/middlewares.js +6 -51
- package/dist/api/reportError.js +4 -4
- package/dist/api/routing/middleware/RouterMiddleware.d.ts +4 -4
- package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +1 -1
- package/dist/api/routing/middleware/middleware.d.ts +6 -7
- package/dist/api/routing/middleware/middleware.d.ts.map +1 -1
- package/dist/api/routing/middleware/middleware.js +9 -13
- package/dist/api/routing/schema/jwt.d.ts +1 -1
- package/dist/api/routing/schema/jwt.d.ts.map +1 -1
- package/dist/api/routing/schema/jwt.js +5 -4
- package/dist/api/routing/utils.d.ts +2 -2
- package/dist/api/routing/utils.d.ts.map +1 -1
- package/dist/api/routing/utils.js +10 -8
- package/dist/api/routing.d.ts +39 -37
- package/dist/api/routing.d.ts.map +1 -1
- package/dist/api/routing.js +17 -21
- package/dist/api/setupRequest.d.ts +4 -6
- package/dist/api/setupRequest.d.ts.map +1 -1
- package/dist/api/setupRequest.js +10 -9
- package/dist/arbs.d.ts +3 -3
- package/dist/arbs.d.ts.map +1 -1
- package/dist/arbs.js +2 -2
- package/dist/errorReporter.d.ts +1 -1
- package/dist/errorReporter.d.ts.map +1 -1
- package/dist/errorReporter.js +12 -12
- package/dist/fileUtil.d.ts +6 -6
- package/dist/fileUtil.d.ts.map +1 -1
- package/dist/logger/jsonLogger.d.ts.map +1 -1
- package/dist/logger/jsonLogger.js +19 -18
- package/dist/logger/logFmtLogger.d.ts.map +1 -1
- package/dist/logger/logFmtLogger.js +11 -13
- package/dist/logger/shared.d.ts +2 -2
- package/dist/logger/shared.d.ts.map +1 -1
- package/dist/logger/shared.js +7 -9
- package/dist/logger.d.ts +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/rateLimit.d.ts +2 -2
- package/dist/rateLimit.d.ts.map +1 -1
- package/dist/rateLimit.js +5 -5
- package/dist/test.d.ts +2 -2
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +6 -24
- package/package.json +24 -27
- package/src/CUPS.ts +15 -14
- package/src/Emailer/Sendgrid.ts +15 -13
- package/src/Emailer/service.ts +3 -3
- package/src/MainFiberSet.ts +16 -12
- package/src/Model/Repository/ext.ts +18 -16
- package/src/Model/Repository/internal/internal.ts +80 -69
- package/src/Model/Repository/legacy.ts +9 -9
- package/src/Model/Repository/makeRepo.ts +5 -5
- package/src/Model/Repository/service.ts +12 -12
- package/src/Model/Repository/validation.ts +1 -1
- package/src/Model/query/dsl.ts +13 -13
- package/src/Model/query/new-kid-interpreter.ts +8 -8
- package/src/Operations.ts +17 -14
- package/src/OperationsRepo.ts +3 -4
- package/src/QueueMaker/SQLQueue.ts +86 -89
- package/src/QueueMaker/errors.ts +1 -1
- package/src/QueueMaker/memQueue.ts +90 -91
- package/src/QueueMaker/sbqueue.ts +90 -92
- package/src/RequestContext.ts +3 -3
- package/src/RequestFiberSet.ts +17 -15
- package/src/Store/ContextMapContainer.ts +4 -4
- package/src/Store/Cosmos.ts +20 -27
- package/src/Store/Disk.ts +13 -17
- package/src/Store/Memory.ts +28 -34
- package/src/Store/index.ts +1 -1
- package/src/Store/service.ts +4 -4
- package/src/Store/utils.ts +9 -5
- package/src/adapters/SQL/Model.ts +255 -268
- package/src/adapters/ServiceBus.ts +17 -20
- package/src/adapters/cosmos-client.ts +5 -5
- package/src/adapters/memQueue.ts +3 -3
- package/src/adapters/mongo-client.ts +5 -5
- package/src/adapters/redis-client.ts +25 -19
- package/src/api/ContextProvider.ts +24 -34
- package/src/api/codec.ts +1 -1
- package/src/api/internal/auth.ts +11 -13
- package/src/api/internal/events.ts +11 -11
- package/src/api/internal/health.ts +1 -1
- package/src/api/layerUtils.ts +20 -20
- package/src/api/middlewares.ts +0 -97
- package/src/api/reportError.ts +3 -3
- package/src/api/routing/middleware/RouterMiddleware.ts +5 -6
- package/src/api/routing/middleware/middleware.ts +13 -25
- package/src/api/routing/schema/jwt.ts +9 -7
- package/src/api/routing/utils.ts +12 -10
- package/src/api/routing.ts +77 -79
- package/src/api/setupRequest.ts +9 -8
- package/src/arbs.ts +3 -3
- package/src/errorReporter.ts +12 -12
- package/src/logger/jsonLogger.ts +18 -17
- package/src/logger/logFmtLogger.ts +10 -12
- package/src/logger/shared.ts +6 -8
- package/src/rateLimit.ts +7 -7
- package/src/test.ts +7 -29
- package/test/contextProvider.test.ts +77 -70
- package/test/controller.test.ts +51 -39
- package/test/dist/contextProvider.test.d.ts.map +1 -1
- package/test/dist/controller.test.d.ts.map +1 -1
- package/test/dist/fixtures.d.ts +33 -81
- package/test/dist/fixtures.d.ts.map +1 -1
- package/test/dist/fixtures.js +9 -8
- package/test/dist/query.test.d.ts.map +1 -1
- package/test/dist/rawQuery.test.d.ts.map +1 -1
- package/test/dist/requires.test.d.ts.map +1 -1
- package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
- package/test/fixtures.ts +9 -7
- package/test/query.test.ts +49 -41
- package/test/rawQuery.test.ts +44 -40
- package/test/requires.test.ts +40 -31
- package/test/rpc-multi-middleware.test.ts +13 -14
- package/test/validateSample.test.ts +2 -2
- package/tsconfig.json +1 -25
- package/dist/api/internal/middlewares.d.ts +0 -15
- package/dist/api/internal/middlewares.d.ts.map +0 -1
- package/dist/api/internal/middlewares.js +0 -168
- package/src/api/internal/middlewares.ts +0 -279
package/src/api/routing.ts
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
-
import {
|
|
6
|
-
import { Config, Effect, Layer, type NonEmptyReadonlyArray, Predicate, S, Schema, type Scope } from "effect-app"
|
|
5
|
+
import { Config, Effect, Layer, type NonEmptyReadonlyArray, Predicate, S, type Scope } from "effect-app"
|
|
7
6
|
import { type HttpHeaders } from "effect-app/http"
|
|
8
7
|
import { type GetEffectContext, type GetEffectError, type RpcContextMap } from "effect-app/rpc/RpcContextMap"
|
|
9
8
|
import { type TypeTestId } from "effect-app/TypeTest"
|
|
10
9
|
import { typedKeysOf, typedValuesOf } from "effect-app/utils"
|
|
11
|
-
import { type
|
|
12
|
-
import type
|
|
13
|
-
import { type YieldWrap } from "effect/Utils"
|
|
10
|
+
import { type Yieldable } from "effect/Effect"
|
|
11
|
+
import { Rpc, RpcGroup, type RpcSerialization, RpcServer } from "effect/unstable/rpc"
|
|
14
12
|
import { type LayerUtils } from "./layerUtils.js"
|
|
15
13
|
import { type RouterMiddleware } from "./routing/middleware.js"
|
|
16
14
|
|
|
@@ -18,11 +16,11 @@ export * from "./routing/middleware.js"
|
|
|
18
16
|
|
|
19
17
|
// it's the result of extending S.Req setting success, config
|
|
20
18
|
// it's a schema plus some metadata
|
|
21
|
-
export type AnyRequestModule = S.
|
|
19
|
+
export type AnyRequestModule = S.Any & {
|
|
22
20
|
_tag: string // unique identifier for the request module
|
|
23
21
|
config: any // ?
|
|
24
|
-
success: S.
|
|
25
|
-
|
|
22
|
+
success: S.Any // validates the success response
|
|
23
|
+
error: S.Any // validates the failure response
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
// builder pattern for adding actions to a router until all actions are added
|
|
@@ -55,12 +53,12 @@ namespace RequestTypes {
|
|
|
55
53
|
}
|
|
56
54
|
type RequestType = typeof RequestTypes[keyof typeof RequestTypes]
|
|
57
55
|
|
|
58
|
-
type GetSuccess<T> = T extends { success: S.
|
|
59
|
-
type GetFailure<T extends {
|
|
56
|
+
type GetSuccess<T> = T extends { success: S.Any } ? T["success"] : typeof S.Void
|
|
57
|
+
type GetFailure<T extends { error?: S.Any }> = T["error"] extends never ? typeof S.Never : T["error"]
|
|
60
58
|
|
|
61
|
-
type GetSuccessShape<Action extends { success?: S.
|
|
59
|
+
type GetSuccessShape<Action extends { success?: S.Any }, RT extends RequestType> = {
|
|
62
60
|
d: S.Schema.Type<GetSuccess<Action>>
|
|
63
|
-
raw: S.
|
|
61
|
+
raw: S.Codec.Encoded<GetSuccess<Action>>
|
|
64
62
|
}[RT]
|
|
65
63
|
|
|
66
64
|
interface HandlerBase<Action extends AnyRequestModule, RT extends RequestType, A, E, R> {
|
|
@@ -75,7 +73,7 @@ export interface Handler<Action extends AnyRequestModule, RT extends RequestType
|
|
|
75
73
|
Action,
|
|
76
74
|
RT,
|
|
77
75
|
GetSuccessShape<Action, RT>,
|
|
78
|
-
S.Schema.Type<GetFailure<Action>> | S.
|
|
76
|
+
S.Schema.Type<GetFailure<Action>> | S.SchemaError,
|
|
79
77
|
R
|
|
80
78
|
>
|
|
81
79
|
{}
|
|
@@ -142,8 +140,8 @@ export type RouteMatcher<
|
|
|
142
140
|
& Match<Resource, RequestContextMap, RequestTypes.DECODED, Key>
|
|
143
141
|
& {
|
|
144
142
|
success: Resource[Key]["success"]
|
|
145
|
-
successRaw: S.
|
|
146
|
-
|
|
143
|
+
successRaw: S.Schema<S.Codec.Encoded<Resource[Key]["success"]>>
|
|
144
|
+
error: Resource[Key]["failure"]
|
|
147
145
|
/**
|
|
148
146
|
* Requires the Encoded shape (e.g directly undecoded from DB, so that we don't do multiple Decode/Encode)
|
|
149
147
|
*/
|
|
@@ -151,7 +149,12 @@ export type RouteMatcher<
|
|
|
151
149
|
}
|
|
152
150
|
}
|
|
153
151
|
|
|
154
|
-
export const skipOnProd =
|
|
152
|
+
export const skipOnProd = Effect
|
|
153
|
+
.gen(function*() {
|
|
154
|
+
const env = yield* Config.string("env")
|
|
155
|
+
return env !== "prod"
|
|
156
|
+
})
|
|
157
|
+
.pipe(Effect.orDie)
|
|
155
158
|
|
|
156
159
|
export const makeRouter = <
|
|
157
160
|
Self,
|
|
@@ -191,14 +194,12 @@ export const makeRouter = <
|
|
|
191
194
|
> = (
|
|
192
195
|
req: S.Schema.Type<Action>
|
|
193
196
|
) => Generator<
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
GetEffectContext<RequestContextMap, Action["config"]> | ContextProviderA
|
|
201
|
-
>
|
|
197
|
+
Effect.Effect<
|
|
198
|
+
any,
|
|
199
|
+
S.Schema.Type<GetFailure<Action>> | S.SchemaError,
|
|
200
|
+
// the actual implementation of the handler may just require the dynamic context provided by the middleware
|
|
201
|
+
// and the per request context provided by the context provider
|
|
202
|
+
GetEffectContext<RequestContextMap, Action["config"]> | ContextProviderA
|
|
202
203
|
>,
|
|
203
204
|
GetSuccessShape<Action, RT>,
|
|
204
205
|
never
|
|
@@ -211,7 +212,7 @@ export const makeRouter = <
|
|
|
211
212
|
req: S.Schema.Type<Action>
|
|
212
213
|
) => Effect.Effect<
|
|
213
214
|
GetSuccessShape<Action, RT>,
|
|
214
|
-
S.Schema.Type<GetFailure<Action>> | S.
|
|
215
|
+
S.Schema.Type<GetFailure<Action>> | S.SchemaError,
|
|
215
216
|
// the actual implementation of the handler may just require the dynamic context provided by the middleware
|
|
216
217
|
// and the per request context provided by the context provider
|
|
217
218
|
GetEffectContext<RequestContextMap, Action["config"]> | ContextProviderA
|
|
@@ -222,7 +223,7 @@ export const makeRouter = <
|
|
|
222
223
|
RT extends RequestType
|
|
223
224
|
> = Effect.Effect<
|
|
224
225
|
GetSuccessShape<Action, RT>,
|
|
225
|
-
S.Schema.Type<GetFailure<Action>> | S.
|
|
226
|
+
S.Schema.Type<GetFailure<Action>> | S.SchemaError,
|
|
226
227
|
// the actual implementation of the handler may just require the dynamic context provided by the middleware
|
|
227
228
|
// and the per request context provided by the context provider
|
|
228
229
|
GetEffectContext<RequestContextMap, Action["config"]> | ContextProviderA
|
|
@@ -247,7 +248,7 @@ export const makeRouter = <
|
|
|
247
248
|
type RequestModules = FilterRequestModules<Resource>
|
|
248
249
|
const requestModules = typedKeysOf(rsc).reduce((acc, cur) => {
|
|
249
250
|
if (Predicate.isObject(rsc[cur]) && rsc[cur]["success"]) {
|
|
250
|
-
acc[cur as keyof RequestModules] = rsc[cur]
|
|
251
|
+
acc[cur as keyof RequestModules] = rsc[cur] as RequestModules[keyof RequestModules]
|
|
251
252
|
}
|
|
252
253
|
return acc
|
|
253
254
|
}, {} as RequestModules)
|
|
@@ -273,8 +274,8 @@ export const makeRouter = <
|
|
|
273
274
|
}
|
|
274
275
|
}, {
|
|
275
276
|
success: rsc[cur].success,
|
|
276
|
-
successRaw: S.
|
|
277
|
-
|
|
277
|
+
successRaw: S.toEncoded(rsc[cur].success),
|
|
278
|
+
error: rsc[cur].error,
|
|
278
279
|
raw: // "Raw" variations are for when you don't want to decode just to encode it again on the response
|
|
279
280
|
// e.g for direct projection from DB
|
|
280
281
|
// but more importantly, to skip Effectful decoders, like to resolve relationships from the database or remote client.
|
|
@@ -318,7 +319,7 @@ export const makeRouter = <
|
|
|
318
319
|
? Impl[K]["raw"] extends (...args: any[]) => Effect.Effect<any, any, infer R> ? R
|
|
319
320
|
: Impl[K]["raw"] extends Effect.Effect<any, any, infer R> ? R
|
|
320
321
|
: Impl[K]["raw"] extends (...args: any[]) => Generator<
|
|
321
|
-
|
|
322
|
+
Effect.Effect<any, any, infer R>,
|
|
322
323
|
any,
|
|
323
324
|
any
|
|
324
325
|
> ? R
|
|
@@ -326,7 +327,7 @@ export const makeRouter = <
|
|
|
326
327
|
: Impl[K] extends (...args: any[]) => Effect.Effect<any, any, infer R> ? R
|
|
327
328
|
: Impl[K] extends Effect.Effect<any, any, infer R> ? R
|
|
328
329
|
: Impl[K] extends (...args: any[]) => Generator<
|
|
329
|
-
|
|
330
|
+
Effect.Effect<any, any, infer R>,
|
|
330
331
|
any,
|
|
331
332
|
any
|
|
332
333
|
> ? R
|
|
@@ -350,14 +351,14 @@ export const makeRouter = <
|
|
|
350
351
|
// important to keep them separate via | for type checking!!
|
|
351
352
|
[K in keyof RequestModules]: AnyHandler<Resource[K]>
|
|
352
353
|
},
|
|
353
|
-
MakeDependencies extends NonEmptyReadonlyArray<Layer.
|
|
354
|
+
MakeDependencies extends NonEmptyReadonlyArray<Layer.Any> | never[]
|
|
354
355
|
>(
|
|
355
356
|
dependencies: MakeDependencies,
|
|
356
357
|
make: (
|
|
357
358
|
match: any
|
|
358
359
|
) =>
|
|
359
360
|
| Effect.Effect<THandlers, MakeE, MakeR>
|
|
360
|
-
| Generator<
|
|
361
|
+
| Generator<Yieldable<any, any, MakeE, MakeR>, THandlers, any>
|
|
361
362
|
) => {
|
|
362
363
|
const dependenciesL = (dependencies ? Layer.mergeAll(...dependencies as any) : Layer.empty) as Layer.Layer<
|
|
363
364
|
LayerUtils.GetLayersSuccess<MakeDependencies>,
|
|
@@ -381,21 +382,12 @@ export const makeRouter = <
|
|
|
381
382
|
acc[cur] = [
|
|
382
383
|
handler._tag === RequestTypes.RAW
|
|
383
384
|
? class extends (resource as any) {
|
|
384
|
-
static success = S.
|
|
385
|
-
get [Schema.symbolSerializable]() {
|
|
386
|
-
return this.constructor
|
|
387
|
-
}
|
|
388
|
-
get [Schema.symbolWithResult]() {
|
|
389
|
-
return {
|
|
390
|
-
failure: resource.failure,
|
|
391
|
-
success: S.encodedSchema(resource.success)
|
|
392
|
-
}
|
|
393
|
-
}
|
|
385
|
+
static success = S.toEncoded(resource.success)
|
|
394
386
|
} as any
|
|
395
387
|
: resource,
|
|
396
388
|
(payload: any, headers: any) =>
|
|
397
389
|
(handler.handler(payload, headers) as Effect.Effect<unknown, unknown, unknown>).pipe(
|
|
398
|
-
Effect.withSpan(`Request.${meta.moduleName}.${resource._tag}`, {
|
|
390
|
+
Effect.withSpan(`Request.${meta.moduleName}.${resource._tag}`, {}, {
|
|
399
391
|
captureStackTrace: () => handler.stack // capturing the handler stack is the main reason why we are doing the span here
|
|
400
392
|
})
|
|
401
393
|
)
|
|
@@ -408,11 +400,11 @@ export const makeRouter = <
|
|
|
408
400
|
req: any,
|
|
409
401
|
headers: HttpHeaders.Headers
|
|
410
402
|
) => Effect.Effect<
|
|
411
|
-
Effect.
|
|
412
|
-
| Effect.
|
|
403
|
+
Effect.Success<ReturnType<THandlers[K]["handler"]>>,
|
|
404
|
+
| Effect.Error<ReturnType<THandlers[K]["handler"]>>
|
|
413
405
|
| GetEffectError<RequestContextMap, Resource[K]["config"]>,
|
|
414
406
|
Exclude<
|
|
415
|
-
Effect.
|
|
407
|
+
Effect.Services<ReturnType<THandlers[K]["handler"]>>,
|
|
416
408
|
ContextProviderA | GetEffectContext<RequestContextMap, Resource[K]["config"]>
|
|
417
409
|
>
|
|
418
410
|
>
|
|
@@ -423,7 +415,7 @@ export const makeRouter = <
|
|
|
423
415
|
.make(
|
|
424
416
|
...typedValuesOf(mapped).map(([resource]) => {
|
|
425
417
|
return Rpc
|
|
426
|
-
.
|
|
418
|
+
.make(resource._tag, { payload: resource, success: resource.success, error: resource.failure })
|
|
427
419
|
.annotate(middleware.requestContext, resource.config ?? {})
|
|
428
420
|
})
|
|
429
421
|
)
|
|
@@ -443,7 +435,7 @@ export const makeRouter = <
|
|
|
443
435
|
>
|
|
444
436
|
|
|
445
437
|
return RpcServer
|
|
446
|
-
.
|
|
438
|
+
.layerHttp({
|
|
447
439
|
spanPrefix: "RpcServer." + meta.moduleName,
|
|
448
440
|
group: rpcs,
|
|
449
441
|
path: ("/rpc/" + meta.moduleName) as `/${typeof meta.moduleName}`,
|
|
@@ -451,7 +443,7 @@ export const makeRouter = <
|
|
|
451
443
|
})
|
|
452
444
|
.pipe(Layer.provide(rpc))
|
|
453
445
|
})
|
|
454
|
-
.pipe(Layer.
|
|
446
|
+
.pipe(Layer.unwrap)
|
|
455
447
|
|
|
456
448
|
const routes = layer.pipe(
|
|
457
449
|
Layer.provide([
|
|
@@ -470,7 +462,7 @@ export const makeRouter = <
|
|
|
470
462
|
}
|
|
471
463
|
return routes
|
|
472
464
|
})
|
|
473
|
-
.pipe(Layer.
|
|
465
|
+
.pipe(Layer.unwrap)
|
|
474
466
|
: routes
|
|
475
467
|
}
|
|
476
468
|
|
|
@@ -478,14 +470,13 @@ export const makeRouter = <
|
|
|
478
470
|
// Multiple times duplicated the "good" overload, so that errors will only mention the last overload when failing
|
|
479
471
|
<
|
|
480
472
|
const Make extends {
|
|
481
|
-
dependencies?: ReadonlyArray<Layer.
|
|
473
|
+
dependencies?: ReadonlyArray<Layer.Any>
|
|
482
474
|
effect: (match: typeof router3) => Generator<
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
>
|
|
475
|
+
Yieldable<
|
|
476
|
+
any,
|
|
477
|
+
any,
|
|
478
|
+
any,
|
|
479
|
+
any
|
|
489
480
|
>,
|
|
490
481
|
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> },
|
|
491
482
|
any
|
|
@@ -499,10 +490,10 @@ export const makeRouter = <
|
|
|
499
490
|
& Layer.Layer<
|
|
500
491
|
never,
|
|
501
492
|
| MakeErrors<Make>
|
|
502
|
-
|
|
|
503
|
-
| Layer.
|
|
504
|
-
|
|
|
505
|
-
| Layer.
|
|
493
|
+
| MakeDepsE<Make>
|
|
494
|
+
| Layer.Error<typeof middleware.Default>,
|
|
495
|
+
| MakeDepsIn<Make>
|
|
496
|
+
| Layer.Services<typeof middleware.Default>
|
|
506
497
|
| Exclude<
|
|
507
498
|
MakeContext<Make>,
|
|
508
499
|
MakeDepsOut<Make>
|
|
@@ -515,15 +506,16 @@ export const makeRouter = <
|
|
|
515
506
|
}
|
|
516
507
|
<
|
|
517
508
|
const Make extends {
|
|
518
|
-
dependencies?: ReadonlyArray<Layer.
|
|
509
|
+
dependencies?: ReadonlyArray<Layer.Any>
|
|
510
|
+
// v4: generators yield Yieldable with asEffect()
|
|
519
511
|
effect: (match: typeof router3) => Generator<
|
|
520
|
-
|
|
521
|
-
Effect.Effect<
|
|
512
|
+
{
|
|
513
|
+
asEffect(): Effect.Effect<
|
|
522
514
|
any,
|
|
523
515
|
any,
|
|
524
516
|
any
|
|
525
517
|
>
|
|
526
|
-
|
|
518
|
+
},
|
|
527
519
|
{ [K in keyof FilterRequestModules<Resource>]: AnyHandler<Resource[K]> },
|
|
528
520
|
any
|
|
529
521
|
>
|
|
@@ -534,10 +526,10 @@ export const makeRouter = <
|
|
|
534
526
|
& Layer.Layer<
|
|
535
527
|
never,
|
|
536
528
|
| MakeErrors<Make>
|
|
537
|
-
|
|
|
538
|
-
| Layer.
|
|
539
|
-
|
|
|
540
|
-
| Layer.
|
|
529
|
+
| MakeDepsE<Make>
|
|
530
|
+
| Layer.Error<typeof middleware.Default>,
|
|
531
|
+
| MakeDepsIn<Make>
|
|
532
|
+
| Layer.Services<typeof middleware.Default>
|
|
541
533
|
| Exclude<
|
|
542
534
|
MakeContext<Make>,
|
|
543
535
|
MakeDepsOut<Make>
|
|
@@ -566,8 +558,8 @@ export const makeRouter = <
|
|
|
566
558
|
|
|
567
559
|
return Layer.mergeAll(...routers as [any]) as unknown as Layer.Layer<
|
|
568
560
|
never,
|
|
569
|
-
Layer.
|
|
570
|
-
Layer.
|
|
561
|
+
Layer.Error<typeof handlers[keyof typeof handlers]>,
|
|
562
|
+
Layer.Services<typeof handlers[keyof typeof handlers]>
|
|
571
563
|
>
|
|
572
564
|
}
|
|
573
565
|
|
|
@@ -577,29 +569,35 @@ export const makeRouter = <
|
|
|
577
569
|
}
|
|
578
570
|
}
|
|
579
571
|
|
|
580
|
-
export type MakeDeps<Make> = Make extends { readonly dependencies: ReadonlyArray<Layer.
|
|
572
|
+
export type MakeDeps<Make> = Make extends { readonly dependencies: ReadonlyArray<Layer.Any> }
|
|
581
573
|
? Make["dependencies"][number]
|
|
582
574
|
: never
|
|
583
575
|
|
|
584
576
|
export type MakeErrors<Make> = /*Make extends { readonly effect: (_: any) => Effect.Effect<any, infer E, any> } ? E
|
|
585
577
|
: Make extends { readonly effect: (_: any) => Effect.Effect<any, never, any> } ? never
|
|
586
578
|
: */
|
|
587
|
-
|
|
588
|
-
|
|
579
|
+
// v4: generators yield Yieldable with asEffect()
|
|
580
|
+
Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, never, any>, any, any> } ? never
|
|
581
|
+
: Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, infer E, any>, any, any> } ? E
|
|
589
582
|
: never
|
|
590
583
|
|
|
591
584
|
export type MakeContext<Make> = /*Make extends { readonly effect: (_: any) => Effect.Effect<any, any, infer R> } ? R
|
|
592
585
|
: Make extends { readonly effect: (_: any) => Effect.Effect<any, any, never> } ? never
|
|
593
586
|
: */
|
|
594
|
-
|
|
595
|
-
|
|
587
|
+
// v4: generators yield Yieldable with asEffect()
|
|
588
|
+
Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, any, never>, any, any> } ? never
|
|
589
|
+
: Make extends { readonly effect: (_: any) => Generator<Yieldable<any, any, any, infer R>, any, any> } ? R
|
|
596
590
|
: never
|
|
597
591
|
|
|
598
592
|
export type MakeHandlers<Make, _Handlers extends Record<string, any>> = /*Make extends
|
|
599
593
|
{ readonly effect: (_: any) => Effect.Effect<{ [K in keyof Handlers]: AnyHandler<Handlers[K]> }, any, any> }
|
|
600
594
|
? Effect.Success<ReturnType<Make["effect"]>>
|
|
601
595
|
: */
|
|
602
|
-
Make extends { readonly effect: (_: any) => Generator<
|
|
596
|
+
Make extends { readonly effect: (_: any) => Generator<any, infer S, any> } ? S
|
|
603
597
|
: never
|
|
604
598
|
|
|
605
|
-
export type
|
|
599
|
+
export type MakeDepsE<Make> = Layer.Error<MakeDeps<Make>>
|
|
600
|
+
|
|
601
|
+
export type MakeDepsIn<Make> = Layer.Services<MakeDeps<Make>>
|
|
602
|
+
|
|
603
|
+
export type MakeDepsOut<Make> = Layer.Success<MakeDeps<Make>>
|
package/src/api/setupRequest.ts
CHANGED
|
@@ -7,8 +7,8 @@ import { storeId } from "../Store/Memory.js"
|
|
|
7
7
|
export const getRequestContext = Effect
|
|
8
8
|
.all({
|
|
9
9
|
span: Effect.currentSpan.pipe(Effect.orDie),
|
|
10
|
-
locale: LocaleRef,
|
|
11
|
-
namespace: storeId
|
|
10
|
+
locale: LocaleRef.asEffect(),
|
|
11
|
+
namespace: storeId.asEffect()
|
|
12
12
|
})
|
|
13
13
|
.pipe(
|
|
14
14
|
Effect.map(({ locale, namespace, span }) =>
|
|
@@ -22,8 +22,8 @@ export const getRequestContext = Effect
|
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
export const getRC = Effect.all({
|
|
25
|
-
locale: LocaleRef,
|
|
26
|
-
namespace: storeId
|
|
25
|
+
locale: LocaleRef.asEffect(),
|
|
26
|
+
namespace: storeId.asEffect()
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
const withRequestSpan = (name = "request", options?: Tracer.SpanOptions) => <R, E, A>(f: Effect.Effect<A, E, R>) =>
|
|
@@ -33,8 +33,9 @@ const withRequestSpan = (name = "request", options?: Tracer.SpanOptions) => <R,
|
|
|
33
33
|
f.pipe(
|
|
34
34
|
Effect.withSpan(name, {
|
|
35
35
|
...options,
|
|
36
|
-
attributes: { ...spanAttributes({ ...ctx, name: NonEmptyString255(name) }), ...options?.attributes }
|
|
37
|
-
|
|
36
|
+
attributes: { ...spanAttributes({ ...ctx, name: NonEmptyString255(name) }), ...options?.attributes }
|
|
37
|
+
}, {
|
|
38
|
+
captureStackTrace: options?.captureStackTrace ?? false
|
|
38
39
|
}),
|
|
39
40
|
// TODO: false
|
|
40
41
|
// request context info is picked up directly in the logger for annotations.
|
|
@@ -55,7 +56,7 @@ export function setupRequestContext<R, E, A>(self: Effect.Effect<A, E, R>, reque
|
|
|
55
56
|
const layer = Layer.mergeAll(
|
|
56
57
|
ContextMapContainer.layer,
|
|
57
58
|
Layer.succeed(LocaleRef, requestContext.locale),
|
|
58
|
-
Layer.succeed(storeId, requestContext.namespace)
|
|
59
|
+
Layer.succeed(storeId, NonEmptyString255(requestContext.namespace))
|
|
59
60
|
)
|
|
60
61
|
return self
|
|
61
62
|
.pipe(
|
|
@@ -73,7 +74,7 @@ export function setupRequestContextWithCustomSpan<R, E, A>(
|
|
|
73
74
|
const layer = Layer.mergeAll(
|
|
74
75
|
ContextMapContainer.layer,
|
|
75
76
|
Layer.succeed(LocaleRef, requestContext.locale),
|
|
76
|
-
Layer.succeed(storeId, requestContext.namespace)
|
|
77
|
+
Layer.succeed(storeId, NonEmptyString255(requestContext.namespace))
|
|
77
78
|
)
|
|
78
79
|
return self
|
|
79
80
|
.pipe(
|
package/src/arbs.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Do not import to frontend
|
|
2
2
|
|
|
3
3
|
import { faker } from "@faker-js/faker"
|
|
4
|
+
import { type S } from "effect-app"
|
|
4
5
|
import { setFaker } from "effect-app/faker"
|
|
5
|
-
import
|
|
6
|
-
import * as FastCheck from "effect/FastCheck"
|
|
6
|
+
import * as FastCheck from "effect/testing/FastCheck"
|
|
7
7
|
import { Random } from "fast-check"
|
|
8
8
|
import * as rand from "pure-rand"
|
|
9
9
|
|
|
@@ -15,6 +15,6 @@ export function generate<T>(arb: FastCheck.Arbitrary<T>) {
|
|
|
15
15
|
return arb.generate(rnd, undefined)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export function generateFromArbitrary<T>(arb:
|
|
18
|
+
export function generateFromArbitrary<T>(arb: S.LazyArbitrary<T>) {
|
|
19
19
|
return generate(arb(FastCheck))
|
|
20
20
|
}
|
package/src/errorReporter.ts
CHANGED
|
@@ -19,11 +19,11 @@ export function reportError(
|
|
|
19
19
|
return (
|
|
20
20
|
cause: Cause.Cause<unknown>,
|
|
21
21
|
extras?: Record<string, unknown>,
|
|
22
|
-
level: LogLevel.
|
|
22
|
+
level: LogLevel.Severity = "Error"
|
|
23
23
|
) =>
|
|
24
24
|
Effect
|
|
25
25
|
.gen(function*() {
|
|
26
|
-
if (Cause.
|
|
26
|
+
if (Cause.hasInterruptsOnly(cause)) {
|
|
27
27
|
yield* InfraLogger.logDebug("Interrupted").pipe(Effect.annotateLogs("extras", JSON.stringify(extras ?? {})))
|
|
28
28
|
return
|
|
29
29
|
}
|
|
@@ -41,16 +41,16 @@ export function reportError(
|
|
|
41
41
|
}))
|
|
42
42
|
)
|
|
43
43
|
.pipe(
|
|
44
|
-
Effect.
|
|
45
|
-
Effect.
|
|
44
|
+
Effect.catchCause((cause) => InfraLogger.logWarning("Failed to log error", cause)),
|
|
45
|
+
Effect.catchCause(() => InfraLogger.logFatal("Failed to log error cause"))
|
|
46
46
|
)
|
|
47
47
|
|
|
48
48
|
return error
|
|
49
49
|
})
|
|
50
50
|
.pipe(
|
|
51
|
-
Effect.
|
|
51
|
+
Effect.tapCause((cause) =>
|
|
52
52
|
InfraLogger.logError("Failed to report error", cause).pipe(
|
|
53
|
-
Effect.
|
|
53
|
+
Effect.tapCause(() => InfraLogger.logFatal("Failed to log error cause"))
|
|
54
54
|
)
|
|
55
55
|
)
|
|
56
56
|
)
|
|
@@ -64,10 +64,10 @@ function reportSentry(
|
|
|
64
64
|
return getRC.pipe(Effect.map((context) => {
|
|
65
65
|
const scope = new Sentry.Scope()
|
|
66
66
|
scope.setLevel(level)
|
|
67
|
-
if (context) scope.setContext("context", context
|
|
67
|
+
if (context) scope.setContext("context", { ...context })
|
|
68
68
|
if (extras) scope.setContext("extras", extras)
|
|
69
|
-
scope.setContext("error", tryToReport(error)
|
|
70
|
-
scope.setContext("cause", tryToJson(error.originalCause)
|
|
69
|
+
scope.setContext("error", { data: tryToReport(error) })
|
|
70
|
+
scope.setContext("cause", { data: tryToJson(error.originalCause) })
|
|
71
71
|
Sentry.captureException(error, scope)
|
|
72
72
|
}))
|
|
73
73
|
}
|
|
@@ -78,7 +78,7 @@ export function logError<E>(
|
|
|
78
78
|
return (cause: Cause.Cause<E>, extras?: Record<string, unknown>) =>
|
|
79
79
|
Effect
|
|
80
80
|
.gen(function*() {
|
|
81
|
-
if (Cause.
|
|
81
|
+
if (Cause.hasInterruptsOnly(cause)) {
|
|
82
82
|
yield* InfraLogger.logDebug("Interrupted").pipe(Effect.annotateLogs(dropUndefined({ extras })))
|
|
83
83
|
return
|
|
84
84
|
}
|
|
@@ -93,7 +93,7 @@ export function logError<E>(
|
|
|
93
93
|
)
|
|
94
94
|
})
|
|
95
95
|
.pipe(
|
|
96
|
-
Effect.
|
|
96
|
+
Effect.tapCause(() => InfraLogger.logFatal("Failed to log error cause"))
|
|
97
97
|
)
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -101,7 +101,7 @@ export function reportMessage(message: string, extras?: Record<string, unknown>)
|
|
|
101
101
|
return Effect.gen(function*() {
|
|
102
102
|
const context = yield* getRC
|
|
103
103
|
const scope = new Sentry.Scope()
|
|
104
|
-
if (context) scope.setContext("context", context
|
|
104
|
+
if (context) scope.setContext("context", { ...context })
|
|
105
105
|
if (extras) scope.setContext("extras", extras)
|
|
106
106
|
Sentry.captureMessage(message, scope)
|
|
107
107
|
|
package/src/logger/jsonLogger.ts
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Array, Cause, Logger } from "effect-app"
|
|
2
|
+
import { CurrentLogAnnotations, CurrentLogSpans } from "effect/References"
|
|
2
3
|
import { spanAttributes } from "../RequestContext.js"
|
|
3
|
-
import {
|
|
4
|
+
import { getRequestContextFromFiber } from "./shared.js"
|
|
4
5
|
|
|
5
6
|
export const jsonLogger = Logger.make<unknown, void>(
|
|
6
|
-
({
|
|
7
|
-
const
|
|
8
|
-
const nowMillis = now.getTime()
|
|
7
|
+
({ cause, date, fiber, logLevel, message }) => {
|
|
8
|
+
const nowMillis = date.getTime()
|
|
9
9
|
|
|
10
|
-
const request =
|
|
10
|
+
const request = getRequestContextFromFiber(fiber)
|
|
11
|
+
const spans = fiber.getRef(CurrentLogSpans)
|
|
12
|
+
const annotations = fiber.getRef(CurrentLogAnnotations)
|
|
11
13
|
|
|
12
14
|
const data = {
|
|
13
|
-
timestamp:
|
|
14
|
-
level: logLevel
|
|
15
|
-
fiber:
|
|
15
|
+
timestamp: date,
|
|
16
|
+
level: logLevel,
|
|
17
|
+
fiber: "#" + fiber.id,
|
|
16
18
|
message,
|
|
17
19
|
request: spanAttributes(request),
|
|
18
|
-
cause: cause !==
|
|
19
|
-
spans:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}, {} as Record<string, unknown>)
|
|
20
|
+
cause: cause !== Cause.empty ? Cause.pretty(cause) : undefined,
|
|
21
|
+
spans: Array.isReadonlyArrayNonEmpty(spans)
|
|
22
|
+
? spans.map(([label, startTime]) => ({ label, timing: nowMillis - startTime }))
|
|
23
|
+
: undefined,
|
|
24
|
+
annotations: Object.keys(annotations).length > 0
|
|
25
|
+
? annotations
|
|
25
26
|
: undefined
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -29,4 +30,4 @@ export const jsonLogger = Logger.make<unknown, void>(
|
|
|
29
30
|
}
|
|
30
31
|
)
|
|
31
32
|
|
|
32
|
-
export const logJson = Logger.
|
|
33
|
+
export const logJson = Logger.layer([jsonLogger])
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Logger } from "effect-app"
|
|
2
2
|
import { spanAttributes } from "../RequestContext.js"
|
|
3
|
-
import {
|
|
3
|
+
import { getRequestContextFromFiber } from "./shared.js"
|
|
4
4
|
|
|
5
5
|
export const logfmtLogger = Logger.make<unknown, void>(
|
|
6
|
-
(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (requestContext
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
])
|
|
6
|
+
(options) => {
|
|
7
|
+
const requestContext = getRequestContextFromFiber(options.fiber)
|
|
8
|
+
let formatted = Logger.formatLogFmt.log(options)
|
|
9
|
+
if (requestContext.name !== "_root_") {
|
|
10
|
+
for (const [key, value] of Object.entries(spanAttributes(requestContext))) {
|
|
11
|
+
formatted += ` ${key}=${JSON.stringify(String(value))}`
|
|
12
|
+
}
|
|
14
13
|
}
|
|
15
|
-
const formatted = Logger.logfmtLogger.log({ ..._, annotations })
|
|
16
14
|
globalThis.console.log(formatted)
|
|
17
15
|
}
|
|
18
16
|
)
|
|
19
17
|
|
|
20
|
-
export const logFmt = Logger.
|
|
18
|
+
export const logFmt = Logger.layer([logfmtLogger])
|
package/src/logger/shared.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Fiber, Option } from "effect-app"
|
|
2
2
|
import { NonEmptyString255 } from "effect-app/Schema"
|
|
3
|
-
import * as FiberRefs from "effect/FiberRefs"
|
|
4
3
|
import { LocaleRef, RequestContext } from "../RequestContext.js"
|
|
5
4
|
import { storeId } from "../Store/Memory.js"
|
|
6
5
|
|
|
7
|
-
export function
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const namespace = Context.get(context, storeId)
|
|
6
|
+
export function getRequestContextFromFiber(fiber: Fiber.Fiber<unknown, unknown>) {
|
|
7
|
+
const span = Option.fromNullishOr(fiber.currentSpan)
|
|
8
|
+
const locale = fiber.getRef(LocaleRef)
|
|
9
|
+
const namespace = fiber.getRef(storeId)
|
|
12
10
|
return new RequestContext({
|
|
13
|
-
span: Option.map(span,
|
|
11
|
+
span: Option.map(span, (s) => ({ spanId: s.spanId, traceId: s.traceId, sampled: s.sampled })).pipe(
|
|
14
12
|
Option.getOrElse(() => ({ spanId: "bogus", sampled: true, traceId: "bogus" }))
|
|
15
13
|
),
|
|
16
14
|
name: NonEmptyString255("_"),
|