effect-app 4.0.0-beta.26 → 4.0.0-beta.261
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 +1194 -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/DataDependencies.d.ts +158 -0
- package/dist/DataDependencies.d.ts.map +1 -0
- package/dist/DataDependencies.js +39 -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 +63 -0
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -0
- package/dist/Model/Repository/internal/internal.js +430 -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 +54 -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 +121 -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 +58 -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 +493 -0
- package/dist/Model/query/dsl.d.ts.map +1 -0
- package/dist/Model/query/dsl.js +376 -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 +91 -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 -27
- 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 +83 -37
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +49 -42
- package/dist/Schema/numbers.d.ts +35 -22
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/numbers.js +55 -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 +19 -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 +43 -15
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +30 -5
- 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 +20 -245
- 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 +741 -0
- package/src/Model/Repository/legacy.ts +29 -0
- package/src/Model/Repository/makeRepo.ts +145 -0
- package/src/Model/Repository/service.ts +666 -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 +2694 -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 -68
- 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 +146 -67
- package/src/Schema/numbers.ts +96 -27
- package/src/Schema/phoneNumber.ts +5 -1
- package/src/Schema/strings.ts +22 -13
- 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 +32 -5
- 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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
|
+
import type { OptimisticConcurrencyException } from "../../client/errors.js"
|
|
4
|
+
import type * as Effect from "../../Effect.js"
|
|
5
|
+
import type * as Option from "../../Option.js"
|
|
6
|
+
import type * as S from "../../Schema.js"
|
|
7
|
+
|
|
8
|
+
export interface Mapped1<A, IdKey extends keyof A, R> {
|
|
9
|
+
all: Effect.Effect<A[], S.SchemaError, R>
|
|
10
|
+
save: (...xes: readonly A[]) => Effect.Effect<void, OptimisticConcurrencyException | S.SchemaError, R>
|
|
11
|
+
find: (id: A[IdKey]) => Effect.Effect<Option.Option<A>, S.SchemaError, R>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// TODO: auto use project, and select fields from the From side of schema only
|
|
15
|
+
export interface Mapped2<A, R> {
|
|
16
|
+
all: Effect.Effect<A[], S.SchemaError, R>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Mapped<Encoded> {
|
|
20
|
+
<A, R, IdKey extends keyof A>(schema: S.Codec<A, Encoded, R>): Mapped1<A, IdKey, R>
|
|
21
|
+
// TODO: constrain on Encoded2 having to contain only fields that fit Encoded
|
|
22
|
+
<A, Encoded2, R>(schema: S.Codec<A, Encoded2, R>): Mapped2<A, R>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface MM<Repo, Encoded> {
|
|
26
|
+
<A, R, IdKey extends keyof A>(schema: S.Codec<A, Encoded, R>): Effect.Effect<Mapped1<A, IdKey, R>, never, Repo>
|
|
27
|
+
// TODO: constrain on Encoded2 having to contain only fields that fit Encoded
|
|
28
|
+
<A, Encoded2, R>(schema: S.Codec<A, Encoded2, R>): Effect.Effect<Mapped2<A, R>, never, Repo>
|
|
29
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
6
|
+
|
|
7
|
+
// import type { ParserEnv } from "../../Schema/custom/Parser.js"
|
|
8
|
+
|
|
9
|
+
import type * as Scope from "effect/Scope"
|
|
10
|
+
import type { NonEmptyReadonlyArray } from "../../Array.js"
|
|
11
|
+
import type * as Context from "../../Context.js"
|
|
12
|
+
import * as Effect from "../../Effect.js"
|
|
13
|
+
import type * as S from "../../Schema.js"
|
|
14
|
+
import type { StoreConfig, StoreMaker } from "../../Store.js"
|
|
15
|
+
import type { FieldValues } from "../filter/types.js"
|
|
16
|
+
import { type ExtendedRepository, extendRepo } from "./ext.js"
|
|
17
|
+
import { makeRepoInternal } from "./internal/internal.js"
|
|
18
|
+
import { RepositoryRegistry } from "./Registry.js"
|
|
19
|
+
import type { Repository } from "./service.js"
|
|
20
|
+
|
|
21
|
+
export interface RepositoryOptions<
|
|
22
|
+
IdKey extends keyof T & keyof Encoded,
|
|
23
|
+
Encoded extends FieldValues,
|
|
24
|
+
T,
|
|
25
|
+
ItemType extends string,
|
|
26
|
+
Evt = never,
|
|
27
|
+
RPublish = never,
|
|
28
|
+
E = never,
|
|
29
|
+
RInitial = never,
|
|
30
|
+
RCtx = never,
|
|
31
|
+
RSchema = never
|
|
32
|
+
> {
|
|
33
|
+
/**
|
|
34
|
+
* Specify the idKey of the Type side, if it's different from the default "id".
|
|
35
|
+
* Does not change the Encoded side, which is always "id" to support database drivers.
|
|
36
|
+
* At this time as queries are operating on the Encoded side, the queries must still specify "id" regardless.
|
|
37
|
+
*/
|
|
38
|
+
idKey: IdKey
|
|
39
|
+
/**
|
|
40
|
+
* just in time Migration: for complex migrations that aren't just default simple values
|
|
41
|
+
* use the config.defaultValues instead for simple default values
|
|
42
|
+
*/
|
|
43
|
+
jitM?: (pm: Encoded) => Encoded
|
|
44
|
+
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
45
|
+
partitionValue?: (e?: Encoded) => string
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Optional handler to be able to publish events after successfull save.
|
|
49
|
+
*/
|
|
50
|
+
publishEvents?: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, RPublish>
|
|
51
|
+
/**
|
|
52
|
+
* Optional creator for initial data in the table when it's created for the first itme.
|
|
53
|
+
*/
|
|
54
|
+
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
55
|
+
/**
|
|
56
|
+
* Optional context to be provided to Schema decode/encode.
|
|
57
|
+
* Useful for effectful transformations like XWithItems, where items is a transformation retrieving elements from another database table or other source.
|
|
58
|
+
*/
|
|
59
|
+
schemaContext?: Context.Context<RCtx>
|
|
60
|
+
|
|
61
|
+
overrides?: (
|
|
62
|
+
repo: Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish, RCtx>
|
|
63
|
+
) => Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish, RCtx>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Create a repository instance.
|
|
68
|
+
* @param itemType an identifier used for the table name and e.g NotFoundError
|
|
69
|
+
* @param schema the Schema used for this Repository
|
|
70
|
+
* @param options @see RepositoryOptions
|
|
71
|
+
* @returns a Repository
|
|
72
|
+
*/
|
|
73
|
+
export const makeRepo: {
|
|
74
|
+
<
|
|
75
|
+
ItemType extends string,
|
|
76
|
+
RSchema,
|
|
77
|
+
Encoded extends FieldValues,
|
|
78
|
+
T,
|
|
79
|
+
IdKey extends keyof T & keyof Encoded,
|
|
80
|
+
E = never,
|
|
81
|
+
Evt = never,
|
|
82
|
+
RInitial = never,
|
|
83
|
+
RPublish = never,
|
|
84
|
+
RCtx = never
|
|
85
|
+
>(
|
|
86
|
+
itemType: ItemType,
|
|
87
|
+
schema: S.Codec<T, Encoded, RSchema>,
|
|
88
|
+
options: RepositoryOptions<IdKey, Encoded, T, ItemType, Evt, RPublish, E, RInitial, RCtx, RSchema>
|
|
89
|
+
): Effect.Effect<
|
|
90
|
+
ExtendedRepository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish, RCtx>,
|
|
91
|
+
E,
|
|
92
|
+
RInitial | StoreMaker | RepositoryRegistry | Scope.Scope
|
|
93
|
+
>
|
|
94
|
+
<
|
|
95
|
+
ItemType extends string,
|
|
96
|
+
RSchema,
|
|
97
|
+
Encoded extends FieldValues,
|
|
98
|
+
T extends { id: unknown },
|
|
99
|
+
E = never,
|
|
100
|
+
Evt = never,
|
|
101
|
+
RInitial = never,
|
|
102
|
+
RPublish = never,
|
|
103
|
+
RCtx = never
|
|
104
|
+
>(
|
|
105
|
+
itemType: ItemType,
|
|
106
|
+
schema: S.Codec<T, Encoded, RSchema>,
|
|
107
|
+
options: Omit<RepositoryOptions<"id", Encoded, T, ItemType, Evt, RPublish, E, RInitial, RCtx, RSchema>, "idKey">
|
|
108
|
+
): Effect.Effect<
|
|
109
|
+
ExtendedRepository<T, Encoded, Evt, ItemType, "id", Exclude<RSchema, RCtx>, RPublish, RCtx>,
|
|
110
|
+
E,
|
|
111
|
+
RInitial | StoreMaker | RepositoryRegistry | Scope.Scope
|
|
112
|
+
>
|
|
113
|
+
} = <
|
|
114
|
+
ItemType extends string,
|
|
115
|
+
RSchema,
|
|
116
|
+
Encoded extends FieldValues,
|
|
117
|
+
T,
|
|
118
|
+
IdKey extends keyof T & keyof Encoded,
|
|
119
|
+
E = never,
|
|
120
|
+
RInitial = never,
|
|
121
|
+
RPublish = never,
|
|
122
|
+
Evt = never,
|
|
123
|
+
RCtx = never
|
|
124
|
+
>(
|
|
125
|
+
itemType: ItemType,
|
|
126
|
+
schema: S.Codec<T, Encoded, RSchema>,
|
|
127
|
+
options: Omit<RepositoryOptions<IdKey, Encoded, T, ItemType, Evt, RPublish, E, RInitial, RCtx, RSchema>, "idKey"> & {
|
|
128
|
+
idKey?: IdKey
|
|
129
|
+
}
|
|
130
|
+
) =>
|
|
131
|
+
Effect.gen(function*() {
|
|
132
|
+
const mkRepo = makeRepoInternal<Evt>()(
|
|
133
|
+
itemType,
|
|
134
|
+
schema,
|
|
135
|
+
options?.jitM ? (pm) => options.jitM!(pm) : (pm) => pm,
|
|
136
|
+
(e, _etag) => ({ ...e, _etag }),
|
|
137
|
+
options.idKey ?? "id" as any
|
|
138
|
+
)
|
|
139
|
+
let r = yield* mkRepo.make<RInitial, E, RPublish, RCtx>(options as any)
|
|
140
|
+
if (options.overrides) r = options.overrides(r)
|
|
141
|
+
const repo = extendRepo(r)
|
|
142
|
+
const registry = yield* RepositoryRegistry
|
|
143
|
+
registry.register(itemType, repo)
|
|
144
|
+
return repo
|
|
145
|
+
})
|