@enonic-types/core 7.11.0-B2
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/README.md +58 -0
- package/index.d.ts +110 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Enonic XP Core TS types
|
|
2
|
+
|
|
3
|
+
> TypeScript definitions that are shared between libraries and represent core
|
|
4
|
+
> data structures.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm i --save-dev @enonic-types/core
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Use
|
|
13
|
+
|
|
14
|
+
> It is not necessary to include this dependency into your project, as all
|
|
15
|
+
> libraries export related core types, e.g. Content library exports `Content`
|
|
16
|
+
> type.
|
|
17
|
+
|
|
18
|
+
All core types can be imported using ES6-style import:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import type {Content} from '@enonic-types/core';
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Content
|
|
25
|
+
|
|
26
|
+
`Content` contains the `x` property, that has a very special `XpXData` type.
|
|
27
|
+
|
|
28
|
+
`XpXData` is an interface, that is added to the global scope, so it can be
|
|
29
|
+
modified using the [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-interfaces).
|
|
30
|
+
This allows you to set the shape of the XData in your project, simply by
|
|
31
|
+
declaring the `XpXData` like this:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
declare global {
|
|
35
|
+
interface XpXData {
|
|
36
|
+
'com-mysite-app': {
|
|
37
|
+
metadata: {
|
|
38
|
+
metaTagTitle: string;
|
|
39
|
+
metaTagImageId: string;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Additional types
|
|
47
|
+
|
|
48
|
+
`Content` is a complex type that contains unions and maps, that are not exported, but may be needed during the development. Actually, these types can easily be retrieved from the `Content` itself:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import type {Content} from '@enonic-types/core';
|
|
52
|
+
|
|
53
|
+
type Attachments = Content['attachments'];
|
|
54
|
+
|
|
55
|
+
type ContentInheritType = Content['inherit'];
|
|
56
|
+
|
|
57
|
+
type Workflow = Content['workflow'];
|
|
58
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface XpXData {
|
|
3
|
+
[key: string]: Record<string, Record<string, unknown>>;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type UserKey = `user:${string}:${string}`;
|
|
8
|
+
export type GroupKey = `group:${string}:${string}`;
|
|
9
|
+
export type RoleKey = `role:${string}`;
|
|
10
|
+
|
|
11
|
+
export type PrincipalKey = UserKey | GroupKey | RoleKey;
|
|
12
|
+
|
|
13
|
+
export interface User {
|
|
14
|
+
type: 'user';
|
|
15
|
+
key: UserKey;
|
|
16
|
+
displayName: string;
|
|
17
|
+
modifiedTime: string;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
email?: string;
|
|
20
|
+
login?: string;
|
|
21
|
+
idProvider: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface Group {
|
|
25
|
+
type: 'group';
|
|
26
|
+
key: GroupKey;
|
|
27
|
+
displayName: string;
|
|
28
|
+
modifiedTime: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface Role {
|
|
33
|
+
type: 'role';
|
|
34
|
+
key: RoleKey;
|
|
35
|
+
displayName: string;
|
|
36
|
+
modifiedTime: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type Principal = User | Group | Role;
|
|
41
|
+
|
|
42
|
+
export interface Attachment {
|
|
43
|
+
name: string;
|
|
44
|
+
label?: string;
|
|
45
|
+
size: number;
|
|
46
|
+
mimeType: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface PublishInfo {
|
|
50
|
+
from?: string;
|
|
51
|
+
to?: string;
|
|
52
|
+
first?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface Component<Config extends object = object, Regions extends Record<string, Region> = Record<string, Region>> {
|
|
56
|
+
config: Config;
|
|
57
|
+
descriptor: string;
|
|
58
|
+
path: string;
|
|
59
|
+
type: 'page' | 'layout' | 'part';
|
|
60
|
+
regions: Regions;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface Region<Config extends object = object> {
|
|
64
|
+
name: string;
|
|
65
|
+
components: Component<Config>[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface Content<
|
|
69
|
+
Data = Record<string, unknown>,
|
|
70
|
+
Type extends string = string,
|
|
71
|
+
Page extends Component = Component,
|
|
72
|
+
> {
|
|
73
|
+
_id: string;
|
|
74
|
+
_name: string;
|
|
75
|
+
_path: string;
|
|
76
|
+
_score: number;
|
|
77
|
+
creator: UserKey;
|
|
78
|
+
modifier: UserKey;
|
|
79
|
+
createdTime: string;
|
|
80
|
+
modifiedTime: string;
|
|
81
|
+
owner: string;
|
|
82
|
+
data: Data;
|
|
83
|
+
type: Type;
|
|
84
|
+
displayName: string;
|
|
85
|
+
hasChildren: boolean;
|
|
86
|
+
language: string;
|
|
87
|
+
valid: boolean;
|
|
88
|
+
originProject: string;
|
|
89
|
+
childOrder?: string;
|
|
90
|
+
_sort?: object[];
|
|
91
|
+
page: Page;
|
|
92
|
+
x: XpXData;
|
|
93
|
+
attachments: Record<string, Attachment>;
|
|
94
|
+
publish?: PublishInfo;
|
|
95
|
+
workflow?: {
|
|
96
|
+
state: 'IN_PROGRESS' | 'PENDING_APPROVAL' | 'REJECTED' | 'READY';
|
|
97
|
+
checks?: Record<string, 'PENDING' | 'REJECTED' | 'APPROVED'>;
|
|
98
|
+
};
|
|
99
|
+
inherit?: ('CONTENT' | 'PARENT' | 'NAME' | 'SORT')[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface Resource {
|
|
103
|
+
getSize(): number;
|
|
104
|
+
|
|
105
|
+
getTimestamp(): number;
|
|
106
|
+
|
|
107
|
+
getStream(): object;
|
|
108
|
+
|
|
109
|
+
exists(): boolean;
|
|
110
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@enonic-types/core",
|
|
3
|
+
"version": "7.11.0-B2",
|
|
4
|
+
"description": "Shared type definition for core libraries.",
|
|
5
|
+
"types": "index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.d.ts"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/enonic/xp.git#master"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"enonic",
|
|
15
|
+
"enonic-xp",
|
|
16
|
+
"core",
|
|
17
|
+
"shared",
|
|
18
|
+
"types",
|
|
19
|
+
"typescript"
|
|
20
|
+
],
|
|
21
|
+
"contributors": [
|
|
22
|
+
"Mikita Taukachou <edloidas@gmail.com> (https://edloidas.github.io/)"
|
|
23
|
+
],
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/enonic/xp/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/enonic/xp/tree/master#readme",
|
|
29
|
+
"dependencies": {},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
}
|
|
33
|
+
}
|