@powersync/service-core 0.0.0-dev-20261005120023 → 0.0.0-dev-20261007110800
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 +22 -11
- 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 +12 -0
- package/dist/api/source-capabilities.js +27 -0
- package/dist/api/source-capabilities.js.map +1 -0
- package/dist/replication/AbstractReplicator.d.ts +6 -0
- package/dist/replication/AbstractReplicator.js +12 -2
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/replication/ReplicationModule.js +10 -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 +51 -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 +4 -4
- 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 +31 -0
- package/src/replication/AbstractReplicator.ts +14 -2
- package/src/replication/ReplicationModule.ts +9 -2
- package/src/routes/endpoints/admin.ts +14 -6
- package/src/routes/endpoints/sync-rules.ts +52 -16
- package/src/storage/BucketStorageFactory.ts +21 -19
- package/src/storage/PersistedReplicationStream.ts +1 -2
- package/src/storage/PersistedSyncConfigContent.ts +9 -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 +94 -23
- package/test/src/PersistedSyncConfigContent.test.ts +1 -3
- package/test/src/diagnostics.test.ts +71 -0
- package/test/src/routes/admin.test.ts +205 -11
- package/test/src/routes/mocks.ts +0 -2
- package/test/src/routes/sync-rules.test.ts +76 -0
- package/test/src/source-capabilities.test.ts +42 -0
- package/test/src/source_table_config.test.ts +55 -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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { BasicRouterRequest, Context, JwtPayload } from '@/index.js';
|
|
2
|
+
import { logger } from '@powersync/lib-services-framework';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { deploySyncRules } from '../../../src/routes/endpoints/sync-rules.js';
|
|
5
|
+
import { mockServiceContext } from './mocks.js';
|
|
6
|
+
|
|
7
|
+
describe('sync-rules routes', () => {
|
|
8
|
+
const request: BasicRouterRequest = {
|
|
9
|
+
headers: {},
|
|
10
|
+
hostname: '',
|
|
11
|
+
protocol: 'http'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function makeContext(): Context {
|
|
15
|
+
const service_context = mockServiceContext(null);
|
|
16
|
+
(service_context.storageEngine as any).activeBucketStorage = {
|
|
17
|
+
updateSyncRules: vi.fn(async () => ({ replicationStreamName: 'new_slot' }))
|
|
18
|
+
};
|
|
19
|
+
// Deploying through the API requires the sync config to not be set in the service config.
|
|
20
|
+
(service_context as any).configuration = { sync_rules: { present: false } };
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
logger: logger,
|
|
24
|
+
service_context,
|
|
25
|
+
token_payload: new JwtPayload({
|
|
26
|
+
sub: '',
|
|
27
|
+
exp: 0,
|
|
28
|
+
iat: 0
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('deploy', () => {
|
|
34
|
+
it('logs that bucket_definitions are deprecated', async () => {
|
|
35
|
+
const warnSpy = vi.spyOn(logger, 'warn');
|
|
36
|
+
|
|
37
|
+
const response = await deploySyncRules.handler({
|
|
38
|
+
context: makeContext(),
|
|
39
|
+
params: {
|
|
40
|
+
content: `
|
|
41
|
+
bucket_definitions:
|
|
42
|
+
global:
|
|
43
|
+
data:
|
|
44
|
+
- SELECT id FROM test
|
|
45
|
+
`
|
|
46
|
+
},
|
|
47
|
+
request
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(response).toEqual({ slot_name: 'new_slot' });
|
|
51
|
+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Sync Rules (`bucket_definitions`) are deprecated'));
|
|
52
|
+
warnSpy.mockRestore();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('does not log a warning for a Sync Streams config', async () => {
|
|
56
|
+
const warnSpy = vi.spyOn(logger, 'warn');
|
|
57
|
+
|
|
58
|
+
await deploySyncRules.handler({
|
|
59
|
+
context: makeContext(),
|
|
60
|
+
params: {
|
|
61
|
+
content: `
|
|
62
|
+
config:
|
|
63
|
+
edition: 3
|
|
64
|
+
streams:
|
|
65
|
+
global:
|
|
66
|
+
query: SELECT id FROM test
|
|
67
|
+
`
|
|
68
|
+
},
|
|
69
|
+
request
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(warnSpy).not.toHaveBeenCalledWith(expect.stringContaining('Sync config warning'));
|
|
73
|
+
warnSpy.mockRestore();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { RouteAPI } from '@/api/RouteAPI.js';
|
|
2
|
+
import { assertSourceCapabilities, validateNoMongoFilterExpressions } from '@/api/source-capabilities.js';
|
|
3
|
+
import { SqlSyncRules } from '@powersync/service-sync-rules';
|
|
4
|
+
import { describe, expect, test } from 'vitest';
|
|
5
|
+
|
|
6
|
+
const FILTERED_CONFIG = /* yaml */ `
|
|
7
|
+
# Sync config fixture.
|
|
8
|
+
config:
|
|
9
|
+
edition: 3
|
|
10
|
+
source_table_options:
|
|
11
|
+
orders:
|
|
12
|
+
mongodb_filter_expression: { $eq: ['$$doc.active', true] }
|
|
13
|
+
streams:
|
|
14
|
+
orders:
|
|
15
|
+
query: SELECT * FROM orders
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
describe('unsupported MongoDB source options', () => {
|
|
19
|
+
test('blocks deployment when a non-MongoDB source uses filtering', async () => {
|
|
20
|
+
const { config } = SqlSyncRules.fromYaml(FILTERED_CONFIG, { defaultSchema: 'public' });
|
|
21
|
+
const adapter = {
|
|
22
|
+
async validateSourceCapabilities(config) {
|
|
23
|
+
return validateNoMongoFilterExpressions(config, 'default');
|
|
24
|
+
}
|
|
25
|
+
} satisfies Pick<RouteAPI, 'validateSourceCapabilities'>;
|
|
26
|
+
await expect(assertSourceCapabilities(adapter as unknown as RouteAPI, config)).rejects.toThrow(
|
|
27
|
+
'only supported by MongoDB sources'
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('ignores options for a different connection', () => {
|
|
32
|
+
const { config } = SqlSyncRules.fromYaml(FILTERED_CONFIG, { defaultSchema: 'public' });
|
|
33
|
+
expect(validateNoMongoFilterExpressions(config, 'other')).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('allows disabled filtering', () => {
|
|
37
|
+
const { config } = SqlSyncRules.fromYaml(FILTERED_CONFIG.replace("{ $eq: ['$$doc.active', true] }", 'disabled'), {
|
|
38
|
+
defaultSchema: 'public'
|
|
39
|
+
});
|
|
40
|
+
expect(validateNoMongoFilterExpressions(config, 'default')).toEqual([]);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { isCompatible, parsePersistedSyncConfigContent, updateSyncRulesFromConfig } from '@/storage/storage-index.js';
|
|
2
|
+
import { logger } from '@powersync/lib-services-framework';
|
|
3
|
+
import { PrecompiledSyncConfig, SqlSyncRules } from '@powersync/service-sync-rules';
|
|
4
|
+
import { describe, expect, test } from 'vitest';
|
|
5
|
+
|
|
6
|
+
const CONFIGURED = /* yaml */ `
|
|
7
|
+
# Sync config fixture.
|
|
8
|
+
config:
|
|
9
|
+
edition: 3
|
|
10
|
+
source_table_options:
|
|
11
|
+
orders:
|
|
12
|
+
mongodb_filter_expression: { $eq: ['$$doc.active', true] }
|
|
13
|
+
streams:
|
|
14
|
+
orders:
|
|
15
|
+
query: SELECT * FROM orders
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
describe('source-table options', () => {
|
|
19
|
+
test('parses without module registration and preserves filters through compiled storage', () => {
|
|
20
|
+
const parsed = SqlSyncRules.fromYaml(CONFIGURED, { defaultSchema: 'app' });
|
|
21
|
+
const update = updateSyncRulesFromConfig(parsed);
|
|
22
|
+
const restored = parsePersistedSyncConfigContent({
|
|
23
|
+
content: CONFIGURED,
|
|
24
|
+
compiledPlan: update.config.plan!,
|
|
25
|
+
storageVersion: 2,
|
|
26
|
+
parseOptions: { defaultSchema: 'app' }
|
|
27
|
+
});
|
|
28
|
+
expect((restored.config as PrecompiledSyncConfig).plan.sourceTableConfig).toEqual(
|
|
29
|
+
(parsed.config as PrecompiledSyncConfig).plan.sourceTableConfig
|
|
30
|
+
);
|
|
31
|
+
expect(update.config.plan!.plan).not.toHaveProperty('moduleData');
|
|
32
|
+
});
|
|
33
|
+
test('reports invalid expressions before storage', () => {
|
|
34
|
+
expect(() =>
|
|
35
|
+
SqlSyncRules.fromYaml(CONFIGURED.replace('$$doc.active', '$doc.active'), {
|
|
36
|
+
defaultSchema: 'app'
|
|
37
|
+
})
|
|
38
|
+
).toThrow('Expected a source field');
|
|
39
|
+
});
|
|
40
|
+
test('removing filters after a downgrade requires replacement processing', () => {
|
|
41
|
+
const deploy = (yaml: string) => updateSyncRulesFromConfig(SqlSyncRules.fromYaml(yaml, { defaultSchema: 'app' }));
|
|
42
|
+
const first = deploy(CONFIGURED);
|
|
43
|
+
const same = deploy(CONFIGURED.replace('SELECT *', 'SELECT id'));
|
|
44
|
+
const changed = deploy(CONFIGURED.replace('true', 'false'));
|
|
45
|
+
const removed = deploy(
|
|
46
|
+
CONFIGURED.replace(
|
|
47
|
+
"mongodb_filter_expression: { $eq: ['$$doc.active', true] }",
|
|
48
|
+
'mongodb_filter_expression: disabled'
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
expect(isCompatible([first.config.plan], same.config, logger)).toBe(true);
|
|
52
|
+
expect(isCompatible([first.config.plan], changed.config, logger)).toBe(false);
|
|
53
|
+
expect(isCompatible([first.config.plan], removed.config, logger)).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import * as storage from '../../../src/storage/storage-index.js';
|
|
3
|
+
|
|
4
|
+
describe('logSyncConfigErrors', () => {
|
|
5
|
+
function makeLogger() {
|
|
6
|
+
return { warn: vi.fn(), error: vi.fn() };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
test('logs fatal errors and warnings when the sync config is not validated', () => {
|
|
10
|
+
// Without validation, as at startup with exit_on_error: false, parsing doesn't throw on fatal errors.
|
|
11
|
+
const updateOptions = storage.updateSyncRulesFromYaml(
|
|
12
|
+
`
|
|
13
|
+
bucket_definitions:
|
|
14
|
+
mybucket:
|
|
15
|
+
data:
|
|
16
|
+
- SELECT FROM
|
|
17
|
+
`,
|
|
18
|
+
{ validate: false }
|
|
19
|
+
);
|
|
20
|
+
const log = makeLogger();
|
|
21
|
+
|
|
22
|
+
storage.logSyncConfigErrors(updateOptions.config.parsed, log as any);
|
|
23
|
+
|
|
24
|
+
expect(log.error).toHaveBeenCalledWith(expect.stringContaining('Sync config error:'));
|
|
25
|
+
expect(log.warn).toHaveBeenCalledWith(expect.stringContaining('Sync Rules (`bucket_definitions`) are deprecated'));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('logs nothing for a valid Sync Streams config', () => {
|
|
29
|
+
const updateOptions = storage.updateSyncRulesFromYaml(
|
|
30
|
+
`
|
|
31
|
+
config:
|
|
32
|
+
edition: 3
|
|
33
|
+
streams:
|
|
34
|
+
global:
|
|
35
|
+
query: SELECT id FROM test
|
|
36
|
+
`,
|
|
37
|
+
{ validate: true }
|
|
38
|
+
);
|
|
39
|
+
const log = makeLogger();
|
|
40
|
+
|
|
41
|
+
storage.logSyncConfigErrors(updateOptions.config.parsed, log as any);
|
|
42
|
+
|
|
43
|
+
expect(log.error).not.toHaveBeenCalled();
|
|
44
|
+
expect(log.warn).not.toHaveBeenCalled();
|
|
45
|
+
});
|
|
46
|
+
});
|