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>
41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
// 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;
|
|
readonly vendor: string;
|
|
validate(value: unknown): StandardResult<Output> | Promise<StandardResult<Output>>;
|
|
readonly types?: { readonly input: Input; readonly output: Output };
|
|
};
|
|
}
|
|
|
|
/** 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> };
|
|
|
|
/** 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 }>;
|
|
}
|
|
|
|
/** Type guard: true if `value` implements Standard Schema v1 (has a callable `~standard.validate`). */
|
|
export function isStandardSchema(value: unknown): value is StandardSchemaV1 {
|
|
return (
|
|
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((segment) => (typeof segment === 'object' && segment !== null && 'key' in segment ? segment.key : segment))
|
|
.map((key) => String(key))
|
|
.join('.');
|
|
}
|