@enonic-types/lib-grid 0.1.0
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 +81 -0
- package/grid.d.ts +71 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Enonic XP lib-grid TS types
|
|
2
|
+
|
|
3
|
+
> TypeScript definitions for `lib-grid` library of Enonic XP
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i --save-dev @enonic/lib-grid
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Use
|
|
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
|
+
### Require and custom imports
|
|
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 global
|
|
30
|
+
objects, e.g. `log`, `app`, `__`, etc, requiring library by the default path will return typed object.
|
|
31
|
+
|
|
32
|
+
`tsconfig.json`
|
|
33
|
+
|
|
34
|
+
```diff
|
|
35
|
+
{
|
|
36
|
+
"compilerOptions": {
|
|
37
|
+
"types": [
|
|
38
|
+
+ "@enonic-types/global"
|
|
39
|
+
"@enonic-types/lib-grid"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`example.ts`
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const {getMap} = require('/lib/xp/grid');
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
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).
|
|
53
|
+
|
|
54
|
+
### ES6-style import
|
|
55
|
+
|
|
56
|
+
If you are planning to use `import` in your code and transpile it with the default `tsc` TypeScript compiler, you'll need to add proper
|
|
57
|
+
types mapping to your configuration.
|
|
58
|
+
|
|
59
|
+
`tsconfig.json`
|
|
60
|
+
|
|
61
|
+
```diff
|
|
62
|
+
{
|
|
63
|
+
"compilerOptions": {
|
|
64
|
+
"types": [
|
|
65
|
+
"@enonic-types/lib-grid"
|
|
66
|
+
]
|
|
67
|
+
+ "baseUrl": "./",
|
|
68
|
+
+ "paths": {
|
|
69
|
+
+ "/lib/xp/grid": ["node_modules/@enonic-types/lib-grid"],
|
|
70
|
+
+ }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`example.ts`
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import {getMap} from '/lib/xp/grid';
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Setting `baseUrl` and `paths` will allow the `tsc` to keep the valid paths in the resulting JavaScript files.
|
package/grid.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface XpLibraries {
|
|
3
|
+
'/lib/xp/grid': typeof import('./grid');
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export declare type SharedMapValueType = string | number | boolean | object | null;
|
|
7
|
+
export declare type SharedMapModifierFn = (oldValue: SharedMapValueType) => SharedMapValueType;
|
|
8
|
+
export interface SetParams {
|
|
9
|
+
key: string;
|
|
10
|
+
value: SharedMapValueType;
|
|
11
|
+
ttlSeconds?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ModifyParams {
|
|
14
|
+
key: string;
|
|
15
|
+
func: SharedMapModifierFn;
|
|
16
|
+
ttlSeconds?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare class SharedMap {
|
|
19
|
+
private map;
|
|
20
|
+
/**
|
|
21
|
+
* Creates an instance of SharedMap which are shared across all applications and even cluster nodes.
|
|
22
|
+
*
|
|
23
|
+
* 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.
|
|
24
|
+
*
|
|
25
|
+
* @param mapId - map identifier
|
|
26
|
+
* @constructor
|
|
27
|
+
*/
|
|
28
|
+
constructor(mapId: string);
|
|
29
|
+
/**
|
|
30
|
+
* Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} key - key the key whose associated value is to be returned
|
|
33
|
+
* @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
|
|
34
|
+
*/
|
|
35
|
+
get(key: string): SharedMapValueType;
|
|
36
|
+
/**
|
|
37
|
+
* Puts an entry into this map with a given time to live (TTL).
|
|
38
|
+
* If value is null, the existing entry will be removed.
|
|
39
|
+
*
|
|
40
|
+
* @param {object} params JSON with the parameters.
|
|
41
|
+
* @param {string} params.key key of the entry
|
|
42
|
+
* @param {string|number|boolean|JSON|null} params.value value of the entry
|
|
43
|
+
* @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)
|
|
44
|
+
*/
|
|
45
|
+
set(params: SetParams): void;
|
|
46
|
+
/**
|
|
47
|
+
* Attempts to compute a mapping for the specified key and its current mapped value.
|
|
48
|
+
*
|
|
49
|
+
* @param {object} params JSON with the parameters.
|
|
50
|
+
* @param {string} params.key key of the entry
|
|
51
|
+
* @param {function} params.func mapping function that accepts the existing mapped value (or null, if there is no associated mapping).
|
|
52
|
+
* The returned value replaces the existing mapped value for the specified key.
|
|
53
|
+
* If returned value is null then the value is removed from the map
|
|
54
|
+
* @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)
|
|
55
|
+
* @returns the new value to which the specified key is mapped, or null if this map no longer contains mapping for the key
|
|
56
|
+
*/
|
|
57
|
+
modify(params: ModifyParams): SharedMapValueType;
|
|
58
|
+
/**
|
|
59
|
+
* Removes the mapping for the key from this map if it is present.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} key the key whose associated value is to be removed
|
|
62
|
+
*/
|
|
63
|
+
delete(key: string): void;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns an instance of SharedMap by the specified map identifier.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} mapId map identifier
|
|
69
|
+
* @returns {SharedMap} an instance of SharedMap
|
|
70
|
+
*/
|
|
71
|
+
export declare function getMap(mapId: string): SharedMap;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@enonic-types/lib-grid",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Type definitions for lib-grid.",
|
|
5
|
+
"types": "grid.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"grid.d.ts"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"pre": "npm run --prefix ../ pre",
|
|
11
|
+
"packlist": "npx npm-packlist"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/enonic/xp.git#master"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"enonic",
|
|
19
|
+
"enonic-xp",
|
|
20
|
+
"lib-grid",
|
|
21
|
+
"grid",
|
|
22
|
+
"types",
|
|
23
|
+
"typescript"
|
|
24
|
+
],
|
|
25
|
+
"contributors": [
|
|
26
|
+
"Mikita Taukachou <edloidas@gmail.com> (https://edloidas.github.io/)"
|
|
27
|
+
],
|
|
28
|
+
"license": "Apache-2.0",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/enonic/xp/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/enonic/xp/tree/master#readme",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
}
|
|
36
|
+
}
|