@effect-app/infra 4.0.0-beta.2 → 4.0.0-beta.200
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 +1514 -0
- package/_check.sh +1 -1
- package/dist/CUPS.d.ts +15 -7
- package/dist/CUPS.d.ts.map +1 -1
- package/dist/CUPS.js +10 -12
- package/dist/Emailer/Sendgrid.d.ts +14 -14
- package/dist/Emailer/Sendgrid.d.ts.map +1 -1
- package/dist/Emailer/Sendgrid.js +16 -15
- package/dist/Emailer/fake.d.ts +1 -1
- package/dist/Emailer/service.d.ts +11 -5
- package/dist/Emailer/service.d.ts.map +1 -1
- package/dist/Emailer/service.js +3 -3
- package/dist/Emailer.d.ts +1 -1
- package/dist/MainFiberSet.d.ts +9 -9
- package/dist/MainFiberSet.d.ts.map +1 -1
- package/dist/MainFiberSet.js +3 -3
- package/dist/Model/Repository/Registry.d.ts +20 -0
- package/dist/Model/Repository/Registry.d.ts.map +1 -0
- package/dist/Model/Repository/Registry.js +17 -0
- package/dist/Model/Repository/ext.d.ts +33 -15
- package/dist/Model/Repository/ext.d.ts.map +1 -1
- package/dist/Model/Repository/ext.js +54 -2
- package/dist/Model/Repository/internal/internal.d.ts +6 -6
- package/dist/Model/Repository/internal/internal.d.ts.map +1 -1
- package/dist/Model/Repository/internal/internal.js +43 -32
- package/dist/Model/Repository/legacy.d.ts +1 -1
- package/dist/Model/Repository/makeRepo.d.ts +7 -6
- package/dist/Model/Repository/makeRepo.d.ts.map +1 -1
- package/dist/Model/Repository/makeRepo.js +5 -1
- package/dist/Model/Repository/service.d.ts +28 -23
- package/dist/Model/Repository/service.d.ts.map +1 -1
- package/dist/Model/Repository/validation.d.ts +142 -17
- package/dist/Model/Repository/validation.d.ts.map +1 -1
- package/dist/Model/Repository/validation.js +5 -5
- package/dist/Model/Repository.d.ts +2 -1
- package/dist/Model/Repository.d.ts.map +1 -1
- package/dist/Model/Repository.js +2 -1
- package/dist/Model/dsl.d.ts +4 -4
- package/dist/Model/dsl.d.ts.map +1 -1
- package/dist/Model/filter/filterApi.d.ts +5 -5
- package/dist/Model/filter/filterApi.d.ts.map +1 -1
- package/dist/Model/filter/types/errors.d.ts +1 -1
- package/dist/Model/filter/types/fields.d.ts +1 -1
- package/dist/Model/filter/types/path/common.d.ts +1 -1
- package/dist/Model/filter/types/path/eager.d.ts +1 -1
- package/dist/Model/filter/types/path/eager.d.ts.map +1 -1
- package/dist/Model/filter/types/path/eager.js +1 -1
- package/dist/Model/filter/types/path/index.d.ts +1 -1
- package/dist/Model/filter/types/utils.d.ts +1 -1
- package/dist/Model/filter/types/validator.d.ts +1 -1
- package/dist/Model/filter/types.d.ts +1 -1
- package/dist/Model/query/dsl.d.ts +25 -25
- package/dist/Model/query/dsl.d.ts.map +1 -1
- package/dist/Model/query/new-kid-interpreter.d.ts +6 -6
- package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -1
- package/dist/Model/query/new-kid-interpreter.js +3 -3
- package/dist/Model/query.d.ts +1 -1
- package/dist/Model.d.ts +2 -1
- package/dist/Model.d.ts.map +1 -1
- package/dist/Model.js +2 -1
- package/dist/QueueMaker/SQLQueue.d.ts +6 -8
- package/dist/QueueMaker/SQLQueue.d.ts.map +1 -1
- package/dist/QueueMaker/SQLQueue.js +106 -115
- package/dist/QueueMaker/errors.d.ts +2 -2
- package/dist/QueueMaker/errors.d.ts.map +1 -1
- package/dist/QueueMaker/memQueue.d.ts +7 -4
- package/dist/QueueMaker/memQueue.d.ts.map +1 -1
- package/dist/QueueMaker/memQueue.js +52 -62
- package/dist/QueueMaker/sbqueue.d.ts +6 -3
- package/dist/QueueMaker/sbqueue.d.ts.map +1 -1
- package/dist/QueueMaker/sbqueue.js +39 -53
- package/dist/QueueMaker/service.d.ts +1 -1
- package/dist/RequestContext.d.ts +117 -31
- package/dist/RequestContext.d.ts.map +1 -1
- package/dist/RequestContext.js +7 -8
- package/dist/RequestFiberSet.d.ts +7 -7
- package/dist/RequestFiberSet.d.ts.map +1 -1
- package/dist/RequestFiberSet.js +5 -5
- package/dist/Store/ContextMapContainer.d.ts +20 -4
- package/dist/Store/ContextMapContainer.d.ts.map +1 -1
- package/dist/Store/ContextMapContainer.js +13 -3
- package/dist/Store/Cosmos/query.d.ts +1 -1
- package/dist/Store/Cosmos/query.d.ts.map +1 -1
- package/dist/Store/Cosmos/query.js +10 -12
- package/dist/Store/Cosmos.d.ts +1 -1
- package/dist/Store/Cosmos.d.ts.map +1 -1
- package/dist/Store/Cosmos.js +318 -240
- package/dist/Store/Disk.d.ts +2 -2
- package/dist/Store/Disk.d.ts.map +1 -1
- package/dist/Store/Disk.js +25 -22
- package/dist/Store/Memory.d.ts +4 -4
- package/dist/Store/Memory.d.ts.map +1 -1
- package/dist/Store/Memory.js +27 -22
- package/dist/Store/SQL/Pg.d.ts +4 -0
- package/dist/Store/SQL/Pg.d.ts.map +1 -0
- package/dist/Store/SQL/Pg.js +189 -0
- package/dist/Store/SQL/query.d.ts +38 -0
- package/dist/Store/SQL/query.d.ts.map +1 -0
- package/dist/Store/SQL/query.js +367 -0
- package/dist/Store/SQL.d.ts +20 -0
- package/dist/Store/SQL.d.ts.map +1 -0
- package/dist/Store/SQL.js +381 -0
- package/dist/Store/codeFilter.d.ts +1 -1
- package/dist/Store/codeFilter.d.ts.map +1 -1
- package/dist/Store/codeFilter.js +2 -1
- package/dist/Store/index.d.ts +5 -2
- package/dist/Store/index.d.ts.map +1 -1
- package/dist/Store/index.js +15 -3
- package/dist/Store/service.d.ts +18 -7
- package/dist/Store/service.d.ts.map +1 -1
- package/dist/Store/service.js +24 -6
- package/dist/Store/utils.d.ts +1 -1
- package/dist/Store/utils.d.ts.map +1 -1
- package/dist/Store/utils.js +3 -4
- package/dist/Store.d.ts +1 -1
- package/dist/adapters/SQL/Model.d.ts +30 -47
- package/dist/adapters/SQL/Model.d.ts.map +1 -1
- package/dist/adapters/SQL/Model.js +22 -14
- package/dist/adapters/SQL.d.ts +1 -1
- package/dist/adapters/ServiceBus.d.ts +11 -11
- package/dist/adapters/ServiceBus.d.ts.map +1 -1
- package/dist/adapters/ServiceBus.js +15 -17
- package/dist/adapters/cosmos-client.d.ts +3 -3
- package/dist/adapters/cosmos-client.d.ts.map +1 -1
- package/dist/adapters/cosmos-client.js +3 -3
- package/dist/adapters/index.d.ts +8 -2
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +8 -2
- package/dist/adapters/logger.d.ts +2 -2
- package/dist/adapters/logger.d.ts.map +1 -1
- package/dist/adapters/memQueue.d.ts +3 -3
- package/dist/adapters/memQueue.d.ts.map +1 -1
- package/dist/adapters/memQueue.js +3 -3
- package/dist/adapters/mongo-client.d.ts +3 -3
- package/dist/adapters/mongo-client.d.ts.map +1 -1
- package/dist/adapters/mongo-client.js +3 -3
- 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 +3 -3
- package/dist/api/ContextProvider.d.ts +8 -8
- package/dist/api/ContextProvider.d.ts.map +1 -1
- package/dist/api/ContextProvider.js +6 -6
- package/dist/api/codec.d.ts +1 -1
- package/dist/api/internal/RequestContextMiddleware.d.ts +2 -2
- package/dist/api/internal/RequestContextMiddleware.d.ts.map +1 -1
- package/dist/api/internal/RequestContextMiddleware.js +2 -2
- package/dist/api/internal/auth.d.ts +45 -7
- package/dist/api/internal/auth.d.ts.map +1 -1
- package/dist/api/internal/auth.js +160 -29
- package/dist/api/internal/events.d.ts +3 -3
- package/dist/api/internal/events.d.ts.map +1 -1
- package/dist/api/internal/events.js +12 -8
- package/dist/api/internal/health.d.ts +1 -1
- package/dist/api/layerUtils.d.ts +6 -6
- package/dist/api/layerUtils.d.ts.map +1 -1
- package/dist/api/layerUtils.js +5 -5
- package/dist/api/middlewares.d.ts +1 -1
- package/dist/api/reportError.d.ts +1 -1
- 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 +50 -4
- package/dist/api/routing/middleware/middleware.d.ts.map +1 -1
- package/dist/api/routing/middleware/middleware.js +79 -17
- package/dist/api/routing/middleware.d.ts +1 -2
- package/dist/api/routing/middleware.d.ts.map +1 -1
- package/dist/api/routing/middleware.js +1 -2
- package/dist/api/routing/schema/jwt.d.ts +2 -2
- package/dist/api/routing/schema/jwt.d.ts.map +1 -1
- package/dist/api/routing/schema/jwt.js +1 -1
- package/dist/api/routing/tsort.d.ts +1 -1
- package/dist/api/routing/tsort.d.ts.map +1 -1
- package/dist/api/routing/utils.d.ts +3 -3
- package/dist/api/routing/utils.d.ts.map +1 -1
- package/dist/api/routing.d.ts +32 -35
- package/dist/api/routing.d.ts.map +1 -1
- package/dist/api/routing.js +84 -36
- package/dist/api/setupRequest.d.ts +8 -5
- package/dist/api/setupRequest.d.ts.map +1 -1
- package/dist/api/setupRequest.js +14 -9
- package/dist/api/util.d.ts +1 -1
- package/dist/arbs.d.ts +1 -1
- package/dist/arbs.d.ts.map +1 -1
- package/dist/arbs.js +5 -3
- package/dist/errorReporter.d.ts +5 -5
- package/dist/errorReporter.d.ts.map +1 -1
- package/dist/errorReporter.js +20 -25
- package/dist/errors.d.ts +1 -1
- package/dist/fileUtil.d.ts +1 -1
- package/dist/fileUtil.d.ts.map +1 -1
- package/dist/fileUtil.js +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/logger/jsonLogger.d.ts +1 -1
- package/dist/logger/logFmtLogger.d.ts +1 -1
- package/dist/logger/shared.d.ts +1 -1
- package/dist/logger/shared.js +2 -2
- package/dist/logger.d.ts +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/rateLimit.d.ts +9 -3
- package/dist/rateLimit.d.ts.map +1 -1
- package/dist/rateLimit.js +5 -11
- package/dist/test.d.ts +2 -2
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +1 -1
- package/dist/vitest.d.ts +1 -1
- package/examples/query.ts +39 -35
- package/package.json +41 -37
- package/src/CUPS.ts +9 -11
- package/src/Emailer/Sendgrid.ts +18 -15
- package/src/Emailer/service.ts +9 -3
- package/src/MainFiberSet.ts +5 -6
- package/src/Model/Repository/Registry.ts +33 -0
- package/src/Model/Repository/ext.ts +96 -10
- package/src/Model/Repository/internal/internal.ts +97 -88
- package/src/Model/Repository/makeRepo.ts +12 -10
- package/src/Model/Repository/service.ts +31 -22
- package/src/Model/Repository/validation.ts +4 -4
- package/src/Model/Repository.ts +1 -0
- package/src/Model/dsl.ts +3 -3
- package/src/Model/filter/types/path/eager.ts +1 -2
- package/src/Model/query/dsl.ts +18 -18
- package/src/Model/query/new-kid-interpreter.ts +2 -2
- package/src/Model.ts +1 -0
- package/src/QueueMaker/SQLQueue.ts +123 -154
- package/src/QueueMaker/memQueue.ts +85 -107
- package/src/QueueMaker/sbqueue.ts +54 -81
- package/src/RequestContext.ts +8 -10
- package/src/RequestFiberSet.ts +4 -4
- package/src/Store/ContextMapContainer.ts +41 -2
- package/src/Store/Cosmos/query.ts +16 -20
- package/src/Store/Cosmos.ts +452 -342
- package/src/Store/Disk.ts +52 -49
- package/src/Store/Memory.ts +55 -51
- package/src/Store/SQL/Pg.ts +318 -0
- package/src/Store/SQL/query.ts +409 -0
- package/src/Store/SQL.ts +668 -0
- package/src/Store/codeFilter.ts +1 -0
- package/src/Store/index.ts +17 -2
- package/src/Store/service.ts +32 -8
- package/src/Store/utils.ts +23 -22
- package/src/adapters/SQL/Model.ts +83 -72
- package/src/adapters/ServiceBus.ts +114 -118
- package/src/adapters/cosmos-client.ts +2 -2
- package/src/adapters/index.ts +7 -0
- package/src/adapters/memQueue.ts +2 -2
- package/src/adapters/mongo-client.ts +2 -2
- package/src/adapters/redis-client.ts +2 -2
- package/src/api/ContextProvider.ts +12 -13
- package/src/api/internal/RequestContextMiddleware.ts +1 -1
- package/src/api/internal/auth.ts +246 -44
- package/src/api/internal/events.ts +15 -10
- package/src/api/layerUtils.ts +8 -8
- package/src/api/routing/middleware/RouterMiddleware.ts +4 -4
- package/src/api/routing/middleware/middleware.ts +112 -15
- package/src/api/routing/middleware.ts +0 -2
- package/src/api/routing/schema/jwt.ts +2 -3
- package/src/api/routing.ts +153 -79
- package/src/api/setupRequest.ts +30 -10
- package/src/arbs.ts +4 -2
- package/src/errorReporter.ts +63 -75
- package/src/fileUtil.ts +2 -1
- package/src/logger/shared.ts +1 -1
- package/src/rateLimit.ts +30 -22
- package/src/test.ts +1 -1
- package/test/auth.test.ts +101 -0
- package/test/contextProvider.test.ts +11 -11
- package/test/controller.test.ts +27 -21
- package/test/dist/auth.test.d.ts.map +1 -0
- 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 +26 -12
- package/test/dist/fixtures.d.ts.map +1 -1
- package/test/dist/fixtures.js +12 -10
- package/test/dist/query.test.d.ts.map +1 -1
- package/test/dist/rawQuery.test.d.ts.map +1 -1
- package/test/dist/repository-ext.test.d.ts.map +1 -0
- package/test/dist/requires.test.d.ts.map +1 -1
- package/test/dist/router-generator.test.d.ts.map +1 -0
- package/test/dist/routing-interruptibility.test.d.ts.map +1 -0
- package/test/dist/rpc-e2e-invalidation.test.d.ts.map +1 -0
- package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
- package/test/dist/rpc-stream-fullstack.test.d.ts.map +1 -0
- package/test/dist/sql-store.test.d.ts.map +1 -0
- package/test/fixtures.ts +11 -9
- package/test/query.test.ts +216 -36
- package/test/rawQuery.test.ts +23 -19
- package/test/repository-ext.test.ts +60 -0
- package/test/requires.test.ts +6 -6
- package/test/router-generator.test.ts +180 -0
- package/test/routing-interruptibility.test.ts +63 -0
- package/test/rpc-e2e-invalidation.test.ts +507 -0
- package/test/rpc-multi-middleware.test.ts +79 -10
- package/test/rpc-stream-fullstack.test.ts +325 -0
- package/test/sql-store.test.ts +1064 -0
- package/test/validateSample.test.ts +15 -12
- package/tsconfig.examples.json +1 -1
- package/tsconfig.json +0 -1
- package/tsconfig.json.bak +2 -2
- package/tsconfig.src.json +35 -35
- package/tsconfig.test.json +2 -2
- package/dist/Operations.d.ts +0 -55
- package/dist/Operations.d.ts.map +0 -1
- package/dist/Operations.js +0 -102
- package/dist/OperationsRepo.d.ts +0 -41
- package/dist/OperationsRepo.d.ts.map +0 -1
- package/dist/OperationsRepo.js +0 -14
- package/eslint.config.mjs +0 -24
- package/src/Operations.ts +0 -235
- package/src/OperationsRepo.ts +0 -16
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
import type
|
|
4
|
-
import { Array, Chunk, Effect, Equivalence, flow, type NonEmptyReadonlyArray, Option, pipe, Pipeable, PubSub, Result, S, SchemaAST, ServiceMap, Unify } from "effect-app"
|
|
2
|
+
|
|
3
|
+
import { Array, Chunk, Context, Effect, Equivalence, flow, type NonEmptyReadonlyArray, Option, pipe, Pipeable, PubSub, Result, S, SchemaAST, Unify } from "effect-app"
|
|
5
4
|
import { toNonEmptyArray } from "effect-app/Array"
|
|
6
5
|
import { NotFoundError } from "effect-app/client/errors"
|
|
7
6
|
import { flatMapOption } from "effect-app/Effect"
|
|
@@ -55,14 +54,14 @@ export function makeRepoInternal<
|
|
|
55
54
|
|
|
56
55
|
function make<RInitial = never, E = never, RPublish = never, RCtx = never>(
|
|
57
56
|
args: [Evt] extends [never] ? {
|
|
58
|
-
schemaContext?:
|
|
57
|
+
schemaContext?: Context.Context<RCtx>
|
|
59
58
|
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
60
59
|
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
61
60
|
partitionValue?: (e?: Encoded) => string
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
: {
|
|
65
|
-
schemaContext?:
|
|
64
|
+
schemaContext?: Context.Context<RCtx>
|
|
66
65
|
publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect.Effect<void, never, RPublish>
|
|
67
66
|
makeInitial?: Effect.Effect<readonly T[], E, RInitial> | undefined
|
|
68
67
|
config?: Omit<StoreConfig<Encoded>, "partitionValue"> & {
|
|
@@ -72,16 +71,16 @@ export function makeRepoInternal<
|
|
|
72
71
|
) {
|
|
73
72
|
return Effect
|
|
74
73
|
.gen(function*() {
|
|
75
|
-
const rctx:
|
|
74
|
+
const rctx: Context.Context<RCtx> = args.schemaContext ?? Context.empty() as any
|
|
76
75
|
const provideRctx = Effect.provide(rctx)
|
|
77
76
|
const encodeMany = flow(
|
|
78
77
|
S.encodeEffect(S.Array(schema)),
|
|
79
78
|
provideRctx,
|
|
80
|
-
Effect.withSpan("encodeMany", {}, { captureStackTrace: false })
|
|
79
|
+
Effect.withSpan("encodeMany", { attributes: { itemType: name } }, { captureStackTrace: false })
|
|
81
80
|
)
|
|
82
|
-
const decode = flow(S.
|
|
81
|
+
const decode = flow(S.decodeEffectConcurrently(schema), provideRctx)
|
|
83
82
|
const decodeMany = flow(
|
|
84
|
-
S.
|
|
83
|
+
S.decodeEffectConcurrently(S.Array(schema)),
|
|
85
84
|
provideRctx
|
|
86
85
|
)
|
|
87
86
|
|
|
@@ -113,11 +112,14 @@ export function makeRepoInternal<
|
|
|
113
112
|
let ast = _.ast
|
|
114
113
|
if (ast._tag === "Declaration") ast = ast.typeParameters[0]!
|
|
115
114
|
|
|
116
|
-
// In v4, to get the encoded (from) side of a schema, use SchemaAST.toEncoded
|
|
117
115
|
const pickIdFromAst = (a: SchemaAST.AST) => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
// Unwrap Declaration (e.g. TaggedClass) to get the underlying Objects AST
|
|
117
|
+
let inner = a
|
|
118
|
+
if (inner._tag === "Declaration") inner = inner.typeParameters[0]!
|
|
119
|
+
// Pick from the original AST to preserve the full encoding chain (e.g. decodeTo transformations).
|
|
120
|
+
// Using toEncoded would lose transformation info needed to encode Type -> Encoded.
|
|
121
|
+
if (SchemaAST.isObjects(inner)) {
|
|
122
|
+
const field = inner.propertySignatures.find((_) => _.name === idKey)
|
|
121
123
|
if (field) {
|
|
122
124
|
return S.Struct({ [idKey]: S.make(field.type) }) as unknown as Codec<T, Encoded>
|
|
123
125
|
}
|
|
@@ -161,7 +163,7 @@ export function makeRepoInternal<
|
|
|
161
163
|
)
|
|
162
164
|
})
|
|
163
165
|
|
|
164
|
-
const find = Effect.fn("find")(function*(id: T[IdKey]) {
|
|
166
|
+
const find = Effect.fn("find", { attributes: { itemType: name } })(function*(id: T[IdKey]) {
|
|
165
167
|
yield* Effect.annotateCurrentSpan({ itemId: id })
|
|
166
168
|
|
|
167
169
|
return yield* flatMapOption(findE(id), (_) => Effect.orDie(decode(_)))
|
|
@@ -188,73 +190,78 @@ export function makeRepoInternal<
|
|
|
188
190
|
Effect.andThen(saveAllE)
|
|
189
191
|
)
|
|
190
192
|
|
|
191
|
-
const saveAndPublish = Effect.fn("saveAndPublish"
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
193
|
+
const saveAndPublish = Effect.fn("saveAndPublish", { attributes: { itemType: name } })(
|
|
194
|
+
function*(items: Iterable<T>, events: Iterable<Evt> = []) {
|
|
195
|
+
const it = Chunk.fromIterable(items)
|
|
196
|
+
const evts = [...events]
|
|
197
|
+
yield* Effect.annotateCurrentSpan({ itemIds: Chunk.map(it, (_) => _[idKey]), events: evts.length })
|
|
198
|
+
return yield* saveAll(it)
|
|
199
|
+
.pipe(
|
|
200
|
+
Effect.andThen(Effect.sync(() => toNonEmptyArray(evts))),
|
|
201
|
+
// TODO: for full consistency the events should be stored within the same database transaction, and then picked up.
|
|
202
|
+
(_) => flatMapOption(_, pub),
|
|
203
|
+
Effect.andThen(PubSub.publish(changeFeed, [Chunk.toArray(it), "save"] as [T[], "save" | "remove"])),
|
|
204
|
+
Effect.asVoid
|
|
205
|
+
)
|
|
206
|
+
}
|
|
207
|
+
)
|
|
204
208
|
|
|
205
|
-
const removeAndPublish = Effect.fn("removeAndPublish"
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
209
|
+
const removeAndPublish = Effect.fn("removeAndPublish", { attributes: { itemType: name } })(
|
|
210
|
+
function*(a: Iterable<T>, events: Iterable<Evt> = []) {
|
|
211
|
+
const { set } = yield* cms
|
|
212
|
+
const it = [...a]
|
|
213
|
+
const evts = [...events]
|
|
214
|
+
yield* Effect.annotateCurrentSpan({ itemIds: it.map((_) => _[idKey]), eventCount: evts.length })
|
|
215
|
+
const items = yield* encodeMany(it).pipe(Effect.orDie)
|
|
216
|
+
if (Array.isReadonlyArrayNonEmpty(items)) {
|
|
217
|
+
yield* store.batchRemove(
|
|
218
|
+
items.map((_) => (_[idKey])),
|
|
219
|
+
args.config?.partitionValue?.(items[0])
|
|
220
|
+
)
|
|
221
|
+
for (const e of items) {
|
|
222
|
+
set(e[idKey], undefined)
|
|
223
|
+
}
|
|
224
|
+
yield* Effect
|
|
225
|
+
.sync(() => toNonEmptyArray(evts))
|
|
226
|
+
// TODO: for full consistency the events should be stored within the same database transaction, and then picked up.
|
|
227
|
+
.pipe((_) => flatMapOption(_, pub))
|
|
223
228
|
|
|
224
|
-
|
|
229
|
+
yield* PubSub.publish(changeFeed, [it, "remove"] as [T[], "save" | "remove"])
|
|
230
|
+
}
|
|
225
231
|
}
|
|
226
|
-
|
|
232
|
+
)
|
|
227
233
|
|
|
228
|
-
const removeById = Effect.fn("removeById"
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
234
|
+
const removeById = Effect.fn("removeById", { attributes: { itemType: name } })(
|
|
235
|
+
function*(idOrIds: T[IdKey] | ReadonlyArray<T[IdKey]>) {
|
|
236
|
+
const ids = globalThis.Array.isArray(idOrIds)
|
|
237
|
+
? idOrIds as readonly T[IdKey][]
|
|
238
|
+
: [idOrIds as T[IdKey]]
|
|
239
|
+
if (!Array.isReadonlyArrayNonEmpty(ids)) {
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
const { set } = yield* cms
|
|
243
|
+
const eids = yield* Effect.forEach(ids, (_) => encodeIdOnly(_ as any)).pipe(Effect.orDie)
|
|
244
|
+
yield* Effect.annotateCurrentSpan({ itemIds: eids })
|
|
245
|
+
yield* store.batchRemove(eids)
|
|
246
|
+
for (const id of eids) {
|
|
247
|
+
set(id, undefined)
|
|
248
|
+
}
|
|
249
|
+
yield* PubSub.publish(changeFeed, [[], "remove"] as [T[], "save" | "remove"])
|
|
238
250
|
}
|
|
239
|
-
|
|
240
|
-
})
|
|
251
|
+
)
|
|
241
252
|
|
|
242
|
-
const parseMany = (items: readonly PM[])
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
.decodeEffect(S.Array(schema))(
|
|
255
|
-
items.map((_) => mapReverse(_, cm.set))
|
|
256
|
-
)
|
|
257
|
-
.pipe(Effect.orDie, Effect.withSpan("parseMany2", {}, { captureStackTrace: false })))
|
|
253
|
+
const parseMany = Effect.fn("parseMany", { attributes: { itemType: name } })(function*(items: readonly PM[]) {
|
|
254
|
+
const cm = yield* cms
|
|
255
|
+
return yield* decodeMany(items.map((_) => mapReverse(_, cm.set))).pipe(Effect.orDie)
|
|
256
|
+
})
|
|
257
|
+
const parseMany2 = Effect.fn("parseMany2", { attributes: { itemType: name } })(
|
|
258
|
+
function*<A, R>(items: readonly PM[], schema: S.Codec<A, Encoded, R>) {
|
|
259
|
+
const cm = yield* cms
|
|
260
|
+
return yield* S.decodeEffectConcurrently(S.Array(schema))(items.map((_) => mapReverse(_, cm.set))).pipe(
|
|
261
|
+
Effect.orDie
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
)
|
|
258
265
|
const filter = <U extends keyof Encoded = keyof Encoded>(args: FilterArgs<Encoded, U>) =>
|
|
259
266
|
store
|
|
260
267
|
.filter(
|
|
@@ -276,24 +283,24 @@ export function makeRepoInternal<
|
|
|
276
283
|
const query: {
|
|
277
284
|
<A, R, From extends FieldValues>(
|
|
278
285
|
q: Q.QueryProjection<Encoded extends From ? From : never, A, R>
|
|
279
|
-
): Effect.Effect<readonly A[], S.SchemaError, R
|
|
286
|
+
): Effect.Effect<readonly A[], S.SchemaError, Exclude<R, RCtx>>
|
|
280
287
|
<A, R, EncodedRefined extends Encoded = Encoded>(
|
|
281
288
|
q: Q.QAll<NoInfer<Encoded>, NoInfer<EncodedRefined>, A, R>
|
|
282
|
-
): Effect.Effect<readonly A[], never, R
|
|
289
|
+
): Effect.Effect<readonly A[], never, Exclude<R, RCtx>>
|
|
283
290
|
} = (<A, R, EncodedRefined extends Encoded = Encoded>(q: Q.QAll<Encoded, EncodedRefined, A, R>) => {
|
|
284
291
|
const a = Q.toFilter(q)
|
|
285
292
|
const eff = a.mode === "project"
|
|
286
293
|
? filter(a)
|
|
287
294
|
// TODO: mapFrom but need to support per field and dependencies
|
|
288
295
|
.pipe(
|
|
289
|
-
Effect.andThen(flow(S.
|
|
296
|
+
Effect.andThen(flow(S.decodeEffectConcurrently(S.Array(a.schema ?? schema)), provideRctx))
|
|
290
297
|
)
|
|
291
298
|
: a.mode === "collect"
|
|
292
299
|
? filter(a)
|
|
293
300
|
// TODO: mapFrom but need to support per field and dependencies
|
|
294
301
|
.pipe(
|
|
295
302
|
Effect.flatMap(flow(
|
|
296
|
-
S.
|
|
303
|
+
S.decodeEffectConcurrently(S.Array(a.schema)),
|
|
297
304
|
Effect.map(Array.getSomes),
|
|
298
305
|
provideRctx
|
|
299
306
|
))
|
|
@@ -327,6 +334,7 @@ export function makeRepoInternal<
|
|
|
327
334
|
: eff,
|
|
328
335
|
Effect.withSpan("Repository.query [effect-app/infra]", {
|
|
329
336
|
attributes: {
|
|
337
|
+
itemType: name,
|
|
330
338
|
"repository.model_name": name,
|
|
331
339
|
query: { ...a, schema: a.schema ? "__SCHEMA__" : a.schema, filter: a.filter }
|
|
332
340
|
}
|
|
@@ -334,7 +342,7 @@ export function makeRepoInternal<
|
|
|
334
342
|
)
|
|
335
343
|
}) as any
|
|
336
344
|
|
|
337
|
-
const validateSample = Effect.fn("validateSample")(function*(options?: {
|
|
345
|
+
const validateSample = Effect.fn("validateSample", { attributes: { itemType: name } })(function*(options?: {
|
|
338
346
|
percentage?: number
|
|
339
347
|
maxItems?: number
|
|
340
348
|
}) {
|
|
@@ -367,14 +375,14 @@ export function makeRepoInternal<
|
|
|
367
375
|
const rawData = rawResult.value as Encoded
|
|
368
376
|
const jitMResult = mapFrom(rawData) // apply jitM
|
|
369
377
|
|
|
370
|
-
const decodeResult = yield* S.
|
|
378
|
+
const decodeResult = yield* S.decodeEffectConcurrently(schema)(jitMResult).pipe(
|
|
371
379
|
Effect.result,
|
|
372
380
|
provideRctx
|
|
373
381
|
)
|
|
374
382
|
|
|
375
383
|
if (Result.isFailure(decodeResult)) {
|
|
376
384
|
errors.push(
|
|
377
|
-
|
|
385
|
+
ValidationError.make({
|
|
378
386
|
id,
|
|
379
387
|
rawData,
|
|
380
388
|
jitMResult,
|
|
@@ -384,7 +392,7 @@ export function makeRepoInternal<
|
|
|
384
392
|
}
|
|
385
393
|
}
|
|
386
394
|
|
|
387
|
-
return
|
|
395
|
+
return ValidationResult.make({
|
|
388
396
|
total: NonNegativeInt(allIds.length),
|
|
389
397
|
sampled: NonNegativeInt(sample.length),
|
|
390
398
|
valid: NonNegativeInt(sample.length - errors.length),
|
|
@@ -401,9 +409,10 @@ export function makeRepoInternal<
|
|
|
401
409
|
saveAndPublish,
|
|
402
410
|
removeAndPublish,
|
|
403
411
|
removeById,
|
|
412
|
+
seedNamespace: (namespace: string) => store.seedNamespace(namespace),
|
|
404
413
|
validateSample,
|
|
405
414
|
queryRaw<A, Out, QR>(schema: S.Codec<A, Out, QR>, q: Q.RawQuery<Encoded, Out>) {
|
|
406
|
-
const dec = S.
|
|
415
|
+
const dec = S.decodeEffectConcurrently(S.Array(schema))
|
|
407
416
|
return store.queryRaw(q).pipe(Effect.flatMap(dec))
|
|
408
417
|
},
|
|
409
418
|
query(q: any) {
|
|
@@ -414,9 +423,9 @@ export function makeRepoInternal<
|
|
|
414
423
|
* @internal
|
|
415
424
|
*/
|
|
416
425
|
mapped: <A, R>(schema: S.Codec<A, any, R>) => {
|
|
417
|
-
const dec = S.
|
|
426
|
+
const dec = S.decodeEffectConcurrently(schema)
|
|
418
427
|
const encMany = S.encodeEffect(S.Array(schema))
|
|
419
|
-
const decMany = S.
|
|
428
|
+
const decMany = S.decodeEffectConcurrently(S.Array(schema))
|
|
420
429
|
return {
|
|
421
430
|
all: allE.pipe(
|
|
422
431
|
Effect.flatMap(decMany),
|
|
@@ -441,12 +450,12 @@ export function makeRepoInternal<
|
|
|
441
450
|
// },
|
|
442
451
|
save: (...xes: any[]) =>
|
|
443
452
|
Effect.flatMap(encMany(xes), (_) => saveAllE(_)).pipe(
|
|
444
|
-
Effect.withSpan("mapped.save", {}, { captureStackTrace: false })
|
|
453
|
+
Effect.withSpan("mapped.save", { attributes: { itemType: name } }, { captureStackTrace: false })
|
|
445
454
|
)
|
|
446
455
|
}
|
|
447
456
|
}
|
|
448
457
|
}
|
|
449
|
-
return r as Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<R, RCtx>, RPublish>
|
|
458
|
+
return r as Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<R, RCtx>, RPublish, RCtx>
|
|
450
459
|
})
|
|
451
460
|
.pipe(Effect
|
|
452
461
|
// .withSpan("Repository.make [effect-app/infra]", { attributes: { "repository.model_name": name } })
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
6
6
|
|
|
7
7
|
// import type { ParserEnv } from "effect-app/Schema/custom/Parser"
|
|
8
|
-
|
|
9
|
-
import type
|
|
10
|
-
import { Effect, type NonEmptyReadonlyArray, type S, type ServiceMap } from "effect-app"
|
|
8
|
+
|
|
9
|
+
import { type Context, Effect, type NonEmptyReadonlyArray, type S } from "effect-app"
|
|
11
10
|
import type { StoreConfig, StoreMaker } from "../../Store.js"
|
|
12
11
|
import type { FieldValues } from "../filter/types.js"
|
|
13
12
|
import { type ExtendedRepository, extendRepo } from "./ext.js"
|
|
14
13
|
import { makeRepoInternal } from "./internal/internal.js"
|
|
14
|
+
import { RepositoryRegistry } from "./Registry.js"
|
|
15
15
|
import type { Repository } from "./service.js"
|
|
16
16
|
|
|
17
17
|
export interface RepositoryOptions<
|
|
@@ -52,11 +52,11 @@ export interface RepositoryOptions<
|
|
|
52
52
|
* Optional context to be provided to Schema decode/encode.
|
|
53
53
|
* Useful for effectful transformations like XWithItems, where items is a transformation retrieving elements from another database table or other source.
|
|
54
54
|
*/
|
|
55
|
-
schemaContext?:
|
|
55
|
+
schemaContext?: Context.Context<RCtx>
|
|
56
56
|
|
|
57
57
|
overrides?: (
|
|
58
|
-
repo: Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish>
|
|
59
|
-
) => Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish>
|
|
58
|
+
repo: Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish, RCtx>
|
|
59
|
+
) => Repository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish, RCtx>
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
@@ -83,9 +83,9 @@ export const makeRepo: {
|
|
|
83
83
|
schema: S.Codec<T, Encoded, RSchema>,
|
|
84
84
|
options: RepositoryOptions<IdKey, Encoded, T, ItemType, Evt, RPublish, E, RInitial, RCtx, RSchema>
|
|
85
85
|
): Effect.Effect<
|
|
86
|
-
ExtendedRepository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish>,
|
|
86
|
+
ExtendedRepository<T, Encoded, Evt, ItemType, IdKey, Exclude<RSchema, RCtx>, RPublish, RCtx>,
|
|
87
87
|
E,
|
|
88
|
-
RInitial | StoreMaker
|
|
88
|
+
RInitial | StoreMaker | RepositoryRegistry
|
|
89
89
|
>
|
|
90
90
|
<
|
|
91
91
|
ItemType extends string,
|
|
@@ -102,9 +102,9 @@ export const makeRepo: {
|
|
|
102
102
|
schema: S.Codec<T, Encoded, RSchema>,
|
|
103
103
|
options: Omit<RepositoryOptions<"id", Encoded, T, ItemType, Evt, RPublish, E, RInitial, RCtx, RSchema>, "idKey">
|
|
104
104
|
): Effect.Effect<
|
|
105
|
-
ExtendedRepository<T, Encoded, Evt, ItemType, "id", Exclude<RSchema, RCtx>, RPublish>,
|
|
105
|
+
ExtendedRepository<T, Encoded, Evt, ItemType, "id", Exclude<RSchema, RCtx>, RPublish, RCtx>,
|
|
106
106
|
E,
|
|
107
|
-
RInitial | StoreMaker
|
|
107
|
+
RInitial | StoreMaker | RepositoryRegistry
|
|
108
108
|
>
|
|
109
109
|
} = <
|
|
110
110
|
ItemType extends string,
|
|
@@ -135,5 +135,7 @@ export const makeRepo: {
|
|
|
135
135
|
let r = yield* mkRepo.make<RInitial, E, RPublish, RCtx>(options as any)
|
|
136
136
|
if (options.overrides) r = options.overrides(r)
|
|
137
137
|
const repo = extendRepo(r)
|
|
138
|
+
const registry = yield* RepositoryRegistry
|
|
139
|
+
registry.register(itemType, repo)
|
|
138
140
|
return repo
|
|
139
141
|
})
|
|
@@ -14,7 +14,8 @@ export interface Repository<
|
|
|
14
14
|
ItemType extends string,
|
|
15
15
|
IdKey extends keyof T,
|
|
16
16
|
RSchema,
|
|
17
|
-
RPublish
|
|
17
|
+
RPublish,
|
|
18
|
+
RProvided = never
|
|
18
19
|
> {
|
|
19
20
|
readonly itemType: ItemType
|
|
20
21
|
readonly idKey: IdKey
|
|
@@ -30,13 +31,21 @@ export interface Repository<
|
|
|
30
31
|
events?: Iterable<Evt>
|
|
31
32
|
) => Effect.Effect<void, never, RSchema | RPublish>
|
|
32
33
|
|
|
33
|
-
readonly removeById: (
|
|
34
|
+
readonly removeById: (
|
|
35
|
+
idOrIds: T[IdKey] | ReadonlyArray<T[IdKey]>
|
|
36
|
+
) => Effect.Effect<void, never, RSchema>
|
|
34
37
|
|
|
35
38
|
readonly queryRaw: <T, Out, R>(
|
|
36
39
|
schema: S.Codec<T, Out, R>,
|
|
37
40
|
raw: RawQuery<Encoded, Out>
|
|
38
41
|
) => Effect.Effect<readonly T[], S.SchemaError, R>
|
|
39
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Explicitly seed a namespace. Primary is seeded eagerly on initialization.
|
|
45
|
+
* Non-primary namespaces must be seeded explicitly before use.
|
|
46
|
+
*/
|
|
47
|
+
readonly seedNamespace: (namespace: string) => Effect.Effect<void>
|
|
48
|
+
|
|
40
49
|
readonly query: {
|
|
41
50
|
// ending with projection
|
|
42
51
|
<
|
|
@@ -53,7 +62,7 @@ export interface Repository<
|
|
|
53
62
|
TType extends "many" ? readonly A[] : TType extends "count" ? NonNegativeInt : A,
|
|
54
63
|
| (TType extends "many" ? never : NotFoundError<ItemType>)
|
|
55
64
|
| (TType extends "count" ? never : S.SchemaError),
|
|
56
|
-
R | RSchema
|
|
65
|
+
Exclude<R, RProvided> | RSchema
|
|
57
66
|
>
|
|
58
67
|
<
|
|
59
68
|
A,
|
|
@@ -73,7 +82,7 @@ export interface Repository<
|
|
|
73
82
|
TType extends "many" ? readonly A[] : TType extends "count" ? NonNegativeInt : A,
|
|
74
83
|
| (TType extends "many" ? never : NotFoundError<ItemType>)
|
|
75
84
|
| (TType extends "count" ? never : S.SchemaError),
|
|
76
|
-
R | RSchema
|
|
85
|
+
Exclude<R, RProvided> | RSchema
|
|
77
86
|
>
|
|
78
87
|
<
|
|
79
88
|
A,
|
|
@@ -95,7 +104,7 @@ export interface Repository<
|
|
|
95
104
|
TType extends "many" ? readonly A[] : TType extends "count" ? NonNegativeInt : A,
|
|
96
105
|
| (TType extends "many" ? never : NotFoundError<ItemType>)
|
|
97
106
|
| (TType extends "count" ? never : S.SchemaError),
|
|
98
|
-
R | RSchema
|
|
107
|
+
Exclude<R, RProvided> | RSchema
|
|
99
108
|
>
|
|
100
109
|
<
|
|
101
110
|
A,
|
|
@@ -119,7 +128,7 @@ export interface Repository<
|
|
|
119
128
|
TType extends "many" ? readonly A[] : TType extends "count" ? NonNegativeInt : A,
|
|
120
129
|
| (TType extends "many" ? never : NotFoundError<ItemType>)
|
|
121
130
|
| (TType extends "count" ? never : S.SchemaError),
|
|
122
|
-
R | RSchema
|
|
131
|
+
Exclude<R, RProvided> | RSchema
|
|
123
132
|
>
|
|
124
133
|
<
|
|
125
134
|
A,
|
|
@@ -145,7 +154,7 @@ export interface Repository<
|
|
|
145
154
|
TType extends "many" ? readonly A[] : TType extends "count" ? NonNegativeInt : A,
|
|
146
155
|
| (TType extends "many" ? never : NotFoundError<ItemType>)
|
|
147
156
|
| (TType extends "count" ? never : S.SchemaError),
|
|
148
|
-
R | RSchema
|
|
157
|
+
Exclude<R, RProvided> | RSchema
|
|
149
158
|
>
|
|
150
159
|
<
|
|
151
160
|
A,
|
|
@@ -171,7 +180,7 @@ export interface Repository<
|
|
|
171
180
|
TType extends "many" ? readonly A[] : TType extends "count" ? NonNegativeInt : A,
|
|
172
181
|
| (TType extends "many" ? never : NotFoundError<ItemType>)
|
|
173
182
|
| (TType extends "count" ? never : S.SchemaError),
|
|
174
|
-
R | RSchema
|
|
183
|
+
Exclude<R, RProvided> | RSchema
|
|
175
184
|
>
|
|
176
185
|
<
|
|
177
186
|
A,
|
|
@@ -199,7 +208,7 @@ export interface Repository<
|
|
|
199
208
|
TType extends "many" ? readonly A[] : TType extends "count" ? NonNegativeInt : A,
|
|
200
209
|
| (TType extends "many" ? never : NotFoundError<ItemType>)
|
|
201
210
|
| (TType extends "count" ? never : S.SchemaError),
|
|
202
|
-
R | RSchema
|
|
211
|
+
Exclude<R, RProvided> | RSchema
|
|
203
212
|
>
|
|
204
213
|
<
|
|
205
214
|
A,
|
|
@@ -229,7 +238,7 @@ export interface Repository<
|
|
|
229
238
|
TType extends "many" ? readonly A[] : TType extends "count" ? NonNegativeInt : A,
|
|
230
239
|
| (TType extends "many" ? never : NotFoundError<ItemType>)
|
|
231
240
|
| (TType extends "count" ? never : S.SchemaError),
|
|
232
|
-
R | RSchema
|
|
241
|
+
Exclude<R, RProvided> | RSchema
|
|
233
242
|
>
|
|
234
243
|
<
|
|
235
244
|
A,
|
|
@@ -261,7 +270,7 @@ export interface Repository<
|
|
|
261
270
|
TType extends "many" ? readonly A[] : TType extends "count" ? NonNegativeInt : A,
|
|
262
271
|
| (TType extends "many" ? never : NotFoundError<ItemType>)
|
|
263
272
|
| (TType extends "count" ? never : S.SchemaError),
|
|
264
|
-
R | RSchema
|
|
273
|
+
Exclude<R, RProvided> | RSchema
|
|
265
274
|
>
|
|
266
275
|
<
|
|
267
276
|
A,
|
|
@@ -295,7 +304,7 @@ export interface Repository<
|
|
|
295
304
|
TType extends "many" ? readonly A[] : TType extends "count" ? NonNegativeInt : A,
|
|
296
305
|
| (TType extends "many" ? never : NotFoundError<ItemType>)
|
|
297
306
|
| (TType extends "count" ? never : S.SchemaError),
|
|
298
|
-
R | RSchema
|
|
307
|
+
Exclude<R, RProvided> | RSchema
|
|
299
308
|
>
|
|
300
309
|
|
|
301
310
|
// ending with generic query
|
|
@@ -309,7 +318,7 @@ export interface Repository<
|
|
|
309
318
|
): Effect.Effect<
|
|
310
319
|
TType extends "many" ? DistributeQueryIfExclusiveOnArray<E, T, EncodedRefined> : RefineTHelper<T, EncodedRefined>,
|
|
311
320
|
TType extends "many" ? never : NotFoundError<ItemType>,
|
|
312
|
-
R | RSchema
|
|
321
|
+
Exclude<R, RProvided> | RSchema
|
|
313
322
|
>
|
|
314
323
|
<
|
|
315
324
|
R = never,
|
|
@@ -325,7 +334,7 @@ export interface Repository<
|
|
|
325
334
|
): Effect.Effect<
|
|
326
335
|
TType extends "many" ? DistributeQueryIfExclusiveOnArray<E, T, EncodedRefined> : RefineTHelper<T, EncodedRefined>,
|
|
327
336
|
TType extends "many" ? never : NotFoundError<ItemType>,
|
|
328
|
-
R | RSchema
|
|
337
|
+
Exclude<R, RProvided> | RSchema
|
|
329
338
|
>
|
|
330
339
|
<
|
|
331
340
|
R = never,
|
|
@@ -345,7 +354,7 @@ export interface Repository<
|
|
|
345
354
|
): Effect.Effect<
|
|
346
355
|
TType extends "many" ? DistributeQueryIfExclusiveOnArray<E, T, EncodedRefined> : RefineTHelper<T, EncodedRefined>,
|
|
347
356
|
TType extends "many" ? never : NotFoundError<ItemType>,
|
|
348
|
-
R | RSchema
|
|
357
|
+
Exclude<R, RProvided> | RSchema
|
|
349
358
|
>
|
|
350
359
|
<
|
|
351
360
|
R = never,
|
|
@@ -365,7 +374,7 @@ export interface Repository<
|
|
|
365
374
|
): Effect.Effect<
|
|
366
375
|
TType extends "many" ? DistributeQueryIfExclusiveOnArray<E, T, EncodedRefined> : RefineTHelper<T, EncodedRefined>,
|
|
367
376
|
TType extends "many" ? never : NotFoundError<ItemType>,
|
|
368
|
-
R | RSchema
|
|
377
|
+
Exclude<R, RProvided> | RSchema
|
|
369
378
|
>
|
|
370
379
|
<
|
|
371
380
|
R = never,
|
|
@@ -387,7 +396,7 @@ export interface Repository<
|
|
|
387
396
|
): Effect.Effect<
|
|
388
397
|
TType extends "many" ? DistributeQueryIfExclusiveOnArray<E, T, EncodedRefined> : RefineTHelper<T, EncodedRefined>,
|
|
389
398
|
TType extends "many" ? never : NotFoundError<ItemType>,
|
|
390
|
-
R | RSchema
|
|
399
|
+
Exclude<R, RProvided> | RSchema
|
|
391
400
|
>
|
|
392
401
|
<
|
|
393
402
|
R = never,
|
|
@@ -411,7 +420,7 @@ export interface Repository<
|
|
|
411
420
|
): Effect.Effect<
|
|
412
421
|
TType extends "many" ? DistributeQueryIfExclusiveOnArray<E, T, EncodedRefined> : RefineTHelper<T, EncodedRefined>,
|
|
413
422
|
TType extends "many" ? never : NotFoundError<ItemType>,
|
|
414
|
-
R | RSchema
|
|
423
|
+
Exclude<R, RProvided> | RSchema
|
|
415
424
|
>
|
|
416
425
|
<
|
|
417
426
|
R = never,
|
|
@@ -437,7 +446,7 @@ export interface Repository<
|
|
|
437
446
|
): Effect.Effect<
|
|
438
447
|
TType extends "many" ? DistributeQueryIfExclusiveOnArray<E, T, EncodedRefined> : RefineTHelper<T, EncodedRefined>,
|
|
439
448
|
TType extends "many" ? never : NotFoundError<ItemType>,
|
|
440
|
-
R | RSchema
|
|
449
|
+
Exclude<R, RProvided> | RSchema
|
|
441
450
|
>
|
|
442
451
|
<
|
|
443
452
|
R = never,
|
|
@@ -466,7 +475,7 @@ export interface Repository<
|
|
|
466
475
|
TType extends "many" ? DistributeQueryIfExclusiveOnArray<E, T, EncodedRefined>
|
|
467
476
|
: RefineTHelper<T, EncodedRefined>,
|
|
468
477
|
TType extends "many" ? never : NotFoundError<ItemType>,
|
|
469
|
-
R | RSchema
|
|
478
|
+
Exclude<R, RProvided> | RSchema
|
|
470
479
|
>
|
|
471
480
|
<
|
|
472
481
|
R = never,
|
|
@@ -497,7 +506,7 @@ export interface Repository<
|
|
|
497
506
|
TType extends "many" ? DistributeQueryIfExclusiveOnArray<E, T, EncodedRefined>
|
|
498
507
|
: RefineTHelper<T, EncodedRefined>,
|
|
499
508
|
TType extends "many" ? never : NotFoundError<ItemType>,
|
|
500
|
-
R | RSchema
|
|
509
|
+
Exclude<R, RProvided> | RSchema
|
|
501
510
|
>
|
|
502
511
|
<
|
|
503
512
|
R = never,
|
|
@@ -530,7 +539,7 @@ export interface Repository<
|
|
|
530
539
|
TType extends "many" ? DistributeQueryIfExclusiveOnArray<E, T, EncodedRefined>
|
|
531
540
|
: RefineTHelper<T, EncodedRefined>,
|
|
532
541
|
TType extends "many" ? never : NotFoundError<ItemType>,
|
|
533
|
-
R | RSchema
|
|
542
|
+
Exclude<R, RProvided> | RSchema
|
|
534
543
|
>
|
|
535
544
|
}
|
|
536
545
|
|
|
@@ -5,7 +5,7 @@ import { NonNegativeInt } from "effect-app/Schema"
|
|
|
5
5
|
* Represents a single validation error when decoding a repository item.
|
|
6
6
|
* Contains full context for debugging: raw data, jitM result, and decode error.
|
|
7
7
|
*/
|
|
8
|
-
export class ValidationError extends S.
|
|
8
|
+
export class ValidationError extends S.Opaque<ValidationError>()(S.Struct({
|
|
9
9
|
/** the id of the item that failed validation */
|
|
10
10
|
id: S.Unknown,
|
|
11
11
|
/** the raw data from the database before jitM */
|
|
@@ -14,12 +14,12 @@ export class ValidationError extends S.Class<ValidationError>("@effect-app/infra
|
|
|
14
14
|
jitMResult: S.Unknown,
|
|
15
15
|
/** the S.SchemaError from schema decode */
|
|
16
16
|
error: S.Unknown
|
|
17
|
-
}) {}
|
|
17
|
+
})) {}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Result of validating a sample of repository items.
|
|
21
21
|
*/
|
|
22
|
-
export class ValidationResult extends S.
|
|
22
|
+
export class ValidationResult extends S.Opaque<ValidationResult>()(S.Struct({
|
|
23
23
|
/** total number of items in the repository */
|
|
24
24
|
total: NonNegativeInt,
|
|
25
25
|
/** number of items that were sampled for validation */
|
|
@@ -28,4 +28,4 @@ export class ValidationResult extends S.Class<ValidationResult>("@effect-app/inf
|
|
|
28
28
|
valid: NonNegativeInt,
|
|
29
29
|
/** list of validation errors with full context */
|
|
30
30
|
errors: S.Array(ValidationError)
|
|
31
|
-
}) {}
|
|
31
|
+
})) {}
|
package/src/Model/Repository.ts
CHANGED
package/src/Model/dsl.ts
CHANGED
|
@@ -42,16 +42,16 @@ export function makeAllDSL<T, Evt>() {
|
|
|
42
42
|
|
|
43
43
|
export type OneDSL<T, Evt> =
|
|
44
44
|
& (<R, A, E, S1 extends T, S2 extends T>(
|
|
45
|
-
pure: (dsl: PureDSL<S1, S2, Evt>) => Effect.Effect<A, E,
|
|
45
|
+
pure: (dsl: PureDSL<S1, S2, Evt>) => Effect.Effect<A, E, R>
|
|
46
46
|
) => Effect.Effect<A, E, FixEnv<R, Evt, S1, S2>>)
|
|
47
47
|
& OneDSLExt<T, Evt>
|
|
48
48
|
|
|
49
49
|
export interface OneDSLExt<T, Evt> {
|
|
50
50
|
modify: <R, E, A, S1 extends T, S2 extends T>(
|
|
51
|
-
pure: (items: S1, dsl: PureDSL<S1, S2, Evt>) => Effect.Effect<A, E,
|
|
51
|
+
pure: (items: S1, dsl: PureDSL<S1, S2, Evt>) => Effect.Effect<A, E, R>
|
|
52
52
|
) => Effect.Effect<A, E, FixEnv<R, Evt, S1, S2> | PureEnvEnv<Evt, S1, S1>>
|
|
53
53
|
update: <R, E, S1 extends T, S2 extends T>(
|
|
54
|
-
pure: (items: S1, log: (...evt: Evt[]) => PureLogT<Evt>) => Effect.Effect<S2, E,
|
|
54
|
+
pure: (items: S1, log: (...evt: Evt[]) => PureLogT<Evt>) => Effect.Effect<S2, E, R>
|
|
55
55
|
) => Effect.Effect<S2, E, FixEnv<R, Evt, S1, S2>>
|
|
56
56
|
updateWith: <S1 extends T, S2 extends T>(
|
|
57
57
|
upd: (item: S1) => S2
|