@danylohotvianskyi/bobra-framework 0.1.9 → 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 (102) hide show
  1. package/batteries/auth/hash.ts +102 -36
  2. package/batteries/auth/token-metadata.ts +25 -8
  3. package/batteries/auth/token.ts +5 -5
  4. package/batteries/openapi/index.ts +62 -41
  5. package/batteries/openapi/merge-openapi.ts +125 -33
  6. package/core/config.ts +40 -14
  7. package/core/discovery.ts +16 -10
  8. package/core/env-resolver.ts +25 -11
  9. package/core/factory.ts +150 -77
  10. package/core/spa.ts +14 -8
  11. package/db/client.ts +80 -415
  12. package/db/drizzle-clients.ts +65 -0
  13. package/db/failover.ts +318 -0
  14. package/db/index.ts +1 -0
  15. package/db/migrate.ts +7 -6
  16. package/db/pgedge.ts +307 -0
  17. package/db/test/client.test.ts +346 -0
  18. package/db/token-auth.ts +40 -0
  19. package/db/types.ts +96 -0
  20. package/dist/batteries/auth/hash.d.ts +10 -2
  21. package/dist/batteries/auth/hash.js +78 -43
  22. package/dist/batteries/auth/hash.js.map +1 -1
  23. package/dist/batteries/auth/token-metadata.d.ts +3 -3
  24. package/dist/batteries/auth/token-metadata.js +14 -6
  25. package/dist/batteries/auth/token-metadata.js.map +1 -1
  26. package/dist/batteries/auth/token.d.ts +3 -3
  27. package/dist/batteries/auth/token.js +2 -2
  28. package/dist/batteries/auth/token.js.map +1 -1
  29. package/dist/batteries/openapi/index.d.ts +51 -13
  30. package/dist/batteries/openapi/index.js +25 -15
  31. package/dist/batteries/openapi/index.js.map +1 -1
  32. package/dist/batteries/openapi/merge-openapi.d.ts +26 -2
  33. package/dist/batteries/openapi/merge-openapi.js +83 -26
  34. package/dist/batteries/openapi/merge-openapi.js.map +1 -1
  35. package/dist/core/config.d.ts +26 -9
  36. package/dist/core/config.js +8 -7
  37. package/dist/core/config.js.map +1 -1
  38. package/dist/core/discovery.d.ts +18 -9
  39. package/dist/core/discovery.js +1 -1
  40. package/dist/core/discovery.js.map +1 -1
  41. package/dist/core/env-resolver.d.ts +7 -4
  42. package/dist/core/env-resolver.js +7 -5
  43. package/dist/core/env-resolver.js.map +1 -1
  44. package/dist/core/factory.d.ts +36 -16
  45. package/dist/core/factory.js +70 -38
  46. package/dist/core/factory.js.map +1 -1
  47. package/dist/core/spa.js +9 -4
  48. package/dist/core/spa.js.map +1 -1
  49. package/dist/db/client.d.ts +16 -66
  50. package/dist/db/client.js +40 -311
  51. package/dist/db/client.js.map +1 -1
  52. package/dist/db/drizzle-clients.d.ts +6 -0
  53. package/dist/db/drizzle-clients.js +42 -0
  54. package/dist/db/drizzle-clients.js.map +1 -0
  55. package/dist/db/failover.d.ts +39 -0
  56. package/dist/db/failover.js +267 -0
  57. package/dist/db/failover.js.map +1 -0
  58. package/dist/db/index.d.ts +1 -0
  59. package/dist/db/index.js +1 -0
  60. package/dist/db/index.js.map +1 -1
  61. package/dist/db/migrate.js +4 -4
  62. package/dist/db/migrate.js.map +1 -1
  63. package/dist/db/pgedge.d.ts +14 -0
  64. package/dist/db/pgedge.js +218 -0
  65. package/dist/db/pgedge.js.map +1 -0
  66. package/dist/db/token-auth.d.ts +34 -0
  67. package/dist/db/token-auth.js +15 -0
  68. package/dist/db/token-auth.js.map +1 -0
  69. package/dist/db/types.d.ts +82 -0
  70. package/dist/db/types.js +2 -0
  71. package/dist/db/types.js.map +1 -0
  72. package/dist/logging/logger.d.ts +13 -13
  73. package/dist/logging/logger.js +11 -2
  74. package/dist/logging/logger.js.map +1 -1
  75. package/dist/logging/logging-middleware.d.ts +1 -1
  76. package/dist/logging/logging-middleware.js +6 -6
  77. package/dist/logging/logging-middleware.js.map +1 -1
  78. package/dist/middleware/ensure-api-token.d.ts +33 -4
  79. package/dist/middleware/ensure-api-token.js.map +1 -1
  80. package/dist/middleware/utils.d.ts +5 -1
  81. package/dist/middleware/utils.js +11 -7
  82. package/dist/middleware/utils.js.map +1 -1
  83. package/dist/network/router.d.ts +9 -6
  84. package/dist/network/router.js +3 -1
  85. package/dist/network/router.js.map +1 -1
  86. package/dist/network/service-discovery.d.ts +1 -1
  87. package/dist/network/service-discovery.js.map +1 -1
  88. package/dist/network/service-fetch.d.ts +6 -9
  89. package/dist/network/service-fetch.js +14 -4
  90. package/dist/network/service-fetch.js.map +1 -1
  91. package/dist/node/generate-wrangler-config.d.ts +28 -4
  92. package/dist/node/generate-wrangler-config.js +75 -20
  93. package/dist/node/generate-wrangler-config.js.map +1 -1
  94. package/logging/logger.ts +31 -21
  95. package/logging/logging-middleware.ts +12 -9
  96. package/middleware/ensure-api-token.ts +8 -6
  97. package/middleware/utils.ts +26 -8
  98. package/network/router.ts +17 -13
  99. package/network/service-discovery.ts +1 -1
  100. package/network/service-fetch.ts +26 -17
  101. package/node/generate-wrangler-config.ts +160 -24
  102. package/package.json +10 -7
package/core/factory.ts CHANGED
@@ -17,18 +17,55 @@ import {
17
17
  } from './config';
18
18
  import { serviceDiscoveryMiddleware } from '../network/service-discovery';
19
19
  import { generateSpecs } from 'hono-openapi';
20
+ import type { OpenAPIV3 } from 'openapi-types';
21
+ import type { MessageBatch, ExecutionContext, ScheduledController } from '@cloudflare/workers-types';
22
+
23
+ const OPENAPI_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const;
24
+ type OpenApiMethod = typeof OPENAPI_METHODS[number];
25
+ type HonoBindingsEnv = { Bindings: Record<string, unknown>; Variables?: Record<string, unknown> };
26
+
27
+ type JsonNode = string | number | boolean | null | JsonNode[] | { [key: string]: JsonNode };
28
+ type QueuePayload = Record<string, string | number | boolean | null>;
29
+ type QueueBatch = MessageBatch<QueuePayload>;
30
+ type WorkerExecutionCtx = ExecutionContext;
31
+ type ScheduledEvent = ScheduledController;
32
+ type SchemaMap = Record<string, OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject>;
33
+ type SecuritySchemeMap = Record<string, OpenAPIV3.SecuritySchemeObject | OpenAPIV3.ReferenceObject>;
34
+
35
+ interface RequestWithCf extends Request {
36
+ cf?: Record<string, unknown> & {
37
+ continent?: string;
38
+ };
39
+ }
40
+
41
+ function isJsonObject(node: JsonNode): node is { [key: string]: JsonNode } {
42
+ return typeof node === 'object' && node !== null && !Array.isArray(node);
43
+ }
44
+
45
+ function isPathItemObject(item: OpenAPIV3.PathItemObject | OpenAPIV3.ReferenceObject): item is OpenAPIV3.PathItemObject {
46
+ return !('$ref' in item);
47
+ }
48
+
49
+ function hasOperation(pathItem: OpenAPIV3.PathItemObject): boolean {
50
+ return OPENAPI_METHODS.some((method) => Boolean(pathItem[method]));
51
+ }
20
52
 
21
53
  // Helper: collect schema $ref names referenced anywhere in the OpenAPI spec
22
- function collectReferencedSchemaNames(obj: any): Set<string> {
54
+ function collectReferencedSchemaNames(obj: JsonNode): Set<string> {
23
55
  const set = new Set<string>();
24
- function scan(val: any) {
25
- if (typeof val === 'object' && val !== null) {
26
- for (const k in val) {
27
- if (k === '$ref' && typeof val[k] === 'string') {
28
- const m = val[k].match(/^#\/components\/schemas\/([A-Za-z0-9_.-]+)/);
56
+ function scan(val: JsonNode) {
57
+ if (Array.isArray(val)) {
58
+ for (const item of val) scan(item);
59
+ return;
60
+ }
61
+
62
+ if (isJsonObject(val)) {
63
+ for (const [k, value] of Object.entries(val)) {
64
+ if (k === '$ref' && typeof value === 'string') {
65
+ const m = value.match(/^#\/components\/schemas\/([A-Za-z0-9_.-]+)/);
29
66
  if (m && m[1]) set.add(m[1]);
30
67
  } else {
31
- scan(val[k]);
68
+ scan(value);
32
69
  }
33
70
  }
34
71
  }
@@ -37,19 +74,23 @@ function collectReferencedSchemaNames(obj: any): Set<string> {
37
74
  return set;
38
75
  }
39
76
 
40
- function pruneComponents(full: any, paths: any, keepAlways: string[] = []) {
41
- const result: any = { ...(full.components || {}) };
42
- const schemas = (full.components && full.components.schemas) || {};
77
+ function pruneComponents(
78
+ full: OpenAPIV3.Document,
79
+ paths: OpenAPIV3.PathsObject,
80
+ keepAlways: string[] = []
81
+ ): OpenAPIV3.ComponentsObject {
82
+ const result: OpenAPIV3.ComponentsObject = { ...(full.components || {}) };
83
+ const schemas = (full.components?.schemas || {}) as SchemaMap;
43
84
 
44
85
  // Start with schemas referenced directly from paths
45
- const refs = collectReferencedSchemaNames(paths);
86
+ const refs = collectReferencedSchemaNames(paths as JsonNode);
46
87
 
47
88
  // Always-keep schemas should be included in the starting set as well
48
89
  for (const name of keepAlways) {
49
90
  refs.add(name);
50
91
  }
51
92
 
52
- const kept: Record<string, any> = {};
93
+ const kept: SchemaMap = {};
53
94
 
54
95
  // Traverse schema references transitively using a work queue to ensure
55
96
  // nested dependencies are not pruned.
@@ -65,8 +106,8 @@ function pruneComponents(full: any, paths: any, keepAlways: string[] = []) {
65
106
  // Keep this schema
66
107
  kept[name] = schema;
67
108
 
68
- // Find any schemas it references and add them to the queue if not already seen
69
- const nestedRefs = collectReferencedSchemaNames(schema);
109
+ // Find referenced schemas and add them to the queue if not already seen
110
+ const nestedRefs = collectReferencedSchemaNames(schema as JsonNode);
70
111
  for (const dep of nestedRefs) {
71
112
  if (!refs.has(dep)) {
72
113
  refs.add(dep);
@@ -83,15 +124,15 @@ export interface OpenAPISpecOptions {
83
124
  /** The path where the OpenAPI spec will be served (e.g. '/openapi', '/internal/openapi') */
84
125
  path?: string;
85
126
  /** Return true to exclude an operation from the generated OpenAPI spec */
86
- excludeEndpoint?: (path: string, method: string, operation: any) => boolean;
87
- /** Exclude operations that have any of these tags (e.g. ['internal']) */
127
+ excludeEndpoint?: (path: string, method: OpenApiMethod, operation: OpenAPIV3.OperationObject) => boolean;
128
+ /** Exclude operations that have one of these tags (e.g. ['internal']) */
88
129
  excludeTags?: string[];
89
130
  /** Whether or not to prune unreferenced OpenAPI component schemas (defaults to true if exclusions are used) */
90
131
  pruneComponents?: boolean;
91
132
  /** An array of schema names to always keep in the OpenAPI spec if pruneComponents is true */
92
133
  pruneComponentsKeepAlways?: string[];
93
134
  /** Additional security schemes to add to the OpenAPI spec */
94
- securitySchemes?: Record<string, any>;
135
+ securitySchemes?: SecuritySchemeMap;
95
136
  }
96
137
 
97
138
  export interface WorkerOptions {
@@ -102,12 +143,14 @@ export interface WorkerOptions {
102
143
  export interface WorkerEnv {
103
144
  CONFIG_CONTENT?: string;
104
145
  WORKER_NAME?: string;
105
- [key: string]: any;
146
+ __cfContinent?: string;
147
+ // Bindings are deployment-specific and can include D1/KV/R2/DO namespaces.
148
+ [key: string]: unknown;
106
149
  }
107
150
 
108
151
  // Create a new worker instance with common middleware
109
152
  export async function createWorker(env?: WorkerEnv, options?: WorkerOptions): Promise<AppWorker> {
110
- const app = new Hono<{ Bindings: WorkerEnv }>();
153
+ const app = new Hono<HonoBindingsEnv>();
111
154
 
112
155
  const config = await loadConfig(env || {});
113
156
  validateConfig(config);
@@ -149,7 +192,7 @@ export async function createWorker(env?: WorkerEnv, options?: WorkerOptions): Pr
149
192
 
150
193
  // Worker-level OpenAPI with router base path prefixing
151
194
  (() => {
152
- const specApp = new Hono<{ Bindings: WorkerEnv }>();
195
+ const specApp = new Hono<HonoBindingsEnv>();
153
196
  const routerBase = getRouterBasePath(config);
154
197
  // Mount the worker app under router base path so generated paths include router base
155
198
  specApp.route(routerBase === '/' ? '/' : routerBase, app);
@@ -162,7 +205,7 @@ export async function createWorker(env?: WorkerEnv, options?: WorkerOptions): Pr
162
205
  description: config.server.description,
163
206
  },
164
207
  },
165
- } as any;
208
+ };
166
209
 
167
210
  const specDefs = options?.openapi
168
211
  ? (Array.isArray(options.openapi) ? options.openapi : [options.openapi])
@@ -171,32 +214,47 @@ export async function createWorker(env?: WorkerEnv, options?: WorkerOptions): Pr
171
214
  for (const specDef of specDefs) {
172
215
  const specPath = specDef.path || '/openapi';
173
216
  app.get(specPath, async (c) => {
174
- const full = await generateSpecs(specApp, specOptions, undefined, c);
217
+ const full = await generateSpecs(specApp, specOptions, undefined, c) as OpenAPIV3.Document;
175
218
  const { excludeEndpoint, excludeTags, pruneComponents: specPrune, securitySchemes } = specDef;
176
219
  const hasExclusions = !!excludeEndpoint || (!!excludeTags && excludeTags.length > 0);
177
220
 
178
221
  let finalSpec = full;
179
222
 
180
223
  if (hasExclusions) {
181
- const filtered: any = { ...full, paths: {} };
182
- for (const [path, ops] of Object.entries(full.paths || {})) {
183
- const keepOps: any = {};
184
- for (const [method, op] of Object.entries(ops as any)) {
224
+ const filtered: OpenAPIV3.Document = { ...full, paths: {} };
225
+ for (const [path, pathItemOrRef] of Object.entries(full.paths ?? {}) as Array<[string, OpenAPIV3.PathItemObject | OpenAPIV3.ReferenceObject]>) {
226
+ if (!pathItemOrRef) continue;
227
+
228
+ if (!isPathItemObject(pathItemOrRef)) {
229
+ filtered.paths[path] = pathItemOrRef;
230
+ continue;
231
+ }
232
+
233
+ const keepPathItem: OpenAPIV3.PathItemObject = { ...pathItemOrRef };
234
+
235
+ for (const method of OPENAPI_METHODS) {
236
+ const operation = pathItemOrRef[method];
237
+ if (!operation) continue;
238
+
185
239
  let shouldExclude = false;
186
- if (excludeEndpoint && excludeEndpoint(path, method, op)) {
240
+ if (excludeEndpoint && excludeEndpoint(path, method, operation)) {
187
241
  shouldExclude = true;
188
242
  }
189
- if (!shouldExclude && excludeTags && Array.isArray((op as any).tags)) {
190
- if ((op as any).tags.some((tag: string) => excludeTags.includes(tag))) {
243
+
244
+ if (!shouldExclude && excludeTags && Array.isArray(operation.tags)) {
245
+ if (operation.tags.some((tag: string) => excludeTags.includes(tag))) {
191
246
  shouldExclude = true;
192
247
  }
193
248
  }
194
249
 
195
- if (!shouldExclude) {
196
- keepOps[method] = op;
250
+ if (shouldExclude) {
251
+ delete keepPathItem[method];
197
252
  }
198
253
  }
199
- if (Object.keys(keepOps).length > 0) filtered.paths[path] = keepOps;
254
+
255
+ if (hasOperation(keepPathItem) || Boolean(keepPathItem.parameters?.length)) {
256
+ filtered.paths[path] = keepPathItem;
257
+ }
200
258
  }
201
259
 
202
260
  const shouldPrune = specPrune ?? true;
@@ -231,7 +289,7 @@ export async function createWorker(env?: WorkerEnv, options?: WorkerOptions): Pr
231
289
 
232
290
  // Core worker class that manages handlers and their lifecycle
233
291
  export class AppWorker {
234
- private app: Hono<{ Bindings: WorkerEnv }>;
292
+ private app: Hono<HonoBindingsEnv>;
235
293
  private handlers: AppHandler[] = [];
236
294
  private config: AppConfig;
237
295
  private workerName: string;
@@ -240,7 +298,7 @@ export class AppWorker {
240
298
  private initialized = false;
241
299
  private startupStack = new LogStack();
242
300
 
243
- constructor(app: Hono<{ Bindings: WorkerEnv }>, config: AppConfig, workerName: string, basePath: string, options?: WorkerOptions) {
301
+ constructor(app: Hono<HonoBindingsEnv>, config: AppConfig, workerName: string, basePath: string, options?: WorkerOptions) {
244
302
  this.app = app;
245
303
  this.config = config;
246
304
  this.workerName = workerName;
@@ -276,7 +334,7 @@ export class AppWorker {
276
334
 
277
335
  // Cloudflare Workers export a single queue() per worker, but a worker can consume multiple queues.
278
336
  // This dispatcher routes each batch to the correct handler based on batch.queue.
279
- getQueueFunction(): ((batch: any, env: WorkerEnv, ctx: any) => Promise<void>) | undefined {
337
+ getQueueFunction(): ((batch: QueueBatch, env: WorkerEnv, ctx: WorkerExecutionCtx) => Promise<void>) | undefined {
280
338
  const queueHandlers = this.handlers.filter(h => typeof h.queue === 'function');
281
339
 
282
340
  if (queueHandlers.length === 0) {
@@ -292,15 +350,17 @@ export class AppWorker {
292
350
  getLogger().warn(`Multiple handlers with queue() found but none declare handlesQueue(). Using first one: ${queueHandlers[0]!.name}`);
293
351
  }
294
352
 
295
- return async (batch: any, env: WorkerEnv, ctx: any) => {
353
+ return async (batch: QueueBatch, env: WorkerEnv, ctx: WorkerExecutionCtx) => {
296
354
  await this.initialize(env);
297
355
 
298
356
  // Build configured queue name list from config for this worker
299
357
  let configuredQueues: string[] = [];
300
358
  try {
301
- const bindings = getWorkerQueueBindings(this.config, this.workerName) || {} as any;
359
+ const bindings = getWorkerQueueBindings(this.config, this.workerName);
302
360
  const consumers = bindings.consumers ?? [];
303
- configuredQueues = consumers.map((c: any) => c?.queue).filter(Boolean) as string[];
361
+ configuredQueues = consumers
362
+ .map((consumer) => consumer.queue)
363
+ .filter((queueName): queueName is string => typeof queueName === 'string' && queueName.length > 0);
304
364
  } catch { }
305
365
 
306
366
  // Try matcher-based dispatch
@@ -366,14 +426,14 @@ export class AppWorker {
366
426
  };
367
427
  }
368
428
 
369
- getScheduledFunction(): ((event: any, env: WorkerEnv, ctx: any) => Promise<void>) | undefined {
429
+ getScheduledFunction(): ((event: ScheduledEvent, env: WorkerEnv, ctx: WorkerExecutionCtx) => Promise<void>) | undefined {
370
430
  const scheduledHandlers = this.handlers.filter(h => typeof h.scheduled === 'function');
371
431
 
372
432
  if (scheduledHandlers.length === 0) {
373
433
  return undefined;
374
434
  }
375
435
 
376
- return async (event: any, env: WorkerEnv, ctx: any) => {
436
+ return async (event: ScheduledEvent, env: WorkerEnv, ctx: WorkerExecutionCtx) => {
377
437
  await this.initialize(env);
378
438
 
379
439
  const promises = scheduledHandlers.map(async (handler) => {
@@ -431,20 +491,13 @@ export class AppWorker {
431
491
 
432
492
  if (handler.name !== 'api-docs') {
433
493
  (() => {
434
- const specApp = new Hono<{ Bindings: WorkerEnv }>();
494
+ const specApp = new Hono<HonoBindingsEnv>();
435
495
  const routerBase = getRouterBasePath(this.config);
436
496
  const prefix = routerBase === '/' ? handlerPath : `${routerBase}${handlerPath}`;
437
497
  specApp.route(prefix, handler.routes);
438
498
 
439
- let componentSchemas = {};
440
- if (handler.componentSchemas) {
441
- componentSchemas = handler.componentSchemas;
442
- }
443
-
444
- let handlerSecuritySchemes = {};
445
- if (handler.securitySchemes) {
446
- handlerSecuritySchemes = handler.securitySchemes;
447
- }
499
+ const componentSchemas = (handler.componentSchemas || {}) as SchemaMap;
500
+ const handlerSecuritySchemes = (handler.securitySchemes || {}) as SecuritySchemeMap;
448
501
 
449
502
  const specOptions = {
450
503
  documentation: {
@@ -458,7 +511,7 @@ export class AppWorker {
458
511
  securitySchemes: handlerSecuritySchemes,
459
512
  },
460
513
  },
461
- } as any;
514
+ };
462
515
 
463
516
  const specDefs = this.options?.openapi
464
517
  ? (Array.isArray(this.options.openapi) ? this.options.openapi : [this.options.openapi])
@@ -467,32 +520,47 @@ export class AppWorker {
467
520
  for (const specDef of specDefs) {
468
521
  const specPath = specDef.path || '/openapi';
469
522
  this.app.get(`${handlerPath}${specPath}`, async (c) => {
470
- const full = await generateSpecs(specApp, specOptions, undefined, c);
523
+ const full = await generateSpecs(specApp, specOptions, undefined, c) as OpenAPIV3.Document;
471
524
  const { excludeEndpoint, excludeTags, pruneComponents: specPrune, securitySchemes } = specDef;
472
525
  const hasExclusions = !!excludeEndpoint || (!!excludeTags && excludeTags.length > 0);
473
526
 
474
527
  let finalSpec = full;
475
528
 
476
529
  if (hasExclusions) {
477
- const filtered: any = { ...full, paths: {} };
478
- for (const [path, ops] of Object.entries(full.paths || {})) {
479
- const keepOps: any = {};
480
- for (const [method, op] of Object.entries(ops as any)) {
530
+ const filtered: OpenAPIV3.Document = { ...full, paths: {} };
531
+ for (const [path, pathItemOrRef] of Object.entries(full.paths ?? {}) as Array<[string, OpenAPIV3.PathItemObject | OpenAPIV3.ReferenceObject]>) {
532
+ if (!pathItemOrRef) continue;
533
+
534
+ if (!isPathItemObject(pathItemOrRef)) {
535
+ filtered.paths[path] = pathItemOrRef;
536
+ continue;
537
+ }
538
+
539
+ const keepPathItem: OpenAPIV3.PathItemObject = { ...pathItemOrRef };
540
+
541
+ for (const method of OPENAPI_METHODS) {
542
+ const operation = pathItemOrRef[method];
543
+ if (!operation) continue;
544
+
481
545
  let shouldExclude = false;
482
- if (excludeEndpoint && excludeEndpoint(path, method, op)) {
546
+ if (excludeEndpoint && excludeEndpoint(path, method, operation)) {
483
547
  shouldExclude = true;
484
548
  }
485
- if (!shouldExclude && excludeTags && Array.isArray((op as any).tags)) {
486
- if ((op as any).tags.some((tag: string) => excludeTags.includes(tag))) {
549
+
550
+ if (!shouldExclude && excludeTags && Array.isArray(operation.tags)) {
551
+ if (operation.tags.some((tag: string) => excludeTags.includes(tag))) {
487
552
  shouldExclude = true;
488
553
  }
489
554
  }
490
555
 
491
- if (!shouldExclude) {
492
- keepOps[method] = op;
556
+ if (shouldExclude) {
557
+ delete keepPathItem[method];
493
558
  }
494
559
  }
495
- if (Object.keys(keepOps).length > 0) filtered.paths[path] = keepOps;
560
+
561
+ if (hasOperation(keepPathItem) || Boolean(keepPathItem.parameters?.length)) {
562
+ filtered.paths[path] = keepPathItem;
563
+ }
496
564
  }
497
565
 
498
566
  const shouldPrune = specPrune ?? true;
@@ -586,7 +654,7 @@ export class AppWorker {
586
654
  }
587
655
  }
588
656
 
589
- getApp(): Hono<{ Bindings: WorkerEnv }> {
657
+ getApp(): Hono<HonoBindingsEnv> {
590
658
  return this.app;
591
659
  }
592
660
 
@@ -596,18 +664,22 @@ export class AppWorker {
596
664
  const queueFunction = this.getQueueFunction();
597
665
  const scheduledFunction = this.getScheduledFunction();
598
666
 
599
- const workerExport: any = {
600
- async fetch(request: any, env: WorkerEnv, ctx: any) {
667
+ const workerExport: {
668
+ fetch: (request: RequestWithCf, env: WorkerEnv, ctx: WorkerExecutionCtx) => Promise<Response>;
669
+ queue?: (batch: QueueBatch, env: WorkerEnv, ctx: WorkerExecutionCtx) => Promise<void>;
670
+ scheduled?: (event: ScheduledEvent, env: WorkerEnv, ctx: WorkerExecutionCtx) => Promise<void>;
671
+ } = {
672
+ async fetch(request: RequestWithCf, env: WorkerEnv, ctx: WorkerExecutionCtx) {
601
673
  try {
602
674
  // Merge global and worker-specific vars into env
603
- const globalVars = (self.config as any).vars || {};
675
+ const globalVars = self.config.vars || {};
604
676
  const workerVars = (self.config.workers?.[self.workerName]?.vars) || {};
605
677
  const mergedEnv = { ...env, ...globalVars, ...workerVars } as WorkerEnv;
606
678
 
607
679
  // Inject CF location for pgEdge geo-routing
608
680
  // Header takes priority: request.cf reflects the worker's colo, not the original client
609
- const cfContinent = request.headers?.get?.('X-CF-Continent') || (request as any).cf?.continent;
610
- if (cfContinent) (mergedEnv as any).__cfContinent = cfContinent;
681
+ const cfContinent = request.headers?.get?.('X-CF-Continent') || request.cf?.continent;
682
+ if (cfContinent) mergedEnv.__cfContinent = cfContinent;
611
683
 
612
684
  await self.initialize(mergedEnv);
613
685
  return await self.app.fetch(request, mergedEnv, ctx);
@@ -628,8 +700,8 @@ export class AppWorker {
628
700
  };
629
701
 
630
702
  if (queueFunction) {
631
- workerExport.queue = async (batch: any, env: WorkerEnv, ctx: any) => {
632
- const globalVars = (self.config as any).vars || {};
703
+ workerExport.queue = async (batch: QueueBatch, env: WorkerEnv, ctx: WorkerExecutionCtx) => {
704
+ const globalVars = self.config.vars || {};
633
705
  const workerVars = (self.config.workers?.[self.workerName]?.vars) || {};
634
706
  const mergedEnv = { ...env, ...globalVars, ...workerVars } as WorkerEnv;
635
707
  await queueFunction(batch, mergedEnv, ctx);
@@ -637,8 +709,8 @@ export class AppWorker {
637
709
  }
638
710
 
639
711
  if (scheduledFunction) {
640
- workerExport.scheduled = async (event: any, env: WorkerEnv, ctx: any) => {
641
- const globalVars = (self.config as any).vars || {};
712
+ workerExport.scheduled = async (event: ScheduledEvent, env: WorkerEnv, ctx: WorkerExecutionCtx) => {
713
+ const globalVars = self.config.vars || {};
642
714
  const workerVars = (self.config.workers?.[self.workerName]?.vars) || {};
643
715
  const mergedEnv = { ...env, ...globalVars, ...workerVars } as WorkerEnv;
644
716
  await scheduledFunction(event, mergedEnv, ctx);
@@ -661,7 +733,7 @@ export function createCloudflareWorker(
661
733
  options?: WorkerOptions
662
734
  ) {
663
735
  return {
664
- async fetch(request: Request, env: WorkerEnv, ctx: any): Promise<Response> {
736
+ async fetch(request: Request, env: WorkerEnv, ctx: WorkerExecutionCtx): Promise<Response> {
665
737
  try {
666
738
  const workerEnv = {
667
739
  ...env,
@@ -670,8 +742,9 @@ export function createCloudflareWorker(
670
742
 
671
743
  // Inject CF location for pgEdge geo-routing
672
744
  // Header takes priority: request.cf reflects the worker's colo, not the original client
673
- const cfContinent = request.headers?.get?.('X-CF-Continent') || (request as any).cf?.continent;
674
- if (cfContinent) (workerEnv as any).__cfContinent = cfContinent;
745
+ const requestWithCf = request as RequestWithCf;
746
+ const cfContinent = request.headers?.get?.('X-CF-Continent') || requestWithCf.cf?.continent;
747
+ if (cfContinent) workerEnv.__cfContinent = cfContinent;
675
748
 
676
749
  const worker = await createWorker(workerEnv, options);
677
750
 
@@ -695,7 +768,7 @@ export function createCloudflareWorker(
695
768
  }
696
769
  },
697
770
 
698
- async queue(batch: any, env: WorkerEnv, ctx: any): Promise<void> {
771
+ async queue(batch: QueueBatch, env: WorkerEnv, ctx: WorkerExecutionCtx): Promise<void> {
699
772
  try {
700
773
  const workerEnv = {
701
774
  ...env,
@@ -723,7 +796,7 @@ export function createCloudflareWorker(
723
796
  }
724
797
  },
725
798
 
726
- async scheduled(event: any, env: WorkerEnv, ctx: any): Promise<void> {
799
+ async scheduled(event: ScheduledEvent, env: WorkerEnv, ctx: WorkerExecutionCtx): Promise<void> {
727
800
  try {
728
801
  const workerEnv = {
729
802
  ...env,
package/core/spa.ts CHANGED
@@ -2,9 +2,8 @@ import { Hono } from 'hono';
2
2
  import { getLogger, initializeLogger } from '../logging/logger';
3
3
  import type { AppHandler } from './discovery';
4
4
 
5
- // Basic environment type for SPA handler
6
- interface SpaEnv {
7
- [key: string]: any;
5
+ interface AssetBinding {
6
+ fetch(request: Request): Promise<Response>;
8
7
  }
9
8
 
10
9
  export interface SpaHandlerOptions {
@@ -44,19 +43,26 @@ export function createSpaHandler(options: SpaHandlerOptions): AppHandler {
44
43
  ignoreWorkerBasePath = false
45
44
  } = options;
46
45
 
47
- const app = new Hono<{ Bindings: SpaEnv }>();
46
+ const app = new Hono<{ Bindings: Record<string, unknown> }>();
48
47
 
49
48
  // Handle all requests under this handler's path
50
49
  app.all('*', async (c) => {
51
50
  const logger = getLogger();
52
51
  const url = new URL(c.req.url);
53
52
 
54
- const ASSETS = c.env[assetsBinding] as any;
55
- if (!ASSETS) {
53
+ const assetBindingValue = c.env[assetsBinding];
54
+ const hasFetch = typeof assetBindingValue === 'object'
55
+ && assetBindingValue !== null
56
+ && 'fetch' in assetBindingValue
57
+ && typeof (assetBindingValue as AssetBinding).fetch === 'function';
58
+
59
+ if (!hasFetch) {
56
60
  logger.error(`${assetsBinding} binding not available within SpaHandler '${name}'`);
57
61
  return c.text(`${assetsBinding} binding not available`, 503);
58
62
  }
59
63
 
64
+ const assets = assetBindingValue as AssetBinding;
65
+
60
66
  // Recursion guard: prevent infinite loops when ASSETS routes back to the handler
61
67
  if (c.req.header('X-Recursive-Fetch') === 'true') {
62
68
  return new Response(null, { status: 404 });
@@ -69,7 +75,7 @@ export function createSpaHandler(options: SpaHandlerOptions): AppHandler {
69
75
  const assetRequest = new Request(c.req.url, c.req.raw);
70
76
  assetRequest.headers.set('X-Recursive-Fetch', 'true');
71
77
 
72
- const response = await ASSETS.fetch(assetRequest);
78
+ const response = await assets.fetch(assetRequest);
73
79
 
74
80
  return response;
75
81
  }
@@ -86,7 +92,7 @@ export function createSpaHandler(options: SpaHandlerOptions): AppHandler {
86
92
  const indexRequest = new Request(indexUrl, c.req.raw);
87
93
  indexRequest.headers.set('X-Recursive-Fetch', 'true');
88
94
 
89
- const response = await ASSETS.fetch(indexRequest);
95
+ const response = await assets.fetch(indexRequest);
90
96
 
91
97
  if (response.status !== 200) {
92
98
  logger.error(`[SpaHandler:${name}] Failed to fetch ${indexPath}. Status: ${response.status}`);