@enonic-types/lib-scheduler 7.11.0-B1 → 7.11.0-B4

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 +19 -28
  2. package/package.json +4 -1
  3. package/scheduler.d.ts +32 -34
package/README.md CHANGED
@@ -1,70 +1,61 @@
1
1
  # Enonic XP lib-scheduler TS types
2
2
 
3
3
  > TypeScript definitions for `lib-scheduler` library of Enonic XP
4
+
4
5
  ## Install
5
6
 
6
7
  ```bash
7
- npm i --save-dev @enonic/lib-scheduler
8
+ npm i --save-dev @enonic-types/lib-scheduler
8
9
  ```
9
10
 
10
11
  ## Use
11
12
 
12
- Add the corresponding types to your `tsconfig.json` file that is used for application's server-side TypeScript code.
13
-
14
- `tsconfig.json`
15
- ```json
16
- {
17
- "compilerOptions": {
18
- "types": [
19
- "@enonic-types/lib-scheduler"
20
- ]
21
- }
22
- }
23
- ```
24
-
25
13
  ### Require and custom imports
26
14
 
27
- To make `require` work out of box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP global objects, e.g. `log`, `app`, `__`, etc, requiring library by the default path will return typed object.
15
+ To make `require` work out of the box, you must install and add the `@enonic-types/global` types. Aside from providing definitions for XP
16
+ global objects, e.g. `log`, `app`, `__`, etc, requiring a library by the default path will return typed object.
28
17
 
29
18
  `tsconfig.json`
30
- ```diff
19
+
20
+ ```json
31
21
  {
32
22
  "compilerOptions": {
33
23
  "types": [
34
- + "@enonic-types/global"
35
- "@enonic-types/lib-scheduler"
24
+ "@enonic-types/global"
36
25
  ]
37
26
  }
38
27
  }
39
28
  ```
40
29
 
41
30
  `example.ts`
31
+
42
32
  ```ts
43
33
  const {create, modify} = require('/lib/xp/scheduler');
44
34
  ```
45
35
 
46
- More detailed explanation on how it works and how to type custom import function can be found [here](https://github.com/enonic/xp/tree/master/modules/lib/typescript/README.md).
36
+ More detailed explanation on how it works and how to type custom import function can be
37
+ found [here](https://developer.enonic.com/docs/xp/stable/api).
47
38
 
48
39
  ### ES6-style import
49
40
 
50
- 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 types mapping to your configuration.
41
+ 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
42
+ types mapping to your configuration.
51
43
 
52
44
  `tsconfig.json`
53
- ```diff
45
+
46
+ ```json
54
47
  {
55
48
  "compilerOptions": {
56
- "types": [
57
- "@enonic-types/lib-scheduler"
58
- ]
59
- + "baseUrl": "./",
60
- + "paths": {
61
- + "/lib/xp/scheduler": ["node_modules/@enonic-types/lib-scheduler"],
62
- + }
49
+ "baseUrl": "./",
50
+ "paths": {
51
+ "/lib/xp/scheduler": ["node_modules/@enonic-types/lib-scheduler"]
52
+ }
63
53
  }
64
54
  }
65
55
  ```
66
56
 
67
57
  `example.ts`
58
+
68
59
  ```ts
69
60
  import {create, modify} from '/lib/xp/scheduler';
70
61
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enonic-types/lib-scheduler",
3
- "version": "7.11.0-B1",
3
+ "version": "7.11.0-B4",
4
4
  "description": "Type definitions for lib-scheduler.",
5
5
  "types": "scheduler.d.ts",
6
6
  "files": [
@@ -26,6 +26,9 @@
26
26
  "url": "https://github.com/enonic/xp/issues"
27
27
  },
28
28
  "homepage": "https://github.com/enonic/xp/tree/master#readme",
29
+ "dependencies": {
30
+ "@enonic-types/core": "7.11.0-B4"
31
+ },
29
32
  "publishConfig": {
30
33
  "access": "public"
31
34
  }
package/scheduler.d.ts CHANGED
@@ -11,43 +11,41 @@ declare global {
11
11
  '/lib/xp/scheduler': typeof import('./scheduler');
12
12
  }
13
13
  }
14
+ import type { UserKey } from '@enonic-types/core';
15
+ export type { PrincipalKey, UserKey, GroupKey, RoleKey } from '@enonic-types/core';
14
16
  export declare type EditorFn<T> = (value: T) => T;
15
- export declare type ScheduleType = 'CRON' | 'ONE_TIME';
16
- export interface Schedule {
17
- value: string;
18
- type: ScheduleType;
19
- timezone: string;
20
- }
21
- export interface CreateScheduledJobParams {
17
+ export interface CreateScheduledJobParams<Config extends object = Record<string, unknown>> {
22
18
  name: string;
23
- description: string;
19
+ description?: string;
24
20
  descriptor: string;
25
- config: Record<string, unknown>;
26
- schedule: Schedule;
27
- user: string;
21
+ config?: Config;
22
+ schedule: OneTimeSchedule | CronSchedule;
23
+ user?: UserKey;
28
24
  enabled: boolean;
29
25
  }
30
- export interface OnTimeSchedule {
26
+ export interface OneTimeSchedule {
27
+ type: 'ONE_TIME';
31
28
  value: string;
32
- type: ScheduleType;
33
29
  }
34
- export interface CronSchedule extends OnTimeSchedule {
30
+ export interface CronSchedule {
31
+ type: 'CRON';
32
+ value: string;
35
33
  timeZone: string;
36
34
  }
37
- export interface ScheduleJob {
35
+ export interface ScheduledJob<Config extends object = Record<string, unknown>> {
38
36
  name: string;
39
37
  descriptor: string;
40
- description: string;
38
+ description?: string | null;
41
39
  enabled: boolean;
42
- config?: Record<string, unknown> | null;
43
- user?: string | null;
44
- creator?: string | null;
45
- modifier?: string | null;
46
- createdTime?: string | null;
47
- modifiedTime?: string | null;
40
+ config?: Config | null;
41
+ user?: UserKey | null;
42
+ creator: UserKey;
43
+ modifier: UserKey;
44
+ createdTime: string;
45
+ modifiedTime: string;
48
46
  lastRun?: string | null;
49
47
  lastTaskId?: string | null;
50
- schedule: OnTimeSchedule | CronSchedule;
48
+ schedule: OneTimeSchedule | CronSchedule;
51
49
  }
52
50
  /**
53
51
  * Creates a job to be scheduled.
@@ -56,20 +54,20 @@ export interface ScheduleJob {
56
54
  *
57
55
  * @param {object} params JSON with the parameters.
58
56
  * @param {string} params.name unique job name.
59
- * @param {string} params.description job description.
57
+ * @param {string} [params.description] job description.
60
58
  * @param {string} params.descriptor descriptor of the task to be scheduled.
61
- * @param {object} params.config config of the task to be scheduled.
59
+ * @param {object} [params.config] config of the task to be scheduled.
62
60
  * @param {object} params.schedule task time run config.
63
- * @param {string} params.schedule.value schedule value according to it's type.
61
+ * @param {string} params.schedule.value schedule value according to its type.
64
62
  * @param {string} params.schedule.type schedule type (CRON | ONE_TIME).
65
63
  * @param {string} params.schedule.timezone time zone of cron scheduling.
66
- * @param {string} params.user key of the user that submitted the task.
64
+ * @param {string} [params.user] key of the user that submitted the task.
67
65
  * @param {boolean} params.enabled job is active or not.
68
66
  */
69
- export declare function create(params: CreateScheduledJobParams): ScheduleJob;
70
- export interface ModifyScheduledJobParams {
67
+ export declare function create<Config extends object = Record<string, unknown>>(params: CreateScheduledJobParams<Config>): ScheduledJob<Config>;
68
+ export interface ModifyScheduledJobParams<Config extends object = Record<string, unknown>> {
71
69
  name: string;
72
- editor: EditorFn<ScheduleJob>;
70
+ editor: EditorFn<ScheduledJob<Config>>;
73
71
  }
74
72
  /**
75
73
  * Modifies scheduled job.
@@ -80,7 +78,7 @@ export interface ModifyScheduledJobParams {
80
78
  * @param {string} params.name unique job name.
81
79
  * @param {function} params.editor editor callback function, has editable existing job as a param.
82
80
  */
83
- export declare function modify(params: ModifyScheduledJobParams): ScheduleJob;
81
+ export declare function modify<Config extends object = Record<string, unknown>>(params: ModifyScheduledJobParams<Config>): ScheduledJob<Config>;
84
82
  export interface DeleteScheduledJobParams {
85
83
  name: string;
86
84
  }
@@ -103,13 +101,13 @@ export interface GetScheduledJobParams {
103
101
  * @example-ref examples/scheduler/get.js
104
102
  *
105
103
  * @param {object} params JSON with the parameters.
106
- * @param {string} params.name job to be deleted name.
104
+ * @param {string} params.name job to be fetched name.
107
105
  */
108
- export declare function get(params: GetScheduledJobParams): ScheduleJob | null;
106
+ export declare function get<Config extends object = Record<string, unknown>>(params: GetScheduledJobParams): ScheduledJob<Config> | null;
109
107
  /**
110
108
  * Lists scheduled jobs.
111
109
  *
112
110
  * @example-ref examples/scheduler/list.js
113
111
  *
114
112
  */
115
- export declare function list(): ScheduleJob[];
113
+ export declare function list<Config extends object = Record<string, unknown>>(): ScheduledJob<Config>[];