@znight/core 0.4.0 → 0.5.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/dist/index.d.mts +62 -2
- package/dist/index.mjs +10 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +10 -1
- package/src/hooks.ts +57 -0
- package/src/index.ts +3 -0
package/dist/index.d.mts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* messaging, config, observability).
|
|
8
8
|
* - From `ZNIGHT030`, each first-party package reserves a block of ten: `ZNIGHT030`–`039`
|
|
9
9
|
* `@znight/openapi`, `ZNIGHT040`–`049` `@znight/schedule`, `ZNIGHT050`–`059` `@znight/websocket`
|
|
10
|
-
* (reserved), `ZNIGHT060`–`069` `@znight/graphql`.
|
|
10
|
+
* (reserved), `ZNIGHT060`–`069` `@znight/graphql`, `ZNIGHT070`–`079` `@znight/events`.
|
|
11
11
|
*
|
|
12
12
|
* Within a range, codes are allocated in order without gaps. A package uses its block for its own
|
|
13
13
|
* failure modes, with one catch-all code for invalid usage and options, and reuses a lower code
|
|
@@ -132,6 +132,12 @@ export declare const ErrorCode: {
|
|
|
132
132
|
* type or argument the SDL does not declare, a signature that does not conform to the SDL types.
|
|
133
133
|
*/
|
|
134
134
|
readonly GraphQLSchemaMismatch: "ZNIGHT068";
|
|
135
|
+
/**
|
|
136
|
+
* Invalid event listener: an `@OnEvent` method whose parameter is not a class (or a union of
|
|
137
|
+
* classes), a generic or optional event, an event class the generated module cannot import, invalid
|
|
138
|
+
* options, the NestJS string form, a detached listener depending on a request-scoped external.
|
|
139
|
+
*/
|
|
140
|
+
readonly InvalidEventListener: "ZNIGHT070";
|
|
135
141
|
};
|
|
136
142
|
export type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
137
143
|
/** Short human readable description of every error code. */
|
|
@@ -652,6 +658,17 @@ interface ZnightHooks {
|
|
|
652
658
|
* emitted when listeners exist.
|
|
653
659
|
*/
|
|
654
660
|
"graphql:operation": GraphQLOperationEvent;
|
|
661
|
+
/**
|
|
662
|
+
* One publication of `@znight/events` (`EventPublisher.publish()` or `emit()`) that matched at least
|
|
663
|
+
* one listener (RFC 0011): wraps the inline phase with `hooks.run` when wrappers exist, then is
|
|
664
|
+
* emitted when listeners exist. A publication without listener produces nothing.
|
|
665
|
+
*/
|
|
666
|
+
"events:publish": EventPublishEvent;
|
|
667
|
+
/**
|
|
668
|
+
* One listener invocation of `@znight/events` (RFC 0011), inline or detached: wrapped with
|
|
669
|
+
* `hooks.run` when wrappers exist, then emitted when listeners exist.
|
|
670
|
+
*/
|
|
671
|
+
"events:listener": EventListenerEvent;
|
|
655
672
|
}
|
|
656
673
|
/**
|
|
657
674
|
* Instrumentation event of the `http:request` hook. Defined in core so that producers
|
|
@@ -833,6 +850,49 @@ interface GraphQLOperationEvent {
|
|
|
833
850
|
/** Errors of the response (field and request errors), set before `hooks.run` resolves. */
|
|
834
851
|
errors?: readonly GraphQLOperationError[];
|
|
835
852
|
}
|
|
853
|
+
/** How an application event was published (`EventPublishEvent.mode`). */
|
|
854
|
+
type EventPublishMode = "publish" | "emit";
|
|
855
|
+
/**
|
|
856
|
+
* Instrumentation event of the `events:publish` hook, produced by `@znight/events` (RFC 0011) for a
|
|
857
|
+
* publication that matched at least one listener. The wrappers surround the inline phase (the
|
|
858
|
+
* detached listeners are scheduled after it succeeded); `error` and `failedListener` are set before
|
|
859
|
+
* `next()` rejects.
|
|
860
|
+
*/
|
|
861
|
+
interface EventPublishEvent {
|
|
862
|
+
/** Class name of the event (`UserCreated`). */
|
|
863
|
+
readonly event: string;
|
|
864
|
+
/** The published object. */
|
|
865
|
+
readonly payload: object;
|
|
866
|
+
readonly mode: EventPublishMode;
|
|
867
|
+
/** Number of inline listeners matched. */
|
|
868
|
+
readonly inline: number;
|
|
869
|
+
/** Number of detached listeners matched. */
|
|
870
|
+
readonly detached: number;
|
|
871
|
+
/** `performance.now()` when the publication started. */
|
|
872
|
+
readonly startTime: number;
|
|
873
|
+
/** First inline error, set before `next()` rejects in the wrappers. */
|
|
874
|
+
error?: unknown;
|
|
875
|
+
/** `Class.method` of the inline listener that failed. */
|
|
876
|
+
failedListener?: string;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Instrumentation event of the `events:listener` hook, produced by `@znight/events` (RFC 0011) for
|
|
880
|
+
* every listener invocation. Inline listeners run in the publisher's async context, detached ones in
|
|
881
|
+
* a fresh scope of their own; `error` is set before `next()` rejects.
|
|
882
|
+
*/
|
|
883
|
+
interface EventListenerEvent {
|
|
884
|
+
/** Class name of the event. */
|
|
885
|
+
readonly event: string;
|
|
886
|
+
/** The published object. */
|
|
887
|
+
readonly payload: object;
|
|
888
|
+
/** `Class.method` of the listener (`WelcomeMail.send`). */
|
|
889
|
+
readonly listener: string;
|
|
890
|
+
readonly detached: boolean;
|
|
891
|
+
/** `performance.now()` when the invocation started. */
|
|
892
|
+
readonly startTime: number;
|
|
893
|
+
/** What the listener threw or rejected with. */
|
|
894
|
+
error?: unknown;
|
|
895
|
+
}
|
|
836
896
|
/** Name of a declared hook. */
|
|
837
897
|
type HookName = keyof ZnightHooks;
|
|
838
898
|
/** Event type of hook `K`. */
|
|
@@ -1249,5 +1309,5 @@ export declare class ZnightAggregateError extends ZnightError {
|
|
|
1249
1309
|
* that were attached to it instead of being thrown. Empty when there are none.
|
|
1250
1310
|
*/
|
|
1251
1311
|
export declare function getSuppressedErrors(error: unknown): readonly unknown[];
|
|
1252
|
-
export type { ApplicationOptions, ApplicationState, ClassKey, ClassMarker, ConsoleLike, ConsoleLoggerOptions, CoreLogger, GraphQLOperationError, GraphQLOperationEvent, GraphQLOperationOutcome, GraphQLOperationTransport, GraphQLOperationType, HookEvent, HookListener, HookName, HookWrapper, HooksOptions, HotContext, HttpRequestEvent, InitOptions, InjectableOptions, InterceptMethodOptions, InterceptOptionsArgs, InterceptorClass, InterceptorLink, LogContext, LogLevel, ManagedInstance, MessageDeliveryEvent, MessagePublishEvent, MethodInterceptor, MethodInvocation, MethodMarker, OnReady, OnStart, OnStop, OpenedScope, ParamContexts, ParamDataArgs, ParamDecorator, ParamFunctionOf, ParamResolver, ParamResolverClass, ParamResolverFunction, ParamResolverOf, ParamResolvers, ParameterMarker, Plugin, PluginContext, PluginHook, PluginOptions, PluginRootsContext, ProcessLike, ProviderKey, ProviderValues, ProvidesOptions, ScheduledRunAbortReason, ScheduledRunEvent, ScheduledRunOutcome, ScheduledRunTrigger, ScopeContext, ScopeValues, ShutdownOptions, ShutdownSignal, TypedToken, ZnightHooks };
|
|
1312
|
+
export type { ApplicationOptions, ApplicationState, ClassKey, ClassMarker, ConsoleLike, ConsoleLoggerOptions, CoreLogger, EventListenerEvent, EventPublishEvent, EventPublishMode, GraphQLOperationError, GraphQLOperationEvent, GraphQLOperationOutcome, GraphQLOperationTransport, GraphQLOperationType, HookEvent, HookListener, HookName, HookWrapper, HooksOptions, HotContext, HttpRequestEvent, InitOptions, InjectableOptions, InterceptMethodOptions, InterceptOptionsArgs, InterceptorClass, InterceptorLink, LogContext, LogLevel, ManagedInstance, MessageDeliveryEvent, MessagePublishEvent, MethodInterceptor, MethodInvocation, MethodMarker, OnReady, OnStart, OnStop, OpenedScope, ParamContexts, ParamDataArgs, ParamDecorator, ParamFunctionOf, ParamResolver, ParamResolverClass, ParamResolverFunction, ParamResolverOf, ParamResolvers, ParameterMarker, Plugin, PluginContext, PluginHook, PluginOptions, PluginRootsContext, ProcessLike, ProviderKey, ProviderValues, ProvidesOptions, ScheduledRunAbortReason, ScheduledRunEvent, ScheduledRunOutcome, ScheduledRunTrigger, ScopeContext, ScopeValues, ShutdownOptions, ShutdownSignal, TypedToken, ZnightHooks };
|
|
1253
1313
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
9
9
|
* messaging, config, observability).
|
|
10
10
|
* - From `ZNIGHT030`, each first-party package reserves a block of ten: `ZNIGHT030`–`039`
|
|
11
11
|
* `@znight/openapi`, `ZNIGHT040`–`049` `@znight/schedule`, `ZNIGHT050`–`059` `@znight/websocket`
|
|
12
|
-
* (reserved), `ZNIGHT060`–`069` `@znight/graphql`.
|
|
12
|
+
* (reserved), `ZNIGHT060`–`069` `@znight/graphql`, `ZNIGHT070`–`079` `@znight/events`.
|
|
13
13
|
*
|
|
14
14
|
* Within a range, codes are allocated in order without gaps. A package uses its block for its own
|
|
15
15
|
* failure modes, with one catch-all code for invalid usage and options, and reuses a lower code
|
|
@@ -133,7 +133,13 @@ const ErrorCode = {
|
|
|
133
133
|
* Schema-first resolvers do not match the SDL (RFC 0007): a field without resolver, a resolver,
|
|
134
134
|
* type or argument the SDL does not declare, a signature that does not conform to the SDL types.
|
|
135
135
|
*/
|
|
136
|
-
GraphQLSchemaMismatch: "ZNIGHT068"
|
|
136
|
+
GraphQLSchemaMismatch: "ZNIGHT068",
|
|
137
|
+
/**
|
|
138
|
+
* Invalid event listener: an `@OnEvent` method whose parameter is not a class (or a union of
|
|
139
|
+
* classes), a generic or optional event, an event class the generated module cannot import, invalid
|
|
140
|
+
* options, the NestJS string form, a detached listener depending on a request-scoped external.
|
|
141
|
+
*/
|
|
142
|
+
InvalidEventListener: "ZNIGHT070"
|
|
137
143
|
};
|
|
138
144
|
/** Short human readable description of every error code. */
|
|
139
145
|
const ERROR_DESCRIPTIONS = {
|
|
@@ -181,7 +187,8 @@ const ERROR_DESCRIPTIONS = {
|
|
|
181
187
|
ZNIGHT065: "Invalid loader: not a Loader of a BatchLoad provider, or a batch returning the wrong number of values",
|
|
182
188
|
ZNIGHT066: "Invalid GraphQL setup: metadata, schema, GraphQLPlugin options, driver or HttpPlugin missing",
|
|
183
189
|
ZNIGHT067: "Invalid GraphQL SDL: the schema-first .graphql files cannot be read, parsed or validated",
|
|
184
|
-
ZNIGHT068: "GraphQL schema mismatch: schema-first resolvers do not cover or conform to the SDL"
|
|
190
|
+
ZNIGHT068: "GraphQL schema mismatch: schema-first resolvers do not cover or conform to the SDL",
|
|
191
|
+
ZNIGHT070: "Invalid event listener: an @OnEvent method does not listen to a class, or its options are invalid"
|
|
185
192
|
};
|
|
186
193
|
/** Base class of every error thrown by Znight at runtime. */
|
|
187
194
|
var ZnightError = class extends Error {
|