11import { isScalar , LineCounter , parseDocument , Scalar , YAMLMap , YAMLSeq } from 'yaml' ;
22import { isValidPriority } from './BucketDescription.js' ;
33import { BucketParameterQuerier , mergeBucketParameterQueriers , QuerierError } from './BucketParameterQuerier.js' ;
4+ import { BucketDataSource , BucketParameterSource } from './BucketSource.js' ;
5+ import { CompatibilityContext , CompatibilityEdition , CompatibilityOption } from './compatibility.js' ;
46import { SqlRuleError , SyncRulesErrors , YamlError } from './errors.js' ;
57import { SqlEventDescriptor } from './events/SqlEventDescriptor.js' ;
68import { validateSyncRulesSchema } from './json_schema.js' ;
79import { SourceTableInterface } from './SourceTableInterface.js' ;
810import { QueryParseResult , SqlBucketDescriptor } from './SqlBucketDescriptor.js' ;
11+ import { syncStreamFromSql } from './streams/from_sql.js' ;
912import { TablePattern } from './TablePattern.js' ;
1013import {
1114 BucketIdTransformer ,
@@ -28,9 +31,6 @@ import {
2831 StreamParseOptions ,
2932 SyncRules
3033} from './types.js' ;
31- import { BucketSource } from './BucketSource.js' ;
32- import { syncStreamFromSql } from './streams/from_sql.js' ;
33- import { CompatibilityContext , CompatibilityEdition , CompatibilityOption } from './compatibility.js' ;
3434import { applyRowContext } from './utils.js' ;
3535
3636const ACCEPT_POTENTIALLY_DANGEROUS_QUERIES = Symbol ( 'ACCEPT_POTENTIALLY_DANGEROUS_QUERIES' ) ;
@@ -94,7 +94,9 @@ export interface GetBucketParameterQuerierResult {
9494}
9595
9696export class SqlSyncRules implements SyncRules {
97- bucketSources : BucketSource [ ] = [ ] ;
97+ bucketDataSources : BucketDataSource [ ] = [ ] ;
98+ bucketParameterSources : BucketParameterSource [ ] = [ ] ;
99+
98100 eventDescriptors : SqlEventDescriptor [ ] = [ ] ;
99101 compatibility : CompatibilityContext = CompatibilityContext . FULL_BACKWARDS_COMPATIBILITY ;
100102
@@ -245,7 +247,8 @@ export class SqlSyncRules implements SyncRules {
245247 return descriptor . addDataQuery ( q , queryOptions , compatibility ) ;
246248 } ) ;
247249 }
248- rules . bucketSources . push ( descriptor ) ;
250+ rules . bucketDataSources . push ( descriptor ) ;
251+ rules . bucketParameterSources . push ( descriptor ) ;
249252 }
250253
251254 for ( const entry of streamMap ?. items ?? [ ] ) {
@@ -270,7 +273,8 @@ export class SqlSyncRules implements SyncRules {
270273 if ( data instanceof Scalar ) {
271274 rules . withScalar ( data , ( q ) => {
272275 const [ parsed , errors ] = syncStreamFromSql ( key , q , queryOptions ) ;
273- rules . bucketSources . push ( parsed ) ;
276+ rules . bucketDataSources . push ( parsed ) ;
277+ rules . bucketParameterSources . push ( parsed ) ;
274278 return {
275279 parsed : true ,
276280 errors
@@ -412,7 +416,7 @@ export class SqlSyncRules implements SyncRules {
412416 } ;
413417
414418 let rawResults : EvaluationResult [ ] = [ ] ;
415- for ( let source of this . bucketSources ) {
419+ for ( let source of this . bucketDataSources ) {
416420 rawResults . push ( ...source . evaluateRow ( resolvedOptions ) ) ;
417421 }
418422
@@ -438,7 +442,7 @@ export class SqlSyncRules implements SyncRules {
438442 row : SqliteRow
439443 ) : { results : EvaluatedParameters [ ] ; errors : EvaluationError [ ] } {
440444 let rawResults : EvaluatedParametersResult [ ] = [ ] ;
441- for ( let source of this . bucketSources ) {
445+ for ( let source of this . bucketParameterSources ) {
442446 rawResults . push ( ...source . evaluateParameterRow ( table , row ) ) ;
443447 }
444448
@@ -460,7 +464,7 @@ export class SqlSyncRules implements SyncRules {
460464 const errors : QuerierError [ ] = [ ] ;
461465 const pending = { queriers, errors } ;
462466
463- for ( const source of this . bucketSources ) {
467+ for ( const source of this . bucketParameterSources ) {
464468 if (
465469 ( source . subscribedToByDefault && resolvedOptions . hasDefaultStreams ) ||
466470 source . name in resolvedOptions . streams
@@ -474,12 +478,18 @@ export class SqlSyncRules implements SyncRules {
474478 }
475479
476480 hasDynamicBucketQueries ( ) {
477- return this . bucketSources . some ( ( s ) => s . hasDynamicBucketQueries ( ) ) ;
481+ return this . bucketParameterSources . some ( ( s ) => s . hasDynamicBucketQueries ( ) ) ;
478482 }
479483
480484 getSourceTables ( ) : TablePattern [ ] {
481485 const sourceTables = new Map < String , TablePattern > ( ) ;
482- for ( const bucket of this . bucketSources ) {
486+ for ( const bucket of this . bucketDataSources ) {
487+ for ( const r of bucket . getSourceTables ( ) ) {
488+ const key = `${ r . connectionTag } .${ r . schema } .${ r . tablePattern } ` ;
489+ sourceTables . set ( key , r ) ;
490+ }
491+ }
492+ for ( const bucket of this . bucketParameterSources ) {
483493 for ( const r of bucket . getSourceTables ( ) ) {
484494 const key = `${ r . connectionTag } .${ r . schema } .${ r . tablePattern } ` ;
485495 sourceTables . set ( key , r ) ;
@@ -513,16 +523,19 @@ export class SqlSyncRules implements SyncRules {
513523 }
514524
515525 tableSyncsData ( table : SourceTableInterface ) : boolean {
516- return this . bucketSources . some ( ( b ) => b . tableSyncsData ( table ) ) ;
526+ return this . bucketDataSources . some ( ( b ) => b . tableSyncsData ( table ) ) ;
517527 }
518528
519529 tableSyncsParameters ( table : SourceTableInterface ) : boolean {
520- return this . bucketSources . some ( ( b ) => b . tableSyncsParameters ( table ) ) ;
530+ return this . bucketParameterSources . some ( ( b ) => b . tableSyncsParameters ( table ) ) ;
521531 }
522532
523533 debugGetOutputTables ( ) {
524534 let result : Record < string , any [ ] > = { } ;
525- for ( let bucket of this . bucketSources ) {
535+ for ( let bucket of this . bucketDataSources ) {
536+ bucket . debugWriteOutputTables ( result ) ;
537+ }
538+ for ( let bucket of this . bucketParameterSources ) {
526539 bucket . debugWriteOutputTables ( result ) ;
527540 }
528541 return result ;
0 commit comments