@powersync/service-module-postgres-storage 0.1.0 → 0.1.2

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.
@@ -1,5 +1,14 @@
1
1
  import * as lib_postgres from '@powersync/lib-service-postgres';
2
- import { container, DisposableObserver, errors, logger } from '@powersync/lib-services-framework';
2
+ import {
3
+ container,
4
+ DisposableObserver,
5
+ ErrorCode,
6
+ errors,
7
+ logger,
8
+ ReplicationAssertionError,
9
+ ServiceAssertionError,
10
+ ServiceError
11
+ } from '@powersync/lib-services-framework';
3
12
  import { storage, utils } from '@powersync/service-core';
4
13
  import * as sync_rules from '@powersync/service-sync-rules';
5
14
  import * as timers from 'timers/promises';
@@ -258,7 +267,7 @@ export class PostgresBucketBatch
258
267
  this.batch = resumeBatch;
259
268
 
260
269
  if (lastOp == null) {
261
- throw new Error('Unexpected last_op == null');
270
+ throw new ServiceAssertionError('Unexpected last_op == null');
262
271
  }
263
272
 
264
273
  this.persisted_op = lastOp;
@@ -631,7 +640,7 @@ export class PostgresBucketBatch
631
640
  return null;
632
641
  }
633
642
  } else {
634
- throw new Error(`${record.tag} not supported with skipExistingRows: true`);
643
+ throw new ReplicationAssertionError(`${record.tag} not supported with skipExistingRows: true`);
635
644
  }
636
645
  }
637
646
 
@@ -680,7 +689,7 @@ export class PostgresBucketBatch
680
689
  try {
681
690
  afterData = storage.serializeBson(after);
682
691
  if (afterData!.byteLength > MAX_ROW_SIZE) {
683
- throw new Error(`Row too large: ${afterData?.byteLength}`);
692
+ throw new ServiceError(ErrorCode.PSYNC_S1002, `Row too large: ${afterData?.byteLength}`);
684
693
  }
685
694
  } catch (e) {
686
695
  // Replace with empty values, equivalent to TOAST values
@@ -1,5 +1,5 @@
1
1
  import * as lib_postgres from '@powersync/lib-service-postgres';
2
- import { logger } from '@powersync/lib-services-framework';
2
+ import { ErrorCode, logger, ServiceError } from '@powersync/lib-services-framework';
3
3
  import { storage } from '@powersync/service-core';
4
4
  import { SqlSyncRules } from '@powersync/service-sync-rules';
5
5
 
@@ -44,7 +44,10 @@ export class PostgresPersistedSyncRulesContent implements storage.PersistedSyncR
44
44
  });
45
45
  const lockHandle = await manager.acquire();
46
46
  if (!lockHandle) {
47
- throw new Error(`Sync rules: ${this.id} have been locked by another process for replication.`);
47
+ throw new ServiceError(
48
+ ErrorCode.PSYNC_S1003,
49
+ `Sync rules: ${this.id} have been locked by another process for replication.`
50
+ );
48
51
  }
49
52
 
50
53
  const interval = setInterval(async () => {
@@ -1,3 +1,4 @@
1
+ import { ReplicationAssertionError } from '@powersync/lib-services-framework';
1
2
  import * as t from 'ts-codec';
2
3
 
3
4
  export const BIGINT_MAX = BigInt('9223372036854775807');
@@ -98,7 +99,7 @@ export const hexBuffer = t.codec(
98
99
  return Buffer.from(encoded);
99
100
  }
100
101
  if (typeof encoded !== 'string') {
101
- throw new Error(`Expected either a Buffer instance or hex encoded buffer string`);
102
+ throw new ReplicationAssertionError(`Expected either a Buffer instance or hex encoded buffer string`);
102
103
  }
103
104
  return Buffer.from(encoded, 'hex');
104
105
  }
@@ -116,7 +117,7 @@ export const pgwire_number = t.codec(
116
117
  return encoded;
117
118
  }
118
119
  if (typeof encoded !== 'bigint') {
119
- throw new Error(`Expected either number or bigint for value`);
120
+ throw new ReplicationAssertionError(`Expected either number or bigint for value`);
120
121
  }
121
122
  if (encoded > BigInt(Number.MAX_SAFE_INTEGER) || encoded < BigInt(Number.MIN_SAFE_INTEGER)) {
122
123
  throw new RangeError('BigInt value is out of safe integer range for conversion to Number.');