@@ -5,19 +5,20 @@ import {
55 BucketDataSourceDefinition ,
66 BucketParameterLookupSourceDefinition ,
77 BucketParameterQuerierSourceDefinition ,
8- BucketSource
8+ BucketSource ,
9+ CreateSourceParams
910} from './BucketSource.js' ;
1011import { CompatibilityContext , CompatibilityEdition , CompatibilityOption } from './compatibility.js' ;
1112import { SqlRuleError , SyncRulesErrors , YamlError } from './errors.js' ;
1213import { SqlEventDescriptor } from './events/SqlEventDescriptor.js' ;
14+ import { DEFAULT_HYDRATION_STATE } from './HydrationState.js' ;
1315import { validateSyncRulesSchema } from './json_schema.js' ;
1416import { SourceTableInterface } from './SourceTableInterface.js' ;
1517import { QueryParseResult , SqlBucketDescriptor } from './SqlBucketDescriptor.js' ;
1618import { syncStreamFromSql } from './streams/from_sql.js' ;
1719import { HydratedSyncRules } from './SyncRules.js' ;
1820import { TablePattern } from './TablePattern.js' ;
1921import {
20- BucketIdTransformer ,
2122 QueryParseOptions ,
2223 RequestParameters ,
2324 SourceSchema ,
@@ -388,21 +389,20 @@ export class SqlSyncRules {
388389 /**
389390 * Hydrate the sync rule definitions with persisted state into runnable sync rules.
390391 *
391- * Right now this is just the bucketIdTransformer, but this is expected to expand in the future to support
392- * incremental sync rule reprocessing.
393- *
394- * @param params.bucketIdTransformer A function that transforms bucket ids based on persisted state. May omit for tests.
392+ * @param params.hydrationState Transforms bucket ids based on persisted state. May omit for tests.
395393 */
396- hydrate ( params ?: { bucketIdTransformer ?: BucketIdTransformer } ) : HydratedSyncRules {
397- const bucketIdTransformer = this . compatibility . isEnabled ( CompatibilityOption . versionedBucketIds )
398- ? ( params ?. bucketIdTransformer ?? ( ( id : string ) => id ) )
399- : ( id : string ) => id ;
394+ hydrate ( params ?: CreateSourceParams ) : HydratedSyncRules {
395+ let hydrationState = params ?. hydrationState ;
396+ if ( hydrationState == null || ! this . compatibility . isEnabled ( CompatibilityOption . versionedBucketIds ) ) {
397+ hydrationState = DEFAULT_HYDRATION_STATE ;
398+ }
399+ const resolvedParams = { hydrationState } ;
400400 return new HydratedSyncRules ( {
401401 definition : this ,
402- createParams : { bucketIdTransformer } ,
403- bucketDataSources : this . bucketDataSources . map ( ( d ) => d . createDataSource ( { bucketIdTransformer } ) ) ,
402+ createParams : resolvedParams ,
403+ bucketDataSources : this . bucketDataSources . map ( ( d ) => d . createDataSource ( resolvedParams ) ) ,
404404 bucketParameterLookupSources : this . bucketParameterLookupSources . map ( ( d ) =>
405- d . createParameterLookupSource ( { bucketIdTransformer } )
405+ d . createParameterLookupSource ( resolvedParams )
406406 ) ,
407407 eventDescriptors : this . eventDescriptors ,
408408 compatibility : this . compatibility
@@ -488,8 +488,4 @@ export class SqlSyncRules {
488488 }
489489 }
490490 }
491-
492- static versionedBucketIdTransformer ( version : string ) {
493- return ( bucketId : string ) => `${ version } #${ bucketId } ` ;
494- }
495491}
0 commit comments