@reventlessdev/reventless-core 3.0.0-alpha.249 → 3.0.0-alpha.250

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
@@ -3,6 +3,13 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 3.0.0-alpha.250 (2026-08-23)
7
+
8
+ ### Bug Fixes
9
+
10
+ * **querydb:** serve the previous page instead of refusing it ([48341c9](https://github.com/ReventlessDev/reventless-core/commit/48341c9f61b5155b441deeb0edc9abf461948346))
11
+
12
+
6
13
  # 3.0.0-alpha.249 (2026-08-23)
7
14
 
8
15
  ### Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reventlessdev/reventless-core",
3
- "version": "3.0.0-alpha.249",
3
+ "version": "3.0.0-alpha.250",
4
4
  "description": "Core package for Reventless framework",
5
5
  "license": "Apache-2.0",
6
6
  "jest": {
@@ -30,15 +30,15 @@
30
30
  "uuid": "^13.0.0",
31
31
  "@reventlessdev/rescript-effect": "0.1.0-alpha.32",
32
32
  "@reventlessdev/rescript-fast-csv": "2.0.0-alpha.8",
33
- "@reventlessdev/rescript-hash-object": "1.2.0-alpha.14",
34
33
  "@reventlessdev/rescript-jest": "1.0.0-alpha.10",
34
+ "@reventlessdev/rescript-hash-object": "1.2.0-alpha.14",
35
35
  "@reventlessdev/rescript-node": "2.0.0-alpha.8",
36
36
  "@reventlessdev/rescript-pulumi-pulumi": "2.3.0-alpha.19",
37
37
  "@reventlessdev/rescript-ssh2": "2.0.0-alpha.8",
38
38
  "@reventlessdev/rescript-uuid": "2.0.0-alpha.0",
39
39
  "@reventlessdev/reventless-interop": "3.0.0-alpha.33",
40
- "@reventlessdev/reventless-infra": "3.0.0-alpha.151",
41
- "@reventlessdev/reventless-spec": "3.0.0-alpha.123"
40
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.123",
41
+ "@reventlessdev/reventless-infra": "3.0.0-alpha.151"
42
42
  },
43
43
  "devDependencies": {
44
44
  "rescript": "12.3.0",
@@ -265,10 +265,22 @@ let run = (
265
265
 
266
266
  let first =
267
267
  argsDict->Dict.get("first")->Option.flatMap(JSON.Decode.float)->Option.map(Float.toInt)
268
- let after = argsDict->Dict.get("after")->Option.flatMap(JSON.Decode.string)
268
+ // An empty cursor is no cursor. The host shell clears the opposite argument by
269
+ // setting it to "" rather than dropping it, and `Some("")` read as a cursor
270
+ // bounds nothing while still selecting the branch that expects one.
271
+ let cursorArg = key =>
272
+ argsDict
273
+ ->Dict.get(key)
274
+ ->Option.flatMap(JSON.Decode.string)
275
+ ->Option.flatMap(s => s == "" ? None : Some(s))
276
+ let after = cursorArg("after")
269
277
  let last = argsDict->Dict.get("last")->Option.flatMap(JSON.Decode.float)->Option.map(Float.toInt)
270
- let before = argsDict->Dict.get("before")->Option.flatMap(JSON.Decode.string)
271
- let isBackward = last->Option.isSome
278
+ let before = cursorArg("before")
279
+ // `before` decides the direction, not `last`. Relay pairs `last` with `before`,
280
+ // but a client that keeps its page size in `first` and only moves the cursor
281
+ // sends `before` alone — and keying on `last` made that a FORWARD read bounded
282
+ // by nothing, which answers page one and calls it the previous page.
283
+ let isBackward = last->Option.isSome || before->Option.isSome
272
284
  let cursorField = orderByField->Option.getOr("id")
273
285
  let getCursorValue = item => getFieldString(item, cursorField)->Option.getOr(getId(item))
274
286
 
@@ -288,8 +300,12 @@ let run = (
288
300
  | _ => sorted
289
301
  }
290
302
 
303
+ // `last` when given, else the page size the caller has been paging with.
291
304
  let pageSize = if isBackward {
292
- last->Option.getOr(defaultListPageSize)
305
+ switch last {
306
+ | Some(n) => n
307
+ | None => first->Option.getOr(defaultListPageSize)
308
+ }
293
309
  } else {
294
310
  first->Option.getOr(defaultListPageSize)
295
311
  }
@@ -311,10 +327,14 @@ let run = (
311
327
  (arr->Array.slice(~start=0, ~end=pageSize), hasMore)
312
328
  }
313
329
 
330
+ // Both directions report both flags. A backward page was cut from ahead, so a
331
+ // next page provably exists — the one the caller came from — and a forward page
332
+ // reached by a cursor has one behind it. Reporting only the flag that matches
333
+ // the direction made Prev vanish the moment it was used.
314
334
  buildConnection(
315
335
  ~pageItems,
316
- ~hasNextPage=!isBackward && hasMore,
317
- ~hasPreviousPage=isBackward && hasMore,
336
+ ~hasNextPage=isBackward ? true : hasMore,
337
+ ~hasPreviousPage=isBackward ? hasMore : after->Option.isSome,
318
338
  ~cursorValueOf=getCursorValue,
319
339
  )
320
340
  }
@@ -154,10 +154,17 @@ function run(items, argsDict, capability, labelField, decodeLocalIdOpt, ownerSco
154
154
  });
155
155
  }
156
156
  let first = Stdlib_Option.map(Stdlib_Option.flatMap(argsDict["first"], Stdlib_JSON.Decode.float), prim => prim | 0);
157
- let after = Stdlib_Option.flatMap(argsDict["after"], Stdlib_JSON.Decode.string);
157
+ let cursorArg = key => Stdlib_Option.flatMap(Stdlib_Option.flatMap(argsDict[key], Stdlib_JSON.Decode.string), s => {
158
+ if (s === "") {
159
+ return;
160
+ } else {
161
+ return s;
162
+ }
163
+ });
164
+ let after = cursorArg("after");
158
165
  let last = Stdlib_Option.map(Stdlib_Option.flatMap(argsDict["last"], Stdlib_JSON.Decode.float), prim => prim | 0);
159
- let before = Stdlib_Option.flatMap(argsDict["before"], Stdlib_JSON.Decode.string);
160
- let isBackward = Stdlib_Option.isSome(last);
166
+ let before = cursorArg("before");
167
+ let isBackward = Stdlib_Option.isSome(last) || Stdlib_Option.isSome(before);
161
168
  let cursorField = Stdlib_Option.getOr(orderByField, "id");
162
169
  let getCursorValue = item => Stdlib_Option.getOr(getFieldString(item, cursorField), getId(item));
163
170
  let cursorBounded;
@@ -188,7 +195,7 @@ function run(items, argsDict, capability, labelField, decodeLocalIdOpt, ownerSco
188
195
  } else {
189
196
  cursorBounded = sorted;
190
197
  }
191
- let pageSize = isBackward ? Stdlib_Option.getOr(last, 50) : Stdlib_Option.getOr(first, 50);
198
+ let pageSize = isBackward && last !== undefined ? last : Stdlib_Option.getOr(first, 50);
192
199
  let take = pageSize + 1 | 0;
193
200
  let match;
194
201
  if (isBackward) {
@@ -210,7 +217,7 @@ function run(items, argsDict, capability, labelField, decodeLocalIdOpt, ownerSco
210
217
  ];
211
218
  }
212
219
  let hasMore$2 = match[1];
213
- return buildConnection(match[0], !isBackward && hasMore$2, isBackward && hasMore$2, getCursorValue);
220
+ return buildConnection(match[0], isBackward ? true : hasMore$2, isBackward ? hasMore$2 : Stdlib_Option.isSome(after), getCursorValue);
214
221
  }
215
222
 
216
223
  let defaultListPageSize = 50;