@enonic-types/lib-context 8.0.4 → 8.1.0-B1
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/context.d.ts +45 -1
- package/package.json +2 -2
package/context.d.ts
CHANGED
|
@@ -17,11 +17,30 @@ export interface AuthInfo {
|
|
|
17
17
|
user?: User;
|
|
18
18
|
principals?: PrincipalKey[];
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* A JSON-like context attribute value.
|
|
22
|
+
*/
|
|
23
|
+
export type ContextAttributeValue = string | number | boolean | ContextAttributeValue[] | {
|
|
24
|
+
[key: string]: ContextAttributeValue;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Context attributes, keyed by name.
|
|
28
|
+
*
|
|
29
|
+
* Note what survives a round trip. A value passed to `run` is stored on the context and reaches Java
|
|
30
|
+
* consumers, but `get()` returns only the scalars among them - an array or object set that way is not
|
|
31
|
+
* part of its output. Values stored with `setCustomLocalAttribute` come back from `get()` in full,
|
|
32
|
+
* keyed `custom.<name>`.
|
|
33
|
+
*/
|
|
34
|
+
export type ContextAttributes = Record<string, ContextAttributeValue>;
|
|
21
35
|
export interface Context {
|
|
22
36
|
branch?: string;
|
|
23
37
|
repository?: string;
|
|
24
38
|
authInfo?: AuthInfo;
|
|
39
|
+
/**
|
|
40
|
+
* Attributes visible in the current context: those set on it, those stored in its local scope with
|
|
41
|
+
* `setCustomLocalAttribute` (keyed `custom.<name>`), and any session attributes, merged in that
|
|
42
|
+
* order of precedence.
|
|
43
|
+
*/
|
|
25
44
|
attributes: ContextAttributes;
|
|
26
45
|
}
|
|
27
46
|
export interface ContextUserParams {
|
|
@@ -35,6 +54,10 @@ export interface ContextParams {
|
|
|
35
54
|
principals?: PrincipalKey[];
|
|
36
55
|
attributes?: ContextAttributes;
|
|
37
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Value accepted by {@link setCustomLocalAttribute}.
|
|
59
|
+
*/
|
|
60
|
+
export type CustomAttributeValue = ContextAttributeValue;
|
|
38
61
|
/**
|
|
39
62
|
* Runs a function within a specified context.
|
|
40
63
|
*
|
|
@@ -60,3 +83,24 @@ export declare function run<T>(context: ContextParams, callback: () => T): T;
|
|
|
60
83
|
* @returns {object} Return the current context as JSON object.
|
|
61
84
|
*/
|
|
62
85
|
export declare function get(): Context;
|
|
86
|
+
/**
|
|
87
|
+
* Stores a JSON-like value as a custom attribute in the local scope of the current context.
|
|
88
|
+
*
|
|
89
|
+
* The local scope lives for the duration of the current execution and is shared with nested `run` calls,
|
|
90
|
+
* so a value stored by one piece of code is visible to everything else running in the same execution.
|
|
91
|
+
*
|
|
92
|
+
* The attribute is stored under the `custom.` prefix and is returned by `get()` as `attributes['custom.<name>']`.
|
|
93
|
+
*
|
|
94
|
+
* The value is serialized on write: later modifications of the passed object are not reflected in the
|
|
95
|
+
* stored attribute, and readers always get their own copy.
|
|
96
|
+
*
|
|
97
|
+
* Setting `null` or `undefined` removes the attribute.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* contextLib.setCustomLocalAttribute('my-data', {values: ['one', 'two']});
|
|
101
|
+
* const data = contextLib.get().attributes['custom.my-data'];
|
|
102
|
+
*
|
|
103
|
+
* @param {string} name Attribute name, stored with the `custom.` prefix.
|
|
104
|
+
* @param {string|number|boolean|array|object|null} [value] JSON-like value to store, or null/undefined to remove the attribute.
|
|
105
|
+
*/
|
|
106
|
+
export declare function setCustomLocalAttribute(name: string, value?: CustomAttributeValue | null): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enonic-types/lib-context",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.1.0-B1",
|
|
4
4
|
"description": "Type definitions for lib-context.",
|
|
5
5
|
"types": "context.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/enonic/xp/tree/master#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@enonic-types/core": "8.0
|
|
30
|
+
"@enonic-types/core": "8.1.0-B1"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|