invoiceddd
Version:
Complete invoice system with domain-driven design - gateway package for easy integration
135 lines (133 loc) • 4.39 kB
JavaScript
import { OrderRepository, InvoiceNumberRepository, InvoiceNumberGenerator } from '@invoiceddd/application';
import * as Layer from 'effect/Layer';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var LayerBuilder = class _LayerBuilder {
static {
__name(this, "LayerBuilder");
}
customLayers = {};
constructor() {
}
/**
* Start a new builder chain.
* @returns {LayerBuilder} A new LayerBuilder instance.
*/
static start() {
return new _LayerBuilder();
}
/**
* Replaces the default shipping policy with a custom implementation.
* @param {Layer.Layer<R, E, never>} layer - The custom shipping policy layer.
* @returns {LayerBuilder} The builder instance (for chaining).
* @template R, E
* @example
* builder.withCustomShippingPolicy(VIPShippingPolicy)
*/
withCustomShippingPolicy(layer) {
this.customLayers.shippingPolicy = layer;
return this;
}
/**
* Replaces the default invoice repository with a custom implementation.
* @param {Layer.Layer<R, E, never>} layer - The custom invoice repository layer.
* @returns {LayerBuilder} The builder instance (for chaining).
* @template R, E
* @example
* builder.withCustomInvoiceRepository(InMemoryInvoiceRepository)
*/
withCustomInvoiceRepository(layer) {
this.customLayers.invoiceRepository = layer;
return this;
}
withCustomOrderRepository(arg) {
if (isLayer(arg)) {
this.customLayers.orderRepository = arg;
} else {
this.customLayers.orderRepository = Layer.succeed(OrderRepository, arg);
}
return this;
}
withCustomInvoiceNumberRepository(arg) {
if (isLayer(arg)) {
this.customLayers.invoiceNumberRepository = arg;
} else {
this.customLayers.invoiceNumberRepository = Layer.succeed(InvoiceNumberRepository, arg);
}
return this;
}
withCustomInvoiceNumberGenerator(arg) {
if (isLayer(arg)) {
this.customLayers.invoiceNumberGenerator = arg;
} else {
this.customLayers.invoiceNumberGenerator = Layer.succeed(InvoiceNumberGenerator, arg);
}
return this;
}
/**
* Replaces the default PDF renderer with a custom implementation.
* @param {Layer.Layer<R, E, never>} layer - The custom PDF renderer layer.
* @returns {LayerBuilder} The builder instance (for chaining).
* @template R, E
* @example
* builder.withCustomPdfRenderer(MyCustomPdfRenderer)
*/
withCustomPdfRenderer(layer) {
this.customLayers.pdfRenderer = layer;
return this;
}
/**
* Replaces the default storage service with a custom implementation.
* @param {Layer.Layer<R, E, never>} layer - The custom storage service layer.
* @returns {LayerBuilder} The builder instance (for chaining).
* @template R, E
* @example
* builder.withCustomStorageService(MyCustomStorageService)
*/
withCustomStorageService(layer) {
this.customLayers.storageService = layer;
return this;
}
/**
* Replaces the default event bus with a custom implementation.
* @param {Layer.Layer<R, E, never>} layer - The custom event bus layer.
* @returns {LayerBuilder} The builder instance (for chaining).
* @template R, E
* @example
* builder.withCustomEventBus(MyCustomEventBus)
*/
withCustomEventBus(layer) {
this.customLayers.eventBus = layer;
return this;
}
/**
* Replaces the default financial calculation service with a custom implementation.
* @param {Layer.Layer<R, E, never>} layer - The custom financial calculation service layer.
* @returns {LayerBuilder} The builder instance (for chaining).
* @template R, E
* @example
* builder.withCustomFinancialCalculationService(MyCustomFinancialService)
*/
withCustomFinancialCalculationService(layer) {
this.customLayers.financialCalculationService = layer;
return this;
}
/**
* Finalizes the builder and returns the custom layer configuration.
* @returns {LayerBuilderConfig} The configuration object for custom layers.
* @example
* const config = builder.build();
*/
build() {
return {
...this.customLayers
};
}
};
function isLayer(value) {
return typeof value === "object" && value !== null && Layer.LayerTypeId in value;
}
__name(isLayer, "isLayer");
export { LayerBuilder };
//# sourceMappingURL=layer-builder.js.map
//# sourceMappingURL=layer-builder.js.map