effect-app 4.0.0-beta.25 → 4.0.0-beta.251
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 +1137 -0
- package/dist/Array.d.ts +3 -2
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +4 -4
- package/dist/Chunk.d.ts +1 -1
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Config/SecretURL.d.ts +4 -2
- package/dist/Config/SecretURL.d.ts.map +1 -1
- package/dist/Config/SecretURL.js +3 -6
- package/dist/Config/internal/configSecretURL.d.ts +1 -1
- package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
- package/dist/Config/internal/configSecretURL.js +2 -2
- package/dist/Config.d.ts +7 -0
- package/dist/Config.d.ts.map +1 -0
- package/dist/Config.js +6 -0
- package/dist/ConfigProvider.d.ts +39 -0
- package/dist/ConfigProvider.d.ts.map +1 -0
- package/dist/ConfigProvider.js +42 -0
- package/dist/Context.d.ts +42 -0
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +67 -0
- package/dist/Effect.d.ts +13 -12
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +5 -8
- package/dist/Emailer.d.ts +51 -0
- package/dist/Emailer.d.ts.map +1 -0
- package/dist/Emailer.js +7 -0
- package/dist/Function.d.ts +1 -1
- package/dist/Function.d.ts.map +1 -1
- package/dist/Inputify.type.d.ts +1 -1
- package/dist/Layer.d.ts +11 -7
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +3 -2
- package/dist/Model/Repository/Registry.d.ts +21 -0
- package/dist/Model/Repository/Registry.d.ts.map +1 -0
- package/dist/Model/Repository/Registry.js +18 -0
- package/dist/Model/Repository/ext.d.ts +60 -0
- package/dist/Model/Repository/ext.d.ts.map +1 -0
- package/dist/Model/Repository/ext.js +122 -0
- package/dist/Model/Repository/internal/internal.d.ts +62 -0
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -0
- package/dist/Model/Repository/internal/internal.js +397 -0
- package/dist/Model/Repository/legacy.d.ts +21 -0
- package/dist/Model/Repository/legacy.d.ts.map +1 -0
- package/dist/Model/Repository/legacy.js +2 -0
- package/dist/Model/Repository/makeRepo.d.ts +53 -0
- package/dist/Model/Repository/makeRepo.d.ts.map +1 -0
- package/dist/Model/Repository/makeRepo.js +27 -0
- package/dist/Model/Repository/service.d.ts +97 -0
- package/dist/Model/Repository/service.d.ts.map +1 -0
- package/dist/Model/Repository/service.js +2 -0
- package/dist/Model/Repository/validation.d.ts +71 -0
- package/dist/Model/Repository/validation.d.ts.map +1 -0
- package/dist/Model/Repository/validation.js +32 -0
- package/dist/Model/Repository.d.ts +7 -0
- package/dist/Model/Repository.d.ts.map +1 -0
- package/dist/Model/Repository.js +7 -0
- package/dist/Model/dsl.d.ts +33 -0
- package/dist/Model/dsl.d.ts.map +1 -0
- package/dist/Model/dsl.js +43 -0
- package/dist/Model/filter/filterApi.d.ts +30 -0
- package/dist/Model/filter/filterApi.d.ts.map +1 -0
- package/dist/Model/filter/filterApi.js +2 -0
- package/dist/Model/filter/types/errors.d.ts +29 -0
- package/dist/Model/filter/types/errors.d.ts.map +1 -0
- package/dist/Model/filter/types/errors.js +2 -0
- package/dist/Model/filter/types/fields.d.ts +15 -0
- package/dist/Model/filter/types/fields.d.ts.map +1 -0
- package/dist/Model/filter/types/fields.js +2 -0
- package/dist/Model/filter/types/path/common.d.ts +316 -0
- package/dist/Model/filter/types/path/common.d.ts.map +1 -0
- package/dist/Model/filter/types/path/common.js +2 -0
- package/dist/Model/filter/types/path/eager.d.ts +95 -0
- package/dist/Model/filter/types/path/eager.d.ts.map +1 -0
- package/dist/Model/filter/types/path/eager.js +31 -0
- package/dist/Model/filter/types/path/index.d.ts +4 -0
- package/dist/Model/filter/types/path/index.d.ts.map +1 -0
- package/dist/Model/filter/types/path/index.js +3 -0
- package/dist/Model/filter/types/utils.d.ts +79 -0
- package/dist/Model/filter/types/utils.d.ts.map +1 -0
- package/dist/Model/filter/types/utils.js +2 -0
- package/dist/Model/filter/types/validator.d.ts +30 -0
- package/dist/Model/filter/types/validator.d.ts.map +1 -0
- package/dist/Model/filter/types/validator.js +2 -0
- package/dist/Model/filter/types.d.ts +5 -0
- package/dist/Model/filter/types.d.ts.map +1 -0
- package/dist/Model/filter/types.js +7 -0
- package/dist/Model/query/dsl.d.ts +446 -0
- package/dist/Model/query/dsl.d.ts.map +1 -0
- package/dist/Model/query/dsl.js +342 -0
- package/dist/Model/query/new-kid-interpreter.d.ts +136 -0
- package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -0
- package/dist/Model/query/new-kid-interpreter.js +336 -0
- package/dist/Model/query.d.ts +15 -0
- package/dist/Model/query.d.ts.map +1 -0
- package/dist/Model/query.js +3 -0
- package/dist/Model.d.ts +5 -0
- package/dist/Model.d.ts.map +1 -0
- package/dist/Model.js +5 -0
- package/dist/NonEmptySet.d.ts +4 -2
- package/dist/NonEmptySet.d.ts.map +1 -1
- package/dist/NonEmptySet.js +2 -2
- package/dist/Option.d.ts +2 -1
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +3 -1
- package/dist/Pure.d.ts +8 -6
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +17 -14
- package/dist/QueueMaker.d.ts +13 -0
- package/dist/QueueMaker.d.ts.map +1 -0
- package/dist/QueueMaker.js +4 -0
- package/dist/RequestContext.d.ts +103 -0
- package/dist/RequestContext.d.ts.map +1 -0
- package/dist/RequestContext.js +49 -0
- package/dist/Schema/Class.d.ts +66 -20
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +192 -23
- package/dist/Schema/FastCheck.d.ts +1 -1
- package/dist/Schema/FastCheck.d.ts.map +1 -1
- package/dist/Schema/Methods.d.ts +1 -1
- package/dist/Schema/SchemaParser.d.ts +5 -0
- package/dist/Schema/SchemaParser.d.ts.map +1 -0
- package/dist/Schema/SchemaParser.js +6 -0
- package/dist/Schema/SpecialJsonSchema.d.ts +34 -0
- package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
- package/dist/Schema/SpecialJsonSchema.js +118 -0
- package/dist/Schema/SpecialOpenApi.d.ts +32 -0
- package/dist/Schema/SpecialOpenApi.d.ts.map +1 -0
- package/dist/Schema/SpecialOpenApi.js +123 -0
- package/dist/Schema/brand.d.ts +5 -3
- package/dist/Schema/brand.d.ts.map +1 -1
- package/dist/Schema/brand.js +3 -1
- package/dist/Schema/email.d.ts +1 -1
- package/dist/Schema/email.d.ts.map +1 -1
- package/dist/Schema/email.js +7 -4
- package/dist/Schema/ext.d.ts +339 -56
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +358 -53
- package/dist/Schema/moreStrings.d.ts +108 -26
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +45 -16
- package/dist/Schema/numbers.d.ts +55 -15
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/numbers.js +60 -12
- package/dist/Schema/phoneNumber.d.ts +1 -1
- package/dist/Schema/phoneNumber.d.ts.map +1 -1
- package/dist/Schema/phoneNumber.js +6 -3
- package/dist/Schema/schema.d.ts +1 -1
- package/dist/Schema/strings.d.ts +5 -5
- package/dist/Schema/strings.d.ts.map +1 -1
- package/dist/Schema/strings.js +1 -5
- package/dist/Schema.d.ts +214 -8
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +190 -11
- package/dist/Set.d.ts +5 -2
- package/dist/Set.d.ts.map +1 -1
- package/dist/Set.js +3 -2
- package/dist/Store.d.ts +170 -0
- package/dist/Store.d.ts.map +1 -0
- package/dist/Store.js +121 -0
- package/dist/TypeTest.d.ts +1 -1
- package/dist/Types.d.ts +1 -1
- package/dist/Widen.type.d.ts +1 -1
- package/dist/_ext/Array.d.ts +2 -2
- package/dist/_ext/Array.d.ts.map +1 -1
- package/dist/_ext/Array.js +4 -2
- package/dist/_ext/date.d.ts +1 -1
- package/dist/_ext/misc.d.ts +5 -2
- package/dist/_ext/misc.d.ts.map +1 -1
- package/dist/_ext/misc.js +4 -2
- package/dist/_ext/ord.ext.d.ts +3 -2
- package/dist/_ext/ord.ext.d.ts.map +1 -1
- package/dist/_ext/ord.ext.js +2 -2
- package/dist/builtin.d.ts +1 -1
- package/dist/builtin.d.ts.map +1 -1
- package/dist/client/InvalidationKeys.d.ts +29 -0
- package/dist/client/InvalidationKeys.d.ts.map +1 -0
- package/dist/client/InvalidationKeys.js +33 -0
- package/dist/client/apiClientFactory.d.ts +20 -32
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +104 -34
- package/dist/client/clientFor.d.ts +53 -19
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/clientFor.js +9 -1
- package/dist/client/errors.d.ts +49 -25
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +43 -17
- package/dist/client/makeClient.d.ts +495 -33
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +66 -24
- package/dist/client.d.ts +6 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/faker.d.ts +1 -1
- package/dist/faker.d.ts.map +1 -1
- package/dist/http/Request.d.ts +2 -2
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +2 -2
- package/dist/http/internal/lib.d.ts +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/ids.d.ts +40 -12
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +25 -3
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/logger.d.ts +1 -1
- package/dist/middleware.d.ts +14 -8
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +14 -8
- package/dist/rpc/Invalidation.d.ts +420 -0
- package/dist/rpc/Invalidation.d.ts.map +1 -0
- package/dist/rpc/Invalidation.js +168 -0
- package/dist/rpc/MiddlewareMaker.d.ts +12 -8
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
- package/dist/rpc/MiddlewareMaker.js +59 -38
- package/dist/rpc/RpcContextMap.d.ts +4 -4
- package/dist/rpc/RpcContextMap.d.ts.map +1 -1
- package/dist/rpc/RpcContextMap.js +4 -4
- package/dist/rpc/RpcMiddleware.d.ts +15 -11
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js +1 -1
- package/dist/rpc.d.ts +2 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +2 -2
- package/dist/runtime.d.ts +19 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +40 -0
- package/dist/setupRequest.d.ts +19 -0
- package/dist/setupRequest.d.ts.map +1 -0
- package/dist/setupRequest.js +69 -0
- package/dist/toast.d.ts +51 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +34 -0
- package/dist/transform.d.ts +2 -2
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +4 -5
- package/dist/utils/effectify.d.ts +2 -2
- package/dist/utils/effectify.d.ts.map +1 -1
- package/dist/utils/effectify.js +2 -2
- package/dist/utils/extend.d.ts +1 -1
- package/dist/utils/extend.d.ts.map +1 -1
- package/dist/utils/gen.d.ts +5 -5
- package/dist/utils/gen.d.ts.map +1 -1
- package/dist/utils/logLevel.d.ts +3 -3
- package/dist/utils/logLevel.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +5 -4
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +4 -4
- package/dist/utils.d.ts +40 -45
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +19 -27
- package/dist/validation/validators.d.ts +1 -1
- package/dist/validation/validators.d.ts.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/dist/withToast.d.ts +30 -0
- package/dist/withToast.d.ts.map +1 -0
- package/dist/withToast.js +64 -0
- package/package.json +162 -24
- package/src/Array.ts +3 -3
- package/src/Config/SecretURL.ts +5 -2
- package/src/Config/internal/configSecretURL.ts +1 -1
- package/src/Config.ts +14 -0
- package/src/ConfigProvider.ts +48 -0
- package/src/{ServiceMap.ts → Context.ts} +56 -63
- package/src/Effect.ts +12 -14
- package/src/Emailer.ts +51 -0
- package/src/Layer.ts +10 -6
- package/src/Model/Repository/Registry.ts +34 -0
- package/src/Model/Repository/ext.ts +375 -0
- package/src/Model/Repository/internal/internal.ts +691 -0
- package/src/Model/Repository/legacy.ts +29 -0
- package/src/Model/Repository/makeRepo.ts +144 -0
- package/src/Model/Repository/service.ts +639 -0
- package/src/Model/Repository/validation.ts +31 -0
- package/src/Model/Repository.ts +6 -0
- package/src/Model/dsl.ts +129 -0
- package/src/Model/filter/filterApi.ts +60 -0
- package/src/Model/filter/types/errors.ts +47 -0
- package/src/Model/filter/types/fields.ts +50 -0
- package/src/Model/filter/types/path/common.ts +404 -0
- package/src/Model/filter/types/path/eager.ts +297 -0
- package/src/Model/filter/types/path/index.ts +4 -0
- package/src/Model/filter/types/utils.ts +128 -0
- package/src/Model/filter/types/validator.ts +46 -0
- package/src/Model/filter/types.ts +6 -0
- package/src/Model/query/dsl.ts +2546 -0
- package/src/Model/query/new-kid-interpreter.ts +484 -0
- package/src/Model/query.ts +13 -0
- package/src/Model.ts +4 -0
- package/src/NonEmptySet.ts +3 -1
- package/src/Option.ts +2 -0
- package/src/Pure.ts +21 -19
- package/src/QueueMaker.ts +19 -0
- package/src/RequestContext.ts +62 -0
- package/src/Schema/Class.ts +274 -64
- package/src/Schema/SchemaParser.ts +12 -0
- package/src/Schema/SpecialJsonSchema.ts +139 -0
- package/src/Schema/SpecialOpenApi.ts +130 -0
- package/src/Schema/brand.ts +22 -2
- package/src/Schema/email.ts +7 -2
- package/src/Schema/ext.ts +443 -88
- package/src/Schema/moreStrings.ts +93 -37
- package/src/Schema/numbers.ts +64 -16
- package/src/Schema/phoneNumber.ts +5 -1
- package/src/Schema/strings.ts +4 -8
- package/src/Schema.ts +374 -10
- package/src/Set.ts +5 -1
- package/src/Store.ts +277 -0
- package/src/_ext/Array.ts +3 -1
- package/src/_ext/misc.ts +4 -1
- package/src/_ext/ord.ext.ts +2 -1
- package/src/client/InvalidationKeys.ts +50 -0
- package/src/client/apiClientFactory.ts +230 -131
- package/src/client/clientFor.ts +102 -31
- package/src/client/errors.ts +52 -26
- package/src/client/makeClient.ts +592 -71
- package/src/client.ts +5 -4
- package/src/http/Request.ts +1 -1
- package/src/ids.ts +25 -3
- package/src/index.ts +7 -10
- package/src/middleware.ts +13 -9
- package/src/rpc/Invalidation.ts +261 -0
- package/src/rpc/MiddlewareMaker.ts +83 -75
- package/src/rpc/README.md +2 -2
- package/src/rpc/RpcContextMap.ts +6 -5
- package/src/rpc/RpcMiddleware.ts +18 -12
- package/src/rpc.ts +1 -1
- package/src/runtime.ts +56 -0
- package/src/setupRequest.ts +134 -0
- package/src/toast.ts +54 -0
- package/src/transform.ts +3 -3
- package/src/utils/effectify.ts +1 -1
- package/src/utils/gen.ts +8 -8
- package/src/utils/logLevel.ts +1 -1
- package/src/utils/logger.ts +4 -3
- package/src/utils.ts +62 -139
- package/src/withToast.ts +133 -0
- package/test/dist/rpc-dynamic-middleware.test.d.ts.map +1 -0
- package/test/dist/rpc.test.d.ts.map +1 -1
- package/test/dist/secretURL.test.d.ts.map +1 -0
- package/test/dist/special.test.d.ts.map +1 -0
- package/test/dist/stream-error.types.d.ts +2 -0
- package/test/dist/stream-error.types.d.ts.map +1 -0
- package/test/dist/stream-error.types.js +27 -0
- package/test/moreStrings.test.ts +1 -1
- package/test/rpc.test.ts +46 -6
- package/test/schema.test.ts +459 -30
- package/test/secretURL.test.ts +160 -0
- package/test/special.test.ts +1026 -0
- package/test/utils.test.ts +7 -7
- package/tsconfig.base.json +6 -5
- package/tsconfig.json +2 -1
- package/tsconfig.json.bak +2 -2
- package/tsconfig.src.json +29 -29
- package/tsconfig.test.json +2 -2
- package/dist/Operations.d.ts +0 -123
- package/dist/Operations.d.ts.map +0 -1
- package/dist/Operations.js +0 -29
- package/dist/ServiceMap.d.ts +0 -44
- package/dist/ServiceMap.d.ts.map +0 -1
- package/dist/ServiceMap.js +0 -91
- package/eslint.config.mjs +0 -26
- package/src/Operations.ts +0 -55
package/src/Effect.ts
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
/* eslint-disable prefer-destructuring */
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4
4
|
|
|
5
|
-
import { Effect, Option, Ref, type ServiceMap } from "effect"
|
|
6
5
|
import * as Def from "effect/Deferred"
|
|
7
|
-
import * as
|
|
6
|
+
import * as Effect from "effect/Effect"
|
|
7
|
+
import * as Option from "effect/Option"
|
|
8
|
+
import * as Ref from "effect/Ref"
|
|
8
9
|
import type { Scope } from "effect/Scope"
|
|
9
10
|
import type { Semaphore } from "effect/Semaphore"
|
|
11
|
+
import type * as Context from "./Context.js"
|
|
10
12
|
import { curry } from "./Function.js"
|
|
11
13
|
import { typedKeysOf } from "./utils.js"
|
|
12
14
|
|
|
@@ -111,15 +113,11 @@ export function modifyWithPermitWithEffect<A>(ref: Ref.Ref<A>, semaphore: Semaph
|
|
|
111
113
|
)
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
export function joinAll<E, A>(fibers: Iterable<Fiber.Fiber<A, E>>): Effect.Effect<readonly A[], E> {
|
|
115
|
-
return Fiber.joinAll(fibers) as any
|
|
116
|
-
}
|
|
117
|
-
|
|
118
116
|
type ServiceA<T> = T extends Effect.Effect<infer S, any, any> ? S
|
|
119
|
-
: T extends
|
|
117
|
+
: T extends Context.Service<any, infer S> ? S
|
|
120
118
|
: never
|
|
121
119
|
type ServiceR<T> = T extends Effect.Effect<any, any, infer R> ? R
|
|
122
|
-
: T extends
|
|
120
|
+
: T extends Context.Service<infer I, any> ? I
|
|
123
121
|
: never
|
|
124
122
|
type ServiceE<T> = T extends Effect.Effect<any, infer E, any> ? E : never
|
|
125
123
|
// type Values<T> = T extends { [s: string]: infer S } ? ServiceA<S> : never
|
|
@@ -140,29 +138,29 @@ type ValuesE<T> = T extends { [s: string]: infer S } ? ServiceE<S> : never
|
|
|
140
138
|
* const b = a({ str: "" }) // valid, but shouldn't be!
|
|
141
139
|
* ```
|
|
142
140
|
*/
|
|
141
|
+
// eslint-disable-next-line import/namespace
|
|
143
142
|
export interface EffectUnunified<R, E, A> extends Effect.Effect<R, E, A> {}
|
|
144
143
|
|
|
145
144
|
export type LowerFirst<S extends PropertyKey> = S extends `${infer First}${infer Rest}` ? `${Lowercase<First>}${Rest}`
|
|
146
145
|
: S
|
|
147
|
-
export type LowerServices<T extends Record<string,
|
|
146
|
+
export type LowerServices<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>> = {
|
|
148
147
|
[key in keyof T as LowerFirst<key>]: ServiceA<T[key]>
|
|
149
148
|
}
|
|
150
149
|
|
|
151
|
-
export function allLower<T extends Record<string,
|
|
150
|
+
export function allLower<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>>(
|
|
152
151
|
services: T
|
|
153
152
|
) {
|
|
154
153
|
return Effect.all(
|
|
155
154
|
typedKeysOf(services).reduce((prev, cur) => {
|
|
156
155
|
const svc = services[cur]!
|
|
157
|
-
prev[((cur as string)[0]!.toLowerCase() + (cur as string).slice(1)) as unknown as LowerFirst<typeof cur>] =
|
|
158
|
-
"asEffect" in svc ? svc.asEffect() : svc
|
|
156
|
+
prev[((cur as string)[0]!.toLowerCase() + (cur as string).slice(1)) as unknown as LowerFirst<typeof cur>] = svc
|
|
159
157
|
return prev
|
|
160
158
|
}, {} as any),
|
|
161
159
|
{ concurrency: "inherit" }
|
|
162
160
|
) as any as Effect.Effect<LowerServices<T>, ValuesE<T>, ValuesR<T>>
|
|
163
161
|
}
|
|
164
162
|
|
|
165
|
-
export function allLowerWith<T extends Record<string,
|
|
163
|
+
export function allLowerWith<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>, A>(
|
|
166
164
|
services: T,
|
|
167
165
|
fn: (services: LowerServices<T>) => A
|
|
168
166
|
) {
|
|
@@ -170,7 +168,7 @@ export function allLowerWith<T extends Record<string, ServiceMap.Service<any, an
|
|
|
170
168
|
}
|
|
171
169
|
|
|
172
170
|
export function allLowerWithEffect<
|
|
173
|
-
T extends Record<string,
|
|
171
|
+
T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>,
|
|
174
172
|
R,
|
|
175
173
|
E,
|
|
176
174
|
A
|
package/src/Emailer.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as Data from "effect/Data"
|
|
2
|
+
import type { NonEmptyReadonlyArray } from "./Array.js"
|
|
3
|
+
import * as Context from "./Context.js"
|
|
4
|
+
import type * as Effect from "./Effect.js"
|
|
5
|
+
import type { Email } from "./Schema.js"
|
|
6
|
+
|
|
7
|
+
export class SendMailError extends Data.TaggedError("SendMailError")<{
|
|
8
|
+
readonly raw: Error
|
|
9
|
+
}> {}
|
|
10
|
+
|
|
11
|
+
export class Emailer extends Context.Opaque<Emailer, {
|
|
12
|
+
sendMail: (msg: EmailMsgOptionalFrom) => Effect.Effect<void, SendMailError>
|
|
13
|
+
}>()("effect-app/Emailer") {}
|
|
14
|
+
|
|
15
|
+
export type EmailData = Email | {
|
|
16
|
+
name?: string
|
|
17
|
+
email: Email
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface EmailContentPart {
|
|
21
|
+
type: string
|
|
22
|
+
value: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type EmailRecipients = EmailData | NonEmptyReadonlyArray<EmailData>
|
|
26
|
+
|
|
27
|
+
export interface EmailMsgBase {
|
|
28
|
+
readonly to: EmailRecipients
|
|
29
|
+
readonly cc?: EmailRecipients
|
|
30
|
+
readonly bcc?: EmailRecipients
|
|
31
|
+
readonly from: EmailData
|
|
32
|
+
readonly replyTo?: EmailData
|
|
33
|
+
readonly subject?: string
|
|
34
|
+
/**
|
|
35
|
+
* should multiple `to` addresess be considered multiple emails?
|
|
36
|
+
* defaults to `true`, not to leak email addresses
|
|
37
|
+
*/
|
|
38
|
+
readonly isMultiple?: boolean
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type EmailContent =
|
|
42
|
+
| { text: string }
|
|
43
|
+
| { html: string }
|
|
44
|
+
| { templateId: string }
|
|
45
|
+
| { content: NonEmptyReadonlyArray<EmailContentPart> }
|
|
46
|
+
|
|
47
|
+
export type EmailMsg =
|
|
48
|
+
& EmailMsgBase
|
|
49
|
+
& EmailContent
|
|
50
|
+
|
|
51
|
+
export type EmailMsgOptionalFrom = Omit<EmailMsgBase, "from"> & Partial<Pick<EmailMsg, "from">> & EmailContent
|
package/src/Layer.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import type * as Array from "effect/Array"
|
|
2
|
+
import * as Effect from "effect/Effect"
|
|
3
3
|
import { dual } from "effect/Function"
|
|
4
|
+
import * as Layer from "effect/Layer"
|
|
5
|
+
import type * as Scope from "effect/Scope"
|
|
6
|
+
import type * as Types from "effect/Types"
|
|
7
|
+
import type * as Context from "./Context.js"
|
|
4
8
|
import { type EffectGenUtils } from "./utils/gen.js"
|
|
5
9
|
|
|
6
10
|
export * from "effect/Layer"
|
|
@@ -11,13 +15,13 @@ type MakeEff<S, E, R> = {
|
|
|
11
15
|
readonly make: Effect.Effect<S, E, R>
|
|
12
16
|
}
|
|
13
17
|
type MakeGen<S, E = never, R = never> = {
|
|
14
|
-
readonly make: () => Generator<
|
|
18
|
+
readonly make: () => Generator<Effect.Effect<any, E, R>, S>
|
|
15
19
|
}
|
|
16
20
|
type MakeGenNo<S> = {
|
|
17
21
|
readonly make: () => Generator<unknown, S>
|
|
18
22
|
}
|
|
19
23
|
type MakeErr<Opts> = Opts extends { make: () => any } ? EffectGenUtils.Error<Opts["make"]> : never
|
|
20
|
-
type MakeContext<Opts> = Opts extends { make: () => any } ? EffectGenUtils.
|
|
24
|
+
type MakeContext<Opts> = Opts extends { make: () => any } ? EffectGenUtils.Context<Opts["make"]> : never
|
|
21
25
|
|
|
22
26
|
type DependenciesOpt = { dependencies?: Array.NonEmptyReadonlyArray<Layer.Any> }
|
|
23
27
|
type Dependencies = { dependencies: Array.NonEmptyReadonlyArray<Layer.Any> }
|
|
@@ -41,12 +45,12 @@ type PackedOrUnpackedLayer<I, Opts> = Opts extends Dependencies ? PackedLayers<I
|
|
|
41
45
|
|
|
42
46
|
export const make: {
|
|
43
47
|
<I, S>(
|
|
44
|
-
tag:
|
|
48
|
+
tag: Context.Service<I, S>
|
|
45
49
|
): <Opts extends Make<Types.NoInfer<S>, any, any>>(
|
|
46
50
|
options: Opts
|
|
47
51
|
) => PackedOrUnpackedLayer<I, Opts>
|
|
48
52
|
<I, S, Opts extends Make<Types.NoInfer<S>, any, any>>(
|
|
49
|
-
tag:
|
|
53
|
+
tag: Context.Service<I, S>,
|
|
50
54
|
options: Opts
|
|
51
55
|
): PackedOrUnpackedLayer<I, Opts>
|
|
52
56
|
} = dual(2, (tag, options) => {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as Context from "../../Context.js"
|
|
2
|
+
import * as Effect from "../../Effect.js"
|
|
3
|
+
|
|
4
|
+
export interface RegisteredRepository {
|
|
5
|
+
readonly seedNamespace: (namespace: string) => Effect.Effect<void>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const make = Effect.sync(() => {
|
|
9
|
+
const repos = new Map<string, RegisteredRepository>()
|
|
10
|
+
return {
|
|
11
|
+
register(modelName: string, repo: RegisteredRepository) {
|
|
12
|
+
repos.set(modelName, repo)
|
|
13
|
+
},
|
|
14
|
+
seedNamespace: (namespace: string) =>
|
|
15
|
+
Effect.suspend(() =>
|
|
16
|
+
Effect.forEach(
|
|
17
|
+
repos.values(),
|
|
18
|
+
(r) => r.seedNamespace(namespace),
|
|
19
|
+
{ concurrency: "unbounded", discard: true }
|
|
20
|
+
)
|
|
21
|
+
),
|
|
22
|
+
get entries(): ReadonlyMap<string, RegisteredRepository> {
|
|
23
|
+
return repos
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export class RepositoryRegistry extends Context.Opaque<RepositoryRegistry, {
|
|
29
|
+
readonly register: (modelName: string, repo: RegisteredRepository) => void
|
|
30
|
+
readonly seedNamespace: (namespace: string) => Effect.Effect<void>
|
|
31
|
+
readonly entries: ReadonlyMap<string, RegisteredRepository>
|
|
32
|
+
}>()("effect-app/RepositoryRegistry", { make }) {}
|
|
33
|
+
|
|
34
|
+
export const RepositoryRegistryLive = RepositoryRegistry.toLayer(RepositoryRegistry.make)
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
3
|
+
import * as Exit from "effect/Exit"
|
|
4
|
+
import * as Request from "effect/Request"
|
|
5
|
+
import * as RequestResolver from "effect/RequestResolver"
|
|
6
|
+
import * as Array from "../../Array.js"
|
|
7
|
+
import type { NonEmptyArray } from "../../Array.js"
|
|
8
|
+
import { type InvalidStateError, NotFoundError, type OptimisticConcurrencyException } from "../../client/errors.js"
|
|
9
|
+
import * as Effect from "../../Effect.js"
|
|
10
|
+
import * as Option from "../../Option.js"
|
|
11
|
+
import { type FixEnv, type PureEnv, runTerm } from "../../Pure.js"
|
|
12
|
+
import { AnyPureDSL } from "../dsl.js"
|
|
13
|
+
import type { FieldValues } from "../filter/types.js"
|
|
14
|
+
import type { Query, QueryEnd, QueryWhere } from "../query.js"
|
|
15
|
+
import * as Q from "../query.js"
|
|
16
|
+
import type { Repository } from "./service.js"
|
|
17
|
+
|
|
18
|
+
interface BatchOptions {
|
|
19
|
+
readonly batch?: true | number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const asReadonlyArray = <T>(itemOrItems: T | ReadonlyArray<T>): ReadonlyArray<T> =>
|
|
23
|
+
globalThis.Array.isArray(itemOrItems)
|
|
24
|
+
? itemOrItems as ReadonlyArray<T>
|
|
25
|
+
: [itemOrItems as T]
|
|
26
|
+
|
|
27
|
+
const getBatchSize = (batch?: true | number) =>
|
|
28
|
+
batch === true
|
|
29
|
+
? 100
|
|
30
|
+
: typeof batch === "number" && Number.isFinite(batch) && batch > 0
|
|
31
|
+
? Math.floor(batch)
|
|
32
|
+
: undefined
|
|
33
|
+
|
|
34
|
+
export const extendRepo = <
|
|
35
|
+
T,
|
|
36
|
+
Encoded extends FieldValues,
|
|
37
|
+
Evt,
|
|
38
|
+
ItemType extends string,
|
|
39
|
+
IdKey extends keyof T & keyof Encoded,
|
|
40
|
+
RSchema,
|
|
41
|
+
RPublish,
|
|
42
|
+
RProvided = never
|
|
43
|
+
>(
|
|
44
|
+
repo: Repository<T, Encoded, Evt, ItemType, IdKey, RSchema, RPublish, RProvided>
|
|
45
|
+
) => {
|
|
46
|
+
const get = (id: T[IdKey]) =>
|
|
47
|
+
repo.find(id).pipe(
|
|
48
|
+
Effect.flatMap(Option.match({
|
|
49
|
+
onNone: () => Effect.fail(new NotFoundError<ItemType>({ type: repo.itemType, id })),
|
|
50
|
+
onSome: Effect.succeed
|
|
51
|
+
}))
|
|
52
|
+
)
|
|
53
|
+
function saveManyWithPure_<
|
|
54
|
+
R,
|
|
55
|
+
A,
|
|
56
|
+
E,
|
|
57
|
+
S1 extends T,
|
|
58
|
+
S2 extends T
|
|
59
|
+
>(
|
|
60
|
+
items: Iterable<S1>,
|
|
61
|
+
pure: Effect.Effect<A, E, FixEnv<R, Evt, readonly S1[], readonly S2[]>>
|
|
62
|
+
) {
|
|
63
|
+
return saveAllWithEffectInt(
|
|
64
|
+
runTerm(pure, [...items])
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function saveWithPure_<
|
|
69
|
+
R,
|
|
70
|
+
A,
|
|
71
|
+
E,
|
|
72
|
+
S1 extends T,
|
|
73
|
+
S2 extends T
|
|
74
|
+
>(
|
|
75
|
+
item: S1,
|
|
76
|
+
pure: Effect.Effect<A, E, FixEnv<R, Evt, S1, S2>>
|
|
77
|
+
) {
|
|
78
|
+
return saveAllWithEffectInt(
|
|
79
|
+
runTerm(pure, item)
|
|
80
|
+
.pipe(Effect
|
|
81
|
+
.map(([item, events, a]) => [[item], events, a]))
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function saveAllWithEffectInt<
|
|
86
|
+
P extends T,
|
|
87
|
+
R,
|
|
88
|
+
E,
|
|
89
|
+
A
|
|
90
|
+
>(
|
|
91
|
+
gen: Effect.Effect<readonly [Iterable<P>, Iterable<Evt>, A], E, R>
|
|
92
|
+
) {
|
|
93
|
+
return Effect.flatMap(gen, ([items, events, a]) => repo.saveAndPublish(items, events).pipe(Effect.map(() => a)))
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function saveManyWithPureBatched_<
|
|
97
|
+
R,
|
|
98
|
+
A,
|
|
99
|
+
E,
|
|
100
|
+
S1 extends T,
|
|
101
|
+
S2 extends T
|
|
102
|
+
>(
|
|
103
|
+
items: Iterable<S1>,
|
|
104
|
+
pure: Effect.Effect<A, E, FixEnv<R, Evt, readonly S1[], readonly S2[]>>,
|
|
105
|
+
batchSize = 100
|
|
106
|
+
) {
|
|
107
|
+
return Effect.forEach(
|
|
108
|
+
Array.chunksOf(items, batchSize),
|
|
109
|
+
(batch) =>
|
|
110
|
+
saveAllWithEffectInt(
|
|
111
|
+
runTerm(pure, batch)
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const queryAndSavePure: {
|
|
117
|
+
<A, E2, R2, T2 extends T>(
|
|
118
|
+
q: (
|
|
119
|
+
q: Query<Encoded>
|
|
120
|
+
) => QueryEnd<Encoded, "one">,
|
|
121
|
+
pure: Effect.Effect<A, E2, FixEnv<R2, Evt, T, T2>>
|
|
122
|
+
): Effect.Effect<
|
|
123
|
+
A,
|
|
124
|
+
InvalidStateError | OptimisticConcurrencyException | NotFoundError<ItemType> | E2,
|
|
125
|
+
Exclude<R2, {
|
|
126
|
+
env: PureEnv<Evt, T, T2>
|
|
127
|
+
}>
|
|
128
|
+
>
|
|
129
|
+
<A, E2, R2, T2 extends T>(
|
|
130
|
+
q: (
|
|
131
|
+
q: Query<Encoded>
|
|
132
|
+
) =>
|
|
133
|
+
| Query<Encoded>
|
|
134
|
+
| QueryWhere<Encoded>
|
|
135
|
+
| QueryEnd<Encoded>,
|
|
136
|
+
pure: Effect.Effect<A, E2, FixEnv<R2, Evt, readonly T[], readonly T2[]>>
|
|
137
|
+
): Effect.Effect<
|
|
138
|
+
A,
|
|
139
|
+
InvalidStateError | OptimisticConcurrencyException | E2,
|
|
140
|
+
| RSchema
|
|
141
|
+
| RPublish
|
|
142
|
+
| Exclude<R2, {
|
|
143
|
+
env: PureEnv<Evt, readonly T[], readonly T2[]>
|
|
144
|
+
}>
|
|
145
|
+
>
|
|
146
|
+
<A, E2, R2, T2 extends T>(
|
|
147
|
+
q: (
|
|
148
|
+
q: Query<Encoded>
|
|
149
|
+
) =>
|
|
150
|
+
| Query<Encoded>
|
|
151
|
+
| QueryWhere<Encoded>
|
|
152
|
+
| QueryEnd<Encoded>,
|
|
153
|
+
pure: Effect.Effect<A, E2, FixEnv<R2, Evt, readonly T[], readonly T2[]>>,
|
|
154
|
+
batch: "batched" | number
|
|
155
|
+
): Effect.Effect<
|
|
156
|
+
A[],
|
|
157
|
+
InvalidStateError | OptimisticConcurrencyException | E2,
|
|
158
|
+
| RSchema
|
|
159
|
+
| RPublish
|
|
160
|
+
| Exclude<R2, {
|
|
161
|
+
env: PureEnv<Evt, readonly T[], readonly T2[]>
|
|
162
|
+
}>
|
|
163
|
+
>
|
|
164
|
+
} = (q, pure, batch?: "batched" | number) =>
|
|
165
|
+
repo.query(q).pipe(
|
|
166
|
+
Effect.andThen((_) =>
|
|
167
|
+
Array.isArray(_)
|
|
168
|
+
? batch === undefined
|
|
169
|
+
? saveManyWithPure_(_ as any, pure as any)
|
|
170
|
+
: saveManyWithPureBatched_(_ as any, pure as any, batch === "batched" ? 100 : batch)
|
|
171
|
+
: saveWithPure_(_ as any, pure as any)
|
|
172
|
+
)
|
|
173
|
+
) as any
|
|
174
|
+
|
|
175
|
+
const saveManyWithPure: {
|
|
176
|
+
<R, A, E, S1 extends T, S2 extends T>(
|
|
177
|
+
items: Iterable<S1>,
|
|
178
|
+
pure: Effect.Effect<A, E, FixEnv<R, Evt, readonly S1[], readonly S2[]>>
|
|
179
|
+
): Effect.Effect<
|
|
180
|
+
A,
|
|
181
|
+
InvalidStateError | OptimisticConcurrencyException | E,
|
|
182
|
+
| RSchema
|
|
183
|
+
| RPublish
|
|
184
|
+
| Exclude<R, {
|
|
185
|
+
env: PureEnv<Evt, readonly S1[], readonly S2[]>
|
|
186
|
+
}>
|
|
187
|
+
>
|
|
188
|
+
<R, A, E, S1 extends T, S2 extends T>(
|
|
189
|
+
items: Iterable<S1>,
|
|
190
|
+
pure: Effect.Effect<A, E, FixEnv<R, Evt, readonly S1[], readonly S2[]>>,
|
|
191
|
+
batch: "batched" | number
|
|
192
|
+
): Effect.Effect<
|
|
193
|
+
A[],
|
|
194
|
+
InvalidStateError | OptimisticConcurrencyException | E,
|
|
195
|
+
| RSchema
|
|
196
|
+
| RPublish
|
|
197
|
+
| Exclude<R, {
|
|
198
|
+
env: PureEnv<Evt, readonly S1[], readonly S2[]>
|
|
199
|
+
}>
|
|
200
|
+
>
|
|
201
|
+
} = (items, pure, batch?: "batched" | number) =>
|
|
202
|
+
batch
|
|
203
|
+
? Effect.forEach(
|
|
204
|
+
Array.chunksOf(items, batch === "batched" ? 100 : batch),
|
|
205
|
+
(batch) =>
|
|
206
|
+
saveAllWithEffectInt(
|
|
207
|
+
runTerm(pure, batch)
|
|
208
|
+
)
|
|
209
|
+
)
|
|
210
|
+
: saveAllWithEffectInt(
|
|
211
|
+
runTerm(pure, [...items])
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
const byIdAndSaveWithPure: {
|
|
215
|
+
<R, A, E, S2 extends T>(
|
|
216
|
+
id: T[IdKey],
|
|
217
|
+
pure: Effect.Effect<A, E, FixEnv<R, Evt, T, S2>>
|
|
218
|
+
): Effect.Effect<
|
|
219
|
+
A,
|
|
220
|
+
InvalidStateError | OptimisticConcurrencyException | NotFoundError<ItemType> | E,
|
|
221
|
+
| RSchema
|
|
222
|
+
| RPublish
|
|
223
|
+
| Exclude<R, {
|
|
224
|
+
env: PureEnv<Evt, T, S2>
|
|
225
|
+
}>
|
|
226
|
+
>
|
|
227
|
+
} = (id, pure): any => get(id).pipe(Effect.flatMap((item) => saveWithPure_(item, pure)))
|
|
228
|
+
|
|
229
|
+
type Req =
|
|
230
|
+
& Request.Request<T, NotFoundError<ItemType>>
|
|
231
|
+
& { _tag: `Get${ItemType}`; id: T[IdKey] }
|
|
232
|
+
const _request = Request.tagged<Req>(`Get${repo.itemType}`)
|
|
233
|
+
|
|
234
|
+
const requestResolver = RequestResolver
|
|
235
|
+
.make((
|
|
236
|
+
entries: NonEmptyArray<Request.Entry<Req>>,
|
|
237
|
+
_key: unknown
|
|
238
|
+
) =>
|
|
239
|
+
(repo.query(Q.where(repo.idKey as any, "in" as any, entries.map((_) => _.request.id)) as any) as Effect.Effect<
|
|
240
|
+
readonly T[]
|
|
241
|
+
>)
|
|
242
|
+
// TODO
|
|
243
|
+
.pipe(
|
|
244
|
+
Effect.andThen((items) =>
|
|
245
|
+
Effect.forEach(entries, (entry) =>
|
|
246
|
+
Request.complete(
|
|
247
|
+
Array
|
|
248
|
+
.findFirst(items, (_) => _[repo.idKey] === entry.request.id)
|
|
249
|
+
.pipe(Option.match({
|
|
250
|
+
onNone: () => Exit.fail(new NotFoundError({ type: repo.itemType, id: entry.request.id })),
|
|
251
|
+
onSome: Exit.succeed
|
|
252
|
+
}))
|
|
253
|
+
)(entry), { discard: true })
|
|
254
|
+
),
|
|
255
|
+
Effect
|
|
256
|
+
.catchCause((cause) =>
|
|
257
|
+
Effect.forEach(entries, (entry) => Request.complete(Exit.failCause(cause))(entry), { discard: true })
|
|
258
|
+
)
|
|
259
|
+
)
|
|
260
|
+
)
|
|
261
|
+
.pipe(
|
|
262
|
+
RequestResolver.batchN(20)
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
const exts = {
|
|
266
|
+
request: (id: T[IdKey]) => Effect.request(_request({ id }), requestResolver),
|
|
267
|
+
get,
|
|
268
|
+
log: (evt: Evt) => AnyPureDSL.log(evt),
|
|
269
|
+
/**
|
|
270
|
+
* Enables chunked writes for large batches via `options.batch`.
|
|
271
|
+
* Note: batching breaks transactional properties because chunks are saved independently.
|
|
272
|
+
*/
|
|
273
|
+
save: ((itemOrItems: T | ReadonlyArray<T>, options?: BatchOptions) => {
|
|
274
|
+
const items = asReadonlyArray(itemOrItems)
|
|
275
|
+
if (!Array.isReadonlyArrayNonEmpty(items)) {
|
|
276
|
+
return Effect.void
|
|
277
|
+
}
|
|
278
|
+
const batchSize = getBatchSize(options?.batch)
|
|
279
|
+
if (batchSize === undefined) {
|
|
280
|
+
return repo.saveAndPublish(items)
|
|
281
|
+
}
|
|
282
|
+
return Effect.forEach(
|
|
283
|
+
Array.chunksOf(items, batchSize),
|
|
284
|
+
(batch) => repo.saveAndPublish(batch),
|
|
285
|
+
{ discard: true }
|
|
286
|
+
)
|
|
287
|
+
}) as (
|
|
288
|
+
itemOrItems: T | ReadonlyArray<T>,
|
|
289
|
+
options?: BatchOptions
|
|
290
|
+
) => Effect.Effect<
|
|
291
|
+
void,
|
|
292
|
+
InvalidStateError | OptimisticConcurrencyException,
|
|
293
|
+
RSchema | RPublish
|
|
294
|
+
>,
|
|
295
|
+
saveWithEvents: (events: Iterable<Evt>) => (...items: NonEmptyArray<T>) => repo.saveAndPublish(items, events),
|
|
296
|
+
/**
|
|
297
|
+
* Enables chunked deletes for large batches via `options.batch`.
|
|
298
|
+
* Note: batching breaks transactional properties because chunks are removed independently.
|
|
299
|
+
*/
|
|
300
|
+
remove: ((itemOrItems: T | ReadonlyArray<T>, options?: BatchOptions) => {
|
|
301
|
+
const items = asReadonlyArray(itemOrItems)
|
|
302
|
+
if (!Array.isReadonlyArrayNonEmpty(items)) {
|
|
303
|
+
return Effect.void
|
|
304
|
+
}
|
|
305
|
+
const batchSize = getBatchSize(options?.batch)
|
|
306
|
+
if (batchSize === undefined) {
|
|
307
|
+
return repo.removeAndPublish(items)
|
|
308
|
+
}
|
|
309
|
+
return Effect.forEach(
|
|
310
|
+
Array.chunksOf(items, batchSize),
|
|
311
|
+
(batch) => repo.removeAndPublish(batch),
|
|
312
|
+
{ discard: true }
|
|
313
|
+
)
|
|
314
|
+
}) as (
|
|
315
|
+
itemOrItems: T | ReadonlyArray<T>,
|
|
316
|
+
options?: BatchOptions
|
|
317
|
+
) => Effect.Effect<void, never, RSchema | RPublish>,
|
|
318
|
+
/**
|
|
319
|
+
* Enables chunked deletes for large batches via `options.batch`.
|
|
320
|
+
* Note: batching breaks transactional properties because chunks are removed independently.
|
|
321
|
+
*/
|
|
322
|
+
removeById: ((idOrIds: T[IdKey] | ReadonlyArray<T[IdKey]>, options?: BatchOptions) => {
|
|
323
|
+
const ids = asReadonlyArray(idOrIds)
|
|
324
|
+
if (!Array.isReadonlyArrayNonEmpty(ids)) {
|
|
325
|
+
return Effect.void
|
|
326
|
+
}
|
|
327
|
+
const batchSize = getBatchSize(options?.batch)
|
|
328
|
+
if (batchSize === undefined) {
|
|
329
|
+
return repo.removeById(ids)
|
|
330
|
+
}
|
|
331
|
+
return Effect.forEach(
|
|
332
|
+
Array.chunksOf(ids, batchSize),
|
|
333
|
+
(batch) => repo.removeById(batch),
|
|
334
|
+
{ discard: true }
|
|
335
|
+
)
|
|
336
|
+
}) as (
|
|
337
|
+
idOrIds: T[IdKey] | ReadonlyArray<T[IdKey]>,
|
|
338
|
+
options?: BatchOptions
|
|
339
|
+
) => Effect.Effect<void, never, RSchema>,
|
|
340
|
+
queryAndSavePure,
|
|
341
|
+
saveManyWithPure,
|
|
342
|
+
byIdAndSaveWithPure,
|
|
343
|
+
saveWithPure: <
|
|
344
|
+
R,
|
|
345
|
+
A,
|
|
346
|
+
E,
|
|
347
|
+
S1 extends T,
|
|
348
|
+
S2 extends T
|
|
349
|
+
>(
|
|
350
|
+
item: S1,
|
|
351
|
+
pure: Effect.Effect<A, E, FixEnv<R, Evt, S1, S2>>
|
|
352
|
+
) =>
|
|
353
|
+
saveAllWithEffectInt(
|
|
354
|
+
runTerm(pure, item)
|
|
355
|
+
.pipe(Effect.map(([item, events, a]) => [[item], events, a]))
|
|
356
|
+
)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
...repo,
|
|
361
|
+
...exts
|
|
362
|
+
} as Repository<T, Encoded, Evt, ItemType, IdKey, RSchema, RPublish, RProvided> & typeof exts
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
366
|
+
export interface ExtendedRepository<
|
|
367
|
+
T,
|
|
368
|
+
Encoded extends FieldValues,
|
|
369
|
+
Evt,
|
|
370
|
+
ItemType extends string,
|
|
371
|
+
IdKey extends keyof T & keyof Encoded,
|
|
372
|
+
RSchema,
|
|
373
|
+
RPublish,
|
|
374
|
+
RProvided = never
|
|
375
|
+
> extends ReturnType<typeof extendRepo<T, Encoded, Evt, ItemType, IdKey, RSchema, RPublish, RProvided>> {}
|