@powersync/service-core 0.0.0-dev-20250507132759 → 0.0.0-dev-20250507151436
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 +24 -4
- package/dist/entry/commands/compact-action.js +4 -1
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/entry/commands/migrate-action.js +4 -1
- package/dist/entry/commands/migrate-action.js.map +1 -1
- package/dist/entry/commands/test-connection-action.js +4 -1
- package/dist/entry/commands/test-connection-action.js.map +1 -1
- package/dist/routes/RouterEngine.d.ts +2 -0
- package/dist/routes/RouterEngine.js +15 -10
- package/dist/routes/RouterEngine.js.map +1 -1
- package/dist/routes/configure-fastify.js +0 -4
- package/dist/routes/configure-fastify.js.map +1 -1
- package/dist/routes/configure-rsocket.js +0 -3
- package/dist/routes/configure-rsocket.js.map +1 -1
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/checkpointing.js.map +1 -1
- package/dist/routes/endpoints/route-endpoints-index.d.ts +1 -0
- package/dist/routes/endpoints/route-endpoints-index.js +1 -0
- package/dist/routes/endpoints/route-endpoints-index.js.map +1 -1
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/routes/router.d.ts +1 -4
- package/dist/routes/router.js.map +1 -1
- package/dist/runner/teardown.js +4 -1
- package/dist/runner/teardown.js.map +1 -1
- package/dist/system/ServiceContext.d.ts +19 -4
- package/dist/system/ServiceContext.js +20 -8
- package/dist/system/ServiceContext.js.map +1 -1
- package/dist/util/config/collectors/config-collector.js +7 -30
- package/dist/util/config/collectors/config-collector.js.map +1 -1
- package/dist/util/config/collectors/impl/yaml-env.d.ts +7 -0
- package/dist/util/config/collectors/impl/yaml-env.js +59 -0
- package/dist/util/config/collectors/impl/yaml-env.js.map +1 -0
- package/dist/util/config/compound-config-collector.js +18 -1
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/config/types.d.ts +11 -0
- package/package.json +4 -4
- package/src/entry/commands/compact-action.ts +4 -1
- package/src/entry/commands/migrate-action.ts +4 -1
- package/src/entry/commands/test-connection-action.ts +4 -1
- package/src/routes/RouterEngine.ts +21 -11
- package/src/routes/configure-fastify.ts +2 -7
- package/src/routes/configure-rsocket.ts +0 -4
- package/src/routes/endpoints/admin.ts +5 -5
- package/src/routes/endpoints/checkpointing.ts +2 -2
- package/src/routes/endpoints/route-endpoints-index.ts +1 -0
- package/src/routes/endpoints/socket-route.ts +3 -3
- package/src/routes/endpoints/sync-rules.ts +4 -4
- package/src/routes/endpoints/sync-stream.ts +3 -3
- package/src/routes/router.ts +2 -1
- package/src/runner/teardown.ts +5 -1
- package/src/system/ServiceContext.ts +31 -12
- package/src/util/config/collectors/config-collector.ts +9 -36
- package/src/util/config/collectors/impl/yaml-env.ts +67 -0
- package/src/util/config/compound-config-collector.ts +22 -5
- package/src/util/config/types.ts +13 -0
- package/test/src/config.test.ts +72 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-collector.js","sourceRoot":"","sources":["../../../../src/util/config/collectors/config-collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"config-collector.js","sourceRoot":"","sources":["../../../../src/util/config/collectors/config-collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,MAAM,CAAN,I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CAAC,OAAe;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as yaml from 'yaml';
|
|
2
|
+
/**
|
|
3
|
+
* Custom YAML tag which performs string environment variable substitution
|
|
4
|
+
* Allows for type casting string environment variables to boolean or number
|
|
5
|
+
* by using the syntax !env PS_MONGO_PORT::number or !env PS_USE_SUPABASE::boolean
|
|
6
|
+
*/
|
|
7
|
+
export declare const YamlEnvTag: yaml.ScalarTag;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment variables can be substituted into the YAML config
|
|
3
|
+
* when parsing if the environment variable name starts with this prefix.
|
|
4
|
+
* Attempting to substitute any other environment variable will throw an exception.
|
|
5
|
+
*
|
|
6
|
+
* Example of substitution:
|
|
7
|
+
* storage:
|
|
8
|
+
* type: mongodb
|
|
9
|
+
* uri: !env PS_MONGO_URI
|
|
10
|
+
*/
|
|
11
|
+
const YAML_ENV_PREFIX = 'PS_';
|
|
12
|
+
/**
|
|
13
|
+
* Custom YAML tag which performs string environment variable substitution
|
|
14
|
+
* Allows for type casting string environment variables to boolean or number
|
|
15
|
+
* by using the syntax !env PS_MONGO_PORT::number or !env PS_USE_SUPABASE::boolean
|
|
16
|
+
*/
|
|
17
|
+
export const YamlEnvTag = {
|
|
18
|
+
tag: '!env',
|
|
19
|
+
resolve(envName, onError) {
|
|
20
|
+
if (!envName.startsWith(YAML_ENV_PREFIX)) {
|
|
21
|
+
onError(`Attempting to substitute environment variable ${envName} is not allowed. Variables must start with "${YAML_ENV_PREFIX}"`);
|
|
22
|
+
return envName;
|
|
23
|
+
}
|
|
24
|
+
// allow type casting if the envName contains a type suffix
|
|
25
|
+
// e.g. PS_MONGO_PORT::number or PS_USE_SUPABASE::boolean
|
|
26
|
+
const [name, type = 'string'] = envName.split('::');
|
|
27
|
+
let value = process.env[name];
|
|
28
|
+
if (typeof value == 'undefined') {
|
|
29
|
+
onError(`Attempted to substitute environment variable "${envName}" which is undefined. Set this variable on the environment.`);
|
|
30
|
+
return envName;
|
|
31
|
+
}
|
|
32
|
+
switch (type) {
|
|
33
|
+
case 'string':
|
|
34
|
+
return value;
|
|
35
|
+
case 'number':
|
|
36
|
+
const numberValue = Number(value);
|
|
37
|
+
if (Number.isNaN(numberValue)) {
|
|
38
|
+
onError(`Environment variable "${envName}" is not a valid number. Got: "${value}".`);
|
|
39
|
+
return envName;
|
|
40
|
+
}
|
|
41
|
+
return numberValue;
|
|
42
|
+
case 'boolean':
|
|
43
|
+
if (value?.toLowerCase() == 'true') {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
else if (value?.toLowerCase() == 'false') {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
onError(`Environment variable "${envName}" is not a boolean. Expected "true" or "false", got "${value}".`);
|
|
51
|
+
return envName;
|
|
52
|
+
}
|
|
53
|
+
default:
|
|
54
|
+
onError(`Environment variable "${envName}" has an invalid type suffix "${type}".`);
|
|
55
|
+
return envName;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=yaml-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-env.js","sourceRoot":"","sources":["../../../../../src/util/config/collectors/impl/yaml-env.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAmB;IACxC,GAAG,EAAE,MAAM;IACX,OAAO,CAAC,OAAe,EAAE,OAAgC;QACvD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;YACzC,OAAO,CACL,iDAAiD,OAAO,+CAA+C,eAAe,GAAG,CAC1H,CAAC;YACF,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,2DAA2D;QAC3D,yDAAyD;QACzD,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEpD,IAAI,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAE9B,IAAI,OAAO,KAAK,IAAI,WAAW,EAAE,CAAC;YAChC,OAAO,CACL,iDAAiD,OAAO,6DAA6D,CACtH,CAAC;YACF,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,QAAQ;gBACX,OAAO,KAAK,CAAC;YACf,KAAK,QAAQ;gBACX,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;gBAClC,IAAI,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC;oBAC9B,OAAO,CAAC,yBAAyB,OAAO,kCAAkC,KAAK,IAAI,CAAC,CAAC;oBACrF,OAAO,OAAO,CAAC;gBACjB,CAAC;gBACD,OAAO,WAAW,CAAC;YACrB,KAAK,SAAS;gBACZ,IAAI,KAAK,EAAE,WAAW,EAAE,IAAI,MAAM,EAAE,CAAC;oBACnC,OAAO,IAAI,CAAC;gBACd,CAAC;qBAAM,IAAI,KAAK,EAAE,WAAW,EAAE,IAAI,OAAO,EAAE,CAAC;oBAC3C,OAAO,KAAK,CAAC;gBACf,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,yBAAyB,OAAO,wDAAwD,KAAK,IAAI,CAAC,CAAC;oBAC3G,OAAO,OAAO,CAAC;gBACjB,CAAC;YACH;gBACE,OAAO,CAAC,yBAAyB,OAAO,iCAAiC,IAAI,IAAI,CAAC,CAAC;gBACnF,OAAO,OAAO,CAAC;QACnB,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -3,10 +3,10 @@ import * as auth from '../../auth/auth-index.js';
|
|
|
3
3
|
import { Base64ConfigCollector } from './collectors/impl/base64-config-collector.js';
|
|
4
4
|
import { FallbackConfigCollector } from './collectors/impl/fallback-config-collector.js';
|
|
5
5
|
import { FileSystemConfigCollector } from './collectors/impl/filesystem-config-collector.js';
|
|
6
|
+
import { DEFAULT_MAX_BUCKETS_PER_CONNECTION, DEFAULT_MAX_CONCURRENT_CONNECTIONS, DEFAULT_MAX_DATA_FETCH_CONCURRENCY, DEFAULT_MAX_PARAMETER_QUERY_RESULTS, DEFAULT_MAX_POOL_SIZE } from './defaults.js';
|
|
6
7
|
import { Base64SyncRulesCollector } from './sync-rules/impl/base64-sync-rules-collector.js';
|
|
7
8
|
import { FileSystemSyncRulesCollector } from './sync-rules/impl/filesystem-sync-rules-collector.js';
|
|
8
9
|
import { InlineSyncRulesCollector } from './sync-rules/impl/inline-sync-rules-collector.js';
|
|
9
|
-
import { DEFAULT_MAX_BUCKETS_PER_CONNECTION, DEFAULT_MAX_CONCURRENT_CONNECTIONS, DEFAULT_MAX_DATA_FETCH_CONCURRENCY, DEFAULT_MAX_PARAMETER_QUERY_RESULTS, DEFAULT_MAX_POOL_SIZE } from './defaults.js';
|
|
10
10
|
const POWERSYNC_DEV_KID = 'powersync-dev';
|
|
11
11
|
const DEFAULT_COLLECTOR_OPTIONS = {
|
|
12
12
|
configCollectors: [new Base64ConfigCollector(), new FileSystemConfigCollector(), new FallbackConfigCollector()],
|
|
@@ -107,6 +107,23 @@ export class CompoundConfigCollector {
|
|
|
107
107
|
disable_telemetry_sharing: baseConfig.telemetry?.disable_telemetry_sharing ?? false,
|
|
108
108
|
internal_service_endpoint: baseConfig.telemetry?.internal_service_endpoint ?? 'https://pulse.journeyapps.com/v1/metrics'
|
|
109
109
|
},
|
|
110
|
+
healthcheck: {
|
|
111
|
+
/**
|
|
112
|
+
* Default to legacy mode if no probes config is provided.
|
|
113
|
+
* If users provide a config, all options require explicit opt-in.
|
|
114
|
+
*/
|
|
115
|
+
probes: baseConfig.healthcheck?.probes
|
|
116
|
+
? {
|
|
117
|
+
use_filesystem: baseConfig.healthcheck.probes.use_filesystem ?? false,
|
|
118
|
+
use_http: baseConfig.healthcheck.probes.use_http ?? false,
|
|
119
|
+
use_legacy: baseConfig.healthcheck.probes.use_legacy ?? false
|
|
120
|
+
}
|
|
121
|
+
: {
|
|
122
|
+
use_filesystem: false,
|
|
123
|
+
use_http: false,
|
|
124
|
+
use_legacy: true
|
|
125
|
+
}
|
|
126
|
+
},
|
|
110
127
|
api_parameters: {
|
|
111
128
|
max_buckets_per_connection: baseConfig.api?.parameters?.max_buckets_per_connection ?? DEFAULT_MAX_BUCKETS_PER_CONNECTION,
|
|
112
129
|
max_parameter_query_results: baseConfig.api?.parameters?.max_parameter_query_results ?? DEFAULT_MAX_PARAMETER_QUERY_RESULTS,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compound-config-collector.js","sourceRoot":"","sources":["../../../src/util/config/compound-config-collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,mCAAmC,CAAC;AAE1E,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,kDAAkD,CAAC;AAC7F,OAAO,
|
|
1
|
+
{"version":3,"file":"compound-config-collector.js","sourceRoot":"","sources":["../../../src/util/config/compound-config-collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,mCAAmC,CAAC;AAE1E,OAAO,KAAK,IAAI,MAAM,0BAA0B,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,kDAAkD,CAAC;AAC7F,OAAO,EACL,kCAAkC,EAClC,kCAAkC,EAClC,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,CAAC;YAAC,OAAO,EAAE,EAAE,CAAC;gBACZ,yCAAyC;gBACzC,MAAM,IAAI,KAAK,CAAC,sCAAsC,SAAS,CAAC,IAAI,8BAA8B,EAAE,EAAE,CAAC,CAAC;YAC1G,CAAC;QACH,CAAC;QACD,OAAO;YACL,OAAO,EAAE,KAAK;YACd,aAAa,EAAE,IAAI;SACpB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -60,5 +60,16 @@ export type ResolvedPowerSyncConfig = {
|
|
|
60
60
|
};
|
|
61
61
|
/** Prefix for postgres replication slot names. May eventually be connection-specific. */
|
|
62
62
|
slot_name_prefix: string;
|
|
63
|
+
healthcheck: {
|
|
64
|
+
probes: {
|
|
65
|
+
use_filesystem: boolean;
|
|
66
|
+
use_http: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated This maintains backwards compatibility with the legacy default.
|
|
69
|
+
* Explicit probe configuration should be used instead.
|
|
70
|
+
*/
|
|
71
|
+
use_legacy: boolean;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
63
74
|
parameters: Record<string, number | string | boolean | null>;
|
|
64
75
|
};
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.0.0-dev-
|
|
8
|
+
"version": "0.0.0-dev-20250507151436",
|
|
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.
|
|
35
|
+
"@powersync/lib-services-framework": "0.0.0-dev-20250507151436",
|
|
36
36
|
"@powersync/service-jsonbig": "0.17.10",
|
|
37
|
-
"@powersync/service-rsocket-router": "0.0.
|
|
37
|
+
"@powersync/service-rsocket-router": "0.0.0-dev-20250507151436",
|
|
38
38
|
"@powersync/service-sync-rules": "0.26.0",
|
|
39
|
-
"@powersync/service-types": "0.
|
|
39
|
+
"@powersync/service-types": "0.10.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/async": "^3.2.24",
|
|
@@ -37,7 +37,10 @@ export function registerCompactAction(program: Command) {
|
|
|
37
37
|
logger.info(`Compacting storage for ${buckets?.join(', ')}...`);
|
|
38
38
|
}
|
|
39
39
|
const config = await utils.loadConfig(extractRunnerOptions(options));
|
|
40
|
-
const serviceContext = new system.ServiceContextContainer(
|
|
40
|
+
const serviceContext = new system.ServiceContextContainer({
|
|
41
|
+
serviceMode: system.ServiceContextMode.COMPACT,
|
|
42
|
+
configuration: config
|
|
43
|
+
});
|
|
41
44
|
|
|
42
45
|
// Register modules in order to allow custom module compacting
|
|
43
46
|
const moduleManager = container.getImplementation(modules.ModuleManager);
|
|
@@ -18,7 +18,10 @@ export function registerMigrationAction(program: Command) {
|
|
|
18
18
|
.argument('<direction>', 'Migration direction. `up` or `down`')
|
|
19
19
|
.action(async (direction: migrations.Direction, options) => {
|
|
20
20
|
const config = await utils.loadConfig(extractRunnerOptions(options));
|
|
21
|
-
const serviceContext = new system.ServiceContextContainer(
|
|
21
|
+
const serviceContext = new system.ServiceContextContainer({
|
|
22
|
+
serviceMode: system.ServiceContextMode.MIGRATION,
|
|
23
|
+
configuration: config
|
|
24
|
+
});
|
|
22
25
|
|
|
23
26
|
// Register modules in order to allow custom module migrations
|
|
24
27
|
const moduleManager = container.getImplementation(modules.ModuleManager);
|
|
@@ -17,7 +17,10 @@ export function registerTestConnectionAction(program: Command) {
|
|
|
17
17
|
return testConnectionCommand.description('Test connection').action(async (options) => {
|
|
18
18
|
try {
|
|
19
19
|
const config = await utils.loadConfig(extractRunnerOptions(options));
|
|
20
|
-
const serviceContext = new system.ServiceContextContainer(
|
|
20
|
+
const serviceContext = new system.ServiceContextContainer({
|
|
21
|
+
serviceMode: system.ServiceContextMode.TEST_CONNECTION,
|
|
22
|
+
configuration: config
|
|
23
|
+
});
|
|
21
24
|
|
|
22
25
|
const replication = new ReplicationEngine();
|
|
23
26
|
serviceContext.register(ReplicationEngine, replication);
|
|
@@ -2,15 +2,8 @@ import { logger } from '@powersync/lib-services-framework';
|
|
|
2
2
|
|
|
3
3
|
import * as api from '../api/api-index.js';
|
|
4
4
|
|
|
5
|
-
import { ADMIN_ROUTES } from './endpoints/admin.js';
|
|
6
|
-
import { CHECKPOINT_ROUTES } from './endpoints/checkpointing.js';
|
|
7
|
-
import { PROBES_ROUTES } from './endpoints/probes.js';
|
|
8
|
-
import { syncStreamReactive } from './endpoints/socket-route.js';
|
|
9
|
-
import { SYNC_RULES_ROUTES } from './endpoints/sync-rules.js';
|
|
10
|
-
import { SYNC_STREAM_ROUTES } from './endpoints/sync-stream.js';
|
|
11
5
|
import { SocketRouteGenerator } from './router-socket.js';
|
|
12
6
|
import { RouteDefinition } from './router.js';
|
|
13
|
-
import { SyncContext } from '../sync/SyncContext.js';
|
|
14
7
|
|
|
15
8
|
export type RouterSetupResponse = {
|
|
16
9
|
onShutdown: () => Promise<void>;
|
|
@@ -47,14 +40,25 @@ export class RouterEngine {
|
|
|
47
40
|
this.cleanupHandler = null;
|
|
48
41
|
this.closed = false;
|
|
49
42
|
|
|
50
|
-
// Default routes
|
|
51
43
|
this.routes = {
|
|
52
|
-
api_routes: [
|
|
53
|
-
stream_routes: [
|
|
54
|
-
socket_routes: [
|
|
44
|
+
api_routes: [],
|
|
45
|
+
stream_routes: [],
|
|
46
|
+
socket_routes: []
|
|
55
47
|
};
|
|
56
48
|
}
|
|
57
49
|
|
|
50
|
+
public registerRoutes(routes: Partial<RouterEngineRoutes>) {
|
|
51
|
+
this.routes.api_routes.push(...(routes.api_routes ?? []));
|
|
52
|
+
this.routes.stream_routes.push(...(routes.stream_routes ?? []));
|
|
53
|
+
this.routes.socket_routes.push(...(routes.socket_routes ?? []));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public get hasRoutes() {
|
|
57
|
+
return (
|
|
58
|
+
this.routes.api_routes.length > 0 || this.routes.stream_routes.length > 0 || this.routes.socket_routes.length > 0
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
58
62
|
public registerAPI(api: api.RouteAPI) {
|
|
59
63
|
if (this.api) {
|
|
60
64
|
logger.warn('A RouteAPI has already been registered. Overriding existing implementation');
|
|
@@ -75,6 +79,12 @@ export class RouterEngine {
|
|
|
75
79
|
*/
|
|
76
80
|
async start(setup: RouterSetup) {
|
|
77
81
|
logger.info('Starting Router Engine...');
|
|
82
|
+
|
|
83
|
+
if (!this.hasRoutes) {
|
|
84
|
+
logger.warn('No routes have been registered. Router Engine will not continue.');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
78
88
|
const { onShutdown } = await setup(this.routes);
|
|
79
89
|
this.cleanupHandler = onShutdown;
|
|
80
90
|
logger.info('Successfully started Router Engine.');
|
|
@@ -9,7 +9,7 @@ import { PROBES_ROUTES } from './endpoints/probes.js';
|
|
|
9
9
|
import { SYNC_RULES_ROUTES } from './endpoints/sync-rules.js';
|
|
10
10
|
import { SYNC_STREAM_ROUTES } from './endpoints/sync-stream.js';
|
|
11
11
|
import { createRequestQueueHook, CreateRequestQueueParams } from './hooks.js';
|
|
12
|
-
import { RouteDefinition
|
|
12
|
+
import { RouteDefinition } from './router.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* A list of route definitions to be registered as endpoints.
|
|
@@ -59,14 +59,9 @@ export function configureFastifyServer(server: fastify.FastifyInstance, options:
|
|
|
59
59
|
const { service_context, routes = DEFAULT_ROUTE_OPTIONS } = options;
|
|
60
60
|
|
|
61
61
|
const generateContext = async () => {
|
|
62
|
-
const { routerEngine } = service_context;
|
|
63
|
-
if (!routerEngine) {
|
|
64
|
-
throw new Error(`RouterEngine has not been registered`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
62
|
return {
|
|
68
63
|
user_id: undefined,
|
|
69
|
-
service_context: service_context
|
|
64
|
+
service_context: service_context
|
|
70
65
|
};
|
|
71
66
|
};
|
|
72
67
|
|
|
@@ -37,10 +37,6 @@ export function configureRSocket(router: ReactiveSocketRouter<Context>, options:
|
|
|
37
37
|
throw new errors.AuthorizationError(token_errors ?? 'Authentication required');
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
if (!service_context.routerEngine) {
|
|
41
|
-
throw new Error(`RouterEngine has not been registered`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
40
|
return {
|
|
45
41
|
token,
|
|
46
42
|
user_agent,
|
|
@@ -19,7 +19,7 @@ export const executeSql = routeDefinition({
|
|
|
19
19
|
}
|
|
20
20
|
} = payload;
|
|
21
21
|
|
|
22
|
-
const apiHandler = payload.context.service_context.routerEngine
|
|
22
|
+
const apiHandler = payload.context.service_context.routerEngine.getAPI();
|
|
23
23
|
|
|
24
24
|
const sourceConfig = await apiHandler.getSourceConfig();
|
|
25
25
|
if (!sourceConfig.debug_api) {
|
|
@@ -47,7 +47,7 @@ export const diagnostics = routeDefinition({
|
|
|
47
47
|
const { service_context } = context;
|
|
48
48
|
const include_content = payload.params.sync_rules_content ?? false;
|
|
49
49
|
|
|
50
|
-
const apiHandler = service_context.routerEngine
|
|
50
|
+
const apiHandler = service_context.routerEngine.getAPI();
|
|
51
51
|
|
|
52
52
|
const status = await apiHandler.getConnectionStatus();
|
|
53
53
|
if (!status) {
|
|
@@ -94,7 +94,7 @@ export const getSchema = routeDefinition({
|
|
|
94
94
|
authorize: authApi,
|
|
95
95
|
validator: schema.createTsCodecValidator(internal_routes.GetSchemaRequest, { allowAdditional: true }),
|
|
96
96
|
handler: async (payload) => {
|
|
97
|
-
const apiHandler = payload.context.service_context.routerEngine
|
|
97
|
+
const apiHandler = payload.context.service_context.routerEngine.getAPI();
|
|
98
98
|
|
|
99
99
|
return internal_routes.GetSchemaResponse.encode(await api.getConnectionsSchema(apiHandler));
|
|
100
100
|
}
|
|
@@ -112,7 +112,7 @@ export const reprocess = routeDefinition({
|
|
|
112
112
|
const {
|
|
113
113
|
storageEngine: { activeBucketStorage }
|
|
114
114
|
} = service_context;
|
|
115
|
-
const apiHandler = service_context.routerEngine
|
|
115
|
+
const apiHandler = service_context.routerEngine.getAPI();
|
|
116
116
|
const next = await activeBucketStorage.getNextSyncRules(apiHandler.getParseSyncRulesOptions());
|
|
117
117
|
if (next != null) {
|
|
118
118
|
throw new Error(`Busy processing sync rules - cannot reprocess`);
|
|
@@ -159,7 +159,7 @@ export const validate = routeDefinition({
|
|
|
159
159
|
context: { service_context }
|
|
160
160
|
} = payload;
|
|
161
161
|
const content = payload.params.sync_rules;
|
|
162
|
-
const apiHandler = service_context.routerEngine
|
|
162
|
+
const apiHandler = service_context.routerEngine.getAPI();
|
|
163
163
|
|
|
164
164
|
const schemaData = await api.getConnectionsSchema(apiHandler);
|
|
165
165
|
const schema = new StaticSchema(schemaData.connections);
|
|
@@ -18,7 +18,7 @@ export const writeCheckpoint = routeDefinition({
|
|
|
18
18
|
const {
|
|
19
19
|
context: { service_context }
|
|
20
20
|
} = payload;
|
|
21
|
-
const apiHandler = service_context.routerEngine
|
|
21
|
+
const apiHandler = service_context.routerEngine.getAPI();
|
|
22
22
|
|
|
23
23
|
// This old API needs a persisted checkpoint id.
|
|
24
24
|
// Since we don't use LSNs anymore, the only way to get that is to wait.
|
|
@@ -54,7 +54,7 @@ export const writeCheckpoint2 = routeDefinition({
|
|
|
54
54
|
handler: async (payload) => {
|
|
55
55
|
const { user_id, service_context } = payload.context;
|
|
56
56
|
|
|
57
|
-
const apiHandler = service_context.routerEngine
|
|
57
|
+
const apiHandler = service_context.routerEngine.getAPI();
|
|
58
58
|
|
|
59
59
|
const { replicationHead, writeCheckpoint } = await util.createWriteCheckpoint({
|
|
60
60
|
userId: user_id,
|
|
@@ -33,7 +33,7 @@ export const syncStreamReactive: SocketRouteGenerator = (router) =>
|
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
if (routerEngine
|
|
36
|
+
if (routerEngine.closed) {
|
|
37
37
|
responder.onError(
|
|
38
38
|
new errors.ServiceError({
|
|
39
39
|
status: 503,
|
|
@@ -64,9 +64,9 @@ export const syncStreamReactive: SocketRouteGenerator = (router) =>
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const syncRules = bucketStorage.getParsedSyncRules(routerEngine
|
|
67
|
+
const syncRules = bucketStorage.getParsedSyncRules(routerEngine.getAPI().getParseSyncRulesOptions());
|
|
68
68
|
|
|
69
|
-
const removeStopHandler = routerEngine
|
|
69
|
+
const removeStopHandler = routerEngine.addStopHandler(() => {
|
|
70
70
|
controller.abort();
|
|
71
71
|
});
|
|
72
72
|
|
|
@@ -53,7 +53,7 @@ export const deploySyncRules = routeDefinition({
|
|
|
53
53
|
const content = payload.params.content;
|
|
54
54
|
|
|
55
55
|
try {
|
|
56
|
-
const apiHandler = service_context.routerEngine
|
|
56
|
+
const apiHandler = service_context.routerEngine.getAPI();
|
|
57
57
|
SqlSyncRules.fromYaml(payload.params.content, {
|
|
58
58
|
...apiHandler.getParseSyncRulesOptions(),
|
|
59
59
|
// We don't do any schema-level validation at this point
|
|
@@ -94,7 +94,7 @@ export const validateSyncRules = routeDefinition({
|
|
|
94
94
|
handler: async (payload) => {
|
|
95
95
|
const content = payload.params.content;
|
|
96
96
|
const { service_context } = payload.context;
|
|
97
|
-
const apiHandler = service_context.routerEngine
|
|
97
|
+
const apiHandler = service_context.routerEngine.getAPI();
|
|
98
98
|
|
|
99
99
|
const info = await debugSyncRules(apiHandler, content);
|
|
100
100
|
|
|
@@ -121,7 +121,7 @@ export const currentSyncRules = routeDefinition({
|
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
const apiHandler = service_context.routerEngine
|
|
124
|
+
const apiHandler = service_context.routerEngine.getAPI();
|
|
125
125
|
const info = await debugSyncRules(apiHandler, sync_rules.sync_rules_content);
|
|
126
126
|
const next = await activeBucketStorage.getNextSyncRulesContent();
|
|
127
127
|
|
|
@@ -158,7 +158,7 @@ export const reprocessSyncRules = routeDefinition({
|
|
|
158
158
|
const {
|
|
159
159
|
storageEngine: { activeBucketStorage }
|
|
160
160
|
} = payload.context.service_context;
|
|
161
|
-
const apiHandler = payload.context.service_context.routerEngine
|
|
161
|
+
const apiHandler = payload.context.service_context.routerEngine.getAPI();
|
|
162
162
|
const sync_rules = await activeBucketStorage.getActiveSyncRules(apiHandler.getParseSyncRulesOptions());
|
|
163
163
|
if (sync_rules == null) {
|
|
164
164
|
throw new errors.ServiceError({
|
|
@@ -26,7 +26,7 @@ export const syncStreamed = routeDefinition({
|
|
|
26
26
|
const userAgent = headers['x-user-agent'] ?? headers['user-agent'];
|
|
27
27
|
const clientId = payload.params.client_id;
|
|
28
28
|
|
|
29
|
-
if (routerEngine
|
|
29
|
+
if (routerEngine.closed) {
|
|
30
30
|
throw new errors.ServiceError({
|
|
31
31
|
status: 503,
|
|
32
32
|
code: ErrorCode.PSYNC_S2003,
|
|
@@ -47,7 +47,7 @@ export const syncStreamed = routeDefinition({
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
const syncRules = bucketStorage.getParsedSyncRules(routerEngine
|
|
50
|
+
const syncRules = bucketStorage.getParsedSyncRules(routerEngine.getAPI().getParseSyncRulesOptions());
|
|
51
51
|
|
|
52
52
|
const controller = new AbortController();
|
|
53
53
|
const tracker = new sync.RequestTracker(metricsEngine);
|
|
@@ -72,7 +72,7 @@ export const syncStreamed = routeDefinition({
|
|
|
72
72
|
{ objectMode: false, highWaterMark: 16 * 1024 }
|
|
73
73
|
);
|
|
74
74
|
|
|
75
|
-
const deregister = routerEngine
|
|
75
|
+
const deregister = routerEngine.addStopHandler(() => {
|
|
76
76
|
// This error is not currently propagated to the client
|
|
77
77
|
controller.abort();
|
|
78
78
|
stream.destroy(new Error('Shutting down system'));
|
package/src/routes/router.ts
CHANGED
|
@@ -6,7 +6,8 @@ import { RouterEngine } from './RouterEngine.js';
|
|
|
6
6
|
/**
|
|
7
7
|
* The {@link RouterEngine} must be provided for these routes
|
|
8
8
|
*/
|
|
9
|
-
export type RouterServiceContext = ServiceContext
|
|
9
|
+
export type RouterServiceContext = ServiceContext;
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* Common context for routes
|
|
12
13
|
*/
|
package/src/runner/teardown.ts
CHANGED
|
@@ -14,7 +14,11 @@ export async function teardown(runnerConfig: utils.RunnerConfig) {
|
|
|
14
14
|
try {
|
|
15
15
|
logger.info(`Tearing down PowerSync instance...`);
|
|
16
16
|
const config = await utils.loadConfig(runnerConfig);
|
|
17
|
-
const serviceContext = new system.ServiceContextContainer(
|
|
17
|
+
const serviceContext = new system.ServiceContextContainer({
|
|
18
|
+
serviceMode: system.ServiceContextMode.TEARDOWN,
|
|
19
|
+
configuration: config
|
|
20
|
+
});
|
|
21
|
+
|
|
18
22
|
const moduleManager = container.getImplementation(modules.ModuleManager);
|
|
19
23
|
await moduleManager.initialize(serviceContext);
|
|
20
24
|
// This is mostly done to ensure that the storage is ready
|
|
@@ -6,18 +6,34 @@ import { PowerSyncMigrationManager } from '../migrations/PowerSyncMigrationManag
|
|
|
6
6
|
import * as replication from '../replication/replication-index.js';
|
|
7
7
|
import * as routes from '../routes/routes-index.js';
|
|
8
8
|
import * as storage from '../storage/storage-index.js';
|
|
9
|
-
import * as utils from '../util/util-index.js';
|
|
10
9
|
import { SyncContext } from '../sync/SyncContext.js';
|
|
10
|
+
import * as utils from '../util/util-index.js';
|
|
11
11
|
|
|
12
12
|
export interface ServiceContext {
|
|
13
13
|
configuration: utils.ResolvedPowerSyncConfig;
|
|
14
14
|
lifeCycleEngine: LifeCycledSystem;
|
|
15
15
|
metricsEngine: metrics.MetricsEngine;
|
|
16
16
|
replicationEngine: replication.ReplicationEngine | null;
|
|
17
|
-
routerEngine: routes.RouterEngine
|
|
17
|
+
routerEngine: routes.RouterEngine;
|
|
18
18
|
storageEngine: storage.StorageEngine;
|
|
19
19
|
migrations: PowerSyncMigrationManager;
|
|
20
20
|
syncContext: SyncContext;
|
|
21
|
+
serviceMode: ServiceContextMode;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export enum ServiceContextMode {
|
|
25
|
+
API = utils.ServiceRunner.API,
|
|
26
|
+
SYNC = utils.ServiceRunner.SYNC,
|
|
27
|
+
UNIFIED = utils.ServiceRunner.UNIFIED,
|
|
28
|
+
COMPACT = 'compact',
|
|
29
|
+
MIGRATION = 'migration',
|
|
30
|
+
TEARDOWN = 'teardown',
|
|
31
|
+
TEST_CONNECTION = 'test-connection'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ServiceContextOptions {
|
|
35
|
+
serviceMode: ServiceContextMode;
|
|
36
|
+
configuration: utils.ResolvedPowerSyncConfig;
|
|
21
37
|
}
|
|
22
38
|
|
|
23
39
|
/**
|
|
@@ -26,11 +42,18 @@ export interface ServiceContext {
|
|
|
26
42
|
* This controls registering, initializing and the lifecycle of various services.
|
|
27
43
|
*/
|
|
28
44
|
export class ServiceContextContainer implements ServiceContext {
|
|
45
|
+
configuration: utils.ResolvedPowerSyncConfig;
|
|
29
46
|
lifeCycleEngine: LifeCycledSystem;
|
|
30
47
|
storageEngine: storage.StorageEngine;
|
|
31
48
|
syncContext: SyncContext;
|
|
49
|
+
routerEngine: routes.RouterEngine;
|
|
50
|
+
serviceMode: ServiceContextMode;
|
|
51
|
+
|
|
52
|
+
constructor(options: ServiceContextOptions) {
|
|
53
|
+
this.serviceMode = options.serviceMode;
|
|
54
|
+
const { configuration } = options;
|
|
55
|
+
this.configuration = configuration;
|
|
32
56
|
|
|
33
|
-
constructor(public configuration: utils.ResolvedPowerSyncConfig) {
|
|
34
57
|
this.lifeCycleEngine = new LifeCycledSystem();
|
|
35
58
|
|
|
36
59
|
this.storageEngine = new storage.StorageEngine({
|
|
@@ -42,6 +65,11 @@ export class ServiceContextContainer implements ServiceContext {
|
|
|
42
65
|
stop: (storageEngine) => storageEngine.shutDown()
|
|
43
66
|
});
|
|
44
67
|
|
|
68
|
+
this.routerEngine = new routes.RouterEngine();
|
|
69
|
+
this.lifeCycleEngine.withLifecycle(this.routerEngine, {
|
|
70
|
+
stop: (routerEngine) => routerEngine.shutDown()
|
|
71
|
+
});
|
|
72
|
+
|
|
45
73
|
this.syncContext = new SyncContext({
|
|
46
74
|
maxDataFetchConcurrency: configuration.api_parameters.max_data_fetch_concurrency,
|
|
47
75
|
maxBuckets: configuration.api_parameters.max_buckets_per_connection,
|
|
@@ -55,21 +83,12 @@ export class ServiceContextContainer implements ServiceContext {
|
|
|
55
83
|
// Migrations should be executed before the system starts
|
|
56
84
|
start: () => migrationManager[Symbol.asyncDispose]()
|
|
57
85
|
});
|
|
58
|
-
|
|
59
|
-
this.lifeCycleEngine.withLifecycle(this.storageEngine, {
|
|
60
|
-
start: (storageEngine) => storageEngine.start(),
|
|
61
|
-
stop: (storageEngine) => storageEngine.shutDown()
|
|
62
|
-
});
|
|
63
86
|
}
|
|
64
87
|
|
|
65
88
|
get replicationEngine(): replication.ReplicationEngine | null {
|
|
66
89
|
return container.getOptional(replication.ReplicationEngine);
|
|
67
90
|
}
|
|
68
91
|
|
|
69
|
-
get routerEngine(): routes.RouterEngine | null {
|
|
70
|
-
return container.getOptional(routes.RouterEngine);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
92
|
get metricsEngine(): metrics.MetricsEngine {
|
|
74
93
|
return container.getImplementation(metrics.MetricsEngine);
|
|
75
94
|
}
|