@effect-app/infra 3.0.13 → 3.0.15
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 +15 -0
- package/dist/Emailer/service.d.ts +4 -4
- package/dist/Emailer/service.d.ts.map +1 -1
- package/dist/MainFiberSet.d.ts +6 -6
- package/dist/MainFiberSet.d.ts.map +1 -1
- package/dist/MainFiberSet.js +1 -1
- package/dist/Model/Repository/ext.d.ts +9 -9
- package/dist/Model/Repository/ext.d.ts.map +1 -1
- package/dist/Model/Repository/ext.js +1 -1
- package/dist/Model/Repository/internal/internal.d.ts +12 -12
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -1
- package/dist/Model/Repository/internal/internal.js +1 -1
- package/dist/Model/Repository/legacy.d.ts +6 -6
- package/dist/Model/Repository/legacy.d.ts.map +1 -1
- package/dist/Model/Repository/makeRepo.d.ts +2 -2
- package/dist/Model/Repository/makeRepo.d.ts.map +1 -1
- package/dist/Model/Repository/service.d.ts +5 -5
- package/dist/Model/Repository/service.d.ts.map +1 -1
- package/dist/Model/dsl.d.ts +14 -14
- package/dist/Model/dsl.d.ts.map +1 -1
- package/dist/Model/dsl.js +1 -1
- package/dist/Model/query/dsl.d.ts +1 -1
- package/dist/Model/query/dsl.d.ts.map +1 -1
- package/dist/Operations.d.ts +37 -37
- package/dist/Operations.d.ts.map +1 -1
- package/dist/Operations.js +1 -1
- package/dist/QueueMaker/SQLQueue.d.ts +1 -1
- package/dist/QueueMaker/SQLQueue.d.ts.map +1 -1
- package/dist/QueueMaker/SQLQueue.js +1 -1
- package/dist/QueueMaker/errors.d.ts +3 -3
- package/dist/QueueMaker/errors.d.ts.map +1 -1
- package/dist/QueueMaker/errors.js +1 -1
- package/dist/QueueMaker/memQueue.d.ts +1 -1
- package/dist/QueueMaker/memQueue.d.ts.map +1 -1
- package/dist/QueueMaker/memQueue.js +1 -1
- package/dist/QueueMaker/sbqueue.d.ts +1 -1
- package/dist/QueueMaker/sbqueue.d.ts.map +1 -1
- package/dist/QueueMaker/sbqueue.js +1 -1
- package/dist/QueueMaker/service.d.ts +2 -2
- package/dist/QueueMaker/service.d.ts.map +1 -1
- package/dist/RequestFiberSet.d.ts +17 -17
- package/dist/RequestFiberSet.d.ts.map +1 -1
- package/dist/RequestFiberSet.js +1 -1
- package/dist/Store/Cosmos.js +1 -1
- package/dist/Store/Disk.d.ts +1 -1
- package/dist/Store/Disk.d.ts.map +1 -1
- package/dist/Store/Disk.js +1 -1
- package/dist/Store/Memory.d.ts +2 -2
- package/dist/Store/Memory.d.ts.map +1 -1
- package/dist/Store/Memory.js +1 -1
- package/dist/Store/service.d.ts +12 -12
- package/dist/Store/service.d.ts.map +1 -1
- package/dist/Store/utils.d.ts +1 -1
- package/dist/Store/utils.d.ts.map +1 -1
- package/dist/Store/utils.js +1 -1
- package/dist/adapters/ServiceBus.d.ts +12 -12
- package/dist/adapters/ServiceBus.d.ts.map +1 -1
- package/dist/adapters/ServiceBus.js +1 -1
- package/dist/adapters/cosmos-client.d.ts +1 -1
- package/dist/adapters/cosmos-client.d.ts.map +1 -1
- package/dist/adapters/mongo-client.d.ts +1 -1
- package/dist/adapters/mongo-client.d.ts.map +1 -1
- package/dist/adapters/redis-client.d.ts +4 -4
- package/dist/adapters/redis-client.d.ts.map +1 -1
- package/dist/adapters/redis-client.js +1 -1
- package/dist/api/ContextProvider.d.ts +5 -5
- package/dist/api/ContextProvider.d.ts.map +1 -1
- package/dist/api/internal/middlewares.d.ts +1 -1
- package/dist/api/internal/middlewares.d.ts.map +1 -1
- package/dist/api/internal/middlewares.js +1 -1
- package/dist/api/layerUtils.d.ts +1 -1
- package/dist/api/layerUtils.d.ts.map +1 -1
- package/dist/api/layerUtils.js +1 -1
- package/dist/api/middlewares.d.ts +1 -1
- package/dist/api/middlewares.d.ts.map +1 -1
- package/dist/api/reportError.d.ts +2 -2
- package/dist/api/reportError.d.ts.map +1 -1
- package/dist/api/reportError.js +2 -2
- package/dist/api/routing/middleware/RouterMiddleware.d.ts +1 -1
- package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +1 -1
- package/dist/api/routing.d.ts +22 -22
- package/dist/api/routing.d.ts.map +1 -1
- package/dist/api/routing.js +1 -1
- package/dist/api/setupRequest.d.ts +3 -3
- package/dist/api/setupRequest.d.ts.map +1 -1
- package/dist/api/setupRequest.js +1 -1
- package/dist/errorReporter.d.ts +2 -2
- package/dist/errorReporter.d.ts.map +1 -1
- package/dist/errorReporter.js +1 -1
- package/dist/rateLimit.d.ts +4 -4
- package/dist/rateLimit.d.ts.map +1 -1
- package/dist/rateLimit.js +4 -4
- package/package.json +2 -2
- package/src/Emailer/service.ts +1 -1
- package/src/MainFiberSet.ts +4 -3
- package/src/Model/Repository/ext.ts +13 -13
- package/src/Model/Repository/internal/internal.ts +13 -13
- package/src/Model/Repository/legacy.ts +6 -6
- package/src/Model/Repository/makeRepo.ts +2 -2
- package/src/Model/Repository/service.ts +5 -5
- package/src/Model/dsl.ts +25 -22
- package/src/Model/query/dsl.ts +1 -1
- package/src/Operations.ts +20 -20
- package/src/QueueMaker/SQLQueue.ts +1 -1
- package/src/QueueMaker/errors.ts +4 -4
- package/src/QueueMaker/memQueue.ts +1 -1
- package/src/QueueMaker/sbqueue.ts +1 -1
- package/src/QueueMaker/service.ts +3 -3
- package/src/RequestFiberSet.ts +9 -8
- package/src/Store/Cosmos.ts +1 -1
- package/src/Store/Disk.ts +2 -2
- package/src/Store/Memory.ts +2 -2
- package/src/Store/service.ts +10 -10
- package/src/Store/utils.ts +1 -1
- package/src/adapters/ServiceBus.ts +14 -10
- package/src/adapters/cosmos-client.ts +1 -1
- package/src/adapters/mongo-client.ts +1 -1
- package/src/adapters/redis-client.ts +4 -4
- package/src/api/ContextProvider.ts +11 -11
- package/src/api/internal/middlewares.ts +1 -1
- package/src/api/layerUtils.ts +9 -2
- package/src/api/middlewares.ts +1 -1
- package/src/api/reportError.ts +2 -2
- package/src/api/routing/middleware/RouterMiddleware.ts +1 -1
- package/src/api/routing.ts +42 -39
- package/src/api/setupRequest.ts +4 -4
- package/src/errorReporter.ts +3 -3
- package/src/rateLimit.ts +12 -12
- package/test/controller.test.ts +3 -8
- package/test/dist/controller.test.d.ts.map +1 -1
- package/test/dist/fixtures.d.ts +1 -1
- package/test/requires.test.ts +1 -1
package/src/RequestFiberSet.ts
CHANGED
|
@@ -14,7 +14,7 @@ const getRootParentSpan = Effect.gen(function*() {
|
|
|
14
14
|
return span
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
export const setRootParentSpan = <A, E, R>(self: Effect<A, E, R>) =>
|
|
17
|
+
export const setRootParentSpan = <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
18
18
|
getRootParentSpan.pipe(Effect.andThen((span) => span ? Effect.withParentSpan(self, span) : self))
|
|
19
19
|
|
|
20
20
|
const make = Effect.gen(function*() {
|
|
@@ -28,7 +28,7 @@ const make = Effect.gen(function*() {
|
|
|
28
28
|
Effect.andThen(FiberSet.join(set))
|
|
29
29
|
)
|
|
30
30
|
const run = FiberSet.run(set)
|
|
31
|
-
const register = <A, E, R>(self: Effect<A, E, R>) =>
|
|
31
|
+
const register = <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
32
32
|
self.pipe(Effect.fork, Effect.tap(add), Effect.andThen(Fiber.join))
|
|
33
33
|
|
|
34
34
|
// const waitUntilEmpty = Effect.gen(function*() {
|
|
@@ -51,7 +51,7 @@ const make = Effect.gen(function*() {
|
|
|
51
51
|
*
|
|
52
52
|
* Reports errors.
|
|
53
53
|
*/
|
|
54
|
-
function forkDaemonReport<R, E, A>(self: Effect<A, E, R>) {
|
|
54
|
+
function forkDaemonReport<R, E, A>(self: Effect.Effect<A, E, R>) {
|
|
55
55
|
return self.pipe(
|
|
56
56
|
reportRequestError,
|
|
57
57
|
Effect.uninterruptible,
|
|
@@ -67,7 +67,7 @@ const make = Effect.gen(function*() {
|
|
|
67
67
|
*
|
|
68
68
|
* Reports unexpected errors.
|
|
69
69
|
*/
|
|
70
|
-
function forkDaemonReportUnexpected<R, E, A>(self: Effect<A, E, R>) {
|
|
70
|
+
function forkDaemonReportUnexpected<R, E, A>(self: Effect.Effect<A, E, R>) {
|
|
71
71
|
return self
|
|
72
72
|
.pipe(
|
|
73
73
|
reportUnknownRequestError,
|
|
@@ -94,9 +94,10 @@ const make = Effect.gen(function*() {
|
|
|
94
94
|
*/
|
|
95
95
|
export class RequestFiberSet extends Context.TagMakeId("RequestFiberSet", make)<RequestFiberSet>() {
|
|
96
96
|
static readonly Live = this.toLayerScoped()
|
|
97
|
-
static readonly register = <A, E, R>(self: Effect<A, E, R>) => this.use((_) => _.register(self))
|
|
98
|
-
static readonly run = <A, E, R>(self: Effect<A, E, R>) => this.use((_) => _.run(self))
|
|
99
|
-
static readonly forkDaemonReport = <R, E, A>(self: Effect<A, E, R>) =>
|
|
100
|
-
|
|
97
|
+
static readonly register = <A, E, R>(self: Effect.Effect<A, E, R>) => this.use((_) => _.register(self))
|
|
98
|
+
static readonly run = <A, E, R>(self: Effect.Effect<A, E, R>) => this.use((_) => _.run(self))
|
|
99
|
+
static readonly forkDaemonReport = <R, E, A>(self: Effect.Effect<A, E, R>) =>
|
|
100
|
+
this.use((_) => _.forkDaemonReport(self))
|
|
101
|
+
static readonly forkDaemonReportUnexpected = <R, E, A>(self: Effect.Effect<A, E, R>) =>
|
|
101
102
|
this.use((_) => _.forkDaemonReportUnexpected(self))
|
|
102
103
|
}
|
package/src/Store/Cosmos.ts
CHANGED
|
@@ -32,7 +32,7 @@ function makeCosmosStore({ prefix }: StorageConfig) {
|
|
|
32
32
|
make: <IdKey extends keyof Encoded, Encoded extends FieldValues, R = never, E = never>(
|
|
33
33
|
name: string,
|
|
34
34
|
idKey: IdKey,
|
|
35
|
-
seed?: Effect<Iterable<Encoded>, E, R>,
|
|
35
|
+
seed?: Effect.Effect<Iterable<Encoded>, E, R>,
|
|
36
36
|
config?: StoreConfig<Encoded>
|
|
37
37
|
) =>
|
|
38
38
|
Effect.gen(function*() {
|
package/src/Store/Disk.ts
CHANGED
|
@@ -14,7 +14,7 @@ function makeDiskStoreInt<IdKey extends keyof Encoded, Encoded extends FieldValu
|
|
|
14
14
|
namespace: string,
|
|
15
15
|
dir: string,
|
|
16
16
|
name: string,
|
|
17
|
-
seed?: Effect<Iterable<Encoded>, E, R>,
|
|
17
|
+
seed?: Effect.Effect<Iterable<Encoded>, E, R>,
|
|
18
18
|
defaultValues?: Partial<Encoded>
|
|
19
19
|
) {
|
|
20
20
|
type PM = PersistenceModelType<Encoded>
|
|
@@ -126,7 +126,7 @@ export function makeDiskStore({ prefix }: StorageConfig, dir: string) {
|
|
|
126
126
|
make: <IdKey extends keyof Encoded, Encoded extends FieldValues, R, E>(
|
|
127
127
|
name: string,
|
|
128
128
|
idKey: IdKey,
|
|
129
|
-
seed?: Effect<Iterable<Encoded>, E, R>,
|
|
129
|
+
seed?: Effect.Effect<Iterable<Encoded>, E, R>,
|
|
130
130
|
config?: StoreConfig<Encoded>
|
|
131
131
|
) =>
|
|
132
132
|
Effect.gen(function*() {
|
package/src/Store/Memory.ts
CHANGED
|
@@ -97,7 +97,7 @@ export function makeMemoryStoreInt<IdKey extends keyof Encoded, Encoded extends
|
|
|
97
97
|
modelName: string,
|
|
98
98
|
idKey: IdKey,
|
|
99
99
|
namespace: string,
|
|
100
|
-
seed?: Effect<Iterable<Encoded>, E, R>,
|
|
100
|
+
seed?: Effect.Effect<Iterable<Encoded>, E, R>,
|
|
101
101
|
_defaultValues?: Partial<Encoded>
|
|
102
102
|
) {
|
|
103
103
|
type PM = PersistenceModelType<Encoded>
|
|
@@ -243,7 +243,7 @@ export const makeMemoryStore = () => ({
|
|
|
243
243
|
make: <IdKey extends keyof Encoded, Encoded extends FieldValues, R, E>(
|
|
244
244
|
modelName: string,
|
|
245
245
|
idKey: IdKey,
|
|
246
|
-
seed?: Effect<Iterable<Encoded>, E, R>,
|
|
246
|
+
seed?: Effect.Effect<Iterable<Encoded>, E, R>,
|
|
247
247
|
config?: StoreConfig<Encoded>
|
|
248
248
|
) =>
|
|
249
249
|
Effect.gen(function*() {
|
package/src/Store/service.ts
CHANGED
|
@@ -68,38 +68,38 @@ export interface FilterArgs<Encoded extends FieldValues, U extends keyof Encoded
|
|
|
68
68
|
|
|
69
69
|
export type FilterFunc<Encoded extends FieldValues> = <U extends keyof Encoded = never>(
|
|
70
70
|
args: FilterArgs<Encoded, U>
|
|
71
|
-
) => Effect<(U extends undefined ? Encoded : Pick<Encoded, U>)[]>
|
|
71
|
+
) => Effect.Effect<(U extends undefined ? Encoded : Pick<Encoded, U>)[]>
|
|
72
72
|
|
|
73
73
|
export interface Store<
|
|
74
74
|
IdKey extends keyof Encoded,
|
|
75
75
|
Encoded extends FieldValues,
|
|
76
76
|
PM extends PersistenceModelType<Encoded> = PersistenceModelType<Encoded>
|
|
77
77
|
> {
|
|
78
|
-
all: Effect<PM[]>
|
|
78
|
+
all: Effect.Effect<PM[]>
|
|
79
79
|
filter: FilterFunc<Encoded>
|
|
80
|
-
find: (id: Encoded[IdKey]) => Effect<Option<PM>>
|
|
81
|
-
set: (e: PM) => Effect<PM, OptimisticConcurrencyException>
|
|
80
|
+
find: (id: Encoded[IdKey]) => Effect.Effect<Option.Option<PM>>
|
|
81
|
+
set: (e: PM) => Effect.Effect<PM, OptimisticConcurrencyException>
|
|
82
82
|
batchSet: (
|
|
83
83
|
items: NonEmptyReadonlyArray<PM>
|
|
84
|
-
) => Effect<NonEmptyReadonlyArray<PM>, OptimisticConcurrencyException>
|
|
84
|
+
) => Effect.Effect<NonEmptyReadonlyArray<PM>, OptimisticConcurrencyException>
|
|
85
85
|
bulkSet: (
|
|
86
86
|
items: NonEmptyReadonlyArray<PM>
|
|
87
|
-
) => Effect<NonEmptyReadonlyArray<PM>, OptimisticConcurrencyException>
|
|
87
|
+
) => Effect.Effect<NonEmptyReadonlyArray<PM>, OptimisticConcurrencyException>
|
|
88
88
|
/**
|
|
89
89
|
* Requires the Encoded type, not Id, because various stores may need to calculate e.g partition keys.
|
|
90
90
|
*/
|
|
91
|
-
remove: (e: Encoded) => Effect<void>
|
|
91
|
+
remove: (e: Encoded) => Effect.Effect<void>
|
|
92
92
|
|
|
93
|
-
queryRaw: <Out>(query: RawQuery<Encoded, Out>) => Effect<readonly Out[]>
|
|
93
|
+
queryRaw: <Out>(query: RawQuery<Encoded, Out>) => Effect.Effect<readonly Out[]>
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
export class StoreMaker extends Context.TagId("effect-app/StoreMaker")<StoreMaker, {
|
|
97
97
|
make: <IdKey extends keyof Encoded, Encoded extends FieldValues, R = never, E = never>(
|
|
98
98
|
name: string,
|
|
99
99
|
idKey: IdKey,
|
|
100
|
-
seed?: Effect<Iterable<Encoded>, E, R>,
|
|
100
|
+
seed?: Effect.Effect<Iterable<Encoded>, E, R>,
|
|
101
101
|
config?: StoreConfig<Encoded>
|
|
102
|
-
) => Effect<Store<IdKey, Encoded>, E, R>
|
|
102
|
+
) => Effect.Effect<Store<IdKey, Encoded>, E, R>
|
|
103
103
|
}>() {
|
|
104
104
|
}
|
|
105
105
|
|
package/src/Store/utils.ts
CHANGED
|
@@ -14,7 +14,7 @@ export const makeETag = <E extends PersistenceModelType<{}>>(
|
|
|
14
14
|
|
|
15
15
|
export const makeUpdateETag =
|
|
16
16
|
(type: string) =>
|
|
17
|
-
<IdKey extends keyof E, E extends PersistenceModelType<{}>>(e: E, idKey: IdKey, current: Option<E>) =>
|
|
17
|
+
<IdKey extends keyof E, E extends PersistenceModelType<{}>>(e: E, idKey: IdKey, current: Option.Option<E>) =>
|
|
18
18
|
Effect.gen(function*() {
|
|
19
19
|
if (e._etag) {
|
|
20
20
|
yield* Effect.mapError(
|
|
@@ -3,7 +3,7 @@ import { type OperationOptionsBase, type ProcessErrorArgs, ServiceBusClient, typ
|
|
|
3
3
|
import { Cause, Context, Effect, Exit, FiberSet, Layer, type Scope } from "effect-app"
|
|
4
4
|
import { InfraLogger } from "../logger.js"
|
|
5
5
|
|
|
6
|
-
const withSpanAndLog = (name: string) => <A, E, R>(self: Effect<A, E, R>) =>
|
|
6
|
+
const withSpanAndLog = (name: string) => <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
7
7
|
Effect.logInfo(name).pipe(
|
|
8
8
|
Effect.zipRight(self),
|
|
9
9
|
Effect.tap(Effect.logInfo(name + " done")),
|
|
@@ -77,7 +77,7 @@ const makeReceiver = (name: string) =>
|
|
|
77
77
|
const serviceBusClient = yield* ServiceBusClientTag
|
|
78
78
|
|
|
79
79
|
const makeReceiver = Effect.fnUntraced(
|
|
80
|
-
function*(queueName: string, waitTillEmpty: Effect<void>, sessionId?: string) {
|
|
80
|
+
function*(queueName: string, waitTillEmpty: Effect.Effect<void>, sessionId?: string) {
|
|
81
81
|
return yield* Effect.acquireRelease(
|
|
82
82
|
(sessionId
|
|
83
83
|
? Effect.promise(() => serviceBusClient.acceptSession(queueName, sessionId))
|
|
@@ -97,9 +97,10 @@ const makeReceiver = (name: string) =>
|
|
|
97
97
|
}
|
|
98
98
|
)
|
|
99
99
|
|
|
100
|
-
const make = (waitTillEmpty: Effect<void>) => makeReceiver(name, waitTillEmpty)
|
|
100
|
+
const make = (waitTillEmpty: Effect.Effect<void>) => makeReceiver(name, waitTillEmpty)
|
|
101
101
|
|
|
102
|
-
const makeSession = (sessionId: string, waitTillEmpty: Effect<void>) =>
|
|
102
|
+
const makeSession = (sessionId: string, waitTillEmpty: Effect.Effect<void>) =>
|
|
103
|
+
makeReceiver(name, waitTillEmpty, sessionId)
|
|
103
104
|
|
|
104
105
|
return {
|
|
105
106
|
name,
|
|
@@ -122,7 +123,7 @@ const makeReceiver = (name: string) =>
|
|
|
122
123
|
)
|
|
123
124
|
: make(wait)
|
|
124
125
|
|
|
125
|
-
const runEffect = <E>(effect: Effect<void, E, RMsg | RErr>) =>
|
|
126
|
+
const runEffect = <E>(effect: Effect.Effect<void, E, RMsg | RErr>) =>
|
|
126
127
|
new Promise<void>((resolve, reject) =>
|
|
127
128
|
fr(effect)
|
|
128
129
|
.addObserver((exit) => {
|
|
@@ -158,15 +159,18 @@ const makeReceiver = (name: string) =>
|
|
|
158
159
|
subscription.close.pipe(
|
|
159
160
|
withSpanAndLog(`ServiceBus.subscription.close ${sessionId}`)
|
|
160
161
|
)
|
|
161
|
-
) as Effect<void, never, Scope> // wth is going on here
|
|
162
|
+
) as Effect.Effect<void, never, Scope.Scope> // wth is going on here
|
|
162
163
|
})
|
|
163
164
|
}
|
|
164
165
|
})
|
|
165
166
|
|
|
166
167
|
export class Receiver extends Context.TagId("Receiver")<Receiver, {
|
|
167
168
|
name: string
|
|
168
|
-
make: (waitTillEmpty: Effect<void>) => Effect<ServiceBusReceiver, never, Scope>
|
|
169
|
-
makeSession: (
|
|
169
|
+
make: (waitTillEmpty: Effect.Effect<void>) => Effect.Effect<ServiceBusReceiver, never, Scope.Scope>
|
|
170
|
+
makeSession: (
|
|
171
|
+
sessionId: string,
|
|
172
|
+
waitTillEmpty: Effect.Effect<void>
|
|
173
|
+
) => Effect.Effect<ServiceBusReceiver, never, Scope.Scope>
|
|
170
174
|
subscribe<RMsg, RErr>(
|
|
171
175
|
hndlr: MessageHandlers<RMsg, RErr>,
|
|
172
176
|
sessionId?: string
|
|
@@ -195,11 +199,11 @@ export interface MessageHandlers<RMsg, RErr> {
|
|
|
195
199
|
*
|
|
196
200
|
* @param message - A message received from Service Bus.
|
|
197
201
|
*/
|
|
198
|
-
processMessage(message: ServiceBusReceivedMessage): Effect<void, never, RMsg>
|
|
202
|
+
processMessage(message: ServiceBusReceivedMessage): Effect.Effect<void, never, RMsg>
|
|
199
203
|
/**
|
|
200
204
|
* Handler that processes errors that occur during receiving.
|
|
201
205
|
* @param args - The error and additional context to indicate where
|
|
202
206
|
* the error originated.
|
|
203
207
|
*/
|
|
204
|
-
processError(args: ProcessErrorArgs): Effect<void, never, RErr>
|
|
208
|
+
processError(args: ProcessErrorArgs): Effect.Effect<void, never, RErr>
|
|
205
209
|
}
|
|
@@ -6,7 +6,7 @@ const withClient = (url: string) => Effect.sync(() => new ComosClient_(url))
|
|
|
6
6
|
export const makeCosmosClient = (url: string, dbName: string) =>
|
|
7
7
|
Effect.map(withClient(url), (x) => ({ db: x.database(dbName) }))
|
|
8
8
|
|
|
9
|
-
export interface CosmosClient extends Effect.Success<ReturnType<typeof makeCosmosClient>> {}
|
|
9
|
+
export interface CosmosClient extends Effect.Effect.Success<ReturnType<typeof makeCosmosClient>> {}
|
|
10
10
|
|
|
11
11
|
export const CosmosClient = Context.GenericTag<CosmosClient>("@services/CosmosClient")
|
|
12
12
|
|
|
@@ -15,7 +15,7 @@ const withClient = (url: string) =>
|
|
|
15
15
|
|
|
16
16
|
const makeMongoClient = (url: string, dbName?: string) => Effect.map(withClient(url), (x) => ({ db: x.db(dbName) }))
|
|
17
17
|
|
|
18
|
-
export interface MongoClient extends Effect.Success<ReturnType<typeof makeMongoClient>> {}
|
|
18
|
+
export interface MongoClient extends Effect.Effect.Success<ReturnType<typeof makeMongoClient>> {}
|
|
19
19
|
|
|
20
20
|
export const MongoClient = Context.GenericTag<MongoClient>("@services/MongoClient")
|
|
21
21
|
|
|
@@ -17,7 +17,7 @@ export const makeRedisClient = (makeClient: () => Client) =>
|
|
|
17
17
|
|
|
18
18
|
function get(key: string) {
|
|
19
19
|
return Effect
|
|
20
|
-
.async<Option<string>, ConnectionException>((res) => {
|
|
20
|
+
.async<Option.Option<string>, ConnectionException>((res) => {
|
|
21
21
|
client.get(key, (err, v) =>
|
|
22
22
|
err
|
|
23
23
|
? res(new ConnectionException(err))
|
|
@@ -50,7 +50,7 @@ export const makeRedisClient = (makeClient: () => Client) =>
|
|
|
50
50
|
|
|
51
51
|
function hget(key: string, field: string) {
|
|
52
52
|
return Effect
|
|
53
|
-
.async<Option<string>, ConnectionException>((res) => {
|
|
53
|
+
.async<Option.Option<string>, ConnectionException>((res) => {
|
|
54
54
|
client.hget(key, field, (err, v) =>
|
|
55
55
|
err
|
|
56
56
|
? res(new ConnectionException(err))
|
|
@@ -60,7 +60,7 @@ export const makeRedisClient = (makeClient: () => Client) =>
|
|
|
60
60
|
}
|
|
61
61
|
function hmgetAll(key: string) {
|
|
62
62
|
return Effect
|
|
63
|
-
.async<Option<{ [key: string]: string }>, ConnectionException>(
|
|
63
|
+
.async<Option.Option<{ [key: string]: string }>, ConnectionException>(
|
|
64
64
|
(res) => {
|
|
65
65
|
client.hgetall(key, (err, v) =>
|
|
66
66
|
err
|
|
@@ -90,7 +90,7 @@ export const makeRedisClient = (makeClient: () => Client) =>
|
|
|
90
90
|
.pipe(Effect.uninterruptible, Effect.orDie)
|
|
91
91
|
)
|
|
92
92
|
|
|
93
|
-
export interface RedisClient extends Effect.Success<ReturnType<typeof makeRedisClient>> {}
|
|
93
|
+
export interface RedisClient extends Effect.Effect.Success<ReturnType<typeof makeRedisClient>> {}
|
|
94
94
|
|
|
95
95
|
export const RedisClient = Context.GenericTag<RedisClient>("@services/RedisClient")
|
|
96
96
|
|
|
@@ -8,7 +8,7 @@ import { type YieldWrap } from "effect/Utils"
|
|
|
8
8
|
import { type ContextTagWithDefault, type GetContext, type LayerUtils, mergeContexts } from "./layerUtils.js"
|
|
9
9
|
|
|
10
10
|
// // the context provider provides additional stuff
|
|
11
|
-
// export type ContextProviderShape<ContextProviderA, ContextProviderR> = Effect<
|
|
11
|
+
// export type ContextProviderShape<ContextProviderA, ContextProviderR> = Effect.Effect<
|
|
12
12
|
// Context.Context<ContextProviderA>,
|
|
13
13
|
// never, // no errors are allowed
|
|
14
14
|
// ContextProviderR
|
|
@@ -18,7 +18,7 @@ export interface ContextProviderId {
|
|
|
18
18
|
_tag: "ContextProvider"
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
// ContextTagWithDefault.Base<Effect<Context.Context<infer _1>, never, infer _R> & { _tag: infer _2 }>
|
|
21
|
+
// ContextTagWithDefault.Base<Effect.Effect<Context.Context<infer _1>, never, infer _R> & { _tag: infer _2 }>
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* TDeps is an array of services with Default implementation
|
|
@@ -26,15 +26,15 @@ export interface ContextProviderId {
|
|
|
26
26
|
*/
|
|
27
27
|
type TDepsArr<TDeps extends ReadonlyArray<any>> = {
|
|
28
28
|
// the following freaking shit helps me with nested variance issues: it wasn't sufficient to use never/any/unknown for
|
|
29
|
-
// the various type parameters, not anymore because of () => Generator<YieldWrap<Effect craziness
|
|
29
|
+
// the various type parameters, not anymore because of () => Generator<YieldWrap<Effect.Effect craziness
|
|
30
30
|
// existential types may help, and all the following usages of infer _ have that meaning: I do not care which is the
|
|
31
31
|
// actual type in that position, I just wanna set the overall structure
|
|
32
32
|
[K in keyof TDeps]: TDeps[K] extends //
|
|
33
33
|
// E = never => the context provided cannot trigger errors
|
|
34
|
-
// TODO: remove HttpLayerRouter.Provided - it's not even relevant outside of Http context, while ContextProviders are for anywhere. Only support Scope?
|
|
34
|
+
// TODO: remove HttpLayerRouter.Provided - it's not even relevant outside of Http context, while ContextProviders are for anywhere. Only support Scope.Scope?
|
|
35
35
|
// _R extends HttpLayerRouter.Provided => the context provided can only have what HttpLayerRouter.Provided provides as requirements
|
|
36
36
|
(
|
|
37
|
-
ContextTagWithDefault.Base<Effect<Context.Context<infer _1>, never, infer _R> & { _tag: infer _2 }>
|
|
37
|
+
ContextTagWithDefault.Base<Effect.Effect<Context.Context<infer _1>, never, infer _R> & { _tag: infer _2 }>
|
|
38
38
|
) ? [_R] extends [HttpLayerRouter.Provided] ? TDeps[K]
|
|
39
39
|
: `HttpLayerRouter.Provided is the only requirement ${TDeps[K]["Service"][
|
|
40
40
|
"_tag"
|
|
@@ -50,7 +50,7 @@ type TDepsArr<TDeps extends ReadonlyArray<any>> = {
|
|
|
50
50
|
>
|
|
51
51
|
) // [_YW] extends [never] if no yield* is used and just some context is returned
|
|
52
52
|
? [_YW] extends [never] ? TDeps[K]
|
|
53
|
-
: [_YW] extends [YieldWrap<Effect<infer _2, never, infer _R>>]
|
|
53
|
+
: [_YW] extends [YieldWrap<Effect.Effect<infer _2, never, infer _R>>]
|
|
54
54
|
? [_R] extends [HttpLayerRouter.Provided] ? TDeps[K]
|
|
55
55
|
: `HttpLayerRouter.Provided is the only requirement ${TDeps[K]["Service"][
|
|
56
56
|
"_tag"
|
|
@@ -106,22 +106,22 @@ export const ContextProvider = <
|
|
|
106
106
|
Dependencies extends NonEmptyReadonlyArray<Layer.Layer.Any>
|
|
107
107
|
>(
|
|
108
108
|
input: {
|
|
109
|
-
effect: Effect<
|
|
110
|
-
| Effect<ContextProviderA, never, ContextProviderR>
|
|
109
|
+
effect: Effect.Effect<
|
|
110
|
+
| Effect.Effect<ContextProviderA, never, ContextProviderR>
|
|
111
111
|
| (() => Generator<
|
|
112
|
-
YieldWrap<Effect<any, never, ContextProviderR>>,
|
|
112
|
+
YieldWrap<Effect.Effect<any, never, ContextProviderR>>,
|
|
113
113
|
ContextProviderA,
|
|
114
114
|
any
|
|
115
115
|
>),
|
|
116
116
|
MakeContextProviderE,
|
|
117
|
-
MakeContextProviderR | Scope
|
|
117
|
+
MakeContextProviderR | Scope.Scope
|
|
118
118
|
>
|
|
119
119
|
dependencies?: Dependencies
|
|
120
120
|
}
|
|
121
121
|
) => {
|
|
122
122
|
const ctx = Context.GenericTag<
|
|
123
123
|
ContextProviderId,
|
|
124
|
-
Effect<ContextProviderA, never, ContextProviderR>
|
|
124
|
+
Effect.Effect<ContextProviderA, never, ContextProviderR>
|
|
125
125
|
>(
|
|
126
126
|
"ContextProvider"
|
|
127
127
|
)
|
|
@@ -89,7 +89,7 @@ const toServerResponse = (err: NotLoggedInError) =>
|
|
|
89
89
|
export const basicAuth = <_, R>(
|
|
90
90
|
checkCredentials: (
|
|
91
91
|
credentials: Middlewares.BasicAuthCredentials
|
|
92
|
-
) => Effect<_, NotLoggedInError, R>,
|
|
92
|
+
) => Effect.Effect<_, NotLoggedInError, R>,
|
|
93
93
|
options?: Partial<{
|
|
94
94
|
headerName: string
|
|
95
95
|
skipPaths: readonly string[]
|
package/src/api/layerUtils.ts
CHANGED
|
@@ -39,7 +39,14 @@ export namespace ContextTagWithDefault {
|
|
|
39
39
|
export type GetContext<T> = T extends Context.Context<infer Y> ? Y : never
|
|
40
40
|
|
|
41
41
|
export const mergeContexts = Effect.fnUntraced(
|
|
42
|
-
function*<
|
|
42
|
+
function*<
|
|
43
|
+
T extends readonly {
|
|
44
|
+
maker: any
|
|
45
|
+
handle: Effect.Effect<Context.Context<any> | Option.Option<Context.Context<any>>>
|
|
46
|
+
}[]
|
|
47
|
+
>(
|
|
48
|
+
makers: T
|
|
49
|
+
) {
|
|
43
50
|
let context = Context.empty()
|
|
44
51
|
for (const mw of makers) {
|
|
45
52
|
const ctx = yield* mw.handle.pipe(Effect.provide(context))
|
|
@@ -52,6 +59,6 @@ export const mergeContexts = Effect.fnUntraced(
|
|
|
52
59
|
context = Context.merge(context, moreContext.value)
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
|
-
return context as Context.Context<Effect.Success<T[number]["handle"]>>
|
|
62
|
+
return context as Context.Context<Effect.Effect.Success<T[number]["handle"]>>
|
|
56
63
|
}
|
|
57
64
|
)
|
package/src/api/middlewares.ts
CHANGED
|
@@ -76,7 +76,7 @@ export interface BasicAuthCredentials {
|
|
|
76
76
|
export const basicAuth: <R2, _>(
|
|
77
77
|
checkCredentials: (
|
|
78
78
|
credentials: BasicAuthCredentials
|
|
79
|
-
) => Effect<_, NotLoggedInError, R2>,
|
|
79
|
+
) => Effect.Effect<_, NotLoggedInError, R2>,
|
|
80
80
|
options?: Partial<{
|
|
81
81
|
headerName: string
|
|
82
82
|
skipPaths: readonly string[]
|
package/src/api/reportError.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { logError, reportError } from "../errorReporter.js"
|
|
|
4
4
|
// const onExitReportError = (name: string, unknownOnly?: boolean) => {
|
|
5
5
|
// const report = reportError(name)
|
|
6
6
|
// const log = logError(name)
|
|
7
|
-
// return <A, E, R>(self: Effect<A, E, R>) =>
|
|
7
|
+
// return <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
8
8
|
// Effect.onExit(self, (exit) =>
|
|
9
9
|
// Exit.isFailure(exit)
|
|
10
10
|
// ? unknownOnly
|
|
@@ -17,7 +17,7 @@ import { logError, reportError } from "../errorReporter.js"
|
|
|
17
17
|
const tapErrorCause = (name: string, unknownOnly?: boolean) => {
|
|
18
18
|
const report = reportError(name)
|
|
19
19
|
const log = logError(name)
|
|
20
|
-
return <A, E, R>(self: Effect<A, E, R>) =>
|
|
20
|
+
return <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
21
21
|
Effect.tapErrorCause(self, (cause) =>
|
|
22
22
|
unknownOnly
|
|
23
23
|
? Cause.isFailure(cause)
|
|
@@ -17,7 +17,7 @@ export type RouterMiddleware<
|
|
|
17
17
|
_ContextProviderR, // what the context provider requires
|
|
18
18
|
RequestContextId
|
|
19
19
|
> =
|
|
20
|
-
& Effect<RpcMiddlewareWrap<ContextProviderA, ContextProviderE>, never, Self>
|
|
20
|
+
& Effect.Effect<RpcMiddlewareWrap<ContextProviderA, ContextProviderE>, never, Self>
|
|
21
21
|
// makes error because of TagUnify :/
|
|
22
22
|
// Context.Tag<Self, RpcMiddlewareWrap<ContextProviderA, ContextProviderE>>
|
|
23
23
|
& {
|