@znight/core 0.5.0 → 0.6.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 +71 -3
- package/dist/index.mjs +14 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +16 -2
- package/src/hooks.ts +62 -0
- package/src/index.ts +4 -0
package/dist/index.d.mts
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* - `ZNIGHT001`–`ZNIGHT029`: the core, the compiler and the features shipped in 0.1 (http,
|
|
7
7
|
* messaging, config, observability).
|
|
8
8
|
* - From `ZNIGHT030`, each first-party package reserves a block of ten: `ZNIGHT030`–`039`
|
|
9
|
-
* `@znight/openapi`, `ZNIGHT040`–`049` `@znight/schedule`, `ZNIGHT050`–`059` `@znight/websocket
|
|
10
|
-
*
|
|
9
|
+
* `@znight/openapi`, `ZNIGHT040`–`049` `@znight/schedule`, `ZNIGHT050`–`059` `@znight/websocket`,
|
|
10
|
+
* `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
|
|
@@ -96,6 +96,16 @@ export declare const ErrorCode: {
|
|
|
96
96
|
readonly MissingLockStore: "ZNIGHT043";
|
|
97
97
|
/** A scheduled run was aborted (`ctx.signal.reason`, `JobAbortedError`); never thrown by the framework. */
|
|
98
98
|
readonly JobAborted: "ZNIGHT044";
|
|
99
|
+
/**
|
|
100
|
+
* Invalid gateway: `@Gateway` options, lifecycle methods, events handled twice, reserved event
|
|
101
|
+
* names, parameters; at boot, invalid `WebSocketPlugin` options or `metadata.extensions.websocket`.
|
|
102
|
+
*/
|
|
103
|
+
readonly InvalidGateway: "ZNIGHT050";
|
|
104
|
+
/**
|
|
105
|
+
* Gateways cannot be served: no `HttpPlugin`, an adapter without upgrade support, `ws` missing on
|
|
106
|
+
* Node.js, a transport that does not match the server.
|
|
107
|
+
*/
|
|
108
|
+
readonly WebSocketTransportUnavailable: "ZNIGHT051";
|
|
99
109
|
/** A TypeScript type cannot be mapped to a GraphQL type, or a resolver lacks the annotation it needs. */
|
|
100
110
|
readonly InvalidGraphQLType: "ZNIGHT060";
|
|
101
111
|
/** Two declarations or root fields share a GraphQL name, or a name is invalid or reserved. */
|
|
@@ -658,6 +668,13 @@ interface ZnightHooks {
|
|
|
658
668
|
* emitted when listeners exist.
|
|
659
669
|
*/
|
|
660
670
|
"graphql:operation": GraphQLOperationEvent;
|
|
671
|
+
/**
|
|
672
|
+
* One inbound WebSocket message handled by `@znight/websocket` (RFC 0003): wrapped with
|
|
673
|
+
* `hooks.run` when wrappers exist, then emitted when listeners exist. `$ping` frames do not run it.
|
|
674
|
+
*/
|
|
675
|
+
"websocket:message": WebSocketMessageEvent;
|
|
676
|
+
/** A WebSocket connection of `@znight/websocket` opened or closed (emitted only). */
|
|
677
|
+
"websocket:connection": WebSocketConnectionEvent;
|
|
661
678
|
/**
|
|
662
679
|
* One publication of `@znight/events` (`EventPublisher.publish()` or `emit()`) that matched at least
|
|
663
680
|
* one listener (RFC 0011): wraps the inline phase with `hooks.run` when wrappers exist, then is
|
|
@@ -729,6 +746,57 @@ interface MessageDeliveryEvent {
|
|
|
729
746
|
outcome?: "ack" | "retry" | "dead-letter";
|
|
730
747
|
error?: unknown;
|
|
731
748
|
}
|
|
749
|
+
/** Outcome of an inbound WebSocket message (`WebSocketMessageEvent.outcome`). */
|
|
750
|
+
type WebSocketMessageOutcome = "ok" | "error" | "rejected" | "unhandled" | "timeout";
|
|
751
|
+
/** Who closed a WebSocket connection (`WsCloseInfo.initiator` of `@znight/websocket`). */
|
|
752
|
+
type WebSocketCloseInitiator = "client" | "server" | "shutdown" | "heartbeat" | "backpressure" | "error";
|
|
753
|
+
/**
|
|
754
|
+
* Instrumentation event of the `websocket:message` hook (RFC 0003 §8.10), one per inbound message
|
|
755
|
+
* of a gateway. `outcome` and `error` are set before `hooks.run` resolves.
|
|
756
|
+
*/
|
|
757
|
+
interface WebSocketMessageEvent {
|
|
758
|
+
/** Display name of the gateway class. */
|
|
759
|
+
readonly gateway: string;
|
|
760
|
+
/** Gateway path pattern, HTTP prefix included (`/api/chat`). */
|
|
761
|
+
readonly path: string;
|
|
762
|
+
/** Event name (`events` gateways); `undefined` on `raw` gateways or for an undecodable frame. */
|
|
763
|
+
readonly event: string | undefined;
|
|
764
|
+
/** Handler method; `undefined` when no handler matched. */
|
|
765
|
+
readonly handler: string | undefined;
|
|
766
|
+
readonly connectionId: string;
|
|
767
|
+
/** The request id of the handshake. */
|
|
768
|
+
readonly requestId: string;
|
|
769
|
+
/** Size of the frame, in bytes (characters for a text frame). */
|
|
770
|
+
readonly bytes: number;
|
|
771
|
+
/** `WsMessageContext` from `@znight/websocket`. */
|
|
772
|
+
readonly context: unknown;
|
|
773
|
+
/** `performance.now()` when the message was dispatched. */
|
|
774
|
+
readonly startTime: number;
|
|
775
|
+
outcome?: WebSocketMessageOutcome;
|
|
776
|
+
error?: unknown;
|
|
777
|
+
}
|
|
778
|
+
/** Instrumentation event of the `websocket:connection` hook (RFC 0003 §8.10). */
|
|
779
|
+
interface WebSocketConnectionEvent {
|
|
780
|
+
readonly type: "open" | "close";
|
|
781
|
+
/** Display name of the gateway class. */
|
|
782
|
+
readonly gateway: string;
|
|
783
|
+
/** Gateway path pattern, HTTP prefix included. */
|
|
784
|
+
readonly path: string;
|
|
785
|
+
readonly connectionId: string;
|
|
786
|
+
/** The request id of the handshake. */
|
|
787
|
+
readonly requestId: string;
|
|
788
|
+
/** `WsConnection` from `@znight/websocket`. */
|
|
789
|
+
readonly connection: unknown;
|
|
790
|
+
/** `performance.now()` when the connection opened. */
|
|
791
|
+
readonly openedAt: number;
|
|
792
|
+
/** Close code (`close` events). */
|
|
793
|
+
readonly code?: number;
|
|
794
|
+
readonly reason?: string;
|
|
795
|
+
readonly initiator?: WebSocketCloseInitiator;
|
|
796
|
+
/** Messages received and sent by the connection (`close` events). */
|
|
797
|
+
readonly messagesIn?: number;
|
|
798
|
+
readonly messagesOut?: number;
|
|
799
|
+
}
|
|
732
800
|
/** How a scheduled run was triggered (`ScheduledRunEvent.trigger`). */
|
|
733
801
|
type ScheduledRunTrigger = "schedule" | "start" | "manual" | "queued";
|
|
734
802
|
/** Outcome of a scheduled run (`ScheduledRunEvent.outcome`). */
|
|
@@ -1309,5 +1377,5 @@ export declare class ZnightAggregateError extends ZnightError {
|
|
|
1309
1377
|
* that were attached to it instead of being thrown. Empty when there are none.
|
|
1310
1378
|
*/
|
|
1311
1379
|
export declare function getSuppressedErrors(error: unknown): readonly unknown[];
|
|
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 };
|
|
1380
|
+
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, WebSocketCloseInitiator, WebSocketConnectionEvent, WebSocketMessageEvent, WebSocketMessageOutcome, ZnightHooks };
|
|
1313
1381
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -8,8 +8,8 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
8
8
|
* - `ZNIGHT001`–`ZNIGHT029`: the core, the compiler and the features shipped in 0.1 (http,
|
|
9
9
|
* messaging, config, observability).
|
|
10
10
|
* - From `ZNIGHT030`, each first-party package reserves a block of ten: `ZNIGHT030`–`039`
|
|
11
|
-
* `@znight/openapi`, `ZNIGHT040`–`049` `@znight/schedule`, `ZNIGHT050`–`059` `@znight/websocket
|
|
12
|
-
*
|
|
11
|
+
* `@znight/openapi`, `ZNIGHT040`–`049` `@znight/schedule`, `ZNIGHT050`–`059` `@znight/websocket`,
|
|
12
|
+
* `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
|
|
@@ -98,6 +98,16 @@ const ErrorCode = {
|
|
|
98
98
|
MissingLockStore: "ZNIGHT043",
|
|
99
99
|
/** A scheduled run was aborted (`ctx.signal.reason`, `JobAbortedError`); never thrown by the framework. */
|
|
100
100
|
JobAborted: "ZNIGHT044",
|
|
101
|
+
/**
|
|
102
|
+
* Invalid gateway: `@Gateway` options, lifecycle methods, events handled twice, reserved event
|
|
103
|
+
* names, parameters; at boot, invalid `WebSocketPlugin` options or `metadata.extensions.websocket`.
|
|
104
|
+
*/
|
|
105
|
+
InvalidGateway: "ZNIGHT050",
|
|
106
|
+
/**
|
|
107
|
+
* Gateways cannot be served: no `HttpPlugin`, an adapter without upgrade support, `ws` missing on
|
|
108
|
+
* Node.js, a transport that does not match the server.
|
|
109
|
+
*/
|
|
110
|
+
WebSocketTransportUnavailable: "ZNIGHT051",
|
|
101
111
|
/** A TypeScript type cannot be mapped to a GraphQL type, or a resolver lacks the annotation it needs. */
|
|
102
112
|
InvalidGraphQLType: "ZNIGHT060",
|
|
103
113
|
/** Two declarations or root fields share a GraphQL name, or a name is invalid or reserved. */
|
|
@@ -179,6 +189,8 @@ const ERROR_DESCRIPTIONS = {
|
|
|
179
189
|
ZNIGHT042: "Unknown job: no job has this name",
|
|
180
190
|
ZNIGHT043: "Missing lock store: a job requires a lock but SchedulePlugin has no store",
|
|
181
191
|
ZNIGHT044: "Job aborted: a scheduled run was aborted (timeout, lost lock, removal or shutdown)",
|
|
192
|
+
ZNIGHT050: "Invalid gateway: a WebSocket gateway, its handlers or the WebSocketPlugin options are invalid",
|
|
193
|
+
ZNIGHT051: "WebSocket transport unavailable: gateways cannot be served by the HTTP server",
|
|
182
194
|
ZNIGHT060: "Invalid GraphQL type: a TypeScript type cannot be mapped to a GraphQL type",
|
|
183
195
|
ZNIGHT061: "GraphQL name conflict: two types or root fields share a name, or a name is invalid or reserved",
|
|
184
196
|
ZNIGHT062: "Invalid resolver: the structure of a GraphQL resolver is invalid",
|