A teapot exports steps and routes, not providers #94

Merged
chrnx merged 18 commits from feat/mesh-steps-only into develop 2026-09-12 20:42:07 +00:00
3 changed files with 20 additions and 10 deletions
Showing only changes of commit bff8778112 - Show all commits

No files matched your search

+11 -7
View File
@@ -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);
};
+3
View File
@@ -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() {
+6 -3
View File
@@ -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);
});