@powersync/service-core 1.20.5 → 1.22.0
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 +66 -0
- package/dist/api/RouteAPI.d.ts +3 -3
- package/dist/api/diagnostics.d.ts +1 -1
- package/dist/api/diagnostics.js +19 -3
- package/dist/api/diagnostics.js.map +1 -1
- package/dist/auth/RemoteJWKSCollector.js +3 -2
- package/dist/auth/RemoteJWKSCollector.js.map +1 -1
- package/dist/entry/commands/teardown-action.js +1 -1
- package/dist/entry/commands/teardown-action.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/modules/AbstractModule.d.ts +1 -1
- package/dist/replication/AbstractReplicationJob.js +1 -1
- package/dist/replication/AbstractReplicationJob.js.map +1 -1
- package/dist/replication/AbstractReplicator.d.ts +6 -6
- package/dist/replication/AbstractReplicator.js +21 -21
- package/dist/replication/AbstractReplicator.js.map +1 -1
- package/dist/replication/RelationCache.d.ts +9 -2
- package/dist/replication/RelationCache.js +21 -2
- package/dist/replication/RelationCache.js.map +1 -1
- package/dist/routes/configure-fastify.js +3 -1
- package/dist/routes/configure-fastify.js.map +1 -1
- package/dist/routes/endpoints/admin.js +16 -8
- 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 +8 -8
- package/dist/routes/endpoints/sync-rules.js.map +1 -1
- package/dist/routes/endpoints/sync-stream.js +2 -2
- package/dist/routes/endpoints/sync-stream.js.map +1 -1
- package/dist/routes/route-register.d.ts +2 -0
- package/dist/routes/route-register.js +65 -3
- package/dist/routes/route-register.js.map +1 -1
- package/dist/runner/teardown.js +4 -4
- package/dist/runner/teardown.js.map +1 -1
- package/dist/storage/BucketStorage.d.ts +9 -9
- package/dist/storage/BucketStorage.js +9 -9
- package/dist/storage/BucketStorageBatch.d.ts +29 -0
- package/dist/storage/BucketStorageBatch.js.map +1 -1
- package/dist/storage/BucketStorageFactory.d.ts +27 -18
- package/dist/storage/BucketStorageFactory.js +13 -12
- package/dist/storage/BucketStorageFactory.js.map +1 -1
- package/dist/storage/PersistedSyncRulesContent.d.ts +6 -4
- package/dist/storage/PersistedSyncRulesContent.js +15 -8
- package/dist/storage/PersistedSyncRulesContent.js.map +1 -1
- package/dist/storage/SourceEntity.d.ts +8 -1
- package/dist/storage/SourceTable.d.ts +32 -11
- package/dist/storage/SourceTable.js +41 -15
- package/dist/storage/SourceTable.js.map +1 -1
- package/dist/storage/StorageVersionConfig.d.ts +1 -1
- package/dist/storage/StorageVersionConfig.js +1 -1
- package/dist/storage/SyncRulesBucketStorage.d.ts +63 -18
- package/dist/storage/SyncRulesBucketStorage.js +14 -0
- package/dist/storage/SyncRulesBucketStorage.js.map +1 -1
- package/dist/storage/WriteCheckpointAPI.d.ts +6 -6
- package/dist/storage/WriteCheckpointAPI.js +1 -1
- package/dist/storage/bson.d.ts +0 -1
- package/dist/storage/bson.js +0 -4
- package/dist/storage/bson.js.map +1 -1
- package/dist/sync/BucketChecksumState.d.ts +6 -9
- package/dist/sync/BucketChecksumState.js +117 -58
- package/dist/sync/BucketChecksumState.js.map +1 -1
- package/dist/sync/sync.d.ts +2 -2
- package/dist/sync/sync.js.map +1 -1
- package/dist/tracing/PerformanceTracer.d.ts +60 -0
- package/dist/tracing/PerformanceTracer.js +105 -0
- package/dist/tracing/PerformanceTracer.js.map +1 -0
- package/dist/tracing/TraceWriter.d.ts +22 -0
- package/dist/tracing/TraceWriter.js +63 -0
- package/dist/tracing/TraceWriter.js.map +1 -0
- package/dist/util/checkpointing.js +1 -1
- package/dist/util/config/compound-config-collector.d.ts +1 -1
- package/dist/util/config/compound-config-collector.js +2 -2
- package/dist/util/config/compound-config-collector.js.map +1 -1
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js +1 -1
- package/dist/util/config/sync-rules/impl/filesystem-sync-rules-collector.js.map +1 -1
- package/dist/util/env.js +1 -1
- package/dist/util/protocol-types.d.ts +1 -1
- package/dist/util/protocol-types.js +1 -1
- package/dist/util/util-index.d.ts +1 -0
- package/dist/util/util-index.js +1 -0
- package/dist/util/util-index.js.map +1 -1
- package/dist/util/utils.d.ts +5 -0
- package/dist/util/utils.js +7 -0
- package/dist/util/utils.js.map +1 -1
- package/package.json +11 -11
- package/src/api/RouteAPI.ts +3 -3
- package/src/api/diagnostics.ts +29 -6
- package/src/auth/RemoteJWKSCollector.ts +3 -1
- package/src/entry/commands/teardown-action.ts +1 -1
- package/src/index.ts +2 -0
- package/src/modules/AbstractModule.ts +1 -1
- package/src/replication/AbstractReplicationJob.ts +1 -1
- package/src/replication/AbstractReplicator.ts +23 -23
- package/src/replication/RelationCache.ts +23 -4
- package/src/routes/configure-fastify.ts +8 -1
- package/src/routes/endpoints/admin.ts +17 -8
- package/src/routes/endpoints/checkpointing.ts +1 -1
- package/src/routes/endpoints/socket-route.ts +1 -1
- package/src/routes/endpoints/sync-rules.ts +8 -8
- package/src/routes/endpoints/sync-stream.ts +2 -2
- package/src/routes/route-register.ts +73 -4
- package/src/runner/teardown.ts +4 -4
- package/src/storage/BucketStorage.ts +9 -9
- package/src/storage/BucketStorageBatch.ts +32 -0
- package/src/storage/BucketStorageFactory.ts +35 -23
- package/src/storage/PersistedSyncRulesContent.ts +20 -12
- package/src/storage/SourceEntity.ts +9 -1
- package/src/storage/SourceTable.ts +56 -22
- package/src/storage/StorageVersionConfig.ts +1 -1
- package/src/storage/SyncRulesBucketStorage.ts +74 -22
- package/src/storage/WriteCheckpointAPI.ts +6 -6
- package/src/storage/bson.ts +0 -5
- package/src/sync/BucketChecksumState.ts +142 -78
- package/src/sync/sync.ts +4 -4
- package/src/tracing/PerformanceTracer.ts +149 -0
- package/src/tracing/TraceWriter.ts +67 -0
- package/src/util/checkpointing.ts +1 -1
- package/src/util/config/compound-config-collector.ts +3 -3
- package/src/util/config/sync-rules/impl/filesystem-sync-rules-collector.ts +1 -1
- package/src/util/env.ts +1 -1
- package/src/util/protocol-types.ts +1 -1
- package/src/util/util-index.ts +1 -0
- package/src/util/utils.ts +8 -0
- package/test/src/auth.test.ts +120 -1
- package/test/src/diagnostics.test.ts +155 -0
- package/test/src/routes/error-handler.integration.test.ts +275 -0
- package/test/src/routes/stream.test.ts +15 -4
- package/test/src/storage/SourceTable.test.ts +89 -0
- package/test/src/sync/BucketChecksumState.test.ts +244 -80
- package/test/tsconfig.json +0 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -9,14 +9,14 @@ import { SyncRulesBucketStorage } from './SyncRulesBucketStorage.js';
|
|
|
9
9
|
/**
|
|
10
10
|
* Represents a configured storage provider.
|
|
11
11
|
*
|
|
12
|
-
* The provider can handle multiple
|
|
13
|
-
* This is to handle replication of a new version of sync
|
|
12
|
+
* The provider can handle multiple replication streams concurrently, each with their own storage.
|
|
13
|
+
* This is to handle replication of a new version of sync config, while the old replication stream is still active.
|
|
14
14
|
*
|
|
15
|
-
* Storage APIs for a specific
|
|
15
|
+
* Storage APIs for a specific replication stream are provided by the `SyncRulesBucketStorage` instances.
|
|
16
16
|
*/
|
|
17
17
|
export declare abstract class BucketStorageFactory extends BaseObserver<BucketStorageFactoryListener> implements AsyncDisposable {
|
|
18
18
|
/**
|
|
19
|
-
* Update sync
|
|
19
|
+
* Update sync config from configuration, if changed.
|
|
20
20
|
*/
|
|
21
21
|
configureSyncRules(options: UpdateSyncRulesOptions): Promise<{
|
|
22
22
|
updated: boolean;
|
|
@@ -24,46 +24,46 @@ export declare abstract class BucketStorageFactory extends BaseObserver<BucketSt
|
|
|
24
24
|
lock?: ReplicationLock;
|
|
25
25
|
}>;
|
|
26
26
|
/**
|
|
27
|
-
* Get a storage instance to query sync data for specific sync
|
|
27
|
+
* Get a storage instance to query sync data for specific sync config.
|
|
28
28
|
*/
|
|
29
29
|
abstract getInstance(syncRules: PersistedSyncRulesContent, options?: GetIntanceOptions): SyncRulesBucketStorage;
|
|
30
30
|
/**
|
|
31
|
-
* Deploy new sync
|
|
31
|
+
* Deploy new sync config.
|
|
32
32
|
*/
|
|
33
33
|
abstract updateSyncRules(options: UpdateSyncRulesOptions): Promise<PersistedSyncRulesContent>;
|
|
34
34
|
/**
|
|
35
35
|
* Indicate that a slot was removed, and we should re-sync by creating
|
|
36
|
-
* a new
|
|
36
|
+
* a new replication stream.
|
|
37
37
|
*
|
|
38
38
|
* This is roughly the same as deploying a new version of the current sync
|
|
39
|
-
*
|
|
40
|
-
* the latest
|
|
39
|
+
* config, but also accounts for cases where the current sync config is not
|
|
40
|
+
* the latest one.
|
|
41
41
|
*
|
|
42
42
|
* Replication should be restarted after this.
|
|
43
43
|
*/
|
|
44
44
|
abstract restartReplication(sync_rules_group_id: number): Promise<void>;
|
|
45
45
|
/**
|
|
46
|
-
* Get the sync
|
|
46
|
+
* Get the sync config used for querying.
|
|
47
47
|
*/
|
|
48
48
|
getActiveSyncRules(options: ParseSyncRulesOptions): Promise<PersistedSyncRules | null>;
|
|
49
49
|
/**
|
|
50
|
-
* Get the sync
|
|
50
|
+
* Get the sync config used for querying.
|
|
51
51
|
*/
|
|
52
52
|
abstract getActiveSyncRulesContent(): Promise<PersistedSyncRulesContent | null>;
|
|
53
53
|
/**
|
|
54
|
-
* Get the sync
|
|
54
|
+
* Get the sync config that will be active next once done with initial replicatino.
|
|
55
55
|
*/
|
|
56
56
|
getNextSyncRules(options: ParseSyncRulesOptions): Promise<PersistedSyncRules | null>;
|
|
57
57
|
/**
|
|
58
|
-
* Get the sync
|
|
58
|
+
* Get the sync config that will be active next once done with initial replicatino.
|
|
59
59
|
*/
|
|
60
60
|
abstract getNextSyncRulesContent(): Promise<PersistedSyncRulesContent | null>;
|
|
61
61
|
/**
|
|
62
|
-
* Get all sync
|
|
62
|
+
* Get all sync config currently replicating. Typically this is the "active" and "next" sync config.
|
|
63
63
|
*/
|
|
64
64
|
abstract getReplicatingSyncRules(): Promise<PersistedSyncRulesContent[]>;
|
|
65
65
|
/**
|
|
66
|
-
* Get all sync
|
|
66
|
+
* Get all sync config stopped but not terminated yet.
|
|
67
67
|
*/
|
|
68
68
|
abstract getStoppedSyncRules(): Promise<PersistedSyncRulesContent[]>;
|
|
69
69
|
/**
|
|
@@ -71,11 +71,11 @@ export declare abstract class BucketStorageFactory extends BaseObserver<BucketSt
|
|
|
71
71
|
*/
|
|
72
72
|
abstract getActiveStorage(): Promise<SyncRulesBucketStorage | null>;
|
|
73
73
|
/**
|
|
74
|
-
* Get storage size of active
|
|
74
|
+
* Get storage size of active replication stream.
|
|
75
75
|
*/
|
|
76
76
|
abstract getStorageMetrics(): Promise<StorageMetrics>;
|
|
77
77
|
/**
|
|
78
|
-
* Get the unique identifier for this instance of Powersync
|
|
78
|
+
* Get the unique identifier for this instance of Powersync.
|
|
79
79
|
*/
|
|
80
80
|
abstract getPowerSyncInstanceId(): Promise<string>;
|
|
81
81
|
/**
|
|
@@ -112,9 +112,18 @@ export interface UpdateSyncRulesOptions {
|
|
|
112
112
|
* compiler.
|
|
113
113
|
*/
|
|
114
114
|
plan: SerializedSyncPlan | null;
|
|
115
|
+
/**
|
|
116
|
+
* Parsed sync config, primarily to generate a definition mapping.
|
|
117
|
+
* Not persisted, and the defaultSchema used for parsing is not relevant.
|
|
118
|
+
*/
|
|
119
|
+
parsed: SyncConfigWithErrors;
|
|
115
120
|
};
|
|
116
121
|
lock?: boolean;
|
|
117
122
|
storageVersion?: number;
|
|
123
|
+
/**
|
|
124
|
+
* Only relevant if the result is used. This does not affect the persisted config.
|
|
125
|
+
*/
|
|
126
|
+
defaultSchema?: string;
|
|
118
127
|
}
|
|
119
128
|
export interface SerializedSyncPlan {
|
|
120
129
|
/**
|
|
@@ -135,7 +144,7 @@ export interface SerializedSyncPlan {
|
|
|
135
144
|
export declare function updateSyncRulesFromYaml(content: string, options?: Omit<UpdateSyncRulesOptions, 'config'> & {
|
|
136
145
|
validate?: boolean;
|
|
137
146
|
}): UpdateSyncRulesOptions;
|
|
138
|
-
export declare function updateSyncRulesFromConfig(
|
|
147
|
+
export declare function updateSyncRulesFromConfig(parsed: SyncConfigWithErrors, options?: Omit<UpdateSyncRulesOptions, 'config'>): UpdateSyncRulesOptions;
|
|
139
148
|
export interface GetIntanceOptions {
|
|
140
149
|
/**
|
|
141
150
|
* Set to true to skip trigger any events for creating the instance.
|
|
@@ -4,41 +4,41 @@ import { syncConfigYamlErrorToReplicationError } from '../util/errors.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Represents a configured storage provider.
|
|
6
6
|
*
|
|
7
|
-
* The provider can handle multiple
|
|
8
|
-
* This is to handle replication of a new version of sync
|
|
7
|
+
* The provider can handle multiple replication streams concurrently, each with their own storage.
|
|
8
|
+
* This is to handle replication of a new version of sync config, while the old replication stream is still active.
|
|
9
9
|
*
|
|
10
|
-
* Storage APIs for a specific
|
|
10
|
+
* Storage APIs for a specific replication stream are provided by the `SyncRulesBucketStorage` instances.
|
|
11
11
|
*/
|
|
12
12
|
export class BucketStorageFactory extends BaseObserver {
|
|
13
13
|
/**
|
|
14
|
-
* Update sync
|
|
14
|
+
* Update sync config from configuration, if changed.
|
|
15
15
|
*/
|
|
16
16
|
async configureSyncRules(options) {
|
|
17
17
|
const next = await this.getNextSyncRulesContent();
|
|
18
18
|
const active = await this.getActiveSyncRulesContent();
|
|
19
19
|
if (next?.sync_rules_content == options.config.yaml) {
|
|
20
|
-
logger.info('Sync
|
|
20
|
+
logger.info('Sync config unchanged');
|
|
21
21
|
return { updated: false };
|
|
22
22
|
}
|
|
23
23
|
else if (next == null && active?.sync_rules_content == options.config.yaml) {
|
|
24
|
-
logger.info('Sync
|
|
24
|
+
logger.info('Sync config unchanged');
|
|
25
25
|
return { updated: false };
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
logger.info('Sync
|
|
28
|
+
logger.info('Sync config updated');
|
|
29
29
|
const persisted_sync_rules = await this.updateSyncRules(options);
|
|
30
30
|
return { updated: true, persisted_sync_rules, lock: persisted_sync_rules.current_lock ?? undefined };
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
* Get the sync
|
|
34
|
+
* Get the sync config used for querying.
|
|
35
35
|
*/
|
|
36
36
|
async getActiveSyncRules(options) {
|
|
37
37
|
const content = await this.getActiveSyncRulesContent();
|
|
38
38
|
return content?.parsed(options) ?? null;
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
* Get the sync
|
|
41
|
+
* Get the sync config that will be active next once done with initial replicatino.
|
|
42
42
|
*/
|
|
43
43
|
async getNextSyncRules(options) {
|
|
44
44
|
const content = await this.getNextSyncRulesContent();
|
|
@@ -49,13 +49,14 @@ export function updateSyncRulesFromYaml(content, options) {
|
|
|
49
49
|
const config = SqlSyncRules.fromYaml(content, {
|
|
50
50
|
// No schema-based validation at this point
|
|
51
51
|
schema: undefined,
|
|
52
|
-
defaultSchema: 'not_applicable', // Not needed for validation
|
|
52
|
+
defaultSchema: options?.defaultSchema ?? 'not_applicable', // Not needed for validation
|
|
53
53
|
throwOnError: options?.validate ?? false
|
|
54
54
|
});
|
|
55
55
|
return updateSyncRulesFromConfig(config, options);
|
|
56
56
|
}
|
|
57
|
-
export function updateSyncRulesFromConfig(
|
|
57
|
+
export function updateSyncRulesFromConfig(parsed, options) {
|
|
58
58
|
let plan = null;
|
|
59
|
+
const { config, errors } = parsed;
|
|
59
60
|
if (config instanceof PrecompiledSyncConfig) {
|
|
60
61
|
const eventDescriptors = {};
|
|
61
62
|
for (const event of config.eventDescriptors) {
|
|
@@ -68,6 +69,6 @@ export function updateSyncRulesFromConfig({ config, errors }, options) {
|
|
|
68
69
|
errors: errors.map((e) => syncConfigYamlErrorToReplicationError(e))
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
|
-
return { config: { yaml: config.content, plan }, ...options };
|
|
72
|
+
return { config: { yaml: config.content, plan, parsed }, ...options };
|
|
72
73
|
}
|
|
73
74
|
//# sourceMappingURL=BucketStorageFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BucketStorageFactory.js","sourceRoot":"","sources":["../../src/storage/BucketStorageFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EACL,qBAAqB,EAErB,iBAAiB,EACjB,YAAY,EAEb,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,qCAAqC,EAAE,MAAM,mBAAmB,CAAC;AAO1E;;;;;;;GAOG;AACH,MAAM,OAAgB,oBACpB,SAAQ,YAA0C;IAGlD;;OAEG;IACH,KAAK,CAAC,kBAAkB,CACtB,OAA+B;QAE/B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,yBAAyB,EAAE,CAAC;QAEtD,IAAI,IAAI,EAAE,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACpD,MAAM,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"BucketStorageFactory.js","sourceRoot":"","sources":["../../src/storage/BucketStorageFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EACL,qBAAqB,EAErB,iBAAiB,EACjB,YAAY,EAEb,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,qCAAqC,EAAE,MAAM,mBAAmB,CAAC;AAO1E;;;;;;;GAOG;AACH,MAAM,OAAgB,oBACpB,SAAQ,YAA0C;IAGlD;;OAEG;IACH,KAAK,CAAC,kBAAkB,CACtB,OAA+B;QAE/B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAClD,MAAM,MAAM,GAAG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ConfigWithErrors } from '@powersync/service-sync-rules';
|
|
2
3
|
import { SerializedSyncPlan, UpdateSyncRulesOptions } from './BucketStorageFactory.js';
|
|
3
4
|
import { ReplicationLock } from './ReplicationLock.js';
|
|
4
5
|
import { StorageVersionConfig } from './StorageVersionConfig.js';
|
|
@@ -11,7 +12,7 @@ export interface PersistedSyncRulesContentData {
|
|
|
11
12
|
readonly compiled_plan: SerializedSyncPlan | null;
|
|
12
13
|
readonly slot_name: string;
|
|
13
14
|
/**
|
|
14
|
-
* True if this is the "active" copy of the sync
|
|
15
|
+
* True if this is the "active" copy of the sync config.
|
|
15
16
|
*/
|
|
16
17
|
readonly active: boolean;
|
|
17
18
|
readonly storageVersion: number;
|
|
@@ -28,6 +29,7 @@ export declare abstract class PersistedSyncRulesContent implements PersistedSync
|
|
|
28
29
|
readonly slot_name: string;
|
|
29
30
|
readonly active: boolean;
|
|
30
31
|
readonly storageVersion: number;
|
|
32
|
+
readonly logger: Logger;
|
|
31
33
|
readonly last_checkpoint_lsn: string | null;
|
|
32
34
|
readonly last_fatal_error?: string | null;
|
|
33
35
|
readonly last_fatal_error_ts?: Date | null;
|
|
@@ -47,11 +49,11 @@ export declare abstract class PersistedSyncRulesContent implements PersistedSync
|
|
|
47
49
|
}
|
|
48
50
|
export interface PersistedSyncRules {
|
|
49
51
|
readonly id: number;
|
|
50
|
-
readonly
|
|
52
|
+
readonly syncConfigWithErrors: SyncConfigWithErrors;
|
|
51
53
|
readonly slot_name: string;
|
|
52
54
|
/**
|
|
53
55
|
* For testing only.
|
|
54
56
|
*/
|
|
55
57
|
readonly hydrationState: HydrationState;
|
|
56
|
-
|
|
58
|
+
hydratedSyncConfig(): HydratedSyncConfig;
|
|
57
59
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ErrorCode, ServiceError } from '@powersync/lib-services-framework';
|
|
2
|
-
import { CompatibilityContext, CompatibilityOption, DEFAULT_HYDRATION_STATE, deserializeSyncPlan,
|
|
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';
|
|
3
4
|
import { STORAGE_VERSION_CONFIG } from './StorageVersionConfig.js';
|
|
4
5
|
export class PersistedSyncRulesContent {
|
|
5
6
|
id;
|
|
@@ -8,6 +9,7 @@ export class PersistedSyncRulesContent {
|
|
|
8
9
|
slot_name;
|
|
9
10
|
active;
|
|
10
11
|
storageVersion;
|
|
12
|
+
logger;
|
|
11
13
|
last_checkpoint_lsn;
|
|
12
14
|
last_fatal_error;
|
|
13
15
|
last_fatal_error_ts;
|
|
@@ -15,6 +17,7 @@ export class PersistedSyncRulesContent {
|
|
|
15
17
|
last_checkpoint_ts;
|
|
16
18
|
constructor(data) {
|
|
17
19
|
Object.assign(this, data);
|
|
20
|
+
this.logger = defaultLogger.child({ prefix: `[${this.slot_name}] ` });
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
23
|
* Load the storage config.
|
|
@@ -24,7 +27,7 @@ export class PersistedSyncRulesContent {
|
|
|
24
27
|
getStorageConfig() {
|
|
25
28
|
const storageConfig = STORAGE_VERSION_CONFIG[this.storageVersion];
|
|
26
29
|
if (storageConfig == null) {
|
|
27
|
-
throw new ServiceError(ErrorCode.PSYNC_S1005, `Unsupported storage version ${this.storageVersion} for
|
|
30
|
+
throw new ServiceError(ErrorCode.PSYNC_S1005, `Unsupported storage version ${this.storageVersion} for replication stream ${this.id}`);
|
|
28
31
|
}
|
|
29
32
|
return storageConfig;
|
|
30
33
|
}
|
|
@@ -45,9 +48,11 @@ export class PersistedSyncRulesContent {
|
|
|
45
48
|
}
|
|
46
49
|
const precompiled = new PrecompiledSyncConfig(plan, compatibility, eventDefinitions, {
|
|
47
50
|
defaultSchema: options.defaultSchema,
|
|
48
|
-
engine: javaScriptExpressionEngine(compatibility),
|
|
49
51
|
sourceText: this.sync_rules_content
|
|
50
52
|
});
|
|
53
|
+
// Note: If the original content did not define a storage version, this will still set the storage version.
|
|
54
|
+
// This means asUpdateOptions will not change the storage version, even if the default changes.
|
|
55
|
+
precompiled.storageVersion = this.storageVersion;
|
|
51
56
|
const errors = [];
|
|
52
57
|
if (this.compiled_plan.errors) {
|
|
53
58
|
for (const error of this.compiled_plan.errors) {
|
|
@@ -76,16 +81,18 @@ export class PersistedSyncRulesContent {
|
|
|
76
81
|
return {
|
|
77
82
|
id: this.id,
|
|
78
83
|
slot_name: this.slot_name,
|
|
79
|
-
|
|
84
|
+
syncConfigWithErrors: config,
|
|
80
85
|
hydrationState,
|
|
81
|
-
|
|
82
|
-
return config.config.hydrate({ hydrationState });
|
|
86
|
+
hydratedSyncConfig: () => {
|
|
87
|
+
return config.config.hydrate({ hydrationState, sqlite: nodeSqlite(sqlite) });
|
|
83
88
|
}
|
|
84
89
|
};
|
|
85
90
|
}
|
|
86
91
|
asUpdateOptions(options) {
|
|
92
|
+
// defaultSchema is not relevant for the parsed version here
|
|
93
|
+
const parsed = this.parsed({ defaultSchema: 'not_applicable' });
|
|
87
94
|
return {
|
|
88
|
-
config: { yaml: this.sync_rules_content, plan: this.compiled_plan },
|
|
95
|
+
config: { yaml: this.sync_rules_content, plan: this.compiled_plan, parsed: parsed.syncConfigWithErrors },
|
|
89
96
|
...options
|
|
90
97
|
};
|
|
91
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersistedSyncRulesContent.js","sourceRoot":"","sources":["../../src/storage/PersistedSyncRulesContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"PersistedSyncRulesContent.js","sourceRoot":"","sources":["../../src/storage/PersistedSyncRulesContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,aAAa,EA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I,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,CAAC,oBAAoB,EAAE;YACxG,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;CAGF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SourceTableRef } from '@powersync/service-sync-rules';
|
|
1
2
|
export interface ColumnDescriptor {
|
|
2
3
|
name: string;
|
|
3
4
|
/**
|
|
@@ -9,7 +10,7 @@ export interface ColumnDescriptor {
|
|
|
9
10
|
*/
|
|
10
11
|
typeId?: number;
|
|
11
12
|
}
|
|
12
|
-
export interface SourceEntityDescriptor {
|
|
13
|
+
export interface SourceEntityDescriptor extends SourceTableRef {
|
|
13
14
|
/**
|
|
14
15
|
* The internal id of the source entity structure in the database.
|
|
15
16
|
* If undefined, the schema and name are used as the identifier.
|
|
@@ -22,4 +23,10 @@ export interface SourceEntityDescriptor {
|
|
|
22
23
|
* The columns that are used to uniquely identify a record in the source entity.
|
|
23
24
|
*/
|
|
24
25
|
replicaIdColumns: ColumnDescriptor[];
|
|
26
|
+
/**
|
|
27
|
+
* Whether the source always sends complete row data with each operation (e.g. Postgres REPLICA
|
|
28
|
+
* IDENTITY FULL). When true, no current_data copy is needed. Undefined means the source does not
|
|
29
|
+
* report this, in which case we default to keeping a copy.
|
|
30
|
+
*/
|
|
31
|
+
sendsCompleteRows?: boolean;
|
|
25
32
|
}
|
|
@@ -1,28 +1,35 @@
|
|
|
1
|
+
import { BucketDataSource, ParameterIndexLookupCreator, SourceTableRef } from '@powersync/service-sync-rules';
|
|
1
2
|
import { bson } from '../index.js';
|
|
2
|
-
import { ColumnDescriptor
|
|
3
|
+
import { ColumnDescriptor } from './SourceEntity.js';
|
|
3
4
|
/**
|
|
4
5
|
* Format of the id depends on the bucket storage module. It should be consistent within the module.
|
|
5
6
|
*/
|
|
6
7
|
export type SourceTableId = string | bson.ObjectId;
|
|
7
8
|
export interface SourceTableOptions {
|
|
8
9
|
id: SourceTableId;
|
|
9
|
-
|
|
10
|
+
ref: SourceTableRef;
|
|
10
11
|
objectId: number | string | undefined;
|
|
11
|
-
schema: string;
|
|
12
|
-
name: string;
|
|
13
12
|
replicaIdColumns: ColumnDescriptor[];
|
|
14
13
|
snapshotComplete: boolean;
|
|
14
|
+
bucketDataSources: BucketDataSource[];
|
|
15
|
+
parameterLookupSources: ParameterIndexLookupCreator[];
|
|
15
16
|
}
|
|
16
17
|
export interface TableSnapshotStatus {
|
|
17
18
|
totalEstimatedCount: number;
|
|
18
19
|
replicatedCount: number;
|
|
19
20
|
lastKey: Uint8Array | null;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Represents a resolved source table.
|
|
24
|
+
*
|
|
25
|
+
* There could be multiple of these for the same SourceTableRef.
|
|
26
|
+
* For that reason, we do not implement the SourceTableRef interface, to ensure that the two are not used interchangably.
|
|
27
|
+
*/
|
|
28
|
+
export declare class SourceTable {
|
|
22
29
|
readonly options: SourceTableOptions;
|
|
23
30
|
static readonly DEFAULT_TAG = "default";
|
|
24
31
|
/**
|
|
25
|
-
* True if the table is used in sync
|
|
32
|
+
* True if the table is used in sync config for data queries.
|
|
26
33
|
*
|
|
27
34
|
* This value is resolved externally, and cached here.
|
|
28
35
|
*
|
|
@@ -30,7 +37,7 @@ export declare class SourceTable implements SourceEntityDescriptor {
|
|
|
30
37
|
*/
|
|
31
38
|
syncData: boolean;
|
|
32
39
|
/**
|
|
33
|
-
* True if the table is used in sync
|
|
40
|
+
* True if the table is used in sync config for data queries.
|
|
34
41
|
*
|
|
35
42
|
* This value is resolved externally, and cached here.
|
|
36
43
|
*
|
|
@@ -38,13 +45,25 @@ export declare class SourceTable implements SourceEntityDescriptor {
|
|
|
38
45
|
*/
|
|
39
46
|
syncParameters: boolean;
|
|
40
47
|
/**
|
|
41
|
-
* True if the table is used in sync
|
|
48
|
+
* True if the table is used in sync config for events.
|
|
42
49
|
*
|
|
43
50
|
* This value is resolved externally, and cached here.
|
|
44
51
|
*
|
|
45
52
|
* Defaults to true for tests.
|
|
46
53
|
*/
|
|
47
54
|
syncEvent: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* True if raw data should be stored in current_data collection.
|
|
57
|
+
*
|
|
58
|
+
* This is needed when the source sends partial row data (e.g. TOAST values).
|
|
59
|
+
* When REPLICA IDENTITY FULL is configured, complete rows are always sent,
|
|
60
|
+
* so we don't need to store raw data.
|
|
61
|
+
*
|
|
62
|
+
* This value is resolved externally based on table configuration.
|
|
63
|
+
*
|
|
64
|
+
* Defaults to true for tests (conservative approach).
|
|
65
|
+
*/
|
|
66
|
+
storeCurrentData: boolean;
|
|
48
67
|
/**
|
|
49
68
|
* Always undefined if snapshotComplete = true.
|
|
50
69
|
*
|
|
@@ -54,14 +73,16 @@ export declare class SourceTable implements SourceEntityDescriptor {
|
|
|
54
73
|
snapshotComplete: boolean;
|
|
55
74
|
constructor(options: SourceTableOptions);
|
|
56
75
|
get id(): SourceTableId;
|
|
57
|
-
get connectionTag(): string;
|
|
58
76
|
get objectId(): string | number | undefined;
|
|
59
77
|
get schema(): string;
|
|
60
78
|
get name(): string;
|
|
79
|
+
get ref(): SourceTableRef;
|
|
61
80
|
get replicaIdColumns(): ColumnDescriptor[];
|
|
81
|
+
get bucketDataSources(): BucketDataSource[];
|
|
82
|
+
get parameterLookupSources(): ParameterIndexLookupCreator[];
|
|
62
83
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
84
|
+
* Sanitized name of the entity in the format of "{schema}.{entity name}".
|
|
85
|
+
* Suitable for safe use in Postgres queries.
|
|
65
86
|
*/
|
|
66
87
|
get qualifiedName(): string;
|
|
67
88
|
get syncAny(): boolean;
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { DEFAULT_TAG } from '@powersync/service-sync-rules';
|
|
2
2
|
import * as util from '../util/util-index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a resolved source table.
|
|
5
|
+
*
|
|
6
|
+
* There could be multiple of these for the same SourceTableRef.
|
|
7
|
+
* For that reason, we do not implement the SourceTableRef interface, to ensure that the two are not used interchangably.
|
|
8
|
+
*/
|
|
3
9
|
export class SourceTable {
|
|
4
10
|
options;
|
|
5
11
|
static DEFAULT_TAG = DEFAULT_TAG;
|
|
6
12
|
/**
|
|
7
|
-
* True if the table is used in sync
|
|
13
|
+
* True if the table is used in sync config for data queries.
|
|
8
14
|
*
|
|
9
15
|
* This value is resolved externally, and cached here.
|
|
10
16
|
*
|
|
@@ -12,7 +18,7 @@ export class SourceTable {
|
|
|
12
18
|
*/
|
|
13
19
|
syncData = true;
|
|
14
20
|
/**
|
|
15
|
-
* True if the table is used in sync
|
|
21
|
+
* True if the table is used in sync config for data queries.
|
|
16
22
|
*
|
|
17
23
|
* This value is resolved externally, and cached here.
|
|
18
24
|
*
|
|
@@ -20,13 +26,25 @@ export class SourceTable {
|
|
|
20
26
|
*/
|
|
21
27
|
syncParameters = true;
|
|
22
28
|
/**
|
|
23
|
-
* True if the table is used in sync
|
|
29
|
+
* True if the table is used in sync config for events.
|
|
24
30
|
*
|
|
25
31
|
* This value is resolved externally, and cached here.
|
|
26
32
|
*
|
|
27
33
|
* Defaults to true for tests.
|
|
28
34
|
*/
|
|
29
35
|
syncEvent = true;
|
|
36
|
+
/**
|
|
37
|
+
* True if raw data should be stored in current_data collection.
|
|
38
|
+
*
|
|
39
|
+
* This is needed when the source sends partial row data (e.g. TOAST values).
|
|
40
|
+
* When REPLICA IDENTITY FULL is configured, complete rows are always sent,
|
|
41
|
+
* so we don't need to store raw data.
|
|
42
|
+
*
|
|
43
|
+
* This value is resolved externally based on table configuration.
|
|
44
|
+
*
|
|
45
|
+
* Defaults to true for tests (conservative approach).
|
|
46
|
+
*/
|
|
47
|
+
storeCurrentData = true;
|
|
30
48
|
/**
|
|
31
49
|
* Always undefined if snapshotComplete = true.
|
|
32
50
|
*
|
|
@@ -41,27 +59,33 @@ export class SourceTable {
|
|
|
41
59
|
get id() {
|
|
42
60
|
return this.options.id;
|
|
43
61
|
}
|
|
44
|
-
get connectionTag() {
|
|
45
|
-
return this.options.connectionTag;
|
|
46
|
-
}
|
|
47
62
|
get objectId() {
|
|
48
63
|
return this.options.objectId;
|
|
49
64
|
}
|
|
50
65
|
get schema() {
|
|
51
|
-
return this.options.schema;
|
|
66
|
+
return this.options.ref.schema;
|
|
52
67
|
}
|
|
53
68
|
get name() {
|
|
54
|
-
return this.options.name;
|
|
69
|
+
return this.options.ref.name;
|
|
70
|
+
}
|
|
71
|
+
get ref() {
|
|
72
|
+
return this.options.ref;
|
|
55
73
|
}
|
|
56
74
|
get replicaIdColumns() {
|
|
57
75
|
return this.options.replicaIdColumns;
|
|
58
76
|
}
|
|
77
|
+
get bucketDataSources() {
|
|
78
|
+
return this.options.bucketDataSources;
|
|
79
|
+
}
|
|
80
|
+
get parameterLookupSources() {
|
|
81
|
+
return this.options.parameterLookupSources;
|
|
82
|
+
}
|
|
59
83
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
84
|
+
* Sanitized name of the entity in the format of "{schema}.{entity name}".
|
|
85
|
+
* Suitable for safe use in Postgres queries.
|
|
62
86
|
*/
|
|
63
87
|
get qualifiedName() {
|
|
64
|
-
return
|
|
88
|
+
return util.qualifiedName(this.ref);
|
|
65
89
|
}
|
|
66
90
|
get syncAny() {
|
|
67
91
|
return this.syncData || this.syncParameters || this.syncEvent;
|
|
@@ -72,15 +96,17 @@ export class SourceTable {
|
|
|
72
96
|
clone() {
|
|
73
97
|
const copy = new SourceTable({
|
|
74
98
|
id: this.id,
|
|
75
|
-
|
|
99
|
+
ref: this.options.ref,
|
|
76
100
|
objectId: this.objectId,
|
|
77
|
-
schema: this.schema,
|
|
78
|
-
name: this.name,
|
|
79
101
|
replicaIdColumns: this.replicaIdColumns,
|
|
80
|
-
snapshotComplete: this.snapshotComplete
|
|
102
|
+
snapshotComplete: this.snapshotComplete,
|
|
103
|
+
bucketDataSources: this.bucketDataSources,
|
|
104
|
+
parameterLookupSources: this.parameterLookupSources
|
|
81
105
|
});
|
|
82
106
|
copy.syncData = this.syncData;
|
|
83
107
|
copy.syncParameters = this.syncParameters;
|
|
108
|
+
copy.syncEvent = this.syncEvent;
|
|
109
|
+
copy.storeCurrentData = this.storeCurrentData;
|
|
84
110
|
copy.snapshotStatus = this.snapshotStatus;
|
|
85
111
|
return copy;
|
|
86
112
|
}
|
|
@@ -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,EAEL,WAAW,EAGZ,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAwB9C;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IAoDM;IAnD5B,MAAM,CAAU,WAAW,GAAG,WAAW,CAAC;IAE1C;;;;;;OAMG;IACI,QAAQ,GAAG,IAAI,CAAC;IAEvB;;;;;;OAMG;IACI,cAAc,GAAG,IAAI,CAAC;IAE7B;;;;;;OAMG;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,CAAC,gBAAgB,CAAC;IACnD,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,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,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC;QAC9C,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sBAAsB;QACpB,IAAI,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,EAAE,CAAC;YACzD,oBAAoB;YACpB,OAAO,GAAG,CAAC;QACb,CAAC;aAAM,IAAI,IAAI,CAAC,cAAc,CAAC,mBAAmB,GAAG,CAAC,EAAE,CAAC;YACvD,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,IAAI,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,KAAK,IAAI,CAAC,cAAc,CAAC,mBAAmB,EAAE,CAAC;QAC9F,CAAC;IACH,CAAC"}
|
|
@@ -38,7 +38,7 @@ export declare const STORAGE_VERSION_3 = 3;
|
|
|
38
38
|
*/
|
|
39
39
|
export declare const LEGACY_STORAGE_VERSION = 1;
|
|
40
40
|
/**
|
|
41
|
-
* Default storage version for newly persisted
|
|
41
|
+
* Default storage version for newly persisted replication streams.
|
|
42
42
|
*/
|
|
43
43
|
export declare const CURRENT_STORAGE_VERSION = 2;
|
|
44
44
|
/**
|
|
@@ -21,7 +21,7 @@ export const STORAGE_VERSION_3 = 3;
|
|
|
21
21
|
*/
|
|
22
22
|
export const LEGACY_STORAGE_VERSION = STORAGE_VERSION_1;
|
|
23
23
|
/**
|
|
24
|
-
* Default storage version for newly persisted
|
|
24
|
+
* Default storage version for newly persisted replication streams.
|
|
25
25
|
*/
|
|
26
26
|
export const CURRENT_STORAGE_VERSION = STORAGE_VERSION_2;
|
|
27
27
|
/**
|