@powersync/service-core 1.22.0 → 1.23.1
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 -0
- package/dist/api/RouteAPI.d.ts +2 -2
- package/dist/api/diagnostics.d.ts +12 -1
- package/dist/api/diagnostics.js +34 -22
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/entry/commands/compact-action.js +1 -1
- package/dist/entry/commands/compact-action.js.map +1 -1
- package/dist/modules/AbstractModule.d.ts +6 -2
- package/dist/modules/AbstractModule.js.map +1 -1
- package/dist/replication/AbstractReplicator.d.ts +14 -3
- package/dist/replication/AbstractReplicator.js +122 -62
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/replication/ReplicationModule.d.ts +3 -3
- package/dist/replication/ReplicationModule.js.map +1 -1
- package/dist/routes/configure-fastify.d.ts +12 -12
- package/dist/routes/endpoints/admin.d.ts +24 -24
- package/dist/routes/endpoints/admin.js +46 -35
- package/dist/routes/endpoints/admin.js.map +1 -1
- package/dist/routes/endpoints/checkpointing.js +1 -1
- package/dist/routes/endpoints/checkpointing.js.map +1 -1
- package/dist/routes/endpoints/socket-route.js +1 -1
- package/dist/routes/endpoints/socket-route.js.map +1 -1
- package/dist/routes/endpoints/sync-rules.js +22 -13
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/routes/endpoints/sync-stream.js +1 -1
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/runner/teardown.js +8 -8
- package/dist/runner/teardown.js.map +1 -1
- package/dist/storage/BucketStorageBatch.d.ts +0 -6
- package/dist/storage/BucketStorageBatch.js.map +1 -1
- package/dist/storage/BucketStorageFactory.d.ts +22 -27
- package/dist/storage/BucketStorageFactory.js +4 -18
- package/dist/storage/BucketStorageFactory.js.map +1 -1
- package/dist/storage/ParsedSyncConfigSet.d.ts +23 -0
- package/dist/storage/ParsedSyncConfigSet.js +2 -0
- package/dist/storage/ParsedSyncConfigSet.js.map +1 -0
- package/dist/storage/PersistedReplicationStream.d.ts +32 -0
- package/dist/storage/PersistedReplicationStream.js +26 -0
- package/dist/storage/PersistedReplicationStream.js.map +1 -0
- package/dist/storage/PersistedSyncConfigContent.d.ts +63 -0
- package/dist/storage/PersistedSyncConfigContent.js +125 -0
- package/dist/storage/PersistedSyncConfigContent.js.map +1 -0
- package/dist/storage/PersistedSyncConfigStatus.d.ts +13 -0
- package/dist/storage/PersistedSyncConfigStatus.js +2 -0
- package/dist/storage/PersistedSyncConfigStatus.js.map +1 -0
- package/dist/storage/SourceTable.d.ts +9 -3
- package/dist/storage/SourceTable.js +13 -3
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/SyncRulesBucketStorage.d.ts +59 -16
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
- package/dist/storage/implementation/BucketDefinitionMapping.d.ts +117 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js +277 -0
- package/dist/storage/implementation/BucketDefinitionMapping.js.map +1 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.d.ts +6 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js +31 -0
- package/dist/storage/implementation/IncrementalReprocessingCompatibility.js.map +1 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.d.ts +17 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js +62 -0
- package/dist/storage/implementation/IncrementalReprocessingSyncConfigLog.js.map +1 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.d.ts +15 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.js +20 -0
- package/dist/storage/implementation/ReplicationStreamStorageIds.js.map +1 -0
- package/dist/storage/storage-index.d.ts +8 -1
- package/dist/storage/storage-index.js +8 -1
- package/dist/storage/storage-index.js.map +1 -1
- package/dist/sync/sync.js +5 -0
- package/dist/sync/sync.js.map +1 -1
- package/dist/util/checkpointing.js +1 -1
- package/dist/util/checkpointing.js.map +1 -1
- package/dist/util/config/types.d.ts +1 -1
- package/dist/util/lsn.d.ts +4 -0
- package/dist/util/lsn.js +10 -0
- package/dist/util/lsn.js.map +1 -1
- package/package.json +6 -7
- package/src/api/RouteAPI.ts +2 -2
- package/src/api/diagnostics.ts +43 -26
- package/src/entry/commands/compact-action.ts +1 -1
- package/src/modules/AbstractModule.ts +6 -2
- package/src/replication/AbstractReplicator.ts +145 -65
- package/src/replication/ReplicationModule.ts +2 -3
- package/src/routes/endpoints/admin.ts +72 -50
- package/src/routes/endpoints/checkpointing.ts +1 -1
- package/src/routes/endpoints/socket-route.ts +1 -1
- package/src/routes/endpoints/sync-rules.ts +23 -13
- package/src/routes/endpoints/sync-stream.ts +1 -1
- package/src/runner/teardown.ts +8 -8
- package/src/storage/BucketStorageBatch.ts +0 -7
- package/src/storage/BucketStorageFactory.ts +30 -39
- package/src/storage/ParsedSyncConfigSet.ts +25 -0
- package/src/storage/PersistedReplicationStream.ts +55 -0
- package/src/storage/PersistedSyncConfigContent.ts +192 -0
- package/src/storage/PersistedSyncConfigStatus.ts +14 -0
- package/src/storage/SourceTable.ts +20 -3
- package/src/storage/SyncRulesBucketStorage.ts +64 -16
- package/src/storage/implementation/BucketDefinitionMapping.ts +436 -0
- package/src/storage/implementation/IncrementalReprocessingCompatibility.ts +41 -0
- package/src/storage/implementation/IncrementalReprocessingSyncConfigLog.ts +109 -0
- package/src/storage/implementation/ReplicationStreamStorageIds.ts +21 -0
- package/src/storage/storage-index.ts +9 -1
- package/src/sync/sync.ts +5 -0
- package/src/util/checkpointing.ts +1 -1
- package/src/util/config/types.ts +1 -1
- package/src/util/lsn.ts +9 -0
- package/test/src/diagnostics.test.ts +62 -34
- package/test/src/module-loader.test.ts +33 -1
- package/test/src/routes/admin.test.ts +182 -18
- package/test/src/routes/mocks.ts +6 -2
- package/tsconfig.json +1 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/storage/PersistedSyncRulesContent.d.ts +0 -59
- package/dist/storage/PersistedSyncRulesContent.js +0 -100
- package/dist/storage/PersistedSyncRulesContent.js.map +0 -1
- package/src/storage/PersistedSyncRulesContent.ts +0 -174
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { logger as defaultLogger, ErrorCode, ServiceError } from '@powersync/lib-services-framework';
|
|
2
|
+
import { CompatibilityContext, CompatibilityOption, DEFAULT_HYDRATION_STATE, deserializeSyncPlan, nodeSqlite, PrecompiledSyncConfig, SqlEventDescriptor, SqlSyncRules, versionedHydrationState, YamlError } from '@powersync/service-sync-rules';
|
|
3
|
+
import * as sqlite from 'node:sqlite';
|
|
4
|
+
import { STORAGE_VERSION_CONFIG } from './StorageVersionConfig.js';
|
|
5
|
+
export function parsePersistedSyncConfigContent(options) {
|
|
6
|
+
const { content, compiledPlan, storageVersion, parseOptions } = options;
|
|
7
|
+
if (compiledPlan == null) {
|
|
8
|
+
// Fallback: Only parse from YAML if no compiled plan is available.
|
|
9
|
+
return SqlSyncRules.fromYaml(content, parseOptions);
|
|
10
|
+
}
|
|
11
|
+
const plan = deserializeSyncPlan(compiledPlan.plan);
|
|
12
|
+
const compatibility = CompatibilityContext.deserialize(compiledPlan.compatibility);
|
|
13
|
+
const eventDefinitions = [];
|
|
14
|
+
for (const [name, queries] of Object.entries(compiledPlan.eventDescriptors)) {
|
|
15
|
+
const descriptor = new SqlEventDescriptor(name, compatibility);
|
|
16
|
+
for (const query of queries) {
|
|
17
|
+
descriptor.addSourceQuery(query, parseOptions);
|
|
18
|
+
}
|
|
19
|
+
eventDefinitions.push(descriptor);
|
|
20
|
+
}
|
|
21
|
+
const precompiled = new PrecompiledSyncConfig(plan, compatibility, eventDefinitions, {
|
|
22
|
+
defaultSchema: parseOptions.defaultSchema,
|
|
23
|
+
sourceText: content
|
|
24
|
+
});
|
|
25
|
+
// Note: If the original content did not define a storage version, this will still set the storage version.
|
|
26
|
+
// This means asUpdateOptions will not change the storage version, even if the default changes.
|
|
27
|
+
precompiled.storageVersion = storageVersion;
|
|
28
|
+
const errors = [];
|
|
29
|
+
if (compiledPlan.errors) {
|
|
30
|
+
for (const error of compiledPlan.errors) {
|
|
31
|
+
const location = error.location && {
|
|
32
|
+
start: error.location.start_offset,
|
|
33
|
+
end: error.location.end_offset
|
|
34
|
+
};
|
|
35
|
+
const asYamlError = new YamlError(new Error(error.message), location);
|
|
36
|
+
asYamlError.type = error.level;
|
|
37
|
+
errors.push(asYamlError);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { config: precompiled, errors };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Immutable sync config content for one sync config inside a replication stream.
|
|
44
|
+
*
|
|
45
|
+
* This represents the persisted config content. Fetch per-config status with
|
|
46
|
+
* {@link getSyncConfigStatus}. Use {@link PersistedReplicationStream} for stream
|
|
47
|
+
* lifecycle concerns such as locking and termination.
|
|
48
|
+
*/
|
|
49
|
+
export class PersistedSyncConfigContent {
|
|
50
|
+
replicationStreamId;
|
|
51
|
+
sync_rules_content;
|
|
52
|
+
compiled_plan;
|
|
53
|
+
replicationStreamName;
|
|
54
|
+
storageVersion;
|
|
55
|
+
logger;
|
|
56
|
+
syncConfigId;
|
|
57
|
+
syncConfigState;
|
|
58
|
+
constructor(data) {
|
|
59
|
+
this.replicationStreamId = data.replicationStreamId;
|
|
60
|
+
this.sync_rules_content = data.sync_rules_content;
|
|
61
|
+
this.compiled_plan = data.compiled_plan;
|
|
62
|
+
this.replicationStreamName = data.replicationStreamName;
|
|
63
|
+
this.storageVersion = data.storageVersion;
|
|
64
|
+
this.syncConfigId = data.syncConfigId ?? null;
|
|
65
|
+
this.syncConfigState = data.syncConfigState;
|
|
66
|
+
this.logger = defaultLogger.child({ prefix: `[${this.replicationStreamName}] ` });
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Load the storage config.
|
|
70
|
+
*
|
|
71
|
+
* This may throw if the persisted storage version is not supported.
|
|
72
|
+
*/
|
|
73
|
+
getStorageConfig() {
|
|
74
|
+
const storageConfig = STORAGE_VERSION_CONFIG[this.storageVersion];
|
|
75
|
+
if (storageConfig == null) {
|
|
76
|
+
throw new ServiceError(ErrorCode.PSYNC_S1005, `Unsupported storage version ${this.storageVersion} for replication stream ${this.replicationStreamId}`);
|
|
77
|
+
}
|
|
78
|
+
return storageConfig;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Parse only this config's content into a single {@link SyncConfigWithErrors}.
|
|
82
|
+
*
|
|
83
|
+
* This does not depend on any other configs in the same replication stream.
|
|
84
|
+
*/
|
|
85
|
+
parseSingleConfig(options) {
|
|
86
|
+
return parsePersistedSyncConfigContent({
|
|
87
|
+
content: this.sync_rules_content,
|
|
88
|
+
compiledPlan: this.compiled_plan,
|
|
89
|
+
storageVersion: this.storageVersion,
|
|
90
|
+
parseOptions: options
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
parsed(options) {
|
|
94
|
+
let hydrationState;
|
|
95
|
+
const config = this.parseSingleConfig(options);
|
|
96
|
+
const storageConfig = this.getStorageConfig();
|
|
97
|
+
if (storageConfig.versionedBuckets ||
|
|
98
|
+
config.config.compatibility.isEnabled(CompatibilityOption.versionedBucketIds)) {
|
|
99
|
+
hydrationState = versionedHydrationState(this.replicationStreamId);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
hydrationState = DEFAULT_HYDRATION_STATE;
|
|
103
|
+
}
|
|
104
|
+
let hydrated;
|
|
105
|
+
return {
|
|
106
|
+
replicationStreamId: this.replicationStreamId,
|
|
107
|
+
replicationStreamName: this.replicationStreamName,
|
|
108
|
+
syncConfigs: [config],
|
|
109
|
+
hydrationState,
|
|
110
|
+
get hydratedSyncConfig() {
|
|
111
|
+
hydrated ??= config.config.hydrate({ hydrationState, sqlite: nodeSqlite(sqlite) });
|
|
112
|
+
return hydrated;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
asUpdateOptions(options) {
|
|
117
|
+
// defaultSchema is not relevant for the parsed version here
|
|
118
|
+
const parsed = this.parseSingleConfig({ defaultSchema: 'not_applicable' });
|
|
119
|
+
return {
|
|
120
|
+
config: { yaml: this.sync_rules_content, plan: this.compiled_plan, parsed },
|
|
121
|
+
...options
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=PersistedSyncConfigContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PersistedSyncConfigContent.js","sourceRoot":"","sources":["../../src/storage/PersistedSyncConfigContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACrG,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EAInB,UAAU,EACV,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EAEZ,uBAAuB,EACvB,SAAS,EACV,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAMtC,OAAO,EAAE,sBAAsB,EAAwB,MAAM,2BAA2B,CAAC;AASzF,MAAM,UAAU,+BAA+B,CAAC,OAA+C;IAC7F,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAExE,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;QACzB,mEAAmE;QACnE,OAAO,YAAY,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,IAAI,GAAG,mBAAmB,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACpD,MAAM,aAAa,GAAG,oBAAoB,CAAC,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;IACnF,MAAM,gBAAgB,GAAyB,EAAE,CAAC;IAClD,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB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ersistedSyncConfigStatus {
|
|
4
|
+
readonly id: PersistedSyncConfigId;
|
|
5
|
+
readonly replicationStreamId: number;
|
|
6
|
+
readonly state: SyncRuleState;
|
|
7
|
+
readonly snapshot_done?: boolean;
|
|
8
|
+
readonly last_checkpoint_lsn: string | null;
|
|
9
|
+
readonly last_fatal_error?: string | null;
|
|
10
|
+
readonly last_fatal_error_ts?: Date | null;
|
|
11
|
+
readonly last_keepalive_ts?: Date | null;
|
|
12
|
+
readonly last_checkpoint_ts?: Date | null;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PersistedSyncConfigStatus.js","sourceRoot":"","sources":["../../src/storage/PersistedSyncConfigStatus.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BucketDataSource, ParameterIndexLookupCreator, SourceTableRef } from '@powersync/service-sync-rules';
|
|
1
|
+
import { BucketDataSource, BucketDefinitionId, ParameterIndexId, ParameterIndexLookupCreator, SourceTableRef } from '@powersync/service-sync-rules';
|
|
2
2
|
import { bson } from '../index.js';
|
|
3
3
|
import { ColumnDescriptor } from './SourceEntity.js';
|
|
4
4
|
/**
|
|
@@ -13,6 +13,8 @@ export interface SourceTableOptions {
|
|
|
13
13
|
snapshotComplete: boolean;
|
|
14
14
|
bucketDataSources: BucketDataSource[];
|
|
15
15
|
parameterLookupSources: ParameterIndexLookupCreator[];
|
|
16
|
+
bucketDataSourceIds?: Set<BucketDefinitionId>;
|
|
17
|
+
parameterLookupSourceIds?: Set<ParameterIndexId>;
|
|
16
18
|
}
|
|
17
19
|
export interface TableSnapshotStatus {
|
|
18
20
|
totalEstimatedCount: number;
|
|
@@ -45,9 +47,11 @@ export declare class SourceTable {
|
|
|
45
47
|
*/
|
|
46
48
|
syncParameters: boolean;
|
|
47
49
|
/**
|
|
48
|
-
* True if
|
|
50
|
+
* True if this table should fire events for row changes.
|
|
49
51
|
*
|
|
50
|
-
* This value is resolved externally, and cached here.
|
|
52
|
+
* This value is resolved externally, and cached here. When multiple SourceTables exist
|
|
53
|
+
* for the same SourceTableRef (v3 storage), resolveTables designates exactly one of them
|
|
54
|
+
* as the event carrier, so that a row change saved once per table fires each event once.
|
|
51
55
|
*
|
|
52
56
|
* Defaults to true for tests.
|
|
53
57
|
*/
|
|
@@ -80,6 +84,8 @@ export declare class SourceTable {
|
|
|
80
84
|
get replicaIdColumns(): ColumnDescriptor[];
|
|
81
85
|
get bucketDataSources(): BucketDataSource[];
|
|
82
86
|
get parameterLookupSources(): ParameterIndexLookupCreator[];
|
|
87
|
+
get bucketDataSourceIds(): Set<string> | undefined;
|
|
88
|
+
get parameterLookupSourceIds(): Set<string> | undefined;
|
|
83
89
|
/**
|
|
84
90
|
* Sanitized name of the entity in the format of "{schema}.{entity name}".
|
|
85
91
|
* Suitable for safe use in Postgres queries.
|
|
@@ -26,9 +26,11 @@ export class SourceTable {
|
|
|
26
26
|
*/
|
|
27
27
|
syncParameters = true;
|
|
28
28
|
/**
|
|
29
|
-
* True if
|
|
29
|
+
* True if this table should fire events for row changes.
|
|
30
30
|
*
|
|
31
|
-
* This value is resolved externally, and cached here.
|
|
31
|
+
* This value is resolved externally, and cached here. When multiple SourceTables exist
|
|
32
|
+
* for the same SourceTableRef (v3 storage), resolveTables designates exactly one of them
|
|
33
|
+
* as the event carrier, so that a row change saved once per table fires each event once.
|
|
32
34
|
*
|
|
33
35
|
* Defaults to true for tests.
|
|
34
36
|
*/
|
|
@@ -80,6 +82,12 @@ export class SourceTable {
|
|
|
80
82
|
get parameterLookupSources() {
|
|
81
83
|
return this.options.parameterLookupSources;
|
|
82
84
|
}
|
|
85
|
+
get bucketDataSourceIds() {
|
|
86
|
+
return this.options.bucketDataSourceIds;
|
|
87
|
+
}
|
|
88
|
+
get parameterLookupSourceIds() {
|
|
89
|
+
return this.options.parameterLookupSourceIds;
|
|
90
|
+
}
|
|
83
91
|
/**
|
|
84
92
|
* Sanitized name of the entity in the format of "{schema}.{entity name}".
|
|
85
93
|
* Suitable for safe use in Postgres queries.
|
|
@@ -101,7 +109,9 @@ export class SourceTable {
|
|
|
101
109
|
replicaIdColumns: this.replicaIdColumns,
|
|
102
110
|
snapshotComplete: this.snapshotComplete,
|
|
103
111
|
bucketDataSources: this.bucketDataSources,
|
|
104
|
-
parameterLookupSources: this.parameterLookupSources
|
|
112
|
+
parameterLookupSources: this.parameterLookupSources,
|
|
113
|
+
bucketDataSourceIds: this.bucketDataSourceIds == null ? undefined : new Set(this.bucketDataSourceIds),
|
|
114
|
+
parameterLookupSourceIds: this.parameterLookupSourceIds == null ? undefined : new Set(this.parameterLookupSourceIds)
|
|
105
115
|
});
|
|
106
116
|
copy.syncData = this.syncData;
|
|
107
117
|
copy.syncParameters = this.syncParameters;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SourceTable.js","sourceRoot":"","sources":["../../src/storage/SourceTable.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"SourceTable.js","sourceRoot":"","sources":["../../src/storage/SourceTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,WAAW,EAIZ,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AA0B9C;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IAsDM;IArD5B,MAAM,CAAU,WAAW,GAAG,WAAW,CAAC;IAE1C;;;;;;OAMG;IACI,QAAQ,GAAG,IAAI,CAAC;IAEvB;;;;;;OAMG;IACI,cAAc,GAAG,IAAI,CAAC;IAE7B;;;;;;;;OAQG;IACI,SAAS,GAAG,IAAI,CAAC;IAExB;;;;;;;;;;OAUG;IACI,gBAAgB,GAAG,IAAI,CAAC;IAE/B;;;;OAIG;IACI,cAAc,GAAoC,SAAS,CAAC;IAE5D,gBAAgB,CAAU;IAEjC,YAA4B,OAA2B;QAA3B,YAAO,GAAP,OAAO,CAAoB;QACrD,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAA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@ -5,7 +5,8 @@ import { PerformanceTracer } from '../tracing/PerformanceTracer.js';
|
|
|
5
5
|
import * as util from '../util/util-index.js';
|
|
6
6
|
import { BucketStorageBatch, FlushedResult, SaveUpdate } from './BucketStorageBatch.js';
|
|
7
7
|
import { BucketStorageFactory } from './BucketStorageFactory.js';
|
|
8
|
-
import {
|
|
8
|
+
import { ParsedSyncConfigSet } from './ParsedSyncConfigSet.js';
|
|
9
|
+
import { ParseSyncConfigOptions } from './PersistedSyncConfigContent.js';
|
|
9
10
|
import { SourceEntityDescriptor } from './SourceEntity.js';
|
|
10
11
|
import { SourceTable } from './SourceTable.js';
|
|
11
12
|
import { StorageVersionConfig } from './StorageVersionConfig.js';
|
|
@@ -14,8 +15,8 @@ import { SyncStorageWriteCheckpointAPI } from './WriteCheckpointAPI.js';
|
|
|
14
15
|
* Storage for a specific replication stream.
|
|
15
16
|
*/
|
|
16
17
|
export interface SyncRulesBucketStorage extends ObserverClient<SyncRulesBucketStorageListener>, SyncStorageWriteCheckpointAPI {
|
|
17
|
-
readonly
|
|
18
|
-
readonly
|
|
18
|
+
readonly replicationStreamId: number;
|
|
19
|
+
readonly replicationStreamName: string;
|
|
19
20
|
readonly storageConfig: StorageVersionConfig;
|
|
20
21
|
readonly factory: BucketStorageFactory;
|
|
21
22
|
readonly logger: Logger;
|
|
@@ -29,7 +30,19 @@ export interface SyncRulesBucketStorage extends ObserverClient<SyncRulesBucketSt
|
|
|
29
30
|
* @deprecated Use `createWriter()` with `await using` instead.
|
|
30
31
|
*/
|
|
31
32
|
startBatch(options: CreateWriterOptions, callback: (batch: BucketStorageBatch) => Promise<void>): Promise<FlushedResult | null>;
|
|
32
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Get the canonical parsed sync config set for the given parse options.
|
|
35
|
+
*
|
|
36
|
+
* Repeated calls with the same options return the same instance for the lifetime of
|
|
37
|
+
* this storage instance. This is the identity boundary for parsed sync config state:
|
|
38
|
+
* all operations against this storage instance must use parsed objects from sets
|
|
39
|
+
* returned here, never from an independent parse of the same content.
|
|
40
|
+
*/
|
|
41
|
+
getParsedSyncConfigSet(options: ParseSyncConfigOptions): ParsedSyncConfigSet;
|
|
42
|
+
/**
|
|
43
|
+
* Shortcut for `getParsedSyncConfigSet(options).hydratedSyncConfig`.
|
|
44
|
+
*/
|
|
45
|
+
getParsedSyncRules(options: ParseSyncConfigOptions): HydratedSyncConfig;
|
|
33
46
|
/**
|
|
34
47
|
* Terminate the replication stream.
|
|
35
48
|
*
|
|
@@ -38,7 +51,7 @@ export interface SyncRulesBucketStorage extends ObserverClient<SyncRulesBucketSt
|
|
|
38
51
|
* Must only be called on stopped replication streams.
|
|
39
52
|
*/
|
|
40
53
|
terminate(options?: TerminateOptions): Promise<void>;
|
|
41
|
-
getStatus(): Promise<
|
|
54
|
+
getStatus(): Promise<ReplicationStreamStatus>;
|
|
42
55
|
/**
|
|
43
56
|
* Clear the storage, without changing state.
|
|
44
57
|
*/
|
|
@@ -100,6 +113,11 @@ export interface SyncRulesBucketStorage extends ObserverClient<SyncRulesBucketSt
|
|
|
100
113
|
* Clear checksum cache. Primarily intended for tests.
|
|
101
114
|
*/
|
|
102
115
|
clearChecksumCache(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Optional storage-provider cleanup for sync configs that have been stopped
|
|
118
|
+
* inside this replication stream.
|
|
119
|
+
*/
|
|
120
|
+
cleanupStoppedSyncConfigs?(options: CleanupStoppedSyncConfigsOptions): Promise<CleanupStoppedSyncConfigsResult>;
|
|
103
121
|
}
|
|
104
122
|
export interface SyncRulesBucketStorageListener {
|
|
105
123
|
batchStarted: (batch: BucketStorageBatch) => void;
|
|
@@ -113,15 +131,15 @@ export interface BucketChecksumRequest {
|
|
|
113
131
|
bucket: string;
|
|
114
132
|
source: BucketDataSource;
|
|
115
133
|
}
|
|
116
|
-
export interface
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
134
|
+
export interface ReplicationStreamStatus {
|
|
135
|
+
/**
|
|
136
|
+
* Source position to resume replication from.
|
|
137
|
+
*/
|
|
138
|
+
resumeLsn: string | null;
|
|
121
139
|
/**
|
|
122
|
-
*
|
|
140
|
+
* True if _every_ active/processing sync config has a client-visible checkpoint.
|
|
123
141
|
*/
|
|
124
|
-
|
|
142
|
+
snapshotDone: boolean;
|
|
125
143
|
}
|
|
126
144
|
export interface ResolveTablesOptions {
|
|
127
145
|
connection_id: number;
|
|
@@ -131,15 +149,15 @@ export interface ResolveTablesOptions {
|
|
|
131
149
|
*/
|
|
132
150
|
idGenerator?: () => string | bson.ObjectId;
|
|
133
151
|
/**
|
|
134
|
-
* For tests only - override the sync
|
|
152
|
+
* For tests only - override the parsed sync config set used.
|
|
135
153
|
*/
|
|
136
|
-
|
|
154
|
+
parsedSyncConfig?: ParsedSyncConfigSet;
|
|
137
155
|
}
|
|
138
156
|
export interface ResolveTablesResult {
|
|
139
157
|
tables: SourceTable[];
|
|
140
158
|
dropTables: SourceTable[];
|
|
141
159
|
}
|
|
142
|
-
export interface CreateWriterOptions extends
|
|
160
|
+
export interface CreateWriterOptions extends ParseSyncConfigOptions {
|
|
143
161
|
zeroLSN: string;
|
|
144
162
|
/**
|
|
145
163
|
* Whether or not to store a copy of the current data.
|
|
@@ -210,6 +228,8 @@ export interface CompactOptions {
|
|
|
210
228
|
moveBatchLimit?: number;
|
|
211
229
|
/** Minimum of 1 */
|
|
212
230
|
moveBatchQueryLimit?: number;
|
|
231
|
+
/** Byte cap per read batch for streaming compaction. Default 16MB. */
|
|
232
|
+
moveBatchByteLimit?: number;
|
|
213
233
|
/**
|
|
214
234
|
* Minimum number new operations in a bucket to trigger compaction of that bucket.
|
|
215
235
|
*
|
|
@@ -230,7 +250,14 @@ export interface CompactOptions {
|
|
|
230
250
|
logger?: Logger;
|
|
231
251
|
}
|
|
232
252
|
export interface PopulateChecksumCacheOptions {
|
|
233
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Compute checksums up to this op id.
|
|
255
|
+
*
|
|
256
|
+
* Defaults to the highest persisted op id for the replication stream, which covers
|
|
257
|
+
* the common case of populating the cache right after initial replication, before
|
|
258
|
+
* the first checkpoint exists.
|
|
259
|
+
*/
|
|
260
|
+
maxOpId?: util.InternalOpId;
|
|
234
261
|
minBucketChanges?: number;
|
|
235
262
|
signal?: AbortSignal;
|
|
236
263
|
}
|
|
@@ -243,6 +270,22 @@ export interface PopulateChecksumCacheResults {
|
|
|
243
270
|
export interface ClearStorageOptions {
|
|
244
271
|
signal?: AbortSignal;
|
|
245
272
|
}
|
|
273
|
+
export interface CleanupStoppedSyncConfigsOptions {
|
|
274
|
+
signal?: AbortSignal;
|
|
275
|
+
logger?: Logger;
|
|
276
|
+
defaultSchema: string;
|
|
277
|
+
sourceConnectionTag: string;
|
|
278
|
+
}
|
|
279
|
+
export interface CleanupStoppedSyncConfigsResult {
|
|
280
|
+
stoppedSyncConfigsRemoved: number;
|
|
281
|
+
bucketDataCollectionsDropped: number;
|
|
282
|
+
parameterIndexCollectionsDropped: number;
|
|
283
|
+
/** Best-effort number, not accurate if the operation takes longer than the timeout. */
|
|
284
|
+
bucketStateDocumentsDeleted: number;
|
|
285
|
+
sourceRecordCollectionsDropped: number;
|
|
286
|
+
sourceTablesUpdated: number;
|
|
287
|
+
sourceTablesDeleted: number;
|
|
288
|
+
}
|
|
246
289
|
export interface TerminateOptions extends ClearStorageOptions {
|
|
247
290
|
/**
|
|
248
291
|
* If true, also clear the storage before terminating.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncRulesBucketStorage.js","sourceRoot":"","sources":["../../src/storage/SyncRulesBucketStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SyncRulesBucketStorage.js","sourceRoot":"","sources":["../../src/storage/SyncRulesBucketStorage.ts"],"names":[],"mappings":"AA4YA;;;;GAIG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAE5C;IACA;IAFX,YACW,KAAa,EACb,SAAyC;QAElD,KAAK,CAAC,yCAAyC,KAAK,GAAG,CAAC,CAAC;QAHhD,UAAK,GAAL,KAAK,CAAQ;QACb,cAAS,GAAT,SAAS,CAAgC;IAGpD,CAAC;CACF;AAqDD,MAAM,CAAC,MAAM,yBAAyB,GAAsB;IAC1D,kBAAkB,EAAE,IAAI,GAAG,EAAU;IACrC,qBAAqB,EAAE,IAAI;IAC3B,uBAAuB,EAAE,IAAI,GAAG,EAAU;IAC1C,0BAA0B,EAAE,IAAI;CACjC,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { BucketDataSource, BucketDefinitionId, ParameterIndexId, ParameterIndexLookupCreator, ParameterLookupDefinitionId, SerializedSyncPlanV1, SourceTableRef, SyncConfigWithErrors } from '@powersync/service-sync-rules';
|
|
2
|
+
export interface SerializedSyncConfigWithMapping {
|
|
3
|
+
plan: SerializedSyncPlanV1;
|
|
4
|
+
mapping: SingleSyncConfigBucketDefinitionMapping;
|
|
5
|
+
}
|
|
6
|
+
export type IncrementalMappingDefinitionType = 'bucket_data' | 'parameter_lookup';
|
|
7
|
+
export interface IncrementalMappingDefinitionChange {
|
|
8
|
+
type: IncrementalMappingDefinitionType;
|
|
9
|
+
name: string;
|
|
10
|
+
id: BucketDefinitionId | ParameterIndexId;
|
|
11
|
+
}
|
|
12
|
+
export interface IncrementalMappingChanges {
|
|
13
|
+
reusedDefinitions: IncrementalMappingDefinitionChange[];
|
|
14
|
+
addedDefinitions: IncrementalMappingDefinitionChange[];
|
|
15
|
+
}
|
|
16
|
+
export interface IncrementalMappingResult {
|
|
17
|
+
mapping: SingleSyncConfigBucketDefinitionMapping;
|
|
18
|
+
changes: IncrementalMappingChanges;
|
|
19
|
+
}
|
|
20
|
+
export interface SyncConfigWithMapping {
|
|
21
|
+
syncConfigId?: string;
|
|
22
|
+
syncConfig: SyncConfigWithErrors;
|
|
23
|
+
mapping: SingleSyncConfigBucketDefinitionMapping | null;
|
|
24
|
+
}
|
|
25
|
+
export interface SyncConfigWithRequiredMapping {
|
|
26
|
+
syncConfigId: string;
|
|
27
|
+
syncConfig: SyncConfigWithErrors;
|
|
28
|
+
mapping: SingleSyncConfigBucketDefinitionMapping;
|
|
29
|
+
}
|
|
30
|
+
export interface PersistedDefinitionMapping {
|
|
31
|
+
/**
|
|
32
|
+
* Map of uniqueName -> id, unique per replication stream.
|
|
33
|
+
*/
|
|
34
|
+
definitions: Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* Map of (lookupName, queryId) -> id, unique per replication stream.
|
|
37
|
+
*/
|
|
38
|
+
parameter_indexes: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents a mapping from bucket data sources and parameter lookup sources to stable IDs used for bucket definition and parameter index persistence.
|
|
42
|
+
*
|
|
43
|
+
* Usage is deliberately restricted: writer/batch paths resolve through their own parsed
|
|
44
|
+
* sync config set's mapping, and read paths resolve through the persisted
|
|
45
|
+
* {@link SingleSyncConfigBucketDefinitionMapping} of the single sync config they serve.
|
|
46
|
+
* Do not construct ad-hoc resolution paths from parsed sources.
|
|
47
|
+
*/
|
|
48
|
+
export interface BucketDefinitionMapping {
|
|
49
|
+
/**
|
|
50
|
+
* Given a BucketDataSource within the associated SyncConfig(s), return the BucketDefinitionId, or throw if not found.
|
|
51
|
+
*/
|
|
52
|
+
bucketSourceId(source: BucketDataSource): BucketDefinitionId;
|
|
53
|
+
parameterLookupId(source: ParameterIndexLookupCreator): ParameterIndexId;
|
|
54
|
+
allBucketDefinitionIds(): BucketDefinitionId[];
|
|
55
|
+
allParameterIndexIds(): ParameterIndexId[];
|
|
56
|
+
syncConfigIdsForSourceTable(selectedSyncConfigIds: string[], table: SourceTableRef, bucketDataSourceIds: BucketDefinitionId[], parameterLookupSourceIds: ParameterIndexId[]): string[];
|
|
57
|
+
snapshotBlockingSourceTablesFilter(syncConfigId: string): Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A BucketDefinitionMapping associated with a single SyncConfig.
|
|
61
|
+
*
|
|
62
|
+
* Within a single SyncConfig, unique names are the persistence key for bucket definitions,
|
|
63
|
+
* so lookups here are name-based by design. MongoHydrationState and
|
|
64
|
+
* MultiSyncConfigBucketDefinitionMapping handle the mapping across multiple SyncConfigs in
|
|
65
|
+
* the same replication stream, where names are not unique.
|
|
66
|
+
*/
|
|
67
|
+
export declare class SingleSyncConfigBucketDefinitionMapping implements BucketDefinitionMapping {
|
|
68
|
+
private definitions;
|
|
69
|
+
private parameterLookupMapping;
|
|
70
|
+
static fromPersistedMapping(mapping: PersistedDefinitionMapping): SingleSyncConfigBucketDefinitionMapping;
|
|
71
|
+
static fromParsedSyncConfig(syncConfig: SyncConfigWithErrors): SingleSyncConfigBucketDefinitionMapping;
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @param compatibleConfigs SyncConfigs with definitions that may be re-used
|
|
75
|
+
* @param newPlan
|
|
76
|
+
* @param reservedMappings _all_ mappings used currently and historically for the replication stream; used to construct new ids
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
79
|
+
static constructIncrementalMappingFromSerializedPlans(compatibleConfigs: SerializedSyncConfigWithMapping[], newPlan: SerializedSyncPlanV1, reservedMappings: SingleSyncConfigBucketDefinitionMapping[]): SingleSyncConfigBucketDefinitionMapping;
|
|
80
|
+
static constructIncrementalMappingWithChanges(compatibleConfigs: SerializedSyncConfigWithMapping[], newPlan: SerializedSyncPlanV1, reservedMappings: SingleSyncConfigBucketDefinitionMapping[]): IncrementalMappingResult;
|
|
81
|
+
constructor(definitions?: Record<string, BucketDefinitionId>, parameterLookupMapping?: Record<string, ParameterIndexId>);
|
|
82
|
+
bucketSourceId(source: BucketDataSource): BucketDefinitionId;
|
|
83
|
+
bucketSourceIdByName(uniqueName: string): BucketDefinitionId;
|
|
84
|
+
allBucketDefinitionIds(): BucketDefinitionId[];
|
|
85
|
+
bucketDefinitionEntries(): IncrementalMappingDefinitionChange[];
|
|
86
|
+
allParameterIndexIds(): ParameterIndexId[];
|
|
87
|
+
parameterIndexEntries(): IncrementalMappingDefinitionChange[];
|
|
88
|
+
allDefinitionEntries(): IncrementalMappingDefinitionChange[];
|
|
89
|
+
parameterLookupId(source: ParameterIndexLookupCreator): ParameterIndexId;
|
|
90
|
+
parameterLookupIdByKey(key: string): ParameterIndexId;
|
|
91
|
+
serialize(): PersistedDefinitionMapping;
|
|
92
|
+
syncConfigIdsForSourceTable(selectedSyncConfigIds: string[], _table: SourceTableRef, bucketDataSourceIds: BucketDefinitionId[], parameterLookupSourceIds: ParameterIndexId[]): string[];
|
|
93
|
+
snapshotBlockingSourceTablesFilter(_syncConfigId: string): Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A BucketDefinitionMapping across all SyncConfigs of one parse of a replication stream.
|
|
97
|
+
*
|
|
98
|
+
* Source lookups are strictly identity-based: a source that did not come from the parse
|
|
99
|
+
* this mapping was constructed with is an error. Unique names are not unique across sync
|
|
100
|
+
* configs in a replication stream, so there is deliberately no name-based fallback.
|
|
101
|
+
*/
|
|
102
|
+
export declare class MultiSyncConfigBucketDefinitionMapping implements BucketDefinitionMapping {
|
|
103
|
+
private bucketDataSourceMappings;
|
|
104
|
+
private bucketDataSourceSyncConfigIdsById;
|
|
105
|
+
private parameterLookupMappings;
|
|
106
|
+
private parameterLookupSyncConfigIdsById;
|
|
107
|
+
private syncConfigsById;
|
|
108
|
+
private mappings;
|
|
109
|
+
constructor(syncConfigs: SyncConfigWithRequiredMapping[]);
|
|
110
|
+
bucketSourceId(source: BucketDataSource): BucketDefinitionId;
|
|
111
|
+
allBucketDefinitionIds(): BucketDefinitionId[];
|
|
112
|
+
parameterLookupId(source: ParameterIndexLookupCreator): ParameterIndexId;
|
|
113
|
+
allParameterIndexIds(): ParameterIndexId[];
|
|
114
|
+
syncConfigIdsForSourceTable(_selectedSyncConfigIds: string[], table: SourceTableRef, bucketDataSourceIds: BucketDefinitionId[], parameterLookupSourceIds: ParameterIndexId[]): string[];
|
|
115
|
+
snapshotBlockingSourceTablesFilter(syncConfigId: string): Record<string, unknown>;
|
|
116
|
+
}
|
|
117
|
+
export declare function parameterLookupKey(id: ParameterLookupDefinitionId): string;
|