refactor(core): #HttpRequestMetadataStorage
MODIFY
packages/core/src/http/response/http.responseHandler.ts
packages/core/src/http/response/http.responseHandler.ts
@@ -7,7 +7,7 @@ import { HttpEffectResponse } from '../effects/http.effects.interface';
import { HttpRequest, HttpResponse, HttpStatus } from '../http.interface';
import { isStream } from '../../+internal/utils';
import { ContextProvider } from '../../context/context.factory';
-import { HttpRequestMetadataStorageToken } from '../server/http.server.tokens';
+import { HttpRequestMetadataStorageToken } from '../server/internal-dependencies/httpRequestMetadataStorage.reader';
import { getTestingRequestIdHeader, isTestingMetadataOn } from '../../+internal/testing';
import { headersFactory } from './http.responseHeaders.factory';
import { bodyFactory } from './http.responseBody.factory';

DELETE
packages/core/src/http/server/http.server.metadata.storage.ts
-import { HttpRequestMetadata } from '../http.interface';
-import { createReader } from '../../context/context.reader.factory';
-
-export type HttpRequestMetadataStorage = ReturnType<typeof httpRequestMetadataStorage>;
-
-export const httpRequestMetadataStorage = createReader(() => {
- const storage = new Map<string, HttpRequestMetadata>();
-
- const set = (key: string | undefined, metadata: HttpRequestMetadata | undefined) => {
- if (key && metadata) storage.set(key, metadata);
- }
-
- const get = (key: string) => {
- const metadata = storage.get(key);
- storage.delete(key);
- return metadata;
- }
-
- const size = () =>
- storage.size;
-
- return {
- set,
- get,
- size,
- }
-});

MODIFY
packages/core/src/http/server/http.server.tokens.ts
packages/core/src/http/server/http.server.tokens.ts
import { Observable, Subject } from 'rxjs';
import { createContextToken } from '../../context/context.token.factory';
import { HttpServer, HttpRequest } from '../http.interface';
-import { Routing } from '../router/http.router.interface';
import { AllServerEvents } from './http.server.event';
-import { HttpRequestMetadataStorage } from './http.server.metadata.storage';
export const HttpServerEventStreamToken = createContextToken<Observable<AllServerEvents>>('HttpServerEventStreamToken');
export const HttpServerClientToken = createContextToken<HttpServer>('HttpServerClientToken');
-export const HttpRoutingToken = createContextToken<Routing>('HttpServerRoutingToken');
-export const HttpRequestMetadataStorageToken = createContextToken<HttpRequestMetadataStorage>('HttpServerRequestMetadataStorageToken');
export const HttpRequestBusToken = createContextToken<Subject<HttpRequest>>('HttpRequestBusToken');

MODIFY
packages/core/src/http/server/http.server.ts
packages/core/src/http/server/http.server.ts
@@ -13,8 +13,8 @@ import { ServerIO } from '../../listener/listener.interface';
import { listening$, close$, error$ } from '../effects/http.effects';
import { LoggerTag } from '../../logger';
import { subscribeServerEvents } from './http.server.event.subscriber';
-import { HttpServerClientToken, HttpServerEventStreamToken, HttpRequestMetadataStorageToken, HttpRequestBusToken } from './http.server.tokens';
-import { httpRequestMetadataStorage } from './http.server.metadata.storage';
+import { HttpServerClientToken, HttpServerEventStreamToken, HttpRequestBusToken } from './http.server.tokens';
+import { HttpRequestMetadataStorage, HttpRequestMetadataStorageToken } from './internal-dependencies/httpRequestMetadataStorage.reader';
import { CreateServerConfig } from './http.server.interface';
import { isCloseEvent } from './http.server.event';
@@ -26,7 +26,7 @@ export const createServer = async (config: CreateServerConfig) => {
const boundHttpServerEvent = bindTo(HttpServerEventStreamToken)(() => serverEvent$);
const boundHttpServerClient = bindTo(HttpServerClientToken)(() => server);
- const boundHttpRequestMetadataStorage = bindTo(HttpRequestMetadataStorageToken)(httpRequestMetadataStorage);
+ const boundHttpRequestMetadataStorage = bindTo(HttpRequestMetadataStorageToken)(HttpRequestMetadataStorage);
const boundHttpRequestBus = bindTo(HttpRequestBusToken)(() => new Subject<HttpRequest>());
const context = await contextFactory(

RENAME
packages/core/src/http/server/specs/http.server.metadata.storage.spec.ts
packages/core/src/http/server/internal-dependencies/httpRequestMetadataStorage.reader.spec.ts
import { createContext } from '../../../context/context.factory';
import { createUuid } from '../../../+internal/utils';
import { HttpRequestMetadata } from '../../http.interface';
-import { httpRequestMetadataStorage } from '../http.server.metadata.storage';
+import { HttpRequestMetadataStorage } from './httpRequestMetadataStorage.reader';
-describe('#httpRequestMetadataStorage', () => {
- const storage = httpRequestMetadataStorage(createContext());
+describe('#HttpRequestMetadataStorage', () => {
+ const storage = HttpRequestMetadataStorage(createContext());
test('sets => gets => removes value from storage', () => {
const id = createUuid();

ADD
packages/core/src/http/server/internal-dependencies/httpRequestMetadataStorage.reader.ts
+import { HttpRequestMetadata } from '../../http.interface';
+import { createReader } from '../../../context/context.reader.factory';
+import { createContextToken } from '../../../context/context.token.factory';
+
+export type HttpRequestMetadataStorage = ReturnType<typeof HttpRequestMetadataStorage>;
+
+export const HttpRequestMetadataStorageToken = createContextToken<HttpRequestMetadataStorage>('HttpRequestMetadataStorage');
+
+export const HttpRequestMetadataStorage = createReader(() => {
+ const storage = new Map<string, HttpRequestMetadata>();
+
+ const set = (key: string | undefined, metadata: HttpRequestMetadata | undefined) => {
+ if (key && metadata) storage.set(key, metadata);
+ }
+
+ const get = (key: string) => {
+ const metadata = storage.get(key);
+ storage.delete(key);
+ return metadata;
+ }
+
+ const size = () =>
+ storage.size;
+
+ return {
+ set,
+ get,
+ size,
+ }
+});

MODIFY
packages/core/src/index.ts
packages/core/src/index.ts
@@ -13,6 +13,9 @@ 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';
+
// core - error
export { coreErrorFactory, CoreErrorOptions } from './error/error.factory';
export { CoreError, EventError, isCoreError, isEventError } from './error/error.model';

refactor(core): #HttpRequestMetadataStorage