@enonic-types/lib-context 8.1.0-RC1 → 8.1.0-RC3

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.
Files changed (2) hide show
  1. package/context.d.ts +9 -6
  2. package/package.json +2 -2
package/context.d.ts CHANGED
@@ -32,7 +32,7 @@ export type ContextAttributeValue = string | number | boolean | ContextAttribute
32
32
  * keyed `custom.<name>`.
33
33
  */
34
34
  export type ContextAttributes = Record<string, ContextAttributeValue>;
35
- export interface Context {
35
+ export interface Context<Attributes extends object = ContextAttributes> {
36
36
  branch?: string;
37
37
  repository?: string;
38
38
  authInfo?: AuthInfo;
@@ -41,7 +41,7 @@ export interface Context {
41
41
  * `setCustomLocalAttribute` (keyed `custom.<name>`), and any session attributes, merged in that
42
42
  * order of precedence.
43
43
  */
44
- attributes: ContextAttributes;
44
+ attributes: ContextAttributes & Partial<Attributes>;
45
45
  }
46
46
  export interface ContextUserParams {
47
47
  login: string;
@@ -55,9 +55,12 @@ export interface ContextParams {
55
55
  attributes?: ContextAttributes;
56
56
  }
57
57
  /**
58
- * Value accepted by {@link setCustomLocalAttribute}.
58
+ * Value accepted by {@link setCustomLocalAttribute}: the JSON-like shape of `T`, where functions and
59
+ * non-JSON objects (like `Date`) become `never`.
59
60
  */
60
- export type CustomAttributeValue = ContextAttributeValue;
61
+ export type CustomAttributeValue<T = ContextAttributeValue> = T extends string | number | boolean ? T : T extends (...args: never[]) => unknown ? never : T extends readonly (infer U)[] ? readonly CustomAttributeValue<U>[] : T extends object ? {
62
+ [K in keyof T]: CustomAttributeValue<T[K]>;
63
+ } : never;
61
64
  /**
62
65
  * Runs a function within a specified context.
63
66
  *
@@ -82,7 +85,7 @@ export declare function run<T>(context: ContextParams, callback: () => T): T;
82
85
  *
83
86
  * @returns {object} Return the current context as JSON object.
84
87
  */
85
- export declare function get(): Context;
88
+ export declare function get<Attributes extends object = ContextAttributes>(): Context<Attributes>;
86
89
  /**
87
90
  * Stores a JSON-like value as a custom attribute in the local scope of the current context.
88
91
  *
@@ -103,4 +106,4 @@ export declare function get(): Context;
103
106
  * @param {string} name Attribute name, stored with the `custom.` prefix.
104
107
  * @param {string|number|boolean|array|object|null} [value] JSON-like value to store, or null/undefined to remove the attribute.
105
108
  */
106
- export declare function setCustomLocalAttribute(name: string, value?: CustomAttributeValue | null): void;
109
+ export declare function setCustomLocalAttribute<Value = ContextAttributeValue>(name: string, value?: CustomAttributeValue<Value> | null): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enonic-types/lib-context",
3
- "version": "8.1.0-RC1",
3
+ "version": "8.1.0-RC3",
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.1.0-RC1"
30
+ "@enonic-types/core": "8.1.0-RC3"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"