diff --git a/packages/backend-plugin-api/src/services/system/types.test.ts b/packages/backend-plugin-api/src/services/system/types.test.ts index 7c0942a4c3..046c711ee7 100644 --- a/packages/backend-plugin-api/src/services/system/types.test.ts +++ b/packages/backend-plugin-api/src/services/system/types.test.ts @@ -199,38 +199,6 @@ describe('createServiceFactory', () => { metaFactory(); }); - it('should create root scoped factory with dependencies and required options', () => { - const metaFactory = createServiceFactory((_options: TestOptions) => ({ - service: createServiceRef({ id: 'foo', scope: 'root' }), - deps: { - root: rootDep, - plugin: pluginDep, - }, - async factory({ root }) { - const root1: number = root; - // @ts-expect-error - const root2: string = root; - unused(root1, root2); - return 0; - }, - })); - expect(metaFactory).toEqual(expect.any(Function)); - - // @ts-expect-error - metaFactory('string'); - // @ts-expect-error - metaFactory({}); - metaFactory({ x: 1 }); - // @ts-expect-error - metaFactory({ x: 1, y: 2 }); - // @ts-expect-error - metaFactory(null); - // @ts-expect-error - metaFactory(undefined); - // @ts-expect-error - metaFactory(); - }); - it('should create factory with dependencies', () => { const metaFactory = createServiceFactory({ service: createServiceRef({ id: 'derp' }), @@ -267,6 +235,36 @@ describe('createServiceFactory', () => { metaFactory(); }); + it('should create factory with dependencies with optional derpFactory', () => { + const metaFactory = createServiceFactory({ + service: createServiceRef({ id: 'derp' }), + deps: { + root: rootDep, + plugin: pluginDep, + }, + async factory({ root, plugin }) { + const root1: number = root; + // @ts-expect-error + const root2: string = root; + const plugin3: boolean = plugin; + // @ts-expect-error + const plugin4: number = plugin; + unused(root1, root2, plugin3, plugin4); + return 'x'; + }, + }); + + expect(metaFactory).toEqual(expect.any(Function)); + + // @ts-expect-error + metaFactory({}); + // @ts-expect-error + metaFactory(null); + // @ts-expect-error + metaFactory(undefined); + metaFactory(); + }); + it('should create factory with required options and dependencies', () => { const metaFactory = createServiceFactory((_opts: TestOptions) => ({ service: ref, diff --git a/packages/backend-plugin-api/src/services/system/types.ts b/packages/backend-plugin-api/src/services/system/types.ts index 71359bad68..9d57d19e49 100644 --- a/packages/backend-plugin-api/src/services/system/types.ts +++ b/packages/backend-plugin-api/src/services/system/types.ts @@ -154,7 +154,7 @@ export interface PluginServiceFactoryConfig< > { service: ServiceRef; deps: TDeps; - rootFactory(deps: ServiceRefsToInstances): Promise; + rootFactory?(deps: ServiceRefsToInstances): Promise; factory( deps: ServiceRefsToInstances, context: TContext,