Skip to content

Commit

Permalink
refactor: export class definition, not factories
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Apr 17, 2019
1 parent 0ddb47e commit 6eeb56c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/util/__tests__/createServer.unit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createHttpLoaderInstance } from '@stoplight/prism-core';
import { HttpLoader } from '@stoplight/prism-core';
import { createServer as createPrismServer } from '@stoplight/prism-http-server';
import { createServer } from '../createServer';

Expand Down Expand Up @@ -26,7 +26,7 @@ describe('server command', () => {

expect(createPrismServer).toHaveBeenLastCalledWith(
{ url: 'http://path.to/spec.oas2.yaml' },
{ components: { loader: createHttpLoaderInstance() }, config: { mock: false } }
{ components: { loader: new HttpLoader() }, config: { mock: false } }
);
});
});
8 changes: 4 additions & 4 deletions packages/cli/src/util/createServer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createHttpLoaderInstance } from '@stoplight/prism-core';
import { HttpLoader } from '@stoplight/prism-core';
import { IHttpConfig } from '@stoplight/prism-http';
import { createServer as createHttpServer } from '@stoplight/prism-http-server';

export function createServer(spec: string, config: IHttpConfig) {
return spec && isHttp(spec)
? createHttpServer(
{ url: spec },
{ components: { loader: createHttpLoaderInstance() }, config }
)
{ url: spec },
{ components: { loader: new HttpLoader() }, config }
)
: createHttpServer({ path: spec }, { config });
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/loaders/filesystem/filesystemLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GraphFacade } from '../../utils/graphFacade';
const DEFAULT_PATH = '.';

export class FilesystemLoader {
constructor(private graphFacade: GraphFacade) {}
constructor(private graphFacade: GraphFacade = new GraphFacade()) { }

/**
* TODO(sl-732): we can't assure we will return an array of 'Resource'.
Expand All @@ -31,4 +31,4 @@ export class FilesystemLoader {
}
}

export const createFilesystemLoaderInstance = () => new FilesystemLoader(new GraphFacade());
export default FilesystemLoader;
4 changes: 2 additions & 2 deletions packages/core/src/loaders/http/httpLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IHttpLoaderOpts } from '../../types';
import { GraphFacade } from '../../utils/graphFacade';

export class HttpLoader {
constructor(private graphFacade: GraphFacade) {}
constructor(private graphFacade: GraphFacade = new GraphFacade()) { }

public async load(opts?: IHttpLoaderOpts): Promise<IHttpOperation[]> {
if (!opts || !opts.url) return [];
Expand All @@ -23,4 +23,4 @@ export class HttpLoader {
}
}

export const createHttpLoaderInstance = () => new HttpLoader(new GraphFacade());
export default HttpLoader;
4 changes: 2 additions & 2 deletions packages/http/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createFilesystemLoaderInstance, factory, PartialPrismConfig } from '@stoplight/prism-core';
import { FilesystemLoader, factory, PartialPrismConfig } from '@stoplight/prism-core';
import { IHttpOperation } from '@stoplight/types';

import { forwarder } from './forwarder';
Expand All @@ -25,7 +25,7 @@ const createInstance = <LoaderInput>(
return factory<IHttpOperation, IHttpRequest, IHttpResponse, IHttpConfig, LoaderInput>(
{ mock: true },
{
loader: createFilesystemLoaderInstance(),
loader: new FilesystemLoader(),
router,
forwarder,
validator,
Expand Down

0 comments on commit 6eeb56c

Please sign in to comment.