@owservable/actions 1.6.3 → 1.7.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.
- package/README.md +240 -17
- package/lib/src/abstracts/action.js.map +1 -0
- package/lib/src/functions/find.command.action.d.ts +2 -0
- package/lib/src/functions/find.command.action.js +40 -0
- package/lib/src/functions/find.command.action.js.map +1 -0
- package/lib/{functions → src/functions}/get.option.and.default.value.js +1 -1
- package/lib/src/functions/get.option.and.default.value.js.map +1 -0
- package/lib/src/functions/run.action.as.command.d.ts +2 -0
- package/lib/{functions → src/functions}/run.action.as.command.js +7 -6
- package/lib/src/functions/run.action.as.command.js.map +1 -0
- package/lib/src/interfaces/action.as.command.interface.js.map +1 -0
- package/lib/src/interfaces/action.as.controller.interface.js.map +1 -0
- package/lib/src/interfaces/action.as.cronjob.interface.js.map +1 -0
- package/lib/src/interfaces/action.as.watcher.interface.js.map +1 -0
- package/lib/src/interfaces/action.as.worker.interface.js.map +1 -0
- package/lib/src/interfaces/action.interface.js.map +1 -0
- package/lib/{owservable.actions.d.ts → src/owservable.actions.d.ts} +4 -3
- package/lib/{owservable.actions.js → src/owservable.actions.js} +0 -2
- package/lib/src/owservable.actions.js.map +1 -0
- package/lib/src/types/command.context.type.d.ts +6 -0
- package/lib/src/types/command.context.type.js +3 -0
- package/lib/src/types/command.context.type.js.map +1 -0
- package/lib/src/types/command.option.type.d.ts +6 -0
- package/lib/src/types/command.option.type.js +3 -0
- package/lib/src/types/command.option.type.js.map +1 -0
- package/lib/src/types/command.signature.type.d.ts +7 -0
- package/lib/src/types/command.signature.type.js +3 -0
- package/lib/src/types/command.signature.type.js.map +1 -0
- package/lib/test/abstracts/action.spec.d.ts +1 -0
- package/lib/test/abstracts/action.spec.js +60 -0
- package/lib/test/abstracts/action.spec.js.map +1 -0
- package/lib/test/functions/find.command.action.spec.d.ts +1 -0
- package/lib/test/functions/find.command.action.spec.js +341 -0
- package/lib/test/functions/find.command.action.spec.js.map +1 -0
- package/lib/test/functions/get.option.and.default.value.spec.d.ts +1 -0
- package/lib/test/functions/get.option.and.default.value.spec.js +47 -0
- package/lib/test/functions/get.option.and.default.value.spec.js.map +1 -0
- package/lib/test/functions/run.action.as.command.spec.d.ts +1 -0
- package/lib/test/functions/run.action.as.command.spec.js +136 -0
- package/lib/test/functions/run.action.as.command.spec.js.map +1 -0
- package/lib/test/interfaces/action.as.command.interface.spec.d.ts +1 -0
- package/lib/test/interfaces/action.as.command.interface.spec.js +77 -0
- package/lib/test/interfaces/action.as.command.interface.spec.js.map +1 -0
- package/lib/test/interfaces/action.as.controller.interface.spec.d.ts +1 -0
- package/lib/test/interfaces/action.as.controller.interface.spec.js +10 -0
- package/lib/test/interfaces/action.as.controller.interface.spec.js.map +1 -0
- package/lib/test/interfaces/action.as.cronjob.interface.spec.d.ts +1 -0
- package/lib/test/interfaces/action.as.cronjob.interface.spec.js +10 -0
- package/lib/test/interfaces/action.as.cronjob.interface.spec.js.map +1 -0
- package/lib/test/interfaces/action.as.watcher.interface.spec.d.ts +1 -0
- package/lib/test/interfaces/action.as.watcher.interface.spec.js +10 -0
- package/lib/test/interfaces/action.as.watcher.interface.spec.js.map +1 -0
- package/lib/test/interfaces/action.as.worker.interface.spec.d.ts +1 -0
- package/lib/test/interfaces/action.as.worker.interface.spec.js +10 -0
- package/lib/test/interfaces/action.as.worker.interface.spec.js.map +1 -0
- package/lib/test/interfaces/action.interface.spec.d.ts +1 -0
- package/lib/test/interfaces/action.interface.spec.js +59 -0
- package/lib/test/interfaces/action.interface.spec.js.map +1 -0
- package/lib/test/owservable.actions.spec.d.ts +1 -0
- package/lib/test/owservable.actions.spec.js +25 -0
- package/lib/test/owservable.actions.spec.js.map +1 -0
- package/package.json +91 -96
- package/lib/abstracts/action.js.map +0 -1
- package/lib/functions/find.command.action.d.ts +0 -3
- package/lib/functions/find.command.action.js +0 -23
- package/lib/functions/find.command.action.js.map +0 -1
- package/lib/functions/get.option.and.default.value.js.map +0 -1
- package/lib/functions/run.action.as.command.d.ts +0 -3
- package/lib/functions/run.action.as.command.js.map +0 -1
- package/lib/interfaces/action.as.command.interface.js.map +0 -1
- package/lib/interfaces/action.as.controller.interface.js.map +0 -1
- package/lib/interfaces/action.as.cronjob.interface.js.map +0 -1
- package/lib/interfaces/action.as.watcher.interface.js.map +0 -1
- package/lib/interfaces/action.as.worker.interface.js.map +0 -1
- package/lib/interfaces/action.interface.js.map +0 -1
- package/lib/owservable.actions.js.map +0 -1
- /package/lib/{abstracts → src/abstracts}/action.d.ts +0 -0
- /package/lib/{abstracts → src/abstracts}/action.js +0 -0
- /package/lib/{functions → src/functions}/get.option.and.default.value.d.ts +0 -0
- /package/lib/{interfaces → src/interfaces}/action.as.command.interface.d.ts +0 -0
- /package/lib/{interfaces → src/interfaces}/action.as.command.interface.js +0 -0
- /package/lib/{interfaces → src/interfaces}/action.as.controller.interface.d.ts +0 -0
- /package/lib/{interfaces → src/interfaces}/action.as.controller.interface.js +0 -0
- /package/lib/{interfaces → src/interfaces}/action.as.cronjob.interface.d.ts +0 -0
- /package/lib/{interfaces → src/interfaces}/action.as.cronjob.interface.js +0 -0
- /package/lib/{interfaces → src/interfaces}/action.as.watcher.interface.d.ts +0 -0
- /package/lib/{interfaces → src/interfaces}/action.as.watcher.interface.js +0 -0
- /package/lib/{interfaces → src/interfaces}/action.as.worker.interface.d.ts +0 -0
- /package/lib/{interfaces → src/interfaces}/action.as.worker.interface.js +0 -0
- /package/lib/{interfaces → src/interfaces}/action.interface.d.ts +0 -0
- /package/lib/{interfaces → src/interfaces}/action.interface.js +0 -0
package/README.md
CHANGED
|
@@ -2,28 +2,251 @@
|
|
|
2
2
|
|
|
3
3
|
# @owservable/actions
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A TypeScript library implementing the Action Pattern for creating reusable, executable units of work that can be run as commands, cronjobs, watchers, workers, or controllers.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## 🚀 Features
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- **Action Pattern Implementation**: Structured approach to organizing business logic
|
|
10
|
+
- **Multiple Execution Contexts**: Run actions as commands, cronjobs, watchers, workers, or controllers
|
|
11
|
+
- **Commander.js Integration**: Built-in CLI command support with option parsing
|
|
12
|
+
- **TypeScript Support**: Full type safety with comprehensive interfaces
|
|
13
|
+
- **Flexible Architecture**: Abstract base class with specialized interfaces
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
## 📦 Installation
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- getOptionAndDefaultValue
|
|
17
|
+
```bash
|
|
18
|
+
npm install @owservable/actions
|
|
19
|
+
```
|
|
17
20
|
|
|
21
|
+
or
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
- ActionAsWatcherInterface
|
|
23
|
-
- ActionAsCommandInterface
|
|
24
|
-
- ActionAsCronjobInterface
|
|
25
|
-
- ActionAsControllerInterface
|
|
23
|
+
```bash
|
|
24
|
+
yarn add @owservable/actions
|
|
25
|
+
```
|
|
26
26
|
|
|
27
|
+
or
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add @owservable/actions
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 🔧 Usage
|
|
34
|
+
|
|
35
|
+
### Basic Action Implementation
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { Action, ActionInterface } from '@owservable/actions';
|
|
39
|
+
|
|
40
|
+
class MyAction extends Action implements ActionInterface {
|
|
41
|
+
protected _description = 'My custom action';
|
|
42
|
+
|
|
43
|
+
async handle(...args: any[]): Promise<any> {
|
|
44
|
+
// Your business logic here
|
|
45
|
+
console.log('Action executed with args:', args);
|
|
46
|
+
return { success: true };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
description(): string {
|
|
50
|
+
return this._description;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Command Line Action
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { Action, ActionAsCommandInterface } from '@owservable/actions';
|
|
59
|
+
|
|
60
|
+
class MyCommandAction extends Action implements ActionAsCommandInterface {
|
|
61
|
+
protected _signature = 'my-command {--option=default}';
|
|
62
|
+
protected _description = 'My command action';
|
|
63
|
+
|
|
64
|
+
async handle(...args: any[]): Promise<any> {
|
|
65
|
+
// Your business logic here
|
|
66
|
+
return { success: true };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async asCommand(options: any): Promise<void> {
|
|
70
|
+
console.log('Command executed with options:', options);
|
|
71
|
+
await this.handle(options);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
signature(): string {
|
|
75
|
+
return this._signature;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
description(): string {
|
|
79
|
+
return this._description;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Running Actions as Commands
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { runActionAsCommand } from '@owservable/actions';
|
|
88
|
+
|
|
89
|
+
const action = new MyCommandAction();
|
|
90
|
+
await runActionAsCommand(action);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Cronjob Action
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { Action, ActionAsCronjobInterface } from '@owservable/actions';
|
|
97
|
+
|
|
98
|
+
class MyCronjobAction extends Action implements ActionAsCronjobInterface {
|
|
99
|
+
protected _schedule = '0 0 * * *'; // Daily at midnight
|
|
100
|
+
protected _description = 'Daily cleanup job';
|
|
101
|
+
|
|
102
|
+
async handle(...args: any[]): Promise<any> {
|
|
103
|
+
// Your cronjob logic here
|
|
104
|
+
return { success: true };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async asCronjob(): Promise<void> {
|
|
108
|
+
console.log('Cronjob executed');
|
|
109
|
+
await this.handle();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
schedule(): string {
|
|
113
|
+
return this._schedule;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
description(): string {
|
|
117
|
+
return this._description;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Watcher Action
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { Action, ActionAsWatcherInterface } from '@owservable/actions';
|
|
126
|
+
|
|
127
|
+
class MyWatcherAction extends Action implements ActionAsWatcherInterface {
|
|
128
|
+
protected _description = 'File watcher action';
|
|
129
|
+
|
|
130
|
+
async handle(...args: any[]): Promise<any> {
|
|
131
|
+
// Your watcher logic here
|
|
132
|
+
return { success: true };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async asWatcher(): Promise<void> {
|
|
136
|
+
console.log('Watcher executed');
|
|
137
|
+
await this.handle();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
description(): string {
|
|
141
|
+
return this._description;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## 📚 API Documentation
|
|
147
|
+
|
|
148
|
+
### Base Classes
|
|
149
|
+
|
|
150
|
+
#### `Action`
|
|
151
|
+
Abstract base class providing common functionality for all actions.
|
|
152
|
+
|
|
153
|
+
**Properties:**
|
|
154
|
+
- `_signature`: Command signature for CLI actions
|
|
155
|
+
- `_description`: Human-readable description
|
|
156
|
+
- `_schedule`: Cron schedule for cronjob actions
|
|
157
|
+
|
|
158
|
+
**Methods:**
|
|
159
|
+
- `signature()`: Returns the command signature
|
|
160
|
+
- `description()`: Returns the action description
|
|
161
|
+
- `schedule()`: Returns the cron schedule
|
|
162
|
+
|
|
163
|
+
### Interfaces
|
|
164
|
+
|
|
165
|
+
#### `ActionInterface`
|
|
166
|
+
Base interface that all actions must implement.
|
|
167
|
+
|
|
168
|
+
**Methods:**
|
|
169
|
+
- `description(): string` - Returns action description
|
|
170
|
+
- `handle(...args: any[]): Promise<any>` - Main action logic
|
|
171
|
+
|
|
172
|
+
#### `ActionAsCommandInterface`
|
|
173
|
+
Interface for actions that can be run as CLI commands.
|
|
174
|
+
|
|
175
|
+
**Extends:** `ActionInterface`
|
|
176
|
+
|
|
177
|
+
**Methods:**
|
|
178
|
+
- `signature(): string` - Returns command signature
|
|
179
|
+
- `asCommand(options: any): Promise<void>` - Execute as command
|
|
180
|
+
|
|
181
|
+
#### `ActionAsCronjobInterface`
|
|
182
|
+
Interface for actions that can be run as scheduled cronjobs.
|
|
183
|
+
|
|
184
|
+
**Extends:** `ActionInterface`
|
|
185
|
+
|
|
186
|
+
**Methods:**
|
|
187
|
+
- `asCronjob(): Promise<void>` - Execute as cronjob
|
|
188
|
+
|
|
189
|
+
#### `ActionAsWatcherInterface`
|
|
190
|
+
Interface for actions that can be run as file/directory watchers.
|
|
191
|
+
|
|
192
|
+
**Extends:** `ActionInterface`
|
|
193
|
+
|
|
194
|
+
**Methods:**
|
|
195
|
+
- `asWatcher(): Promise<void>` - Execute as watcher
|
|
196
|
+
|
|
197
|
+
#### `ActionAsWorkerInterface`
|
|
198
|
+
Interface for actions that can be run as background workers.
|
|
199
|
+
|
|
200
|
+
**Extends:** `ActionInterface`
|
|
201
|
+
|
|
202
|
+
**Methods:**
|
|
203
|
+
- `asWorker(): Promise<void>` - Execute as worker
|
|
204
|
+
|
|
205
|
+
#### `ActionAsControllerInterface`
|
|
206
|
+
Interface for actions that can be run as HTTP controllers.
|
|
207
|
+
|
|
208
|
+
**Extends:** `ActionInterface`
|
|
209
|
+
|
|
210
|
+
**Methods:**
|
|
211
|
+
- `asController(): Promise<void>` - Execute as controller
|
|
212
|
+
|
|
213
|
+
### Utility Functions
|
|
214
|
+
|
|
215
|
+
#### `runActionAsCommand(action: ActionAsCommandInterface): Promise<void>`
|
|
216
|
+
Executes an action as a CLI command with option parsing.
|
|
217
|
+
|
|
218
|
+
#### `findCommandAction(actionsFolder: string, actionName: string): ActionAsCommandInterface`
|
|
219
|
+
Finds and loads a command action from a folder.
|
|
220
|
+
|
|
221
|
+
#### `getOptionAndDefaultValue(config: string): {option: string, defaultValue: any}`
|
|
222
|
+
Parses command option configuration strings.
|
|
223
|
+
|
|
224
|
+
## 🏗️ Requirements
|
|
225
|
+
|
|
226
|
+
- Node.js >= 20
|
|
227
|
+
- TypeScript support
|
|
228
|
+
|
|
229
|
+
## 🧪 Testing
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npm test
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## 📖 Documentation
|
|
236
|
+
|
|
237
|
+
- **TypeDoc Documentation**: [https://owservable.github.io/actions/docs/](https://owservable.github.io/actions/docs/)
|
|
238
|
+
- **Test Coverage**: [https://owservable.github.io/actions/coverage/](https://owservable.github.io/actions/coverage/)
|
|
239
|
+
|
|
240
|
+
## 🔗 Related Projects
|
|
241
|
+
|
|
242
|
+
- [@owservable/folders](https://github.com/owservable/folders) - File system utilities
|
|
243
|
+
- [@owservable/fastify-auto-routes](https://github.com/owservable/fastify-auto-routes) - Fastify auto routing
|
|
244
|
+
- [owservable](https://github.com/owservable/owservable) - Main reactive backend library
|
|
245
|
+
|
|
246
|
+
## 📄 License
|
|
247
|
+
|
|
248
|
+
Licensed under [The Unlicense](./LICENSE).
|
|
249
|
+
|
|
250
|
+
## 🤝 Contributing
|
|
251
|
+
|
|
252
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../../src/abstracts/action.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,MAA8B,MAAM;IAApC;QACW,eAAU,GAAW,EAAE,CAAC;QACxB,iBAAY,GAAW,EAAE,CAAC;QAC1B,cAAS,GAAW,EAAE,CAAC;IAalC,CAAC;IAXO,SAAS;QACf,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAEM,WAAW;QACjB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAEM,QAAQ;QACd,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;CACD;AAhBD,yBAgBC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.findCommandAction = void 0;
|
|
13
|
+
const folders_1 = require("@owservable/folders");
|
|
14
|
+
const findCommandAction = (root, cliCommand) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const actionPaths = yield (0, folders_1.listSubfoldersFilesByFolderName)(root, 'actions');
|
|
16
|
+
for (const actionPath of actionPaths) {
|
|
17
|
+
try {
|
|
18
|
+
const ActionClass = require(actionPath).default;
|
|
19
|
+
if (!ActionClass)
|
|
20
|
+
continue;
|
|
21
|
+
const actionInstance = new ActionClass();
|
|
22
|
+
const signature = actionInstance.signature();
|
|
23
|
+
if (!signature || typeof signature !== 'string')
|
|
24
|
+
continue;
|
|
25
|
+
const signatureParts = signature.trim().split(/\s+/);
|
|
26
|
+
const actionCommand = signatureParts[0];
|
|
27
|
+
if (!actionCommand || actionCommand.length === 0)
|
|
28
|
+
continue;
|
|
29
|
+
if (cliCommand === actionCommand)
|
|
30
|
+
return actionInstance;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.warn(`[@owservable/actions] Failed to load action from ${actionPath}:`, error instanceof Error ? error.message : error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
});
|
|
38
|
+
exports.findCommandAction = findCommandAction;
|
|
39
|
+
exports.default = exports.findCommandAction;
|
|
40
|
+
//# sourceMappingURL=find.command.action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.command.action.js","sourceRoot":"","sources":["../../../src/functions/find.command.action.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;AAEb,iDAAoE;AAI7D,MAAM,iBAAiB,GAAa,CAAO,IAAY,EAAE,UAAkB,EAA4C,EAAE;IAC/H,MAAM,WAAW,GAAa,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAErF,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACtC,IAAI,CAAC;YACJ,MAAM,WAAW,GAAuC,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC;YACpF,IAAI,CAAC,WAAW;gBAAE,SAAS;YAE3B,MAAM,cAAc,GAA6B,IAAI,WAAW,EAAE,CAAC;YAGnE,MAAM,SAAS,GAAuB,cAAc,CAAC,SAAS,EAAE,CAAC;YACjE,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ;gBAAE,SAAS;YAG1D,MAAM,cAAc,GAAa,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC/D,MAAM,aAAa,GAAW,cAAc,CAAC,CAAC,CAAC,CAAC;YAChD,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;gBAAE,SAAS;YAE3D,IAAI,UAAU,KAAK,aAAa;gBAAE,OAAO,cAAc,CAAC;QACzD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAEhB,OAAO,CAAC,IAAI,CAAC,oDAAoD,UAAU,GAAG,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACjI,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAA,CAAC;AA3BW,QAAA,iBAAiB,qBA2B5B;AACF,kBAAe,yBAAiB,CAAC"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getOptionAndDefaultValue = void 0;
|
|
4
4
|
const getOptionAndDefaultValue = (config) => {
|
|
5
5
|
let defaultValue;
|
|
6
|
-
let option = config.
|
|
6
|
+
let option = config.slice(1, -1).trim();
|
|
7
7
|
if (option.indexOf('=') >= 0) {
|
|
8
8
|
defaultValue = option.substring(option.indexOf('=') + 1).trim();
|
|
9
9
|
option = option.replace('=' + defaultValue, '').trim();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.option.and.default.value.js","sourceRoot":"","sources":["../../../src/functions/get.option.and.default.value.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAEN,MAAM,wBAAwB,GAAG,CAAC,MAAc,EAA0C,EAAE;IAClG,IAAI,YAAgC,CAAC;IACrC,IAAI,MAAM,GAAW,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAGhD,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAChE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,YAAY,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxD,CAAC;IAED,OAAO,EAAC,MAAM,EAAE,YAAY,EAAC,CAAC;AAC/B,CAAC,CAAC;AAXW,QAAA,wBAAwB,4BAWnC;AACF,kBAAe,gCAAwB,CAAC"}
|
|
@@ -11,21 +11,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.runActionAsCommand = void 0;
|
|
13
13
|
const commander_1 = require("commander");
|
|
14
|
-
const lodash_1 = require("lodash");
|
|
15
14
|
const get_option_and_default_value_1 = require("../functions/get.option.and.default.value");
|
|
16
15
|
const runActionAsCommand = (action) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
16
|
const program = new commander_1.Command();
|
|
18
17
|
const signature = action.signature();
|
|
19
|
-
const actionCommand =
|
|
18
|
+
const actionCommand = signature.split(' ')[0];
|
|
20
19
|
program
|
|
21
20
|
.name('pnpm cli')
|
|
22
21
|
.command(actionCommand)
|
|
23
22
|
.description(action.description());
|
|
24
23
|
const options = signature.match(/{([^}]*)}/g);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (options) {
|
|
25
|
+
options.forEach((config) => {
|
|
26
|
+
const { option, defaultValue } = (0, get_option_and_default_value_1.default)(config);
|
|
27
|
+
program.option(option, '', defaultValue);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
29
30
|
program.parse(process.argv);
|
|
30
31
|
return action.asCommand(program.opts());
|
|
31
32
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.action.as.command.js","sourceRoot":"","sources":["../../../src/functions/run.action.as.command.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;AAEb,yCAAkC;AAGlC,4FAAiF;AAE1E,MAAM,kBAAkB,GAAa,CAAO,MAAgC,EAAiB,EAAE;IACrG,MAAM,OAAO,GAAY,IAAI,mBAAO,EAAE,CAAC;IACvC,MAAM,SAAS,GAAW,MAAM,CAAC,SAAS,EAAE,CAAC;IAC7C,MAAM,aAAa,GAAW,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAEtD,OAAO;SACL,IAAI,CAAC,UAAU,CAAC;SAChB,OAAO,CAAC,aAAa,CAAC;SACtB,WAAW,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IAEpC,MAAM,OAAO,GAAoB,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAC/D,IAAI,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,OAAO,CAAC,CAAC,MAAc,EAAQ,EAAE;YACxC,MAAM,EAAC,MAAM,EAAE,YAAY,EAAC,GAAuD,IAAA,sCAAwB,EAAC,MAAM,CAAC,CAAC;YACpH,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE,YAAY,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B,OAAO,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC,CAAA,CAAC;AArBW,QAAA,kBAAkB,sBAqB7B;AACF,kBAAe,0BAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.as.command.interface.js","sourceRoot":"","sources":["../../../src/interfaces/action.as.command.interface.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.as.controller.interface.js","sourceRoot":"","sources":["../../../src/interfaces/action.as.controller.interface.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.as.cronjob.interface.js","sourceRoot":"","sources":["../../../src/interfaces/action.as.cronjob.interface.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.as.watcher.interface.js","sourceRoot":"","sources":["../../../src/interfaces/action.as.watcher.interface.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.as.worker.interface.js","sourceRoot":"","sources":["../../../src/interfaces/action.as.worker.interface.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.interface.js","sourceRoot":"","sources":["../../../src/interfaces/action.interface.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
|
|
@@ -8,6 +8,7 @@ import ActionAsCommandInterface from './interfaces/action.as.command.interface';
|
|
|
8
8
|
import ActionAsCronjobInterface from './interfaces/action.as.cronjob.interface';
|
|
9
9
|
import ActionAsControllerInterface from './interfaces/action.as.controller.interface';
|
|
10
10
|
import Action from './abstracts/action';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
import CommandSignatureType from './types/command.signature.type';
|
|
12
|
+
import CommandOptionType from './types/command.option.type';
|
|
13
|
+
import CommandContextType from './types/command.context.type';
|
|
14
|
+
export { findCommandAction, runActionAsCommand, getOptionAndDefaultValue, ActionInterface, ActionAsWorkerInterface, ActionAsWatcherInterface, ActionAsCommandInterface, ActionAsCronjobInterface, ActionAsControllerInterface, Action, CommandSignatureType, CommandOptionType, CommandContextType };
|
|
@@ -9,6 +9,4 @@ const get_option_and_default_value_1 = require("./functions/get.option.and.defau
|
|
|
9
9
|
exports.getOptionAndDefaultValue = get_option_and_default_value_1.default;
|
|
10
10
|
const action_1 = require("./abstracts/action");
|
|
11
11
|
exports.Action = action_1.default;
|
|
12
|
-
const OwservableActions = {};
|
|
13
|
-
exports.default = OwservableActions;
|
|
14
12
|
//# sourceMappingURL=owservable.actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owservable.actions.js","sourceRoot":"","sources":["../../src/owservable.actions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAGb,yEAAgE;AAsB/D,4BAtBM,6BAAiB,CAsBN;AArBlB,6EAAmE;AAsBlE,6BAtBM,+BAAkB,CAsBN;AArBnB,2FAAgF;AAsB/E,mCAtBM,sCAAwB,CAsBN;AAXzB,+CAAwC;AAsBvC,iBAtBM,gBAAM,CAsBN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.context.type.js","sourceRoot":"","sources":["../../../src/types/command.context.type.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.option.type.js","sourceRoot":"","sources":["../../../src/types/command.option.type.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.signature.type.js","sourceRoot":"","sources":["../../../src/types/command.signature.type.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const action_1 = require("../../src/abstracts/action");
|
|
4
|
+
class TestAction extends action_1.default {
|
|
5
|
+
constructor(signature, description, schedule) {
|
|
6
|
+
super();
|
|
7
|
+
if (signature)
|
|
8
|
+
this._signature = signature;
|
|
9
|
+
if (description)
|
|
10
|
+
this._description = description;
|
|
11
|
+
if (schedule)
|
|
12
|
+
this._schedule = schedule;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
describe('action tests', () => {
|
|
16
|
+
it('Action exists and is a function', () => {
|
|
17
|
+
expect(action_1.default).toBeDefined();
|
|
18
|
+
expect(typeof action_1.default).toBe('function');
|
|
19
|
+
});
|
|
20
|
+
it('Action can be extended', () => {
|
|
21
|
+
const action = new TestAction();
|
|
22
|
+
expect(action).toBeDefined();
|
|
23
|
+
expect(action).toBeInstanceOf(action_1.default);
|
|
24
|
+
});
|
|
25
|
+
it('Action has signature method that returns empty string by default', () => {
|
|
26
|
+
const action = new TestAction();
|
|
27
|
+
expect(typeof action.signature).toBe('function');
|
|
28
|
+
expect(action.signature()).toBe('');
|
|
29
|
+
});
|
|
30
|
+
it('Action has description method that returns empty string by default', () => {
|
|
31
|
+
const action = new TestAction();
|
|
32
|
+
expect(typeof action.description).toBe('function');
|
|
33
|
+
expect(action.description()).toBe('');
|
|
34
|
+
});
|
|
35
|
+
it('Action has schedule method that returns empty string by default', () => {
|
|
36
|
+
const action = new TestAction();
|
|
37
|
+
expect(typeof action.schedule).toBe('function');
|
|
38
|
+
expect(action.schedule()).toBe('');
|
|
39
|
+
});
|
|
40
|
+
it('Action protected properties can be set and retrieved', () => {
|
|
41
|
+
const testSignature = 'test-command {--option}';
|
|
42
|
+
const testDescription = 'Test command description';
|
|
43
|
+
const testSchedule = '0 */5 * * * *';
|
|
44
|
+
const action = new TestAction(testSignature, testDescription, testSchedule);
|
|
45
|
+
expect(action.signature()).toBe(testSignature);
|
|
46
|
+
expect(action.description()).toBe(testDescription);
|
|
47
|
+
expect(action.schedule()).toBe(testSchedule);
|
|
48
|
+
});
|
|
49
|
+
it('Action methods return string type', () => {
|
|
50
|
+
const action = new TestAction();
|
|
51
|
+
expect(typeof action.signature()).toBe('string');
|
|
52
|
+
expect(typeof action.description()).toBe('string');
|
|
53
|
+
expect(typeof action.schedule()).toBe('string');
|
|
54
|
+
});
|
|
55
|
+
it('Action is an abstract class', () => {
|
|
56
|
+
expect(action_1.default).toBeDefined();
|
|
57
|
+
expect(typeof action_1.default).toBe('function');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=action.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.spec.js","sourceRoot":"","sources":["../../../test/abstracts/action.spec.ts"],"names":[],"mappings":"AAAA,YAA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