@enonic-types/lib-context 0.1.1 → 7.11.0-B3
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 +4 -4
- package/context.d.ts +62 -73
- package/package.json +35 -32
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm i --save-dev @enonic/lib-context
|
|
8
|
+
npm i --save-dev @enonic-types/lib-context
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Use
|
|
@@ -26,8 +26,8 @@ Add the corresponding types to your `tsconfig.json` file that is used for applic
|
|
|
26
26
|
|
|
27
27
|
### Require and custom imports
|
|
28
28
|
|
|
29
|
-
To make `require` work out of box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP
|
|
30
|
-
objects, e.g. `log`, `app`, `__`, etc, requiring library by the default path will return typed object.
|
|
29
|
+
To make `require` work out of the box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP
|
|
30
|
+
global objects, e.g. `log`, `app`, `__`, etc, requiring a library by the default path will return typed object.
|
|
31
31
|
|
|
32
32
|
`tsconfig.json`
|
|
33
33
|
|
|
@@ -49,7 +49,7 @@ const {get, run} = require('/lib/xp/context');
|
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
More detailed explanation on how it works and how to type custom import function can be
|
|
52
|
-
found [here](https://
|
|
52
|
+
found [here](https://developer.enonic.com/docs/xp/stable/api).
|
|
53
53
|
|
|
54
54
|
### ES6-style import
|
|
55
55
|
|
package/context.d.ts
CHANGED
|
@@ -1,73 +1,62 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Built-in context functions.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* var contextLib = require('/lib/xp/context');
|
|
6
|
-
*
|
|
7
|
-
* @module context
|
|
8
|
-
*/
|
|
9
|
-
declare global {
|
|
10
|
-
interface XpLibraries {
|
|
11
|
-
'/lib/xp/context': typeof import('./context');
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
export interface
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
branch
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
attributes
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* @
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* @
|
|
59
|
-
*
|
|
60
|
-
* @
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
* @returns {object} Result of the function execution.
|
|
64
|
-
*/
|
|
65
|
-
export declare function run<T>(context: ContextParams, callback: () => T): T;
|
|
66
|
-
/**
|
|
67
|
-
* Returns the current context.
|
|
68
|
-
*
|
|
69
|
-
* @example-ref examples/context/get.js
|
|
70
|
-
*
|
|
71
|
-
* @returns {object} Return the current context as JSON object.
|
|
72
|
-
*/
|
|
73
|
-
export declare function get(): Context;
|
|
1
|
+
/**
|
|
2
|
+
* Built-in context functions.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* var contextLib = require('/lib/xp/context');
|
|
6
|
+
*
|
|
7
|
+
* @module context
|
|
8
|
+
*/
|
|
9
|
+
declare global {
|
|
10
|
+
interface XpLibraries {
|
|
11
|
+
'/lib/xp/context': typeof import('./context');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
import type { PrincipalKey, User } from '@enonic-types/core';
|
|
15
|
+
export type { PrincipalKey, UserKey, Principal, User } from '@enonic-types/core';
|
|
16
|
+
export interface AuthInfo {
|
|
17
|
+
user?: User | null;
|
|
18
|
+
principals?: PrincipalKey[] | null;
|
|
19
|
+
}
|
|
20
|
+
export declare type ContextAttributes = Record<string, number | string | boolean | Record<string, unknown>>;
|
|
21
|
+
export interface Context {
|
|
22
|
+
branch: string;
|
|
23
|
+
repository: string;
|
|
24
|
+
authInfo?: AuthInfo;
|
|
25
|
+
attributes: ContextAttributes;
|
|
26
|
+
}
|
|
27
|
+
export interface ContextUserParams {
|
|
28
|
+
login: string;
|
|
29
|
+
idProvider?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ContextParams {
|
|
32
|
+
repository?: string;
|
|
33
|
+
branch?: string;
|
|
34
|
+
user?: ContextUserParams;
|
|
35
|
+
principals?: PrincipalKey[];
|
|
36
|
+
attributes?: ContextAttributes;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Runs a function within a specified context.
|
|
40
|
+
*
|
|
41
|
+
* @example-ref examples/context/run.js
|
|
42
|
+
*
|
|
43
|
+
* @param {object} context JSON parameters.
|
|
44
|
+
* @param {string} [context.repository] Repository to execute the callback in. Default is the current repository set in portal.
|
|
45
|
+
* @param {string} [context.branch] Name of the branch to execute the callback in. Default is the current branch set in portal.
|
|
46
|
+
* @param {object} [context.user] User to execute the callback with. Default is the current user.
|
|
47
|
+
* @param {string} context.user.login Login of the user.
|
|
48
|
+
* @param {string} [context.user.idProvider] Id provider containing the user. By default, all the id providers will be used.
|
|
49
|
+
* @param {array} [context.principals] Additional principals to execute the callback with.
|
|
50
|
+
* @param {object} [context.attributes] Additional Context attributes.
|
|
51
|
+
* @param {function} callback Function to execute.
|
|
52
|
+
* @returns {object} Result of the function execution.
|
|
53
|
+
*/
|
|
54
|
+
export declare function run<T>(context: ContextParams, callback: () => T): T;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the current context.
|
|
57
|
+
*
|
|
58
|
+
* @example-ref examples/context/get.js
|
|
59
|
+
*
|
|
60
|
+
* @returns {object} Return the current context as JSON object.
|
|
61
|
+
*/
|
|
62
|
+
export declare function get(): Context;
|
package/package.json
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@enonic-types/lib-context",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Type definitions for lib-context.",
|
|
5
|
-
"types": "context.d.ts",
|
|
6
|
-
"files": [
|
|
7
|
-
"context.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
|
-
"lib-context",
|
|
17
|
-
"context",
|
|
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
|
-
"
|
|
30
|
-
"
|
|
31
|
-
}
|
|
32
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@enonic-types/lib-context",
|
|
3
|
+
"version": "7.11.0-B3",
|
|
4
|
+
"description": "Type definitions for lib-context.",
|
|
5
|
+
"types": "context.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"context.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
|
+
"lib-context",
|
|
17
|
+
"context",
|
|
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
|
+
"@enonic-types/core": "7.11.0-B3"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|