feat: beta-hardening — routing, degradation, mesh gate, uploads, @header

Restructure first: split the two oversized files by cohesion (http.ts 449
→ http/{router,request,stream,ws,server,types}; app.ts 556 → app/{types,
introspect,index}), rename cryptic locals, JSDoc the public API, and
extract helpers so no function exceeds the complexity gate (createApp
187 → <15, listen 113 → 6). Public import paths are unchanged (barrels).

On that structure, five features that close the biggest gaps vs
Express/Fastify/Nest for a comparable beta:

- routing: `:name*` catch-all, specificity precedence (static ▸ param ▸
  catch-all, not registration order), and 405 + Allow when a path exists
  under a different method (was 404)
- visible degradation: optional providers that fail boot are summarized on
  listen() and queryable via app.degraded(), instead of a silent warn
- mesh is alpha — gated behind `experimental: true`; createApp throws if
  `mesh` is configured without it
- multipart moves to the optional `busboy` peer dependency (clear 501 when
  absent), keeping the core at one runtime dependency
- `@header('name')` as a singular alias of `@headers`

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-07 12:00:15 -05:00
1 parent 9d79972f62
commit d6c5cee0ee
42 files changed
+2619 -1170

No files matched your search

+14 -8
View File
@@ -1,4 +1,6 @@
// src/standard-schema.ts — vendored Standard Schema (~standard) types + helpers. No imports.
/** Standard Schema v1 interface (spec.standardschema.dev): a validator under the `~standard` key. */
export interface StandardSchemaV1<Input = unknown, Output = Input> {
readonly '~standard': {
readonly version: 1;
@@ -8,27 +10,31 @@ export interface StandardSchemaV1<Input = unknown, Output = Input> {
};
}
/** Validation outcome: either a parsed `value` or a list of `issues`. */
export type StandardResult<T> =
| { readonly value: T; readonly issues?: undefined }
| { readonly issues: ReadonlyArray<StandardIssue> };
{ readonly value: T; readonly issues?: undefined } | { readonly issues: ReadonlyArray<StandardIssue> };
/** A single validation issue with a message and optional path to the offending field. */
export interface StandardIssue {
readonly message: string;
readonly path?: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }>;
}
export function isStandardSchema(x: unknown): x is StandardSchemaV1 {
/** Type guard: true if `value` implements Standard Schema v1 (has a callable `~standard.validate`). */
export function isStandardSchema(value: unknown): value is StandardSchemaV1 {
return (
typeof x === 'object' && x !== null &&
'~standard' in x &&
typeof (x as { ['~standard']?: { validate?: unknown } })['~standard']?.validate === 'function'
typeof value === 'object' &&
value !== null &&
'~standard' in value &&
typeof (value as { ['~standard']?: { validate?: unknown } })['~standard']?.validate === 'function'
);
}
/** Render an issue's path as a dotted string (e.g. `user.email`); empty if pathless. */
export function flattenPath(issue: StandardIssue): string {
if (!issue.path) return '';
return issue.path
.map((seg) => (typeof seg === 'object' && seg !== null && 'key' in seg ? seg.key : seg))
.map((k) => String(k))
.map((segment) => (typeof segment === 'object' && segment !== null && 'key' in segment ? segment.key : segment))
.map((key) => String(key))
.join('.');
}