Skip to content

Commit 0dcae0d

Browse files
cleanup router code and naming
1 parent b4fcb37 commit 0dcae0d

File tree

23 files changed

+54
-61
lines changed

23 files changed

+54
-61
lines changed

modules/module-core/src/CoreModule.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class CoreModule extends core.modules.AbstractModule {
1414
public async initialize(context: core.ServiceContextContainer): Promise<void> {
1515
this.configureTags(context);
1616

17-
if ([core.system.ServiceContextMode.API, core.system.ServiceContextMode.UNIFIED].includes(context.mode)) {
17+
if ([core.system.ServiceContextMode.API, core.system.ServiceContextMode.UNIFIED].includes(context.serviceMode)) {
1818
// Service should include API routes
1919
this.registerAPIRoutes(context);
2020
}
@@ -115,7 +115,7 @@ export class CoreModule extends core.modules.AbstractModule {
115115
} = context;
116116

117117
const exposesAPI = [core.system.ServiceContextMode.API, core.system.ServiceContextMode.UNIFIED].includes(
118-
context.mode
118+
context.serviceMode
119119
);
120120

121121
/**
@@ -124,13 +124,13 @@ export class CoreModule extends core.modules.AbstractModule {
124124
* - Always enabling filesystem probes always exposing HTTP probes
125125
* Probe types must explicitly be selected if not using LEGACY_DEFAULT
126126
*/
127-
if (probes.http || (exposesAPI && probes.legacy)) {
127+
if (probes.use_http || (exposesAPI && probes.use_legacy)) {
128128
context.routerEngine.registerRoutes({
129129
api_routes: core.routes.endpoints.PROBES_ROUTES
130130
});
131131
}
132132

133-
if (probes.legacy || probes.filesystem) {
133+
if (probes.use_legacy || probes.use_filesystem) {
134134
context.register(framework.ContainerImplementation.PROBES, framework.createFSProbe());
135135
}
136136
}
@@ -146,7 +146,7 @@ export class CoreModule extends core.modules.AbstractModule {
146146

147147
await core.metrics.registerMetrics({
148148
service_context: context,
149-
modes: metricsModeMap[context.mode] ?? []
149+
modes: metricsModeMap[context.serviceMode] ?? []
150150
});
151151
}
152152

modules/module-core/test/src/index.ts

Whitespace-only changes.

modules/module-core/test/src/probes.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const createTestContainer = async (options: TestContainerOptions) => {
2424

2525
const serviceContext = new system.ServiceContextContainer({
2626
configuration: collectedConfig,
27-
mode: options.mode
27+
serviceMode: options.mode
2828
});
2929

3030
await moduleManager.initialize(serviceContext);
@@ -89,7 +89,7 @@ describe('Probes', () => {
8989
type: memory
9090
healthcheck:
9191
probes:
92-
http: true
92+
use_http: true
9393
`,
9494
mode: system.ServiceContextMode.SYNC
9595
});
@@ -148,7 +148,7 @@ describe('Probes', () => {
148148
type: memory
149149
healthcheck:
150150
probes:
151-
http: true
151+
use_http: true
152152
`,
153153
mode: system.ServiceContextMode.API
154154
});

packages/service-core/src/entry/commands/compact-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function registerCompactAction(program: Command) {
3838
}
3939
const config = await utils.loadConfig(extractRunnerOptions(options));
4040
const serviceContext = new system.ServiceContextContainer({
41-
mode: system.ServiceContextMode.COMPACT,
41+
serviceMode: system.ServiceContextMode.COMPACT,
4242
configuration: config
4343
});
4444

packages/service-core/src/entry/commands/migrate-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function registerMigrationAction(program: Command) {
1919
.action(async (direction: migrations.Direction, options) => {
2020
const config = await utils.loadConfig(extractRunnerOptions(options));
2121
const serviceContext = new system.ServiceContextContainer({
22-
mode: system.ServiceContextMode.MIGRATION,
22+
serviceMode: system.ServiceContextMode.MIGRATION,
2323
configuration: config
2424
});
2525

packages/service-core/src/entry/commands/test-connection-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function registerTestConnectionAction(program: Command) {
1818
try {
1919
const config = await utils.loadConfig(extractRunnerOptions(options));
2020
const serviceContext = new system.ServiceContextContainer({
21-
mode: system.ServiceContextMode.TEST_CONNECTION,
21+
serviceMode: system.ServiceContextMode.TEST_CONNECTION,
2222
configuration: config
2323
});
2424

packages/service-core/src/routes/configure-fastify.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PROBES_ROUTES } from './endpoints/probes.js';
99
import { SYNC_RULES_ROUTES } from './endpoints/sync-rules.js';
1010
import { SYNC_STREAM_ROUTES } from './endpoints/sync-stream.js';
1111
import { createRequestQueueHook, CreateRequestQueueParams } from './hooks.js';
12-
import { RouteDefinition, RouterServiceContext } from './router.js';
12+
import { RouteDefinition } from './router.js';
1313

1414
/**
1515
* A list of route definitions to be registered as endpoints.
@@ -59,14 +59,9 @@ export function configureFastifyServer(server: fastify.FastifyInstance, options:
5959
const { service_context, routes = DEFAULT_ROUTE_OPTIONS } = options;
6060

6161
const generateContext = async () => {
62-
const { routerEngine } = service_context;
63-
if (!routerEngine) {
64-
throw new Error(`RouterEngine has not been registered`);
65-
}
66-
6762
return {
6863
user_id: undefined,
69-
service_context: service_context as RouterServiceContext
64+
service_context: service_context
7065
};
7166
};
7267

packages/service-core/src/routes/configure-rsocket.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ export function configureRSocket(router: ReactiveSocketRouter<Context>, options:
3737
throw new errors.AuthorizationError(token_errors ?? 'Authentication required');
3838
}
3939

40-
if (!service_context.routerEngine) {
41-
throw new Error(`RouterEngine has not been registered`);
42-
}
43-
4440
return {
4541
token,
4642
user_agent,

packages/service-core/src/routes/endpoints/admin.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const executeSql = routeDefinition({
1919
}
2020
} = payload;
2121

22-
const apiHandler = payload.context.service_context.routerEngine!.getAPI();
22+
const apiHandler = payload.context.service_context.routerEngine.getAPI();
2323

2424
const sourceConfig = await apiHandler.getSourceConfig();
2525
if (!sourceConfig.debug_api) {
@@ -47,7 +47,7 @@ export const diagnostics = routeDefinition({
4747
const { service_context } = context;
4848
const include_content = payload.params.sync_rules_content ?? false;
4949

50-
const apiHandler = service_context.routerEngine!.getAPI();
50+
const apiHandler = service_context.routerEngine.getAPI();
5151

5252
const status = await apiHandler.getConnectionStatus();
5353
if (!status) {
@@ -94,7 +94,7 @@ export const getSchema = routeDefinition({
9494
authorize: authApi,
9595
validator: schema.createTsCodecValidator(internal_routes.GetSchemaRequest, { allowAdditional: true }),
9696
handler: async (payload) => {
97-
const apiHandler = payload.context.service_context.routerEngine!.getAPI();
97+
const apiHandler = payload.context.service_context.routerEngine.getAPI();
9898

9999
return internal_routes.GetSchemaResponse.encode(await api.getConnectionsSchema(apiHandler));
100100
}
@@ -112,7 +112,7 @@ export const reprocess = routeDefinition({
112112
const {
113113
storageEngine: { activeBucketStorage }
114114
} = service_context;
115-
const apiHandler = service_context.routerEngine!.getAPI();
115+
const apiHandler = service_context.routerEngine.getAPI();
116116
const next = await activeBucketStorage.getNextSyncRules(apiHandler.getParseSyncRulesOptions());
117117
if (next != null) {
118118
throw new Error(`Busy processing sync rules - cannot reprocess`);
@@ -159,7 +159,7 @@ export const validate = routeDefinition({
159159
context: { service_context }
160160
} = payload;
161161
const content = payload.params.sync_rules;
162-
const apiHandler = service_context.routerEngine!.getAPI();
162+
const apiHandler = service_context.routerEngine.getAPI();
163163

164164
const schemaData = await api.getConnectionsSchema(apiHandler);
165165
const schema = new StaticSchema(schemaData.connections);

packages/service-core/src/routes/endpoints/checkpointing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const writeCheckpoint = routeDefinition({
1818
const {
1919
context: { service_context }
2020
} = payload;
21-
const apiHandler = service_context.routerEngine!.getAPI();
21+
const apiHandler = service_context.routerEngine.getAPI();
2222

2323
// This old API needs a persisted checkpoint id.
2424
// Since we don't use LSNs anymore, the only way to get that is to wait.
@@ -54,7 +54,7 @@ export const writeCheckpoint2 = routeDefinition({
5454
handler: async (payload) => {
5555
const { user_id, service_context } = payload.context;
5656

57-
const apiHandler = service_context.routerEngine!.getAPI();
57+
const apiHandler = service_context.routerEngine.getAPI();
5858

5959
const { replicationHead, writeCheckpoint } = await util.createWriteCheckpoint({
6060
userId: user_id,

0 commit comments

Comments
 (0)