@apisurf/ngn-core 0.2.3 → 0.2.5
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/dist/core.d.ts +2 -0
- package/dist/core.js +28 -34
- package/package.json +5 -4
package/dist/core.d.ts
CHANGED
package/dist/core.js
CHANGED
|
@@ -414,7 +414,7 @@ var Task = class {
|
|
|
414
414
|
await this.entry.load();
|
|
415
415
|
this.entryExports = await this.entry.getExports();
|
|
416
416
|
}
|
|
417
|
-
async
|
|
417
|
+
async loadAndRegister() {
|
|
418
418
|
invariant5(this.entry, "Entry not initialized.");
|
|
419
419
|
try {
|
|
420
420
|
await this.loadEntry();
|
|
@@ -436,19 +436,33 @@ var Task = class {
|
|
|
436
436
|
}
|
|
437
437
|
throw error;
|
|
438
438
|
}
|
|
439
|
+
}
|
|
440
|
+
async runTask(task, taskContext, hooks) {
|
|
441
|
+
invariant5(this.entry, "Entry not initialized.");
|
|
442
|
+
const path = this.entry.paths.relativeEntry;
|
|
443
|
+
try {
|
|
444
|
+
await this.runtimeCallbacks?.onStart?.({ path });
|
|
445
|
+
const taskReturnValue = await task(taskContext);
|
|
446
|
+
await this.runtimeCallbacks?.onSuccess?.({ path });
|
|
447
|
+
await hooks.onSuccess?.(taskContext);
|
|
448
|
+
return taskReturnValue;
|
|
449
|
+
} catch (err) {
|
|
450
|
+
await this.runtimeCallbacks?.onFailure?.({ path });
|
|
451
|
+
await hooks.onError?.(err, taskContext);
|
|
452
|
+
throw err;
|
|
453
|
+
} finally {
|
|
454
|
+
await hooks.onComplete?.(taskContext);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
async execute() {
|
|
458
|
+
invariant5(this.entry, "Entry not initialized.");
|
|
459
|
+
await this.loadAndRegister();
|
|
460
|
+
invariant5(this.entryExports, "Entry failed to get exports.");
|
|
439
461
|
await this.taskCallbacks?.onTaskExecutionStart?.();
|
|
440
|
-
const {
|
|
441
|
-
|
|
442
|
-
// shouldRetry,
|
|
443
|
-
onSuccess,
|
|
444
|
-
onError,
|
|
445
|
-
onComplete,
|
|
446
|
-
task
|
|
447
|
-
} = this.entryExports;
|
|
462
|
+
const { shouldSkip, onSuccess, onError, onComplete, task } = this.entryExports;
|
|
463
|
+
const path = this.entry.paths.relativeEntry;
|
|
448
464
|
if (!task) {
|
|
449
|
-
await this.runtimeCallbacks?.onNotFound?.({
|
|
450
|
-
path: this.entry.paths.relativeEntry
|
|
451
|
-
});
|
|
465
|
+
await this.runtimeCallbacks?.onNotFound?.({ path });
|
|
452
466
|
throw new Error("Task function not found");
|
|
453
467
|
}
|
|
454
468
|
const taskContext = {
|
|
@@ -460,30 +474,10 @@ var Task = class {
|
|
|
460
474
|
sqlite: this.sqlite
|
|
461
475
|
};
|
|
462
476
|
if (await shouldSkip?.(taskContext)) {
|
|
463
|
-
await this.runtimeCallbacks?.onSkip?.({
|
|
464
|
-
path: this.entry.paths.relativeEntry
|
|
465
|
-
});
|
|
477
|
+
await this.runtimeCallbacks?.onSkip?.({ path });
|
|
466
478
|
return;
|
|
467
479
|
}
|
|
468
|
-
|
|
469
|
-
await this.runtimeCallbacks?.onStart?.({
|
|
470
|
-
path: this.entry.paths.relativeEntry
|
|
471
|
-
});
|
|
472
|
-
const taskReturnValue = await task(taskContext);
|
|
473
|
-
await this.runtimeCallbacks?.onSuccess?.({
|
|
474
|
-
path: this.entry.paths.relativeEntry
|
|
475
|
-
});
|
|
476
|
-
await onSuccess?.(taskContext);
|
|
477
|
-
return taskReturnValue;
|
|
478
|
-
} catch (err) {
|
|
479
|
-
await this.runtimeCallbacks?.onFailure?.({
|
|
480
|
-
path: this.entry.paths.relativeEntry
|
|
481
|
-
});
|
|
482
|
-
await onError?.(err, taskContext);
|
|
483
|
-
throw err;
|
|
484
|
-
} finally {
|
|
485
|
-
await onComplete?.(taskContext);
|
|
486
|
-
}
|
|
480
|
+
return this.runTask(task, taskContext, { onSuccess, onError, onComplete });
|
|
487
481
|
}
|
|
488
482
|
};
|
|
489
483
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apisurf/ngn-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "ngn runtime: task compilation, scheduling and the run/log/timing services.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Luka Vidakovic",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"node-cron": "^3.0.3",
|
|
39
39
|
"tiny-invariant": "^1.3.3",
|
|
40
40
|
"zod": "^3.24.2",
|
|
41
|
-
"@apisurf/ngn-os": "0.2.
|
|
42
|
-
"@apisurf/ngn-
|
|
43
|
-
"@apisurf/ngn-
|
|
41
|
+
"@apisurf/ngn-os": "0.2.5",
|
|
42
|
+
"@apisurf/ngn-schema": "0.2.5",
|
|
43
|
+
"@apisurf/ngn-persistence": "0.2.5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "^22.8.1",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"tsup": "^8.3.5"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
51
52
|
"build": "tsup src/core.ts --dts --out-dir dist --format esm",
|
|
52
53
|
"dev": "tsup src/core.ts --dts --out-dir dist --format esm --watch"
|
|
53
54
|
}
|