@stacksjs/bun-router 0.1.3 → 0.1.5

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/dist/cli.js CHANGED
@@ -29,7 +29,7 @@ Received ${s}, cleaning up...`),e)try{await e()}catch(r){console.error("Error du
29
29
  \u2717 Command "${e}" not found.
30
30
  `)),this.enableDidYouMean){let t=[];for(let r of this.commands){if(r.displayName)t.push(r.displayName);if(r.aliasNames)t.push(...r.aliasNames)}let s=ue(e,t);if(s.length>0)console.log(E.yellow("Did you mean one of these?")),s.forEach((r)=>console.log(` ${E.dim("\u2022")} ${this.name} ${r}`)),console.log("")}console.log(E.dim("Run"),`${this.name} --help`,E.dim("to see all available commands")),x.exit(1)}async parse(e=oe,t={}){let{run:s=!0,exitOnError:r=!1}=t;if(r)try{return await this.parse(e,{run:s})}catch(i){throw this.handleUsageError(i),i}if(this.rawArgs=e,!this.name)this.name=e[1]?Ve(e[1]):"cli";let n=!0,o=e.slice(2),l=o[0];if(l&&!l.startsWith("-")){for(let i of this.commands)if(i.isMatched(l)){let u=this.mri(o,i);n=!1;let d={...u,args:u.args.slice(1)};this.setParsedInfo(d,i,l),this.emit(`command:${l}`,i);break}}if(n){for(let i of this.commands)if(i.name===""){n=!1;let u=this.mri(o,i);this.setParsedInfo(u,i),this.emit("command:!",i);break}}if(n){let i=this.mri(e.slice(2));this.setParsedInfo(i)}if(this.options.verbose)this.isVerbose=!0;if(this.options.quiet)this.isQuiet=!0;if(this.options.debug)this.isDebug=!0;if(this.options.noInteraction)this.isNoInteraction=!0;if(this.options.env)this.environment=String(this.options.env);if(this.options.dryRun)this.isDryRun=!0;if(this.options.force)this.isForce=!0;if(this.options.noEmoji!==void 0)this.useEmoji=!this.options.noEmoji;if(this.options.theme)this.theme=String(this.options.theme);if(this.options.noCache!==void 0)this.isNoCache=Boolean(this.options.noCache);if(this.options.help&&this.showHelpOnExit)this.outputHelp(),s=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),s=!1,this.unsetMatchedCommand();let a={args:this.args,options:this.options};if(s)await this.runMatchedCommand();if(!this.matchedCommand&&this.args[0]){if(this.emit("command:*"),!(this.listenerCount("command:*")>0))this.showCommandNotFound(this.args[0])}return a}mri(e,t){let s=[...this.globalCommand.options,...t?t.options:[]],r=Ae(s),n=[],o=e.indexOf("--");if(o>-1)n=e.slice(o+1),e=e.slice(0,o);let l=ke(e,r),a={_:l._};for(let m of Object.keys(l))if(m!=="_")a[ce(m)]=l[m];let i=a._,u={"--":n},d=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,h=Object.create(null);for(let m of s){if(!d&&m.config.default!==void 0)for(let f of m.names)u[f]=m.config.default;if(Array.isArray(m.config.type)){if(h[m.name]===void 0)h[m.name]={shouldTransform:!0,transformFunction:m.config.type[0]}}}for(let m of Object.keys(a))if(m!=="_"){let f=m.split(".");Le(u,f,a[m]),Pe(u,h)}return{args:i,options:u}}async run(e=oe){return this.parse(e,{run:!0,exitOnError:!0})}handleUsageError(e){if(!(!!e&&typeof e==="object"&&e.name==="ClappError"&&e.isUsageError!==!1))return;let r=e,n=r.message??"command-line error",o=this.name?`${this.name}: `:"",l=/--help/.test(n)?"":`
31
31
  Run \`${this.name??"cli"} --help\` for usage.`;x.stderr.write(`${o}${n}${l}
32
- `),x.exit(r.exitCode??2)}async runMatchedCommand(){let{args:e,options:t,matchedCommand:s}=this;if(!s||!s.commandAction)return;s.checkUnknownOptions(),s.checkOptionValue(),s.checkRequiredArgs();let r=[];s.args.forEach((a,i)=>{if(a.variadic)r.push(e.slice(i));else r.push(e[i])}),r.push(t);let n={command:s,args:r,options:t};for(let a of s.beforeHooks)await a(n);let o,l=async()=>{let a=s.commandAction.apply(this,r);if(a instanceof Promise)o=await a;else o=a;return o};if(s.middleware.length>0){let a=0,i=async()=>{if(a<s.middleware.length){let u=s.middleware[a++];await u({...n,next:i})}else await l()};await i()}else await l();for(let a of s.afterHooks)await a(n);return o}removeSignalHandlers(){if(!this.signalHandlersSet)return this;return x.removeAllListeners("SIGINT"),x.removeAllListeners("SIGTERM"),this.signalHandlersSet=!1,this}destroy(){this.removeSignalHandlers(),this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.matchedCommand=void 0,this.matchedCommandName=void 0,this.removeAllListeners()}}class he{cache;enabled;cleanupInterval=null;hits=0;misses=0;constructor(){this.cache=new Map,this.enabled=!0,this.startCleanupInterval()}startCleanupInterval(){if(this.cleanupInterval)return;this.cleanupInterval=setInterval(()=>{this.cleanup()},30000),this.cleanupInterval.unref()}stopCleanup(){if(this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}isEnabled(){return this.enabled}get(e){if(!this.enabled){this.misses++;return}let t=this.cache.get(e);if(!t){this.misses++;return}if(Date.now()-t.timestamp>t.ttl){this.cache.delete(e),this.misses++;return}return this.hits++,t.value}set(e,t,s=5000){if(!this.enabled)return;this.cache.set(e,{value:t,timestamp:Date.now(),ttl:s})}has(e){if(!this.enabled)return!1;let t=this.cache.get(e);if(!t)return!1;if(Date.now()-t.timestamp>t.ttl)return this.cache.delete(e),!1;return!0}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}disable(){this.enabled=!1,this.clear()}enable(){this.enabled=!0}stats(){return{size:this.cache.size,enabled:this.enabled,hits:this.hits,misses:this.misses}}resetStats(){this.hits=0,this.misses=0}keys(){return Array.from(this.cache.keys())}cleanup(){let e=Date.now();for(let[t,s]of this.cache.entries())if(e-s.timestamp>s.ttl)this.cache.delete(t)}destroy(){this.stopCleanup(),this.clear(),this.resetStats()}}var ns=new he;function qe(){if("FORCE_COLOR"in M.env)return M.env.FORCE_COLOR!=="0";if("NO_COLOR"in M.env||M.env.TERM==="dumb")return!1;if(M.platform==="win32")return!0;return ae.isatty(1)&&ae.isatty(2)}var me=qe();function y(e,t){if(!me)return(s)=>s;return(s)=>e+s+t}var Ke=y("\x1B[0m","\x1B[0m"),Ye=y("\x1B[31m","\x1B[39m"),Je=y("\x1B[32m","\x1B[39m"),Qe=y("\x1B[33m","\x1B[39m"),Xe=y("\x1B[34m","\x1B[39m"),Ze=y("\x1B[35m","\x1B[39m"),et=y("\x1B[36m","\x1B[39m"),tt=y("\x1B[37m","\x1B[39m"),st=y("\x1B[90m","\x1B[39m"),rt=y("\x1B[1m","\x1B[22m"),it=y("\x1B[3m","\x1B[23m"),nt=y("\x1B[4m","\x1B[24m"),ot=y("\x1B[2m","\x1B[22m"),at=y("\x1B[7m","\x1B[27m"),lt=y("\x1B[8m","\x1B[28m"),ct=y("\x1B[9m","\x1B[29m"),ut=y("\x1B[41m","\x1B[49m"),dt=y("\x1B[42m","\x1B[49m"),ht=y("\x1B[43m","\x1B[49m"),mt=y("\x1B[44m","\x1B[49m"),pt=y("\x1B[45m","\x1B[49m"),ft=y("\x1B[46m","\x1B[49m"),gt=y("\x1B[47m","\x1B[49m"),yt=me,$t={reset:Ke,red:Ye,green:Je,yellow:Qe,blue:Xe,magenta:Ze,cyan:et,white:tt,gray:st,bold:rt,italic:it,underline:nt,dim:ot,inverse:at,hidden:lt,strikethrough:ct,bgRed:ut,bgGreen:dt,bgYellow:ht,bgBlue:mt,bgMagenta:pt,bgCyan:ft,bgWhite:gt,isColorSupported:yt},wt=$t,vt=["up","down","left","right","space","enter","cancel"],ds={actions:new Set(vt),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"}};var hs=bt.platform.startsWith("win"),ms=Symbol("clapp:cancel");var xt=De();var g=(e,t)=>xt?e:t,ps=g("\u25C6","*"),fs=g("\u25A0","x"),gs=g("\u25B2","x"),ys=g("\u25C7","o"),$s=g("\u250C","T"),Ct=g("\u2502","|"),ws=g("\u2514","\u2014"),bs=g("\u25CF",">"),vs=g("\u25CB"," "),xs=g("\u25FB","[\u2022]"),Cs=g("\u25FC","[+]"),Rs=g("\u25FB","[ ]"),Os=g("\u25AA","\u2022"),Ss=g("\u2500","-"),Ts=g("\u256E","+"),Is=g("\u251C","+"),Es=g("\u256F","+"),Ms=g("\u25CF","\u2022"),_s=g("\u25C6","*"),js=g("\u25B2","!"),ks=g("\u25A0","x");var Bs={light:g("\u2500","-"),heavy:g("\u2501","="),block:g("\u2588","#")};function Rt(){return`${wt.gray(Ct)} `}var As=Rt();var pe="0.1.3";import R from"fs/promises";import Q from"path";import L from"process";var b={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m",white:"\x1B[37m",gray:"\x1B[90m"},c={red:(e)=>`${b.red}${e}${b.reset}`,green:(e)=>`${b.green}${e}${b.reset}`,yellow:(e)=>`${b.yellow}${e}${b.reset}`,blue:(e)=>`${b.blue}${e}${b.reset}`,cyan:(e)=>`${b.cyan}${e}${b.reset}`,white:(e)=>`${b.white}${e}${b.reset}`,gray:(e)=>`${b.gray}${e}${b.reset}`,bold:(e)=>`${b.bold}${e}${b.reset}`,dim:(e)=>`${b.dim}${e}${b.reset}`,hex:(e)=>(t)=>t};async function P(e){let t=Object.entries(fe).map(([r,n])=>({name:r,className:n.constructor.name})),s=`/**
32
+ `),x.exit(r.exitCode??2)}async runMatchedCommand(){let{args:e,options:t,matchedCommand:s}=this;if(!s||!s.commandAction)return;s.checkUnknownOptions(),s.checkOptionValue(),s.checkRequiredArgs();let r=[];s.args.forEach((a,i)=>{if(a.variadic)r.push(e.slice(i));else r.push(e[i])}),r.push(t);let n={command:s,args:r,options:t};for(let a of s.beforeHooks)await a(n);let o,l=async()=>{let a=s.commandAction.apply(this,r);if(a instanceof Promise)o=await a;else o=a;return o};if(s.middleware.length>0){let a=0,i=async()=>{if(a<s.middleware.length){let u=s.middleware[a++];await u({...n,next:i})}else await l()};await i()}else await l();for(let a of s.afterHooks)await a(n);return o}removeSignalHandlers(){if(!this.signalHandlersSet)return this;return x.removeAllListeners("SIGINT"),x.removeAllListeners("SIGTERM"),this.signalHandlersSet=!1,this}destroy(){this.removeSignalHandlers(),this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.matchedCommand=void 0,this.matchedCommandName=void 0,this.removeAllListeners()}}class he{cache;enabled;cleanupInterval=null;hits=0;misses=0;constructor(){this.cache=new Map,this.enabled=!0,this.startCleanupInterval()}startCleanupInterval(){if(this.cleanupInterval)return;this.cleanupInterval=setInterval(()=>{this.cleanup()},30000),this.cleanupInterval.unref()}stopCleanup(){if(this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}isEnabled(){return this.enabled}get(e){if(!this.enabled){this.misses++;return}let t=this.cache.get(e);if(!t){this.misses++;return}if(Date.now()-t.timestamp>t.ttl){this.cache.delete(e),this.misses++;return}return this.hits++,t.value}set(e,t,s=5000){if(!this.enabled)return;this.cache.set(e,{value:t,timestamp:Date.now(),ttl:s})}has(e){if(!this.enabled)return!1;let t=this.cache.get(e);if(!t)return!1;if(Date.now()-t.timestamp>t.ttl)return this.cache.delete(e),!1;return!0}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}disable(){this.enabled=!1,this.clear()}enable(){this.enabled=!0}stats(){return{size:this.cache.size,enabled:this.enabled,hits:this.hits,misses:this.misses}}resetStats(){this.hits=0,this.misses=0}keys(){return Array.from(this.cache.keys())}cleanup(){let e=Date.now();for(let[t,s]of this.cache.entries())if(e-s.timestamp>s.ttl)this.cache.delete(t)}destroy(){this.stopCleanup(),this.clear(),this.resetStats()}}var ns=new he;function qe(){if("FORCE_COLOR"in M.env)return M.env.FORCE_COLOR!=="0";if("NO_COLOR"in M.env||M.env.TERM==="dumb")return!1;if(M.platform==="win32")return!0;return ae.isatty(1)&&ae.isatty(2)}var me=qe();function y(e,t){if(!me)return(s)=>s;return(s)=>e+s+t}var Ke=y("\x1B[0m","\x1B[0m"),Ye=y("\x1B[31m","\x1B[39m"),Je=y("\x1B[32m","\x1B[39m"),Qe=y("\x1B[33m","\x1B[39m"),Xe=y("\x1B[34m","\x1B[39m"),Ze=y("\x1B[35m","\x1B[39m"),et=y("\x1B[36m","\x1B[39m"),tt=y("\x1B[37m","\x1B[39m"),st=y("\x1B[90m","\x1B[39m"),rt=y("\x1B[1m","\x1B[22m"),it=y("\x1B[3m","\x1B[23m"),nt=y("\x1B[4m","\x1B[24m"),ot=y("\x1B[2m","\x1B[22m"),at=y("\x1B[7m","\x1B[27m"),lt=y("\x1B[8m","\x1B[28m"),ct=y("\x1B[9m","\x1B[29m"),ut=y("\x1B[41m","\x1B[49m"),dt=y("\x1B[42m","\x1B[49m"),ht=y("\x1B[43m","\x1B[49m"),mt=y("\x1B[44m","\x1B[49m"),pt=y("\x1B[45m","\x1B[49m"),ft=y("\x1B[46m","\x1B[49m"),gt=y("\x1B[47m","\x1B[49m"),yt=me,$t={reset:Ke,red:Ye,green:Je,yellow:Qe,blue:Xe,magenta:Ze,cyan:et,white:tt,gray:st,bold:rt,italic:it,underline:nt,dim:ot,inverse:at,hidden:lt,strikethrough:ct,bgRed:ut,bgGreen:dt,bgYellow:ht,bgBlue:mt,bgMagenta:pt,bgCyan:ft,bgWhite:gt,isColorSupported:yt},wt=$t,vt=["up","down","left","right","space","enter","cancel"],ds={actions:new Set(vt),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"}};var hs=bt.platform.startsWith("win"),ms=Symbol("clapp:cancel");var xt=De();var g=(e,t)=>xt?e:t,ps=g("\u25C6","*"),fs=g("\u25A0","x"),gs=g("\u25B2","x"),ys=g("\u25C7","o"),$s=g("\u250C","T"),Ct=g("\u2502","|"),ws=g("\u2514","\u2014"),bs=g("\u25CF",">"),vs=g("\u25CB"," "),xs=g("\u25FB","[\u2022]"),Cs=g("\u25FC","[+]"),Rs=g("\u25FB","[ ]"),Os=g("\u25AA","\u2022"),Ss=g("\u2500","-"),Ts=g("\u256E","+"),Is=g("\u251C","+"),Es=g("\u256F","+"),Ms=g("\u25CF","\u2022"),_s=g("\u25C6","*"),js=g("\u25B2","!"),ks=g("\u25A0","x");var Bs={light:g("\u2500","-"),heavy:g("\u2501","="),block:g("\u2588","#")};function Rt(){return`${wt.gray(Ct)} `}var As=Rt();var pe="0.1.5";import R from"fs/promises";import Q from"path";import L from"process";var b={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m",white:"\x1B[37m",gray:"\x1B[90m"},c={red:(e)=>`${b.red}${e}${b.reset}`,green:(e)=>`${b.green}${e}${b.reset}`,yellow:(e)=>`${b.yellow}${e}${b.reset}`,blue:(e)=>`${b.blue}${e}${b.reset}`,cyan:(e)=>`${b.cyan}${e}${b.reset}`,white:(e)=>`${b.white}${e}${b.reset}`,gray:(e)=>`${b.gray}${e}${b.reset}`,bold:(e)=>`${b.bold}${e}${b.reset}`,dim:(e)=>`${b.dim}${e}${b.reset}`,hex:(e)=>(t)=>t};async function P(e){let t=Object.entries(fe).map(([r,n])=>({name:r,className:n.constructor.name})),s=`/**
33
33
  * This file is auto-generated.
34
34
  * DO NOT EDIT THIS FILE DIRECTLY.
35
35
  * To update, run 'bun router middleware:types'
package/dist/index.d.ts CHANGED
@@ -29,7 +29,44 @@ export { MiddlewareGroupRegistry, middlewareGroups } from './router/middleware-g
29
29
  export * from './testing';
30
30
  export * from './typed';
31
31
  export * from './types';
32
- export type { FromRegistry, KnownActionPath, KnownMiddlewareName, KnownRouteName, KnownRoutes, MiddlewareReference, PathForRouteName, RouterTypeRegistry, } from './types/registry';
32
+ /**
33
+ * What an application tells the router about itself.
34
+ *
35
+ * A router deals in strings that are really identifiers: `'Actions/CreateUser'`
36
+ * names a file, `'auth'` names a middleware, `'users.show'` names a route. The
37
+ * compiler has no idea which of them exist, so a typo in any of the three is a
38
+ * runtime error at best - a silently unprotected endpoint at worst, when the
39
+ * typo is in a middleware alias.
40
+ *
41
+ * The router cannot know them either. The application can, so it says so:
42
+ *
43
+ * ```ts
44
+ * declare module '@stacksjs/bun-router' {
45
+ * interface RouterTypeRegistry {
46
+ * actions: 'Actions/CreateUserAction' | 'Actions/ListUsersAction'
47
+ * middleware: 'auth' | 'throttle'
48
+ * routes: { 'users.index': '/users', 'users.show': '/users/{id}' }
49
+ * }
50
+ * }
51
+ * ```
52
+ *
53
+ * Every key is independent, and every one falls back to exactly the type it had
54
+ * before this existed when absent. Declaring nothing changes nothing.
55
+ *
56
+ * ## Why it is declared HERE, in the entry
57
+ *
58
+ * A module augmentation merges into the module it names. `RouterTypeRegistry`
59
+ * used to be declared in `./types/registry` and merely re-exported from here,
60
+ * which meant `declare module '@stacksjs/bun-router'` created a second,
61
+ * unrelated interface: `keyof RouterTypeRegistry` looked right at the call
62
+ * site, while every type computed from it inside the package still saw an empty
63
+ * one and quietly fell back. Everything looked wired up and nothing was
64
+ * checked. Declaring it in the entry is what makes the obvious augmentation the
65
+ * one that works.
66
+ */
67
+ export interface RouterTypeRegistry {
68
+ }
69
+ export type { FromRegistry, KnownActionPath, KnownMiddlewareName, KnownRouteName, KnownRoutes, MiddlewareReference, PathForRouteName, } from './types/registry';
33
70
  export * from './validation/validator';
34
71
  export { clearNamedRoutes, getNamedRoutePath, getNamedRoutes, registerNamedRoute, url, type UrlOptions } from './url';
35
72
  export * from './utils';
@@ -1,59 +1,27 @@
1
+ import type { RouterTypeRegistry } from '../index';
1
2
  import type { BuiltInMiddleware } from '../types';
2
3
  /**
3
- * What an application tells the router about itself.
4
- *
5
- * A router deals in strings that are really identifiers: `'Actions/CreateUser'`
6
- * names a file, `'auth'` names a middleware, `'users.show'` names a route. The
7
- * compiler has no idea which of them exist, so a typo in any of the three is a
8
- * runtime error at best — a silently unprotected endpoint at worst, when the
9
- * typo is in a middleware alias.
10
- *
11
- * The router cannot know them either. The application can, so it says so, by
12
- * augmenting this interface:
13
- *
14
- * ```ts
15
- * // types/router.d.ts
16
- * declare module '@stacksjs/bun-router' {
17
- * interface RouterTypeRegistry {
18
- * actions: 'Actions/CreateUser' | 'Actions/ListUsers'
19
- * middleware: 'auth' | 'throttle' | 'signed'
20
- * routes: {
21
- * 'users.index': '/users'
22
- * 'users.show': '/users/{id}'
23
- * }
24
- * }
25
- * }
26
- * ```
27
- *
28
- * From then on, `router.post('/users', 'Actions/CreateUsr')` is a compile
29
- * error, so is `.middleware('atuh')`, and `url('users.show')` demands an `id`
30
- * because the path says it has one.
31
- *
32
- * ## Nothing is required
33
- *
34
- * Every key is independent, and every one falls back to exactly the type it had
35
- * before this existed when it is absent. An application that declares none of
36
- * them sees no change at all. That is the point: this cannot be a breaking
37
- * change, and it cannot be a thing you must do before the router is usable.
38
- *
39
- * ## Generating it
40
- *
41
- * The three unions are facts a build step already knows. A framework on top of
42
- * this router that scans `app/Actions/` or a middleware alias map can emit the
43
- * augmentation into a `.d.ts` and the whole surface types itself with nothing
44
- * hand-written. Writing it by hand works just as well for a smaller app.
4
+ * Reading what the application declared. The interface itself lives in
5
+ * `../index`, which is the module an application can name in a
6
+ * `declare module '@stacksjs/bun-router'` augmentation - see the note there.
45
7
  */
46
- export interface RouterTypeRegistry {
47
- }
48
8
  /**
49
9
  * Read a key out of the registry, or fall back.
50
10
  *
51
- * `K extends keyof RouterTypeRegistry` is `never extends never` — false — while
52
- * the interface is empty, which is what makes every fallback the default. The
53
- * second check keeps a malformed augmentation (say, `actions: number`) from
54
- * poisoning the type: it falls back rather than producing something unusable.
11
+ * `TKey extends keyof RouterTypeRegistry` is false while the interface is
12
+ * empty, which is what makes every fallback the default.
13
+ *
14
+ * `TShape` is checked separately from `TFallback`, and the distinction is
15
+ * load-bearing. It used to test the declared value against the fallback itself,
16
+ * which sounds like the same thing and is not: the fallback for an action path
17
+ * is the loose pattern `Actions/${string}Action`, and a real application's
18
+ * action list contains names like `'Actions/Dashboard/Library/GetFunctions'`
19
+ * that do not match it. So a correct, complete declaration failed the guard and
20
+ * fell back to the pattern - the feature looked wired up and checked nothing.
21
+ * The guard is meant to catch `actions: number`, so it asks whether the
22
+ * declared value is a string, and nothing more.
55
23
  */
56
- export type FromRegistry<TKey extends string, TFallback> = TKey extends keyof RouterTypeRegistry ? (RouterTypeRegistry[TKey] extends TFallback ? RouterTypeRegistry[TKey] : TFallback) : TFallback;
24
+ export type FromRegistry<TKey extends string, TShape, TFallback> = TKey extends keyof RouterTypeRegistry ? (RouterTypeRegistry[TKey] extends TShape ? RouterTypeRegistry[TKey] : TFallback) : TFallback;
57
25
  /**
58
26
  * The action paths this application has, or the shape of one when it has not
59
27
  * said.
@@ -62,7 +30,7 @@ export type FromRegistry<TKey extends string, TFallback> = TKey extends keyof Ro
62
30
  * ending in `Action`, or a `Controller@method` reference. It catches a shape
63
31
  * mistake and nothing else, which is why declaring the real set is worth doing.
64
32
  */
65
- export type KnownActionPath = FromRegistry<'actions', `Actions/${string}Action` | `actions/${string}Action` | `${string}Controller@${string}`>;
33
+ export type KnownActionPath = FromRegistry<'actions', string, `Actions/${string}Action` | `actions/${string}Action` | `${string}Controller@${string}`>;
66
34
  /**
67
35
  * The middleware aliases this application registers, or any string.
68
36
  *
@@ -71,7 +39,7 @@ export type KnownActionPath = FromRegistry<'actions', `Actions/${string}Action`
71
39
  * to the group - so the union has to contain both or the group form stops
72
40
  * type-checking the moment anything is declared.
73
41
  */
74
- export type KnownMiddlewareName = FromRegistry<'middleware', string>;
42
+ export type KnownMiddlewareName = FromRegistry<'middleware', string, string>;
75
43
  /**
76
44
  * A middleware reference: an alias, or an alias with parameters.
77
45
  *
@@ -86,7 +54,7 @@ export type KnownMiddlewareName = FromRegistry<'middleware', string>;
86
54
  */
87
55
  export type MiddlewareReference = BuiltInMiddleware | `${BuiltInMiddleware}:${string}` | KnownMiddlewareName | `${KnownMiddlewareName}:${string}`;
88
56
  /** The named routes this application registers, as `name → path`. */
89
- export type KnownRoutes = FromRegistry<'routes', Record<string, string>>;
57
+ export type KnownRoutes = FromRegistry<'routes', Record<string, string>, Record<string, string>>;
90
58
  /** The names of those routes, or any string when none are declared. */
91
59
  export type KnownRouteName = keyof KnownRoutes extends never ? string : Extract<keyof KnownRoutes, string>;
92
60
  /** The path a declared route name resolves to, or any path when it is not declared. */
package/dist/types.d.ts CHANGED
@@ -1906,4 +1906,4 @@ export interface EnhancedLaravelModelBindingMethods {
1906
1906
  */
1907
1907
  scopedBindings: <Parent extends string, Child extends string>(bindings: Record<Child, Parent>) => MiddlewareHandler;
1908
1908
  }
1909
- export type { FromRegistry, KnownActionPath, KnownMiddlewareName, KnownRouteName, KnownRoutes, MiddlewareReference, PathForRouteName, RouterTypeRegistry, } from './types/registry';
1909
+ export type { FromRegistry, KnownActionPath, KnownMiddlewareName, KnownRouteName, KnownRoutes, MiddlewareReference, PathForRouteName, } from './types/registry';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/bun-router",
3
3
  "type": "module",
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "description": "A fast, type-safe router for Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",