@reventlessdev/reventless-postgres 3.0.0-alpha.15 → 3.0.0-alpha.151
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 +1093 -0
- package/README.md +83 -0
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/ReventlessPostgres.cmt +0 -0
- package/lib/bs/ReventlessPostgres.mlmap +0 -2
- package/lib/bs/compiler-info.json +4 -4
- package/lib/bs/src/DcbEventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres.ast +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres.res +1 -1
- package/lib/bs/src/DcbEventLogStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres_Ops.ast +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres_Ops.res +43 -42
- package/lib/bs/src/DcbEventLogStorage_Postgres_Ops.res.mjs +4 -4
- package/lib/bs/src/EventLogChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/EventLogChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/EventLogChangeFeed.ast +0 -0
- package/lib/bs/src/EventLogChangeFeed.res +15 -6
- package/lib/bs/src/EventLogChangeFeed.res.mjs +3 -3
- package/lib/bs/src/EventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/EventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/EventLogStorage_Postgres.ast +0 -0
- package/lib/bs/src/EventLogStorage_Postgres.res +1 -1
- package/lib/bs/src/EventLogStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/EventLogStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/EventLogStorage_Postgres_Ops.ast +0 -0
- package/lib/bs/src/EventLogStorage_Postgres_Ops.res +24 -14
- package/lib/bs/src/PgChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/PgChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/PgChangeFeed.ast +0 -0
- package/lib/bs/src/PgChangeFeed.res +21 -9
- package/lib/bs/src/PgChangeFeed.res.mjs +6 -6
- package/lib/bs/src/PgDriver-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/PgDriver-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/PgDriver-ReventlessPostgres.cmti +0 -0
- package/lib/bs/src/PgDriver.ast +0 -0
- package/lib/bs/src/PgDriver.iast +0 -0
- package/lib/bs/src/PgDriver.res +1 -2
- package/lib/bs/src/PgSchema-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/PgSchema-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/PgSchema.ast +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres.ast +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres.res +7 -2
- package/lib/bs/src/QueryDbStorage_Postgres.res.mjs +1 -1
- package/lib/bs/src/QueryDbStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres_Ops.ast +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres_Ops.res +14 -14
- package/lib/bs/src/QueryEnginePostgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/QueryEnginePostgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/QueryEnginePostgres.ast +0 -0
- package/lib/bs/src/QueryEnginePostgres.res +141 -42
- package/lib/bs/src/QueryEnginePostgres.res.mjs +53 -30
- package/lib/bs/tests/PostgresIntegrationTest-ReventlessPostgres.cmi +0 -0
- package/lib/bs/tests/PostgresIntegrationTest-ReventlessPostgres.cmt +0 -0
- package/lib/bs/tests/PostgresIntegrationTest.ast +0 -0
- package/lib/bs/tests/PostgresIntegrationTest.res +157 -104
- package/lib/bs/tests/QueryEnginePostgresListPageTest-ReventlessPostgres.cmi +0 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest-ReventlessPostgres.cmt +0 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest.ast +0 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest.res +29 -6
- package/lib/bs/tests/QueryEnginePostgresListPageTest.res.mjs +4 -4
- package/lib/ocaml/.compiler.log +2 -2
- package/lib/ocaml/DcbEventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres.ast +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres.res +1 -1
- package/lib/ocaml/DcbEventLogStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres_Ops.ast +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres_Ops.res +43 -42
- package/lib/ocaml/EventLogChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/EventLogChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/EventLogChangeFeed.ast +0 -0
- package/lib/ocaml/EventLogChangeFeed.res +15 -6
- package/lib/ocaml/EventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/EventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/EventLogStorage_Postgres.ast +0 -0
- package/lib/ocaml/EventLogStorage_Postgres.res +1 -1
- package/lib/ocaml/EventLogStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/EventLogStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/EventLogStorage_Postgres_Ops.ast +0 -0
- package/lib/ocaml/EventLogStorage_Postgres_Ops.res +24 -14
- package/lib/ocaml/PgChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/PgChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/PgChangeFeed.ast +0 -0
- package/lib/ocaml/PgChangeFeed.res +21 -9
- package/lib/ocaml/PgDriver-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/PgDriver-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/PgDriver-ReventlessPostgres.cmti +0 -0
- package/lib/ocaml/PgDriver.ast +0 -0
- package/lib/ocaml/PgDriver.iast +0 -0
- package/lib/ocaml/PgDriver.res +1 -2
- package/lib/ocaml/PgSchema-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/PgSchema-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/PgSchema.ast +0 -0
- package/lib/ocaml/PostgresIntegrationTest.res +157 -104
- package/lib/ocaml/QueryDbStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres.ast +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres.res +7 -2
- package/lib/ocaml/QueryDbStorage_Postgres_Ops-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres_Ops-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres_Ops.ast +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres_Ops.res +14 -14
- package/lib/ocaml/QueryEnginePostgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/QueryEnginePostgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/QueryEnginePostgres.ast +0 -0
- package/lib/ocaml/QueryEnginePostgres.res +141 -42
- package/lib/ocaml/QueryEnginePostgresListPageTest.res +29 -6
- package/lib/ocaml/ReventlessPostgres.cmt +0 -0
- package/package.json +13 -13
- package/rescript.json +2 -1
- package/src/DcbEventLogStorage_Postgres.res +1 -1
- package/src/DcbEventLogStorage_Postgres_Ops.res +43 -42
- package/src/DcbEventLogStorage_Postgres_Ops.res.mjs +4 -4
- package/src/EventLogChangeFeed.res +15 -6
- package/src/EventLogChangeFeed.res.mjs +3 -3
- package/src/EventLogStorage_Postgres.res +1 -1
- package/src/EventLogStorage_Postgres_Ops.res +24 -14
- package/src/PgChangeFeed.res +21 -9
- package/src/PgChangeFeed.res.mjs +6 -6
- package/src/PgDriver.res +1 -2
- package/src/QueryDbStorage_Postgres.res +7 -2
- package/src/QueryDbStorage_Postgres.res.mjs +1 -1
- package/src/QueryDbStorage_Postgres_Ops.res +14 -14
- package/src/QueryEnginePostgres.res +141 -42
- package/src/QueryEnginePostgres.res.mjs +53 -30
- package/tests/PostgresIntegrationTest.res +157 -104
- package/tests/QueryEnginePostgresListPageTest.res +29 -6
- package/lib/ocaml/PostgresIntegrationTest-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/PostgresIntegrationTest-ReventlessPostgres.cmj +0 -0
- package/lib/ocaml/PostgresIntegrationTest-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/PostgresIntegrationTest.ast +0 -0
- package/lib/ocaml/QueryEnginePostgresListPageTest-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/QueryEnginePostgresListPageTest-ReventlessPostgres.cmj +0 -0
- package/lib/ocaml/QueryEnginePostgresListPageTest-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/QueryEnginePostgresListPageTest.ast +0 -0
- package/tests/PostgresIntegrationTest.res.mjs +0 -377
- package/tests/QueryEnginePostgresListPageTest.res.mjs +0 -461
|
@@ -28,7 +28,12 @@ let param = (b: paramBuilder, v: JSON.t): string => {
|
|
|
28
28
|
let col = (field: string): string => `(item->>'${field->String.replaceAll("'", "''")}')`
|
|
29
29
|
|
|
30
30
|
// One Filter.config → SQL predicate, appending any bound params.
|
|
31
|
-
let filterSql = (
|
|
31
|
+
let filterSql = (
|
|
32
|
+
b: paramBuilder,
|
|
33
|
+
field: string,
|
|
34
|
+
cmp: QueryEngine.Filter.comparator,
|
|
35
|
+
v: QueryEngine.value,
|
|
36
|
+
): string => {
|
|
32
37
|
let c = col(field)
|
|
33
38
|
let bind = () => b->param(JSON.Encode.string(valueToText(v)))
|
|
34
39
|
let cmpSql = op =>
|
|
@@ -48,10 +53,16 @@ let filterSql = (b: paramBuilder, field: string, cmp: QueryEngine.Filter.compara
|
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
let subIdSql = (
|
|
56
|
+
let subIdSql = (
|
|
57
|
+
b: paramBuilder,
|
|
58
|
+
field: string,
|
|
59
|
+
cmp: QueryEngine.SubId.comparator,
|
|
60
|
+
v: QueryEngine.value,
|
|
61
|
+
): string => {
|
|
52
62
|
let c = col(field)
|
|
53
63
|
let bind = () => b->param(JSON.Encode.string(valueToText(v)))
|
|
54
|
-
let cmpSql = op =>
|
|
64
|
+
let cmpSql = op =>
|
|
65
|
+
isNumeric(v) ? `${c}::numeric ${op} ${bind()}::numeric` : `${c} ${op} ${bind()}`
|
|
55
66
|
switch cmp {
|
|
56
67
|
| QueryEngine.SubId.Equal => cmpSql("=")
|
|
57
68
|
| Unequal => cmpSql("<>")
|
|
@@ -63,24 +74,28 @@ let subIdSql = (b: paramBuilder, field: string, cmp: QueryEngine.SubId.comparato
|
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
|
|
66
|
-
let notExpired =
|
|
77
|
+
let notExpired = QueryDbStorage_Postgres_Ops.notExpiredClause
|
|
67
78
|
|
|
68
79
|
// Add `id` (from partition_key) when absent — matches allRows/scan in the SQLite
|
|
69
80
|
// engine; partition-key queries return items as stored.
|
|
70
81
|
let decodeRow = (~withId, row: dict<JSON.t>): JSON.t => {
|
|
71
|
-
let item =
|
|
82
|
+
let item = QueryDbStorage_Postgres_Ops.decodeItem(row)
|
|
72
83
|
if withId {
|
|
73
84
|
let pk = switch row->Dict.get("partition_key") {
|
|
74
85
|
| Some(JSON.String(s)) => s
|
|
75
86
|
| _ => ""
|
|
76
87
|
}
|
|
77
|
-
|
|
88
|
+
QueryDbStorage_Postgres_Ops.withId(item, pk)
|
|
78
89
|
} else {
|
|
79
90
|
item
|
|
80
91
|
}
|
|
81
92
|
}
|
|
82
93
|
|
|
83
|
-
module Make = (
|
|
94
|
+
module Make = (
|
|
95
|
+
P: {
|
|
96
|
+
let pool: PgDriver.pool
|
|
97
|
+
},
|
|
98
|
+
) => {
|
|
84
99
|
let query = async (
|
|
85
100
|
~readModelName,
|
|
86
101
|
~key=?,
|
|
@@ -90,7 +105,7 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
90
105
|
~ascending=?,
|
|
91
106
|
~limit=?,
|
|
92
107
|
): array<JSON.t> => {
|
|
93
|
-
let table =
|
|
108
|
+
let table = QueryDbStorage_Postgres_Ops.tableName(readModelName)
|
|
94
109
|
let keyStr = switch key {
|
|
95
110
|
| Some(k) => k
|
|
96
111
|
| None => valueToText(id)
|
|
@@ -109,16 +124,22 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
109
124
|
| Some(n) => ` LIMIT ${b->param(JSON.Encode.int(n))}`
|
|
110
125
|
| None => ""
|
|
111
126
|
}
|
|
112
|
-
let sql = `SELECT partition_key, item FROM ${table} WHERE ${where->Array.join(
|
|
127
|
+
let sql = `SELECT partition_key, item FROM ${table} WHERE ${where->Array.join(
|
|
128
|
+
" AND ",
|
|
129
|
+
)} ORDER BY sub_key ${dir}${limitClause}`
|
|
113
130
|
(await P.pool->PgDriver.query(sql, b.params))->Array.map(decodeRow(~withId=false, ...))
|
|
114
131
|
}
|
|
115
132
|
|
|
116
133
|
let scan = async (~readModelName, ~filterConfigs, ~limit): array<JSON.t> => {
|
|
117
|
-
let table =
|
|
134
|
+
let table = QueryDbStorage_Postgres_Ops.tableName(readModelName)
|
|
118
135
|
let b = {params: []}
|
|
119
136
|
let where = [notExpired]
|
|
120
|
-
filterConfigs->Array.forEach(((field, cmp, v)) =>
|
|
121
|
-
|
|
137
|
+
filterConfigs->Array.forEach(((field, cmp, v)) =>
|
|
138
|
+
where->Array.push(filterSql(b, field, cmp, v))
|
|
139
|
+
)
|
|
140
|
+
let sql = `SELECT partition_key, item FROM ${table} WHERE ${where->Array.join(
|
|
141
|
+
" AND ",
|
|
142
|
+
)} ORDER BY partition_key, sub_key LIMIT ${b->param(JSON.Encode.int(limit))}`
|
|
122
143
|
(await P.pool->PgDriver.query(sql, b.params))->Array.map(decodeRow(~withId=true, ...))
|
|
123
144
|
}
|
|
124
145
|
|
|
@@ -138,7 +159,7 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
138
159
|
// (`ensureIndexes`) instead of scanning. String comparison mirrors the
|
|
139
160
|
// resolver's JS path (which only matched string-typed fields).
|
|
140
161
|
let indexLookup = async (~readModelName, field: string, value: string): array<JSON.t> => {
|
|
141
|
-
let table =
|
|
162
|
+
let table = QueryDbStorage_Postgres_Ops.tableName(readModelName)
|
|
142
163
|
let b = {params: []}
|
|
143
164
|
let sql = `SELECT partition_key, item FROM ${table} WHERE ${col(field)} = ${b->param(
|
|
144
165
|
JSON.Encode.string(value),
|
|
@@ -154,7 +175,7 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
154
175
|
if ids->Array.length == 0 {
|
|
155
176
|
[]
|
|
156
177
|
} else {
|
|
157
|
-
let table =
|
|
178
|
+
let table = QueryDbStorage_Postgres_Ops.tableName(readModelName)
|
|
158
179
|
let b = {params: []}
|
|
159
180
|
let idsJson = JSON.Encode.array(ids->Array.map(JSON.Encode.string))
|
|
160
181
|
let sql = `SELECT partition_key, item FROM ${table} WHERE partition_key = ANY(${b->param(
|
|
@@ -168,6 +189,39 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
168
189
|
let idExprC = `COALESCE(item->>'id', partition_key) COLLATE "C"`
|
|
169
190
|
let jsonTextC = (field: string): string => `${col(field)} COLLATE "C"`
|
|
170
191
|
|
|
192
|
+
// "not retired", as jsonb rather than text. `->` keeps the value typed, so a
|
|
193
|
+
// JSON boolean true is distinguishable from the JSON string "true"; `->>`
|
|
194
|
+
// would render both as 'true' and hide a row the shared spec keeps, since that
|
|
195
|
+
// spec decodes strictly and reads a non-boolean as "no flag". `IS DISTINCT
|
|
196
|
+
// FROM` rather than `<>` so an absent key — NULL — keeps the row instead of
|
|
197
|
+
// making the whole predicate NULL and dropping it.
|
|
198
|
+
//
|
|
199
|
+
// The state form compares against JSON strings instead of `true`, one
|
|
200
|
+
// `IS DISTINCT FROM` per state, ANDed. Not `NOT IN`: that is ordinary
|
|
201
|
+
// equality, so an absent key makes the predicate NULL and drops a row this
|
|
202
|
+
// spec keeps. Same shape and same index behaviour as the single-state form —
|
|
203
|
+
// a handful of equality predicates over an enum-valued attribute cost what one
|
|
204
|
+
// over a boolean does — so the `@index` guidance carries over unchanged.
|
|
205
|
+
//
|
|
206
|
+
// A set naming no states withdraws nothing, so the predicate is vacuously
|
|
207
|
+
// true, matching what `isRetiredValue` answers for it.
|
|
208
|
+
let notRetiredC = (scope: Reventless.OwnerScope.retiredScope): string => {
|
|
209
|
+
let key = scope.field->String.replaceAll("'", "''")
|
|
210
|
+
let distinctFrom = lit => `(item->'${key}') IS DISTINCT FROM ${lit}`
|
|
211
|
+
switch scope.values {
|
|
212
|
+
| None => distinctFrom("'true'::jsonb")
|
|
213
|
+
| Some([]) => "TRUE"
|
|
214
|
+
| Some(states) =>
|
|
215
|
+
// Parenthesised though every caller ANDs these together already: a clause
|
|
216
|
+
// that is safe only because of where it is spliced is a clause that breaks
|
|
217
|
+
// the first time it is spliced somewhere else.
|
|
218
|
+
"(" ++
|
|
219
|
+
states
|
|
220
|
+
->Array.map(state => distinctFrom(`'"${state->String.replaceAll("'", "''")}"'::jsonb`))
|
|
221
|
+
->Array.join(" AND ") ++ ")"
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
171
225
|
// Connection-list push-down. Builds `item->>'field'` predicates + keyset
|
|
172
226
|
// WHERE + `ORDER BY … LIMIT pageSize+1` so a page reads only what it returns
|
|
173
227
|
// rather than the whole read model. Reproduces `QueryDbListQuery` semantics
|
|
@@ -183,8 +237,10 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
183
237
|
~argsDict: dict<JSON.t>,
|
|
184
238
|
~capability: GraphQL_FragmentGenerator.serverCapability,
|
|
185
239
|
~labelField as _,
|
|
240
|
+
~ownerScope: option<(string, string)>=?,
|
|
241
|
+
~retiredScope: option<Reventless.OwnerScope.retiredScope>=?,
|
|
186
242
|
): option<JSON.t> => {
|
|
187
|
-
let table =
|
|
243
|
+
let table = QueryDbStorage_Postgres_Ops.tableName(readModelName)
|
|
188
244
|
let filterDict =
|
|
189
245
|
argsDict->Dict.get("filter")->Option.flatMap(JSON.Decode.object)->Option.getOr(Dict.make())
|
|
190
246
|
let strNonEmpty = k =>
|
|
@@ -210,6 +266,19 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
210
266
|
} else {
|
|
211
267
|
let b = {params: []}
|
|
212
268
|
let whereParts = [notExpired]
|
|
269
|
+
// Into the SQL, before the LIMIT — narrowing the returned page instead
|
|
270
|
+
// would hand back fewer rows than asked for while still claiming a next
|
|
271
|
+
// page. Mirrors the SQLite push-down; the parity harness holds the two
|
|
272
|
+
// and the shared spec to the same answer.
|
|
273
|
+
switch ownerScope {
|
|
274
|
+
| Some((field, required)) =>
|
|
275
|
+
whereParts->Array.push(`${jsonTextC(field)} = ${b->param(JSON.Encode.string(required))}`)
|
|
276
|
+
| None => ()
|
|
277
|
+
}
|
|
278
|
+
switch retiredScope {
|
|
279
|
+
| Some(scope) => whereParts->Array.push(notRetiredC(scope))
|
|
280
|
+
| None => ()
|
|
281
|
+
}
|
|
213
282
|
let valString = v =>
|
|
214
283
|
switch v->JSON.Decode.string {
|
|
215
284
|
| Some(s) => Some(s)
|
|
@@ -217,15 +286,17 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
217
286
|
}
|
|
218
287
|
capability.filterFields->Array.forEach(f => {
|
|
219
288
|
switch filterDict->Dict.get(f.name ++ "Eq") {
|
|
220
|
-
| Some(v)
|
|
289
|
+
| Some(v) if v != JSON.Encode.null =>
|
|
221
290
|
whereParts->Array.push(
|
|
222
|
-
`${jsonTextC(f.name)} = ${b->param(
|
|
291
|
+
`${jsonTextC(f.name)} = ${b->param(
|
|
292
|
+
JSON.Encode.string(valString(v)->Option.getOr("")),
|
|
293
|
+
)}`,
|
|
223
294
|
)
|
|
224
295
|
| _ => ()
|
|
225
296
|
}
|
|
226
297
|
if f.range {
|
|
227
298
|
switch filterDict->Dict.get(f.name ++ "From") {
|
|
228
|
-
| Some(v)
|
|
299
|
+
| Some(v) if v != JSON.Encode.null =>
|
|
229
300
|
whereParts->Array.push(
|
|
230
301
|
`${jsonTextC(f.name)} >= ${b->param(
|
|
231
302
|
JSON.Encode.string(valString(v)->Option.getOr("")),
|
|
@@ -234,7 +305,7 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
234
305
|
| _ => ()
|
|
235
306
|
}
|
|
236
307
|
switch filterDict->Dict.get(f.name ++ "To") {
|
|
237
|
-
| Some(v)
|
|
308
|
+
| Some(v) if v != JSON.Encode.null =>
|
|
238
309
|
whereParts->Array.push(
|
|
239
310
|
`${jsonTextC(f.name)} <= ${b->param(
|
|
240
311
|
JSON.Encode.string(valString(v)->Option.getOr("")),
|
|
@@ -256,7 +327,8 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
256
327
|
| Some(f) => jsonTextC(f)
|
|
257
328
|
| None => idExprC
|
|
258
329
|
}
|
|
259
|
-
|
|
330
|
+
let afterCursor = argsDict->Dict.get("after")->Option.flatMap(JSON.Decode.string)
|
|
331
|
+
switch afterCursor {
|
|
260
332
|
| Some(c) =>
|
|
261
333
|
whereParts->Array.push(
|
|
262
334
|
`${cursorExpr} ${isDesc ? "<" : ">"} ${b->param(
|
|
@@ -278,7 +350,8 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
278
350
|
let sql = `SELECT partition_key, item FROM ${table} WHERE ${whereParts->Array.join(
|
|
279
351
|
" AND ",
|
|
280
352
|
)} ORDER BY ${orderClause} LIMIT ${b->param(JSON.Encode.int(pageSize + 1))}`
|
|
281
|
-
let rows =
|
|
353
|
+
let rows =
|
|
354
|
+
(await P.pool->PgDriver.query(sql, b.params))->Array.map(decodeRow(~withId=true, ...))
|
|
282
355
|
let hasMore = rows->Array.length > pageSize
|
|
283
356
|
let pageItems = rows->Array.slice(~start=0, ~end=pageSize)
|
|
284
357
|
let cursorField = orderByField->Option.getOr("id")
|
|
@@ -290,7 +363,10 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
290
363
|
ReventlessCore.QueryDbListQuery.buildConnection(
|
|
291
364
|
~pageItems,
|
|
292
365
|
~hasNextPage=hasMore,
|
|
293
|
-
|
|
366
|
+
// Same rule the spec uses, because the parity suite compares them: a
|
|
367
|
+
// forward page reached by a cursor has one behind it. Hardcoding false
|
|
368
|
+
// made Prev disappear on exactly the pages that have a previous one.
|
|
369
|
+
~hasPreviousPage=afterCursor->Option.isSome,
|
|
294
370
|
~cursorValueOf,
|
|
295
371
|
),
|
|
296
372
|
)
|
|
@@ -309,14 +385,18 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
309
385
|
~subIdField as _: string,
|
|
310
386
|
~id: string,
|
|
311
387
|
~argsDict: dict<JSON.t>,
|
|
388
|
+
~ownerScope: option<(string, string)>=?,
|
|
389
|
+
~retiredScope: option<Reventless.OwnerScope.retiredScope>=?,
|
|
312
390
|
): JSON.t => {
|
|
313
|
-
let table =
|
|
391
|
+
let table = QueryDbStorage_Postgres_Ops.tableName(readModelName)
|
|
314
392
|
let filterDict =
|
|
315
393
|
argsDict->Dict.get("filter")->Option.flatMap(JSON.Decode.object)->Option.getOr(Dict.make())
|
|
316
394
|
let fstr = k => filterDict->Dict.get(k)->Option.flatMap(JSON.Decode.string)
|
|
317
395
|
let orderDesc = fstr("order")->Option.mapOr(false, o => o == "DESC")
|
|
318
|
-
let last =
|
|
319
|
-
|
|
396
|
+
let last =
|
|
397
|
+
argsDict->Dict.get("last")->Option.flatMap(JSON.Decode.float)->Option.map(Float.toInt)
|
|
398
|
+
let first =
|
|
399
|
+
argsDict->Dict.get("first")->Option.flatMap(JSON.Decode.float)->Option.map(Float.toInt)
|
|
320
400
|
let after = argsDict->Dict.get("after")->Option.flatMap(JSON.Decode.string)
|
|
321
401
|
let before = argsDict->Dict.get("before")->Option.flatMap(JSON.Decode.string)
|
|
322
402
|
let isBackward = last->Option.isSome
|
|
@@ -324,28 +404,49 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
324
404
|
let sk = `sub_key COLLATE "C"`
|
|
325
405
|
let b = {params: []}
|
|
326
406
|
let where = [`partition_key = ${b->param(JSON.Encode.string(id))}`, notExpired]
|
|
407
|
+
// Before the keyset window and the LIMIT, for the same reason as `listPage`.
|
|
408
|
+
switch ownerScope {
|
|
409
|
+
| Some((field, required)) =>
|
|
410
|
+
where->Array.push(`${jsonTextC(field)} = ${b->param(JSON.Encode.string(required))}`)
|
|
411
|
+
| None => ()
|
|
412
|
+
}
|
|
413
|
+
switch retiredScope {
|
|
414
|
+
| Some(scope) => where->Array.push(notRetiredC(scope))
|
|
415
|
+
| None => ()
|
|
416
|
+
}
|
|
327
417
|
fstr("prefix")->Option.forEach(p =>
|
|
328
418
|
where->Array.push(`starts_with(sub_key, ${b->param(JSON.Encode.string(p))})`)
|
|
329
419
|
)
|
|
330
|
-
fstr("from")->Option.forEach(f =>
|
|
331
|
-
|
|
420
|
+
fstr("from")->Option.forEach(f =>
|
|
421
|
+
where->Array.push(`${sk} >= ${b->param(JSON.Encode.string(f))}`)
|
|
422
|
+
)
|
|
423
|
+
fstr("to")->Option.forEach(t =>
|
|
424
|
+
where->Array.push(`${sk} <= ${b->param(JSON.Encode.string(t))}`)
|
|
425
|
+
)
|
|
332
426
|
fstr("eq")->Option.forEach(e => where->Array.push(`${sk} = ${b->param(JSON.Encode.string(e))}`))
|
|
333
427
|
// Keyset: forward excludes ≤ after; backward excludes ≥ before.
|
|
334
428
|
switch (isBackward, after, before) {
|
|
335
429
|
| (false, Some(c), _) =>
|
|
336
|
-
where->Array.push(
|
|
430
|
+
where->Array.push(
|
|
431
|
+
`${sk} > ${b->param(JSON.Encode.string(ReventlessCore.QueryDbListQuery.decodeCursor(c)))}`,
|
|
432
|
+
)
|
|
337
433
|
| (true, _, Some(c)) =>
|
|
338
|
-
where->Array.push(
|
|
434
|
+
where->Array.push(
|
|
435
|
+
`${sk} < ${b->param(JSON.Encode.string(ReventlessCore.QueryDbListQuery.decodeCursor(c)))}`,
|
|
436
|
+
)
|
|
339
437
|
| _ => ()
|
|
340
438
|
}
|
|
341
439
|
// Page-fetch direction is the LOGICAL order forward, and its OPPOSITE
|
|
342
440
|
// backward (take the N nearest `before`, then reverse to logical) — mirrors
|
|
343
441
|
// the resolver's `reverse = isBackward ? !orderDesc : orderDesc`.
|
|
344
442
|
let fetchDesc = isBackward ? !orderDesc : orderDesc
|
|
345
|
-
let pageSize =
|
|
443
|
+
let pageSize =
|
|
444
|
+
(isBackward ? last : first)->Option.getOr(ReventlessCore.QueryDbListQuery.defaultListPageSize)
|
|
346
445
|
let sql = `SELECT partition_key, sub_key, item FROM ${table} WHERE ${where->Array.join(
|
|
347
446
|
" AND ",
|
|
348
|
-
)} ORDER BY ${sk} ${fetchDesc ? "DESC" : "ASC"} LIMIT ${b->param(
|
|
447
|
+
)} ORDER BY ${sk} ${fetchDesc ? "DESC" : "ASC"} LIMIT ${b->param(
|
|
448
|
+
JSON.Encode.int(pageSize + 1),
|
|
449
|
+
)}`
|
|
349
450
|
let rows = await P.pool->PgDriver.query(sql, b.params)
|
|
350
451
|
let hasMore = rows->Array.length > pageSize
|
|
351
452
|
let taken = rows->Array.slice(~start=0, ~end=pageSize)
|
|
@@ -359,17 +460,18 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
359
460
|
| _ => ""
|
|
360
461
|
}
|
|
361
462
|
let cursors = logical->Array.map(subKeyOf)
|
|
362
|
-
let edges =
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
)
|
|
463
|
+
let edges = pageItems->Array.mapWithIndex((item, i) =>
|
|
464
|
+
Obj.magic({
|
|
465
|
+
"node": item,
|
|
466
|
+
"cursor": ReventlessCore.QueryDbListQuery.encodeCursor(cursors->Array.getUnsafe(i)),
|
|
467
|
+
})
|
|
468
|
+
)
|
|
369
469
|
let startCursor =
|
|
370
470
|
cursors->Array.get(0)->Option.map(ReventlessCore.QueryDbListQuery.encodeCursor)
|
|
371
471
|
let endCursor =
|
|
372
|
-
cursors
|
|
472
|
+
cursors
|
|
473
|
+
->Array.get(cursors->Array.length - 1)
|
|
474
|
+
->Option.map(ReventlessCore.QueryDbListQuery.encodeCursor)
|
|
373
475
|
Obj.magic({
|
|
374
476
|
"edges": edges,
|
|
375
477
|
"pageInfo": {
|
|
@@ -380,7 +482,4 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
380
482
|
},
|
|
381
483
|
})
|
|
382
484
|
}
|
|
383
|
-
|
|
384
|
-
let make: QueryDb_Adapter.queryEngineMaker = _allQueryDbs =>
|
|
385
|
-
Pulumi.Output.make({QueryEngine.scan, query})
|
|
386
485
|
}
|
|
@@ -135,7 +135,12 @@ switch processEnv->Dict.get("PG_URL") {
|
|
|
135
135
|
|
|
136
136
|
// Assert the push-down declines this shape (resolver falls back to the spec).
|
|
137
137
|
let checkFallback = async args => {
|
|
138
|
-
let r = await Eng.listPage(
|
|
138
|
+
let r = await Eng.listPage(
|
|
139
|
+
~readModelName=name,
|
|
140
|
+
~argsDict=argsOf(args),
|
|
141
|
+
~capability,
|
|
142
|
+
~labelField="name",
|
|
143
|
+
)
|
|
139
144
|
expect(r->Option.isSome)->toBe(false)
|
|
140
145
|
}
|
|
141
146
|
|
|
@@ -204,7 +209,9 @@ switch processEnv->Dict.get("PG_URL") {
|
|
|
204
209
|
checkFallback([("filter", filterOf([("searchPrefix", JSON.Encode.string("A"))]))])
|
|
205
210
|
)
|
|
206
211
|
testPromise("ids → fallback", () =>
|
|
207
|
-
checkFallback([
|
|
212
|
+
checkFallback([
|
|
213
|
+
("filter", filterOf([("ids", JSON.Encode.array([JSON.Encode.string("p-1")]))])),
|
|
214
|
+
])
|
|
208
215
|
)
|
|
209
216
|
testPromise("backward (last/before) → fallback", () =>
|
|
210
217
|
checkFallback([("last", JSON.Encode.int(2)), ("before", JSON.Encode.string(cur("p-4")))])
|
|
@@ -265,10 +272,20 @@ switch processEnv->Dict.get("PG_URL") {
|
|
|
265
272
|
->Array.filterMap(e => e->field("node")->Option.flatMap(n => n->str("seq")))
|
|
266
273
|
|
|
267
274
|
let pageInfoBool = (conn, key) =>
|
|
268
|
-
conn
|
|
275
|
+
conn
|
|
276
|
+
->field("pageInfo")
|
|
277
|
+
->Option.getOr(JSON.Encode.null)
|
|
278
|
+
->field(key)
|
|
279
|
+
->Option.flatMap(JSON.Decode.bool)
|
|
280
|
+
->Option.getOr(false)
|
|
269
281
|
|
|
270
282
|
let itemsPage = args =>
|
|
271
|
-
Eng.itemsPage(
|
|
283
|
+
Eng.itemsPage(
|
|
284
|
+
~readModelName=itemsName,
|
|
285
|
+
~subIdField="seq",
|
|
286
|
+
~id="order-1",
|
|
287
|
+
~argsDict=argsOf(args),
|
|
288
|
+
)
|
|
272
289
|
|
|
273
290
|
describe("QueryEnginePostgres itemsPage (sub-id keyset)", () => {
|
|
274
291
|
testPromise("bare → all lines ASC, no next page", async () => {
|
|
@@ -282,7 +299,10 @@ switch processEnv->Dict.get("PG_URL") {
|
|
|
282
299
|
expect(pageInfoBool(r, "hasNextPage"))->toBe(true)
|
|
283
300
|
})
|
|
284
301
|
testPromise("first:2 after b → [c,d]", async () => {
|
|
285
|
-
let r = await itemsPage([
|
|
302
|
+
let r = await itemsPage([
|
|
303
|
+
("first", JSON.Encode.int(2)),
|
|
304
|
+
("after", JSON.Encode.string(cur("b"))),
|
|
305
|
+
])
|
|
286
306
|
expect(r->itemSeqs)->toEqual(["c", "d"])
|
|
287
307
|
})
|
|
288
308
|
testPromise("order DESC → [e..a]", async () => {
|
|
@@ -304,7 +324,10 @@ switch processEnv->Dict.get("PG_URL") {
|
|
|
304
324
|
expect(r->itemSeqs)->toEqual(["c"])
|
|
305
325
|
})
|
|
306
326
|
testPromise("backward last:2 before d → [b,c] (logical ASC)", async () => {
|
|
307
|
-
let r = await itemsPage([
|
|
327
|
+
let r = await itemsPage([
|
|
328
|
+
("last", JSON.Encode.int(2)),
|
|
329
|
+
("before", JSON.Encode.string(cur("d"))),
|
|
330
|
+
])
|
|
308
331
|
expect(r->itemSeqs)->toEqual(["b", "c"])
|
|
309
332
|
expect(pageInfoBool(r, "hasPreviousPage"))->toBe(true)
|
|
310
333
|
})
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reventlessdev/reventless-postgres",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.151",
|
|
4
4
|
"description": "Postgres storage backend for Reventless (classic + DCB event logs, query DB, change feed). Connection-string only — RDS/Aurora, any managed provider, or a local container.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"jest": {
|
|
@@ -21,22 +21,22 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"pg": "^8.13.1",
|
|
24
|
-
"sury": "11.0.0
|
|
25
|
-
"@reventlessdev/rescript-effect": "0.1.0-alpha.
|
|
26
|
-
"@reventlessdev/rescript-
|
|
27
|
-
"@reventlessdev/rescript-
|
|
28
|
-
"@reventlessdev/reventless-
|
|
29
|
-
"@reventlessdev/reventless-
|
|
30
|
-
"@reventlessdev/reventless-spec": "3.0.0-alpha.
|
|
24
|
+
"sury": "11.0.0",
|
|
25
|
+
"@reventlessdev/rescript-effect": "0.1.0-alpha.34",
|
|
26
|
+
"@reventlessdev/rescript-pulumi-pulumi": "2.3.0-alpha.23",
|
|
27
|
+
"@reventlessdev/rescript-jest": "1.0.0-alpha.11",
|
|
28
|
+
"@reventlessdev/reventless-infra": "3.0.0-alpha.185",
|
|
29
|
+
"@reventlessdev/reventless-core": "3.0.0-alpha.287",
|
|
30
|
+
"@reventlessdev/reventless-spec": "3.0.0-alpha.157"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/pg": "^8.11.10",
|
|
34
|
-
"rescript": "
|
|
35
|
-
"sury-ppx": "11.0.0
|
|
36
|
-
"@reventlessdev/reventless-ppx": "1.0.0-alpha.
|
|
34
|
+
"rescript": "12.3.1",
|
|
35
|
+
"sury-ppx": "11.0.0",
|
|
36
|
+
"@reventlessdev/reventless-ppx": "1.0.0-alpha.96"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"rescript": "^12.3.
|
|
39
|
+
"rescript": "^12.3.1"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"registry": "https://registry.npmjs.org"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
46
|
"url": "git+https://github.com/ReventlessDev/reventless-core.git",
|
|
47
|
-
"directory": "reventless/
|
|
47
|
+
"directory": "reventless/postgres"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rescript build",
|
package/rescript.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// existing `DcbEventLogStorage_Postgres.*` reference keeps working) and adds only
|
|
9
9
|
// the deploy-time `DcbEventLog_Adapter` shape, keeping the historic `makeStorage`
|
|
10
10
|
// 3-tuple `(name, ops, adapter)` API unchanged.
|
|
11
|
-
// See docs/plans/deployed-lambda-esm-self-containment.md (Rung-3 finding).
|
|
11
|
+
// See docs/plans/done/deployed-lambda-esm-self-containment.md (Rung-3 finding).
|
|
12
12
|
|
|
13
13
|
open ReventlessCore
|
|
14
14
|
include DcbEventLogStorage_Postgres_Ops
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// would leak into the Lambda import graph and fail resolution on real Lambda. The
|
|
7
7
|
// thin `DcbEventLogStorage_Postgres` wrapper `include`s this and adds the
|
|
8
8
|
// deploy-time `Pulumi.Output`-shaped adapter for local/deploy consumers.
|
|
9
|
-
// See docs/plans/deployed-lambda-esm-self-containment.md (Rung-3 finding).
|
|
9
|
+
// See docs/plans/done/deployed-lambda-esm-self-containment.md (Rung-3 finding).
|
|
10
10
|
|
|
11
11
|
open ReventlessCore
|
|
12
12
|
open Reventless
|
|
@@ -67,7 +67,7 @@ let rowToEvent = (row: dict<JSON.t>): DcbEventLog_Adapter.rawSequencedEvent => {
|
|
|
67
67
|
| _ => ""
|
|
68
68
|
}
|
|
69
69
|
let meta = switch row->Dict.get("meta") {
|
|
70
|
-
| Some(metaJson) => metaJson->
|
|
70
|
+
| Some(metaJson) => metaJson->Reventless.Util_Sury.fromJson(Reventless.Message.metaSchema)
|
|
71
71
|
| None => JsError.throwWithMessage("missing meta column in dcb_event row")
|
|
72
72
|
}
|
|
73
73
|
{
|
|
@@ -143,7 +143,7 @@ let buildReadWhere = (
|
|
|
143
143
|
// Strip the zero-padding a cursor carries for string-sortability, leaving a
|
|
144
144
|
// plain decimal both `::xid8` and `::bigint` parse unambiguously ("0" if empty).
|
|
145
145
|
let stripZeros = (s: string): string => {
|
|
146
|
-
let t = s->String.replaceRegExp(
|
|
146
|
+
let t = s->String.replaceRegExp(/^0+/, "")
|
|
147
147
|
t == "" ? "0" : t
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -222,49 +222,45 @@ let makeOps = (
|
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
let append = async (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
225
|
+
let append = async (newEvents: array<DcbEventLog_Adapter.rawStoredEvent>, ~condition=?): result<
|
|
226
|
+
DcbTag.sequencePosition,
|
|
227
|
+
ReventlessInfra.DcbEventLog.appendError,
|
|
228
|
+
> => {
|
|
229
229
|
let eventsJson = JSON.Array(
|
|
230
|
-
newEvents->Array.map(ev =>
|
|
231
|
-
|
|
230
|
+
newEvents->Array.map(ev => JSON.Object(
|
|
231
|
+
Dict.fromArray([
|
|
232
|
+
("event_type", JSON.Encode.string(ev.eventType)),
|
|
233
|
+
(
|
|
234
|
+
"tags",
|
|
235
|
+
JSON.Array(ev.tags->Array.map(t => JSON.Encode.string(t.key ++ "=" ++ t.value))),
|
|
236
|
+
),
|
|
237
|
+
("data", ev.data),
|
|
238
|
+
("meta", ev.meta->Reventless.Util_Sury.toJson(Reventless.Message.metaSchema)),
|
|
239
|
+
]),
|
|
240
|
+
)),
|
|
241
|
+
)
|
|
242
|
+
let conditionParam = switch condition {
|
|
243
|
+
| Some(cond: DcbTag.appendCondition) =>
|
|
244
|
+
let queryJson = JSON.Array(
|
|
245
|
+
cond.query->Array.map(clause => JSON.Object(
|
|
232
246
|
Dict.fromArray([
|
|
233
|
-
(
|
|
247
|
+
(
|
|
248
|
+
"eventTypes",
|
|
249
|
+
switch clause.eventTypes {
|
|
250
|
+
| Some(types) => JSON.Array(types->Array.map(JSON.Encode.string))
|
|
251
|
+
| None => JSON.Encode.null
|
|
252
|
+
},
|
|
253
|
+
),
|
|
234
254
|
(
|
|
235
255
|
"tags",
|
|
236
|
-
|
|
256
|
+
switch clause.tags {
|
|
257
|
+
| Some(tags) =>
|
|
258
|
+
JSON.Array(tags->Array.map(t => JSON.Encode.string(t.key ++ "=" ++ t.value)))
|
|
259
|
+
| None => JSON.Encode.null
|
|
260
|
+
},
|
|
237
261
|
),
|
|
238
|
-
("data", ev.data),
|
|
239
|
-
("meta", ev.meta->S.reverseConvertToJsonOrThrow(Reventless.Message.metaSchema)),
|
|
240
262
|
]),
|
|
241
|
-
)
|
|
242
|
-
),
|
|
243
|
-
)
|
|
244
|
-
let conditionParam = switch condition {
|
|
245
|
-
| Some(cond: DcbTag.appendCondition) =>
|
|
246
|
-
let queryJson = JSON.Array(
|
|
247
|
-
cond.query->Array.map(clause =>
|
|
248
|
-
JSON.Object(
|
|
249
|
-
Dict.fromArray([
|
|
250
|
-
(
|
|
251
|
-
"eventTypes",
|
|
252
|
-
switch clause.eventTypes {
|
|
253
|
-
| Some(types) => JSON.Array(types->Array.map(JSON.Encode.string))
|
|
254
|
-
| None => JSON.Encode.null
|
|
255
|
-
},
|
|
256
|
-
),
|
|
257
|
-
(
|
|
258
|
-
"tags",
|
|
259
|
-
switch clause.tags {
|
|
260
|
-
| Some(tags) =>
|
|
261
|
-
JSON.Array(tags->Array.map(t => JSON.Encode.string(t.key ++ "=" ++ t.value)))
|
|
262
|
-
| None => JSON.Encode.null
|
|
263
|
-
},
|
|
264
|
-
),
|
|
265
|
-
]),
|
|
266
|
-
)
|
|
267
|
-
),
|
|
263
|
+
)),
|
|
268
264
|
)
|
|
269
265
|
let fields = [("query", queryJson)]
|
|
270
266
|
switch cond.after {
|
|
@@ -306,7 +302,10 @@ let makeOps = (
|
|
|
306
302
|
? Error(ReventlessInfra.DcbEventLog.Conflict)
|
|
307
303
|
: Error(
|
|
308
304
|
ReventlessInfra.DcbEventLog.StorageFailure(
|
|
309
|
-
exn
|
|
305
|
+
exn
|
|
306
|
+
->JsExn.fromException
|
|
307
|
+
->Option.flatMap(JsExn.message)
|
|
308
|
+
->Option.getOr("storage error"),
|
|
310
309
|
),
|
|
311
310
|
)
|
|
312
311
|
}
|
|
@@ -324,7 +323,9 @@ let makeOps = (
|
|
|
324
323
|
Effect.promise(() => {
|
|
325
324
|
let b = mkBuilder()
|
|
326
325
|
let where = buildReadWhere(b, ~name, ~query, ~after=cursor, ~applyFence=true)
|
|
327
|
-
let sql = `SELECT ${selectColumns}, transaction_id::text AS tx_raw, position::text AS pos_raw FROM dcb_event WHERE ${where} ORDER BY transaction_id ASC, position ASC LIMIT ${Int.toString(
|
|
326
|
+
let sql = `SELECT ${selectColumns}, transaction_id::text AS tx_raw, position::text AS pos_raw FROM dcb_event WHERE ${where} ORDER BY transaction_id ASC, position ASC LIMIT ${Int.toString(
|
|
327
|
+
pageSize,
|
|
328
|
+
)}`
|
|
328
329
|
pool->PgDriver.query(sql, b.params)
|
|
329
330
|
})->Effect.map(rows => {
|
|
330
331
|
let events = rows->Array.map(rowToEvent)
|