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.
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, andctx.createServiceContextare then fully typed with no casts.