route-sprout 2.0.0 → 3.0.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/README.md CHANGED
@@ -41,8 +41,8 @@ const Api = root([
41
41
 
42
42
  Api.invoices(); // "/invoices"
43
43
  Api.invoices("page=1"); // "/invoices?page=1"
44
- Api.invoices.id("abc")("a=1"); // "/invoices/abc?a=1"
45
- Api.invoices.id("abc").customers(); // "/invoices/abc/customers"
44
+ Api.invoices.$id("abc")("a=1"); // "/invoices/abc?a=1"
45
+ Api.invoices.$id("abc").customers(); // "/invoices/abc/customers"
46
46
  ```
47
47
 
48
48
  ---
@@ -69,7 +69,7 @@ When you have lots of endpoints, you usually end up with:
69
69
  This DSL gives you:
70
70
 
71
71
  - a single, declarative source of truth
72
- - fluent, discoverable usage (`Api.invoices.id("x").customers()`)
72
+ - fluent, discoverable usage (`Api.invoices.$id("x").customers()`)
73
73
  - TypeScript autocomplete and type checking from **usage**, not comments
74
74
 
75
75
  ---
@@ -111,7 +111,7 @@ The `name` is only the **property key**. It is **not** inserted into the path.
111
111
 
112
112
  ```ts
113
113
  path("invoices", [slot("id")]);
114
- // Api.invoices.id("abc")() -> "/invoices/abc"
114
+ // Api.invoices.$id("abc")() -> "/invoices/abc"
115
115
  ```
116
116
 
117
117
  With children:
@@ -124,7 +124,7 @@ path("invoices", [
124
124
  ]),
125
125
  ]);
126
126
 
127
- // Api.invoices.id("abc").customers() -> "/invoices/abc/customers"
127
+ // Api.invoices.$id("abc").customers() -> "/invoices/abc/customers"
128
128
  ```
129
129
 
130
130
  ### `wrap(name, predicate, children?)`
@@ -143,12 +143,29 @@ path("core", [
143
143
  ]),
144
144
  ]);
145
145
 
146
- Api.core.admin({ isAdmin: true }).invoices(); // "/core/admin/invoices"
147
- Api.core.admin({ isAdmin: false }).invoices(); // "/core/invoices"
146
+ Api.core.$admin({ isAdmin: true }).invoices(); // "/core/admin/invoices"
147
+ Api.core.$admin({ isAdmin: false }).invoices(); // "/core/invoices"
148
148
  ```
149
149
 
150
150
  > `wrap` is ideal for *well-known*, reusable gates: `admin`, `v2`, `tenant`, etc.
151
151
 
152
+ ### `pick(name, segments, children?)`
153
+
154
+ An enumerated segment group *defined in the tree*.
155
+
156
+ ```ts
157
+ type User = { isAdmin: boolean } | null;
158
+
159
+ path("core", [
160
+ pick("role", { admin: "admin", user: ["user", "role"] }, [
161
+ path("invoices", [keep()]),
162
+ ]),
163
+ ]);
164
+
165
+ Api.core.$role("admin").invoices(); // "/core/admin/invoices"
166
+ Api.core.$role("user").invoices(); // "/core/user/role/invoices"
167
+ ```
168
+
152
169
  ### `.$when(cond, segment | segment[])`
153
170
 
154
171
  Ad‑hoc conditional segment insertion at **runtime**, anywhere in the chain.
@@ -156,7 +173,7 @@ Ad‑hoc conditional segment insertion at **runtime**, anywhere in the chain.
156
173
  ```ts
157
174
  Api.core.$when(isAdmin, "admin").invoices();
158
175
  Api.core.$when(true, ["tenant", tenantId]).invoices();
159
- Api.invoices.id("abc").$when(flags.preview, "preview").activities();
176
+ Api.invoices.$id("abc").$when(flags.preview, "preview").activities();
160
177
  ```
161
178
 
162
179
  - `cond = false` → no-op
@@ -216,18 +233,18 @@ export const Api = root([
216
233
 
217
234
  // usage
218
235
  Api.invoices(); // "/invoices"
219
- Api.invoices.id("123").customers(); // "/invoices/123/customers"
236
+ Api.invoices.$id("123").customers(); // "/invoices/123/customers"
220
237
 
221
238
  // runtime insert
222
239
  Api.core.$when(true, "v2").invoices(); // "/core/v2/invoices"
223
- Api.core.admin({ isAdmin: true }).$when(true, "v2").invoices(); // "/core/admin/v2/invoices"
240
+ Api.core.$admin({ isAdmin: true }).$when(true, "v2").invoices(); // "/core/admin/v2/invoices"
224
241
  ```
225
242
 
226
243
  ### Autocomplete-friendly patterns
227
244
  Because everything is computed from the definition tree, your editor can autocomplete:
228
245
 
229
246
  - paths (`Api.invoices`, `Api.orders.export`)
230
- - slots (`Api.invoices.id(…)`)
247
+ - slots (`Api.invoices.$id(…)`)
231
248
  - nested children (`…id("x").customers()`)
232
249
 
233
250
  ---
@@ -237,9 +254,10 @@ Because everything is computed from the definition tree, your editor can autocom
237
254
  ### Exports
238
255
 
239
256
  - `root(defs)`
240
- - `path(name, rest?)`
241
- - `slot(name, rest?)`
242
- - `wrap(name, when, rest?)`
257
+ - `path(name, defs?)`
258
+ - `slot(name, defs?)`
259
+ - `wrap(name, when, defs?)`
260
+ - `pick(name, mode, defs?)`
243
261
  - `keep()`
244
262
 
245
263
  ### Path level builders
@@ -272,7 +290,7 @@ const Api = root([
272
290
  path("invoices", [keep(), slot("id")]),
273
291
  ]);
274
292
 
275
- Api.invoices.id("123")(); // "/invoices/123"
293
+ Api.invoices.$id("123")(); // "/invoices/123"
276
294
  ```
277
295
 
278
296
  #### `route-sprout/dialect-step`
@@ -302,7 +320,7 @@ const Api = grow([
302
320
  ]),
303
321
  ]);
304
322
 
305
- Api.core.admin({ isAdmin: true }).jobs(); // "/core/admin/jobs"
323
+ Api.core.$admin({ isAdmin: true }).jobs(); // "/core/admin/jobs"
306
324
  ```
307
325
 
308
326
  #### `route-sprout/dialect-node`
@@ -315,7 +333,7 @@ const Api = link([
315
333
  node("tasks", [base(), bind("id", [node("logs")])]),
316
334
  ]);
317
335
 
318
- Api.tasks.id("x").logs(); // "/tasks/x/logs"
336
+ Api.tasks.$id("x").logs(); // "/tasks/x/logs"
319
337
  ```
320
338
 
321
339
  ### Mix-and-match?
@@ -347,7 +365,7 @@ import { root, path, slot, keep } from "route-sprout";
347
365
  test("builds routes", () => {
348
366
  const Api = root([path("invoices", [keep(), slot("id")])] as const);
349
367
  expect(Api.invoices()).toBe("/invoices");
350
- expect(Api.invoices.id("x")()).toBe("/invoices/x");
368
+ expect(Api.invoices.$id("x")()).toBe("/invoices/x");
351
369
  });
352
370
  ```
353
371
 
package/dist/api.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var f=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var w=(t,e)=>{for(var a in e)f(t,a,{get:e[a],enumerable:!0})},b=(t,e,a,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of N(e))!P.call(t,s)&&s!==a&&f(t,s,{get:()=>e[s],enumerable:!(r=y(e,s))||r.enumerable});return t};var D=t=>b(f({},"__esModule",{value:!0}),t);var $={};w($,{keep:()=>R,path:()=>p,root:()=>F,slot:()=>k,wrap:()=>x});module.exports=D($);var g=t=>t.replace(/-([a-zA-Z0-9])/g,(e,a)=>a.toUpperCase()),R=()=>({kind:"keep"}),p=(t,e)=>({kind:"path",name:S("path",t),uuid:g(t),rest:e??[]}),k=(t,e)=>({kind:"slot",name:S("slot",t),uuid:g(t),rest:e??[]}),x=(t,e,a)=>({kind:"wrap",name:S("wrap",t),uuid:g(t),when:e,rest:a??[]}),K=/^[A-Za-z_][A-Za-z0-9_]*$/;function S(t,e){if(t==="path"&&e==="")return e.trim();if(!e)throw new Error(`${t} name cannot be empty`);if(!K.test(e))throw new Error(`${t} name "${e}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return e.trim()}var m=(t,e)=>`/${t.filter(Boolean).join("/").replace("//{2,}/g","/")}${e?`?${e}`:""}`;function F(t){return u([],p("",t))}function u(t,e){let a=n=>n.rest.some(o=>o.kind==="keep"),r=e.kind==="slot"||e.kind==="wrap"?t:e.uuid?[...t,e.uuid]:t,s=a(e)?n=>m(r,n):Object.create(null);for(let n of e.rest)if(n.kind==="slot")n.rest.length===0?s[n.uuid]=o=>{let l=[...r,o];return c(d=>m(l,d),l,[])}:s[n.uuid]=o=>{let l=u([...r,o],n);return Object.assign(a(n)?i=>m([...r,o],i):Object.create(null),l)};else if(n.kind==="path")if(n.rest.length===0){let o=[...r,n.uuid],l=i=>m(o,i);s[n.uuid]=c(l,o,[])}else s[n.uuid]=u(r,n);else n.kind==="wrap"&&(s[n.uuid]=o=>{let i=n.when(o)?[...r,n.uuid]:r,d=u(i,n);return Object.assign(a(n)?h=>m(i,h):Object.create(null),d)});return c(s,r,e.rest)}function c(t,e,a){let r=(s,n)=>{let o=s?[...e,...Array.isArray(n)?n:[n]]:e;return a.length===0&&typeof t=="function"?c(i=>m(o,i),o,a):u(o,p("",a))};return t.$when=r,t.$join=s=>r(!0,s),t}0&&(module.exports={keep,path,root,slot,wrap});
1
+ "use strict";var g=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var w=(t,e)=>{for(var s in e)g(t,s,{get:e[s],enumerable:!0})},y=(t,e,s,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of N(e))!S.call(t,o)&&o!==s&&g(t,o,{get:()=>e[o],enumerable:!(a=$(e,o))||a.enumerable});return t};var x=t=>y(g({},"__esModule",{value:!0}),t);var _={};w(_,{keep:()=>C,path:()=>p,pick:()=>b,root:()=>A,slot:()=>L,wrap:()=>P});module.exports=x(_);var u=t=>t.replace(/^-+/,"").replace(/-+$/,"").replace(/^_+/,"").replace(/_+$/,"").replace(/-([a-zA-Z0-9])/g,(e,s)=>s.toUpperCase()).replace(/_([a-zA-Z0-9])/g,(e,s)=>s.toUpperCase()),D=/^[A-Za-z_-][A-Za-z0-9_-]*$/;function m(t,e){if(t==="path"&&e==="")return e.trim();if(!e)throw new Error(`${t} name cannot be empty`);if(!D.test(e))throw new Error(`${t} name "${e}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return e.trim()}var C=()=>({kind:"keep"}),p=(t,e)=>({kind:"path",name:m("path",t),uuid:u(t),list:e??[]}),L=(t,e)=>({kind:"slot",name:m("slot",t),uuid:`$${u(t)}`,list:e??[]}),P=(t,e,s)=>({kind:"wrap",name:m("wrap",t),uuid:`$${u(t)}`,when:e,list:s??[]}),b=(t,e,s)=>({kind:"pick",name:m("pick",t),uuid:`$${u(t)}`,mode:e,list:s??[]}),A=t=>l([],p("",t)),T=(t,e)=>`/${t.filter(Boolean).join("/").replace(/\/{2,}/g,"/")}${e?`?${e}`:""}`;function l(t,e){let s=n=>n.list.some(r=>r.kind==="keep"),a=e.kind==="path"&&e.name?[...t,e.name]:t,o=i(s(e),a);for(let n of e.list){if(n.kind!=="keep"&&n.uuid in o)throw new Error(`Duplicate uuid "${String(n.uuid)}" under "${a.join("/")||"/"}"`);if(n.kind==="slot")o[n.uuid]=function(f){let d=[...a,f];return n.list.length===0?c(i(!0,d),d,[]):Object.assign(i(s(n),d),l(d,n))};else if(n.kind==="path")if(n.list.length===0){let r=[...a,n.name];o[n.uuid]=c(i(!0,r),r,[])}else o[n.uuid]=l(a,n);else n.kind==="wrap"?o[n.uuid]=function(f){let h=n.when(f)?[...a,n.name]:a,k=l(h,n);return Object.assign(i(s(n),h),k)}:n.kind==="pick"&&(o[n.uuid]=r=>{if(n.mode[r])return l([...a,...n.mode[r]],p("",n.list));throw new Error(`pick("${n.name}") got unknown value: ${String(r)}`)})}return c(o,a,e.list)}function c(t,e,s){let a=(o,n)=>{let r=o?[...e,...Array.isArray(n)?n:[n]]:e;return s.length===0&&typeof t=="function"?c(i(!0,r),r,s):l(r,p("",s))};return t.$when=a,t.$join=function(n){return a(!0,n)},t}var i=(t,e)=>t?s=>T(e,s):Object.create(null);0&&(module.exports={keep,path,pick,root,slot,wrap});
2
2
  //# sourceMappingURL=api.cjs.map
package/dist/api.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/api.ts"],"sourcesContent":["import {\n\tKebabToCamel,\n\tKeep,\n\tPath,\n\tPathDef,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamel = (s: string) => s.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\ntype KeyFromSeg<S extends string> = KebabToCamel<S>\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Path<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Slot<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\trest?: Rest\n): Wrap<Name, KeyFromSeg<Name>, Rest, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\twhen,\n\trest: (rest ?? []) as Rest,\n})\n\nconst IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path.filter(Boolean).join('/').replace('/\\/{2,}/g', '/')}${search ? `?${search}` : ''}`\n\n// ---------- Typed root signature ----------\nexport function root<const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> {\n\treturn buildPath([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n}\n\nfunction buildPath(prefix: Segment[], def: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.rest.some((c: any) => c.kind === 'keep')\n\tconst allPath =\n\t\tdef.kind === 'slot' || def.kind === 'wrap'\n\t\t\t? prefix\n\t\t\t: def.uuid\n\t\t\t\t? [...prefix, def.uuid]\n\t\t\t\t: prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = hasKeep(def)\n\t\t? (search?: SParams) => url(allPath, search)\n\t\t: Object.create(null)\n\n\tfor (const child of def.rest) {\n\t\tif (child.kind === 'slot') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\tconst leafPath = [...allPath, param]\n\t\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\t\treturn attachWhenAndJoin(fn, leafPath, [])\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\t// Build subtree for nested parts under :id\n\t\t\t\t\t// Synthetic path with empty name so we don't add extra segment.\n\t\t\t\t\tconst subTree = buildPath([...allPath, param], child)\n\n\t\t\t\t\t// Attach children (info, activities, etc.) to that function\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\thasKeep(child)\n\t\t\t\t\t\t\t? (search?: SParams) => url([...allPath, param], search)\n\t\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\t\tsubTree\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.uuid]\n\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(fn, leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildPath(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = (arg: unknown) => {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.uuid] : allPath\n\t\t\t\tconst subTree = buildPath(wrapped, child as any)\n\n\t\t\t\treturn Object.assign(\n\t\t\t\t\t// if wrap has keep(), it becomes callable at that point\n\t\t\t\t\thasKeep(child as any)\n\t\t\t\t\t\t? (search?: SParams) => url(wrapped, search)\n\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\tsubTree\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, def.rest)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], rest: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (rest.length === 0 && typeof target === 'function') {\n\t\t\tconst leaf: any = (search?: SParams) => url(nextPath, search)\n\t\t\treturn attachWhenAndJoin(leaf, nextPath, rest)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildPath(nextPath, path('', rest))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = (seg: Segment | readonly Segment[]) => when(true, seg)\n\n\treturn target\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAP,GAcA,IAAMQ,EAAWC,GAAcA,EAAE,QAAQ,kBAAmB,CAACC,EAAGC,IAAMA,EAAE,YAAY,CAAC,EAIxET,EAAO,KAAa,CAAE,KAAM,MAAO,GAEnCC,EAAO,CAInBS,EACAC,KACyC,CACzC,KAAM,OACN,KAAMC,EAAgB,O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CAAC,GAAGD,EAAU,GAAI,MAAM,QAAQE,CAAG,EAAIA,EAAM,CAACA,CAAG,CAAE,EAAIF,EAG/E,OAAIvB,EAAK,SAAW,GAAK,OAAOc,GAAW,WAEnCI,EADYZ,GAAqBD,EAAIqB,EAAUpB,CAAM,EAC7BoB,EAAU1B,CAAI,EAKvCQ,EAAUkB,EAAUpC,EAAK,GAAIU,CAAI,CAAC,CAC1C,EAEA,OAAAc,EAAO,MAAQZ,EACfY,EAAO,MAASW,GAAsCvB,EAAK,GAAMuB,CAAG,EAE7DX,CACR","names":["api_exports","__export","keep","path","root","slot","wrap","__toCommonJS","toCamel","s","_","c","name","rest","assertValidName","when","IDENT","kind","url","search","defs","buildPath","prefix","def","hasKeep","pathDef","allPath","target","child","param","leafPath","attachWhenAndJoin","subTree","fn","arg","wrapped","basePath","cond","seg","nextPath"]}
1
+ {"version":3,"sources":["../src/api.ts"],"sourcesContent":["import {\n\tKeep,\n\tPath,\n\tPathDef,\n\tPick,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tToCamelCase,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamelCase = <S extends string>(s: S) =>\n\ts\n\t\t.replace(/^-+/, '')\n\t\t.replace(/-+$/, '')\n\t\t.replace(/^_+/, '')\n\t\t.replace(/_+$/, '')\n\t\t.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\n\t\t.replace(/_([a-zA-Z0-9])/g, (_, c) => c.toUpperCase()) as ToCamelCase<S>\n\nconst IDENT = /^[A-Za-z_-][A-Za-z0-9_-]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap' | 'pick',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Path<Name, ToCamelCase<Name>, List> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamelCase(name),\n\tlist: (list ?? []) as List,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Slot<Name, `$${ToCamelCase<Name>}`, List> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tlist: (list ?? []) as List,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\tlist?: List\n): Wrap<Name, `$${ToCamelCase<Name>}`, List, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: `$${toCamelCase(name)}`,\n\twhen,\n\tlist: (list ?? []) as List,\n})\n\nexport const pick = <\n\tconst Name extends string,\n\tconst Mode extends Record<string, readonly Segment[]>,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tmode: Mode,\n\tlist?: List\n): Pick<Name, `$${ToCamelCase<Name>}`, Mode, List> => ({\n\tkind: 'pick',\n\tname: assertValidName('pick', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tmode,\n\tlist: (list ?? []) as List,\n})\n\nexport const root = <const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> =>\n\tbuildNode([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path\n\t\t.filter(Boolean)\n\t\t.join('/')\n\t\t.replace(/\\/{2,}/g, '/')}${search ? `?${search}` : ''}`\n\nfunction buildNode(prefix: Segment[], parent: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.list.some((node: any) => node.kind === 'keep')\n\tconst allPath = parent.kind === 'path' && parent.name ? [...prefix, parent.name] : prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = makeTarget(hasKeep(parent), allPath)\n\n\tfor (const child of parent.list) {\n\t\tif (child.kind !== 'keep') {\n\t\t\tif (child.uuid in target) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Duplicate uuid \"${String(child.uuid)}\" under \"${allPath.join('/') || '/'}\"`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tif (child.kind === 'slot') {\n\t\t\ttarget[child.uuid] = function bind(param: Segment) {\n\t\t\t\tconst next = [...allPath, param]\n\n\t\t\t\t// leaf slot => callable endpoint directly\n\t\t\t\tif (child.list.length === 0) {\n\t\t\t\t\treturn attachWhenAndJoin(makeTarget(true, next), next, [])\n\t\t\t\t}\n\n\t\t\t\t// non-leaf => subtree (optionally callable if keep())\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), next), buildNode(next, child))\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.list.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.name]\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(makeTarget(true, leafPath), leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildNode(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = function wrap(arg: unknown) {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.name] : allPath\n\t\t\t\tconst subTree = buildNode(wrapped, child)\n\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), wrapped), subTree)\n\t\t\t}\n\t\t} else if (child.kind === 'pick') {\n\t\t\ttarget[child.uuid] = (value: keyof typeof child.mode) => {\n\t\t\t\tif (child.mode[value]) {\n\t\t\t\t\treturn buildNode([...allPath, ...child.mode[value]], path('', child.list))\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`pick(\"${child.name}\") got unknown value: ${String(value)}`)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, parent.list)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], list: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (list.length === 0 && typeof target === 'function') {\n\t\t\treturn attachWhenAndJoin(makeTarget(true, nextPath), nextPath, list)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildNode(nextPath, path('', list))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = function join(seg: Segment | readonly Segment[]) {\n\t\treturn when(true, seg)\n\t}\n\n\treturn target\n}\n\nconst makeTarget = (callable: boolean, currentPath: Segment[]) => {\n\treturn callable ? (search?: SParams) => url(currentPath, search) : Object.create(null)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAR,GAeA,IAAMS,EAAiCC,GACtCA,EACE,QAAQ,MAAO,EAAE,EACjB,QAAQ,MAAO,EAAE,EACjB,QAAQ,MAAO,EAAE,EACjB,QAAQ,MAAO,EAAE,EACjB,QAAQ,kBAAmB,CAACC,EAAGC,IAAMA,EAAE,YAAY,CAAC,EACpD,QAAQ,kBAAmB,CAACD,EAAG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,EAAM,OAAS,SACzBF,EAAOE,EAAM,IAAI,EAAKQ,GAAmC,CACxD,GAAIR,EAAM,KAAKQ,CAAK,EACnB,OAAOnB,EAAU,CAAC,GAAGQ,EAAS,GAAGG,EAAM,KAAKQ,CAAK,CAAC,EAAGrC,EAAK,GAAI6B,EAAM,IAAI,CAAC,EAEzE,MAAM,IAAI,MAAM,SAASA,EAAM,IAAI,yBAAyB,OAAOQ,CAAK,CAAC,EAAE,CAE7E,EAEF,CAEA,OAAOL,EAAkBL,EAAQD,EAASJ,EAAO,IAAI,CACtD,CAEA,SAASU,EAAkBL,EAAaW,EAAqBxB,EAA0B,CACtF,IAAMC,EAAO,CAACwB,EAAeC,IAAsC,CAClE,IAAMC,EAAWF,EAAO,CAAC,GAAGD,EAAU,GAAI,MAAM,QAAQE,CAAG,EAAIA,EAAM,CAACA,CAAG,CAAE,EAAIF,EAG/E,OAAIxB,EAAK,SAAW,GAAK,OAAOa,GAAW,WACnCK,EAAkBJ,EAAW,GAAMa,CAAQ,EAAGA,EAAU3B,CAAI,EAK7DI,EAAUuB,EAAUzC,EAAK,GAAIc,CAAI,CAAC,CAC1C,EAEA,OAAAa,EAAO,MAAQZ,EACfY,EAAO,MAAQ,SAAca,EAAmC,CAC/D,OAAOzB,EAAK,GAAMyB,CAAG,CACtB,EAEOb,CACR,CAEA,IAAMC,EAAa,CAACc,EAAmBC,IAC/BD,EAAYtB,GAAqBD,EAAIwB,EAAavB,CAAM,EAAI,OAAO,OAAO,IAAI","names":["api_exports","__export","keep","path","pick","root","slot","wrap","__toCommonJS","toCamelCase","s","_","c","IDENT","assertValidName","kind","name","list","when","mode","defs","buildNode","url","search","prefix","parent","hasKeep","pathDef","node","allPath","target","makeTarget","child","param","next","attachWhenAndJoin","leafPath","arg","wrapped","subTree","value","basePath","cond","seg","nextPath","callable","currentPath"]}
package/dist/api.d.cts CHANGED
@@ -1,6 +1,9 @@
1
1
  // ---------- Helpers ----------------------
2
- type KebabToCamel<S extends string> = S extends `${infer A}-${infer B}`
3
- ? `${A}${Capitalize<KebabToCamel<B>>}`
2
+ type Delimiter = '_' | '-'
3
+ type ToCamelCase<S extends string> = S extends `${infer A}${Delimiter}${infer B}`
4
+ ? A extends ''
5
+ ? ToCamelCase<B>
6
+ : `${A}${Capitalize<ToCamelCase<B>>}`
4
7
  : S
5
8
 
6
9
  // ---------- Shared public types ----------
@@ -13,93 +16,84 @@ type Keep = { kind: 'keep' }
13
16
  type Path<
14
17
  Name extends string = string,
15
18
  Uuid extends string = string,
16
- Rest extends readonly PathDef[] = readonly PathDef[],
17
- > = { kind: 'path'; name: Name; uuid: Uuid; rest: Rest }
19
+ List extends readonly PathDef[] = readonly PathDef[],
20
+ > = { kind: 'path'; name: Name; uuid: Uuid; list: List }
18
21
 
19
22
  type Slot<
20
23
  Name extends string = string,
21
24
  Uuid extends string = string,
22
- Rest extends readonly PathDef[] = readonly PathDef[],
23
- > = { kind: 'slot'; name: Name; uuid: Uuid; rest: Rest }
25
+ List extends readonly PathDef[] = readonly PathDef[],
26
+ > = { kind: 'slot'; name: Name; uuid: Uuid; list: List }
24
27
 
25
28
  type Wrap<
26
29
  Name extends string = string,
27
30
  Uuid extends string = string,
28
- Rest extends readonly PathDef[] = readonly PathDef[],
31
+ List extends readonly PathDef[] = readonly PathDef[],
29
32
  Args = unknown,
30
- > = { kind: 'wrap'; name: Name; uuid: Uuid; rest: Rest; when: (args: Args) => boolean }
33
+ > = { kind: 'wrap'; name: Name; uuid: Uuid; list: List; when: (args: Args) => boolean }
31
34
 
32
- type SlotDef =
33
- | Path<string, readonly PathDef[]>
34
- | Slot<string, readonly PathDef[]>
35
- | Wrap<string, readonly PathDef[], any>
36
- type PathDef = SlotDef | Keep
35
+ type Pick<
36
+ Name extends string = string,
37
+ Uuid extends string = string,
38
+ Mode extends Record<string, readonly Segment[]> = Record<string, readonly Segment[]>,
39
+ List extends readonly PathDef[] = readonly PathDef[],
40
+ > = { kind: 'pick'; name: Name; uuid: Uuid; mode: Mode; list: List }
41
+ type PathDef = Path | Slot | Wrap | Pick | Keep
37
42
 
38
43
  // ---------- Type-level route builder ----------
39
- interface Whenable {
44
+ type PickKey<M> = Extract<keyof M, string>
45
+ type List<Defs extends readonly PathDef[]> = Defs[number]
46
+ type CallIfKeep<U, Props> =
47
+ Extract<U, Keep> extends never ? Props : ((search?: SParams) => string) & Props
48
+ type WithWhen<T> = T & {
40
49
  $when(cond: boolean, seg: Segment | readonly Segment[]): this
41
50
  $join(seg: Segment | readonly Segment[]): this
42
51
  }
43
52
 
44
- type HasKeep<Rest extends readonly PathDef[]> =
45
- Extract<Rest[number], Keep> extends never ? false : true
46
-
47
- type NonKeepChildren<Rest extends readonly PathDef[]> = Exclude<Rest[number], Keep>
48
-
49
- type PropsFromChildren<Rest extends readonly PathDef[]> = {
50
- [C in NonKeepChildren<Rest> as C extends { name: infer N extends string }
51
- ? N
53
+ type PropsFromChildren<Defs extends readonly PathDef[]> = {
54
+ [C in Exclude<List<Defs>, Keep> as C extends { uuid: infer N extends string }
55
+ ? ToCamelCase<N>
52
56
  : never]: C extends Path<any, any, any>
53
57
  ? RouteFromPath<C>
54
58
  : C extends Slot<any, any, any>
55
59
  ? RouteFromSlot<C>
56
60
  : C extends Wrap<any, any, any, any>
57
61
  ? RouteFromWrap<C>
58
- : never
62
+ : C extends Pick<any, any, any, any>
63
+ ? RouteFromPick<C>
64
+ : never
59
65
  }
60
66
 
61
- type WithWhen<T> = T & Whenable
62
-
63
- // Example: apply it to the outputs
64
- type RouteFromPath<N extends Path<any, any, any>> = WithWhen<
65
- N['rest'] extends readonly []
67
+ type RouteFromPath<Node extends Path<any, any, any>> = WithWhen<
68
+ Node['list'] extends readonly []
66
69
  ? (search?: SParams) => string
67
- : HasKeep<N['rest']> extends true
68
- ? ((search?: SParams) => string) & PropsFromChildren<N['rest']>
69
- : PropsFromChildren<N['rest']>
70
+ : CallIfKeep<List<Node['list']>, PropsFromChildren<Node['list']>>
70
71
  >
71
72
 
72
- type SlotResult<Rest extends readonly PathDef[]> = WithWhen<
73
- Rest extends readonly []
73
+ type RouteFromSlot<Node extends Slot<any, any, any>> = (param: Segment) => SlotResult<Node['list']>
74
+ type SlotResult<Defs extends readonly PathDef[]> = WithWhen<
75
+ Defs extends readonly []
74
76
  ? (search?: SParams) => string
75
- : HasKeep<Rest> extends true
76
- ? ((search?: SParams) => string) & PropsFromChildren<Rest>
77
- : PropsFromChildren<Rest>
77
+ : CallIfKeep<List<Defs>, PropsFromChildren<Defs>>
78
78
  >
79
79
 
80
- type RouteFromSlot<I extends Slot<any, any, any>> = (param: Segment) => SlotResult<I['rest']>
81
-
82
- type WrapArg<W extends Wrap<any, any, any, any>> = Parameters<W['when']>[0]
83
-
84
- type WrapResult<Rest extends readonly PathDef[]> = WithWhen<
85
- HasKeep<Rest> extends true
86
- ? ((search?: SParams) => string) & PropsFromChildren<Rest>
87
- : PropsFromChildren<Rest>
88
- >
80
+ type RouteFromWrap<W extends Wrap<any, any, any, any>> = (
81
+ arg: Parameters<W['when']>[0]
82
+ ) => WithWhen<CallIfKeep<List<W['list']>, PropsFromChildren<W['list']>>>
89
83
 
90
- type RouteFromWrap<W extends Wrap<any, any, any, any>> = (arg: WrapArg<W>) => WrapResult<W['rest']>
84
+ type RouteFromPick<P extends Pick<any, any, any, any>> = (
85
+ val: PickKey<P['mode']>
86
+ ) => RoutesFromDefs<P['list']>
91
87
 
92
88
  type RoutesFromDefs<Defs extends readonly PathDef[]> = WithWhen<
93
- HasKeep<Defs> extends true
94
- ? ((search?: SParams) => string) & PropsFromChildren<Defs>
95
- : PropsFromChildren<Defs>
89
+ CallIfKeep<List<Defs>, PropsFromChildren<Defs>>
96
90
  >
97
91
 
98
- type KeyFromSeg<S extends string> = KebabToCamel<S>;
99
92
  declare const keep: () => Keep;
100
- declare const path: <const Name extends string, const Rest extends readonly PathDef[] = readonly []>(name: Name, rest?: Rest) => Path<Name, KeyFromSeg<Name>, Rest>;
101
- declare const slot: <const Name extends string, const Rest extends readonly PathDef[] = readonly []>(name: Name, rest?: Rest) => Slot<Name, KeyFromSeg<Name>, Rest>;
102
- declare const wrap: <const Name extends string, const Rest extends readonly PathDef[] = readonly [], Args = unknown>(name: Name, when: (args: Args) => boolean, rest?: Rest) => Wrap<Name, KeyFromSeg<Name>, Rest, Args>;
103
- declare function root<const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs>;
93
+ declare const path: <const Name extends string, const List extends readonly PathDef[] = readonly []>(name: Name, list?: List) => Path<Name, ToCamelCase<Name>, List>;
94
+ declare const slot: <const Name extends string, const List extends readonly PathDef[] = readonly []>(name: Name, list?: List) => Slot<Name, `$${ToCamelCase<Name>}`, List>;
95
+ declare const wrap: <const Name extends string, const List extends readonly PathDef[] = readonly [], Args = unknown>(name: Name, when: (args: Args) => boolean, list?: List) => Wrap<Name, `$${ToCamelCase<Name>}`, List, Args>;
96
+ declare const pick: <const Name extends string, const Mode extends Record<string, readonly Segment[]>, const List extends readonly PathDef[] = readonly []>(name: Name, mode: Mode, list?: List) => Pick<Name, `$${ToCamelCase<Name>}`, Mode, List>;
97
+ declare const root: <const Defs extends readonly PathDef[]>(defs: Defs) => RoutesFromDefs<Defs>;
104
98
 
105
- export { keep, path, root, slot, wrap };
99
+ export { keep, path, pick, root, slot, wrap };
package/dist/api.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  // ---------- Helpers ----------------------
2
- type KebabToCamel<S extends string> = S extends `${infer A}-${infer B}`
3
- ? `${A}${Capitalize<KebabToCamel<B>>}`
2
+ type Delimiter = '_' | '-'
3
+ type ToCamelCase<S extends string> = S extends `${infer A}${Delimiter}${infer B}`
4
+ ? A extends ''
5
+ ? ToCamelCase<B>
6
+ : `${A}${Capitalize<ToCamelCase<B>>}`
4
7
  : S
5
8
 
6
9
  // ---------- Shared public types ----------
@@ -13,93 +16,84 @@ type Keep = { kind: 'keep' }
13
16
  type Path<
14
17
  Name extends string = string,
15
18
  Uuid extends string = string,
16
- Rest extends readonly PathDef[] = readonly PathDef[],
17
- > = { kind: 'path'; name: Name; uuid: Uuid; rest: Rest }
19
+ List extends readonly PathDef[] = readonly PathDef[],
20
+ > = { kind: 'path'; name: Name; uuid: Uuid; list: List }
18
21
 
19
22
  type Slot<
20
23
  Name extends string = string,
21
24
  Uuid extends string = string,
22
- Rest extends readonly PathDef[] = readonly PathDef[],
23
- > = { kind: 'slot'; name: Name; uuid: Uuid; rest: Rest }
25
+ List extends readonly PathDef[] = readonly PathDef[],
26
+ > = { kind: 'slot'; name: Name; uuid: Uuid; list: List }
24
27
 
25
28
  type Wrap<
26
29
  Name extends string = string,
27
30
  Uuid extends string = string,
28
- Rest extends readonly PathDef[] = readonly PathDef[],
31
+ List extends readonly PathDef[] = readonly PathDef[],
29
32
  Args = unknown,
30
- > = { kind: 'wrap'; name: Name; uuid: Uuid; rest: Rest; when: (args: Args) => boolean }
33
+ > = { kind: 'wrap'; name: Name; uuid: Uuid; list: List; when: (args: Args) => boolean }
31
34
 
32
- type SlotDef =
33
- | Path<string, readonly PathDef[]>
34
- | Slot<string, readonly PathDef[]>
35
- | Wrap<string, readonly PathDef[], any>
36
- type PathDef = SlotDef | Keep
35
+ type Pick<
36
+ Name extends string = string,
37
+ Uuid extends string = string,
38
+ Mode extends Record<string, readonly Segment[]> = Record<string, readonly Segment[]>,
39
+ List extends readonly PathDef[] = readonly PathDef[],
40
+ > = { kind: 'pick'; name: Name; uuid: Uuid; mode: Mode; list: List }
41
+ type PathDef = Path | Slot | Wrap | Pick | Keep
37
42
 
38
43
  // ---------- Type-level route builder ----------
39
- interface Whenable {
44
+ type PickKey<M> = Extract<keyof M, string>
45
+ type List<Defs extends readonly PathDef[]> = Defs[number]
46
+ type CallIfKeep<U, Props> =
47
+ Extract<U, Keep> extends never ? Props : ((search?: SParams) => string) & Props
48
+ type WithWhen<T> = T & {
40
49
  $when(cond: boolean, seg: Segment | readonly Segment[]): this
41
50
  $join(seg: Segment | readonly Segment[]): this
42
51
  }
43
52
 
44
- type HasKeep<Rest extends readonly PathDef[]> =
45
- Extract<Rest[number], Keep> extends never ? false : true
46
-
47
- type NonKeepChildren<Rest extends readonly PathDef[]> = Exclude<Rest[number], Keep>
48
-
49
- type PropsFromChildren<Rest extends readonly PathDef[]> = {
50
- [C in NonKeepChildren<Rest> as C extends { name: infer N extends string }
51
- ? N
53
+ type PropsFromChildren<Defs extends readonly PathDef[]> = {
54
+ [C in Exclude<List<Defs>, Keep> as C extends { uuid: infer N extends string }
55
+ ? ToCamelCase<N>
52
56
  : never]: C extends Path<any, any, any>
53
57
  ? RouteFromPath<C>
54
58
  : C extends Slot<any, any, any>
55
59
  ? RouteFromSlot<C>
56
60
  : C extends Wrap<any, any, any, any>
57
61
  ? RouteFromWrap<C>
58
- : never
62
+ : C extends Pick<any, any, any, any>
63
+ ? RouteFromPick<C>
64
+ : never
59
65
  }
60
66
 
61
- type WithWhen<T> = T & Whenable
62
-
63
- // Example: apply it to the outputs
64
- type RouteFromPath<N extends Path<any, any, any>> = WithWhen<
65
- N['rest'] extends readonly []
67
+ type RouteFromPath<Node extends Path<any, any, any>> = WithWhen<
68
+ Node['list'] extends readonly []
66
69
  ? (search?: SParams) => string
67
- : HasKeep<N['rest']> extends true
68
- ? ((search?: SParams) => string) & PropsFromChildren<N['rest']>
69
- : PropsFromChildren<N['rest']>
70
+ : CallIfKeep<List<Node['list']>, PropsFromChildren<Node['list']>>
70
71
  >
71
72
 
72
- type SlotResult<Rest extends readonly PathDef[]> = WithWhen<
73
- Rest extends readonly []
73
+ type RouteFromSlot<Node extends Slot<any, any, any>> = (param: Segment) => SlotResult<Node['list']>
74
+ type SlotResult<Defs extends readonly PathDef[]> = WithWhen<
75
+ Defs extends readonly []
74
76
  ? (search?: SParams) => string
75
- : HasKeep<Rest> extends true
76
- ? ((search?: SParams) => string) & PropsFromChildren<Rest>
77
- : PropsFromChildren<Rest>
77
+ : CallIfKeep<List<Defs>, PropsFromChildren<Defs>>
78
78
  >
79
79
 
80
- type RouteFromSlot<I extends Slot<any, any, any>> = (param: Segment) => SlotResult<I['rest']>
81
-
82
- type WrapArg<W extends Wrap<any, any, any, any>> = Parameters<W['when']>[0]
83
-
84
- type WrapResult<Rest extends readonly PathDef[]> = WithWhen<
85
- HasKeep<Rest> extends true
86
- ? ((search?: SParams) => string) & PropsFromChildren<Rest>
87
- : PropsFromChildren<Rest>
88
- >
80
+ type RouteFromWrap<W extends Wrap<any, any, any, any>> = (
81
+ arg: Parameters<W['when']>[0]
82
+ ) => WithWhen<CallIfKeep<List<W['list']>, PropsFromChildren<W['list']>>>
89
83
 
90
- type RouteFromWrap<W extends Wrap<any, any, any, any>> = (arg: WrapArg<W>) => WrapResult<W['rest']>
84
+ type RouteFromPick<P extends Pick<any, any, any, any>> = (
85
+ val: PickKey<P['mode']>
86
+ ) => RoutesFromDefs<P['list']>
91
87
 
92
88
  type RoutesFromDefs<Defs extends readonly PathDef[]> = WithWhen<
93
- HasKeep<Defs> extends true
94
- ? ((search?: SParams) => string) & PropsFromChildren<Defs>
95
- : PropsFromChildren<Defs>
89
+ CallIfKeep<List<Defs>, PropsFromChildren<Defs>>
96
90
  >
97
91
 
98
- type KeyFromSeg<S extends string> = KebabToCamel<S>;
99
92
  declare const keep: () => Keep;
100
- declare const path: <const Name extends string, const Rest extends readonly PathDef[] = readonly []>(name: Name, rest?: Rest) => Path<Name, KeyFromSeg<Name>, Rest>;
101
- declare const slot: <const Name extends string, const Rest extends readonly PathDef[] = readonly []>(name: Name, rest?: Rest) => Slot<Name, KeyFromSeg<Name>, Rest>;
102
- declare const wrap: <const Name extends string, const Rest extends readonly PathDef[] = readonly [], Args = unknown>(name: Name, when: (args: Args) => boolean, rest?: Rest) => Wrap<Name, KeyFromSeg<Name>, Rest, Args>;
103
- declare function root<const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs>;
93
+ declare const path: <const Name extends string, const List extends readonly PathDef[] = readonly []>(name: Name, list?: List) => Path<Name, ToCamelCase<Name>, List>;
94
+ declare const slot: <const Name extends string, const List extends readonly PathDef[] = readonly []>(name: Name, list?: List) => Slot<Name, `$${ToCamelCase<Name>}`, List>;
95
+ declare const wrap: <const Name extends string, const List extends readonly PathDef[] = readonly [], Args = unknown>(name: Name, when: (args: Args) => boolean, list?: List) => Wrap<Name, `$${ToCamelCase<Name>}`, List, Args>;
96
+ declare const pick: <const Name extends string, const Mode extends Record<string, readonly Segment[]>, const List extends readonly PathDef[] = readonly []>(name: Name, mode: Mode, list?: List) => Pick<Name, `$${ToCamelCase<Name>}`, Mode, List>;
97
+ declare const root: <const Defs extends readonly PathDef[]>(defs: Defs) => RoutesFromDefs<Defs>;
104
98
 
105
- export { keep, path, root, slot, wrap };
99
+ export { keep, path, pick, root, slot, wrap };
package/dist/api.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a,b,c,d,e}from"./chunk-5ZW66SPO.js";export{a as keep,b as path,e as root,c as slot,d as wrap};
1
+ import{a,b,c,d,e,f}from"./chunk-TB22YO7J.js";export{a as keep,b as path,e as pick,f as root,c as slot,d as wrap};
2
2
  //# sourceMappingURL=api.js.map
@@ -0,0 +1,2 @@
1
+ var u=t=>t.replace(/^-+/,"").replace(/-+$/,"").replace(/^_+/,"").replace(/_+$/,"").replace(/-([a-zA-Z0-9])/g,(n,s)=>s.toUpperCase()).replace(/_([a-zA-Z0-9])/g,(n,s)=>s.toUpperCase()),k=/^[A-Za-z_-][A-Za-z0-9_-]*$/;function m(t,n){if(t==="path"&&n==="")return n.trim();if(!n)throw new Error(`${t} name cannot be empty`);if(!k.test(n))throw new Error(`${t} name "${n}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return n.trim()}var N=()=>({kind:"keep"}),f=(t,n)=>({kind:"path",name:m("path",t),uuid:u(t),list:n??[]}),S=(t,n)=>({kind:"slot",name:m("slot",t),uuid:`$${u(t)}`,list:n??[]}),w=(t,n,s)=>({kind:"wrap",name:m("wrap",t),uuid:`$${u(t)}`,when:n,list:s??[]}),y=(t,n,s)=>({kind:"pick",name:m("pick",t),uuid:`$${u(t)}`,mode:n,list:s??[]}),x=t=>l([],f("",t)),$=(t,n)=>`/${t.filter(Boolean).join("/").replace(/\/{2,}/g,"/")}${n?`?${n}`:""}`;function l(t,n){let s=e=>e.list.some(o=>o.kind==="keep"),a=n.kind==="path"&&n.name?[...t,n.name]:t,r=i(s(n),a);for(let e of n.list){if(e.kind!=="keep"&&e.uuid in r)throw new Error(`Duplicate uuid "${String(e.uuid)}" under "${a.join("/")||"/"}"`);if(e.kind==="slot")r[e.uuid]=function(p){let d=[...a,p];return e.list.length===0?c(i(!0,d),d,[]):Object.assign(i(s(e),d),l(d,e))};else if(e.kind==="path")if(e.list.length===0){let o=[...a,e.name];r[e.uuid]=c(i(!0,o),o,[])}else r[e.uuid]=l(a,e);else e.kind==="wrap"?r[e.uuid]=function(p){let g=e.when(p)?[...a,e.name]:a,h=l(g,e);return Object.assign(i(s(e),g),h)}:e.kind==="pick"&&(r[e.uuid]=o=>{if(e.mode[o])return l([...a,...e.mode[o]],f("",e.list));throw new Error(`pick("${e.name}") got unknown value: ${String(o)}`)})}return c(r,a,n.list)}function c(t,n,s){let a=(r,e)=>{let o=r?[...n,...Array.isArray(e)?e:[e]]:n;return s.length===0&&typeof t=="function"?c(i(!0,o),o,s):l(o,f("",s))};return t.$when=a,t.$join=function(e){return a(!0,e)},t}var i=(t,n)=>t?s=>$(n,s):Object.create(null);export{N as a,f as b,S as c,w as d,y as e,x as f};
2
+ //# sourceMappingURL=chunk-TB22YO7J.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/api.ts"],"sourcesContent":["import {\n\tKeep,\n\tPath,\n\tPathDef,\n\tPick,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tToCamelCase,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamelCase = <S extends string>(s: S) =>\n\ts\n\t\t.replace(/^-+/, '')\n\t\t.replace(/-+$/, '')\n\t\t.replace(/^_+/, '')\n\t\t.replace(/_+$/, '')\n\t\t.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\n\t\t.replace(/_([a-zA-Z0-9])/g, (_, c) => c.toUpperCase()) as ToCamelCase<S>\n\nconst IDENT = /^[A-Za-z_-][A-Za-z0-9_-]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap' | 'pick',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Path<Name, ToCamelCase<Name>, List> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamelCase(name),\n\tlist: (list ?? []) as List,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Slot<Name, `$${ToCamelCase<Name>}`, List> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tlist: (list ?? []) as List,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\tlist?: List\n): Wrap<Name, `$${ToCamelCase<Name>}`, List, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: `$${toCamelCase(name)}`,\n\twhen,\n\tlist: (list ?? []) as List,\n})\n\nexport const pick = <\n\tconst Name extends string,\n\tconst Mode extends Record<string, readonly Segment[]>,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tmode: Mode,\n\tlist?: List\n): Pick<Name, `$${ToCamelCase<Name>}`, Mode, List> => ({\n\tkind: 'pick',\n\tname: assertValidName('pick', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tmode,\n\tlist: (list ?? []) as List,\n})\n\nexport const root = <const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> =>\n\tbuildNode([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path\n\t\t.filter(Boolean)\n\t\t.join('/')\n\t\t.replace(/\\/{2,}/g, '/')}${search ? `?${search}` : ''}`\n\nfunction buildNode(prefix: Segment[], parent: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.list.some((node: any) => node.kind === 'keep')\n\tconst allPath = parent.kind === 'path' && parent.name ? [...prefix, parent.name] : prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = makeTarget(hasKeep(parent), allPath)\n\n\tfor (const child of parent.list) {\n\t\tif (child.kind !== 'keep') {\n\t\t\tif (child.uuid in target) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Duplicate uuid \"${String(child.uuid)}\" under \"${allPath.join('/') || '/'}\"`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tif (child.kind === 'slot') {\n\t\t\ttarget[child.uuid] = function bind(param: Segment) {\n\t\t\t\tconst next = [...allPath, param]\n\n\t\t\t\t// leaf slot => callable endpoint directly\n\t\t\t\tif (child.list.length === 0) {\n\t\t\t\t\treturn attachWhenAndJoin(makeTarget(true, next), next, [])\n\t\t\t\t}\n\n\t\t\t\t// non-leaf => subtree (optionally callable if keep())\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), next), buildNode(next, child))\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.list.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.name]\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(makeTarget(true, leafPath), leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildNode(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = function wrap(arg: unknown) {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.name] : allPath\n\t\t\t\tconst subTree = buildNode(wrapped, child)\n\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), wrapped), subTree)\n\t\t\t}\n\t\t} else if (child.kind === 'pick') {\n\t\t\ttarget[child.uuid] = (value: keyof typeof child.mode) => {\n\t\t\t\tif (child.mode[value]) {\n\t\t\t\t\treturn buildNode([...allPath, ...child.mode[value]], path('', child.list))\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`pick(\"${child.name}\") got unknown value: ${String(value)}`)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, parent.list)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], list: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (list.length === 0 && typeof target === 'function') {\n\t\t\treturn attachWhenAndJoin(makeTarget(true, nextPath), nextPath, list)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildNode(nextPath, path('', list))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = function join(seg: Segment | readonly Segment[]) {\n\t\treturn when(true, seg)\n\t}\n\n\treturn target\n}\n\nconst makeTarget = (callable: boolean, currentPath: Segment[]) => {\n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","kind","name","keep","path","list","slot","wrap","when","pick","mode","root","defs","buildNode","url","search","prefix","parent","hasKeep","pathDef","node","allPath","target","makeTarget","child","param","next","attachWhenAndJoin","leafPath","arg","wrapped","subTree","value","basePath","cond","seg","nextPath","callable","currentPath"]}
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var a in e)p(t,a,{get:e[a],enumerable:!0})},x=(t,e,a,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of k(e))!D.call(t,s)&&s!==a&&p(t,s,{get:()=>e[s],enumerable:!(o=w(e,s))||o.enumerable});return t};var K=t=>x(p({},"__esModule",{value:!0}),t);var $={};R($,{base:()=>h,bind:()=>y,link:()=>P,mask:()=>N,node:()=>d});module.exports=K($);var g=t=>t.replace(/-([a-zA-Z0-9])/g,(e,a)=>a.toUpperCase()),h=()=>({kind:"keep"}),d=(t,e)=>({kind:"path",name:S("path",t),uuid:g(t),rest:e??[]}),y=(t,e)=>({kind:"slot",name:S("slot",t),uuid:g(t),rest:e??[]}),N=(t,e,a)=>({kind:"wrap",name:S("wrap",t),uuid:g(t),when:e,rest:a??[]}),F=/^[A-Za-z_][A-Za-z0-9_]*$/;function S(t,e){if(t==="path"&&e==="")return e.trim();if(!e)throw new Error(`${t} name cannot be empty`);if(!F.test(e))throw new Error(`${t} name "${e}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return e.trim()}var m=(t,e)=>`/${t.filter(Boolean).join("/").replace("//{2,}/g","/")}${e?`?${e}`:""}`;function P(t){return u([],d("",t))}function u(t,e){let a=n=>n.rest.some(r=>r.kind==="keep"),o=e.kind==="slot"||e.kind==="wrap"?t:e.uuid?[...t,e.uuid]:t,s=a(e)?n=>m(o,n):Object.create(null);for(let n of e.rest)if(n.kind==="slot")n.rest.length===0?s[n.uuid]=r=>{let l=[...o,r];return c(f=>m(l,f),l,[])}:s[n.uuid]=r=>{let l=u([...o,r],n);return Object.assign(a(n)?i=>m([...o,r],i):Object.create(null),l)};else if(n.kind==="path")if(n.rest.length===0){let r=[...o,n.uuid],l=i=>m(r,i);s[n.uuid]=c(l,r,[])}else s[n.uuid]=u(o,n);else n.kind==="wrap"&&(s[n.uuid]=r=>{let i=n.when(r)?[...o,n.uuid]:o,f=u(i,n);return Object.assign(a(n)?b=>m(i,b):Object.create(null),f)});return c(s,o,e.rest)}function c(t,e,a){let o=(s,n)=>{let r=s?[...e,...Array.isArray(n)?n:[n]]:e;return a.length===0&&typeof t=="function"?c(i=>m(r,i),r,a):u(r,d("",a))};return t.$when=o,t.$join=s=>o(!0,s),t}0&&(module.exports={base,bind,link,mask,node});
1
+ "use strict";var h=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var L=(t,e)=>{for(var s in e)h(t,s,{get:e[s],enumerable:!0})},P=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of D(e))!C.call(t,a)&&a!==s&&h(t,a,{get:()=>e[a],enumerable:!(o=x(e,a))||o.enumerable});return t};var b=t=>P(h({},"__esModule",{value:!0}),t);var _={};L(_,{base:()=>k,bind:()=>$,link:()=>S,mask:()=>w,node:()=>c,pick:()=>N});module.exports=b(_);var u=t=>t.replace(/^-+/,"").replace(/-+$/,"").replace(/^_+/,"").replace(/_+$/,"").replace(/-([a-zA-Z0-9])/g,(e,s)=>s.toUpperCase()).replace(/_([a-zA-Z0-9])/g,(e,s)=>s.toUpperCase()),A=/^[A-Za-z_-][A-Za-z0-9_-]*$/;function p(t,e){if(t==="path"&&e==="")return e.trim();if(!e)throw new Error(`${t} name cannot be empty`);if(!A.test(e))throw new Error(`${t} name "${e}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return e.trim()}var k=()=>({kind:"keep"}),c=(t,e)=>({kind:"path",name:p("path",t),uuid:u(t),list:e??[]}),$=(t,e)=>({kind:"slot",name:p("slot",t),uuid:`$${u(t)}`,list:e??[]}),w=(t,e,s)=>({kind:"wrap",name:p("wrap",t),uuid:`$${u(t)}`,when:e,list:s??[]}),N=(t,e,s)=>({kind:"pick",name:p("pick",t),uuid:`$${u(t)}`,mode:e,list:s??[]}),S=t=>l([],c("",t)),T=(t,e)=>`/${t.filter(Boolean).join("/").replace(/\/{2,}/g,"/")}${e?`?${e}`:""}`;function l(t,e){let s=n=>n.list.some(r=>r.kind==="keep"),o=e.kind==="path"&&e.name?[...t,e.name]:t,a=i(s(e),o);for(let n of e.list){if(n.kind!=="keep"&&n.uuid in a)throw new Error(`Duplicate uuid "${String(n.uuid)}" under "${o.join("/")||"/"}"`);if(n.kind==="slot")a[n.uuid]=function(f){let d=[...o,f];return n.list.length===0?m(i(!0,d),d,[]):Object.assign(i(s(n),d),l(d,n))};else if(n.kind==="path")if(n.list.length===0){let r=[...o,n.name];a[n.uuid]=m(i(!0,r),r,[])}else a[n.uuid]=l(o,n);else n.kind==="wrap"?a[n.uuid]=function(f){let g=n.when(f)?[...o,n.name]:o,y=l(g,n);return Object.assign(i(s(n),g),y)}:n.kind==="pick"&&(a[n.uuid]=r=>{if(n.mode[r])return l([...o,...n.mode[r]],c("",n.list));throw new Error(`pick("${n.name}") got unknown value: ${String(r)}`)})}return m(a,o,e.list)}function m(t,e,s){let o=(a,n)=>{let r=a?[...e,...Array.isArray(n)?n:[n]]:e;return s.length===0&&typeof t=="function"?m(i(!0,r),r,s):l(r,c("",s))};return t.$when=o,t.$join=function(n){return o(!0,n)},t}var i=(t,e)=>t?s=>T(e,s):Object.create(null);0&&(module.exports={base,bind,link,mask,node,pick});
2
2
  //# sourceMappingURL=dialect-node.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dialect-node.ts","../src/api.ts"],"sourcesContent":["export { root as link, path as node, slot as bind, keep as base, wrap as mask } from './api'\n","import {\n\tKebabToCamel,\n\tKeep,\n\tPath,\n\tPathDef,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamel = (s: string) => s.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\ntype KeyFromSeg<S extends string> = KebabToCamel<S>\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Path<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Slot<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\trest?: Rest\n): Wrap<Name, KeyFromSeg<Name>, Rest, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\twhen,\n\trest: (rest ?? []) as Rest,\n})\n\nconst IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path.filter(Boolean).join('/').replace('/\\/{2,}/g', '/')}${search ? `?${search}` : ''}`\n\n// ---------- Typed root signature ----------\nexport function root<const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> {\n\treturn buildPath([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n}\n\nfunction buildPath(prefix: Segment[], def: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.rest.some((c: any) => c.kind === 'keep')\n\tconst allPath =\n\t\tdef.kind === 'slot' || def.kind === 'wrap'\n\t\t\t? prefix\n\t\t\t: def.uuid\n\t\t\t\t? [...prefix, def.uuid]\n\t\t\t\t: prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = hasKeep(def)\n\t\t? (search?: SParams) => url(allPath, search)\n\t\t: Object.create(null)\n\n\tfor (const child of def.rest) {\n\t\tif (child.kind === 'slot') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\tconst leafPath = [...allPath, param]\n\t\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\t\treturn attachWhenAndJoin(fn, leafPath, [])\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\t// Build subtree for nested parts under :id\n\t\t\t\t\t// Synthetic path with empty name so we don't add extra segment.\n\t\t\t\t\tconst subTree = buildPath([...allPath, param], child)\n\n\t\t\t\t\t// Attach children (info, activities, etc.) to that function\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\thasKeep(child)\n\t\t\t\t\t\t\t? (search?: SParams) => url([...allPath, param], search)\n\t\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\t\tsubTree\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.uuid]\n\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(fn, leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildPath(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = (arg: unknown) => {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.uuid] : allPath\n\t\t\t\tconst subTree = buildPath(wrapped, child as any)\n\n\t\t\t\treturn Object.assign(\n\t\t\t\t\t// if wrap has keep(), it becomes callable at that point\n\t\t\t\t\thasKeep(child as any)\n\t\t\t\t\t\t? (search?: SParams) => url(wrapped, search)\n\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\tsubTree\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, def.rest)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], rest: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (rest.length === 0 && typeof target === 'function') {\n\t\t\tconst leaf: any = (search?: SParams) => url(nextPath, search)\n\t\t\treturn attachWhenAndJoin(leaf, nextPath, rest)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildPath(nextPath, path('', rest))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = (seg: Segment | readonly Segment[]) => when(true, seg)\n\n\treturn target\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE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,EAAQI,CAAY,EAChBV,GAAqBD,EAAIkB,EAASjB,CAAM,EACzC,OAAO,OAAO,IAAI,EACrBc,CACD,CACD,GAIF,OAAOD,EAAkBJ,EAAQD,EAASH,EAAI,IAAI,CACnD,CAEA,SAASQ,EAAkBJ,EAAaS,EAAqB1B,EAA0B,CACtF,IAAMI,EAAO,CAACuB,EAAeC,IAAsC,CAClE,IAAMC,EAAWF,EAAO,CAAC,GAAGD,EAAU,GAAI,MAAM,QAAQE,CAAG,EAAIA,EAAM,CAACA,CAAG,CAAE,EAAIF,EAG/E,OAAI1B,EAAK,SAAW,GAAK,OAAOiB,GAAW,WAEnCI,EADYb,GAAqBD,EAAIsB,EAAUrB,CAAM,EAC7BqB,EAAU7B,CAAI,EAKvCW,EAAUkB,EAAU/B,EAAK,GAAIE,CAAI,CAAC,CAC1C,EAEA,OAAAiB,EAAO,MAAQb,EACfa,EAAO,MAASW,GAAsCxB,EAAK,GAAMwB,CAAG,EAE7DX,CACR","names":["dialect_node_exports","__export","keep","slot","root","wrap","path","__toCommonJS","toCamel","s","_","c","keep","path","name","rest","assertValidName","slot","wrap","when","IDENT","kind","url","search","root","defs","buildPath","prefix","def","hasKeep","pathDef","allPath","target","child","param","leafPath","attachWhenAndJoin","subTree","fn","arg","wrapped","basePath","cond","seg","nextPath"]}
1
+ {"version":3,"sources":["../src/dialect-node.ts","../src/api.ts"],"sourcesContent":["export { root as link, path as node, slot as bind, keep as base, wrap as mask, pick } from './api'\n","import {\n\tKeep,\n\tPath,\n\tPathDef,\n\tPick,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tToCamelCase,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamelCase = <S extends string>(s: S) =>\n\ts\n\t\t.replace(/^-+/, '')\n\t\t.replace(/-+$/, '')\n\t\t.replace(/^_+/, '')\n\t\t.replace(/_+$/, '')\n\t\t.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\n\t\t.replace(/_([a-zA-Z0-9])/g, (_, c) => c.toUpperCase()) as ToCamelCase<S>\n\nconst IDENT = /^[A-Za-z_-][A-Za-z0-9_-]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap' | 'pick',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Path<Name, ToCamelCase<Name>, List> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamelCase(name),\n\tlist: (list ?? []) as List,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Slot<Name, `$${ToCamelCase<Name>}`, List> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tlist: (list ?? []) as List,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\tlist?: List\n): Wrap<Name, `$${ToCamelCase<Name>}`, List, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: `$${toCamelCase(name)}`,\n\twhen,\n\tlist: (list ?? []) as List,\n})\n\nexport const pick = <\n\tconst Name extends string,\n\tconst Mode extends Record<string, readonly Segment[]>,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tmode: Mode,\n\tlist?: List\n): Pick<Name, `$${ToCamelCase<Name>}`, Mode, List> => ({\n\tkind: 'pick',\n\tname: assertValidName('pick', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tmode,\n\tlist: (list ?? []) as List,\n})\n\nexport const root = <const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> =>\n\tbuildNode([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path\n\t\t.filter(Boolean)\n\t\t.join('/')\n\t\t.replace(/\\/{2,}/g, '/')}${search ? `?${search}` : ''}`\n\nfunction buildNode(prefix: Segment[], parent: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.list.some((node: any) => node.kind === 'keep')\n\tconst allPath = parent.kind === 'path' && parent.name ? [...prefix, parent.name] : prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = makeTarget(hasKeep(parent), allPath)\n\n\tfor (const child of parent.list) {\n\t\tif (child.kind !== 'keep') {\n\t\t\tif (child.uuid in target) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Duplicate uuid \"${String(child.uuid)}\" under \"${allPath.join('/') || '/'}\"`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tif (child.kind === 'slot') {\n\t\t\ttarget[child.uuid] = function bind(param: Segment) {\n\t\t\t\tconst next = [...allPath, param]\n\n\t\t\t\t// leaf slot => callable endpoint directly\n\t\t\t\tif (child.list.length === 0) {\n\t\t\t\t\treturn attachWhenAndJoin(makeTarget(true, next), next, [])\n\t\t\t\t}\n\n\t\t\t\t// non-leaf => subtree (optionally callable if keep())\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), next), buildNode(next, child))\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.list.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.name]\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(makeTarget(true, leafPath), leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildNode(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = function wrap(arg: unknown) {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.name] : allPath\n\t\t\t\tconst subTree = buildNode(wrapped, child)\n\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), wrapped), subTree)\n\t\t\t}\n\t\t} else if (child.kind === 'pick') {\n\t\t\ttarget[child.uuid] = (value: keyof typeof child.mode) => {\n\t\t\t\tif (child.mode[value]) {\n\t\t\t\t\treturn buildNode([...allPath, ...child.mode[value]], path('', child.list))\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`pick(\"${child.name}\") got unknown value: ${String(value)}`)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, parent.list)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], list: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (list.length === 0 && typeof target === 'function') {\n\t\t\treturn attachWhenAndJoin(makeTarget(true, nextPath), nextPath, list)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildNode(nextPath, path('', list))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = function join(seg: Segment | readonly Segment[]) {\n\t\treturn when(true, seg)\n\t}\n\n\treturn target\n}\n\nconst makeTarget = (callable: boolean, currentPath: Segment[]) => {\n\treturn callable ? (search?: SParams) => url(currentPath, search) : Object.create(null)\n}\n"],"mappings":"yaAAA,IAAAA,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B,CAAM,EAAI,OAAO,OAAO,IAAI","names":["dialect_node_exports","__export","keep","slot","root","wrap","path","pick","__toCommonJS","toCamelCase","s","_","c","IDENT","assertValidName","kind","name","keep","path","list","slot","wrap","when","pick","mode","root","defs","buildNode","url","search","prefix","parent","hasKeep","pathDef","node","allPath","target","makeTarget","child","param","next","attachWhenAndJoin","leafPath","arg","wrapped","subTree","value","basePath","cond","seg","nextPath","callable","currentPath"]}
@@ -1 +1 @@
1
- export { keep as base, slot as bind, root as link, wrap as mask, path as node } from './api.cjs';
1
+ export { keep as base, slot as bind, root as link, wrap as mask, path as node, pick } from './api.cjs';
@@ -1 +1 @@
1
- export { keep as base, slot as bind, root as link, wrap as mask, path as node } from './api.js';
1
+ export { keep as base, slot as bind, root as link, wrap as mask, path as node, pick } from './api.js';
@@ -1,2 +1,2 @@
1
- import{a,b as s,c as o,d as e,e as p}from"./chunk-5ZW66SPO.js";export{a as base,o as bind,p as link,e as mask,s as node};
1
+ import{a,b as s,c as o,d as e,e as p,f as k}from"./chunk-TB22YO7J.js";export{a as base,o as bind,k as link,e as mask,s as node,p as pick};
2
2
  //# sourceMappingURL=dialect-node.js.map
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var a in e)p(t,a,{get:e[a],enumerable:!0})},x=(t,e,a,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of D(e))!k.call(t,s)&&s!==a&&p(t,s,{get:()=>e[s],enumerable:!(o=b(e,s))||o.enumerable});return t};var K=t=>x(p({},"__esModule",{value:!0}),t);var $={};R($,{keep:()=>h,path:()=>d,root:()=>P,slot:()=>y,wrap:()=>N});module.exports=K($);var g=t=>t.replace(/-([a-zA-Z0-9])/g,(e,a)=>a.toUpperCase()),h=()=>({kind:"keep"}),d=(t,e)=>({kind:"path",name:S("path",t),uuid:g(t),rest:e??[]}),y=(t,e)=>({kind:"slot",name:S("slot",t),uuid:g(t),rest:e??[]}),N=(t,e,a)=>({kind:"wrap",name:S("wrap",t),uuid:g(t),when:e,rest:a??[]}),F=/^[A-Za-z_][A-Za-z0-9_]*$/;function S(t,e){if(t==="path"&&e==="")return e.trim();if(!e)throw new Error(`${t} name cannot be empty`);if(!F.test(e))throw new Error(`${t} name "${e}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return e.trim()}var m=(t,e)=>`/${t.filter(Boolean).join("/").replace("//{2,}/g","/")}${e?`?${e}`:""}`;function P(t){return u([],d("",t))}function u(t,e){let a=n=>n.rest.some(r=>r.kind==="keep"),o=e.kind==="slot"||e.kind==="wrap"?t:e.uuid?[...t,e.uuid]:t,s=a(e)?n=>m(o,n):Object.create(null);for(let n of e.rest)if(n.kind==="slot")n.rest.length===0?s[n.uuid]=r=>{let l=[...o,r];return c(f=>m(l,f),l,[])}:s[n.uuid]=r=>{let l=u([...o,r],n);return Object.assign(a(n)?i=>m([...o,r],i):Object.create(null),l)};else if(n.kind==="path")if(n.rest.length===0){let r=[...o,n.uuid],l=i=>m(r,i);s[n.uuid]=c(l,r,[])}else s[n.uuid]=u(o,n);else n.kind==="wrap"&&(s[n.uuid]=r=>{let i=n.when(r)?[...o,n.uuid]:o,f=u(i,n);return Object.assign(a(n)?w=>m(i,w):Object.create(null),f)});return c(s,o,e.rest)}function c(t,e,a){let o=(s,n)=>{let r=s?[...e,...Array.isArray(n)?n:[n]]:e;return a.length===0&&typeof t=="function"?c(i=>m(r,i),r,a):u(r,d("",a))};return t.$when=o,t.$join=s=>o(!0,s),t}0&&(module.exports={keep,path,root,slot,wrap});
1
+ "use strict";var h=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var L=(t,e)=>{for(var o in e)h(t,o,{get:e[o],enumerable:!0})},P=(t,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of D(e))!C.call(t,s)&&s!==o&&h(t,s,{get:()=>e[s],enumerable:!(a=x(e,s))||a.enumerable});return t};var b=t=>P(h({},"__esModule",{value:!0}),t);var _={};L(_,{keep:()=>k,path:()=>c,pick:()=>N,root:()=>S,slot:()=>$,wrap:()=>w});module.exports=b(_);var u=t=>t.replace(/^-+/,"").replace(/-+$/,"").replace(/^_+/,"").replace(/_+$/,"").replace(/-([a-zA-Z0-9])/g,(e,o)=>o.toUpperCase()).replace(/_([a-zA-Z0-9])/g,(e,o)=>o.toUpperCase()),A=/^[A-Za-z_-][A-Za-z0-9_-]*$/;function p(t,e){if(t==="path"&&e==="")return e.trim();if(!e)throw new Error(`${t} name cannot be empty`);if(!A.test(e))throw new Error(`${t} name "${e}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return e.trim()}var k=()=>({kind:"keep"}),c=(t,e)=>({kind:"path",name:p("path",t),uuid:u(t),list:e??[]}),$=(t,e)=>({kind:"slot",name:p("slot",t),uuid:`$${u(t)}`,list:e??[]}),w=(t,e,o)=>({kind:"wrap",name:p("wrap",t),uuid:`$${u(t)}`,when:e,list:o??[]}),N=(t,e,o)=>({kind:"pick",name:p("pick",t),uuid:`$${u(t)}`,mode:e,list:o??[]}),S=t=>l([],c("",t)),T=(t,e)=>`/${t.filter(Boolean).join("/").replace(/\/{2,}/g,"/")}${e?`?${e}`:""}`;function l(t,e){let o=n=>n.list.some(r=>r.kind==="keep"),a=e.kind==="path"&&e.name?[...t,e.name]:t,s=i(o(e),a);for(let n of e.list){if(n.kind!=="keep"&&n.uuid in s)throw new Error(`Duplicate uuid "${String(n.uuid)}" under "${a.join("/")||"/"}"`);if(n.kind==="slot")s[n.uuid]=function(f){let d=[...a,f];return n.list.length===0?m(i(!0,d),d,[]):Object.assign(i(o(n),d),l(d,n))};else if(n.kind==="path")if(n.list.length===0){let r=[...a,n.name];s[n.uuid]=m(i(!0,r),r,[])}else s[n.uuid]=l(a,n);else n.kind==="wrap"?s[n.uuid]=function(f){let g=n.when(f)?[...a,n.name]:a,y=l(g,n);return Object.assign(i(o(n),g),y)}:n.kind==="pick"&&(s[n.uuid]=r=>{if(n.mode[r])return l([...a,...n.mode[r]],c("",n.list));throw new Error(`pick("${n.name}") got unknown value: ${String(r)}`)})}return m(s,a,e.list)}function m(t,e,o){let a=(s,n)=>{let r=s?[...e,...Array.isArray(n)?n:[n]]:e;return o.length===0&&typeof t=="function"?m(i(!0,r),r,o):l(r,c("",o))};return t.$when=a,t.$join=function(n){return a(!0,n)},t}var i=(t,e)=>t?o=>T(e,o):Object.create(null);0&&(module.exports={keep,path,pick,root,slot,wrap});
2
2
  //# sourceMappingURL=dialect-path.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dialect-path.ts","../src/api.ts"],"sourcesContent":["export { root, path, slot, keep, wrap } from './api'\n","import {\n\tKebabToCamel,\n\tKeep,\n\tPath,\n\tPathDef,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamel = (s: string) => s.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\ntype KeyFromSeg<S extends string> = KebabToCamel<S>\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Path<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Slot<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\trest?: Rest\n): Wrap<Name, KeyFromSeg<Name>, Rest, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\twhen,\n\trest: (rest ?? []) as Rest,\n})\n\nconst IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path.filter(Boolean).join('/').replace('/\\/{2,}/g', '/')}${search ? `?${search}` : ''}`\n\n// ---------- Typed root signature ----------\nexport function root<const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> {\n\treturn buildPath([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n}\n\nfunction buildPath(prefix: Segment[], def: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.rest.some((c: any) => c.kind === 'keep')\n\tconst allPath =\n\t\tdef.kind === 'slot' || def.kind === 'wrap'\n\t\t\t? prefix\n\t\t\t: def.uuid\n\t\t\t\t? [...prefix, def.uuid]\n\t\t\t\t: prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = hasKeep(def)\n\t\t? (search?: SParams) => url(allPath, search)\n\t\t: Object.create(null)\n\n\tfor (const child of def.rest) {\n\t\tif (child.kind === 'slot') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\tconst leafPath = [...allPath, param]\n\t\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\t\treturn attachWhenAndJoin(fn, leafPath, [])\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\t// Build subtree for nested parts under :id\n\t\t\t\t\t// Synthetic path with empty name so we don't add extra segment.\n\t\t\t\t\tconst subTree = buildPath([...allPath, param], child)\n\n\t\t\t\t\t// Attach children (info, activities, etc.) to that function\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\thasKeep(child)\n\t\t\t\t\t\t\t? (search?: SParams) => url([...allPath, param], search)\n\t\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\t\tsubTree\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.uuid]\n\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(fn, leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildPath(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = (arg: unknown) => {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.uuid] : allPath\n\t\t\t\tconst subTree = buildPath(wrapped, child as any)\n\n\t\t\t\treturn Object.assign(\n\t\t\t\t\t// if wrap has keep(), it becomes callable at that point\n\t\t\t\t\thasKeep(child as any)\n\t\t\t\t\t\t? (search?: SParams) => url(wrapped, search)\n\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\tsubTree\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, def.rest)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], rest: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (rest.length === 0 && typeof target === 'function') {\n\t\t\tconst leaf: any = (search?: SParams) => url(nextPath, search)\n\t\t\treturn attachWhenAndJoin(leaf, nextPath, rest)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildPath(nextPath, path('', rest))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = (seg: Segment | readonly Segment[]) => when(true, seg)\n\n\treturn target\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAP,GCcA,IAAMQ,EAAWC,GAAcA,EAAE,QAAQ,kBAAmB,CAACC,EAAGC,IAAMA,EAAE,YAAY,CAAC,EAIxEC,EAAO,KAAa,CAAE,KAAM,MAAO,GAEnCC,EAAO,CAInBC,EACAC,KACyC,CACzC,KAAM,OACN,KAAMC,EAAgB,OAAQF,CAAI,EAClC,KAAMN,EAAQM,CAAI,EAClB,KAAOC,GAAQ,CAAC,CACjB,GAEaE,EAAO,CAInBH,EACAC,KACyC,CACzC,KAAM,OACN,KAAMC,EAAgB,OAAQF,CAAI,EAClC,KAAMN,EAAQM,CAAI,EAClB,KAAOC,GAAQ,CAAC,CACjB,GAEaG,EAAO,CAKnBJ,EACAK,EACAJ,KAC+C,CAC/C,KAAM,OACN,KAAMC,EAAgB,OAAQF,CAAI,EAClC,KAAMN,EAAQM,CAAI,EAClB,KAAAK,EACA,KAAOJ,GAAQ,CAAC,CACjB,GAEMK,EAAQ,2BAEd,SAASJ,EACRK,EACAP,EACO,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ASG,CAAK,EAAGX,CAAM,EACrD,OAAO,OAAO,IAAI,EACrBc,CACD,CACD,UAESJ,EAAM,OAAS,OACzB,GAAIA,EAAM,KAAK,SAAW,EAAG,CAC5B,IAAME,EAAW,CAAC,GAAGJ,EAASE,EAAM,IAAI,EAClCK,EAAWf,GAAqBD,EAAIa,EAAUZ,CAAM,EAC1DS,EAAOC,EAAM,IAAI,EAAIG,EAAkBE,EAAIH,EAAU,CAAC,CAAC,CACxD,MACCH,EAAOC,EAAM,IAAI,EAAIP,EAAUK,EAASE,CAAK,OAEpCA,EAAM,OAAS,SACzBD,EAAOC,EAAM,IAAI,EAAKM,GAAiB,CAEtC,IAAMC,EADUP,EAAM,KAAKM,CAAG,EACJ,CAAC,GAAGR,EAASE,EAAM,IAAI,EAAIF,EAC/CM,EAAUX,EAAUc,EAASP,CAAY,EAE/C,OAAO,OAAO,OAEbJ,EAAQI,CAAY,EAChBV,GAAqBD,EAAIkB,EAASjB,CAAM,EACzC,OAAO,OAAO,IAAI,EACrBc,CACD,CACD,GAIF,OAAOD,EAAkBJ,EAAQD,EAASH,EAAI,IAAI,CACnD,CAEA,SAASQ,EAAkBJ,EAAaS,EAAqB1B,EAA0B,CACtF,IAAMI,EAAO,CAACuB,EAAeC,IAAsC,CAClE,IAAMC,EAAWF,EAAO,CAAC,GAAGD,EAAU,GAAI,MAAM,QAAQE,CAAG,EAAIA,EAAM,CAACA,CAAG,CAAE,EAAIF,EAG/E,OAAI1B,EAAK,SAAW,GAAK,OAAOiB,GAAW,WAEnCI,EADYb,GAAqBD,EAAIsB,EAAUrB,CAAM,EAC7BqB,EAAU7B,CAAI,EAKvCW,EAAUkB,EAAU/B,EAAK,GAAIE,CAAI,CAAC,CAC1C,EAEA,OAAAiB,EAAO,MAAQb,EACfa,EAAO,MAASW,GAAsCxB,EAAK,GAAMwB,CAAG,EAE7DX,CACR","names":["dialect_path_exports","__export","keep","path","root","slot","wrap","__toCommonJS","toCamel","s","_","c","keep","path","name","rest","assertValidName","slot","wrap","when","IDENT","kind","url","search","root","defs","buildPath","prefix","def","hasKeep","pathDef","allPath","target","child","param","leafPath","attachWhenAndJoin","subTree","fn","arg","wrapped","basePath","cond","seg","nextPath"]}
1
+ {"version":3,"sources":["../src/dialect-path.ts","../src/api.ts"],"sourcesContent":["export { root, path, slot, keep, wrap, pick } from './api'\n","import {\n\tKeep,\n\tPath,\n\tPathDef,\n\tPick,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tToCamelCase,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamelCase = <S extends string>(s: S) =>\n\ts\n\t\t.replace(/^-+/, '')\n\t\t.replace(/-+$/, '')\n\t\t.replace(/^_+/, '')\n\t\t.replace(/_+$/, '')\n\t\t.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\n\t\t.replace(/_([a-zA-Z0-9])/g, (_, c) => c.toUpperCase()) as ToCamelCase<S>\n\nconst IDENT = /^[A-Za-z_-][A-Za-z0-9_-]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap' | 'pick',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Path<Name, ToCamelCase<Name>, List> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamelCase(name),\n\tlist: (list ?? []) as List,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Slot<Name, `$${ToCamelCase<Name>}`, List> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tlist: (list ?? []) as List,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\tlist?: List\n): Wrap<Name, `$${ToCamelCase<Name>}`, List, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: `$${toCamelCase(name)}`,\n\twhen,\n\tlist: (list ?? []) as List,\n})\n\nexport const pick = <\n\tconst Name extends string,\n\tconst Mode extends Record<string, readonly Segment[]>,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tmode: Mode,\n\tlist?: List\n): Pick<Name, `$${ToCamelCase<Name>}`, Mode, List> => ({\n\tkind: 'pick',\n\tname: assertValidName('pick', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tmode,\n\tlist: (list ?? []) as List,\n})\n\nexport const root = <const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> =>\n\tbuildNode([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path\n\t\t.filter(Boolean)\n\t\t.join('/')\n\t\t.replace(/\\/{2,}/g, '/')}${search ? `?${search}` : ''}`\n\nfunction buildNode(prefix: Segment[], parent: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.list.some((node: any) => node.kind === 'keep')\n\tconst allPath = parent.kind === 'path' && parent.name ? [...prefix, parent.name] : prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = makeTarget(hasKeep(parent), allPath)\n\n\tfor (const child of parent.list) {\n\t\tif (child.kind !== 'keep') {\n\t\t\tif (child.uuid in target) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Duplicate uuid \"${String(child.uuid)}\" under \"${allPath.join('/') || '/'}\"`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tif (child.kind === 'slot') {\n\t\t\ttarget[child.uuid] = function bind(param: Segment) {\n\t\t\t\tconst next = [...allPath, param]\n\n\t\t\t\t// leaf slot => callable endpoint directly\n\t\t\t\tif (child.list.length === 0) {\n\t\t\t\t\treturn attachWhenAndJoin(makeTarget(true, next), next, [])\n\t\t\t\t}\n\n\t\t\t\t// non-leaf => subtree (optionally callable if keep())\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), next), buildNode(next, child))\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.list.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.name]\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(makeTarget(true, leafPath), leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildNode(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = function wrap(arg: unknown) {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.name] : allPath\n\t\t\t\tconst subTree = buildNode(wrapped, child)\n\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), wrapped), subTree)\n\t\t\t}\n\t\t} else if (child.kind === 'pick') {\n\t\t\ttarget[child.uuid] = (value: keyof typeof child.mode) => {\n\t\t\t\tif (child.mode[value]) {\n\t\t\t\t\treturn buildNode([...allPath, ...child.mode[value]], path('', child.list))\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`pick(\"${child.name}\") got unknown value: ${String(value)}`)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, parent.list)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], list: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (list.length === 0 && typeof target === 'function') {\n\t\t\treturn attachWhenAndJoin(makeTarget(true, nextPath), nextPath, list)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildNode(nextPath, path('', list))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = function join(seg: Segment | readonly Segment[]) {\n\t\treturn when(true, seg)\n\t}\n\n\treturn target\n}\n\nconst makeTarget = (callable: boolean, currentPath: Segment[]) => {\n\treturn callable ? (search?: SParams) => url(currentPath, search) : Object.create(null)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAR,GCeA,IAAMS,EAAiCC,GACtCA,EACE,QAAQ,MAAO,EAAE,EACjB,QAAQ,MAAO,EAAE,EACjB,QAAQ,MAAO,EAAE,EACjB,QAAQ,MAAO,EAAE,EACjB,QAAQ,kBAAmB,CAACC,EAAGC,IAAMA,EAAE,YAAY,CAAC,EACpD,QAAQ,kBAAmB,CAACD,EAAGC,IAAMA,EAAE,YAAY,CAAC,EAEjDC,EAAQ,6BAEd,SAASC,EACRC,EACAC,EACO,CAEP,GAAID,IAAS,QAAUC,IAAS,GAAI,OAAOA,EAAK,KAAK,EAErD,GAAI,CAACA,EAAM,MAAM,IAAI,MAAM,GAAGD,CAAI,uBAAuB,EACzD,GAAI,CAACF,EAAM,KAAKG,CAAI,EACnB,MAAM,IAAI,MACT,GAAGD,CAAI,UAAUC,CAAI,+EACtB,EAGD,OAAOA,EAAK,KAAK,CAClB,CAGO,IAAMC,EAAO,KAAa,CAAE,KAAM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AAkBL,EAAaW,EAAqB5B,EAA0B,CACtF,IAAMG,EAAO,CAAC0B,EAAeC,IAAsC,CAClE,IAAMC,EAAWF,EAAO,CAAC,GAAGD,EAAU,GAAI,MAAM,QAAQE,CAAG,EAAIA,EAAM,CAACA,CAAG,CAAE,EAAIF,EAG/E,OAAI5B,EAAK,SAAW,GAAK,OAAOiB,GAAW,WACnCK,EAAkBJ,EAAW,GAAMa,CAAQ,EAAGA,EAAU/B,CAAI,EAK7DQ,EAAUuB,EAAUhC,EAAK,GAAIC,CAAI,CAAC,CAC1C,EAEA,OAAAiB,EAAO,MAAQd,EACfc,EAAO,MAAQ,SAAca,EAAmC,CAC/D,OAAO3B,EAAK,GAAM2B,CAAG,CACtB,EAEOb,CACR,CAEA,IAAMC,EAAa,CAACc,EAAmBC,IAC/BD,EAAYtB,GAAqBD,EAAIwB,EAAavB,CAAM,EAAI,OAAO,OAAO,IAAI","names":["dialect_path_exports","__export","keep","path","pick","root","slot","wrap","__toCommonJS","toCamelCase","s","_","c","IDENT","assertValidName","kind","name","keep","path","list","slot","wrap","when","pick","mode","root","defs","buildNode","url","search","prefix","parent","hasKeep","pathDef","node","allPath","target","makeTarget","child","param","next","attachWhenAndJoin","leafPath","arg","wrapped","subTree","value","basePath","cond","seg","nextPath","callable","currentPath"]}
@@ -1 +1 @@
1
- export { keep, path, root, slot, wrap } from './api.cjs';
1
+ export { keep, path, pick, root, slot, wrap } from './api.cjs';
@@ -1 +1 @@
1
- export { keep, path, root, slot, wrap } from './api.js';
1
+ export { keep, path, pick, root, slot, wrap } from './api.js';
@@ -1,2 +1,2 @@
1
- import{a as o,b as p,c as r,d as t,e}from"./chunk-5ZW66SPO.js";export{o as keep,p as path,e as root,r as slot,t as wrap};
1
+ import{a as o,b as p,c as r,d as t,e,f as a}from"./chunk-TB22YO7J.js";export{o as keep,p as path,e as pick,a as root,r as slot,t as wrap};
2
2
  //# sourceMappingURL=dialect-path.js.map
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var a in e)p(t,a,{get:e[a],enumerable:!0})},x=(t,e,a,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of D(e))!k.call(t,s)&&s!==a&&p(t,s,{get:()=>e[s],enumerable:!(o=b(e,s))||o.enumerable});return t};var K=t=>x(p({},"__esModule",{value:!0}),t);var $={};R($,{gate:()=>N,item:()=>y,make:()=>P,self:()=>h,step:()=>d});module.exports=K($);var g=t=>t.replace(/-([a-zA-Z0-9])/g,(e,a)=>a.toUpperCase()),h=()=>({kind:"keep"}),d=(t,e)=>({kind:"path",name:S("path",t),uuid:g(t),rest:e??[]}),y=(t,e)=>({kind:"slot",name:S("slot",t),uuid:g(t),rest:e??[]}),N=(t,e,a)=>({kind:"wrap",name:S("wrap",t),uuid:g(t),when:e,rest:a??[]}),F=/^[A-Za-z_][A-Za-z0-9_]*$/;function S(t,e){if(t==="path"&&e==="")return e.trim();if(!e)throw new Error(`${t} name cannot be empty`);if(!F.test(e))throw new Error(`${t} name "${e}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return e.trim()}var m=(t,e)=>`/${t.filter(Boolean).join("/").replace("//{2,}/g","/")}${e?`?${e}`:""}`;function P(t){return u([],d("",t))}function u(t,e){let a=n=>n.rest.some(r=>r.kind==="keep"),o=e.kind==="slot"||e.kind==="wrap"?t:e.uuid?[...t,e.uuid]:t,s=a(e)?n=>m(o,n):Object.create(null);for(let n of e.rest)if(n.kind==="slot")n.rest.length===0?s[n.uuid]=r=>{let l=[...o,r];return c(f=>m(l,f),l,[])}:s[n.uuid]=r=>{let l=u([...o,r],n);return Object.assign(a(n)?i=>m([...o,r],i):Object.create(null),l)};else if(n.kind==="path")if(n.rest.length===0){let r=[...o,n.uuid],l=i=>m(r,i);s[n.uuid]=c(l,r,[])}else s[n.uuid]=u(o,n);else n.kind==="wrap"&&(s[n.uuid]=r=>{let i=n.when(r)?[...o,n.uuid]:o,f=u(i,n);return Object.assign(a(n)?w=>m(i,w):Object.create(null),f)});return c(s,o,e.rest)}function c(t,e,a){let o=(s,n)=>{let r=s?[...e,...Array.isArray(n)?n:[n]]:e;return a.length===0&&typeof t=="function"?c(i=>m(r,i),r,a):u(r,d("",a))};return t.$when=o,t.$join=s=>o(!0,s),t}0&&(module.exports={gate,item,make,self,step});
1
+ "use strict";var g=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var L=(t,e)=>{for(var s in e)g(t,s,{get:e[s],enumerable:!0})},P=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of D(e))!C.call(t,a)&&a!==s&&g(t,a,{get:()=>e[a],enumerable:!(o=x(e,a))||o.enumerable});return t};var b=t=>P(g({},"__esModule",{value:!0}),t);var _={};L(_,{gate:()=>w,item:()=>$,make:()=>S,pick:()=>N,self:()=>k,step:()=>c});module.exports=b(_);var u=t=>t.replace(/^-+/,"").replace(/-+$/,"").replace(/^_+/,"").replace(/_+$/,"").replace(/-([a-zA-Z0-9])/g,(e,s)=>s.toUpperCase()).replace(/_([a-zA-Z0-9])/g,(e,s)=>s.toUpperCase()),A=/^[A-Za-z_-][A-Za-z0-9_-]*$/;function p(t,e){if(t==="path"&&e==="")return e.trim();if(!e)throw new Error(`${t} name cannot be empty`);if(!A.test(e))throw new Error(`${t} name "${e}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return e.trim()}var k=()=>({kind:"keep"}),c=(t,e)=>({kind:"path",name:p("path",t),uuid:u(t),list:e??[]}),$=(t,e)=>({kind:"slot",name:p("slot",t),uuid:`$${u(t)}`,list:e??[]}),w=(t,e,s)=>({kind:"wrap",name:p("wrap",t),uuid:`$${u(t)}`,when:e,list:s??[]}),N=(t,e,s)=>({kind:"pick",name:p("pick",t),uuid:`$${u(t)}`,mode:e,list:s??[]}),S=t=>l([],c("",t)),T=(t,e)=>`/${t.filter(Boolean).join("/").replace(/\/{2,}/g,"/")}${e?`?${e}`:""}`;function l(t,e){let s=n=>n.list.some(r=>r.kind==="keep"),o=e.kind==="path"&&e.name?[...t,e.name]:t,a=i(s(e),o);for(let n of e.list){if(n.kind!=="keep"&&n.uuid in a)throw new Error(`Duplicate uuid "${String(n.uuid)}" under "${o.join("/")||"/"}"`);if(n.kind==="slot")a[n.uuid]=function(f){let d=[...o,f];return n.list.length===0?m(i(!0,d),d,[]):Object.assign(i(s(n),d),l(d,n))};else if(n.kind==="path")if(n.list.length===0){let r=[...o,n.name];a[n.uuid]=m(i(!0,r),r,[])}else a[n.uuid]=l(o,n);else n.kind==="wrap"?a[n.uuid]=function(f){let h=n.when(f)?[...o,n.name]:o,y=l(h,n);return Object.assign(i(s(n),h),y)}:n.kind==="pick"&&(a[n.uuid]=r=>{if(n.mode[r])return l([...o,...n.mode[r]],c("",n.list));throw new Error(`pick("${n.name}") got unknown value: ${String(r)}`)})}return m(a,o,e.list)}function m(t,e,s){let o=(a,n)=>{let r=a?[...e,...Array.isArray(n)?n:[n]]:e;return s.length===0&&typeof t=="function"?m(i(!0,r),r,s):l(r,c("",s))};return t.$when=o,t.$join=function(n){return o(!0,n)},t}var i=(t,e)=>t?s=>T(e,s):Object.create(null);0&&(module.exports={gate,item,make,pick,self,step});
2
2
  //# sourceMappingURL=dialect-step.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dialect-step.ts","../src/api.ts"],"sourcesContent":["export { root as make, path as step, slot as item, keep as self, wrap as gate } from './api'\n","import {\n\tKebabToCamel,\n\tKeep,\n\tPath,\n\tPathDef,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamel = (s: string) => s.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\ntype KeyFromSeg<S extends string> = KebabToCamel<S>\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Path<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Slot<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\trest?: Rest\n): Wrap<Name, KeyFromSeg<Name>, Rest, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\twhen,\n\trest: (rest ?? []) as Rest,\n})\n\nconst IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path.filter(Boolean).join('/').replace('/\\/{2,}/g', '/')}${search ? `?${search}` : ''}`\n\n// ---------- Typed root signature ----------\nexport function root<const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> {\n\treturn buildPath([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n}\n\nfunction buildPath(prefix: Segment[], def: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.rest.some((c: any) => c.kind === 'keep')\n\tconst allPath =\n\t\tdef.kind === 'slot' || def.kind === 'wrap'\n\t\t\t? prefix\n\t\t\t: def.uuid\n\t\t\t\t? [...prefix, def.uuid]\n\t\t\t\t: prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = hasKeep(def)\n\t\t? (search?: SParams) => url(allPath, search)\n\t\t: Object.create(null)\n\n\tfor (const child of def.rest) {\n\t\tif (child.kind === 'slot') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\tconst leafPath = [...allPath, param]\n\t\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\t\treturn attachWhenAndJoin(fn, leafPath, [])\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\t// Build subtree for nested parts under :id\n\t\t\t\t\t// Synthetic path with empty name so we don't add extra segment.\n\t\t\t\t\tconst subTree = buildPath([...allPath, param], child)\n\n\t\t\t\t\t// Attach children (info, activities, etc.) to that function\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\thasKeep(child)\n\t\t\t\t\t\t\t? (search?: SParams) => url([...allPath, param], search)\n\t\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\t\tsubTree\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.uuid]\n\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(fn, leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildPath(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = (arg: unknown) => {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.uuid] : allPath\n\t\t\t\tconst subTree = buildPath(wrapped, child as any)\n\n\t\t\t\treturn Object.assign(\n\t\t\t\t\t// if wrap has keep(), it becomes callable at that point\n\t\t\t\t\thasKeep(child as any)\n\t\t\t\t\t\t? (search?: SParams) => url(wrapped, search)\n\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\tsubTree\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, def.rest)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], rest: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (rest.length === 0 && typeof target === 'function') {\n\t\t\tconst leaf: any = (search?: SParams) => url(nextPath, search)\n\t\t\treturn attachWhenAndJoin(leaf, nextPath, rest)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildPath(nextPath, path('', rest))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = (seg: Segment | readonly Segment[]) => when(true, seg)\n\n\treturn target\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAP,GCcA,IAAMQ,EAAWC,GAAcA,EAAE,QAAQ,kBAAmB,CAACC,EAAGC,IAAMA,EAAE,YAAY,CAAC,EAIxEC,EAAO,KAAa,CAAE,KAAM,MAAO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AAMI,EAAO,CAACuB,EAAeC,IAAsC,CAClE,IAAMC,EAAWF,EAAO,CAAC,GAAGD,EAAU,GAAI,MAAM,QAAQE,CAAG,EAAIA,EAAM,CAACA,CAAG,CAAE,EAAIF,EAG/E,OAAI1B,EAAK,SAAW,GAAK,OAAOiB,GAAW,WAEnCI,EADYb,GAAqBD,EAAIsB,EAAUrB,CAAM,EAC7BqB,EAAU7B,CAAI,EAKvCW,EAAUkB,EAAU/B,EAAK,GAAIE,CAAI,CAAC,CAC1C,EAEA,OAAAiB,EAAO,MAAQb,EACfa,EAAO,MAASW,GAAsCxB,EAAK,GAAMwB,CAAG,EAE7DX,CACR","names":["dialect_step_exports","__export","wrap","slot","root","keep","path","__toCommonJS","toCamel","s","_","c","keep","path","name","rest","assertValidName","slot","wrap","when","IDENT","kind","url","search","root","defs","buildPath","prefix","def","hasKeep","pathDef","allPath","target","child","param","leafPath","attachWhenAndJoin","subTree","fn","arg","wrapped","basePath","cond","seg","nextPath"]}
1
+ {"version":3,"sources":["../src/dialect-step.ts","../src/api.ts"],"sourcesContent":["export { root as make, path as step, slot as item, keep as self, wrap as gate, pick } from './api'\n","import {\n\tKeep,\n\tPath,\n\tPathDef,\n\tPick,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tToCamelCase,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamelCase = <S extends string>(s: S) =>\n\ts\n\t\t.replace(/^-+/, '')\n\t\t.replace(/-+$/, '')\n\t\t.replace(/^_+/, '')\n\t\t.replace(/_+$/, '')\n\t\t.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\n\t\t.replace(/_([a-zA-Z0-9])/g, (_, c) => c.toUpperCase()) as ToCamelCase<S>\n\nconst IDENT = /^[A-Za-z_-][A-Za-z0-9_-]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap' | 'pick',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Path<Name, ToCamelCase<Name>, List> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamelCase(name),\n\tlist: (list ?? []) as List,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Slot<Name, `$${ToCamelCase<Name>}`, List> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tlist: (list ?? []) as List,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\tlist?: List\n): Wrap<Name, `$${ToCamelCase<Name>}`, List, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: `$${toCamelCase(name)}`,\n\twhen,\n\tlist: (list ?? []) as List,\n})\n\nexport const pick = <\n\tconst Name extends string,\n\tconst Mode extends Record<string, readonly Segment[]>,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tmode: Mode,\n\tlist?: List\n): Pick<Name, `$${ToCamelCase<Name>}`, Mode, List> => ({\n\tkind: 'pick',\n\tname: assertValidName('pick', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tmode,\n\tlist: (list ?? []) as List,\n})\n\nexport const root = <const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> =>\n\tbuildNode([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path\n\t\t.filter(Boolean)\n\t\t.join('/')\n\t\t.replace(/\\/{2,}/g, '/')}${search ? `?${search}` : ''}`\n\nfunction buildNode(prefix: Segment[], parent: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.list.some((node: any) => node.kind === 'keep')\n\tconst allPath = parent.kind === 'path' && parent.name ? [...prefix, parent.name] : prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = makeTarget(hasKeep(parent), allPath)\n\n\tfor (const child of parent.list) {\n\t\tif (child.kind !== 'keep') {\n\t\t\tif (child.uuid in target) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Duplicate uuid \"${String(child.uuid)}\" under \"${allPath.join('/') || '/'}\"`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tif (child.kind === 'slot') {\n\t\t\ttarget[child.uuid] = function bind(param: Segment) {\n\t\t\t\tconst next = [...allPath, param]\n\n\t\t\t\t// leaf slot => callable endpoint directly\n\t\t\t\tif (child.list.length === 0) {\n\t\t\t\t\treturn attachWhenAndJoin(makeTarget(true, next), next, [])\n\t\t\t\t}\n\n\t\t\t\t// non-leaf => subtree (optionally callable if keep())\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), next), buildNode(next, child))\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.list.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.name]\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(makeTarget(true, leafPath), leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildNode(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = function wrap(arg: unknown) {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.name] : allPath\n\t\t\t\tconst subTree = buildNode(wrapped, child)\n\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), wrapped), subTree)\n\t\t\t}\n\t\t} else if (child.kind === 'pick') {\n\t\t\ttarget[child.uuid] = (value: keyof typeof child.mode) => {\n\t\t\t\tif (child.mode[value]) {\n\t\t\t\t\treturn buildNode([...allPath, ...child.mode[value]], path('', child.list))\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`pick(\"${child.name}\") got unknown value: ${String(value)}`)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, parent.list)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], list: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (list.length === 0 && typeof target === 'function') {\n\t\t\treturn attachWhenAndJoin(makeTarget(true, nextPath), nextPath, list)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildNode(nextPath, path('', list))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = function join(seg: Segment | readonly Segment[]) {\n\t\treturn when(true, seg)\n\t}\n\n\treturn target\n}\n\nconst makeTarget = (callable: boolean, currentPath: Segment[]) => {\n\treturn callable ? (search?: SParams) => url(currentPath, search) : Object.create(null)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAR,GCeA,IAAMS,EAAiCC,GACtCA,EACE,QAAQ,MAAO,EAAE,EACjB,QAAQ,MAAO,EAAE,EACj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AI,EAAIH,EAC/CU,EAAUlB,EAAUiB,EAASN,CAAK,EAExC,OAAO,OAAO,OAAOD,EAAWL,EAAQM,CAAK,EAAGM,CAAO,EAAGC,CAAO,CAClE,EACUP,EAAM,OAAS,SACzBF,EAAOE,EAAM,IAAI,EAAKQ,GAAmC,CACxD,GAAIR,EAAM,KAAKQ,CAAK,EACnB,OAAOnB,EAAU,CAAC,GAAGQ,EAAS,GAAGG,EAAM,KAAKQ,CAAK,CAAC,EAAG5B,EAAK,GAAIoB,EAAM,IAAI,CAAC,EAEzE,MAAM,IAAI,MAAM,SAASA,EAAM,IAAI,yBAAyB,OAAOQ,CAAK,CAAC,EAAE,CAE7E,EAEF,CAEA,OAAOL,EAAkBL,EAAQD,EAASJ,EAAO,IAAI,CACtD,CAEA,SAASU,EAAkBL,EAAaW,EAAqB5B,EAA0B,CACtF,IAAMG,EAAO,CAAC0B,EAAeC,IAAsC,CAClE,IAAMC,EAAWF,EAAO,CAAC,GAAGD,EAAU,GAAI,MAAM,QAAQE,CAAG,EAAIA,EAAM,CAACA,CAAG,CAAE,EAAIF,EAG/E,OAAI5B,EAAK,SAAW,GAAK,OAAOiB,GAAW,WACnCK,EAAkBJ,EAAW,GAAMa,CAAQ,EAAGA,EAAU/B,CAAI,EAK7DQ,EAAUuB,EAAUhC,EAAK,GAAIC,CAAI,CAAC,CAC1C,EAEA,OAAAiB,EAAO,MAAQd,EACfc,EAAO,MAAQ,SAAca,EAAmC,CAC/D,OAAO3B,EAAK,GAAM2B,CAAG,CACtB,EAEOb,CACR,CAEA,IAAMC,EAAa,CAACc,EAAmBC,IAC/BD,EAAYtB,GAAqBD,EAAIwB,EAAavB,CAAM,EAAI,OAAO,OAAO,IAAI","names":["dialect_step_exports","__export","wrap","slot","root","pick","keep","path","__toCommonJS","toCamelCase","s","_","c","IDENT","assertValidName","kind","name","keep","path","list","slot","wrap","when","pick","mode","root","defs","buildNode","url","search","prefix","parent","hasKeep","pathDef","node","allPath","target","makeTarget","child","param","next","attachWhenAndJoin","leafPath","arg","wrapped","subTree","value","basePath","cond","seg","nextPath","callable","currentPath"]}
@@ -1 +1 @@
1
- export { wrap as gate, slot as item, root as make, keep as self, path as step } from './api.cjs';
1
+ export { wrap as gate, slot as item, root as make, pick, keep as self, path as step } from './api.cjs';
@@ -1 +1 @@
1
- export { wrap as gate, slot as item, root as make, keep as self, path as step } from './api.js';
1
+ export { wrap as gate, slot as item, root as make, pick, keep as self, path as step } from './api.js';
@@ -1,2 +1,2 @@
1
- import{a,b as e,c as s,d as t,e as o}from"./chunk-5ZW66SPO.js";export{t as gate,s as item,o as make,a as self,e as step};
1
+ import{a,b as e,c as s,d as t,e as p,f as o}from"./chunk-TB22YO7J.js";export{t as gate,s as item,o as make,p as pick,a as self,e as step};
2
2
  //# sourceMappingURL=dialect-step.js.map
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var a in e)p(t,a,{get:e[a],enumerable:!0})},x=(t,e,a,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of D(e))!k.call(t,s)&&s!==a&&p(t,s,{get:()=>e[s],enumerable:!(r=b(e,s))||r.enumerable});return t};var K=t=>x(p({},"__esModule",{value:!0}),t);var $={};R($,{grow:()=>w,nest:()=>N,seed:()=>y,tree:()=>d,twig:()=>h});module.exports=K($);var g=t=>t.replace(/-([a-zA-Z0-9])/g,(e,a)=>a.toUpperCase()),h=()=>({kind:"keep"}),d=(t,e)=>({kind:"path",name:S("path",t),uuid:g(t),rest:e??[]}),y=(t,e)=>({kind:"slot",name:S("slot",t),uuid:g(t),rest:e??[]}),N=(t,e,a)=>({kind:"wrap",name:S("wrap",t),uuid:g(t),when:e,rest:a??[]}),F=/^[A-Za-z_][A-Za-z0-9_]*$/;function S(t,e){if(t==="path"&&e==="")return e.trim();if(!e)throw new Error(`${t} name cannot be empty`);if(!F.test(e))throw new Error(`${t} name "${e}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return e.trim()}var m=(t,e)=>`/${t.filter(Boolean).join("/").replace("//{2,}/g","/")}${e?`?${e}`:""}`;function w(t){return u([],d("",t))}function u(t,e){let a=n=>n.rest.some(o=>o.kind==="keep"),r=e.kind==="slot"||e.kind==="wrap"?t:e.uuid?[...t,e.uuid]:t,s=a(e)?n=>m(r,n):Object.create(null);for(let n of e.rest)if(n.kind==="slot")n.rest.length===0?s[n.uuid]=o=>{let l=[...r,o];return c(f=>m(l,f),l,[])}:s[n.uuid]=o=>{let l=u([...r,o],n);return Object.assign(a(n)?i=>m([...r,o],i):Object.create(null),l)};else if(n.kind==="path")if(n.rest.length===0){let o=[...r,n.uuid],l=i=>m(o,i);s[n.uuid]=c(l,o,[])}else s[n.uuid]=u(r,n);else n.kind==="wrap"&&(s[n.uuid]=o=>{let i=n.when(o)?[...r,n.uuid]:r,f=u(i,n);return Object.assign(a(n)?P=>m(i,P):Object.create(null),f)});return c(s,r,e.rest)}function c(t,e,a){let r=(s,n)=>{let o=s?[...e,...Array.isArray(n)?n:[n]]:e;return a.length===0&&typeof t=="function"?c(i=>m(o,i),o,a):u(o,d("",a))};return t.$when=r,t.$join=s=>r(!0,s),t}0&&(module.exports={grow,nest,seed,tree,twig});
1
+ "use strict";var g=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var L=(t,e)=>{for(var s in e)g(t,s,{get:e[s],enumerable:!0})},P=(t,e,s,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of D(e))!C.call(t,o)&&o!==s&&g(t,o,{get:()=>e[o],enumerable:!(a=x(e,o))||a.enumerable});return t};var b=t=>P(g({},"__esModule",{value:!0}),t);var _={};L(_,{grow:()=>S,nest:()=>w,pick:()=>N,seed:()=>$,tree:()=>c,twig:()=>k});module.exports=b(_);var u=t=>t.replace(/^-+/,"").replace(/-+$/,"").replace(/^_+/,"").replace(/_+$/,"").replace(/-([a-zA-Z0-9])/g,(e,s)=>s.toUpperCase()).replace(/_([a-zA-Z0-9])/g,(e,s)=>s.toUpperCase()),A=/^[A-Za-z_-][A-Za-z0-9_-]*$/;function p(t,e){if(t==="path"&&e==="")return e.trim();if(!e)throw new Error(`${t} name cannot be empty`);if(!A.test(e))throw new Error(`${t} name "${e}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return e.trim()}var k=()=>({kind:"keep"}),c=(t,e)=>({kind:"path",name:p("path",t),uuid:u(t),list:e??[]}),$=(t,e)=>({kind:"slot",name:p("slot",t),uuid:`$${u(t)}`,list:e??[]}),w=(t,e,s)=>({kind:"wrap",name:p("wrap",t),uuid:`$${u(t)}`,when:e,list:s??[]}),N=(t,e,s)=>({kind:"pick",name:p("pick",t),uuid:`$${u(t)}`,mode:e,list:s??[]}),S=t=>l([],c("",t)),T=(t,e)=>`/${t.filter(Boolean).join("/").replace(/\/{2,}/g,"/")}${e?`?${e}`:""}`;function l(t,e){let s=n=>n.list.some(r=>r.kind==="keep"),a=e.kind==="path"&&e.name?[...t,e.name]:t,o=i(s(e),a);for(let n of e.list){if(n.kind!=="keep"&&n.uuid in o)throw new Error(`Duplicate uuid "${String(n.uuid)}" under "${a.join("/")||"/"}"`);if(n.kind==="slot")o[n.uuid]=function(f){let d=[...a,f];return n.list.length===0?m(i(!0,d),d,[]):Object.assign(i(s(n),d),l(d,n))};else if(n.kind==="path")if(n.list.length===0){let r=[...a,n.name];o[n.uuid]=m(i(!0,r),r,[])}else o[n.uuid]=l(a,n);else n.kind==="wrap"?o[n.uuid]=function(f){let h=n.when(f)?[...a,n.name]:a,y=l(h,n);return Object.assign(i(s(n),h),y)}:n.kind==="pick"&&(o[n.uuid]=r=>{if(n.mode[r])return l([...a,...n.mode[r]],c("",n.list));throw new Error(`pick("${n.name}") got unknown value: ${String(r)}`)})}return m(o,a,e.list)}function m(t,e,s){let a=(o,n)=>{let r=o?[...e,...Array.isArray(n)?n:[n]]:e;return s.length===0&&typeof t=="function"?m(i(!0,r),r,s):l(r,c("",s))};return t.$when=a,t.$join=function(n){return a(!0,n)},t}var i=(t,e)=>t?s=>T(e,s):Object.create(null);0&&(module.exports={grow,nest,pick,seed,tree,twig});
2
2
  //# sourceMappingURL=dialect-tree.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dialect-tree.ts","../src/api.ts"],"sourcesContent":["export { root as grow, path as tree, slot as seed, keep as twig, wrap as nest } from './api'\n","import {\n\tKebabToCamel,\n\tKeep,\n\tPath,\n\tPathDef,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamel = (s: string) => s.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\ntype KeyFromSeg<S extends string> = KebabToCamel<S>\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Path<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Slot<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\trest?: Rest\n): Wrap<Name, KeyFromSeg<Name>, Rest, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\twhen,\n\trest: (rest ?? []) as Rest,\n})\n\nconst IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path.filter(Boolean).join('/').replace('/\\/{2,}/g', '/')}${search ? `?${search}` : ''}`\n\n// ---------- Typed root signature ----------\nexport function root<const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> {\n\treturn buildPath([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n}\n\nfunction buildPath(prefix: Segment[], def: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.rest.some((c: any) => c.kind === 'keep')\n\tconst allPath =\n\t\tdef.kind === 'slot' || def.kind === 'wrap'\n\t\t\t? prefix\n\t\t\t: def.uuid\n\t\t\t\t? [...prefix, def.uuid]\n\t\t\t\t: prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = hasKeep(def)\n\t\t? (search?: SParams) => url(allPath, search)\n\t\t: Object.create(null)\n\n\tfor (const child of def.rest) {\n\t\tif (child.kind === 'slot') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\tconst leafPath = [...allPath, param]\n\t\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\t\treturn attachWhenAndJoin(fn, leafPath, [])\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\t// Build subtree for nested parts under :id\n\t\t\t\t\t// Synthetic path with empty name so we don't add extra segment.\n\t\t\t\t\tconst subTree = buildPath([...allPath, param], child)\n\n\t\t\t\t\t// Attach children (info, activities, etc.) to that function\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\thasKeep(child)\n\t\t\t\t\t\t\t? (search?: SParams) => url([...allPath, param], search)\n\t\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\t\tsubTree\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.uuid]\n\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(fn, leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildPath(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = (arg: unknown) => {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.uuid] : allPath\n\t\t\t\tconst subTree = buildPath(wrapped, child as any)\n\n\t\t\t\treturn Object.assign(\n\t\t\t\t\t// if wrap has keep(), it becomes callable at that point\n\t\t\t\t\thasKeep(child as any)\n\t\t\t\t\t\t? (search?: SParams) => url(wrapped, search)\n\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\tsubTree\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, def.rest)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], rest: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (rest.length === 0 && typeof target === 'function') {\n\t\t\tconst leaf: any = (search?: SParams) => url(nextPath, search)\n\t\t\treturn attachWhenAndJoin(leaf, nextPath, rest)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildPath(nextPath, path('', rest))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = (seg: Segment | readonly Segment[]) => when(true, seg)\n\n\treturn target\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAP,GCcA,IAAMQ,EAAWC,GAAcA,EAAE,QAAQ,kBAAmB,CAACC,EAAGC,IAAMA,EAAE,YAAY,CAAC,EAIxEC,EAAO,KAAa,CAAE,KAAM,MAAO,GAEnCC,EAAO,CAInBC,EACAC,KACyC,CACzC,KAAM,OACN,KAAMC,EAAgB,OAAQF,CAAI,EAClC,KAAMN,EAAQM,CAAI,EAClB,KAAOC,GAAQ,CAAC,CACjB,GAEaE,EAAO,CAInBH,EACAC,KACyC,CACzC,KAAM,OACN,KAAMC,EAAgB,OAAQF,CAAI,EAClC,KAAMN,EAAQM,CAAI,EAClB,KAAOC,GAAQ,CAAC,CACjB,GAEaG,EAAO,CAKnBJ,EACAK,EACAJ,KAC+C,CAC/C,KAAM,OACN,KAAMC,EAAgB,OAAQF,CAAI,EAClC,KAAMN,EAAQM,CAAI,EAClB,KAAAK,EACA,KAAOJ,GAAQ,CAAC,CACjB,GAEMK,EAAQ,2BAEd,SAASJ,EACRK,EACAP,EACO,CAEP,GAAIO,IAAS,QAAUP,IAAS,GAAI,OAAOA,EAAK,KAAK,EAErD,GAAI,CAACA,EAAM,MAAM,IAAI,MAAM,GAAGO,CAAI,uBAAuB,EACzD,GAAI,CAACD,EAAM,KAAKN,CAAI,EACnB,MAAM,IAAI,MACT,GA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f,GAAqBD,EAAIa,EAAUZ,CAAM,EAC1DS,EAAOC,EAAM,IAAI,EAAIG,EAAkBE,EAAIH,EAAU,CAAC,CAAC,CACxD,MACCH,EAAOC,EAAM,IAAI,EAAIP,EAAUK,EAASE,CAAK,OAEpCA,EAAM,OAAS,SACzBD,EAAOC,EAAM,IAAI,EAAKM,GAAiB,CAEtC,IAAMC,EADUP,EAAM,KAAKM,CAAG,EACJ,CAAC,GAAGR,EAASE,EAAM,IAAI,EAAIF,EAC/CM,EAAUX,EAAUc,EAASP,CAAY,EAE/C,OAAO,OAAO,OAEbJ,EAAQI,CAAY,EAChBV,GAAqBD,EAAIkB,EAASjB,CAAM,EACzC,OAAO,OAAO,IAAI,EACrBc,CACD,CACD,GAIF,OAAOD,EAAkBJ,EAAQD,EAASH,EAAI,IAAI,CACnD,CAEA,SAASQ,EAAkBJ,EAAaS,EAAqB1B,EAA0B,CACtF,IAAMI,EAAO,CAACuB,EAAeC,IAAsC,CAClE,IAAMC,EAAWF,EAAO,CAAC,GAAGD,EAAU,GAAI,MAAM,QAAQE,CAAG,EAAIA,EAAM,CAACA,CAAG,CAAE,EAAIF,EAG/E,OAAI1B,EAAK,SAAW,GAAK,OAAOiB,GAAW,WAEnCI,EADYb,GAAqBD,EAAIsB,EAAUrB,CAAM,EAC7BqB,EAAU7B,CAAI,EAKvCW,EAAUkB,EAAU/B,EAAK,GAAIE,CAAI,CAAC,CAC1C,EAEA,OAAAiB,EAAO,MAAQb,EACfa,EAAO,MAASW,GAAsCxB,EAAK,GAAMwB,CAAG,EAE7DX,CACR","names":["dialect_tree_exports","__export","root","wrap","slot","path","keep","__toCommonJS","toCamel","s","_","c","keep","path","name","rest","assertValidName","slot","wrap","when","IDENT","kind","url","search","root","defs","buildPath","prefix","def","hasKeep","pathDef","allPath","target","child","param","leafPath","attachWhenAndJoin","subTree","fn","arg","wrapped","basePath","cond","seg","nextPath"]}
1
+ {"version":3,"sources":["../src/dialect-tree.ts","../src/api.ts"],"sourcesContent":["export { root as grow, path as tree, slot as seed, keep as twig, wrap as nest, pick } from './api'\n","import {\n\tKeep,\n\tPath,\n\tPathDef,\n\tPick,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tToCamelCase,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamelCase = <S extends string>(s: S) =>\n\ts\n\t\t.replace(/^-+/, '')\n\t\t.replace(/-+$/, '')\n\t\t.replace(/^_+/, '')\n\t\t.replace(/_+$/, '')\n\t\t.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\n\t\t.replace(/_([a-zA-Z0-9])/g, (_, c) => c.toUpperCase()) as ToCamelCase<S>\n\nconst IDENT = /^[A-Za-z_-][A-Za-z0-9_-]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap' | 'pick',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Path<Name, ToCamelCase<Name>, List> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamelCase(name),\n\tlist: (list ?? []) as List,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tlist?: List\n): Slot<Name, `$${ToCamelCase<Name>}`, List> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tlist: (list ?? []) as List,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst List extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\tlist?: List\n): Wrap<Name, `$${ToCamelCase<Name>}`, List, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: `$${toCamelCase(name)}`,\n\twhen,\n\tlist: (list ?? []) as List,\n})\n\nexport const pick = <\n\tconst Name extends string,\n\tconst Mode extends Record<string, readonly Segment[]>,\n\tconst List extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\tmode: Mode,\n\tlist?: List\n): Pick<Name, `$${ToCamelCase<Name>}`, Mode, List> => ({\n\tkind: 'pick',\n\tname: assertValidName('pick', name),\n\tuuid: `$${toCamelCase(name)}`,\n\tmode,\n\tlist: (list ?? []) as List,\n})\n\nexport const root = <const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> =>\n\tbuildNode([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path\n\t\t.filter(Boolean)\n\t\t.join('/')\n\t\t.replace(/\\/{2,}/g, '/')}${search ? `?${search}` : ''}`\n\nfunction buildNode(prefix: Segment[], parent: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.list.some((node: any) => node.kind === 'keep')\n\tconst allPath = parent.kind === 'path' && parent.name ? [...prefix, parent.name] : prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = makeTarget(hasKeep(parent), allPath)\n\n\tfor (const child of parent.list) {\n\t\tif (child.kind !== 'keep') {\n\t\t\tif (child.uuid in target) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Duplicate uuid \"${String(child.uuid)}\" under \"${allPath.join('/') || '/'}\"`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tif (child.kind === 'slot') {\n\t\t\ttarget[child.uuid] = function bind(param: Segment) {\n\t\t\t\tconst next = [...allPath, param]\n\n\t\t\t\t// leaf slot => callable endpoint directly\n\t\t\t\tif (child.list.length === 0) {\n\t\t\t\t\treturn attachWhenAndJoin(makeTarget(true, next), next, [])\n\t\t\t\t}\n\n\t\t\t\t// non-leaf => subtree (optionally callable if keep())\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), next), buildNode(next, child))\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.list.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.name]\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(makeTarget(true, leafPath), leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildNode(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = function wrap(arg: unknown) {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.name] : allPath\n\t\t\t\tconst subTree = buildNode(wrapped, child)\n\n\t\t\t\treturn Object.assign(makeTarget(hasKeep(child), wrapped), subTree)\n\t\t\t}\n\t\t} else if (child.kind === 'pick') {\n\t\t\ttarget[child.uuid] = (value: keyof typeof child.mode) => {\n\t\t\t\tif (child.mode[value]) {\n\t\t\t\t\treturn buildNode([...allPath, ...child.mode[value]], path('', child.list))\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`pick(\"${child.name}\") got unknown value: ${String(value)}`)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, parent.list)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], list: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (list.length === 0 && typeof target === 'function') {\n\t\t\treturn attachWhenAndJoin(makeTarget(true, nextPath), nextPath, list)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildNode(nextPath, path('', list))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = function join(seg: Segment | readonly Segment[]) {\n\t\treturn when(true, seg)\n\t}\n\n\treturn target\n}\n\nconst makeTarget = (callable: boolean, currentPath: Segment[]) => {\n\treturn callable ? (search?: SParams) => url(currentPath, search) : Object.create(null)\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,EAAA,SAAAC,IAAA,eAAAC,EAAAR,GCeA,IAAMS,EAAiCC,GACtCA,EACE,QAAQ,MAAO,EAAE,EACjB,QAAQ,MAAO,EAAE,EACjB,QAAQ,MAAO,EAAE,EACjB,QAAQ,MAAO,EAAE,EACjB,QAAQ,kBAAmB,CAACC,EAAGC,IAAMA,EAAE,YAAY,CAAC,EACpD,QAAQ,kBAAmB,CAACD,EAAGC,IAAMA,EAAE,YAAY,CAAC,EAEjDC,EAAQ,6BAEd,SAASC,EACRC,EACAC,EACO,CAEP,GAAID,IAAS,QAAUC,IAAS,GAAI,OAAOA,EAAK,KAAK,EAErD,GAAI,CAACA,EAAM,MAAM,IAAI,MAAM,GAAGD,CAAI,uBAAuB,EACzD,GAAI,CAACF,EAAM,KAAKG,CAAI,EACnB,MAAM,IAAI,MACT,GAAGD,CAAI,UAAUC,CAAI,+EACtB,EAGD,OAAOA,EAAK,KAAK,CAClB,CAGO,IAAMC,EAAO,KAAa,CAAE,KAAM,MAAO,GAEnCC,EAAO,CAInBF,EACAG,KAC0C,CAC1C,KAAM,OACN,KAAML,EAAgB,OAAQE,CAAI,EAClC,KAAMP,EAAYO,CAAI,EACtB,KAAOG,GAAQ,CAAC,CACjB,GAEaC,EAAO,CAInB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CAAG,CAAE,EAAIF,EAG/E,OAAI5B,EAAK,SAAW,GAAK,OAAOiB,GAAW,WACnCK,EAAkBJ,EAAW,GAAMa,CAAQ,EAAGA,EAAU/B,CAAI,EAK7DQ,EAAUuB,EAAUhC,EAAK,GAAIC,CAAI,CAAC,CAC1C,EAEA,OAAAiB,EAAO,MAAQd,EACfc,EAAO,MAAQ,SAAca,EAAmC,CAC/D,OAAO3B,EAAK,GAAM2B,CAAG,CACtB,EAEOb,CACR,CAEA,IAAMC,EAAa,CAACc,EAAmBC,IAC/BD,EAAYtB,GAAqBD,EAAIwB,EAAavB,CAAM,EAAI,OAAO,OAAO,IAAI","names":["dialect_tree_exports","__export","root","wrap","pick","slot","path","keep","__toCommonJS","toCamelCase","s","_","c","IDENT","assertValidName","kind","name","keep","path","list","slot","wrap","when","pick","mode","root","defs","buildNode","url","search","prefix","parent","hasKeep","pathDef","node","allPath","target","makeTarget","child","param","next","attachWhenAndJoin","leafPath","arg","wrapped","subTree","value","basePath","cond","seg","nextPath","callable","currentPath"]}
@@ -1 +1 @@
1
- export { root as grow, wrap as nest, slot as seed, path as tree, keep as twig } from './api.cjs';
1
+ export { root as grow, wrap as nest, pick, slot as seed, path as tree, keep as twig } from './api.cjs';
@@ -1 +1 @@
1
- export { root as grow, wrap as nest, slot as seed, path as tree, keep as twig } from './api.js';
1
+ export { root as grow, wrap as nest, pick, slot as seed, path as tree, keep as twig } from './api.js';
@@ -1,2 +1,2 @@
1
- import{a as e,b as s,c as a,d as t,e as o}from"./chunk-5ZW66SPO.js";export{o as grow,t as nest,a as seed,s as tree,e as twig};
1
+ import{a as e,b as s,c as a,d as t,e as o,f as r}from"./chunk-TB22YO7J.js";export{r as grow,t as nest,o as pick,a as seed,s as tree,e as twig};
2
2
  //# sourceMappingURL=dialect-tree.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "route-sprout",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "A tiny, cute DSL that grows type-safe, composable URL builders from a declarative route tree.",
5
5
  "author": "Piotr Siatkowski <p.siatkowski@gmail.com>",
6
6
  "license": "MIT",
@@ -1,2 +0,0 @@
1
- var f=e=>e.replace(/-([a-zA-Z0-9])/g,(t,r)=>r.toUpperCase()),y=()=>({kind:"keep"}),p=(e,t)=>({kind:"path",name:g("path",e),uuid:f(e),rest:t??[]}),N=(e,t)=>({kind:"slot",name:g("slot",e),uuid:f(e),rest:t??[]}),P=(e,t,r)=>({kind:"wrap",name:g("wrap",e),uuid:f(e),when:t,rest:r??[]}),h=/^[A-Za-z_][A-Za-z0-9_]*$/;function g(e,t){if(e==="path"&&t==="")return t.trim();if(!t)throw new Error(`${e} name cannot be empty`);if(!h.test(t))throw new Error(`${e} name "${t}" must be a valid identifier (letters/digits/_/$, not starting with a digit).`);return t.trim()}var m=(e,t)=>`/${e.filter(Boolean).join("/").replace("//{2,}/g","/")}${t?`?${t}`:""}`;function w(e){return u([],p("",e))}function u(e,t){let r=n=>n.rest.some(a=>a.kind==="keep"),s=t.kind==="slot"||t.kind==="wrap"?e:t.uuid?[...e,t.uuid]:e,o=r(t)?n=>m(s,n):Object.create(null);for(let n of t.rest)if(n.kind==="slot")n.rest.length===0?o[n.uuid]=a=>{let l=[...s,a];return c(d=>m(l,d),l,[])}:o[n.uuid]=a=>{let l=u([...s,a],n);return Object.assign(r(n)?i=>m([...s,a],i):Object.create(null),l)};else if(n.kind==="path")if(n.rest.length===0){let a=[...s,n.uuid],l=i=>m(a,i);o[n.uuid]=c(l,a,[])}else o[n.uuid]=u(s,n);else n.kind==="wrap"&&(o[n.uuid]=a=>{let i=n.when(a)?[...s,n.uuid]:s,d=u(i,n);return Object.assign(r(n)?S=>m(i,S):Object.create(null),d)});return c(o,s,t.rest)}function c(e,t,r){let s=(o,n)=>{let a=o?[...t,...Array.isArray(n)?n:[n]]:t;return r.length===0&&typeof e=="function"?c(i=>m(a,i),a,r):u(a,p("",r))};return e.$when=s,e.$join=o=>s(!0,o),e}export{y as a,p as b,N as c,P as d,w as e};
2
- //# sourceMappingURL=chunk-5ZW66SPO.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/api.ts"],"sourcesContent":["import {\n\tKebabToCamel,\n\tKeep,\n\tPath,\n\tPathDef,\n\tRoutesFromDefs,\n\tSParams,\n\tSegment,\n\tSlot,\n\tSlotDef,\n\tWrap,\n} from './dsl'\n\n// ---------- Transform helpers ------------\nconst toCamel = (s: string) => s.replace(/-([a-zA-Z0-9])/g, (_, c) => c.toUpperCase())\ntype KeyFromSeg<S extends string> = KebabToCamel<S>\n\n// ---------- DSL helpers (typed) ----------\nexport const keep = (): Keep => ({ kind: 'keep' })\n\nexport const path = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Path<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'path',\n\tname: assertValidName('path', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const slot = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n>(\n\tname: Name,\n\trest?: Rest\n): Slot<Name, KeyFromSeg<Name>, Rest> => ({\n\tkind: 'slot',\n\tname: assertValidName('slot', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\trest: (rest ?? []) as Rest,\n})\n\nexport const wrap = <\n\tconst Name extends string,\n\tconst Rest extends readonly PathDef[] = readonly [],\n\tArgs = unknown,\n>(\n\tname: Name,\n\twhen: (args: Args) => boolean,\n\trest?: Rest\n): Wrap<Name, KeyFromSeg<Name>, Rest, Args> => ({\n\tkind: 'wrap',\n\tname: assertValidName('wrap', name),\n\tuuid: toCamel(name) as KeyFromSeg<Name>,\n\twhen,\n\trest: (rest ?? []) as Rest,\n})\n\nconst IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/\n\nfunction assertValidName<const Name extends string>(\n\tkind: 'path' | 'slot' | 'wrap',\n\tname: Name\n): Name {\n\t// Allow your synthetic node(\"\") only for nodes (internal)\n\tif (kind === 'path' && name === '') return name.trim() as Name\n\n\tif (!name) throw new Error(`${kind} name cannot be empty`)\n\tif (!IDENT.test(name)) {\n\t\tthrow new Error(\n\t\t\t`${kind} name \"${name}\" must be a valid identifier (letters/digits/_/$, not starting with a digit).`\n\t\t)\n\t}\n\n\treturn name.trim() as Name\n}\n\n// ---------- Runtime implementation ----------\nconst url = (path: Segment[], search?: SParams) =>\n\t`/${path.filter(Boolean).join('/').replace('/\\/{2,}/g', '/')}${search ? `?${search}` : ''}`\n\n// ---------- Typed root signature ----------\nexport function root<const Defs extends readonly PathDef[]>(defs: Defs): RoutesFromDefs<Defs> {\n\treturn buildPath([], path('', defs)) as unknown as RoutesFromDefs<Defs>\n}\n\nfunction buildPath(prefix: Segment[], def: SlotDef) {\n\tconst hasKeep = (pathDef: SlotDef) => pathDef.rest.some((c: any) => c.kind === 'keep')\n\tconst allPath =\n\t\tdef.kind === 'slot' || def.kind === 'wrap'\n\t\t\t? prefix\n\t\t\t: def.uuid\n\t\t\t\t? [...prefix, def.uuid]\n\t\t\t\t: prefix\n\n\t// If there is a keep(), the path itself is callable and acts as \"keep\"\n\tconst target: any = hasKeep(def)\n\t\t? (search?: SParams) => url(allPath, search)\n\t\t: Object.create(null)\n\n\tfor (const child of def.rest) {\n\t\tif (child.kind === 'slot') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\tconst leafPath = [...allPath, param]\n\t\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\t\treturn attachWhenAndJoin(fn, leafPath, [])\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = (param: Segment) => {\n\t\t\t\t\t// Build subtree for nested parts under :id\n\t\t\t\t\t// Synthetic path with empty name so we don't add extra segment.\n\t\t\t\t\tconst subTree = buildPath([...allPath, param], child)\n\n\t\t\t\t\t// Attach children (info, activities, etc.) to that function\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\thasKeep(child)\n\t\t\t\t\t\t\t? (search?: SParams) => url([...allPath, param], search)\n\t\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\t\tsubTree\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (child.kind === 'path') {\n\t\t\tif (child.rest.length === 0) {\n\t\t\t\tconst leafPath = [...allPath, child.uuid]\n\t\t\t\tconst fn: any = (search?: SParams) => url(leafPath, search)\n\t\t\t\ttarget[child.uuid] = attachWhenAndJoin(fn, leafPath, [])\n\t\t\t} else {\n\t\t\t\ttarget[child.uuid] = buildPath(allPath, child)\n\t\t\t}\n\t\t} else if (child.kind === 'wrap') {\n\t\t\ttarget[child.uuid] = (arg: unknown) => {\n\t\t\t\tconst enabled = child.when(arg)\n\t\t\t\tconst wrapped = enabled ? [...allPath, child.uuid] : allPath\n\t\t\t\tconst subTree = buildPath(wrapped, child as any)\n\n\t\t\t\treturn Object.assign(\n\t\t\t\t\t// if wrap has keep(), it becomes callable at that point\n\t\t\t\t\thasKeep(child as any)\n\t\t\t\t\t\t? (search?: SParams) => url(wrapped, search)\n\t\t\t\t\t\t: Object.create(null),\n\t\t\t\t\tsubTree\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn attachWhenAndJoin(target, allPath, def.rest)\n}\n\nfunction attachWhenAndJoin(target: any, basePath: Segment[], rest: readonly PathDef[]) {\n\tconst when = (cond: boolean, seg: Segment | readonly Segment[]) => {\n\t\tconst nextPath = cond ? [...basePath, ...(Array.isArray(seg) ? seg : [seg])] : basePath\n\n\t\t// If this is a callable leaf (no children), preserve callability after .when().\n\t\tif (rest.length === 0 && typeof target === 'function') {\n\t\t\tconst leaf: any = (search?: SParams) => url(nextPath, search)\n\t\t\treturn attachWhenAndJoin(leaf, nextPath, rest)\n\t\t}\n\n\t\t// Rebuild \"same subtree\" at a new prefix:\n\t\t// Use a synthetic path '' so we don't append an extra segment name.\n\t\treturn buildPath(nextPath, path('', rest))\n\t}\n\n\ttarget.$when = when\n\ttarget.$join = (seg: Segment | readonly Segment[]) => when(true, seg)\n\n\treturn target\n}\n"],"mappings":"AAcA,IAAMA,EAAWC,GAAcA,EAAE,QAAQ,kBAAmB,CAACC,EAAGC,IAAMA,EAAE,YAAY,CAAC,EAIxEC,EAAO,KAAa,CAAE,KAAM,MAAO,GAEnCC,EAAO,CAInBC,EACAC,KACyC,CACzC,KAAM,OACN,KAAMC,EAAgB,OAAQF,CAAI,EAClC,KAAMN,EAAQM,CAAI,EAClB,KAAOC,GAAQ,CAAC,CACjB,GAEaE,EAAO,CAInBH,EACAC,KACyC,CACzC,KAAM,OACN,KAAMC,EAAgB,OAAQF,CAAI,EAClC,KAAMN,EAAQM,CAAI,EAClB,KAAOC,GAAQ,CAAC,CACjB,GAEaG,EAAO,CAKnBJ,EACAK,EACAJ,KAC+C,CAC/C,KAAM,OACN,KAAMC,EAAgB,OAAQF,CAAI,EAClC,KAAMN,EAAQM,CAAI,EAClB,KAAAK,EACA,KAAOJ,GAAQ,CAAC,CACjB,GAEMK,EAAQ,2BAEd,SAASJ,EACRK,EACAP,EACO,CAEP,GAAIO,IAAS,QAAUP,IAAS,GAAI,OAAOA,EAAK,KAAK,EAErD,GAAI,CAACA,EAAM,MAAM,IAAI,MAAM,GAAGO,CAAI,uBAAuB,EACzD,GAAI,CAACD,EAAM,KAAKN,CAAI,EACnB,MAAM,IAAI,MACT,GAAGO,CAAI,UAAUP,CAAI,+EACtB,EAGD,OAAOA,EAAK,KAAK,CAClB,CAGA,IAAMQ,EAAM,CAACT,EAAiBU,IAC7B,IAAIV,EAAK,OAAO,OAAO,EAAE,KAAK,GAAG,EAAE,QAAQ,WAAa,GAAG,CAAC,GAAGU,EAAS,IAAIA,CAAM,GAAK,EAAE,GAGnF,SAASC,EAA4CC,EAAkC,CAC7F,OAAOC,EAAU,CAAC,EAAGb,EAAK,GAAIY,CAAI,CA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F,EAC/CM,EAAUX,EAAUc,EAASP,CAAY,EAE/C,OAAO,OAAO,OAEbJ,EAAQI,CAAY,EAChBV,GAAqBD,EAAIkB,EAASjB,CAAM,EACzC,OAAO,OAAO,IAAI,EACrBc,CACD,CACD,GAIF,OAAOD,EAAkBJ,EAAQD,EAASH,EAAI,IAAI,CACnD,CAEA,SAASQ,EAAkBJ,EAAaS,EAAqB1B,EAA0B,CACtF,IAAMI,EAAO,CAACuB,EAAeC,IAAsC,CAClE,IAAMC,EAAWF,EAAO,CAAC,GAAGD,EAAU,GAAI,MAAM,QAAQE,CAAG,EAAIA,EAAM,CAACA,CAAG,CAAE,EAAIF,EAG/E,OAAI1B,EAAK,SAAW,GAAK,OAAOiB,GAAW,WAEnCI,EADYb,GAAqBD,EAAIsB,EAAUrB,CAAM,EAC7BqB,EAAU7B,CAAI,EAKvCW,EAAUkB,EAAU/B,EAAK,GAAIE,CAAI,CAAC,CAC1C,EAEA,OAAAiB,EAAO,MAAQb,EACfa,EAAO,MAASW,GAAsCxB,EAAK,GAAMwB,CAAG,EAE7DX,CACR","names":["toCamel","s","_","c","keep","path","name","rest","assertValidName","slot","wrap","when","IDENT","kind","url","search","root","defs","buildPath","prefix","def","hasKeep","pathDef","allPath","target","child","param","leafPath","attachWhenAndJoin","subTree","fn","arg","wrapped","basePath","cond","seg","nextPath"]}