@powersync/service-core 0.0.0-dev-20260803144812 → 0.0.0-dev-20260929095716
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 +114 -5
- package/dist/api/diagnostics.js +7 -2
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/entry/commands/compact-action.js +29 -25
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/entry/commands/config-command.js +1 -1
- package/dist/entry/commands/config-command.js.map +1 -1
- package/dist/metrics/metrics-interfaces.d.ts +5 -1
- package/dist/metrics/metrics-interfaces.js.map +1 -1
- package/dist/metrics/open-telemetry/MetricAttributeFilteringExporter.d.ts +36 -0
- package/dist/metrics/open-telemetry/MetricAttributeFilteringExporter.js +70 -0
- package/dist/metrics/open-telemetry/MetricAttributeFilteringExporter.js.map +1 -0
- package/dist/metrics/open-telemetry/OpenTelemetryMetricsFactory.js +6 -1
- package/dist/metrics/open-telemetry/OpenTelemetryMetricsFactory.js.map +1 -1
- package/dist/metrics/open-telemetry/util.js +7 -3
- package/dist/metrics/open-telemetry/util.js.map +1 -1
- package/dist/migrations/PowerSyncMigrationManager.js +2 -1
- package/dist/migrations/PowerSyncMigrationManager.js.map +1 -1
- package/dist/replication/AbstractReplicator.d.ts +5 -0
- package/dist/replication/AbstractReplicator.js +31 -13
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/replication/ReplicationModule.d.ts +0 -7
- package/dist/replication/ReplicationModule.js +0 -1
- package/dist/replication/ReplicationModule.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +12 -3
- package/dist/routes/endpoints/admin.d.ts +24 -6
- package/dist/routes/endpoints/admin.js +17 -11
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/socket-route.js +7 -5
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/endpoints/sync-rules.js +18 -10
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/storage/BucketStorageBatch.d.ts +2 -1
- package/dist/storage/BucketStorageBatch.js.map +1 -1
- package/dist/storage/BucketStorageFactory.d.ts +49 -6
- package/dist/storage/BucketStorageFactory.js +25 -8
- package/dist/storage/BucketStorageFactory.js.map +1 -1
- package/dist/storage/PersistedReplicationStream.d.ts +2 -1
- package/dist/storage/PersistedReplicationStream.js.map +1 -1
- package/dist/storage/PersistedSyncConfigContent.d.ts +6 -4
- package/dist/storage/PersistedSyncConfigContent.js +34 -14
- package/dist/storage/PersistedSyncConfigContent.js.map +1 -1
- package/dist/storage/ReplicationEventPayload.d.ts +6 -1
- package/dist/storage/SourceEntity.d.ts +7 -2
- package/dist/storage/SourceTable.d.ts +37 -6
- package/dist/storage/SourceTable.js +42 -10
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/SourceTableReconciler.d.ts +83 -0
- package/dist/storage/SourceTableReconciler.js +95 -0
- package/dist/storage/SourceTableReconciler.js.map +1 -0
- package/dist/storage/StorageEngine.d.ts +4 -0
- package/dist/storage/StorageEngine.js +7 -1
- package/dist/storage/StorageEngine.js.map +1 -1
- package/dist/storage/StorageProvider.d.ts +8 -0
- package/dist/storage/StorageVersionConfig.d.ts +4 -0
- package/dist/storage/StorageVersionConfig.js +10 -1
- package/dist/storage/StorageVersionConfig.js.map +1 -1
- package/dist/storage/SyncConfigParser.d.ts +44 -0
- package/dist/storage/SyncConfigParser.js +70 -0
- package/dist/storage/SyncConfigParser.js.map +1 -0
- package/dist/storage/SyncRulesBucketStorage.d.ts +48 -8
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
- package/dist/storage/WriteCheckpointAPI.d.ts +25 -3
- package/dist/storage/WriteCheckpointAPI.js.map +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +23 -7
- package/dist/storage/implementation/BucketDefinitionMapping.js +88 -14
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -1
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js +9 -5
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js.map +1 -1
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js +9 -1
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js.map +1 -1
- package/dist/storage/storage-index.d.ts +2 -0
- package/dist/storage/storage-index.js +2 -0
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/storage/storage-metrics.js +120 -4
- package/dist/storage/storage-metrics.js.map +1 -1
- package/dist/sync/BucketChecksumState.d.ts +2 -2
- package/dist/sync/BucketChecksumState.js +5 -4
- package/dist/sync/BucketChecksumState.js.map +1 -1
- package/dist/sync/sync.js +37 -9
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/util.d.ts +1 -1
- package/dist/sync/util.js +13 -1
- package/dist/sync/util.js.map +1 -1
- package/dist/system/ServiceContext.d.ts +20 -0
- package/dist/system/ServiceContext.js +29 -1
- package/dist/system/ServiceContext.js.map +1 -1
- package/dist/util/config/compound-config-collector.js +5 -0
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.js +1 -0
- package/dist/util/config/sync-rules/impl/base64-sync-rules-collector.js.map +1 -1
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js +1 -0
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js.map +1 -1
- package/dist/util/config/sync-rules/sync-rules-provider.d.ts +2 -0
- package/dist/util/config/sync-rules/sync-rules-provider.js +3 -0
- package/dist/util/config/sync-rules/sync-rules-provider.js.map +1 -1
- package/dist/util/config/types.d.ts +1 -0
- package/dist/util/param-logging.d.ts +5 -2
- package/dist/util/param-logging.js +17 -9
- package/dist/util/param-logging.js.map +1 -1
- package/dist/util/protocol-types.d.ts +11 -11
- package/dist/util/protocol-types.js +6 -5
- package/dist/util/protocol-types.js.map +1 -1
- package/dist/util/utils.d.ts +2 -1
- package/dist/util/utils.js +16 -1
- package/dist/util/utils.js.map +1 -1
- package/package.json +6 -5
- package/src/api/diagnostics.ts +8 -2
- package/src/entry/commands/compact-action.ts +33 -25
- package/src/entry/commands/config-command.ts +1 -1
- package/src/metrics/metrics-interfaces.ts +6 -1
- package/src/metrics/open-telemetry/MetricAttributeFilteringExporter.ts +85 -0
- package/src/metrics/open-telemetry/OpenTelemetryMetricsFactory.ts +7 -2
- package/src/metrics/open-telemetry/util.ts +7 -3
- package/src/migrations/PowerSyncMigrationManager.ts +2 -1
- package/src/replication/AbstractReplicator.ts +42 -13
- package/src/replication/ReplicationModule.ts +0 -10
- package/src/routes/endpoints/admin.ts +17 -17
- package/src/routes/endpoints/socket-route.ts +9 -6
- package/src/routes/endpoints/sync-rules.ts +21 -12
- package/src/storage/BucketStorageBatch.ts +2 -1
- package/src/storage/BucketStorageFactory.ts +77 -14
- package/src/storage/PersistedReplicationStream.ts +2 -1
- package/src/storage/PersistedSyncConfigContent.ts +42 -19
- package/src/storage/ReplicationEventPayload.ts +6 -1
- package/src/storage/SourceEntity.ts +6 -2
- package/src/storage/SourceTable.ts +68 -11
- package/src/storage/SourceTableReconciler.ts +188 -0
- package/src/storage/StorageEngine.ts +10 -1
- package/src/storage/StorageProvider.ts +8 -0
- package/src/storage/StorageVersionConfig.ts +11 -1
- package/src/storage/SyncConfigParser.ts +121 -0
- package/src/storage/SyncRulesBucketStorage.ts +56 -8
- package/src/storage/WriteCheckpointAPI.ts +32 -3
- package/src/storage/implementation/BucketDefinitionMapping.ts +120 -17
- package/src/storage/implementation/IncrementalReprocessingCompatibility.ts +14 -5
- package/src/storage/implementation/IncrementalReprocessingSyncConfigLog.ts +22 -5
- package/src/storage/storage-index.ts +2 -0
- package/src/storage/storage-metrics.ts +154 -8
- package/src/sync/BucketChecksumState.ts +8 -5
- package/src/sync/sync.ts +40 -11
- package/src/sync/util.ts +25 -9
- package/src/system/ServiceContext.ts +47 -1
- package/src/util/config/compound-config-collector.ts +6 -0
- package/src/util/config/sync-rules/impl/base64-sync-rules-collector.ts +1 -0
- package/src/util/config/sync-rules/impl/filesystem-sync-rules-collector.ts +1 -0
- package/src/util/config/sync-rules/sync-rules-provider.ts +5 -0
- package/src/util/config/types.ts +1 -0
- package/src/util/param-logging.ts +21 -14
- package/src/util/protocol-types.ts +8 -7
- package/src/util/utils.ts +15 -1
- package/test/src/AbstractReplicator.test.ts +62 -0
- package/test/src/MetricAttributeFilteringExporter.test.ts +96 -0
- package/test/src/PersistedSyncConfigContent.test.ts +154 -0
- package/test/src/SyncConfigParser.test.ts +330 -0
- package/test/src/broadcast_iterable.test.ts +26 -8
- package/test/src/config.test.ts +40 -0
- package/test/src/diagnostics.test.ts +48 -0
- package/test/src/routes/admin.test.ts +30 -2
- package/test/src/routes/mocks.ts +2 -0
- package/test/src/routes/stream.test.ts +123 -2
- package/test/src/source-table-reconciler.test.ts +244 -0
- package/test/src/storage/SourceTable.test.ts +4 -1
- package/test/src/storage-metrics.test.ts +148 -0
- package/test/src/sync/BucketChecksumState.test.ts +195 -6
- package/test/src/sync/util.test.ts +34 -0
- package/test/src/util/param-logging.test.ts +59 -0
- package/test/src/util/utils.test.ts +23 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_HYDRATION_STATE,
|
|
3
|
+
DEFAULT_TAG,
|
|
4
|
+
nodeSqlite,
|
|
5
|
+
PrecompiledSyncConfig,
|
|
6
|
+
serializeSyncPlan,
|
|
7
|
+
SqlSyncRules
|
|
8
|
+
} from '@powersync/service-sync-rules';
|
|
9
|
+
import * as sqlite from 'node:sqlite';
|
|
10
|
+
import { describe, expect, test } from 'vitest';
|
|
11
|
+
import {
|
|
12
|
+
parsePersistedSyncConfigContent,
|
|
13
|
+
SerializedSyncPlan,
|
|
14
|
+
SqlSyncConfigParser,
|
|
15
|
+
updateSyncRulesFromConfig
|
|
16
|
+
} from '../../src/storage/storage-index.js';
|
|
17
|
+
|
|
18
|
+
const EVENT_QUERY = 'SELECT user_id, checkpoint FROM checkpoints WHERE active = true';
|
|
19
|
+
const yamlWithoutEvents = `
|
|
20
|
+
config:
|
|
21
|
+
edition: 3
|
|
22
|
+
|
|
23
|
+
streams:
|
|
24
|
+
checkpoints:
|
|
25
|
+
query: SELECT * FROM checkpoints
|
|
26
|
+
`;
|
|
27
|
+
const yamlWithEvents = `${yamlWithoutEvents}
|
|
28
|
+
event_definitions:
|
|
29
|
+
write_checkpoints:
|
|
30
|
+
payloads:
|
|
31
|
+
- ${EVENT_QUERY}
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
describe('persisted compiled replication events', () => {
|
|
35
|
+
test('dual-writes additive compiled events and restores the compiled evaluator', () => {
|
|
36
|
+
const parsed = SqlSyncRules.fromYaml(yamlWithEvents, { defaultSchema: 'test_schema' });
|
|
37
|
+
const update = updateSyncRulesFromConfig(parsed);
|
|
38
|
+
const compiled = update.config.plan!;
|
|
39
|
+
const originalEvent = compiled.plan.events![0];
|
|
40
|
+
|
|
41
|
+
expect(compiled.plan.version).toBeLessThanOrEqual(2);
|
|
42
|
+
expect(compiled.plan.events).toHaveLength(1);
|
|
43
|
+
expect(originalEvent.name).toBe('write_checkpoints');
|
|
44
|
+
expect(compiled.eventDescriptors).toEqual({ write_checkpoints: [EVENT_QUERY] });
|
|
45
|
+
|
|
46
|
+
const restored = restore(compiled);
|
|
47
|
+
expect(restored.config).toBeInstanceOf(PrecompiledSyncConfig);
|
|
48
|
+
expect(restored.config).not.toHaveProperty('eventDescriptors');
|
|
49
|
+
expect(restored.config.eventDefinitions).toHaveLength(1);
|
|
50
|
+
expect(restored.config.eventDefinitions[0].name).toBe('write_checkpoints');
|
|
51
|
+
|
|
52
|
+
const hydrated = restored.config.hydrate({
|
|
53
|
+
hydrationState: DEFAULT_HYDRATION_STATE,
|
|
54
|
+
sqlite: nodeSqlite(sqlite)
|
|
55
|
+
});
|
|
56
|
+
expect(
|
|
57
|
+
hydrated.eventDescriptors[0].evaluateRowWithErrors({
|
|
58
|
+
sourceTable: { connectionTag: DEFAULT_TAG, schema: 'test_schema', name: 'checkpoints' },
|
|
59
|
+
record: { user_id: 'user-1', checkpoint: 4n, active: 1 }
|
|
60
|
+
})
|
|
61
|
+
).toEqual({ results: [{ data: { user_id: 'user-1', checkpoint: 4n } }], errors: [] });
|
|
62
|
+
|
|
63
|
+
// This represents what an older compiler sees after ignoring the additive plan.events field. The raw descriptor
|
|
64
|
+
// mirror is normalized into the compiled representation by the new loading boundary, retaining the legacy behavior
|
|
65
|
+
// of ignoring payload filters until the sync config is redeployed.
|
|
66
|
+
const { events: _ignored, ...planWithoutCompiledEvents } = compiled.plan;
|
|
67
|
+
const legacyView = restore({ ...compiled, plan: planWithoutCompiledEvents });
|
|
68
|
+
expect(legacyView.config).not.toHaveProperty('eventDescriptors');
|
|
69
|
+
expect(legacyView.config.eventDefinitions).toHaveLength(1);
|
|
70
|
+
expect(legacyView.config.eventDefinitions[0].name).toBe('write_checkpoints');
|
|
71
|
+
expect(legacyView.errors).toHaveLength(1);
|
|
72
|
+
expect(legacyView.errors[0]).toMatchObject({ type: 'warning' });
|
|
73
|
+
|
|
74
|
+
const legacyEvent = serializeSyncPlan((legacyView.config as PrecompiledSyncConfig).plan).events![0];
|
|
75
|
+
expect(legacyEvent.sourceQueries[0].variants[0].filters).toEqual([]);
|
|
76
|
+
expect(originalEvent.sourceQueries[0].variants[0].filters).not.toEqual([]);
|
|
77
|
+
|
|
78
|
+
const legacyHydrated = legacyView.config.hydrate({
|
|
79
|
+
hydrationState: DEFAULT_HYDRATION_STATE,
|
|
80
|
+
sqlite: nodeSqlite(sqlite)
|
|
81
|
+
});
|
|
82
|
+
expect(
|
|
83
|
+
legacyHydrated.eventDescriptors[0].evaluateRowWithErrors({
|
|
84
|
+
sourceTable: { connectionTag: DEFAULT_TAG, schema: 'test_schema', name: 'checkpoints' },
|
|
85
|
+
record: { user_id: 'user-1', checkpoint: 4n, active: 0 }
|
|
86
|
+
})
|
|
87
|
+
).toEqual({ results: [{ data: { user_id: 'user-1', checkpoint: 4n } }], errors: [] });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('restores raw event descriptors attached to version 1 and 2 plans', () => {
|
|
91
|
+
const parsed = SqlSyncRules.fromYaml(yamlWithoutEvents, { defaultSchema: 'test_schema' });
|
|
92
|
+
const update = updateSyncRulesFromConfig(parsed);
|
|
93
|
+
const legacy: SerializedSyncPlan = {
|
|
94
|
+
...update.config.plan!,
|
|
95
|
+
eventDescriptors: { write_checkpoints: [EVENT_QUERY] }
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
expect(legacy.plan.version).toBeLessThanOrEqual(2);
|
|
99
|
+
const restored = restore(legacy);
|
|
100
|
+
expect(restored.config).not.toHaveProperty('eventDescriptors');
|
|
101
|
+
expect(restored.config.eventDefinitions).toHaveLength(1);
|
|
102
|
+
expect((restored.config as PrecompiledSyncConfig).plan.events).toMatchObject([
|
|
103
|
+
{ name: 'write_checkpoints', sourceQueries: [{ sql: EVENT_QUERY }] }
|
|
104
|
+
]);
|
|
105
|
+
expect(restored.errors).toHaveLength(1);
|
|
106
|
+
expect(restored.errors[0]).toMatchObject({ type: 'warning' });
|
|
107
|
+
expect(
|
|
108
|
+
serializeSyncPlan((restored.config as PrecompiledSyncConfig).plan).events![0].sourceQueries[0].variants[0].filters
|
|
109
|
+
).toEqual([]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Event SQL accepted by the legacy evaluator must remain loadable after an upgrade, even when its ignored filter uses
|
|
114
|
+
* expressions that the compiled event evaluator intentionally rejects for new deployments.
|
|
115
|
+
*/
|
|
116
|
+
test.each([
|
|
117
|
+
['request parameters', 'SELECT user_id FROM checkpoints WHERE user_id = request.user_id()'],
|
|
118
|
+
['unsupported expressions', 'SELECT user_id FROM checkpoints WHERE active IN (1, 2)']
|
|
119
|
+
])('loads legacy event descriptors without validating ignored %s', (_description, eventQuery) => {
|
|
120
|
+
const parsed = SqlSyncRules.fromYaml(yamlWithoutEvents, { defaultSchema: 'test_schema' });
|
|
121
|
+
const update = updateSyncRulesFromConfig(parsed);
|
|
122
|
+
const legacy: SerializedSyncPlan = {
|
|
123
|
+
...update.config.plan!,
|
|
124
|
+
eventDescriptors: {
|
|
125
|
+
write_checkpoints: [eventQuery]
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const restored = restore(legacy);
|
|
130
|
+
expect(restored.errors).toHaveLength(1);
|
|
131
|
+
expect(restored.errors[0]).toMatchObject({ type: 'warning' });
|
|
132
|
+
|
|
133
|
+
const event = restored.config.hydrate({
|
|
134
|
+
hydrationState: DEFAULT_HYDRATION_STATE,
|
|
135
|
+
sqlite: nodeSqlite(sqlite)
|
|
136
|
+
}).eventDescriptors[0];
|
|
137
|
+
expect(
|
|
138
|
+
event.evaluateRowWithErrors({
|
|
139
|
+
sourceTable: { connectionTag: DEFAULT_TAG, schema: 'test_schema', name: 'checkpoints' },
|
|
140
|
+
record: { user_id: 'user-1' }
|
|
141
|
+
})
|
|
142
|
+
).toEqual({ results: [{ data: { user_id: 'user-1' } }], errors: [] });
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
function restore(compiledPlan: SerializedSyncPlan) {
|
|
147
|
+
return parsePersistedSyncConfigContent({
|
|
148
|
+
content: yamlWithEvents,
|
|
149
|
+
compiledPlan,
|
|
150
|
+
storageVersion: 1,
|
|
151
|
+
parseOptions: { defaultSchema: 'test_schema' },
|
|
152
|
+
syncConfigParser: new SqlSyncConfigParser()
|
|
153
|
+
});
|
|
154
|
+
}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { SqlSyncConfigParser } from '@/storage/SyncConfigParser.js';
|
|
2
|
+
import { isCompatible, parsePersistedSyncConfigContent, updateSyncRulesFromConfig } from '@/storage/storage-index.js';
|
|
3
|
+
import { ServiceContextContainer, ServiceContextMode } from '@/system/ServiceContext.js';
|
|
4
|
+
import { logger } from '@powersync/lib-services-framework';
|
|
5
|
+
import * as syncRules from '@powersync/service-sync-rules';
|
|
6
|
+
import {
|
|
7
|
+
AdditionalSyncConfigParser,
|
|
8
|
+
DEFAULT_HYDRATION_STATE,
|
|
9
|
+
HydratedSyncConfig,
|
|
10
|
+
nodeSqlite,
|
|
11
|
+
normalizeConnectionConfig,
|
|
12
|
+
PrecompiledSyncConfig,
|
|
13
|
+
SyncConfig
|
|
14
|
+
} from '@powersync/service-sync-rules';
|
|
15
|
+
import * as sqlite from 'node:sqlite';
|
|
16
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
17
|
+
|
|
18
|
+
const STREAMS = /* yaml */ `
|
|
19
|
+
config: { edition: 3 }
|
|
20
|
+
streams:
|
|
21
|
+
orders:
|
|
22
|
+
query: SELECT * FROM orders
|
|
23
|
+
`;
|
|
24
|
+
const CONFIGURED = /* yaml */ `
|
|
25
|
+
config:
|
|
26
|
+
edition: 3
|
|
27
|
+
connections:
|
|
28
|
+
default:
|
|
29
|
+
type: example
|
|
30
|
+
tables:
|
|
31
|
+
orders: { sample: 10 }
|
|
32
|
+
streams:
|
|
33
|
+
orders:
|
|
34
|
+
query: SELECT * FROM orders
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
// This fixture represents an external module. Core only knows the connection/table maps; sample is module-owned.
|
|
38
|
+
function additionalParser(): AdditionalSyncConfigParser {
|
|
39
|
+
const check = (config: SyncConfig) => {
|
|
40
|
+
for (const connection of Object.values(config.connectionConfig)) {
|
|
41
|
+
if (connection?.type != 'example') continue;
|
|
42
|
+
for (const table of Object.values(connection.tables ?? {})) {
|
|
43
|
+
if (typeof (table as { sample?: number })?.sample != 'number') throw new Error('Invalid persisted sample.');
|
|
44
|
+
if ((table as { sample?: number })?.sample === 13) throw new Error('Sample 13 is unsupported.');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
id: 'example.tables',
|
|
50
|
+
extendJsonSchema({ schema }) {
|
|
51
|
+
const map = (schema.properties as any).config.properties.connections;
|
|
52
|
+
map.additionalProperties = {
|
|
53
|
+
if: { type: 'object', required: ['type'], properties: { type: { const: 'example' } } },
|
|
54
|
+
then: {
|
|
55
|
+
type: 'object',
|
|
56
|
+
additionalProperties: false,
|
|
57
|
+
required: ['type'],
|
|
58
|
+
properties: {
|
|
59
|
+
type: { const: 'example' },
|
|
60
|
+
tables: {
|
|
61
|
+
type: 'object',
|
|
62
|
+
propertyNames: { minLength: 1 },
|
|
63
|
+
additionalProperties: {
|
|
64
|
+
type: 'object',
|
|
65
|
+
additionalProperties: false,
|
|
66
|
+
properties: { sample: { type: 'number' } }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
else: map.additionalProperties
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
parse({ config, context }) {
|
|
75
|
+
const connections = normalizeConnectionConfig(
|
|
76
|
+
(config as { config?: { connections?: unknown } }).config?.connections
|
|
77
|
+
);
|
|
78
|
+
for (const [tag, connection] of Object.entries(connections)) {
|
|
79
|
+
if (connection?.type != 'example') continue;
|
|
80
|
+
context.parsedConfig.connectionConfig = { ...context.parsedConfig.connectionConfig, [tag]: connection };
|
|
81
|
+
const { plan } = context.parsedConfig as PrecompiledSyncConfig;
|
|
82
|
+
plan.moduleData = { ...plan.moduleData, ['example.tables']: null };
|
|
83
|
+
}
|
|
84
|
+
check(context.parsedConfig);
|
|
85
|
+
},
|
|
86
|
+
validatePersisted({ config }) {
|
|
87
|
+
check(config);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function deployOptions(yaml = CONFIGURED, parser = new SqlSyncConfigParser([additionalParser()])) {
|
|
93
|
+
return updateSyncRulesFromConfig(parser.parseContent(yaml, { defaultSchema: 'app' }));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
describe('service sync config parser', () => {
|
|
97
|
+
test('reuses compiled validation until a parser is registered', () => {
|
|
98
|
+
const compile = vi.spyOn(syncRules, 'compileSyncRulesSchemaValidator');
|
|
99
|
+
try {
|
|
100
|
+
const parser = new SqlSyncConfigParser();
|
|
101
|
+
expect(compile).toHaveBeenCalledTimes(1);
|
|
102
|
+
for (let i = 0; i < 2; i++) {
|
|
103
|
+
expect(parser.parseContent(STREAMS, { defaultSchema: 'app' }).errors).toEqual([]);
|
|
104
|
+
expect(() => parser.parseContent(CONFIGURED, { defaultSchema: 'app' })).toThrow();
|
|
105
|
+
}
|
|
106
|
+
expect(compile).toHaveBeenCalledTimes(1);
|
|
107
|
+
|
|
108
|
+
parser.registerParser(additionalParser());
|
|
109
|
+
expect(compile).toHaveBeenCalledTimes(2);
|
|
110
|
+
for (let i = 0; i < 2; i++) {
|
|
111
|
+
expect(parser.parseContent(CONFIGURED, { defaultSchema: 'app' }).errors).toEqual([]);
|
|
112
|
+
expect(() =>
|
|
113
|
+
parser.parseContent(CONFIGURED.replace('sample: 10', 'sample: wrong'), { defaultSchema: 'app' })
|
|
114
|
+
).toThrow();
|
|
115
|
+
}
|
|
116
|
+
expect(compile).toHaveBeenCalledTimes(2);
|
|
117
|
+
} finally {
|
|
118
|
+
compile.mockRestore();
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('composes generic registrations atomically and keeps returned schema copies isolated', () => {
|
|
123
|
+
const parser = new SqlSyncConfigParser();
|
|
124
|
+
const baseSchema = parser.jsonSchema;
|
|
125
|
+
expect(() => parser.parseContent(CONFIGURED, { defaultSchema: 'app' })).toThrow();
|
|
126
|
+
parser.registerParser(additionalParser());
|
|
127
|
+
expect(parser.parseContent(CONFIGURED, { defaultSchema: 'app' }).errors).toEqual([]);
|
|
128
|
+
expect(baseSchema).toEqual(new SqlSyncConfigParser().jsonSchema);
|
|
129
|
+
const composed = parser.jsonSchema;
|
|
130
|
+
delete (composed.properties as any).config.properties.connections;
|
|
131
|
+
expect(parser.parseContent(CONFIGURED, { defaultSchema: 'app' }).errors).toEqual([]);
|
|
132
|
+
|
|
133
|
+
expect(() => parser.registerParser(additionalParser())).toThrow('already registered');
|
|
134
|
+
expect(() => parser.registerParser({ id: '', parse() {} })).toThrow('must not be empty');
|
|
135
|
+
expect(() =>
|
|
136
|
+
parser.registerParser({
|
|
137
|
+
id: 'bad-schema',
|
|
138
|
+
parse() {},
|
|
139
|
+
extendJsonSchema({ schema }) {
|
|
140
|
+
schema.misspelledKeyword = true;
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
).toThrow();
|
|
144
|
+
// The failed schema is not retained and its ID can be used by a corrected registration.
|
|
145
|
+
parser.registerParser({ id: 'bad-schema', parse() {} });
|
|
146
|
+
expect(parser.parseContent(CONFIGURED, { defaultSchema: 'app' }).errors).toEqual([]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('supplies one parser to storage and closes registration before asynchronous startup completes', async () => {
|
|
150
|
+
const context = new ServiceContextContainer({
|
|
151
|
+
serviceMode: ServiceContextMode.TEST_CONNECTION,
|
|
152
|
+
configuration: {
|
|
153
|
+
storage: { type: 'example' },
|
|
154
|
+
api_parameters: {
|
|
155
|
+
max_data_fetch_concurrency: 1,
|
|
156
|
+
max_buckets_per_connection: 1,
|
|
157
|
+
max_parameter_query_results: 1
|
|
158
|
+
}
|
|
159
|
+
} as never
|
|
160
|
+
});
|
|
161
|
+
const parser = context.syncConfigParser;
|
|
162
|
+
parser.registerParser(additionalParser());
|
|
163
|
+
let finish!: () => void;
|
|
164
|
+
const ready = new Promise<void>((resolve) => {
|
|
165
|
+
finish = resolve;
|
|
166
|
+
});
|
|
167
|
+
const getStorage = vi.fn(async () => {
|
|
168
|
+
await ready;
|
|
169
|
+
return { storage: {} as never, reportStorage: {} as never, shutDown: async () => {}, tearDown: async () => true };
|
|
170
|
+
});
|
|
171
|
+
context.storageEngine.registerProvider({ type: 'example', getStorage });
|
|
172
|
+
const startup = context.storageEngine.start();
|
|
173
|
+
try {
|
|
174
|
+
expect(() => parser.registerParser({ id: 'too-late', parse() {} })).toThrow(
|
|
175
|
+
'after the storage engine has started'
|
|
176
|
+
);
|
|
177
|
+
finish();
|
|
178
|
+
await startup;
|
|
179
|
+
expect(getStorage).toHaveBeenCalledWith({ resolvedConfig: context.configuration, syncConfigParser: parser });
|
|
180
|
+
expect(context.syncConfigParser).toBe(parser);
|
|
181
|
+
} finally {
|
|
182
|
+
finish();
|
|
183
|
+
await startup;
|
|
184
|
+
await context.storageEngine.shutDown();
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('requires recorded modules and semantic validation when restoring a saved plan', () => {
|
|
189
|
+
const parser = new SqlSyncConfigParser([additionalParser()]);
|
|
190
|
+
const compiled = deployOptions();
|
|
191
|
+
const restore = (syncConfigParser = parser, compiledPlan = compiled.config.plan) =>
|
|
192
|
+
parsePersistedSyncConfigContent({
|
|
193
|
+
content: CONFIGURED,
|
|
194
|
+
compiledPlan,
|
|
195
|
+
storageVersion: 2,
|
|
196
|
+
parseOptions: { defaultSchema: 'app' },
|
|
197
|
+
syncConfigParser
|
|
198
|
+
});
|
|
199
|
+
const restored = restore();
|
|
200
|
+
expect(restored.config.connectionConfig).toEqual(compiled.config.parsed.config.connectionConfig);
|
|
201
|
+
expect(
|
|
202
|
+
restored.config.hydrate({ hydrationState: DEFAULT_HYDRATION_STATE, sqlite: nodeSqlite(sqlite) }).connectionConfig
|
|
203
|
+
).toEqual(restored.config.connectionConfig);
|
|
204
|
+
expect(() => restore(new SqlSyncConfigParser())).toThrow('Missing required sync config parsers: example.tables');
|
|
205
|
+
const malformed = structuredClone(compiled.config.plan!);
|
|
206
|
+
(malformed.plan.connectionConfig!.default!.tables!.orders as any).sample = 'wrong';
|
|
207
|
+
expect(() => restore(parser, malformed)).toThrow();
|
|
208
|
+
(malformed.plan.connectionConfig!.default!.tables!.orders as any).sample = 13;
|
|
209
|
+
expect(() => restore(parser, malformed)).toThrow('Sample 13');
|
|
210
|
+
// A compiled plan is authoritative; its failure must not be hidden by reparsing valid source YAML.
|
|
211
|
+
expect(() => restore(new SqlSyncConfigParser(), null)).toThrow();
|
|
212
|
+
expect(restore(parser, null).config.connectionConfig).toEqual(restored.config.connectionConfig);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('checks all dependencies before hooks and ignores unused registered parsers', () => {
|
|
216
|
+
const validatePersisted = vi.fn();
|
|
217
|
+
const parser = new SqlSyncConfigParser([{ id: 'installed', parse() {}, validatePersisted }]);
|
|
218
|
+
const { config } = parser.parseContent(STREAMS, { defaultSchema: 'app' });
|
|
219
|
+
expect(parser.validatePersisted({ config, context: { defaultSchema: 'app' } })).toEqual([]);
|
|
220
|
+
expect(validatePersisted).not.toHaveBeenCalled();
|
|
221
|
+
(config as PrecompiledSyncConfig).plan.moduleData = { installed: null, missing: null, 'also-missing': null };
|
|
222
|
+
expect(() => parser.validatePersisted({ config, context: { defaultSchema: 'app' } })).toThrow(
|
|
223
|
+
'Missing required sync config parsers: missing, also-missing'
|
|
224
|
+
);
|
|
225
|
+
expect(validatePersisted).not.toHaveBeenCalled();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('restores transformed module state without applying the authoring schema', () => {
|
|
229
|
+
const parser = new SqlSyncConfigParser([
|
|
230
|
+
{
|
|
231
|
+
id: 'transformed',
|
|
232
|
+
parse({ context }) {
|
|
233
|
+
const { plan } = context.parsedConfig as PrecompiledSyncConfig;
|
|
234
|
+
plan.moduleData = { ...plan.moduleData, ['transformed']: null };
|
|
235
|
+
context.parsedConfig.connectionConfig = {
|
|
236
|
+
default: { type: 'transformed', tables: { orders: { compiled: true } } }
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
]);
|
|
241
|
+
const compiled = deployOptions(STREAMS, parser);
|
|
242
|
+
const restore = (syncConfigParser: SqlSyncConfigParser) =>
|
|
243
|
+
parsePersistedSyncConfigContent({
|
|
244
|
+
content: STREAMS,
|
|
245
|
+
compiledPlan: compiled.config.plan,
|
|
246
|
+
storageVersion: 2,
|
|
247
|
+
parseOptions: { defaultSchema: 'app' },
|
|
248
|
+
syncConfigParser
|
|
249
|
+
});
|
|
250
|
+
expect((restore(parser).config as PrecompiledSyncConfig).plan.moduleData).toEqual({ transformed: null });
|
|
251
|
+
expect(restore(parser).config.connectionConfig).toEqual(compiled.config.parsed.config.connectionConfig);
|
|
252
|
+
expect(() => restore(new SqlSyncConfigParser())).toThrow('Missing required sync config parsers: transformed');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('persists module dependencies without connection options and accepts legacy plans without module data', () => {
|
|
256
|
+
const parser = new SqlSyncConfigParser([
|
|
257
|
+
{
|
|
258
|
+
id: 'required',
|
|
259
|
+
parse({ context }) {
|
|
260
|
+
const { plan } = context.parsedConfig as PrecompiledSyncConfig;
|
|
261
|
+
plan.moduleData = { ...plan.moduleData, ['required']: null };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
]);
|
|
265
|
+
const compiled = deployOptions(STREAMS, parser);
|
|
266
|
+
expect(compiled.config.plan!.plan.version).toBe(3);
|
|
267
|
+
expect(compiled.config.plan!.plan.moduleData).toEqual({ required: null });
|
|
268
|
+
const restore = (compiledPlan = compiled.config.plan) =>
|
|
269
|
+
parsePersistedSyncConfigContent({
|
|
270
|
+
content: STREAMS,
|
|
271
|
+
compiledPlan,
|
|
272
|
+
storageVersion: 2,
|
|
273
|
+
parseOptions: { defaultSchema: 'app' },
|
|
274
|
+
syncConfigParser: new SqlSyncConfigParser()
|
|
275
|
+
});
|
|
276
|
+
expect(() => restore()).toThrow('Missing required sync config parsers: required');
|
|
277
|
+
const malformed = structuredClone(compiled.config.plan!);
|
|
278
|
+
(malformed.plan as any).moduleData = 'required';
|
|
279
|
+
expect(() => restore(malformed)).toThrow('Invalid sync config module data');
|
|
280
|
+
const legacy = deployOptions(STREAMS, new SqlSyncConfigParser());
|
|
281
|
+
expect((restore(legacy.config.plan).config as PrecompiledSyncConfig).plan.moduleData).toBeUndefined();
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test('runs generic persisted validators with context and retains their warnings', () => {
|
|
285
|
+
const hook: AdditionalSyncConfigParser = {
|
|
286
|
+
id: 'core-check',
|
|
287
|
+
parse({ context }) {
|
|
288
|
+
const { plan } = context.parsedConfig as PrecompiledSyncConfig;
|
|
289
|
+
plan.moduleData = { ...plan.moduleData, ['core-check']: null };
|
|
290
|
+
},
|
|
291
|
+
validatePersisted({ config, context }) {
|
|
292
|
+
expect(config.getSourceTables()[0].name).toBe('orders');
|
|
293
|
+
expect(context.defaultSchema).toBe('app');
|
|
294
|
+
context.reportDiagnostic({ level: 'warning', message: 'Review this configuration.' });
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
const parser = new SqlSyncConfigParser([hook]);
|
|
298
|
+
const parsed = parser.parseContent(STREAMS, { defaultSchema: 'app' });
|
|
299
|
+
expect(parser.validatePersisted({ config: parsed.config, context: { defaultSchema: 'app' } })).toEqual([
|
|
300
|
+
expect.objectContaining({ type: 'warning', message: 'Review this configuration.' })
|
|
301
|
+
]);
|
|
302
|
+
hook.validatePersisted = ({ context }) => context.reportDiagnostic({ level: 'fatal', message: 'Rejected.' });
|
|
303
|
+
expect(() => parser.validatePersisted({ config: parsed.config, context: { defaultSchema: 'app' } })).toThrow(
|
|
304
|
+
'Rejected.'
|
|
305
|
+
);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test('reuses equal connection options but requires replacement for additions, changes and removals', () => {
|
|
309
|
+
const first = deployOptions();
|
|
310
|
+
const same = deployOptions(CONFIGURED.replace('SELECT * FROM orders', 'SELECT id FROM orders'));
|
|
311
|
+
const changed = deployOptions(CONFIGURED.replace('sample: 10', 'sample: 20'));
|
|
312
|
+
const absent = deployOptions(STREAMS);
|
|
313
|
+
expect(isCompatible([first.config.plan], same.config, logger)).toBe(true);
|
|
314
|
+
expect(isCompatible([first.config.plan], changed.config, logger)).toBe(false);
|
|
315
|
+
expect(isCompatible([first.config.plan], absent.config, logger)).toBe(false);
|
|
316
|
+
expect(isCompatible([absent.config.plan], first.config, logger)).toBe(false);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test('merges equal connection config once', () => {
|
|
320
|
+
const first = deployOptions().config.parsed.config;
|
|
321
|
+
const same = deployOptions(CONFIGURED.replace('SELECT * FROM orders', 'SELECT id FROM orders')).config.parsed
|
|
322
|
+
.config;
|
|
323
|
+
const hydrate = (definitions: SyncConfig[]) =>
|
|
324
|
+
new HydratedSyncConfig({
|
|
325
|
+
definitions,
|
|
326
|
+
createParams: { hydrationState: DEFAULT_HYDRATION_STATE, sqlite: nodeSqlite(sqlite) }
|
|
327
|
+
});
|
|
328
|
+
expect(hydrate([first, same]).connectionConfig).toEqual(first.connectionConfig);
|
|
329
|
+
});
|
|
330
|
+
});
|
|
@@ -4,10 +4,16 @@ import { delayEach } from 'ix/asynciterable/operators/delayeach.js';
|
|
|
4
4
|
import { take } from 'ix/asynciterable/operators/take.js';
|
|
5
5
|
import { wrapWithAbort } from 'ix/asynciterable/operators/withabort.js';
|
|
6
6
|
import { toArray } from 'ix/asynciterable/toarray.js';
|
|
7
|
-
import
|
|
8
|
-
|
|
7
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
8
|
+
|
|
9
|
+
// The global setTimeout, not the one from timers/promises: vi.useFakeTimers() only replaces the global timers
|
|
10
|
+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
9
11
|
|
|
10
12
|
describe('BroadcastIterable', () => {
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
vi.useRealTimers();
|
|
15
|
+
});
|
|
16
|
+
|
|
11
17
|
it('should iterate', async () => {
|
|
12
18
|
const range = AsyncIterableX.from([1, 2, 3]);
|
|
13
19
|
const broadcast = new BroadcastIterable(() => range);
|
|
@@ -47,6 +53,7 @@ describe('BroadcastIterable', () => {
|
|
|
47
53
|
});
|
|
48
54
|
|
|
49
55
|
it('should handle indefinite sources', async () => {
|
|
56
|
+
vi.useFakeTimers();
|
|
50
57
|
const source: IterableSource<number> = (signal) => {
|
|
51
58
|
return wrapWithAbort(interval(1), signal);
|
|
52
59
|
};
|
|
@@ -55,7 +62,9 @@ describe('BroadcastIterable', () => {
|
|
|
55
62
|
|
|
56
63
|
const delayed = delayEach(10)(broadcast);
|
|
57
64
|
expect(broadcast.active).toBe(false);
|
|
58
|
-
const
|
|
65
|
+
const resultsPromise = toArray(take(5)(delayed));
|
|
66
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
67
|
+
const results = await resultsPromise;
|
|
59
68
|
|
|
60
69
|
expect(results.length).toEqual(5);
|
|
61
70
|
expect(results[0]).toEqual(0);
|
|
@@ -66,6 +75,7 @@ describe('BroadcastIterable', () => {
|
|
|
66
75
|
});
|
|
67
76
|
|
|
68
77
|
it('should handle multiple subscribers', async () => {
|
|
78
|
+
vi.useFakeTimers();
|
|
69
79
|
let sourceIndex = 0;
|
|
70
80
|
const source = async function* (signal: AbortSignal) {
|
|
71
81
|
// Test value out by 1000 means it may have used the wrong iteration of the source
|
|
@@ -75,7 +85,7 @@ describe('BroadcastIterable', () => {
|
|
|
75
85
|
});
|
|
76
86
|
for (let i = 0; !signal.aborted; i++) {
|
|
77
87
|
yield base + i;
|
|
78
|
-
await Promise.race([abortedPromise,
|
|
88
|
+
await Promise.race([abortedPromise, sleep(1)]);
|
|
79
89
|
}
|
|
80
90
|
// Test value out by 100 means this wasn't reached
|
|
81
91
|
sourceIndex += 100;
|
|
@@ -88,6 +98,7 @@ describe('BroadcastIterable', () => {
|
|
|
88
98
|
expect(broadcast.active).toBe(false);
|
|
89
99
|
const results1Promise = toArray(take(5)(delayed1));
|
|
90
100
|
const results2Promise = toArray(take(5)(delayed2));
|
|
101
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
91
102
|
const [results1, results2] = [await results1Promise, await results2Promise];
|
|
92
103
|
|
|
93
104
|
expect(broadcast.active).toBe(false);
|
|
@@ -104,7 +115,9 @@ describe('BroadcastIterable', () => {
|
|
|
104
115
|
|
|
105
116
|
// This starts a new source
|
|
106
117
|
const delayed3 = delayEach(10)(broadcast);
|
|
107
|
-
const
|
|
118
|
+
const results3Promise = toArray(take(5)(delayed3));
|
|
119
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
120
|
+
const results3 = await results3Promise;
|
|
108
121
|
expect(results3.length).toEqual(5);
|
|
109
122
|
expect(results3[0]).toEqual(2100);
|
|
110
123
|
expect(results3[4]).toBeGreaterThan(2110);
|
|
@@ -112,6 +125,7 @@ describe('BroadcastIterable', () => {
|
|
|
112
125
|
});
|
|
113
126
|
|
|
114
127
|
it('should handle errors on multiple subscribers', async () => {
|
|
128
|
+
vi.useFakeTimers();
|
|
115
129
|
let sourceIndex = 0;
|
|
116
130
|
const source = async function* (signal: AbortSignal) {
|
|
117
131
|
// Test value out by 1000 means it may have used the wrong iteration of the source
|
|
@@ -124,7 +138,7 @@ describe('BroadcastIterable', () => {
|
|
|
124
138
|
throw new Error('simulated failure');
|
|
125
139
|
}
|
|
126
140
|
yield base + i;
|
|
127
|
-
await Promise.race([abortedPromise,
|
|
141
|
+
await Promise.race([abortedPromise, sleep(1)]);
|
|
128
142
|
}
|
|
129
143
|
// Test value out by 100 means this wasn't reached
|
|
130
144
|
sourceIndex += 100;
|
|
@@ -138,7 +152,9 @@ describe('BroadcastIterable', () => {
|
|
|
138
152
|
const results1Promise = toArray(take(5)(delayed1)) as Promise<number[]>;
|
|
139
153
|
const results2Promise = toArray(take(5)(delayed2)) as Promise<number[]>;
|
|
140
154
|
|
|
141
|
-
const
|
|
155
|
+
const settled = Promise.allSettled([results1Promise, results2Promise]);
|
|
156
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
157
|
+
const [r1, r2] = await settled;
|
|
142
158
|
|
|
143
159
|
expect(r1).toEqual({ status: 'rejected', reason: new Error('simulated failure') });
|
|
144
160
|
expect(r2).toEqual({ status: 'rejected', reason: new Error('simulated failure') });
|
|
@@ -147,7 +163,9 @@ describe('BroadcastIterable', () => {
|
|
|
147
163
|
|
|
148
164
|
// This starts a new source
|
|
149
165
|
const delayed3 = delayEach(10)(broadcast);
|
|
150
|
-
const
|
|
166
|
+
const results3Promise = toArray(take(5)(delayed3));
|
|
167
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
168
|
+
const results3 = await results3Promise;
|
|
151
169
|
expect(results3.length).toEqual(5);
|
|
152
170
|
expect(results3[0]).toEqual(2000);
|
|
153
171
|
expect(results3[4]).toBeGreaterThan(2010);
|
package/test/src/config.test.ts
CHANGED
|
@@ -70,6 +70,44 @@ describe('Config', () => {
|
|
|
70
70
|
expect(config.api_parameters.max_buckets_per_connection).toBe(1);
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
+
it('should resolve the storage default version', {}, async () => {
|
|
74
|
+
const yamlConfig = /* yaml */ `
|
|
75
|
+
# PowerSync config
|
|
76
|
+
replication:
|
|
77
|
+
connections: []
|
|
78
|
+
storage:
|
|
79
|
+
type: mongodb
|
|
80
|
+
default_storage_version: 4
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
const collector = new CompoundConfigCollector();
|
|
84
|
+
|
|
85
|
+
const config = await collector.collectConfig({
|
|
86
|
+
config_base64: Buffer.from(yamlConfig, 'utf-8').toString('base64')
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(config.storage.default_storage_version).toBe(4);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it.each([1, 1.5, 5])('should reject unsupported storage default version %s', async (defaultStorageVersion) => {
|
|
93
|
+
const yamlConfig = /* yaml */ `
|
|
94
|
+
# PowerSync config
|
|
95
|
+
replication:
|
|
96
|
+
connections: []
|
|
97
|
+
storage:
|
|
98
|
+
type: mongodb
|
|
99
|
+
default_storage_version: ${defaultStorageVersion}
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
const collector = new CompoundConfigCollector();
|
|
103
|
+
|
|
104
|
+
await expect(
|
|
105
|
+
collector.collectConfig({
|
|
106
|
+
config_base64: Buffer.from(yamlConfig, 'utf-8').toString('base64')
|
|
107
|
+
})
|
|
108
|
+
).rejects.toThrow(`Storage version ${defaultStorageVersion} is not supported`);
|
|
109
|
+
});
|
|
110
|
+
|
|
73
111
|
it('should resolve checkpoint request retention config', {}, async () => {
|
|
74
112
|
const yamlConfig = /* yaml */ `
|
|
75
113
|
# PowerSync config
|
|
@@ -198,6 +236,7 @@ describe('Config', () => {
|
|
|
198
236
|
storage:
|
|
199
237
|
type: mongodb
|
|
200
238
|
sync_config:
|
|
239
|
+
version_label: v6
|
|
201
240
|
content: |
|
|
202
241
|
config:
|
|
203
242
|
edition: 2
|
|
@@ -214,6 +253,7 @@ describe('Config', () => {
|
|
|
214
253
|
|
|
215
254
|
expect(result.sync_rules).toEqual({
|
|
216
255
|
present: true,
|
|
256
|
+
version_label: 'v6',
|
|
217
257
|
exit_on_error: true,
|
|
218
258
|
content: expect.stringContaining('edition: 2')
|
|
219
259
|
});
|