@effect-app/infra 4.0.0-beta.21 → 4.0.0-beta.211
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 +1556 -0
- package/_check.sh +1 -1
- package/dist/CUPS.d.ts +7 -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 +10 -4
- 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 +98 -50
- 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 +46 -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 +16 -16
- 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 +5 -7
- package/dist/QueueMaker/SQLQueue.d.ts.map +1 -1
- package/dist/QueueMaker/SQLQueue.js +130 -116
- 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 +75 -63
- package/dist/QueueMaker/sbqueue.d.ts +6 -3
- package/dist/QueueMaker/sbqueue.d.ts.map +1 -1
- package/dist/QueueMaker/sbqueue.js +52 -53
- package/dist/QueueMaker/service.d.ts +1 -1
- package/dist/RequestContext.d.ts +74 -35
- package/dist/RequestContext.d.ts.map +1 -1
- package/dist/RequestContext.js +13 -14
- package/dist/RequestFiberSet.d.ts +7 -7
- package/dist/RequestFiberSet.d.ts.map +1 -1
- package/dist/RequestFiberSet.js +3 -3
- package/dist/Store/ContextMapContainer.d.ts +19 -3
- 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 +335 -243
- package/dist/Store/Disk.d.ts +2 -2
- package/dist/Store/Disk.d.ts.map +1 -1
- package/dist/Store/Disk.js +72 -35
- package/dist/Store/Memory.d.ts +6 -4
- package/dist/Store/Memory.d.ts.map +1 -1
- package/dist/Store/Memory.js +90 -57
- 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 +231 -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 +464 -0
- package/dist/Store/codeFilter.d.ts +1 -1
- package/dist/Store/codeFilter.d.ts.map +1 -1
- package/dist/Store/codeFilter.js +4 -2
- 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 +31 -42
- package/dist/adapters/SQL/Model.d.ts.map +1 -1
- package/dist/adapters/SQL/Model.js +29 -38
- 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 +25 -21
- 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 +3 -3
- 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 +44 -6
- 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 +10 -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 +39 -3
- package/dist/api/routing/middleware/middleware.d.ts.map +1 -1
- package/dist/api/routing/middleware/middleware.js +48 -16
- 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 +1 -1
- package/dist/api/routing/schema/jwt.d.ts.map +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 +80 -37
- package/dist/api/routing.d.ts.map +1 -1
- package/dist/api/routing.js +112 -40
- package/dist/api/setupRequest.d.ts +8 -5
- package/dist/api/setupRequest.d.ts.map +1 -1
- package/dist/api/setupRequest.js +12 -7
- 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 +4 -4
- 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/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/otel.d.ts +75 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +65 -0
- 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 +45 -37
- package/src/CUPS.ts +9 -11
- package/src/Emailer/Sendgrid.ts +17 -14
- 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 +213 -148
- 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 +144 -152
- package/src/QueueMaker/memQueue.ts +104 -103
- package/src/QueueMaker/sbqueue.ts +70 -86
- package/src/RequestContext.ts +14 -16
- package/src/RequestFiberSet.ts +2 -2
- package/src/Store/ContextMapContainer.ts +41 -2
- package/src/Store/Cosmos/query.ts +16 -20
- package/src/Store/Cosmos.ts +473 -348
- package/src/Store/Disk.ts +102 -65
- package/src/Store/Memory.ts +118 -83
- package/src/Store/SQL/Pg.ts +352 -0
- package/src/Store/SQL/query.ts +409 -0
- package/src/Store/SQL.ts +734 -0
- package/src/Store/codeFilter.ts +3 -1
- 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 +41 -40
- package/src/adapters/ServiceBus.ts +125 -121
- 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 +13 -9
- package/src/api/layerUtils.ts +8 -8
- package/src/api/routing/middleware/RouterMiddleware.ts +4 -4
- package/src/api/routing/middleware/middleware.ts +55 -14
- package/src/api/routing/middleware.ts +0 -2
- package/src/api/routing.ts +298 -128
- package/src/api/setupRequest.ts +28 -8
- package/src/arbs.ts +4 -2
- package/src/errorReporter.ts +62 -74
- package/src/logger/shared.ts +1 -1
- package/src/otel.ts +152 -0
- 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 +21 -30
- 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/date-query.test.d.ts.map +1 -0
- 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 -34
- 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 +183 -0
- package/test/routing-interruptibility.test.ts +63 -0
- package/test/rpc-e2e-invalidation.test.ts +251 -0
- package/test/rpc-multi-middleware.test.ts +78 -9
- package/test/rpc-stream-fullstack.test.ts +300 -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
package/test/query.test.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
/* eslint-disable unused-imports/no-unused-vars */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
import {
|
|
4
|
+
import { SchemaTransformation } from "effect"
|
|
5
|
+
import { Context, Effect, flow, Layer, Option, pipe, S, Struct } from "effect-app"
|
|
5
6
|
import { inspect } from "util"
|
|
6
7
|
import { expect, expectTypeOf, it } from "vitest"
|
|
7
8
|
import { setupRequestContextFromCurrent } from "../src/api/setupRequest.js"
|
|
8
9
|
import { and, count, make, one, or, order, page, project, type QueryEnd, type QueryProjection, type QueryWhere, toFilter, where } from "../src/Model/query.js"
|
|
9
10
|
import { makeRepo } from "../src/Model/Repository.js"
|
|
11
|
+
import { RepositoryRegistryLive } from "../src/Model/Repository/Registry.js"
|
|
10
12
|
import { memFilter, MemoryStoreLive } from "../src/Store/Memory.js"
|
|
11
13
|
import { SomeService } from "./fixtures.js"
|
|
12
14
|
|
|
15
|
+
const TestStoreLive = Layer.merge(MemoryStoreLive, RepositoryRegistryLive)
|
|
16
|
+
|
|
13
17
|
const str = S.Struct({ _tag: S.Literal("string"), value: S.String })
|
|
14
|
-
const num = S.Struct({ _tag: S.Literal("number"), value: S.
|
|
18
|
+
const num = S.Struct({ _tag: S.Literal("number"), value: S.Finite })
|
|
15
19
|
const someUnion = S.Union([str, num])
|
|
16
20
|
|
|
17
21
|
export class Something extends S.Class<Something>("Something")({
|
|
@@ -19,7 +23,7 @@ export class Something extends S.Class<Something>("Something")({
|
|
|
19
23
|
displayName: S.NonEmptyString255,
|
|
20
24
|
name: S.NullOr(S.NonEmptyString255).withDefault,
|
|
21
25
|
n: S.Date.withDefault,
|
|
22
|
-
union: someUnion.pipe(S.
|
|
26
|
+
union: someUnion.pipe(S.withConstructorDefault(Effect.succeed({ _tag: "string" as const, value: "hi" })))
|
|
23
27
|
}) {}
|
|
24
28
|
export declare namespace Something {
|
|
25
29
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
@@ -90,8 +94,8 @@ it("works", () => {
|
|
|
90
94
|
|
|
91
95
|
const processed = memFilter(interpreted)(items.map((_) =>
|
|
92
96
|
S.encodeUnknownSync(S.Struct({
|
|
93
|
-
...
|
|
94
|
-
displayName: S.
|
|
97
|
+
...Struct.omit(Something.fields, ["displayName"]),
|
|
98
|
+
displayName: S.Literals(["Verona", "Riley"])
|
|
95
99
|
}))(_)
|
|
96
100
|
))
|
|
97
101
|
|
|
@@ -99,7 +103,7 @@ it("works", () => {
|
|
|
99
103
|
})
|
|
100
104
|
|
|
101
105
|
// @effect-diagnostics-next-line missingEffectServiceDependency:off
|
|
102
|
-
class SomethingRepo extends
|
|
106
|
+
class SomethingRepo extends Context.Service<SomethingRepo>()("SomethingRepo", {
|
|
103
107
|
make: Effect.gen(function*() {
|
|
104
108
|
return yield* makeRepo("Something", Something, {})
|
|
105
109
|
})
|
|
@@ -112,7 +116,7 @@ class SomethingRepo extends ServiceMap.Service<SomethingRepo>()("SomethingRepo",
|
|
|
112
116
|
})
|
|
113
117
|
)
|
|
114
118
|
.pipe(
|
|
115
|
-
Layer.provide(
|
|
119
|
+
Layer.provide(TestStoreLive)
|
|
116
120
|
)
|
|
117
121
|
}
|
|
118
122
|
|
|
@@ -236,15 +240,15 @@ it("collect", () =>
|
|
|
236
240
|
Effect.runPromise
|
|
237
241
|
))
|
|
238
242
|
|
|
239
|
-
class Person extends S.
|
|
243
|
+
class Person extends S.TaggedClass<Person, Person.Encoded>()("person", {
|
|
240
244
|
id: S.String,
|
|
241
245
|
surname: S.String
|
|
242
246
|
}) {}
|
|
243
|
-
class Animal extends S.
|
|
247
|
+
class Animal extends S.TaggedClass<Animal, Animal.Encoded>()("animal", {
|
|
244
248
|
id: S.String,
|
|
245
249
|
surname: S.String
|
|
246
250
|
}) {}
|
|
247
|
-
class Test extends S.
|
|
251
|
+
class Test extends S.TaggedClass<Test, Test.Encoded>()("test", {
|
|
248
252
|
id: S.String
|
|
249
253
|
}) {}
|
|
250
254
|
|
|
@@ -279,7 +283,7 @@ it(
|
|
|
279
283
|
expect(result).toEqual([])
|
|
280
284
|
expect(result2).toEqual([])
|
|
281
285
|
})
|
|
282
|
-
.pipe(Effect.provide(
|
|
286
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
283
287
|
)
|
|
284
288
|
|
|
285
289
|
it(
|
|
@@ -465,7 +469,7 @@ it(
|
|
|
465
469
|
|
|
466
470
|
expect([]).toEqual([])
|
|
467
471
|
})
|
|
468
|
-
.pipe(Effect.provide(
|
|
472
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
469
473
|
)
|
|
470
474
|
|
|
471
475
|
it(
|
|
@@ -508,7 +512,7 @@ it(
|
|
|
508
512
|
|
|
509
513
|
expect([]).toEqual([])
|
|
510
514
|
})
|
|
511
|
-
.pipe(Effect.provide(
|
|
515
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
512
516
|
)
|
|
513
517
|
|
|
514
518
|
it(
|
|
@@ -519,8 +523,8 @@ it(
|
|
|
519
523
|
const schema = S.Struct({
|
|
520
524
|
id: S.String,
|
|
521
525
|
createdAt: S.Date.pipe(
|
|
522
|
-
S.withDecodingDefault(() => new Date().toISOString()),
|
|
523
|
-
S.withConstructorDefault(() =>
|
|
526
|
+
S.withDecodingDefault(Effect.sync(() => new Date().toISOString())),
|
|
527
|
+
S.withConstructorDefault(Effect.sync(() => new Date()))
|
|
524
528
|
)
|
|
525
529
|
})
|
|
526
530
|
const repo = yield* makeRepo(
|
|
@@ -532,8 +536,8 @@ it(
|
|
|
532
536
|
const outputSchema = S.Struct({
|
|
533
537
|
id: S.Literal("123"),
|
|
534
538
|
createdAt: S.Date.pipe(
|
|
535
|
-
S.withDecodingDefault(() => new Date().toISOString()),
|
|
536
|
-
S.withConstructorDefault(() =>
|
|
539
|
+
S.withDecodingDefault(Effect.sync(() => new Date().toISOString())),
|
|
540
|
+
S.withConstructorDefault(Effect.sync(() => new Date()))
|
|
537
541
|
)
|
|
538
542
|
})
|
|
539
543
|
|
|
@@ -541,7 +545,34 @@ it(
|
|
|
541
545
|
|
|
542
546
|
expect(result).toEqual([])
|
|
543
547
|
})
|
|
544
|
-
.pipe(Effect.provide(
|
|
548
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
549
|
+
)
|
|
550
|
+
|
|
551
|
+
it(
|
|
552
|
+
"project with encodeKeys in projection maps encoded keys",
|
|
553
|
+
() =>
|
|
554
|
+
Effect
|
|
555
|
+
.gen(function*() {
|
|
556
|
+
const schema = S.Struct({
|
|
557
|
+
id: S.String,
|
|
558
|
+
a: S.Number
|
|
559
|
+
})
|
|
560
|
+
|
|
561
|
+
const repo = yield* makeRepo(
|
|
562
|
+
"test",
|
|
563
|
+
schema,
|
|
564
|
+
{
|
|
565
|
+
makeInitial: Effect.sync(() => [{ id: "1", a: 1 }])
|
|
566
|
+
}
|
|
567
|
+
)
|
|
568
|
+
|
|
569
|
+
const outputSchema = S.Struct({ b: S.Number }).pipe(S.encodeKeys({ b: "a" }))
|
|
570
|
+
|
|
571
|
+
const result = yield* repo.query(project(outputSchema))
|
|
572
|
+
|
|
573
|
+
expect(result).toStrictEqual([{ b: 1 }])
|
|
574
|
+
})
|
|
575
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
545
576
|
)
|
|
546
577
|
|
|
547
578
|
it(
|
|
@@ -551,7 +582,7 @@ it(
|
|
|
551
582
|
.gen(function*() {
|
|
552
583
|
const schema = S.Struct({
|
|
553
584
|
id: S.String,
|
|
554
|
-
literals: S.
|
|
585
|
+
literals: S.Literals(["a", "b", "c"])
|
|
555
586
|
})
|
|
556
587
|
|
|
557
588
|
type Schema = typeof schema.Type
|
|
@@ -571,7 +602,7 @@ it(
|
|
|
571
602
|
|
|
572
603
|
expect(result).toEqual([])
|
|
573
604
|
})
|
|
574
|
-
.pipe(Effect.provide(
|
|
605
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
575
606
|
)
|
|
576
607
|
|
|
577
608
|
it(
|
|
@@ -581,7 +612,7 @@ it(
|
|
|
581
612
|
.gen(function*() {
|
|
582
613
|
const schema = S.Struct({
|
|
583
614
|
id: S.String,
|
|
584
|
-
literals: S.Union([S.
|
|
615
|
+
literals: S.Union([S.Literals(["a", "b", "c"]), S.Null])
|
|
585
616
|
})
|
|
586
617
|
|
|
587
618
|
type Schema = typeof schema.Type
|
|
@@ -615,7 +646,7 @@ it(
|
|
|
615
646
|
|
|
616
647
|
expect(result).toEqual([])
|
|
617
648
|
})
|
|
618
|
-
.pipe(Effect.provide(
|
|
649
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
619
650
|
)
|
|
620
651
|
|
|
621
652
|
it(
|
|
@@ -659,7 +690,7 @@ it(
|
|
|
659
690
|
|
|
660
691
|
expect(result).toEqual([])
|
|
661
692
|
})
|
|
662
|
-
.pipe(Effect.provide(
|
|
693
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
663
694
|
)
|
|
664
695
|
|
|
665
696
|
it("remove null from one constituent of a tagged union", () =>
|
|
@@ -672,7 +703,7 @@ it("remove null from one constituent of a tagged union", () =>
|
|
|
672
703
|
|
|
673
704
|
class BB extends S.Class<BB>("BB")({
|
|
674
705
|
id: S.Literal("BB"),
|
|
675
|
-
b: S.NullOr(S.
|
|
706
|
+
b: S.NullOr(S.Finite)
|
|
676
707
|
}) {}
|
|
677
708
|
|
|
678
709
|
type Union = AA | BB
|
|
@@ -708,7 +739,7 @@ it("remove null from one constituent of a tagged union", () =>
|
|
|
708
739
|
})[]
|
|
709
740
|
>()
|
|
710
741
|
})
|
|
711
|
-
.pipe(Effect.provide(
|
|
742
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
712
743
|
|
|
713
744
|
it("refine 3", () =>
|
|
714
745
|
Effect
|
|
@@ -746,7 +777,7 @@ it("refine 3", () =>
|
|
|
746
777
|
const resQuer1 = yield* repo.query(where("id", "AA"))
|
|
747
778
|
expectTypeOf(resQuer1).toEqualTypeOf<readonly AA[]>()
|
|
748
779
|
})
|
|
749
|
-
.pipe(Effect.provide(
|
|
780
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
750
781
|
|
|
751
782
|
it("my test", () =>
|
|
752
783
|
Effect
|
|
@@ -764,7 +795,7 @@ it("my test", () =>
|
|
|
764
795
|
)
|
|
765
796
|
expectTypeOf(resQuer1).toEqualTypeOf<readonly AA[]>()
|
|
766
797
|
})
|
|
767
|
-
.pipe(Effect.provide(
|
|
798
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
768
799
|
|
|
769
800
|
it("refine inner without imposing a projection", () =>
|
|
770
801
|
Effect
|
|
@@ -808,7 +839,7 @@ it("refine inner without imposing a projection", () =>
|
|
|
808
839
|
where("union._tag", "AA"),
|
|
809
840
|
// But if I wanna the whole Data as output ignoring the inner refinement
|
|
810
841
|
// I wanna be able to do so
|
|
811
|
-
project(
|
|
842
|
+
project(Data.mapFields(Struct.pick(["union"])))
|
|
812
843
|
)
|
|
813
844
|
|
|
814
845
|
expectTypeOf(query2).toEqualTypeOf<
|
|
@@ -839,7 +870,7 @@ it("refine inner without imposing a projection", () =>
|
|
|
839
870
|
}[]
|
|
840
871
|
>()
|
|
841
872
|
})
|
|
842
|
-
.pipe(Effect.provide(
|
|
873
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
843
874
|
|
|
844
875
|
it("does not allow string queries on arrays", () =>
|
|
845
876
|
Effect
|
|
@@ -874,7 +905,7 @@ it("does not allow string queries on arrays", () =>
|
|
|
874
905
|
expectTypeOf(good3).toEqualTypeOf<QueryWhere<Some, Some>>()
|
|
875
906
|
expectTypeOf(good4).toEqualTypeOf<QueryWhere<Some, Some>>()
|
|
876
907
|
})
|
|
877
|
-
.pipe(Effect.provide(
|
|
908
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
878
909
|
|
|
879
910
|
it("test array.length", () =>
|
|
880
911
|
Effect
|
|
@@ -915,7 +946,7 @@ it("test array.length", () =>
|
|
|
915
946
|
QueryWhere<Something, Something>
|
|
916
947
|
>()
|
|
917
948
|
})
|
|
918
|
-
.pipe(Effect.provide(
|
|
949
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
919
950
|
|
|
920
951
|
it("distribution over union", () =>
|
|
921
952
|
Effect
|
|
@@ -939,7 +970,7 @@ it("distribution over union", () =>
|
|
|
939
970
|
})[]
|
|
940
971
|
>()
|
|
941
972
|
})
|
|
942
|
-
.pipe(Effect.provide(
|
|
973
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
943
974
|
|
|
944
975
|
it("refine nested union", () =>
|
|
945
976
|
Effect
|
|
@@ -980,7 +1011,158 @@ it("refine nested union", () =>
|
|
|
980
1011
|
}[]
|
|
981
1012
|
>()
|
|
982
1013
|
})
|
|
983
|
-
.pipe(Effect.provide(
|
|
1014
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
1015
|
+
|
|
1016
|
+
it("find with transformed id", () =>
|
|
1017
|
+
Effect
|
|
1018
|
+
.gen(function*() {
|
|
1019
|
+
const ConfiguratorId = S.NonEmptyString255
|
|
1020
|
+
|
|
1021
|
+
class PreconfigurationId extends S.Class<PreconfigurationId>("PreconfigurationId")({
|
|
1022
|
+
configuratorId: ConfiguratorId,
|
|
1023
|
+
label: S.NonEmptyString50
|
|
1024
|
+
}) {}
|
|
1025
|
+
|
|
1026
|
+
const PreconfigurationIdFromString = S.NonEmptyString255.pipe(
|
|
1027
|
+
S.decodeTo(
|
|
1028
|
+
S.toType(PreconfigurationId),
|
|
1029
|
+
SchemaTransformation.transformOrFail({
|
|
1030
|
+
decode: Effect.fnUntraced(function*(value) {
|
|
1031
|
+
const values = value.split("_")
|
|
1032
|
+
const label = yield* S.SchemaParser.decodeUnknownEffect(S.NonEmptyString50)(values.pop())
|
|
1033
|
+
const configuratorId = yield* S.SchemaParser.decodeUnknownEffect(ConfiguratorId)(
|
|
1034
|
+
values.join("_")
|
|
1035
|
+
)
|
|
1036
|
+
return new PreconfigurationId({ configuratorId, label })
|
|
1037
|
+
}),
|
|
1038
|
+
encode: (id) => Effect.succeed(S.NonEmptyString255(`${id.configuratorId}_${id.label}`))
|
|
1039
|
+
})
|
|
1040
|
+
),
|
|
1041
|
+
S.revealCodec
|
|
1042
|
+
)
|
|
1043
|
+
|
|
1044
|
+
const Preconfiguration = S.Struct({
|
|
1045
|
+
id: PreconfigurationIdFromString,
|
|
1046
|
+
name: S.String
|
|
1047
|
+
})
|
|
1048
|
+
|
|
1049
|
+
const repo = yield* makeRepo("Preconfiguration", Preconfiguration, { idKey: "id" as const })
|
|
1050
|
+
|
|
1051
|
+
const id = new PreconfigurationId({
|
|
1052
|
+
configuratorId: S.NonEmptyString255("myConfigurator"),
|
|
1053
|
+
label: S.NonEmptyString50("myLabel")
|
|
1054
|
+
})
|
|
1055
|
+
const item = { id, name: "test preconfig" }
|
|
1056
|
+
|
|
1057
|
+
yield* repo.saveAndPublish([item])
|
|
1058
|
+
|
|
1059
|
+
const found = yield* repo.find(id)
|
|
1060
|
+
expect(Option.isSome(found)).toBe(true)
|
|
1061
|
+
expect(Option.getOrThrow(found).name).toBe("test preconfig")
|
|
1062
|
+
expect(Option.getOrThrow(found).id).toEqual(id)
|
|
1063
|
+
|
|
1064
|
+
const notFound = yield* repo.find(
|
|
1065
|
+
new PreconfigurationId({
|
|
1066
|
+
configuratorId: S.NonEmptyString255("other"),
|
|
1067
|
+
label: S.NonEmptyString50("nope")
|
|
1068
|
+
})
|
|
1069
|
+
)
|
|
1070
|
+
expect(Option.isNone(notFound)).toBe(true)
|
|
1071
|
+
})
|
|
1072
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
1073
|
+
|
|
1074
|
+
it("find with transformed id in tagged union", () =>
|
|
1075
|
+
Effect
|
|
1076
|
+
.gen(function*() {
|
|
1077
|
+
const ConfiguratorId = S.NonEmptyString255
|
|
1078
|
+
|
|
1079
|
+
class PreconfigurationId extends S.Class<PreconfigurationId>("PreconfigurationId")({
|
|
1080
|
+
configuratorId: ConfiguratorId,
|
|
1081
|
+
label: S.NonEmptyString50
|
|
1082
|
+
}) {}
|
|
1083
|
+
|
|
1084
|
+
const PreconfigurationIdFromString = S.NonEmptyString255.pipe(
|
|
1085
|
+
S.decodeTo(
|
|
1086
|
+
S.toType(PreconfigurationId),
|
|
1087
|
+
SchemaTransformation.transformOrFail({
|
|
1088
|
+
decode: Effect.fnUntraced(function*(value) {
|
|
1089
|
+
const values = value.split("_")
|
|
1090
|
+
const label = yield* S.SchemaParser.decodeUnknownEffect(S.NonEmptyString50)(values.pop())
|
|
1091
|
+
const configuratorId = yield* S.SchemaParser.decodeUnknownEffect(ConfiguratorId)(
|
|
1092
|
+
values.join("_")
|
|
1093
|
+
)
|
|
1094
|
+
return new PreconfigurationId({ configuratorId, label })
|
|
1095
|
+
}),
|
|
1096
|
+
encode: (id) => Effect.succeed(S.NonEmptyString255(`${id.configuratorId}_${id.label}`))
|
|
1097
|
+
})
|
|
1098
|
+
),
|
|
1099
|
+
S.revealCodec
|
|
1100
|
+
)
|
|
1101
|
+
|
|
1102
|
+
class Draft extends S.TaggedClass<Draft>()("Draft", {
|
|
1103
|
+
id: PreconfigurationIdFromString,
|
|
1104
|
+
name: S.String
|
|
1105
|
+
}) {}
|
|
1106
|
+
|
|
1107
|
+
class Published extends S.TaggedClass<Published>()("Published", {
|
|
1108
|
+
id: PreconfigurationIdFromString,
|
|
1109
|
+
name: S.String,
|
|
1110
|
+
publishedAt: S.String
|
|
1111
|
+
}) {}
|
|
1112
|
+
|
|
1113
|
+
class Archived extends S.TaggedClass<Archived>()("Archived", {
|
|
1114
|
+
id: PreconfigurationIdFromString,
|
|
1115
|
+
name: S.String,
|
|
1116
|
+
archivedAt: S.String
|
|
1117
|
+
}) {}
|
|
1118
|
+
|
|
1119
|
+
const Preconfiguration = S.Union([Draft, Published, Archived])
|
|
1120
|
+
|
|
1121
|
+
const repo = yield* makeRepo("Preconfiguration", Preconfiguration, {})
|
|
1122
|
+
|
|
1123
|
+
const id1 = new PreconfigurationId({
|
|
1124
|
+
configuratorId: S.NonEmptyString255("conf1"),
|
|
1125
|
+
label: S.NonEmptyString50("draft1")
|
|
1126
|
+
})
|
|
1127
|
+
const id2 = new PreconfigurationId({
|
|
1128
|
+
configuratorId: S.NonEmptyString255("conf2"),
|
|
1129
|
+
label: S.NonEmptyString50("pub1")
|
|
1130
|
+
})
|
|
1131
|
+
const id3 = new PreconfigurationId({
|
|
1132
|
+
configuratorId: S.NonEmptyString255("conf3"),
|
|
1133
|
+
label: S.NonEmptyString50("arch1")
|
|
1134
|
+
})
|
|
1135
|
+
|
|
1136
|
+
const draft = new Draft({ id: id1, name: "my draft" })
|
|
1137
|
+
const published = new Published({ id: id2, name: "my published", publishedAt: "2024-01-01" })
|
|
1138
|
+
const archived = new Archived({ id: id3, name: "my archived", archivedAt: "2024-06-01" })
|
|
1139
|
+
|
|
1140
|
+
yield* repo.saveAndPublish([draft, published, archived])
|
|
1141
|
+
|
|
1142
|
+
// find each by their PreconfigurationId instance
|
|
1143
|
+
const foundDraft = yield* repo.find(id1)
|
|
1144
|
+
expect(Option.isSome(foundDraft)).toBe(true)
|
|
1145
|
+
expect(Option.getOrThrow(foundDraft)._tag).toBe("Draft")
|
|
1146
|
+
expect(Option.getOrThrow(foundDraft).name).toBe("my draft")
|
|
1147
|
+
|
|
1148
|
+
const foundPublished = yield* repo.find(id2)
|
|
1149
|
+
expect(Option.isSome(foundPublished)).toBe(true)
|
|
1150
|
+
expect(Option.getOrThrow(foundPublished)._tag).toBe("Published")
|
|
1151
|
+
|
|
1152
|
+
const foundArchived = yield* repo.find(id3)
|
|
1153
|
+
expect(Option.isSome(foundArchived)).toBe(true)
|
|
1154
|
+
expect(Option.getOrThrow(foundArchived)._tag).toBe("Archived")
|
|
1155
|
+
|
|
1156
|
+
// not found
|
|
1157
|
+
const notFound = yield* repo.find(
|
|
1158
|
+
new PreconfigurationId({
|
|
1159
|
+
configuratorId: S.NonEmptyString255("nope"),
|
|
1160
|
+
label: S.NonEmptyString50("nope")
|
|
1161
|
+
})
|
|
1162
|
+
)
|
|
1163
|
+
expect(Option.isNone(notFound)).toBe(true)
|
|
1164
|
+
})
|
|
1165
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
984
1166
|
|
|
985
1167
|
it("refine union with nested union", () =>
|
|
986
1168
|
Effect
|
|
@@ -1095,4 +1277,4 @@ it("refine union with nested union", () =>
|
|
|
1095
1277
|
})[]
|
|
1096
1278
|
>()
|
|
1097
1279
|
})
|
|
1098
|
-
.pipe(Effect.provide(
|
|
1280
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
package/test/rawQuery.test.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
-
import { Array, Config, Effect, flow, Layer, ManagedRuntime, Redacted, References, Result, S
|
|
2
|
+
import { Array, Config, Context, Effect, flow, Layer, ManagedRuntime, Redacted, References, Result, S } from "effect-app"
|
|
3
3
|
import { LogLevels } from "effect-app/utils"
|
|
4
4
|
import { setupRequestContextFromCurrent } from "../src/api/setupRequest.js"
|
|
5
5
|
import { and, or, project, where, whereEvery, whereSome } from "../src/Model/query.js"
|
|
6
6
|
import { makeRepo } from "../src/Model/Repository/makeRepo.js"
|
|
7
|
+
import { RepositoryRegistryLive } from "../src/Model/Repository/Registry.js"
|
|
7
8
|
import { CosmosStoreLayer } from "../src/Store/Cosmos.js"
|
|
8
9
|
import { MemoryStoreLive } from "../src/Store/Memory.js"
|
|
9
10
|
|
|
@@ -24,7 +25,7 @@ class Something extends S.Class<Something>("Something")({
|
|
|
24
25
|
id: S.String,
|
|
25
26
|
name: S.String,
|
|
26
27
|
description: S.String,
|
|
27
|
-
items: S.Array(S.Struct({ id: S.String, value: S.
|
|
28
|
+
items: S.Array(S.Struct({ id: S.String, value: S.Finite, description: S.String }))
|
|
28
29
|
}) {}
|
|
29
30
|
|
|
30
31
|
const items = [
|
|
@@ -49,7 +50,7 @@ const items = [
|
|
|
49
50
|
]
|
|
50
51
|
|
|
51
52
|
// @effect-diagnostics-next-line missingEffectServiceDependency:off
|
|
52
|
-
class SomethingRepo extends
|
|
53
|
+
class SomethingRepo extends Context.Service<SomethingRepo>()(
|
|
53
54
|
"SomethingRepo",
|
|
54
55
|
{
|
|
55
56
|
make: Effect.gen(function*() {
|
|
@@ -76,28 +77,31 @@ class SomethingRepo extends ServiceMap.Service<SomethingRepo>()(
|
|
|
76
77
|
static readonly Test = this
|
|
77
78
|
.layer
|
|
78
79
|
.pipe(
|
|
79
|
-
Layer.provide(MemoryStoreLive)
|
|
80
|
+
Layer.provide(Layer.merge(MemoryStoreLive, RepositoryRegistryLive))
|
|
80
81
|
)
|
|
81
82
|
|
|
82
83
|
static readonly TestCosmos = this
|
|
83
84
|
.layer
|
|
84
85
|
.pipe(
|
|
85
86
|
Layer.provide(
|
|
86
|
-
Effect
|
|
87
|
-
|
|
88
|
-
Config.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
Effect
|
|
88
|
+
.gen(function*() {
|
|
89
|
+
const url = yield* Config.redacted("STORAGE_URL").pipe(
|
|
90
|
+
Config.withDefault(
|
|
91
|
+
Redacted.make(
|
|
92
|
+
// the emulator doesn't implement array projections :/ so you need an actual cloud instance!
|
|
93
|
+
"AccountEndpoint=http://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
|
|
94
|
+
)
|
|
92
95
|
)
|
|
93
96
|
)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
return CosmosStoreLayer({
|
|
98
|
+
dbName: "test",
|
|
99
|
+
prefix: "",
|
|
100
|
+
url
|
|
101
|
+
})
|
|
102
|
+
.pipe(Layer.merge(RepositoryRegistryLive))
|
|
99
103
|
})
|
|
100
|
-
|
|
104
|
+
.pipe(Layer.unwrap)
|
|
101
105
|
)
|
|
102
106
|
)
|
|
103
107
|
}
|
|
@@ -107,7 +111,7 @@ describe("select first-level array fields", () => {
|
|
|
107
111
|
.gen(function*() {
|
|
108
112
|
const repo = yield* SomethingRepo
|
|
109
113
|
|
|
110
|
-
const projected = S.Struct({ name: S.String, items: S.Array(S.Struct({ id: S.String, value: S.
|
|
114
|
+
const projected = S.Struct({ name: S.String, items: S.Array(S.Struct({ id: S.String, value: S.Finite })) })
|
|
111
115
|
|
|
112
116
|
// ok crazy lol, "value" is a reserved word in CosmosDB, so we have to use t["value"] as a field name instead of t.value
|
|
113
117
|
const items = yield* repo.queryRaw(projected, {
|
|
@@ -159,7 +163,7 @@ describe("select first-level array fields", () => {
|
|
|
159
163
|
.pipe(Effect.provide(SomethingRepo.Test), rt.runPromise))
|
|
160
164
|
})
|
|
161
165
|
|
|
162
|
-
const projected = S.Struct({ name: S.String, items: S.Array(S.Struct({ id: S.String, value: S.
|
|
166
|
+
const projected = S.Struct({ name: S.String, items: S.Array(S.Struct({ id: S.String, value: S.Finite })) })
|
|
163
167
|
|
|
164
168
|
const expected = [
|
|
165
169
|
{
|
|
@@ -405,7 +409,7 @@ describe("removeByIds", () => {
|
|
|
405
409
|
|
|
406
410
|
yield* repo.saveAndPublish(items)
|
|
407
411
|
const itemsAfterSave = yield* repo.all
|
|
408
|
-
yield* repo.removeById(
|
|
412
|
+
yield* repo.removeById([items[0]!.id, items[1]!.id])
|
|
409
413
|
|
|
410
414
|
const items2 = yield* repo.all
|
|
411
415
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
+
import { Effect, Layer, S } from "effect-app"
|
|
3
|
+
import { setupRequestContextFromCurrent } from "../src/api/setupRequest.js"
|
|
4
|
+
import { makeRepo } from "../src/Model/Repository.js"
|
|
5
|
+
import { RepositoryRegistryLive } from "../src/Model/Repository/Registry.js"
|
|
6
|
+
import { MemoryStoreLive } from "../src/Store/Memory.js"
|
|
7
|
+
|
|
8
|
+
class BatchItem extends S.Class<BatchItem>("BatchItem")({
|
|
9
|
+
id: S.String,
|
|
10
|
+
label: S.String
|
|
11
|
+
}) {}
|
|
12
|
+
|
|
13
|
+
const TestStoreLive = Layer.merge(MemoryStoreLive, RepositoryRegistryLive)
|
|
14
|
+
|
|
15
|
+
describe("repository ext save/remove batching", () => {
|
|
16
|
+
it.effect("supports save batching overload", () =>
|
|
17
|
+
Effect
|
|
18
|
+
.gen(function*() {
|
|
19
|
+
const repo = yield* makeRepo("BatchItem", BatchItem, {})
|
|
20
|
+
const items = [
|
|
21
|
+
new BatchItem({ id: "1", label: "one" }),
|
|
22
|
+
new BatchItem({ id: "2", label: "two" }),
|
|
23
|
+
new BatchItem({ id: "3", label: "three" }),
|
|
24
|
+
new BatchItem({ id: "4", label: "four" })
|
|
25
|
+
] as const
|
|
26
|
+
|
|
27
|
+
yield* repo.save(items, { batch: 2 })
|
|
28
|
+
|
|
29
|
+
const all = yield* repo.all
|
|
30
|
+
expect(all).toHaveLength(4)
|
|
31
|
+
expect(all.map((_) => _.id).toSorted()).toEqual(["1", "2", "3", "4"])
|
|
32
|
+
})
|
|
33
|
+
.pipe(
|
|
34
|
+
setupRequestContextFromCurrent(),
|
|
35
|
+
Effect.provide(TestStoreLive)
|
|
36
|
+
))
|
|
37
|
+
|
|
38
|
+
it.effect("supports remove batching overload", () =>
|
|
39
|
+
Effect
|
|
40
|
+
.gen(function*() {
|
|
41
|
+
const repo = yield* makeRepo("BatchItem", BatchItem, {})
|
|
42
|
+
const items = [
|
|
43
|
+
new BatchItem({ id: "1", label: "one" }),
|
|
44
|
+
new BatchItem({ id: "2", label: "two" }),
|
|
45
|
+
new BatchItem({ id: "3", label: "three" }),
|
|
46
|
+
new BatchItem({ id: "4", label: "four" })
|
|
47
|
+
] as const
|
|
48
|
+
|
|
49
|
+
yield* repo.save(items)
|
|
50
|
+
yield* repo.remove([items[0], items[1], items[2]], { batch: true })
|
|
51
|
+
|
|
52
|
+
const all = yield* repo.all
|
|
53
|
+
expect(all).toHaveLength(1)
|
|
54
|
+
expect(all[0]?.id).toBe("4")
|
|
55
|
+
})
|
|
56
|
+
.pipe(
|
|
57
|
+
setupRequestContextFromCurrent(),
|
|
58
|
+
Effect.provide(TestStoreLive)
|
|
59
|
+
))
|
|
60
|
+
})
|
package/test/requires.test.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { describe, expect, expectTypeOf, it } from "@effect/vitest"
|
|
2
|
-
import { Effect, Layer, Result,
|
|
2
|
+
import { Context, Effect, Layer, Result, RpcX, S } from "effect-app"
|
|
3
3
|
import { NotLoggedInError, UnauthorizedError } from "effect-app/client"
|
|
4
4
|
import { HttpHeaders } from "effect-app/http"
|
|
5
|
-
import * as RpcX from "effect-app/rpc"
|
|
6
5
|
import { MiddlewareMaker } from "effect-app/rpc"
|
|
7
6
|
import type { unhandled } from "effect-app/Types"
|
|
8
7
|
import { Rpc } from "effect/unstable/rpc"
|
|
@@ -63,11 +62,12 @@ const testSuite = (_mw: typeof middleware3) =>
|
|
|
63
62
|
"works",
|
|
64
63
|
Effect.fn(function*() {
|
|
65
64
|
const defaultOpts = {
|
|
65
|
+
client: null as any, // TODO?
|
|
66
66
|
headers: HttpHeaders.fromRecordUnsafe({}),
|
|
67
67
|
payload: { _tag: "Test" },
|
|
68
68
|
clientId: 0,
|
|
69
69
|
requestId: "test-id" as any,
|
|
70
|
-
rpc: { ...TestRpc, annotations:
|
|
70
|
+
rpc: { ...TestRpc, annotations: Context.make(_mw.requestContext, {}) }
|
|
71
71
|
}
|
|
72
72
|
const next = Effect.void as unknown as Effect.Effect<SuccessValue, unhandled, never>
|
|
73
73
|
const layer = _mw.layer.pipe(
|
|
@@ -89,7 +89,7 @@ const testSuite = (_mw: typeof middleware3) =>
|
|
|
89
89
|
headers: HttpHeaders.fromRecordUnsafe({ "x-user": "test-user", "x-is-manager": "true" }),
|
|
90
90
|
rpc: {
|
|
91
91
|
...defaultOpts.rpc,
|
|
92
|
-
annotations:
|
|
92
|
+
annotations: Context.make(_mw.requestContext, { requireRoles: ["manager"] })
|
|
93
93
|
}
|
|
94
94
|
})
|
|
95
95
|
)
|
|
@@ -127,7 +127,7 @@ const testSuite = (_mw: typeof middleware3) =>
|
|
|
127
127
|
Object.assign({ ...defaultOpts }, {
|
|
128
128
|
rpc: {
|
|
129
129
|
...defaultOpts.rpc,
|
|
130
|
-
annotations:
|
|
130
|
+
annotations: Context.make(_mw.requestContext, { requireRoles: ["manager"] })
|
|
131
131
|
}
|
|
132
132
|
})
|
|
133
133
|
)
|
|
@@ -153,7 +153,7 @@ const testSuite = (_mw: typeof middleware3) =>
|
|
|
153
153
|
{
|
|
154
154
|
rpc: {
|
|
155
155
|
...defaultOpts.rpc,
|
|
156
|
-
annotations:
|
|
156
|
+
annotations: Context.make(_mw.requestContext, { requireRoles: ["manager"] })
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
)
|