feat(core): export utility functions from `core` package
MODIFY
packages/core/src/index.spec.ts
packages/core/src/index.spec.ts
@@ -10,6 +10,7 @@ describe('@marblejs/core public API', () => {
expect(API.error$).toBeDefined();
expect(API.combineRoutes).toBeDefined();
expect(API.ContentType).toBeDefined();
+ expect(API.compose).toBeDefined();
});
});

MODIFY
packages/core/src/index.ts
packages/core/src/index.ts
-export * from './effects/effects.interface';
export { combineRoutes } from './effects/effects.combiner';
+export * from './effects/effects.interface';
export { error$ } from './error/error.middleware';
export { HttpError } from './error/error.model';
-export * from './operators';
export * from './http.interface';
export * from './http.listener';
+export * from './operators';
+export { compose } from './util/compose.util';
export { ContentType } from './util/contentType.util';

MODIFY
packages/middleware-logger/src/index.ts
packages/middleware-logger/src/index.ts
-import { Effect, HttpRequest } from '@marblejs/core';
+import { compose, Effect, HttpRequest } from '@marblejs/core';
import chalk from 'chalk';
import { tap } from 'rxjs/operators';
-import { TimeFactory } from './time.factory';
+import { formatTime, getTimeDifferenceMs } from './time.factory';
const getStatusCode = (statusCode: number): string =>
statusCode >= 400
@@ -27,7 +27,7 @@ export const logger$: Effect<HttpRequest> = (request$, response) =>
request.method!,
request.url!,
getStatusCode(response.statusCode),
- TimeFactory.formatTime(TimeFactory.getTimeDifferenceMs(startTime))
+ compose(formatTime, getTimeDifferenceMs)(startTime)
)
);
})

MODIFY
packages/middleware-logger/src/time.factory.spec.ts
packages/middleware-logger/src/time.factory.spec.ts
-import { TimeFactory } from './time.factory';
+import { formatTime, getTimeDifferenceMs } from './time.factory';
describe('TimeFactory', () => {
@@ -8,8 +8,8 @@ describe('TimeFactory', () => {
const lessThanSecond = 800;
// when
- const formattedSecond = TimeFactory.formatTime(moreThanSecond);
- const formattedMilisecond = TimeFactory.formatTime(lessThanSecond);
+ const formattedSecond = formatTime(moreThanSecond);
+ const formattedMilisecond = formatTime(lessThanSecond);
// then
expect(formattedSecond).toBe('1.2s');
@@ -22,7 +22,7 @@ describe('TimeFactory', () => {
spyOn(global, 'Date').and.returnValue({ getTime: () => 2000 });
// when
- const timeDifference = TimeFactory.getTimeDifferenceMs(startTime);
+ const timeDifference = getTimeDifferenceMs(startTime);
// then
expect(timeDifference).toBe(2000 - 1000);

MODIFY
packages/middleware-logger/src/time.factory.ts
packages/middleware-logger/src/time.factory.ts
-export namespace TimeFactory {
-
export const formatTime = (timeMs: number) =>
timeMs > 1000
? `${timeMs / 1000}s`
@@ -7,5 +5,3 @@ export namespace TimeFactory {
export const getTimeDifferenceMs = (startTime: Date): number =>
new Date().getTime() - startTime.getTime();
-
-}

feat(core): export utility functions from `core` package