refactor(core): removed deprecated `EffectFactory`
DELETE
packages/core/src/http/effects/http.effects.factory.ts
-/* eslint-disable deprecation/deprecation */
-
-import { getArrayFromEnum } from '../../+internal/utils';
-import { coreErrorFactory, CoreErrorOptions } from '../../error/error.factory';
-import { HttpEffect } from '../effects/http.effects.interface';
-import { RouteEffect } from '../router/http.router.interface';
-import { HttpMethod, HttpMethodType } from '../http.interface';
-
-const httpMethods = getArrayFromEnum(HttpMethodType);
-const coreErrorOptions: CoreErrorOptions = { contextMethod: 'EffectFactory' };
-
-/**
- * @deprecated since version 3.0, use pipable builder instead
- *
- * #EffectFactory will be deleted in the next major version (v4.0),
- */
-export const EffectFactory = {
- matchPath: (path: string) => {
- if (!path) {
- throw coreErrorFactory('Path cannot be empty', coreErrorOptions);
- }
-
- return { matchType: EffectFactory.matchType(path) };
- },
-
- matchType: (path: string) => (method: HttpMethod) => {
- if (!method) {
- throw coreErrorFactory('HttpMethod needs to be defined', coreErrorOptions);
- }
-
- if (!httpMethods.includes(method)) {
- throw coreErrorFactory(
- `HttpMethod needs to be one of the following: ${httpMethods}`,
- coreErrorOptions,
- );
- }
-
- return { use: EffectFactory.use(path)(method) };
- },
-
- use: (path: string) => (method: HttpMethod) => (effect: HttpEffect): RouteEffect => {
- if (!effect) {
- throw coreErrorFactory('Effect needs to be provided', coreErrorOptions);
- }
-
- return { path, method, effect };
- },
-}

DELETE
packages/core/src/http/effects/specs/http.effects.factory.spec.ts
-/* eslint-disable deprecation/deprecation */
-
-import { mapTo } from 'rxjs/operators';
-import { HttpEffect } from '../http.effects.interface';
-import { EffectFactory } from '../http.effects.factory';
-import { HttpMethod } from '../../http.interface';
-
-describe('EffectFactory', () => {
-
- let expectedError: Error;
- let coreError;
-
- beforeEach(() => {
- jest.unmock('../../../error/error.factory.ts');
- coreError = require('../../../error/error.factory.ts');
- coreError.coreErrorFactory = jest.fn(() => expectedError);
- });
-
- afterEach(() => {
- jest.clearAllMocks();
- });
-
- test('factorizes RouteConfig', () => {
- // given
- const effect$: HttpEffect = req$ => req$.pipe(mapTo({ body: 'test' }));
- const path = '/foo';
- const method = 'GET';
-
- // when
- const factorizedEffect = EffectFactory
- .matchPath(path)
- .matchType(method)
- .use(effect$);
-
- // then
- expect(factorizedEffect.path).toEqual('/foo');
- expect(factorizedEffect.method).toEqual('GET');
- expect(factorizedEffect.effect).toBeDefined();
- });
-
- test('throws an error if "path" is not provided', () => {
- // given
- expectedError = new Error('Path cannot be empty');
-
- // when
- const effectFactoryFn = () => EffectFactory.matchPath(undefined as any);
-
- // then
- expect(effectFactoryFn).toThrowError(expectedError);
- });
-
- test('throws an error if "method" is not provided', () => {
- // given
- expectedError = new Error('HttpMethod needs to be defined');
-
- // when
- const effectFactoryFn = () => EffectFactory
- .matchPath('/')
- .matchType(undefined as any);
-
- // then
- expect(effectFactoryFn).toThrowError(expectedError);
- });
-
- test('throws an error if provided "method" is not included in the list', () => {
- // given
- expectedError = new Error(
- 'HttpMethod needs to be one of the following: POST,PUT,PATCH,GET,HEAD,DELETE,CONNECT,OPTIONS,TRACE,*'
- );
-
- // when
- const effectFactoryFn = () => EffectFactory
- .matchPath('/')
- .matchType('TEST' as HttpMethod);
-
- // then
- expect(effectFactoryFn).toThrowError(expectedError);
- });
-
- test('throws an error if "effect" is not provided', () => {
- // given
- expectedError = new Error('Effect needs to be provided');
-
- // when
- const effectFactoryFn = () => EffectFactory
- .matchPath('/')
- .matchType('GET')
- .use(undefined as any);
-
- // then
- expect(effectFactoryFn).toThrowError(expectedError);
- });
-
-});

MODIFY
packages/core/src/index.spec.ts
packages/core/src/index.spec.ts
@@ -4,8 +4,6 @@ describe('@marblejs/core public API', () => {
test('apis are defined', () => {
expect(API.httpListener).toBeDefined();
expect(API.defaultError$).toBeDefined();
- // eslint-disable-next-line deprecation/deprecation
- expect(API.EffectFactory).toBeDefined();
expect(API.combineRoutes).toBeDefined();
expect(API.combineEffects).toBeDefined();
expect(API.combineMiddlewares).toBeDefined();

MODIFY
packages/core/src/index.ts
packages/core/src/index.ts
// http
// eslint-disable-next-line deprecation/deprecation
-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';

refactor(core): removed deprecated `EffectFactory`