@leaven-graphql/nestjs 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.
@@ -0,0 +1,156 @@
1
+ /**
2
+ * @leaven-graphql/nestjs - Interceptors
3
+ *
4
+ * Copyright 2026 Pegasus Heavy Industries LLC
5
+ * Licensed under the Apache License, Version 2.0
6
+ */
7
+ import { type NestInterceptor, type ExecutionContext, type CallHandler } from '@nestjs/common';
8
+ import { Observable } from 'rxjs';
9
+ import { Reflector } from '@nestjs/core';
10
+ /**
11
+ * Logging interceptor for GraphQL operations
12
+ *
13
+ * Logs timing and operation information for debugging.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * @UseInterceptors(LoggingInterceptor)
18
+ * @Resolver(() => User)
19
+ * export class UserResolver {
20
+ * // ...
21
+ * }
22
+ * ```
23
+ */
24
+ export declare class LoggingInterceptor implements NestInterceptor {
25
+ intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
26
+ }
27
+ /**
28
+ * Error formatting interceptor
29
+ *
30
+ * Catches errors and formats them consistently.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * @UseInterceptors(ErrorFormattingInterceptor)
35
+ * @Resolver(() => User)
36
+ * export class UserResolver {
37
+ * // ...
38
+ * }
39
+ * ```
40
+ */
41
+ export declare class ErrorFormattingInterceptor implements NestInterceptor {
42
+ intercept(_context: ExecutionContext, next: CallHandler): Observable<unknown>;
43
+ /**
44
+ * Format an error for GraphQL response
45
+ */
46
+ private formatError;
47
+ }
48
+ /**
49
+ * Complexity tracking interceptor
50
+ *
51
+ * Tracks query complexity for monitoring.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * @UseInterceptors(ComplexityInterceptor)
56
+ * @Resolver(() => User)
57
+ * export class UserResolver {
58
+ * @Query(() => [User])
59
+ * @Complexity(10)
60
+ * async users() {
61
+ * return this.userService.findAll();
62
+ * }
63
+ * }
64
+ * ```
65
+ */
66
+ export declare class ComplexityInterceptor implements NestInterceptor {
67
+ private readonly reflector;
68
+ constructor(reflector: Reflector);
69
+ intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
70
+ }
71
+ /**
72
+ * Caching interceptor
73
+ *
74
+ * Handles cache hints for responses.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * @UseInterceptors(CachingInterceptor)
79
+ * @Resolver(() => Settings)
80
+ * export class SettingsResolver {
81
+ * @Query(() => Settings)
82
+ * @CacheHint({ maxAge: 3600, scope: 'PUBLIC' })
83
+ * async settings() {
84
+ * return this.settingsService.getAll();
85
+ * }
86
+ * }
87
+ * ```
88
+ */
89
+ export declare class CachingInterceptor implements NestInterceptor {
90
+ private readonly reflector;
91
+ constructor(reflector: Reflector);
92
+ intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
93
+ }
94
+ /**
95
+ * Metrics interceptor
96
+ *
97
+ * Collects metrics for GraphQL operations.
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * @UseInterceptors(MetricsInterceptor)
102
+ * @Resolver(() => User)
103
+ * export class UserResolver {
104
+ * // ...
105
+ * }
106
+ * ```
107
+ */
108
+ export declare class MetricsInterceptor implements NestInterceptor {
109
+ private readonly metrics;
110
+ intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
111
+ /**
112
+ * Record a successful operation
113
+ */
114
+ private recordSuccess;
115
+ /**
116
+ * Record an error
117
+ */
118
+ private recordError;
119
+ /**
120
+ * Get or create metrics for a key
121
+ */
122
+ private getOrCreateMetrics;
123
+ /**
124
+ * Get all metrics
125
+ */
126
+ getMetrics(): Map<string, OperationMetrics>;
127
+ /**
128
+ * Get metrics summary
129
+ */
130
+ getSummary(): MetricsSummary[];
131
+ /**
132
+ * Reset all metrics
133
+ */
134
+ reset(): void;
135
+ }
136
+ /**
137
+ * Operation metrics
138
+ */
139
+ export interface OperationMetrics {
140
+ totalCount: number;
141
+ successCount: number;
142
+ errorCount: number;
143
+ totalDuration: number;
144
+ lastDuration: number;
145
+ minDuration: number;
146
+ maxDuration: number;
147
+ }
148
+ /**
149
+ * Metrics summary for an operation
150
+ */
151
+ export interface MetricsSummary extends OperationMetrics {
152
+ operation: string;
153
+ averageDuration: number;
154
+ errorRate: number;
155
+ }
156
+ //# sourceMappingURL=interceptors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../src/interceptors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAA+B,MAAM,MAAM,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC;;;;;;;;;;;;;GAaG;AACH,qBACa,kBAAmB,YAAW,eAAe;IACjD,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;CAYpF;AAED;;;;;;;;;;;;;GAaG;AACH,qBACa,0BAA2B,YAAW,eAAe;IACzD,SAAS,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;IAUpF;;OAEG;IACH,OAAO,CAAC,WAAW;CAUpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBACa,qBAAsB,YAAW,eAAe;IAC/C,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS;IAE1C,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;CAiBpF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBACa,kBAAmB,YAAW,eAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,SAAS;IAE1C,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;CAsBpF;AAED;;;;;;;;;;;;;GAaG;AACH,qBACa,kBAAmB,YAAW,eAAe;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAExD,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC;IAmBnF;;OAEG;IACH,OAAO,CAAC,aAAa;IAUrB;;OAEG;IACH,OAAO,CAAC,WAAW;IAQnB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAiB1B;;OAEG;IACI,UAAU,IAAI,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAIlD;;OAEG;IACI,UAAU,IAAI,cAAc,EAAE;IASrC;;OAEG;IACI,KAAK,IAAI,IAAI;CAGrB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @leaven-graphql/nestjs - Middleware
3
+ *
4
+ * Copyright 2026 Pegasus Heavy Industries LLC
5
+ * Licensed under the Apache License, Version 2.0
6
+ */
7
+ import { type NestMiddleware, type Type } from '@nestjs/common';
8
+ interface Request {
9
+ method: string;
10
+ path: string;
11
+ body?: Record<string, unknown>;
12
+ headers: Record<string, string | string[] | undefined>;
13
+ }
14
+ interface Response {
15
+ status(code: number): Response;
16
+ json(body: unknown): Response;
17
+ send(body: unknown): Response;
18
+ setHeader(name: string, value: string): Response;
19
+ end(): Response;
20
+ }
21
+ type NextFunction = () => void;
22
+ import { LeavenDriver } from './driver';
23
+ import type { LeavenModuleOptions } from './types';
24
+ /**
25
+ * GraphQL middleware for handling GraphQL requests
26
+ *
27
+ * This middleware intercepts requests to the GraphQL endpoint
28
+ * and processes them through the Leaven driver.
29
+ */
30
+ export declare class GraphQLMiddleware implements NestMiddleware {
31
+ private readonly driver;
32
+ private readonly options;
33
+ constructor(driver: LeavenDriver, options: LeavenModuleOptions);
34
+ /**
35
+ * Handle incoming requests
36
+ */
37
+ use(req: Request, res: Response, next: NextFunction): Promise<void>;
38
+ /**
39
+ * Handle GraphQL request
40
+ */
41
+ private handleGraphQLRequest;
42
+ /**
43
+ * Serve GraphQL Playground HTML
44
+ */
45
+ private servePlayground;
46
+ /**
47
+ * Handle CORS preflight request
48
+ */
49
+ private handleCorsPreFlight;
50
+ /**
51
+ * Get the playground HTML
52
+ */
53
+ private getPlaygroundHtml;
54
+ }
55
+ /**
56
+ * Create middleware module with proper configuration
57
+ */
58
+ export declare function createGraphQLMiddleware(): Type<NestMiddleware>;
59
+ export {};
60
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,KAAK,cAAc,EAEnB,KAAK,IAAI,EACV,MAAM,gBAAgB,CAAC;AAGxB,UAAU,OAAO;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;CACxD;AAED,UAAU,QAAQ;IAChB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC/B,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC9B,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC9B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC;IACjD,GAAG,IAAI,QAAQ,CAAC;CACjB;AAED,KAAK,YAAY,GAAG,MAAM,IAAI,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD;;;;;GAKG;AACH,qBACa,iBAAkB,YAAW,cAAc;IAE7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADf,MAAM,EAAE,YAAY,EACZ,OAAO,EAAE,mBAAmB;IAG9E;;OAEG;IACU,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BhF;;OAEG;YACW,oBAAoB;IAyClC;;OAEG;IACH,OAAO,CAAC,eAAe;IAOvB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAwC3B;;OAEG;IACH,OAAO,CAAC,iBAAiB;CA6B1B;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAAC,cAAc,CAAC,CAE9D"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @leaven-graphql/nestjs - NestJS Module
3
+ *
4
+ * Copyright 2026 Pegasus Heavy Industries LLC
5
+ * Licensed under the Apache License, Version 2.0
6
+ */
7
+ import { DynamicModule } from '@nestjs/common';
8
+ import type { LeavenModuleOptions, LeavenModuleAsyncOptions } from './types';
9
+ /**
10
+ * Injection token for Leaven module options
11
+ */
12
+ export declare const LEAVEN_MODULE_OPTIONS = "LEAVEN_MODULE_OPTIONS";
13
+ /**
14
+ * Injection token for Leaven driver
15
+ */
16
+ export declare const LEAVEN_DRIVER = "LEAVEN_DRIVER";
17
+ /**
18
+ * Leaven GraphQL Module for NestJS
19
+ *
20
+ * This module provides integration between NestJS and Leaven GraphQL.
21
+ * It can be used with both schema-first and code-first approaches.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * // Schema-first approach
26
+ * @Module({
27
+ * imports: [
28
+ * LeavenModule.forRoot({
29
+ * typeDefs: `
30
+ * type Query {
31
+ * hello: String!
32
+ * }
33
+ * `,
34
+ * resolvers: {
35
+ * Query: {
36
+ * hello: () => 'Hello World!',
37
+ * },
38
+ * },
39
+ * }),
40
+ * ],
41
+ * })
42
+ * export class AppModule {}
43
+ * ```
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * // Async configuration
48
+ * @Module({
49
+ * imports: [
50
+ * LeavenModule.forRootAsync({
51
+ * useFactory: (configService: ConfigService) => ({
52
+ * playground: configService.get('GRAPHQL_PLAYGROUND'),
53
+ * introspection: configService.get('GRAPHQL_INTROSPECTION'),
54
+ * }),
55
+ * inject: [ConfigService],
56
+ * }),
57
+ * ],
58
+ * })
59
+ * export class AppModule {}
60
+ * ```
61
+ */
62
+ export declare class LeavenModule {
63
+ /**
64
+ * Configure the module synchronously
65
+ */
66
+ static forRoot(options?: LeavenModuleOptions): DynamicModule;
67
+ /**
68
+ * Configure the module asynchronously
69
+ */
70
+ static forRootAsync(options: LeavenModuleAsyncOptions): DynamicModule;
71
+ /**
72
+ * Create async providers based on configuration
73
+ */
74
+ private static createAsyncProviders;
75
+ /**
76
+ * Create the async options provider
77
+ */
78
+ private static createAsyncOptionsProvider;
79
+ }
80
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,aAAa,EAKd,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EAEzB,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,qBAEa,YAAY;IACvB;;OAEG;WACW,OAAO,CAAC,OAAO,GAAE,mBAAwB,GAAG,aAAa;IAmBvE;;OAEG;WACW,YAAY,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;IAiB5E;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAiBnC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,0BAA0B;CAsB1C"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @leaven-graphql/nestjs - Schema Builder Integration
3
+ *
4
+ * Provides integration with NestJS's code-first schema building approach.
5
+ *
6
+ * Copyright 2026 Pegasus Heavy Industries LLC
7
+ * Licensed under the Apache License, Version 2.0
8
+ */
9
+ import { type OnModuleInit, type Type } from '@nestjs/common';
10
+ import type { GraphQLSchema } from 'graphql';
11
+ import { LeavenDriver } from './driver';
12
+ import type { LeavenModuleOptions, BuildSchemaOptions } from './types';
13
+ /**
14
+ * Schema source type - determines how to build the schema
15
+ */
16
+ export type SchemaSource = {
17
+ type: 'provided';
18
+ schema: GraphQLSchema;
19
+ } | {
20
+ type: 'typeDefs';
21
+ typeDefs: string;
22
+ resolvers: Record<string, unknown>;
23
+ } | {
24
+ type: 'autoSchema';
25
+ options: BuildSchemaOptions;
26
+ };
27
+ /**
28
+ * Schema builder service
29
+ *
30
+ * Handles building the GraphQL schema from various sources and
31
+ * integrating it with the Leaven driver.
32
+ */
33
+ export declare class SchemaBuilderService implements OnModuleInit {
34
+ private readonly options;
35
+ private readonly driver;
36
+ private builtSchema;
37
+ constructor(options: LeavenModuleOptions, driver: LeavenDriver);
38
+ /**
39
+ * Initialize the schema on module init
40
+ */
41
+ onModuleInit(): Promise<void>;
42
+ /**
43
+ * Build the schema from configured sources
44
+ */
45
+ buildSchema(): Promise<GraphQLSchema | null>;
46
+ /**
47
+ * Build schema from type definitions (SDL)
48
+ */
49
+ private buildFromTypeDefs;
50
+ /**
51
+ * Merge multiple type definition strings
52
+ */
53
+ private mergeTypeDefs;
54
+ /**
55
+ * Merge multiple resolver objects
56
+ */
57
+ private mergeResolvers;
58
+ /**
59
+ * Get the built schema
60
+ */
61
+ getSchema(): GraphQLSchema | null;
62
+ /**
63
+ * Set a new schema (for hot-reloading scenarios)
64
+ */
65
+ setSchema(schema: GraphQLSchema): void;
66
+ /**
67
+ * Check if schema is ready
68
+ */
69
+ isSchemaReady(): boolean;
70
+ }
71
+ /**
72
+ * Schema file generator options
73
+ */
74
+ export interface SchemaFileOptions {
75
+ /**
76
+ * Path to write the schema file
77
+ */
78
+ path: string;
79
+ /**
80
+ * Sort schema alphabetically
81
+ */
82
+ sortSchema?: boolean;
83
+ /**
84
+ * Include comments/descriptions
85
+ */
86
+ includeDescriptions?: boolean;
87
+ }
88
+ /**
89
+ * Generate a schema file from the current schema
90
+ */
91
+ export declare function generateSchemaFile(schema: GraphQLSchema, options: SchemaFileOptions): Promise<void>;
92
+ /**
93
+ * Resolver decorator metadata storage
94
+ */
95
+ export interface ResolverMetadata {
96
+ type: 'Query' | 'Mutation' | 'Subscription' | 'Field';
97
+ name: string;
98
+ returnType: Type<unknown> | string;
99
+ target: Type<unknown>;
100
+ methodName: string;
101
+ args?: Array<{
102
+ name: string;
103
+ type: Type<unknown> | string;
104
+ nullable?: boolean;
105
+ }>;
106
+ }
107
+ /**
108
+ * Get all registered resolver metadata
109
+ */
110
+ export declare function getResolverMetadata(): ResolverMetadata[];
111
+ /**
112
+ * Register resolver metadata
113
+ */
114
+ export declare function registerResolverMetadata(metadata: ResolverMetadata): void;
115
+ /**
116
+ * Clear resolver metadata (for testing)
117
+ */
118
+ export declare function clearResolverMetadata(): void;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;IACI,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAK7C;;OAEG;IACI,aAAa,IAAI,OAAO;CAGhC;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,cAAc,GAAG,OAAO,CAAC;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IACnC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,KAAK,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;QAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,CAAC,CAAC;CACJ;AAOD;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,EAAE,CAExD;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAEzE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C"}
@@ -0,0 +1,195 @@
1
+ /**
2
+ * @leaven-graphql/nestjs - Subscriptions Support
3
+ *
4
+ * Provides WebSocket-based GraphQL subscriptions integration for NestJS.
5
+ *
6
+ * Copyright 2026 Pegasus Heavy Industries LLC
7
+ * Licensed under the Apache License, Version 2.0
8
+ */
9
+ import { type OnModuleInit, type OnModuleDestroy } from '@nestjs/common';
10
+ import { LeavenDriver } from './driver';
11
+ import type { LeavenModuleOptions, GqlContext } from './types';
12
+ /**
13
+ * Subscription configuration
14
+ */
15
+ export interface SubscriptionConfig {
16
+ /**
17
+ * WebSocket path for subscriptions
18
+ * @default '/graphql'
19
+ */
20
+ path?: string;
21
+ /**
22
+ * Keep-alive interval in milliseconds
23
+ * @default 12000
24
+ */
25
+ keepAlive?: number;
26
+ /**
27
+ * Connection initialization timeout in milliseconds
28
+ * @default 3000
29
+ */
30
+ connectionInitWaitTimeout?: number;
31
+ /**
32
+ * Maximum number of subscriptions per connection
33
+ * @default 100
34
+ */
35
+ maxSubscriptionsPerConnection?: number;
36
+ /**
37
+ * Context factory for subscription connections
38
+ */
39
+ context?: (ctx: SubscriptionContext) => GqlContext | Promise<GqlContext>;
40
+ /**
41
+ * Connection callback - called when a client connects
42
+ */
43
+ onConnect?: (ctx: SubscriptionContext) => boolean | Promise<boolean>;
44
+ /**
45
+ * Disconnect callback - called when a client disconnects
46
+ */
47
+ onDisconnect?: (ctx: SubscriptionContext) => void | Promise<void>;
48
+ /**
49
+ * Subscribe callback - called when a subscription starts
50
+ */
51
+ onSubscribe?: (ctx: SubscriptionContext, message: SubscribeMessage) => void | Promise<void>;
52
+ /**
53
+ * Operation callback - called for each subscription operation
54
+ */
55
+ onOperation?: (ctx: SubscriptionContext, message: SubscribeMessage, args: ExecutionArgs) => ExecutionArgs | Promise<ExecutionArgs>;
56
+ /**
57
+ * Complete callback - called when a subscription completes
58
+ */
59
+ onComplete?: (ctx: SubscriptionContext, message: CompleteMessage) => void | Promise<void>;
60
+ }
61
+ /**
62
+ * Subscription context
63
+ */
64
+ export interface SubscriptionContext {
65
+ /**
66
+ * The WebSocket connection
67
+ */
68
+ socket: WebSocket;
69
+ /**
70
+ * Connection parameters from client
71
+ */
72
+ connectionParams: Record<string, unknown> | undefined;
73
+ /**
74
+ * Extra data attached to the connection
75
+ */
76
+ extra?: Record<string, unknown>;
77
+ /**
78
+ * Request object (if available)
79
+ */
80
+ request: Request | undefined;
81
+ }
82
+ /**
83
+ * Subscribe message
84
+ */
85
+ export interface SubscribeMessage {
86
+ id: string;
87
+ type: 'subscribe';
88
+ payload: {
89
+ query: string;
90
+ variables?: Record<string, unknown>;
91
+ operationName?: string;
92
+ extensions?: Record<string, unknown>;
93
+ };
94
+ }
95
+ /**
96
+ * Complete message
97
+ */
98
+ export interface CompleteMessage {
99
+ id: string;
100
+ type: 'complete';
101
+ }
102
+ /**
103
+ * Execution args for GraphQL
104
+ */
105
+ export interface ExecutionArgs {
106
+ schema: unknown;
107
+ document: unknown;
108
+ rootValue?: unknown;
109
+ contextValue?: unknown;
110
+ variableValues?: Record<string, unknown>;
111
+ operationName?: string;
112
+ }
113
+ /**
114
+ * Subscription manager
115
+ *
116
+ * Manages WebSocket connections and GraphQL subscriptions.
117
+ */
118
+ export declare class SubscriptionManager implements OnModuleInit, OnModuleDestroy {
119
+ private readonly options;
120
+ private readonly driver;
121
+ private connections;
122
+ private config;
123
+ constructor(options: LeavenModuleOptions, driver: LeavenDriver);
124
+ /**
125
+ * Initialize subscription manager
126
+ */
127
+ onModuleInit(): Promise<void>;
128
+ /**
129
+ * Cleanup on module destroy
130
+ */
131
+ onModuleDestroy(): Promise<void>;
132
+ /**
133
+ * Normalize subscription configuration
134
+ */
135
+ private normalizeConfig;
136
+ /**
137
+ * Handle new WebSocket connection
138
+ */
139
+ handleConnection(socket: WebSocket, request?: Request): Promise<void>;
140
+ /**
141
+ * Handle incoming WebSocket message
142
+ */
143
+ private handleMessage;
144
+ /**
145
+ * Handle connection initialization
146
+ */
147
+ private handleConnectionInit;
148
+ /**
149
+ * Handle subscribe message
150
+ */
151
+ private handleSubscribe;
152
+ /**
153
+ * Handle complete message
154
+ */
155
+ private handleComplete;
156
+ /**
157
+ * Handle WebSocket close
158
+ */
159
+ private handleClose;
160
+ /**
161
+ * Handle WebSocket error
162
+ */
163
+ private handleError;
164
+ /**
165
+ * Send message to client
166
+ */
167
+ private send;
168
+ /**
169
+ * Send error to client
170
+ */
171
+ private sendError;
172
+ /**
173
+ * Publish to subscription
174
+ */
175
+ publish(id: string, payload: unknown): void;
176
+ /**
177
+ * Get connection count
178
+ */
179
+ getConnectionCount(): number;
180
+ /**
181
+ * Get total subscription count
182
+ */
183
+ getSubscriptionCount(): number;
184
+ }
185
+ /**
186
+ * Create a subscription decorator for NestJS resolvers
187
+ */
188
+ export declare function Subscription(returns: () => unknown, options?: {
189
+ filter?: (payload: unknown, variables: unknown, context: unknown) => boolean;
190
+ }): MethodDecorator;
191
+ /**
192
+ * PubSub decorator for injecting PubSub instance
193
+ */
194
+ export declare function InjectPubSub(): ParameterDecorator;
195
+ //# sourceMappingURL=subscriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../src/subscriptions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAsB,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE7F,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IAEnC;;;OAGG;IACH,6BAA6B,CAAC,EAAE,MAAM,CAAC;IAEvC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,mBAAmB,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAEzE;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,mBAAmB,KAAK,O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