@enonic-types/global 0.1.0 → 0.1.1
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 +3 -2
- package/global.d.ts +53 -15
- package/package.json +32 -32
- package/index.d.ts +0 -54
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ Add the corresponding types to your `tsconfig.json` file that is used for applic
|
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
> The paths to the `
|
|
26
|
+
> The paths to the `node_modules` assume that your `tsconfig.json` is placed under your project root.
|
|
27
27
|
|
|
28
28
|
After that, all the global XP variables will be typed.
|
|
29
29
|
|
|
@@ -36,7 +36,8 @@ libraries are also added to your `tsconfig.json`.
|
|
|
36
36
|
|
|
37
37
|
### Require
|
|
38
38
|
|
|
39
|
-
To add support for type resolution for the custom libraries via `require`, you can redeclare the `XpLibraries` interface in global scope,
|
|
39
|
+
To add support for type resolution for the custom libraries via `require`, you can redeclare the `XpLibraries` interface in global scope,
|
|
40
|
+
which will lead to declaration merging:
|
|
40
41
|
|
|
41
42
|
```ts
|
|
42
43
|
declare global {
|
package/global.d.ts
CHANGED
|
@@ -1,18 +1,56 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This project don't include XP libraries definitions and need this interface
|
|
3
|
-
* to properly map imports via require.
|
|
4
|
-
*
|
|
5
|
-
* Warning: this interface is empty. If you want type definitions for various
|
|
6
|
-
* libraries, you need to redefine this interface in your library in global
|
|
7
|
-
* path and add a new property with library path.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* declare global {
|
|
11
|
-
* interface XpLibraries {
|
|
12
|
-
* '/lib/xp/event': typeof import('./event');
|
|
13
|
-
* }
|
|
14
|
-
* }
|
|
15
|
-
*/
|
|
16
1
|
interface XpLibraries {}
|
|
17
2
|
|
|
18
3
|
interface XpBeans {}
|
|
4
|
+
|
|
5
|
+
declare const app: {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
config: Record<string, string | undefined>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
declare const log: {
|
|
12
|
+
debug: (...args: unknown[]) => void;
|
|
13
|
+
info: (...args: unknown[]) => void;
|
|
14
|
+
warning: (...args: unknown[]) => void;
|
|
15
|
+
error: (...args: unknown[]) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
declare interface ScriptValue {
|
|
19
|
+
isArray(): boolean;
|
|
20
|
+
|
|
21
|
+
isObject(): boolean;
|
|
22
|
+
|
|
23
|
+
isValue(): boolean;
|
|
24
|
+
|
|
25
|
+
isFunction(): boolean;
|
|
26
|
+
|
|
27
|
+
getValue(): unknown;
|
|
28
|
+
|
|
29
|
+
getKeys(): string[];
|
|
30
|
+
|
|
31
|
+
hasMember(key: string): boolean;
|
|
32
|
+
|
|
33
|
+
getMember(key: string): ScriptValue;
|
|
34
|
+
|
|
35
|
+
getArray(): ScriptValue[];
|
|
36
|
+
|
|
37
|
+
getMap(): Record<string, unknown>;
|
|
38
|
+
|
|
39
|
+
getList(): object[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type NewBean = <T = unknown, Bean extends keyof XpBeans | string = string>(bean: Bean) =>
|
|
43
|
+
Bean extends keyof XpBeans ? XpBeans[Bean] : T;
|
|
44
|
+
|
|
45
|
+
declare const __: {
|
|
46
|
+
newBean: NewBean;
|
|
47
|
+
toNativeObject: <T = unknown>(beanResult: T) => T;
|
|
48
|
+
toScriptValue: <T = object>(value: T) => ScriptValue;
|
|
49
|
+
disposer: (callback: (...args: unknown[]) => unknown) => void;
|
|
50
|
+
nullOrValue: <T = object>(value: T) => T | null | undefined;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
declare type XpRequire = <Key extends keyof XpLibraries | string = string>(path: Key) =>
|
|
54
|
+
Key extends keyof XpLibraries ? XpLibraries[Key] : unknown;
|
|
55
|
+
|
|
56
|
+
declare const require: XpRequire;
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@enonic-types/global",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Type definitions for
|
|
5
|
-
"types": "
|
|
6
|
-
"files": [
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"enonic",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"types",
|
|
19
|
-
"typescript"
|
|
20
|
-
],
|
|
21
|
-
"contributors": [
|
|
22
|
-
"Mikita Taukachou <edloidas@gmail.com> (https://edloidas.github.io/)"
|
|
23
|
-
],
|
|
24
|
-
"license": "Apache-2.0",
|
|
25
|
-
"bugs": {
|
|
26
|
-
"url": "https://github.com/enonic/xp/issues"
|
|
27
|
-
},
|
|
28
|
-
"homepage": "https://github.com/enonic/xp/tree/master#readme",
|
|
29
|
-
"publishConfig": {
|
|
30
|
-
"access": "public"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@enonic-types/global",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Type definitions for global.",
|
|
5
|
+
"types": "global.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"global.d.ts"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/enonic/xp.git#master"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"enonic",
|
|
15
|
+
"enonic-xp",
|
|
16
|
+
"global",
|
|
17
|
+
"common",
|
|
18
|
+
"types",
|
|
19
|
+
"typescript"
|
|
20
|
+
],
|
|
21
|
+
"contributors": [
|
|
22
|
+
"Mikita Taukachou <edloidas@gmail.com> (https://edloidas.github.io/)"
|
|
23
|
+
],
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/enonic/xp/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/enonic/xp/tree/master#readme",
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/index.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/// <reference path='global.d.ts' />
|
|
2
|
-
|
|
3
|
-
declare const app: {
|
|
4
|
-
name: string;
|
|
5
|
-
version: string;
|
|
6
|
-
config: Record<string, string | undefined>;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
declare const log: {
|
|
10
|
-
debug: (...args: unknown[]) => void;
|
|
11
|
-
info: (...args: unknown[]) => void;
|
|
12
|
-
warning: (...args: unknown[]) => void;
|
|
13
|
-
error: (...args: unknown[]) => void;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
declare interface ScriptValue {
|
|
17
|
-
isArray(): boolean;
|
|
18
|
-
|
|
19
|
-
isObject(): boolean;
|
|
20
|
-
|
|
21
|
-
isValue(): boolean;
|
|
22
|
-
|
|
23
|
-
isFunction(): boolean;
|
|
24
|
-
|
|
25
|
-
getValue(): unknown;
|
|
26
|
-
|
|
27
|
-
getKeys(): string[];
|
|
28
|
-
|
|
29
|
-
hasMember(key: string): boolean;
|
|
30
|
-
|
|
31
|
-
getMember(key: string): ScriptValue;
|
|
32
|
-
|
|
33
|
-
getArray(): ScriptValue[];
|
|
34
|
-
|
|
35
|
-
getMap(): Record<String, unknown>;
|
|
36
|
-
|
|
37
|
-
getList(): object[];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type NewBean = <T = unknown, Bean extends keyof XpBeans | string = string>(bean: Bean) =>
|
|
41
|
-
Bean extends keyof XpBeans ? XpBeans[Bean] : T;
|
|
42
|
-
|
|
43
|
-
declare const __: {
|
|
44
|
-
newBean: NewBean;
|
|
45
|
-
toNativeObject: <T = unknown>(beanResult: T) => T;
|
|
46
|
-
toScriptValue: <T = object>(value: T) => ScriptValue;
|
|
47
|
-
disposer: (callback: (...args: unknown[]) => unknown) => void;
|
|
48
|
-
nullOrValue: <T = object>(value: T) => T | null | undefined;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
declare type XpRequire = <Key extends keyof XpLibraries | string = string>(path: Key) =>
|
|
52
|
-
Key extends keyof XpLibraries ? XpLibraries[Key] : unknown;
|
|
53
|
-
|
|
54
|
-
declare const require: XpRequire;
|