refactor(core): #HttpServerClient
MODIFY
packages/core/src/+internal/testing/http.helper.ts
packages/core/src/+internal/testing/http.helper.ts
@@ -18,7 +18,7 @@ import { factorizeRegExpWithParams } from '../../http/router/http.router.params.
import { HttpEffect } from '../../http/effects/http.effects.interface';
import { RoutingItem } from '../../http/router/http.router.interface';
import { HttpRequestBusToken, HttpRequestBus } from '../../http/server/internal-dependencies/httpRequestBus.reader';
-import { HttpServerClientToken } from '../../http/server/http.server.tokens';
+import { HttpServerClientToken, HttpServerClient } from '../../http/server/internal-dependencies/httpServerClient.reader';
interface HttpRequestMockParams {
url?: string;
@@ -72,7 +72,7 @@ export const createMockEffectContext = () => {
const dependencies = [
bindTo(LoggerToken)(mockLogger),
bindTo(HttpRequestBusToken)(HttpRequestBus),
- bindTo(HttpServerClientToken)(() => http.createServer()),
+ bindTo(HttpServerClientToken)(HttpServerClient(http.createServer())),
];
const context = registerAll(dependencies)(createContext());
const client = http.createServer();

MODIFY
packages/core/src/http/server/http.server.listener.ts
packages/core/src/http/server/http.server.listener.ts
@@ -8,7 +8,7 @@ import { factorizeRoutingWithDefaults } from '../router/http.router.factory';
import { createEffectContext } from '../../effects/effectsContext.factory';
import { useContext } from '../../context/context.hook';
import { createListener } from '../../listener/listener.factory';
-import { HttpServerClientToken } from './http.server.tokens';
+import { HttpServerClientToken } from './internal-dependencies/httpServerClient.reader';
export interface HttpListenerConfig {
effects?: (RouteEffect | RouteEffectGroup)[];

MODIFY
packages/core/src/http/server/http.server.spec.ts
packages/core/src/http/server/http.server.spec.ts
@@ -7,6 +7,7 @@ import { tap, filter, take } from 'rxjs/operators';
import { HttpServer } from '../http.interface';
import { lookup } from '../../context/context';
import { useContext } from '../../context/context.hook';
+import { HttpServerClientToken } from './internal-dependencies/httpServerClient.reader';
import { httpListener } from './http.server.listener';
import { createServer } from './http.server';
import {
@@ -21,7 +22,6 @@ import {
isClientErrorEvent,
isCloseEvent,
} from './http.server.event';
-import { HttpServerClientToken } from './http.server.tokens';
describe('#createServer', () => {
let server: HttpServer;

DELETE
packages/core/src/http/server/http.server.tokens.ts
-import { createContextToken } from '../../context/context.token.factory';
-import { HttpServer } from '../http.interface';
-
-export const HttpServerClientToken = createContextToken<HttpServer>('HttpServerClientToken');

MODIFY
packages/core/src/http/server/http.server.ts
packages/core/src/http/server/http.server.ts
@@ -14,7 +14,6 @@ import { ServerIO } from '../../listener/listener.interface';
import { listening$, close$, error$ } from '../effects/http.effects';
import { LoggerTag } from '../../logger';
import { useContext } from '../../context/context.hook';
-import { HttpServerClientToken } from './http.server.tokens';
import { CreateServerConfig } from './http.server.interface';
import { isCloseEvent } from './http.server.event';
@@ -22,6 +21,7 @@ import { isCloseEvent } from './http.server.event';
import { HttpRequestMetadataStorage, HttpRequestMetadataStorageToken } from './internal-dependencies/httpRequestMetadataStorage.reader';
import { HttpServerEventStreamToken, HttpServerEventStream } from './internal-dependencies/httpServerEventStream.reader';
import { HttpRequestBusToken, HttpRequestBus } from './internal-dependencies/httpRequestBus.reader';
+import { HttpServerClient, HttpServerClientToken } from './internal-dependencies/httpServerClient.reader';
export const createServer = async (config: CreateServerConfig) => {
const { listener, event$, port, hostname, dependencies = [], options = {} } = config;
@@ -30,7 +30,7 @@ export const createServer = async (config: CreateServerConfig) => {
? https.createServer(options.httpsOptions)
: http.createServer();
- const boundHttpServerClient = bindEagerlyTo(HttpServerClientToken)(() => server);
+ const boundHttpServerClient = bindEagerlyTo(HttpServerClientToken)(HttpServerClient(server));
const boundHttpServerEvent = bindEagerlyTo(HttpServerEventStreamToken)(HttpServerEventStream({ server, hostname }));
const boundHttpRequestBus = bindEagerlyTo(HttpRequestBusToken)(HttpRequestBus);
const boundHttpRequestMetadataStorage = bindTo(HttpRequestMetadataStorageToken)(HttpRequestMetadataStorage);

ADD
packages/core/src/http/server/internal-dependencies/httpServerClient.reader.ts
+import { createReader } from '../../../context/context.reader.factory';
+import { createContextToken } from '../../../context/context.token.factory';
+import { HttpServer } from '../../http.interface';
+import { HttpRequestBus } from './httpRequestBus.reader';
+
+export type HttpServerClient = ReturnType<typeof HttpRequestBus>;
+
+export const HttpServerClientToken = createContextToken<HttpServer>('HttpServerClient');
+
+export const HttpServerClient = (httpServer: HttpServer) => createReader(_ => httpServer);

MODIFY
packages/core/src/index.spec.ts
packages/core/src/index.spec.ts
@@ -30,6 +30,7 @@ describe('@marblejs/core public API', () => {
expect(API.matchEvent).toBeDefined();
// internal dependencies
+ expect(API.HttpServerClientToken).toBeDefined();
expect(API.HttpServerEventStreamToken).toBeDefined();
expect(API.HttpRequestMetadataStorageToken).toBeDefined();
expect(API.HttpRequestBusToken).toBeDefined();

MODIFY
packages/core/src/index.ts
packages/core/src/index.ts
export { EffectFactory } from './http/effects/http.effects.factory';
export { defaultError$ } from './http/error/http.error.effect';
export { HttpError, HttpRequestError, isHttpError, isHttpRequestError } from './http/error/http.error.model';
+export { createServer } from './http/server/http.server';
export { combineRoutes } from './http/router/http.router.combiner';
export { r } from './http/router/http.router.ixbuilder';
export * from './http/router/http.router.interface';
export * from './http/effects/http.effects.interface';
export * from './http/server/http.server.event';
export * from './http/server/http.server.interface';
-export * from './http/server/http.server.tokens';
-export * from './http/server/http.server';
export * from './http/server/http.server.listener';
export * from './http/http.interface';
// http - server - internal dependencies
export * from './http/server/internal-dependencies/httpRequestMetadataStorage.reader';
+export * from './http/server/internal-dependencies/httpServerClient.reader';
export * from './http/server/internal-dependencies/httpServerEventStream.reader';
export * from './http/server/internal-dependencies/httpRequestBus.reader';

refactor(core): #HttpServerClient