@webtypen/webframez-core 0.3.29 → 0.3.31
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 +345 -130
- package/dev/storage/test-storage-check/a.txt +1 -0
- package/dist/BaseKernelWeb.js +1 -0
- package/dist/Commands/ConsoleCommand.js +10 -1
- package/dist/Commands/QueueStopCommand.js +1 -1
- package/dist/Commands/QueueWorkerCommand.js +38 -1
- package/dist/ConsoleApplication.js +26 -4
- package/dist/DataBuilder/DataBuilder.js +9 -0
- package/dist/ErrorHandling/ErrorHandler.d.ts +46 -0
- package/dist/ErrorHandling/ErrorHandler.js +79 -0
- package/dist/Facades/Storage.d.ts +7 -30
- package/dist/Facades/Storage.js +14 -10
- package/dist/Facades/StorageDrivers/LocalStorageDriver.d.ts +1 -0
- package/dist/Facades/StorageDrivers/LocalStorageDriver.js +29 -12
- package/dist/LambdaApplication.js +9 -0
- package/dist/Queue/QueueJobsRegisty.d.ts +4 -0
- package/dist/Queue/QueueJobsRegisty.js +35 -2
- package/dist/Router/Route.d.ts +15 -12
- package/dist/Router/Route.js +30 -28
- package/dist/Router/Router.d.ts +9 -0
- package/dist/Router/Router.js +131 -26
- package/dist/WebApplication.js +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -2
- package/dist/info.js +1 -1
- package/package.json +1 -1
- package/src/BaseKernelWeb.ts +1 -1
- package/src/Commands/ConsoleCommand.ts +10 -1
- package/src/Commands/QueueStopCommand.ts +3 -3
- package/src/Commands/QueueWorkerCommand.ts +38 -1
- package/src/ConsoleApplication.ts +25 -4
- package/src/DataBuilder/DataBuilder.ts +26 -16
- package/src/ErrorHandling/ErrorHandler.ts +109 -0
- package/src/Facades/Storage.ts +15 -10
- package/src/Facades/StorageDrivers/LocalStorageDriver.ts +35 -11
- package/src/LambdaApplication.ts +9 -0
- package/src/Queue/QueueJobsRegisty.ts +43 -2
- package/src/Router/Route.ts +52 -64
- package/src/Router/Router.ts +154 -27
- package/src/WebApplication.ts +9 -0
- package/src/index.ts +2 -2
- package/src/info.ts +1 -1
- package/src/Telemetry/SigNozTelemetry.ts +0 -268
package/README.md
CHANGED
|
@@ -1,207 +1,422 @@
|
|
|
1
|
-
# webtypen
|
|
1
|
+
# @webtypen/webframez-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript-first backend framework core for Node.js.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This README reflects the current API in this repository and focuses on:
|
|
6
|
+
- Routing
|
|
7
|
+
- Datatables
|
|
8
|
+
- DataBuilder
|
|
9
|
+
- Console Commands
|
|
10
|
+
- Queue and Jobs
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
## Requirements
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
- Node.js `>= 20` (recommended)
|
|
15
|
+
- TypeScript for development
|
|
10
16
|
|
|
11
|
-
##
|
|
17
|
+
## Installation
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
```bash
|
|
20
|
+
npm i @webtypen/webframez-core
|
|
21
|
+
```
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
## Basic Web Setup
|
|
16
24
|
|
|
17
25
|
```ts
|
|
18
|
-
Route
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
import { BaseKernelWeb, Request, Response, Route, WebApplication } from "@webtypen/webframez-core";
|
|
27
|
+
|
|
28
|
+
class Kernel extends BaseKernelWeb {
|
|
29
|
+
static controller = {
|
|
30
|
+
TestController: class {
|
|
31
|
+
async index(req: Request, res: Response) {
|
|
32
|
+
return res.send({ status: "ok" });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
static middleware = {
|
|
38
|
+
auth: async (next: Function, reject: Function, req: Request, res: Response) => {
|
|
39
|
+
const isAllowed = true;
|
|
40
|
+
if (!isAllowed) {
|
|
41
|
+
return reject(new Error("Unauthorized"));
|
|
42
|
+
}
|
|
43
|
+
next(true);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const app = new WebApplication();
|
|
49
|
+
app.boot({
|
|
50
|
+
kernel: Kernel,
|
|
51
|
+
port: 3000,
|
|
52
|
+
basename: null,
|
|
53
|
+
routesFunction: () => {
|
|
54
|
+
Route.get("/", "TestController@index");
|
|
55
|
+
}
|
|
56
|
+
});
|
|
23
57
|
```
|
|
24
58
|
|
|
25
|
-
|
|
59
|
+
`WebApplication.boot(...)` supports:
|
|
60
|
+
- `kernel`
|
|
61
|
+
- `port`
|
|
62
|
+
- `basename`
|
|
63
|
+
- `routesFunction`
|
|
64
|
+
- `modules`
|
|
65
|
+
- `config`
|
|
66
|
+
- `datatables`
|
|
67
|
+
- `jobs`
|
|
68
|
+
- `mode`
|
|
69
|
+
- `onBoot`
|
|
26
70
|
|
|
27
|
-
|
|
71
|
+
## Routing
|
|
72
|
+
|
|
73
|
+
### Register Routes
|
|
28
74
|
|
|
29
75
|
```ts
|
|
30
|
-
|
|
31
|
-
Route.
|
|
76
|
+
Route.get("/", "HomeController@index");
|
|
77
|
+
Route.post("/login", "AuthController@login");
|
|
78
|
+
Route.put("/users/:id", "UserController@update");
|
|
79
|
+
Route.delete("/users/:id", "UserController@delete");
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
You can also register inline handlers:
|
|
32
83
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
84
|
+
```ts
|
|
85
|
+
Route.get("/health", (req: Request, res: Response) => {
|
|
86
|
+
return res.send({ status: "ok" });
|
|
87
|
+
});
|
|
36
88
|
```
|
|
37
89
|
|
|
38
|
-
###
|
|
90
|
+
### Path Parameters and Wildcards
|
|
39
91
|
|
|
40
|
-
|
|
92
|
+
Supported path patterns:
|
|
93
|
+
- Required parameter: `/:id`
|
|
94
|
+
- Optional parameter: `/:id?`
|
|
95
|
+
- Single wildcard: `/*`
|
|
96
|
+
- Catch-all wildcard: `/**`
|
|
41
97
|
|
|
42
|
-
|
|
98
|
+
Matched values are available in `req.params`.
|
|
43
99
|
|
|
44
|
-
|
|
45
|
-
- `abort`: Function that aborts the request when called. An HTTP status code can be specified in the first parameter and a request body (usually text or JSON) in the second.
|
|
46
|
-
- `req`: The Request-Object
|
|
47
|
-
- `res`: The Response-Object
|
|
100
|
+
### Route Groups
|
|
48
101
|
|
|
49
|
-
|
|
102
|
+
```ts
|
|
103
|
+
Route.group({ prefix: "/admin", middleware: ["auth"] }, () => {
|
|
104
|
+
Route.get("/dashboard", "AdminController@dashboard");
|
|
105
|
+
|
|
106
|
+
Route.group({ prefix: "/users" }, () => {
|
|
107
|
+
Route.get("/:id", "AdminUserController@details");
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Route Middleware
|
|
113
|
+
|
|
114
|
+
Attach middleware by key via route options:
|
|
50
115
|
|
|
51
116
|
```ts
|
|
52
|
-
|
|
53
|
-
auth: async (next: any, abort: any, req: Request, res: Response) => {
|
|
54
|
-
console.log("auth-middleware");
|
|
55
|
-
next();
|
|
56
|
-
},
|
|
57
|
-
};
|
|
117
|
+
Route.get("/me", "AccountController@me", { middleware: ["auth"] });
|
|
58
118
|
```
|
|
59
119
|
|
|
60
|
-
|
|
120
|
+
Middleware signature:
|
|
61
121
|
|
|
62
|
-
|
|
122
|
+
```ts
|
|
123
|
+
(next, reject, req, res) => {
|
|
124
|
+
// allow:
|
|
125
|
+
next(true);
|
|
63
126
|
|
|
64
|
-
|
|
127
|
+
// abort with error:
|
|
128
|
+
// reject(new Error("Forbidden"));
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Extend the Route Facade
|
|
133
|
+
|
|
134
|
+
You can add custom route registration helpers:
|
|
65
135
|
|
|
66
136
|
```ts
|
|
67
|
-
Route.
|
|
137
|
+
Route.extend("jsonGet", (route) => {
|
|
138
|
+
return (path: string, component: any, options?: any) => {
|
|
139
|
+
route.get(path, async (req: Request, res: Response) => {
|
|
140
|
+
res.header("Content-Type", "application/json");
|
|
141
|
+
return component(req, res);
|
|
142
|
+
}, options);
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
(Route as any).jsonGet("/x", (req: Request, res: Response) => res.send({ ok: true }));
|
|
68
147
|
```
|
|
69
148
|
|
|
70
|
-
|
|
149
|
+
## Request and Response
|
|
150
|
+
|
|
151
|
+
### Request
|
|
71
152
|
|
|
72
|
-
|
|
153
|
+
`Request` includes:
|
|
154
|
+
- `method`, `url`, `headers`, `rawHeaders`
|
|
155
|
+
- `body`, `bodyPlain`
|
|
156
|
+
- `query`, `queryRaw`
|
|
157
|
+
- `params`
|
|
158
|
+
- `files`
|
|
159
|
+
- `message` (native `IncomingMessage`)
|
|
73
160
|
|
|
74
|
-
|
|
161
|
+
### Response
|
|
162
|
+
|
|
163
|
+
Common helpers:
|
|
75
164
|
|
|
76
165
|
```ts
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}});
|
|
166
|
+
res.status(201);
|
|
167
|
+
res.header("X-Test", "1");
|
|
168
|
+
res.send({ status: "success" });
|
|
81
169
|
```
|
|
82
170
|
|
|
83
|
-
|
|
171
|
+
Also available:
|
|
172
|
+
- `sendCsv(...)`
|
|
173
|
+
- `download(filepath, options?)`
|
|
174
|
+
- `stream(req, filepath, filename, mimeType)`
|
|
175
|
+
- `registerEvent("after", fn)`
|
|
176
|
+
|
|
177
|
+
## Datatables
|
|
178
|
+
|
|
179
|
+
Use `Datatable` + `DatatableRegistry` + `DatatableController`.
|
|
180
|
+
|
|
181
|
+
### Define a Datatable
|
|
84
182
|
|
|
85
183
|
```ts
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
184
|
+
import { Datatable, Request } from "@webtypen/webframez-core";
|
|
185
|
+
|
|
186
|
+
export class UsersTable extends Datatable {
|
|
187
|
+
collection = "users";
|
|
188
|
+
perPage = 25;
|
|
89
189
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
190
|
+
columns = {
|
|
191
|
+
name: { label: "Name" },
|
|
192
|
+
email: { label: "E-Mail" }
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
filter = {
|
|
196
|
+
name: { type: "text", mapping: "name" }
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
aggregation = async (req: Request) => {
|
|
200
|
+
return [{ $sort: { created_at: -1 } }];
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Register Datatables
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
app.boot({
|
|
209
|
+
// ...
|
|
210
|
+
datatables: {
|
|
211
|
+
users: UsersTable
|
|
212
|
+
}
|
|
213
|
+
});
|
|
93
214
|
```
|
|
94
215
|
|
|
95
|
-
|
|
216
|
+
### Datatable Endpoints
|
|
96
217
|
|
|
97
|
-
|
|
218
|
+
Use `DatatableController` in your routes:
|
|
98
219
|
|
|
99
220
|
```ts
|
|
100
|
-
|
|
101
|
-
Route.get("/", "TestController@test"); // Path: /test/
|
|
102
|
-
Route.get("/test2", "TestController@test"); // Path: /test2/
|
|
221
|
+
import { DatatableController, Route } from "@webtypen/webframez-core";
|
|
103
222
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
});
|
|
223
|
+
Route.post("/api/datatable", "DatatableController@restApi");
|
|
224
|
+
Route.post("/api/datatable/export", "DatatableController@tableExport");
|
|
108
225
|
```
|
|
109
226
|
|
|
110
|
-
|
|
227
|
+
`restApi` supports:
|
|
228
|
+
- init requests (`init_request`)
|
|
229
|
+
- paginated data
|
|
230
|
+
- selectable functions (`apiFunction`)
|
|
111
231
|
|
|
112
|
-
|
|
232
|
+
`tableExport` uses your table `exports` definition.
|
|
113
233
|
|
|
114
|
-
|
|
234
|
+
## DataBuilder
|
|
115
235
|
|
|
116
|
-
|
|
236
|
+
Use `DataBuilder` + `DataBuilderController` for schema-driven CRUD flows.
|
|
117
237
|
|
|
118
|
-
|
|
238
|
+
### Define and Register Types
|
|
119
239
|
|
|
120
|
-
|
|
240
|
+
```ts
|
|
241
|
+
import { DataBuilder } from "@webtypen/webframez-core";
|
|
242
|
+
|
|
243
|
+
const builder = new DataBuilder();
|
|
244
|
+
|
|
245
|
+
builder.registerType({
|
|
246
|
+
key: "user",
|
|
247
|
+
singular: "User",
|
|
248
|
+
plural: "Users",
|
|
249
|
+
schema: {
|
|
250
|
+
version: "1.0.0",
|
|
251
|
+
collection: "users",
|
|
252
|
+
fields: {
|
|
253
|
+
email: { type: "text", required: true, unique: { match: {} } },
|
|
254
|
+
age: { type: "integer" }
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
You can also use:
|
|
261
|
+
- `registerModelType(...)`
|
|
262
|
+
- `registerFieldType(...)`
|
|
121
263
|
|
|
122
|
-
|
|
264
|
+
### Expose the REST API
|
|
123
265
|
|
|
124
266
|
```ts
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
267
|
+
import { DataBuilderController, Route } from "@webtypen/webframez-core";
|
|
268
|
+
|
|
269
|
+
class MyDataBuilderController extends DataBuilderController {
|
|
270
|
+
constructor() {
|
|
271
|
+
super(builder);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Register controller in kernel, then:
|
|
276
|
+
Route.post("/api/builder", "MyDataBuilderController@restApi");
|
|
134
277
|
```
|
|
135
278
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
* @param foreignKey
|
|
163
|
-
* @param localKey (optional)
|
|
164
|
-
* @param queryBuilderFunction (optional) customize the query
|
|
165
|
-
**/
|
|
166
|
-
@hasMany(() => Session, "_user")
|
|
167
|
-
sessions!: () => Session[];
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* @param CustomerGroups Dependency Model
|
|
171
|
-
* @param foreignKey
|
|
172
|
-
* @param localKey (optional)
|
|
173
|
-
* @param queryBuilderFunction (optional) customize the query
|
|
174
|
-
**/
|
|
175
|
-
@hasManyArray(() => CustomerGroups, "_groups")
|
|
176
|
-
groups!: () => CustomerGroups[];
|
|
279
|
+
`__builder_rest_api` actions:
|
|
280
|
+
- `type`
|
|
281
|
+
- `details`
|
|
282
|
+
- `details-newdata`
|
|
283
|
+
- `save`
|
|
284
|
+
- `delete`
|
|
285
|
+
- `api-autocomplete`
|
|
286
|
+
|
|
287
|
+
## Console Commands
|
|
288
|
+
|
|
289
|
+
Use `ConsoleApplication` with `BaseKernelConsole`.
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
import { BaseKernelConsole, ConsoleApplication, ConsoleCommand } from "@webtypen/webframez-core";
|
|
293
|
+
|
|
294
|
+
class HelloCommand extends ConsoleCommand {
|
|
295
|
+
static signature = "hello";
|
|
296
|
+
static description = "Print a greeting";
|
|
297
|
+
|
|
298
|
+
async handle() {
|
|
299
|
+
this.success("Hello world");
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
class KernelConsole extends BaseKernelConsole {
|
|
304
|
+
static commands = [HelloCommand];
|
|
177
305
|
}
|
|
306
|
+
|
|
307
|
+
const app = new ConsoleApplication();
|
|
308
|
+
app.boot({
|
|
309
|
+
kernel: KernelConsole,
|
|
310
|
+
config: {}
|
|
311
|
+
});
|
|
178
312
|
```
|
|
179
313
|
|
|
180
|
-
|
|
314
|
+
`ConsoleCommand` helpers include:
|
|
315
|
+
- `getArguments()`, `getOptions()`, `getOption(...)`
|
|
316
|
+
- `ask(...)`
|
|
317
|
+
- `write`, `writeln`, `info`, `warning`, `success`, `error`
|
|
318
|
+
- progress helpers (`progress`, `progressIncrement`, `progressFinish`)
|
|
319
|
+
|
|
320
|
+
## Queue and Jobs
|
|
321
|
+
|
|
322
|
+
Queue workers run through console commands and use `queue_jobs` storage.
|
|
323
|
+
|
|
324
|
+
### Create a Job
|
|
181
325
|
|
|
182
326
|
```ts
|
|
183
|
-
import {
|
|
327
|
+
import { BaseQueueJob } from "@webtypen/webframez-core";
|
|
328
|
+
|
|
329
|
+
export class SendMailJob extends BaseQueueJob {
|
|
330
|
+
async handle(job: any) {
|
|
331
|
+
this.log("Sending mail", job.payload);
|
|
332
|
+
// do work...
|
|
333
|
+
|
|
334
|
+
// optional delayed re-run:
|
|
335
|
+
// return this.executeAgain(5, "minutes");
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
```
|
|
184
339
|
|
|
185
|
-
|
|
186
|
-
|
|
340
|
+
Create a new queue entry:
|
|
341
|
+
|
|
342
|
+
```ts
|
|
343
|
+
await SendMailJob.create({
|
|
344
|
+
payload: { userId: "..." },
|
|
345
|
+
priority: 5,
|
|
346
|
+
worker: null
|
|
347
|
+
});
|
|
187
348
|
```
|
|
188
349
|
|
|
189
|
-
|
|
350
|
+
### Register Jobs
|
|
190
351
|
|
|
191
352
|
```ts
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
353
|
+
app.boot({
|
|
354
|
+
// ConsoleApplication or WebApplication
|
|
355
|
+
jobs: [SendMailJob]
|
|
356
|
+
});
|
|
195
357
|
```
|
|
196
358
|
|
|
197
|
-
|
|
359
|
+
### Queue Config
|
|
360
|
+
|
|
361
|
+
Configure workers in `config.queue`:
|
|
198
362
|
|
|
199
363
|
```ts
|
|
200
|
-
|
|
364
|
+
export default {
|
|
365
|
+
workers: {
|
|
366
|
+
default: {
|
|
367
|
+
is_active: true,
|
|
368
|
+
jobclasses: ["SendMailJob"],
|
|
369
|
+
automation: [
|
|
370
|
+
{
|
|
371
|
+
jobclass: "SendMailJob",
|
|
372
|
+
executions: [
|
|
373
|
+
["every_x_mins", 15],
|
|
374
|
+
["daily", "08:00"],
|
|
375
|
+
["every_hour", 5],
|
|
376
|
+
["mondays", "09:30"]
|
|
377
|
+
]
|
|
378
|
+
}
|
|
379
|
+
]
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
};
|
|
201
383
|
```
|
|
202
384
|
|
|
203
|
-
|
|
385
|
+
### Built-in Queue Commands
|
|
386
|
+
|
|
387
|
+
- `queue:start`
|
|
388
|
+
- `queue:status`
|
|
389
|
+
- `queue:stop`
|
|
390
|
+
- `queue:log`
|
|
391
|
+
- `queue:worker`
|
|
392
|
+
- `queue:worker:autorestart`
|
|
393
|
+
|
|
394
|
+
Additional built-in command:
|
|
395
|
+
- `build`
|
|
396
|
+
|
|
397
|
+
## Modules
|
|
398
|
+
|
|
399
|
+
You can load module providers via `modules` in `WebApplication.boot(...)`.
|
|
400
|
+
|
|
401
|
+
A module provider can:
|
|
402
|
+
- register controllers/middleware
|
|
403
|
+
- define `boot()`
|
|
404
|
+
- define `routes()`
|
|
405
|
+
|
|
406
|
+
## Lambda Mode
|
|
407
|
+
|
|
408
|
+
`LambdaApplication` uses the same router in AWS Lambda mode:
|
|
204
409
|
|
|
205
410
|
```ts
|
|
206
|
-
|
|
411
|
+
import { LambdaApplication } from "@webtypen/webframez-core";
|
|
412
|
+
|
|
413
|
+
const app = new LambdaApplication();
|
|
414
|
+
export const handler = (event: any, context: any) => {
|
|
415
|
+
return app.boot(event, context, {
|
|
416
|
+
kernel: Kernel,
|
|
417
|
+
routesFunction: () => {
|
|
418
|
+
Route.get("/status", (req, res) => res.send({ ok: true }));
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
};
|
|
207
422
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hello
|
package/dist/BaseKernelWeb.js
CHANGED
|
@@ -16,6 +16,7 @@ exports.ConsoleCommand = void 0;
|
|
|
16
16
|
const readline_1 = __importDefault(require("readline"));
|
|
17
17
|
const ConsoleProgressBar_1 = require("./ConsoleProgressBar");
|
|
18
18
|
const ConsoleOutputHelper_1 = require("./ConsoleOutputHelper");
|
|
19
|
+
const ErrorHandler_1 = require("../ErrorHandling/ErrorHandler");
|
|
19
20
|
class ConsoleCommand {
|
|
20
21
|
constructor(args) {
|
|
21
22
|
this.rl = null;
|
|
@@ -41,7 +42,15 @@ class ConsoleCommand {
|
|
|
41
42
|
yield this.handle();
|
|
42
43
|
}
|
|
43
44
|
catch (e) {
|
|
44
|
-
|
|
45
|
+
yield ErrorHandler_1.ErrorHandler.report(e, {
|
|
46
|
+
scope: "command",
|
|
47
|
+
source: "console.command.handleSystem",
|
|
48
|
+
command: {
|
|
49
|
+
signature: this.constructor.signature,
|
|
50
|
+
className: this.constructor.name,
|
|
51
|
+
args: this.args,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
45
54
|
}
|
|
46
55
|
finally {
|
|
47
56
|
yield this.finallySystem();
|
|
@@ -63,7 +63,7 @@ class QueueStopCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
63
63
|
let promises = [];
|
|
64
64
|
for (let worker of stopping) {
|
|
65
65
|
if (!worker || !worker.worker || !worker.pid)
|
|
66
|
-
|
|
66
|
+
continue;
|
|
67
67
|
promises.push(new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
68
68
|
try {
|
|
69
69
|
yield this.stopWorker(worker.worker, worker.pid);
|
|
@@ -23,6 +23,7 @@ const StringFunctions_1 = require("../Functions/StringFunctions");
|
|
|
23
23
|
const Config_1 = require("../Config");
|
|
24
24
|
const DBConnection_1 = require("../Database/DBConnection");
|
|
25
25
|
const DateFunctions_1 = require("../Functions/DateFunctions");
|
|
26
|
+
const ErrorHandler_1 = require("../ErrorHandling/ErrorHandler");
|
|
26
27
|
class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
27
28
|
constructor() {
|
|
28
29
|
super(...arguments);
|
|
@@ -70,6 +71,18 @@ class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
70
71
|
yield this.run();
|
|
71
72
|
}
|
|
72
73
|
catch (e) {
|
|
74
|
+
yield ErrorHandler_1.ErrorHandler.report(e, {
|
|
75
|
+
scope: "command",
|
|
76
|
+
source: "queue.worker.run",
|
|
77
|
+
command: {
|
|
78
|
+
signature: this.constructor.signature,
|
|
79
|
+
className: this.constructor.name,
|
|
80
|
+
args: this.args,
|
|
81
|
+
},
|
|
82
|
+
metadata: {
|
|
83
|
+
worker: this.workerKey,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
73
86
|
this.error(`Queue run failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
74
87
|
}
|
|
75
88
|
finally {
|
|
@@ -354,7 +367,18 @@ class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
354
367
|
}
|
|
355
368
|
}
|
|
356
369
|
catch (e) {
|
|
357
|
-
|
|
370
|
+
yield ErrorHandler_1.ErrorHandler.report(e, {
|
|
371
|
+
scope: "command",
|
|
372
|
+
source: "queue.worker.automation",
|
|
373
|
+
command: {
|
|
374
|
+
signature: this.constructor.signature,
|
|
375
|
+
className: this.constructor.name,
|
|
376
|
+
args: this.args,
|
|
377
|
+
},
|
|
378
|
+
metadata: {
|
|
379
|
+
worker: this.workerKey,
|
|
380
|
+
},
|
|
381
|
+
});
|
|
358
382
|
}
|
|
359
383
|
});
|
|
360
384
|
}
|
|
@@ -500,6 +524,19 @@ class QueueWorkerCommand extends ConsoleCommand_1.ConsoleCommand {
|
|
|
500
524
|
this.log(`Finished Job #${job.number} - ${job.jobclass} - ${(job.executions[0].duration_ms / 1000).toFixed(2)}s`);
|
|
501
525
|
}
|
|
502
526
|
catch (e) {
|
|
527
|
+
yield ErrorHandler_1.ErrorHandler.report(e, {
|
|
528
|
+
scope: "job",
|
|
529
|
+
source: "queue.worker.job.handle",
|
|
530
|
+
job: {
|
|
531
|
+
id: job && job._id ? job._id.toString() : undefined,
|
|
532
|
+
number: job && job.number ? job.number : undefined,
|
|
533
|
+
jobclass: job && job.jobclass ? job.jobclass : undefined,
|
|
534
|
+
worker: this.workerKey,
|
|
535
|
+
},
|
|
536
|
+
metadata: {
|
|
537
|
+
executionKey: executionKey,
|
|
538
|
+
},
|
|
539
|
+
});
|
|
503
540
|
const errorMessage = e instanceof Error ? e.stack || e.message : String(e);
|
|
504
541
|
const endedAt = new Date();
|
|
505
542
|
job.status = "failed";
|