@powersync/service-core 0.0.0-dev-20241021185145 → 0.0.0-dev-20241022094219

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
@@ -1,6 +1,6 @@
1
1
  # @powersync/service-core
2
2
 
3
- ## 0.0.0-dev-20241021185145
3
+ ## 0.0.0-dev-20241022094219
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -22,10 +22,10 @@
22
22
  - Updated dependencies [d2ece1b]
23
23
  - Updated dependencies [d51921f]
24
24
  - Updated dependencies [4ecaee2]
25
- - @powersync/lib-services-framework@0.0.0-dev-20241021185145
26
- - @powersync/service-sync-rules@0.0.0-dev-20241021185145
27
- - @powersync/service-rsocket-router@0.0.0-dev-20241021185145
28
- - @powersync/service-types@0.0.0-dev-20241021185145
25
+ - @powersync/lib-services-framework@0.0.0-dev-20241022094219
26
+ - @powersync/service-sync-rules@0.0.0-dev-20241022094219
27
+ - @powersync/service-rsocket-router@0.0.0-dev-20241022094219
28
+ - @powersync/service-types@0.0.0-dev-20241022094219
29
29
 
30
30
  ## 0.8.5
31
31
 
@@ -4,6 +4,16 @@ import * as api from '../api/api-index.js';
4
4
  import * as modules from '../modules/modules-index.js';
5
5
  import * as system from '../system/system-index.js';
6
6
  import { AbstractReplicator } from './AbstractReplicator.js';
7
+ /**
8
+ * Provides a common interface for testing the connection to a DataSource.
9
+ */
10
+ export interface ConnectionTester<TConfig extends DataSourceConfig> {
11
+ /**
12
+ * Confirm if a connection can be established to the datasource for the provided datasource configuration
13
+ * @param config
14
+ */
15
+ testConnection(config: TConfig): Promise<void>;
16
+ }
7
17
  export interface ReplicationModuleOptions extends modules.AbstractModuleOptions {
8
18
  type: string;
9
19
  configSchema: t.AnyCodec;
@@ -12,7 +22,7 @@ export interface ReplicationModuleOptions extends modules.AbstractModuleOptions
12
22
  * A replication module describes all the functionality that PowerSync requires to
13
23
  * replicate data from a DataSource. Whenever a new data source is added to powersync this class should be extended.
14
24
  */
15
- export declare abstract class ReplicationModule<TConfig extends DataSourceConfig> extends modules.AbstractModule {
25
+ export declare abstract class ReplicationModule<TConfig extends DataSourceConfig> extends modules.AbstractModule implements ConnectionTester<TConfig> {
16
26
  protected type: string;
17
27
  protected configSchema: t.AnyCodec;
18
28
  protected decodedConfig: TConfig | undefined;
@@ -30,10 +40,12 @@ export declare abstract class ReplicationModule<TConfig extends DataSourceConfig
30
40
  * Create the Replicator to be used by the ReplicationEngine.
31
41
  */
32
42
  protected abstract createReplicator(context: system.ServiceContext): AbstractReplicator;
43
+ abstract testConnection(config: TConfig): Promise<void>;
33
44
  /**
34
45
  * Register this module's Replicators and RouteAPI adapters if the required configuration is present.
35
46
  */
36
47
  initialize(context: system.ServiceContext): Promise<void>;
48
+ protected decodeConfig(config: TConfig): void;
37
49
  private validateConfig;
38
50
  protected getDefaultId(dataSourceName: string): string;
39
51
  }
@@ -26,10 +26,7 @@ export class ReplicationModule extends modules.AbstractModule {
26
26
  }
27
27
  const matchingConfig = context.configuration.connections.filter((dataSource) => dataSource.type === this.type);
28
28
  if (!matchingConfig.length) {
29
- // This module is needed given the config
30
- return;
31
- }
32
- if (!matchingConfig.length) {
29
+ // No configuration for this module was found
33
30
  return;
34
31
  }
35
32
  if (matchingConfig.length > 1) {
@@ -37,9 +34,8 @@ export class ReplicationModule extends modules.AbstractModule {
37
34
  }
38
35
  try {
39
36
  const baseMatchingConfig = matchingConfig[0];
40
- // If validation fails, log the error and continue, no replication will happen for this data source
41
- this.validateConfig(baseMatchingConfig);
42
- this.decodedConfig = this.configSchema.decode(baseMatchingConfig);
37
+ // If decoding fails, log the error and continue, no replication will happen for this data source
38
+ this.decodeConfig(baseMatchingConfig);
43
39
  context.replicationEngine?.register(this.createReplicator(context));
44
40
  context.routerEngine?.registerAPI(this.createRouteAPIAdapter());
45
41
  }
@@ -47,6 +43,10 @@ export class ReplicationModule extends modules.AbstractModule {
47
43
  this.logger.error('Failed to initialize.', e);
48
44
  }
49
45
  }
46
+ decodeConfig(config) {
47
+ this.validateConfig(config);
48
+ this.decodedConfig = this.configSchema.decode(config);
49
+ }
50
50
  validateConfig(config) {
51
51
  const validator = schema
52
52
  .parseJSONSchema(
@@ -1 +1 @@
1
- {"version":3,"file":"ReplicationModule.js","sourceRoot":"","sources":["../../src/replication/ReplicationModule.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,OAAO,KAAK,KAAK,MAAM,0BAA0B,CAAC;AAElD,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAQ3D;;;GAGG;AACH,MAAM,OAAgB,iBAAoD,SAAQ,OAAO,CAAC,cAAc;IAKtG;;;OAGG;IACH,YAAsB,OAAiC;QACrD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAaD;;OAEG;IACI,KAAK,CAAC,UAAU,CAAC,OAA8B;QACpD,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;YACvC,gEAAgE;YAChE,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/G,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;YAC3B,yCAAyC;YACzC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;YAC3B,OAAO;QACT,CAAC;QAED,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,MAAM,CAAC,OAAO,CACjB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9
  "main": "dist/index.js",
10
10
  "license": "FSL-1.1-Apache-2.0",
11
11
  "type": "module",
@@ -33,11 +33,11 @@
33
33
  "uuid": "^9.0.1",
34
34
  "winston": "^3.13.0",
35
35
  "yaml": "^2.3.2",
36
- "@powersync/lib-services-framework": "0.0.0-dev-20241021185145",
36
+ "@powersync/lib-services-framework": "0.0.0-dev-20241022094219",
37
37
  "@powersync/service-jsonbig": "0.17.10",
38
- "@powersync/service-rsocket-router": "0.0.0-dev-20241021185145",
39
- "@powersync/service-sync-rules": "0.0.0-dev-20241021185145",
40
- "@powersync/service-types": "0.0.0-dev-20241021185145"
38
+ "@powersync/service-rsocket-router": "0.0.0-dev-20241022094219",
39
+ "@powersync/service-sync-rules": "0.0.0-dev-20241022094219",
40
+ "@powersync/service-types": "0.0.0-dev-20241022094219"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/async": "^3.2.24",
@@ -7,6 +7,18 @@ import * as modules from '../modules/modules-index.js';
7
7
  import * as system from '../system/system-index.js';
8
8
  import { schema } from '@powersync/lib-services-framework';
9
9
  import { AbstractReplicator } from './AbstractReplicator.js';
10
+ import { TearDownOptions } from '../modules/modules-index.js';
11
+
12
+ /**
13
+ * Provides a common interface for testing the connection to a DataSource.
14
+ */
15
+ export interface ConnectionTester<TConfig extends DataSourceConfig> {
16
+ /**
17
+ * Confirm if a connection can be established to the datasource for the provided datasource configuration
18
+ * @param config
19
+ */
20
+ testConnection(config: TConfig): Promise<void>;
21
+ }
10
22
 
11
23
  export interface ReplicationModuleOptions extends modules.AbstractModuleOptions {
12
24
  type: string;
@@ -17,7 +29,10 @@ export interface ReplicationModuleOptions extends modules.AbstractModuleOptions
17
29
  * A replication module describes all the functionality that PowerSync requires to
18
30
  * replicate data from a DataSource. Whenever a new data source is added to powersync this class should be extended.
19
31
  */
20
- export abstract class ReplicationModule<TConfig extends DataSourceConfig> extends modules.AbstractModule {
32
+ export abstract class ReplicationModule<TConfig extends DataSourceConfig>
33
+ extends modules.AbstractModule
34
+ implements ConnectionTester<TConfig>
35
+ {
21
36
  protected type: string;
22
37
  protected configSchema: t.AnyCodec;
23
38
  protected decodedConfig: TConfig | undefined;
@@ -43,6 +58,8 @@ export abstract class ReplicationModule<TConfig extends DataSourceConfig> extend
43
58
  */
44
59
  protected abstract createReplicator(context: system.ServiceContext): AbstractReplicator;
45
60
 
61
+ public abstract testConnection(config: TConfig): Promise<void>;
62
+
46
63
  /**
47
64
  * Register this module's Replicators and RouteAPI adapters if the required configuration is present.
48
65
  */
@@ -54,11 +71,7 @@ export abstract class ReplicationModule<TConfig extends DataSourceConfig> extend
54
71
 
55
72
  const matchingConfig = context.configuration.connections.filter((dataSource) => dataSource.type === this.type);
56
73
  if (!matchingConfig.length) {
57
- // This module is needed given the config
58
- return;
59
- }
60
-
61
- if (!matchingConfig.length) {
74
+ // No configuration for this module was found
62
75
  return;
63
76
  }
64
77
 
@@ -70,9 +83,8 @@ export abstract class ReplicationModule<TConfig extends DataSourceConfig> extend
70
83
 
71
84
  try {
72
85
  const baseMatchingConfig = matchingConfig[0] as TConfig;
73
- // If validation fails, log the error and continue, no replication will happen for this data source
74
- this.validateConfig(baseMatchingConfig);
75
- this.decodedConfig = this.configSchema.decode(baseMatchingConfig);
86
+ // If decoding fails, log the error and continue, no replication will happen for this data source
87
+ this.decodeConfig(baseMatchingConfig);
76
88
 
77
89
  context.replicationEngine?.register(this.createReplicator(context));
78
90
  context.routerEngine?.registerAPI(this.createRouteAPIAdapter());
@@ -81,6 +93,11 @@ export abstract class ReplicationModule<TConfig extends DataSourceConfig> extend
81
93
  }
82
94
  }
83
95
 
96
+ protected decodeConfig(config: TConfig): void {
97
+ this.validateConfig(config);
98
+ this.decodedConfig = this.configSchema.decode(config);
99
+ }
100
+
84
101
  private validateConfig(config: TConfig): void {
85
102
  const validator = schema
86
103
  .parseJSONSchema(