@syncular/server 0.50.0 → 0.51.0

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/README.md CHANGED
@@ -286,6 +286,14 @@ Whole-commit validation checks a client-proposed commit; it does not grant
286
286
  authority. Privileged operations such as connecting facilities still belong in
287
287
  explicit server-authoritative commands.
288
288
 
289
+ For a whole-commit authority refusal, throw `CommitAuthorizationRejection`
290
+ with the operation index and a static message. The server returns
291
+ `sync.forbidden` and rolls back the commit. An absent-row delete is normally an
292
+ idempotent no-op; a validator that denies it can use the message
293
+ `delete denied by scope authorization (§3.4)` to match the refusal for a
294
+ stored row outside the actor's scopes. Do not put row data or identifiers in
295
+ the message.
296
+
289
297
  ## Push idempotency and retry contract
290
298
 
291
299
  The idempotency key for a push commit is the triple
package/dist/push.js CHANGED
@@ -29,7 +29,7 @@ import { readCandidateRows, serveGateRefusal } from './storage.js';
29
29
  import { StorageConstraintError } from './storage-errors.js';
30
30
  import { transactionQuery } from './storage-query.js';
31
31
  import { serveNotReadyError } from './readiness.js';
32
- import { CommitValidationRejection, toValidateRow, ValidationRejection, } from './validate.js';
32
+ import { CommitAuthorizationRejection, CommitValidationRejection, toValidateRow, ValidationRejection, } from './validate.js';
33
33
  /**
34
34
  * Extract the blobIds a decoded row references through its `blob_ref`
35
35
  * columns (§5.9.4), skipping NULLs. Malformed BlobRefs already failed at
@@ -730,6 +730,12 @@ async function runCommitValidator(validator, onError, tx, schema, clientId, clie
730
730
  });
731
731
  }
732
732
  catch (error) {
733
+ if (error instanceof CommitAuthorizationRejection) {
734
+ if (error.opIndex >= operations.length) {
735
+ return errorRecord(0, 'sync.constraint_violation', 'commit authorization rejection names an unavailable operation');
736
+ }
737
+ return errorRecord(error.opIndex, error.code, error.message, false);
738
+ }
733
739
  if (error instanceof CommitValidationRejection) {
734
740
  if (error.opIndex >= operations.length) {
735
741
  return errorRecord(0, 'sync.constraint_violation', `commit validator rejection names unavailable opIndex ${error.opIndex}`);
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import { type RejectionDetails, type RowColumn, type RowValue, type ScopeMap } from '@syncular/core';
17
17
  import type { AuthoritativeQueryRequest, AuthoritativeQueryResult } from './storage.js';
18
+ import { SyncError } from './errors.js';
18
19
  /**
19
20
  * §6.7 reserved code prefixes. A host validator code MUST NOT start with
20
21
  * any of these: they namespace the protocol's own error families (§10.2)
@@ -210,5 +211,10 @@ export declare class CommitValidationRejection extends ValidationRejection {
210
211
  readonly opIndex: number;
211
212
  constructor(opIndex: number, code: string, message?: string, details?: RejectionDetails);
212
213
  }
214
+ /** A whole-commit authority refusal attributed to one operation (§6.8). */
215
+ export declare class CommitAuthorizationRejection extends SyncError {
216
+ readonly opIndex: number;
217
+ constructor(opIndex: number, message: string);
218
+ }
213
219
  /** Build the column-keyed row object a validator inspects (§6.7). */
214
220
  export declare function toValidateRow(columns: readonly RowColumn[], values: readonly RowValue[]): ValidateRow;
package/dist/validate.js CHANGED
@@ -14,6 +14,7 @@
14
14
  * object — zero cost, the events-seam discipline.
15
15
  */
16
16
  import { normalizeRejectionDetails, } from '@syncular/core';
17
+ import { SyncError } from './errors.js';
17
18
  /**
18
19
  * §6.7 reserved code prefixes. A host validator code MUST NOT start with
19
20
  * any of these: they namespace the protocol's own error families (§10.2)
@@ -73,6 +74,17 @@ export class CommitValidationRejection extends ValidationRejection {
73
74
  }
74
75
  }
75
76
  }
77
+ /** A whole-commit authority refusal attributed to one operation (§6.8). */
78
+ export class CommitAuthorizationRejection extends SyncError {
79
+ opIndex;
80
+ constructor(opIndex, message) {
81
+ super('sync.forbidden', message);
82
+ this.opIndex = opIndex;
83
+ if (!Number.isSafeInteger(opIndex) || opIndex < 0) {
84
+ throw new Error('CommitAuthorizationRejection opIndex must be a non-negative safe integer');
85
+ }
86
+ }
87
+ }
76
88
  /** Build the column-keyed row object a validator inspects (§6.7). */
77
89
  export function toValidateRow(columns, values) {
78
90
  const row = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/server",
3
- "version": "0.50.0",
3
+ "version": "0.51.0",
4
4
  "description": "Syncular server: handleSyncRequest + storage/auth interfaces for the sync protocol",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Benjamin Kniffler",
@@ -68,7 +68,7 @@
68
68
  "verify:node": "cd ../.. && bun build ./packages/server/test/sqlite-runtime/verify-node.mjs --target=node --conditions=bun --outfile=./packages/server/.verify-node.built.mjs && node ./packages/server/.verify-node.built.mjs"
69
69
  },
70
70
  "dependencies": {
71
- "@syncular/core": "0.50.0"
71
+ "@syncular/core": "0.51.0"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@electric-sql/pglite": "^0.5.4"
package/src/push.ts CHANGED
@@ -67,6 +67,7 @@ import type {
67
67
  ValidatorRegistry,
68
68
  } from './validate';
69
69
  import {
70
+ CommitAuthorizationRejection,
70
71
  CommitValidationRejection,
71
72
  toValidateRow,
72
73
  ValidationRejection,
@@ -1164,6 +1165,16 @@ async function runCommitValidator(
1164
1165
  read: commitValidationReader(tx, schema),
1165
1166
  });
1166
1167
  } catch (error) {
1168
+ if (error instanceof CommitAuthorizationRejection) {
1169
+ if (error.opIndex >= operations.length) {
1170
+ return errorRecord(
1171
+ 0,
1172
+ 'sync.constraint_violation',
1173
+ 'commit authorization rejection names an unavailable operation',
1174
+ );
1175
+ }
1176
+ return errorRecord(error.opIndex, error.code, error.message, false);
1177
+ }
1167
1178
  if (error instanceof CommitValidationRejection) {
1168
1179
  if (error.opIndex >= operations.length) {
1169
1180
  return errorRecord(
package/src/validate.ts CHANGED
@@ -24,6 +24,7 @@ import type {
24
24
  AuthoritativeQueryRequest,
25
25
  AuthoritativeQueryResult,
26
26
  } from './storage';
27
+ import { SyncError } from './errors';
27
28
 
28
29
  /**
29
30
  * §6.7 reserved code prefixes. A host validator code MUST NOT start with
@@ -284,6 +285,21 @@ export class CommitValidationRejection extends ValidationRejection {
284
285
  }
285
286
  }
286
287
 
288
+ /** A whole-commit authority refusal attributed to one operation (§6.8). */
289
+ export class CommitAuthorizationRejection extends SyncError {
290
+ constructor(
291
+ readonly opIndex: number,
292
+ message: string,
293
+ ) {
294
+ super('sync.forbidden', message);
295
+ if (!Number.isSafeInteger(opIndex) || opIndex < 0) {
296
+ throw new Error(
297
+ 'CommitAuthorizationRejection opIndex must be a non-negative safe integer',
298
+ );
299
+ }
300
+ }
301
+ }
302
+
287
303
  /** Build the column-keyed row object a validator inspects (§6.7). */
288
304
  export function toValidateRow(
289
305
  columns: readonly RowColumn[],