@spikard/node 0.9.0 → 0.10.1

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/config.d.ts DELETED
@@ -1,281 +0,0 @@
1
- /**
2
- * Configuration types for Spikard Node.js bindings
3
- *
4
- * These types mirror the Rust ServerConfig and related configuration structs.
5
- */
6
-
7
- /**
8
- * Compression configuration for response compression middleware.
9
- *
10
- * Spikard supports gzip and brotli compression for responses.
11
- * Compression is applied based on Accept-Encoding headers.
12
- */
13
- export interface CompressionConfig {
14
- /** Enable gzip compression (default: true) */
15
- gzip?: boolean;
16
- /** Enable brotli compression (default: true) */
17
- brotli?: boolean;
18
- /** Minimum response size in bytes to compress (default: 1024) */
19
- minSize?: number;
20
- /** Compression quality level (0-11 for brotli, 0-9 for gzip, default: 6) */
21
- quality?: number;
22
- }
23
-
24
- /**
25
- * Rate limiting configuration using Generic Cell Rate Algorithm (GCRA).
26
- *
27
- * By default, rate limits are applied per IP address.
28
- */
29
- export interface RateLimitConfig {
30
- /** Maximum requests per second */
31
- perSecond: number;
32
- /** Burst allowance - allows temporary spikes */
33
- burst: number;
34
- /** Apply rate limits per IP address (default: true) */
35
- ipBased?: boolean;
36
- }
37
-
38
- /**
39
- * JWT authentication configuration.
40
- *
41
- * Validates JWT tokens using the specified secret and algorithm.
42
- * Tokens are expected in the Authorization header as "Bearer <token>".
43
- *
44
- * Supported algorithms:
45
- * - HS256, HS384, HS512 (HMAC with SHA)
46
- * - RS256, RS384, RS512 (RSA signatures)
47
- * - ES256, ES384, ES512 (ECDSA signatures)
48
- * - PS256, PS384, PS512 (RSA-PSS signatures)
49
- */
50
- export interface JwtConfig {
51
- /** Secret key for JWT validation */
52
- secret: string;
53
- /** JWT algorithm (default: "HS256") */
54
- algorithm?: string;
55
- /** Expected audience claim(s) */
56
- audience?: string[];
57
- /** Expected issuer claim */
58
- issuer?: string;
59
- /** Time leeway in seconds for exp/nbf/iat claims (default: 0) */
60
- leeway?: number;
61
- }
62
-
63
- /**
64
- * API key authentication configuration.
65
- *
66
- * Validates API keys from request headers. Keys are matched exactly.
67
- */
68
- export interface ApiKeyConfig {
69
- /** List of valid API keys */
70
- keys: string[];
71
- /** HTTP header name to check for API key (default: "X-API-Key") */
72
- headerName?: string;
73
- }
74
-
75
- /**
76
- * Static file serving configuration.
77
- *
78
- * Serves files from a directory at a given route prefix.
79
- * Multiple static file configurations can be registered.
80
- */
81
- export interface StaticFilesConfig {
82
- /** Directory path containing static files */
83
- directory: string;
84
- /** URL prefix for serving static files (e.g., "/static") */
85
- routePrefix: string;
86
- /** Serve index.html for directory requests (default: true) */
87
- indexFile?: boolean;
88
- /** Optional Cache-Control header value (e.g., "public, max-age=3600") */
89
- cacheControl?: string;
90
- }
91
-
92
- /**
93
- * Contact information for OpenAPI documentation.
94
- */
95
- export interface ContactInfo {
96
- /** Name of the contact person/organization */
97
- name?: string;
98
- /** Email address for contact */
99
- email?: string;
100
- /** URL for contact information */
101
- url?: string;
102
- }
103
-
104
- /**
105
- * License information for OpenAPI documentation.
106
- */
107
- export interface LicenseInfo {
108
- /** License name (e.g., "MIT", "Apache 2.0") */
109
- name: string;
110
- /** URL to the full license text */
111
- url?: string;
112
- }
113
-
114
- /**
115
- * Server information for OpenAPI documentation.
116
- *
117
- * Multiple servers can be specified for different environments.
118
- */
119
- export interface ServerInfo {
120
- /** Server URL (e.g., "https://api.example.com") */
121
- url: string;
122
- /** Description of the server (e.g., "Production", "Staging") */
123
- description?: string;
124
- }
125
-
126
- /**
127
- * Security scheme configuration for OpenAPI documentation.
128
- *
129
- * Supports HTTP (Bearer/JWT) and API Key authentication schemes.
130
- */
131
- export type SecuritySchemeInfo =
132
- | {
133
- /** Security scheme type */
134
- type: "http";
135
- /** HTTP scheme (e.g., "bearer", "basic") */
136
- scheme: string;
137
- /** Format hint for Bearer tokens (e.g., "JWT") */
138
- bearerFormat?: string;
139
- }
140
- | {
141
- /** Security scheme type */
142
- type: "apiKey";
143
- /** Where to look for the API key: "header", "query", or "cookie" */
144
- location: "header" | "query" | "cookie";
145
- /** Parameter name (e.g., "X-API-Key") */
146
- name: string;
147
- };
148
-
149
- /**
150
- * OpenAPI 3.1.0 documentation configuration.
151
- *
152
- * Spikard can automatically generate OpenAPI documentation from your routes.
153
- * When enabled, it serves:
154
- * - Swagger UI at /docs (customizable)
155
- * - Redoc at /redoc (customizable)
156
- * - OpenAPI JSON spec at /openapi.json (customizable)
157
- *
158
- * Security schemes are auto-detected from middleware configuration.
159
- * Schemas are generated from your route type hints and validation.
160
- *
161
- * @example
162
- * ```typescript
163
- * const openapi: OpenApiConfig = {
164
- * enabled: true,
165
- * title: "My API",
166
- * version: "1.0.0",
167
- * description: "A great API built with Spikard",
168
- * contact: {
169
- * name: "API Team",
170
- * email: "api@example.com",
171
- * url: "https://example.com"
172
- * },
173
- * license: {
174
- * name: "MIT",
175
- * url: "https://opensource.org/licenses/MIT"
176
- * },
177
- * servers: [
178
- * { url: "https://api.example.com", description: "Production" },
179
- * { url: "http://localhost:8000", description: "Development" }
180
- * ]
181
- * };
182
- * ```
183
- */
184
- export interface OpenApiConfig {
185
- /** Enable OpenAPI generation (default: false for zero overhead) */
186
- enabled?: boolean;
187
- /** API title (required if enabled) */
188
- title?: string;
189
- /** API version (required if enabled) */
190
- version?: string;
191
- /** API description (supports Markdown) */
192
- description?: string;
193
- /** Path to serve Swagger UI (default: "/docs") */
194
- swaggerUiPath?: string;
195
- /** Path to serve Redoc (default: "/redoc") */
196
- redocPath?: string;
197
- /** Path to serve OpenAPI JSON spec (default: "/openapi.json") */
198
- openapiJsonPath?: string;
199
- /** Contact information for the API */
200
- contact?: ContactInfo;
201
- /** License information for the API */
202
- license?: LicenseInfo;
203
- /** List of server URLs for different environments */
204
- servers?: ServerInfo[];
205
- /** Custom security schemes (auto-detected if not provided) */
206
- securitySchemes?: Record<string, SecuritySchemeInfo>;
207
- }
208
-
209
- /**
210
- * Complete server configuration for Spikard.
211
- *
212
- * This is the main configuration object that controls all aspects of the server
213
- * including network settings, middleware, authentication, and more.
214
- *
215
- * @example
216
- * ```typescript
217
- * import { Spikard } from 'spikard';
218
- *
219
- * const config: ServerConfig = {
220
- * host: "0.0.0.0",
221
- * port: 8080,
222
- * workers: 4,
223
- * compression: {
224
- * quality: 9
225
- * },
226
- * rateLimit: {
227
- * perSecond: 100,
228
- * burst: 200
229
- * },
230
- * staticFiles: [
231
- * {
232
- * directory: "./public",
233
- * routePrefix: "/static"
234
- * }
235
- * ],
236
- * openapi: {
237
- * enabled: true,
238
- * title: "My API",
239
- * version: "1.0.0"
240
- * }
241
- * };
242
- *
243
- * const app = new Spikard(config);
244
- * ```
245
- */
246
- export interface ServerConfig {
247
- /** Host address to bind to (default: "127.0.0.1") */
248
- host?: string;
249
- /** Port number to listen on (default: 8000, range: 1-65535) */
250
- port?: number;
251
- /** Number of worker processes (default: 1) */
252
- workers?: number;
253
-
254
- /** Add X-Request-ID header to responses (default: true) */
255
- enableRequestId?: boolean;
256
- /** Enable per-request HTTP tracing via tower-http TraceLayer (default: false) */
257
- enableHttpTrace?: boolean;
258
- /** Maximum request body size in bytes (default: 10MB, 0 or null for unlimited) */
259
- maxBodySize?: number | null;
260
- /** Request timeout in seconds (default: 30, null for no timeout) */
261
- requestTimeout?: number | null;
262
-
263
- /** Response compression configuration (default: enabled with defaults) */
264
- compression?: CompressionConfig | null;
265
- /** Rate limiting configuration (default: null/disabled) */
266
- rateLimit?: RateLimitConfig | null;
267
- /** JWT authentication configuration (default: null/disabled) */
268
- jwtAuth?: JwtConfig | null;
269
- /** API key authentication configuration (default: null/disabled) */
270
- apiKeyAuth?: ApiKeyConfig | null;
271
- /** List of static file serving configurations (default: empty array) */
272
- staticFiles?: StaticFilesConfig[];
273
-
274
- /** Enable graceful shutdown (default: true) */
275
- gracefulShutdown?: boolean;
276
- /** Graceful shutdown timeout in seconds (default: 30) */
277
- shutdownTimeout?: number;
278
-
279
- /** OpenAPI configuration (default: null/disabled) */
280
- openapi?: OpenApiConfig | null;
281
- }
package/graphql.d.ts DELETED
@@ -1,287 +0,0 @@
1
- /**
2
- * GraphQL Schema Configuration Bindings for Node.js
3
- *
4
- * High-performance TypeScript bindings for configuring GraphQL schemas
5
- * with support for introspection control, complexity limits, and depth limits.
6
- *
7
- * @module spikard/graphql
8
- */
9
-
10
- /**
11
- * GraphQL Schema Configuration
12
- *
13
- * Represents the final configuration for a GraphQL schema after builder setup.
14
- * This object is passed to the GraphQL execution engine to apply constraints
15
- * and settings to query execution.
16
- *
17
- * @interface SchemaConfig
18
- */
19
- export interface SchemaConfig {
20
- /**
21
- * Whether to enable GraphQL introspection queries.
22
- * Introspection allows clients to query the schema structure.
23
- *
24
- * @default true
25
- */
26
- introspectionEnabled?: boolean;
27
-
28
- /**
29
- * Maximum complexity allowed for queries (0 = unlimited).
30
- * Queries exceeding this complexity will be rejected.
31
- *
32
- * Complexity is calculated based on the query structure and field costs.
33
- * Typical production values: 1000-5000
34
- *
35
- * @default undefined (unlimited)
36
- */
37
- complexityLimit?: number;
38
-
39
- /**
40
- * Maximum depth allowed for queries (0 = unlimited).
41
- * Queries exceeding this depth will be rejected.
42
- *
43
- * Depth is the maximum nesting level of selections.
44
- * Typical production values: 15-25
45
- *
46
- * @default undefined (unlimited)
47
- */
48
- depthLimit?: number;
49
- }
50
-
51
- /**
52
- * GraphQL Schema Builder
53
- *
54
- * Provides a fluent interface for building GraphQL schema configurations.
55
- * The builder follows the same pattern as the Rust SchemaBuilder with
56
- * mutations applied directly to the builder instance.
57
- *
58
- * @class GraphQLSchemaBuilder
59
- * @example
60
- * const builder = new GraphQLSchemaBuilder();
61
- * builder.enableIntrospection(true);
62
- * builder.complexityLimit(5000);
63
- * builder.depthLimit(50);
64
- * const config = builder.finish();
65
- */
66
- export class GraphQLSchemaBuilder {
67
- /**
68
- * Create a new GraphQL schema builder with default settings
69
- *
70
- * Default configuration:
71
- * - Introspection enabled
72
- * - No complexity limit
73
- * - No depth limit
74
- *
75
- * @constructor
76
- */
77
- constructor();
78
-
79
- /**
80
- * Enable or disable GraphQL introspection
81
- *
82
- * Introspection is enabled by default. Disabling it prevents clients
83
- * from querying the schema structure via introspection queries, which
84
- * can be useful for security through obscurity in production.
85
- *
86
- * @param enabled - Whether to enable introspection
87
- * @returns void (mutates this instance)
88
- *
89
- * @example
90
- * builder.enableIntrospection(false); // Disable introspection
91
- */
92
- enableIntrospection(enabled: boolean): void;
93
-
94
- /**
95
- * Set the maximum complexity allowed for queries
96
- *
97
- * The complexity is calculated based on the query structure and field costs.
98
- * Queries exceeding this limit will be rejected with a validation error.
99
- * A value of 0 means unlimited.
100
- *
101
- * Typical values:
102
- * - Production: 1000-5000
103
- * - Development: 10000+
104
- * - Testing: varies based on test scenarios
105
- *
106
- * @param limit - The maximum complexity allowed (0 = unlimited)
107
- * @returns void (mutates this instance)
108
- *
109
- * @example
110
- * builder.complexityLimit(5000); // Allow up to 5000 complexity
111
- */
112
- complexityLimit(limit: number): void;
113
-
114
- /**
115
- * Set the maximum depth allowed for queries
116
- *
117
- * The depth is the maximum nesting level of selections in a query.
118
- * Queries exceeding this limit will be rejected with a validation error.
119
- * A value of 0 means unlimited.
120
- *
121
- * Typical values:
122
- * - Production: 15-25
123
- * - Development: 50-100
124
- * - Testing: varies based on test scenarios
125
- *
126
- * @param limit - The maximum depth allowed (0 = unlimited)
127
- * @returns void (mutates this instance)
128
- *
129
- * @example
130
- * builder.depthLimit(50); // Allow up to 50 nesting levels
131
- */
132
- depthLimit(limit: number): void;
133
-
134
- /**
135
- * Check if introspection is currently enabled
136
- *
137
- * @returns true if introspection is enabled, false otherwise
138
- */
139
- isIntrospectionEnabled(): boolean;
140
-
141
- /**
142
- * Get the current complexity limit if set
143
- *
144
- * @returns The complexity limit, or null if unlimited
145
- */
146
- getComplexityLimit(): number | null;
147
-
148
- /**
149
- * Get the current depth limit if set
150
- *
151
- * @returns The depth limit, or null if unlimited
152
- */
153
- getDepthLimit(): number | null;
154
-
155
- /**
156
- * Build and return the schema configuration
157
- *
158
- * This method finalizes the configuration and returns a SchemaConfig object
159
- * that can be serialized and passed to the GraphQL execution engine.
160
- *
161
- * @returns A SchemaConfig instance with the configured settings
162
- *
163
- * @example
164
- * const builder = new GraphQLSchemaBuilder();
165
- * builder.complexityLimit(5000);
166
- * const config = builder.finish();
167
- * // config is now {
168
- * // introspectionEnabled: true,
169
- * // complexityLimit: 5000,
170
- * // depthLimit: undefined
171
- * // }
172
- */
173
- finish(): SchemaConfig;
174
-
175
- /**
176
- * Convert the schema configuration to a JSON object
177
- *
178
- * This method serializes the current builder state to a JSON Value
179
- * for transmission to the Rust execution engine or storage.
180
- * Zero-copy serialization is used where possible.
181
- *
182
- * @returns A JSON representation of the schema configuration
183
- *
184
- * @example
185
- * const builder = new GraphQLSchemaBuilder();
186
- * builder.complexityLimit(5000);
187
- * const json = builder.to_json();
188
- * console.log(JSON.stringify(json, null, 2));
189
- */
190
- to_json(): Record<string, any>;
191
- }
192
-
193
- /**
194
- * GraphQL Utilities and Factory Functions
195
- *
196
- * Provides factory methods for creating schema builders and configurations
197
- * with common patterns. All factory methods follow the same configuration
198
- * semantics as the SchemaBuilder.
199
- *
200
- * @class GraphQL
201
- *
202
- * @example
203
- * const builder = GraphQL.schemaBuilder();
204
- * const config = GraphQL.defaultSchemaConfig();
205
- * const queryConfig = GraphQL.queryOnlyConfig();
206
- */
207
- export class GraphQL {
208
- /**
209
- * Create a new GraphQL schema builder
210
- *
211
- * Returns a builder instance that can be configured with various settings.
212
- * The builder uses fluent API with mutation methods (returns void).
213
- *
214
- * @static
215
- * @returns A new GraphQLSchemaBuilder instance with default settings
216
- *
217
- * @example
218
- * const builder = GraphQL.schemaBuilder()
219
- * .enableIntrospection(true)
220
- * .complexityLimit(5000)
221
- * .depthLimit(50);
222
- */
223
- static schemaBuilder(): GraphQLSchemaBuilder;
224
-
225
- /**
226
- * Create a default schema configuration
227
- *
228
- * Returns a configuration with default settings:
229
- * - Introspection enabled
230
- * - No complexity limit
231
- * - No depth limit
232
- *
233
- * @static
234
- * @returns A SchemaConfig with default settings
235
- *
236
- * @example
237
- * const config = GraphQL.defaultSchemaConfig();
238
- * console.log(config.introspectionEnabled); // true
239
- */
240
- static defaultSchemaConfig(): SchemaConfig;
241
-
242
- /**
243
- * Create a schema configuration for query-only schemas
244
- *
245
- * Returns a configuration suitable for schemas without mutations or
246
- * subscriptions. Useful for read-only APIs.
247
- *
248
- * @static
249
- * @returns A SchemaConfig optimized for query-only schemas
250
- *
251
- * @example
252
- * const config = GraphQL.queryOnlyConfig();
253
- * // Use this for read-only GraphQL endpoints
254
- */
255
- static queryOnlyConfig(): SchemaConfig;
256
-
257
- /**
258
- * Create a schema configuration for query and mutation schemas
259
- *
260
- * Returns a configuration suitable for schemas with queries and mutations
261
- * but no subscriptions. This is the most common pattern for REST-like
262
- * GraphQL APIs.
263
- *
264
- * @static
265
- * @returns A SchemaConfig optimized for query and mutation schemas
266
- *
267
- * @example
268
- * const config = GraphQL.queryMutationConfig();
269
- * // Use this for typical CRUD GraphQL endpoints
270
- */
271
- static queryMutationConfig(): SchemaConfig;
272
-
273
- /**
274
- * Create a full schema configuration
275
- *
276
- * Returns a configuration suitable for schemas with queries, mutations,
277
- * and subscriptions. Use this for real-time GraphQL APIs.
278
- *
279
- * @static
280
- * @returns A SchemaConfig optimized for full-featured schemas
281
- *
282
- * @example
283
- * const config = GraphQL.fullSchemaConfig();
284
- * // Use this for real-time GraphQL APIs with subscriptions
285
- */
286
- static fullSchemaConfig(): SchemaConfig;
287
- }