@effect-app/infra 0.168.0 → 0.170.0

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 (167) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/_cjs/RequestContext.cjs +3 -4
  3. package/_cjs/RequestContext.cjs.map +1 -1
  4. package/_cjs/api/codec.cjs.map +1 -1
  5. package/_cjs/api/express/schema/jwt.cjs.map +1 -1
  6. package/_cjs/api/routing/base.cjs.map +1 -1
  7. package/_cjs/api/routing/defaultErrorHandler.cjs +2 -2
  8. package/_cjs/api/routing/defaultErrorHandler.cjs.map +1 -1
  9. package/_cjs/api/routing/makeRequestHandler.cjs.map +1 -1
  10. package/_cjs/api/routing/match.cjs +1 -1
  11. package/_cjs/api/routing/match.cjs.map +1 -1
  12. package/_cjs/logger/logFmtLogger.cjs.map +1 -1
  13. package/_cjs/services/Emailer/Sendgrid.cjs.map +1 -1
  14. package/_cjs/services/QueueMaker/errors.cjs.map +1 -1
  15. package/_cjs/services/QueueMaker/memQueue.cjs.map +1 -1
  16. package/_cjs/services/QueueMaker/sbqueue.cjs.map +1 -1
  17. package/_cjs/services/Repository.cjs.map +1 -1
  18. package/_cjs/services/RepositoryBase.cjs.map +1 -1
  19. package/_cjs/services/RequestContextContainer.cjs +1 -1
  20. package/_cjs/services/RequestContextContainer.cjs.map +1 -1
  21. package/_cjs/services/Store/ContextMapContainer.cjs +1 -1
  22. package/_cjs/services/Store/ContextMapContainer.cjs.map +1 -1
  23. package/_cjs/services/Store/utils.cjs.map +1 -1
  24. package/_cjs/services/simpledb/cosmosdb.cjs +2 -2
  25. package/_cjs/services/simpledb/cosmosdb.cjs.map +1 -1
  26. package/_cjs/services/simpledb/redisdb.cjs.map +1 -1
  27. package/_cjs/services/simpledb/shared.cjs +5 -4
  28. package/_cjs/services/simpledb/shared.cjs.map +1 -1
  29. package/_cjs/services/simpledb/simpledb.cjs +1 -1
  30. package/_cjs/services/simpledb/simpledb.cjs.map +1 -1
  31. package/_src/RequestContext.ts +3 -3
  32. package/_src/api/codec.ts +1 -1
  33. package/_src/api/defaultErrorHandler.ts +2 -2
  34. package/_src/api/express/schema/jwt.ts +3 -3
  35. package/_src/api/express/schema/routing.ts +7 -7
  36. package/_src/api/reportError.ts +2 -2
  37. package/_src/api/routing/base.ts +19 -22
  38. package/_src/api/routing/defaultErrorHandler.ts +3 -3
  39. package/_src/api/routing/makeRequestHandler.ts +20 -28
  40. package/_src/api/routing/match.ts +4 -4
  41. package/_src/api/setupRequest.ts +3 -3
  42. package/_src/logger/logFmtLogger.ts +1 -1
  43. package/_src/rateLimit.ts +9 -9
  44. package/_src/services/Emailer/Sendgrid.ts +3 -7
  45. package/_src/services/Emailer/service.ts +1 -1
  46. package/_src/services/Operations/service.ts +9 -9
  47. package/_src/services/QueueMaker/errors.ts +5 -5
  48. package/_src/services/QueueMaker/memQueue.ts +5 -5
  49. package/_src/services/QueueMaker/sbqueue.ts +5 -5
  50. package/_src/services/QueueMaker/service.ts +3 -3
  51. package/_src/services/Repository.ts +90 -110
  52. package/_src/services/RepositoryBase.ts +29 -45
  53. package/_src/services/RequestContextContainer.ts +7 -9
  54. package/_src/services/Store/ContextMapContainer.ts +4 -4
  55. package/_src/services/Store/Cosmos.ts +3 -3
  56. package/_src/services/Store/Disk.ts +4 -4
  57. package/_src/services/Store/Memory.ts +2 -2
  58. package/_src/services/Store/Redis.ts +3 -3
  59. package/_src/services/Store/service.ts +10 -10
  60. package/_src/services/Store/utils.ts +2 -2
  61. package/_src/services/simpledb/cosmosdb.ts +3 -3
  62. package/_src/services/simpledb/diskdb.ts +3 -3
  63. package/_src/services/simpledb/memdb.ts +3 -3
  64. package/_src/services/simpledb/mongodb.ts +3 -3
  65. package/_src/services/simpledb/redisdb.ts +5 -5
  66. package/_src/services/simpledb/shared.ts +4 -3
  67. package/_src/services/simpledb/simpledb.ts +8 -8
  68. package/dist/RequestContext.d.ts +48 -48
  69. package/dist/RequestContext.js +4 -5
  70. package/dist/_ext/Array.d.ts +1 -1
  71. package/dist/api/codec.d.ts +1 -1
  72. package/dist/api/codec.d.ts.map +1 -1
  73. package/dist/api/codec.js +1 -1
  74. package/dist/api/defaultErrorHandler.d.ts +2 -2
  75. package/dist/api/defaultErrorHandler.d.ts.map +1 -1
  76. package/dist/api/express/schema/jwt.d.ts +1 -1
  77. package/dist/api/express/schema/jwt.js +1 -1
  78. package/dist/api/express/schema/routing.d.ts +6 -6
  79. package/dist/api/express/schema/routing.d.ts.map +1 -1
  80. package/dist/api/reportError.d.ts +2 -2
  81. package/dist/api/routing/base.d.ts +11 -10
  82. package/dist/api/routing/base.d.ts.map +1 -1
  83. package/dist/api/routing/base.js +1 -1
  84. package/dist/api/routing/defaultErrorHandler.d.ts +5 -5
  85. package/dist/api/routing/defaultErrorHandler.d.ts.map +1 -1
  86. package/dist/api/routing/defaultErrorHandler.js +3 -3
  87. package/dist/api/routing/makeRequestHandler.d.ts +2 -2
  88. package/dist/api/routing/makeRequestHandler.d.ts.map +1 -1
  89. package/dist/api/routing/makeRequestHandler.js +11 -15
  90. package/dist/api/routing/match.d.ts +1 -1
  91. package/dist/api/routing/match.d.ts.map +1 -1
  92. package/dist/api/routing/match.js +2 -2
  93. package/dist/api/setupRequest.d.ts +2 -2
  94. package/dist/errorReporter.d.ts +3 -3
  95. package/dist/logger/logFmtLogger.js +2 -2
  96. package/dist/rateLimit.d.ts +4 -4
  97. package/dist/rateLimit.js +1 -1
  98. package/dist/services/Emailer/Sendgrid.d.ts +1 -1
  99. package/dist/services/Emailer/Sendgrid.d.ts.map +1 -1
  100. package/dist/services/Emailer/Sendgrid.js +1 -1
  101. package/dist/services/Emailer/fake.d.ts +1 -1
  102. package/dist/services/Emailer/service.d.ts +2 -2
  103. package/dist/services/Emailer/service.d.ts.map +1 -1
  104. package/dist/services/Operations/live.d.ts +1 -1
  105. package/dist/services/Operations/service.d.ts +12 -12
  106. package/dist/services/Operations/service.d.ts.map +1 -1
  107. package/dist/services/QueueMaker/errors.d.ts +5 -5
  108. package/dist/services/QueueMaker/errors.d.ts.map +1 -1
  109. package/dist/services/QueueMaker/errors.js +1 -1
  110. package/dist/services/QueueMaker/memQueue.d.ts +4 -4
  111. package/dist/services/QueueMaker/memQueue.d.ts.map +1 -1
  112. package/dist/services/QueueMaker/memQueue.js +1 -1
  113. package/dist/services/QueueMaker/sbqueue.d.ts +5 -5
  114. package/dist/services/QueueMaker/sbqueue.d.ts.map +1 -1
  115. package/dist/services/QueueMaker/sbqueue.js +1 -1
  116. package/dist/services/QueueMaker/service.d.ts +11 -11
  117. package/dist/services/QueueMaker/service.d.ts.map +1 -1
  118. package/dist/services/Repository.d.ts +67 -67
  119. package/dist/services/Repository.d.ts.map +1 -1
  120. package/dist/services/Repository.js +1 -1
  121. package/dist/services/RepositoryBase.d.ts +30 -30
  122. package/dist/services/RepositoryBase.d.ts.map +1 -1
  123. package/dist/services/RepositoryBase.js +1 -1
  124. package/dist/services/RequestContextContainer.d.ts +9 -9
  125. package/dist/services/RequestContextContainer.d.ts.map +1 -1
  126. package/dist/services/RequestContextContainer.js +11 -13
  127. package/dist/services/Store/ContextMapContainer.d.ts +7 -7
  128. package/dist/services/Store/ContextMapContainer.d.ts.map +1 -1
  129. package/dist/services/Store/ContextMapContainer.js +2 -2
  130. package/dist/services/Store/Cosmos/query.d.ts +1 -1
  131. package/dist/services/Store/Cosmos.d.ts +1 -1
  132. package/dist/services/Store/Cosmos.js +1 -1
  133. package/dist/services/Store/Disk.d.ts +4 -4
  134. package/dist/services/Store/Disk.d.ts.map +1 -1
  135. package/dist/services/Store/Disk.js +1 -1
  136. package/dist/services/Store/Memory.d.ts +4 -4
  137. package/dist/services/Store/Memory.d.ts.map +1 -1
  138. package/dist/services/Store/Redis.d.ts +1 -1
  139. package/dist/services/Store/Redis.js +1 -1
  140. package/dist/services/Store/index.d.ts +1 -1
  141. package/dist/services/Store/service.d.ts +14 -14
  142. package/dist/services/Store/service.d.ts.map +1 -1
  143. package/dist/services/Store/utils.d.ts +1 -1
  144. package/dist/services/Store/utils.d.ts.map +1 -1
  145. package/dist/services/Store/utils.js +1 -1
  146. package/dist/services/simpledb/cosmosdb.d.ts +6 -6
  147. package/dist/services/simpledb/cosmosdb.d.ts.map +1 -1
  148. package/dist/services/simpledb/cosmosdb.js +3 -3
  149. package/dist/services/simpledb/diskdb.d.ts +4 -4
  150. package/dist/services/simpledb/diskdb.d.ts.map +1 -1
  151. package/dist/services/simpledb/diskdb.js +1 -1
  152. package/dist/services/simpledb/memdb.d.ts +4 -4
  153. package/dist/services/simpledb/memdb.d.ts.map +1 -1
  154. package/dist/services/simpledb/memdb.js +1 -1
  155. package/dist/services/simpledb/mongodb.d.ts +5 -5
  156. package/dist/services/simpledb/mongodb.d.ts.map +1 -1
  157. package/dist/services/simpledb/mongodb.js +1 -1
  158. package/dist/services/simpledb/redisdb.d.ts +13 -13
  159. package/dist/services/simpledb/redisdb.d.ts.map +1 -1
  160. package/dist/services/simpledb/redisdb.js +1 -1
  161. package/dist/services/simpledb/shared.d.ts +19 -19
  162. package/dist/services/simpledb/shared.d.ts.map +1 -1
  163. package/dist/services/simpledb/shared.js +6 -5
  164. package/dist/services/simpledb/simpledb.d.ts +5 -5
  165. package/dist/services/simpledb/simpledb.d.ts.map +1 -1
  166. package/dist/services/simpledb/simpledb.js +2 -2
  167. package/package.json +12 -12
@@ -74,17 +74,13 @@ export function projectEffect<
74
74
  S = PM
75
75
  >(
76
76
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
77
- map: Effect<
78
- R,
79
- E,
80
- {
81
- filter?: Filter<PM> | undefined
82
- collect?: ((t: PM) => Option<S>) | undefined
83
- limit?: number | undefined
84
- skip?: number | undefined
85
- }
86
- >
87
- ): Effect<R, E, S[]>
77
+ map: Effect<{
78
+ filter?: Filter<PM> | undefined
79
+ collect?: ((t: PM) => Option<S>) | undefined
80
+ limit?: number | undefined
81
+ skip?: number | undefined
82
+ }, E, R>
83
+ ): Effect<S[], E, R>
88
84
  export function projectEffect<
89
85
  T extends { id: unknown },
90
86
  PM extends PersistenceModelType<string>,
@@ -96,17 +92,13 @@ export function projectEffect<
96
92
  S = PM
97
93
  >(
98
94
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
99
- map: Effect<
100
- R,
101
- E,
102
- {
103
- filter?: QueryBuilder<PM> | undefined
104
- collect?: ((t: PM) => Option<S>) | undefined
105
- limit?: number | undefined
106
- skip?: number | undefined
107
- }
108
- >
109
- ): Effect<R, E, Pick<PM, U>[]>
95
+ map: Effect<{
96
+ filter?: QueryBuilder<PM> | undefined
97
+ collect?: ((t: PM) => Option<S>) | undefined
98
+ limit?: number | undefined
99
+ skip?: number | undefined
100
+ }, E, R>
101
+ ): Effect<Pick<PM, U>[], E, R>
110
102
  export function projectEffect<
111
103
  T extends { id: unknown },
112
104
  PM extends PersistenceModelType<string>,
@@ -118,18 +110,14 @@ export function projectEffect<
118
110
  S = Pick<PM, U>
119
111
  >(
120
112
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
121
- map: Effect<
122
- R,
123
- E,
124
- {
125
- filter?: Filter<PM> | undefined
126
- select?: NonEmptyReadonlyArray<U> | undefined
127
- collect?: ((t: PM) => Option<S>) | undefined
128
- limit?: number | undefined
129
- skip?: number | undefined
130
- }
131
- >
132
- ): Effect<R, E, S[]> {
113
+ map: Effect<{
114
+ filter?: Filter<PM> | undefined
115
+ select?: NonEmptyReadonlyArray<U> | undefined
116
+ collect?: ((t: PM) => Option<S>) | undefined
117
+ limit?: number | undefined
118
+ skip?: number | undefined
119
+ }, E, R>
120
+ ): Effect<S[], E, R> {
133
121
  // TODO: a projection that gets sent to the db instead.
134
122
  return map.flatMap((f) =>
135
123
  self
@@ -157,7 +145,7 @@ export function project<
157
145
  limit?: number
158
146
  skip?: number
159
147
  }
160
- ): Effect<never, never, S[]>
148
+ ): Effect<S[]>
161
149
  export function project<
162
150
  T extends { id: unknown },
163
151
  PM extends PersistenceModelType<string>,
@@ -172,7 +160,7 @@ export function project<
172
160
  limit?: number
173
161
  skip?: number
174
162
  }
175
- ): Effect<never, never, Pick<PM, U>[]>
163
+ ): Effect<Pick<PM, U>[]>
176
164
  export function project<
177
165
  T extends { id: unknown },
178
166
  PM extends PersistenceModelType<string>,
@@ -189,7 +177,7 @@ export function project<
189
177
  limit?: number
190
178
  skip?: number
191
179
  }
192
- ): Effect<never, never, S[]> {
180
+ ): Effect<S[]> {
193
181
  return self.projectEffect(Effect.sync(() => map))
194
182
  }
195
183
 
@@ -225,7 +213,7 @@ export function queryEffect<
225
213
  >(
226
214
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
227
215
  // TODO: think about collectPM, collectE, and collect(Parsed)
228
- map: Effect<R, E, { filter?: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }>
216
+ map: Effect<{ filter?: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }, E, R>
229
217
  ) {
230
218
  return map.flatMap((f) =>
231
219
  (f.filter ? self.utils.filter(f) : self.utils.all)
@@ -247,8 +235,8 @@ export function queryOneEffect<
247
235
  >(
248
236
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
249
237
  // TODO: think about collectPM, collectE, and collect(Parsed)
250
- map: Effect<R, E, { filter?: Filter<PM> }>
251
- ): Effect<R, E | NotFoundError<ItemType>, T>
238
+ map: Effect<{ filter?: Filter<PM> }, E, R>
239
+ ): Effect<T, E | NotFoundError<ItemType>, R>
252
240
  export function queryOneEffect<
253
241
  T extends { id: unknown },
254
242
  PM extends PersistenceModelType<string>,
@@ -260,8 +248,8 @@ export function queryOneEffect<
260
248
  >(
261
249
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
262
250
  // TODO: think about collectPM, collectE, and collect(Parsed)
263
- map: Effect<R, E, { filter?: Filter<PM>; collect: (t: T) => Option<S> }>
264
- ): Effect<R, E | NotFoundError<ItemType>, S>
251
+ map: Effect<{ filter?: Filter<PM>; collect: (t: T) => Option<S> }, E, R>
252
+ ): Effect<S, E | NotFoundError<ItemType>, R>
265
253
  export function queryOneEffect<
266
254
  T extends { id: unknown },
267
255
  PM extends PersistenceModelType<string>,
@@ -273,8 +261,8 @@ export function queryOneEffect<
273
261
  >(
274
262
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
275
263
  // TODO: think about collectPM, collectE, and collect(Parsed)
276
- map: Effect<R, E, { filter?: Filter<PM>; collect?: (t: T) => Option<S> }>
277
- ): Effect<R, E | NotFoundError<ItemType>, S> {
264
+ map: Effect<{ filter?: Filter<PM>; collect?: (t: T) => Option<S> }, E, R>
265
+ ): Effect<S, E | NotFoundError<ItemType>, R> {
278
266
  return map.flatMap((f) =>
279
267
  (f.filter ? self.utils.filter({ filter: f.filter, limit: 1 }) : self.utils.all)
280
268
  .flatMap((_) => self.utils.parseMany(_))
@@ -316,7 +304,7 @@ export function queryOne<
316
304
  >(
317
305
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
318
306
  map: { filter?: Filter<PM>; collect: (t: T) => Option<S> }
319
- ): Effect<never, NotFoundError<ItemType>, S>
307
+ ): Effect<S, NotFoundError<ItemType>>
320
308
  export function queryOne<
321
309
  T extends { id: unknown },
322
310
  PM extends PersistenceModelType<string>,
@@ -325,7 +313,7 @@ export function queryOne<
325
313
  >(
326
314
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
327
315
  map: { filter?: Filter<PM> }
328
- ): Effect<never, NotFoundError<ItemType>, T>
316
+ ): Effect<T, NotFoundError<ItemType>>
329
317
  export function queryOne<
330
318
  T extends { id: unknown },
331
319
  PM extends PersistenceModelType<string>,
@@ -352,15 +340,11 @@ export function queryAndSaveOnePureEffect<
352
340
  S extends T = T
353
341
  >(
354
342
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
355
- map: Effect<R, E, { filter: Filter<PM>; collect: (t: T) => Option<S>; limit?: number; skip?: number }>
356
- ): <R2, A, E2, S2 extends T>(pure: Effect<FixEnv<R2, Evt, S, S2>, E2, A>) => Effect<
357
- | R
358
- | Exclude<R2, {
359
- env: PureEnv<Evt, S, S2>
360
- }>,
361
- InvalidStateError | OptimisticConcurrencyException | E | E2 | NotFoundError<ItemType>,
362
- A
363
- >
343
+ map: Effect<{ filter: Filter<PM>; collect: (t: T) => Option<S>; limit?: number; skip?: number }, E, R>
344
+ ): <R2, A, E2, S2 extends T>(pure: Effect<A, E2, FixEnv<R2, Evt, S, S2>>) => Effect<A, InvalidStateError | OptimisticConcurrencyException | E | E2 | NotFoundError<ItemType>, | R
345
+ | Exclude<R2, {
346
+ env: PureEnv<Evt, S, S2>
347
+ }>>
364
348
  export function queryAndSaveOnePureEffect<
365
349
  T extends { id: unknown },
366
350
  PM extends PersistenceModelType<string>,
@@ -370,15 +354,11 @@ export function queryAndSaveOnePureEffect<
370
354
  E
371
355
  >(
372
356
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
373
- map: Effect<R, E, { filter: Filter<PM> }>
374
- ): <R2, A, E2, T2 extends T>(pure: Effect<FixEnv<R2, Evt, T, T2>, E2, A>) => Effect<
375
- | R
376
- | Exclude<R2, {
377
- env: PureEnv<Evt, T, T2>
378
- }>,
379
- InvalidStateError | OptimisticConcurrencyException | E | E2 | NotFoundError<ItemType>,
380
- A
381
- >
357
+ map: Effect<{ filter: Filter<PM> }, E, R>
358
+ ): <R2, A, E2, T2 extends T>(pure: Effect<A, E2, FixEnv<R2, Evt, T, T2>>) => Effect<A, InvalidStateError | OptimisticConcurrencyException | E | E2 | NotFoundError<ItemType>, | R
359
+ | Exclude<R2, {
360
+ env: PureEnv<Evt, T, T2>
361
+ }>>
382
362
  export function queryAndSaveOnePureEffect(
383
363
  self: any,
384
364
  map: any
@@ -400,12 +380,12 @@ export function queryAndSaveOnePure<
400
380
  >(
401
381
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
402
382
  map: { filter: Filter<PM>; collect: (t: T) => Option<S>; limit?: number; skip?: number }
403
- ): <R2, A, E2, S2>(pure: Effect<FixEnv<R2, Evt, S, S2>, E2, A>) => Effect<
383
+ ): <R2, A, E2, S2>(pure: Effect<A, E2, FixEnv<R2, Evt, S, S2>>) => Effect<
384
+ A,
385
+ InvalidStateError | OptimisticConcurrencyException | E2 | NotFoundError<ItemType>,
404
386
  Exclude<R2, {
405
387
  env: PureEnv<Evt, S, S2>
406
- }>,
407
- InvalidStateError | OptimisticConcurrencyException | E2 | NotFoundError<ItemType>,
408
- A
388
+ }>
409
389
  >
410
390
  export function queryAndSaveOnePure<
411
391
  T extends { id: unknown },
@@ -415,12 +395,12 @@ export function queryAndSaveOnePure<
415
395
  >(
416
396
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
417
397
  map: { filter: Filter<PM> }
418
- ): <R2, A, E2, T2>(pure: Effect<FixEnv<R2, Evt, T, T2>, E2, A>) => Effect<
398
+ ): <R2, A, E2, T2>(pure: Effect<A, E2, FixEnv<R2, Evt, T, T2>>) => Effect<
399
+ A,
400
+ InvalidStateError | OptimisticConcurrencyException | E2 | NotFoundError<ItemType>,
419
401
  Exclude<R2, {
420
402
  env: PureEnv<Evt, T, T2>
421
- }>,
422
- InvalidStateError | OptimisticConcurrencyException | E2 | NotFoundError<ItemType>,
423
- A
403
+ }>
424
404
  >
425
405
  export function queryAndSaveOnePure(
426
406
  self: any,
@@ -442,11 +422,11 @@ export function queryAndSavePureEffect<
442
422
  S extends T = T
443
423
  >(
444
424
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
445
- map: Effect<R, E, { filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }>
425
+ map: Effect<{ filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }, E, R>
446
426
  ) {
447
- return <R2, A, E2, S2 extends T>(pure: Effect<FixEnv<R2, Evt, S[], S2[]>, E2, A>) =>
427
+ return <R2, A, E2, S2 extends T>(pure: Effect<A, E2, FixEnv<R2, Evt, S[], S2[]>>) =>
448
428
  queryEffect(self, map)
449
- .flatMap((_) => self.saveManyWithPure_(_, pure))
429
+ .flatMap((_) => self.saveManyWithPure_(_, pure));
450
430
  }
451
431
 
452
432
  /**
@@ -474,8 +454,8 @@ export function saveManyWithPure<
474
454
  Evt,
475
455
  ItemType extends string
476
456
  >(self: RepositoryBaseC<T, PM, Evt, ItemType>) {
477
- return <R, A, E, S1 extends T, S2 extends T>(pure: Effect<FixEnv<R, Evt, S1[], S2[]>, E, A>) =>
478
- (items: Iterable<S1>) => saveManyWithPure_(self, items, pure)
457
+ return <R, A, E, S1 extends T, S2 extends T>(pure: Effect<A, E, FixEnv<R, Evt, S1[], S2[]>>) =>
458
+ (items: Iterable<S1>) => saveManyWithPure_(self, items, pure);
479
459
  }
480
460
 
481
461
  /**
@@ -487,8 +467,8 @@ export function byIdAndSaveWithPure<
487
467
  Evt,
488
468
  ItemType extends string
489
469
  >(self: RepositoryBaseC<T, PM, Evt, ItemType>, id: T["id"]) {
490
- return <R, A, E, S2 extends T>(pure: Effect<FixEnv<R, Evt, T, S2>, E, A>) =>
491
- get(self, id).flatMap((item) => saveWithPure_(self, item, pure))
470
+ return <R, A, E, S2 extends T>(pure: Effect<A, E, FixEnv<R, Evt, T, S2>>) =>
471
+ get(self, id).flatMap((item) => saveWithPure_(self, item, pure));
492
472
  }
493
473
 
494
474
  /**
@@ -502,9 +482,9 @@ export function handleByIdAndSaveWithPure<
502
482
  ItemType extends string
503
483
  >(self: RepositoryBaseC<T, PM, Evt, ItemType>) {
504
484
  return <Req extends { id: T["id"] }, Context, R, A, E, S2 extends T>(
505
- pure: (req: Req, ctx: Context) => Effect<FixEnv<R, Evt, T, S2>, E, A>
485
+ pure: (req: Req, ctx: Context) => Effect<A, E, FixEnv<R, Evt, T, S2>>
506
486
  ) =>
507
- (req: Req, ctx: Context) => byIdAndSaveWithPure(self, req.id)(pure(req, ctx))
487
+ (req: Req, ctx: Context) => byIdAndSaveWithPure(self, req.id)(pure(req, ctx));
508
488
  }
509
489
 
510
490
  /**
@@ -523,7 +503,7 @@ export function saveManyWithPure_<
523
503
  >(
524
504
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
525
505
  items: Iterable<S1>,
526
- pure: Effect<FixEnv<R, Evt, S1[], S2[]>, E, A>
506
+ pure: Effect<A, E, FixEnv<R, Evt, S1[], S2[]>>
527
507
  ) {
528
508
  return saveAllWithEffectInt(
529
509
  self,
@@ -547,7 +527,7 @@ export function saveWithPure_<
547
527
  >(
548
528
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
549
529
  item: S1,
550
- pure: Effect<FixEnv<R, Evt, S1, S2>, E, A>
530
+ pure: Effect<A, E, FixEnv<R, Evt, S1, S2>>
551
531
  ) {
552
532
  return saveAllWithEffectInt(
553
533
  self,
@@ -568,7 +548,7 @@ export function saveAllWithEffectInt<
568
548
  A
569
549
  >(
570
550
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
571
- gen: Effect<R, E, readonly [Iterable<P>, Iterable<Evt>, A]>
551
+ gen: Effect<readonly [Iterable<P>, Iterable<Evt>, A], E, R>
572
552
  ) {
573
553
  return gen
574
554
  .flatMap(
@@ -590,12 +570,12 @@ export function queryAndSavePureEffectBatched<
590
570
  >(
591
571
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
592
572
  // TODO: think about collectPM, collectE, and collect(Parsed)
593
- map: Effect<R, E, { filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }>,
573
+ map: Effect<{ filter: Filter<PM>; collect?: (t: T) => Option<S>; limit?: number; skip?: number }, E, R>,
594
574
  batchSize = 100
595
575
  ) {
596
- return <R2, A, E2, S2 extends T>(pure: Effect<FixEnv<R2, Evt, S[], S2[]>, E2, A>) =>
576
+ return <R2, A, E2, S2 extends T>(pure: Effect<A, E2, FixEnv<R2, Evt, S[], S2[]>>) =>
597
577
  queryEffect(self, map)
598
- .flatMap((_) => self.saveManyWithPureBatched_(_, pure, batchSize))
578
+ .flatMap((_) => self.saveManyWithPureBatched_(_, pure, batchSize));
599
579
  }
600
580
 
601
581
  /**
@@ -625,8 +605,8 @@ export function saveManyWithPureBatched<
625
605
  Evt,
626
606
  ItemType extends string
627
607
  >(self: RepositoryBaseC<T, PM, Evt, ItemType>, batchSize = 100) {
628
- return <R, A, E, S1 extends T, S2 extends T>(pure: Effect<FixEnv<R, Evt, S1[], S2[]>, E, A>) =>
629
- (items: Iterable<S1>) => saveManyWithPureBatched_(self, items, pure, batchSize)
608
+ return <R, A, E, S1 extends T, S2 extends T>(pure: Effect<A, E, FixEnv<R, Evt, S1[], S2[]>>) =>
609
+ (items: Iterable<S1>) => saveManyWithPureBatched_(self, items, pure, batchSize);
630
610
  }
631
611
 
632
612
  /**
@@ -645,7 +625,7 @@ export function saveManyWithPureBatched_<
645
625
  >(
646
626
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
647
627
  items: Iterable<S1>,
648
- pure: Effect<FixEnv<R, Evt, S1[], S2[]>, E, A>,
628
+ pure: Effect<A, E, FixEnv<R, Evt, S1[], S2[]>>,
649
629
  batchSize = 100
650
630
  ) {
651
631
  return items
@@ -662,8 +642,8 @@ const anyDSL = makeDSL<any, any, any>()
662
642
 
663
643
  export type AllDSL<T, Evt> =
664
644
  & (<R, A, E, S1 extends T, S2 extends T>(
665
- pure: (dsl: PureDSL<S1[], S2[], Evt>) => Effect<R, E, A>
666
- ) => Effect<FixEnv<R, Evt, S1[], S2[]>, E, A>)
645
+ pure: (dsl: PureDSL<S1[], S2[], Evt>) => Effect<A, E, R>
646
+ ) => Effect<A, E, FixEnv<R, Evt, S1[], S2[]>>)
667
647
  & AllDSLExt<T, Evt>
668
648
 
669
649
  /**
@@ -671,11 +651,11 @@ export type AllDSL<T, Evt> =
671
651
  */
672
652
  export interface AllDSLExt<T, Evt> {
673
653
  modify: <R, E, A, S1 extends T, S2 extends T>(
674
- pure: (items: S1[], dsl: PureDSL<S1[], S2[], Evt>) => Effect<R, E, A>
675
- ) => Effect<FixEnv<R, Evt, S1[], S2[]>, E, A>
654
+ pure: (items: S1[], dsl: PureDSL<S1[], S2[], Evt>) => Effect<A, E, R>
655
+ ) => Effect<A, E, FixEnv<R, Evt, S1[], S2[]>>
676
656
  update: <R, E, S1 extends T, S2 extends T>(
677
- pure: (items: S1[], log: (...evt: Evt[]) => PureLogT<Evt>) => Effect<R, E, S2[]>
678
- ) => Effect<FixEnv<R, Evt, S1[], S2[]>, E, S2[]>
657
+ pure: (items: S1[], log: (...evt: Evt[]) => PureLogT<Evt>) => Effect<S2[], E, R>
658
+ ) => Effect<S2[], E, FixEnv<R, Evt, S1[], S2[]>>
679
659
  }
680
660
 
681
661
  export function makeAllDSL<T, Evt>() {
@@ -685,8 +665,8 @@ export function makeAllDSL<T, Evt>() {
685
665
 
686
666
  export type OneDSL<T, Evt> =
687
667
  & (<R, A, E, S1 extends T, S2 extends T>(
688
- pure: (dsl: PureDSL<S1, S2, Evt>) => Effect<FixEnv<R, Evt, S1, S2>, E, A>
689
- ) => Effect<FixEnv<R, Evt, S1, S2>, E, A>)
668
+ pure: (dsl: PureDSL<S1, S2, Evt>) => Effect<A, E, FixEnv<R, Evt, S1, S2>>
669
+ ) => Effect<A, E, FixEnv<R, Evt, S1, S2>>)
690
670
  & OneDSLExt<T, Evt>
691
671
 
692
672
  /**
@@ -694,11 +674,11 @@ export type OneDSL<T, Evt> =
694
674
  */
695
675
  export interface OneDSLExt<T, Evt> {
696
676
  modify: <R, E, A, S1 extends T, S2 extends T>(
697
- pure: (items: S1, dsl: PureDSL<S1, S2, Evt>) => Effect<FixEnv<R, Evt, S1, S2>, E, A>
698
- ) => Effect<FixEnv<R, Evt, S1, S2> | PureEnvEnv<Evt, S1, S1>, E, A>
677
+ pure: (items: S1, dsl: PureDSL<S1, S2, Evt>) => Effect<A, E, FixEnv<R, Evt, S1, S2>>
678
+ ) => Effect<A, E, FixEnv<R, Evt, S1, S2> | PureEnvEnv<Evt, S1, S1>>
699
679
  update: <R, E, S1 extends T, S2 extends T>(
700
- pure: (items: S1, log: (...evt: Evt[]) => PureLogT<Evt>) => Effect<FixEnv<R, Evt, S1, S2>, E, S2>
701
- ) => Effect<FixEnv<R, Evt, S1, S2>, E, S2>
680
+ pure: (items: S1, log: (...evt: Evt[]) => PureLogT<Evt>) => Effect<S2, E, FixEnv<R, Evt, S1, S2>>
681
+ ) => Effect<S2, E, FixEnv<R, Evt, S1, S2>>
702
682
  }
703
683
 
704
684
  /**
@@ -733,8 +713,8 @@ export function makeDSL<S1, S2, Evt>() {
733
713
  pure: (
734
714
  items: S1,
735
715
  dsl: PureDSL<S1, S2, Evt>
736
- ) => Effect<R, E, A>
737
- ): Effect<FixEnv<R, Evt, S1, S2>, E, A> {
716
+ ) => Effect<A, E, R>
717
+ ): Effect<A, E, FixEnv<R, Evt, S1, S2>> {
738
718
  return dsl.get.flatMap((items) => pure(items, dsl)) as any
739
719
  }
740
720
 
@@ -745,8 +725,8 @@ export function makeDSL<S1, S2, Evt>() {
745
725
  pure: (
746
726
  items: S1,
747
727
  log: (...evt: Evt[]) => PureLogT<Evt>
748
- ) => Effect<R, E, S2>
749
- ): Effect<FixEnv<R, Evt, S1, S2>, E, S2> {
728
+ ) => Effect<S2, E, R>
729
+ ): Effect<S2, E, FixEnv<R, Evt, S1, S2>> {
750
730
  return dsl.get.flatMap((items) => pure(items, dsl.log).tap(dsl.set)) as any
751
731
  }
752
732
 
@@ -755,8 +735,8 @@ export function makeDSL<S1, S2, Evt>() {
755
735
  A,
756
736
  E
757
737
  >(
758
- pure: (dsl: PureDSL<S1, S2, Evt>) => Effect<R, E, A>
759
- ): Effect<FixEnv<R, Evt, S1, S2>, E, A> {
738
+ pure: (dsl: PureDSL<S1, S2, Evt>) => Effect<A, E, R>
739
+ ): Effect<A, E, FixEnv<R, Evt, S1, S2>> {
760
740
  return pure(AnyPureDSL) as any
761
741
  }
762
742
 
@@ -771,14 +751,14 @@ export function makeDSL<S1, S2, Evt>() {
771
751
 
772
752
  export interface DSLExt<S1, S2, Evt> extends ReturnType<typeof makeDSL<S1, S2, Evt>> {}
773
753
 
774
- export function ifAny<T, R, E, A>(fn: (items: NonEmptyReadonlyArray<T>) => Effect<R, E, A>) {
754
+ export function ifAny<T, R, E, A>(fn: (items: NonEmptyReadonlyArray<T>) => Effect<A, E, R>) {
775
755
  return (items: Iterable<T>) => Effect.sync(() => items.toNonEmptyArray).flatMapOpt(fn)
776
756
  }
777
757
 
778
758
  /**
779
759
  * @tsplus fluent Iterable ifAny
780
760
  */
781
- export function ifAny_<T, R, E, A>(items: Iterable<T>, fn: (items: NonEmptyReadonlyArray<T>) => Effect<R, E, A>) {
761
+ export function ifAny_<T, R, E, A>(items: Iterable<T>, fn: (items: NonEmptyReadonlyArray<T>) => Effect<A, E, R>) {
782
762
  return Effect.sync(() => items.toNonEmptyArray).flatMapOpt(fn)
783
763
  }
784
764
 
@@ -23,15 +23,15 @@ export abstract class RepositoryBaseC<
23
23
  ItemType extends string
24
24
  > {
25
25
  abstract readonly itemType: ItemType
26
- abstract readonly find: (id: T["id"]) => Effect<never, never, Opt<T>>
27
- abstract readonly all: Effect<never, never, T[]>
26
+ abstract readonly find: (id: T["id"]) => Effect<Opt<T>>
27
+ abstract readonly all: Effect<T[]>
28
28
  abstract readonly saveAndPublish: (
29
29
  items: Iterable<T>,
30
30
  events?: Iterable<Evt>
31
- ) => Effect<never, InvalidStateError | OptimisticConcurrencyException, void>
31
+ ) => Effect<void, InvalidStateError | OptimisticConcurrencyException>
32
32
  abstract readonly utils: {
33
- parseMany: (a: readonly PM[]) => Effect<never, never, readonly T[]>
34
- all: Effect<never, never, PM[]>
33
+ parseMany: (a: readonly PM[]) => Effect<readonly T[]>
34
+ all: Effect<PM[]>
35
35
  filter: FilterFunc<PM>
36
36
  // count: (filter?: Filter<PM>) => Effect<never, never, NonNegativeInt>
37
37
  }
@@ -39,7 +39,7 @@ export abstract class RepositoryBaseC<
39
39
  abstract readonly removeAndPublish: (
40
40
  items: Iterable<T>,
41
41
  events?: Iterable<Evt>
42
- ) => Effect<never, never, void>
42
+ ) => Effect<void>
43
43
  }
44
44
 
45
45
  export abstract class RepositoryBaseC1<
@@ -91,7 +91,7 @@ export function makeRepo<
91
91
  T extends { id: unknown }
92
92
  >(
93
93
  name: ItemType,
94
- schema: S.Schema<R, From, T>,
94
+ schema: S.Schema<T, From, R>,
95
95
  mapFrom: (pm: Omit<PM, "_etag">) => From,
96
96
  mapTo: (e: From, etag: string | undefined) => PM
97
97
  ) => {
@@ -116,14 +116,14 @@ export function makeRepo<
116
116
 
117
117
  function make<RInitial = never, E = never, R2 = never>(
118
118
  args: [Evt] extends [never] ? {
119
- makeInitial?: Effect<RInitial, E, readonly T[]>
119
+ makeInitial?: Effect<readonly T[], E, RInitial>
120
120
  config?: Omit<StoreConfig<PM>, "partitionValue"> & {
121
121
  partitionValue?: (a: PM) => string
122
122
  }
123
123
  }
124
124
  : {
125
- publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect<R2, never, void>
126
- makeInitial?: Effect<RInitial, E, readonly T[]>
125
+ publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect<void, never, R2>
126
+ makeInitial?: Effect<readonly T[], E, RInitial>
127
127
  config?: Omit<StoreConfig<PM>, "partitionValue"> & {
128
128
  partitionValue?: (a: PM) => string
129
129
  }
@@ -161,19 +161,11 @@ export function makeRepo<
161
161
  _.ast._tag === "Union"
162
162
  // we need to get the TypeLiteral, incase of class it's behind a transform...
163
163
  ? S.union(..._.ast.types.map((_) =>
164
- (S.make(_._tag === "Transform" ? _.from : _) as unknown as Schema<
165
- never,
166
- From,
167
- T
168
- >)
164
+ (S.make(_._tag === "Transform" ? _.from : _) as unknown as Schema<T, From>)
169
165
  .pipe(S.pick("id"))
170
166
  ))
171
167
  : _.ast._tag === "Transform"
172
- ? (S.make(_.ast.from) as unknown as Schema<
173
- never,
174
- From,
175
- T
176
- >)
168
+ ? (S.make(_.ast.from) as unknown as Schema<T, From>)
177
169
  .pipe(S.pick("id"))
178
170
  : _.pipe(S.pick("id"))
179
171
  )
@@ -277,7 +269,7 @@ export function makeRepo<
277
269
  return r
278
270
  })
279
271
  // .withSpan("Repository.make [effect-app/infra]", { attributes: { "repository.model_name": name } })
280
- .withLogSpan("Repository.make: " + name)
272
+ .withLogSpan("Repository.make: " + name);
281
273
  }
282
274
 
283
275
  return {
@@ -285,7 +277,7 @@ export function makeRepo<
285
277
  where,
286
278
  query: QueryBuilder.make<PM>()
287
279
  }
288
- }
280
+ };
289
281
  }
290
282
 
291
283
  /**
@@ -346,7 +338,7 @@ export function makeStore<
346
338
  T extends { id: unknown }
347
339
  >(
348
340
  name: ItemType,
349
- schema: S.Schema<R, E, T>,
341
+ schema: S.Schema<T, E, R>,
350
342
  mapTo: (e: E, etag: string | undefined) => PM
351
343
  ) => {
352
344
  function encodeToPM() {
@@ -366,7 +358,7 @@ export function makeStore<
366
358
  }
367
359
 
368
360
  function makeStore<RInitial = never, EInitial = never>(
369
- makeInitial?: Effect<RInitial, EInitial, readonly T[]>,
361
+ makeInitial?: Effect<readonly T[], EInitial, RInitial>,
370
362
  config?: Omit<StoreConfig<PM>, "partitionValue"> & {
371
363
  partitionValue?: (a: PM) => string
372
364
  }
@@ -396,7 +388,7 @@ export function makeStore<
396
388
  }
397
389
 
398
390
  return makeStore
399
- }
391
+ };
400
392
  }
401
393
 
402
394
  export interface Repos<
@@ -408,43 +400,35 @@ export interface Repos<
408
400
  > {
409
401
  make<RInitial = never, E = never, R2 = never>(
410
402
  args: [Evt] extends [never] ? {
411
- makeInitial?: Effect<RInitial, E, readonly T[]>
403
+ makeInitial?: Effect<readonly T[], E, RInitial>
412
404
  config?: Omit<StoreConfig<PM>, "partitionValue"> & {
413
405
  partitionValue?: (a: PM) => string
414
406
  }
415
407
  }
416
408
  : {
417
- publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect<R2, never, void>
418
- makeInitial?: Effect<RInitial, E, readonly T[]>
409
+ publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect<void, never, R2>
410
+ makeInitial?: Effect<readonly T[], E, RInitial>
419
411
  config?: Omit<StoreConfig<PM>, "partitionValue"> & {
420
412
  partitionValue?: (a: PM) => string
421
413
  }
422
414
  }
423
- ): Effect<
424
- StoreMaker | ContextMapContainer | R | RInitial | R2,
425
- E,
426
- Repository<T, PM, Evt, ItemType>
427
- >
415
+ ): Effect<Repository<T, PM, Evt, ItemType>, E, StoreMaker | ContextMapContainer | R | RInitial | R2>
428
416
  makeWith<Out, RInitial = never, E = never, R2 = never>(
429
417
  args: [Evt] extends [never] ? {
430
- makeInitial?: Effect<RInitial, E, readonly T[]>
418
+ makeInitial?: Effect<readonly T[], E, RInitial>
431
419
  config?: Omit<StoreConfig<PM>, "partitionValue"> & {
432
420
  partitionValue?: (a: PM) => string
433
421
  }
434
422
  }
435
423
  : {
436
- publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect<R2, never, void>
437
- makeInitial?: Effect<RInitial, E, readonly T[]>
424
+ publishEvents: (evt: NonEmptyReadonlyArray<Evt>) => Effect<void, never, R2>
425
+ makeInitial?: Effect<readonly T[], E, RInitial>
438
426
  config?: Omit<StoreConfig<PM>, "partitionValue"> & {
439
427
  partitionValue?: (a: PM) => string
440
428
  }
441
429
  },
442
430
  f: (r: Repository<T, PM, Evt, ItemType>) => Out
443
- ): Effect<
444
- StoreMaker | ContextMapContainer | R | RInitial | R2,
445
- E,
446
- Out
447
- >
431
+ ): Effect<Out, E, StoreMaker | ContextMapContainer | R | RInitial | R2>
448
432
  /** @deprecated use `query` instead */
449
433
  readonly where: ReturnType<typeof makeWhere<PM>>
450
434
  readonly query: ReturnType<typeof QueryBuilder.make<PM>>
@@ -460,7 +444,7 @@ export const RepositoryBaseImpl = <Service>() => {
460
444
  >() =>
461
445
  <ItemType extends string, R, From extends { id: string }, T extends { id: unknown }>(
462
446
  itemType: ItemType,
463
- schema: S.Schema<R, From, T>,
447
+ schema: S.Schema<T, From, R>,
464
448
  jitM?: (pm: From) => From
465
449
  ): Exact<PM, From & { _etag: string | undefined }> extends true ?
466
450
  & (abstract new() => RepositoryBaseC1<T, PM, Evt, ItemType>)
@@ -492,7 +476,7 @@ export const RepositoryBaseImpl = <Service>() => {
492
476
  static readonly type: Repository<T, PM, Evt, ItemType> = undefined as any
493
477
  }
494
478
  return assignTag<Service>()(Cls) as any
495
- }
479
+ };
496
480
  }
497
481
 
498
482
  export const RepositoryDefaultImpl = <Service>() => {
@@ -502,7 +486,7 @@ export const RepositoryDefaultImpl = <Service>() => {
502
486
  >() =>
503
487
  <ItemType extends string, R, From extends { id: string }, T extends { id: unknown }>(
504
488
  itemType: ItemType,
505
- schema: S.Schema<R, From, T>,
489
+ schema: S.Schema<T, From, R>,
506
490
  jitM?: (pm: From) => From
507
491
  ): Exact<PM, From & { _etag: string | undefined }> extends true ?
508
492
  & (abstract new(
@@ -539,5 +523,5 @@ export const RepositoryDefaultImpl = <Service>() => {
539
523
  static readonly type: Repository<T, PM, Evt, ItemType> = undefined as any
540
524
  }
541
525
  return assignTag<Service>()(Cls) as any // impl is missing, but its marked protected
542
- }
526
+ };
543
527
  }