import { HasInfrastructure , ProviderLibrary , RocketDescriptor , UserApp } from '@boostercloud/framework-types' ; import { rawEventsToEnvelopes , readEntityEventsSince , readEntityLatestSnapshot , storeEvents , } from './library/events-adapter' ; import { requestSucceeded , requestFailed } from './library/api-adapter' ; import { EventRegistry } from './services' ; import { rawGraphQLRequestToEnvelope } from './library/graphql-adapter' ; import * as path from 'path' ; import { ReadModelRegistry } from './services' ; import { fetchReadModel , rawReadModelEventsToEnvelopes , searchReadModel , storeReadModel , } from './library/read-model-adapter' ; export * from './paths' ; export * from './services' ; const eventRegistry = new EventRegistry ( ) ; const readModelRegistry = new ReadModelRegistry ( ) ; const userApp = require ( path . join ( process . cwd ( ) , 'dist' , 'index.js' ) ) ; export function loadInfrastructurePackage ( packageName ) { return require ( packageName ) ; } export const Provider = ( rocketDescriptors ? ) : ProviderLibrary => ( { events : { rawToEnvelopes : rawEventsToEnvelopes , forEntitySince : readEntityEventsSince . bind ( null , eventRegistry ) , latestEntitySnapshot : readEntityLatestSnapshot . bind ( null , eventRegistry ) , store : storeEvents . bind ( null , userApp , eventRegistry ) , search : undefined as any , } , readModels : { rawToEnvelopes : rawReadModelEventsToEnvelopes , fetch : fetchReadModel . bind ( null , readModelRegistry ) , search : searchReadModel . bind ( null , readModelRegistry ) , store : storeReadModel . bind ( null , readModelRegistry ) , delete : undefined as any , subscribe : undefined as any , fetchSubscriptions : undefined as any , deleteSubscription : undefined as any , deleteAllSubscriptions : undefined as any , } , graphQL : { rawToEnvelope : rawGraphQLRequestToEnvelope , handleResult : requestSucceeded , } , api : { requestSucceeded , requestFailed , } , connections : { storeData : notImplemented as any , fetchData : notImplemented as any , deleteData : notImplemented as any , sendMessage : notImplemented as any , } , scheduled : { rawToEnvelope : undefined as any , } , infrastructure : ( ) => { const infrastructurePackageName = require ( '../package.json' ) . name + '-infrastructure' ; let infrastructure ; try { infrastructure = loadInfrastructurePackage ( infrastructurePackageName ) ; } catch ( e ) { throw new Error ( `The Local infrastructure package could not be loaded. The following error was thrown: ${ e . message }. Please ensure that one of the following actions has been done:\n` + `  - It has been specified in your "devDependencies" section of your "package.json" file. You can do so by running 'npm install --save-dev ${ infrastructurePackageName }'\n` + `  - Or it has been installed globally. You can do so by running 'npm install -g ${ infrastructurePackageName }'` ) ; } return infrastructure . Infrastructure ( rocketDescriptors ) ; } , } ) ; function notImplemented ( ) { }