UNPKG

dbaas

Version:

Database as a service. Expose db to REST and GraphQL.

37 lines 1.35 kB
import { ItemsService } from "directus"; function createItemsService(collectionName, reqOrFilterCtxOrActionCtx, options) { let itemsService; if ("database" in reqOrFilterCtxOrActionCtx) { // 2nd param is FilterHookContext | ActionHookContext const filterCtxOrActionCtx = reqOrFilterCtxOrActionCtx; itemsService = new ItemsService(collectionName, { schema: filterCtxOrActionCtx.schema, knex: filterCtxOrActionCtx.database, ...options, accountability: { ...filterCtxOrActionCtx.accountability, ...options?.accountability, }, }); } else if ("url" in reqOrFilterCtxOrActionCtx) { // 2nd param is express Request const req = reqOrFilterCtxOrActionCtx; itemsService = new ItemsService(collectionName, { schema: req.schema, ...options, accountability: { // Satisfy required type ...{ role: null }, ...req.accountability, ...options?.accountability, }, }); } else { throw new Error(`Invalid parameters type passed to ${createItemsService.name}`); } return itemsService; } export default createItemsService; //# sourceMappingURL=createItemsService.js.map