forked from restspace/rs-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeServiceContext.ts
More file actions
25 lines (24 loc) · 1023 Bytes
/
makeServiceContext.ts
File metadata and controls
25 lines (24 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { IAdapter } from "../rs-core/adapter/IAdapter.ts";
import { PrePost } from "../rs-core/IServiceConfig.ts";
import { Message } from "../rs-core/Message.ts";
import { PipelineSpec } from "../rs-core/PipelineSpec.ts";
import { ServiceContext } from "../rs-core/ServiceContext.ts";
import { Url } from "../rs-core/Url.ts";
import { config } from "./config.ts";
import { handleOutgoingRequest } from "./handleRequest.ts";
import { pipeline } from "./pipeline/pipeline.ts";
export function makeServiceContext(tenantName: string, prePost?: PrePost): ServiceContext<IAdapter> {
const context = {
tenant: tenantName,
makeRequest: handleOutgoingRequest,
runPipeline: (msg: Message, pipelineSpec: PipelineSpec, contextUrl?: Url) => {
pipeline(msg, pipelineSpec, contextUrl);
},
prePost,
logger: config.logger,
getAdapter: <T extends IAdapter>(url: string, adapterConfig: unknown) => {
return config.modules.getAdapter<T>(url, context, adapterConfig)
}
} as ServiceContext<IAdapter>;
return context;
}