Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MS-3808 review sdk docs #9312

Draft
wants to merge 10 commits into
base: development
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ customer.location = { x: 100, y: 100 };
With these ingredients, you can create the two entities. Replace the snippet that creates a single entity in the script that you created in the [previous how-to steps](/apidocs-mxsdk/mxsdk/creating-your-first-script/) with the following snippet to create the two new entities:

```ts
const domainModel = await loadDomainModel(workingCopy);
const domainModel = await domainModelInterface.load();
const customer = domainmodels.Entity.createIn(domainModel);
customer.name = `Customer`;
customer.location = { x: 100, y: 100 };
Expand Down Expand Up @@ -148,14 +148,16 @@ In the Model SDK, the [`Entity.generalization`](https://apidocs.rnd.mendix.com/m
So, to set up entity `Customer` as a specialization of entity `Administration.Account`, you first need to look up the `Account` entity which [can be done in several ways](/apidocs-mxsdk/mxsdk/finding-things-in-the-model/). The following snippet looks up the `Account` entity in the `Administration` domain model, using the `findEntityByQualifiedName` function:

```ts
const systemUser = workingCopy.model().findEntityByQualifiedName(`Administration.Account`);
const systemUser = model.findEntityByQualifiedName(`Administration.Account`);
```

The `domainmodels.Generalization` instance that will be used to configure the `Account` instance can now be created. The `generalization` property is set to the `System.User` entity instance that was looked up:

```ts
const generalization = domainmodels.Generalization.createIn(customer);
generalization.generalization = systemUser;
if(systemUser){
const generalization = domainmodels.Generalization.createIn(customer);
generalization.generalization = systemUser;
}
```

Together, the creation of the `Customer` entity will look like the following code snippet. Replace the creation of the `customer` entity instance in the script with the following snippet:
Expand All @@ -166,8 +168,10 @@ customer.name = `Customer`;
customer.location = { x: 100, y: 100 };

const generalization = domainmodels.Generalization.createIn(customer);
const systemUser = workingCopy.model().findEntityByQualifiedName(`Administration.Account`);
generalization.generalization = systemUser;
const systemUser = model.findEntityByQualifiedName(`Administration.Account`);
if (systemUser) {
generalization.generalization = systemUser;
}
```

### Resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ After setting up all the prerequisites, you can start writing a first script tha

Don't forget to [set up your personal access token](/apidocs-mxsdk/mxsdk/set-up-your-pat/) before executing the script.

{{% alert color="warning" %}}
Working copy creation a resource intensive process, consider reusing previously created ones by invoking `app.getOnlineWorkingCopy(workingCopy.workingCopyId)`. All working copies are automatically deleted after 24 hours.
{{% /alert %}}

### Code Explanation

Here are some explanations about the script:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@ url: /apidocs-mxsdk/mxsdk/closing-the-server-connection/

The SDK observes the complete model using the [mobx](https://github.com/mobxjs/mobx) library. This means that any change you make to the model is immediately synced with the working copy on the server. Sending changes to the server happens in the background and automatically, so there is no explicit commit. However, sending changes might take a while and your script should not end before all changes are flushed. In particular, changes are by default sent in batches of 1000 or after 200ms, whichever happens first. To wait until all changes are submitted to the server, use the [`closeConnection`](https://apidocs.rnd.mendix.com/modelsdk/latest/classes/model.html#closeconnection) function of the `model` object.

This example shows the function `closeConnection`, which you can invoke when working with a `workingCopy` instance as a last step before the final commit:
This example shows the function `closeConnection`, which you can invoke when working with a `model` instance as a last step before the final commit:

```ts
async function closeConnection(workingCopy: OnlineWorkingCopy) {
await new Promise<void>((resolve, reject) => {
workingCopy.model().closeConnection(
() => {
console.log(`Closed connection to Model API successfully.`);
resolve();
},
(err) => {
console.error(`Failed to closed connection to Model API. Error: ${err}`);
reject();
}
);
async function closeConnection(model: IModel): Promise<void> {
return model
.closeConnection()
.then(() => {
console.log(`Closed connection to Model API successfully.`);
})
.catch((err) => {
console.error(`Failed to closed connection to Model API. Error: ${err}`);
});
}

```

Continue with [How to Find Things in the Model](/apidocs-mxsdk/mxsdk/finding-things-in-the-model/).
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ url: /apidocs-mxsdk/mxsdk/finding-things-in-the-model/

## Introduction

The `model` object you get back from `workingCopy.model()` can be used to find and even manipulate units and elements. It provides three different means with which you can find units and elements.
The `model` object you get back from `workingCopy.openModel()` can be used to find and even manipulate units and elements. It provides three different means with which you can find units and elements.

## The model.root Property

Expand All @@ -14,7 +14,8 @@ The `root` object refers to the `root` app node in the **App Explorer** in Studi
For example, this snippet finds the name of the first attribute of the `Customer` entity in the first module of your app:

```js
const model = workingCopy.model();
const model = await workingCopy.openModel();

const domainModel = model.root.modules[0].domainModel;
const customerEntity = domainModel.entities.filter(entity => entity.name === "Customer")[0]

Expand All @@ -40,7 +41,9 @@ For all the referable concepts in a model (both units, such as a page, as well a

```js
const customerEntity = model.findEntityByQualifiedName("Customers.Customer");
const attributeName = customerEntity.attributes[0].name;
if (customerEntity) {
const attributeName = customerEntity.attributes[0].name;
}
```

For more information, see [How to Load Units and Elements](/apidocs-mxsdk/mxsdk/loading-units-and-elements/).
Expand All @@ -50,7 +53,7 @@ For more information, see [How to Load Units and Elements](/apidocs-mxsdk/mxsdk/
Implement this snippet to fetch information on all the Marketplace modules used in your app:

```js
const model = workingCopy.model();
const model = workingCopy.openModel();
model.allModules()
.filter(module => module.fromAppStore === true)
.forEach(module =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ Since a unit might already have been loaded before, you are also allowed to use
The following (slightly) contrived example demonstrates the behavior of `load`. The type information is made explicit in this example for demonstration purposes, but you can just omit this code since the TypeScript compiler will infer it. Note that this example is contrived: a normal flow would be to call `load` on the `domainModel` and work with the fully-loaded domain model inside its callback.

```ts
import {domainmodels} from "mendixmodelsdk";

const model = workingCopy.model();
const model = await workingCopy.openModel();

// at first, only interfaces are available:
const domainModel = model.allDomainModels()[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ To set up your development tools, follow these steps:

```bash
$ node --version
v14.15.0
v18.20.8
```

For Debian-based Linux distributions such as Ubuntu, please refer to [NodeSource Node.js Binary Distributions](https://github.com/nodesource/distributions#user-content-installation-instructions) to properly set up your apt-get sources.

In the rest of the how-tos, in blocks such as the above, lines starting with a `$` represent commands to type into a terminal. Sometimes a line follows without a $, represents output of the command.

3. Install [Visual Studio Code](https://code.visualstudio.com/) (not to be confused with Visual Studio), a text editor/IDE with good support for [TypeScript](https://www.typescriptlang.org/). Make sure you have a recent version (v1.11.0+); check the version you are using through Help > About when you have Code opened.
4. Install TypeScript 4.4.3 or higher with [`npm`](https://www.npmjs.com/) (or [`yarn`](https://yarnpkg.com/)), Node.js's package manager:
4. Install TypeScript 4.6.2 or higher with [`npm`](https://www.npmjs.com/) (or [`yarn`](https://yarnpkg.com/)), Node.js's package manager:

```bash
$ npm install -g typescript
Expand All @@ -52,7 +52,7 @@ To set up your development tools, follow these steps:

```bash
$ tsc --version
Version 4.4.3 (or higher)
Version 4.6.2 (or higher)
```

If the version number is much lower, it could be that you also have an outdated TypeScript SDK on your system, left over from a previous installation. You can either uninstall the old TypeScript SDK, or bypass it by removing the old TypeScript SDK from your system's PATH environment variable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ This how-to provides guidance on using the Platform SDK to do the following:
The entry point for the Mendix Platform SDK is `MendixPlatformClient`. In most cases, you will need to instantiate a new object from this class:

```ts
import { MendixPlatformClient } from "mendixplatformsdk";

const client = new MendixPlatformClient();
```

Expand All @@ -31,6 +33,8 @@ The platform client allows you to create a new Mendix app by simply passing the

```ts
const app = await client.createNewApp("My new App");

console.log(`App created with ID: ${app.appId}`);
```

You can pass the following options to `createNewApp`:
Expand All @@ -45,16 +49,14 @@ You can pass the following options to `createNewApp`:

If both `templateDownloadURL` and `templateId` are left blank, the app will be created using the standard blank app template in the latest Mendix version.

Here is an example for creating a Mendix app based on the [Asset Manager App](https://marketplace.mendix.com/link/component/69674) template:
Here is an example for creating a Mendix app based on the [Blank GenAI App](https://marketplace.mendix.com/link/component/227934) template:

```ts
const app = await client.createNewApp("My Asset Management", {
templateId: "6e66fe4d-6e96-4eb8-a2b6-a61dec37a799"
const app = await client.createNewApp("My GenAI App", {
templateId: "ba6ca01b-e2a4-45fa-870d-9e28b6acb845"
});
```

{{% alert color="warning" %}}The [Asset Manager App](https://marketplace.mendix.com/link/component/69674) template is deprecated and was created using Studio Pro 8.14.0. You cannot open it directly in Studio Pro 10 versions. To be able to use it in Studio Pro 10, you need to first upgrade it to a Studio Pro 9 app and then upgrade it to a Studio Pro 10 app. For more instructions, see the [Prerequisites](/refguide/extending-your-application-with-custom-java/#prerequisites) section in *Extending Your Application with Custom Java*.{{% /alert %}}

## Opening an Existing App {#opening-existing-app}

The platform client allows you to open an existing app using the app ID:
Expand All @@ -72,7 +74,13 @@ You can get the **App ID** (represented as **Project ID**) in the app's [Setting
From the app object, you can get some information about its repository (such as the repository type, URL, and default branch name):

```ts
const repositoryInfo = app.getRepositoryInfo();
const repository = app.getRepository();

const repositoryInfo = await repository.getInfo();
console.log("Repository Info: ", repositoryInfo);

const commitsIDs = (await repository.getBranchCommits("main")).items.map(commit => commit.id);
console.log("Repository commits IDs: ", commitsIDs);
```

## Deleting an App {#deleting}
Expand All @@ -93,8 +101,14 @@ To change your app, you need to create a temporary working copy of a particular

```ts
const workingCopy = await app.createTemporaryWorkingCopy("main");

console.log(`Working ID: ${workingCopy.workingCopyId}`);
```

{{% alert color="warning" %}}
Working copy creation a resource intensive process, consider reusing previously created ones by invoking `app.getOnlineWorkingCopy(workingCopy.workingCopyId)`. All working copies are automatically deleted after 24 hours.
{{% /alert %}}

You can pass the following options to `createTemporaryWorkingCopy`:

| Name | Description |
Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/apidocs-mxsdk/mxsdk/sdk-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ To set up the Mendix Platform and Model SDKs, perform the following steps using

1. `npm init --yes`
2. `npm install -g typescript`
3. `npm install mendixmodelsdk mendixplatformsdk when @types/when --save`
3. `npm install mendixmodelsdk mendixplatformsdk --save`
4. `tsc --init`

### Detailed Resources
Expand Down