@protobase/server 0.23.12 → 0.23.13

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.
@@ -39,7 +39,8 @@ const moveAside = async (trx, access, field, keys) => {
39
39
  }
40
40
  };
41
41
  /**
42
- * `reorder`: the listed records end up with `field` = 1, 2, 3, ... in the given order. Only records whose value changes
42
+ * `reorder`: the listed records end up with `field` = `start`, `start` + 1, ... in the given order, `start` 1 unless
43
+ * given, so a client sends only the stretch of a long list that moved. Only records whose value changes
43
44
  * are written, each as an ordinary update (validation, access, ETag, hooks); they are first moved aside (see `moveAside`)
44
45
  * so that a unique index such as (invoice_id, position) is never violated half way. Everything checks out before any row moves.
45
46
  */
@@ -64,9 +65,9 @@ const reorderIn = async (trx, deps, access, input) => {
64
65
  if (!found) throw missing(entry);
65
66
  return found;
66
67
  }));
67
- const changing = input.keys.flatMap((key, i) => Number(current[i].record[input.field]) === i + 1 ? [] : [i]);
68
+ const changing = input.keys.flatMap((key, i) => Number(current[i].record[input.field]) === input.start + i ? [] : [i]);
68
69
  const plans = /* @__PURE__ */ new Map();
69
- for (const i of changing) plans.set(i, await planUpdate(trx, access, input.keys[i], { [input.field]: i + 1 }, input.etags[names[i]] ?? null));
70
+ for (const i of changing) plans.set(i, await planUpdate(trx, access, input.keys[i], { [input.field]: input.start + i }, input.etags[names[i]] ?? null));
70
71
  if (changing.length > 0) await moveAside(trx, access, input.field, changing.map((i) => input.keys[i]));
71
72
  const results = [];
72
73
  for (const [i, key] of input.keys.entries()) {
@@ -88,7 +88,8 @@ const runBatch = async (deps, session, operations) => {
88
88
  const records = await reorderIn(trx, deps, access, {
89
89
  field: operation.field,
90
90
  keys,
91
- etags: operation.etags ?? {}
91
+ etags: operation.etags ?? {},
92
+ start: operation.start ?? 1
92
93
  });
93
94
  results.push({
94
95
  op: "reorder",
@@ -42,6 +42,7 @@ const operations = z.array(z.discriminatedUnion("op", [
42
42
  resource,
43
43
  field: z.string().min(1),
44
44
  keys: z.array(key).min(1),
45
+ start: z.number().int().optional(),
45
46
  etags: z.record(z.string(), z.string()).optional()
46
47
  })
47
48
  ])).min(1).max(500);
@@ -301,7 +301,12 @@ const batchSchemas = {
301
301
  type: "array",
302
302
  minItems: 1,
303
303
  items: { $ref: "#/components/schemas/BatchKey" },
304
- description: "The records in their final order: `field` becomes 1, 2, 3, ..."
304
+ description: "The records in their final order: `field` becomes `start`, `start` + 1, ..."
305
+ },
306
+ start: {
307
+ type: "integer",
308
+ default: 1,
309
+ description: "The value of the first record, so a long list sends only the stretch that moved"
305
310
  },
306
311
  etags: {
307
312
  type: "object",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/server",
3
- "version": "0.23.12",
3
+ "version": "0.23.13",
4
4
  "description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -32,9 +32,9 @@
32
32
  "dependencies": {
33
33
  "@better-auth/passkey": "^1.7.7",
34
34
  "@better-auth/sso": "^1.7.7",
35
- "@protobase/layout": "0.23.12",
36
- "@protobase/query": "0.23.12",
37
- "@protobase/schema": "0.23.12",
35
+ "@protobase/layout": "0.23.13",
36
+ "@protobase/query": "0.23.13",
37
+ "@protobase/schema": "0.23.13",
38
38
  "@react-email/render": "^2.1.0",
39
39
  "@scalar/hono-api-reference": "^0.12.10",
40
40
  "@sentry/core": "^11.7.0",