@ontrails/http 1.0.0-beta.12 → 1.0.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-lint.log +1 -1
- package/CHANGELOG.md +62 -23
- package/README.md +10 -10
- package/dist/build.d.ts +11 -9
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +24 -18
- package/dist/build.js.map +1 -1
- package/dist/hono/blaze.js +2 -2
- package/dist/hono/blaze.js.map +1 -1
- package/dist/hono/index.d.ts +1 -1
- package/dist/hono/index.d.ts.map +1 -1
- package/dist/hono/index.js +1 -1
- package/dist/hono/index.js.map +1 -1
- package/dist/hono/trailhead.d.ts +36 -0
- package/dist/hono/trailhead.d.ts.map +1 -0
- package/dist/hono/trailhead.js +222 -0
- package/dist/hono/trailhead.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/build.test.ts +60 -44
- package/src/build.ts +37 -27
- package/src/hono/__tests__/{blaze.test.ts → trailhead.test.ts} +79 -77
- package/src/hono/index.ts +1 -1
- package/src/hono/{blaze.ts → trailhead.ts} +21 -33
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hono
|
|
2
|
+
* Hono connector for Trails HTTP routes.
|
|
3
3
|
*
|
|
4
4
|
* Takes framework-agnostic HttpRouteDefinition[] and wires them into a
|
|
5
5
|
* Hono application, handling request parsing, response mapping, and errors.
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
8
|
* const app = topo("myapp", entity);
|
|
9
|
-
* await
|
|
9
|
+
* await trailhead(app, { port: 3000 });
|
|
10
10
|
* ```
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { isTrailsError, statusCodeMap
|
|
13
|
+
import { isTrailsError, statusCodeMap } from '@ontrails/core';
|
|
14
14
|
import type {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
Gate,
|
|
16
|
+
ProvisionOverrideMap,
|
|
17
17
|
Topo,
|
|
18
18
|
TrailContextInit,
|
|
19
19
|
} from '@ontrails/core';
|
|
@@ -29,9 +29,9 @@ import { buildHttpRoutes } from '../build.js';
|
|
|
29
29
|
// Options
|
|
30
30
|
// ---------------------------------------------------------------------------
|
|
31
31
|
|
|
32
|
-
export interface
|
|
32
|
+
export interface TrailheadHttpOptions {
|
|
33
33
|
readonly basePath?: string | undefined;
|
|
34
|
-
/** Config values for
|
|
34
|
+
/** Config values for provisions that declare a `config` schema, keyed by provision ID. */
|
|
35
35
|
readonly configValues?:
|
|
36
36
|
| Readonly<Record<string, Record<string, unknown>>>
|
|
37
37
|
| undefined;
|
|
@@ -39,10 +39,10 @@ export interface BlazeHttpOptions {
|
|
|
39
39
|
| (() => TrailContextInit | Promise<TrailContextInit>)
|
|
40
40
|
| undefined;
|
|
41
41
|
readonly hostname?: string | undefined;
|
|
42
|
-
readonly
|
|
42
|
+
readonly gates?: readonly Gate[] | undefined;
|
|
43
43
|
readonly name?: string | undefined;
|
|
44
44
|
readonly port?: number | undefined;
|
|
45
|
-
readonly
|
|
45
|
+
readonly provisions?: ProvisionOverrideMap | undefined;
|
|
46
46
|
/** Set false to return the Hono app without starting a server. */
|
|
47
47
|
readonly serve?: boolean | undefined;
|
|
48
48
|
/** Set to `false` to skip topo validation at startup. Defaults to `true`. */
|
|
@@ -233,10 +233,10 @@ const createHonoHandler =
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
const requestId = c.req.header('X-Request-ID') ?? undefined;
|
|
236
|
-
const { signal } = c.req.raw;
|
|
236
|
+
const { signal: abortSignal } = c.req.raw;
|
|
237
237
|
|
|
238
238
|
try {
|
|
239
|
-
const result = await route.execute(rawInput, requestId,
|
|
239
|
+
const result = await route.execute(rawInput, requestId, abortSignal);
|
|
240
240
|
return mapResultToResponse(result, c);
|
|
241
241
|
} catch (error: unknown) {
|
|
242
242
|
return handleCaughtError(error, c);
|
|
@@ -294,34 +294,21 @@ const registerErrorHandler = (hono: Hono): void => {
|
|
|
294
294
|
// Validation
|
|
295
295
|
// ---------------------------------------------------------------------------
|
|
296
296
|
|
|
297
|
-
/**
|
|
298
|
-
* Throw a ValidationError if the topo has structural issues.
|
|
299
|
-
* Pass `skip: true` to bypass validation (e.g. when `validate: false` is set).
|
|
300
|
-
*/
|
|
301
|
-
const assertValidTopo = (app: Topo, skip = false): void => {
|
|
302
|
-
if (skip) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
const validated = validateTopo(app);
|
|
306
|
-
if (validated.isErr()) {
|
|
307
|
-
throw validated.error;
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
|
|
311
297
|
// ---------------------------------------------------------------------------
|
|
312
|
-
//
|
|
298
|
+
// trailhead
|
|
313
299
|
// ---------------------------------------------------------------------------
|
|
314
300
|
|
|
315
301
|
/**
|
|
316
302
|
* Build HTTP routes from a topo, create a Hono app, and optionally start serving.
|
|
303
|
+
*
|
|
304
|
+
* Topo validation runs before route construction — pass `validate: false`
|
|
305
|
+
* to skip it (e.g. during hot-reload or progressive startup).
|
|
317
306
|
*/
|
|
318
|
-
// oxlint-disable-next-line require-await -- async for consistency with other
|
|
319
|
-
export const
|
|
307
|
+
// oxlint-disable-next-line require-await -- async for consistency with other trailhead() entrypoints
|
|
308
|
+
export const trailhead = async (
|
|
320
309
|
app: Topo,
|
|
321
|
-
options:
|
|
310
|
+
options: TrailheadHttpOptions = {}
|
|
322
311
|
): Promise<Hono> => {
|
|
323
|
-
assertValidTopo(app, options.validate === false);
|
|
324
|
-
|
|
325
312
|
const hono = new Hono();
|
|
326
313
|
|
|
327
314
|
registerErrorHandler(hono);
|
|
@@ -330,8 +317,9 @@ export const blaze = async (
|
|
|
330
317
|
basePath: options.basePath,
|
|
331
318
|
configValues: options.configValues,
|
|
332
319
|
createContext: options.createContext,
|
|
333
|
-
|
|
334
|
-
|
|
320
|
+
gates: options.gates,
|
|
321
|
+
provisions: options.provisions,
|
|
322
|
+
validate: options.validate,
|
|
335
323
|
});
|
|
336
324
|
|
|
337
325
|
if (routesResult.isErr()) {
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/build.ts","./src/index.ts","./src/hono/
|
|
1
|
+
{"root":["./src/build.ts","./src/index.ts","./src/hono/index.ts","./src/hono/trailhead.ts"],"version":"5.9.3"}
|