@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.
Files changed (308) hide show
  1. package/CHANGELOG.md +1514 -0
  2. package/_check.sh +1 -1
  3. package/dist/CUPS.d.ts +15 -7
  4. package/dist/CUPS.d.ts.map +1 -1
  5. package/dist/CUPS.js +10 -12
  6. package/dist/Emailer/Sendgrid.d.ts +14 -14
  7. package/dist/Emailer/Sendgrid.d.ts.map +1 -1
  8. package/dist/Emailer/Sendgrid.js +16 -15
  9. package/dist/Emailer/fake.d.ts +1 -1
  10. package/dist/Emailer/service.d.ts +11 -5
  11. package/dist/Emailer/service.d.ts.map +1 -1
  12. package/dist/Emailer/service.js +3 -3
  13. package/dist/Emailer.d.ts +1 -1
  14. package/dist/MainFiberSet.d.ts +9 -9
  15. package/dist/MainFiberSet.d.ts.map +1 -1
  16. package/dist/MainFiberSet.js +3 -3
  17. package/dist/Model/Repository/Registry.d.ts +20 -0
  18. package/dist/Model/Repository/Registry.d.ts.map +1 -0
  19. package/dist/Model/Repository/Registry.js +17 -0
  20. package/dist/Model/Repository/ext.d.ts +33 -15
  21. package/dist/Model/Repository/ext.d.ts.map +1 -1
  22. package/dist/Model/Repository/ext.js +54 -2
  23. package/dist/Model/Repository/internal/internal.d.ts +6 -6
  24. package/dist/Model/Repository/internal/internal.d.ts.map +1 -1
  25. package/dist/Model/Repository/internal/internal.js +43 -32
  26. package/dist/Model/Repository/legacy.d.ts +1 -1
  27. package/dist/Model/Repository/makeRepo.d.ts +7 -6
  28. package/dist/Model/Repository/makeRepo.d.ts.map +1 -1
  29. package/dist/Model/Repository/makeRepo.js +5 -1
  30. package/dist/Model/Repository/service.d.ts +28 -23
  31. package/dist/Model/Repository/service.d.ts.map +1 -1
  32. package/dist/Model/Repository/validation.d.ts +142 -17
  33. package/dist/Model/Repository/validation.d.ts.map +1 -1
  34. package/dist/Model/Repository/validation.js +5 -5
  35. package/dist/Model/Repository.d.ts +2 -1
  36. package/dist/Model/Repository.d.ts.map +1 -1
  37. package/dist/Model/Repository.js +2 -1
  38. package/dist/Model/dsl.d.ts +4 -4
  39. package/dist/Model/dsl.d.ts.map +1 -1
  40. package/dist/Model/filter/filterApi.d.ts +5 -5
  41. package/dist/Model/filter/filterApi.d.ts.map +1 -1
  42. package/dist/Model/filter/types/errors.d.ts +1 -1
  43. package/dist/Model/filter/types/fields.d.ts +1 -1
  44. package/dist/Model/filter/types/path/common.d.ts +1 -1
  45. package/dist/Model/filter/types/path/eager.d.ts +1 -1
  46. package/dist/Model/filter/types/path/eager.d.ts.map +1 -1
  47. package/dist/Model/filter/types/path/eager.js +1 -1
  48. package/dist/Model/filter/types/path/index.d.ts +1 -1
  49. package/dist/Model/filter/types/utils.d.ts +1 -1
  50. package/dist/Model/filter/types/validator.d.ts +1 -1
  51. package/dist/Model/filter/types.d.ts +1 -1
  52. package/dist/Model/query/dsl.d.ts +25 -25
  53. package/dist/Model/query/dsl.d.ts.map +1 -1
  54. package/dist/Model/query/new-kid-interpreter.d.ts +6 -6
  55. package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -1
  56. package/dist/Model/query/new-kid-interpreter.js +3 -3
  57. package/dist/Model/query.d.ts +1 -1
  58. package/dist/Model.d.ts +2 -1
  59. package/dist/Model.d.ts.map +1 -1
  60. package/dist/Model.js +2 -1
  61. package/dist/QueueMaker/SQLQueue.d.ts +6 -8
  62. package/dist/QueueMaker/SQLQueue.d.ts.map +1 -1
  63. package/dist/QueueMaker/SQLQueue.js +106 -115
  64. package/dist/QueueMaker/errors.d.ts +2 -2
  65. package/dist/QueueMaker/errors.d.ts.map +1 -1
  66. package/dist/QueueMaker/memQueue.d.ts +7 -4
  67. package/dist/QueueMaker/memQueue.d.ts.map +1 -1
  68. package/dist/QueueMaker/memQueue.js +52 -62
  69. package/dist/QueueMaker/sbqueue.d.ts +6 -3
  70. package/dist/QueueMaker/sbqueue.d.ts.map +1 -1
  71. package/dist/QueueMaker/sbqueue.js +39 -53
  72. package/dist/QueueMaker/service.d.ts +1 -1
  73. package/dist/RequestContext.d.ts +117 -31
  74. package/dist/RequestContext.d.ts.map +1 -1
  75. package/dist/RequestContext.js +7 -8
  76. package/dist/RequestFiberSet.d.ts +7 -7
  77. package/dist/RequestFiberSet.d.ts.map +1 -1
  78. package/dist/RequestFiberSet.js +5 -5
  79. package/dist/Store/ContextMapContainer.d.ts +20 -4
  80. package/dist/Store/ContextMapContainer.d.ts.map +1 -1
  81. package/dist/Store/ContextMapContainer.js +13 -3
  82. package/dist/Store/Cosmos/query.d.ts +1 -1
  83. package/dist/Store/Cosmos/query.d.ts.map +1 -1
  84. package/dist/Store/Cosmos/query.js +10 -12
  85. package/dist/Store/Cosmos.d.ts +1 -1
  86. package/dist/Store/Cosmos.d.ts.map +1 -1
  87. package/dist/Store/Cosmos.js +318 -240
  88. package/dist/Store/Disk.d.ts +2 -2
  89. package/dist/Store/Disk.d.ts.map +1 -1
  90. package/dist/Store/Disk.js +25 -22
  91. package/dist/Store/Memory.d.ts +4 -4
  92. package/dist/Store/Memory.d.ts.map +1 -1
  93. package/dist/Store/Memory.js +27 -22
  94. package/dist/Store/SQL/Pg.d.ts +4 -0
  95. package/dist/Store/SQL/Pg.d.ts.map +1 -0
  96. package/dist/Store/SQL/Pg.js +189 -0
  97. package/dist/Store/SQL/query.d.ts +38 -0
  98. package/dist/Store/SQL/query.d.ts.map +1 -0
  99. package/dist/Store/SQL/query.js +367 -0
  100. package/dist/Store/SQL.d.ts +20 -0
  101. package/dist/Store/SQL.d.ts.map +1 -0
  102. package/dist/Store/SQL.js +381 -0
  103. package/dist/Store/codeFilter.d.ts +1 -1
  104. package/dist/Store/codeFilter.d.ts.map +1 -1
  105. package/dist/Store/codeFilter.js +2 -1
  106. package/dist/Store/index.d.ts +5 -2
  107. package/dist/Store/index.d.ts.map +1 -1
  108. package/dist/Store/index.js +15 -3
  109. package/dist/Store/service.d.ts +18 -7
  110. package/dist/Store/service.d.ts.map +1 -1
  111. package/dist/Store/service.js +24 -6
  112. package/dist/Store/utils.d.ts +1 -1
  113. package/dist/Store/utils.d.ts.map +1 -1
  114. package/dist/Store/utils.js +3 -4
  115. package/dist/Store.d.ts +1 -1
  116. package/dist/adapters/SQL/Model.d.ts +30 -47
  117. package/dist/adapters/SQL/Model.d.ts.map +1 -1
  118. package/dist/adapters/SQL/Model.js +22 -14
  119. package/dist/adapters/SQL.d.ts +1 -1
  120. package/dist/adapters/ServiceBus.d.ts +11 -11
  121. package/dist/adapters/ServiceBus.d.ts.map +1 -1
  122. package/dist/adapters/ServiceBus.js +15 -17
  123. package/dist/adapters/cosmos-client.d.ts +3 -3
  124. package/dist/adapters/cosmos-client.d.ts.map +1 -1
  125. package/dist/adapters/cosmos-client.js +3 -3
  126. package/dist/adapters/index.d.ts +8 -2
  127. package/dist/adapters/index.d.ts.map +1 -1
  128. package/dist/adapters/index.js +8 -2
  129. package/dist/adapters/logger.d.ts +2 -2
  130. package/dist/adapters/logger.d.ts.map +1 -1
  131. package/dist/adapters/memQueue.d.ts +3 -3
  132. package/dist/adapters/memQueue.d.ts.map +1 -1
  133. package/dist/adapters/memQueue.js +3 -3
  134. package/dist/adapters/mongo-client.d.ts +3 -3
  135. package/dist/adapters/mongo-client.d.ts.map +1 -1
  136. package/dist/adapters/mongo-client.js +3 -3
  137. package/dist/adapters/redis-client.d.ts +4 -4
  138. package/dist/adapters/redis-client.d.ts.map +1 -1
  139. package/dist/adapters/redis-client.js +3 -3
  140. package/dist/api/ContextProvider.d.ts +8 -8
  141. package/dist/api/ContextProvider.d.ts.map +1 -1
  142. package/dist/api/ContextProvider.js +6 -6
  143. package/dist/api/codec.d.ts +1 -1
  144. package/dist/api/internal/RequestContextMiddleware.d.ts +2 -2
  145. package/dist/api/internal/RequestContextMiddleware.d.ts.map +1 -1
  146. package/dist/api/internal/RequestContextMiddleware.js +2 -2
  147. package/dist/api/internal/auth.d.ts +45 -7
  148. package/dist/api/internal/auth.d.ts.map +1 -1
  149. package/dist/api/internal/auth.js +160 -29
  150. package/dist/api/internal/events.d.ts +3 -3
  151. package/dist/api/internal/events.d.ts.map +1 -1
  152. package/dist/api/internal/events.js +12 -8
  153. package/dist/api/internal/health.d.ts +1 -1
  154. package/dist/api/layerUtils.d.ts +6 -6
  155. package/dist/api/layerUtils.d.ts.map +1 -1
  156. package/dist/api/layerUtils.js +5 -5
  157. package/dist/api/middlewares.d.ts +1 -1
  158. package/dist/api/reportError.d.ts +1 -1
  159. package/dist/api/routing/middleware/RouterMiddleware.d.ts +4 -4
  160. package/dist/api/routing/middleware/RouterMiddleware.d.ts.map +1 -1
  161. package/dist/api/routing/middleware/middleware.d.ts +50 -4
  162. package/dist/api/routing/middleware/middleware.d.ts.map +1 -1
  163. package/dist/api/routing/middleware/middleware.js +79 -17
  164. package/dist/api/routing/middleware.d.ts +1 -2
  165. package/dist/api/routing/middleware.d.ts.map +1 -1
  166. package/dist/api/routing/middleware.js +1 -2
  167. package/dist/api/routing/schema/jwt.d.ts +2 -2
  168. package/dist/api/routing/schema/jwt.d.ts.map +1 -1
  169. package/dist/api/routing/schema/jwt.js +1 -1
  170. package/dist/api/routing/tsort.d.ts +1 -1
  171. package/dist/api/routing/tsort.d.ts.map +1 -1
  172. package/dist/api/routing/utils.d.ts +3 -3
  173. package/dist/api/routing/utils.d.ts.map +1 -1
  174. package/dist/api/routing.d.ts +32 -35
  175. package/dist/api/routing.d.ts.map +1 -1
  176. package/dist/api/routing.js +84 -36
  177. package/dist/api/setupRequest.d.ts +8 -5
  178. package/dist/api/setupRequest.d.ts.map +1 -1
  179. package/dist/api/setupRequest.js +14 -9
  180. package/dist/api/util.d.ts +1 -1
  181. package/dist/arbs.d.ts +1 -1
  182. package/dist/arbs.d.ts.map +1 -1
  183. package/dist/arbs.js +5 -3
  184. package/dist/errorReporter.d.ts +5 -5
  185. package/dist/errorReporter.d.ts.map +1 -1
  186. package/dist/errorReporter.js +20 -25
  187. package/dist/errors.d.ts +1 -1
  188. package/dist/fileUtil.d.ts +1 -1
  189. package/dist/fileUtil.d.ts.map +1 -1
  190. package/dist/fileUtil.js +3 -2
  191. package/dist/index.d.ts +1 -1
  192. package/dist/logger/jsonLogger.d.ts +1 -1
  193. package/dist/logger/logFmtLogger.d.ts +1 -1
  194. package/dist/logger/shared.d.ts +1 -1
  195. package/dist/logger/shared.js +2 -2
  196. package/dist/logger.d.ts +1 -1
  197. package/dist/logger.d.ts.map +1 -1
  198. package/dist/rateLimit.d.ts +9 -3
  199. package/dist/rateLimit.d.ts.map +1 -1
  200. package/dist/rateLimit.js +5 -11
  201. package/dist/test.d.ts +2 -2
  202. package/dist/test.d.ts.map +1 -1
  203. package/dist/test.js +1 -1
  204. package/dist/vitest.d.ts +1 -1
  205. package/examples/query.ts +39 -35
  206. package/package.json +41 -37
  207. package/src/CUPS.ts +9 -11
  208. package/src/Emailer/Sendgrid.ts +18 -15
  209. package/src/Emailer/service.ts +9 -3
  210. package/src/MainFiberSet.ts +5 -6
  211. package/src/Model/Repository/Registry.ts +33 -0
  212. package/src/Model/Repository/ext.ts +96 -10
  213. package/src/Model/Repository/internal/internal.ts +97 -88
  214. package/src/Model/Repository/makeRepo.ts +12 -10
  215. package/src/Model/Repository/service.ts +31 -22
  216. package/src/Model/Repository/validation.ts +4 -4
  217. package/src/Model/Repository.ts +1 -0
  218. package/src/Model/dsl.ts +3 -3
  219. package/src/Model/filter/types/path/eager.ts +1 -2
  220. package/src/Model/query/dsl.ts +18 -18
  221. package/src/Model/query/new-kid-interpreter.ts +2 -2
  222. package/src/Model.ts +1 -0
  223. package/src/QueueMaker/SQLQueue.ts +123 -154
  224. package/src/QueueMaker/memQueue.ts +85 -107
  225. package/src/QueueMaker/sbqueue.ts +54 -81
  226. package/src/RequestContext.ts +8 -10
  227. package/src/RequestFiberSet.ts +4 -4
  228. package/src/Store/ContextMapContainer.ts +41 -2
  229. package/src/Store/Cosmos/query.ts +16 -20
  230. package/src/Store/Cosmos.ts +452 -342
  231. package/src/Store/Disk.ts +52 -49
  232. package/src/Store/Memory.ts +55 -51
  233. package/src/Store/SQL/Pg.ts +318 -0
  234. package/src/Store/SQL/query.ts +409 -0
  235. package/src/Store/SQL.ts +668 -0
  236. package/src/Store/codeFilter.ts +1 -0
  237. package/src/Store/index.ts +17 -2
  238. package/src/Store/service.ts +32 -8
  239. package/src/Store/utils.ts +23 -22
  240. package/src/adapters/SQL/Model.ts +83 -72
  241. package/src/adapters/ServiceBus.ts +114 -118
  242. package/src/adapters/cosmos-client.ts +2 -2
  243. package/src/adapters/index.ts +7 -0
  244. package/src/adapters/memQueue.ts +2 -2
  245. package/src/adapters/mongo-client.ts +2 -2
  246. package/src/adapters/redis-client.ts +2 -2
  247. package/src/api/ContextProvider.ts +12 -13
  248. package/src/api/internal/RequestContextMiddleware.ts +1 -1
  249. package/src/api/internal/auth.ts +246 -44
  250. package/src/api/internal/events.ts +15 -10
  251. package/src/api/layerUtils.ts +8 -8
  252. package/src/api/routing/middleware/RouterMiddleware.ts +4 -4
  253. package/src/api/routing/middleware/middleware.ts +112 -15
  254. package/src/api/routing/middleware.ts +0 -2
  255. package/src/api/routing/schema/jwt.ts +2 -3
  256. package/src/api/routing.ts +153 -79
  257. package/src/api/setupRequest.ts +30 -10
  258. package/src/arbs.ts +4 -2
  259. package/src/errorReporter.ts +63 -75
  260. package/src/fileUtil.ts +2 -1
  261. package/src/logger/shared.ts +1 -1
  262. package/src/rateLimit.ts +30 -22
  263. package/src/test.ts +1 -1
  264. package/test/auth.test.ts +101 -0
  265. package/test/contextProvider.test.ts +11 -11
  266. package/test/controller.test.ts +27 -21
  267. package/test/dist/auth.test.d.ts.map +1 -0
  268. package/test/dist/contextProvider.test.d.ts.map +1 -1
  269. package/test/dist/controller.test.d.ts.map +1 -1
  270. package/test/dist/fixtures.d.ts +26 -12
  271. package/test/dist/fixtures.d.ts.map +1 -1
  272. package/test/dist/fixtures.js +12 -10
  273. package/test/dist/query.test.d.ts.map +1 -1
  274. package/test/dist/rawQuery.test.d.ts.map +1 -1
  275. package/test/dist/repository-ext.test.d.ts.map +1 -0
  276. package/test/dist/requires.test.d.ts.map +1 -1
  277. package/test/dist/router-generator.test.d.ts.map +1 -0
  278. package/test/dist/routing-interruptibility.test.d.ts.map +1 -0
  279. package/test/dist/rpc-e2e-invalidation.test.d.ts.map +1 -0
  280. package/test/dist/rpc-multi-middleware.test.d.ts.map +1 -1
  281. package/test/dist/rpc-stream-fullstack.test.d.ts.map +1 -0
  282. package/test/dist/sql-store.test.d.ts.map +1 -0
  283. package/test/fixtures.ts +11 -9
  284. package/test/query.test.ts +216 -36
  285. package/test/rawQuery.test.ts +23 -19
  286. package/test/repository-ext.test.ts +60 -0
  287. package/test/requires.test.ts +6 -6
  288. package/test/router-generator.test.ts +180 -0
  289. package/test/routing-interruptibility.test.ts +63 -0
  290. package/test/rpc-e2e-invalidation.test.ts +507 -0
  291. package/test/rpc-multi-middleware.test.ts +79 -10
  292. package/test/rpc-stream-fullstack.test.ts +325 -0
  293. package/test/sql-store.test.ts +1064 -0
  294. package/test/validateSample.test.ts +15 -12
  295. package/tsconfig.examples.json +1 -1
  296. package/tsconfig.json +0 -1
  297. package/tsconfig.json.bak +2 -2
  298. package/tsconfig.src.json +35 -35
  299. package/tsconfig.test.json +2 -2
  300. package/dist/Operations.d.ts +0 -55
  301. package/dist/Operations.d.ts.map +0 -1
  302. package/dist/Operations.js +0 -102
  303. package/dist/OperationsRepo.d.ts +0 -41
  304. package/dist/OperationsRepo.d.ts.map +0 -1
  305. package/dist/OperationsRepo.js +0 -14
  306. package/eslint.config.mjs +0 -24
  307. package/src/Operations.ts +0 -235
  308. package/src/OperationsRepo.ts +0 -16
@@ -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 { Effect, flow, Layer, Option, pipe, S, ServiceMap, Struct } from "effect-app"
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.Number })
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.withDefaultConstructor(() => ({ _tag: "string" as const, value: "hi" })))
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
- ...Something.omit("displayName"),
94
- displayName: S.Literal("Verona", "Riley")
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 ServiceMap.Service<SomethingRepo>()("SomethingRepo", {
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(MemoryStoreLive)
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.ExtendedTaggedClass<Person, Person.Encoded>()("person", {
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.ExtendedTaggedClass<Animal, Animal.Encoded>()("animal", {
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.ExtendedTaggedClass<Test, Test.Encoded>()("test", {
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
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(() => Option.some(new Date()))
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(() => Option.some(new Date()))
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
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.Literal("a", "b", "c")
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
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.Literal("a", "b", "c"), S.Null])
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise)
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.Number)
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
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(S.Struct(Data.pick("union")))
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
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(MemoryStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
1280
+ .pipe(Effect.provide(TestStoreLive), setupRequestContextFromCurrent(), Effect.runPromise))
@@ -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, ServiceMap } from "effect-app"
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.Number, description: S.String }))
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 ServiceMap.Service<SomethingRepo>()(
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.gen(function*() {
87
- const url = yield* Config.redacted("STORAGE_URL").pipe(
88
- Config.withDefault(
89
- Redacted.make(
90
- // the emulator doesn't implement array projections :/ so you need an actual cloud instance!
91
- "AccountEndpoint=http://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
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
- return CosmosStoreLayer({
96
- dbName: "test",
97
- prefix: "",
98
- url
97
+ return CosmosStoreLayer({
98
+ dbName: "test",
99
+ prefix: "",
100
+ url
101
+ })
102
+ .pipe(Layer.merge(RepositoryRegistryLive))
99
103
  })
100
- }).pipe(Layer.unwrap)
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.Number })) })
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.Number })) })
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(...items.slice(0, 2).map((_) => _.id))
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
+ })
@@ -1,8 +1,7 @@
1
1
  import { describe, expect, expectTypeOf, it } from "@effect/vitest"
2
- import { Effect, Layer, Result, S, ServiceMap } from "effect-app"
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: ServiceMap.make(_mw.requestContext, {}) }
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: ServiceMap.make(_mw.requestContext, { requireRoles: ["manager"] })
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: ServiceMap.make(_mw.requestContext, { requireRoles: ["manager"] })
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: ServiceMap.make(_mw.requestContext, { requireRoles: ["manager"] })
156
+ annotations: Context.make(_mw.requestContext, { requireRoles: ["manager"] })
157
157
  }
158
158
  }
159
159
  )