diff --git a/src/metadata.ts b/src/metadata.ts index 660225a..8e63175 100644 --- a/src/metadata.ts +++ b/src/metadata.ts @@ -15,6 +15,12 @@ export interface ProviderMeta { provides: string; needs: string[]; optional: boolean; + /** + * Always refused. `@Provider`'s options no longer declare `export`, so TypeScript rejects it at + * the decorator and this can only be true for a JavaScript caller. It is still recorded so that + * caller reaches `collectProviders`' boot error, which names the provider and the replacement, + * rather than having the option silently ignored. + */ export: boolean; } /** Metadata attached by `@Step`: what it provides, what it needs, and its visibility. */ @@ -58,18 +64,16 @@ const K = { }; /** Marks a class as a provider: a lazily-built dependency addressable by its `provides` key. */ -export function Provider(opts: { - provides: string; - needs?: string[]; - optional?: boolean; - export?: boolean; -}): ClassDecorator { +export function Provider(opts: { provides: string; needs?: string[]; optional?: boolean }): ClassDecorator { return (target) => { const meta: ProviderMeta = { provides: opts.provides, needs: opts.needs ?? [], optional: opts.optional ?? false, - export: opts.export ?? false, + // Read through a cast because the options type deliberately does not offer `export`: only a + // `@Step` or a route is exportable, and the option's only behaviour was to throw at boot. + // A JavaScript caller can still pass it, and recording it is what routes them to that error. + export: (opts as { export?: boolean }).export ?? false, }; Reflect.defineMetadata(K.provider, meta, target); }; diff --git a/test/mesh/failure.test.ts b/test/mesh/failure.test.ts index 4333874..8d78c46 100644 --- a/test/mesh/failure.test.ts +++ b/test/mesh/failure.test.ts @@ -124,6 +124,9 @@ describe('mesh link failure', () => { describe('provider export', () => { it('refuses to boot when a provider is exported over the mesh', async () => { + // `as any` is load-bearing, not laziness: `export` is not in `@Provider`'s options type, so a + // TypeScript caller cannot write this at all. The cast is how the test reaches the runtime + // backstop that a JavaScript caller would hit. @Provider({ provides: 'db', needs: [], export: true } as any) class Db { provide() { diff --git a/test/metadata.test.ts b/test/metadata.test.ts index f41546e..7293a74 100644 --- a/test/metadata.test.ts +++ b/test/metadata.test.ts @@ -67,12 +67,15 @@ describe('HEAD and OPTIONS decorators', () => { }); describe('mesh export flags', () => { - it('providers/steps carry export (default false)', () => { - @Provider({ provides: 'config', export: true }) class C { provide() { return {}; } } + it('steps carry export, and a provider defaults to not exported', () => { @Step({ provides: 'auth', export: true }) class A { run() { return {}; } } @Provider({ provides: 'priv' }) class P { provide() { return {}; } } - expect(getProviderMeta(C)!.export).toBe(true); expect(getStepMeta(A)!.export).toBe(true); + // No `export: true` case for a provider: the option is gone from `@Provider`'s type, and its + // only behaviour is the boot throw that `test/mesh/failure.test.ts` covers end to end — + // asserting it is *stored* here would assert the option works. The default is a different + // claim and still load-bearing: `collectProviders` throws on anything truthy, so every plain + // provider recording `false` is what keeps ordinary apps booting. expect(getProviderMeta(P)!.export).toBe(false); });