Beignet API reference
    Preparing search index...

    Function createProvider

    • Helper function to create a provider with proper type inference.

      This is a simple identity function that helps TypeScript infer the correct types for the provider definition.

      App-local providers can use the curried zero-argument form to declare the ports they require from earlier providers plus their app context and service-context input. The required ports, ctx.ports, and ctx.createServiceContext are then fully typed with no casts.

      Type Parameters

      • Requires = unknown
      • Context = unknown
      • ServiceInput = void

      Returns <
          CfgSchema extends
              StandardSchemaV1<unknown, unknown> = StandardSchemaV1<void, void>,
          Provided extends ProviderPorts = NoProvidedPorts,
      >(
          def: ServiceProvider<
              Requires,
              CfgSchema,
              Provided,
              Context,
              ServiceInput,
          >,
      ) => ServiceProvider<Requires, CfgSchema, Provided, Context, ServiceInput>

      export const myProvider = createProvider({
      name: "my-provider",
      config: {
      schema: z.object({ apiKey: z.string() }),
      envPrefix: "MY_SERVICE_",
      },
      async setup({ config }) {
      return { ports: { myService: createMyService(config) } };
      },
      });

      // Typed app-local provider:
      export const appDatabaseProvider = createProvider<
      { db: DbPort<typeof schema>; devtools?: DevtoolsPort },
      AppContext,
      AppServiceContextInput
      >()({
      name: "app-database",
      async setup({ ports, createServiceContext }) {
      const repositories = createRepositories(ports.db.drizzle);
      return { ports: repositories };
      },
      });
    • Helper function to create a provider with proper type inference.

      This is a simple identity function that helps TypeScript infer the correct types for the provider definition.

      App-local providers can use the curried zero-argument form to declare the ports they require from earlier providers plus their app context and service-context input. The required ports, ctx.ports, and ctx.createServiceContext are then fully typed with no casts.

      Type Parameters

      Returns ServiceProvider<Ports, CfgSchema, ProvidedPorts>

      export const myProvider = createProvider({
      name: "my-provider",
      config: {
      schema: z.object({ apiKey: z.string() }),
      envPrefix: "MY_SERVICE_",
      },
      async setup({ config }) {
      return { ports: { myService: createMyService(config) } };
      },
      });

      // Typed app-local provider:
      export const appDatabaseProvider = createProvider<
      { db: DbPort<typeof schema>; devtools?: DevtoolsPort },
      AppContext,
      AppServiceContextInput
      >()({
      name: "app-database",
      async setup({ ports, createServiceContext }) {
      const repositories = createRepositories(ports.db.drizzle);
      return { ports: repositories };
      },
      });