@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
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
|
|
|
@@ -156,8 +160,6 @@ it("works with repo", () =>
|
|
|
156
160
|
|
|
157
161
|
expectTypeOf(smtArr).toEqualTypeOf<readonly Something[]>()
|
|
158
162
|
|
|
159
|
-
console.log(" $$$$$$")
|
|
160
|
-
console.log(Struct.pick(["id", "displayName"]))
|
|
161
163
|
expect(q1).toEqual(items.slice(0, 2).toReversed().map(Struct.pick(["id", "displayName"])))
|
|
162
164
|
expect(q2).toEqual(items.slice(0, 2).toReversed().map(Struct.pick(["displayName"])))
|
|
163
165
|
})
|
|
@@ -238,15 +240,15 @@ it("collect", () =>
|
|
|
238
240
|
Effect.runPromise
|
|
239
241
|
))
|
|
240
242
|
|
|
241
|
-
class Person extends S.
|
|
243
|
+
class Person extends S.TaggedClass<Person, Person.Encoded>()("person", {
|
|
242
244
|
id: S.String,
|
|
243
245
|
surname: S.String
|
|
244
246
|
}) {}
|
|
245
|
-
class Animal extends S.
|
|
247
|
+
class Animal extends S.TaggedClass<Animal, Animal.Encoded>()("animal", {
|
|
246
248
|
id: S.String,
|
|
247
249
|
surname: S.String
|
|
248
250
|
}) {}
|
|
249
|
-
class Test extends S.
|
|
251
|
+
class Test extends S.TaggedClass<Test, Test.Encoded>()("test", {
|
|
250
252
|
id: S.String
|
|
251
253
|
}) {}
|
|
252
254
|
|
|
@@ -281,7 +283,7 @@ it(
|
|
|
281
283
|
expect(result).toEqual([])
|
|
282
284
|
expect(result2).toEqual([])
|
|
283
285
|
})
|
|
284
|
-
.pipe(Effect.provide(
|
|
286
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
285
287
|
)
|
|
286
288
|
|
|
287
289
|
it(
|
|
@@ -467,7 +469,7 @@ it(
|
|
|
467
469
|
|
|
468
470
|
expect([]).toEqual([])
|
|
469
471
|
})
|
|
470
|
-
.pipe(Effect.provide(
|
|
472
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
471
473
|
)
|
|
472
474
|
|
|
473
475
|
it(
|
|
@@ -510,7 +512,7 @@ it(
|
|
|
510
512
|
|
|
511
513
|
expect([]).toEqual([])
|
|
512
514
|
})
|
|
513
|
-
.pipe(Effect.provide(
|
|
515
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
514
516
|
)
|
|
515
517
|
|
|
516
518
|
it(
|
|
@@ -521,8 +523,8 @@ it(
|
|
|
521
523
|
const schema = S.Struct({
|
|
522
524
|
id: S.String,
|
|
523
525
|
createdAt: S.Date.pipe(
|
|
524
|
-
S.withDecodingDefault(() => new Date().toISOString()),
|
|
525
|
-
S.withConstructorDefault(() =>
|
|
526
|
+
S.withDecodingDefault(Effect.sync(() => new Date().toISOString())),
|
|
527
|
+
S.withConstructorDefault(Effect.sync(() => new Date()))
|
|
526
528
|
)
|
|
527
529
|
})
|
|
528
530
|
const repo = yield* makeRepo(
|
|
@@ -534,8 +536,8 @@ it(
|
|
|
534
536
|
const outputSchema = S.Struct({
|
|
535
537
|
id: S.Literal("123"),
|
|
536
538
|
createdAt: S.Date.pipe(
|
|
537
|
-
S.withDecodingDefault(() => new Date().toISOString()),
|
|
538
|
-
S.withConstructorDefault(() =>
|
|
539
|
+
S.withDecodingDefault(Effect.sync(() => new Date().toISOString())),
|
|
540
|
+
S.withConstructorDefault(Effect.sync(() => new Date()))
|
|
539
541
|
)
|
|
540
542
|
})
|
|
541
543
|
|
|
@@ -543,7 +545,34 @@ it(
|
|
|
543
545
|
|
|
544
546
|
expect(result).toEqual([])
|
|
545
547
|
})
|
|
546
|
-
.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)
|
|
547
576
|
)
|
|
548
577
|
|
|
549
578
|
it(
|
|
@@ -553,7 +582,7 @@ it(
|
|
|
553
582
|
.gen(function*() {
|
|
554
583
|
const schema = S.Struct({
|
|
555
584
|
id: S.String,
|
|
556
|
-
literals: S.
|
|
585
|
+
literals: S.Literals(["a", "b", "c"])
|
|
557
586
|
})
|
|
558
587
|
|
|
559
588
|
type Schema = typeof schema.Type
|
|
@@ -573,7 +602,7 @@ it(
|
|
|
573
602
|
|
|
574
603
|
expect(result).toEqual([])
|
|
575
604
|
})
|
|
576
|
-
.pipe(Effect.provide(
|
|
605
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
577
606
|
)
|
|
578
607
|
|
|
579
608
|
it(
|
|
@@ -583,7 +612,7 @@ it(
|
|
|
583
612
|
.gen(function*() {
|
|
584
613
|
const schema = S.Struct({
|
|
585
614
|
id: S.String,
|
|
586
|
-
literals: S.Union([S.
|
|
615
|
+
literals: S.Union([S.Literals(["a", "b", "c"]), S.Null])
|
|
587
616
|
})
|
|
588
617
|
|
|
589
618
|
type Schema = typeof schema.Type
|
|
@@ -617,7 +646,7 @@ it(
|
|
|
617
646
|
|
|
618
647
|
expect(result).toEqual([])
|
|
619
648
|
})
|
|
620
|
-
.pipe(Effect.provide(
|
|
649
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
621
650
|
)
|
|
622
651
|
|
|
623
652
|
it(
|
|
@@ -661,7 +690,7 @@ it(
|
|
|
661
690
|
|
|
662
691
|
expect(result).toEqual([])
|
|
663
692
|
})
|
|
664
|
-
.pipe(Effect.provide(
|
|
693
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
|
|
665
694
|
)
|
|
666
695
|
|
|
667
696
|
it("remove null from one constituent of a tagged union", () =>
|
|
@@ -674,7 +703,7 @@ it("remove null from one constituent of a tagged union", () =>
|
|
|
674
703
|
|
|
675
704
|
class BB extends S.Class<BB>("BB")({
|
|
676
705
|
id: S.Literal("BB"),
|
|
677
|
-
b: S.NullOr(S.
|
|
706
|
+
b: S.NullOr(S.Finite)
|
|
678
707
|
}) {}
|
|
679
708
|
|
|
680
709
|
type Union = AA | BB
|
|
@@ -710,7 +739,7 @@ it("remove null from one constituent of a tagged union", () =>
|
|
|
710
739
|
})[]
|
|
711
740
|
>()
|
|
712
741
|
})
|
|
713
|
-
.pipe(Effect.provide(
|
|
742
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
714
743
|
|
|
715
744
|
it("refine 3", () =>
|
|
716
745
|
Effect
|
|
@@ -748,7 +777,7 @@ it("refine 3", () =>
|
|
|
748
777
|
const resQuer1 = yield* repo.query(where("id", "AA"))
|
|
749
778
|
expectTypeOf(resQuer1).toEqualTypeOf<readonly AA[]>()
|
|
750
779
|
})
|
|
751
|
-
.pipe(Effect.provide(
|
|
780
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
752
781
|
|
|
753
782
|
it("my test", () =>
|
|
754
783
|
Effect
|
|
@@ -766,7 +795,7 @@ it("my test", () =>
|
|
|
766
795
|
)
|
|
767
796
|
expectTypeOf(resQuer1).toEqualTypeOf<readonly AA[]>()
|
|
768
797
|
})
|
|
769
|
-
.pipe(Effect.provide(
|
|
798
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
770
799
|
|
|
771
800
|
it("refine inner without imposing a projection", () =>
|
|
772
801
|
Effect
|
|
@@ -810,7 +839,7 @@ it("refine inner without imposing a projection", () =>
|
|
|
810
839
|
where("union._tag", "AA"),
|
|
811
840
|
// But if I wanna the whole Data as output ignoring the inner refinement
|
|
812
841
|
// I wanna be able to do so
|
|
813
|
-
project(
|
|
842
|
+
project(Data.mapFields(Struct.pick(["union"])))
|
|
814
843
|
)
|
|
815
844
|
|
|
816
845
|
expectTypeOf(query2).toEqualTypeOf<
|
|
@@ -841,7 +870,7 @@ it("refine inner without imposing a projection", () =>
|
|
|
841
870
|
}[]
|
|
842
871
|
>()
|
|
843
872
|
})
|
|
844
|
-
.pipe(Effect.provide(
|
|
873
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
845
874
|
|
|
846
875
|
it("does not allow string queries on arrays", () =>
|
|
847
876
|
Effect
|
|
@@ -876,7 +905,7 @@ it("does not allow string queries on arrays", () =>
|
|
|
876
905
|
expectTypeOf(good3).toEqualTypeOf<QueryWhere<Some, Some>>()
|
|
877
906
|
expectTypeOf(good4).toEqualTypeOf<QueryWhere<Some, Some>>()
|
|
878
907
|
})
|
|
879
|
-
.pipe(Effect.provide(
|
|
908
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
880
909
|
|
|
881
910
|
it("test array.length", () =>
|
|
882
911
|
Effect
|
|
@@ -917,7 +946,7 @@ it("test array.length", () =>
|
|
|
917
946
|
QueryWhere<Something, Something>
|
|
918
947
|
>()
|
|
919
948
|
})
|
|
920
|
-
.pipe(Effect.provide(
|
|
949
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
921
950
|
|
|
922
951
|
it("distribution over union", () =>
|
|
923
952
|
Effect
|
|
@@ -941,7 +970,7 @@ it("distribution over union", () =>
|
|
|
941
970
|
})[]
|
|
942
971
|
>()
|
|
943
972
|
})
|
|
944
|
-
.pipe(Effect.provide(
|
|
973
|
+
.pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
|
|
945
974
|
|
|
946
975
|
it("refine nested union", () =>
|
|
947
976
|
Effect
|
|
@@ -982,7 +1011,158 @@ it("refine nested union", () =>
|
|
|
982
1011
|
}[]
|
|
983
1012
|
>()
|
|
984
1013
|
})
|
|
985
|
-
.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))
|
|
986
1166
|
|
|
987
1167
|
it("refine union with nested union", () =>
|
|
988
1168
|
Effect
|
|
@@ -1097,4 +1277,4 @@ it("refine union with nested union", () =>
|
|
|
1097
1277
|
})[]
|
|
1098
1278
|
>()
|
|
1099
1279
|
})
|
|
1100
|
-
.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
|
)
|