import { HasInfrastructure , ProviderLibrary , RocketDescriptor } from '@boostercloud/framework-types' ; import { requestFailed , requestSucceeded } from './library/api-adapter' ; import { rawGraphQLRequestToEnvelope } from './library/graphql-adapter' ; import { rawEventsToEnvelopes , storeEvents , readEntityEventsSince , readEntityLatestSnapshot , } from './library/events-adapter' ; import { CosmosClient } from '@azure/cosmos' ; import { environmentVarNames } from './constants' ; import { deleteReadModel , fetchReadModel , storeReadModel } from './library/read-model-adapter' ; import { searchReadModel } from './library/searcher-adapter' ; import { rawScheduledInputToEnvelope } from './library/scheduled-adapter' ; let cosmosClient ; if ( typeof process . env [ environmentVarNames . cosmosDbConnectionString ] === 'undefined' ) { cosmosClient = { } as any ; } else { cosmosClient = new CosmosClient ( process . env [ environmentVarNames . cosmosDbConnectionString ] as string ) ; } export function loadInfrastructurePackage ( packageName ) { return require ( packageName ) ; } export const Provider = ( rockets ? ) : ProviderLibrary => ( { events : { rawToEnvelopes : rawEventsToEnvelopes , store : storeEvents . bind ( null , cosmosClient ) , forEntitySince : readEntityEventsSince . bind ( null , cosmosClient ) , latestEntitySnapshot : readEntityLatestSnapshot . bind ( null , cosmosClient ) , search : undefined as any , } , readModels : { fetch : fetchReadModel . bind ( null , cosmosClient ) , search : searchReadModel . bind ( null , cosmosClient ) , subscribe : undefined as any , rawToEnvelopes : undefined as any , fetchSubscriptions : undefined as any , store : storeReadModel . bind ( null , cosmosClient ) , delete : deleteReadModel . bind ( null , cosmosClient ) , 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 : rawScheduledInputToEnvelope , } , infrastructure : ( ) => { const infrastructurePackageName = require ( '../package.json' ) . name + '-infrastructure' ; let infrastructure ; try { infrastructure = loadInfrastructurePackage ( infrastructurePackageName ) ; } catch ( e ) { throw new Error ( `The Azure 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 ( rockets ) ; } , } ) ; function notImplemented ( ) { } export * from './constants' ;