From bff87781129b81cc9efa632d8ecf173b928c5b85 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Sun, 6 Sep 2026 17:37:00 -0500 Subject: [PATCH] refactor(mesh): @Provider's options no longer advertise `export` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The framework's public type offered an option whose only behaviour is to throw at boot. Removing the field from the options type means a TypeScript caller gets a compile error at the decorator, where the mistake is, instead of a boot error a deploy away. The runtime throw in collectProviders stays as the JavaScript backstop, so ProviderMeta keeps the field and the decorator still records it through a cast — a JS caller reaches the error naming the provider and its replacement rather than having the option silently ignored. The `as any` in the boot-throw test is now genuinely load-bearing, since no TypeScript caller can write that decorator at all, and says so. test/metadata.test.ts asserted the flag was stored for a provider. That half described the option working, which is the message being removed, and the boot throw it fed is already covered end to end in test/mesh/failure.test.ts. The default is a different claim and stays: collectProviders throws on anything truthy, so every plain provider recording `false` is what keeps ordinary apps booting. Signed-off-by: Diego Resendez --- src/metadata.ts | 18 +++++++++++------- test/mesh/failure.test.ts | 3 +++ test/metadata.test.ts | 9 ++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) 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); });