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

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,20 @@
1
1
  # @effect-app/infra
2
2
 
3
+ ## 4.0.0-beta.296
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [e0c4835]
8
+ - effect-app@4.0.0-beta.296
9
+
10
+ ## 4.0.0-beta.295
11
+
12
+ ### Patch Changes
13
+
14
+ - eb06b32: improve root union select
15
+ - Updated dependencies [eb06b32]
16
+ - effect-app@4.0.0-beta.295
17
+
3
18
  ## 4.0.0-beta.294
4
19
 
5
20
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/infra",
3
- "version": "4.0.0-beta.294",
3
+ "version": "4.0.0-beta.296",
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.294"
13
+ "effect-app": "4.0.0-beta.296"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@azure/cosmos": "^4.9.3",
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { and, computed, make, projectComputed, relation, toFilter, where } from "effect-app/Model/query"
2
+ import { and, computed, make, project, projectComputed, relation, toFilter, where } from "effect-app/Model/query"
3
3
  import * as S from "effect-app/Schema"
4
4
  import { describe, expect, it } from "vitest"
5
5
  import { buildWhereCosmosQuery3 } from "../src/Store/Cosmos/query.js"
@@ -40,6 +40,75 @@ describe("cosmos query projection: array length", () => {
40
40
  })
41
41
  })
42
42
 
43
+ describe("cosmos query projection: union array fields", () => {
44
+ const PackageView = S.Array(S.Struct({ carrier: S.String }))
45
+
46
+ class UnionOrder extends S.Class<UnionOrder>("UnionOrder")({
47
+ id: S.String,
48
+ _tag: S.Literals(["picked", "packed"]),
49
+ packages: PackageView
50
+ }) {}
51
+
52
+ type UnionOrderEnc = S.Codec.Encoded<typeof UnionOrder>
53
+
54
+ const ProjectProjection = S.Union([
55
+ S.TaggedStruct("picked", {
56
+ id: S.String,
57
+ packages: PackageView
58
+ }),
59
+ S.TaggedStruct("packed", {
60
+ id: S.String,
61
+ packages: PackageView
62
+ })
63
+ ])
64
+
65
+ const ComputedProjection = S.Union([
66
+ S.TaggedStruct("picked", {
67
+ id: S.String,
68
+ packages: PackageView,
69
+ packageCount: S.NonNegativeInt
70
+ }),
71
+ S.TaggedStruct("packed", {
72
+ id: S.String,
73
+ packages: PackageView,
74
+ packageCount: S.NonNegativeInt
75
+ })
76
+ ])
77
+
78
+ it("dedupes array selects for project union schemas", () => {
79
+ const q = make<UnionOrderEnc>().pipe(project(ProjectProjection))
80
+
81
+ const ir = toFilter(q as any, UnionOrder as any)
82
+ const select: readonly unknown[] = ir.select ?? []
83
+ const packageSelects = select.filter((item) =>
84
+ typeof item === "object" && item !== null && "key" in item && item.key === "packages"
85
+ )
86
+ const result = buildWhereCosmosQuery3("id", ir.filter ?? [], "Orders", {}, ir.select as any)
87
+
88
+ expect(packageSelects).toHaveLength(1)
89
+ expect(result.query.match(/\bAS\s+packages\b/g) ?? []).toHaveLength(1)
90
+ })
91
+
92
+ it("dedupes array selects for projectComputed union schemas", () => {
93
+ const q = make<UnionOrderEnc>().pipe(
94
+ projectComputed(
95
+ ComputedProjection,
96
+ computed({ packageCount: relation<UnionOrderEnc>("packages").length() })
97
+ )
98
+ )
99
+
100
+ const ir = toFilter(q as any, UnionOrder as any)
101
+ const select: readonly unknown[] = ir.select ?? []
102
+ const packageSelects = select.filter((item) =>
103
+ typeof item === "object" && item !== null && "key" in item && item.key === "packages"
104
+ )
105
+ const result = buildWhereCosmosQuery3("id", ir.filter ?? [], "Orders", {}, ir.select as any)
106
+
107
+ expect(packageSelects).toHaveLength(1)
108
+ expect(result.query.match(/\bAS\s+packages\b/g) ?? []).toHaveLength(1)
109
+ })
110
+ })
111
+
43
112
  // Regression: `relation-every` previously walked its filter twice (once for the
44
113
  // shared `where` variable, once for the NOT-EXISTS branch), double-bumping the
45
114
  // shared `i` counter and shifting every subsequent @v index against the bound