k99 0.7.1 → 0.9.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/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /*!
2
- * k99 v0.7.1
3
- * (c) 2019-2025 猛火Fierflame
2
+ * k99 v0.9.0
3
+ * (c) 2019-2026 猛火Fierflame
4
4
  * @license MIT
5
5
  */
6
- type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS';
6
+ type Method = string | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS';
7
7
  interface CookieOption {
8
8
  domain?: string;
9
9
  path?: string;
@@ -108,375 +108,393 @@ interface Options {
108
108
  error?(error: unknown): void;
109
109
  catch?(error: unknown): PromiseLike<Response | null> | Response | null;
110
110
  environment?: object;
111
+ replacer?(this: any, key: string, value: any): any;
111
112
  }
112
- type HandlerResult = void | undefined | string | BufferSource | ArrayBufferView | AsyncIterable<string | BufferSource | ArrayBufferView> | Iterable<string | BufferSource | ArrayBufferView> | object | Response | ReadableStream | Blob | FormData | boolean;
113
+ type HandlerResult = void | undefined | string | BufferSource | ArrayBufferView | AsyncIterable<string | BufferSource | ArrayBufferView> | Iterable<string | BufferSource | ArrayBufferView> | object | Response | ReadableStream | Blob | FormData | number | bigint | boolean;
113
114
  /** 处理函数定义 */
114
115
  interface Handler {
115
116
  (ctx: Context): PromiseLike<HandlerResult> | HandlerResult;
116
- /** 所属组 */
117
- plugin?: string;
118
117
  }
119
118
  interface FindHandler {
120
- (ctx: Context, setParams: (v: Params) => void): PromiseLike<Handler | null> | Handler | null;
119
+ (ctx: Context, setParams: (v: Params) => void): PromiseLike<Handler | Handler[] | null> | Handler | Handler[] | null;
121
120
  }
122
121
 
122
+ type FindItem<T extends Function> = [T | T[] | Router<T>, Record<string | symbol, any>, string[]];
123
+ type Finder<T extends Function> = (this: Router<T>, method: Method, path: string[]) => AsyncIterable<FindItem<T>> | Iterable<FindItem<T>>;
124
+ /** @import { Method, Params } from './main/types' */
123
125
  /**
124
- *
125
- * @param {...(Onionskin | Onionskin[])} handlers
126
- * @returns {Handler}
126
+ * @template {Function} T
127
+ * @typedef {[T | T[] | Router<T>, Record<string | symbol, any>, string[]]} FindItem
128
+ */
129
+ /**
130
+ * @template {Function} T
131
+ * @callback Finder
132
+ * @this {Router<T>}
133
+ * @param {Method} method
134
+ * @param {string[]} path
135
+ * @returns {AsyncIterable<FindItem<T>> | Iterable<FindItem<T>>}
127
136
  */
128
- declare function onionskin(...handlers: (Onionskin | Onionskin[])[]): Handler;
129
- type Onionskin = (ctx: Context, next: () => Promise<HandlerResult>) => PromiseLike<HandlerResult> | HandlerResult;
130
-
131
- type Guard = (ctx: Context) => PromiseLike<boolean | Handler | void> | boolean | Handler | void;
132
- type FindItem = [Handler | Router, Record<string | symbol, any>, string[]];
133
- type Finder = (this: Router, method: Method, path: string[], ctx: Context) => AsyncIterable<FindItem> | Iterable<FindItem>;
134
137
  /**
135
138
  * @abstract
139
+ * @template {Function} T
136
140
  */
137
- declare class Router {
141
+ declare class Router<T extends Function> {
142
+ /**
143
+ *
144
+ * @template {Function} T
145
+ * @param {Router<T> | T[] | T} route
146
+ * @param {Method} method
147
+ * @param {string[]} path
148
+ * @param {Params} params
149
+ * @param {AbortSignal?} [signal]
150
+ * @param {((v: Params) => void)?} [setParams]
151
+ * @returns {Promise<T[] | null>}
152
+ */
153
+ static "__#2@#find"<T_1 extends Function>(route: Router<T_1> | T_1[] | T_1, method: Method, path: string[], params: Params, signal?: AbortSignal | null, setParams?: ((v: Params) => void) | null): Promise<T_1[] | null>;
138
154
  /**
139
155
  *
140
- * @param {Router[]} routers
141
- * @returns {FindHandler}
156
+ * @template {Function} T
157
+ * @param {Router<T>[]} routers
158
+ * @param {Method} method
159
+ * @param {string[]} path
160
+ * @param {AbortSignal?} [signal]
161
+ * @param {((v: Params) => void)?} [setParams]
162
+ * @returns {Promise<T[] | null>}
142
163
  */
143
- static make(routers: Router[]): FindHandler;
164
+ static find<T_1 extends Function>(routers: Router<T_1>[], method: Method, path: string[], signal?: AbortSignal | null, setParams?: ((v: Params) => void) | null): Promise<T_1[] | null>;
144
165
  /**
145
166
  *
146
- * @param {Finder} find
147
- * @returns {Router}
167
+ * @template {Function} T
168
+ * @param {Finder<T>} find
169
+ * @returns {Router<T>}
148
170
  */
149
- static create(find: Finder): Router;
171
+ static create<T_1 extends Function>(find: Finder<T_1>): Router<T_1>;
150
172
  disabled: boolean;
151
173
  /**
152
174
  * @abstract
153
175
  * @param {Method} method
154
176
  * @param {string[]} path
155
- * @param {Context} ctx
156
- * @returns {AsyncIterable<FindItem> | Iterable<FindItem>}
177
+ * @returns {AsyncIterable<FindItem<T>> | Iterable<FindItem<T>>}
157
178
  */
158
- find(method: Method, path: string[], ctx: Context): AsyncIterable<FindItem> | Iterable<FindItem>;
159
- /** @readonly @type {Set<Guard>} */
160
- readonly guards: Set<Guard>;
179
+ find(method: Method, path: string[]): AsyncIterable<FindItem<T>> | Iterable<FindItem<T>>;
161
180
  /**
162
181
  *
163
- * @param {Handler} h
164
- * @returns {Handler}
182
+ * @param {...T | T[]} guards
165
183
  */
166
- __onionskin: (h: Handler) => Handler;
167
- /** @param {Onionskin} os */
168
- onionskin(os: Onionskin): void;
184
+ guard(...guards: (T | T[])[]): void;
185
+ #private;
169
186
  }
170
187
 
171
- declare class ApiRouter extends Router {
188
+ /**
189
+ *
190
+ * @template {Function} T
191
+ * @extends {Router<T>}
192
+ */
193
+ declare class MapRouter<T extends Function> extends Router<T> {
172
194
  /**
173
195
  * 添加子路由
174
- * @template {Router | Finder} [T=ApiRouter]
196
+ * @template {Router<T> | Finder<T>} [P=MapRouter<T>]
175
197
  * @overload
176
- * @param {T} [router] 要注册的子路由或子路由的 Finder
177
- * @returns {T extends Finder ? Router : T}
198
+ * @param {P} [router] 要注册的子路由或子路由的 Finder<T>
199
+ * @returns {P extends Finder<T> ? Router<T> : P}
178
200
  */
179
- route<T extends Router | Finder = ApiRouter>(router?: T | undefined): T extends Finder ? Router : T;
201
+ route<P extends Router<T> | Finder<T> = MapRouter<T>>(router?: P | undefined): P extends Finder<T> ? Router<T> : P;
180
202
  /**
181
203
  * 添加子路由
182
- * @template {Router | Finder} [T=ApiRouter]
204
+ * @template {Router<T> | Finder<T>} [P=MapRouter<T>]
183
205
  * @overload
184
206
  * @param {string} path 要注册的路径
185
- * @param {T} [router] 要注册的子路由或子路由的 Finder
186
- * @returns {T extends Finder ? Router : T}
207
+ * @param {P} [router] 要注册的子路由或子路由的 Finder<T>
208
+ * @returns {P extends Finder<T> ? Router<T> : P}
187
209
  */
188
- route<T extends Router | Finder = ApiRouter>(path: string, router?: T | undefined): T extends Finder ? Router : T;
210
+ route<P extends Router<T> | Finder<T> = MapRouter<T>>(path: string, router?: P | undefined): P extends Finder<T> ? Router<T> : P;
189
211
  /**
190
212
  * 添加子路由
191
213
  * @overload
192
214
  * @param {TemplateStringsArray} template 要注册的路径模板
193
215
  * @param {...any} substitutions 要注册的路径模板代替内容
194
- * @returns {RouteBinder}
216
+ * @returns {RouteBinder<T>}
195
217
  */
196
- route(template: TemplateStringsArray, ...substitutions: any[]): RouteBinder;
218
+ route(template: TemplateStringsArray, ...substitutions: any[]): RouteBinder<T>;
197
219
  /**
198
220
  *
199
221
  * @param {Method} method
200
222
  * @param {string[]} path
201
- * @param {Context} ctx
202
- * @returns {Iterable<FindItem>}
223
+ * @returns {Iterable<FindItem<T>>}
203
224
  */
204
- find(method: Method, path: string[], ctx: Context): Iterable<FindItem>;
225
+ find(method: Method, path: string[]): Iterable<FindItem<T>>;
205
226
  /**
206
227
  * 注册处理函数
207
228
  * @overload
208
229
  * @param {Method | Iterable<Method> | ArrayLike<Method>} method 要注册的方法
209
- * @param {Handler} handler 要注册的处理函数
230
+ * @param {T} handler 要注册的处理函数
210
231
  * @returns {() => void}
211
232
  */
212
- verb(method: Method | Iterable<Method> | ArrayLike<Method>, handler: Handler): () => void;
233
+ verb(method: Method | Iterable<Method> | ArrayLike<Method>, handler: T): () => void;
213
234
  /**
214
235
  * 注册处理函数
215
236
  * @overload
216
237
  * @param {Method | Iterable<Method> | ArrayLike<Method>} method 要注册的方法
217
238
  * @param {string} path 要注册的路径
218
- * @param {Handler} handler 要注册的处理函数
239
+ * @param {T} handler 要注册的处理函数
219
240
  * @returns {() => void}
220
241
  */
221
- verb(method: Method | Iterable<Method> | ArrayLike<Method>, path: string, handler: Handler): () => void;
242
+ verb(method: Method | Iterable<Method> | ArrayLike<Method>, path: string, handler: T): () => void;
222
243
  /**
223
244
  * 注册处理函数
224
245
  * @overload
225
246
  * @param {Method | Iterable<Method> | ArrayLike<Method>} method 要注册的方法
226
247
  * @param {string} path 要注册的路径
227
- * @returns {Binder}
248
+ * @returns {Binder<T>}
249
+ */
250
+ verb(method: Method | Iterable<Method> | ArrayLike<Method>, path: string): Binder<T>;
251
+ /**
252
+ * @param {Method | Iterable<Method> | ArrayLike<Method>} method 要注册的方法
253
+ * @returns {Verb<T>}
228
254
  */
229
- verb(method: Method | Iterable<Method> | ArrayLike<Method>, path: string): Binder;
255
+ method(method: Method | Iterable<Method> | ArrayLike<Method>): Verb<T>;
230
256
  /**
231
257
  * 注册 HTTP GET/POST/PUT/DELETE 处理函数
232
258
  * @overload
233
- * @param {Handler} handler 要注册的处理函数
259
+ * @param {...T} handlers 要注册的处理函数
234
260
  * @returns {() => void}
235
261
  */
236
- match(handler: Handler): () => void;
262
+ match(...handlers: T[]): () => void;
237
263
  /**
238
264
  * 注册处理函数
239
265
  * @overload
240
266
  * @param {string} path 要注册的路径
241
- * @param {Handler} handler 要注册的处理函数
267
+ * @param {...T} handlers 要注册的处理函数
242
268
  * @returns {() => void}
243
269
  */
244
- match(path: string, handler: Handler): () => void;
270
+ match(path: string, ...handlers: T[]): () => void;
245
271
  /**
246
272
  * 注册 HTTP GET/POST/PUT/DELETE 处理函数
247
273
  * @overload
248
274
  * @param {string} path 要注册的路径
249
- * @returns {Binder}
275
+ * @returns {Binder<T>}
250
276
  */
251
- match(path: string): Binder;
277
+ match(path: string): Binder<T>;
252
278
  /**
253
279
  * 注册 HTTP GET/POST/PUT/DELETE 处理函数
254
280
  * @overload
255
281
  * @param {TemplateStringsArray} template 要注册的路径模板
256
282
  * @param {...any} substitutions 要注册的路径模板代替内容
257
- * @returns {Binder}
283
+ * @returns {Binder<T>}
258
284
  */
259
- match(template: TemplateStringsArray, ...substitutions: any[]): Binder;
285
+ match(template: TemplateStringsArray, ...substitutions: any[]): Binder<T>;
260
286
  /**
261
287
  * 注册 HTTP GET 处理函数
262
288
  * @overload
263
- * @param {Handler} handler 要注册的处理函数
289
+ * @param {...Handler} handlers 要注册的处理函数
264
290
  * @returns {() => void}
265
291
  */
266
- get(handler: Handler): () => void;
292
+ get(...handlers: Handler[]): () => void;
267
293
  /**
268
294
  * 注册 HTTP GET 处理函数
269
295
  * @overload
270
296
  * @param {string} path 要注册的路径
271
- * @param {Handler} handler 要注册的处理函数
297
+ * @param {...Handler} handlers 要注册的处理函数
272
298
  * @returns {() => void}
273
299
  */
274
- get(path: string, handler: Handler): () => void;
300
+ get(path: string, ...handlers: Handler[]): () => void;
275
301
  /**
276
302
  * 注册 HTTP GET 处理函数
277
303
  * @overload
278
304
  * @param {string} path 要注册的路径
279
- * @returns {Binder}
305
+ * @returns {Binder<T>}
280
306
  */
281
- get(path: string): Binder;
307
+ get(path: string): Binder<T>;
282
308
  /**
283
309
  * 注册 HTTP GET 处理函数
284
310
  * @overload
285
311
  * @param {TemplateStringsArray} template 要注册的路径模板
286
312
  * @param {...any} substitutions 要注册的路径模板代替内容
287
- * @returns {Binder}
313
+ * @returns {Binder<T>}
288
314
  */
289
- get(template: TemplateStringsArray, ...substitutions: any[]): Binder;
315
+ get(template: TemplateStringsArray, ...substitutions: any[]): Binder<T>;
290
316
  /**
291
317
  * 注册 HTTP POST 处理函数
292
318
  * @overload
293
- * @param {Handler} handler 要注册的处理函数
319
+ * @param {...Handler} handlers 要注册的处理函数
294
320
  * @returns {() => void}
295
321
  */
296
- post(handler: Handler): () => void;
322
+ post(...handlers: Handler[]): () => void;
297
323
  /**
298
324
  * 注册 HTTP POST 处理函数
299
325
  * @overload
300
326
  * @param {string} path 要注册的路径
301
- * @param {Handler} handler 要注册的处理函数
327
+ * @param {...Handler} handlers 要注册的处理函数
302
328
  * @returns {() => void}
303
329
  */
304
- post(path: string, handler: Handler): () => void;
330
+ post(path: string, ...handlers: Handler[]): () => void;
305
331
  /**
306
332
  * 注册 HTTP POST 处理函数
307
333
  * @overload
308
334
  * @param {string} path 要注册的路径
309
- * @returns {Binder}
335
+ * @returns {Binder<T>}
310
336
  */
311
- post(path: string): Binder;
337
+ post(path: string): Binder<T>;
312
338
  /**
313
339
  * 注册 HTTP POST 处理函数
314
340
  * @overload
315
341
  * @param {TemplateStringsArray} template 要注册的路径模板
316
342
  * @param {...any} substitutions 要注册的路径模板代替内容
317
- * @returns {Binder}
343
+ * @returns {Binder<T>}
318
344
  */
319
- post(template: TemplateStringsArray, ...substitutions: any[]): Binder;
345
+ post(template: TemplateStringsArray, ...substitutions: any[]): Binder<T>;
320
346
  /**
321
347
  * 注册 HTTP PUT 处理函数
322
348
  * @overload
323
- * @param {Handler} handler 要注册的处理函数
349
+ * @param {...Handler} handlers 要注册的处理函数
324
350
  * @returns {() => void}
325
351
  */
326
- put(handler: Handler): () => void;
352
+ put(...handlers: Handler[]): () => void;
327
353
  /**
328
354
  * 注册 HTTP PUT 处理函数
329
355
  * @overload
330
356
  * @param {string} path 要注册的路径
331
- * @param {Handler} handler 要注册的处理函数
357
+ * @param {...Handler} handlers 要注册的处理函数
332
358
  * @returns {() => void}
333
359
  */
334
- put(path: string, handler: Handler): () => void;
360
+ put(path: string, ...handlers: Handler[]): () => void;
335
361
  /**
336
362
  * 注册 HTTP PUT 处理函数
337
363
  * @overload
338
364
  * @param {string} path 要注册的路径
339
- * @returns {Binder}
365
+ * @returns {Binder<T>}
340
366
  */
341
- put(path: string): Binder;
367
+ put(path: string): Binder<T>;
342
368
  /**
343
369
  * 注册 HTTP PUT 处理函数
344
370
  * @overload
345
371
  * @param {TemplateStringsArray} template 要注册的路径模板
346
372
  * @param {...any} substitutions 要注册的路径模板代替内容
347
- * @returns {Binder}
373
+ * @returns {Binder<T>}
348
374
  */
349
- put(template: TemplateStringsArray, ...substitutions: any[]): Binder;
375
+ put(template: TemplateStringsArray, ...substitutions: any[]): Binder<T>;
350
376
  /**
351
377
  * 注册 HTTP DELETE 处理函数
352
378
  * @overload
353
- * @param {Handler} handler 要注册的处理函数
379
+ * @param {...Handler} handlers 要注册的处理函数
354
380
  * @returns {() => void}
355
381
  */
356
- delete(handler: Handler): () => void;
382
+ delete(...handlers: Handler[]): () => void;
357
383
  /**
358
384
  * 注册 HTTP DELETE 处理函数
359
385
  * @overload
360
386
  * @param {string} path 要注册的路径
361
- * @param {Handler} handler 要注册的处理函数
387
+ * @param {...Handler} handlers 要注册的处理函数
362
388
  * @returns {() => void}
363
389
  */
364
- delete(path: string, handler: Handler): () => void;
390
+ delete(path: string, ...handlers: Handler[]): () => void;
365
391
  /**
366
392
  * 注册 HTTP DELETE 处理函数
367
393
  * @overload
368
394
  * @param {string} path 要注册的路径
369
- * @returns {Binder}
395
+ * @returns {Binder<T>}
370
396
  */
371
- delete(path: string): Binder;
397
+ delete(path: string): Binder<T>;
372
398
  /**
373
399
  * 注册 HTTP DELETE 处理函数
374
400
  * @overload
375
401
  * @param {TemplateStringsArray} template 要注册的路径模板
376
402
  * @param {...any} substitutions 要注册的路径模板代替内容
377
- * @returns {Binder}
403
+ * @returns {Binder<T>}
378
404
  */
379
- delete(template: TemplateStringsArray, ...substitutions: any[]): Binder;
405
+ delete(template: TemplateStringsArray, ...substitutions: any[]): Binder<T>;
380
406
  /**
381
407
  * 注册 HTTP HEAD 处理函数
382
408
  * @overload
383
- * @param {Handler} handler 要注册的处理函数
409
+ * @param {...Handler} handlers 要注册的处理函数
384
410
  * @returns {() => void}
385
411
  */
386
- head(handler: Handler): () => void;
412
+ head(...handlers: Handler[]): () => void;
387
413
  /**
388
414
  * 注册 HTTP HEAD 处理函数
389
415
  * @overload
390
416
  * @param {string} path 要注册的路径
391
- * @param {Handler} handler 要注册的处理函数
417
+ * @param {...Handler} handlers 要注册的处理函数
392
418
  * @returns {() => void}
393
419
  */
394
- head(path: string, handler: Handler): () => void;
420
+ head(path: string, ...handlers: Handler[]): () => void;
395
421
  /**
396
422
  * 注册 HTTP HEAD 处理函数
397
423
  * @overload
398
424
  * @param {string} path 要注册的路径
399
- * @returns {Binder}
425
+ * @returns {Binder<T>}
400
426
  */
401
- head(path: string): Binder;
427
+ head(path: string): Binder<T>;
402
428
  /**
403
429
  * 注册 HTTP HEAD 处理函数
404
430
  * @overload
405
431
  * @param {TemplateStringsArray} template 要注册的路径模板
406
432
  * @param {...any} substitutions 要注册的路径模板代替内容
407
- * @returns {Binder}
433
+ * @returns {Binder<T>}
408
434
  */
409
- head(template: TemplateStringsArray, ...substitutions: any[]): Binder;
435
+ head(template: TemplateStringsArray, ...substitutions: any[]): Binder<T>;
410
436
  /**
411
437
  * 注册 HTTP OPTIONS 处理函数
412
438
  * @overload
413
- * @param {Handler} handler 要注册的处理函数
439
+ * @param {...Handler} handlers 要注册的处理函数
414
440
  * @returns {() => void}
415
441
  */
416
- options(handler: Handler): () => void;
442
+ options(...handlers: Handler[]): () => void;
417
443
  /**
418
444
  * 注册 HTTP OPTIONS 处理函数
419
445
  * @overload
420
446
  * @param {string} path 要注册的路径
421
- * @param {Handler} handler 要注册的处理函数
447
+ * @param {...Handler} handlers 要注册的处理函数
422
448
  * @returns {() => void}
423
449
  */
424
- options(path: string, handler: Handler): () => void;
450
+ options(path: string, ...handlers: Handler[]): () => void;
425
451
  /**
426
452
  * 注册 HTTP OPTIONS 处理函数
427
453
  * @overload
428
454
  * @param {string} path 要注册的路径
429
- * @returns {Binder}
455
+ * @returns {Binder<T>}
430
456
  */
431
- options(path: string): Binder;
457
+ options(path: string): Binder<T>;
432
458
  /**
433
459
  * 注册 HTTP OPTIONS 处理函数
434
460
  * @overload
435
461
  * @param {TemplateStringsArray} template 要注册的路径模板
436
462
  * @param {...any} substitutions 要注册的路径模板代替内容
437
- * @returns {Binder}
463
+ * @returns {Binder<T>}
438
464
  */
439
- options(template: TemplateStringsArray, ...substitutions: any[]): Binder;
465
+ options(template: TemplateStringsArray, ...substitutions: any[]): Binder<T>;
440
466
  #private;
441
467
  }
442
468
  type Match = (paths: string[]) => [Params, string[]] | undefined;
443
- type Binder = (handler: Handler, ...handlers: Handler[]) => () => void;
444
- type Route = {
469
+ type Binder<T extends Function> = (handler: T, ...handlers: T[]) => () => void;
470
+ type Verb1<T extends Function> = (handler: T, ...handlers: T[]) => () => void;
471
+ type Verb2<T extends Function> = (path: string, handler: T, ...handlers: T[]) => () => void;
472
+ type Verb3<T extends Function> = (path: string) => Binder<T>;
473
+ type Verb4<T extends Function> = (template: TemplateStringsArray, ...substitutions: any[]) => Binder<T>;
474
+ type Verb<T extends Function> = Verb1<T> & Verb2<T> & Verb3<T> & Verb4<T>;
475
+ type Route<T extends Function> = {
445
476
  /**
446
477
  * 路径匹配
447
478
  */
448
479
  match?: Match | undefined;
449
480
  router?: null | undefined;
450
- /**
451
- * 所属插件
452
- */
453
- plugin?: string | undefined;
454
481
  /**
455
482
  * 处理函数
456
483
  */
457
- handler: Handler;
484
+ handlers: T[];
458
485
  /**
459
486
  * 方法列表
460
487
  */
461
488
  methods: Set<Method>;
462
489
  };
463
- type RouterRoute = {
490
+ type RouterRoute<T extends Function> = {
464
491
  /**
465
492
  * 路径匹配
466
493
  */
467
494
  match?: Match | undefined;
468
- router: Router;
495
+ router: Router<T>;
469
496
  };
470
- type RouteBinder<T extends Router | Finder = ApiRouter> = (router?: T | undefined) => T extends Finder ? Router : T;
471
-
472
- /**
473
- *
474
- * @param {Onionskin} onionskin
475
- * @param {Packer} [packer]
476
- * @returns {Packer}
477
- */
478
- declare function packer(onionskin: Onionskin, packer?: Packer): Packer;
479
- type Packer = (handler: Handler) => Handler;
497
+ type RouteBinder<T extends Function, P extends Router<T> | Finder<T> = MapRouter<T>> = (router?: P | undefined) => P extends Finder<T> ? Router<T> : P;
480
498
 
481
499
  /**
482
500
  *
@@ -485,23 +503,24 @@ type Packer = (handler: Handler) => Handler;
485
503
  * @param {Options} [options]
486
504
  * @returns {Promise<Response | null>}
487
505
  */
488
- declare function main(request: Request, getHandler: FindHandler, { runner, error: echoError, catch: catchError, method: toMethod, environment }?: Options): Promise<Response | null>;
506
+ declare function main(request: Request, getHandler: FindHandler, { runner, error: echoError, catch: catchError, method: toMethod, environment, replacer: JSONReplacer, }?: Options): Promise<Response | null>;
489
507
 
490
- /** @import { FindHandler, Options } from './main/types' */
491
508
  /**
492
509
  *
493
- * @param {FindHandler} getHandler
510
+ * @param {Router<Handler> | Router<Handler>[] | FindHandler} routers
494
511
  * @param {Options} options
495
512
  * @returns {(request: Request) => Promise<Response | null>}
496
513
  */
497
- declare function make(getHandler: FindHandler, options: Options): (request: Request) => Promise<Response | null>;
514
+ declare function make(routers: Router<Handler> | Router<Handler>[] | FindHandler, options: Options): (request: Request) => Promise<Response | null>;
498
515
 
516
+ /** @import { FindHandler, Options } from './main/types' */
499
517
  /**
500
518
  *
501
- * @param {...(Handler | Handler[])} handlers
502
- * @returns {Handler}
519
+ * @param {FindHandler} getHandler
520
+ * @param {Options} options
521
+ * @returns {(request: Request) => Promise<Response | null>}
503
522
  */
504
- declare function merge(...handlers: (Handler | Handler[])[]): Handler;
523
+ declare function bind(getHandler: FindHandler, options: Options): (request: Request) => Promise<Response | null>;
505
524
 
506
525
  /**
507
526
  *
@@ -616,5 +635,5 @@ declare class Param {
616
635
  #private;
617
636
  }
618
637
 
619
- export { ApiRouter, Param, Router, Service, createFetch, main, make, merge, onionskin, packer, service, stateService, storeService };
620
- export type { Binder, Context, Cookie, CookieOption, FindHandler, FindItem, Finder, Guard, Handler, HandlerResult, Match, Method, Onionskin, Options, Packer, Route, RouteBinder, RouterRoute, Runner, StateService, StoreService };
638
+ export { MapRouter, Param, Router, Service, bind, createFetch, main, make, service, stateService, storeService };
639
+ export type { Binder, Context, Cookie, CookieOption, FindHandler, FindItem, Finder, Handler, HandlerResult, Match, Method, Options, Route, RouteBinder, RouterRoute, Runner, StateService, StoreService, Verb, Verb1, Verb2, Verb3, Verb4 };