@enonic-types/lib-app 7.11.0-B1

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 +97 -0
  2. package/app.d.ts +115 -0
  3. package/package.json +32 -0
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # Enonic XP lib-app TS types
2
+
3
+ > TypeScript definitions for `lib-app` library of Enonic XP
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i --save-dev @enonic/lib-app
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-app"
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-app"
40
+ ]
41
+ }
42
+ }
43
+ ```
44
+
45
+ `example.ts`
46
+
47
+ ```ts
48
+ const {
49
+ createVirtualApplication,
50
+ deleteVirtualApplication,
51
+ get,
52
+ list,
53
+ getDescriptor,
54
+ hasVirtual,
55
+ hasReal
56
+ } = require('/lib/xp/app');
57
+ ```
58
+
59
+ More detailed explanation on how it works and how to type custom import function can be
60
+ found [here](https://github.com/enonic/xp/tree/master/modules/lib/typescript/README.md).
61
+
62
+ ### ES6-style import
63
+
64
+ 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
65
+ types mapping to your configuration.
66
+
67
+ `tsconfig.json`
68
+
69
+ ```diff
70
+ {
71
+ "compilerOptions": {
72
+ "types": [
73
+ "@enonic-types/lib-app"
74
+ ]
75
+ + "baseUrl": "./",
76
+ + "paths": {
77
+ + "/lib/xp/app": ["node_modules/@enonic-types/lib-app"],
78
+ + }
79
+ }
80
+ }
81
+ ```
82
+
83
+ `example.ts`
84
+
85
+ ```ts
86
+ import {
87
+ createVirtualApplication,
88
+ deleteVirtualApplication,
89
+ get,
90
+ list,
91
+ getDescriptor,
92
+ hasVirtual,
93
+ hasReal
94
+ } from '/lib/xp/app';
95
+ ```
96
+
97
+ Setting `baseUrl` and `paths` will allow the `tsc` to keep the valid paths in the resulting JavaScript files.
package/app.d.ts ADDED
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Application related functions.
3
+ *
4
+ * @example
5
+ * var schema = require('/lib/xp/app');
6
+ *
7
+ * @module app
8
+ */
9
+ declare global {
10
+ interface XpLibraries {
11
+ '/lib/xp/app': typeof import('./app');
12
+ }
13
+ }
14
+ export interface CreateVirtualApplicationParams {
15
+ key: string;
16
+ }
17
+ export interface Application {
18
+ key: string;
19
+ displayName: string | null;
20
+ vendorName: string | null;
21
+ vendorUrl: string | null;
22
+ url: string | null;
23
+ version: string | null;
24
+ systemVersion: string | null;
25
+ minSystemVersion: string | null;
26
+ maxSystemVersion: string | null;
27
+ modifiedTime: string | null;
28
+ started: boolean | null;
29
+ system: boolean | null;
30
+ }
31
+ /**
32
+ * Creates virtual application.
33
+ *
34
+ * @param {object} params JSON with the parameters.
35
+ * @param {string} params.key Application key.
36
+ *
37
+ * @returns {object} created application.
38
+ */
39
+ export declare function createVirtualApplication(params: CreateVirtualApplicationParams): Application;
40
+ export interface DeleteVirtualApplicationParams {
41
+ key: string;
42
+ }
43
+ /**
44
+ * Deletes virtual application.
45
+ *
46
+ * @param {object} params JSON with the parameters.
47
+ * @param {string} params.key Application key.
48
+ *
49
+ * @returns {boolean} deletion result.
50
+ */
51
+ export declare function deleteVirtualApplication(params: DeleteVirtualApplicationParams): boolean;
52
+ export interface GetApplicationParams {
53
+ key: string;
54
+ }
55
+ /**
56
+ * Fetches application by key.
57
+ *
58
+ * @param {object} params JSON with the parameters.
59
+ * @param {string} params.key Application key.
60
+ *
61
+ * @returns {Application} fetched application.
62
+ */
63
+ export declare function get(params: GetApplicationParams): Application;
64
+ /**
65
+ * Fetches both static and virtual applications.
66
+ *
67
+ * @returns {object[]} applications list.
68
+ */
69
+ export declare function list(): Application[];
70
+ export interface GetApplicationDescriptorParams {
71
+ key: string;
72
+ }
73
+ export interface Icon {
74
+ data: unknown;
75
+ mimeType: string;
76
+ modifiedTime: string;
77
+ }
78
+ export interface ApplicationDescriptor {
79
+ key: string;
80
+ description: string | null;
81
+ icon?: Icon;
82
+ }
83
+ /**
84
+ * Fetches application descriptor by key.
85
+ *
86
+ * @param {object} params JSON with the parameters.
87
+ * @param {string} params.key Application key.
88
+ *
89
+ * @returns {object} fetched application descriptor.
90
+ */
91
+ export declare function getDescriptor(params: GetApplicationDescriptorParams): ApplicationDescriptor;
92
+ export interface HasVirtualApplicationParams {
93
+ key: string;
94
+ }
95
+ /**
96
+ * Checks if there is a virtual app with the app key.
97
+ *
98
+ * @param {object} params JSON with the parameters.
99
+ * @param {string} params.key Application key.
100
+ *
101
+ * @returns {boolean} result.
102
+ */
103
+ export declare function hasVirtual(params: HasVirtualApplicationParams): boolean;
104
+ export interface HasRealApplicationParams {
105
+ key: string;
106
+ }
107
+ /**
108
+ * Checks if there is a real app with the app key.
109
+ *
110
+ * @param {object} params JSON with the parameters.
111
+ * @param {string} params.key Application key.
112
+ *
113
+ * @returns {boolean} result.
114
+ */
115
+ export declare function hasReal(params: HasRealApplicationParams): boolean;
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@enonic-types/lib-app",
3
+ "version": "7.11.0-B1",
4
+ "description": "Type definitions for lib-app.",
5
+ "types": "app.d.ts",
6
+ "files": [
7
+ "app.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
+ "lib-app",
17
+ "app",
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
+ }