50 lines
2.0 KiB
TypeScript
50 lines
2.0 KiB
TypeScript
// The handlers of the module's procedures: each takes the service its kind may use and calls one use
|
|
// case. No rule lives here.
|
|
|
|
import { implement } from "@conusai-kit/core"
|
|
import { importApply, importList, productGet, productList, productSearch } from "../contract/index.js"
|
|
import { applyImport, listImports, listProducts, searchProducts } from "../core/catalog.js"
|
|
import { catalogServiceOf } from "./service.js"
|
|
|
|
export const productListImpl = implement(productList, ({ input, ctx }) =>
|
|
listProducts(catalogServiceOf(ctx.container, ctx.kind), {
|
|
...(input.after === undefined ? {} : { after: input.after }),
|
|
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
}),
|
|
)
|
|
|
|
export const productSearchImpl = implement(productSearch, ({ input, ctx }) =>
|
|
searchProducts(catalogServiceOf(ctx.container, ctx.kind), {
|
|
q: input.q,
|
|
...(input.by === undefined ? {} : { by: input.by }),
|
|
...(input.after === undefined ? {} : { after: input.after }),
|
|
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
}),
|
|
)
|
|
|
|
export const productGetImpl = implement(productGet, ({ input, ctx }) =>
|
|
catalogServiceOf(ctx.container, ctx.kind).getProduct(input.productId),
|
|
)
|
|
|
|
export const importListImpl = implement(importList, ({ input, ctx }) =>
|
|
listImports(catalogServiceOf(ctx.container, ctx.kind), {
|
|
...(input.after === undefined ? {} : { after: input.after }),
|
|
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
}),
|
|
)
|
|
|
|
export const importApplyImpl = implement(importApply, ({ input, ctx }) =>
|
|
applyImport(catalogServiceOf(ctx.container, "effect"), ctx.scope, {
|
|
fileHash: input.fileHash,
|
|
sourceName: input.sourceName,
|
|
format: input.format,
|
|
chunk: input.chunk,
|
|
finalChunk: input.finalChunk,
|
|
...(input.revision === undefined ? {} : { revision: input.revision }),
|
|
rows: input.rows,
|
|
requestId: input.requestId,
|
|
}),
|
|
)
|
|
|
|
export const CATALOG_PROCEDURES = [productListImpl, productSearchImpl, productGetImpl, importListImpl, importApplyImpl]
|