@tridion-sites/models 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +72 -0
- package/dist/index.d.ts +11 -0
- package/package.json +2 -9
package/CHANGELOG.md
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Tridion Sites models for Extensions
|
|
2
|
+
|
|
3
|
+
This NPM package provides a set of domain models specifically designed for frontend development of Tridion Sites. These models encapsulate domain-specific logic and provide a convenient abstraction for interacting with the backend data.
|
|
4
|
+
|
|
5
|
+
## Note
|
|
6
|
+
|
|
7
|
+
Due to reliance on various functionality provided at runtime by Tridion Sites, this package is not suitable for standalone usage and can only be utilized as a part of an extension.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Class-based definitions allow for easy item type checks
|
|
12
|
+
- Quality of life utilities provided as class instance methods
|
|
13
|
+
- Handling of TCM / ECL URI formats
|
|
14
|
+
- Easy conversion from and to `@tridion-sites/open-api-client` objects
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
To install `@tridion-sites/models`, you can use npm or yarn:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
$ npm install @tridion-sites/models
|
|
22
|
+
# or
|
|
23
|
+
$ yarn add @tridion-sites/models
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Mapping to and from the backend data
|
|
27
|
+
|
|
28
|
+
### Converting from a `@tridion-sites/open-api-client` response to a model
|
|
29
|
+
|
|
30
|
+
Primary utility methods for conversion of the backend DTOs to models are:
|
|
31
|
+
|
|
32
|
+
- `tryMapToModel<TModel>(backendDto)` - maps provided dto to a model, returns `undefined` on failure.
|
|
33
|
+
<b>Important</b>: generic argument is provided to simplify usage of the utility. It doesn't check that the provided type actually corresponds with the realtime type after the conversion.
|
|
34
|
+
- `mapToModel<TModel>(backendDto)` - convenience method that throws an error instead of returning `undefined` if conversion has failed.
|
|
35
|
+
- `mapToModels<TModel>(backendDto[])` - maps an array of backend DTOs to models, returning only successfully mapped objects.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import type { ActivityInstance, ItemUri } from '@tridion-sites/models';
|
|
39
|
+
import { mapToModel } from '@tridion-sites/models';
|
|
40
|
+
import { ItemsService } from '@tridion-sites/open-api-client';
|
|
41
|
+
|
|
42
|
+
const getActivityById = async (activityId: ItemUri) => {
|
|
43
|
+
const activity = await ItemsService.getItem(activityId.asString);
|
|
44
|
+
return mapToModel<ActivityInstance>(activity);
|
|
45
|
+
};
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Converting from a model to a `@tridion-sites/open-api-client` DTO
|
|
49
|
+
|
|
50
|
+
Every model contains `.getInternalModel()` method that allows to get the underlying backend DTO.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { IdentifiableObject } from '@tridion-sites/models';
|
|
54
|
+
import { ItemsService } from '@tridion-sites/open-api-client';
|
|
55
|
+
|
|
56
|
+
const updateItem = async (item: IdentifiableObject) => {
|
|
57
|
+
const backendDto = item.getInternalModel();
|
|
58
|
+
await ItemsService.update(backendDto.Id, backendDto);
|
|
59
|
+
};
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Item URI handling
|
|
63
|
+
|
|
64
|
+
There are 2 primary methods for parsing string URIs:
|
|
65
|
+
|
|
66
|
+
- `tryParseItemUri` - parses a string into an ItemUri object. Returns `undefined` if the conversion has failed
|
|
67
|
+
- `parseItemUri` - convenience method that throws an error instead of returning `undefined` if conversion has failed.
|
|
68
|
+
|
|
69
|
+
## API Documentation
|
|
70
|
+
|
|
71
|
+
Documentation for all available models, their methods and model utilities can be found at
|
|
72
|
+
http://developers.rws.com/tridion-sites-extensions-api-docs/models.html
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This NPM package provides a set of domain models specifically designed for frontend development of Tridion Sites.
|
|
3
|
+
* These models encapsulate domain-specific logic and provide a convenient abstraction for interacting with the backend data.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Due to reliance on various functionality provided at runtime by Tridion Sites,
|
|
7
|
+
* this package is not suitable for standalone usage and can only be utilized as a part of an extension.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
import type { AccessControlEntry as AccessControlEntry_2 } from '@tridion-sites/open-api-client';
|
|
2
13
|
import type { AccessControlList as AccessControlList_2 } from '@tridion-sites/open-api-client';
|
|
3
14
|
import type { AccessToken as AccessToken_2 } from '@tridion-sites/open-api-client';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tridion-sites/models",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Tridion Sites models",
|
|
5
5
|
"author": "RWS",
|
|
6
6
|
"homepage": "https://www.rws.com",
|
|
@@ -9,13 +9,6 @@
|
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"module": "dist/index.js",
|
|
11
11
|
"typings": "dist/index.d.ts",
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://stash.sdl.com/scm/tdx/tridion-sites.git"
|
|
15
|
-
},
|
|
16
|
-
"bugs": {
|
|
17
|
-
"url": "https://jira.sdl.com/projects/DXUI/issues/"
|
|
18
|
-
},
|
|
19
12
|
"files": [
|
|
20
13
|
"dist/**/*"
|
|
21
14
|
],
|
|
@@ -31,7 +24,7 @@
|
|
|
31
24
|
"test:ci": "jest --verbose --reporters='default' --reporters='jest-junit'"
|
|
32
25
|
},
|
|
33
26
|
"dependencies": {
|
|
34
|
-
"@tridion-sites/open-api-client": "1.0.
|
|
27
|
+
"@tridion-sites/open-api-client": "1.0.6",
|
|
35
28
|
"immer": "9.0.16"
|
|
36
29
|
},
|
|
37
30
|
"devDependencies": {
|