@ontrails/http 1.0.0-beta.16 → 1.0.0-beta.17

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @ontrails/http
2
2
 
3
+ ## 1.0.0-beta.17
4
+
5
+ ### Patch Changes
6
+
7
+ - 61497c5: Add v1-minimum public API examples for shipped surface entrypoints.
8
+ - Updated dependencies [3dc8254]
9
+ - @ontrails/core@1.0.0-beta.17
10
+
3
11
  ## 1.0.0-beta.16
4
12
 
5
13
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ontrails/http",
3
- "version": "1.0.0-beta.16",
3
+ "version": "1.0.0-beta.17",
4
4
  "files": [
5
5
  "src/**/*.ts",
6
6
  "!src/**/__tests__/**",
@@ -22,7 +22,7 @@
22
22
  "clean": "rm -rf dist *.tsbuildinfo"
23
23
  },
24
24
  "dependencies": {
25
- "@ontrails/core": "^1.0.0-beta.15"
25
+ "@ontrails/core": "^1.0.0-beta.16"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "zod": "^4.3.5"
package/src/build.ts CHANGED
@@ -1279,6 +1279,18 @@ const accumulateRoutes = (
1279
1279
  *
1280
1280
  * Returns `Result.err(ValidationError)` if two trails derive the same
1281
1281
  * (method, path) pair. Returns `Result.ok(routes)` on success.
1282
+ *
1283
+ * @example
1284
+ * ```ts
1285
+ * import { deriveHttpRoutes } from '@ontrails/http';
1286
+ *
1287
+ * const routes = deriveHttpRoutes(graph, { basePath: '/api' });
1288
+ * if (routes.isErr()) throw routes.error;
1289
+ *
1290
+ * for (const route of routes.value) {
1291
+ * console.log(`${route.method} ${route.path}`);
1292
+ * }
1293
+ * ```
1282
1294
  */
1283
1295
  export const deriveHttpRoutes = (
1284
1296
  graph: Topo,
package/src/method.ts CHANGED
@@ -12,13 +12,46 @@ export const httpMethodByIntent = {
12
12
  write: 'POST',
13
13
  } as const satisfies Record<Intent, HttpMethod>;
14
14
 
15
+ /**
16
+ * Derive the HTTP method used for a trail intent.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { deriveHttpMethod } from '@ontrails/http';
21
+ *
22
+ * const method = deriveHttpMethod('read');
23
+ * // method === 'GET'
24
+ * ```
25
+ */
15
26
  export const deriveHttpMethod = (intent: Intent): HttpMethod =>
16
27
  (httpMethodByIntent as Partial<Record<string, HttpMethod>>)[intent] ?? 'POST';
17
28
 
29
+ /**
30
+ * Derive the lowercase OpenAPI operation method for a trail intent.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { deriveHttpOperationMethod } from '@ontrails/http';
35
+ *
36
+ * const operationMethod = deriveHttpOperationMethod('destroy');
37
+ * // operationMethod === 'delete'
38
+ * ```
39
+ */
18
40
  export const deriveHttpOperationMethod = (
19
41
  intent: Intent
20
42
  ): HttpOperationMethod =>
21
43
  deriveHttpMethod(intent).toLowerCase() as HttpOperationMethod;
22
44
 
45
+ /**
46
+ * Derive where request input should be read from for an HTTP method.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * import { deriveHttpInputSource } from '@ontrails/http';
51
+ *
52
+ * const source = deriveHttpInputSource('GET');
53
+ * // source === 'query'
54
+ * ```
55
+ */
23
56
  export const deriveHttpInputSource = (method: HttpMethod): InputSource =>
24
57
  method === 'GET' ? 'query' : 'body';
package/src/openapi.ts CHANGED
@@ -331,6 +331,16 @@ const buildInfo = (
331
331
  * Iterates all trails, skipping signals and internal trails, and produces
332
332
  * paths, operations, parameters, and response schemas derived from
333
333
  * the trail contract.
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * import { deriveOpenApiSpec } from '@ontrails/http';
338
+ *
339
+ * const spec = deriveOpenApiSpec(graph, {
340
+ * basePath: '/api',
341
+ * title: 'Demo API',
342
+ * });
343
+ * ```
334
344
  */
335
345
  export const deriveOpenApiSpec = (
336
346
  graph: Topo,