import { createMenuCrud } from "./crud/menus.crud" ; import { createCategoriesCrud } from "./crud/categories.crud" ; import { createPageCrud } from "./crud/pages.crud" ; import { createPageValidation } from "./crud/pages.validation" ; import { createPageElementsCrud } from "./crud/pageElements.crud" ; import { createSettingsCrud } from "./crud/settings.crud" ; import { createSystemCrud } from "./crud/system.crud" ; import { ContextPlugin } from "@webiny/handler" ; import { PbContext } from "~/graphql/types" ; import WebinyError from "@webiny/error" ; import { JsonpackContentCompressionPlugin } from "~/plugins/JsonpackContentCompressionPlugin" ; import { createTopic } from "@webiny/pubsub" ; import { PageBuilderStorageOperations } from "~/types" ; export interface Params { storageOperations : PageBuilderStorageOperations ; } const createPageBuilder = ( ) => { let prerenderingHandlers = { render : async ( ) => { } , flush : async ( ) => { } } ; return { onPageBeforeRender : createTopic ( "pageBuilder.onBeforeRenderPage" ) , onPageAfterRender : createTopic ( "pageBuilder.onAfterRenderPage" ) , onPageBeforeFlush : createTopic ( "pageBuilder.onBeforeFlushPage" ) , onPageAfterFlush : createTopic ( "pageBuilder.onAfterFlushPage" ) , setPrerenderingHandlers : handlers => { prerenderingHandlers = handlers ; } , getPrerenderingHandlers : ( ) => prerenderingHandlers } ; } ; const setup = ( params ) => { const { storageOperations } = params ; return new ContextPlugin < PbContext > ( async ( context ) => { if ( context . pageBuilder ) { throw new WebinyError ( "PbContext setup must be first loaded." , "CONTEXT_SETUP_ERROR" ) ; } const system = await createSystemCrud ( { context , storageOperations } ) ; const settings = createSettingsCrud ( { context , storageOperations } ) ; const menus = createMenuCrud ( { context , storageOperations } ) ; const categories = createCategoriesCrud ( { context , storageOperations } ) ; const pageElements = createPageElementsCrud ( { context , storageOperations } ) ; const pages = createPageCrud ( { context , storageOperations } ) ; context . pageBuilder = { ... createPageBuilder ( ) , ... system , ... settings , ... menus , ... pages , ... pageElements , ... categories } ; } ) ; } ; export const createCrud = ( params ) => { return [ new JsonpackContentCompressionPlugin ( ) , setup ( params ) , createPageValidation ( ) ] ; } ;