Skip to content

Commit c0a46e2

Browse files
committed
Review
1 parent ba65a89 commit c0a46e2

1 file changed

Lines changed: 34 additions & 27 deletions

File tree

  • content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/consistency-checks.md

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
title: "Consistency Checks for Custom Blob Documents"
33
linktitle: "Consistency Checks"
44
url: /apidocs-mxsdk/apidocs/web-extensibility-api-11/consistency-checks/
5+
description: "Describes how to define consistency checks for custom blob documents in Studio Pro extensions."
56
---
67

8+
## Introduction
9+
10+
Consistency checks allow your extension to validate custom blob documents and display errors, warnings, and deprecation notices in Studio Pro's **Errors** pane. These checks run automatically before deployment and whenever referenced elements change, ensuring your documents remain valid throughout the development lifecycle.
11+
712
## Prerequisites
813

9-
* This how-to uses the results of [Get Started with the Web Extensibility API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/getting-started/).
10-
* Make sure you are familiar with creating custom documents as described in [Custom Blob Documents](/apidocs-mxsdk/apidocs/web-extensibility-api-11/custom-blob-documents/).
14+
* This how-to uses the results of [Get Started with the Web Extensibility API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/getting-started/). Complete that how-to before starting this one.
15+
* Familiarize yourself with creating custom documents as described in [Custom Blob Documents](/apidocs-mxsdk/apidocs/web-extensibility-api-11/custom-blob-documents/).
1116

1217
{{% alert color="warning" %}}
13-
If you try to change the blob document or any of its dependencies during the consistency checks, you will get an exception on save. Saving is not allowed because you might interfere with the checks and make the app invalid.
18+
Do not modify the blob document or its dependencies during consistency checks. Saving is blocked at this point because changes could interfere with the checks and leave the app in an invalid state.
1419
{{% /alert %}}
1520

16-
## Introduction
17-
18-
Consistency checks allow your extension to validate custom blob documents and display errors, warnings, and deprecation notices in Studio Pro's Errors pane. These checks run automatically before deployment and whenever referenced elements change, ensuring your documents remain valid throughout the development lifecycle.
19-
2021
## Basic Example
2122

22-
Based on the code described in [Custom Blob Documents](/apidocs-mxsdk/apidocs/web-extensibility-api-11/custom-blob-documents/), you will define consistency checks for the first name field, where you can learn how to display errors, warnings, and deprecation notices in Studio Pro's Errors pane.
23+
Based on the code described in [Custom Blob Documents](/apidocs-mxsdk/apidocs/web-extensibility-api-11/custom-blob-documents/), this section defines consistency checks for the first name field and shows how to display errors, warnings, and deprecation notices in Studio Pro's **Errors** pane.
2324

2425
```typescript {hl_lines=["10-13", "19-58", "69"]}
2526
import {
@@ -105,16 +106,16 @@ export const component: IComponent = {
105106
}
106107
```
107108

108-
Every `errorCode` returned by your check function **must** be listed in `reservedErrorCodes`. At the registration time you cannot use Mendix reserved prefixes or your registration will fail: `cw`, `ce`, `ci`. Make sure that your check only returns errors with codes included in the `reservedErrorCodes` list, otherwise your check will fail and a generic error message will show in the Errors Pane.
109+
Every `errorCode` returned by your check function must be listed in `reservedErrorCodes`. You cannot use the Mendix reserved prefixes `cw`, `ce`, or `ci`during registration or the check will fail and a generic error message will appear in the **Errors** pane.
109110

110-
{{< figure src="/attachments/apidocs-mxsdk/apidocs/extensibility-api/web/consistencyChecks/generic_error.png" >}}
111+
{{< figure src="/attachments/apidocs-mxsdk/apidocs/extensibility-api/web/consistencyChecks/generic_error.png" alt="" >}}
111112

112-
This error will also show if one of your checks throw an unexpected exception. In order to know what the exception was, you can check the Mendix logs.
113+
This error also appears if one of your checks throws an unexpected exception. To find out what the exception was, check the Mendix logs.
113114

114-
It is important to remember that you are not allowed to call save operations on the model api when the consistency checks are running. An error will throw and you will see the generic error in the Errors Pane again.
115+
You cannot call save operations on the model API while consistency checks are running. If you do, an error throws and the generic error appears in the **Errors** pane again.
115116

116117
{{% alert color="info" %}}
117-
The check function is async so you can use await when loading other model elements to validate references.
118+
The check function is async, so you can use `await` when loading other model elements to validate references.
118119
{{% /alert %}}
119120

120121
## ConsistencyError Properties
@@ -129,7 +130,7 @@ The check function is async so you can use await when loading other model elemen
129130

130131
## Checking References to Other Documents
131132

132-
When your document stores references to other model elements (microflows, constants, or other custom blob documents), you might want to validate that those elements still exist. If a user deletes a referenced microflow, your consistency check can report that error.
133+
If your document stores references to other model elements (microflows, constants, or other custom blob documents), you can validate that those elements still exist. If a user deletes a referenced microflow, your consistency check can report the error.
133134

134135
Replace your `src/main/index.ts` file with the following:
135136

@@ -408,15 +409,15 @@ export const component: IComponent = {
408409
```
409410

410411

411-
Return dependentElementIds to tell Studio Pro which elements your document depends on. When those elements change, your checks re-run automatically.
412+
Return `dependentElementIds` to tell Studio Pro which elements your document depends on. When those elements change, your checks rerun automatically.
412413

413414
{{% alert color="info" %}}
414415
Without dependency tracking, your checks only run during full consistency check runs. With dependency tracking, checks run immediately when referenced elements change.
415416
{{% /alert %}}
416417

417418
### Excluded Documents
418419

419-
If a document you reference is excluded you must check for it like this:
420+
If a document you reference is excluded, you must check for it using the following code:
420421

421422
```typescript
422423
const customDoc = await studioPro.app.model.customBlobDocuments.getDocumentById(refId);
@@ -431,9 +432,10 @@ if ("document" in customDoc && customDoc.document.excluded) {
431432
```
432433

433434
### Changed Elements
434-
When one of your dependencies gets modified in Studio Pro, you should be notified, in case one of them is your dependency. Based on that change you might want to return a consistency error. In order to be notified of any element (document or entity) that has changed, you need to subscribe to the `documentsChanged` event.
435435

436-
Let's say you have a document type that contains multiple lists of dependencies, for microflows, entities, or other custom blob documents. Then for each of these types you can and update your document.
436+
When one of your dependencies gets modified in Studio Pro, you can return a consistency error based on that change. To be notified when any element (document or entity) changes, subscribe to the `documentsChanged` event.
437+
438+
For example, if you have a document type that contains multiple lists of dependencies for microflows, entities, or other custom blob documents, you can update your document for each of these types.
437439

438440
```typescript
439441
import { DocumentInfo, getStudioProApi } from "@mendix/extensions-api";
@@ -491,15 +493,18 @@ async function checkDependencyWasChanged(dependencies: Dependency[], documents:
491493
}
492494
```
493495

494-
By checking if any of the changed documents from the event payload are included in your dependencies, you can trigger the consistency checks to run again by updating the content of your blob document and running ` studioPro.app.model.customBlobDocuments.updateDocumentContent`. This way you can be sure your checks will be run again whenever one of your dependencies is modified from Studio Pro.
496+
By checking whether any of the changed documents from the event payload are included in your dependencies, you can trigger the consistency checks to run again by updating the content of your blob document using `studioPro.app.model.customBlobDocuments.updateDocumentContent`. This ensures your checks run again whenever one of your dependencies is modified in Studio Pro.
495497

496498

497499
### Renamed Elements
498-
If one of your dependencies gets renamed, you might want to know about it and update the names of the dependencies in your document. Studio Pro cannot automatically rename your dependencies, it can only let you know that the document matching the id now has a new name. It is up to you to update your dependency's name.
499500

500-
In order to be notified when a element (any document or entity) gets renamed, you need to subscribe to the `elementsRenamed` event. The event payload contains a list of `ElementRenameInfo`, which contains the old name, the new name, and the document type. You can then use the old name to search your dependencies, and if it exists, you can then update the dependency with its new name.
501+
If one of your dependencies gets renamed, you may need to update the dependency names in your document. Studio Pro cannot automatically rename your dependencies; it can only notify you that the document matching the ID now has a new name. It is up to you to update your dependency's name.
502+
503+
To be notified when an element (any document or entity) gets renamed, subscribe to the `elementsRenamed` event. The event payload contains a list of `ElementRenameInfo`, which includes the old name, the new name, and the document type. You can use the old name to search your dependencies, and if it exists, update the dependency with its new name.
501504

502-
**This is also very useful if you need to know if one of your dependencies has been moved to a different module. When entities or documents get moved between modules, their fully qualified name is changed, triggering the rename event.**
505+
{{% alert color="info" %}}
506+
This is also useful for detecting when one of your dependencies has been moved to a different module. When entities or documents move between modules, their fully qualified name changes, which triggers the rename event.
507+
{{% /alert %}}
503508

504509
```typescript
505510
import { getStudioProApi, StudioProApi } from "@mendix/extensions-api";
@@ -620,13 +625,15 @@ function checkDependencyRenamed(
620625
}
621626
```
622627

623-
As you can see, you search for your dependency by qualified name instead of id, by comparing it to the `oldName` property of the event's list payload. Once you rename your dependency, you then need to update your custom document's content.
628+
You search for your dependency by qualified name instead of ID, by comparing it to the `oldName` property of the event's list payload. After renaming your dependency, you must update your custom document's content.
624629

625-
Important to note that if a module gets renamed inside Studio Pro, you will need to update all the qualified names of your dependencies. So you can listen to the `elementsRenamed` event, and check for the type to be `Projects$Module`. That way you can be sure that your dependencies always have the correct qualified name. If a module gets renamed inside Studio Pro, the event only contains the module as the payload, not the documents that it contains. So it is up to the extension developer to update the dependencies that belong to the renamed module and update their qualified names.
630+
Note that if a module gets renamed in Studio Pro, you must update all the qualified names of your dependencies. Listen to the `elementsRenamed` event and check whether the type is `Projects$Module` to ensure your dependencies always have the correct qualified name. When a module is renamed in Studio Pro, the event payload contains only the module, not the documents it contains. It is up to the extension developer to update the qualified names of all dependencies belonging to the renamed module.
626631

627632
### Added Documents
628-
In order to detect a new document being added in Studio Pro, you need to subscribe to the `documentAdded` event in the `projectChanges` api. Keep in mind that this does not trigger if entities get added to a domain model, since entities are not documents, but the `documentsChanged` event will trigger in that case, with the `DomainModels$DomainModel` being the type of the document that has changed.
629-
Let's say you have a dependency on a microflow named "MySpecialMicroflow", and you have a consistency check that will show an error if this microflow gets deleted. If the user decides to resolve this error by adding another microflow with the same exact name, inside the same module, they would expect the error to go away. But since this new microflow's ID is different that the one you originally depended on, you need to update your dependency's ID with this new ID. So you can listen to the `documentAdded` event, and compare the dependencies by name, and when you find it, update the ID and then update your custom document.
633+
634+
To detect when a new document is added in Studio Pro, subscribe to the `documentAdded` event in the `projectChanges` API. Note that this does not trigger when entities are added to a domain model, because entities are not documents. In that case, the `documentsChanged` event triggers instead, with `DomainModels$DomainModel` as the document type.
635+
636+
For example, if you have a dependency on a microflow named *MySpecialMicroflow* and a consistency check that shows an error when that microflow is deleted, a user may resolve the error by adding a new microflow with the same name in the same module. Because the new microflow has a different ID than the original, you must update your dependency's ID. To do this, listen to the `documentAdded` event, compare dependencies by name, and when a match is found, update the ID and then update your custom document.
630637

631638
```typescript
632639
import { DocumentInfo, getStudioProApi } from "@mendix/extensions-api";
@@ -690,7 +697,7 @@ function dependencyWasRemovedAndReaddedWithSameName(dependencies: Dependency[],
690697
}
691698
```
692699

693-
If you need to know when an entity is removed, then added with one of the same name, you should use `documentsChanged` instead, as mentioned above, and retrieve the entities of the changed Domain Model in order to compare them to your current list of entity dependencies you have in your custom document. Then you can trigger the checks by saving the document.
700+
To detect when an entity is removed and then another one is added with the same name, use `documentsChanged` instead. Retrieve the entities of the changed domain model and compare them to your current list of entity dependencies in your custom document, then trigger the checks by saving the document.
694701

695702
```typescript
696703
/* eslint-disable no-console */

0 commit comments

Comments
 (0)