@reventlessdev/reventless-postgres 3.0.0-alpha.3 → 3.0.0-alpha.5

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 (95) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/lib/bs/.compiler.log +2 -2
  3. package/lib/bs/ReventlessPostgres.cmi +0 -0
  4. package/lib/bs/ReventlessPostgres.cmt +0 -0
  5. package/lib/bs/ReventlessPostgres.mlmap +2 -0
  6. package/lib/bs/compiler-info.json +1 -1
  7. package/lib/bs/src/DcbEventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
  8. package/lib/bs/src/DcbEventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
  9. package/lib/bs/src/EventLogChangeFeed-ReventlessPostgres.cmi +0 -0
  10. package/lib/bs/src/EventLogChangeFeed-ReventlessPostgres.cmj +0 -0
  11. package/lib/bs/src/EventLogChangeFeed-ReventlessPostgres.cmt +0 -0
  12. package/lib/bs/src/EventLogChangeFeed.ast +0 -0
  13. package/lib/bs/src/EventLogChangeFeed.res +184 -0
  14. package/lib/bs/src/EventLogChangeFeed.res.mjs +134 -0
  15. package/lib/bs/src/EventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
  16. package/lib/bs/src/EventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
  17. package/lib/bs/src/PgChangeFeed-ReventlessPostgres.cmi +0 -0
  18. package/lib/bs/src/PgChangeFeed-ReventlessPostgres.cmt +0 -0
  19. package/lib/bs/src/PgSchema-ReventlessPostgres.cmi +0 -0
  20. package/lib/bs/src/PgSchema-ReventlessPostgres.cmt +0 -0
  21. package/lib/bs/src/PgSchema.ast +0 -0
  22. package/lib/bs/src/PgSchema.res +36 -2
  23. package/lib/bs/src/PgSchema.res.mjs +9 -2
  24. package/lib/bs/src/QueryDbStorage_Postgres-ReventlessPostgres.cmi +0 -0
  25. package/lib/bs/src/QueryDbStorage_Postgres-ReventlessPostgres.cmj +0 -0
  26. package/lib/bs/src/QueryDbStorage_Postgres-ReventlessPostgres.cmt +0 -0
  27. package/lib/bs/src/QueryDbStorage_Postgres.ast +0 -0
  28. package/lib/bs/src/QueryDbStorage_Postgres.res +35 -14
  29. package/lib/bs/src/QueryDbStorage_Postgres.res.mjs +23 -8
  30. package/lib/bs/src/QueryEnginePostgres-ReventlessPostgres.cmi +0 -0
  31. package/lib/bs/src/QueryEnginePostgres-ReventlessPostgres.cmt +0 -0
  32. package/lib/bs/src/QueryEnginePostgres.ast +0 -0
  33. package/lib/bs/src/QueryEnginePostgres.res +175 -0
  34. package/lib/bs/src/QueryEnginePostgres.res.mjs +91 -0
  35. package/lib/bs/tests/PostgresIntegrationTest-ReventlessPostgres.cmi +0 -0
  36. package/lib/bs/tests/PostgresIntegrationTest-ReventlessPostgres.cmt +0 -0
  37. package/lib/bs/tests/PostgresIntegrationTest.ast +0 -0
  38. package/lib/bs/tests/PostgresIntegrationTest.res +68 -0
  39. package/lib/bs/tests/PostgresIntegrationTest.res.mjs +49 -0
  40. package/lib/bs/tests/QueryEnginePostgresListPageTest-ReventlessPostgres.cmi +0 -0
  41. package/lib/bs/tests/QueryEnginePostgresListPageTest-ReventlessPostgres.cmj +0 -0
  42. package/lib/bs/tests/QueryEnginePostgresListPageTest-ReventlessPostgres.cmt +0 -0
  43. package/lib/bs/tests/QueryEnginePostgresListPageTest.ast +0 -0
  44. package/lib/bs/tests/QueryEnginePostgresListPageTest.res +236 -0
  45. package/lib/bs/tests/QueryEnginePostgresListPageTest.res.mjs +325 -0
  46. package/lib/ocaml/.compiler.log +2 -2
  47. package/lib/ocaml/DcbEventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
  48. package/lib/ocaml/DcbEventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
  49. package/lib/ocaml/EventLogChangeFeed-ReventlessPostgres.cmi +0 -0
  50. package/lib/ocaml/EventLogChangeFeed-ReventlessPostgres.cmj +0 -0
  51. package/lib/ocaml/EventLogChangeFeed-ReventlessPostgres.cmt +0 -0
  52. package/lib/ocaml/EventLogChangeFeed.ast +0 -0
  53. package/lib/ocaml/EventLogChangeFeed.res +184 -0
  54. package/lib/ocaml/EventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
  55. package/lib/ocaml/EventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
  56. package/lib/ocaml/PgChangeFeed-ReventlessPostgres.cmi +0 -0
  57. package/lib/ocaml/PgChangeFeed-ReventlessPostgres.cmt +0 -0
  58. package/lib/ocaml/PgSchema-ReventlessPostgres.cmi +0 -0
  59. package/lib/ocaml/PgSchema-ReventlessPostgres.cmt +0 -0
  60. package/lib/ocaml/PgSchema.ast +0 -0
  61. package/lib/ocaml/PgSchema.res +36 -2
  62. package/lib/ocaml/PostgresIntegrationTest-ReventlessPostgres.cmi +0 -0
  63. package/lib/ocaml/PostgresIntegrationTest-ReventlessPostgres.cmt +0 -0
  64. package/lib/ocaml/PostgresIntegrationTest.ast +0 -0
  65. package/lib/ocaml/PostgresIntegrationTest.res +68 -0
  66. package/lib/ocaml/QueryDbStorage_Postgres-ReventlessPostgres.cmi +0 -0
  67. package/lib/ocaml/QueryDbStorage_Postgres-ReventlessPostgres.cmj +0 -0
  68. package/lib/ocaml/QueryDbStorage_Postgres-ReventlessPostgres.cmt +0 -0
  69. package/lib/ocaml/QueryDbStorage_Postgres.ast +0 -0
  70. package/lib/ocaml/QueryDbStorage_Postgres.res +35 -14
  71. package/lib/ocaml/QueryEnginePostgres-ReventlessPostgres.cmi +0 -0
  72. package/lib/ocaml/QueryEnginePostgres-ReventlessPostgres.cmt +0 -0
  73. package/lib/ocaml/QueryEnginePostgres.ast +0 -0
  74. package/lib/ocaml/QueryEnginePostgres.res +175 -0
  75. package/lib/ocaml/QueryEnginePostgresListPageTest-ReventlessPostgres.cmi +0 -0
  76. package/lib/ocaml/QueryEnginePostgresListPageTest-ReventlessPostgres.cmj +0 -0
  77. package/lib/ocaml/QueryEnginePostgresListPageTest-ReventlessPostgres.cmt +0 -0
  78. package/lib/ocaml/QueryEnginePostgresListPageTest.ast +0 -0
  79. package/lib/ocaml/QueryEnginePostgresListPageTest.res +236 -0
  80. package/lib/ocaml/ReventlessPostgres.cmi +0 -0
  81. package/lib/ocaml/ReventlessPostgres.cmt +0 -0
  82. package/lib/ocaml/ReventlessPostgres.mlmap +2 -0
  83. package/package.json +7 -7
  84. package/src/EventLogChangeFeed.res +184 -0
  85. package/src/EventLogChangeFeed.res.mjs +134 -0
  86. package/src/PgSchema.res +36 -2
  87. package/src/PgSchema.res.mjs +9 -2
  88. package/src/QueryDbStorage_Postgres.res +35 -14
  89. package/src/QueryDbStorage_Postgres.res.mjs +23 -8
  90. package/src/QueryEnginePostgres.res +175 -0
  91. package/src/QueryEnginePostgres.res.mjs +91 -0
  92. package/tests/PostgresIntegrationTest.res +68 -0
  93. package/tests/PostgresIntegrationTest.res.mjs +49 -0
  94. package/tests/QueryEnginePostgresListPageTest.res +236 -0
  95. package/tests/QueryEnginePostgresListPageTest.res.mjs +325 -0
@@ -0,0 +1,236 @@
1
+ // Parity harness for the Postgres connection-list push-down (B3.2a-1).
2
+ //
3
+ // `QueryEnginePostgres.listPage` builds `item->>'field'` predicates + keyset
4
+ // WHERE + ORDER BY … LIMIT to serve a page without materialising the whole read
5
+ // model. Its result MUST equal `QueryDbListQuery.run` (the shared spec in
6
+ // reventless-core that the in-memory backend, the SQLite push-down, and the
7
+ // resolver fallback all use) for every shape it claims to handle. This is the
8
+ // Postgres twin of reventless-local's `QueryDbListPushdownParityTest` — same
9
+ // capability, same rows, same (data, args) matrix — so all three backends are
10
+ // held to one spec.
11
+ //
12
+ // Skipped unless PG_URL is set (like PostgresIntegrationTest), so the default
13
+ // `pnpm test` stays dependency-free. Run with e.g.:
14
+ // PG_URL=postgres://postgres:postgres@localhost:5432/postgres pnpm test
15
+
16
+ open JestGlobals
17
+ open ReventlessCore
18
+
19
+ @val external processEnv: dict<string> = "process.env"
20
+
21
+ let capability: GraphQL_FragmentGenerator.serverCapability = {
22
+ filterFields: [
23
+ {name: "status", gqlType: "String", range: false},
24
+ {name: "qty", gqlType: "Int", range: true},
25
+ ],
26
+ sortFields: ["name", "qty", "status"],
27
+ }
28
+
29
+ let mk = (id, status, name, qty) => {
30
+ let o = Dict.make()
31
+ o->Dict.set("id", JSON.Encode.string(id))
32
+ o->Dict.set("status", JSON.Encode.string(status))
33
+ o->Dict.set("name", JSON.Encode.string(name))
34
+ o->Dict.set("qty", JSON.Encode.int(qty))
35
+ JSON.Encode.object(o)
36
+ }
37
+
38
+ // Names differ from id-order; status has duplicates (tiebreak); qty exercises the
39
+ // numeric-field-as-string comparison the push-down must match.
40
+ let rows = [
41
+ ("p-1", "active", "Charlie", 3),
42
+ ("p-2", "active", "Alpha", 1),
43
+ ("p-3", "inactive", "Echo", 5),
44
+ ("p-4", "active", "Bravo", 2),
45
+ ("p-5", "inactive", "Delta", 4),
46
+ ]
47
+
48
+ // The exact items seeded, in memory — the spec runs over these (equivalent to a
49
+ // full scan of the table, since every save upserts one of these by id).
50
+ let seededItems = rows->Array.map(((id, status, name, qty)) => mk(id, status, name, qty))
51
+
52
+ // ── normalise a connection to a comparable value ────────────────────────────
53
+ type normEdge = {id: string, cursor: string}
54
+ type normConn = {
55
+ edges: array<normEdge>,
56
+ hasNext: bool,
57
+ hasPrev: bool,
58
+ startCursor: option<string>,
59
+ endCursor: option<string>,
60
+ }
61
+
62
+ let field = (j, k) => j->JSON.Decode.object->Option.flatMap(d => d->Dict.get(k))
63
+ let str = (j, k) => j->field(k)->Option.flatMap(JSON.Decode.string)
64
+
65
+ let norm = (conn: JSON.t): normConn => {
66
+ let edges =
67
+ conn
68
+ ->field("edges")
69
+ ->Option.flatMap(JSON.Decode.array)
70
+ ->Option.getOr([])
71
+ ->Array.map(e => {
72
+ id: e->field("node")->Option.flatMap(n => n->str("id"))->Option.getOr(""),
73
+ cursor: e->str("cursor")->Option.getOr(""),
74
+ })
75
+ let pi = conn->field("pageInfo")->Option.getOr(JSON.Encode.null)
76
+ {
77
+ edges,
78
+ hasNext: pi->field("hasNextPage")->Option.flatMap(JSON.Decode.bool)->Option.getOr(false),
79
+ hasPrev: pi->field("hasPreviousPage")->Option.flatMap(JSON.Decode.bool)->Option.getOr(false),
80
+ startCursor: pi->str("startCursor"),
81
+ endCursor: pi->str("endCursor"),
82
+ }
83
+ }
84
+
85
+ let argsOf = (entries: array<(string, JSON.t)>): dict<JSON.t> => Dict.fromArray(entries)
86
+ let filterOf = (entries: array<(string, JSON.t)>): JSON.t =>
87
+ JSON.Encode.object(Dict.fromArray(entries))
88
+ let orderBy = (f, dir) =>
89
+ JSON.Encode.object(
90
+ Dict.fromArray([("field", JSON.Encode.string(f)), ("direction", JSON.Encode.string(dir))]),
91
+ )
92
+ let cur = QueryDbListQuery.encodeCursor
93
+
94
+ let expectedFor = argsDict =>
95
+ QueryDbListQuery.run(
96
+ ~items=seededItems,
97
+ ~argsDict,
98
+ ~capability,
99
+ ~labelField="name",
100
+ ~decodeLocalId=_ => None,
101
+ )->norm
102
+
103
+ switch processEnv->Dict.get("PG_URL") {
104
+ | None =>
105
+ testSync("Postgres list push-down parity (skipped — set PG_URL to run)", () =>
106
+ expect(true)->toBe(true)
107
+ )
108
+ | Some(url) =>
109
+ let pool = PgDriver.makePool({connectionString: url})
110
+ module Eng = QueryEnginePostgres.Make({
111
+ let pool = pool
112
+ })
113
+ let name = "listparity"
114
+
115
+ // Seed via the real storage ops (upsert by id → table converges to the 5 rows).
116
+ beforeAllAsync(async () => {
117
+ let ops = QueryDbStorage_Postgres.makeOperations(~pool, ~name, ~indexes=[], ~subIdField=None)
118
+ for i in 0 to rows->Array.length - 1 {
119
+ let (id, status, nm, qty) = rows->Array.getUnsafe(i)
120
+ let _ = await ops.save(id, mk(id, status, nm, qty), QueryDb.Any, None)
121
+ }
122
+ })
123
+ afterAll(() => {
124
+ let _ = pool->PgDriver.endPool
125
+ })
126
+
127
+ // Assert the push-down serves this shape AND matches the spec exactly.
128
+ let checkPushed = async (~label, args) => {
129
+ let argsDict = argsOf(args)
130
+ switch await Eng.listPage(~readModelName=name, ~argsDict, ~capability, ~labelField="name") {
131
+ | Some(actual) => expect(actual->norm)->toEqual(expectedFor(argsDict))
132
+ | None => expect("push-down for " ++ label)->toBe("returned None")
133
+ }
134
+ }
135
+
136
+ // Assert the push-down declines this shape (resolver falls back to the spec).
137
+ let checkFallback = async args => {
138
+ let r = await Eng.listPage(~readModelName=name, ~argsDict=argsOf(args), ~capability, ~labelField="name")
139
+ expect(r->Option.isSome)->toBe(false)
140
+ }
141
+
142
+ describe("QueryDb list push-down parity (Postgres ≡ QueryDbListQuery spec)", () => {
143
+ testPromise("bare page", () => checkPushed(~label="bare", []))
144
+ testPromise("first:2", () => checkPushed(~label="first", [("first", JSON.Encode.int(2))]))
145
+ testPromise("first:2 + after", () =>
146
+ checkPushed(
147
+ ~label="after",
148
+ [("first", JSON.Encode.int(2)), ("after", JSON.Encode.string(cur("p-2")))],
149
+ )
150
+ )
151
+ testPromise("statusEq active", () =>
152
+ checkPushed(~label="eq", [("filter", filterOf([("statusEq", JSON.Encode.string("active"))]))])
153
+ )
154
+ testPromise("statusEq active + first:2", () =>
155
+ checkPushed(
156
+ ~label="eq+first",
157
+ [
158
+ ("filter", filterOf([("statusEq", JSON.Encode.string("active"))])),
159
+ ("first", JSON.Encode.int(2)),
160
+ ],
161
+ )
162
+ )
163
+ testPromise("orderBy name ASC", () =>
164
+ checkPushed(~label="order-asc", [("orderBy", orderBy("name", "ASC"))])
165
+ )
166
+ testPromise("orderBy name DESC", () =>
167
+ checkPushed(~label="order-desc", [("orderBy", orderBy("name", "DESC"))])
168
+ )
169
+ testPromise("orderBy name DESC + first:2 + after", () =>
170
+ checkPushed(
171
+ ~label="order-desc-after",
172
+ [
173
+ ("orderBy", orderBy("name", "DESC")),
174
+ ("first", JSON.Encode.int(2)),
175
+ ("after", JSON.Encode.string(cur("Delta"))),
176
+ ],
177
+ )
178
+ )
179
+ // status has duplicate values → exercises the id tiebreak in ORDER BY.
180
+ testPromise("orderBy status ASC (tiebreak by id)", () =>
181
+ checkPushed(~label="order-tiebreak", [("orderBy", orderBy("status", "ASC"))])
182
+ )
183
+ // qty is numeric → exercises `item->>'qty'` (text) vs Float.toString string parity.
184
+ testPromise("qty range From/To (numeric-as-string)", () =>
185
+ checkPushed(
186
+ ~label="range",
187
+ [
188
+ (
189
+ "filter",
190
+ filterOf([("qtyFrom", JSON.Encode.string("2")), ("qtyTo", JSON.Encode.string("4"))]),
191
+ ),
192
+ ],
193
+ )
194
+ )
195
+ testPromise("orderBy qty ASC (numeric-as-string sort)", () =>
196
+ checkPushed(~label="order-qty", [("orderBy", orderBy("qty", "ASC"))])
197
+ )
198
+
199
+ // Shapes the push-down declines → resolver uses the JS fallback.
200
+ testPromise("search → fallback", () =>
201
+ checkFallback([("filter", filterOf([("search", JSON.Encode.string("alp"))]))])
202
+ )
203
+ testPromise("searchPrefix → fallback", () =>
204
+ checkFallback([("filter", filterOf([("searchPrefix", JSON.Encode.string("A"))]))])
205
+ )
206
+ testPromise("ids → fallback", () =>
207
+ checkFallback([("filter", filterOf([("ids", JSON.Encode.array([JSON.Encode.string("p-1")]))]))])
208
+ )
209
+ testPromise("backward (last/before) → fallback", () =>
210
+ checkFallback([("last", JSON.Encode.int(2)), ("before", JSON.Encode.string(cur("p-4")))])
211
+ )
212
+ })
213
+
214
+ // ── indexLookup / byIds push-downs ────────────────────────────────────────
215
+ let idsOf = (items: array<JSON.t>): array<string> =>
216
+ items->Array.filterMap(i => i->str("id"))->Array.toSorted(String.compare)
217
+
218
+ describe("QueryEnginePostgres index / batch push-downs", () => {
219
+ testPromise("indexLookup by status = active", async () => {
220
+ let items = await Eng.indexLookup(~readModelName=name, "status", "active")
221
+ expect(items->idsOf)->toEqual(["p-1", "p-2", "p-4"])
222
+ })
223
+ testPromise("indexLookup miss → empty", async () => {
224
+ let items = await Eng.indexLookup(~readModelName=name, "status", "nope")
225
+ expect(items->Array.length)->toBe(0)
226
+ })
227
+ testPromise("byIds returns matches, drops missing", async () => {
228
+ let items = await Eng.byIds(~readModelName=name, ["p-1", "p-3", "absent"])
229
+ expect(items->idsOf)->toEqual(["p-1", "p-3"])
230
+ })
231
+ testPromise("byIds [] → empty (no query)", async () => {
232
+ let items = await Eng.byIds(~readModelName=name, [])
233
+ expect(items->Array.length)->toBe(0)
234
+ })
235
+ })
236
+ }
@@ -0,0 +1,325 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
4
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
5
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
6
+ import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
7
+ import * as PgDriver$ReventlessPostgres from "../src/PgDriver.res.mjs";
8
+ import * as QueryDbListQuery$ReventlessCore from "@reventlessdev/reventless-core/src/components/Api/QueryDbListQuery.res.mjs";
9
+ import * as QueryEnginePostgres$ReventlessPostgres from "../src/QueryEnginePostgres.res.mjs";
10
+ import * as QueryDbStorage_Postgres$ReventlessPostgres from "../src/QueryDbStorage_Postgres.res.mjs";
11
+
12
+ let capability_filterFields = [
13
+ {
14
+ name: "status",
15
+ gqlType: "String",
16
+ range: false
17
+ },
18
+ {
19
+ name: "qty",
20
+ gqlType: "Int",
21
+ range: true
22
+ }
23
+ ];
24
+
25
+ let capability_sortFields = [
26
+ "name",
27
+ "qty",
28
+ "status"
29
+ ];
30
+
31
+ let capability = {
32
+ filterFields: capability_filterFields,
33
+ sortFields: capability_sortFields
34
+ };
35
+
36
+ function mk(id, status, name, qty) {
37
+ let o = {};
38
+ o["id"] = id;
39
+ o["status"] = status;
40
+ o["name"] = name;
41
+ o["qty"] = qty;
42
+ return o;
43
+ }
44
+
45
+ let rows = [
46
+ [
47
+ "p-1",
48
+ "active",
49
+ "Charlie",
50
+ 3
51
+ ],
52
+ [
53
+ "p-2",
54
+ "active",
55
+ "Alpha",
56
+ 1
57
+ ],
58
+ [
59
+ "p-3",
60
+ "inactive",
61
+ "Echo",
62
+ 5
63
+ ],
64
+ [
65
+ "p-4",
66
+ "active",
67
+ "Bravo",
68
+ 2
69
+ ],
70
+ [
71
+ "p-5",
72
+ "inactive",
73
+ "Delta",
74
+ 4
75
+ ]
76
+ ];
77
+
78
+ let seededItems = rows.map(param => mk(param[0], param[1], param[2], param[3]));
79
+
80
+ function field(j, k) {
81
+ return Stdlib_Option.flatMap(Stdlib_JSON.Decode.object(j), d => d[k]);
82
+ }
83
+
84
+ function str(j, k) {
85
+ return Stdlib_Option.flatMap(field(j, k), Stdlib_JSON.Decode.string);
86
+ }
87
+
88
+ function norm(conn) {
89
+ let edges = Stdlib_Option.getOr(Stdlib_Option.flatMap(field(conn, "edges"), Stdlib_JSON.Decode.array), []).map(e => ({
90
+ id: Stdlib_Option.getOr(Stdlib_Option.flatMap(field(e, "node"), n => str(n, "id")), ""),
91
+ cursor: Stdlib_Option.getOr(str(e, "cursor"), "")
92
+ }));
93
+ let pi = Stdlib_Option.getOr(field(conn, "pageInfo"), null);
94
+ return {
95
+ edges: edges,
96
+ hasNext: Stdlib_Option.getOr(Stdlib_Option.flatMap(field(pi, "hasNextPage"), Stdlib_JSON.Decode.bool), false),
97
+ hasPrev: Stdlib_Option.getOr(Stdlib_Option.flatMap(field(pi, "hasPreviousPage"), Stdlib_JSON.Decode.bool), false),
98
+ startCursor: str(pi, "startCursor"),
99
+ endCursor: str(pi, "endCursor")
100
+ };
101
+ }
102
+
103
+ function argsOf(entries) {
104
+ return Object.fromEntries(entries);
105
+ }
106
+
107
+ function filterOf(entries) {
108
+ return Object.fromEntries(entries);
109
+ }
110
+
111
+ function orderBy(f, dir) {
112
+ return Object.fromEntries([
113
+ [
114
+ "field",
115
+ f
116
+ ],
117
+ [
118
+ "direction",
119
+ dir
120
+ ]
121
+ ]);
122
+ }
123
+
124
+ function expectedFor(argsDict) {
125
+ return norm(QueryDbListQuery$ReventlessCore.run(seededItems, argsDict, capability, "name", param => {}));
126
+ }
127
+
128
+ let url = process.env["PG_URL"];
129
+
130
+ if (url !== undefined) {
131
+ let pool = PgDriver$ReventlessPostgres.makePool({
132
+ connectionString: url
133
+ });
134
+ let Eng = QueryEnginePostgres$ReventlessPostgres.Make({
135
+ pool: pool
136
+ });
137
+ let name = "listparity";
138
+ globalThis.beforeAll(async () => {
139
+ let ops = QueryDbStorage_Postgres$ReventlessPostgres.makeOperations(pool, name, [], undefined);
140
+ for (let i = 0, i_finish = rows.length; i < i_finish; ++i) {
141
+ let match = rows[i];
142
+ let id = match[0];
143
+ await ops.save(id, mk(id, match[1], match[2], match[3]), "Any", undefined);
144
+ }
145
+ });
146
+ globalThis.afterAll(() => {
147
+ PgDriver$ReventlessPostgres.endPool(pool);
148
+ });
149
+ let checkPushed = async (label, args) => {
150
+ let argsDict = Object.fromEntries(args);
151
+ let actual = await Eng.listPage(name, argsDict, capability, "name");
152
+ if (actual !== undefined) {
153
+ globalThis.expect(norm(actual)).toEqual(expectedFor(argsDict));
154
+ } else {
155
+ globalThis.expect("push-down for " + label).toBe("returned None");
156
+ }
157
+ };
158
+ let checkFallback = async args => {
159
+ let r = await Eng.listPage(name, Object.fromEntries(args), capability, "name");
160
+ globalThis.expect(Stdlib_Option.isSome(r)).toBe(false);
161
+ };
162
+ globalThis.describe("QueryDb list push-down parity (Postgres ≡ QueryDbListQuery spec)", () => {
163
+ globalThis.test("bare page", () => checkPushed("bare", []));
164
+ globalThis.test("first:2", () => checkPushed("first", [[
165
+ "first",
166
+ 2
167
+ ]]));
168
+ globalThis.test("first:2 + after", () => checkPushed("after", [
169
+ [
170
+ "first",
171
+ 2
172
+ ],
173
+ [
174
+ "after",
175
+ QueryDbListQuery$ReventlessCore.encodeCursor("p-2")
176
+ ]
177
+ ]));
178
+ globalThis.test("statusEq active", () => checkPushed("eq", [[
179
+ "filter",
180
+ Object.fromEntries([[
181
+ "statusEq",
182
+ "active"
183
+ ]])
184
+ ]]));
185
+ globalThis.test("statusEq active + first:2", () => checkPushed("eq+first", [
186
+ [
187
+ "filter",
188
+ Object.fromEntries([[
189
+ "statusEq",
190
+ "active"
191
+ ]])
192
+ ],
193
+ [
194
+ "first",
195
+ 2
196
+ ]
197
+ ]));
198
+ globalThis.test("orderBy name ASC", () => checkPushed("order-asc", [[
199
+ "orderBy",
200
+ orderBy("name", "ASC")
201
+ ]]));
202
+ globalThis.test("orderBy name DESC", () => checkPushed("order-desc", [[
203
+ "orderBy",
204
+ orderBy("name", "DESC")
205
+ ]]));
206
+ globalThis.test("orderBy name DESC + first:2 + after", () => checkPushed("order-desc-after", [
207
+ [
208
+ "orderBy",
209
+ orderBy("name", "DESC")
210
+ ],
211
+ [
212
+ "first",
213
+ 2
214
+ ],
215
+ [
216
+ "after",
217
+ QueryDbListQuery$ReventlessCore.encodeCursor("Delta")
218
+ ]
219
+ ]));
220
+ globalThis.test("orderBy status ASC (tiebreak by id)", () => checkPushed("order-tiebreak", [[
221
+ "orderBy",
222
+ orderBy("status", "ASC")
223
+ ]]));
224
+ globalThis.test("qty range From/To (numeric-as-string)", () => checkPushed("range", [[
225
+ "filter",
226
+ Object.fromEntries([
227
+ [
228
+ "qtyFrom",
229
+ "2"
230
+ ],
231
+ [
232
+ "qtyTo",
233
+ "4"
234
+ ]
235
+ ])
236
+ ]]));
237
+ globalThis.test("orderBy qty ASC (numeric-as-string sort)", () => checkPushed("order-qty", [[
238
+ "orderBy",
239
+ orderBy("qty", "ASC")
240
+ ]]));
241
+ globalThis.test("search → fallback", () => checkFallback([[
242
+ "filter",
243
+ Object.fromEntries([[
244
+ "search",
245
+ "alp"
246
+ ]])
247
+ ]]));
248
+ globalThis.test("searchPrefix → fallback", () => checkFallback([[
249
+ "filter",
250
+ Object.fromEntries([[
251
+ "searchPrefix",
252
+ "A"
253
+ ]])
254
+ ]]));
255
+ globalThis.test("ids → fallback", () => checkFallback([[
256
+ "filter",
257
+ Object.fromEntries([[
258
+ "ids",
259
+ ["p-1"]
260
+ ]])
261
+ ]]));
262
+ globalThis.test("backward (last/before) → fallback", () => checkFallback([
263
+ [
264
+ "last",
265
+ 2
266
+ ],
267
+ [
268
+ "before",
269
+ QueryDbListQuery$ReventlessCore.encodeCursor("p-4")
270
+ ]
271
+ ]));
272
+ });
273
+ let idsOf = items => Stdlib_Array.filterMap(items, i => str(i, "id")).toSorted(Primitive_string.compare);
274
+ globalThis.describe("QueryEnginePostgres index / batch push-downs", () => {
275
+ globalThis.test("indexLookup by status = active", async () => {
276
+ let items = await Eng.indexLookup(name, "status", "active");
277
+ globalThis.expect(idsOf(items)).toEqual([
278
+ "p-1",
279
+ "p-2",
280
+ "p-4"
281
+ ]);
282
+ });
283
+ globalThis.test("indexLookup miss → empty", async () => {
284
+ let items = await Eng.indexLookup(name, "status", "nope");
285
+ globalThis.expect(items.length).toBe(0);
286
+ });
287
+ globalThis.test("byIds returns matches, drops missing", async () => {
288
+ let items = await Eng.byIds(name, [
289
+ "p-1",
290
+ "p-3",
291
+ "absent"
292
+ ]);
293
+ globalThis.expect(idsOf(items)).toEqual([
294
+ "p-1",
295
+ "p-3"
296
+ ]);
297
+ });
298
+ globalThis.test("byIds [] → empty (no query)", async () => {
299
+ let items = await Eng.byIds(name, []);
300
+ globalThis.expect(items.length).toBe(0);
301
+ });
302
+ });
303
+ } else {
304
+ globalThis.test("Postgres list push-down parity (skipped — set PG_URL to run)", () => {
305
+ globalThis.expect(true).toBe(true);
306
+ });
307
+ }
308
+
309
+ let cur = QueryDbListQuery$ReventlessCore.encodeCursor;
310
+
311
+ export {
312
+ capability,
313
+ mk,
314
+ rows,
315
+ seededItems,
316
+ field,
317
+ str,
318
+ norm,
319
+ argsOf,
320
+ filterOf,
321
+ orderBy,
322
+ cur,
323
+ expectedFor,
324
+ }
325
+ /* seededItems Not a pure module */
@@ -1,2 +1,2 @@
1
- #Start(1783258950748)
2
- #Done(1783258952632)
1
+ #Start(1783298008858)
2
+ #Done(1783298010813)
Binary file