@enonic-types/lib-grid 7.11.0-B1 → 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/grid.d.ts +14 -53
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
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
|
|
@@ -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 {getMap} = require('/lib/xp/grid');
|
|
|
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/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
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
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:
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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-
|
|
3
|
+
"version": "7.11.0-B3",
|
|
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
|
}
|