@enonic-types/lib-grid 7.11.0-B1 → 7.11.0-B4

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 (3) hide show
  1. package/README.md +11 -29
  2. package/grid.d.ts +14 -53
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -5,38 +5,23 @@
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm i --save-dev @enonic/lib-grid
8
+ npm i --save-dev @enonic-types/lib-grid
9
9
  ```
10
10
 
11
11
  ## Use
12
12
 
13
- Add the corresponding types to your `tsconfig.json` file that is used for application's server-side TypeScript code.
14
-
15
- `tsconfig.json`
16
-
17
- ```json
18
- {
19
- "compilerOptions": {
20
- "types": [
21
- "@enonic-types/lib-grid"
22
- ]
23
- }
24
- }
25
- ```
26
-
27
13
  ### Require and custom imports
28
14
 
29
- To make `require` work out of box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP global
30
- objects, e.g. `log`, `app`, `__`, etc, requiring library by the default path will return typed object.
15
+ To make `require` work out of the box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP
16
+ global objects, e.g. `log`, `app`, `__`, etc, requiring a library by the default path will return typed object.
31
17
 
32
18
  `tsconfig.json`
33
19
 
34
- ```diff
20
+ ```json
35
21
  {
36
22
  "compilerOptions": {
37
23
  "types": [
38
- + "@enonic-types/global"
39
- "@enonic-types/lib-grid"
24
+ "@enonic-types/global"
40
25
  ]
41
26
  }
42
27
  }
@@ -49,7 +34,7 @@ const {getMap} = require('/lib/xp/grid');
49
34
  ```
50
35
 
51
36
  More detailed explanation on how it works and how to type custom import function can be
52
- found [here](https://github.com/enonic/xp/tree/master/modules/lib/typescript/README.md).
37
+ found [here](https://developer.enonic.com/docs/xp/stable/api).
53
38
 
54
39
  ### ES6-style import
55
40
 
@@ -58,16 +43,13 @@ types mapping to your configuration.
58
43
 
59
44
  `tsconfig.json`
60
45
 
61
- ```diff
46
+ ```json
62
47
  {
63
48
  "compilerOptions": {
64
- "types": [
65
- "@enonic-types/lib-grid"
66
- ]
67
- + "baseUrl": "./",
68
- + "paths": {
69
- + "/lib/xp/grid": ["node_modules/@enonic-types/lib-grid"],
70
- + }
49
+ "baseUrl": "./",
50
+ "paths": {
51
+ "/lib/xp/grid": ["node_modules/@enonic-types/lib-grid"]
52
+ }
71
53
  }
72
54
  }
73
55
  ```
package/grid.d.ts CHANGED
@@ -12,62 +12,23 @@ declare global {
12
12
  }
13
13
  }
14
14
  export declare type SharedMapValueType = string | number | boolean | object | null;
15
- export declare type SharedMapModifierFn = (oldValue: SharedMapValueType) => SharedMapValueType;
16
- export interface SetParams {
17
- key: string;
18
- value: SharedMapValueType;
15
+ export declare type GridMap = Record<string, SharedMapValueType>;
16
+ export declare type SharedMapModifierFn<Map extends GridMap, Key extends keyof Map> = (value: Map[Key] | null) => SharedMapValueType | Record<string, unknown> | object[];
17
+ export interface SetParams<Map extends GridMap, Key extends keyof Map> {
18
+ key: Key;
19
+ value: Map[Key] | null;
19
20
  ttlSeconds?: number;
20
21
  }
21
- export interface ModifyParams {
22
- key: string;
23
- func: SharedMapModifierFn;
22
+ export interface ModifyParams<Map extends GridMap, Key extends keyof Map> {
23
+ key: Key;
24
+ func: SharedMapModifierFn<Map, Key>;
24
25
  ttlSeconds?: number;
25
26
  }
26
- /**
27
- * Shared Map is similar to other Map, but its instances are shared across all applications and even cluster nodes.
28
-
29
- WARNING: Due to distributed nature of the Shared Map not all types of keys and values can be used. Strings, numbers, and pure JSON objects are supported. There is no runtime check for type compatibility due to performance reasons. The developer is also responsible for not modifying shared objects (keys and values) in place.
30
- * @param mapId - map identifier
31
- * @constructor
32
- */
33
- export declare class SharedMap {
34
- private map;
35
- constructor(mapId: string);
36
- /**
37
- * Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
38
- *
39
- * @param {string} key - key the key whose associated value is to be returned
40
- * @returns {string|number|boolean|JSON|null} the value to which the specified key is mapped, or null if this map contains no mapping for the key
41
- */
42
- get(key: string): SharedMapValueType;
43
- /**
44
- * Puts an entry into this map with a given time to live (TTL).
45
- * If value is null, the existing entry will be removed.
46
- *
47
- * @param {object} params JSON with the parameters.
48
- * @param {string} params.key key of the entry
49
- * @param {string|number|boolean|JSON|null} params.value value of the entry
50
- * @param {number} [params.ttlSeconds] maximum time to live in seconds for this entry to stay in the map. (0 means infinite, negative means map config default or infinite if map config is not available)
51
- */
52
- set(params: SetParams): void;
53
- /**
54
- * Attempts to compute a mapping for the specified key and its current mapped value.
55
- *
56
- * @param {object} params JSON with the parameters.
57
- * @param {string} params.key key of the entry
58
- * @param {function} params.func mapping function that accepts the existing mapped value (or null, if there is no associated mapping).
59
- * The returned value replaces the existing mapped value for the specified key.
60
- * If returned value is null then the value is removed from the map
61
- * @param {number} [params.ttlSeconds] maximum time to live in seconds for this entry to stay in the map. (0 means infinite, negative means map config default or infinite if map config is not available)
62
- * @returns the new value to which the specified key is mapped, or null if this map no longer contains mapping for the key
63
- */
64
- modify(params: ModifyParams): SharedMapValueType;
65
- /**
66
- * Removes the mapping for the key from this map if it is present.
67
- *
68
- * @param {string} key the key whose associated value is to be removed
69
- */
70
- delete(key: string): void;
27
+ export interface SharedMap<Map extends GridMap> {
28
+ get<Key extends keyof Map>(key: Key): Map[Key];
29
+ set<Key extends keyof Map>(params: SetParams<Map, Key>): void;
30
+ modify<Key extends keyof Map>(params: ModifyParams<Map, Key>): Map[Key];
31
+ delete(key: keyof Map): void;
71
32
  }
72
33
  /**
73
34
  * Returns an instance of SharedMap by the specified map identifier.
@@ -75,4 +36,4 @@ export declare class SharedMap {
75
36
  * @param {string} mapId map identifier
76
37
  * @returns {SharedMap} an instance of SharedMap
77
38
  */
78
- export declare function getMap(mapId: string): SharedMap;
39
+ export declare function getMap<Map extends GridMap>(mapId: string): SharedMap<Map>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enonic-types/lib-grid",
3
- "version": "7.11.0-B1",
3
+ "version": "7.11.0-B4",
4
4
  "description": "Type definitions for lib-grid.",
5
5
  "types": "grid.d.ts",
6
6
  "files": [
@@ -26,6 +26,7 @@
26
26
  "url": "https://github.com/enonic/xp/issues"
27
27
  },
28
28
  "homepage": "https://github.com/enonic/xp/tree/master#readme",
29
+ "dependencies": {},
29
30
  "publishConfig": {
30
31
  "access": "public"
31
32
  }