Skip to content

Commit

Permalink
feat: do not create singleton grahite and loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Apr 16, 2019
1 parent 4b5415f commit a33b860
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 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 { httpLoaderInstance } from '@stoplight/prism-core';
import { createHttpLoaderInstance } 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: httpLoaderInstance }, config: { mock: false } }
{ components: { loader: createHttpLoaderInstance() }, config: { mock: false } }
);
});
});
4 changes: 2 additions & 2 deletions packages/cli/src/util/createServer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { httpLoaderInstance } from '@stoplight/prism-core';
import { createHttpLoaderInstance } 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: httpLoaderInstance }, config })
? createHttpServer({ url: spec }, { components: { loader: createHttpLoaderInstance() }, config })
: createHttpServer({ path: spec }, { config });
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export function factory<Resource, Input, Output, Config, LoadOpts>(
defaultConfig: PrismConfig<Config, Input>,
defaultComponents: Partial<IPrismComponents<Resource, Input, Output, Config, LoadOpts>>
): (
customConfig?: PartialPrismConfig<Config, Input>,
customComponents?: Partial<IPrismComponents<Resource, Input, Output, Config, LoadOpts>>
) => IPrism<Resource, Input, Output, Config, LoadOpts> {
customConfig?: PartialPrismConfig<Config, Input>,
customComponents?: Partial<IPrismComponents<Resource, Input, Output, Config, LoadOpts>>
) => IPrism<Resource, Input, Output, Config, LoadOpts> {
const prism = (
customConfig?: PartialPrismConfig<Config, Input>,
customComponents?: Partial<IPrismComponents<Resource, Input, Output, Config, LoadOpts>>
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) { }

/**
* 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 filesystemLoaderInstance = new FilesystemLoader(new GraphFacade());
export const createFilesystemLoaderInstance = () => new FilesystemLoader(new GraphFacade());
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) { }

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

export const httpLoaderInstance = new HttpLoader(new GraphFacade());
export const createHttpLoaderInstance = () => new HttpLoader(new GraphFacade());
2 changes: 1 addition & 1 deletion packages/http/src/__tests__/http-prism-instance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('Http Prism Instance function tests', () => {
path: relative(process.cwd(), resolve(__dirname, 'fixtures', 'petstore.oas2.yaml')),
});

expect(prism.resources).toHaveLength(5);
expect(prism.resources).toHaveLength(3);
});

test('returns stringified static example when one defined in spec', async () => {
Expand Down
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 { factory, filesystemLoaderInstance, PartialPrismConfig } from '@stoplight/prism-core';
import { factory, createFilesystemLoaderInstance, 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: filesystemLoaderInstance,
loader: createFilesystemLoaderInstance(),
router,
forwarder,
validator,
Expand Down

0 comments on commit a33b860

Please sign in to comment.