@@ -34,6 +34,7 @@ import { Hook } from './api/integrations/Hook';
3434import { BigSegmentStoreMembership } from './api/interfaces' ;
3535import { LDWaitForInitializationOptions } from './api/LDWaitForInitializationOptions' ;
3636import {
37+ isCustomOptions ,
3738 isPollingOnlyOptions ,
3839 isStandardOptions ,
3940 isStreamingOnlyOptions ,
@@ -65,9 +66,10 @@ import FlagsStateBuilder from './FlagsStateBuilder';
6566import HookRunner from './hooks/HookRunner' ;
6667import MigrationOpEventToInputEvent from './MigrationOpEventConversion' ;
6768import MigrationOpTracker from './MigrationOpTracker' ;
68- import Configuration , { DEFAULT_POLL_INTERVAL } from './options/Configuration' ;
69+ import Configuration , { DEFAULT_POLL_INTERVAL , DEFAULT_STREAM_RECONNECT_DELAY } from './options/Configuration' ;
6970import { ServerInternalOptions } from './options/ServerInternalOptions' ;
7071import VersionedDataKinds from './store/VersionedDataKinds' ;
72+ import FileDataInitializerFDv2 from './data_sources/fileDataInitilizerFDv2' ;
7173
7274const { ClientMessages, ErrorKinds, NullEventProcessor } = internal ;
7375enum InitState {
@@ -323,60 +325,96 @@ function constructFDv2(
323325 if ( ! ( config . offline || config . dataSystem ! . useLdd ) ) {
324326 // make the FDv2 composite datasource with initializers/synchronizers
325327 const initializers : subsystem . LDDataSourceFactory [ ] = [ ] ;
328+ const synchronizers : subsystem . LDDataSourceFactory [ ] = [ ] ;
329+ const fdv1FallbackSynchronizers : subsystem . LDDataSourceFactory [ ] = [ ] ;
330+
331+ if ( isCustomOptions ( dataSystem . dataSource ) ) {
332+ const {
333+ initializers : initializerConfigs = [ ] ,
334+ synchronizers : synchronizerConfigs = [ ] ,
335+ } = dataSystem . dataSource ;
336+
337+ initializerConfigs . forEach ( ( initializerConfig ) => {
338+ switch ( initializerConfig . type ) {
339+ case 'file' :
340+ initializers . push ( ( ) => new FileDataInitializerFDv2 ( initializerConfig , platform , config . logger ) ) ;
341+ break ;
342+ case 'polling' :
343+ const { pollInterval = DEFAULT_POLL_INTERVAL } = initializerConfig ;
344+ initializers . push ( ( ) => new PollingProcessorFDv2 ( new Requestor ( config , platform . requests , baseHeaders , '/sdk/poll' , config . logger ) , pollInterval , config . logger ) ) ;
345+ break ;
346+ default :
347+ throw new Error ( 'Unsupported initializer type' ) ;
348+ }
349+ } ) ;
350+ synchronizerConfigs . forEach ( ( synchronizerConfig ) => {
351+ switch ( synchronizerConfig . type ) {
352+ case 'streaming' :
353+ const { streamInitialReconnectDelay = DEFAULT_STREAM_RECONNECT_DELAY } = synchronizerConfig ;
354+ synchronizers . push ( ( ) => new StreamingProcessorFDv2 ( clientContext , '/sdk/stream' , [ ] , baseHeaders , diagnosticsManager , streamInitialReconnectDelay ) ) ;
355+ break ;
356+ case 'polling' :
357+ const { pollInterval = DEFAULT_POLL_INTERVAL } = synchronizerConfig ;
358+ synchronizers . push ( ( ) => new PollingProcessorFDv2 ( new Requestor ( config , platform . requests , baseHeaders , '/sdk/poll' , config . logger ) , pollInterval , config . logger ) ) ;
359+ break ;
360+ default :
361+ throw new Error ( 'Unsupported synchronizer type' ) ;
362+ }
363+ } ) ;
364+ } else {
365+ // use one shot initializer for performance and cost if we can do a combination of polling and streaming
366+ if ( isStandardOptions ( dataSystem . dataSource ) ) {
367+ initializers . push (
368+ ( ) =>
369+ new OneShotInitializerFDv2 (
370+ new Requestor ( config , platform . requests , baseHeaders , '/sdk/poll' , config . logger ) ,
371+ config . logger ,
372+ ) ,
373+ ) ;
374+ }
326375
327- // use one shot initializer for performance and cost if we can do a combination of polling and streaming
328- if ( isStandardOptions ( dataSystem . dataSource ) ) {
329- initializers . push (
330- ( ) =>
331- new OneShotInitializerFDv2 (
332- new Requestor ( config , platform . requests , baseHeaders , '/sdk/poll' , config . logger ) ,
333- config . logger ,
334- ) ,
335- ) ;
336- }
376+ // if streaming is configured, add streaming synchronizer
377+ if ( isStandardOptions ( dataSystem . dataSource ) || isStreamingOnlyOptions ( dataSystem . dataSource ) ) {
378+ const reconnectDelay = dataSystem . dataSource . streamInitialReconnectDelay ;
379+ synchronizers . push (
380+ ( ) =>
381+ new StreamingProcessorFDv2 (
382+ clientContext ,
383+ '/sdk/stream' ,
384+ [ ] ,
385+ baseHeaders ,
386+ diagnosticsManager ,
387+ reconnectDelay ,
388+ ) ,
389+ ) ;
390+ }
337391
338- const synchronizers : subsystem . LDDataSourceFactory [ ] = [ ] ;
339- // if streaming is configured, add streaming synchronizer
340- if ( isStandardOptions ( dataSystem . dataSource ) || isStreamingOnlyOptions ( dataSystem . dataSource ) ) {
341- const reconnectDelay = dataSystem . dataSource . streamInitialReconnectDelay ;
342- synchronizers . push (
343- ( ) =>
344- new StreamingProcessorFDv2 (
345- clientContext ,
346- '/sdk/stream' ,
347- [ ] ,
348- baseHeaders ,
349- diagnosticsManager ,
350- reconnectDelay ,
351- ) ,
352- ) ;
353- }
392+ let pollingInterval = DEFAULT_POLL_INTERVAL ;
393+ // if polling is configured, add polling synchronizer
394+ if ( isStandardOptions ( dataSystem . dataSource ) || isPollingOnlyOptions ( dataSystem . dataSource ) ) {
395+ pollingInterval = dataSystem . dataSource . pollInterval ?? DEFAULT_POLL_INTERVAL ;
396+ synchronizers . push (
397+ ( ) =>
398+ new PollingProcessorFDv2 (
399+ new Requestor ( config , platform . requests , baseHeaders , '/sdk/poll' , logger ) ,
400+ pollingInterval ,
401+ logger ,
402+ ) ,
403+ ) ;
404+ }
354405
355- let pollingInterval = DEFAULT_POLL_INTERVAL ;
356- // if polling is configured, add polling synchronizer
357- if ( isStandardOptions ( dataSystem . dataSource ) || isPollingOnlyOptions ( dataSystem . dataSource ) ) {
358- pollingInterval = dataSystem . dataSource . pollInterval ?? DEFAULT_POLL_INTERVAL ;
359- synchronizers . push (
406+ // This is short term handling and will be removed once FDv2 adoption is sufficient.
407+ fdv1FallbackSynchronizers . push (
360408 ( ) =>
361409 new PollingProcessorFDv2 (
362- new Requestor ( config , platform . requests , baseHeaders , '/sdk/poll ' , logger ) ,
410+ new Requestor ( config , platform . requests , baseHeaders , '/sdk/latest-all ' , config . logger ) ,
363411 pollingInterval ,
364- logger ,
412+ config . logger ,
413+ true ,
365414 ) ,
366- ) ;
415+ ) ;
367416 }
368417
369- // This is short term handling and will be removed once FDv2 adoption is sufficient.
370- const fdv1FallbackSynchronizers = [
371- ( ) =>
372- new PollingProcessorFDv2 (
373- new Requestor ( config , platform . requests , baseHeaders , '/sdk/latest-all' , config . logger ) ,
374- pollingInterval ,
375- config . logger ,
376- true ,
377- ) ,
378- ] ;
379-
380418 dataSource = new CompositeDataSource (
381419 initializers ,
382420 synchronizers ,
0 commit comments