Skip to content

Commit

Permalink
fix(api-headless-cms): export createModelField and isHeadlessCmsReady (
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 authored Feb 22, 2024
1 parent 8ed17c6 commit 5678056
Show file tree
Hide file tree
Showing 25 changed files with 79 additions and 114 deletions.
5 changes: 3 additions & 2 deletions packages/api-aco/src/createAcoContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import WebinyError from "@webiny/error";
import { ContextPlugin } from "@webiny/api";
import { I18NLocale } from "@webiny/api-i18n/types";
import { Tenant } from "@webiny/api-tenancy/types";
import { isHeadlessCmsReady } from "@webiny/api-headless-cms";
import { createAcoHooks } from "~/createAcoHooks";
import { createAcoStorageOperations } from "~/createAcoStorageOperations";
import { isInstallationPending } from "~/utils/isInstallationPending";
import { AcoContext, CreateAcoParams, Folder, IAcoAppRegisterParams } from "~/types";
import { createFolderCrudMethods } from "~/folder/folder.crud";
import { createSearchRecordCrudMethods } from "~/record/record.crud";
Expand Down Expand Up @@ -185,9 +185,10 @@ export const createAcoContext = (params: CreateAcoContextParams = {}) => {
/**
* We can skip the ACO initialization if the installation is pending.
*/
if (isInstallationPending(context)) {
if (!(await isHeadlessCmsReady(context))) {
return;
}

await context.benchmark.measure("aco.context.setup", async () => {
await setupAcoContext(context, params);
});
Expand Down
12 changes: 4 additions & 8 deletions packages/api-aco/src/createAcoModels.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { CmsContext } from "@webiny/api-headless-cms/types";
import { createFilterModelDefinition } from "~/filter/filter.model";
import { createFolderModelDefinition } from "~/folder/folder.model";
import { createSearchModelDefinition } from "~/record/record.model";
import { createFilterModel } from "~/filter/filter.model";
import { createFolderModel } from "~/folder/folder.model";
import { createSearchModel } from "~/record/record.model";
import { modelFactory } from "~/utils/modelFactory";

export const createAcoModels = (context: CmsContext) => {
/**
* Create CmsModel plugins.
*/
const modelDefinitions = [
createFolderModelDefinition(),
createSearchModelDefinition(),
createFilterModelDefinition()
];
const modelDefinitions = [createFolderModel(), createSearchModel(), createFilterModel()];
const cmsModelPlugins = modelDefinitions.map(modelDefinition => {
return modelFactory({
modelDefinition
Expand Down
6 changes: 3 additions & 3 deletions packages/api-aco/src/filter/filter.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createModelField } from "~/utils/createModelField";
import { createPrivateModelDefinition } from "@webiny/api-headless-cms";
import { createPrivateModel } from "@webiny/api-headless-cms";
import { CmsModelField } from "@webiny/api-headless-cms/types";

const name = () =>
Expand Down Expand Up @@ -145,8 +145,8 @@ const value = () =>

export const FILTER_MODEL_ID = "acoFilter";

export const createFilterModelDefinition = () => {
return createPrivateModelDefinition({
export const createFilterModel = () => {
return createPrivateModel({
name: "ACO - Filter",
modelId: FILTER_MODEL_ID,
titleFieldId: "name",
Expand Down
6 changes: 3 additions & 3 deletions packages/api-aco/src/folder/folder.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createModelField } from "~/utils/createModelField";
import { createPrivateModelDefinition } from "@webiny/api-headless-cms";
import { createPrivateModel } from "@webiny/api-headless-cms";

const titleField = () =>
createModelField({
Expand Down Expand Up @@ -115,8 +115,8 @@ const permissionsField = () =>

export const FOLDER_MODEL_ID = "acoFolder";

export const createFolderModelDefinition = () => {
return createPrivateModelDefinition({
export const createFolderModel = () => {
return createPrivateModel({
name: "ACO - Folder",
modelId: FOLDER_MODEL_ID,
titleFieldId: "title",
Expand Down
8 changes: 4 additions & 4 deletions packages/api-aco/src/record/record.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CmsModelField } from "@webiny/api-headless-cms/types";
import { createModelField } from "~/utils/createModelField";
import { createPrivateModelDefinition } from "@webiny/api-headless-cms";
import { createPrivateModel } from "@webiny/api-headless-cms";

const typeField = () =>
createModelField({
Expand Down Expand Up @@ -92,14 +92,14 @@ const tagsField = () =>

export const SEARCH_RECORD_MODEL_ID = "acoSearchRecord";

interface CreateSearchModelDefinitionParams {
interface CreateSearchModelParams {
fields?: CmsModelField[];
}

export const DEFAULT_FIELDS = ["type", "title", "content", "location", "data", "tags"];

export const createSearchModelDefinition = (params?: CreateSearchModelDefinitionParams) => {
return createPrivateModelDefinition({
export const createSearchModel = (params?: CreateSearchModelParams) => {
return createPrivateModel({
name: "ACO - Search Record",
modelId: SEARCH_RECORD_MODEL_ID,
titleFieldId: "title",
Expand Down
15 changes: 0 additions & 15 deletions packages/api-aco/src/utils/isInstallationPending.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPrivateModelDefinition } from "@webiny/api-headless-cms";
import { createPrivateModel } from "@webiny/api-headless-cms";
import { createModelField } from "./utils";

const bodyField = () =>
Expand Down Expand Up @@ -44,8 +44,8 @@ const stepField = () =>

export const CHANGE_REQUEST_MODEL_ID = "apwChangeRequestModelDefinition";

export const createChangeRequestModelDefinition = () => {
return createPrivateModelDefinition({
export const createChangeRequestModel = () => {
return createPrivateModel({
name: "APW - Change Request",
modelId: CHANGE_REQUEST_MODEL_ID,
titleFieldId: "title",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPrivateModelDefinition } from "@webiny/api-headless-cms";
import { createPrivateModel } from "@webiny/api-headless-cms";
import { createModelField } from "./utils";

const commentBody = () =>
Expand Down Expand Up @@ -48,8 +48,8 @@ interface CreateCommentModelDefinitionParams {

export const COMMENT_MODEL_ID = "apwCommentModelDefinition";

export const createCommentModelDefinition = ({ modelId }: CreateCommentModelDefinitionParams) => {
return createPrivateModelDefinition({
export const createCommentModel = ({ modelId }: CreateCommentModelDefinitionParams) => {
return createPrivateModel({
name: "APW - Comment",
modelId: COMMENT_MODEL_ID,
titleFieldId: "step",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPrivateModelDefinition } from "@webiny/api-headless-cms";
import { createPrivateModel } from "@webiny/api-headless-cms";
import { CmsModelField } from "@webiny/api-headless-cms/types";
import { createModelField } from "./utils";
import { stepTitleField, stepTypeField, stepIdField, stepReviewersField } from "./workflow.model";
Expand Down Expand Up @@ -279,10 +279,10 @@ interface CreateContentReviewModelDefinitionParams {

export const CONTENT_REVIEW_MODEL_ID = "apwContentReviewModelDefinition";

export const createContentReviewModelDefinition = ({
export const createContentReviewModel = ({
reviewerModelId
}: CreateContentReviewModelDefinitionParams) => {
return createPrivateModelDefinition({
return createPrivateModel({
name: "APW - Content Review",
modelId: CONTENT_REVIEW_MODEL_ID,
titleFieldId: "content",
Expand Down
20 changes: 10 additions & 10 deletions packages/api-apw/src/storageOperations/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import WebinyError from "@webiny/error";
import { CmsModelPlugin, createCmsModel } from "@webiny/api-headless-cms";
import { createWorkflowModelDefinition } from "./workflow.model";
import { createContentReviewModelDefinition } from "./contentReview.model";
import { createReviewerModelDefinition } from "./reviewer.model";
import { createCommentModelDefinition } from "./comment.model";
import { createChangeRequestModelDefinition } from "./changeRequest.model";
import { createWorkflowModel } from "./workflow.model";
import { createContentReviewModel } from "./contentReview.model";
import { createReviewerModel } from "./reviewer.model";
import { createCommentModel } from "./comment.model";
import { createChangeRequestModel } from "./changeRequest.model";
import { CmsContext } from "@webiny/api-headless-cms/types";
import { isInstallationPending } from "~/plugins/utils";

Expand Down Expand Up @@ -33,15 +33,15 @@ export const createApwModels = (context: CmsContext) => {
/**
* Create CmsModel plugins.
*/
const changeRequestModelDefinition = createChangeRequestModelDefinition();
const reviewerModelDefinition = createReviewerModelDefinition();
const workflowModelDefinition = createWorkflowModelDefinition({
const changeRequestModelDefinition = createChangeRequestModel();
const reviewerModelDefinition = createReviewerModel();
const workflowModelDefinition = createWorkflowModel({
reviewerModelId: reviewerModelDefinition.modelId
});
const commentModelDefinition = createCommentModelDefinition({
const commentModelDefinition = createCommentModel({
modelId: changeRequestModelDefinition.modelId
});
const contentReviewModelDefinition = createContentReviewModelDefinition({
const contentReviewModelDefinition = createContentReviewModel({
reviewerModelId: reviewerModelDefinition.modelId
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createModelField } from "./utils";
import { createPrivateModelDefinition } from "@webiny/api-headless-cms";
import { createPrivateModel } from "@webiny/api-headless-cms";

const idField = () =>
createModelField({
Expand Down Expand Up @@ -61,8 +61,8 @@ const emailField = () =>

export const REVIEWER_MODEL_ID = "apwReviewerModelDefinition";

export const createReviewerModelDefinition = () => {
return createPrivateModelDefinition({
export const createReviewerModel = () => {
return createPrivateModel({
name: "APW - Reviewer",
titleFieldId: "displayName",
modelId: REVIEWER_MODEL_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPrivateModelDefinition } from "@webiny/api-headless-cms";
import { createPrivateModel } from "@webiny/api-headless-cms";
import { CmsModelField } from "@webiny/api-headless-cms/types";
import { createModelField } from "./utils";
import { WorkflowScopeTypes } from "~/types";
Expand Down Expand Up @@ -208,10 +208,8 @@ interface CreateWorkflowModelDefinitionParams {

export const WORKFLOW_MODEL_ID = "apwWorkflowModelDefinition";

export const createWorkflowModelDefinition = ({
reviewerModelId
}: CreateWorkflowModelDefinitionParams) => {
return createPrivateModelDefinition({
export const createWorkflowModel = ({ reviewerModelId }: CreateWorkflowModelDefinitionParams) => {
return createPrivateModel({
name: "APW - Workflow",
/**
* Id of the model cannot be appWorkflow because it clashes with the GraphQL types for APW.
Expand Down
10 changes: 4 additions & 6 deletions packages/api-file-manager/src/FileManagerContextSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { createFileManager, FileManagerConfig } from "~/createFileManager";
import { FileStorage } from "~/storage/FileStorage";
import WebinyError from "@webiny/error";
import { SecurityPermission } from "@webiny/api-security/types";
import { isInstallationPending } from "~/cmsFileStorage/isInstallationPending";
import { createFileModel } from "~/cmsFileStorage/createFileManagerPlugins";
import { FILE_MODEL_ID } from "~/cmsFileStorage/file.model";
import { createFileModel, FILE_MODEL_ID } from "~/cmsFileStorage/file.model";
import { CmsFilesStorage } from "~/cmsFileStorage/CmsFilesStorage";
import { CmsModelModifierPlugin } from "~/modelModifier/CmsModelModifier";
import { CmsModelPlugin } from "@webiny/api-headless-cms";
import { CmsModelPlugin, isHeadlessCmsReady } from "@webiny/api-headless-cms";
import { FilesPermissions } from "~/createFileManager/permissions/FilesPermissions";

export class FileManagerContextSetup {
Expand Down Expand Up @@ -78,15 +76,15 @@ export class FileManagerContextSetup {
}

private async setupCmsStorageOperations(aliases: FileManagerAliasesStorageOperations) {
if (isInstallationPending({ tenancy: this.context.tenancy, i18n: this.context.i18n })) {
if (!(await isHeadlessCmsReady(this.context))) {
console.log("Installation pending!");
return;
}

const withPrivateFiles = this.context.wcp.canUsePrivateFiles();

// This registers code plugins (model group, models)
const { fileModelDefinition } = createFileModel({ withPrivateFiles });
const fileModelDefinition = createFileModel({ withPrivateFiles });

const modelModifiers = this.context.plugins.byType<CmsModelModifierPlugin>(
CmsModelModifierPlugin.type
Expand Down

This file was deleted.

7 changes: 3 additions & 4 deletions packages/api-file-manager/src/cmsFileStorage/file.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createPrivateModelDefinition } from "@webiny/api-headless-cms";
import { createModelField } from "./createModelField";
import { createPrivateModel, createModelField } from "@webiny/api-headless-cms";

const required = () => {
return {
Expand Down Expand Up @@ -160,7 +159,7 @@ interface CreateFileModelDefinitionParams {
withPrivateFiles: boolean;
}

export const createFileModelDefinition = (params: CreateFileModelDefinitionParams) => {
export const createFileModel = (params: CreateFileModelDefinitionParams) => {
const fields = [
locationField(),
nameField(),
Expand All @@ -176,7 +175,7 @@ export const createFileModelDefinition = (params: CreateFileModelDefinitionParam
fields.push(accessControlField());
}

return createPrivateModelDefinition({
return createPrivateModel({
name: "FmFile",
modelId: FILE_MODEL_ID,
titleFieldId: "name",
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions packages/api-file-manager/src/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createBaseSchema } from "~/graphql/baseSchema";
import { ContextPlugin } from "@webiny/api";
import { isHeadlessCmsReady } from "@webiny/api-headless-cms";
import { CmsModel } from "@webiny/api-headless-cms/types";
import { createFieldTypePluginRecords } from "@webiny/api-headless-cms/graphql/schema/createFieldTypePluginRecords";
import { createGraphQLSchemaPluginFromFieldPlugins } from "@webiny/api-headless-cms/utils/getSchemaFromFieldPlugins";
import { createBaseSchema } from "~/graphql/baseSchema";
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
import { createFilesSchema } from "~/graphql/filesSchema";
import { isInstallationPending } from "~/cmsFileStorage/isInstallationPending";
import { getFileByUrl } from "~/graphql/getFileByUrl";
import { FileManagerContext } from "~/types";

Expand All @@ -15,7 +15,7 @@ export const createGraphQLSchemaPlugin = () => {
// Files schema is generated dynamically, based on a CMS model, so we need to
// register it from a ContextPlugin, to perform additional bootstrap.
new ContextPlugin<FileManagerContext>(async context => {
if (isInstallationPending(context)) {
if (!(await isHeadlessCmsReady(context))) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Plugin } from "@webiny/plugins";
import { CmsModelField as BaseModelField } from "@webiny/api-headless-cms/types";
import { CmsPrivateModelFull, createModelField } from "@webiny/api-headless-cms";
import { FILE_MODEL_ID } from "~/cmsFileStorage/file.model";
import { createModelField } from "~/cmsFileStorage/createModelField";
import { CmsPrivateModelFull } from "@webiny/api-headless-cms";

type CmsModelField = Omit<BaseModelField, "storageId"> & { bulkEdit?: boolean };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
CmsGroup,
createCmsGroup,
createCmsModel,
createPrivateModelDefinition
createPrivateModel
} from "@webiny/api-headless-cms";

export const createMockModels = () => {
Expand Down Expand Up @@ -64,7 +64,7 @@ export const createMockModels = () => {
titleFieldId: "title"
}),
createCmsModel(
createPrivateModelDefinition({
createPrivateModel({
modelId: "tag",
name: "Tag",
fields: [],
Expand Down
2 changes: 2 additions & 0 deletions packages/api-headless-cms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { createFieldConverters } from "~/fieldConverters";
import { createExportGraphQL } from "~/export";
import { createStorageTransform } from "~/storage";
import { createLexicalHTMLRenderer } from "./htmlRenderer/createLexicalHTMLRenderer";
export * from "./utils/isHeadlessCmsReady";
export * from "./utils/createModelField";

export type CreateHeadlessCmsGraphQLParams = CreateGraphQLParams;
export const createHeadlessCmsGraphQL = (params: CreateHeadlessCmsGraphQLParams = {}) => {
Expand Down
Loading

0 comments on commit 5678056

Please sign in to comment.