@spfn/core 0.3.0-beta.28 → 0.3.0-beta.29

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/route/route-builder.ts","../../src/route/router.ts","../../src/surface/error.ts","../../src/surface/wording.ts","../../src/surface/manifest.ts","../../src/surface/route-overlap.ts","../../src/surface/module.ts","../../src/surface/namespace.ts","../../src/surface/define-surface.ts"],"names":["route","isRouter","isRouteDef"],"mappings":";AAmEO,IAAM,YAAA,GAAN,MAAM,aAAA,CAKb;AAAA,EACW,OAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,gBAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA;AAAA;AAAA;AAAA,EAKC,MAIJ,SAAA,EAUJ;AACI,IAAA,MAAM,OAAA,GAAU,IAAI,aAAA,EAAoD;AACxE,IAAA,OAAA,CAAQ,UAAU,IAAA,CAAK,OAAA;AACvB,IAAA,OAAA,CAAQ,QAAQ,IAAA,CAAK,KAAA;AACrB,IAAA,OAAA,CAAQ,MAAA,GAAU,SAAA,EAAW,KAAA,IAAS,IAAA,CAAK,MAAA;AAC3C,IAAA,OAAA,CAAQ,YAAA,GAAgB,SAAA,EAAW,WAAA,IAAe,IAAA,CAAK,YAAA;AACvD,IAAA,OAAA,CAAQ,YAAA,GAAe,SAAA,EAAW,WAAA,IAAe,IAAA,CAAK,YAAA;AACtD,IAAA,OAAA,CAAQ,gBAAA,GAAmB,SAAA,EAAW,eAAA,IAAmB,IAAA,CAAK,gBAAA;AAC9D,IAAA,OAAA,CAAQ,SAAA,GAAY,SAAA,EAAW,QAAA,IAAY,IAAA,CAAK,SAAA;AAChD,IAAA,OAAA,CAAQ,OAAA,GAAU,SAAA,EAAW,MAAA,IAAU,IAAA,CAAK,OAAA;AAC5C,IAAA,OAAA,CAAQ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M,OAAA,CAAQ,IAAA;AAAA,IACd,WAAW,OAAA,CAAQ,SAAA;AAAA,IACnB,QAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,eAAe,KAAA,CAAM;AAAA,GACzB;AACJ;AAQO,SAAS,aAAA,CAAc,OAAA,EAAyB,OAAA,EAAyB,KAAA,EAChF;AACI,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,OAAA,EAAS,OAAA,EAAS,KAAK,CAAA;AAE3C,EAAA,OAAO;AAAA,IACH,WAAW,IAAA,CAAK,SAAA;AAAA,IAChB,KAAA,EAAO,mBAAA,CAAoB,IAAA,CAAK,SAAA,EAAW,OAAO,CAAA;AAAA,IAClD,MAAA,EAAQ,CAAA,MAAA,KAAU,WAAA,CAAY,IAAA,EAAM,MAAM;AAAA,GAC9C;AACJ;AAcO,SAAS,cAAc,OAAA,EAC9B;AACI,EAAA,OAAO,cAAc,OAAA,EAAS,eAAA,EAAiB,EAAE,aAAA,EAAe,MAAM,CAAA;AAC1E","file":"index.js","sourcesContent":["/**\n * Route Builder\n *\n * Provides tRPC-style chainable API for route definition\n */\n\nimport type { MiddlewareHandler } from 'hono';\nimport type { NamedMiddleware } from './define-middleware';\nimport type { RouteInput } from './route-input';\nimport type { RouteBuilderContext } from './context';\nimport type { RouteContract } from './contract';\nimport type { HttpMethod, RouteEffect } from './types';\n\n/**\n * Route handler function\n */\nexport type RouteHandlerFn<\n TInput extends RouteInput = RouteInput,\n TInterceptor extends RouteInput = {},\n TResponse = unknown,\n> = (c: RouteBuilderContext<TInput, TInterceptor>) => Response | Promise<Response> | TResponse | Promise<TResponse>;\n\n/**\n * Route definition result\n *\n * Contains all information needed for type inference and registration\n */\nexport type RouteDef<\n TInput extends RouteInput = RouteInput,\n TInterceptor extends RouteInput = {},\n TResponse = unknown,\n> = {\n method?: HttpMethod;\n path?: string;\n input?: TInput;\n interceptor?: TInterceptor;\n middlewares?: (MiddlewareHandler | NamedMiddleware<string>)[];\n skipMiddlewares?: string[] | '*';\n\n /**\n * Public promise this route makes to separately deployed clients.\n *\n * Present as a runtime value, unlike `_response`: the contract generator and\n * the compatibility gate read it.\n */\n contract?: RouteContract;\n\n /**\n * What invoking this route does. Read by a command surface, which\n * announces it in its manifest; codegen and the contract ignore it.\n */\n effect?: RouteEffect;\n\n /** One line a command surface announces beside the route; codegen and the contract ignore it. */\n summary?: string;\n\n handler: RouteHandlerFn<TInput, TInterceptor, TResponse>;\n\n // Type inference helpers\n _input: TInput;\n _interceptor: TInterceptor;\n _response: TResponse;\n};\n\n/**\n * Route builder with chainable API (tRPC-style)\n */\nexport class RouteBuilder<\n TInput extends RouteInput = {},\n TInterceptor extends RouteInput = {},\n TResponse = never,\n>\n{\n public _method?: HttpMethod;\n public _path?: string;\n public _input?: TInput;\n public _interceptor?: TInterceptor;\n public _middlewares?: (MiddlewareHandler | NamedMiddleware<string>)[];\n public _skipMiddlewares?: string[] | '*';\n public _contract?: RouteContract;\n public _effect?: RouteEffect;\n public _summary?: string;\n\n /**\n * Create a new RouteBuilder with copied properties and optional overrides\n */\n private clone<\n TNewInput extends RouteInput = TInput,\n TNewInterceptor extends RouteInput = TInterceptor,\n >(\n overrides?: Partial<{\n input: TNewInput;\n interceptor: TNewInterceptor;\n middlewares: (MiddlewareHandler | NamedMiddleware<string>)[];\n skipMiddlewares: string[] | '*';\n contract: RouteContract;\n effect: RouteEffect;\n summary: string;\n }>,\n ): RouteBuilder<TNewInput, TNewInterceptor, TResponse>\n {\n const builder = new RouteBuilder<TNewInput, TNewInterceptor, TResponse>();\n builder._method = this._method;\n builder._path = this._path;\n builder._input = (overrides?.input ?? this._input) as TNewInput | undefined;\n builder._interceptor = (overrides?.interceptor ?? this._interceptor) as TNewInterceptor | undefined;\n builder._middlewares = overrides?.middlewares ?? this._middlewares;\n builder._skipMiddlewares = overrides?.skipMiddlewares ?? this._skipMiddlewares;\n builder._contract = overrides?.contract ?? this._contract;\n builder._effect = overrides?.effect ?? this._effect;\n builder._summary = overrides?.summary ?? this._summary;\n\n return builder;\n }\n\n /**\n * Define input schemas\n *\n * @example\n * ```ts\n * route.get('/users/:id')\n * .input({\n * params: Type.Object({ id: Type.String() }),\n * query: Type.Object({ page: Type.Number() }),\n * headers: Type.Object({ authorization: Type.String() })\n * })\n * .handler(async (c) => {\n * const { params, query, headers } = await c.data();\n * // params = { id: string }\n * // query = { page: number }\n * // headers = { authorization: string }\n * })\n * ```\n */\n input<TNewInput extends RouteInput>(input: TNewInput): RouteBuilder<TNewInput, TInterceptor, TResponse>\n {\n return this.clone({ input });\n }\n\n /**\n * Define fields injected by interceptors\n *\n * These fields are:\n * - Available in the handler (merged with input)\n * - Excluded from client types (codegen uses only input)\n * - Not validated by route input schema (injected by middleware)\n *\n * Use this when middleware/interceptors add fields to the request\n * before it reaches the handler.\n *\n * @example\n * ```ts\n * // Auth interceptor injects crypto key fields\n * route.post('/_auth/login')\n * .input({\n * body: Type.Object({\n * email: Type.String(),\n * password: Type.String()\n * })\n * })\n * .interceptor({\n * body: Type.Object({\n * publicKey: Type.String(),\n * keyId: Type.String(),\n * fingerprint: Type.String()\n * })\n * })\n * .handler(async (c) => {\n * const { body } = await c.data();\n * // body type: { email, password, publicKey, keyId, fingerprint }\n * // Client only sees: { email, password }\n * return loginService(body);\n * });\n * ```\n */\n interceptor<TNewInterceptor extends RouteInput>(\n interceptor: TNewInterceptor,\n ): RouteBuilder<TInput, TNewInterceptor, TResponse>\n {\n return this.clone({ interceptor });\n }\n\n /**\n * Add middlewares to the route\n *\n * Accepts both regular middleware handlers and named middlewares (NamedMiddleware).\n * Named middlewares that are already registered globally will be automatically\n * deduplicated to prevent double execution.\n *\n * @example\n * ```ts\n * import { authenticate } from '@spfn/auth/server/middleware';\n *\n * // With NamedMiddleware (auto-deduped if registered globally)\n * route.get('/users')\n * .use([authenticate, RateLimitMiddleware()])\n *\n * // With regular middleware handlers\n * route.get('/users')\n * .use([AuthMiddleware(), RateLimitMiddleware()])\n * ```\n */\n middleware(middlewares: (MiddlewareHandler | NamedMiddleware<string>)[]): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.clone({ middlewares });\n }\n\n /**\n * Add middlewares to the route (alias for `.middleware()`)\n *\n * Accepts both regular middleware handlers and named middlewares (NamedMiddleware).\n * Named middlewares that are already registered globally will be automatically\n * deduplicated to prevent double execution.\n *\n * @example\n * ```ts\n * import { authenticate } from '@spfn/auth/server/middleware';\n *\n * // With NamedMiddleware (auto-deduped if registered globally)\n * route.get('/users')\n * .use([authenticate, RateLimitMiddleware()])\n *\n * // With regular middleware handlers\n * route.get('/users')\n * .use([AuthMiddleware(), RateLimitMiddleware()])\n * ```\n */\n use(middlewares: (MiddlewareHandler | NamedMiddleware<string>)[]): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.middleware(middlewares);\n }\n\n /**\n * Skip server-level named middlewares\n *\n * Useful for public endpoints that should bypass auth or rate limiting\n *\n * @param middlewareNames - Array of middleware names to skip, or '*' to skip all\n *\n * @example\n * ```ts\n * // Skip specific middlewares\n * route.get('/status')\n * .skip(['auth', 'rateLimit'])\n * .handler(async (c) => c.json({ status: 'ok' }));\n *\n * // Skip only auth (still apply rate limiting)\n * route.get('/public-data')\n * .skip(['auth'])\n * .handler(async (c) => { ... });\n *\n * // Skip all middlewares\n * route.get('/public-health')\n * .skip('*')\n * .handler(async (c) => c.json({ status: 'ok' }));\n * ```\n */\n skip(middlewareNames: string[] | '*'): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.clone({ skipMiddlewares: middlewareNames });\n }\n\n /**\n * Publish this route as a versioned contract operation\n *\n * Marks the route as a promise to clients that are compiled and deployed\n * separately from the server — a mobile app, an external API consumer.\n * The `@spfn/core:contract` generator writes every contracted route into\n * `contracts/current.json`, and the build refuses a change that would break\n * an already-released client.\n *\n * Routes without `.contract()` are unaffected: they simply do not appear in\n * the contract. A web client needs nothing here — it derives its types from\n * the router in the same build.\n *\n * @example\n * ```ts\n * export const getUser = route.get('/users/:id')\n * .input({ params: Type.Object({ id: Type.String() }) })\n * .contract({\n * since: '1.2.0',\n * auth: 'clientProofV1',\n * requiresSession: true,\n * response: Type.Object({\n * id: Type.String(),\n * name: Type.String(),\n * email: Type.Optional(Type.String()),\n * }),\n * })\n * .handler(async (c) => { ... });\n * ```\n */\n contract(contract: RouteContract): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.clone({ contract });\n }\n\n /**\n * Declare what invoking this route does\n *\n * Read by a command surface (`@spfn/core/surface`, `@spfn/core/ops`),\n * which announces it in its manifest so a machine caller can tell a read\n * from a write before it calls — `spfn ops call` asks for `--yes` before a\n * `destructive` command. A surface built with `defineSurface` refuses an\n * app command that does not declare one; on `/_ops` it is optional.\n *\n * Nothing else reads it: codegen, the route map, and the contract are\n * unaffected, and a route outside any surface simply carries it.\n *\n * @example\n * ```ts\n * export const pageAdd = app.route.post('/pages')\n * .input({ body: PageAddBody })\n * .effect('write')\n * .summary('Add a page to the blueprint')\n * .handler(async (c) => { ... });\n * ```\n */\n effect(effect: RouteEffect): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.clone({ effect });\n }\n\n /**\n * Describe this route in one line for a command surface's manifest\n *\n * A surface announces it beside the command in `spfn ops list` and\n * `--describe`, and refuses one that is empty or longer than 500\n * characters. Codegen, the route map, and the contract ignore it. On a\n * module command the module's own summary wins.\n *\n * @example\n * ```ts\n * export const pageAdd = app.route.post('/pages')\n * .effect('write')\n * .summary('Add a page to the blueprint')\n * .handler(async (c) => { ... });\n * ```\n */\n summary(summary: string): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.clone({ summary });\n }\n\n /**\n * Define handler function\n *\n * Response type is automatically inferred from the return value.\n * Use helper methods like `c.created()`, `c.paginated()` for proper type inference.\n *\n * @example\n * ```ts\n * // Direct return - type inferred from data\n * route.get('/users/:id')\n * .input({ params: Type.Object({ id: Type.String() }) })\n * .handler(async (c) => {\n * const { params } = await c.data();\n * return await getUser(params.id); // Type: User\n * })\n *\n * // Using c.created() - returns data with 201 status, type preserved\n * route.post('/users')\n * .input({ body: Type.Object({ name: Type.String() }) })\n * .handler(async (c) => {\n * const { body } = await c.data();\n * return c.created(await createUser(body)); // Type: User\n * })\n *\n * // Using c.paginated() - returns PaginatedResult<T>\n * route.get('/users')\n * .handler(async (c) => {\n * const users = await getUsers();\n * return c.paginated(users, 1, 20, 100); // Type: PaginatedResult<User>\n * })\n *\n * // Using c.noContent() - returns void\n * route.delete('/users/:id')\n * .handler(async (c) => {\n * await deleteUser(params.id);\n * return c.noContent(); // Type: void\n * })\n *\n * // Using c.json() - returns Response (type inference lost)\n * // Use only when you need custom status codes not covered by helpers\n * route.get('/custom')\n * .handler(async (c) => {\n * return c.json({ data }, 418); // Type: Response\n * })\n * ```\n */\n handler<THandlerResponse>(\n fn: RouteHandlerFn<TInput, TInterceptor, THandlerResponse>,\n ): RouteDef<TInput, TInterceptor, THandlerResponse>\n {\n return {\n method: this._method,\n path: this._path,\n input: this._input,\n interceptor: this._interceptor,\n middlewares: this._middlewares,\n skipMiddlewares: this._skipMiddlewares,\n contract: this._contract,\n ...(this._effect !== undefined ? { effect: this._effect } : {}),\n ...(this._summary !== undefined ? { summary: this._summary } : {}),\n handler: fn,\n _input: {} as TInput,\n _interceptor: {} as TInterceptor,\n _response: {} as THandlerResponse,\n };\n }\n}\n\n/**\n * Create a route definition with HTTP method shortcuts\n */\nfunction createMethodRoute(method: HttpMethod): (path: string) => RouteBuilder\n{\n return (path: string) =>\n {\n const builder = new RouteBuilder();\n builder._method = method;\n builder._path = path;\n\n return builder;\n };\n}\n\n/**\n * Route builder entry point\n *\n * @example\n * ```ts\n * // GET request\n * export const getUser = route.get('/users/:id')\n * .input({ params: Type.Object({ id: Type.String() }) })\n * .handler(async (c) => {\n * const { params } = await c.data();\n * return await db.user.findUnique({ where: { id: params.id } });\n * });\n *\n * // POST request\n * export const createUser = route.post('/users')\n * .input({ body: Type.Object({ name: Type.String(), email: Type.String() }) })\n * .handler(async (c) => {\n * const { body } = await c.data();\n * return c.created(await db.user.create({ data: body }));\n * });\n * ```\n */\nexport const route = {\n get: createMethodRoute('GET'),\n post: createMethodRoute('POST'),\n put: createMethodRoute('PUT'),\n patch: createMethodRoute('PATCH'),\n delete: createMethodRoute('DELETE'),\n};\n","/**\n * Router Definition\n *\n * Provides router composition and middleware management\n */\n\nimport type { NamedMiddleware } from './define-middleware';\nimport type { RouteDef } from './route-builder';\n\n/**\n * Router definition - holds all routes\n */\nexport interface Router<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>> {\n routes: TRoutes;\n _routes: TRoutes;\n _packageRouters: Router<any>[];\n _globalMiddlewares: NamedMiddleware<string>[];\n\n /** The contract version these routes publish, or null when uncontracted. */\n _contractVersion: string | null;\n\n /**\n * Whether a client ever addresses these routes by name.\n *\n * True for an ordinary router. A mounted package router that is true here\n * has its routes written into the app's generated route map, which is what\n * lets the package's own client (`authApi.login`) resolve a name through the\n * app's RPC proxy. It is also what makes an app route sharing a name with a\n * package route a defect worth refusing a build over: the map holds one\n * entry per name, so one of the two paths would become unreachable while the\n * generated types still describe the app's route.\n *\n * False says no client names these routes: they are reached by URL, by\n * something that was handed the URL, so nothing of them belongs in the map\n * and a name they share with an app route is only a shared name.\n * `createOpsRouter` sets it — `spfn ops` invokes an ops command over the URL\n * the manifest gave it.\n */\n _publishesRouteMap: boolean;\n\n /**\n * The namespace of the command surface that built this router, absent on\n * any other. Set by `defineSurface` (and so by `createOpsRouter`) as a\n * non-enumerable property, so `.packages()` can refuse two surfaces on one\n * namespace.\n */\n readonly _surfaceNamespace?: string;\n\n /**\n * Register package routers (type-hidden)\n *\n * Package routes are:\n * - Recognized by RPC proxy and backend\n * - NOT exposed in client types (use package's own API like authApi, cmsApi)\n *\n * @example\n * ```ts\n * import { authRouter } from '@spfn/auth/server';\n * import { cmsAppRouter } from '@spfn/cms/server';\n *\n * export const appRouter = defineRouter({\n * getRoot,\n * getStatus,\n * })\n * .packages([authRouter, cmsAppRouter]);\n *\n * // Client usage:\n * // api.getRoot.call({}) - app routes\n * // authApi.login.call({}) - package API\n * ```\n */\n packages(routers: Router<any>[]): Router<TRoutes>;\n\n /**\n * Register global middlewares\n *\n * Applied to all routes unless explicitly skipped via .skip()\n *\n * @example\n * ```ts\n * import { authMiddleware, loggingMiddleware } from './middlewares';\n *\n * export const appRouter = defineRouter({\n * getRoot,\n * getStatus,\n * })\n * .packages([authRouter])\n * .use([authMiddleware, loggingMiddleware]);\n * ```\n */\n use(middlewares: NamedMiddleware<string>[]): Router<TRoutes>;\n\n /**\n * Declare the contract version these routes publish.\n *\n * A client compiled against this server — a mobile app in a store — is\n * generated from one version of the contract and cannot be updated when the\n * server changes. The server announces this version on every response so\n * that client can tell whether the two ends still agree.\n *\n * This is the version's source. A released snapshot is written to\n * `contracts/released/<version>.json` from what is declared here, so the\n * filename follows the code rather than the code having to be told what the\n * filename said.\n *\n * Only a server with contracted routes needs it. Without it the contract\n * generator still writes `current.json` and still runs the compatibility\n * gate; what it cannot do is cut a release or announce a version.\n *\n * @example\n * ```ts\n * export const appRouter = defineRouter({ getRoot, listItems })\n * .contractVersion('1.2.0')\n * .packages([authRouter]);\n * ```\n */\n contractVersion(version: string): Router<TRoutes>;\n}\n\n/**\n * Everything a router carries, so that a chainable method rebuilding the router\n * states what it changes and cannot silently drop what it does not.\n */\ninterface RouterState<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>\n{\n routes: TRoutes;\n packageRouters: Router<any>[];\n globalMiddlewares: NamedMiddleware<string>[];\n contractVersion: string | null;\n publishesRouteMap: boolean;\n}\n\n/**\n * Create a Router instance with chainable methods\n */\nfunction createRouterInstance<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(\n state: RouterState<TRoutes>,\n): Router<TRoutes>\n{\n return {\n routes: state.routes,\n _routes: state.routes,\n _packageRouters: state.packageRouters,\n _globalMiddlewares: state.globalMiddlewares,\n _contractVersion: state.contractVersion,\n _publishesRouteMap: state.publishesRouteMap,\n\n packages(routers: Router<any>[]): Router<TRoutes>\n {\n const newPackageRouters = [...state.packageRouters, ...routers];\n\n // Also include nested package routers if any\n for (const pkgRouter of routers)\n {\n if (pkgRouter._packageRouters?.length > 0)\n {\n newPackageRouters.push(...pkgRouter._packageRouters);\n }\n }\n\n assertDistinctSurfaces(newPackageRouters);\n\n return createRouterInstance({ ...state, packageRouters: newPackageRouters });\n },\n\n use(middlewares: NamedMiddleware<string>[]): Router<TRoutes>\n {\n return createRouterInstance({\n ...state,\n globalMiddlewares: [...state.globalMiddlewares, ...middlewares],\n });\n },\n\n contractVersion(version: string): Router<TRoutes>\n {\n assertContractVersion(version);\n\n return createRouterInstance({ ...state, contractVersion: version });\n },\n };\n}\n\n/**\n * A version that cannot be ordered cannot gate a release.\n *\n * Checked when it is declared rather than when a snapshot is cut: the failure\n * belongs next to the typo, not in a build step that runs much later.\n */\nfunction assertContractVersion(version: string): void\n{\n if (!/^\\d+\\.\\d+\\.\\d+(?:[-+][0-9A-Za-z.-]+)*$/.test(version))\n {\n throw new Error(\n `contractVersion(\"${version}\") is not a version of the form major.minor.patch. `\n + 'The released snapshot is named from this value and releases are compared by it.',\n );\n }\n}\n\n/**\n * Two command surfaces on one namespace both serve `<namespace>/_manifest`.\n * The first registered answers it, so the second surface's commands stay\n * live behind their own auth while no manifest lists them.\n *\n * Checked when the routers are mounted: that is the first point that sees\n * both, and the failure belongs where the app put them side by side.\n */\nfunction assertDistinctSurfaces(packageRouters: readonly Router<any>[]): void\n{\n const namespaces = new Set<string>();\n\n for (const router of packageRouters)\n {\n const namespace = router._surfaceNamespace;\n if (namespace === undefined)\n {\n continue;\n }\n\n if (namespaces.has(namespace))\n {\n throw new Error(\n `.packages() mounts two command surfaces on \"${namespace}\". `\n + `Both serve ${namespace}/_manifest, so the second one's commands would answer `\n + 'while no manifest lists them. Mount one router per namespace.',\n );\n }\n namespaces.add(namespace);\n }\n}\n\n/**\n * Define a router with multiple routes (tRPC-style)\n *\n * Supports chainable API for packages and middlewares:\n *\n * @example\n * ```ts\n * // Basic usage\n * export const appRouter = defineRouter({\n * getRoot,\n * getStatus,\n * listExamples,\n * });\n *\n * // With package routers (type-hidden)\n * export const appRouter = defineRouter({\n * getRoot,\n * getStatus,\n * })\n * .packages([authRouter, cmsAppRouter]);\n *\n * // With global middlewares\n * export const appRouter = defineRouter({\n * getRoot,\n * getStatus,\n * })\n * .packages([authRouter])\n * .use([authMiddleware, loggingMiddleware]);\n *\n * export type AppRouter = typeof appRouter;\n * ```\n *\n * Package routes:\n * - Recognized by RPC proxy and backend for routing\n * - NOT included in AppRouter type (use authApi, cmsApi instead)\n * - Prevents confusion between app API and package APIs\n */\nexport function defineRouter<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(\n routes: TRoutes,\n): Router<TRoutes>\n{\n return createRouterInstance({\n routes,\n packageRouters: [],\n globalMiddlewares: [],\n contractVersion: null,\n publishesRouteMap: true,\n });\n}\n\n/**\n * A router no client addresses by name.\n *\n * The app's generated route map carries the routes of every package router the\n * app mounts with `.packages()`, so that a package client calling its own route\n * by name resolves through the app's RPC proxy. A router built here is left out\n * of that map: its routes are reached by URL, by a tool that was told the URL,\n * so no name of theirs has to resolve anywhere and a name shared with an app\n * route is only a shared name.\n *\n * Declared by the package that ships the router, because only it knows whether\n * any client names these routes: `createOpsRouter` and the tracking routes of\n * `@spfn/notification` do it, and any package whose surface is reached by URL\n * may. The obligation is the whole of it — a package whose client *does* name\n * its routes must use `defineRouter`, or those names land in nobody's map and\n * resolve nowhere (and a collision that really would take an app route's entry\n * generates silently). `defineRouter` is the default for exactly that reason: a\n * package that says nothing is carried and checked.\n */\nexport function defineUnmappedRouter<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(\n routes: TRoutes,\n): Router<TRoutes>\n{\n return createRouterInstance({\n routes,\n packageRouters: [],\n globalMiddlewares: [],\n contractVersion: null,\n publishesRouteMap: false,\n });\n}\n","/**\n * Thrown when a namespace, route, or module cannot be part of a command\n * surface. `@spfn/core/ops` exports the same class as `OpsRouterError`.\n */\nexport class SurfaceError extends Error\n{\n constructor(message: string)\n {\n super(message);\n this.name = 'SurfaceError';\n }\n}\n","/**\n * How refusals name the surface they come from.\n *\n * A command surface is generic, but the ops surface predates it and its\n * refusals already say \"ops route\" and point at `opsRoute`. The ops layer\n * passes its own wording so an operator reading an ops refusal sees the same\n * text as before; every other surface reads the neutral one.\n */\nexport interface SurfaceWording\n{\n /** What a route on this surface is called: \"ops route\", \"surface route\". */\n noun: string;\n\n /** The builder that applies the namespace, as named in a refusal. */\n builder: string;\n\n /** The function that builds the surface, as named in a refusal. */\n factory: string;\n}\n\nexport const SURFACE_WORDING: SurfaceWording = {\n noun: 'surface',\n builder: '`<surface>.route`',\n factory: 'defineSurface',\n};\n\n/** The noun at the start of a sentence. */\nexport function capitalized(noun: string): string\n{\n return noun.charAt(0).toUpperCase() + noun.slice(1);\n}\n","/**\n * Surface Manifest\n *\n * The server's self-description of a command surface: every command an app\n * exposes under the surface's namespace, with each command's input schemas as\n * plain JSON Schema. A client fetches this from the running server, so command\n * discovery needs neither the app's source nor a generated artifact on the\n * caller's machine.\n *\n * The router is loaded and walked (the contract collector's approach) rather\n * than parsed from source: route schemas built from imported values resolve,\n * and TypeBox schemas serialize to JSON Schema by construction.\n */\n\nimport type { JsonSchema } from '../contract/types';\nimport type { RouteDef } from '../route/route-builder';\nimport type { RouteInput } from '../route/route-input';\nimport type { Router } from '../route/router';\nimport type { HttpMethod } from '../route/types';\nimport { SurfaceError } from './error';\nimport type { SurfaceEffect } from './module';\nimport { SURFACE_WORDING, type SurfaceWording } from './wording';\n\n/** One explicitly mounted capability module, as a client sees it. */\nexport interface SurfaceModuleDescriptor\n{\n id: string;\n source: string;\n contractVersion: string;\n summary: string;\n}\n\n/** One invokable command, as a client sees it. */\nexport interface SurfaceCommand\n{\n name: string;\n method: HttpMethod;\n path: string;\n\n /** Present for commands contributed by an explicitly mounted module. */\n module?: string;\n\n /**\n * A module command's from its declaration; an app command's from the\n * route's `.summary()` and `.effect()`, present only when declared.\n */\n summary?: string;\n effect?: SurfaceEffect;\n\n /** Present for module commands only. */\n scopes?: string[];\n\n /** Input sections the route declares, each as JSON Schema. */\n input: {\n params?: JsonSchema;\n query?: JsonSchema;\n body?: JsonSchema;\n };\n}\n\n/** What `GET <namespace>/_manifest` answers. */\nexport interface SurfaceManifest\n{\n manifestVersion: 1;\n /** Additive module metadata. Omitted for an app-only v1 surface. */\n modules?: SurfaceModuleDescriptor[];\n commands: SurfaceCommand[];\n}\n\nfunction isRouter(value: unknown): value is Router<any>\n{\n return value !== null\n && typeof value === 'object'\n && 'routes' in value\n && '_routes' in value;\n}\n\nfunction isRouteDef(value: unknown): value is RouteDef<any>\n{\n return value !== null\n && typeof value === 'object'\n && 'handler' in value;\n}\n\n/**\n * Strip TypeBox's symbol-keyed metadata and hand back plain JSON — the same\n * round trip the contract collector uses.\n */\nfunction toJsonSchema(schema: unknown): JsonSchema\n{\n return JSON.parse(JSON.stringify(schema)) as JsonSchema;\n}\n\nconst INPUT_SECTIONS = ['params', 'query', 'body'] as const;\n\nfunction toCommandInput(input: RouteInput | undefined): SurfaceCommand['input']\n{\n const sections: SurfaceCommand['input'] = {};\n\n if (!input)\n {\n return sections;\n }\n\n for (const section of INPUT_SECTIONS)\n {\n const schema = input[section];\n if (schema)\n {\n sections[section] = toJsonSchema(schema);\n }\n }\n\n return sections;\n}\n\n/**\n * Walk a routes record (nested routers included) and collect every RouteDef\n * as a command, with the summary and effect its route declared. Validation of\n * paths and of that metadata happens in the surface's `router()`, so nothing\n * here is checked but the uniqueness of names.\n */\nexport function collectSurfaceCommands(\n routes: Record<string, RouteDef<any> | Router<any>>,\n wording: SurfaceWording = SURFACE_WORDING,\n): SurfaceCommand[]\n{\n const commands: SurfaceCommand[] = [];\n visit(routes, commands, new Map<string, string>(), wording);\n commands.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n\n return commands;\n}\n\nfunction visit(\n routes: Record<string, RouteDef<any> | Router<any>>,\n commands: SurfaceCommand[],\n claimed: Map<string, string>,\n wording: SurfaceWording,\n): void\n{\n for (const [name, entry] of Object.entries(routes))\n {\n if (isRouter(entry))\n {\n visit(entry.routes, commands, claimed, wording);\n continue;\n }\n\n if (!isRouteDef(entry) || !entry.method || !entry.path)\n {\n continue;\n }\n\n assertUnclaimedName(name, entry.path, claimed, wording);\n\n commands.push({\n name,\n method: entry.method,\n path: entry.path,\n ...(entry.summary !== undefined ? { summary: entry.summary } : {}),\n ...(entry.effect !== undefined ? { effect: entry.effect } : {}),\n input: toCommandInput(entry.input as RouteInput | undefined),\n });\n }\n}\n\n/**\n * Nested routers flatten into one command list, so two routes keyed alike in\n * different routers would both be announced under the same command name. The\n * client resolves a name to the first match, which means a caller asking for\n * one command silently invokes the other — refuse it at definition time.\n */\nfunction assertUnclaimedName(\n name: string,\n path: string,\n claimed: Map<string, string>,\n wording: SurfaceWording,\n): void\n{\n const existing = claimed.get(name);\n if (existing !== undefined)\n {\n throw new SurfaceError(\n `Two ${wording.noun} routes are named \"${name}\" (\"${existing}\" and \"${path}\"). `\n + 'Command names are flattened across nested routers, so each must be unique '\n + 'for a client to resolve the one its caller asked for.',\n );\n }\n\n claimed.set(name, path);\n}\n","interface RouteSegment\n{\n kind: 'static' | 'parameter' | 'wildcard';\n value: string;\n optional: boolean;\n}\n\nfunction routeSegments(path: string): RouteSegment[]\n{\n return path.split('/').slice(1).map((raw): RouteSegment =>\n {\n if (raw === '*' || raw.endsWith('*'))\n {\n return { kind: 'wildcard', value: raw, optional: true };\n }\n if (raw.startsWith(':'))\n {\n return {\n kind: 'parameter',\n value: raw.slice(1).replace(/\\?$/, ''),\n optional: raw.endsWith('?'),\n };\n }\n\n return { kind: 'static', value: raw, optional: false };\n });\n}\n\nfunction customPattern(parameter: string): string | null\n{\n const openingBrace = parameter.indexOf('{');\n\n return openingBrace >= 0 && parameter.endsWith('}')\n ? parameter.slice(openingBrace + 1, -1)\n : null;\n}\n\nfunction parameterAccepts(parameter: string, value: string): boolean\n{\n const pattern = customPattern(parameter);\n if (pattern === null)\n {\n return value.length > 0 && !value.includes('/');\n }\n\n try\n {\n return new RegExp(`^(?:${pattern})$`).test(value);\n }\n catch\n {\n // Hono will reject an invalid pattern when registering it. Treat it as\n // overlapping here so it cannot bypass the scope check first.\n return true;\n }\n}\n\nfunction remainingStaticPath(segments: RouteSegment[], from: number): string | null\n{\n const remaining = segments.slice(from);\n\n return remaining.every(segment => segment.kind === 'static')\n ? remaining.map(segment => segment.value).join('/')\n : null;\n}\n\n/**\n * Whether two Hono route patterns can claim at least one common URL.\n *\n * Custom-regex intersection is deliberately conservative. If disjointness\n * cannot be established from static material, composition is refused: scope\n * middleware must never depend on registration order.\n */\nexport function routePatternsOverlap(firstPath: string, secondPath: string): boolean\n{\n const first = routeSegments(firstPath);\n const second = routeSegments(secondPath);\n const length = Math.max(first.length, second.length);\n\n for (let index = 0; index < length; index++)\n {\n const left = first[index];\n const right = second[index];\n\n if (!left || !right)\n {\n const remaining = left ? first.slice(index) : second.slice(index);\n\n return remaining.every(segment => segment.optional || segment.kind === 'wildcard');\n }\n if (left.kind === 'wildcard' || right.kind === 'wildcard')\n {\n return true;\n }\n if (left.kind === 'static' && right.kind === 'static')\n {\n if (left.value !== right.value)\n {\n return false;\n }\n continue;\n }\n if (left.kind === 'parameter' && right.kind === 'static')\n {\n const remaining = remainingStaticPath(second, index);\n if (customPattern(left.value) !== null && remaining !== null\n && parameterAccepts(left.value, remaining))\n {\n return true;\n }\n if (!parameterAccepts(left.value, right.value))\n {\n return customPattern(left.value) !== null && remaining === null;\n }\n if (customPattern(left.value) !== null && first.length !== second.length)\n {\n return true;\n }\n continue;\n }\n if (left.kind === 'static' && right.kind === 'parameter')\n {\n const remaining = remainingStaticPath(first, index);\n if (customPattern(right.value) !== null && remaining !== null\n && parameterAccepts(right.value, remaining))\n {\n return true;\n }\n if (!parameterAccepts(right.value, left.value))\n {\n return customPattern(right.value) !== null && remaining === null;\n }\n if (customPattern(right.value) !== null && first.length !== second.length)\n {\n return true;\n }\n continue;\n }\n\n // Two parameters both admit some non-empty segment. Custom regexes\n // may also consume separators, which only strengthens the overlap.\n return true;\n }\n\n return true;\n}\n","/**\n * Capability module contract\n *\n * A package describes commands here, but an adopter application decides\n * whether to mount the resulting module, and on which surface. Validation\n * keeps an installed package from becoming a command surface merely by\n * existing, and gives the surface enough metadata to enforce scopes and\n * describe the module to a client from one declaration.\n *\n * A module's paths are written for one namespace — `/_ops/<id>/...` for an\n * ops module — so it is validated against the namespace of the surface that\n * mounts it. A module written for `/_ops` mounted on `/_app` is refused rather\n * than registered at paths outside the surface that is supposed to guard them.\n */\n\nimport type { RouteDef } from '../route/route-builder';\nimport type { RouteEffect } from '../route/types';\nimport { SurfaceError } from './error';\nimport { routePatternsOverlap } from './route-overlap';\nimport { capitalized, SURFACE_WORDING, type SurfaceWording } from './wording';\n\n/** One vocabulary for module commands and an app's own: the route's `.effect()`. */\nexport type SurfaceEffect = RouteEffect;\n\nexport interface SurfaceModuleCommand<TRoute extends RouteDef<any> = RouteDef<any>>\n{\n summary: string;\n effect: SurfaceEffect;\n scopes: readonly string[];\n route: TRoute;\n}\n\nexport interface SurfaceModule<\n TCommands extends Record<string, SurfaceModuleCommand<any>> = Record<string, SurfaceModuleCommand<any>>,\n>\n{\n id: string;\n source: string;\n contractVersion: string;\n summary: string;\n commands: TCommands;\n}\n\nconst MODULE_ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\nconst COMMAND_NAME = /^[A-Za-z][A-Za-z0-9]*(?:\\.[A-Za-z][A-Za-z0-9]*)*$/;\nconst CONTRACT_VERSION = /^\\d+\\.\\d+\\.\\d+(?:[-+][0-9A-Za-z.-]+)*$/;\nconst EFFECTS = new Set<SurfaceEffect>(['read', 'write', 'destructive']);\nconst PATH_BASE = 'https://spfn.invalid';\n\n/** Whether `value` is one of the effects a command can declare. */\nexport function isSurfaceEffect(value: unknown): value is SurfaceEffect\n{\n return EFFECTS.has(value as SurfaceEffect);\n}\n\nfunction assertText(label: string, value: unknown): asserts value is string\n{\n if (typeof value !== 'string' || value.trim().length === 0)\n {\n throw new SurfaceError(`${label} must be a non-empty string.`);\n }\n}\n\n/** Where a module is being mounted, and what its refusals call it. */\ninterface MountPoint\n{\n namespace: string;\n label: string;\n}\n\nfunction assertStableModulePath(at: MountPoint, moduleId: string, commandName: string, path: string): void\n{\n const label = `${at.label} command \"${moduleId}.${commandName}\" path \"${path}\"`;\n // Hono path patterns use braces for regex parameters and a trailing `?`\n // for optional ones. Escape those route-language characters before asking\n // WHATWG URL normalization whether the transport-level path moves.\n const transportPath = path.replace(/[{}?#]/g, character =>\n `%${character.charCodeAt(0).toString(16).toUpperCase()}`);\n let url: URL;\n try\n {\n url = new URL(transportPath, PATH_BASE);\n }\n catch\n {\n throw new SurfaceError(`${label} is not a valid URL path.`);\n }\n\n if (url.origin !== PATH_BASE || url.search !== '' || url.hash !== '' || url.pathname !== transportPath)\n {\n throw new SurfaceError(`${label} is not a stable plain absolute path.`);\n }\n\n const slashCount = (path.match(/\\//g) ?? []).length;\n let decoded = path;\n for (let depth = 0; depth < 8; depth++)\n {\n let next: string;\n try\n {\n next = decodeURIComponent(decoded);\n }\n catch\n {\n throw new SurfaceError(`${label} contains malformed percent encoding.`);\n }\n\n if (next.includes('\\\\') || (next.match(/\\//g) ?? []).length !== slashCount\n || next.split('/').some(segment => segment === '.' || segment === '..'))\n {\n throw new SurfaceError(`${label} contains encoded path separators or dot segments.`);\n }\n if (next === decoded)\n {\n return;\n }\n decoded = next;\n }\n\n throw new SurfaceError(`${label} uses too many percent-encoding layers.`);\n}\n\nfunction assertCliCallableModulePath(at: MountPoint, moduleId: string, commandName: string, path: string): void\n{\n const unsupported = path.split('/').slice(1).find(segment =>\n segment === '*'\n || segment.includes('*')\n || (segment.startsWith(':')\n ? !/^:[A-Za-z0-9_]+$/.test(segment)\n : !/^[A-Za-z0-9._~-]+$/.test(segment)));\n\n if (unsupported !== undefined)\n {\n throw new SurfaceError(\n `${at.label} command \"${moduleId}.${commandName}\" path segment \"${unsupported}\" is not CLI-callable. `\n + 'Module routes support URL-safe static segments and simple :name parameters only; '\n + 'optional, wildcard, and custom-regex parameters are not supported.',\n );\n }\n}\n\nfunction assertCommand(at: MountPoint, moduleId: string, name: string, command: SurfaceModuleCommand<any>): void\n{\n if (!COMMAND_NAME.test(name))\n {\n throw new SurfaceError(\n `${at.label} module \"${moduleId}\" has invalid command name \"${name}\". `\n + 'Use dot-separated alphanumeric names.',\n );\n }\n\n assertText(`${at.label} command \"${moduleId}.${name}\" summary`, command?.summary);\n\n if (!EFFECTS.has(command?.effect))\n {\n throw new SurfaceError(\n `${at.label} command \"${moduleId}.${name}\" has invalid effect ${JSON.stringify(command?.effect)}.`,\n );\n }\n\n if (!Array.isArray(command?.scopes) || command.scopes.length === 0\n || command.scopes.some(scope => typeof scope !== 'string' || scope.trim().length === 0))\n {\n throw new SurfaceError(`${at.label} command \"${moduleId}.${name}\" must declare at least one non-empty scope.`);\n }\n\n const route = command?.route;\n if (!route || typeof route.handler !== 'function' || !route.method || !route.path)\n {\n throw new SurfaceError(`${at.label} command \"${moduleId}.${name}\" must carry a complete route.`);\n }\n\n assertStableModulePath(at, moduleId, name, route.path);\n assertCliCallableModulePath(at, moduleId, name, route.path);\n\n const modulePath = `${at.namespace}/${moduleId}/`;\n if (!route.path.startsWith(modulePath))\n {\n throw new SurfaceError(\n `${at.label} command \"${moduleId}.${name}\" is at \"${route.path}\", outside \"${modulePath}\". `\n + `A module mounted on \"${at.namespace}\" keeps every command under \"${modulePath}\".`,\n );\n }\n if (route.path.split('/').includes('..'))\n {\n throw new SurfaceError(`${at.label} command \"${moduleId}.${name}\" path climbs out of its module namespace.`);\n }\n}\n\n/**\n * Validate a capability module against the namespace it is mounted on.\n *\n * This function intentionally does not register anything. Only an adopter's\n * explicit `modules: [...]` composition exposes the module, and the surface\n * calls this for each one when its router is built.\n */\nexport function validateSurfaceModule<\n TCommands extends Record<string, SurfaceModuleCommand<any>>,\n>(\n module: SurfaceModule<TCommands>,\n namespace: string,\n wording: SurfaceWording = SURFACE_WORDING,\n): SurfaceModule<TCommands>\n{\n const at: MountPoint = { namespace, label: capitalized(wording.noun) };\n\n if (!MODULE_ID.test(module?.id ?? ''))\n {\n throw new SurfaceError(\n `${at.label} module id ${JSON.stringify(module?.id)} is invalid. Use lower-kebab-case.`,\n );\n }\n\n assertText(`${at.label} module \"${module.id}\" source`, module.source);\n assertText(`${at.label} module \"${module.id}\" summary`, module.summary);\n\n if (!CONTRACT_VERSION.test(module.contractVersion))\n {\n throw new SurfaceError(\n `${at.label} module \"${module.id}\" contractVersion must be a semantic version.`,\n );\n }\n\n if (!module.commands || typeof module.commands !== 'object' || Array.isArray(module.commands))\n {\n throw new SurfaceError(`${at.label} module \"${module.id}\" commands must be an object.`);\n }\n\n const signatures = new Map<string, string>();\n const claimedRoutes: Array<{ name: string; method: string; path: string }> = [];\n for (const [name, command] of Object.entries(module.commands))\n {\n assertCommand(at, module.id, name, command);\n\n const signature = `${command.route.method} ${command.route.path}`;\n const existing = signatures.get(signature);\n if (existing)\n {\n throw new SurfaceError(\n `${at.label} module \"${module.id}\" commands \"${existing}\" and \"${name}\" both use ${signature}.`,\n );\n }\n signatures.set(signature, name);\n\n const overlapping = claimedRoutes.find(claim =>\n claim.method === command.route.method\n && routePatternsOverlap(claim.path, command.route.path!));\n if (overlapping)\n {\n throw new SurfaceError(\n `${at.label} module \"${module.id}\" commands \"${overlapping.name}\" and \"${name}\" `\n + `have overlapping ${command.route.method} routes `\n + `(\"${overlapping.path}\" and \"${command.route.path}\").`,\n );\n }\n claimedRoutes.push({\n name,\n method: command.route.method!,\n path: command.route.path!,\n });\n }\n\n return module;\n}\n\n/**\n * Validate and return a capability module written for a surface on\n * `namespace` — every command under `<namespace>/<id>/`. The surface checks\n * it again against its own namespace when it mounts it, so a module defined\n * for one namespace and mounted on another is still refused.\n */\nexport function defineSurfaceModule<\n TCommands extends Record<string, SurfaceModuleCommand<any>>,\n>(module: SurfaceModule<TCommands>, namespace: string): SurfaceModule<TCommands>\n{\n return validateSurfaceModule(module, namespace);\n}\n","/**\n * Surface namespace and route builder\n *\n * A namespace is the path every command on a surface lives under — `/_ops`\n * for operators, `/_app` or anything else an app chooses for another caller.\n * It is refused at definition time unless it is a plain absolute path of\n * URL-safe segments: no trailing slash, no dots, no percent signs, no\n * parameters. Every check downstream — the prefix a route must carry, the\n * module paths, the manifest URL, the CLI's own path checks — is a string\n * comparison against it, and only a literal path keeps those comparisons\n * honest.\n *\n * The route builder is `route` with the namespace applied, so a definition\n * carries only the part of the path the app owns:\n *\n * ```ts\n * const pageAdd = app.route.post('/pages') // POST /_app/pages\n * .handler(async () => ({ ok: true }));\n * ```\n */\n\nimport { route, type RouteBuilder } from '../route/route-builder';\nimport { SurfaceError } from './error';\nimport { capitalized, type SurfaceWording } from './wording';\n\nconst NAMESPACE = /^(?:\\/[A-Za-z0-9_-]+)+$/;\n\n/** `route`, with a surface's namespace applied. */\nexport interface SurfaceRouteBuilder\n{\n get: (path: string) => RouteBuilder;\n post: (path: string) => RouteBuilder;\n put: (path: string) => RouteBuilder;\n patch: (path: string) => RouteBuilder;\n delete: (path: string) => RouteBuilder;\n}\n\nexport function assertNamespace(namespace: string): void\n{\n if (typeof namespace !== 'string' || !NAMESPACE.test(namespace))\n {\n throw new SurfaceError(\n `Surface namespace ${JSON.stringify(namespace)} is invalid. `\n + 'Use an absolute path of [A-Za-z0-9_-] segments without a trailing slash, such as \"/_app\".',\n );\n }\n}\n\n/** Where a surface serves its manifest. */\nexport function manifestPathOf(namespace: string): string\n{\n return `${namespace}/_manifest`;\n}\n\n/**\n * The reserved route name of a surface's manifest: `get`, the namespace\n * encoded, `Manifest`. `/_ops` → `getOpsManifest`, `/_app` → `getAppManifest`.\n *\n * The encoding is one-to-one, so two surfaces mounted side by side never\n * register two routes under one name. The leading `/` is dropped, and then:\n *\n * - a lowercase letter or a digit stays as it is;\n * - `_` followed by a lowercase letter becomes that letter in uppercase\n * (`_app` → `App`), which keeps the common namespaces readable;\n * - every other character is escaped with `_`: an uppercase letter `X` →\n * `_X`, any other `_` → `__`, `-` → `_d`, `/` → `_s`.\n *\n * A `_` in the output therefore always opens a two-character escape, and an\n * uppercase letter outside one always stands for `_` and a lowercase letter. Read left\n * to right, every name decodes to exactly one namespace: `/app` →\n * `getappManifest`, `/Ops` → `get_OpsManifest`, `/a/b` → `geta_sbManifest`,\n * `/a_b` → `getaBManifest`, `/a-b` → `geta_dbManifest`.\n */\nexport function manifestNameOf(namespace: string): string\n{\n return `get${namespace.slice(1).replace(/_[a-z]|[A-Z_/-]/g, encodedCharacter)}Manifest`;\n}\n\nconst ESCAPES: Record<string, string> = { '_': '_', '-': 'd', '/': 's' };\n\nfunction encodedCharacter(match: string): string\n{\n if (match.length === 2)\n {\n return match.charAt(1).toUpperCase();\n }\n\n return `_${ESCAPES[match] ?? match}`;\n}\n\nfunction toSurfacePath(namespace: string, path: string, wording: SurfaceWording): string\n{\n const label = capitalized(wording.noun);\n\n if (!path.startsWith('/'))\n {\n throw new SurfaceError(\n `${label} route path \"${path}\" must start with \"/\". It is appended to \"${namespace}\", `\n + `so \"${path}\" would read as \"${namespace}${path}\".`,\n );\n }\n\n if (path === '/')\n {\n throw new SurfaceError(\n `${label} route path \"/\" names no command — \"${namespace}\" itself is not a command.`,\n );\n }\n\n return namespace + path;\n}\n\nexport function surfaceRouteBuilder(namespace: string, wording: SurfaceWording): SurfaceRouteBuilder\n{\n const method = (name: keyof SurfaceRouteBuilder) =>\n (path: string) => route[name](toSurfacePath(namespace, path, wording));\n\n return {\n get: method('get'),\n post: method('post'),\n put: method('put'),\n patch: method('patch'),\n delete: method('delete'),\n };\n}\n","/**\n * Command Surface\n *\n * A namespace of commands an app exposes to a caller that is not its own\n * frontend — operators on `/_ops`, an issuer's signed tokens on `/_app`, any\n * other machine caller on a namespace the app picks. An app develops the\n * commands as ordinary routes; `defineSurface` turns them into a mountable\n * package router that:\n *\n * - requires every route to carry the surface's namespace, applied by the\n * surface's own `route`, so a command is recognizable by its path and can\n * never shadow an app route;\n * - injects the given auth middleware into every command, so a command\n * reachable without authentication cannot be created by accident — there is\n * no opt-out;\n * - serves `GET <namespace>/_manifest`, the self-description a client\n * discovers commands from, registered first so no command takes its URL.\n * The manifest is the one route that may be public, and only when the\n * surface says so: its commands stay behind auth regardless.\n *\n * What the path looks like after the namespace is the app's business, decided\n * when the route is written — this factory does not audit its shape.\n *\n * The auth middleware lives with the app's auth stack (`@spfn/auth` ships\n * `opsTokenAuth` and `signedTokenAuth`); core owns only the structure, so a\n * surface has no opinion about how a credential is stored or verified.\n * `@spfn/core/ops` is this factory fixed to `/_ops`.\n *\n * @example\n * ```ts\n * import { defineSurface } from '@spfn/core/surface';\n * import { signedTokenAuth } from '@spfn/auth/server';\n *\n * export const app = defineSurface({\n * namespace: '/_app',\n * auth: signedTokenAuth({ keysUrl, iss, aud }),\n * manifest: 'public',\n * });\n *\n * export const pageAdd = app.route.post('/pages') // POST /_app/pages\n * .input({ body: PageAddBody })\n * .handler(async (c) => pagesRepository.add((await c.data()).body));\n *\n * // mounted like any package router, beside `/_ops`:\n * export const appRouter = defineRouter({ ... }).packages([app.router({ pageAdd }), opsRouter]);\n * ```\n */\n\nimport type { MiddlewareHandler } from 'hono';\nimport type { NamedMiddleware } from '../route/define-middleware';\nimport { route, type RouteDef } from '../route/route-builder';\nimport { defineUnmappedRouter, type Router } from '../route/router';\nimport { SurfaceError } from './error';\nimport {\n collectSurfaceCommands,\n type SurfaceCommand,\n type SurfaceManifest,\n type SurfaceModuleDescriptor,\n} from './manifest';\nimport { isSurfaceEffect, validateSurfaceModule, type SurfaceModule, type SurfaceModuleCommand } from './module';\nimport {\n assertNamespace,\n manifestNameOf,\n manifestPathOf,\n surfaceRouteBuilder,\n type SurfaceRouteBuilder,\n} from './namespace';\nimport { routePatternsOverlap } from './route-overlap';\nimport { capitalized, SURFACE_WORDING, type SurfaceWording } from './wording';\n\ntype SurfaceMiddleware = NamedMiddleware<string> | MiddlewareHandler;\n\n/**\n * Build the guard for one command, or `undefined` for none. Called once per\n * command when the router is built; the guard runs after `auth` and before the\n * command's own middlewares.\n *\n * The command is the manifest entry, so its `effect` is there to read — a\n * guard can be stricter for a `destructive` command than for a `read`.\n */\nexport type SurfaceAuthorize = (command: SurfaceCommand) => SurfaceMiddleware | undefined;\n\nexport interface SurfaceOptions\n{\n /** Every command lives under it, e.g. `/_app`. Must be a plain absolute path. */\n namespace: string;\n\n /**\n * The middleware that authenticates every command. Required — a surface\n * without authentication is refused at definition time, not discovered in\n * production.\n */\n auth: NamedMiddleware<string>;\n\n /** Per-command guard. Required when modules are mounted. */\n authorize?: SurfaceAuthorize;\n\n /**\n * `'authenticated'` (default): the manifest carries `auth` like every\n * command. `'public'`: it carries none and skips a global `auth`\n * middleware, so a caller can discover commands before it holds a token.\n */\n manifest?: 'authenticated' | 'public';\n\n /** Capability modules this application explicitly chooses to expose here. */\n modules?: readonly SurfaceModule[];\n}\n\nexport interface Surface\n{\n /** The validated namespace, as given. */\n readonly namespace: string;\n\n /** `route` with the namespace applied. */\n readonly route: SurfaceRouteBuilder;\n\n /**\n * Build the unmapped package router: the manifest first, then the\n * secured commands, then the secured module commands.\n */\n router<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(routes: TRoutes): Router<any>;\n}\n\n/** What `router()` builds from: the options, checked, plus the derived names. */\ninterface Plan\n{\n namespace: string;\n prefix: string;\n manifestPath: string;\n manifestName: string;\n auth: NamedMiddleware<string>;\n authorize?: SurfaceAuthorize;\n manifest: 'authenticated' | 'public';\n modules: readonly SurfaceModule[];\n wording: SurfaceWording;\n requireEffect: boolean;\n}\n\n/** How a surface treats an app command that declares no `.effect()`. Internal to core. */\nexport interface SurfaceRules\n{\n /** `true`: refuse it. `false`: announce it without an effect, as `/_ops` always has. */\n requireEffect: boolean;\n}\n\n/**\n * The longest summary a command may announce. The same 500 as the CLI's\n * `MAX_SUMMARY_LENGTH` in `spfn/surface`'s manifest trust, so a server never\n * announces a summary its own client would refuse.\n */\nconst MAX_COMMAND_SUMMARY_LENGTH = 500;\n\nconst EFFECT_METHOD = \".effect('read' | 'write' | 'destructive')\";\n\ninterface CompiledModuleRoute\n{\n route: RouteDef<any>;\n command: SurfaceCommand;\n}\n\ninterface CompiledModuleSurface\n{\n descriptors: SurfaceModuleDescriptor[];\n commands: SurfaceCommand[];\n routes: Record<string, CompiledModuleRoute>;\n}\n\nfunction isRouter(value: unknown): value is Router<any>\n{\n return value !== null\n && typeof value === 'object'\n && 'routes' in value\n && '_routes' in value;\n}\n\nfunction isRouteDef(value: unknown): value is RouteDef<any>\n{\n return value !== null\n && typeof value === 'object'\n && 'handler' in value;\n}\n\nfunction assertSurfaceRoute(plan: Plan, name: string, def: RouteDef<any>): void\n{\n const label = capitalized(plan.wording.noun);\n\n if (!def.method || !def.path)\n {\n throw new SurfaceError(\n `${label} route \"${name}\" has no method or path. `\n + 'A command is invoked on the wire, so both are required.',\n );\n }\n\n if (!def.path.startsWith(plan.prefix))\n {\n throw new SurfaceError(\n `${label} route \"${name}\" is at \"${def.path}\", outside \"${plan.prefix}\". `\n + `Build ${plan.wording.noun} routes with ${plan.wording.builder} rather than \\`route\\` — it applies the namespace, `\n + 'so the path a definition carries is only the part the app owns.',\n );\n }\n\n if (def.path === plan.manifestPath)\n {\n throw new SurfaceError(\n `${label} route \"${name}\" claims \"${plan.manifestPath}\", which is reserved for the manifest. `\n + 'The manifest is registered first, so this route would never answer.',\n );\n }\n}\n\n/**\n * Refuse an app command whose route declares an effect or summary a client\n * could not use — or, on a surface that requires it, no effect at all. A\n * manifest is then never built announcing a command whose effect is unknown,\n * and a defaulted effect is never put in its place: that would be a claim the\n * app did not make, in the field a client reads to decide whether to retry.\n */\nfunction assertCommandMetadata(plan: Plan, name: string, def: RouteDef<any>): void\n{\n const label = `${capitalized(plan.wording.noun)} command \"${name}\"`;\n\n if (def.effect === undefined && plan.requireEffect)\n {\n throw new SurfaceError(\n `${label} declares no effect. A client reads it to decide whether to call, retry, `\n + `or ask for confirmation, so ${plan.wording.factory} refuses a command without one. `\n + `Declare it on the route with ${EFFECT_METHOD}.`,\n );\n }\n\n if (def.effect !== undefined && !isSurfaceEffect(def.effect))\n {\n throw new SurfaceError(\n `${label} has invalid effect ${JSON.stringify(def.effect)}. `\n + `A client knows no other, so declare it with ${EFFECT_METHOD}.`,\n );\n }\n\n assertCommandSummary(label, def.summary);\n}\n\n/** Refuse a summary the CLI would refuse: blank, or longer than it accepts. */\nfunction assertCommandSummary(label: string, summary: unknown): void\n{\n if (summary === undefined)\n {\n return;\n }\n\n if (typeof summary !== 'string' || summary.trim().length === 0)\n {\n throw new SurfaceError(\n `${label} has an empty summary. A client would list it as a command described by nothing; `\n + 'give .summary() one line of text, or leave it out.',\n );\n }\n\n if (summary.length > MAX_COMMAND_SUMMARY_LENGTH)\n {\n throw new SurfaceError(\n `${label} has a summary of ${summary.length} characters, over the ${MAX_COMMAND_SUMMARY_LENGTH} `\n + 'a client accepts — it would drop the command\\'s metadata and treat it as destructive. Shorten it.',\n );\n }\n}\n\n/**\n * A module command's effect is the module's declaration; its route's own\n * `.effect()` is ignored when it agrees and refused when it does not, because\n * the manifest can announce only one and the route's author meant the other.\n * The route's `.summary()` is not read at all — the module's wins.\n */\nfunction assertModuleRouteEffect(plan: Plan, name: string, definition: SurfaceModuleCommand<any>): void\n{\n const routeEffect = definition.route.effect;\n\n if (routeEffect !== undefined && routeEffect !== definition.effect)\n {\n throw new SurfaceError(\n `${capitalized(plan.wording.noun)} command \"${name}\" is declared ${JSON.stringify(definition.effect)} `\n + `by its module, but its route says .effect(${JSON.stringify(routeEffect)}). `\n + 'The manifest announces the module\\'s declaration, so the two cannot disagree. '\n + 'Drop the route\\'s .effect() or make it match.',\n );\n }\n}\n\n/**\n * The reserved name is checked for every entry, route and nested router\n * alike, because the merge cannot refuse a duplicate key on its own. The\n * manifest is merged in first and the app's entries spread over it, so an\n * entry under this name would replace the manifest — the surface would then\n * announce nothing and a client would discover no commands at all.\n */\nfunction assertSurfaceName(plan: Plan, name: string): void\n{\n if (name === plan.manifestName)\n {\n throw new SurfaceError(\n `${capitalized(plan.wording.noun)} route name \"${plan.manifestName}\" is reserved for the manifest route.`,\n );\n }\n}\n\n/**\n * Rebuild a nested router with the auth middleware injected into its routes,\n * carrying over what the original declared. A plain `defineRouter` of the\n * secured routes would silently drop the router's own `.use()` middlewares —\n * a scope guard among them — leaving those routes reachable by any valid\n * credential.\n *\n * It is rebuilt unmapped, like the surface that holds it: a nested surface\n * router publishes no route map either.\n *\n * Those middlewares are handed down to the routes rather than left on the\n * rebuilt router. Router-level middlewares are registered ahead of every\n * route-level one, so a guard left in place would run before the auth that\n * was injected per route — reading a request no one had authenticated yet.\n *\n * `.packages()` is refused rather than carried: package routes are registered\n * without passing through this factory, so they would join the surface with\n * neither the prefix check nor the auth injection.\n */\nfunction rebuildNestedRouter(\n plan: Plan,\n name: string,\n router: Router<any>,\n commandsByName: ReadonlyMap<string, SurfaceCommand>,\n inherited: ReadonlyArray<NamedMiddleware<string>>,\n): Router<any>\n{\n if (router._packageRouters?.length > 0)\n {\n throw new SurfaceError(\n `${capitalized(plan.wording.noun)} router \"${name}\" mounts package routers with .packages(). `\n + 'Their routes bypass the prefix check and the auth injection, so a surface cannot carry them.',\n );\n }\n\n const handedDown = [...inherited, ...(router._globalMiddlewares ?? [])];\n\n let rebuilt = defineUnmappedRouter(\n secureRoutes(plan, router.routes, commandsByName, handedDown) as Record<string, RouteDef<any>>,\n );\n\n if (router._contractVersion)\n {\n rebuilt = rebuilt.contractVersion(router._contractVersion);\n }\n\n return rebuilt;\n}\n\n/**\n * Validate every route and hand back a copy carrying, in order, the auth\n * middleware, the command's guard when `authorize` gave one, the middlewares\n * its enclosing routers declared with `.use()`, and its own. Route-level\n * injection (rather than router-level `.use`) makes the middleware's `skips`\n * declaration effective, so `opsTokenAuth` can auto-skip a server-level `auth`\n * middleware exactly as `oneTimeTokenAuth` does — and it is what puts auth\n * ahead of every group guard.\n *\n * `authorize` is asked for a command's guard only once its own route has\n * passed `assertSurfaceRoute` and `assertCommandMetadata` — an `authorize`\n * written to switch exhaustively on `command.effect` must never be handed one\n * `defineSurface` would otherwise have refused.\n */\nfunction secureRoutes(\n plan: Plan,\n routes: Record<string, RouteDef<any> | Router<any>>,\n commandsByName: ReadonlyMap<string, SurfaceCommand>,\n inherited: ReadonlyArray<NamedMiddleware<string>> = [],\n): Record<string, RouteDef<any> | Router<any>>\n{\n const secured: Record<string, RouteDef<any> | Router<any>> = {};\n\n for (const [name, entry] of Object.entries(routes))\n {\n assertSurfaceName(plan, name);\n\n if (isRouter(entry))\n {\n secured[name] = rebuildNestedRouter(plan, name, entry, commandsByName, inherited);\n continue;\n }\n\n if (!isRouteDef(entry))\n {\n throw new SurfaceError(\n `${capitalized(plan.wording.noun)} router entry \"${name}\" is neither a route nor a router.`,\n );\n }\n\n assertSurfaceRoute(plan, name, entry);\n assertCommandMetadata(plan, name, entry);\n const guard = plan.authorize?.(commandsByName.get(name)!);\n secured[name] = {\n ...entry,\n middlewares: commandChain(plan, name, guard, [...inherited, ...(entry.middlewares ?? [])]),\n };\n }\n\n return secured;\n}\n\n/**\n * A command's middlewares in the order they run: auth, the guard when\n * `authorize` gave one, then the ones the command declared — its enclosing\n * routers' first, its own last.\n *\n * A guard sharing its name with the surface's auth middleware or a declared\n * middleware is refused rather than chained. Registration keeps one\n * middleware per name, so the other one would be dropped without a word —\n * and a guard factory that returns a named middleware per call makes that\n * collision easy to hit by accident.\n */\nfunction commandChain(\n plan: Plan,\n name: string,\n guard: SurfaceMiddleware | undefined,\n declared: readonly SurfaceMiddleware[],\n): SurfaceMiddleware[]\n{\n if (guard === undefined)\n {\n return [plan.auth, ...declared];\n }\n\n const guardName = middlewareNameOf(guard);\n if (guardName !== undefined)\n {\n refuseGuardCollision(plan, name, guardName, declared);\n }\n\n return [plan.auth, guard, ...declared];\n}\n\n/** Throw when the guard's name collides with `auth` or a declared middleware. */\nfunction refuseGuardCollision(\n plan: Plan,\n name: string,\n guardName: string,\n declared: readonly SurfaceMiddleware[],\n): void\n{\n const noun = capitalized(plan.wording.noun);\n\n if (middlewareNameOf(plan.auth) === guardName)\n {\n throw new SurfaceError(\n `${noun} command \"${name}\"'s guard shares the name \"${guardName}\" with the surface's auth `\n + 'middleware. Route registration keeps one middleware per name, so the command\\'s guard '\n + 'would never run. Give one of the two a distinct name.',\n );\n }\n\n if (declared.some(middleware => middlewareNameOf(middleware) === guardName))\n {\n throw new SurfaceError(\n `${noun} command \"${name}\" declares a middleware named \"${guardName}\", `\n + 'the name of the guard authorize gave it. Route registration keeps one middleware per name, '\n + 'so the command\\'s own guard would never run. Give one of the two a distinct name.',\n );\n }\n}\n\n/** The name registration deduplicates by — a plain handler has none. */\nfunction middlewareNameOf(middleware: SurfaceMiddleware): string | undefined\n{\n return typeof middleware === 'function' ? undefined : middleware.name;\n}\n\n/**\n * Refuse a module command that would collide with a command already claimed:\n * same name, same method and path, or — against an app command — a pattern\n * that can claim a common URL.\n */\nfunction assertModuleCommandFree(\n plan: Plan,\n command: SurfaceCommand,\n appCommands: readonly SurfaceCommand[],\n claimed: { names: Set<string>; signatures: Map<string, string> },\n): void\n{\n const noun = plan.wording.noun;\n\n if (claimed.names.has(command.name))\n {\n throw new SurfaceError(`Two ${noun} commands are named \"${command.name}\".`);\n }\n\n const signature = `${command.method} ${command.path}`;\n const existing = claimed.signatures.get(signature);\n if (existing)\n {\n throw new SurfaceError(\n `${capitalized(noun)} commands \"${existing}\" and \"${command.name}\" both use ${signature}.`,\n );\n }\n\n // Whether the two patterns can claim a common URL, not whether the app\n // route sits in the module's namespace. An app route at exactly\n // `<namespace>/<moduleId>` shares the prefix but can never be reached by a\n // `<namespace>/<moduleId>/<command>` request, and refusing it would fail a\n // legitimate app at boot.\n const overlapping = appCommands.find(app =>\n app.method === command.method && routePatternsOverlap(app.path, command.path));\n if (overlapping)\n {\n throw new SurfaceError(\n `App ${noun} command \"${overlapping.name}\" at ${command.method} ${overlapping.path} `\n + `overlaps module command \"${command.name}\" at ${command.method} ${command.path}. `\n + 'Which one answers cannot depend on route registration order.',\n );\n }\n\n claimed.names.add(command.name);\n claimed.signatures.set(signature, command.name);\n}\n\nfunction compileModules(plan: Plan, appCommands: readonly SurfaceCommand[]): CompiledModuleSurface\n{\n const compiled: CompiledModuleSurface = { descriptors: [], commands: [], routes: {} };\n const moduleIds = new Set<string>();\n const claimed = {\n names: new Set(appCommands.map(command => command.name)),\n signatures: new Map(appCommands.map(command => [`${command.method} ${command.path}`, command.name])),\n };\n\n for (const rawModule of plan.modules)\n {\n const module = validateSurfaceModule(rawModule, plan.namespace, plan.wording);\n\n if (moduleIds.has(module.id))\n {\n throw new SurfaceError(`Two ${plan.wording.noun} modules use id \"${module.id}\".`);\n }\n moduleIds.add(module.id);\n\n compiled.descriptors.push({\n id: module.id,\n source: module.source,\n contractVersion: module.contractVersion,\n summary: module.summary,\n });\n\n for (const [localName, definition] of Object.entries(module.commands))\n {\n const command: SurfaceCommand = {\n name: `${module.id}.${localName}`,\n module: module.id,\n summary: definition.summary,\n effect: definition.effect,\n scopes: [...definition.scopes],\n method: definition.route.method!,\n path: definition.route.path!,\n input: collectSurfaceCommands({ [localName]: definition.route }, plan.wording)[0]!.input,\n };\n\n assertModuleRouteEffect(plan, command.name, definition);\n assertModuleCommandFree(plan, command, appCommands, claimed);\n compiled.commands.push(command);\n compiled.routes[command.name] = { route: definition.route, command };\n }\n }\n\n compiled.descriptors.sort((a, b) => a.id.localeCompare(b.id));\n compiled.commands.sort((a, b) => a.name.localeCompare(b.name));\n\n return compiled;\n}\n\nfunction secureModuleRoutes(plan: Plan, routes: Record<string, CompiledModuleRoute>): Record<string, RouteDef<any>>\n{\n const secured: Record<string, RouteDef<any>> = {};\n\n for (const [name, definition] of Object.entries(routes))\n {\n assertSurfaceName(plan, name);\n assertSurfaceRoute(plan, name, definition.route);\n secured[name] = {\n ...definition.route,\n middlewares: commandChain(\n plan,\n name,\n plan.authorize?.(definition.command),\n definition.route.middlewares ?? [],\n ),\n };\n }\n\n return secured;\n}\n\n/**\n * The manifest route. Authenticated, it carries `auth` like every command.\n * Public, it carries none and skips a server-level `auth` by name — the\n * global middleware `opsTokenAuth` and `optionalAuth` auto-skip — which would\n * otherwise demand an app session before the manifest could answer.\n */\nfunction manifestRoute(plan: Plan, manifest: SurfaceManifest): RouteDef<any>\n{\n const builder = route.get(plan.manifestPath);\n\n return (plan.manifest === 'public' ? builder.skip(['auth']) : builder.use([plan.auth]))\n .handler(async () => manifest);\n}\n\nfunction buildRouter(plan: Plan, routes: Record<string, RouteDef<any> | Router<any>>): Router<any>\n{\n const appCommands = collectSurfaceCommands(routes, plan.wording);\n const moduleSurface = compileModules(plan, appCommands);\n const commands = [...appCommands, ...moduleSurface.commands]\n .sort((a, b) => a.name.localeCompare(b.name));\n\n const manifest: SurfaceManifest = {\n manifestVersion: 1,\n ...(moduleSurface.descriptors.length > 0 ? { modules: moduleSurface.descriptors } : {}),\n commands,\n };\n\n const commandsByName = new Map(appCommands.map(command => [command.name, command]));\n const secured = secureRoutes(plan, routes, commandsByName);\n const securedModules = secureModuleRoutes(plan, moduleSurface.routes);\n\n // The manifest goes first, so no route in this object can answer its path.\n // A route pattern that happens to cover `<namespace>/_manifest` —\n // `<namespace>/:name`, say — is then only a route the app never reaches\n // through that one URL, not a surface-wide outage where a client cannot\n // discover any command.\n //\n // The ordering reaches no further than this object. `registerRoutes`\n // registers a router's own routes before its package routers, so a pattern\n // the app declares in its own router still shadows the manifest — as it\n // shadows every other package route, which is a property of where the app\n // put that pattern rather than of this factory.\n // `defineUnmappedRouter`, not `defineRouter`: no surface route map is\n // published for an app to merge, and a client invokes a command over the\n // URL the manifest gave it rather than by name through the RPC client. So a\n // command and an app route sharing a name overwrite nothing, and the\n // route-map generator must not refuse the build over it.\n //\n // The namespace marker is non-enumerable, so the router compares and\n // spreads as any other does; `.packages()` reads it to refuse a second\n // surface on this namespace.\n return Object.defineProperty(defineUnmappedRouter({\n [plan.manifestName]: manifestRoute(plan, manifest),\n ...secured,\n ...securedModules,\n } as Record<string, RouteDef<any>>), '_surfaceNamespace', { value: plan.namespace, enumerable: false });\n}\n\nfunction planOf(options: SurfaceOptions, wording: SurfaceWording, rules: SurfaceRules): Plan\n{\n assertNamespace(options?.namespace);\n\n if (!options.auth)\n {\n throw new SurfaceError(\n `${wording.factory} requires an auth middleware ({ auth: ... }). `\n + 'A surface reachable without authentication cannot be created.',\n );\n }\n\n const modules = options.modules ?? [];\n if (modules.length > 0 && !options.authorize)\n {\n throw new SurfaceError(`${wording.factory} requires an authorize function when modules are mounted.`);\n }\n\n const manifest = options.manifest ?? 'authenticated';\n if (manifest !== 'authenticated' && manifest !== 'public')\n {\n throw new SurfaceError(\n `${wording.factory} manifest must be 'authenticated' or 'public', got ${JSON.stringify(manifest)}.`,\n );\n }\n\n return {\n namespace: options.namespace,\n prefix: `${options.namespace}/`,\n manifestPath: manifestPathOf(options.namespace),\n manifestName: manifestNameOf(options.namespace),\n auth: options.auth,\n authorize: options.authorize,\n manifest,\n modules,\n wording,\n requireEffect: rules.requireEffect,\n };\n}\n\n/**\n * `defineSurface` with the words its refusals use and the rules it holds app\n * commands to. Internal: `@spfn/core/ops` passes its own so an ops refusal\n * reads as it always has, and so an ops route that never declared an effect\n * boots as it always has.\n */\nexport function createSurface(options: SurfaceOptions, wording: SurfaceWording, rules: SurfaceRules): Surface\n{\n const plan = planOf(options, wording, rules);\n\n return {\n namespace: plan.namespace,\n route: surfaceRouteBuilder(plan.namespace, wording),\n router: routes => buildRouter(plan, routes),\n };\n}\n\n/**\n * Define a command surface on a namespace.\n *\n * The namespace, the auth middleware, and the `authorize` requirement are\n * checked here; routes and modules when `router()` builds the package router.\n * Every app command must declare its effect with\n * `.effect('read' | 'write' | 'destructive')` — `router()` refuses one that\n * does not, so a client is never handed a command it cannot classify.\n * The router is an ordinary `Router` meant to be mounted with `.packages()`,\n * so its routes stay out of the app's client types exactly like other\n * package routes.\n */\nexport function defineSurface(options: SurfaceOptions): Surface\n{\n return createSurface(options, SURFACE_WORDING, { requireEffect: true });\n}\n"]}
1
+ {"version":3,"sources":["../../src/route/route-builder.ts","../../src/route/router.ts","../../src/surface/error.ts","../../src/surface/wording.ts","../../src/surface/manifest.ts","../../src/surface/route-overlap.ts","../../src/surface/module.ts","../../src/surface/namespace.ts","../../src/surface/define-surface.ts"],"names":["route","isRouter","isRouteDef"],"mappings":";AAmEO,IAAM,YAAA,GAAN,MAAM,aAAA,CAKb;AAAA,EACW,OAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,gBAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA;AAAA;AAAA;AAAA,EAKC,MAIJ,SAAA,EAUJ;AACI,IAAA,MAAM,OAAA,GAAU,IAAI,aAAA,EAAoD;AACxE,IAAA,OAAA,CAAQ,UAAU,IAAA,CAAK,OAAA;AACvB,IAAA,OAAA,CAAQ,QAAQ,IAAA,CAAK,KAAA;AACrB,IAAA,OAAA,CAAQ,MAAA,GAAU,SAAA,EAAW,KAAA,IAAS,IAAA,CAAK,MAAA;AAC3C,IAAA,OAAA,CAAQ,YAAA,GAAgB,SAAA,EAAW,WAAA,IAAe,IAAA,CAAK,YAAA;AACvD,IAAA,OAAA,CAAQ,YAAA,GAAe,SAAA,EAAW,WAAA,IAAe,IAAA,CAAK,YAAA;AACtD,IAAA,OAAA,CAAQ,gBAAA,GAAmB,SAAA,EAAW,eAAA,IAAmB,IAAA,CAAK,gBAAA;AAC9D,IAAA,OAAA,CAAQ,SAAA,GAAY,SAAA,EAAW,QAAA,IAAY,IAAA,CAAK,SAAA;AAChD,IAAA,OAAA,CAAQ,OAAA,GAAU,SAAA,EAAW,MAAA,IAAU,IAAA,CAAK,OAAA;AAC5C,IAAA,OAAA,CAAQ,QAAA,GAAW,SAAA,E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,QAAA,IAAY,eAAA;AACrC,EAAA,IAAI,QAAA,KAAa,eAAA,IAAmB,QAAA,KAAa,QAAA,EACjD;AACI,IAAA,MAAM,IAAI,YAAA;AAAA,MACN,GAAG,OAAA,CAAQ,OAAO,sDAAsD,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAC,CAAA,CAAA;AAAA,KACpG;AAAA,EACJ;AAEA,EAAA,OAAO;AAAA,IACH,WAAW,OAAA,CAAQ,SAAA;AAAA,IACnB,MAAA,EAAQ,CAAA,EAAG,OAAA,CAAQ,SAAS,CAAA,CAAA,CAAA;AAAA,IAC5B,YAAA,EAAc,cAAA,CAAe,OAAA,CAAQ,SAAS,CAAA;AAAA,IAC9C,YAAA,EAAc,cAAA,CAAe,OAAA,CAAQ,SAAS,CAAA;AAAA,IAC9C,MAAM,OAAA,CAAQ,IAAA;AAAA,IACd,WAAW,OAAA,CAAQ,SAAA;AAAA,IACnB,QAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,eAAe,KAAA,CAAM;AAAA,GACzB;AACJ;AAQO,SAAS,aAAA,CAAc,OAAA,EAAyB,OAAA,EAAyB,KAAA,EAChF;AACI,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,OAAA,EAAS,OAAA,EAAS,KAAK,CAAA;AAE3C,EAAA,OAAO;AAAA,IACH,WAAW,IAAA,CAAK,SAAA;AAAA,IAChB,KAAA,EAAO,mBAAA,CAAoB,IAAA,CAAK,SAAA,EAAW,OAAO,CAAA;AAAA,IAClD,MAAA,EAAQ,CAAA,MAAA,KAAU,WAAA,CAAY,IAAA,EAAM,MAAM;AAAA,GAC9C;AACJ;AAcO,SAAS,cAAc,OAAA,EAC9B;AACI,EAAA,OAAO,cAAc,OAAA,EAAS,eAAA,EAAiB,EAAE,aAAA,EAAe,MAAM,CAAA;AAC1E","file":"index.js","sourcesContent":["/**\n * Route Builder\n *\n * Provides tRPC-style chainable API for route definition\n */\n\nimport type { MiddlewareHandler } from 'hono';\nimport type { NamedMiddleware } from './define-middleware';\nimport type { RouteInput } from './route-input';\nimport type { RouteBuilderContext } from './context';\nimport type { RouteContract } from './contract';\nimport type { HttpMethod, RouteEffect } from './types';\n\n/**\n * Route handler function\n */\nexport type RouteHandlerFn<\n TInput extends RouteInput = RouteInput,\n TInterceptor extends RouteInput = {},\n TResponse = unknown,\n> = (c: RouteBuilderContext<TInput, TInterceptor>) => Response | Promise<Response> | TResponse | Promise<TResponse>;\n\n/**\n * Route definition result\n *\n * Contains all information needed for type inference and registration\n */\nexport type RouteDef<\n TInput extends RouteInput = RouteInput,\n TInterceptor extends RouteInput = {},\n TResponse = unknown,\n> = {\n method?: HttpMethod;\n path?: string;\n input?: TInput;\n interceptor?: TInterceptor;\n middlewares?: (MiddlewareHandler | NamedMiddleware<string>)[];\n skipMiddlewares?: string[] | '*';\n\n /**\n * Public promise this route makes to separately deployed clients.\n *\n * Present as a runtime value, unlike `_response`: the contract generator and\n * the compatibility gate read it.\n */\n contract?: RouteContract;\n\n /**\n * What invoking this route does. Read by a command surface, which\n * announces it in its manifest; codegen and the contract ignore it.\n */\n effect?: RouteEffect;\n\n /** One line a command surface announces beside the route; codegen and the contract ignore it. */\n summary?: string;\n\n handler: RouteHandlerFn<TInput, TInterceptor, TResponse>;\n\n // Type inference helpers\n _input: TInput;\n _interceptor: TInterceptor;\n _response: TResponse;\n};\n\n/**\n * Route builder with chainable API (tRPC-style)\n */\nexport class RouteBuilder<\n TInput extends RouteInput = {},\n TInterceptor extends RouteInput = {},\n TResponse = never,\n>\n{\n public _method?: HttpMethod;\n public _path?: string;\n public _input?: TInput;\n public _interceptor?: TInterceptor;\n public _middlewares?: (MiddlewareHandler | NamedMiddleware<string>)[];\n public _skipMiddlewares?: string[] | '*';\n public _contract?: RouteContract;\n public _effect?: RouteEffect;\n public _summary?: string;\n\n /**\n * Create a new RouteBuilder with copied properties and optional overrides\n */\n private clone<\n TNewInput extends RouteInput = TInput,\n TNewInterceptor extends RouteInput = TInterceptor,\n >(\n overrides?: Partial<{\n input: TNewInput;\n interceptor: TNewInterceptor;\n middlewares: (MiddlewareHandler | NamedMiddleware<string>)[];\n skipMiddlewares: string[] | '*';\n contract: RouteContract;\n effect: RouteEffect;\n summary: string;\n }>,\n ): RouteBuilder<TNewInput, TNewInterceptor, TResponse>\n {\n const builder = new RouteBuilder<TNewInput, TNewInterceptor, TResponse>();\n builder._method = this._method;\n builder._path = this._path;\n builder._input = (overrides?.input ?? this._input) as TNewInput | undefined;\n builder._interceptor = (overrides?.interceptor ?? this._interceptor) as TNewInterceptor | undefined;\n builder._middlewares = overrides?.middlewares ?? this._middlewares;\n builder._skipMiddlewares = overrides?.skipMiddlewares ?? this._skipMiddlewares;\n builder._contract = overrides?.contract ?? this._contract;\n builder._effect = overrides?.effect ?? this._effect;\n builder._summary = overrides?.summary ?? this._summary;\n\n return builder;\n }\n\n /**\n * Define input schemas\n *\n * @example\n * ```ts\n * route.get('/users/:id')\n * .input({\n * params: Type.Object({ id: Type.String() }),\n * query: Type.Object({ page: Type.Number() }),\n * headers: Type.Object({ authorization: Type.String() })\n * })\n * .handler(async (c) => {\n * const { params, query, headers } = await c.data();\n * // params = { id: string }\n * // query = { page: number }\n * // headers = { authorization: string }\n * })\n * ```\n */\n input<TNewInput extends RouteInput>(input: TNewInput): RouteBuilder<TNewInput, TInterceptor, TResponse>\n {\n return this.clone({ input });\n }\n\n /**\n * Define fields injected by interceptors\n *\n * These fields are:\n * - Available in the handler (merged with input)\n * - Excluded from client types (codegen uses only input)\n * - Not validated by route input schema (injected by middleware)\n *\n * Use this when middleware/interceptors add fields to the request\n * before it reaches the handler.\n *\n * @example\n * ```ts\n * // Auth interceptor injects crypto key fields\n * route.post('/_auth/login')\n * .input({\n * body: Type.Object({\n * email: Type.String(),\n * password: Type.String()\n * })\n * })\n * .interceptor({\n * body: Type.Object({\n * publicKey: Type.String(),\n * keyId: Type.String(),\n * fingerprint: Type.String()\n * })\n * })\n * .handler(async (c) => {\n * const { body } = await c.data();\n * // body type: { email, password, publicKey, keyId, fingerprint }\n * // Client only sees: { email, password }\n * return loginService(body);\n * });\n * ```\n */\n interceptor<TNewInterceptor extends RouteInput>(\n interceptor: TNewInterceptor,\n ): RouteBuilder<TInput, TNewInterceptor, TResponse>\n {\n return this.clone({ interceptor });\n }\n\n /**\n * Add middlewares to the route\n *\n * Accepts both regular middleware handlers and named middlewares (NamedMiddleware).\n * Named middlewares that are already registered globally will be automatically\n * deduplicated to prevent double execution.\n *\n * @example\n * ```ts\n * import { authenticate } from '@spfn/auth/server/middleware';\n *\n * // With NamedMiddleware (auto-deduped if registered globally)\n * route.get('/users')\n * .use([authenticate, RateLimitMiddleware()])\n *\n * // With regular middleware handlers\n * route.get('/users')\n * .use([AuthMiddleware(), RateLimitMiddleware()])\n * ```\n */\n middleware(middlewares: (MiddlewareHandler | NamedMiddleware<string>)[]): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.clone({ middlewares });\n }\n\n /**\n * Add middlewares to the route (alias for `.middleware()`)\n *\n * Accepts both regular middleware handlers and named middlewares (NamedMiddleware).\n * Named middlewares that are already registered globally will be automatically\n * deduplicated to prevent double execution.\n *\n * @example\n * ```ts\n * import { authenticate } from '@spfn/auth/server/middleware';\n *\n * // With NamedMiddleware (auto-deduped if registered globally)\n * route.get('/users')\n * .use([authenticate, RateLimitMiddleware()])\n *\n * // With regular middleware handlers\n * route.get('/users')\n * .use([AuthMiddleware(), RateLimitMiddleware()])\n * ```\n */\n use(middlewares: (MiddlewareHandler | NamedMiddleware<string>)[]): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.middleware(middlewares);\n }\n\n /**\n * Skip server-level named middlewares\n *\n * Useful for public endpoints that should bypass auth or rate limiting\n *\n * @param middlewareNames - Array of middleware names to skip, or '*' to skip all\n *\n * @example\n * ```ts\n * // Skip specific middlewares\n * route.get('/status')\n * .skip(['auth', 'rateLimit'])\n * .handler(async (c) => c.json({ status: 'ok' }));\n *\n * // Skip only auth (still apply rate limiting)\n * route.get('/public-data')\n * .skip(['auth'])\n * .handler(async (c) => { ... });\n *\n * // Skip all middlewares\n * route.get('/public-health')\n * .skip('*')\n * .handler(async (c) => c.json({ status: 'ok' }));\n * ```\n */\n skip(middlewareNames: string[] | '*'): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.clone({ skipMiddlewares: middlewareNames });\n }\n\n /**\n * Publish this route as a versioned contract operation\n *\n * Marks the route as a promise to clients that are compiled and deployed\n * separately from the server — a mobile app, an external API consumer.\n * The `@spfn/core:contract` generator writes every contracted route into\n * `contracts/current.json`, and the build refuses a change that would break\n * an already-released client.\n *\n * Routes without `.contract()` are unaffected: they simply do not appear in\n * the contract. A web client needs nothing here — it derives its types from\n * the router in the same build.\n *\n * @example\n * ```ts\n * export const getUser = route.get('/users/:id')\n * .input({ params: Type.Object({ id: Type.String() }) })\n * .contract({\n * since: '1.2.0',\n * auth: 'clientProofV1',\n * requiresSession: true,\n * response: Type.Object({\n * id: Type.String(),\n * name: Type.String(),\n * email: Type.Optional(Type.String()),\n * }),\n * })\n * .handler(async (c) => { ... });\n * ```\n */\n contract(contract: RouteContract): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.clone({ contract });\n }\n\n /**\n * Declare what invoking this route does\n *\n * Read by a command surface (`@spfn/core/surface`, `@spfn/core/ops`),\n * which announces it in its manifest so a machine caller can tell a read\n * from a write before it calls — `spfn ops call` asks for `--yes` before a\n * `destructive` command. A surface built with `defineSurface` refuses an\n * app command that does not declare one; on `/_ops` it is optional.\n *\n * Nothing else reads it: codegen, the route map, and the contract are\n * unaffected, and a route outside any surface simply carries it.\n *\n * @example\n * ```ts\n * export const pageAdd = app.route.post('/pages')\n * .input({ body: PageAddBody })\n * .effect('write')\n * .summary('Add a page to the blueprint')\n * .handler(async (c) => { ... });\n * ```\n */\n effect(effect: RouteEffect): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.clone({ effect });\n }\n\n /**\n * Describe this route in one line for a command surface's manifest\n *\n * A surface announces it beside the command in `spfn ops list` and\n * `--describe`, and refuses one that is empty or longer than 500\n * characters. Codegen, the route map, and the contract ignore it. On a\n * module command the module's own summary wins.\n *\n * @example\n * ```ts\n * export const pageAdd = app.route.post('/pages')\n * .effect('write')\n * .summary('Add a page to the blueprint')\n * .handler(async (c) => { ... });\n * ```\n */\n summary(summary: string): RouteBuilder<TInput, TInterceptor, TResponse>\n {\n return this.clone({ summary });\n }\n\n /**\n * Define handler function\n *\n * Response type is automatically inferred from the return value.\n * Use helper methods like `c.created()`, `c.paginated()` for proper type inference.\n *\n * @example\n * ```ts\n * // Direct return - type inferred from data\n * route.get('/users/:id')\n * .input({ params: Type.Object({ id: Type.String() }) })\n * .handler(async (c) => {\n * const { params } = await c.data();\n * return await getUser(params.id); // Type: User\n * })\n *\n * // Using c.created() - returns data with 201 status, type preserved\n * route.post('/users')\n * .input({ body: Type.Object({ name: Type.String() }) })\n * .handler(async (c) => {\n * const { body } = await c.data();\n * return c.created(await createUser(body)); // Type: User\n * })\n *\n * // Using c.paginated() - returns PaginatedResult<T>\n * route.get('/users')\n * .handler(async (c) => {\n * const users = await getUsers();\n * return c.paginated(users, 1, 20, 100); // Type: PaginatedResult<User>\n * })\n *\n * // Using c.noContent() - returns void\n * route.delete('/users/:id')\n * .handler(async (c) => {\n * await deleteUser(params.id);\n * return c.noContent(); // Type: void\n * })\n *\n * // Using c.json() - returns Response (type inference lost)\n * // Use only when you need custom status codes not covered by helpers\n * route.get('/custom')\n * .handler(async (c) => {\n * return c.json({ data }, 418); // Type: Response\n * })\n * ```\n */\n handler<THandlerResponse>(\n fn: RouteHandlerFn<TInput, TInterceptor, THandlerResponse>,\n ): RouteDef<TInput, TInterceptor, THandlerResponse>\n {\n return {\n method: this._method,\n path: this._path,\n input: this._input,\n interceptor: this._interceptor,\n middlewares: this._middlewares,\n skipMiddlewares: this._skipMiddlewares,\n contract: this._contract,\n ...(this._effect !== undefined ? { effect: this._effect } : {}),\n ...(this._summary !== undefined ? { summary: this._summary } : {}),\n handler: fn,\n _input: {} as TInput,\n _interceptor: {} as TInterceptor,\n _response: {} as THandlerResponse,\n };\n }\n}\n\n/**\n * Create a route definition with HTTP method shortcuts\n */\nfunction createMethodRoute(method: HttpMethod): (path: string) => RouteBuilder\n{\n return (path: string) =>\n {\n const builder = new RouteBuilder();\n builder._method = method;\n builder._path = path;\n\n return builder;\n };\n}\n\n/**\n * Route builder entry point\n *\n * @example\n * ```ts\n * // GET request\n * export const getUser = route.get('/users/:id')\n * .input({ params: Type.Object({ id: Type.String() }) })\n * .handler(async (c) => {\n * const { params } = await c.data();\n * return await db.user.findUnique({ where: { id: params.id } });\n * });\n *\n * // POST request\n * export const createUser = route.post('/users')\n * .input({ body: Type.Object({ name: Type.String(), email: Type.String() }) })\n * .handler(async (c) => {\n * const { body } = await c.data();\n * return c.created(await db.user.create({ data: body }));\n * });\n * ```\n */\nexport const route = {\n get: createMethodRoute('GET'),\n post: createMethodRoute('POST'),\n put: createMethodRoute('PUT'),\n patch: createMethodRoute('PATCH'),\n delete: createMethodRoute('DELETE'),\n};\n","/**\n * Router Definition\n *\n * Provides router composition and middleware management\n */\n\nimport type { NamedMiddleware } from './define-middleware';\nimport type { RouteDef } from './route-builder';\n\n/**\n * Router definition - holds all routes\n */\nexport interface Router<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>> {\n routes: TRoutes;\n _routes: TRoutes;\n _packageRouters: Router<any>[];\n _globalMiddlewares: NamedMiddleware<string>[];\n\n /** The contract version these routes publish, or null when uncontracted. */\n _contractVersion: string | null;\n\n /**\n * Whether a client ever addresses these routes by name.\n *\n * True for an ordinary router. A mounted package router that is true here\n * has its routes written into the app's generated route map, which is what\n * lets the package's own client (`authApi.login`) resolve a name through the\n * app's RPC proxy. It is also what makes an app route sharing a name with a\n * package route a defect worth refusing a build over: the map holds one\n * entry per name, so one of the two paths would become unreachable while the\n * generated types still describe the app's route.\n *\n * False says no client names these routes: they are reached by URL, by\n * something that was handed the URL, so nothing of them belongs in the map\n * and a name they share with an app route is only a shared name.\n * `createOpsRouter` sets it — `spfn ops` invokes an ops command over the URL\n * the manifest gave it.\n */\n _publishesRouteMap: boolean;\n\n /**\n * The namespace of the command surface that built this router, absent on\n * any other. Set by `defineSurface` (and so by `createOpsRouter`) as a\n * non-enumerable property, so `.packages()` can refuse two surfaces on one\n * namespace.\n */\n readonly _surfaceNamespace?: string;\n\n /**\n * The manifest of the states that built this router — each state's key\n * fields and whether it has a write, in declaration order — absent on any\n * other. Set by `defineStateRouter` on the router it derives as a\n * non-enumerable property; it is the object the snapshot route answers as\n * `manifest`, and what `@spfn/core:states` reads to write the app's declared\n * state ids. Written structurally so the route module does not import state.\n */\n readonly _stateManifest?: Readonly<Record<string, { readonly key: readonly string[]; readonly write: boolean }>>;\n\n /**\n * Register package routers (type-hidden)\n *\n * Package routes are:\n * - Recognized by RPC proxy and backend\n * - NOT exposed in client types (use package's own API like authApi, cmsApi)\n *\n * @example\n * ```ts\n * import { authRouter } from '@spfn/auth/server';\n * import { cmsAppRouter } from '@spfn/cms/server';\n *\n * export const appRouter = defineRouter({\n * getRoot,\n * getStatus,\n * })\n * .packages([authRouter, cmsAppRouter]);\n *\n * // Client usage:\n * // api.getRoot.call({}) - app routes\n * // authApi.login.call({}) - package API\n * ```\n */\n packages(routers: Router<any>[]): Router<TRoutes>;\n\n /**\n * Register global middlewares\n *\n * Applied to all routes unless explicitly skipped via .skip()\n *\n * @example\n * ```ts\n * import { authMiddleware, loggingMiddleware } from './middlewares';\n *\n * export const appRouter = defineRouter({\n * getRoot,\n * getStatus,\n * })\n * .packages([authRouter])\n * .use([authMiddleware, loggingMiddleware]);\n * ```\n */\n use(middlewares: NamedMiddleware<string>[]): Router<TRoutes>;\n\n /**\n * Declare the contract version these routes publish.\n *\n * A client compiled against this server — a mobile app in a store — is\n * generated from one version of the contract and cannot be updated when the\n * server changes. The server announces this version on every response so\n * that client can tell whether the two ends still agree.\n *\n * This is the version's source. A released snapshot is written to\n * `contracts/released/<version>.json` from what is declared here, so the\n * filename follows the code rather than the code having to be told what the\n * filename said.\n *\n * Only a server with contracted routes needs it. Without it the contract\n * generator still writes `current.json` and still runs the compatibility\n * gate; what it cannot do is cut a release or announce a version.\n *\n * @example\n * ```ts\n * export const appRouter = defineRouter({ getRoot, listItems })\n * .contractVersion('1.2.0')\n * .packages([authRouter]);\n * ```\n */\n contractVersion(version: string): Router<TRoutes>;\n}\n\n/**\n * Everything a router carries, so that a chainable method rebuilding the router\n * states what it changes and cannot silently drop what it does not.\n */\ninterface RouterState<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>\n{\n routes: TRoutes;\n packageRouters: Router<any>[];\n globalMiddlewares: NamedMiddleware<string>[];\n contractVersion: string | null;\n publishesRouteMap: boolean;\n}\n\n/**\n * Create a Router instance with chainable methods\n */\nfunction createRouterInstance<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(\n state: RouterState<TRoutes>,\n): Router<TRoutes>\n{\n const router: Router<TRoutes> = {\n routes: state.routes,\n _routes: state.routes,\n _packageRouters: state.packageRouters,\n _globalMiddlewares: state.globalMiddlewares,\n _contractVersion: state.contractVersion,\n _publishesRouteMap: state.publishesRouteMap,\n\n packages(routers: Router<any>[]): Router<TRoutes>\n {\n const newPackageRouters = [...state.packageRouters, ...routers];\n\n // Also include nested package routers if any\n for (const pkgRouter of routers)\n {\n if (pkgRouter._packageRouters?.length > 0)\n {\n newPackageRouters.push(...pkgRouter._packageRouters);\n }\n }\n\n assertDistinctSurfaces(newPackageRouters);\n\n return carryMarkers(router, createRouterInstance({ ...state, packageRouters: newPackageRouters }));\n },\n\n use(middlewares: NamedMiddleware<string>[]): Router<TRoutes>\n {\n return carryMarkers(router, createRouterInstance({\n ...state,\n globalMiddlewares: [...state.globalMiddlewares, ...middlewares],\n }));\n },\n\n contractVersion(version: string): Router<TRoutes>\n {\n assertContractVersion(version);\n\n return carryMarkers(router, createRouterInstance({ ...state, contractVersion: version }));\n },\n };\n\n return router;\n}\n\n/** The non-enumerable markers a factory sets after `createRouterInstance`, which `RouterState` does not hold. */\nconst MARKERS = ['_surfaceNamespace', '_stateManifest'] as const;\n\n/**\n * Copy the markers of a router onto the one a chainable method rebuilt from it.\n *\n * `defineSurface` and `defineStateRouter` set theirs on the router they return,\n * so the state a rebuild starts from has never seen them: without this,\n * `states.router.use([...])` would mount a router `@spfn/core:states` cannot\n * find, and a surface's `.use()` would slip past the one-surface-per-namespace\n * refusal. They stay non-enumerable, as their factories set them.\n */\nfunction carryMarkers<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(\n from: Router<TRoutes>,\n to: Router<TRoutes>,\n): Router<TRoutes>\n{\n for (const marker of MARKERS)\n {\n if (from[marker] !== undefined)\n {\n Object.defineProperty(to, marker, { value: from[marker], enumerable: false });\n }\n }\n\n return to;\n}\n\n/**\n * A version that cannot be ordered cannot gate a release.\n *\n * Checked when it is declared rather than when a snapshot is cut: the failure\n * belongs next to the typo, not in a build step that runs much later.\n */\nfunction assertContractVersion(version: string): void\n{\n if (!/^\\d+\\.\\d+\\.\\d+(?:[-+][0-9A-Za-z.-]+)*$/.test(version))\n {\n throw new Error(\n `contractVersion(\"${version}\") is not a version of the form major.minor.patch. `\n + 'The released snapshot is named from this value and releases are compared by it.',\n );\n }\n}\n\n/**\n * Two command surfaces on one namespace both serve `<namespace>/_manifest`.\n * The first registered answers it, so the second surface's commands stay\n * live behind their own auth while no manifest lists them.\n *\n * Checked when the routers are mounted: that is the first point that sees\n * both, and the failure belongs where the app put them side by side.\n */\nfunction assertDistinctSurfaces(packageRouters: readonly Router<any>[]): void\n{\n const namespaces = new Set<string>();\n\n for (const router of packageRouters)\n {\n const namespace = router._surfaceNamespace;\n if (namespace === undefined)\n {\n continue;\n }\n\n if (namespaces.has(namespace))\n {\n throw new Error(\n `.packages() mounts two command surfaces on \"${namespace}\". `\n + `Both serve ${namespace}/_manifest, so the second one's commands would answer `\n + 'while no manifest lists them. Mount one router per namespace.',\n );\n }\n namespaces.add(namespace);\n }\n}\n\n/**\n * Define a router with multiple routes (tRPC-style)\n *\n * Supports chainable API for packages and middlewares:\n *\n * @example\n * ```ts\n * // Basic usage\n * export const appRouter = defineRouter({\n * getRoot,\n * getStatus,\n * listExamples,\n * });\n *\n * // With package routers (type-hidden)\n * export const appRouter = defineRouter({\n * getRoot,\n * getStatus,\n * })\n * .packages([authRouter, cmsAppRouter]);\n *\n * // With global middlewares\n * export const appRouter = defineRouter({\n * getRoot,\n * getStatus,\n * })\n * .packages([authRouter])\n * .use([authMiddleware, loggingMiddleware]);\n *\n * export type AppRouter = typeof appRouter;\n * ```\n *\n * Package routes:\n * - Recognized by RPC proxy and backend for routing\n * - NOT included in AppRouter type (use authApi, cmsApi instead)\n * - Prevents confusion between app API and package APIs\n */\nexport function defineRouter<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(\n routes: TRoutes,\n): Router<TRoutes>\n{\n return createRouterInstance({\n routes,\n packageRouters: [],\n globalMiddlewares: [],\n contractVersion: null,\n publishesRouteMap: true,\n });\n}\n\n/**\n * A router no client addresses by name.\n *\n * The app's generated route map carries the routes of every package router the\n * app mounts with `.packages()`, so that a package client calling its own route\n * by name resolves through the app's RPC proxy. A router built here is left out\n * of that map: its routes are reached by URL, by a tool that was told the URL,\n * so no name of theirs has to resolve anywhere and a name shared with an app\n * route is only a shared name.\n *\n * Declared by the package that ships the router, because only it knows whether\n * any client names these routes: `createOpsRouter` and the tracking routes of\n * `@spfn/notification` do it, and any package whose surface is reached by URL\n * may. The obligation is the whole of it — a package whose client *does* name\n * its routes must use `defineRouter`, or those names land in nobody's map and\n * resolve nowhere (and a collision that really would take an app route's entry\n * generates silently). `defineRouter` is the default for exactly that reason: a\n * package that says nothing is carried and checked.\n */\nexport function defineUnmappedRouter<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(\n routes: TRoutes,\n): Router<TRoutes>\n{\n return createRouterInstance({\n routes,\n packageRouters: [],\n globalMiddlewares: [],\n contractVersion: null,\n publishesRouteMap: false,\n });\n}\n","/**\n * Thrown when a namespace, route, or module cannot be part of a command\n * surface. `@spfn/core/ops` exports the same class as `OpsRouterError`.\n */\nexport class SurfaceError extends Error\n{\n constructor(message: string)\n {\n super(message);\n this.name = 'SurfaceError';\n }\n}\n","/**\n * How refusals name the surface they come from.\n *\n * A command surface is generic, but the ops surface predates it and its\n * refusals already say \"ops route\" and point at `opsRoute`. The ops layer\n * passes its own wording so an operator reading an ops refusal sees the same\n * text as before; every other surface reads the neutral one.\n */\nexport interface SurfaceWording\n{\n /** What a route on this surface is called: \"ops route\", \"surface route\". */\n noun: string;\n\n /** The builder that applies the namespace, as named in a refusal. */\n builder: string;\n\n /** The function that builds the surface, as named in a refusal. */\n factory: string;\n}\n\nexport const SURFACE_WORDING: SurfaceWording = {\n noun: 'surface',\n builder: '`<surface>.route`',\n factory: 'defineSurface',\n};\n\n/** The noun at the start of a sentence. */\nexport function capitalized(noun: string): string\n{\n return noun.charAt(0).toUpperCase() + noun.slice(1);\n}\n","/**\n * Surface Manifest\n *\n * The server's self-description of a command surface: every command an app\n * exposes under the surface's namespace, with each command's input schemas as\n * plain JSON Schema. A client fetches this from the running server, so command\n * discovery needs neither the app's source nor a generated artifact on the\n * caller's machine.\n *\n * The router is loaded and walked (the contract collector's approach) rather\n * than parsed from source: route schemas built from imported values resolve,\n * and TypeBox schemas serialize to JSON Schema by construction.\n */\n\nimport type { JsonSchema } from '../contract/types';\nimport type { RouteDef } from '../route/route-builder';\nimport type { RouteInput } from '../route/route-input';\nimport type { Router } from '../route/router';\nimport type { HttpMethod } from '../route/types';\nimport { SurfaceError } from './error';\nimport type { SurfaceEffect } from './module';\nimport { SURFACE_WORDING, type SurfaceWording } from './wording';\n\n/** One explicitly mounted capability module, as a client sees it. */\nexport interface SurfaceModuleDescriptor\n{\n id: string;\n source: string;\n contractVersion: string;\n summary: string;\n}\n\n/** One invokable command, as a client sees it. */\nexport interface SurfaceCommand\n{\n name: string;\n method: HttpMethod;\n path: string;\n\n /** Present for commands contributed by an explicitly mounted module. */\n module?: string;\n\n /**\n * A module command's from its declaration; an app command's from the\n * route's `.summary()` and `.effect()`, present only when declared.\n */\n summary?: string;\n effect?: SurfaceEffect;\n\n /** Present for module commands only. */\n scopes?: string[];\n\n /** Input sections the route declares, each as JSON Schema. */\n input: {\n params?: JsonSchema;\n query?: JsonSchema;\n body?: JsonSchema;\n };\n}\n\n/** What `GET <namespace>/_manifest` answers. */\nexport interface SurfaceManifest\n{\n manifestVersion: 1;\n /** Additive module metadata. Omitted for an app-only v1 surface. */\n modules?: SurfaceModuleDescriptor[];\n commands: SurfaceCommand[];\n}\n\nfunction isRouter(value: unknown): value is Router<any>\n{\n return value !== null\n && typeof value === 'object'\n && 'routes' in value\n && '_routes' in value;\n}\n\nfunction isRouteDef(value: unknown): value is RouteDef<any>\n{\n return value !== null\n && typeof value === 'object'\n && 'handler' in value;\n}\n\n/**\n * Strip TypeBox's symbol-keyed metadata and hand back plain JSON — the same\n * round trip the contract collector uses.\n */\nfunction toJsonSchema(schema: unknown): JsonSchema\n{\n return JSON.parse(JSON.stringify(schema)) as JsonSchema;\n}\n\nconst INPUT_SECTIONS = ['params', 'query', 'body'] as const;\n\nfunction toCommandInput(input: RouteInput | undefined): SurfaceCommand['input']\n{\n const sections: SurfaceCommand['input'] = {};\n\n if (!input)\n {\n return sections;\n }\n\n for (const section of INPUT_SECTIONS)\n {\n const schema = input[section];\n if (schema)\n {\n sections[section] = toJsonSchema(schema);\n }\n }\n\n return sections;\n}\n\n/**\n * Walk a routes record (nested routers included) and collect every RouteDef\n * as a command, with the summary and effect its route declared. Validation of\n * paths and of that metadata happens in the surface's `router()`, so nothing\n * here is checked but the uniqueness of names.\n */\nexport function collectSurfaceCommands(\n routes: Record<string, RouteDef<any> | Router<any>>,\n wording: SurfaceWording = SURFACE_WORDING,\n): SurfaceCommand[]\n{\n const commands: SurfaceCommand[] = [];\n visit(routes, commands, new Map<string, string>(), wording);\n commands.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n\n return commands;\n}\n\nfunction visit(\n routes: Record<string, RouteDef<any> | Router<any>>,\n commands: SurfaceCommand[],\n claimed: Map<string, string>,\n wording: SurfaceWording,\n): void\n{\n for (const [name, entry] of Object.entries(routes))\n {\n if (isRouter(entry))\n {\n visit(entry.routes, commands, claimed, wording);\n continue;\n }\n\n if (!isRouteDef(entry) || !entry.method || !entry.path)\n {\n continue;\n }\n\n assertUnclaimedName(name, entry.path, claimed, wording);\n\n commands.push({\n name,\n method: entry.method,\n path: entry.path,\n ...(entry.summary !== undefined ? { summary: entry.summary } : {}),\n ...(entry.effect !== undefined ? { effect: entry.effect } : {}),\n input: toCommandInput(entry.input as RouteInput | undefined),\n });\n }\n}\n\n/**\n * Nested routers flatten into one command list, so two routes keyed alike in\n * different routers would both be announced under the same command name. The\n * client resolves a name to the first match, which means a caller asking for\n * one command silently invokes the other — refuse it at definition time.\n */\nfunction assertUnclaimedName(\n name: string,\n path: string,\n claimed: Map<string, string>,\n wording: SurfaceWording,\n): void\n{\n const existing = claimed.get(name);\n if (existing !== undefined)\n {\n throw new SurfaceError(\n `Two ${wording.noun} routes are named \"${name}\" (\"${existing}\" and \"${path}\"). `\n + 'Command names are flattened across nested routers, so each must be unique '\n + 'for a client to resolve the one its caller asked for.',\n );\n }\n\n claimed.set(name, path);\n}\n","interface RouteSegment\n{\n kind: 'static' | 'parameter' | 'wildcard';\n value: string;\n optional: boolean;\n}\n\nfunction routeSegments(path: string): RouteSegment[]\n{\n return path.split('/').slice(1).map((raw): RouteSegment =>\n {\n if (raw === '*' || raw.endsWith('*'))\n {\n return { kind: 'wildcard', value: raw, optional: true };\n }\n if (raw.startsWith(':'))\n {\n return {\n kind: 'parameter',\n value: raw.slice(1).replace(/\\?$/, ''),\n optional: raw.endsWith('?'),\n };\n }\n\n return { kind: 'static', value: raw, optional: false };\n });\n}\n\nfunction customPattern(parameter: string): string | null\n{\n const openingBrace = parameter.indexOf('{');\n\n return openingBrace >= 0 && parameter.endsWith('}')\n ? parameter.slice(openingBrace + 1, -1)\n : null;\n}\n\nfunction parameterAccepts(parameter: string, value: string): boolean\n{\n const pattern = customPattern(parameter);\n if (pattern === null)\n {\n return value.length > 0 && !value.includes('/');\n }\n\n try\n {\n return new RegExp(`^(?:${pattern})$`).test(value);\n }\n catch\n {\n // Hono will reject an invalid pattern when registering it. Treat it as\n // overlapping here so it cannot bypass the scope check first.\n return true;\n }\n}\n\nfunction remainingStaticPath(segments: RouteSegment[], from: number): string | null\n{\n const remaining = segments.slice(from);\n\n return remaining.every(segment => segment.kind === 'static')\n ? remaining.map(segment => segment.value).join('/')\n : null;\n}\n\n/**\n * Whether two Hono route patterns can claim at least one common URL.\n *\n * Custom-regex intersection is deliberately conservative. If disjointness\n * cannot be established from static material, composition is refused: scope\n * middleware must never depend on registration order.\n */\nexport function routePatternsOverlap(firstPath: string, secondPath: string): boolean\n{\n const first = routeSegments(firstPath);\n const second = routeSegments(secondPath);\n const length = Math.max(first.length, second.length);\n\n for (let index = 0; index < length; index++)\n {\n const left = first[index];\n const right = second[index];\n\n if (!left || !right)\n {\n const remaining = left ? first.slice(index) : second.slice(index);\n\n return remaining.every(segment => segment.optional || segment.kind === 'wildcard');\n }\n if (left.kind === 'wildcard' || right.kind === 'wildcard')\n {\n return true;\n }\n if (left.kind === 'static' && right.kind === 'static')\n {\n if (left.value !== right.value)\n {\n return false;\n }\n continue;\n }\n if (left.kind === 'parameter' && right.kind === 'static')\n {\n const remaining = remainingStaticPath(second, index);\n if (customPattern(left.value) !== null && remaining !== null\n && parameterAccepts(left.value, remaining))\n {\n return true;\n }\n if (!parameterAccepts(left.value, right.value))\n {\n return customPattern(left.value) !== null && remaining === null;\n }\n if (customPattern(left.value) !== null && first.length !== second.length)\n {\n return true;\n }\n continue;\n }\n if (left.kind === 'static' && right.kind === 'parameter')\n {\n const remaining = remainingStaticPath(first, index);\n if (customPattern(right.value) !== null && remaining !== null\n && parameterAccepts(right.value, remaining))\n {\n return true;\n }\n if (!parameterAccepts(right.value, left.value))\n {\n return customPattern(right.value) !== null && remaining === null;\n }\n if (customPattern(right.value) !== null && first.length !== second.length)\n {\n return true;\n }\n continue;\n }\n\n // Two parameters both admit some non-empty segment. Custom regexes\n // may also consume separators, which only strengthens the overlap.\n return true;\n }\n\n return true;\n}\n","/**\n * Capability module contract\n *\n * A package describes commands here, but an adopter application decides\n * whether to mount the resulting module, and on which surface. Validation\n * keeps an installed package from becoming a command surface merely by\n * existing, and gives the surface enough metadata to enforce scopes and\n * describe the module to a client from one declaration.\n *\n * A module's paths are written for one namespace — `/_ops/<id>/...` for an\n * ops module — so it is validated against the namespace of the surface that\n * mounts it. A module written for `/_ops` mounted on `/_app` is refused rather\n * than registered at paths outside the surface that is supposed to guard them.\n */\n\nimport type { RouteDef } from '../route/route-builder';\nimport type { RouteEffect } from '../route/types';\nimport { SurfaceError } from './error';\nimport { routePatternsOverlap } from './route-overlap';\nimport { capitalized, SURFACE_WORDING, type SurfaceWording } from './wording';\n\n/** One vocabulary for module commands and an app's own: the route's `.effect()`. */\nexport type SurfaceEffect = RouteEffect;\n\nexport interface SurfaceModuleCommand<TRoute extends RouteDef<any> = RouteDef<any>>\n{\n summary: string;\n effect: SurfaceEffect;\n scopes: readonly string[];\n route: TRoute;\n}\n\nexport interface SurfaceModule<\n TCommands extends Record<string, SurfaceModuleCommand<any>> = Record<string, SurfaceModuleCommand<any>>,\n>\n{\n id: string;\n source: string;\n contractVersion: string;\n summary: string;\n commands: TCommands;\n}\n\nconst MODULE_ID = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\nconst COMMAND_NAME = /^[A-Za-z][A-Za-z0-9]*(?:\\.[A-Za-z][A-Za-z0-9]*)*$/;\nconst CONTRACT_VERSION = /^\\d+\\.\\d+\\.\\d+(?:[-+][0-9A-Za-z.-]+)*$/;\nconst EFFECTS = new Set<SurfaceEffect>(['read', 'write', 'destructive']);\nconst PATH_BASE = 'https://spfn.invalid';\n\n/** Whether `value` is one of the effects a command can declare. */\nexport function isSurfaceEffect(value: unknown): value is SurfaceEffect\n{\n return EFFECTS.has(value as SurfaceEffect);\n}\n\nfunction assertText(label: string, value: unknown): asserts value is string\n{\n if (typeof value !== 'string' || value.trim().length === 0)\n {\n throw new SurfaceError(`${label} must be a non-empty string.`);\n }\n}\n\n/** Where a module is being mounted, and what its refusals call it. */\ninterface MountPoint\n{\n namespace: string;\n label: string;\n}\n\nfunction assertStableModulePath(at: MountPoint, moduleId: string, commandName: string, path: string): void\n{\n const label = `${at.label} command \"${moduleId}.${commandName}\" path \"${path}\"`;\n // Hono path patterns use braces for regex parameters and a trailing `?`\n // for optional ones. Escape those route-language characters before asking\n // WHATWG URL normalization whether the transport-level path moves.\n const transportPath = path.replace(/[{}?#]/g, character =>\n `%${character.charCodeAt(0).toString(16).toUpperCase()}`);\n let url: URL;\n try\n {\n url = new URL(transportPath, PATH_BASE);\n }\n catch\n {\n throw new SurfaceError(`${label} is not a valid URL path.`);\n }\n\n if (url.origin !== PATH_BASE || url.search !== '' || url.hash !== '' || url.pathname !== transportPath)\n {\n throw new SurfaceError(`${label} is not a stable plain absolute path.`);\n }\n\n const slashCount = (path.match(/\\//g) ?? []).length;\n let decoded = path;\n for (let depth = 0; depth < 8; depth++)\n {\n let next: string;\n try\n {\n next = decodeURIComponent(decoded);\n }\n catch\n {\n throw new SurfaceError(`${label} contains malformed percent encoding.`);\n }\n\n if (next.includes('\\\\') || (next.match(/\\//g) ?? []).length !== slashCount\n || next.split('/').some(segment => segment === '.' || segment === '..'))\n {\n throw new SurfaceError(`${label} contains encoded path separators or dot segments.`);\n }\n if (next === decoded)\n {\n return;\n }\n decoded = next;\n }\n\n throw new SurfaceError(`${label} uses too many percent-encoding layers.`);\n}\n\nfunction assertCliCallableModulePath(at: MountPoint, moduleId: string, commandName: string, path: string): void\n{\n const unsupported = path.split('/').slice(1).find(segment =>\n segment === '*'\n || segment.includes('*')\n || (segment.startsWith(':')\n ? !/^:[A-Za-z0-9_]+$/.test(segment)\n : !/^[A-Za-z0-9._~-]+$/.test(segment)));\n\n if (unsupported !== undefined)\n {\n throw new SurfaceError(\n `${at.label} command \"${moduleId}.${commandName}\" path segment \"${unsupported}\" is not CLI-callable. `\n + 'Module routes support URL-safe static segments and simple :name parameters only; '\n + 'optional, wildcard, and custom-regex parameters are not supported.',\n );\n }\n}\n\nfunction assertCommand(at: MountPoint, moduleId: string, name: string, command: SurfaceModuleCommand<any>): void\n{\n if (!COMMAND_NAME.test(name))\n {\n throw new SurfaceError(\n `${at.label} module \"${moduleId}\" has invalid command name \"${name}\". `\n + 'Use dot-separated alphanumeric names.',\n );\n }\n\n assertText(`${at.label} command \"${moduleId}.${name}\" summary`, command?.summary);\n\n if (!EFFECTS.has(command?.effect))\n {\n throw new SurfaceError(\n `${at.label} command \"${moduleId}.${name}\" has invalid effect ${JSON.stringify(command?.effect)}.`,\n );\n }\n\n if (!Array.isArray(command?.scopes) || command.scopes.length === 0\n || command.scopes.some(scope => typeof scope !== 'string' || scope.trim().length === 0))\n {\n throw new SurfaceError(`${at.label} command \"${moduleId}.${name}\" must declare at least one non-empty scope.`);\n }\n\n const route = command?.route;\n if (!route || typeof route.handler !== 'function' || !route.method || !route.path)\n {\n throw new SurfaceError(`${at.label} command \"${moduleId}.${name}\" must carry a complete route.`);\n }\n\n assertStableModulePath(at, moduleId, name, route.path);\n assertCliCallableModulePath(at, moduleId, name, route.path);\n\n const modulePath = `${at.namespace}/${moduleId}/`;\n if (!route.path.startsWith(modulePath))\n {\n throw new SurfaceError(\n `${at.label} command \"${moduleId}.${name}\" is at \"${route.path}\", outside \"${modulePath}\". `\n + `A module mounted on \"${at.namespace}\" keeps every command under \"${modulePath}\".`,\n );\n }\n if (route.path.split('/').includes('..'))\n {\n throw new SurfaceError(`${at.label} command \"${moduleId}.${name}\" path climbs out of its module namespace.`);\n }\n}\n\n/**\n * Validate a capability module against the namespace it is mounted on.\n *\n * This function intentionally does not register anything. Only an adopter's\n * explicit `modules: [...]` composition exposes the module, and the surface\n * calls this for each one when its router is built.\n */\nexport function validateSurfaceModule<\n TCommands extends Record<string, SurfaceModuleCommand<any>>,\n>(\n module: SurfaceModule<TCommands>,\n namespace: string,\n wording: SurfaceWording = SURFACE_WORDING,\n): SurfaceModule<TCommands>\n{\n const at: MountPoint = { namespace, label: capitalized(wording.noun) };\n\n if (!MODULE_ID.test(module?.id ?? ''))\n {\n throw new SurfaceError(\n `${at.label} module id ${JSON.stringify(module?.id)} is invalid. Use lower-kebab-case.`,\n );\n }\n\n assertText(`${at.label} module \"${module.id}\" source`, module.source);\n assertText(`${at.label} module \"${module.id}\" summary`, module.summary);\n\n if (!CONTRACT_VERSION.test(module.contractVersion))\n {\n throw new SurfaceError(\n `${at.label} module \"${module.id}\" contractVersion must be a semantic version.`,\n );\n }\n\n if (!module.commands || typeof module.commands !== 'object' || Array.isArray(module.commands))\n {\n throw new SurfaceError(`${at.label} module \"${module.id}\" commands must be an object.`);\n }\n\n const signatures = new Map<string, string>();\n const claimedRoutes: Array<{ name: string; method: string; path: string }> = [];\n for (const [name, command] of Object.entries(module.commands))\n {\n assertCommand(at, module.id, name, command);\n\n const signature = `${command.route.method} ${command.route.path}`;\n const existing = signatures.get(signature);\n if (existing)\n {\n throw new SurfaceError(\n `${at.label} module \"${module.id}\" commands \"${existing}\" and \"${name}\" both use ${signature}.`,\n );\n }\n signatures.set(signature, name);\n\n const overlapping = claimedRoutes.find(claim =>\n claim.method === command.route.method\n && routePatternsOverlap(claim.path, command.route.path!));\n if (overlapping)\n {\n throw new SurfaceError(\n `${at.label} module \"${module.id}\" commands \"${overlapping.name}\" and \"${name}\" `\n + `have overlapping ${command.route.method} routes `\n + `(\"${overlapping.path}\" and \"${command.route.path}\").`,\n );\n }\n claimedRoutes.push({\n name,\n method: command.route.method!,\n path: command.route.path!,\n });\n }\n\n return module;\n}\n\n/**\n * Validate and return a capability module written for a surface on\n * `namespace` — every command under `<namespace>/<id>/`. The surface checks\n * it again against its own namespace when it mounts it, so a module defined\n * for one namespace and mounted on another is still refused.\n */\nexport function defineSurfaceModule<\n TCommands extends Record<string, SurfaceModuleCommand<any>>,\n>(module: SurfaceModule<TCommands>, namespace: string): SurfaceModule<TCommands>\n{\n return validateSurfaceModule(module, namespace);\n}\n","/**\n * Surface namespace and route builder\n *\n * A namespace is the path every command on a surface lives under — `/_ops`\n * for operators, `/_app` or anything else an app chooses for another caller.\n * It is refused at definition time unless it is a plain absolute path of\n * URL-safe segments: no trailing slash, no dots, no percent signs, no\n * parameters. Every check downstream — the prefix a route must carry, the\n * module paths, the manifest URL, the CLI's own path checks — is a string\n * comparison against it, and only a literal path keeps those comparisons\n * honest.\n *\n * The route builder is `route` with the namespace applied, so a definition\n * carries only the part of the path the app owns:\n *\n * ```ts\n * const pageAdd = app.route.post('/pages') // POST /_app/pages\n * .handler(async () => ({ ok: true }));\n * ```\n */\n\nimport { route, type RouteBuilder } from '../route/route-builder';\nimport { SurfaceError } from './error';\nimport { capitalized, type SurfaceWording } from './wording';\n\nconst NAMESPACE = /^(?:\\/[A-Za-z0-9_-]+)+$/;\n\n/** `route`, with a surface's namespace applied. */\nexport interface SurfaceRouteBuilder\n{\n get: (path: string) => RouteBuilder;\n post: (path: string) => RouteBuilder;\n put: (path: string) => RouteBuilder;\n patch: (path: string) => RouteBuilder;\n delete: (path: string) => RouteBuilder;\n}\n\nexport function assertNamespace(namespace: string): void\n{\n if (typeof namespace !== 'string' || !NAMESPACE.test(namespace))\n {\n throw new SurfaceError(\n `Surface namespace ${JSON.stringify(namespace)} is invalid. `\n + 'Use an absolute path of [A-Za-z0-9_-] segments without a trailing slash, such as \"/_app\".',\n );\n }\n}\n\n/** Where a surface serves its manifest. */\nexport function manifestPathOf(namespace: string): string\n{\n return `${namespace}/_manifest`;\n}\n\n/**\n * The reserved route name of a surface's manifest: `get`, the namespace\n * encoded, `Manifest`. `/_ops` → `getOpsManifest`, `/_app` → `getAppManifest`.\n *\n * The encoding is one-to-one, so two surfaces mounted side by side never\n * register two routes under one name. The leading `/` is dropped, and then:\n *\n * - a lowercase letter or a digit stays as it is;\n * - `_` followed by a lowercase letter becomes that letter in uppercase\n * (`_app` → `App`), which keeps the common namespaces readable;\n * - every other character is escaped with `_`: an uppercase letter `X` →\n * `_X`, any other `_` → `__`, `-` → `_d`, `/` → `_s`.\n *\n * A `_` in the output therefore always opens a two-character escape, and an\n * uppercase letter outside one always stands for `_` and a lowercase letter. Read left\n * to right, every name decodes to exactly one namespace: `/app` →\n * `getappManifest`, `/Ops` → `get_OpsManifest`, `/a/b` → `geta_sbManifest`,\n * `/a_b` → `getaBManifest`, `/a-b` → `geta_dbManifest`.\n */\nexport function manifestNameOf(namespace: string): string\n{\n return `get${namespace.slice(1).replace(/_[a-z]|[A-Z_/-]/g, encodedCharacter)}Manifest`;\n}\n\nconst ESCAPES: Record<string, string> = { '_': '_', '-': 'd', '/': 's' };\n\nfunction encodedCharacter(match: string): string\n{\n if (match.length === 2)\n {\n return match.charAt(1).toUpperCase();\n }\n\n return `_${ESCAPES[match] ?? match}`;\n}\n\nfunction toSurfacePath(namespace: string, path: string, wording: SurfaceWording): string\n{\n const label = capitalized(wording.noun);\n\n if (!path.startsWith('/'))\n {\n throw new SurfaceError(\n `${label} route path \"${path}\" must start with \"/\". It is appended to \"${namespace}\", `\n + `so \"${path}\" would read as \"${namespace}${path}\".`,\n );\n }\n\n if (path === '/')\n {\n throw new SurfaceError(\n `${label} route path \"/\" names no command — \"${namespace}\" itself is not a command.`,\n );\n }\n\n return namespace + path;\n}\n\nexport function surfaceRouteBuilder(namespace: string, wording: SurfaceWording): SurfaceRouteBuilder\n{\n const method = (name: keyof SurfaceRouteBuilder) =>\n (path: string) => route[name](toSurfacePath(namespace, path, wording));\n\n return {\n get: method('get'),\n post: method('post'),\n put: method('put'),\n patch: method('patch'),\n delete: method('delete'),\n };\n}\n","/**\n * Command Surface\n *\n * A namespace of commands an app exposes to a caller that is not its own\n * frontend — operators on `/_ops`, an issuer's signed tokens on `/_app`, any\n * other machine caller on a namespace the app picks. An app develops the\n * commands as ordinary routes; `defineSurface` turns them into a mountable\n * package router that:\n *\n * - requires every route to carry the surface's namespace, applied by the\n * surface's own `route`, so a command is recognizable by its path and can\n * never shadow an app route;\n * - injects the given auth middleware into every command, so a command\n * reachable without authentication cannot be created by accident — there is\n * no opt-out;\n * - serves `GET <namespace>/_manifest`, the self-description a client\n * discovers commands from, registered first so no command takes its URL.\n * The manifest is the one route that may be public, and only when the\n * surface says so: its commands stay behind auth regardless.\n *\n * What the path looks like after the namespace is the app's business, decided\n * when the route is written — this factory does not audit its shape.\n *\n * The auth middleware lives with the app's auth stack (`@spfn/auth` ships\n * `opsTokenAuth` and `signedTokenAuth`); core owns only the structure, so a\n * surface has no opinion about how a credential is stored or verified.\n * `@spfn/core/ops` is this factory fixed to `/_ops`.\n *\n * @example\n * ```ts\n * import { defineSurface } from '@spfn/core/surface';\n * import { signedTokenAuth } from '@spfn/auth/server';\n *\n * export const app = defineSurface({\n * namespace: '/_app',\n * auth: signedTokenAuth({ keysUrl, iss, aud }),\n * manifest: 'public',\n * });\n *\n * export const pageAdd = app.route.post('/pages') // POST /_app/pages\n * .input({ body: PageAddBody })\n * .handler(async (c) => pagesRepository.add((await c.data()).body));\n *\n * // mounted like any package router, beside `/_ops`:\n * export const appRouter = defineRouter({ ... }).packages([app.router({ pageAdd }), opsRouter]);\n * ```\n */\n\nimport type { MiddlewareHandler } from 'hono';\nimport type { NamedMiddleware } from '../route/define-middleware';\nimport { route, type RouteDef } from '../route/route-builder';\nimport { defineUnmappedRouter, type Router } from '../route/router';\nimport { SurfaceError } from './error';\nimport {\n collectSurfaceCommands,\n type SurfaceCommand,\n type SurfaceManifest,\n type SurfaceModuleDescriptor,\n} from './manifest';\nimport { isSurfaceEffect, validateSurfaceModule, type SurfaceModule, type SurfaceModuleCommand } from './module';\nimport {\n assertNamespace,\n manifestNameOf,\n manifestPathOf,\n surfaceRouteBuilder,\n type SurfaceRouteBuilder,\n} from './namespace';\nimport { routePatternsOverlap } from './route-overlap';\nimport { capitalized, SURFACE_WORDING, type SurfaceWording } from './wording';\n\ntype SurfaceMiddleware = NamedMiddleware<string> | MiddlewareHandler;\n\n/**\n * Build the guard for one command, or `undefined` for none. Called once per\n * command when the router is built; the guard runs after `auth` and before the\n * command's own middlewares.\n *\n * The command is the manifest entry, so its `effect` is there to read — a\n * guard can be stricter for a `destructive` command than for a `read`.\n */\nexport type SurfaceAuthorize = (command: SurfaceCommand) => SurfaceMiddleware | undefined;\n\nexport interface SurfaceOptions\n{\n /** Every command lives under it, e.g. `/_app`. Must be a plain absolute path. */\n namespace: string;\n\n /**\n * The middleware that authenticates every command. Required — a surface\n * without authentication is refused at definition time, not discovered in\n * production.\n */\n auth: NamedMiddleware<string>;\n\n /** Per-command guard. Required when modules are mounted. */\n authorize?: SurfaceAuthorize;\n\n /**\n * `'authenticated'` (default): the manifest carries `auth` like every\n * command. `'public'`: it carries none and skips a global `auth`\n * middleware, so a caller can discover commands before it holds a token.\n */\n manifest?: 'authenticated' | 'public';\n\n /** Capability modules this application explicitly chooses to expose here. */\n modules?: readonly SurfaceModule[];\n}\n\nexport interface Surface\n{\n /** The validated namespace, as given. */\n readonly namespace: string;\n\n /** `route` with the namespace applied. */\n readonly route: SurfaceRouteBuilder;\n\n /**\n * Build the unmapped package router: the manifest first, then the\n * secured commands, then the secured module commands.\n */\n router<TRoutes extends Record<string, RouteDef<any, any, any> | Router<any>>>(routes: TRoutes): Router<any>;\n}\n\n/** What `router()` builds from: the options, checked, plus the derived names. */\ninterface Plan\n{\n namespace: string;\n prefix: string;\n manifestPath: string;\n manifestName: string;\n auth: NamedMiddleware<string>;\n authorize?: SurfaceAuthorize;\n manifest: 'authenticated' | 'public';\n modules: readonly SurfaceModule[];\n wording: SurfaceWording;\n requireEffect: boolean;\n}\n\n/** How a surface treats an app command that declares no `.effect()`. Internal to core. */\nexport interface SurfaceRules\n{\n /** `true`: refuse it. `false`: announce it without an effect, as `/_ops` always has. */\n requireEffect: boolean;\n}\n\n/**\n * The longest summary a command may announce. The same 500 as the CLI's\n * `MAX_SUMMARY_LENGTH` in `spfn/surface`'s manifest trust, so a server never\n * announces a summary its own client would refuse.\n */\nconst MAX_COMMAND_SUMMARY_LENGTH = 500;\n\nconst EFFECT_METHOD = \".effect('read' | 'write' | 'destructive')\";\n\ninterface CompiledModuleRoute\n{\n route: RouteDef<any>;\n command: SurfaceCommand;\n}\n\ninterface CompiledModuleSurface\n{\n descriptors: SurfaceModuleDescriptor[];\n commands: SurfaceCommand[];\n routes: Record<string, CompiledModuleRoute>;\n}\n\nfunction isRouter(value: unknown): value is Router<any>\n{\n return value !== null\n && typeof value === 'object'\n && 'routes' in value\n && '_routes' in value;\n}\n\nfunction isRouteDef(value: unknown): value is RouteDef<any>\n{\n return value !== null\n && typeof value === 'object'\n && 'handler' in value;\n}\n\nfunction assertSurfaceRoute(plan: Plan, name: string, def: RouteDef<any>): void\n{\n const label = capitalized(plan.wording.noun);\n\n if (!def.method || !def.path)\n {\n throw new SurfaceError(\n `${label} route \"${name}\" has no method or path. `\n + 'A command is invoked on the wire, so both are required.',\n );\n }\n\n if (!def.path.startsWith(plan.prefix))\n {\n throw new SurfaceError(\n `${label} route \"${name}\" is at \"${def.path}\", outside \"${plan.prefix}\". `\n + `Build ${plan.wording.noun} routes with ${plan.wording.builder} rather than \\`route\\` — it applies the namespace, `\n + 'so the path a definition carries is only the part the app owns.',\n );\n }\n\n if (def.path === plan.manifestPath)\n {\n throw new SurfaceError(\n `${label} route \"${name}\" claims \"${plan.manifestPath}\", which is reserved for the manifest. `\n + 'The manifest is registered first, so this route would never answer.',\n );\n }\n}\n\n/**\n * Refuse an app command whose route declares an effect or summary a client\n * could not use — or, on a surface that requires it, no effect at all. A\n * manifest is then never built announcing a command whose effect is unknown,\n * and a defaulted effect is never put in its place: that would be a claim the\n * app did not make, in the field a client reads to decide whether to retry.\n */\nfunction assertCommandMetadata(plan: Plan, name: string, def: RouteDef<any>): void\n{\n const label = `${capitalized(plan.wording.noun)} command \"${name}\"`;\n\n if (def.effect === undefined && plan.requireEffect)\n {\n throw new SurfaceError(\n `${label} declares no effect. A client reads it to decide whether to call, retry, `\n + `or ask for confirmation, so ${plan.wording.factory} refuses a command without one. `\n + `Declare it on the route with ${EFFECT_METHOD}.`,\n );\n }\n\n if (def.effect !== undefined && !isSurfaceEffect(def.effect))\n {\n throw new SurfaceError(\n `${label} has invalid effect ${JSON.stringify(def.effect)}. `\n + `A client knows no other, so declare it with ${EFFECT_METHOD}.`,\n );\n }\n\n assertCommandSummary(label, def.summary);\n}\n\n/** Refuse a summary the CLI would refuse: blank, or longer than it accepts. */\nfunction assertCommandSummary(label: string, summary: unknown): void\n{\n if (summary === undefined)\n {\n return;\n }\n\n if (typeof summary !== 'string' || summary.trim().length === 0)\n {\n throw new SurfaceError(\n `${label} has an empty summary. A client would list it as a command described by nothing; `\n + 'give .summary() one line of text, or leave it out.',\n );\n }\n\n if (summary.length > MAX_COMMAND_SUMMARY_LENGTH)\n {\n throw new SurfaceError(\n `${label} has a summary of ${summary.length} characters, over the ${MAX_COMMAND_SUMMARY_LENGTH} `\n + 'a client accepts — it would drop the command\\'s metadata and treat it as destructive. Shorten it.',\n );\n }\n}\n\n/**\n * A module command's effect is the module's declaration; its route's own\n * `.effect()` is ignored when it agrees and refused when it does not, because\n * the manifest can announce only one and the route's author meant the other.\n * The route's `.summary()` is not read at all — the module's wins.\n */\nfunction assertModuleRouteEffect(plan: Plan, name: string, definition: SurfaceModuleCommand<any>): void\n{\n const routeEffect = definition.route.effect;\n\n if (routeEffect !== undefined && routeEffect !== definition.effect)\n {\n throw new SurfaceError(\n `${capitalized(plan.wording.noun)} command \"${name}\" is declared ${JSON.stringify(definition.effect)} `\n + `by its module, but its route says .effect(${JSON.stringify(routeEffect)}). `\n + 'The manifest announces the module\\'s declaration, so the two cannot disagree. '\n + 'Drop the route\\'s .effect() or make it match.',\n );\n }\n}\n\n/**\n * The reserved name is checked for every entry, route and nested router\n * alike, because the merge cannot refuse a duplicate key on its own. The\n * manifest is merged in first and the app's entries spread over it, so an\n * entry under this name would replace the manifest — the surface would then\n * announce nothing and a client would discover no commands at all.\n */\nfunction assertSurfaceName(plan: Plan, name: string): void\n{\n if (name === plan.manifestName)\n {\n throw new SurfaceError(\n `${capitalized(plan.wording.noun)} route name \"${plan.manifestName}\" is reserved for the manifest route.`,\n );\n }\n}\n\n/**\n * Rebuild a nested router with the auth middleware injected into its routes,\n * carrying over what the original declared. A plain `defineRouter` of the\n * secured routes would silently drop the router's own `.use()` middlewares —\n * a scope guard among them — leaving those routes reachable by any valid\n * credential.\n *\n * It is rebuilt unmapped, like the surface that holds it: a nested surface\n * router publishes no route map either.\n *\n * Those middlewares are handed down to the routes rather than left on the\n * rebuilt router. Router-level middlewares are registered ahead of every\n * route-level one, so a guard left in place would run before the auth that\n * was injected per route — reading a request no one had authenticated yet.\n *\n * `.packages()` is refused rather than carried: package routes are registered\n * without passing through this factory, so they would join the surface with\n * neither the prefix check nor the auth injection.\n */\nfunction rebuildNestedRouter(\n plan: Plan,\n name: string,\n router: Router<any>,\n commandsByName: ReadonlyMap<string, SurfaceCommand>,\n inherited: ReadonlyArray<NamedMiddleware<string>>,\n): Router<any>\n{\n if (router._packageRouters?.length > 0)\n {\n throw new SurfaceError(\n `${capitalized(plan.wording.noun)} router \"${name}\" mounts package routers with .packages(). `\n + 'Their routes bypass the prefix check and the auth injection, so a surface cannot carry them.',\n );\n }\n\n const handedDown = [...inherited, ...(router._globalMiddlewares ?? [])];\n\n let rebuilt = defineUnmappedRouter(\n secureRoutes(plan, router.routes, commandsByName, handedDown) as Record<string, RouteDef<any>>,\n );\n\n if (router._contractVersion)\n {\n rebuilt = rebuilt.contractVersion(router._contractVersion);\n }\n\n return rebuilt;\n}\n\n/**\n * Validate every route and hand back a copy carrying, in order, the auth\n * middleware, the command's guard when `authorize` gave one, the middlewares\n * its enclosing routers declared with `.use()`, and its own. Route-level\n * injection (rather than router-level `.use`) makes the middleware's `skips`\n * declaration effective, so `opsTokenAuth` can auto-skip a server-level `auth`\n * middleware exactly as `oneTimeTokenAuth` does — and it is what puts auth\n * ahead of every group guard.\n *\n * `authorize` is asked for a command's guard only once its own route has\n * passed `assertSurfaceRoute` and `assertCommandMetadata` — an `authorize`\n * written to switch exhaustively on `command.effect` must never be handed one\n * `defineSurface` would otherwise have refused.\n */\nfunction secureRoutes(\n plan: Plan,\n routes: Record<string, RouteDef<any> | Router<any>>,\n commandsByName: ReadonlyMap<string, SurfaceCommand>,\n inherited: ReadonlyArray<NamedMiddleware<string>> = [],\n): Record<string, RouteDef<any> | Router<any>>\n{\n const secured: Record<string, RouteDef<any> | Router<any>> = {};\n\n for (const [name, entry] of Object.entries(routes))\n {\n assertSurfaceName(plan, name);\n\n if (isRouter(entry))\n {\n secured[name] = rebuildNestedRouter(plan, name, entry, commandsByName, inherited);\n continue;\n }\n\n if (!isRouteDef(entry))\n {\n throw new SurfaceError(\n `${capitalized(plan.wording.noun)} router entry \"${name}\" is neither a route nor a router.`,\n );\n }\n\n assertSurfaceRoute(plan, name, entry);\n assertCommandMetadata(plan, name, entry);\n const guard = plan.authorize?.(commandsByName.get(name)!);\n secured[name] = {\n ...entry,\n middlewares: commandChain(plan, name, guard, [...inherited, ...(entry.middlewares ?? [])]),\n };\n }\n\n return secured;\n}\n\n/**\n * A command's middlewares in the order they run: auth, the guard when\n * `authorize` gave one, then the ones the command declared — its enclosing\n * routers' first, its own last.\n *\n * A guard sharing its name with the surface's auth middleware or a declared\n * middleware is refused rather than chained. Registration keeps one\n * middleware per name, so the other one would be dropped without a word —\n * and a guard factory that returns a named middleware per call makes that\n * collision easy to hit by accident.\n */\nfunction commandChain(\n plan: Plan,\n name: string,\n guard: SurfaceMiddleware | undefined,\n declared: readonly SurfaceMiddleware[],\n): SurfaceMiddleware[]\n{\n if (guard === undefined)\n {\n return [plan.auth, ...declared];\n }\n\n const guardName = middlewareNameOf(guard);\n if (guardName !== undefined)\n {\n refuseGuardCollision(plan, name, guardName, declared);\n }\n\n return [plan.auth, guard, ...declared];\n}\n\n/** Throw when the guard's name collides with `auth` or a declared middleware. */\nfunction refuseGuardCollision(\n plan: Plan,\n name: string,\n guardName: string,\n declared: readonly SurfaceMiddleware[],\n): void\n{\n const noun = capitalized(plan.wording.noun);\n\n if (middlewareNameOf(plan.auth) === guardName)\n {\n throw new SurfaceError(\n `${noun} command \"${name}\"'s guard shares the name \"${guardName}\" with the surface's auth `\n + 'middleware. Route registration keeps one middleware per name, so the command\\'s guard '\n + 'would never run. Give one of the two a distinct name.',\n );\n }\n\n if (declared.some(middleware => middlewareNameOf(middleware) === guardName))\n {\n throw new SurfaceError(\n `${noun} command \"${name}\" declares a middleware named \"${guardName}\", `\n + 'the name of the guard authorize gave it. Route registration keeps one middleware per name, '\n + 'so the command\\'s own guard would never run. Give one of the two a distinct name.',\n );\n }\n}\n\n/** The name registration deduplicates by — a plain handler has none. */\nfunction middlewareNameOf(middleware: SurfaceMiddleware): string | undefined\n{\n return typeof middleware === 'function' ? undefined : middleware.name;\n}\n\n/**\n * Refuse a module command that would collide with a command already claimed:\n * same name, same method and path, or — against an app command — a pattern\n * that can claim a common URL.\n */\nfunction assertModuleCommandFree(\n plan: Plan,\n command: SurfaceCommand,\n appCommands: readonly SurfaceCommand[],\n claimed: { names: Set<string>; signatures: Map<string, string> },\n): void\n{\n const noun = plan.wording.noun;\n\n if (claimed.names.has(command.name))\n {\n throw new SurfaceError(`Two ${noun} commands are named \"${command.name}\".`);\n }\n\n const signature = `${command.method} ${command.path}`;\n const existing = claimed.signatures.get(signature);\n if (existing)\n {\n throw new SurfaceError(\n `${capitalized(noun)} commands \"${existing}\" and \"${command.name}\" both use ${signature}.`,\n );\n }\n\n // Whether the two patterns can claim a common URL, not whether the app\n // route sits in the module's namespace. An app route at exactly\n // `<namespace>/<moduleId>` shares the prefix but can never be reached by a\n // `<namespace>/<moduleId>/<command>` request, and refusing it would fail a\n // legitimate app at boot.\n const overlapping = appCommands.find(app =>\n app.method === command.method && routePatternsOverlap(app.path, command.path));\n if (overlapping)\n {\n throw new SurfaceError(\n `App ${noun} command \"${overlapping.name}\" at ${command.method} ${overlapping.path} `\n + `overlaps module command \"${command.name}\" at ${command.method} ${command.path}. `\n + 'Which one answers cannot depend on route registration order.',\n );\n }\n\n claimed.names.add(command.name);\n claimed.signatures.set(signature, command.name);\n}\n\nfunction compileModules(plan: Plan, appCommands: readonly SurfaceCommand[]): CompiledModuleSurface\n{\n const compiled: CompiledModuleSurface = { descriptors: [], commands: [], routes: {} };\n const moduleIds = new Set<string>();\n const claimed = {\n names: new Set(appCommands.map(command => command.name)),\n signatures: new Map(appCommands.map(command => [`${command.method} ${command.path}`, command.name])),\n };\n\n for (const rawModule of plan.modules)\n {\n const module = validateSurfaceModule(rawModule, plan.namespace, plan.wording);\n\n if (moduleIds.has(module.id))\n {\n throw new SurfaceError(`Two ${plan.wording.noun} modules use id \"${module.id}\".`);\n }\n moduleIds.add(module.id);\n\n compiled.descriptors.push({\n id: module.id,\n source: module.source,\n contractVersion: module.contractVersion,\n summary: module.summary,\n });\n\n for (const [localName, definition] of Object.entries(module.commands))\n {\n const command: SurfaceCommand = {\n name: `${module.id}.${localName}`,\n module: module.id,\n summary: definition.summary,\n effect: definition.effect,\n scopes: [...definition.scopes],\n method: definition.route.method!,\n path: definition.route.path!,\n input: collectSurfaceCommands({ [localName]: definition.route }, plan.wording)[0]!.input,\n };\n\n assertModuleRouteEffect(plan, command.name, definition);\n assertModuleCommandFree(plan, command, appCommands, claimed);\n compiled.commands.push(command);\n compiled.routes[command.name] = { route: definition.route, command };\n }\n }\n\n compiled.descriptors.sort((a, b) => a.id.localeCompare(b.id));\n compiled.commands.sort((a, b) => a.name.localeCompare(b.name));\n\n return compiled;\n}\n\nfunction secureModuleRoutes(plan: Plan, routes: Record<string, CompiledModuleRoute>): Record<string, RouteDef<any>>\n{\n const secured: Record<string, RouteDef<any>> = {};\n\n for (const [name, definition] of Object.entries(routes))\n {\n assertSurfaceName(plan, name);\n assertSurfaceRoute(plan, name, definition.route);\n secured[name] = {\n ...definition.route,\n middlewares: commandChain(\n plan,\n name,\n plan.authorize?.(definition.command),\n definition.route.middlewares ?? [],\n ),\n };\n }\n\n return secured;\n}\n\n/**\n * The manifest route. Authenticated, it carries `auth` like every command.\n * Public, it carries none and skips a server-level `auth` by name — the\n * global middleware `opsTokenAuth` and `optionalAuth` auto-skip — which would\n * otherwise demand an app session before the manifest could answer.\n */\nfunction manifestRoute(plan: Plan, manifest: SurfaceManifest): RouteDef<any>\n{\n const builder = route.get(plan.manifestPath);\n\n return (plan.manifest === 'public' ? builder.skip(['auth']) : builder.use([plan.auth]))\n .handler(async () => manifest);\n}\n\nfunction buildRouter(plan: Plan, routes: Record<string, RouteDef<any> | Router<any>>): Router<any>\n{\n const appCommands = collectSurfaceCommands(routes, plan.wording);\n const moduleSurface = compileModules(plan, appCommands);\n const commands = [...appCommands, ...moduleSurface.commands]\n .sort((a, b) => a.name.localeCompare(b.name));\n\n const manifest: SurfaceManifest = {\n manifestVersion: 1,\n ...(moduleSurface.descriptors.length > 0 ? { modules: moduleSurface.descriptors } : {}),\n commands,\n };\n\n const commandsByName = new Map(appCommands.map(command => [command.name, command]));\n const secured = secureRoutes(plan, routes, commandsByName);\n const securedModules = secureModuleRoutes(plan, moduleSurface.routes);\n\n // The manifest goes first, so no route in this object can answer its path.\n // A route pattern that happens to cover `<namespace>/_manifest` —\n // `<namespace>/:name`, say — is then only a route the app never reaches\n // through that one URL, not a surface-wide outage where a client cannot\n // discover any command.\n //\n // The ordering reaches no further than this object. `registerRoutes`\n // registers a router's own routes before its package routers, so a pattern\n // the app declares in its own router still shadows the manifest — as it\n // shadows every other package route, which is a property of where the app\n // put that pattern rather than of this factory.\n // `defineUnmappedRouter`, not `defineRouter`: no surface route map is\n // published for an app to merge, and a client invokes a command over the\n // URL the manifest gave it rather than by name through the RPC client. So a\n // command and an app route sharing a name overwrite nothing, and the\n // route-map generator must not refuse the build over it.\n //\n // The namespace marker is non-enumerable, so the router compares and\n // spreads as any other does; `.packages()` reads it to refuse a second\n // surface on this namespace.\n return Object.defineProperty(defineUnmappedRouter({\n [plan.manifestName]: manifestRoute(plan, manifest),\n ...secured,\n ...securedModules,\n } as Record<string, RouteDef<any>>), '_surfaceNamespace', { value: plan.namespace, enumerable: false });\n}\n\nfunction planOf(options: SurfaceOptions, wording: SurfaceWording, rules: SurfaceRules): Plan\n{\n assertNamespace(options?.namespace);\n\n if (!options.auth)\n {\n throw new SurfaceError(\n `${wording.factory} requires an auth middleware ({ auth: ... }). `\n + 'A surface reachable without authentication cannot be created.',\n );\n }\n\n const modules = options.modules ?? [];\n if (modules.length > 0 && !options.authorize)\n {\n throw new SurfaceError(`${wording.factory} requires an authorize function when modules are mounted.`);\n }\n\n const manifest = options.manifest ?? 'authenticated';\n if (manifest !== 'authenticated' && manifest !== 'public')\n {\n throw new SurfaceError(\n `${wording.factory} manifest must be 'authenticated' or 'public', got ${JSON.stringify(manifest)}.`,\n );\n }\n\n return {\n namespace: options.namespace,\n prefix: `${options.namespace}/`,\n manifestPath: manifestPathOf(options.namespace),\n manifestName: manifestNameOf(options.namespace),\n auth: options.auth,\n authorize: options.authorize,\n manifest,\n modules,\n wording,\n requireEffect: rules.requireEffect,\n };\n}\n\n/**\n * `defineSurface` with the words its refusals use and the rules it holds app\n * commands to. Internal: `@spfn/core/ops` passes its own so an ops refusal\n * reads as it always has, and so an ops route that never declared an effect\n * boots as it always has.\n */\nexport function createSurface(options: SurfaceOptions, wording: SurfaceWording, rules: SurfaceRules): Surface\n{\n const plan = planOf(options, wording, rules);\n\n return {\n namespace: plan.namespace,\n route: surfaceRouteBuilder(plan.namespace, wording),\n router: routes => buildRouter(plan, routes),\n };\n}\n\n/**\n * Define a command surface on a namespace.\n *\n * The namespace, the auth middleware, and the `authorize` requirement are\n * checked here; routes and modules when `router()` builds the package router.\n * Every app command must declare its effect with\n * `.effect('read' | 'write' | 'destructive')` — `router()` refuses one that\n * does not, so a client is never handed a command it cannot classify.\n * The router is an ordinary `Router` meant to be mounted with `.packages()`,\n * so its routes stay out of the app's client types exactly like other\n * package routes.\n */\nexport function defineSurface(options: SurfaceOptions): Surface\n{\n return createSurface(options, SURFACE_WORDING, { requireEffect: true });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spfn/core",
3
- "version": "0.3.0-beta.28",
3
+ "version": "0.3.0-beta.29",
4
4
  "description": "Full-stack TypeScript backend for Next.js: file-based typed routes, Drizzle entities and repositories, PostgreSQL transactions and a generated end-to-end client, in one fixed vertical slice per feature",
5
5
  "type": "module",
6
6
  "exports": {