@enonic-types/global 0.1.1 → 7.11.0-B2

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 +10 -8
  2. package/global.d.ts +148 -1
  3. package/package.json +33 -32
package/README.md CHANGED
@@ -17,7 +17,7 @@ Add the corresponding types to your `tsconfig.json` file that is used for applic
17
17
  "compilerOptions": {
18
18
  "typeRoots": [
19
19
  "node_modules/@types",
20
- "node_modules/@enonic-types",
20
+ "node_modules/@enonic-types"
21
21
  ]
22
22
  }
23
23
  }
@@ -29,8 +29,8 @@ After that, all the global XP variables will be typed.
29
29
 
30
30
  Adding not `"types": [...]` but `"typeRoots"` will allow to discover types for every other enonic library, that will be installed later.
31
31
 
32
- Import functions, such as `require`, will return typed objects if the corresponding types for imported
33
- libraries are also added to your `tsconfig.json`.
32
+ Import functions, such as `require`, will return typed objects if the corresponding types for imported libraries are also added to
33
+ your `tsconfig.json`.
34
34
 
35
35
  ## Configuration
36
36
 
@@ -47,24 +47,26 @@ declare global {
47
47
  }
48
48
  ```
49
49
 
50
- __Other imports__
50
+ #### Other imports
51
51
 
52
52
  If you want to use custom import functions, like `__non_webpack_require__` with Webpack, just use global `XpRequire` type for this:
53
+
53
54
  ```ts
54
55
  declare const __non_webpack_require__: XpRequire;
55
56
  ```
56
57
 
57
58
  ### Beans
58
59
 
59
- To create a new bean, a `__.newBean()` function must be used. Making it return a proper type can be done in two ways. Say you have create an interface for that been somewhere in your project:
60
+ To create a new bean, a `__.newBean()` function must be used. Making it return a proper type can be done in two ways. Say you have created
61
+ an interface for that been somewhere in your project:
60
62
 
61
63
  ```ts
62
64
  interface SomeHelper {
63
- help(text: string): void;
65
+ help(text: string): void;
64
66
  }
65
67
  ```
66
68
 
67
- __Option 1__
69
+ #### Option 1
68
70
 
69
71
  You can pass the type argument explicitly. This option is a bit cleaner.
70
72
 
@@ -72,7 +74,7 @@ You can pass the type argument explicitly. This option is a bit cleaner.
72
74
  const helper = __.newBean<SomeHelper>('com.me.project.SomeHelper');
73
75
  ```
74
76
 
75
- __Option 2__
77
+ #### Option 2
76
78
 
77
79
  Or you can map the bean name to bean interface. It may be a preferable way to do it, if the bean is used across multiple files:
78
80
 
package/global.d.ts CHANGED
@@ -2,16 +2,86 @@ interface XpLibraries {}
2
2
 
3
3
  interface XpBeans {}
4
4
 
5
+ /**
6
+ * The globally available app object holds information about the contextual application.
7
+ * @example
8
+ * var nameVersion = app.name + ' v' + app.version;
9
+ *
10
+ * @global
11
+ * @namespace
12
+ */
5
13
  declare const app: {
14
+ /**
15
+ * The name of the application.
16
+ *
17
+ * @type string
18
+ */
6
19
  name: string;
20
+ /**
21
+ * Version of the application.
22
+ *
23
+ * @type string
24
+ */
7
25
  version: string;
26
+ /**
27
+ * Values from the application’s configuration file.
28
+ * This can be set using $XP_HOME/config/<app.name>.cfg.
29
+ * Every time the configuration is changed the app is restarted.
30
+ *
31
+ * @type Object
32
+ */
8
33
  config: Record<string, string | undefined>;
9
34
  };
10
35
 
36
+ /**
37
+ * Logging functions.
38
+ *
39
+ * @example
40
+ * // Log with simple message
41
+ * log.debug('My log message');
42
+ *
43
+ * @example
44
+ * // Log with placeholders
45
+ * log.info('My %s message with %s', 'log', 'placeholders');
46
+ *
47
+ * @example
48
+ * // Log a JSON object
49
+ * log.warning('My JSON: %s', {a: 1});
50
+ *
51
+ * @example
52
+ * // Log JSON object using string
53
+ * log.error('My JSON: %s', JSON.stringify({a: 1}, null, 2));
54
+ *
55
+ * @global
56
+ * @namespace
57
+ */
11
58
  declare const log: {
59
+ /**
60
+ * Log debug message.
61
+ *
62
+ * @param {Array} args... logging arguments.
63
+ */
12
64
  debug: (...args: unknown[]) => void;
65
+
66
+ /**
67
+ * Log info message.
68
+ *
69
+ * @param {Array} args... logging arguments.
70
+ */
13
71
  info: (...args: unknown[]) => void;
72
+
73
+ /**
74
+ * Log warning message.
75
+ *
76
+ * @param {Array} args... logging arguments.
77
+ */
14
78
  warning: (...args: unknown[]) => void;
79
+
80
+ /**
81
+ * Log error message.
82
+ *
83
+ * @param {Array} args... logging arguments.
84
+ */
15
85
  error: (...args: unknown[]) => void;
16
86
  };
17
87
 
@@ -42,15 +112,92 @@ declare interface ScriptValue {
42
112
  type NewBean = <T = unknown, Bean extends keyof XpBeans | string = string>(bean: Bean) =>
43
113
  Bean extends keyof XpBeans ? XpBeans[Bean] : T;
44
114
 
115
+ /**
116
+ * Javascript to Java bridge functions.
117
+ *
118
+ * @example
119
+ * var bean = __.newBean('com.enonic.xp.MyJavaUtils');
120
+ *
121
+ * @example
122
+ * return __.toNativeObject(bean.findArray(arrayName));
123
+ *
124
+ * @global
125
+ * @namespace
126
+ */
45
127
  declare const __: {
128
+ /**
129
+ * Creates a new JavaScript bean that wraps the given Java class and makes its methods available to be called from JavaScript.
130
+ */
46
131
  newBean: NewBean;
47
- toNativeObject: <T = unknown>(beanResult: T) => T;
132
+ /**
133
+ * Converts arrays or complex Java objects to JSON.
134
+ * @param value Value to convert
135
+ */
136
+ toNativeObject: <T = unknown>(value: T) => T;
137
+ /**
138
+ * Converts JSON to a Java Map structure that can be used as parameters to a Java method on a bean created with newBean.
139
+ * @param value Value to convert
140
+ */
48
141
  toScriptValue: <T = object>(value: T) => ScriptValue;
142
+ /**
143
+ * Add a disposer that is called when the app is stopped.
144
+ * @param callback Function to call
145
+ */
49
146
  disposer: (callback: (...args: unknown[]) => unknown) => void;
147
+ /**
148
+ * Converts a JavaScript variable that is undefined to a Java <code>null</code> object.
149
+ * If the JavaScript variable is defined, it is returned as is.
150
+ * @param value Value to convert
151
+ */
50
152
  nullOrValue: <T = object>(value: T) => T | null | undefined;
153
+
154
+ /**
155
+ * Doc registerMock.
156
+ *
157
+ * @param name Name of mock.
158
+ * @param value Value to register.
159
+ */
160
+ registerMock: (name: string, value: object) => void
51
161
  };
52
162
 
53
163
  declare type XpRequire = <Key extends keyof XpLibraries | string = string>(path: Key) =>
54
164
  Key extends keyof XpLibraries ? XpLibraries[Key] : unknown;
55
165
 
166
+ /**
167
+ * This globally available function will load a JavaScript file and return the exports as objects.
168
+ * The function implements parts of the `CommonJS Modules Specification`.
169
+ *
170
+ * @example
171
+ * // Require relative to this
172
+ * var other = require('./other.js');
173
+ *
174
+ * @example
175
+ * // Require absolute
176
+ * var other = require('/path/to/other.js');
177
+ *
178
+ * @example
179
+ * // Require without .js extension
180
+ * var other = require('./other');
181
+ *
182
+ * @param {string} path Path for javascript file (relative or absolute and .js ending is optional).
183
+ * @returns {object} Exports from loaded javascript.
184
+ * @global
185
+ */
56
186
  declare const require: XpRequire;
187
+
188
+ /**
189
+ * Resolves a path to another file. Can use relative or absolute path.
190
+ *
191
+ * @example
192
+ * // Resolve relative to this
193
+ * var path = resolve('./other.html');
194
+ *
195
+ * @example
196
+ * // Reslove absolute
197
+ * var path = resolve('/path/to/other.html');
198
+ *
199
+ * @param {string} path Path to resolve.
200
+ * @returns {*} Reference to an object.
201
+ * @global
202
+ */
203
+ declare const resolve: (path: string) => object;
package/package.json CHANGED
@@ -1,32 +1,33 @@
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
- }
1
+ {
2
+ "name": "@enonic-types/global",
3
+ "version": "7.11.0-B2",
4
+ "description": "Global variables and functions type definition.",
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
+ "dependencies": {},
30
+ "publishConfig": {
31
+ "access": "public"
32
+ }
33
+ }