@powersync/service-core 0.0.0-dev-20250117095455 → 0.0.0-dev-20250122110924

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +13 -8
  2. package/dist/auth/RemoteJWKSCollector.d.ts +3 -0
  3. package/dist/auth/RemoteJWKSCollector.js +8 -4
  4. package/dist/auth/RemoteJWKSCollector.js.map +1 -1
  5. package/dist/entry/cli-entry.js +2 -0
  6. package/dist/entry/cli-entry.js.map +1 -1
  7. package/dist/entry/commands/teardown-action.js +2 -1
  8. package/dist/entry/commands/teardown-action.js.map +1 -1
  9. package/dist/entry/commands/test-connection-action.d.ts +2 -0
  10. package/dist/entry/commands/test-connection-action.js +32 -0
  11. package/dist/entry/commands/test-connection-action.js.map +1 -0
  12. package/dist/metrics/Metrics.js +2 -2
  13. package/dist/metrics/Metrics.js.map +1 -1
  14. package/dist/replication/AbstractReplicator.d.ts +2 -0
  15. package/dist/replication/AbstractReplicator.js.map +1 -1
  16. package/dist/replication/ReplicationEngine.d.ts +2 -0
  17. package/dist/replication/ReplicationEngine.js +3 -0
  18. package/dist/replication/ReplicationEngine.js.map +1 -1
  19. package/dist/replication/ReplicationModule.d.ts +8 -2
  20. package/dist/replication/ReplicationModule.js +6 -11
  21. package/dist/replication/ReplicationModule.js.map +1 -1
  22. package/dist/routes/endpoints/admin.js +3 -3
  23. package/dist/routes/endpoints/admin.js.map +1 -1
  24. package/dist/routes/endpoints/socket-route.js +5 -5
  25. package/dist/routes/endpoints/socket-route.js.map +1 -1
  26. package/dist/routes/endpoints/sync-rules.js +9 -9
  27. package/dist/routes/endpoints/sync-rules.js.map +1 -1
  28. package/dist/routes/endpoints/sync-stream.js +5 -5
  29. package/dist/routes/endpoints/sync-stream.js.map +1 -1
  30. package/dist/routes/route-register.js +4 -4
  31. package/dist/routes/route-register.js.map +1 -1
  32. package/dist/util/utils.js +2 -1
  33. package/dist/util/utils.js.map +1 -1
  34. package/package.json +5 -5
  35. package/src/auth/RemoteJWKSCollector.ts +18 -5
  36. package/src/entry/cli-entry.ts +2 -0
  37. package/src/entry/commands/teardown-action.ts +2 -1
  38. package/src/entry/commands/test-connection-action.ts +41 -0
  39. package/src/metrics/Metrics.ts +2 -2
  40. package/src/replication/AbstractReplicator.ts +3 -0
  41. package/src/replication/ReplicationEngine.ts +5 -0
  42. package/src/replication/ReplicationModule.ts +15 -13
  43. package/src/routes/endpoints/admin.ts +3 -3
  44. package/src/routes/endpoints/socket-route.ts +5 -5
  45. package/src/routes/endpoints/sync-rules.ts +9 -9
  46. package/src/routes/endpoints/sync-stream.ts +5 -5
  47. package/src/routes/route-register.ts +4 -4
  48. package/src/util/utils.ts +2 -1
  49. package/tsconfig.tsbuildinfo +1 -1
@@ -1,4 +1,4 @@
1
- import { errors, logger, router, schema } from '@powersync/lib-services-framework';
1
+ import { ErrorCode, errors, logger, router, schema } from '@powersync/lib-services-framework';
2
2
  import { RequestParameters } from '@powersync/service-sync-rules';
3
3
  import { Readable } from 'stream';
4
4
  import * as sync from '../../sync/sync-index.js';
@@ -22,9 +22,9 @@ export const syncStreamed = routeDefinition({
22
22
  const userAgent = headers['x-user-agent'] ?? headers['user-agent'];
23
23
  const clientId = payload.params.client_id;
24
24
  if (routerEngine.closed) {
25
- throw new errors.JourneyError({
25
+ throw new errors.ServiceError({
26
26
  status: 503,
27
- code: 'SERVICE_UNAVAILABLE',
27
+ code: ErrorCode.PSYNC_S2003,
28
28
  description: 'Service temporarily unavailable'
29
29
  });
30
30
  }
@@ -33,9 +33,9 @@ export const syncStreamed = routeDefinition({
33
33
  // Sanity check before we start the stream
34
34
  const cp = await storageEngine.activeBucketStorage.getActiveCheckpoint();
35
35
  if (!cp.hasSyncRules()) {
36
- throw new errors.JourneyError({
36
+ throw new errors.ServiceError({
37
37
  status: 500,
38
- code: 'NO_SYNC_RULES',
38
+ code: ErrorCode.PSYNC_S2302,
39
39
  description: 'No sync rules available'
40
40
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GAAG;gBACX,OAAO,EAAE;oBACP,cAAc,EAAE,sBAAsB;iBACvC;gBACD,IAAI,EAAE,MAAM;gBACZ,SAAS,EAAE,KAAK,IAAI,EAAE;oBACpB,UAAU,CAAC,KAAK,EAAE,CAAC;oBACnB,OAAO,CAAC,WAAW,EAAE,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;oBACrD,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE;wBAClC,OAAO,EAAE,UAAU,CAAC,OAAO;wBAC3B,SAAS,EAAE,QAAQ;wBACnB,UAAU,EAAE,SAAS;wBACrB,iBAAiB,EAAE,OAAO,CAAC,gBAAgB;wBAC3C,iBAAiB,EAAE,OAAO,CAAC,eAAe;qBAC3C,CAAC,CAAC;gBACL,CAAC;aACF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,UAAU,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO,CAAC,WAAW,EAAE,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,YAAY,CAAC,CAAC"}
@@ -47,15 +47,15 @@ export function registerFastifyRoutes(app, contextProvider, endpoints) {
47
47
  }
48
48
  }
49
49
  catch (ex) {
50
- const journeyError = errors.JourneyError.isJourneyError(ex) ? ex : new errors.InternalServerError(ex);
51
- logger.error(`Request failed`, journeyError);
50
+ const serviceError = errors.asServiceError(ex);
51
+ logger.error(`Request failed`, serviceError);
52
52
  response = new router.RouterResponse({
53
- status: journeyError.errorData.status || 500,
53
+ status: serviceError.errorData.status || 500,
54
54
  headers: {
55
55
  'Content-Type': 'application/json'
56
56
  },
57
57
  data: {
58
- error: journeyError.errorData
58
+ error: serviceError.errorData
59
59
  }
60
60
  });
61
61
  }
@@ -1 +1 @@
1
- {"version":3,"file":"route-register.js","sourceRo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AG,CAAC,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE;4BACxC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;4BACpF,MAAM,EAAE,QAAQ,CAAC,MAAM;4BACvB,MAAM,EAAE,CAAC,CAAC,MAAM;4BAChB,IAAI,EAAE,OAAO,CAAC,GAAG;4BACjB,KAAK,EAAE,CAAC,CAAC,IAAI;yBACd,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;aACF,CAAC,CAAC;YAEH,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,EAAE,CAAC;gBACvB,OAAO,CAAC,2BAA2B,EAAE,CAAC;YACxC,CAAC;YAED,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import * as bson from 'bson';
2
2
  import crypto from 'crypto';
3
3
  import * as uuid from 'uuid';
4
+ import { ServiceAssertionError } from '@powersync/lib-services-framework';
4
5
  export const ID_NAMESPACE = 'a396dd91-09fc-4017-a28d-3df722f651e9';
5
6
  export function escapeIdentifier(identifier) {
6
7
  return `"${identifier.replace(/"/g, '""').replace(/\./g, '"."')}"`;
@@ -21,7 +22,7 @@ export function timestampToOpId(ts) {
21
22
  // Dynamic values are passed in in some cases, so we make extra sure that the
22
23
  // number is a bigint and not number or Long.
23
24
  if (typeof ts != 'bigint') {
24
- throw new Error(`bigint expected, got: ${ts} (${typeof ts})`);
25
+ throw new ServiceAssertionError(`bigint expected, got: ${ts} (${typeof ts})`);
25
26
  }
26
27
  return ts.toString(10);
27
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":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ACpC,IAAI,IAAI,CAAC,CAAC;QACZ,CAAC;aAAM,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE,CAAC;YACpC,IAAI,IAAI,CAAC,CAAC;QACZ,CAAC;aAAM,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE,CAAC;YACpC,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC;QACvB,CAAC;aAAM,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;YACvC,IAAI,IAAI,KAAK,CAAC,UAAU,CAAC;QAC3B,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.0.0-dev-20250117095455",
8
+ "version": "0.0.0-dev-20250122110924",
9
9
  "main": "dist/index.js",
10
10
  "license": "FSL-1.1-Apache-2.0",
11
11
  "type": "module",
@@ -32,11 +32,11 @@
32
32
  "uuid": "^9.0.1",
33
33
  "winston": "^3.13.0",
34
34
  "yaml": "^2.3.2",
35
- "@powersync/lib-services-framework": "0.0.0-dev-20250117095455",
35
+ "@powersync/lib-services-framework": "0.0.0-dev-20250122110924",
36
36
  "@powersync/service-jsonbig": "0.17.10",
37
- "@powersync/service-rsocket-router": "0.0.0-dev-20250117095455",
38
- "@powersync/service-sync-rules": "0.23.1",
39
- "@powersync/service-types": "0.0.0-dev-20250117095455"
37
+ "@powersync/service-rsocket-router": "0.0.0-dev-20250122110924",
38
+ "@powersync/service-sync-rules": "0.0.0-dev-20250122110924",
39
+ "@powersync/service-types": "0.0.0-dev-20250122110924"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/async": "^3.2.24",
@@ -3,7 +3,13 @@ import * as https from 'https';
3
3
  import * as jose from 'jose';
4
4
  import fetch from 'node-fetch';
5
5
 
6
- import { LookupOptions, makeHostnameLookupFunction } from '@powersync/lib-services-framework';
6
+ import {
7
+ ErrorCode,
8
+ LookupOptions,
9
+ makeHostnameLookupFunction,
10
+ ServiceAssertionError,
11
+ ServiceError
12
+ } from '@powersync/lib-services-framework';
7
13
  import { KeyCollector, KeyResult } from './KeyCollector.js';
8
14
  import { KeySpec } from './KeySpec.js';
9
15
 
@@ -24,14 +30,17 @@ export class RemoteJWKSCollector implements KeyCollector {
24
30
  ) {
25
31
  try {
26
32
  this.url = new URL(url);
27
- } catch (e) {
28
- throw new Error(`Invalid jwks_uri: ${url}`);
33
+ } catch (e: any) {
34
+ throw new ServiceError(ErrorCode.PSYNC_S3102, `Invalid jwks_uri: ${JSON.stringify(url)} Details: ${e.message}`);
29
35
  }
30
36
 
31
37
  // We do support http here for self-hosting use cases.
32
38
  // Management service restricts this to https for hosted versions.
33
39
  if (this.url.protocol != 'https:' && this.url.protocol != 'http:') {
34
- throw new Error(`Only http(s) is supported for jwks_uri, got: ${url}`);
40
+ throw new ServiceError(
41
+ ErrorCode.PSYNC_S3103,
42
+ `Only http(s) is supported for jwks_uri, got: ${JSON.stringify(url)}`
43
+ );
35
44
  }
36
45
 
37
46
  this.agent = this.resolveAgent();
@@ -96,6 +105,9 @@ export class RemoteJWKSCollector implements KeyCollector {
96
105
 
97
106
  /**
98
107
  * Agent that uses a custom lookup function.
108
+ *
109
+ * This will synchronously raise an error if the URL contains an IP in the reject list.
110
+ * For domain names resolving to a rejected IP, that will fail when making the request.
99
111
  */
100
112
  resolveAgent(): http.Agent | https.Agent {
101
113
  const lookupOptions = this.options?.lookupOptions ?? { reject_ip_ranges: [] };
@@ -111,6 +123,7 @@ export class RemoteJWKSCollector implements KeyCollector {
111
123
  case 'https:':
112
124
  return new https.Agent(options);
113
125
  }
114
- throw new Error('http or or https is required for protocol');
126
+ // Already validated the URL before, so this is not expected
127
+ throw new ServiceAssertionError('http or or https is required for JWKS protocol');
115
128
  }
116
129
  }
@@ -6,6 +6,7 @@ import { registerCompactAction } from './commands/compact-action.js';
6
6
  import { registerMigrationAction } from './commands/migrate-action.js';
7
7
  import { registerStartAction } from './commands/start-action.js';
8
8
  import { registerTearDownAction } from './commands/teardown-action.js';
9
+ import { registerTestConnectionAction } from './commands/test-connection-action.js';
9
10
 
10
11
  /**
11
12
  * Generates a Commander program which serves as the entry point
@@ -20,6 +21,7 @@ export function generateEntryProgram(startHandlers?: Record<utils.ServiceRunner,
20
21
  registerTearDownAction(entryProgram);
21
22
  registerMigrationAction(entryProgram);
22
23
  registerCompactAction(entryProgram);
24
+ registerTestConnectionAction(entryProgram);
23
25
 
24
26
  if (startHandlers) {
25
27
  registerStartAction(entryProgram, startHandlers);
@@ -2,6 +2,7 @@ import { Command } from 'commander';
2
2
 
3
3
  import { teardown } from '../../runner/teardown.js';
4
4
  import { extractRunnerOptions, wrapConfigCommand } from './config-command.js';
5
+ import { ErrorCode, ServiceError } from '@powersync/lib-services-framework';
5
6
 
6
7
  const COMMAND_NAME = 'teardown';
7
8
 
@@ -15,7 +16,7 @@ export function registerTearDownAction(program: Command) {
15
16
  .description('Terminate all replicating sync rules, clear remote configuration and remove all data')
16
17
  .action(async (ack, options) => {
17
18
  if (ack !== 'TEARDOWN') {
18
- throw new Error('TEARDOWN was not acknowledged.');
19
+ throw new ServiceError(ErrorCode.PSYNC_S0102, 'TEARDOWN was not acknowledged.');
19
20
  }
20
21
 
21
22
  await teardown(extractRunnerOptions(options));
@@ -0,0 +1,41 @@
1
+ import { Command } from 'commander';
2
+
3
+ import { container, logger } from '@powersync/lib-services-framework';
4
+ import * as system from '../../system/system-index.js';
5
+ import * as utils from '../../util/util-index.js';
6
+
7
+ import { modules, ReplicationEngine } from '../../index.js';
8
+ import { extractRunnerOptions, wrapConfigCommand } from './config-command.js';
9
+
10
+ const COMMAND_NAME = 'test-connection';
11
+
12
+ export function registerTestConnectionAction(program: Command) {
13
+ const testConnectionCommand = program.command(COMMAND_NAME);
14
+
15
+ wrapConfigCommand(testConnectionCommand);
16
+
17
+ return testConnectionCommand.description('Test connection').action(async (options) => {
18
+ try {
19
+ const config = await utils.loadConfig(extractRunnerOptions(options));
20
+ const serviceContext = new system.ServiceContextContainer(config);
21
+
22
+ const replication = new ReplicationEngine();
23
+ serviceContext.register(ReplicationEngine, replication);
24
+
25
+ // Register modules in order to load the correct config
26
+ const moduleManager = container.getImplementation(modules.ModuleManager);
27
+ await moduleManager.initialize(serviceContext);
28
+
29
+ // Start the storage engine in order to create the appropriate BucketStorage
30
+ await serviceContext.lifeCycleEngine.start();
31
+
32
+ logger.info('Testing connection...');
33
+ const results = await replication.testConnection();
34
+ logger.info(`Connection succeeded to ${results.map((r) => r.connectionDescription).join(', ')}`);
35
+ process.exit(0);
36
+ } catch (e) {
37
+ logger.error(`Connection failed: ${e.message}`);
38
+ process.exit(1);
39
+ }
40
+ });
41
+ }
@@ -3,7 +3,7 @@ import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
3
3
  import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
4
4
  import { Resource } from '@opentelemetry/resources';
5
5
  import { MeterProvider, MetricReader, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
6
- import { logger } from '@powersync/lib-services-framework';
6
+ import { logger, ServiceAssertionError } from '@powersync/lib-services-framework';
7
7
  import * as storage from '../storage/storage-index.js';
8
8
  import * as util from '../util/util-index.js';
9
9
 
@@ -132,7 +132,7 @@ export class Metrics {
132
132
 
133
133
  public static getInstance(): Metrics {
134
134
  if (!Metrics.instance) {
135
- throw new Error('Metrics have not been initialised');
135
+ throw new ServiceAssertionError('Metrics have not been initialized');
136
136
  }
137
137
 
138
138
  return Metrics.instance;
@@ -6,6 +6,7 @@ import { StorageEngine } from '../storage/storage-index.js';
6
6
  import { SyncRulesProvider } from '../util/config/sync-rules/sync-rules-provider.js';
7
7
  import { AbstractReplicationJob } from './AbstractReplicationJob.js';
8
8
  import { ErrorRateLimiter } from './ErrorRateLimiter.js';
9
+ import { ConnectionTestResult } from './ReplicationModule.js';
9
10
 
10
11
  // 5 minutes
11
12
  const PING_INTERVAL = 1_000_000_000n * 300n;
@@ -225,4 +226,6 @@ export abstract class AbstractReplicator<T extends AbstractReplicationJob = Abst
225
226
  this.logger.warn(`Failed clean up replication config for sync rules: ${syncRuleStorage.group_id}`, e);
226
227
  }
227
228
  }
229
+
230
+ abstract testConnection(): Promise<ConnectionTestResult>;
228
231
  }
@@ -1,5 +1,6 @@
1
1
  import { logger } from '@powersync/lib-services-framework';
2
2
  import { AbstractReplicator } from './AbstractReplicator.js';
3
+ import { ConnectionTestResult } from './ReplicationModule.js';
3
4
 
4
5
  export class ReplicationEngine {
5
6
  private readonly replicators: Map<string, AbstractReplicator> = new Map();
@@ -40,4 +41,8 @@ export class ReplicationEngine {
40
41
  }
41
42
  logger.info('Successfully shut down Replication Engine.');
42
43
  }
44
+
45
+ public async testConnection(): Promise<ConnectionTestResult[]> {
46
+ return await Promise.all([...this.replicators.values()].map((replicator) => replicator.testConnection()));
47
+ }
43
48
  }
@@ -1,13 +1,19 @@
1
1
  import { DataSourceConfig } from '@powersync/service-types/dist/config/PowerSyncConfig.js';
2
2
  import * as t from 'ts-codec';
3
3
 
4
+ import { schema } from '@powersync/lib-services-framework';
4
5
  import * as types from '@powersync/service-types';
5
6
  import * as api from '../api/api-index.js';
6
7
  import * as modules from '../modules/modules-index.js';
7
8
  import * as system from '../system/system-index.js';
8
- import { schema } from '@powersync/lib-services-framework';
9
9
  import { AbstractReplicator } from './AbstractReplicator.js';
10
- import { TearDownOptions } from '../modules/modules-index.js';
10
+
11
+ export interface ConnectionTestResult {
12
+ /**
13
+ * Connection URI or hostname.
14
+ */
15
+ connectionDescription: string;
16
+ }
11
17
 
12
18
  /**
13
19
  * Provides a common interface for testing the connection to a DataSource.
@@ -17,7 +23,7 @@ export interface ConnectionTester<TConfig extends DataSourceConfig> {
17
23
  * Confirm if a connection can be established to the datasource for the provided datasource configuration
18
24
  * @param config
19
25
  */
20
- testConnection(config: TConfig): Promise<void>;
26
+ testConnection(config: TConfig): Promise<ConnectionTestResult>;
21
27
  }
22
28
 
23
29
  export interface ReplicationModuleOptions extends modules.AbstractModuleOptions {
@@ -58,7 +64,7 @@ export abstract class ReplicationModule<TConfig extends DataSourceConfig>
58
64
  */
59
65
  protected abstract createReplicator(context: system.ServiceContext): AbstractReplicator;
60
66
 
61
- public abstract testConnection(config: TConfig): Promise<void>;
67
+ public abstract testConnection(config: TConfig): Promise<ConnectionTestResult>;
62
68
 
63
69
  /**
64
70
  * Register this module's Replicators and RouteAPI adapters if the required configuration is present.
@@ -81,16 +87,12 @@ export abstract class ReplicationModule<TConfig extends DataSourceConfig>
81
87
  );
82
88
  }
83
89
 
84
- try {
85
- const baseMatchingConfig = matchingConfig[0] as TConfig;
86
- // If decoding fails, log the error and continue, no replication will happen for this data source
87
- this.decodeConfig(baseMatchingConfig);
90
+ const baseMatchingConfig = matchingConfig[0] as TConfig;
91
+ // If decoding fails, this will raise a hard error, and stop the service.
92
+ this.decodeConfig(baseMatchingConfig);
88
93
 
89
- context.replicationEngine?.register(this.createReplicator(context));
90
- context.routerEngine?.registerAPI(this.createRouteAPIAdapter());
91
- } catch (e) {
92
- this.logger.error('Failed to initialize.', e);
93
- }
94
+ context.replicationEngine?.register(this.createReplicator(context));
95
+ context.routerEngine?.registerAPI(this.createRouteAPIAdapter());
94
96
  }
95
97
 
96
98
  protected decodeConfig(config: TConfig): void {
@@ -1,4 +1,4 @@
1
- import { errors, router, schema } from '@powersync/lib-services-framework';
1
+ import { ErrorCode, errors, router, schema } from '@powersync/lib-services-framework';
2
2
  import { SqlSyncRules, StaticSchema } from '@powersync/service-sync-rules';
3
3
  import { internal_routes } from '@powersync/service-types';
4
4
 
@@ -120,9 +120,9 @@ export const reprocess = routeDefinition({
120
120
 
121
121
  const active = await activeBucketStorage.getActiveSyncRules(apiHandler.getParseSyncRulesOptions());
122
122
  if (active == null) {
123
- throw new errors.JourneyError({
123
+ throw new errors.ServiceError({
124
124
  status: 422,
125
- code: 'NO_SYNC_RULES',
125
+ code: ErrorCode.PSYNC_S4104,
126
126
  description: 'No active sync rules'
127
127
  });
128
128
  }
@@ -1,4 +1,4 @@
1
- import { errors, logger, schema } from '@powersync/lib-services-framework';
1
+ import { ErrorCode, errors, logger, schema } from '@powersync/lib-services-framework';
2
2
  import { RequestParameters } from '@powersync/service-sync-rules';
3
3
  import { serialize } from 'bson';
4
4
 
@@ -34,9 +34,9 @@ export const syncStreamReactive: SocketRouteGenerator = (router) =>
34
34
 
35
35
  if (routerEngine!.closed) {
36
36
  responder.onError(
37
- new errors.JourneyError({
37
+ new errors.ServiceError({
38
38
  status: 503,
39
- code: 'SERVICE_UNAVAILABLE',
39
+ code: ErrorCode.PSYNC_S2003,
40
40
  description: 'Service temporarily unavailable'
41
41
  })
42
42
  );
@@ -53,9 +53,9 @@ export const syncStreamReactive: SocketRouteGenerator = (router) =>
53
53
  const cp = await activeBucketStorage.getActiveCheckpoint();
54
54
  if (!cp.hasSyncRules()) {
55
55
  responder.onError(
56
- new errors.JourneyError({
56
+ new errors.ServiceError({
57
57
  status: 500,
58
- code: 'NO_SYNC_RULES',
58
+ code: ErrorCode.PSYNC_S2302,
59
59
  description: 'No sync rules available'
60
60
  })
61
61
  );
@@ -1,4 +1,4 @@
1
- import { errors, router, schema } from '@powersync/lib-services-framework';
1
+ import { ErrorCode, errors, router, schema } from '@powersync/lib-services-framework';
2
2
  import { SqlSyncRules, SyncRulesErrors } from '@powersync/service-sync-rules';
3
3
  import type { FastifyPluginAsync } from 'fastify';
4
4
  import * as t from 'ts-codec';
@@ -43,9 +43,9 @@ export const deploySyncRules = routeDefinition({
43
43
 
44
44
  if (service_context.configuration.sync_rules.present) {
45
45
  // If sync rules are configured via the config, disable deploy via the API.
46
- throw new errors.JourneyError({
46
+ throw new errors.ServiceError({
47
47
  status: 422,
48
- code: 'API_DISABLED',
48
+ code: ErrorCode.PSYNC_S4105,
49
49
  description: 'Sync rules API disabled',
50
50
  details: 'Use the management API to deploy sync rules'
51
51
  });
@@ -60,9 +60,9 @@ export const deploySyncRules = routeDefinition({
60
60
  schema: undefined
61
61
  });
62
62
  } catch (e) {
63
- throw new errors.JourneyError({
63
+ throw new errors.ServiceError({
64
64
  status: 422,
65
- code: 'INVALID_SYNC_RULES',
65
+ code: ErrorCode.PSYNC_R0001,
66
66
  description: 'Sync rules parsing failed',
67
67
  details: e.message
68
68
  });
@@ -112,9 +112,9 @@ export const currentSyncRules = routeDefinition({
112
112
 
113
113
  const sync_rules = await activeBucketStorage.getActiveSyncRulesContent();
114
114
  if (!sync_rules) {
115
- throw new errors.JourneyError({
115
+ throw new errors.ServiceError({
116
116
  status: 422,
117
- code: 'NO_SYNC_RULES',
117
+ code: ErrorCode.PSYNC_S4104,
118
118
  description: 'No active sync rules'
119
119
  });
120
120
  }
@@ -159,9 +159,9 @@ export const reprocessSyncRules = routeDefinition({
159
159
  const apiHandler = payload.context.service_context.routerEngine!.getAPI();
160
160
  const sync_rules = await activeBucketStorage.getActiveSyncRules(apiHandler.getParseSyncRulesOptions());
161
161
  if (sync_rules == null) {
162
- throw new errors.JourneyError({
162
+ throw new errors.ServiceError({
163
163
  status: 422,
164
- code: 'NO_SYNC_RULES',
164
+ code: ErrorCode.PSYNC_S4104,
165
165
  description: 'No active sync rules'
166
166
  });
167
167
  }
@@ -1,4 +1,4 @@
1
- import { errors, logger, router, schema } from '@powersync/lib-services-framework';
1
+ import { ErrorCode, errors, logger, router, schema } from '@powersync/lib-services-framework';
2
2
  import { RequestParameters } from '@powersync/service-sync-rules';
3
3
  import { Readable } from 'stream';
4
4
 
@@ -26,9 +26,9 @@ export const syncStreamed = routeDefinition({
26
26
  const clientId = payload.params.client_id;
27
27
 
28
28
  if (routerEngine!.closed) {
29
- throw new errors.JourneyError({
29
+ throw new errors.ServiceError({
30
30
  status: 503,
31
- code: 'SERVICE_UNAVAILABLE',
31
+ code: ErrorCode.PSYNC_S2003,
32
32
  description: 'Service temporarily unavailable'
33
33
  });
34
34
  }
@@ -39,9 +39,9 @@ export const syncStreamed = routeDefinition({
39
39
  // Sanity check before we start the stream
40
40
  const cp = await storageEngine.activeBucketStorage.getActiveCheckpoint();
41
41
  if (!cp.hasSyncRules()) {
42
- throw new errors.JourneyError({
42
+ throw new errors.ServiceError({
43
43
  status: 500,
44
- code: 'NO_SYNC_RULES',
44
+ code: ErrorCode.PSYNC_S2302,
45
45
  description: 'No sync rules available'
46
46
  });
47
47
  }
@@ -62,16 +62,16 @@ export function registerFastifyRoutes(
62
62
  });
63
63
  }
64
64
  } catch (ex) {
65
- const journeyError = errors.JourneyError.isJourneyError(ex) ? ex : new errors.InternalServerError(ex);
66
- logger.error(`Request failed`, journeyError);
65
+ const serviceError = errors.asServiceError(ex);
66
+ logger.error(`Request failed`, serviceError);
67
67
 
68
68
  response = new router.RouterResponse({
69
- status: journeyError.errorData.status || 500,
69
+ status: serviceError.errorData.status || 500,
70
70
  headers: {
71
71
  'Content-Type': 'application/json'
72
72
  },
73
73
  data: {
74
- error: journeyError.errorData
74
+ error: serviceError.errorData
75
75
  }
76
76
  });
77
77
  }
package/src/util/utils.ts CHANGED
@@ -7,6 +7,7 @@ import { BucketChecksum, OpId, OplogEntry } from './protocol-types.js';
7
7
  import * as storage from '../storage/storage-index.js';
8
8
 
9
9
  import { PartialChecksum } from '../storage/ChecksumCache.js';
10
+ import { ServiceAssertionError } from '@powersync/lib-services-framework';
10
11
 
11
12
  export type ChecksumMap = Map<string, BucketChecksum>;
12
13
 
@@ -34,7 +35,7 @@ export function timestampToOpId(ts: bigint): OpId {
34
35
  // Dynamic values are passed in in some cases, so we make extra sure that the
35
36
  // number is a bigint and not number or Long.
36
37
  if (typeof ts != 'bigint') {
37
- throw new Error(`bigint expected, got: ${ts} (${typeof ts})`);
38
+ throw new ServiceAssertionError(`bigint expected, got: ${ts} (${typeof ts})`);
38
39
  }
39
40
  return ts.toString(10);
40
41
  }