@moostjs/event-cli 0.2.6 → 0.2.7
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/index.cjs +2 -33
- package/dist/index.d.ts +63 -2
- package/dist/index.mjs +1 -32
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var eventCli = require('@wooksjs/event-cli');
|
|
4
|
-
var
|
|
4
|
+
var eventCore = require('@wooksjs/event-core');
|
|
5
5
|
var moost = require('moost');
|
|
6
6
|
|
|
7
7
|
/******************************************************************************
|
|
@@ -29,37 +29,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const banner = () => `[${"@wooksjs/event-core"}][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
33
|
-
|
|
34
|
-
/* istanbul ignore file */
|
|
35
|
-
function logError(error) {
|
|
36
|
-
console.error('[91m' + '[1m' + banner() + error + '[0m');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function panic(error) {
|
|
40
|
-
logError(error);
|
|
41
|
-
return new Error(error);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Use existing event context
|
|
45
|
-
*
|
|
46
|
-
* !Must be called syncronously while context is reachable
|
|
47
|
-
*
|
|
48
|
-
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
49
|
-
*/
|
|
50
|
-
function useEventContext(expectedTypes) {
|
|
51
|
-
{
|
|
52
|
-
throw panic('Event context does not exist. Use event context synchronously within the runtime of the event.');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function useEventId() {
|
|
57
|
-
const { store } = useEventContext();
|
|
58
|
-
const { init } = store('event');
|
|
59
|
-
const getId = () => init('id', () => crypto.randomUUID());
|
|
60
|
-
return { getId };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
32
|
class MoostCli {
|
|
64
33
|
constructor(cliApp) {
|
|
65
34
|
if (cliApp && cliApp instanceof eventCli.WooksCli) {
|
|
@@ -85,7 +54,7 @@ class MoostCli {
|
|
|
85
54
|
if (!fn) {
|
|
86
55
|
fn = () => __awaiter(this, void 0, void 0, function* () {
|
|
87
56
|
const { restoreCtx } = eventCli.useCliContext();
|
|
88
|
-
const scopeId = useEventId().getId();
|
|
57
|
+
const scopeId = eventCore.useEventId().getId();
|
|
89
58
|
const unscope = opts.registerEventScope(scopeId);
|
|
90
59
|
const instance = yield opts.getInstance();
|
|
91
60
|
restoreCtx();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TMoostAdapterOptions } from 'moost';
|
|
1
|
+
import { TProvideRegistry } from '@prostojs/infact';
|
|
3
2
|
import { TWooksCliOptions } from '@wooksjs/event-cli';
|
|
4
3
|
import { WooksCli } from '@wooksjs/event-cli';
|
|
5
4
|
|
|
@@ -20,6 +19,20 @@ export declare function Flag(name: string): ParameterDecorator;
|
|
|
20
19
|
*/
|
|
21
20
|
export declare function Flags(): ParameterDecorator;
|
|
22
21
|
|
|
22
|
+
declare class InterceptorHandler {
|
|
23
|
+
protected handlers: TInterceptorFn[];
|
|
24
|
+
constructor(handlers: TInterceptorFn[]);
|
|
25
|
+
protected before: TInterceptorBefore[];
|
|
26
|
+
protected after: TInterceptorAfter[];
|
|
27
|
+
protected onError: TInterceptorOnError[];
|
|
28
|
+
response?: unknown;
|
|
29
|
+
responseOverwritten: boolean;
|
|
30
|
+
replyFn(reply: unknown): void;
|
|
31
|
+
init(): Promise<void>;
|
|
32
|
+
fireBefore(response: unknown): Promise<unknown>;
|
|
33
|
+
fireAfter(response: unknown): Promise<unknown>;
|
|
34
|
+
}
|
|
35
|
+
|
|
23
36
|
export declare class MoostCli implements TMoostAdapter<TCliHandlerMeta> {
|
|
24
37
|
protected cliApp: WooksCli;
|
|
25
38
|
constructor(cliApp?: WooksCli | TWooksCliOptions);
|
|
@@ -27,8 +40,56 @@ export declare class MoostCli implements TMoostAdapter<TCliHandlerMeta> {
|
|
|
27
40
|
bindHandler<T extends object = object>(opts: TMoostAdapterOptions<TCliHandlerMeta, T>): void | Promise<void>;
|
|
28
41
|
}
|
|
29
42
|
|
|
43
|
+
declare type TAny = any;
|
|
44
|
+
|
|
30
45
|
export declare interface TCliHandlerMeta {
|
|
31
46
|
path: string;
|
|
32
47
|
}
|
|
33
48
|
|
|
49
|
+
declare type TInterceptorAfter = (response: TAny, reply: (response: TAny) => void) => void | Promise<void>;
|
|
50
|
+
|
|
51
|
+
declare type TInterceptorBefore = (reply: (response: TAny) => void) => void | Promise<void>;
|
|
52
|
+
|
|
53
|
+
declare type TInterceptorFn = {
|
|
54
|
+
(before: (fn: TInterceptorBefore) => void, after: (fn: TInterceptorAfter) => void, onError: (fn: TInterceptorOnError) => void): void | Promise<void>;
|
|
55
|
+
priority?: TInterceptorPriority;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
declare type TInterceptorOnError = (error: Error, reply: (response: TAny) => void) => void | Promise<void>;
|
|
59
|
+
|
|
60
|
+
declare enum TInterceptorPriority {
|
|
61
|
+
BEFORE_ALL = 0,
|
|
62
|
+
BEFORE_GUARD = 1,
|
|
63
|
+
GUARD = 2,
|
|
64
|
+
AFTER_GUARD = 3,
|
|
65
|
+
INTERCEPTOR = 4,
|
|
66
|
+
CATCH_ERROR = 5,
|
|
67
|
+
AFTER_ALL = 6
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare interface TMoostAdapter<H extends object> {
|
|
71
|
+
bindHandler<T extends TObject = TObject>(options: TMoostAdapterOptions<H, T>): void | Promise<void>;
|
|
72
|
+
onInit?: () => void | Promise<void>;
|
|
73
|
+
getProvideRegistry?: () => TProvideRegistry;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare interface TMoostAdapterOptions<H extends object, T extends object> {
|
|
77
|
+
prefix: string;
|
|
78
|
+
fakeInstance: T;
|
|
79
|
+
getInstance: () => Promise<T>;
|
|
80
|
+
silent: boolean;
|
|
81
|
+
method: keyof T;
|
|
82
|
+
handlers: TMoostHandler<H>[];
|
|
83
|
+
getIterceptorHandler: () => Promise<InterceptorHandler>;
|
|
84
|
+
registerEventScope: (scopeId: string) => () => void;
|
|
85
|
+
resolveArgs: () => Promise<unknown[]>;
|
|
86
|
+
logHandler: (eventName: string) => void;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare type TMoostHandler<T extends object> = T & {
|
|
90
|
+
type: string;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
declare type TObject = object;
|
|
94
|
+
|
|
34
95
|
export { }
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WooksCli, createCliApp, useCliContext, useFlags } from '@wooksjs/event-cli';
|
|
2
|
-
import {
|
|
2
|
+
import { useEventId } from '@wooksjs/event-core';
|
|
3
3
|
import { Resolve, getMoostMate } from 'moost';
|
|
4
4
|
|
|
5
5
|
/******************************************************************************
|
|
@@ -27,37 +27,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const banner = () => `[${"@wooksjs/event-core"}][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
|
|
31
|
-
|
|
32
|
-
/* istanbul ignore file */
|
|
33
|
-
function logError(error) {
|
|
34
|
-
console.error('[91m' + '[1m' + banner() + error + '[0m');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function panic(error) {
|
|
38
|
-
logError(error);
|
|
39
|
-
return new Error(error);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Use existing event context
|
|
43
|
-
*
|
|
44
|
-
* !Must be called syncronously while context is reachable
|
|
45
|
-
*
|
|
46
|
-
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
47
|
-
*/
|
|
48
|
-
function useEventContext(expectedTypes) {
|
|
49
|
-
{
|
|
50
|
-
throw panic('Event context does not exist. Use event context synchronously within the runtime of the event.');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function useEventId() {
|
|
55
|
-
const { store } = useEventContext();
|
|
56
|
-
const { init } = store('event');
|
|
57
|
-
const getId = () => init('id', () => randomUUID());
|
|
58
|
-
return { getId };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
30
|
class MoostCli {
|
|
62
31
|
constructor(cliApp) {
|
|
63
32
|
if (cliApp && cliApp instanceof WooksCli) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "@moostjs/event-cli",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,8 +28,9 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-cli#readme",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"moost": "0.2.
|
|
32
|
-
"wooks": "^0.2.5"
|
|
31
|
+
"moost": "0.2.7",
|
|
32
|
+
"wooks": "^0.2.5",
|
|
33
|
+
"@wooksjs/event-core": "^0.2.5"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"@wooksjs/event-cli": "^0.2.5"
|