Beignet API reference
    Preparing search index...

    Interface ServiceProvider<Ports, CfgSchema, ProvidedPorts, Context, ServiceInput>

    A service provider that can extend or replace ports during app initialization.

    Providers support:

    • Configuration via Standard Schema (any compatible library: Zod, Valibot, etc.)
    • Returning ports with new capabilities (e.g., cache, mailer)
    • Replacing existing ports by returning the same key
    • Optional start/stop hooks
    const cacheProvider = createProvider({
    name: "cache-redis",
    config: {
    schema: z.object({ URL: z.string().url() }),
    envPrefix: "REDIS_",
    },
    async setup({ config }) {
    const client = new Redis(config.URL);
    return {
    ports: {
    cache: {
    get: (key) => client.get(key),
    set: (key, value) => client.set(key, value),
    },
    },
    stop: () => client.quit(),
    };
    },
    });
    interface ServiceProvider<
        Ports,
        CfgSchema extends StandardSchemaV1 = StandardSchemaV1<void, void>,
        ProvidedPorts extends ProviderPorts = NoProvidedPorts,
        Context = unknown,
        ServiceInput = void,
    > {
        __providedPorts?: ProvidedPorts;
        config?: ProviderConfigDef<CfgSchema>;
        metadata?: ServiceProviderMetadata;
        name: string;
        setup(
            ctx: {
                config: InferOutput<CfgSchema> | undefined;
                createServiceContext: ProviderServiceContextFactory<
                    Context,
                    ServiceInput,
                >;
                ports: Readonly<Ports>;
            },
        ): MaybePromise<
            ProviderSetupResult<ProvidedPorts, Ports, Context, ServiceInput>,
        >;
    }

    Type Parameters

    • Ports
    • CfgSchema extends StandardSchemaV1 = StandardSchemaV1<void, void>
    • ProvidedPorts extends ProviderPorts = NoProvidedPorts
    • Context = unknown
    • ServiceInput = void
    Index
    __providedPorts?: ProvidedPorts

    Type-only marker for ports this provider contributes. Runtime provider objects do not need to set this property.

    Optional configuration definition. If provided, the config will be loaded and validated before calling setup.

    Optional static metadata for docs and diagnostics.

    name: string

    Unique name for this provider (used for logging/debugging)