@edd-kernel/factory
v0.2.0-alpha.1
Published
Factory for creating EDD Kernel clients from provider names.
Maintainers
Readme
@edd-kernel/factory
Factory for creating EDD Kernel clients from provider names.
This package belongs to the EDD Kernel composition layer. It owns provider name
resolution and dynamic provider loading. It does not own provider-specific
transport behavior; that belongs to each @edd-kernel/provider-* package.
Repository: brunnofoggia/edd-kernel-js
Install
This is the package an application imports from. Install it with the provider your application uses:
npm install @edd-kernel/factory @edd-kernel/provider-aws-sqsIt re-exports the whole of @edd-kernel/contracts — the types, the enums, the error
classes and the provider registry — so the application does not install the contract
separately.
Provider packages are optional peer dependencies. Install only the provider package used by the application.
Usage
import { EddProviderName, createEddClient } from '@edd-kernel/factory';
const client = await createEddClient({
providerName: EddProviderName.AwsSqs,
createIfNotExists: true,
options: {
region: 'us-east-1',
},
});
await client.send({ queueName: 'email-jobs' }, { type: 'email.requested', payload: {} });Use options for provider-specific configuration. Shared EDD Kernel options stay
at the top level:
const client = await createEddClient({
providerName: EddProviderName.RabbitMq,
createIfNotExists: true,
autoAck: false,
concurrency: 4,
options: {
url: 'amqp://guest:guest@localhost:5672',
},
});providerName is always required. To use an application-defined provider,
pass its class constructor in providerClass:
import { createEddClient } from '@edd-kernel/factory';
import { InMemoryEddClient } from '@edd-kernel/provider-in-memory';
class CustomEddClient extends InMemoryEddClient {
static readonly providerName = 'custom';
}
const client = await createEddClient({
providerName: CustomEddClient.providerName,
providerClass: CustomEddClient,
createIfNotExists: true,
});providerClass must be a class to instantiate, not an existing client
instance. If the class declares a static providerName, it must match the
configured name. Custom names are accepted only when providerClass is
provided; otherwise the name must identify a built-in provider.
Providers
Supported provider names:
| Name | Package |
| ------------- | ---------------------------------- |
| in-memory | @edd-kernel/provider-in-memory |
| aws-sqs | @edd-kernel/provider-aws-sqs |
| rabbitmq | @edd-kernel/provider-rabbitmq |
| gcp-pub-sub | @edd-kernel/provider-gcp-pub-sub |
The same options are exported as EddProviderName. Provider package and class
targets are exported as EDD_PROVIDER_TARGET_BY_NAME; the package-only mapping
remains available as EDD_PROVIDER_PACKAGE_BY_NAME.
Common Options
The factory forwards shared EDD Kernel options to the selected provider:
serializationautoIdempotencyKeycreateIfNotExistsautoAckunhandledErrorActionconcurrencyloggerdebug
