@powersync/service-core 0.0.0-dev-20261005120023 → 0.0.0-dev-20261015071128
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 +23 -12
- package/dist/api/RouteAPI.d.ts +8 -1
- package/dist/api/api-index.d.ts +1 -0
- package/dist/api/api-index.js +1 -0
- package/dist/api/api-index.js.map +1 -1
- package/dist/api/diagnostics.js +28 -14
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/api/source-capabilities.d.ts +7 -0
- package/dist/api/source-capabilities.js +23 -0
- package/dist/api/source-capabilities.js.map +1 -0
- package/dist/replication/AbstractReplicationJob.d.ts +4 -6
- package/dist/replication/AbstractReplicationJob.js.map +1 -1
- package/dist/replication/AbstractReplicator.d.ts +11 -0
- package/dist/replication/AbstractReplicator.js +24 -2
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/replication/ReplicationModule.js +13 -2
- package/dist/replication/ReplicationModule.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +24 -24
- package/dist/routes/endpoints/admin.d.ts +48 -48
- package/dist/routes/endpoints/admin.js +8 -8
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/sync-rules.js +41 -14
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/storage/BucketStorageFactory.d.ts +11 -13
- package/dist/storage/BucketStorageFactory.js +21 -11
- package/dist/storage/BucketStorageFactory.js.map +1 -1
- package/dist/storage/PersistedReplicationStream.d.ts +1 -2
- package/dist/storage/PersistedReplicationStream.js.map +1 -1
- package/dist/storage/PersistedSyncConfigContent.d.ts +6 -5
- package/dist/storage/PersistedSyncConfigContent.js +5 -12
- package/dist/storage/PersistedSyncConfigContent.js.map +1 -1
- package/dist/storage/StorageEngine.d.ts +0 -4
- package/dist/storage/StorageEngine.js +1 -7
- package/dist/storage/StorageEngine.js.map +1 -1
- package/dist/storage/StorageProvider.d.ts +1 -6
- package/dist/storage/SyncRulesBucketStorage.d.ts +1 -1
- package/dist/storage/storage-index.d.ts +0 -1
- package/dist/storage/storage-index.js +0 -1
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/system/ServiceContext.d.ts +0 -20
- package/dist/system/ServiceContext.js +1 -29
- package/dist/system/ServiceContext.js.map +1 -1
- package/package.json +11 -11
- package/src/api/RouteAPI.ts +9 -1
- package/src/api/api-index.ts +1 -0
- package/src/api/diagnostics.ts +24 -12
- package/src/api/source-capabilities.ts +24 -0
- package/src/replication/AbstractReplicationJob.ts +2 -4
- package/src/replication/AbstractReplicator.ts +32 -2
- package/src/replication/ReplicationModule.ts +12 -2
- package/src/routes/endpoints/admin.ts +14 -6
- package/src/routes/endpoints/sync-rules.ts +42 -16
- package/src/storage/BucketStorageFactory.ts +21 -19
- package/src/storage/PersistedReplicationStream.ts +1 -2
- package/src/storage/PersistedSyncConfigContent.ts +11 -16
- package/src/storage/StorageEngine.ts +1 -10
- package/src/storage/StorageProvider.ts +1 -6
- package/src/storage/SyncRulesBucketStorage.ts +1 -1
- package/src/storage/storage-index.ts +0 -1
- package/src/system/ServiceContext.ts +1 -47
- package/test/src/AbstractReplicator.test.ts +109 -23
- package/test/src/PersistedSyncConfigContent.test.ts +1 -3
- package/test/src/diagnostics.test.ts +104 -0
- package/test/src/routes/admin.test.ts +221 -12
- package/test/src/routes/mocks.ts +0 -2
- package/test/src/routes/sync-rules.test.ts +124 -0
- package/test/src/source_table_config.test.ts +104 -0
- package/test/src/storage/BucketStorageFactory.test.ts +46 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/SyncConfigParser.d.ts +0 -44
- package/dist/storage/SyncConfigParser.js +0 -73
- package/dist/storage/SyncConfigParser.js.map +0 -1
- package/src/storage/SyncConfigParser.ts +0 -124
- package/test/src/SyncConfigParser.test.ts +0 -309
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
HydrationState,
|
|
11
11
|
nodeSqlite,
|
|
12
12
|
PrecompiledSyncConfig,
|
|
13
|
+
SourceConnectionMap,
|
|
14
|
+
SqlSyncRules,
|
|
13
15
|
SyncConfigWithErrors,
|
|
14
16
|
versionedHydrationState,
|
|
15
17
|
YamlError
|
|
@@ -21,22 +23,20 @@ import { SerializedSyncPlan, UpdateSyncRulesOptions } from './BucketStorageFacto
|
|
|
21
23
|
import { ParsedSyncConfigSet } from './ParsedSyncConfigSet.js';
|
|
22
24
|
import { PersistedSyncConfigStatus } from './PersistedSyncConfigStatus.js';
|
|
23
25
|
import { STORAGE_VERSION_CONFIG, StorageVersionConfig } from './StorageVersionConfig.js';
|
|
24
|
-
import { ParseSyncConfigOptions, SyncConfigParser } from './SyncConfigParser.js';
|
|
25
26
|
|
|
26
27
|
export interface ParsePersistedSyncConfigContentOptions {
|
|
27
28
|
content: string;
|
|
28
29
|
compiledPlan: SerializedSyncPlan | null;
|
|
29
30
|
storageVersion: number;
|
|
30
31
|
parseOptions: ParseSyncConfigOptions;
|
|
31
|
-
syncConfigParser: SyncConfigParser;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function parsePersistedSyncConfigContent(options: ParsePersistedSyncConfigContentOptions): SyncConfigWithErrors {
|
|
35
|
-
const { content, compiledPlan, storageVersion, parseOptions
|
|
35
|
+
const { content, compiledPlan, storageVersion, parseOptions } = options;
|
|
36
36
|
|
|
37
37
|
if (compiledPlan == null) {
|
|
38
38
|
// Fallback: Only parse from YAML if no compiled plan is available.
|
|
39
|
-
return
|
|
39
|
+
return SqlSyncRules.fromYaml(content, parseOptions);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const plan = deserializeSyncPlan(compiledPlan.plan);
|
|
@@ -70,12 +70,6 @@ export function parsePersistedSyncConfigContent(options: ParsePersistedSyncConfi
|
|
|
70
70
|
// Note: If the original content did not define a storage version, this will still set the storage version.
|
|
71
71
|
// This means asUpdateOptions will not change the storage version, even if the default changes.
|
|
72
72
|
precompiled.storageVersion = storageVersion;
|
|
73
|
-
errors.push(
|
|
74
|
-
...syncConfigParser.validatePersisted({
|
|
75
|
-
config: precompiled,
|
|
76
|
-
context: { defaultSchema: parseOptions.defaultSchema }
|
|
77
|
-
})
|
|
78
|
-
);
|
|
79
73
|
|
|
80
74
|
if (compiledPlan.errors) {
|
|
81
75
|
for (const error of compiledPlan.errors) {
|
|
@@ -112,10 +106,7 @@ export abstract class PersistedSyncConfigContent implements PersistedSyncConfigC
|
|
|
112
106
|
readonly syncConfigState: SyncRuleState;
|
|
113
107
|
readonly version_label: string | undefined;
|
|
114
108
|
|
|
115
|
-
constructor(
|
|
116
|
-
data: PersistedSyncConfigContentData,
|
|
117
|
-
private readonly syncConfigParser: SyncConfigParser
|
|
118
|
-
) {
|
|
109
|
+
constructor(data: PersistedSyncConfigContentData) {
|
|
119
110
|
this.replicationStreamId = data.replicationStreamId;
|
|
120
111
|
this.sync_rules_content = data.sync_rules_content;
|
|
121
112
|
this.compiled_plan = data.compiled_plan;
|
|
@@ -154,8 +145,7 @@ export abstract class PersistedSyncConfigContent implements PersistedSyncConfigC
|
|
|
154
145
|
content: this.sync_rules_content,
|
|
155
146
|
compiledPlan: this.compiled_plan,
|
|
156
147
|
storageVersion: this.storageVersion,
|
|
157
|
-
parseOptions: options
|
|
158
|
-
syncConfigParser: this.syncConfigParser
|
|
148
|
+
parseOptions: options
|
|
159
149
|
});
|
|
160
150
|
}
|
|
161
151
|
|
|
@@ -213,3 +203,8 @@ export interface PersistedSyncConfigContentData {
|
|
|
213
203
|
readonly version_label?: string;
|
|
214
204
|
}
|
|
215
205
|
export type PersistedSyncConfigId = string;
|
|
206
|
+
|
|
207
|
+
export interface ParseSyncConfigOptions {
|
|
208
|
+
defaultSchema: string;
|
|
209
|
+
connections?: SourceConnectionMap;
|
|
210
|
+
}
|
|
@@ -2,11 +2,9 @@ import { BaseObserver, logger, ServiceError } from '@powersync/lib-services-fram
|
|
|
2
2
|
import { ResolvedPowerSyncConfig } from '../util/util-index.js';
|
|
3
3
|
import { BucketStorageFactory } from './BucketStorageFactory.js';
|
|
4
4
|
import { ActiveStorage, StorageProvider } from './StorageProvider.js';
|
|
5
|
-
import { SyncConfigParser } from './SyncConfigParser.js';
|
|
6
5
|
|
|
7
6
|
export type StorageEngineOptions = {
|
|
8
7
|
configuration: ResolvedPowerSyncConfig;
|
|
9
|
-
syncConfigParser: SyncConfigParser;
|
|
10
8
|
};
|
|
11
9
|
|
|
12
10
|
export interface StorageEngineListener {
|
|
@@ -17,7 +15,6 @@ export interface StorageEngineListener {
|
|
|
17
15
|
export class StorageEngine extends BaseObserver<StorageEngineListener> {
|
|
18
16
|
// TODO: This will need to revisited when we actually support multiple storage providers.
|
|
19
17
|
private storageProviders: Map<string, StorageProvider> = new Map();
|
|
20
|
-
private startupStarted = false;
|
|
21
18
|
private currentActiveStorage: ActiveStorage | null = null;
|
|
22
19
|
|
|
23
20
|
constructor(private options: StorageEngineOptions) {
|
|
@@ -36,10 +33,6 @@ export class StorageEngine extends BaseObserver<StorageEngineListener> {
|
|
|
36
33
|
return this.currentActiveStorage;
|
|
37
34
|
}
|
|
38
35
|
|
|
39
|
-
get started(): boolean {
|
|
40
|
-
return this.startupStarted;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
36
|
/**
|
|
44
37
|
* Register a provider which generates a {@link BucketStorageFactory}
|
|
45
38
|
* given the matching config specified in the loaded {@link ResolvedPowerSyncConfig}
|
|
@@ -49,12 +42,10 @@ export class StorageEngine extends BaseObserver<StorageEngineListener> {
|
|
|
49
42
|
}
|
|
50
43
|
|
|
51
44
|
public async start(): Promise<void> {
|
|
52
|
-
this.startupStarted = true;
|
|
53
45
|
logger.info('Starting Storage Engine...');
|
|
54
46
|
const { configuration } = this.options;
|
|
55
47
|
this.currentActiveStorage = await this.storageProviders.get(configuration.storage.type)!.getStorage({
|
|
56
|
-
resolvedConfig: configuration
|
|
57
|
-
syncConfigParser: this.options.syncConfigParser
|
|
48
|
+
resolvedConfig: configuration
|
|
58
49
|
});
|
|
59
50
|
this.iterateListeners((cb) => cb.storageActivated?.(this.activeBucketStorage));
|
|
60
51
|
this.currentActiveStorage.onFatalError?.((error) => {
|
|
@@ -2,7 +2,6 @@ import { ServiceError } from '@powersync/lib-services-framework';
|
|
|
2
2
|
import * as util from '../util/util-index.js';
|
|
3
3
|
import { BucketStorageFactory } from './BucketStorageFactory.js';
|
|
4
4
|
import { ReportStorage } from './ReportStorage.js';
|
|
5
|
-
import { SyncConfigParser } from './SyncConfigParser.js';
|
|
6
5
|
|
|
7
6
|
export interface ActiveStorage {
|
|
8
7
|
storage: BucketStorageFactory;
|
|
@@ -20,10 +19,6 @@ export interface ActiveStorage {
|
|
|
20
19
|
export interface GetStorageOptions {
|
|
21
20
|
// TODO: This should just be the storage config. Update once the slot name prefix coupling has been removed from the storage
|
|
22
21
|
resolvedConfig: util.ResolvedPowerSyncConfig;
|
|
23
|
-
/**
|
|
24
|
-
* Service-wide parser containing every extension registered during module initialization.
|
|
25
|
-
*/
|
|
26
|
-
syncConfigParser: SyncConfigParser;
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
/**
|
|
@@ -37,7 +32,7 @@ export interface StorageProvider {
|
|
|
37
32
|
type: string;
|
|
38
33
|
|
|
39
34
|
/**
|
|
40
|
-
* Creates active storage during storage-engine startup
|
|
35
|
+
* Creates active storage during storage-engine startup.
|
|
41
36
|
*/
|
|
42
37
|
getStorage(options: GetStorageOptions): Promise<ActiveStorage>;
|
|
43
38
|
}
|
|
@@ -11,11 +11,11 @@ import * as util from '../util/util-index.js';
|
|
|
11
11
|
import { BucketStorageBatch, FlushedResult, SaveUpdate } from './BucketStorageBatch.js';
|
|
12
12
|
import { BucketStorageFactory } from './BucketStorageFactory.js';
|
|
13
13
|
import { ParsedSyncConfigSet } from './ParsedSyncConfigSet.js';
|
|
14
|
+
import type { ParseSyncConfigOptions } from './PersistedSyncConfigContent.js';
|
|
14
15
|
import { SourceEntityDescriptor } from './SourceEntity.js';
|
|
15
16
|
import { SourceTable } from './SourceTable.js';
|
|
16
17
|
import { SourceTableCandidateReconciler } from './SourceTableReconciler.js';
|
|
17
18
|
import { StorageVersionConfig } from './StorageVersionConfig.js';
|
|
18
|
-
import { ParseSyncConfigOptions } from './SyncConfigParser.js';
|
|
19
19
|
import { SyncStorageWriteCheckpointAPI } from './WriteCheckpointAPI.js';
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -25,4 +25,3 @@ export * from './implementation/BucketDefinitionMapping.js';
|
|
|
25
25
|
export * from './implementation/IncrementalReprocessingCompatibility.js';
|
|
26
26
|
export * from './implementation/IncrementalReprocessingSyncConfigLog.js';
|
|
27
27
|
export * from './implementation/ReplicationStreamStorageIds.js';
|
|
28
|
-
export * from './SyncConfigParser.js';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { container, LifeCycledSystem, MigrationManager, ServiceIdentifier } from '@powersync/lib-services-framework';
|
|
2
|
-
import type { AdditionalSyncConfigParser } from '@powersync/service-sync-rules';
|
|
3
2
|
|
|
4
3
|
import { EventsEngine } from '../events/EventsEngine.js';
|
|
5
4
|
import { framework } from '../index.js';
|
|
@@ -11,16 +10,6 @@ import * as storage from '../storage/storage-index.js';
|
|
|
11
10
|
import { SyncContext } from '../sync/SyncContext.js';
|
|
12
11
|
import * as utils from '../util/util-index.js';
|
|
13
12
|
|
|
14
|
-
/**
|
|
15
|
-
* Registration-capable sync-config parser exposed to modules through the service context.
|
|
16
|
-
*/
|
|
17
|
-
export interface ServiceContextSyncConfigParser extends storage.SyncConfigParser {
|
|
18
|
-
/**
|
|
19
|
-
* Registers a deterministic parser extension during module initialization, before storage starts.
|
|
20
|
-
*/
|
|
21
|
-
registerParser(extension: AdditionalSyncConfigParser): void;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
13
|
export interface ServiceContext {
|
|
25
14
|
configuration: utils.ResolvedPowerSyncConfig;
|
|
26
15
|
lifeCycleEngine: LifeCycledSystem;
|
|
@@ -33,11 +22,6 @@ export interface ServiceContext {
|
|
|
33
22
|
writeCheckpointBatcher: utils.WriteCheckpointBatcher;
|
|
34
23
|
serviceMode: ServiceContextMode;
|
|
35
24
|
eventsEngine: EventsEngine;
|
|
36
|
-
/**
|
|
37
|
-
* Service-wide parser shared by routes, replication, and storage. Source modules register parser extensions on this
|
|
38
|
-
* instance during module initialization.
|
|
39
|
-
*/
|
|
40
|
-
readonly syncConfigParser: ServiceContextSyncConfigParser;
|
|
41
25
|
}
|
|
42
26
|
|
|
43
27
|
export enum ServiceContextMode {
|
|
@@ -69,20 +53,16 @@ export class ServiceContextContainer implements ServiceContext {
|
|
|
69
53
|
routerEngine: routes.RouterEngine;
|
|
70
54
|
writeCheckpointBatcher: utils.WriteCheckpointBatcher;
|
|
71
55
|
serviceMode: ServiceContextMode;
|
|
72
|
-
readonly #syncConfigParser: ServiceContextSyncConfigParser;
|
|
73
56
|
|
|
74
57
|
constructor(options: ServiceContextOptions) {
|
|
75
58
|
this.serviceMode = options.serviceMode;
|
|
76
59
|
const { configuration } = options;
|
|
77
60
|
this.configuration = configuration;
|
|
78
61
|
|
|
79
|
-
this.#syncConfigParser = new ServiceContextSyncConfigParserImpl(() => this.storageEngine.started);
|
|
80
|
-
|
|
81
62
|
this.lifeCycleEngine = new LifeCycledSystem();
|
|
82
63
|
|
|
83
64
|
this.storageEngine = new storage.StorageEngine({
|
|
84
|
-
configuration
|
|
85
|
-
syncConfigParser: this.#syncConfigParser
|
|
65
|
+
configuration
|
|
86
66
|
});
|
|
87
67
|
this.storageEngine.registerListener({
|
|
88
68
|
storageFatalError: (error) => {
|
|
@@ -134,13 +114,6 @@ export class ServiceContextContainer implements ServiceContext {
|
|
|
134
114
|
return container.getOptional(replication.ReplicationEngine);
|
|
135
115
|
}
|
|
136
116
|
|
|
137
|
-
/**
|
|
138
|
-
* Returns the service-wide parser shared by routes, replication, and storage.
|
|
139
|
-
*/
|
|
140
|
-
get syncConfigParser(): ServiceContextSyncConfigParser {
|
|
141
|
-
return this.#syncConfigParser;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
117
|
get metricsEngine(): metrics.MetricsEngine {
|
|
145
118
|
return container.getImplementation(metrics.MetricsEngine);
|
|
146
119
|
}
|
|
@@ -164,22 +137,3 @@ export class ServiceContextContainer implements ServiceContext {
|
|
|
164
137
|
return container.getImplementation(identifier);
|
|
165
138
|
}
|
|
166
139
|
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Registration-capable parser exposed by the service context during module initialization.
|
|
170
|
-
*/
|
|
171
|
-
class ServiceContextSyncConfigParserImpl extends storage.SqlSyncConfigParser implements ServiceContextSyncConfigParser {
|
|
172
|
-
constructor(private readonly isStorageStarted: () => boolean) {
|
|
173
|
-
super();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Registers an extension while preserving one parser definition for the service lifetime.
|
|
178
|
-
*/
|
|
179
|
-
override registerParser(extension: AdditionalSyncConfigParser): void {
|
|
180
|
-
if (this.isStorageStarted()) {
|
|
181
|
-
throw new Error('A sync config parser extension cannot be registered after the storage engine has started.');
|
|
182
|
-
}
|
|
183
|
-
super.registerParser(extension);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { RouteAPI } from '@/api/RouteAPI.js';
|
|
2
|
+
import { assertSourceCapabilities } from '@/api/source-capabilities.js';
|
|
1
3
|
import { AbstractReplicationJob } from '@/replication/AbstractReplicationJob.js';
|
|
2
4
|
import { AbstractReplicator, AbstractReplicatorOptions, CreateJobOptions } from '@/replication/AbstractReplicator.js';
|
|
3
5
|
import { PersistedReplicationStream } from '@/storage/PersistedReplicationStream.js';
|
|
4
|
-
import {
|
|
6
|
+
import type { ReplicationLock } from '@/storage/ReplicationLock.js';
|
|
5
7
|
import { SyncRulesBucketStorage } from '@/storage/SyncRulesBucketStorage.js';
|
|
6
|
-
import { PrecompiledSyncConfig } from '@powersync/service-sync-rules';
|
|
7
8
|
import { describe, expect, it, vi } from 'vitest';
|
|
8
9
|
|
|
9
10
|
class TestReplicator extends AbstractReplicator {
|
|
@@ -54,6 +55,14 @@ class TestReplicator extends AbstractReplicator {
|
|
|
54
55
|
await (this as any).runLoop();
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
async refreshForTest(configuredLock?: ReplicationLock): Promise<{ replicationJobStarted: boolean }> {
|
|
59
|
+
(this as any).abortController = new AbortController();
|
|
60
|
+
return (this as any).refresh({
|
|
61
|
+
configuredLock,
|
|
62
|
+
loadedVersionLabel: this.syncRuleProvider.versionLabel
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
57
66
|
shouldHandleStreamForTest(
|
|
58
67
|
replicationStream: PersistedReplicationStream,
|
|
59
68
|
loadedSyncRules: string | undefined,
|
|
@@ -64,26 +73,102 @@ class TestReplicator extends AbstractReplicator {
|
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
describe('AbstractReplicator startup sync config', () => {
|
|
67
|
-
it.each([true, false])('
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
it.each([true, false])('respects exit_on_error=%s for unsupported file-loaded filters', async (exitOnError) => {
|
|
77
|
+
const yaml = /* yaml */ `
|
|
78
|
+
# sync config fixture.
|
|
79
|
+
config:
|
|
80
|
+
edition: 3
|
|
81
|
+
source_table_options:
|
|
82
|
+
orders:
|
|
83
|
+
mongodb_filter_expression: { $eq: ['$$doc.active', true] }
|
|
84
|
+
streams:
|
|
85
|
+
orders:
|
|
86
|
+
query: SELECT * FROM orders
|
|
87
|
+
`;
|
|
88
|
+
const configureSyncRules = vi.fn(
|
|
89
|
+
async (_options: import('@/storage/BucketStorageFactory.js').UpdateSyncRulesOptions) => ({ updated: false })
|
|
90
|
+
);
|
|
91
|
+
const replicator = new TestReplicator(async () => {}, {
|
|
92
|
+
id: 'test',
|
|
93
|
+
storageEngine: {
|
|
94
|
+
activeBucketStorage: { configureSyncRules }
|
|
95
|
+
} as unknown as AbstractReplicatorOptions['storageEngine'],
|
|
96
|
+
configuration: { connections: [{ type: 'postgresql' }] },
|
|
97
|
+
syncRuleProvider: { get: async () => yaml, exitOnError, versionLabel: undefined },
|
|
98
|
+
metricsEngine: {} as AbstractReplicatorOptions['metricsEngine'],
|
|
99
|
+
rateLimiter: {} as AbstractReplicatorOptions['rateLimiter']
|
|
100
|
+
});
|
|
101
|
+
if (exitOnError) {
|
|
102
|
+
await expect(replicator.runStartupForTest()).rejects.toThrow('only supported by MongoDB sources');
|
|
103
|
+
expect(configureSyncRules).not.toHaveBeenCalled();
|
|
104
|
+
} else {
|
|
105
|
+
await expect(replicator.runStartupForTest()).resolves.toBeUndefined();
|
|
106
|
+
expect(configureSyncRules).toHaveBeenCalledOnce();
|
|
107
|
+
expect(configureSyncRules.mock.calls[0][0].config.plan?.errors).toEqual([
|
|
108
|
+
expect.objectContaining({
|
|
109
|
+
level: 'fatal',
|
|
110
|
+
message: expect.stringContaining('only supported by MongoDB sources')
|
|
111
|
+
})
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it.each(
|
|
117
|
+
[true, false].flatMap((exitOnError) =>
|
|
118
|
+
(['warning', 'valid', 'unexpected error'] as const).map((result) => ({ exitOnError, result }))
|
|
119
|
+
)
|
|
120
|
+
)(
|
|
121
|
+
'checks source capabilities before persistence: $result, exit_on_error=$exitOnError',
|
|
122
|
+
async ({ result, exitOnError }) => {
|
|
123
|
+
const yaml = /* yaml */ `
|
|
124
|
+
# sync config fixture.
|
|
125
|
+
config:
|
|
126
|
+
edition: 3
|
|
127
|
+
streams:
|
|
128
|
+
orders:
|
|
129
|
+
query: SELECT * FROM orders
|
|
130
|
+
`;
|
|
131
|
+
const calls: string[] = [];
|
|
132
|
+
const configureSyncRules = vi.fn(async () => {
|
|
133
|
+
calls.push('persist');
|
|
134
|
+
return { updated: false };
|
|
135
|
+
});
|
|
136
|
+
const replicator = new TestReplicator(async () => {}, {
|
|
137
|
+
id: 'test',
|
|
138
|
+
storageEngine: {
|
|
139
|
+
activeBucketStorage: { configureSyncRules }
|
|
140
|
+
} as unknown as AbstractReplicatorOptions['storageEngine'],
|
|
141
|
+
syncRuleProvider: { get: async () => yaml, exitOnError, versionLabel: undefined },
|
|
142
|
+
metricsEngine: {} as AbstractReplicatorOptions['metricsEngine'],
|
|
143
|
+
rateLimiter: {} as AbstractReplicatorOptions['rateLimiter']
|
|
144
|
+
});
|
|
145
|
+
replicator.registerSourceCapabilitiesAssertion((config) =>
|
|
146
|
+
assertSourceCapabilities(
|
|
147
|
+
{
|
|
148
|
+
async validateSourceCapabilities() {
|
|
149
|
+
calls.push('validate');
|
|
150
|
+
if (result === 'unexpected error') throw new Error('Source validation failed');
|
|
151
|
+
return result === 'warning' ? [{ level: 'warning', message: 'Missing index' }] : [];
|
|
152
|
+
}
|
|
153
|
+
} as unknown as RouteAPI,
|
|
154
|
+
config
|
|
155
|
+
)
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
if (result === 'unexpected error' && exitOnError) {
|
|
159
|
+
await expect(replicator.runStartupForTest()).rejects.toThrow('Source validation failed');
|
|
160
|
+
expect(calls).toEqual(['validate']);
|
|
161
|
+
} else {
|
|
162
|
+
await replicator.runStartupForTest();
|
|
163
|
+
expect(calls).toEqual(['validate', 'persist']);
|
|
82
164
|
}
|
|
83
|
-
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
it.each([true, false])('retains source-table options with exit_on_error=%s', async (exitOnError) => {
|
|
84
169
|
const yaml = /* yaml */ `
|
|
85
170
|
{
|
|
86
|
-
config: { edition: 3, source_table_options: { orders: {
|
|
171
|
+
config: { edition: 3, source_table_options: { orders: { mongodb_filter_expression: 'disabled' } } },
|
|
87
172
|
streams: { orders: { query: SELECT * FROM orders } }
|
|
88
173
|
}
|
|
89
174
|
`;
|
|
@@ -91,7 +176,7 @@ describe('AbstractReplicator startup sync config', () => {
|
|
|
91
176
|
const replicator = new TestReplicator(async () => {}, {
|
|
92
177
|
id: 'test',
|
|
93
178
|
storageEngine: {
|
|
94
|
-
activeBucketStorage: {
|
|
179
|
+
activeBucketStorage: { configureSyncRules }
|
|
95
180
|
} as unknown as AbstractReplicatorOptions['storageEngine'],
|
|
96
181
|
syncRuleProvider: { get: async () => yaml, exitOnError, versionLabel: 'v2' },
|
|
97
182
|
metricsEngine: {} as AbstractReplicatorOptions['metricsEngine'],
|
|
@@ -108,14 +193,15 @@ describe('AbstractReplicator startup sync config', () => {
|
|
|
108
193
|
parsed: expect.objectContaining({
|
|
109
194
|
errors: [],
|
|
110
195
|
config: expect.objectContaining({
|
|
111
|
-
|
|
196
|
+
plan: expect.objectContaining({
|
|
197
|
+
sourceTableConfig: { orders: { mongodb_filter_expression: 'disabled' } }
|
|
198
|
+
})
|
|
112
199
|
})
|
|
113
200
|
}),
|
|
114
201
|
plan: expect.objectContaining({
|
|
115
202
|
plan: expect.objectContaining({
|
|
116
203
|
version: 3,
|
|
117
|
-
sourceTableConfig: { orders: {
|
|
118
|
-
moduleData: { 'example.tables': null }
|
|
204
|
+
sourceTableConfig: { orders: { mongodb_filter_expression: 'disabled' } }
|
|
119
205
|
})
|
|
120
206
|
})
|
|
121
207
|
})
|
|
@@ -11,7 +11,6 @@ import { describe, expect, test } from 'vitest';
|
|
|
11
11
|
import {
|
|
12
12
|
parsePersistedSyncConfigContent,
|
|
13
13
|
SerializedSyncPlan,
|
|
14
|
-
SqlSyncConfigParser,
|
|
15
14
|
updateSyncRulesFromConfig
|
|
16
15
|
} from '../../src/storage/storage-index.js';
|
|
17
16
|
|
|
@@ -148,7 +147,6 @@ function restore(compiledPlan: SerializedSyncPlan) {
|
|
|
148
147
|
content: yamlWithEvents,
|
|
149
148
|
compiledPlan,
|
|
150
149
|
storageVersion: 1,
|
|
151
|
-
parseOptions: { defaultSchema: 'test_schema' }
|
|
152
|
-
syncConfigParser: new SqlSyncConfigParser()
|
|
150
|
+
parseOptions: { defaultSchema: 'test_schema' }
|
|
153
151
|
});
|
|
154
152
|
}
|
|
@@ -230,3 +230,107 @@ streams:
|
|
|
230
230
|
expect(yaml.slice(error.location!.start_offset, error.location!.end_offset)).toBe('unknown_key');
|
|
231
231
|
});
|
|
232
232
|
});
|
|
233
|
+
|
|
234
|
+
describe('source capability validation', () => {
|
|
235
|
+
test('exposes stored replication errors when source checks cannot run', async () => {
|
|
236
|
+
const content = makeSyncRulesContent({
|
|
237
|
+
status: {
|
|
238
|
+
id: '1',
|
|
239
|
+
replicationStreamId: 1,
|
|
240
|
+
state: storage.SyncRuleState.PROCESSING,
|
|
241
|
+
last_checkpoint_lsn: null,
|
|
242
|
+
last_fatal_error: 'Source capability unavailable',
|
|
243
|
+
last_fatal_error_ts: new Date(),
|
|
244
|
+
last_keepalive_ts: null,
|
|
245
|
+
last_checkpoint_ts: null
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
const result = await getSyncRulesStatus(
|
|
249
|
+
makeRouteAPI(),
|
|
250
|
+
content,
|
|
251
|
+
{
|
|
252
|
+
...OPTIONS,
|
|
253
|
+
check_connection: false,
|
|
254
|
+
active: false,
|
|
255
|
+
include_content: true
|
|
256
|
+
},
|
|
257
|
+
makeSystemStorage()
|
|
258
|
+
);
|
|
259
|
+
expect(result?.content).toBe(MINIMAL_SYNC_RULES);
|
|
260
|
+
expect(result?.errors).toContainEqual(
|
|
261
|
+
expect.objectContaining({
|
|
262
|
+
level: 'fatal',
|
|
263
|
+
message: 'Source capability unavailable'
|
|
264
|
+
})
|
|
265
|
+
);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test('reports capability failures alongside table diagnostics', async () => {
|
|
269
|
+
const api = makeRouteAPI();
|
|
270
|
+
api.validateSourceCapabilities = async () => [
|
|
271
|
+
{ level: 'fatal', message: 'Source capability unavailable' },
|
|
272
|
+
{ level: 'warning', message: 'Source advisory', location: { start_offset: 1, end_offset: 4 } }
|
|
273
|
+
];
|
|
274
|
+
api.getDebugTablesInfo = async () => [
|
|
275
|
+
{
|
|
276
|
+
schema: 'public',
|
|
277
|
+
pattern: 'items',
|
|
278
|
+
wildcard: false,
|
|
279
|
+
table: {
|
|
280
|
+
schema: 'public',
|
|
281
|
+
name: 'items',
|
|
282
|
+
data_queries: true,
|
|
283
|
+
parameter_queries: false,
|
|
284
|
+
replication_id: [],
|
|
285
|
+
errors: [{ level: 'warning', message: 'Index missing' }]
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
];
|
|
289
|
+
const result = await getSyncRulesStatus(api, makeSyncRulesContent(), OPTIONS, makeSystemStorage());
|
|
290
|
+
expect(result!.errors).toEqual(
|
|
291
|
+
expect.arrayContaining([
|
|
292
|
+
expect.objectContaining({ level: 'fatal', message: 'Source capability unavailable' }),
|
|
293
|
+
expect.objectContaining({ level: 'warning', message: 'Index missing' }),
|
|
294
|
+
expect.objectContaining({
|
|
295
|
+
level: 'warning',
|
|
296
|
+
message: 'Source advisory',
|
|
297
|
+
location: { start_offset: 1, end_offset: 4 }
|
|
298
|
+
})
|
|
299
|
+
])
|
|
300
|
+
);
|
|
301
|
+
expect(result!.connections[0].tables).toHaveLength(1);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
test('preserves both validation failures and continues independent diagnostics', async () => {
|
|
305
|
+
const api = makeRouteAPI({
|
|
306
|
+
wal_status: 'extended',
|
|
307
|
+
safe_wal_size: 4 * GB,
|
|
308
|
+
max_slot_wal_keep_size: 10 * GB
|
|
309
|
+
});
|
|
310
|
+
api.validateSourceCapabilities = async () => {
|
|
311
|
+
throw new Error('Source capability unavailable');
|
|
312
|
+
};
|
|
313
|
+
api.getDebugTablesInfo = async () => {
|
|
314
|
+
throw new Error('Table metadata unavailable');
|
|
315
|
+
};
|
|
316
|
+
const result = await getSyncRulesStatus(api, makeSyncRulesContent(), OPTIONS, makeSystemStorage());
|
|
317
|
+
expect(result!.errors).toEqual(
|
|
318
|
+
expect.arrayContaining([
|
|
319
|
+
expect.objectContaining({ level: 'fatal', message: 'Source capability unavailable' }),
|
|
320
|
+
expect.objectContaining({ level: 'fatal', message: 'Table metadata unavailable' }),
|
|
321
|
+
expect.objectContaining({ level: 'warning', message: expect.stringContaining('WAL budget') })
|
|
322
|
+
])
|
|
323
|
+
);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test('does not check capabilities when connection checks are disabled', async () => {
|
|
327
|
+
const api = makeRouteAPI();
|
|
328
|
+
let called = false;
|
|
329
|
+
api.validateSourceCapabilities = async () => {
|
|
330
|
+
called = true;
|
|
331
|
+
return [];
|
|
332
|
+
};
|
|
333
|
+
await getSyncRulesStatus(api, makeSyncRulesContent(), { ...OPTIONS, check_connection: false }, makeSystemStorage());
|
|
334
|
+
expect(called).toBe(false);
|
|
335
|
+
});
|
|
336
|
+
});
|