@rexezuge/contracts 1.15.0 → 1.17.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
@@ -102,6 +102,11 @@ both a Worker and a browser.
102
102
  without a `params` entry (also a type error), `params` keys that differ from the
103
103
  path's, a `GET` with a body, an error status outside 400–599, an unknown method
104
104
  or auth surface, and a missing `response`.
105
+ - **Trailing wildcard, nothing else.** A final `/:path*` (or bare `/*`, shorthand for `:path*`) captures the rest
106
+ of the path, slashes included, as a typed param (`params: z.object({ path: z.string() })`; the bare form names
107
+ it `path`). `registerContract` registers it as Hono's `:path{.+}`, so the remainder is never empty, and
108
+ `buildPath` encodes each sub-segment and refuses `.`/`..`. `*` anywhere else is a `TypeError`. The OpenAPI path
109
+ of a wildcard reads `/{path}{.+}`: valid for routing, rough in Swagger.
105
110
  - **Frozen and branded.** Only `defineEndpoint` makes an endpoint (`isEndpoint`),
106
111
  and `defineContract` refuses a spread copy, non-identifier names, and two
107
112
  endpoints with the same method and path.
@@ -112,26 +117,27 @@ both a Worker and a browser.
112
117
 
113
118
  ## Extending
114
119
 
115
- | You want | Door |
116
- | ----------------------------------------------------- | -------------------------------------------------------------------------- |
117
- | Your shapes | any zod 4 schema for `params` / `query` / `body` / `response` |
118
- | Extra documented errors, your own wording | `errors: [409]` or `errors: { 404: 'No such item' }` |
119
- | A 204 endpoint | `response: null` |
120
- | Docs grouping | `summary`, `description`, `tags` |
121
- | Compose contracts | `defineContract({ ...a, ...b })` |
122
- | A hand-written route (errorMapping, a raw `Response`) | `schemaFromEndpoint(endpoint)` in your own `FamilyRoute` subclass |
123
- | Types elsewhere | `EndpointInput`, `EndpointOutput`, `EndpointServerInput`, `EndpointResult` |
124
- | Build a URL yourself | `buildPath(endpoint.path, params)` |
120
+ | You want | Door |
121
+ | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
122
+ | Your shapes | any zod 4 schema for `params` / `query` / `body` / `response` |
123
+ | Extra documented errors, your own wording | `errors: [409]` or `errors: { 404: 'No such item' }` |
124
+ | A 204 endpoint | `response: null` |
125
+ | A text body (`text/plain`, any `text/*`) | `response: { kind: 'text' }` / `{ kind: 'text', mediaType: 'text/markdown' }`: the handler returns a string, OpenAPI documents `string` under that media type, the client resolves the unparsed string |
126
+ | Docs grouping | `summary`, `description`, `tags` |
127
+ | Compose contracts | `defineContract({ ...a, ...b })` |
128
+ | A hand-written route (errorMapping, a raw `Response`) | `schemaFromEndpoint(endpoint)` in your own `FamilyRoute` subclass |
129
+ | Types elsewhere | `EndpointInput`, `EndpointOutput`, `EndpointServerInput`, `EndpointResult` |
130
+ | Build a URL yourself | `buildPath(endpoint.path, params)` |
125
131
 
126
132
  ## Types
127
133
 
128
- | Type | Is |
129
- | ------------------------ | -------------------------------------------------------------------------- |
130
- | `EndpointInput<E>` | what the client passes: `params`, `query`, `body` (zod input), as declared |
131
- | `EndpointOutput<E>` | what the client resolves: the response's zod output, or `null` |
132
- | `EndpointServerInput<E>` | what the handler receives: validated zod output |
133
- | `EndpointResult<E>` | what the handler returns: the response's zod input, or `null` |
134
- | `PathParamNames<P>` | `'id' \| 'sub'` for `'/a/:id/b/:sub'` |
134
+ | Type | Is |
135
+ | ------------------------ | -------------------------------------------------------------------------------------------- |
136
+ | `EndpointInput<E>` | what the client passes: `params`, `query`, `body` (zod input), as declared |
137
+ | `EndpointOutput<E>` | what the client resolves: the response's zod output, `string` for a text response, or `null` |
138
+ | `EndpointServerInput<E>` | what the handler receives: validated zod output |
139
+ | `EndpointResult<E>` | what the handler returns: the response's zod input, `string` for a text response, or `null` |
140
+ | `PathParamNames<P>` | `'id' \| 'sub'` for `'/a/:id/b/:sub'` |
135
141
 
136
142
  A slot whose input accepts `{}` or `undefined` (an all-optional query) is optional
137
143
  in `EndpointInput`. Keep response schemas JSON-safe: the client receives JSON, so a
@@ -51,9 +51,20 @@ type AuthSurface = 'access' | 'apiKey' | 'public';
51
51
  Extra error statuses: a list (catalog wording) or status → description.
52
52
  */
53
53
  type EndpointErrors = readonly number[] | Readonly<Record<number, string>>;
54
+ /**
55
+ * A non-JSON success response: `{ kind: 'text' }` is `text/plain`. The handler returns a string, the OpenAPI
56
+ * schema documents `string` under that media type, and the client resolves it to the string, unparsed.
57
+ */
58
+ interface TextResponse {
59
+ readonly kind: 'text';
60
+ /**
61
+ The media type, any `text/*`. Defaults to `text/plain`.
62
+ */
63
+ readonly mediaType?: `text/${string}`;
64
+ }
54
65
  /**
55
66
  * What you write. `response: null` declares a `204 No Content` endpoint, and
56
- * the client resolves it to `null`.
67
+ * the client resolves it to `null`; `response: { kind: 'text' }` a text body (see {@link TextResponse}).
57
68
  */
58
69
  interface EndpointDefinition {
59
70
  method: HttpMethod;
@@ -68,7 +79,7 @@ interface EndpointDefinition {
68
79
  params?: z.ZodObject;
69
80
  query?: z.ZodObject;
70
81
  body?: z.ZodType;
71
- response: z.ZodType | null;
82
+ response: z.ZodType | TextResponse | null;
72
83
  errors?: EndpointErrors;
73
84
  }
74
85
  /**
@@ -153,14 +164,26 @@ type EndpointServerInput<E extends EndpointDefinition> = Simplify<(E extends {
153
164
  What the client resolves to: the response schema's output, or `null` for a 204.
154
165
  */
155
166
  type EndpointOutput<E extends EndpointDefinition> = E extends {
167
+ response: TextResponse;
168
+ } ? string : E extends {
156
169
  response: infer R extends z.ZodType;
157
170
  } ? z.output<R> : null;
158
171
  /**
159
172
  What a handler returns for serialization: the response schema's *input*, or `null`.
160
173
  */
161
174
  type EndpointResult<E extends EndpointDefinition> = E extends {
175
+ response: TextResponse;
176
+ } ? string : E extends {
162
177
  response: infer R extends z.ZodType;
163
178
  } ? z.input<R> : null;
179
+ /**
180
+ Whether a response declaration is the text form (a zod schema has no `kind`).
181
+ */
182
+ declare function isTextResponse(response: EndpointDefinition['response']): response is TextResponse;
183
+ /**
184
+ The media type of a text response.
185
+ */
186
+ declare function textMediaType(response: TextResponse): string;
164
187
  /**
165
188
  * Define one endpoint.
166
189
  *
@@ -180,6 +203,6 @@ declare function defineEndpoint<const D extends EndpointDefinition>(definition:
180
203
  Whether `value` came from `defineEndpoint`.
181
204
  */
182
205
  declare function isEndpoint(value: unknown): value is Endpoint;
183
- export { defineEndpoint, isEndpoint };
184
- export type { AuthSurface, Endpoint, EndpointDefinition, EndpointError, EndpointErrors, EndpointInput, EndpointOutput, EndpointResult, EndpointServerInput, HttpMethod, };
206
+ export { defineEndpoint, isEndpoint, isTextResponse, textMediaType };
207
+ export type { AuthSurface, Endpoint, EndpointDefinition, EndpointError, EndpointErrors, EndpointInput, EndpointOutput, EndpointResult, EndpointServerInput, HttpMethod, TextResponse, };
185
208
  //# sourceMappingURL=endpoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAC;AAE9B,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3D,KAAK,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,KAAK,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAElD;;EAEE;AACF,KAAK,cAAc,GAAG,SAAS,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE3E;;;GAGG;AACH,UAAU,kBAAkB;IAC1B,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,IAAI,EAAE,WAA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AAC,CAAC,CAyBzG;AAED;;EAEE;AACF,iBAAS,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAErD;AAED,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AACrE,YAAY,EACV,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,CAAC"}
package/dist/endpoint.js CHANGED
@@ -1 +1 @@
1
- var l=Object.defineProperty;var u=(e,r)=>l(e,"name",{value:r,configurable:!0});import{pathParamNames as b}from"./path.js";const m=["GET","POST","PUT","PATCH","DELETE"],n=["access","apiKey","public"],h=new WeakSet;function o(e,r){throw new TypeError(`Invalid endpoint ${String(e.method)} ${String(e.path)}: ${r}`)}u(o,"fail");function j(e,r){if(e.params===void 0){r.length>0&&o(e,`path declares ${r.map(a=>`:${a}`).join(", ")} but no params schema`);return}const t=e.params.shape;(typeof t!="object"||t===null)&&o(e,"params must be a zod object schema");const c=Object.keys(t).sort((a,p)=>a.localeCompare(p)),s=[...r].sort((a,p)=>a.localeCompare(p));c.join(",")!==s.join(",")&&o(e,`params keys [${c.join(", ")}] must match the path's [${s.join(", ")}]`)}u(j,"checkParams");function f(e){const r=[];(e.params!==void 0||e.query!==void 0||e.body!==void 0)&&r.push(400),e.auth!=="public"&&r.push(401,403),r.push(500);const t=Array.isArray(e.errors)?e.errors.map(s=>({status:s,description:null})):Object.entries(e.errors??{}).map(([s,a])=>({status:Number(s),description:a}));for(const{status:s}of t)(!Number.isInteger(s)||s<400||s>599)&&o(e,`error status ${s} is not 400\u2013599`);const c=new Map;for(const s of r)c.set(s,{status:s,description:null});for(const s of t)c.set(s.status,Object.freeze({...s}));return[...c.values()].sort((s,a)=>s.status-a.status).map(s=>Object.freeze(s))}u(f,"normalizeErrors");function y(e){m.includes(e.method)||o(e,`method must be one of ${m.join(", ")}`),n.includes(e.auth)||o(e,`auth must be one of ${n.join(", ")}`),e.response===void 0&&o(e,"response is required (a schema, or null for 204)"),e.method==="GET"&&e.body!==void 0&&o(e,"a GET endpoint cannot declare a body");let r;try{r=b(e.path)}catch(c){o(e,c.message)}j(e,r);const t={...e,...e.tags!==void 0&&{tags:Object.freeze([...e.tags])},pathParams:Object.freeze(r),errorResponses:Object.freeze(f(e))};return Object.freeze(t),h.add(t),t}u(y,"defineEndpoint");function E(e){return typeof e=="object"&&e!==null&&h.has(e)}u(E,"isEndpoint");export{y as defineEndpoint,E as isEndpoint};
1
+ var y=Object.defineProperty;var u=(e,t)=>y(e,"name",{value:t,configurable:!0});import{pathParamNames as j}from"./path.js";const m=["GET","POST","PUT","PATCH","DELETE"],h=["access","apiKey","public"];function l(e){return typeof e=="object"&&e!==null&&e.kind==="text"}u(l,"isTextResponse");function n(e){return e.mediaType??"text/plain"}u(n,"textMediaType");const b=new WeakSet;function a(e,t){throw new TypeError(`Invalid endpoint ${String(e.method)} ${String(e.path)}: ${t}`)}u(a,"fail");function f(e,t){if(e.params===void 0){t.length>0&&a(e,`path declares ${t.map(o=>`:${o}`).join(", ")} but no params schema`);return}const r=e.params.shape;(typeof r!="object"||r===null)&&a(e,"params must be a zod object schema");const c=Object.keys(r).sort((o,p)=>o.localeCompare(p)),s=[...t].sort((o,p)=>o.localeCompare(p));c.join(",")!==s.join(",")&&a(e,`params keys [${c.join(", ")}] must match the path's [${s.join(", ")}]`)}u(f,"checkParams");function d(e){const t=[];(e.params!==void 0||e.query!==void 0||e.body!==void 0)&&t.push(400),e.auth!=="public"&&t.push(401,403),t.push(500);const r=Array.isArray(e.errors)?e.errors.map(s=>({status:s,description:null})):Object.entries(e.errors??{}).map(([s,o])=>({status:Number(s),description:o}));for(const{status:s}of r)(!Number.isInteger(s)||s<400||s>599)&&a(e,`error status ${s} is not 400\u2013599`);const c=new Map;for(const s of t)c.set(s,{status:s,description:null});for(const s of r)c.set(s.status,Object.freeze({...s}));return[...c.values()].sort((s,o)=>s.status-o.status).map(s=>Object.freeze(s))}u(d,"normalizeErrors");function E(e){m.includes(e.method)||a(e,`method must be one of ${m.join(", ")}`),h.includes(e.auth)||a(e,`auth must be one of ${h.join(", ")}`),e.response===void 0&&a(e,"response is required (a schema, { kind: 'text' }, or null for 204)"),l(e.response)&&!/^text\/[\w.+-]+$/.test(n(e.response))&&a(e,`text response mediaType ${n(e.response)} must be text/*`),e.method==="GET"&&e.body!==void 0&&a(e,"a GET endpoint cannot declare a body");let t;try{t=j(e.path)}catch(c){a(e,c.message)}f(e,t);const r={...e,...e.tags!==void 0&&{tags:Object.freeze([...e.tags])},pathParams:Object.freeze(t),errorResponses:Object.freeze(d(e))};return Object.freeze(r),b.add(r),r}u(E,"defineEndpoint");function T(e){return typeof e=="object"&&e!==null&&b.has(e)}u(T,"isEndpoint");export{E as defineEndpoint,T as isEndpoint,l as isTextResponse,n as textMediaType};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/endpoint.ts"],
4
- "sourcesContent": ["/**\n * `defineEndpoint`: one object that describes a route to both ends.\n *\n * Twelve repos hand-copied their API's request and response shapes into\n * `apps/web/src/types.ts`, and a copy is the half of a contract nobody checks:\n * a renamed field compiled on both sides and failed only in a browser. An\n * endpoint here is the single source. The backend turns it into a chanfana\n * route (`@rexezuge/http/hono`'s `routeFromEndpoint`), whose schema validates the\n * request and documents the responses. The SPA turns it into a typed call\n * (`@rexezuge/web`'s `createContractClient`). There is no code generation, so\n * there is no generated file to go stale.\n *\n * ## Closed\n *\n * - The definition is **validated once**, at module load: a malformed path, a\n * `:param` without a schema entry (or a schema entry without a `:param`), a\n * `GET` with a body, an error status outside 400–599. Each throws a\n * `TypeError`, so a bad contract fails every test that imports it.\n * - The result is **frozen**, and only `defineEndpoint` makes one\n * (`isEndpoint` checks a private brand), so a contract cannot be patched\n * after the backend registered it.\n * - The errors every endpoint can produce are **implied**, never forgotten:\n * `400` when it validates input, `401`/`403` on an authenticated surface,\n * `500` always. `errors` adds to that set.\n *\n * ## Open\n *\n * Your schemas (zod 4, the major chanfana 3 uses), `summary`/`description`/\n * `tags`, the auth surface, and the extra error statuses with your own wording.\n *\n * This module imports nothing from zod at runtime. It only reads `.shape` from\n * a params object, so zod is a peer you need to *write* a contract, and the\n * client bundle carries no second copy.\n */\nimport type * as z from 'zod';\nimport { pathParamNames } from './path.ts';\nimport type { PathParamNames, PathValue } from './path.ts';\n\ntype HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/**\n * Which authenticated surface serves the endpoint.\n *\n * - `access`: Cloudflare Access (`accessAuth`), the SPA's `/user/*` surface.\n * - `apiKey`: a key or token surface (`apiKeyAuth`).\n * - `public`: no authentication.\n *\n * The backend adapter fails closed on it. An `access` or `apiKey` endpoint\n * served without an authenticated user answers `401`, even if the app forgot\n * to mount the auth middleware on its path.\n */\ntype AuthSurface = 'access' | 'apiKey' | 'public';\n\n/**\nExtra error statuses: a list (catalog wording) or status → description.\n*/\ntype EndpointErrors = readonly number[] | Readonly<Record<number, string>>;\n\n/**\n * What you write. `response: null` declares a `204 No Content` endpoint, and\n * the client resolves it to `null`.\n */\ninterface EndpointDefinition {\n method: HttpMethod;\n path: string;\n summary?: string;\n description?: string;\n tags?: readonly string[];\n auth: AuthSurface;\n /**\n Required when `path` has `:params`; its keys must be exactly those names.\n */\n params?: z.ZodObject;\n query?: z.ZodObject;\n body?: z.ZodType;\n response: z.ZodType | null;\n errors?: EndpointErrors;\n}\n\n/**\nOne documented error status. `description` is `null` for the catalog wording.\n*/\ninterface EndpointError {\n status: number;\n description: string | null;\n}\n\ndeclare const ENDPOINT_BRAND: unique symbol;\n\n/**\n * A defined endpoint: your definition, frozen, plus the derived facts both\n * adapters read.\n */\ntype Endpoint<D extends EndpointDefinition = EndpointDefinition> = Readonly<D> & {\n readonly [ENDPOINT_BRAND]: true;\n /**\n The template's parameter names, in order.\n */\n readonly pathParams: readonly string[];\n /**\n Every error status the endpoint documents: implied ones first, then yours.\n */\n readonly errorResponses: readonly EndpointError[];\n};\n\n/**\n`params` is required by the type as soon as the template has a `:name`.\n*/\ntype RequireParams<D extends EndpointDefinition> = [PathParamNames<D['path']>] extends [never]\n ? unknown\n : { params: z.ZodObject<Record<PathParamNames<D['path']>, z.ZodType>> };\n\n/**\nThe empty slot set: an endpoint that takes no input.\n*/\ntype NoSlots = Record<never, never>;\n\ntype Simplify<T> = { [K in keyof T]: T[K] };\n\n/**\n`{ key: T }` when `T` must be given, `{ key?: T }` when it may be omitted.\n*/\ntype Slot<K extends string, T> = undefined extends T ? { [P in K]?: T } : NoSlots extends T ? { [P in K]?: T } : { [P in K]: T };\n\n/**\n * What a caller passes: `params` (typed from the schema, or from the template's\n * names), `query` and `body` (each a zod *input*), each present only when the\n * endpoint declares it.\n */\ntype EndpointInput<E extends EndpointDefinition> = Simplify<\n (E extends { params: infer P extends z.ZodType }\n ? { params: z.input<P> }\n : [PathParamNames<E['path']>] extends [never]\n ? NoSlots\n : { params: Record<PathParamNames<E['path']>, PathValue> }) &\n (E extends { query: infer Q extends z.ZodType } ? Slot<'query', z.input<Q>> : NoSlots) &\n (E extends { body: infer B extends z.ZodType } ? Slot<'body', z.input<B>> : NoSlots)\n>;\n\n/**\nWhat the handler receives: the same slots, as validated zod *output*.\n*/\ntype EndpointServerInput<E extends EndpointDefinition> = Simplify<\n (E extends { params: infer P extends z.ZodType } ? { params: z.output<P> } : NoSlots) &\n (E extends { query: infer Q extends z.ZodType } ? { query: z.output<Q> } : NoSlots) &\n (E extends { body: infer B extends z.ZodType } ? { body: z.output<B> } : NoSlots)\n>;\n\n/**\nWhat the client resolves to: the response schema's output, or `null` for a 204.\n*/\ntype EndpointOutput<E extends EndpointDefinition> = E extends { response: infer R extends z.ZodType } ? z.output<R> : null;\n\n/**\nWhat a handler returns for serialization: the response schema's *input*, or `null`.\n*/\ntype EndpointResult<E extends EndpointDefinition> = E extends { response: infer R extends z.ZodType } ? z.input<R> : null;\n\nconst METHODS: readonly HttpMethod[] = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];\nconst AUTH_SURFACES: readonly AuthSurface[] = ['access', 'apiKey', 'public'];\n\n/**\nEndpoints `defineEndpoint` made: the brand that cannot be forged by spreading.\n*/\nconst DEFINED = new WeakSet<object>();\n\nfunction fail(definition: { method?: unknown; path?: unknown }, problem: string): never {\n throw new TypeError(`Invalid endpoint ${String(definition.method)} ${String(definition.path)}: ${problem}`);\n}\n\nfunction checkParams(definition: EndpointDefinition, names: readonly string[]): void {\n if (definition.params === undefined) {\n if (names.length > 0) fail(definition, `path declares ${names.map((name) => `:${name}`).join(', ')} but no params schema`);\n return;\n }\n const shape = (definition.params as { shape?: unknown }).shape;\n if (typeof shape !== 'object' || shape === null) fail(definition, 'params must be a zod object schema');\n const keys = Object.keys(shape).sort((left, right) => left.localeCompare(right));\n const expected = [...names].sort((left, right) => left.localeCompare(right));\n if (keys.join(',') !== expected.join(',')) {\n fail(definition, `params keys [${keys.join(', ')}] must match the path's [${expected.join(', ')}]`);\n }\n}\n\nfunction normalizeErrors(definition: EndpointDefinition): EndpointError[] {\n const implied: number[] = [];\n if (definition.params !== undefined || definition.query !== undefined || definition.body !== undefined) implied.push(400);\n if (definition.auth !== 'public') implied.push(401, 403);\n implied.push(500);\n\n const given: EndpointError[] = Array.isArray(definition.errors)\n ? (definition.errors as readonly number[]).map((status) => ({ status, description: null }))\n : Object.entries((definition.errors ?? {}) as Readonly<Record<number, string>>).map(([status, description]) => ({\n status: Number(status),\n description,\n }));\n for (const { status } of given) {\n if (!Number.isInteger(status) || status < 400 || status > 599) fail(definition, `error status ${status} is not 400–599`);\n }\n\n const byStatus = new Map<number, EndpointError>();\n for (const status of implied) byStatus.set(status, { status, description: null });\n // Yours win: the same status with your wording replaces the catalog one.\n for (const entry of given) byStatus.set(entry.status, Object.freeze({ ...entry }));\n return [...byStatus.values()].sort((left, right) => left.status - right.status).map((entry) => Object.freeze(entry));\n}\n\n/**\n * Define one endpoint.\n *\n * ```ts\n * const getItem = defineEndpoint({\n * method: 'GET',\n * path: '/user/items/:id',\n * auth: 'access',\n * params: z.object({ id: z.string() }),\n * response: Item,\n * errors: { 404: 'No such item' },\n * });\n * ```\n */\nfunction defineEndpoint<const D extends EndpointDefinition>(definition: D & RequireParams<D>): Endpoint<D> {\n if (!METHODS.includes(definition.method)) fail(definition, `method must be one of ${METHODS.join(', ')}`);\n if (!AUTH_SURFACES.includes(definition.auth)) fail(definition, `auth must be one of ${AUTH_SURFACES.join(', ')}`);\n if (definition.response === undefined) fail(definition, 'response is required (a schema, or null for 204)');\n if (definition.method === 'GET' && definition.body !== undefined) fail(definition, 'a GET endpoint cannot declare a body');\n let names: string[];\n try {\n names = pathParamNames(definition.path);\n } catch (error: unknown) {\n fail(definition, (error as Error).message);\n }\n checkParams(definition, names);\n\n const endpoint = {\n ...definition,\n ...(definition.tags !== undefined && { tags: Object.freeze([...definition.tags]) }),\n pathParams: Object.freeze(names),\n errorResponses: Object.freeze(normalizeErrors(definition)),\n };\n Object.freeze(endpoint);\n DEFINED.add(endpoint);\n return endpoint as unknown as Endpoint<D>;\n}\n\n/**\nWhether `value` came from `defineEndpoint`.\n*/\nfunction isEndpoint(value: unknown): value is Endpoint {\n return typeof value === 'object' && value !== null && DEFINED.has(value);\n}\n\nexport { defineEndpoint, isEndpoint };\nexport type {\n AuthSurface,\n Endpoint,\n EndpointDefinition,\n EndpointError,\n EndpointErrors,\n EndpointInput,\n EndpointOutput,\n EndpointResult,\n EndpointServerInput,\n HttpMethod,\n};\n"],
5
- "mappings": "+EAmCA,OAAS,kBAAAA,MAAsB,YA2H/B,MAAMC,EAAiC,CAAC,MAAO,OAAQ,MAAO,QAAS,QAAQ,EACzEC,EAAwC,CAAC,SAAU,SAAU,QAAQ,EAKrEC,EAAU,IAAI,QAEpB,SAASC,EAAKC,EAAkDC,EAAe,CAC7E,MAAM,IAAI,UAAU,oBAAoB,OAAOD,EAAW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AQ,IAAIsB,CAAQ,EACbA,CACT,CAtBSlB,EAAAgB,EAAA,kBA2BT,SAASG,EAAWC,EAAc,CAChC,OAAO,OAAOA,GAAU,UAAYA,IAAU,MAAQxB,EAAQ,IAAIwB,CAAK,CACzE,CAFSpB,EAAAmB,EAAA",
6
- "names": ["pathParamNames", "METHODS", "AUTH_SURFACES", "DEFINED", "fail", "definition", "problem", "__name", "checkParams", "names", "name", "shape", "keys", "left", "right", "expected", "normalizeErrors", "implied", "given", "status", "description", "byStatus", "entry", "defineEndpoint", "error", "endpoint", "isEndpoint", "value"]
4
+ "sourcesContent": ["/**\n * `defineEndpoint`: one object that describes a route to both ends.\n *\n * Twelve repos hand-copied their API's request and response shapes into\n * `apps/web/src/types.ts`, and a copy is the half of a contract nobody checks:\n * a renamed field compiled on both sides and failed only in a browser. An\n * endpoint here is the single source. The backend turns it into a chanfana\n * route (`@rexezuge/http/hono`'s `routeFromEndpoint`), whose schema validates the\n * request and documents the responses. The SPA turns it into a typed call\n * (`@rexezuge/web`'s `createContractClient`). There is no code generation, so\n * there is no generated file to go stale.\n *\n * ## Closed\n *\n * - The definition is **validated once**, at module load: a malformed path, a\n * `:param` without a schema entry (or a schema entry without a `:param`), a\n * `GET` with a body, an error status outside 400–599. Each throws a\n * `TypeError`, so a bad contract fails every test that imports it.\n * - The result is **frozen**, and only `defineEndpoint` makes one\n * (`isEndpoint` checks a private brand), so a contract cannot be patched\n * after the backend registered it.\n * - The errors every endpoint can produce are **implied**, never forgotten:\n * `400` when it validates input, `401`/`403` on an authenticated surface,\n * `500` always. `errors` adds to that set.\n *\n * ## Open\n *\n * Your schemas (zod 4, the major chanfana 3 uses), `summary`/`description`/\n * `tags`, the auth surface, and the extra error statuses with your own wording.\n *\n * This module imports nothing from zod at runtime. It only reads `.shape` from\n * a params object, so zod is a peer you need to *write* a contract, and the\n * client bundle carries no second copy.\n */\nimport type * as z from 'zod';\nimport { pathParamNames } from './path.ts';\nimport type { PathParamNames, PathValue } from './path.ts';\n\ntype HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/**\n * Which authenticated surface serves the endpoint.\n *\n * - `access`: Cloudflare Access (`accessAuth`), the SPA's `/user/*` surface.\n * - `apiKey`: a key or token surface (`apiKeyAuth`).\n * - `public`: no authentication.\n *\n * The backend adapter fails closed on it. An `access` or `apiKey` endpoint\n * served without an authenticated user answers `401`, even if the app forgot\n * to mount the auth middleware on its path.\n */\ntype AuthSurface = 'access' | 'apiKey' | 'public';\n\n/**\nExtra error statuses: a list (catalog wording) or status → description.\n*/\ntype EndpointErrors = readonly number[] | Readonly<Record<number, string>>;\n\n/**\n * A non-JSON success response: `{ kind: 'text' }` is `text/plain`. The handler returns a string, the OpenAPI\n * schema documents `string` under that media type, and the client resolves it to the string, unparsed.\n */\ninterface TextResponse {\n readonly kind: 'text';\n /**\n The media type, any `text/*`. Defaults to `text/plain`.\n */\n readonly mediaType?: `text/${string}`;\n}\n\n/**\n * What you write. `response: null` declares a `204 No Content` endpoint, and\n * the client resolves it to `null`; `response: { kind: 'text' }` a text body (see {@link TextResponse}).\n */\ninterface EndpointDefinition {\n method: HttpMethod;\n path: string;\n summary?: string;\n description?: string;\n tags?: readonly string[];\n auth: AuthSurface;\n /**\n Required when `path` has `:params`; its keys must be exactly those names.\n */\n params?: z.ZodObject;\n query?: z.ZodObject;\n body?: z.ZodType;\n response: z.ZodType | TextResponse | null;\n errors?: EndpointErrors;\n}\n\n/**\nOne documented error status. `description` is `null` for the catalog wording.\n*/\ninterface EndpointError {\n status: number;\n description: string | null;\n}\n\ndeclare const ENDPOINT_BRAND: unique symbol;\n\n/**\n * A defined endpoint: your definition, frozen, plus the derived facts both\n * adapters read.\n */\ntype Endpoint<D extends EndpointDefinition = EndpointDefinition> = Readonly<D> & {\n readonly [ENDPOINT_BRAND]: true;\n /**\n The template's parameter names, in order.\n */\n readonly pathParams: readonly string[];\n /**\n Every error status the endpoint documents: implied ones first, then yours.\n */\n readonly errorResponses: readonly EndpointError[];\n};\n\n/**\n`params` is required by the type as soon as the template has a `:name`.\n*/\ntype RequireParams<D extends EndpointDefinition> = [PathParamNames<D['path']>] extends [never]\n ? unknown\n : { params: z.ZodObject<Record<PathParamNames<D['path']>, z.ZodType>> };\n\n/**\nThe empty slot set: an endpoint that takes no input.\n*/\ntype NoSlots = Record<never, never>;\n\ntype Simplify<T> = { [K in keyof T]: T[K] };\n\n/**\n`{ key: T }` when `T` must be given, `{ key?: T }` when it may be omitted.\n*/\ntype Slot<K extends string, T> = undefined extends T ? { [P in K]?: T } : NoSlots extends T ? { [P in K]?: T } : { [P in K]: T };\n\n/**\n * What a caller passes: `params` (typed from the schema, or from the template's\n * names), `query` and `body` (each a zod *input*), each present only when the\n * endpoint declares it.\n */\ntype EndpointInput<E extends EndpointDefinition> = Simplify<\n (E extends { params: infer P extends z.ZodType }\n ? { params: z.input<P> }\n : [PathParamNames<E['path']>] extends [never]\n ? NoSlots\n : { params: Record<PathParamNames<E['path']>, PathValue> }) &\n (E extends { query: infer Q extends z.ZodType } ? Slot<'query', z.input<Q>> : NoSlots) &\n (E extends { body: infer B extends z.ZodType } ? Slot<'body', z.input<B>> : NoSlots)\n>;\n\n/**\nWhat the handler receives: the same slots, as validated zod *output*.\n*/\ntype EndpointServerInput<E extends EndpointDefinition> = Simplify<\n (E extends { params: infer P extends z.ZodType } ? { params: z.output<P> } : NoSlots) &\n (E extends { query: infer Q extends z.ZodType } ? { query: z.output<Q> } : NoSlots) &\n (E extends { body: infer B extends z.ZodType } ? { body: z.output<B> } : NoSlots)\n>;\n\n/**\nWhat the client resolves to: the response schema's output, or `null` for a 204.\n*/\ntype EndpointOutput<E extends EndpointDefinition> = E extends { response: TextResponse }\n ? string\n : E extends { response: infer R extends z.ZodType }\n ? z.output<R>\n : null;\n\n/**\nWhat a handler returns for serialization: the response schema's *input*, or `null`.\n*/\ntype EndpointResult<E extends EndpointDefinition> = E extends { response: TextResponse }\n ? string\n : E extends { response: infer R extends z.ZodType }\n ? z.input<R>\n : null;\n\nconst METHODS: readonly HttpMethod[] = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];\nconst AUTH_SURFACES: readonly AuthSurface[] = ['access', 'apiKey', 'public'];\n\n/**\nWhether a response declaration is the text form (a zod schema has no `kind`).\n*/\nfunction isTextResponse(response: EndpointDefinition['response']): response is TextResponse {\n return typeof response === 'object' && response !== null && (response as { kind?: unknown }).kind === 'text';\n}\n\n/**\nThe media type of a text response.\n*/\nfunction textMediaType(response: TextResponse): string {\n return response.mediaType ?? 'text/plain';\n}\n\n/**\nEndpoints `defineEndpoint` made: the brand that cannot be forged by spreading.\n*/\nconst DEFINED = new WeakSet<object>();\n\nfunction fail(definition: { method?: unknown; path?: unknown }, problem: string): never {\n throw new TypeError(`Invalid endpoint ${String(definition.method)} ${String(definition.path)}: ${problem}`);\n}\n\nfunction checkParams(definition: EndpointDefinition, names: readonly string[]): void {\n if (definition.params === undefined) {\n if (names.length > 0) fail(definition, `path declares ${names.map((name) => `:${name}`).join(', ')} but no params schema`);\n return;\n }\n const shape = (definition.params as { shape?: unknown }).shape;\n if (typeof shape !== 'object' || shape === null) fail(definition, 'params must be a zod object schema');\n const keys = Object.keys(shape).sort((left, right) => left.localeCompare(right));\n const expected = [...names].sort((left, right) => left.localeCompare(right));\n if (keys.join(',') !== expected.join(',')) {\n fail(definition, `params keys [${keys.join(', ')}] must match the path's [${expected.join(', ')}]`);\n }\n}\n\nfunction normalizeErrors(definition: EndpointDefinition): EndpointError[] {\n const implied: number[] = [];\n if (definition.params !== undefined || definition.query !== undefined || definition.body !== undefined) implied.push(400);\n if (definition.auth !== 'public') implied.push(401, 403);\n implied.push(500);\n\n const given: EndpointError[] = Array.isArray(definition.errors)\n ? (definition.errors as readonly number[]).map((status) => ({ status, description: null }))\n : Object.entries((definition.errors ?? {}) as Readonly<Record<number, string>>).map(([status, description]) => ({\n status: Number(status),\n description,\n }));\n for (const { status } of given) {\n if (!Number.isInteger(status) || status < 400 || status > 599) fail(definition, `error status ${status} is not 400–599`);\n }\n\n const byStatus = new Map<number, EndpointError>();\n for (const status of implied) byStatus.set(status, { status, description: null });\n // Yours win: the same status with your wording replaces the catalog one.\n for (const entry of given) byStatus.set(entry.status, Object.freeze({ ...entry }));\n return [...byStatus.values()].sort((left, right) => left.status - right.status).map((entry) => Object.freeze(entry));\n}\n\n/**\n * Define one endpoint.\n *\n * ```ts\n * const getItem = defineEndpoint({\n * method: 'GET',\n * path: '/user/items/:id',\n * auth: 'access',\n * params: z.object({ id: z.string() }),\n * response: Item,\n * errors: { 404: 'No such item' },\n * });\n * ```\n */\nfunction defineEndpoint<const D extends EndpointDefinition>(definition: D & RequireParams<D>): Endpoint<D> {\n if (!METHODS.includes(definition.method)) fail(definition, `method must be one of ${METHODS.join(', ')}`);\n if (!AUTH_SURFACES.includes(definition.auth)) fail(definition, `auth must be one of ${AUTH_SURFACES.join(', ')}`);\n if (definition.response === undefined) fail(definition, \"response is required (a schema, { kind: 'text' }, or null for 204)\");\n if (isTextResponse(definition.response) && !/^text\\/[\\w.+-]+$/.test(textMediaType(definition.response))) {\n fail(definition, `text response mediaType ${textMediaType(definition.response)} must be text/*`);\n }\n if (definition.method === 'GET' && definition.body !== undefined) fail(definition, 'a GET endpoint cannot declare a body');\n let names: string[];\n try {\n names = pathParamNames(definition.path);\n } catch (error: unknown) {\n fail(definition, (error as Error).message);\n }\n checkParams(definition, names);\n\n const endpoint = {\n ...definition,\n ...(definition.tags !== undefined && { tags: Object.freeze([...definition.tags]) }),\n pathParams: Object.freeze(names),\n errorResponses: Object.freeze(normalizeErrors(definition)),\n };\n Object.freeze(endpoint);\n DEFINED.add(endpoint);\n return endpoint as unknown as Endpoint<D>;\n}\n\n/**\nWhether `value` came from `defineEndpoint`.\n*/\nfunction isEndpoint(value: unknown): value is Endpoint {\n return typeof value === 'object' && value !== null && DEFINED.has(value);\n}\n\nexport { defineEndpoint, isEndpoint, isTextResponse, textMediaType };\nexport type {\n AuthSurface,\n Endpoint,\n EndpointDefinition,\n EndpointError,\n EndpointErrors,\n EndpointInput,\n EndpointOutput,\n EndpointResult,\n EndpointServerInput,\n HttpMethod,\n TextResponse,\n};\n"],
5
+ "mappings": "+EAmCA,OAAS,kBAAAA,MAAsB,YA+I/B,MAAMC,EAAiC,CAAC,MAAO,OAAQ,MAAO,QAAS,QAAQ,EACzEC,EAAwC,CAAC,SAAU,SAAU,QAAQ,EAK3E,SAASC,EAAeC,EAAwC,CAC9D,OAAO,OAAOA,GAAa,UAAYA,IAAa,MAASA,EAAgC,OAAS,MACxG,CAFSC,EAAAF,EAAA,kBAOT,SAASG,EAAcF,EAAsB,CAC3C,OAAOA,EAAS,WAAa,YAC/B,CAFSC,EAAAC,EAAA,iBAOT,MAAMC,EAAU,IAAI,QAEpB,SAASC,EAAKC,EAAkDC,EAAe,CAC7E,MAAM,IAAI,UAAU,oBAAoB,OAAOD,EAAW,MAAM,CAAC,IAAI,OAAOA,EAAW,IAAI,CAAC,KAAKC,CAAO,EAAE,CAC5G,CAFSL,EAAAG,EAAA,QAIT,SAASG,EAAYF,EAAgCG,EAAwB,CAC3E,GAAIH,EAAW,SAAW,OAAW,CAC/BG,EAAM,OAAS,GAAGJ,EAAKC,EAAY,iBAAiBG,EAAM,IAAKC,GAAS,IAAIA,CAAI,EAAE,EAAE,KAAK,IAAI,CAAC,uBAAuB,EACzH,MACF,CACA,MAAMC,EAASL,EAAW,OAA+B,OACrD,OAAOK,GAAU,UAAYA,IAAU,OAAMN,EAAKC,EAAY,oCAAoC,EACtG,MAAMM,EAAO,OAAO,KAAKD,CAAK,EAAE,KAAK,CAACE,EAAMC,IAAUD,EAAK,cAAcC,CAAK,CAAC,EACzEC,EAAW,CAAC,GAAGN,CAAK,EAAE,KAAK,CAACI,EAAMC,IAAUD,EAAK,cAAcC,CAAK,CAAC,EACvEF,EAAK,KAAK,GAAG,IAAMG,EAAS,KAAK,GAAG,GACtCV,EAAKC,EAAY,gBAAgBM,EAAK,KAAK,IAAI,CA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KC,EAAY,uBAAuBP,EAAc,KAAK,IAAI,CAAC,EAAE,EAC5GO,EAAW,WAAa,QAAWD,EAAKC,EAAY,oEAAoE,EACxHN,EAAeM,EAAW,QAAQ,GAAK,CAAC,mBAAmB,KAAKH,EAAcG,EAAW,QAAQ,CAAC,GACpGD,EAAKC,EAAY,2BAA2BH,EAAcG,EAAW,QAAQ,CAAC,iBAAiB,EAE7FA,EAAW,SAAW,OAASA,EAAW,OAAS,QAAWD,EAAKC,EAAY,sCAAsC,EACzH,IAAIG,EACJ,GAAI,CACFA,EAAQZ,EAAeS,EAAW,IAAI,CACxC,OAASkB,EAAgB,CACvBnB,EAAKC,EAAakB,EAAgB,OAAO,CAC3C,CACAhB,EAAYF,EAAYG,CAAK,EAE7B,MAAMgB,EAAW,CACf,GAAGnB,EACH,GAAIA,EAAW,OAAS,QAAa,CAAE,KAAM,OAAO,OAAO,CAAC,GAAGA,EAAW,IAAI,CAAC,CAAC,EAChF,WAAY,OAAO,OAAOG,CAAK,EAC/B,eAAgB,OAAO,OAAOO,EAAgBV,CAAU,CAAC,GAE3D,cAAO,OAAOmB,CAAQ,EACtBrB,EAAQ,IAAIqB,CAAQ,EACbA,CACT,CAzBSvB,EAAAqB,EAAA,kBA8BT,SAASG,EAAWC,EAAc,CAChC,OAAO,OAAOA,GAAU,UAAYA,IAAU,MAAQvB,EAAQ,IAAIuB,CAAK,CACzE,CAFSzB,EAAAwB,EAAA",
6
+ "names": ["pathParamNames", "METHODS", "AUTH_SURFACES", "isTextResponse", "response", "__name", "textMediaType", "DEFINED", "fail", "definition", "problem", "checkParams", "names", "name", "shape", "keys", "left", "right", "expected", "normalizeErrors", "implied", "given", "status", "description", "byStatus", "entry", "defineEndpoint", "error", "endpoint", "isEndpoint", "value"]
7
7
  }
package/dist/index.d.ts CHANGED
@@ -10,8 +10,8 @@
10
10
  */
11
11
  export { defineContract } from './contract.ts';
12
12
  export type { Contract, ContractEndpoints } from './contract.ts';
13
- export { defineEndpoint, isEndpoint } from './endpoint.ts';
14
- export type { AuthSurface, Endpoint, EndpointDefinition, EndpointError, EndpointErrors, EndpointInput, EndpointOutput, EndpointResult, EndpointServerInput, HttpMethod, } from './endpoint.ts';
15
- export { buildPath, pathParamNames } from './path.ts';
13
+ export { defineEndpoint, isEndpoint, isTextResponse, textMediaType } from './endpoint.ts';
14
+ export type { AuthSurface, Endpoint, EndpointDefinition, EndpointError, EndpointErrors, EndpointInput, EndpointOutput, EndpointResult, EndpointServerInput, HttpMethod, TextResponse, } from './endpoint.ts';
15
+ export { buildPath, honoPath, pathParamNames, wildcardParamName } from './path.ts';
16
16
  export type { PathParamNames, PathValue } from './path.ts';
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3D,YAAY,EACV,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,UAAU,GACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACtD,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC1F,YAAY,EACV,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnF,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{defineContract as e}from"./contract.js";import{defineEndpoint as n,isEndpoint as a}from"./endpoint.js";import{buildPath as p,pathParamNames as d}from"./path.js";export{p as buildPath,e as defineContract,n as defineEndpoint,a as isEndpoint,d as pathParamNames};
1
+ import{defineContract as a}from"./contract.js";import{defineEndpoint as r,isEndpoint as i,isTextResponse as n,textMediaType as d}from"./endpoint.js";import{buildPath as m,honoPath as f,pathParamNames as s,wildcardParamName as x}from"./path.js";export{m as buildPath,a as defineContract,r as defineEndpoint,f as honoPath,i as isEndpoint,n as isTextResponse,s as pathParamNames,d as textMediaType,x as wildcardParamName};
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["/**\n * `@rexezuge/contracts`: endpoint definitions shared by a family API and its SPA.\n *\n * Framework-free and runtime-dependency-free. The two adapters live where their\n * frameworks already are: the chanfana route in `@rexezuge/http/hono`\n * (`routeFromEndpoint`, `registerContract`) and the typed client in\n * `@rexezuge/web` (`createContractClient`). Both depend on this package, and\n * it depends on neither, so the layer order stays\n * `errors`/`shared` → `contracts` → `http` → `web`.\n */\nexport { defineContract } from './contract.ts';\nexport type { Contract, ContractEndpoints } from './contract.ts';\n\nexport { defineEndpoint, isEndpoint } from './endpoint.ts';\nexport type {\n AuthSurface,\n Endpoint,\n EndpointDefinition,\n EndpointError,\n EndpointErrors,\n EndpointInput,\n EndpointOutput,\n EndpointResult,\n EndpointServerInput,\n HttpMethod,\n} from './endpoint.ts';\n\nexport { buildPath, pathParamNames } from './path.ts';\nexport type { PathParamNames, PathValue } from './path.ts';\n"],
5
- "mappings": "AAUA,OAAS,kBAAAA,MAAsB,gBAG/B,OAAS,kBAAAC,EAAgB,cAAAC,MAAkB,gBAc3C,OAAS,aAAAC,EAAW,kBAAAC,MAAsB",
6
- "names": ["defineContract", "defineEndpoint", "isEndpoint", "buildPath", "pathParamNames"]
4
+ "sourcesContent": ["/**\n * `@rexezuge/contracts`: endpoint definitions shared by a family API and its SPA.\n *\n * Framework-free and runtime-dependency-free. The two adapters live where their\n * frameworks already are: the chanfana route in `@rexezuge/http/hono`\n * (`routeFromEndpoint`, `registerContract`) and the typed client in\n * `@rexezuge/web` (`createContractClient`). Both depend on this package, and\n * it depends on neither, so the layer order stays\n * `errors`/`shared` → `contracts` → `http` → `web`.\n */\nexport { defineContract } from './contract.ts';\nexport type { Contract, ContractEndpoints } from './contract.ts';\n\nexport { defineEndpoint, isEndpoint, isTextResponse, textMediaType } from './endpoint.ts';\nexport type {\n AuthSurface,\n Endpoint,\n EndpointDefinition,\n EndpointError,\n EndpointErrors,\n EndpointInput,\n EndpointOutput,\n EndpointResult,\n EndpointServerInput,\n HttpMethod,\n TextResponse,\n} from './endpoint.ts';\n\nexport { buildPath, honoPath, pathParamNames, wildcardParamName } from './path.ts';\nexport type { PathParamNames, PathValue } from './path.ts';\n"],
5
+ "mappings": "AAUA,OAAS,kBAAAA,MAAsB,gBAG/B,OAAS,kBAAAC,EAAgB,cAAAC,EAAY,kBAAAC,EAAgB,iBAAAC,MAAqB,gBAe1E,OAAS,aAAAC,EAAW,YAAAC,EAAU,kBAAAC,EAAgB,qBAAAC,MAAyB",
6
+ "names": ["defineContract", "defineEndpoint", "isEndpoint", "isTextResponse", "textMediaType", "buildPath", "honoPath", "pathParamNames", "wildcardParamName"]
7
7
  }
package/dist/path.d.ts CHANGED
@@ -6,16 +6,32 @@
6
6
  * optional (`:id?`) forms are refused at definition: the client would have to
7
7
  * re-implement Hono's matcher to build those URLs, and a contract whose two
8
8
  * ends disagree about a URL is the bug this package exists to remove.
9
+ *
10
+ * One extension, because a catch-all is a real route shape: a **trailing
11
+ * wildcard** segment, `/files/:path*` (or the bare `/files/*`, shorthand for
12
+ * `:path*`). It captures the rest of the path, slashes included, as the param
13
+ * `path` (or the name you chose). The client builds it by encoding each
14
+ * sub-segment, so `a/b c` becomes `a/b%20c`. A `*` anywhere else is refused.
9
15
  */
10
16
  /**
11
17
  * The parameter names in a template, as a union: `PathParamNames<'/a/:id/b/:sub'>`
12
18
  * is `'id' | 'sub'`, and `never` for a template with none.
13
19
  */
14
- type PathParamNames<P extends string> = P extends `${string}:${infer Rest}` ? Rest extends `${infer Name}/${infer Tail}` ? Name | PathParamNames<`/${Tail}`> : Rest : never;
20
+ type PathParamNames<P extends string> = P extends `${string}:${infer Rest}` ? Rest extends `${infer Name}/${infer Tail}` ? Name | PathParamNames<`/${Tail}`> : Rest extends `${infer Name}*` ? Name : Rest : P extends `${string}/*` ? 'path' : never;
15
21
  /**
16
22
  A value a path segment may be built from. Encoded with `encodeURIComponent`.
17
23
  */
18
24
  type PathValue = string | number;
25
+ /**
26
+ * The name of the trailing wildcard param (`/files/:path*` gives `path`, bare `/files/*` gives `path`),
27
+ * or `null` when the template has none.
28
+ */
29
+ declare function wildcardParamName(template: string): string | null;
30
+ /**
31
+ * The template as Hono spells it: a trailing wildcard becomes `:name{.+}`, so the remainder is never empty
32
+ * (`/files` alone is a miss; declare it as its own endpoint if it should answer). A template without one is returned unchanged.
33
+ */
34
+ declare function honoPath(template: string): string;
19
35
  /**
20
36
  * The parameter names of a template, in order. Throws a `TypeError` for a
21
37
  * template the client could not build: not starting with `/`, a malformed or
@@ -26,8 +42,11 @@ declare function pathParamNames(template: string): string[];
26
42
  * Fills a template. Every value is `encodeURIComponent`-encoded, so an id with
27
43
  * a `/` or `?` stays one segment. A missing or empty value throws rather than
28
44
  * producing `/user/items/` or `/user/items/undefined`.
45
+ *
46
+ * The trailing wildcard is the exception on encoding only: its value is encoded per sub-segment, so
47
+ * `a/b` stays two segments (a `.` or `..` sub-segment throws). It may not be empty.
29
48
  */
30
49
  declare function buildPath(template: string, params?: Readonly<Record<string, PathValue>>): string;
31
- export { buildPath, pathParamNames };
50
+ export { buildPath, honoPath, pathParamNames, wildcardParamName };
32
51
  export type { PathParamNames, PathValue };
33
52
  //# sourceMappingURL=path.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,KAAK,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,IAAI,EAAE,GACvE,IAAI,SAAS,GAAG,MAAM,IAAI,IAAI,MAAM,IAAI,EAAE,GACxC,IAAI,GAAG,cAAc,CAAC,IAAI,IAAI,EAAE,CAAC,GACjC,IAAI,GACN,KAAK,CAAC;AAEV;;EAEE;AACF,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAIjC;;;;GAIG;AACH,iBAAS,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAiBlD;AAED;;;;GAIG;AACH,iBAAS,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAM,GAAG,MAAM,CAa7F;AAED,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;AACrC,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;GAGG;AACH,KAAK,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,IAAI,EAAE,GACvE,IAAI,SAAS,GAAG,MAAM,IAAI,IAAI,MAAM,IAAI,EAAE,GACxC,IAAI,GAAG,cAAc,CAAC,IAAI,IAAI,EAAE,CAAC,GACjC,IAAI,SAAS,GAAG,MAAM,IAAI,GAAG,GAC3B,IAAI,GACJ,IAAI,GACR,CAAC,SAAS,GAAG,MAAM,IAAI,GACrB,MAAM,GACN,KAAK,CAAC;AAEZ;;EAEE;AACF,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AASjC;;;GAGG;AACH,iBAAS,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI1D;AAED;;;GAGG;AACH,iBAAS,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAI1C;AAED;;;;GAIG;AACH,iBAAS,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAuBlD;AAED;;;;;;;GAOG;AACH,iBAAS,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAM,GAAG,MAAM,CAuB7F;AAED,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC;AAClE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC"}
package/dist/path.js CHANGED
@@ -1 +1 @@
1
- var s=Object.defineProperty;var o=(t,r)=>s(t,"name",{value:r,configurable:!0});const a=/^[a-z_]\w*$/i;function c(t){if(!t.startsWith("/"))throw new TypeError(`Contract path must start with "/": ${t}`);const r=[];for(const e of t.split("/")){if(!e.startsWith(":"))continue;const n=e.slice(1);if(!a.test(n))throw new TypeError(`Contract path parameter must be a plain ":name" segment: ${t}`);if(r.includes(n))throw new TypeError(`Contract path repeats parameter "${n}": ${t}`);r.push(n)}return r}o(c,"pathParamNames");function h(t,r={}){return t.split("/").map(e=>{if(!e.startsWith(":"))return e;const n=e.slice(1),i=Object.hasOwn(r,n)?r[n]:void 0;if(i==null||String(i)==="")throw new TypeError(`Missing path parameter "${n}" for ${t}`);return encodeURIComponent(String(i))}).join("/")}o(h,"buildPath");export{h as buildPath,c as pathParamNames};
1
+ var f=Object.defineProperty;var u=(n,t)=>f(n,"name",{value:t,configurable:!0});const d=/^[a-z_]\w*$/i,w="path";function h(n){const t=n.slice(n.lastIndexOf("/")+1);return t==="*"?w:t.startsWith(":")&&t.endsWith("*")?t.slice(1,-1):null}u(h,"wildcardParamName");function m(n){const t=h(n);return t===null?n:`${n.slice(0,n.lastIndexOf("/")+1)}:${t}{.+}`}u(m,"honoPath");function p(n){if(!n.startsWith("/"))throw new TypeError(`Contract path must start with "/": ${n}`);const t=[],s=h(n),o=n.split("/");for(const[i,a]of o.entries()){const e=s!==null&&i===o.length-1;if(!e&&a.includes("*"))throw new TypeError(`Contract path may use "*" only as the last segment ("*" or ":name*"): ${n}`);if(!e&&!a.startsWith(":"))continue;const r=e?s:a.slice(1);if(!d.test(r))throw new TypeError(`Contract path parameter must be a plain ":name" segment: ${n}`);if(t.includes(r))throw new TypeError(`Contract path repeats parameter "${r}": ${n}`);t.push(r)}return t}u(p,"pathParamNames");function $(n,t={}){const s=h(n),o=n.split("/");return o.map((i,a)=>{const e=s!==null&&a===o.length-1;if(!e&&!i.startsWith(":"))return i;const r=e?s:i.slice(1),c=Object.hasOwn(t,r)?t[r]:void 0;if(c==null||String(c)==="")throw new TypeError(`Missing path parameter "${r}" for ${n}`);return e?String(c).split("/").map(l=>{if(l==="."||l==="..")throw new TypeError(`Path parameter "${r}" may not contain "." or ".." segments`);return encodeURIComponent(l)}).join("/"):encodeURIComponent(String(c))}).join("/")}u($,"buildPath");export{$ as buildPath,m as honoPath,p as pathParamNames,h as wildcardParamName};
package/dist/path.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/path.ts"],
4
- "sourcesContent": ["/**\n * Path templates: `/user/items/:id`, the Hono/chanfana spelling, so one string\n * is both the route the backend registers and the URL the client builds.\n *\n * Only plain `:name` segments are accepted. Hono's regex (`:id{[0-9]+}`) and\n * optional (`:id?`) forms are refused at definition: the client would have to\n * re-implement Hono's matcher to build those URLs, and a contract whose two\n * ends disagree about a URL is the bug this package exists to remove.\n */\n\n/**\n * The parameter names in a template, as a union: `PathParamNames<'/a/:id/b/:sub'>`\n * is `'id' | 'sub'`, and `never` for a template with none.\n */\ntype PathParamNames<P extends string> = P extends `${string}:${infer Rest}`\n ? Rest extends `${infer Name}/${infer Tail}`\n ? Name | PathParamNames<`/${Tail}`>\n : Rest\n : never;\n\n/**\nA value a path segment may be built from. Encoded with `encodeURIComponent`.\n*/\ntype PathValue = string | number;\n\nconst PARAM_NAME = /^[a-z_]\\w*$/i;\n\n/**\n * The parameter names of a template, in order. Throws a `TypeError` for a\n * template the client could not build: not starting with `/`, a malformed or\n * repeated name, or Hono's regex/optional syntax.\n */\nfunction pathParamNames(template: string): string[] {\n if (!template.startsWith('/')) {\n throw new TypeError(`Contract path must start with \"/\": ${template}`);\n }\n const names: string[] = [];\n for (const segment of template.split('/')) {\n if (!segment.startsWith(':')) continue;\n const name = segment.slice(1);\n if (!PARAM_NAME.test(name)) {\n throw new TypeError(`Contract path parameter must be a plain \":name\" segment: ${template}`);\n }\n if (names.includes(name)) {\n throw new TypeError(`Contract path repeats parameter \"${name}\": ${template}`);\n }\n names.push(name);\n }\n return names;\n}\n\n/**\n * Fills a template. Every value is `encodeURIComponent`-encoded, so an id with\n * a `/` or `?` stays one segment. A missing or empty value throws rather than\n * producing `/user/items/` or `/user/items/undefined`.\n */\nfunction buildPath(template: string, params: Readonly<Record<string, PathValue>> = {}): string {\n return template\n .split('/')\n .map((segment) => {\n if (!segment.startsWith(':')) return segment;\n const name = segment.slice(1);\n const value = Object.hasOwn(params, name) ? params[name] : undefined;\n if (value === undefined || value === null || String(value) === '') {\n throw new TypeError(`Missing path parameter \"${name}\" for ${template}`);\n }\n return encodeURIComponent(String(value));\n })\n .join('/');\n}\n\nexport { buildPath, pathParamNames };\nexport type { PathParamNames, PathValue };\n"],
5
- "mappings": "+EAyBA,MAAMA,EAAa,eAOnB,SAASC,EAAeC,EAAgB,CACtC,GAAI,CAACA,EAAS,WAAW,GAAG,EAC1B,MAAM,IAAI,UAAU,sCAAsCA,CAAQ,EAAE,EAEtE,MAAMC,EAAkB,CAAA,EACxB,UAAWC,KAAWF,EAAS,MAAM,GAAG,EAAG,CACzC,GAAI,CAACE,EAAQ,WAAW,GAAG,EAAG,SAC9B,MAAMC,EAAOD,EAAQ,MAAM,CAAC,EAC5B,GAAI,CAACJ,EAAW,KAAKK,CAAI,EACvB,MAAM,IAAI,UAAU,4DAA4DH,CAAQ,EAAE,EAE5F,GAAIC,EAAM,SAASE,CAAI,EACrB,MAAM,IAAI,UAAU,oCAAoCA,CAAI,MAAMH,CAAQ,EAAE,EAE9EC,EAAM,KAAKE,CAAI,CACjB,CACA,OAAOF,CACT,CAjBSG,EAAAL,EAAA,kBAwBT,SAASM,EAAUL,EAAkBM,EAA8C,CAAA,EAAE,CACnF,OAAON,EACJ,MAAM,GAAG,EACT,IAAKE,GAAW,CACf,GAAI,CAACA,EAAQ,WAAW,GAAG,EAAG,OAAOA,EACrC,MAAMC,EAAOD,EAAQ,MAAM,CAAC,EACtBK,EAAQ,OAAO,OAAOD,EAAQH,CAAI,EAAIG,EAAOH,CAAI,EAAI,OAC3D,GAA2BI,GAAU,MAAQ,OAAOA,CAAK,IAAM,GAC7D,MAAM,IAAI,UAAU,2BAA2BJ,CAAI,SAASH,CAAQ,EAAE,EAExE,OAAO,mBAAmB,OAAOO,CAAK,CAAC,CACzC,CAAC,EACA,KAAK,GAAG,CACb,CAbSH,EAAAC,EAAA",
6
- "names": ["PARAM_NAME", "pathParamNames", "template", "names", "segment", "name", "__name", "buildPath", "params", "value"]
4
+ "sourcesContent": ["/**\n * Path templates: `/user/items/:id`, the Hono/chanfana spelling, so one string\n * is both the route the backend registers and the URL the client builds.\n *\n * Only plain `:name` segments are accepted. Hono's regex (`:id{[0-9]+}`) and\n * optional (`:id?`) forms are refused at definition: the client would have to\n * re-implement Hono's matcher to build those URLs, and a contract whose two\n * ends disagree about a URL is the bug this package exists to remove.\n *\n * One extension, because a catch-all is a real route shape: a **trailing\n * wildcard** segment, `/files/:path*` (or the bare `/files/*`, shorthand for\n * `:path*`). It captures the rest of the path, slashes included, as the param\n * `path` (or the name you chose). The client builds it by encoding each\n * sub-segment, so `a/b c` becomes `a/b%20c`. A `*` anywhere else is refused.\n */\n\n/**\n * The parameter names in a template, as a union: `PathParamNames<'/a/:id/b/:sub'>`\n * is `'id' | 'sub'`, and `never` for a template with none.\n */\ntype PathParamNames<P extends string> = P extends `${string}:${infer Rest}`\n ? Rest extends `${infer Name}/${infer Tail}`\n ? Name | PathParamNames<`/${Tail}`>\n : Rest extends `${infer Name}*`\n ? Name\n : Rest\n : P extends `${string}/*`\n ? 'path'\n : never;\n\n/**\nA value a path segment may be built from. Encoded with `encodeURIComponent`.\n*/\ntype PathValue = string | number;\n\nconst PARAM_NAME = /^[a-z_]\\w*$/i;\n\n/**\nThe param a bare trailing `*` captures.\n*/\nconst WILDCARD_DEFAULT_NAME = 'path';\n\n/**\n * The name of the trailing wildcard param (`/files/:path*` gives `path`, bare `/files/*` gives `path`),\n * or `null` when the template has none.\n */\nfunction wildcardParamName(template: string): string | null {\n const last = template.slice(template.lastIndexOf('/') + 1);\n if (last === '*') return WILDCARD_DEFAULT_NAME;\n return last.startsWith(':') && last.endsWith('*') ? last.slice(1, -1) : null;\n}\n\n/**\n * The template as Hono spells it: a trailing wildcard becomes `:name{.+}`, so the remainder is never empty\n * (`/files` alone is a miss; declare it as its own endpoint if it should answer). A template without one is returned unchanged.\n */\nfunction honoPath(template: string): string {\n const name = wildcardParamName(template);\n if (name === null) return template;\n return `${template.slice(0, template.lastIndexOf('/') + 1)}:${name}{.+}`;\n}\n\n/**\n * The parameter names of a template, in order. Throws a `TypeError` for a\n * template the client could not build: not starting with `/`, a malformed or\n * repeated name, or Hono's regex/optional syntax.\n */\nfunction pathParamNames(template: string): string[] {\n if (!template.startsWith('/')) {\n throw new TypeError(`Contract path must start with \"/\": ${template}`);\n }\n const names: string[] = [];\n const wildcard = wildcardParamName(template);\n const segments = template.split('/');\n for (const [index, segment] of segments.entries()) {\n const terminal = wildcard !== null && index === segments.length - 1;\n if (!terminal && segment.includes('*')) {\n throw new TypeError(`Contract path may use \"*\" only as the last segment (\"*\" or \":name*\"): ${template}`);\n }\n if (!terminal && !segment.startsWith(':')) continue;\n const name = terminal ? wildcard : segment.slice(1);\n if (!PARAM_NAME.test(name)) {\n throw new TypeError(`Contract path parameter must be a plain \":name\" segment: ${template}`);\n }\n if (names.includes(name)) {\n throw new TypeError(`Contract path repeats parameter \"${name}\": ${template}`);\n }\n names.push(name);\n }\n return names;\n}\n\n/**\n * Fills a template. Every value is `encodeURIComponent`-encoded, so an id with\n * a `/` or `?` stays one segment. A missing or empty value throws rather than\n * producing `/user/items/` or `/user/items/undefined`.\n *\n * The trailing wildcard is the exception on encoding only: its value is encoded per sub-segment, so\n * `a/b` stays two segments (a `.` or `..` sub-segment throws). It may not be empty.\n */\nfunction buildPath(template: string, params: Readonly<Record<string, PathValue>> = {}): string {\n const wildcard = wildcardParamName(template);\n const segments = template.split('/');\n return segments\n .map((segment, index) => {\n const terminal = wildcard !== null && index === segments.length - 1;\n if (!terminal && !segment.startsWith(':')) return segment;\n const name = terminal ? wildcard : segment.slice(1);\n const value = Object.hasOwn(params, name) ? params[name] : undefined;\n if (value === undefined || value === null || String(value) === '') {\n throw new TypeError(`Missing path parameter \"${name}\" for ${template}`);\n }\n return terminal\n ? String(value)\n .split('/')\n .map((part) => {\n if (part === '.' || part === '..') throw new TypeError(`Path parameter \"${name}\" may not contain \".\" or \"..\" segments`);\n return encodeURIComponent(part);\n })\n .join('/')\n : encodeURIComponent(String(value));\n })\n .join('/');\n}\n\nexport { buildPath, honoPath, pathParamNames, wildcardParamName };\nexport type { PathParamNames, PathValue };\n"],
5
+ "mappings": "+EAmCA,MAAMA,EAAa,eAKbC,EAAwB,OAM9B,SAASC,EAAkBC,EAAgB,CACzC,MAAMC,EAAOD,EAAS,MAAMA,EAAS,YAAY,GAAG,EAAI,CAAC,EACzD,OAAIC,IAAS,IAAYH,EAClBG,EAAK,WAAW,GAAG,GAAKA,EAAK,SAAS,GAAG,EAAIA,EAAK,MAAM,EAAG,EAAE,EAAI,IAC1E,CAJSC,EAAAH,EAAA,qBAUT,SAASI,EAASH,EAAgB,CAChC,MAAMI,EAAOL,EAAkBC,CAAQ,EACvC,OAAII,IAAS,KAAaJ,EACnB,GAAGA,EAAS,MAAM,EAAGA,EAAS,YAAY,GAAG,EAAI,CAAC,CAAC,IAAII,CAAI,MACpE,CAJSF,EAAAC,EAAA,YAWT,SAASE,EAAeL,EAAgB,CACtC,GAAI,CAACA,EAAS,WAAW,GAAG,EAC1B,MAAM,IAAI,UAAU,sCAAsCA,CAAQ,EAAE,EAEtE,MAAMM,EAAkB,CAAA,EAClBC,EAAWR,EAAkBC,CAAQ,EACrCQ,EAAWR,EAAS,MAAM,GAAG,EACnC,SAAW,CAACS,EAAOC,CAAO,IAAKF,EAAS,QAAO,EAAI,CACjD,MAAMG,EAAWJ,IAAa,MAAQE,IAAUD,EAAS,OAAS,EAClE,GAAI,CAACG,GAAYD,EAAQ,SAAS,GAAG,EACnC,MAAM,IAAI,UAAU,yEAAyEV,CAAQ,EAAE,EAEzG,GAAI,CAACW,GAAY,CAACD,EAAQ,WAAW,GAAG,EAAG,SAC3C,MAAMN,EAAOO,EAAWJ,EAAWG,EAAQ,MAAM,CAAC,EAClD,GAAI,CAACb,EAAW,KAAKO,CAAI,EACvB,MAAM,IAAI,UAAU,4DAA4DJ,CAAQ,EAAE,EAE5F,GAAIM,EAAM,SAASF,CAAI,EACrB,MAAM,IAAI,UAAU,oCAAoCA,CAAI,MAAMJ,CAAQ,EAAE,EAE9EM,EAAM,KAAKF,CAAI,CACjB,CACA,OAAOE,CACT,CAvBSJ,EAAAG,EAAA,kBAiCT,SAASO,EAAUZ,EAAkBa,EAA8C,CAAA,EAAE,CACnF,MAAMN,EAAWR,EAAkBC,CAAQ,EACrCQ,EAAWR,EAAS,MAAM,GAAG,EACnC,OAAOQ,EACJ,IAAI,CAACE,EAASD,IAAS,CACtB,MAAME,EAAWJ,IAAa,MAAQE,IAAUD,EAAS,OAAS,EAClE,GAAI,CAACG,GAAY,CAACD,EAAQ,WAAW,GAAG,EAAG,OAAOA,EAClD,MAAMN,EAAOO,EAAWJ,EAAWG,EAAQ,MAAM,CAAC,EAC5CI,EAAQ,OAAO,OAAOD,EAAQT,CAAI,EAAIS,EAAOT,CAAI,EAAI,OAC3D,GAA2BU,GAAU,MAAQ,OAAOA,CAAK,IAAM,GAC7D,MAAM,IAAI,UAAU,2BAA2BV,CAAI,SAASJ,CAAQ,EAAE,EAExE,OAAOW,EACH,OAAOG,CAAK,EACT,MAAM,GAAG,EACT,IAAKC,GAAQ,CACZ,GAAIA,IAAS,KAAOA,IAAS,KAAM,MAAM,IAAI,UAAU,mBAAmBX,CAAI,wCAAwC,EACtH,OAAO,mBAAmBW,CAAI,CAChC,CAAC,EACA,KAAK,GAAG,EACX,mBAAmB,OAAOD,CAAK,CAAC,CACtC,CAAC,EACA,KAAK,GAAG,CACb,CAvBSZ,EAAAU,EAAA",
6
+ "names": ["PARAM_NAME", "WILDCARD_DEFAULT_NAME", "wildcardParamName", "template", "last", "__name", "honoPath", "name", "pathParamNames", "names", "wildcard", "segments", "index", "segment", "terminal", "buildPath", "params", "value", "part"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexezuge/contracts",
3
- "version": "1.15.0",
3
+ "version": "1.17.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "repository": {