diff --git a/.changeset/slow-stingrays-kiss.md b/.changeset/slow-stingrays-kiss.md new file mode 100644 index 00000000..a93126de --- /dev/null +++ b/.changeset/slow-stingrays-kiss.md @@ -0,0 +1,5 @@ +--- +'@powersync/service-core': minor +--- + +Moved Write Checkpoint APIs to SyncBucketStorage diff --git a/packages/service-core/src/routes/endpoints/checkpointing.ts b/packages/service-core/src/routes/endpoints/checkpointing.ts index 0cfd2dc1..3ce913ad 100644 --- a/packages/service-core/src/routes/endpoints/checkpointing.ts +++ b/packages/service-core/src/routes/endpoints/checkpointing.ts @@ -1,6 +1,7 @@ import { logger, router, schema } from '@powersync/lib-services-framework'; import * as t from 'ts-codec'; +import * as framework from '@powersync/lib-services-framework'; import * as util from '../../util/util-index.js'; import { authUser } from '../auth.js'; import { routeDefinition } from '../router.js'; @@ -63,7 +64,13 @@ export const writeCheckpoint2 = routeDefinition({ storageEngine: { activeBucketStorage } } = service_context; - const writeCheckpoint = await activeBucketStorage.createManagedWriteCheckpoint({ + const activeSyncRules = await activeBucketStorage.getActiveSyncRulesContent(); + if (!activeSyncRules) { + throw new framework.errors.ValidationError(`Cannot create Write Checkpoint since no sync rules are active.`); + } + + using syncBucketStorage = activeBucketStorage.getInstance(activeSyncRules); + const writeCheckpoint = await syncBucketStorage.createManagedWriteCheckpoint({ user_id: full_user_id, heads: { '1': currentCheckpoint } }); diff --git a/packages/service-core/src/storage/BucketStorage.ts b/packages/service-core/src/storage/BucketStorage.ts index 84165fb7..446362a5 100644 --- a/packages/service-core/src/storage/BucketStorage.ts +++ b/packages/service-core/src/storage/BucketStorage.ts @@ -12,16 +12,15 @@ import * as util from '../util/util-index.js'; import { ReplicationEventPayload } from './ReplicationEventPayload.js'; import { SourceEntityDescriptor } from './SourceEntity.js'; import { SourceTable } from './SourceTable.js'; -import { BatchedCustomWriteCheckpointOptions, ReplicaId, WriteCheckpointAPI } from './storage-index.js'; +import { BatchedCustomWriteCheckpointOptions, ReplicaId } from './storage-index.js'; +import { SyncStorageWriteCheckpointAPI } from './WriteCheckpointAPI.js'; export interface BucketStorageFactoryListener extends DisposableListener { syncStorageCreated: (storage: SyncRulesBucketStorage) => void; replicationEvent: (event: ReplicationEventPayload) => void; } -export interface BucketStorageFactory - extends DisposableObserverClient, - WriteCheckpointAPI { +export interface BucketStorageFactory extends DisposableObserverClient { /** * Update sync rules from configuration, if changed. */ @@ -206,7 +205,9 @@ export interface SyncRulesBucketStorageListener extends DisposableListener { batchStarted: (batch: BucketStorageBatch) => void; } -export interface SyncRulesBucketStorage extends DisposableObserverClient { +export interface SyncRulesBucketStorage + extends DisposableObserverClient, + SyncStorageWriteCheckpointAPI { readonly group_id: number; readonly slot_name: string; diff --git a/packages/service-core/src/storage/MongoBucketStorage.ts b/packages/service-core/src/storage/MongoBucketStorage.ts index 9da62758..f3175b91 100644 --- a/packages/service-core/src/storage/MongoBucketStorage.ts +++ b/packages/service-core/src/storage/MongoBucketStorage.ts @@ -25,16 +25,7 @@ import { PowerSyncMongo, PowerSyncMongoOptions } from './mongo/db.js'; import { SyncRuleDocument, SyncRuleState } from './mongo/models.js'; import { MongoPersistedSyncRulesContent } from './mongo/MongoPersistedSyncRulesContent.js'; import { MongoSyncBucketStorage } from './mongo/MongoSyncBucketStorage.js'; -import { MongoWriteCheckpointAPI } from './mongo/MongoWriteCheckpointAPI.js'; import { generateSlotName } from './mongo/util.js'; -import { - CustomWriteCheckpointOptions, - DEFAULT_WRITE_CHECKPOINT_MODE, - LastWriteCheckpointFilters, - ManagedWriteCheckpointOptions, - WriteCheckpointAPI, - WriteCheckpointMode -} from './write-checkpoint.js'; export interface MongoBucketStorageOptions extends PowerSyncMongoOptions {} @@ -47,10 +38,6 @@ export class MongoBucketStorage // TODO: This is still Postgres specific and needs to be reworked public readonly slot_name_prefix: string; - readonly write_checkpoint_mode: WriteCheckpointMode; - - protected readonly writeCheckpointAPI: WriteCheckpointAPI; - private readonly storageCache = new LRUCache({ max: 3, fetchMethod: async (id) => { @@ -78,7 +65,6 @@ export class MongoBucketStorage db: PowerSyncMongo, options: { slot_name_prefix: string; - write_checkpoint_mode?: WriteCheckpointMode; } ) { super(); @@ -86,11 +72,6 @@ export class MongoBucketStorage this.db = db; this.session = this.client.startSession(); this.slot_name_prefix = options.slot_name_prefix; - this.write_checkpoint_mode = options.write_checkpoint_mode ?? DEFAULT_WRITE_CHECKPOINT_MODE; - this.writeCheckpointAPI = new MongoWriteCheckpointAPI({ - db, - mode: this.write_checkpoint_mode - }); } getInstance(options: PersistedSyncRulesContent): MongoSyncBucketStorage { @@ -299,22 +280,6 @@ export class MongoBucketStorage }); } - async batchCreateCustomWriteCheckpoints(checkpoints: CustomWriteCheckpointOptions[]): Promise { - return this.writeCheckpointAPI.batchCreateCustomWriteCheckpoints(checkpoints); - } - - async createCustomWriteCheckpoint(options: CustomWriteCheckpointOptions): Promise { - return this.writeCheckpointAPI.createCustomWriteCheckpoint(options); - } - - async createManagedWriteCheckpoint(options: ManagedWriteCheckpointOptions): Promise { - return this.writeCheckpointAPI.createManagedWriteCheckpoint(options); - } - - async lastWriteCheckpoint(filters: LastWriteCheckpointFilters): Promise { - return this.writeCheckpointAPI.lastWriteCheckpoint(filters); - } - async getActiveCheckpoint(): Promise { const doc = await this.db.sync_rules.findOne( { @@ -426,7 +391,7 @@ export class MongoBucketStorage } return (await this.storageCache.fetch(doc._id)) ?? null; } - }; + } satisfies ActiveCheckpoint; } /** @@ -516,6 +481,7 @@ export class MongoBucketStorage if (doc == null) { continue; } + const op = this.makeActiveCheckpoint(doc); // Check for LSN / checkpoint changes - ignore other metadata changes if (lastOp == null || op.lsn != lastOp.lsn || op.checkpoint != lastOp.checkpoint) { @@ -546,12 +512,14 @@ export class MongoBucketStorage // 1. checkpoint (op_id) changes. // 2. write checkpoint changes for the specific user const bucketStorage = await cp.getBucketStorage(); + if (!bucketStorage) { + continue; + } const lsnFilters: Record = lsn ? { 1: lsn } : {}; - const currentWriteCheckpoint = await this.lastWriteCheckpoint({ + const currentWriteCheckpoint = await bucketStorage.lastWriteCheckpoint({ user_id, - sync_rules_id: bucketStorage?.group_id, heads: { ...lsnFilters } diff --git a/packages/service-core/src/storage/StorageEngine.ts b/packages/service-core/src/storage/StorageEngine.ts index bdafeb24..a6639211 100644 --- a/packages/service-core/src/storage/StorageEngine.ts +++ b/packages/service-core/src/storage/StorageEngine.ts @@ -1,17 +1,12 @@ import { DisposableListener, DisposableObserver, logger } from '@powersync/lib-services-framework'; import { ResolvedPowerSyncConfig } from '../util/util-index.js'; import { BucketStorageFactory } from './BucketStorage.js'; -import { ActiveStorage, BucketStorageProvider, StorageSettings } from './StorageProvider.js'; -import { DEFAULT_WRITE_CHECKPOINT_MODE } from './write-checkpoint.js'; +import { ActiveStorage, BucketStorageProvider } from './StorageProvider.js'; export type StorageEngineOptions = { configuration: ResolvedPowerSyncConfig; }; -export const DEFAULT_STORAGE_SETTINGS: StorageSettings = { - writeCheckpointMode: DEFAULT_WRITE_CHECKPOINT_MODE -}; - export interface StorageEngineListener extends DisposableListener { storageActivated: (storage: BucketStorageFactory) => void; } @@ -20,11 +15,9 @@ export class StorageEngine extends DisposableObserver { // TODO: This will need to revisited when we actually support multiple storage providers. private storageProviders: Map = new Map(); private currentActiveStorage: ActiveStorage | null = null; - private _activeSettings: StorageSettings; constructor(private options: StorageEngineOptions) { super(); - this._activeSettings = DEFAULT_STORAGE_SETTINGS; } get activeBucketStorage(): BucketStorageFactory { @@ -39,20 +32,6 @@ export class StorageEngine extends DisposableObserver { return this.currentActiveStorage; } - get activeSettings(): StorageSettings { - return { ...this._activeSettings }; - } - - updateSettings(settings: Partial) { - if (this.currentActiveStorage) { - throw new Error(`Storage is already active, settings cannot be modified.`); - } - this._activeSettings = { - ...this._activeSettings, - ...settings - }; - } - /** * Register a provider which generates a {@link BucketStorageFactory} * given the matching config specified in the loaded {@link ResolvedPowerSyncConfig} @@ -65,8 +44,7 @@ export class StorageEngine extends DisposableObserver { logger.info('Starting Storage Engine...'); const { configuration } = this.options; this.currentActiveStorage = await this.storageProviders.get(configuration.storage.type)!.getStorage({ - resolvedConfig: configuration, - ...this.activeSettings + resolvedConfig: configuration }); this.iterateListeners((cb) => cb.storageActivated?.(this.activeBucketStorage)); logger.info(`Successfully activated storage: ${configuration.storage.type}.`); diff --git a/packages/service-core/src/storage/StorageProvider.ts b/packages/service-core/src/storage/StorageProvider.ts index 7c730fb4..385a042f 100644 --- a/packages/service-core/src/storage/StorageProvider.ts +++ b/packages/service-core/src/storage/StorageProvider.ts @@ -1,6 +1,5 @@ import * as util from '../util/util-index.js'; import { BucketStorageFactory } from './BucketStorage.js'; -import { WriteCheckpointMode } from './write-checkpoint.js'; export interface ActiveStorage { storage: BucketStorageFactory; @@ -12,14 +11,7 @@ export interface ActiveStorage { tearDown(): Promise; } -/** - * Settings which can be modified by various modules in their initialization. - */ -export interface StorageSettings { - writeCheckpointMode: WriteCheckpointMode; -} - -export interface GetStorageOptions extends StorageSettings { +export interface GetStorageOptions { // TODO: This should just be the storage config. Update once the slot name prefix coupling has been removed from the storage resolvedConfig: util.ResolvedPowerSyncConfig; } diff --git a/packages/service-core/src/storage/write-checkpoint.ts b/packages/service-core/src/storage/WriteCheckpointAPI.ts similarity index 55% rename from packages/service-core/src/storage/write-checkpoint.ts rename to packages/service-core/src/storage/WriteCheckpointAPI.ts index 0b61fe0c..d38ac397 100644 --- a/packages/service-core/src/storage/write-checkpoint.ts +++ b/packages/service-core/src/storage/WriteCheckpointAPI.ts @@ -3,7 +3,7 @@ export enum WriteCheckpointMode { * Raw mappings of `user_id` to `write_checkpoint`s should * be supplied for each set of sync rules. */ - CUSTOM = 'manual', + CUSTOM = 'custom', /** * Write checkpoints are stored as a mapping of `user_id` plus * replication HEAD (lsn in Postgres) to an automatically generated @@ -26,19 +26,19 @@ export interface CustomWriteCheckpointFilters extends BaseWriteCheckpointIdentif sync_rules_id: number; } -export interface CustomWriteCheckpointOptions extends CustomWriteCheckpointFilters { +export interface BatchedCustomWriteCheckpointOptions extends BaseWriteCheckpointIdentifier { /** * A supplied incrementing Write Checkpoint number */ checkpoint: bigint; } -/** - * Options for creating a custom Write Checkpoint in a batch. - * A {@link BucketStorageBatch} is already associated with a Sync Rules instance. - * The `sync_rules_id` is not required here. - */ -export type BatchedCustomWriteCheckpointOptions = Omit; +export interface CustomWriteCheckpointOptions extends BatchedCustomWriteCheckpointOptions { + /** + * Sync rules which were active when this checkpoint was created. + */ + sync_rules_id: number; +} /** * Managed Write Checkpoints are a mapping of User ID to replication HEAD @@ -52,15 +52,33 @@ export interface ManagedWriteCheckpointFilters extends BaseWriteCheckpointIdenti export type ManagedWriteCheckpointOptions = ManagedWriteCheckpointFilters; +export type SyncStorageLastWriteCheckpointFilters = BaseWriteCheckpointIdentifier | ManagedWriteCheckpointFilters; export type LastWriteCheckpointFilters = CustomWriteCheckpointFilters | ManagedWriteCheckpointFilters; -export interface WriteCheckpointAPI { - batchCreateCustomWriteCheckpoints(checkpoints: CustomWriteCheckpointOptions[]): Promise; - - createCustomWriteCheckpoint(checkpoint: CustomWriteCheckpointOptions): Promise; - +export interface BaseWriteCheckpointAPI { + readonly writeCheckpointMode: WriteCheckpointMode; + setWriteCheckpointMode(mode: WriteCheckpointMode): void; createManagedWriteCheckpoint(checkpoint: ManagedWriteCheckpointOptions): Promise; +} + +/** + * Write Checkpoint API to be used in conjunction with a {@link SyncRulesBucketStorage}. + * This storage corresponds with a set of sync rules. These APIs don't require specifying a + * sync rules id. + */ +export interface SyncStorageWriteCheckpointAPI extends BaseWriteCheckpointAPI { + batchCreateCustomWriteCheckpoints(checkpoints: BatchedCustomWriteCheckpointOptions[]): Promise; + createCustomWriteCheckpoint(checkpoint: BatchedCustomWriteCheckpointOptions): Promise; + lastWriteCheckpoint(filters: SyncStorageLastWriteCheckpointFilters): Promise; +} +/** + * Write Checkpoint API which is interfaced directly with the storage layer. This requires + * sync rules identifiers for custom write checkpoints. + */ +export interface WriteCheckpointAPI extends BaseWriteCheckpointAPI { + batchCreateCustomWriteCheckpoints(checkpoints: CustomWriteCheckpointOptions[]): Promise; + createCustomWriteCheckpoint(checkpoint: CustomWriteCheckpointOptions): Promise; lastWriteCheckpoint(filters: LastWriteCheckpointFilters): Promise; } diff --git a/packages/service-core/src/storage/mongo/MongoBucketBatch.ts b/packages/service-core/src/storage/mongo/MongoBucketBatch.ts index f0f95cd4..c24a0499 100644 --- a/packages/service-core/src/storage/mongo/MongoBucketBatch.ts +++ b/packages/service-core/src/storage/mongo/MongoBucketBatch.ts @@ -12,7 +12,7 @@ import { SaveOptions } from '../BucketStorage.js'; import { SourceTable } from '../SourceTable.js'; -import { CustomWriteCheckpointOptions } from '../write-checkpoint.js'; +import { BatchedCustomWriteCheckpointOptions, CustomWriteCheckpointOptions } from '../WriteCheckpointAPI.js'; import { PowerSyncMongo } from './db.js'; import { CurrentBucket, CurrentDataDocument, SourceKey, SyncRuleDocument } from './models.js'; import { MongoIdSequence } from './MongoIdSequence.js'; @@ -83,7 +83,7 @@ export class MongoBucketBatch extends DisposableObserver client.close(), tearDown: () => { diff --git a/packages/service-core/src/storage/mongo/MongoSyncBucketStorage.ts b/packages/service-core/src/storage/mongo/MongoSyncBucketStorage.ts index e4b57788..9243c010 100644 --- a/packages/service-core/src/storage/mongo/MongoSyncBucketStorage.ts +++ b/packages/service-core/src/storage/mongo/MongoSyncBucketStorage.ts @@ -2,7 +2,8 @@ import { SqliteJsonRow, SqliteJsonValue, SqlSyncRules } from '@powersync/service import * as bson from 'bson'; import * as mongo from 'mongodb'; -import { DisposableObserver } from '@powersync/lib-services-framework'; +import { DisposableObserver, logger } from '@powersync/lib-services-framework'; +import * as timers from 'timers/promises'; import * as db from '../../db/db-index.js'; import * as util from '../../util/util-index.js'; import { @@ -26,13 +27,19 @@ import { import { ChecksumCache, FetchPartialBucketChecksum, PartialChecksum, PartialChecksumMap } from '../ChecksumCache.js'; import { MongoBucketStorage } from '../MongoBucketStorage.js'; import { SourceTable } from '../SourceTable.js'; +import { + BatchedCustomWriteCheckpointOptions, + ManagedWriteCheckpointOptions, + SyncStorageLastWriteCheckpointFilters, + WriteCheckpointAPI, + WriteCheckpointMode +} from '../WriteCheckpointAPI.js'; import { PowerSyncMongo } from './db.js'; import { BucketDataDocument, BucketDataKey, SourceKey, SyncRuleState } from './models.js'; import { MongoBucketBatch } from './MongoBucketBatch.js'; import { MongoCompactor } from './MongoCompactor.js'; +import { MongoWriteCheckpointAPI } from './MongoWriteCheckpointAPI.js'; import { BSON_DESERIALIZE_OPTIONS, idPrefixFilter, mapOpEntry, readSingleBatch, serializeLookup } from './util.js'; -import { logger } from '@powersync/lib-services-framework'; -import * as timers from 'timers/promises'; export class MongoSyncBucketStorage extends DisposableObserver @@ -46,15 +53,53 @@ export class MongoSyncBucketStorage }); private parsedSyncRulesCache: SqlSyncRules | undefined; + private writeCheckpointAPI: WriteCheckpointAPI; constructor( public readonly factory: MongoBucketStorage, public readonly group_id: number, private readonly sync_rules: PersistedSyncRulesContent, - public readonly slot_name: string + public readonly slot_name: string, + writeCheckpointMode: WriteCheckpointMode = WriteCheckpointMode.MANAGED ) { super(); this.db = factory.db; + this.writeCheckpointAPI = new MongoWriteCheckpointAPI({ + db: this.db, + mode: writeCheckpointMode + }); + } + + get writeCheckpointMode() { + return this.writeCheckpointAPI.writeCheckpointMode; + } + + setWriteCheckpointMode(mode: WriteCheckpointMode): void { + this.writeCheckpointAPI.setWriteCheckpointMode(mode); + } + + batchCreateCustomWriteCheckpoints(checkpoints: BatchedCustomWriteCheckpointOptions[]): Promise { + return this.writeCheckpointAPI.batchCreateCustomWriteCheckpoints( + checkpoints.map((checkpoint) => ({ ...checkpoint, sync_rules_id: this.group_id })) + ); + } + + createCustomWriteCheckpoint(checkpoint: BatchedCustomWriteCheckpointOptions): Promise { + return this.writeCheckpointAPI.createCustomWriteCheckpoint({ + ...checkpoint, + sync_rules_id: this.group_id + }); + } + + createManagedWriteCheckpoint(checkpoint: ManagedWriteCheckpointOptions): Promise { + return this.writeCheckpointAPI.createManagedWriteCheckpoint(checkpoint); + } + + lastWriteCheckpoint(filters: SyncStorageLastWriteCheckpointFilters): Promise { + return this.writeCheckpointAPI.lastWriteCheckpoint({ + ...filters, + sync_rules_id: this.group_id + }); } getParsedSyncRules(options: ParseSyncRulesOptions): SqlSyncRules { diff --git a/packages/service-core/src/storage/mongo/MongoWriteCheckpointAPI.ts b/packages/service-core/src/storage/mongo/MongoWriteCheckpointAPI.ts index 230db315..bbcebb0d 100644 --- a/packages/service-core/src/storage/mongo/MongoWriteCheckpointAPI.ts +++ b/packages/service-core/src/storage/mongo/MongoWriteCheckpointAPI.ts @@ -7,7 +7,7 @@ import { ManagedWriteCheckpointOptions, WriteCheckpointAPI, WriteCheckpointMode -} from '../write-checkpoint.js'; +} from '../WriteCheckpointAPI.js'; import { PowerSyncMongo } from './db.js'; export type MongoCheckpointAPIOptions = { @@ -17,11 +17,19 @@ export type MongoCheckpointAPIOptions = { export class MongoWriteCheckpointAPI implements WriteCheckpointAPI { readonly db: PowerSyncMongo; - readonly mode: WriteCheckpointMode; + private _mode: WriteCheckpointMode; constructor(options: MongoCheckpointAPIOptions) { this.db = options.db; - this.mode = options.mode; + this._mode = options.mode; + } + + get writeCheckpointMode() { + return this._mode; + } + + setWriteCheckpointMode(mode: WriteCheckpointMode): void { + this._mode = mode; } async batchCreateCustomWriteCheckpoints(checkpoints: CustomWriteCheckpointOptions[]): Promise { @@ -29,9 +37,9 @@ export class MongoWriteCheckpointAPI implements WriteCheckpointAPI { } async createCustomWriteCheckpoint(options: CustomWriteCheckpointOptions): Promise { - if (this.mode !== WriteCheckpointMode.CUSTOM) { + if (this.writeCheckpointMode !== WriteCheckpointMode.CUSTOM) { throw new framework.errors.ValidationError( - `Creating a custom Write Checkpoint when the current Write Checkpoint mode is set to "${this.mode}"` + `Creating a custom Write Checkpoint when the current Write Checkpoint mode is set to "${this.writeCheckpointMode}"` ); } @@ -52,9 +60,9 @@ export class MongoWriteCheckpointAPI implements WriteCheckpointAPI { } async createManagedWriteCheckpoint(checkpoint: ManagedWriteCheckpointOptions): Promise { - if (this.mode !== WriteCheckpointMode.MANAGED) { + if (this.writeCheckpointMode !== WriteCheckpointMode.MANAGED) { throw new framework.errors.ValidationError( - `Creating a managed Write Checkpoint when the current Write Checkpoint mode is set to "${this.mode}"` + `Attempting to create a managed Write Checkpoint when the current Write Checkpoint mode is set to "${this.writeCheckpointMode}"` ); } @@ -77,7 +85,7 @@ export class MongoWriteCheckpointAPI implements WriteCheckpointAPI { } async lastWriteCheckpoint(filters: LastWriteCheckpointFilters): Promise { - switch (this.mode) { + switch (this.writeCheckpointMode) { case WriteCheckpointMode.CUSTOM: if (false == 'sync_rules_id' in filters) { throw new framework.errors.ValidationError(`Sync rules ID is required for custom Write Checkpoint filtering`); diff --git a/packages/service-core/src/storage/storage-index.ts b/packages/service-core/src/storage/storage-index.ts index b5857663..231bb384 100644 --- a/packages/service-core/src/storage/storage-index.ts +++ b/packages/service-core/src/storage/storage-index.ts @@ -5,6 +5,7 @@ export * from './SourceEntity.js'; export * from './SourceTable.js'; export * from './StorageEngine.js'; +export * from './mongo/config.js'; export * from './mongo/db.js'; export * from './mongo/models.js'; export * from './mongo/MongoBucketBatch.js'; @@ -17,5 +18,4 @@ export * from './mongo/MongoSyncRulesLock.js'; export * from './mongo/OperationBatch.js'; export * from './mongo/PersistedBatch.js'; export * from './mongo/util.js'; -export * from './mongo/config.js'; -export * from './write-checkpoint.js'; +export * from './WriteCheckpointAPI.js'; diff --git a/packages/service-core/src/util/config/compound-config-collector.ts b/packages/service-core/src/util/config/compound-config-collector.ts index 78e8500c..7c2b70c8 100644 --- a/packages/service-core/src/util/config/compound-config-collector.ts +++ b/packages/service-core/src/util/config/compound-config-collector.ts @@ -122,7 +122,8 @@ export class CompoundConfigCollector { }, // TODO maybe move this out of the connection or something // slot_name_prefix: connections[0]?.slot_name_prefix ?? 'powersync_' - slot_name_prefix: 'powersync_' + slot_name_prefix: 'powersync_', + parameters: baseConfig.parameters ?? {} }; return config; diff --git a/packages/service-core/src/util/config/types.ts b/packages/service-core/src/util/config/types.ts index e5f461e4..99829526 100644 --- a/packages/service-core/src/util/config/types.ts +++ b/packages/service-core/src/util/config/types.ts @@ -64,4 +64,5 @@ export type ResolvedPowerSyncConfig = { /** Prefix for postgres replication slot names. May eventually be connection-specific. */ slot_name_prefix: string; + parameters: Record; }; diff --git a/packages/sync-rules/package.json b/packages/sync-rules/package.json index bb942b1e..727188bb 100644 --- a/packages/sync-rules/package.json +++ b/packages/sync-rules/package.json @@ -15,10 +15,9 @@ "type": "module", "scripts": { "clean": "rm -r ./dist && tsc -b --clean", - "build": "tsc -b", + "build:tsc": "tsc -b", + "build": "pnpm build:tsc && node scripts/compile-schema.js", "build:tests": "tsc -b test/tsconfig.json", - "compile:schema": "pnpm build && node scripts/compile-schema.js", - "postversion": "pnpm compile:schema", "test": "vitest" }, "dependencies": { diff --git a/packages/types/src/config/PowerSyncConfig.ts b/packages/types/src/config/PowerSyncConfig.ts index e9dff54f..dbd33e1a 100644 --- a/packages/types/src/config/PowerSyncConfig.ts +++ b/packages/types/src/config/PowerSyncConfig.ts @@ -135,7 +135,9 @@ export const powerSyncConfig = t.object({ disable_telemetry_sharing: t.boolean, internal_service_endpoint: t.string.optional() }) - .optional() + .optional(), + + parameters: t.record(t.number.or(t.string).or(t.boolean).or(t.Null)).optional() }); export type PowerSyncConfig = t.Decoded; diff --git a/service/Dockerfile b/service/Dockerfile index 715931b1..d6641555 100644 --- a/service/Dockerfile +++ b/service/Dockerfile @@ -29,6 +29,7 @@ COPY packages/jpgwire/src packages/jpgwire/src/ COPY packages/jpgwire/ca packages/jpgwire/ca/ COPY packages/jsonbig/src packages/jsonbig/src/ COPY packages/sync-rules/src packages/sync-rules/src/ +COPY packages/sync-rules/scripts packages/sync-rules/scripts/ COPY packages/rsocket-router/src packages/rsocket-router/src/ COPY packages/types/src packages/types/src/