@digipair/skill-cron 0.91.0-0 → 0.92.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.
@@ -0,0 +1,16 @@
1
+ import { PinsSettings } from '@digipair/engine';
2
+ export declare const initialize: (launcher: Function) => Promise<void>;
3
+ export declare const start: (path: string) => Promise<void>;
4
+ export declare const crons: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any[]>;
5
+ export declare const addCron: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<{
6
+ id: string;
7
+ time: any;
8
+ digipair: any;
9
+ reasoning: any;
10
+ enabled: boolean;
11
+ }>;
12
+ export declare const deleteCron: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<{
13
+ id: any;
14
+ }>;
15
+ export declare const enableCron: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
16
+ export declare const disableCron: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
package/package.json CHANGED
@@ -1,28 +1,14 @@
1
1
  {
2
2
  "name": "@digipair/skill-cron",
3
- "version": "0.91.0-0",
4
- "type": "module",
5
- "main": "dist/libs/skill-cron/index.cjs.js",
6
- "module": "dist/libs/skill-cron/index.esm.js",
7
- "types": "dist/libs/skill-cron/index.esm.d.ts",
8
- "exports": {
9
- "./package.json": "./libs/skill-cron/package.json",
10
- ".": {
11
- "development": "./dist/libs/skill-cron/src/index.ts",
12
- "types": "./dist/libs/skill-cron/index.esm.d.ts",
13
- "import": "./dist/libs/skill-cron/index.esm.js",
14
- "default": "./dist/libs/skill-cron/index.cjs.js"
15
- }
16
- },
3
+ "version": "0.92.0",
17
4
  "keywords": [
18
5
  "digipair",
19
- "web",
20
- "service"
6
+ "service",
7
+ "util"
21
8
  ],
22
- "nx": {
23
- "name": "skill-cron"
24
- },
25
9
  "dependencies": {
26
- "@digipair/engine": "0.91.0-0"
27
- }
28
- }
10
+ "cron": "^3.1.7"
11
+ },
12
+ "main": "./index.cjs.js",
13
+ "module": "./index.esm.js"
14
+ }
package/.swcrc DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "jsc": {
3
- "target": "es2017",
4
- "parser": {
5
- "syntax": "typescript",
6
- "decorators": true,
7
- "dynamicImport": true
8
- },
9
- "transform": {
10
- "decoratorMetadata": true,
11
- "legacyDecorator": true
12
- },
13
- "keepClassNames": true,
14
- "externalHelpers": true,
15
- "loose": true
16
- },
17
- "module": {
18
- "type": "es6"
19
- },
20
- "sourceMaps": true,
21
- "exclude": [
22
- "jest.config.ts",
23
- ".*\\.spec.tsx?$",
24
- ".*\\.test.tsx?$",
25
- "./src/jest-setup.ts$",
26
- "./**/jest-setup.ts$"
27
- ]
28
- }
package/README.md DELETED
@@ -1,7 +0,0 @@
1
- # mylib
2
-
3
- This library was generated with [Nx](https://nx.dev).
4
-
5
- ## Building
6
-
7
- Run `nx build mylib` to build the library.
package/eslint.config.mjs DELETED
@@ -1,22 +0,0 @@
1
- import baseConfig from '../../eslint.config.mjs';
2
-
3
- export default [
4
- ...baseConfig,
5
- {
6
- files: ['**/*.json'],
7
- rules: {
8
- '@nx/dependency-checks': [
9
- 'error',
10
- {
11
- ignoredFiles: [
12
- '{projectRoot}/eslint.config.{js,cjs,mjs}',
13
- '{projectRoot}/rollup.config.{js,ts,mjs,mts,cjs,cts}',
14
- ],
15
- },
16
- ],
17
- },
18
- languageOptions: {
19
- parser: await import('jsonc-eslint-parser'),
20
- },
21
- },
22
- ];
package/rollup.config.cjs DELETED
@@ -1,28 +0,0 @@
1
- const { withNx } = require('@nx/rollup/with-nx');
2
-
3
- module.exports = withNx(
4
- {
5
- main: 'libs/skill-cron/src/index.ts',
6
- outputPath: 'dist/libs/skill-cron',
7
- tsConfig: 'libs/skill-cron/tsconfig.lib.json',
8
- compiler: 'swc',
9
- format: ['esm', "cjs"],
10
- assets: [
11
- {
12
- input: 'libs/skill-cron/',
13
- glob: 'package.json',
14
- output: '.'
15
- },
16
- {
17
- input: 'libs/skill-cron/src/',
18
- glob: '*.json',
19
- output: '.'
20
- }
21
- ]
22
- },
23
- {
24
- // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
25
- // e.g.
26
- // output: { sourcemap: true },
27
- }
28
- );
@@ -1,7 +0,0 @@
1
- import { skillCron } from './skill-cron';
2
-
3
- describe('skillCron', () => {
4
- it('should work', () => {
5
- expect(skillCron()).toEqual('skill-cron');
6
- });
7
- });
@@ -1,235 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import { PinsSettings } from '@digipair/engine';
3
- import { promises } from 'fs';
4
- import { CronJob } from 'cron';
5
- import { v4 } from 'uuid';
6
-
7
- class CronService {
8
- private jobs: { [key: string]: CronJob } = {};
9
- private startTask!: Function;
10
-
11
- async initialize(startTask: Function) {
12
- this.startTask = startTask;
13
- }
14
-
15
- async start(path: string, utcOffset = 'Europe/Paris') {
16
- const content = await promises.readFile(`${path}/planning.jsonl`, 'utf8');
17
- const lines = content.split('\n').filter(line => line !== '');
18
- const planning = lines.map((line: string) => JSON.parse(line));
19
-
20
- for (const plan of planning) {
21
- if (plan.time === '@startup') {
22
- if (plan.enabled) {
23
- await this.startTask(path, plan.digipair, plan.reasoning);
24
- }
25
- continue;
26
- }
27
-
28
- const job = new CronJob(
29
- plan.time,
30
- async () => {
31
- await this.startTask(path, plan.digipair, plan.reasoning);
32
- },
33
- null,
34
- !!plan.enabled,
35
- utcOffset,
36
- );
37
-
38
- if (this.jobs[plan.id]) {
39
- this.jobs[plan.id].stop();
40
- }
41
-
42
- this.jobs[plan.id] = job;
43
- }
44
- }
45
-
46
- private addJob(
47
- path: string,
48
- id: string,
49
- digipair: string,
50
- reasoning: string,
51
- time: string,
52
- utcOffset: string,
53
- ) {
54
- if (time === '@startup') {
55
- this.startTask(path, digipair, reasoning);
56
- return;
57
- }
58
-
59
- const job = new CronJob(
60
- time,
61
- async () => {
62
- await this.startTask(path, digipair, reasoning);
63
- },
64
- null,
65
- true,
66
- utcOffset,
67
- );
68
-
69
- if (this.jobs[id]) {
70
- this.jobs[id].stop();
71
- }
72
-
73
- this.jobs[id] = job;
74
- }
75
-
76
- private deleteJob(id: string) {
77
- if (!this.jobs[id]) {
78
- return;
79
- }
80
-
81
- this.jobs[id].stop();
82
- delete this.jobs[id];
83
- }
84
-
85
- private enableJob(id: string) {
86
- if (!this.jobs[id]) {
87
- return;
88
- }
89
-
90
- this.jobs[id].start();
91
- }
92
-
93
- private disableJob(id: string) {
94
- if (!this.jobs[id]) {
95
- return;
96
- }
97
-
98
- this.jobs[id].stop();
99
- }
100
-
101
- async crons(params: any, _pinsSettingsList: PinsSettings[], context: any) {
102
- const {
103
- path = context.privates?.EDITOR_PATH ??
104
- (process.env['DIGIPAIR_FACTORY_PATH']
105
- ? `${process.env['DIGIPAIR_FACTORY_PATH']}/digipairs`
106
- : './factory/digipairs'),
107
- } = params;
108
-
109
- const text = await promises.readFile(`${path}/planning.jsonl`, 'utf8');
110
- const lines = text.split('\n').filter(line => line !== '');
111
- const crons = lines.map((line: string) => JSON.parse(line));
112
-
113
- return crons;
114
- }
115
-
116
- async addCron(params: any, _pinsSettingsList: PinsSettings[], context: any) {
117
- const {
118
- path = context.privates?.EDITOR_PATH ??
119
- (process.env['DIGIPAIR_FACTORY_PATH']
120
- ? `${process.env['DIGIPAIR_FACTORY_PATH']}/digipairs`
121
- : './factory/digipairs'),
122
- utcOffset = 'Europe/Paris',
123
- time,
124
- digipair,
125
- reasoning,
126
- } = params;
127
-
128
- const cron = {
129
- id: v4(),
130
- time,
131
- digipair,
132
- reasoning,
133
- enabled: true,
134
- };
135
- await promises.appendFile(`${path}/planning.jsonl`, '\n' + JSON.stringify(cron), 'utf8');
136
- this.addJob(path, cron.id, digipair, reasoning, time, utcOffset);
137
-
138
- return cron;
139
- }
140
-
141
- async deleteCron(params: any, _pinsSettingsList: PinsSettings[], context: any) {
142
- const {
143
- path = context.privates?.EDITOR_PATH ??
144
- (process.env['DIGIPAIR_FACTORY_PATH']
145
- ? `${process.env['DIGIPAIR_FACTORY_PATH']}/digipairs`
146
- : './factory/digipairs'),
147
- id,
148
- } = params;
149
-
150
- const text = await promises.readFile(`${path}/planning.jsonl`, 'utf8');
151
- const lines = text.split('\n').filter(line => line !== '');
152
- const crons = lines
153
- .map((line: string) => JSON.parse(line))
154
- .filter((cron: any) => cron.id !== id);
155
- const ndjson = crons.map(line => JSON.stringify(line)).join('\n');
156
-
157
- this.deleteJob(id);
158
- await promises.writeFile(`${path}/planning.jsonl`, ndjson, 'utf8');
159
-
160
- return { id };
161
- }
162
-
163
- async enableCron(params: any, _pinsSettingsList: PinsSettings[], context: any) {
164
- const {
165
- path = context.privates?.EDITOR_PATH ??
166
- (process.env['DIGIPAIR_FACTORY_PATH']
167
- ? `${process.env['DIGIPAIR_FACTORY_PATH']}/digipairs`
168
- : './factory/digipairs'),
169
- id,
170
- } = params;
171
-
172
- const text = await promises.readFile(`${path}/planning.jsonl`, 'utf8');
173
- const lines = text.split('\n').filter(line => line !== '');
174
- const crons = lines.map((line: string) => JSON.parse(line));
175
- const cron = crons.find((cron: any) => cron.id === id);
176
-
177
- cron.enabled = true;
178
-
179
- const ndjson = crons.map(line => JSON.stringify(line)).join('\n');
180
- await promises.writeFile(`${path}/planning.jsonl`, ndjson, 'utf8');
181
-
182
- if (cron.time === '@startup') {
183
- this.startTask(path, cron.digipair, cron.reasoning);
184
- } else {
185
- this.enableJob(id);
186
- }
187
-
188
- return cron;
189
- }
190
-
191
- async disableCron(params: any, _pinsSettingsList: PinsSettings[], context: any) {
192
- const {
193
- path = context.privates?.EDITOR_PATH ??
194
- (process.env['DIGIPAIR_FACTORY_PATH']
195
- ? `${process.env['DIGIPAIR_FACTORY_PATH']}/digipairs`
196
- : './factory/digipairs'),
197
- id,
198
- } = params;
199
-
200
- const text = await promises.readFile(`${path}/planning.jsonl`, 'utf8');
201
- const lines = text.split('\n').filter(line => line !== '');
202
- const crons = lines.map((line: string) => JSON.parse(line));
203
- const cron = crons.find((cron: any) => cron.id === id);
204
-
205
- cron.enabled = false;
206
- this.disableJob(id);
207
-
208
- const ndjson = crons.map(line => JSON.stringify(line)).join('\n');
209
- await promises.writeFile(`${path}/planning.jsonl`, ndjson, 'utf8');
210
-
211
- return cron;
212
- }
213
- }
214
-
215
- let instance: CronService;
216
-
217
- export const initialize = (launcher: Function) =>
218
- (instance = new CronService()).initialize(launcher);
219
-
220
- export const start = (path: string) => instance.start(path);
221
-
222
- export const crons = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
223
- instance.crons(params, pinsSettingsList, context);
224
-
225
- export const addCron = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
226
- instance.addCron(params, pinsSettingsList, context);
227
-
228
- export const deleteCron = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
229
- instance.deleteCron(params, pinsSettingsList, context);
230
-
231
- export const enableCron = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
232
- instance.enableCron(params, pinsSettingsList, context);
233
-
234
- export const disableCron = (params: any, pinsSettingsList: PinsSettings[], context: any) =>
235
- instance.disableCron(params, pinsSettingsList, context);
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "files": [],
4
- "include": [],
5
- "references": [
6
- {
7
- "path": "../engine"
8
- },
9
- {
10
- "path": "./tsconfig.lib.json"
11
- }
12
- ]
13
- }
package/tsconfig.lib.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "dist",
6
- "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
7
- "emitDeclarationOnly": true,
8
- "module": "esnext",
9
- "moduleResolution": "node",
10
- "forceConsistentCasingInFileNames": true,
11
- "types": ["node"]
12
- },
13
- "include": ["src/**/*.ts"],
14
- "references": [
15
- {
16
- "path": "../engine/tsconfig.lib.json"
17
- }
18
- ]
19
- }
File without changes
File without changes
File without changes