yinzerflow 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. package/YinzerFlow.d.ts +96 -28
  2. package/package.json +3 -3
package/YinzerFlow.d.ts CHANGED
@@ -1,9 +1,13 @@
1
- type CreateEnum<T> = T[keyof T];
2
- type DeepPartial<T> = {
1
+ export type CreateEnum<T> = T[keyof T];
2
+ /**
3
+ * Utility type for deep partial - makes all properties optional recursively
4
+ * Used internally to create public configuration types from internal shapes
5
+ */
6
+ export type DeepPartial<T> = {
3
7
  [P in keyof T]?: T[P] extends object ? T[P] extends Array<infer U> ? Array<U> // Keep arrays as-is, don't make array items partial
4
8
  : DeepPartial<T[P]> : T[P];
5
9
  };
6
- interface InternalHandlerCallbackGenerics {
10
+ export interface InternalHandlerCallbackGenerics {
7
11
  body: unknown;
8
12
  response: unknown;
9
13
  query: Record<string, string>;
@@ -122,9 +126,9 @@ declare const httpHeaders: {
122
126
  readonly clearSiteData: "Clear-Site-Data";
123
127
  readonly noVarySearch: "No-Vary-Search";
124
128
  };
125
- type InternalHttpStatusCode = CreateEnum<typeof httpStatusCode>;
126
- type InternalHttpMethod = CreateEnum<typeof httpMethod>;
127
- type InternalHttpHeaders = Lowercase<CreateEnum<typeof httpHeaders>> | string;
129
+ export type InternalHttpStatusCode = CreateEnum<typeof httpStatusCode>;
130
+ export type InternalHttpMethod = CreateEnum<typeof httpMethod>;
131
+ export type InternalHttpHeaders = Lowercase<CreateEnum<typeof httpHeaders>> | string;
128
132
  interface Request$1<T = InternalHandlerCallbackGenerics> {
129
133
  protocol: string;
130
134
  method: InternalHttpMethod;
@@ -141,17 +145,27 @@ interface Response$1 {
141
145
  addHeaders: (headers: Partial<Record<InternalHttpHeaders, string>>) => void;
142
146
  removeHeaders: (headerNames: Array<InternalHttpHeaders>) => void;
143
147
  }
144
- interface Context {
148
+ export interface Context {
145
149
  request: Request$1;
146
150
  response: Response$1;
147
151
  }
148
- type HandlerCallback<T = InternalHandlerCallbackGenerics> = (ctx: Context) => Promise<T["response"] | void> | T["response"] | void;
149
- type InternalGlobalHookOptions = {
152
+ /**
153
+ * Represents a route handler function that returns a response body
154
+ *
155
+ * This type defines the signature for route handlers that process requests
156
+ * and return a response. The function can return either a promise that resolves
157
+ * to a response body or a response body directly.
158
+ *
159
+ * @param ctx - The request context containing request and response objects
160
+ * @returns A response body or a promise that resolves to a response body
161
+ */
162
+ export type HandlerCallback<T = InternalHandlerCallbackGenerics> = (ctx: Context) => Promise<T["response"] | void> | T["response"] | void;
163
+ export type InternalGlobalHookOptions = {
150
164
  routesToExclude: Array<string>;
151
165
  } & {
152
166
  routesToInclude: Array<string>;
153
167
  };
154
- interface InternalHookRegistryImpl {
168
+ export interface InternalHookRegistryImpl {
155
169
  readonly _beforeAll: Set<{
156
170
  handler: HandlerCallback;
157
171
  options?: InternalGlobalHookOptions;
@@ -167,17 +181,17 @@ interface InternalHookRegistryImpl {
167
181
  _addOnError: (handler: HandlerCallback) => void;
168
182
  _addOnNotFound: (handler: HandlerCallback) => void;
169
183
  }
170
- interface InternalRouteRegistryImpl {
184
+ export interface InternalRouteRegistryImpl {
171
185
  readonly _exactRoutes: Map<InternalHttpMethod, Map<string, InternalRouteRegistry>>;
172
186
  readonly _parameterizedRoutes: Map<InternalHttpMethod, Array<InternalPreCompiledRoute>>;
173
187
  _register: (route: InternalRouteRegistry) => void;
174
188
  _findRoute: (method: InternalHttpMethod, path: string) => InternalRouteRegistry | undefined;
175
189
  }
176
- interface InternalRouteRegistryOptions {
190
+ export interface InternalRouteRegistryOptions {
177
191
  beforeHooks: Array<HandlerCallback>;
178
192
  afterHooks: Array<HandlerCallback>;
179
193
  }
180
- interface InternalRouteRegistry {
194
+ export interface InternalRouteRegistry {
181
195
  prefix?: string;
182
196
  path: string;
183
197
  method: InternalHttpMethod;
@@ -185,7 +199,19 @@ interface InternalRouteRegistry {
185
199
  options: InternalRouteRegistryOptions;
186
200
  params: Record<string, string>;
187
201
  }
188
- interface InternalPreCompiledRoute extends InternalRouteRegistry {
202
+ /**
203
+ * Pre-compiled route with regex pattern for efficient runtime matching
204
+ *
205
+ * We compile route patterns into regexes at registration time (server startup)
206
+ * rather than at request time for performance reasons:
207
+ * - Registration: O(1) one-time cost per route
208
+ * - Runtime: O(1) for exact routes, O(n) for parameterized routes with pre-compiled regex
209
+ *
210
+ * Example: "/users/:id/posts/:postId" becomes:
211
+ * - pattern: /^\/users\/([^\/]+)\/posts\/([^\/]+)$/
212
+ * - paramNames: ["id", "postId"]
213
+ */
214
+ export interface InternalPreCompiledRoute extends InternalRouteRegistry {
189
215
  pattern: RegExp;
190
216
  paramNames: Array<string>;
191
217
  isParameterized: boolean;
@@ -195,14 +221,25 @@ declare const logLevels: {
195
221
  readonly verbose: "verbose";
196
222
  readonly network: "network";
197
223
  };
198
- type InternalCorsConfiguration = InternalCorsDisabledConfiguration | InternalCorsEnabledConfiguration;
199
- interface InternalCorsDisabledConfiguration {
224
+ /**
225
+ * Internal CORS Configuration Options
226
+ * Provides fine-grained control over Cross-Origin Resource Sharing
227
+ */
228
+ export type InternalCorsConfiguration = InternalCorsDisabledConfiguration | InternalCorsEnabledConfiguration;
229
+ /**
230
+ * Internal CORS Disabled Configuration
231
+ */
232
+ export interface InternalCorsDisabledConfiguration {
200
233
  /**
201
234
  * Disable CORS handling
202
235
  */
203
236
  enabled: false;
204
237
  }
205
- interface InternalCorsEnabledConfiguration {
238
+ /**
239
+ * Internal CORS Enabled Configuration
240
+ * When CORS is enabled, origin is required
241
+ */
242
+ export interface InternalCorsEnabledConfiguration {
206
243
  /**
207
244
  * Enable CORS handling
208
245
  */
@@ -257,7 +294,10 @@ interface InternalCorsEnabledConfiguration {
257
294
  */
258
295
  optionsSuccessStatus: InternalHttpStatusCode;
259
296
  }
260
- interface InternalConnectionOptions {
297
+ /**
298
+ * Internal Connection Options
299
+ */
300
+ export interface InternalConnectionOptions {
261
301
  /**
262
302
  * Default socket timeout in milliseconds (30 seconds)
263
303
  *
@@ -293,7 +333,11 @@ interface InternalConnectionOptions {
293
333
  */
294
334
  headersTimeout: number;
295
335
  }
296
- interface InternalBodyParserConfiguration {
336
+ /**
337
+ * Internal Body Parser Security Configuration
338
+ * Protects against DoS attacks, prototype pollution, and memory exhaustion
339
+ */
340
+ export interface InternalBodyParserConfiguration {
297
341
  /**
298
342
  * JSON parsing security configuration
299
343
  */
@@ -307,7 +351,11 @@ interface InternalBodyParserConfiguration {
307
351
  */
308
352
  urlEncoded: InternalUrlEncodedConfiguration;
309
353
  }
310
- interface InternalJsonParserConfiguration {
354
+ /**
355
+ * Internal JSON Parser Security Configuration
356
+ * Protects against JSON-specific attacks like prototype pollution and DoS
357
+ */
358
+ export interface InternalJsonParserConfiguration {
311
359
  /**
312
360
  * Maximum JSON request body size in bytes
313
361
  * @default 262144 (256KB) - reasonable for API payloads
@@ -345,7 +393,10 @@ interface InternalJsonParserConfiguration {
345
393
  */
346
394
  maxArrayLength: number;
347
395
  }
348
- interface InternalFileUploadConfiguration {
396
+ /**
397
+ * Internal File Upload Security Configuration
398
+ */
399
+ export interface InternalFileUploadConfiguration {
349
400
  /**
350
401
  * Maximum size per file in bytes
351
402
  * @default 10485760 (10MB) - reasonable for documents/images
@@ -382,7 +433,10 @@ interface InternalFileUploadConfiguration {
382
433
  */
383
434
  maxFilenameLength: number;
384
435
  }
385
- interface InternalUrlEncodedConfiguration {
436
+ /**
437
+ * Internal URL-encoded Configuration
438
+ */
439
+ export interface InternalUrlEncodedConfiguration {
386
440
  /**
387
441
  * Maximum URL-encoded form data size in bytes
388
442
  * @default 1048576 (1MB)
@@ -408,7 +462,10 @@ interface InternalUrlEncodedConfiguration {
408
462
  */
409
463
  maxFieldLength: number;
410
464
  }
411
- interface InternalIpValidationConfig {
465
+ /**
466
+ * Internal IP Security Configuration
467
+ */
468
+ export interface InternalIpValidationConfig {
412
469
  /**
413
470
  * List of trusted proxy IP addresses that are allowed to set forwarded headers
414
471
  * Only these IPs can provide X-Forwarded-For and similar headers
@@ -445,7 +502,12 @@ interface InternalIpValidationConfig {
445
502
  */
446
503
  detectSpoofing: boolean;
447
504
  }
448
- interface InternalServerConfiguration {
505
+ /**
506
+ * Complete internal server configuration shape - single source of truth
507
+ * This defines ALL possible configuration options with their required types
508
+ * Used as the foundation for both internal (complete) and public (partial) configurations
509
+ */
510
+ export interface InternalServerConfiguration {
449
511
  /**
450
512
  * Port number for the server to listen on
451
513
  * @default 5000
@@ -481,7 +543,7 @@ interface InternalServerConfiguration {
481
543
  */
482
544
  connectionOptions: InternalConnectionOptions;
483
545
  }
484
- interface Setup {
546
+ export interface Setup {
485
547
  get: InternalSetupMethod;
486
548
  post: InternalSetupMethod;
487
549
  put: InternalSetupMethod;
@@ -494,8 +556,8 @@ interface Setup {
494
556
  onError: (handler: HandlerCallback) => void;
495
557
  onNotFound: (handler: HandlerCallback) => void;
496
558
  }
497
- type InternalSetupMethod = (path: string, handler: HandlerCallback, options?: InternalRouteRegistryOptions) => void;
498
- interface InternalSetupImpl extends Setup {
559
+ export type InternalSetupMethod = (path: string, handler: HandlerCallback, options?: InternalRouteRegistryOptions) => void;
560
+ export interface InternalSetupImpl extends Setup {
499
561
  readonly _configuration: InternalServerConfiguration;
500
562
  readonly _routeRegistry: InternalRouteRegistryImpl;
501
563
  readonly _hooks: InternalHookRegistryImpl;
@@ -517,7 +579,13 @@ declare class HookRegistryImpl implements InternalHookRegistryImpl {
517
579
  _addOnError(handler: HandlerCallback): void;
518
580
  _addOnNotFound(handler: HandlerCallback): void;
519
581
  }
520
- type ServerConfiguration = DeepPartial<InternalServerConfiguration>;
582
+ /**
583
+ * User-facing configuration interface where all properties are optional
584
+ * Users only need to specify what they want to override from defaults
585
+ *
586
+ * This is created by making the complete internal ServerConfigurationShape partially optional
587
+ */
588
+ export type ServerConfiguration = DeepPartial<InternalServerConfiguration>;
521
589
  declare class RouteRegistryImpl implements InternalRouteRegistryImpl {
522
590
  readonly _exactRoutes: Map<InternalHttpMethod, Map<string, InternalRouteRegistry>>;
523
591
  readonly _parameterizedRoutes: Map<InternalHttpMethod, InternalPreCompiledRoute[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yinzerflow",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "author": "Patrick Rizzardi <patrick@redact.digital> (https://redact.digital)",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/yinzers/YinzerFlow.git",
@@ -22,8 +22,8 @@
22
22
  "bun",
23
23
  "yinzerflow"
24
24
  ],
25
- "types": "lib/YinzerFlow.d.ts",
26
- "main": "lib/YinzerFlow.js",
25
+ "types": "YinzerFlow.d.ts",
26
+ "main": "YinzerFlow.js",
27
27
  "type": "module",
28
28
  "scripts": {
29
29
  "test": "bun test --watch --coverage",