@leaven-graphql/ws 0.1.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/LICENSE +190 -0
- package/README.md +282 -0
- package/dist/handler.d.ts +112 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9274 -0
- package/dist/manager.d.ts +96 -0
- package/dist/manager.d.ts.map +1 -0
- package/dist/protocol.d.ts +133 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/pubsub.d.ts +77 -0
- package/dist/pubsub.d.ts.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @leaven-graphql/ws - Subscription manager
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2026 Pegasus Heavy Industries LLC
|
|
5
|
+
* Licensed under the Apache License, Version 2.0
|
|
6
|
+
*/
|
|
7
|
+
import type { GraphQLSchema } from 'graphql';
|
|
8
|
+
import { type GraphQLRequest, type GraphQLResponse } from '@leaven-graphql/core';
|
|
9
|
+
/**
|
|
10
|
+
* Subscription status
|
|
11
|
+
*/
|
|
12
|
+
export type SubscriptionStatus = 'pending' | 'active' | 'completed' | 'error';
|
|
13
|
+
/**
|
|
14
|
+
* Active subscription
|
|
15
|
+
*/
|
|
16
|
+
export interface Subscription {
|
|
17
|
+
/** Unique subscription ID */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Connection ID */
|
|
20
|
+
connectionId: string;
|
|
21
|
+
/** The original request */
|
|
22
|
+
request: GraphQLRequest;
|
|
23
|
+
/** Subscription status */
|
|
24
|
+
status: SubscriptionStatus;
|
|
25
|
+
/** When the subscription was created */
|
|
26
|
+
createdAt: number;
|
|
27
|
+
/** Async iterator */
|
|
28
|
+
iterator?: AsyncIterableIterator<GraphQLResponse>;
|
|
29
|
+
/** Cleanup function */
|
|
30
|
+
cleanup?: () => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Subscription manager configuration
|
|
34
|
+
*/
|
|
35
|
+
export interface SubscriptionManagerConfig {
|
|
36
|
+
/** GraphQL schema */
|
|
37
|
+
schema: GraphQLSchema;
|
|
38
|
+
/** Maximum subscriptions per connection */
|
|
39
|
+
maxSubscriptionsPerConnection?: number;
|
|
40
|
+
/** Subscription timeout in milliseconds */
|
|
41
|
+
subscriptionTimeout?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Manages GraphQL subscriptions
|
|
45
|
+
*/
|
|
46
|
+
export declare class SubscriptionManager {
|
|
47
|
+
private readonly executor;
|
|
48
|
+
private readonly subscriptions;
|
|
49
|
+
private readonly connectionSubscriptions;
|
|
50
|
+
private readonly maxSubscriptionsPerConnection;
|
|
51
|
+
private readonly subscriptionTimeout;
|
|
52
|
+
constructor(config: SubscriptionManagerConfig);
|
|
53
|
+
/**
|
|
54
|
+
* Create a new subscription
|
|
55
|
+
*/
|
|
56
|
+
subscribe<TContext = unknown>(connectionId: string, subscriptionId: string, request: GraphQLRequest, context: TContext, onNext: (result: GraphQLResponse) => void, onComplete: () => void, onError: (errors: readonly {
|
|
57
|
+
message: string;
|
|
58
|
+
}[]) => void): Promise<Subscription>;
|
|
59
|
+
/**
|
|
60
|
+
* Consume an async iterator and call callbacks
|
|
61
|
+
*/
|
|
62
|
+
private consumeIterator;
|
|
63
|
+
/**
|
|
64
|
+
* Unsubscribe from a subscription
|
|
65
|
+
*/
|
|
66
|
+
unsubscribe(subscriptionId: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Unsubscribe all subscriptions for a connection
|
|
69
|
+
*/
|
|
70
|
+
unsubscribeConnection(connectionId: string): number;
|
|
71
|
+
/**
|
|
72
|
+
* Get a subscription by ID
|
|
73
|
+
*/
|
|
74
|
+
getSubscription(subscriptionId: string): Subscription | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Get all subscriptions for a connection
|
|
77
|
+
*/
|
|
78
|
+
getConnectionSubscriptions(connectionId: string): Subscription[];
|
|
79
|
+
/**
|
|
80
|
+
* Get the total number of active subscriptions
|
|
81
|
+
*/
|
|
82
|
+
get subscriptionCount(): number;
|
|
83
|
+
/**
|
|
84
|
+
* Get the number of active connections
|
|
85
|
+
*/
|
|
86
|
+
get connectionCount(): number;
|
|
87
|
+
/**
|
|
88
|
+
* Clear all subscriptions
|
|
89
|
+
*/
|
|
90
|
+
clear(): void;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Create a new subscription manager
|
|
94
|
+
*/
|
|
95
|
+
export declare function createSubscriptionManager(config: SubscriptionManagerConfig): SubscriptionManager;
|
|
96
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAkB,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEjG;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,GAAG,OAAO,CAAC;AAE9E;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,oBAAoB;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,0BAA0B;IAC1B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,qBAAqB,CAAC,eAAe,CAAC,CAAC;IAClD,uBAAuB;IACvB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,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I,IAAI;CAKrB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,yBAAyB,GAChC,mBAAmB,CAErB"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @leaven-graphql/ws - GraphQL over WebSocket protocol
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2026 Pegasus Heavy Industries LLC
|
|
5
|
+
* Licensed under the Apache License, Version 2.0
|
|
6
|
+
*
|
|
7
|
+
* Implements graphql-ws protocol
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Message types as defined by graphql-ws protocol
|
|
11
|
+
*/
|
|
12
|
+
export declare enum MessageType {
|
|
13
|
+
ConnectionInit = "connection_init",
|
|
14
|
+
ConnectionAck = "connection_ack",
|
|
15
|
+
Ping = "ping",
|
|
16
|
+
Pong = "pong",
|
|
17
|
+
Subscribe = "subscribe",
|
|
18
|
+
Next = "next",
|
|
19
|
+
Error = "error",
|
|
20
|
+
Complete = "complete"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Connection init message
|
|
24
|
+
*/
|
|
25
|
+
export interface ConnectionInitMessage {
|
|
26
|
+
type: MessageType.ConnectionInit;
|
|
27
|
+
payload?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Connection ack message
|
|
31
|
+
*/
|
|
32
|
+
export interface ConnectionAckMessage {
|
|
33
|
+
type: MessageType.ConnectionAck;
|
|
34
|
+
payload?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Ping message
|
|
38
|
+
*/
|
|
39
|
+
export interface PingMessage {
|
|
40
|
+
type: MessageType.Ping;
|
|
41
|
+
payload?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Pong message
|
|
45
|
+
*/
|
|
46
|
+
export interface PongMessage {
|
|
47
|
+
type: MessageType.Pong;
|
|
48
|
+
payload?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Subscribe message
|
|
52
|
+
*/
|
|
53
|
+
export interface SubscribeMessage {
|
|
54
|
+
id: string;
|
|
55
|
+
type: MessageType.Subscribe;
|
|
56
|
+
payload: {
|
|
57
|
+
operationName?: string;
|
|
58
|
+
query: string;
|
|
59
|
+
variables?: Record<string, unknown>;
|
|
60
|
+
extensions?: Record<string, unknown>;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Next message (data result)
|
|
65
|
+
*/
|
|
66
|
+
export interface NextMessage {
|
|
67
|
+
id: string;
|
|
68
|
+
type: MessageType.Next;
|
|
69
|
+
payload: {
|
|
70
|
+
data?: Record<string, unknown> | null;
|
|
71
|
+
errors?: readonly {
|
|
72
|
+
message: string;
|
|
73
|
+
[key: string]: unknown;
|
|
74
|
+
}[];
|
|
75
|
+
extensions?: Record<string, unknown>;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Error message
|
|
80
|
+
*/
|
|
81
|
+
export interface ErrorMessage {
|
|
82
|
+
id: string;
|
|
83
|
+
type: MessageType.Error;
|
|
84
|
+
payload: readonly {
|
|
85
|
+
message: string;
|
|
86
|
+
[key: string]: unknown;
|
|
87
|
+
}[];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Complete message
|
|
91
|
+
*/
|
|
92
|
+
export interface CompleteMessage {
|
|
93
|
+
id: string;
|
|
94
|
+
type: MessageType.Complete;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* All message types
|
|
98
|
+
*/
|
|
99
|
+
export type Message = ConnectionInitMessage | ConnectionAckMessage | PingMessage | PongMessage | SubscribeMessage | NextMessage | ErrorMessage | CompleteMessage;
|
|
100
|
+
/**
|
|
101
|
+
* Parse a WebSocket message
|
|
102
|
+
*/
|
|
103
|
+
export declare function parseMessage(data: string | Buffer): Message;
|
|
104
|
+
/**
|
|
105
|
+
* Format a message for sending
|
|
106
|
+
*/
|
|
107
|
+
export declare function formatMessage(message: Message): string;
|
|
108
|
+
/**
|
|
109
|
+
* Create a connection ack message
|
|
110
|
+
*/
|
|
111
|
+
export declare function createConnectionAck(payload?: Record<string, unknown>): ConnectionAckMessage;
|
|
112
|
+
/**
|
|
113
|
+
* Create a next message
|
|
114
|
+
*/
|
|
115
|
+
export declare function createNextMessage(id: string, data: Record<string, unknown> | null | undefined, errors?: readonly {
|
|
116
|
+
message: string;
|
|
117
|
+
}[]): NextMessage;
|
|
118
|
+
/**
|
|
119
|
+
* Create an error message
|
|
120
|
+
*/
|
|
121
|
+
export declare function createErrorMessage(id: string, errors: readonly {
|
|
122
|
+
message: string;
|
|
123
|
+
[key: string]: unknown;
|
|
124
|
+
}[]): ErrorMessage;
|
|
125
|
+
/**
|
|
126
|
+
* Create a complete message
|
|
127
|
+
*/
|
|
128
|
+
export declare function createCompleteMessage(id: string): CompleteMessage;
|
|
129
|
+
/**
|
|
130
|
+
* Create a pong message
|
|
131
|
+
*/
|
|
132
|
+
export declare function createPongMessage(payload?: Record<string, unknown>): PongMessage;
|
|
133
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,oBAAY,WAAW;IACrB,cAAc,oBAAoB;IAClC,aAAa,mBAAmB;IAChC,IAAI,SAAS;IACb,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,WAAW,CAAC,cAAc,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI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,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,WAAW,CAKb"}
|
package/dist/pubsub.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @leaven-graphql/ws - PubSub implementation
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2026 Pegasus Heavy Industries LLC
|
|
5
|
+
* Licensed under the Apache License, Version 2.0
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Subscribe function type
|
|
9
|
+
*/
|
|
10
|
+
export type SubscribeFn<T = unknown> = (topic: string, callback: (payload: T) => void) => () => void;
|
|
11
|
+
/**
|
|
12
|
+
* Publish function type
|
|
13
|
+
*/
|
|
14
|
+
export type PublishFn<T = unknown> = (topic: string, payload: T) => void;
|
|
15
|
+
/**
|
|
16
|
+
* PubSub engine interface
|
|
17
|
+
*/
|
|
18
|
+
export interface PubSubEngine {
|
|
19
|
+
subscribe: SubscribeFn;
|
|
20
|
+
publish: PublishFn;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* PubSub configuration
|
|
24
|
+
*/
|
|
25
|
+
export interface PubSubConfig {
|
|
26
|
+
/** Maximum subscribers per topic */
|
|
27
|
+
maxSubscribersPerTopic?: number;
|
|
28
|
+
/** Enable topic wildcards */
|
|
29
|
+
wildcards?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* In-memory PubSub implementation
|
|
33
|
+
*/
|
|
34
|
+
export declare class PubSub implements PubSubEngine {
|
|
35
|
+
private readonly subscribers;
|
|
36
|
+
private readonly maxSubscribersPerTopic;
|
|
37
|
+
private readonly wildcards;
|
|
38
|
+
private nextId;
|
|
39
|
+
constructor(config?: PubSubConfig);
|
|
40
|
+
/**
|
|
41
|
+
* Subscribe to a topic
|
|
42
|
+
*/
|
|
43
|
+
subscribe<T = unknown>(topic: string, callback: (payload: T) => void): () => void;
|
|
44
|
+
/**
|
|
45
|
+
* Publish to a topic
|
|
46
|
+
*/
|
|
47
|
+
publish<T = unknown>(topic: string, payload: T): void;
|
|
48
|
+
/**
|
|
49
|
+
* Publish to wildcard subscribers
|
|
50
|
+
*/
|
|
51
|
+
private publishToWildcards;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a topic pattern matches
|
|
54
|
+
*/
|
|
55
|
+
private matchesWildcard;
|
|
56
|
+
/**
|
|
57
|
+
* Create an async iterator for a topic
|
|
58
|
+
*/
|
|
59
|
+
asyncIterator<T = unknown>(topic: string | string[]): AsyncIterableIterator<T>;
|
|
60
|
+
/**
|
|
61
|
+
* Get the number of subscribers for a topic
|
|
62
|
+
*/
|
|
63
|
+
getSubscriberCount(topic: string): number;
|
|
64
|
+
/**
|
|
65
|
+
* Get all topics with subscribers
|
|
66
|
+
*/
|
|
67
|
+
getTopics(): string[];
|
|
68
|
+
/**
|
|
69
|
+
* Clear all subscriptions
|
|
70
|
+
*/
|
|
71
|
+
clear(): void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Create a new PubSub instance
|
|
75
|
+
*/
|
|
76
|
+
export declare function createPubSub(config?: PubSubConfig): PubSub;
|
|
77
|
+
//# sourceMappingURL=pubsub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pubsub.d.ts","sourceRoot":"","sources":["../src/pubsub.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,CACrC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,KAC3B,MAAM,IAAI,CAAC;AAEhB;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,WAAW,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0",
|
|
4
|
+
"description": "WebSocket subscriptions support for Leaven GraphQL",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"graphql",
|
|
20
|
+
"bun",
|
|
21
|
+
"websocket",
|
|
22
|
+
"subscriptions"
|
|
23
|
+
],
|
|
24
|
+
"author": "Pegasus Heavy Industries LLC",
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"graphql": "^16.8.0",
|
|
28
|
+
"@leaven-graphql/core": "0.1.0",
|
|
29
|
+
"@leaven-graphql/context": "0.1.0",
|
|
30
|
+
"@leaven-graphql/errors": "0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/bun": "^1.1.0",
|
|
34
|
+
"typescript": "^5.3.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"graphql": "^16.0.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target bun && tsc -p tsconfig.build.json",
|
|
41
|
+
"clean": "rm -rf dist",
|
|
42
|
+
"test": "bun test",
|
|
43
|
+
"typecheck": "tsc --noEmit"
|
|
44
|
+
}
|
|
45
|
+
}
|