@enonic-types/lib-export 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.
Files changed (3) hide show
  1. package/README.md +81 -0
  2. package/export.d.ts +95 -0
  3. package/package.json +36 -0
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Enonic XP lib-export TS types
2
+
3
+ > TypeScript definitions for `lib-export` library of Enonic XP
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i --save-dev @enonic/lib-export
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-export"
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-export"
40
+ ]
41
+ }
42
+ }
43
+ ```
44
+
45
+ `example.ts`
46
+
47
+ ```ts
48
+ const {importNodes, exportNodes} = require('/lib/xp/export');
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-export"
66
+ ]
67
+ + "baseUrl": "./",
68
+ + "paths": {
69
+ + "/lib/xp/export": ["node_modules/@enonic-types/lib-export"],
70
+ + }
71
+ }
72
+ }
73
+ ```
74
+
75
+ `example.ts`
76
+
77
+ ```ts
78
+ import {importNodes, exportNodes} from '/lib/xp/export';
79
+ ```
80
+
81
+ Setting `baseUrl` and `paths` will allow the `tsc` to keep the valid paths in the resulting JavaScript files.
package/export.d.ts ADDED
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Export related functions.
3
+ *
4
+ * @example
5
+ * var exportLib = require('/lib/xp/export');
6
+ *
7
+ * @module export
8
+ */
9
+ declare global {
10
+ interface XpLibraries {
11
+ '/lib/xp/export': typeof import('./export');
12
+ }
13
+ }
14
+ export interface ResourceKey {
15
+ applicationKey: string;
16
+ path: string;
17
+ uri: string;
18
+ root: boolean;
19
+ name: string;
20
+ extension: string;
21
+ }
22
+ export interface ImportNodesParams {
23
+ source: string | object;
24
+ targetNodePath: string;
25
+ xslt?: string | ResourceKey;
26
+ xsltParams?: unknown;
27
+ includeNodeIds?: boolean;
28
+ includePermissions?: boolean;
29
+ nodeResolved: (numberOfNodes: number) => void;
30
+ nodeImported: (numberOfImportedNodes: number) => void;
31
+ }
32
+ export interface ImportNodesError {
33
+ exception: string;
34
+ message: string;
35
+ stacktrace: string[];
36
+ }
37
+ export interface ImportNodesResult {
38
+ addedNodes: string[];
39
+ updatedNodes: string[];
40
+ importedBinaries: string[];
41
+ importErrors: ImportNodesError[];
42
+ }
43
+ /**
44
+ * Import nodes from a nodes-export.
45
+ * Could be used to import node-export from exports directory or from application resource files.
46
+ * Optionally pre-transforms node XML node files with XSLT before import.
47
+ *
48
+ * @example-ref examples/export/importNodes.js
49
+ *
50
+ * @param {object} params JSON with the parameters.
51
+ * @param {string|object} params.source Either name of nodes-export located in exports directory or application resource key.
52
+ * @param {string} params.targetNodePath Target path for imported nodes.
53
+ * @param {string|object} [params.xslt] XSLT file name in exports directory or application resource key. Used for XSLT transformation.
54
+ * @param {object} [params.xsltParams] Parameters used in XSLT transformation.
55
+ * @param {boolean} [params.includeNodeIds=false] Set to true to use node IDs from the import, false to generate new node IDs.
56
+ * @param {boolean} [params.includePermissions=false] Set to true to use Node permissions from the import, false to use target node permissions.
57
+ * @param {function} [params.nodeResolved] A function to be called before import starts with number of nodes to import.
58
+ * @param {function} [params.nodeImported] A function to be called during import with number of nodes imported since last call.
59
+ *
60
+ * @returns {ImportNodesResult} Node import results.
61
+ */
62
+ export declare function importNodes(params: ImportNodesParams): ImportNodesResult;
63
+ export interface ExportNodesParams {
64
+ sourceNodePath: string;
65
+ exportName: string;
66
+ includeNodeIds?: boolean;
67
+ includeVersions?: boolean;
68
+ nodeResolved: (numberOfNodes: number) => void;
69
+ nodeExported: (numberOfExportedNodes: number) => void;
70
+ }
71
+ export interface ExportNodesError {
72
+ message: string;
73
+ }
74
+ export interface ExportNodesResult {
75
+ exportedNodes: string[];
76
+ exportedBinaries: string[];
77
+ exportErrors: ExportNodesError[];
78
+ }
79
+ /**
80
+ * Export nodes to a nodes-export.
81
+ * Export is created in exports directory.
82
+ *
83
+ * @example-ref examples/export/exportNodes.js
84
+ *
85
+ * @param {object} params JSON with the parameters.
86
+ * @param {string} params.sourceNodePath Source nodes path.
87
+ * @param {string} params.exportName Export name.
88
+ * @param {boolean} [params.includeNodeIds=true] Set to true to export node IDs.
89
+ * @param {boolean} [params.includeVersions=false] Set to true to export all node versions.
90
+ * @param {function} [params.nodeResolved] A function to be called before export starts with number of nodes to export.
91
+ * @param {function} [params.nodeExported] A function to be called during export with number of nodes exported since last call.
92
+ *
93
+ * @returns {ExportNodesResult} Node export results.
94
+ */
95
+ export declare function exportNodes(params: ExportNodesParams): ExportNodesResult;
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@enonic-types/lib-export",
3
+ "version": "0.1.0",
4
+ "description": "Type definitions for lib-export.",
5
+ "types": "export.d.ts",
6
+ "files": [
7
+ "export.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-export",
21
+ "export",
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
+ }