@effect-app/infra 4.0.0-beta.292 → 4.0.0-beta.294

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @effect-app/infra
2
2
 
3
+ ## 4.0.0-beta.294
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a211c12]
8
+ - effect-app@4.0.0-beta.294
9
+
10
+ ## 4.0.0-beta.293
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [d1c15d3]
15
+ - effect-app@4.0.0-beta.293
16
+
3
17
  ## 4.0.0-beta.292
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/infra",
3
- "version": "4.0.0-beta.292",
3
+ "version": "4.0.0-beta.294",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "dependencies": {
@@ -10,7 +10,7 @@
10
10
  "proper-lockfile": "^4.1.2",
11
11
  "pure-rand": "8.4.0",
12
12
  "query-string": "^9.4.0",
13
- "effect-app": "4.0.0-beta.292"
13
+ "effect-app": "4.0.0-beta.294"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@azure/cosmos": "^4.9.3",
@@ -629,6 +629,7 @@ it("projectComputed validates extra computed keys", () => {
629
629
  const query = make<S.Codec.Encoded<typeof baseSchema>>().pipe(
630
630
  projectComputed(
631
631
  S.Struct({ id: S.String }),
632
+ // @ts-expect-error extra computed keys are rejected statically; keep runtime guard covered
632
633
  computed({
633
634
  pickedCount: relation<S.Codec.Encoded<typeof baseSchema>>("items").count()
634
635
  })
@@ -637,12 +638,116 @@ it("projectComputed validates extra computed keys", () => {
637
638
  expect(() => toFilter(query, baseSchema)).toThrowError("Computed projection keys must exist in projection schema")
638
639
  })
639
640
 
641
+ it("projectComputed constrains projection schema to encoded repo fields and computed outputs", () => {
642
+ const baseSchema = S.Struct({
643
+ id: S.String,
644
+ name: S.String,
645
+ items: S.Array(S.Struct({ articleId: S.String, weight: S.Number }))
646
+ })
647
+ type Encoded = S.Codec.Encoded<typeof baseSchema>
648
+
649
+ make<Encoded>().pipe(
650
+ projectComputed(
651
+ S.Struct({
652
+ id: S.String,
653
+ itemCount: S.Number,
654
+ hasItems: S.Boolean,
655
+ articleIds: S.Array(S.String)
656
+ }),
657
+ ({ relation }) => ({
658
+ itemCount: relation("items").count(),
659
+ hasItems: relation("items").any(),
660
+ articleIds: relation("items").collect("articleId")
661
+ })
662
+ )
663
+ )
664
+
665
+ make<Encoded>().pipe(
666
+ // @ts-expect-error missingField is neither an encoded repo field nor a computed projection
667
+ projectComputed(S.Struct({ missingField: S.String }), computed({}))
668
+ )
669
+
670
+ make<Encoded>().pipe(
671
+ projectComputed(
672
+ // @ts-expect-error repo field name is encoded as string
673
+ S.Struct({ name: S.Number }),
674
+ computed({})
675
+ )
676
+ )
677
+
678
+ make<Encoded>().pipe(
679
+ projectComputed(
680
+ // @ts-expect-error itemCount computes a number
681
+ S.Struct({ itemCount: S.String }),
682
+ computed({ itemCount: relation<Encoded>("items").count() })
683
+ )
684
+ )
685
+
686
+ make<Encoded>().pipe(
687
+ projectComputed(
688
+ S.Struct({ itemCount: S.Number }),
689
+ // @ts-expect-error extra computed keys must exist in the projection schema
690
+ computed({
691
+ itemCount: relation<Encoded>("items").count(),
692
+ extraCount: relation<Encoded>("items").count()
693
+ })
694
+ )
695
+ )
696
+ })
697
+
698
+ it("projectComputed supports union projection schemas", () => {
699
+ const baseSchema = S.Union([
700
+ S.Struct({
701
+ _tag: S.Literal("open"),
702
+ id: S.String,
703
+ items: S.Array(S.Struct({ articleId: S.String, weight: S.Number }))
704
+ }),
705
+ S.Struct({
706
+ _tag: S.Literal("closed"),
707
+ id: S.String,
708
+ closedAt: S.String
709
+ })
710
+ ])
711
+ type Encoded = S.Codec.Encoded<typeof baseSchema>
712
+ const query = make<Encoded>().pipe(
713
+ projectComputed(
714
+ S.Union([
715
+ S.Struct({
716
+ _tag: S.Literal("open"),
717
+ id: S.String,
718
+ articleCount: S.Number,
719
+ weight: S.Number,
720
+ articleIds: S.Array(S.String)
721
+ }),
722
+ S.Struct({
723
+ _tag: S.Literal("closed"),
724
+ id: S.String,
725
+ closedAt: S.String
726
+ })
727
+ ]),
728
+ computed({
729
+ articleCount: relation<Encoded>("items").count(),
730
+ weight: relation<Encoded>("items").sum("weight"),
731
+ articleIds: relation<Encoded>("items").collect("articleId")
732
+ })
733
+ )
734
+ )
735
+
736
+ const interpreted = toFilter(query, baseSchema)
737
+ expect(interpreted.computed && Object.keys(interpreted.computed).toSorted()).toEqual([
738
+ "articleCount",
739
+ "articleIds",
740
+ "weight"
741
+ ])
742
+ })
743
+
640
744
  it("projection schema with computed fields fails without computed map", () => {
641
745
  const baseSchema = S.Struct({
642
746
  id: S.String,
643
747
  items: S.Array(S.Struct({ value: S.Number }))
644
748
  })
645
749
  const query = make<S.Codec.Encoded<typeof baseSchema>>().pipe(
750
+ // @ts-expect-error missing computed keys are rejected statically; keep runtime guard covered
646
751
  projectComputed(S.Struct({ pickedCount: S.NonNegativeInt }), computed({}))
647
752
  )
648
753
  expect(() => toFilter(query, baseSchema)).toThrowError("Missing computed projections for schema keys")
@@ -1764,6 +1869,7 @@ it("memFilter: rejects extra computed keys not in projection schema", () => {
1764
1869
  const q = make<ComputedBase>().pipe(
1765
1870
  projectComputed(
1766
1871
  S.Struct({ id: S.String }),
1872
+ // @ts-expect-error extra computed keys are rejected statically; keep runtime guard covered
1767
1873
  computed({
1768
1874
  bogus: relation<ComputedBase>("items").count(where("tag", "a"))
1769
1875
  })