@effect-app/infra 0.133.0-next.9 → 0.133.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 (127) hide show
  1. package/CHANGELOG.md +485 -0
  2. package/_cjs/RequestContext.cjs +8 -9
  3. package/_cjs/RequestContext.cjs.map +1 -1
  4. package/_cjs/_ext/Array.cjs +4 -3
  5. package/_cjs/_ext/Array.cjs.map +1 -1
  6. package/_cjs/_global.ext.cjs +0 -25
  7. package/_cjs/_global.ext.cjs.map +1 -1
  8. package/_cjs/api/codec.cjs +1 -1
  9. package/_cjs/api/codec.cjs.map +1 -1
  10. package/_cjs/api/http.cjs +42 -0
  11. package/_cjs/api/http.cjs.map +1 -0
  12. package/_cjs/api/routing/base.cjs +169 -0
  13. package/_cjs/api/routing/base.cjs.map +1 -0
  14. package/_cjs/api/routing/defaultErrorHandler.cjs +50 -0
  15. package/_cjs/api/routing/defaultErrorHandler.cjs.map +1 -0
  16. package/_cjs/api/routing/makeRequestHandler.cjs +134 -0
  17. package/_cjs/api/routing/makeRequestHandler.cjs.map +1 -0
  18. package/_cjs/api/routing/match.cjs +45 -0
  19. package/_cjs/api/routing/match.cjs.map +1 -0
  20. package/_cjs/api/routing.cjs +50 -0
  21. package/_cjs/api/routing.cjs.map +1 -0
  22. package/_cjs/api/setupRequest.cjs +31 -30
  23. package/_cjs/api/setupRequest.cjs.map +1 -1
  24. package/_cjs/errorReporter.cjs +4 -2
  25. package/_cjs/errorReporter.cjs.map +1 -1
  26. package/_cjs/errors.cjs +18 -66
  27. package/_cjs/errors.cjs.map +1 -1
  28. package/_cjs/services/Operations/live.cjs +11 -12
  29. package/_cjs/services/Operations/live.cjs.map +1 -1
  30. package/_cjs/services/QueueMaker/memQueue.cjs +9 -10
  31. package/_cjs/services/QueueMaker/memQueue.cjs.map +1 -1
  32. package/_cjs/services/QueueMaker/sbqueue.cjs +4 -4
  33. package/_cjs/services/QueueMaker/sbqueue.cjs.map +1 -1
  34. package/_cjs/services/Repository.cjs +3 -3
  35. package/_cjs/services/Repository.cjs.map +1 -1
  36. package/_cjs/services/RepositoryBase.cjs +14 -6
  37. package/_cjs/services/RepositoryBase.cjs.map +1 -1
  38. package/_cjs/services/RequestContextContainer.cjs +3 -3
  39. package/_cjs/services/RequestContextContainer.cjs.map +1 -1
  40. package/_cjs/services/Store/Redis.cjs.map +1 -1
  41. package/_cjs/test.arbs.cjs +24 -1
  42. package/_cjs/test.arbs.cjs.map +1 -1
  43. package/_src/RequestContext.ts +9 -12
  44. package/_src/_ext/Array.ts +4 -4
  45. package/_src/_global.ext.ts +0 -23
  46. package/_src/api/codec.ts +1 -1
  47. package/_src/api/http.ts +26 -0
  48. package/_src/api/routing/base.ts +476 -0
  49. package/_src/api/routing/defaultErrorHandler.ts +83 -0
  50. package/_src/api/routing/makeRequestHandler.ts +278 -0
  51. package/_src/api/routing/match.ts +119 -0
  52. package/_src/api/routing.ts +11 -0
  53. package/_src/api/setupRequest.ts +39 -34
  54. package/_src/errorReporter.ts +4 -2
  55. package/_src/errors.ts +1 -58
  56. package/_src/services/QueueMaker/memQueue.ts +3 -3
  57. package/_src/services/QueueMaker/sbqueue.ts +3 -3
  58. package/_src/services/Repository.ts +40 -43
  59. package/_src/services/RepositoryBase.ts +26 -20
  60. package/_src/services/Store/Redis.ts +1 -1
  61. package/_src/services/Store/service.ts +4 -4
  62. package/_src/test.arbs.ts +17 -14
  63. package/dist/RequestContext.d.ts +72 -24
  64. package/dist/RequestContext.d.ts.map +1 -1
  65. package/dist/RequestContext.js +10 -11
  66. package/dist/_ext/Array.d.ts +2 -2
  67. package/dist/_ext/Array.d.ts.map +1 -1
  68. package/dist/_ext/Array.js +5 -4
  69. package/dist/_global.ext.d.ts +0 -22
  70. package/dist/_global.ext.d.ts.map +1 -1
  71. package/dist/_global.ext.js +1 -18
  72. package/dist/api/codec.d.ts +1 -1
  73. package/dist/api/codec.d.ts.map +1 -1
  74. package/dist/api/codec.js +2 -2
  75. package/dist/api/http.d.ts +16 -0
  76. package/dist/api/http.d.ts.map +1 -0
  77. package/dist/api/http.js +12 -0
  78. package/dist/api/routing/base.d.ts +117 -0
  79. package/dist/api/routing/base.d.ts.map +1 -0
  80. package/dist/api/routing/base.js +137 -0
  81. package/dist/api/routing/defaultErrorHandler.d.ts +16 -0
  82. package/dist/api/routing/defaultErrorHandler.d.ts.map +1 -0
  83. package/dist/api/routing/defaultErrorHandler.js +42 -0
  84. package/dist/api/routing/makeRequestHandler.d.ts +20 -0
  85. package/dist/api/routing/makeRequestHandler.d.ts.map +1 -0
  86. package/dist/api/routing/makeRequestHandler.js +121 -0
  87. package/dist/api/routing/match.d.ts +12 -0
  88. package/dist/api/routing/match.d.ts.map +1 -0
  89. package/dist/api/routing/match.js +31 -0
  90. package/dist/api/routing.d.ts +5 -0
  91. package/dist/api/routing.d.ts.map +1 -0
  92. package/dist/api/routing.js +8 -0
  93. package/dist/api/setupRequest.d.ts +4 -4
  94. package/dist/api/setupRequest.d.ts.map +1 -1
  95. package/dist/api/setupRequest.js +31 -37
  96. package/dist/errorReporter.d.ts.map +1 -1
  97. package/dist/errorReporter.js +5 -3
  98. package/dist/errors.d.ts +1 -81
  99. package/dist/errors.d.ts.map +1 -1
  100. package/dist/errors.js +4 -46
  101. package/dist/services/Operations/live.js +16 -17
  102. package/dist/services/QueueMaker/memQueue.d.ts +3 -3
  103. package/dist/services/QueueMaker/memQueue.d.ts.map +1 -1
  104. package/dist/services/QueueMaker/memQueue.js +9 -10
  105. package/dist/services/QueueMaker/sbqueue.d.ts +3 -3
  106. package/dist/services/QueueMaker/sbqueue.d.ts.map +1 -1
  107. package/dist/services/QueueMaker/sbqueue.js +4 -4
  108. package/dist/services/QueueMaker/service.d.ts +1 -1
  109. package/dist/services/Repository.d.ts +37 -38
  110. package/dist/services/Repository.d.ts.map +1 -1
  111. package/dist/services/Repository.js +4 -4
  112. package/dist/services/RepositoryBase.d.ts +15 -15
  113. package/dist/services/RepositoryBase.d.ts.map +1 -1
  114. package/dist/services/RepositoryBase.js +12 -7
  115. package/dist/services/RequestContextContainer.d.ts +1 -1
  116. package/dist/services/RequestContextContainer.js +3 -3
  117. package/dist/services/Store/Redis.js +1 -1
  118. package/dist/services/Store/service.d.ts +4 -4
  119. package/dist/services/Store/service.d.ts.map +1 -1
  120. package/dist/services/simpledb/redisdb.d.ts +5 -1
  121. package/dist/services/simpledb/redisdb.d.ts.map +1 -1
  122. package/dist/services/simpledb/shared.d.ts +5 -1
  123. package/dist/services/simpledb/shared.d.ts.map +1 -1
  124. package/dist/test.arbs.d.ts +12 -1
  125. package/dist/test.arbs.d.ts.map +1 -1
  126. package/dist/test.arbs.js +18 -2
  127. package/package.json +73 -11
@@ -3,7 +3,6 @@
3
3
  // Modify = Must `set` updated items, and can return anything.
4
4
  import type { FixEnv, PureLogT } from "@effect-app/prelude/Pure"
5
5
  import { Pure } from "@effect-app/prelude/Pure"
6
- import type { S } from "vitest/dist/reporters-O4LBziQ_.js"
7
6
  import type { InvalidStateError, OptimisticConcurrencyException } from "../errors.js"
8
7
  import { NotFoundError } from "../errors.js"
9
8
  import type { Filter, PersistenceModelType } from "../services/Store.js"
@@ -14,7 +13,7 @@ import type { QueryBuilder } from "./Store/filterApi/query.js"
14
13
  * @tsplus type Repository
15
14
  */
16
15
  export interface Repository<
17
- T extends { id: string },
16
+ T extends { id: unknown },
18
17
  PM extends PersistenceModelType<string>,
19
18
  Evt,
20
19
  ItemType extends string
@@ -36,7 +35,7 @@ export const AnyPureDSL: PureDSL<any, any, any> = {
36
35
  * @tsplus fluent Repository get
37
36
  */
38
37
  export function get<
39
- T extends { id: string },
38
+ T extends { id: unknown },
40
39
  PM extends PersistenceModelType<string>,
41
40
  Evt,
42
41
  ItemType extends string
@@ -44,14 +43,14 @@ export function get<
44
43
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
45
44
  id: T["id"]
46
45
  ) {
47
- return self.find(id).flatMap((_) => _.encaseInEffect(() => new NotFoundError({ type: self.itemType, id })))
46
+ return self.find(id).flatMap((_) => _.encaseInEffect(() => new NotFoundError<ItemType>({ type: self.itemType, id })))
48
47
  }
49
48
 
50
49
  /**
51
50
  * @tsplus getter Repository log
52
51
  */
53
52
  export function log<
54
- T extends { id: string },
53
+ T extends { id: unknown },
55
54
  PM extends PersistenceModelType<string>,
56
55
  Evt,
57
56
  ItemType extends string
@@ -64,7 +63,7 @@ export function log<
64
63
  * @tsplus fluent Repository projectEffect
65
64
  */
66
65
  export function projectEffect<
67
- T extends { id: string },
66
+ T extends { id: unknown },
68
67
  PM extends PersistenceModelType<string>,
69
68
  Evt,
70
69
  ItemType extends string,
@@ -85,13 +84,14 @@ export function projectEffect<
85
84
  >
86
85
  ): Effect<R, E, S[]>
87
86
  export function projectEffect<
88
- T extends { id: string },
87
+ T extends { id: unknown },
89
88
  PM extends PersistenceModelType<string>,
90
89
  Evt,
91
90
  ItemType extends string,
92
91
  R,
93
92
  E,
94
- U extends keyof PM
93
+ U extends keyof PM,
94
+ S = PM
95
95
  >(
96
96
  self: RepositoryBaseC<T, PM, Evt, ItemType>,
97
97
  map: Effect<
@@ -106,7 +106,7 @@ export function projectEffect<
106
106
  >
107
107
  ): Effect<R, E, Pick<PM, U>[]>
108
108
  export function projectEffect<
109
- T extends { id: string },
109
+ T extends { id: unknown },
110
110
  PM extends PersistenceModelType<string>,
111
111
  Evt,
112
112
  ItemType extends string,
@@ -142,7 +142,7 @@ export function projectEffect<
142
142
  * @tsplus fluent Repository project
143
143
  */
144
144
  export function project<
145
- T extends { id: string },
145
+ T extends { id: unknown },
146
146
  PM extends PersistenceModelType<string>,
147
147
  Evt,
148
148
  ItemType extends string,
@@ -157,7 +157,7 @@ export function project<
157
157
  }
158
158
  ): Effect<never, never, S[]>
159
159
  export function project<
160
- T extends { id: string },
160
+ T extends { id: unknown },
161
161
  PM extends PersistenceModelType<string>,
162
162
  Evt,
163
163
  ItemType extends string,
@@ -172,7 +172,7 @@ export function project<
172
172
  }
173
173
  ): Effect<never, never, Pick<PM, U>[]>
174
174
  export function project<
175
- T extends { id: string },
175
+ T extends { id: unknown },
176
176
  PM extends PersistenceModelType<string>,
177
177
  Evt,
178
178
  ItemType extends string,
@@ -196,7 +196,7 @@ export function project<
196
196
  * @tsplus fluent Repository project
197
197
  */
198
198
  export function count<
199
- T extends { id: string },
199
+ T extends { id: unknown },
200
200
  PM extends PersistenceModelType<string>,
201
201
  Evt,
202
202
  ItemType extends string
@@ -213,7 +213,7 @@ export function count<
213
213
  * @tsplus fluent Repository queryEffect
214
214
  */
215
215
  export function queryEffect<
216
- T extends { id: string },
216
+ T extends { id: unknown },
217
217
  PM extends PersistenceModelType<string>,
218
218
  Evt,
219
219
  ItemType extends string,
@@ -236,7 +236,7 @@ export function queryEffect<
236
236
  * @tsplus fluent Repository queryOneEffect
237
237
  */
238
238
  export function queryOneEffect<
239
- T extends { id: string },
239
+ T extends { id: unknown },
240
240
  PM extends PersistenceModelType<string>,
241
241
  Evt,
242
242
  ItemType extends string,
@@ -248,7 +248,7 @@ export function queryOneEffect<
248
248
  map: Effect<R, E, { filter?: Filter<PM> }>
249
249
  ): Effect<R, E | NotFoundError<ItemType>, T>
250
250
  export function queryOneEffect<
251
- T extends { id: string },
251
+ T extends { id: unknown },
252
252
  PM extends PersistenceModelType<string>,
253
253
  Evt,
254
254
  ItemType extends string,
@@ -261,7 +261,7 @@ export function queryOneEffect<
261
261
  map: Effect<R, E, { filter?: Filter<PM>; collect: (t: T) => Option<S> }>
262
262
  ): Effect<R, E | NotFoundError<ItemType>, S>
263
263
  export function queryOneEffect<
264
- T extends { id: string },
264
+ T extends { id: unknown },
265
265
  PM extends PersistenceModelType<string>,
266
266
  Evt,
267
267
  ItemType extends string,
@@ -279,7 +279,7 @@ export function queryOneEffect<
279
279
  .flatMap((_) =>
280
280
  (f.collect ? _.filterMap(f.collect) : _ as any as S[])
281
281
  .toNonEmpty
282
- .encaseInEffect(() => new NotFoundError({ type: self.itemType, id: JSON.stringify(f.filter) }))
282
+ .encaseInEffect(() => new NotFoundError<ItemType>({ type: self.itemType, id: f.filter }))
283
283
  .map((_) => _[0])
284
284
  )
285
285
  )
@@ -289,7 +289,7 @@ export function queryOneEffect<
289
289
  * @tsplus fluent Repository query
290
290
  */
291
291
  export function query<
292
- T extends { id: string },
292
+ T extends { id: unknown },
293
293
  PM extends PersistenceModelType<string>,
294
294
  Evt,
295
295
  ItemType extends string,
@@ -306,7 +306,7 @@ export function query<
306
306
  * @tsplus fluent Repository queryOne
307
307
  */
308
308
  export function queryOne<
309
- T extends { id: string },
309
+ T extends { id: unknown },
310
310
  PM extends PersistenceModelType<string>,
311
311
  Evt,
312
312
  ItemType extends string,
@@ -316,7 +316,7 @@ export function queryOne<
316
316
  map: { filter?: Filter<PM>; collect: (t: T) => Option<S> }
317
317
  ): Effect<never, NotFoundError<ItemType>, S>
318
318
  export function queryOne<
319
- T extends { id: string },
319
+ T extends { id: unknown },
320
320
  PM extends PersistenceModelType<string>,
321
321
  Evt,
322
322
  ItemType extends string
@@ -325,7 +325,7 @@ export function queryOne<
325
325
  map: { filter?: Filter<PM> }
326
326
  ): Effect<never, NotFoundError<ItemType>, T>
327
327
  export function queryOne<
328
- T extends { id: string },
328
+ T extends { id: unknown },
329
329
  PM extends PersistenceModelType<string>,
330
330
  Evt,
331
331
  ItemType extends string,
@@ -341,7 +341,7 @@ export function queryOne<
341
341
  * @tsplus fluent Repository queryAndSaveOnePureEffect
342
342
  */
343
343
  export function queryAndSaveOnePureEffect<
344
- T extends { id: string },
344
+ T extends { id: unknown },
345
345
  PM extends PersistenceModelType<string>,
346
346
  Evt,
347
347
  ItemType extends string,
@@ -360,7 +360,7 @@ export function queryAndSaveOnePureEffect<
360
360
  A
361
361
  >
362
362
  export function queryAndSaveOnePureEffect<
363
- T extends { id: string },
363
+ T extends { id: unknown },
364
364
  PM extends PersistenceModelType<string>,
365
365
  Evt,
366
366
  ItemType extends string,
@@ -391,7 +391,7 @@ export function queryAndSaveOnePureEffect(
391
391
  */
392
392
 
393
393
  export function queryAndSaveOnePure<
394
- T extends { id: string },
394
+ T extends { id: unknown },
395
395
  PM extends PersistenceModelType<string>,
396
396
  Evt,
397
397
  ItemType extends string,
@@ -407,7 +407,7 @@ export function queryAndSaveOnePure<
407
407
  A
408
408
  >
409
409
  export function queryAndSaveOnePure<
410
- T extends { id: string },
410
+ T extends { id: unknown },
411
411
  PM extends PersistenceModelType<string>,
412
412
  Evt,
413
413
  ItemType extends string
@@ -432,7 +432,7 @@ export function queryAndSaveOnePure(
432
432
  * @tsplus fluent Repository queryAndSavePureEffect
433
433
  */
434
434
  export function queryAndSavePureEffect<
435
- T extends { id: string },
435
+ T extends { id: unknown },
436
436
  PM extends PersistenceModelType<string>,
437
437
  Evt,
438
438
  ItemType extends string,
@@ -452,7 +452,7 @@ export function queryAndSavePureEffect<
452
452
  * @tsplus fluent Repository queryAndSavePure
453
453
  */
454
454
  export function queryAndSavePure<
455
- T extends { id: string },
455
+ T extends { id: unknown },
456
456
  PM extends PersistenceModelType<string>,
457
457
  Evt,
458
458
  ItemType extends string,
@@ -468,7 +468,7 @@ export function queryAndSavePure<
468
468
  * @tsplus getter Repository saveManyWithPure
469
469
  */
470
470
  export function saveManyWithPure<
471
- T extends { id: string },
471
+ T extends { id: unknown },
472
472
  PM extends PersistenceModelType<string>,
473
473
  Evt,
474
474
  ItemType extends string
@@ -481,7 +481,7 @@ export function saveManyWithPure<
481
481
  * @tsplus fluent Repository byIdAndSaveWithPure
482
482
  */
483
483
  export function byIdAndSaveWithPure<
484
- T extends { id: string },
484
+ T extends { id: unknown },
485
485
  PM extends PersistenceModelType<string>,
486
486
  Evt,
487
487
  ItemType extends string
@@ -495,7 +495,7 @@ export function byIdAndSaveWithPure<
495
495
  * @tsplus getter Repository handleByIdAndSaveWithPure
496
496
  */
497
497
  export function handleByIdAndSaveWithPure<
498
- T extends { id: string },
498
+ T extends { id: unknown },
499
499
  PM extends PersistenceModelType<string>,
500
500
  Evt,
501
501
  ItemType extends string
@@ -510,9 +510,8 @@ export function handleByIdAndSaveWithPure<
510
510
  * @tsplus fluent Repository saveManyWithPure_
511
511
  */
512
512
  export function saveManyWithPure_<
513
- Id extends string,
514
513
  R,
515
- T extends { id: Id },
514
+ T extends { id: unknown },
516
515
  PM extends PersistenceModelType<string>,
517
516
  A,
518
517
  E,
@@ -535,9 +534,8 @@ export function saveManyWithPure_<
535
534
  * @tsplus fluent Repository saveWithPure_
536
535
  */
537
536
  export function saveWithPure_<
538
- Id extends string,
539
537
  R,
540
- T extends { id: Id },
538
+ T extends { id: unknown },
541
539
  PM extends PersistenceModelType<string>,
542
540
  A,
543
541
  E,
@@ -559,7 +557,7 @@ export function saveWithPure_<
559
557
  }
560
558
 
561
559
  export function saveAllWithEffectInt<
562
- T extends { id: string },
560
+ T extends { id: unknown },
563
561
  PM extends PersistenceModelType<string>,
564
562
  P extends T,
565
563
  Evt,
@@ -581,7 +579,7 @@ export function saveAllWithEffectInt<
581
579
  * @tsplus fluent Repository queryAndSavePureEffectBatched
582
580
  */
583
581
  export function queryAndSavePureEffectBatched<
584
- T extends { id: string },
582
+ T extends { id: unknown },
585
583
  PM extends PersistenceModelType<string>,
586
584
  Evt,
587
585
  ItemType extends string,
@@ -603,7 +601,7 @@ export function queryAndSavePureEffectBatched<
603
601
  * @tsplus fluent Repository queryAndSavePureBatched
604
602
  */
605
603
  export function queryAndSavePureBatched<
606
- T extends { id: string },
604
+ T extends { id: unknown },
607
605
  PM extends PersistenceModelType<string>,
608
606
  Evt,
609
607
  ItemType extends string,
@@ -621,7 +619,7 @@ export function queryAndSavePureBatched<
621
619
  * @tsplus fluent Repository saveManyWithPureBatched
622
620
  */
623
621
  export function saveManyWithPureBatched<
624
- T extends { id: string },
622
+ T extends { id: unknown },
625
623
  PM extends PersistenceModelType<string>,
626
624
  Evt,
627
625
  ItemType extends string
@@ -634,9 +632,8 @@ export function saveManyWithPureBatched<
634
632
  * @tsplus fluent Repository saveManyWithPureBatched_
635
633
  */
636
634
  export function saveManyWithPureBatched_<
637
- Id extends string,
638
635
  R,
639
- T extends { id: Id },
636
+ T extends { id: unknown },
640
637
  PM extends PersistenceModelType<string>,
641
638
  A,
642
639
  E,
@@ -788,7 +785,7 @@ export function ifAny_<T, R, E, A>(items: Iterable<T>, fn: (items: NonEmptyReado
788
785
  * @tsplus getter Repository save
789
786
  */
790
787
  export function save<
791
- T extends { id: string },
788
+ T extends { id: unknown },
792
789
  PM extends PersistenceModelType<string>,
793
790
  Evt,
794
791
  ItemType extends string
@@ -802,7 +799,7 @@ export function save<
802
799
  * @tsplus getter Repository saveWithEvents
803
800
  */
804
801
  export function saveWithEvents<
805
- T extends { id: string },
802
+ T extends { id: unknown },
806
803
  PM extends PersistenceModelType<string>,
807
804
  Evt,
808
805
  ItemType extends string
@@ -9,7 +9,7 @@ import type {} from "effect/Hash"
9
9
  import type { Opt } from "@effect-app/core/Option"
10
10
  import { makeCodec } from "@effect-app/infra/api/codec"
11
11
  import { makeFilters } from "@effect-app/infra/filter"
12
- import type { Schema2 } from "@effect-app/prelude"
12
+ import { S } from "@effect-app/prelude"
13
13
  import type { InvalidStateError, OptimisticConcurrencyException } from "../errors.js"
14
14
  import { ContextMapContainer } from "./Store/ContextMapContainer.js"
15
15
  import { QueryBuilder } from "./Store/filterApi/query.js"
@@ -18,7 +18,7 @@ import { QueryBuilder } from "./Store/filterApi/query.js"
18
18
  * @tsplus type Repository
19
19
  */
20
20
  export abstract class RepositoryBaseC<
21
- T extends { id: string },
21
+ T extends { id: unknown },
22
22
  PM extends PersistenceModelType<string>,
23
23
  Evt,
24
24
  ItemType extends string
@@ -44,7 +44,7 @@ export abstract class RepositoryBaseC<
44
44
  }
45
45
 
46
46
  export abstract class RepositoryBaseC1<
47
- T extends { id: string },
47
+ T extends { id: unknown },
48
48
  PM extends PersistenceModelType<string>,
49
49
  Evt,
50
50
  ItemType extends string
@@ -57,7 +57,7 @@ export abstract class RepositoryBaseC1<
57
57
  }
58
58
 
59
59
  export class RepositoryBaseC2<
60
- T extends { id: string },
60
+ T extends { id: unknown },
61
61
  PM extends PersistenceModelType<string>,
62
62
  Evt,
63
63
  ItemType extends string
@@ -87,11 +87,11 @@ export function makeRepo<
87
87
  >() {
88
88
  return <
89
89
  ItemType extends string,
90
- T extends { id: string },
90
+ T extends { id: unknown },
91
91
  From extends { id: string }
92
92
  >(
93
93
  name: ItemType,
94
- schema: Schema2.Schema<From, T>,
94
+ schema: S.Schema<From, T>,
95
95
  mapFrom: (pm: Omit<PM, "_etag">) => From,
96
96
  mapTo: (e: From, etag: string | undefined) => PM
97
97
  ) => {
@@ -147,7 +147,10 @@ export function makeRepo<
147
147
 
148
148
  const all = allE.flatMap((_) => _.forEachEffect((_) => parse(_)))
149
149
 
150
- function findE(id: T["id"]) {
150
+ const structSchema = schema as unknown as { struct: typeof schema }
151
+ const i = ("struct" in structSchema ? structSchema["struct"] : schema).pipe(S.pick("id"))
152
+ function findE(_id: T["id"]) {
153
+ const { id } = i.encodeSync({ id: _id })
151
154
  return store
152
155
  .find(id)
153
156
  .flatMap((items) =>
@@ -172,6 +175,7 @@ export function makeRepo<
172
175
  ret.forEach((_) => set(_.id, _._etag))
173
176
  })
174
177
  )
178
+ .asUnit
175
179
  const encode = (i: T) => schema.encodeSync(i)
176
180
 
177
181
  const saveAll = (a: Iterable<T>) => saveAllE(a.toChunk.map(encode))
@@ -179,10 +183,12 @@ export function makeRepo<
179
183
  const saveAndPublish = (items: Iterable<T>, events: Iterable<Evt> = []) => {
180
184
  const it = items.toChunk
181
185
  return saveAll(it)
182
- > Effect(events.toNonEmptyArray)
183
- // TODO: for full consistency the events should be stored within the same database transaction, and then picked up.
184
- .flatMapOpt(pub)
185
- > changeFeed.publish([it.toArray, "save"])
186
+ .andThen(Effect(events.toNonEmptyArray))
187
+ // TODO: for full consistency the events should be stored within the same database transaction, and then picked up.
188
+ .flatMapOpt(pub)
189
+ .andThen(changeFeed
190
+ .publish([it.toArray, "save"]))
191
+ .asUnit
186
192
  }
187
193
 
188
194
  function removeAndPublish(a: Iterable<T>, events: Iterable<Evt> = []) {
@@ -205,7 +211,7 @@ export function makeRepo<
205
211
  })
206
212
  }
207
213
 
208
- const p = schema.parseSync
214
+ const p = schema.decodeSync
209
215
 
210
216
  const r: Repository<T, PM, Evt, ItemType> = {
211
217
  /**
@@ -249,7 +255,7 @@ export function makeRepo<
249
255
  * @tsplus fluent Repository removeById
250
256
  */
251
257
  export function removeById<
252
- T extends { id: string },
258
+ T extends { id: unknown },
253
259
  PM extends PersistenceModelType<string>,
254
260
  Evt,
255
261
  ItemType extends string
@@ -297,11 +303,11 @@ export function makeStore<
297
303
  >() {
298
304
  return <
299
305
  ItemType extends string,
300
- T extends { id: string },
306
+ T extends { id: unknown },
301
307
  E extends { id: string }
302
308
  >(
303
309
  name: ItemType,
304
- schema: Schema2.Schema<E, T>,
310
+ schema: S.Schema<E, T>,
305
311
  mapTo: (e: E, etag: string | undefined) => PM
306
312
  ) => {
307
313
  const [_dec, encode] = makeCodec(schema)
@@ -352,7 +358,7 @@ export function makeStore<
352
358
  }
353
359
 
354
360
  export interface Repos<
355
- T extends { id: string },
361
+ T extends { id: unknown },
356
362
  PM extends { id: string; _etag: string | undefined },
357
363
  Evt,
358
364
  ItemType extends string
@@ -409,9 +415,9 @@ export const RepositoryBaseImpl = <Service>() => {
409
415
  PM extends { id: string; _etag: string | undefined },
410
416
  Evt = never
411
417
  >() =>
412
- <ItemType extends string, T extends { id: string }, From extends { id: string }>(
418
+ <ItemType extends string, T extends { id: unknown }, From extends { id: string }>(
413
419
  itemType: ItemType,
414
- schema: Schema2.Schema<From, T>,
420
+ schema: S.Schema<From, T>,
415
421
  jitM?: (pm: From) => From
416
422
  ): Exact<PM, From & { _etag: string | undefined }> extends true ?
417
423
  & (abstract new() => RepositoryBaseC1<T, PM, Evt, ItemType>)
@@ -450,9 +456,9 @@ export const RepositoryDefaultImpl = <Service>() => {
450
456
  PM extends { id: string; _etag: string | undefined },
451
457
  Evt = never
452
458
  >() =>
453
- <ItemType extends string, T extends { id: string }, From extends { id: string }>(
459
+ <ItemType extends string, T extends { id: unknown }, From extends { id: string }>(
454
460
  itemType: ItemType,
455
- schema: Schema2.Schema<From, T>,
461
+ schema: S.Schema<From, T>,
456
462
  jitM?: (pm: From) => From
457
463
  ): Exact<PM, From & { _etag: string | undefined }> extends true ?
458
464
  & (abstract new(
@@ -30,7 +30,7 @@ function makeRedisStore({ prefix }: StorageConfig) {
30
30
  }
31
31
  const get = redis
32
32
  .get(key)
33
- .flatMap((x) => x.encaseInEffect(() => new NotFoundError({ type: "data", id: "" })))
33
+ .flatMap((x) => x.encaseInEffect(() => new NotFoundError<"data">({ type: "data", id: "" })))
34
34
  .orDie
35
35
  .map((x) => JSON.parse(x) as { data: readonly PM[] })
36
36
  .map((_) => _.data)
@@ -63,18 +63,18 @@ export type FilterJoinSelect = {
63
63
  value: any /* value path[valueKey] of E */
64
64
  }
65
65
 
66
- export interface FilterArgs<PM extends PersistenceModelType<string>, U extends keyof PM = never> {
66
+ export interface FilterArgs<PM extends PersistenceModelType<unknown>, U extends keyof PM = never> {
67
67
  filter?: Filter<PM> | undefined
68
68
  select?: NonEmptyReadonlyArray<U> | undefined
69
69
  limit?: number | undefined
70
70
  skip?: number | undefined
71
71
  }
72
72
 
73
- export type FilterFunc<PM extends PersistenceModelType<string>> = <U extends keyof PM = never>(
73
+ export type FilterFunc<PM extends PersistenceModelType<unknown>> = <U extends keyof PM = never>(
74
74
  args: FilterArgs<PM, U>
75
75
  ) => Effect<never, never, (U extends undefined ? PM : Pick<PM, U>)[]>
76
76
 
77
- export interface Store<PM extends PersistenceModelType<Id>, Id extends string> {
77
+ export interface Store<PM extends PersistenceModelType<Id>, Id> {
78
78
  all: Effect<never, never, PM[]>
79
79
  filter: FilterFunc<PM>
80
80
  /** @deprecated */
@@ -189,7 +189,7 @@ export class ContextMap extends TagClass<ContextMap, {
189
189
  }>() {
190
190
  }
191
191
 
192
- export interface PersistenceModelType<Id extends string> {
192
+ export interface PersistenceModelType<Id> {
193
193
  id: Id
194
194
  _etag: string | undefined
195
195
  }
package/_src/test.arbs.ts CHANGED
@@ -1,23 +1,26 @@
1
1
  // Do not import to frontend
2
2
 
3
3
  import { setFaker } from "@effect-app/prelude/faker"
4
+ import type { A } from "@effect-app/schema"
4
5
  import { faker } from "@faker-js/faker"
6
+ import { Random } from "fast-check"
7
+ import * as fc from "fast-check"
8
+ import * as rand from "pure-rand"
5
9
 
6
- // const rnd = new Random(rand.congruential32(5))
10
+ const rnd = new Random(rand.congruential32(5))
7
11
 
8
12
  setFaker(faker)
9
13
 
10
- // /**
11
- // * @tsplus getter FastCheck generate
12
- // */
13
- // export function generate<T>(arb: fc.Arbitrary<T>) {
14
- // return arb.generate(rnd, undefined)
15
- // }
14
+ /**
15
+ * @tsplus getter FastCheck generate
16
+ */
17
+ export function generate<T>(arb: fc.Arbitrary<T>) {
18
+ return arb.generate(rnd, undefined)
19
+ }
16
20
 
17
- // /**
18
- // * @tsplus getter ets/Schema/Arbitrary/Gen generate
19
- // */
20
-
21
- // export function generateFromArbitrary<T>(arb: Arbitrary.Gen<T>) {
22
- // return generate(arb(fc))
23
- // }
21
+ /**
22
+ * @tsplus getter effect/schema/Arbitrary generate
23
+ */
24
+ export function generateFromArbitrary<T>(arb: A.Arbitrary<T>) {
25
+ return generate(arb(fc))
26
+ }