typespec-hono 0.8.0 → 0.10.0

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.
@@ -101,6 +101,20 @@ export async function $onEmit(context) {
101
101
  * its server, so `@server("/api/v1")` plus `/accounts` publishes `/api/v1/accounts`. Mounting at
102
102
  * the root made every client generated from the document 404.
103
103
  */
104
+ /**
105
+ * **A service this project does not serve still belongs in the program.**
106
+ *
107
+ * One compile is what makes a shared vocabulary shared, so a surface not yet served is in the
108
+ * spec for its types and its validators. Its server is not wanted, and without a way to say so
109
+ * the emitter wrote an `app.gen.ts` the project had to keep honest with probe tests and never
110
+ * mounted.
111
+ *
112
+ * Only this file is withheld. Everything the library emits for that service is untouched,
113
+ * because those are the reason it is in the program at all.
114
+ */
115
+ const serviceName = emitted.service.namespace.name;
116
+ if (context.options.services?.[serviceName]?.["emit-server"] === false)
117
+ continue;
104
118
  const base = resolveBasePath(context.program, emitted.service.namespace);
105
119
  await emitFile(context.program, {
106
120
  path: resolvePath(emitted.outputDir, "app.gen.ts"),
package/dist/src/lib.d.ts CHANGED
@@ -18,7 +18,17 @@ import { type EmitterOptions as HttpZodOptions } from "typespec-http-zod";
18
18
  * because it carries anything today. The moment a Hono-only option appears it goes here, and the
19
19
  * derivation keeps the rest honest.
20
20
  */
21
- export type EmitterOptions = HttpZodOptions;
21
+ export type EmitterOptions = HttpZodOptions & {
22
+ /**
23
+ * Per-service overrides this emitter adds on top of the library's.
24
+ *
25
+ * **The library's own `services` map is preserved**, because the type is an intersection: an
26
+ * option added there still arrives here, and this only widens what each entry may carry.
27
+ */
28
+ services?: Record<string, {
29
+ "emit-server"?: boolean;
30
+ }>;
31
+ };
22
32
  /**
23
33
  * **A spread of the published schema, so a new key arrives for free.**
24
34
  *
package/dist/src/lib.js CHANGED
@@ -9,7 +9,25 @@ import { EmitterOptionsSchema as httpZodOptions, } from "typespec-http-zod";
9
9
  */
10
10
  const EmitterOptionsSchema = {
11
11
  ...httpZodOptions,
12
- properties: { ...httpZodOptions.properties },
12
+ properties: {
13
+ ...httpZodOptions.properties,
14
+ /**
15
+ * **Spread from the library's own entry rather than restated**, so a per-service option added
16
+ * there still validates here. Only `emit-server` is added.
17
+ */
18
+ services: {
19
+ ...httpZodOptions.properties.services,
20
+ additionalProperties: {
21
+ type: "object",
22
+ additionalProperties: false,
23
+ properties: {
24
+ ...httpZodOptions.properties.services.additionalProperties.properties,
25
+ "emit-server": { type: "boolean", nullable: true },
26
+ },
27
+ required: [],
28
+ },
29
+ },
30
+ },
13
31
  };
14
32
  /**
15
33
  * What this emitter refuses that the library does not.
@@ -12,6 +12,28 @@ import type { input, output, ZodType } from "zod";
12
12
  export interface ResponseArm {
13
13
  readonly status: number | "default" | `${1 | 2 | 3 | 4 | 5}XX`;
14
14
  readonly schema: ZodType | undefined;
15
+ /**
16
+ * The media types this response offers, where the document names MORE than one.
17
+ *
18
+ * Absent where it names one, which is what an application already assumes, so "one type" and
19
+ * "not carried" are the same state rather than two to tell apart. Present, it is the set to
20
+ * negotiate against: `selectContentType` takes the caller's `Accept` and these.
21
+ */
22
+ readonly contentTypes?: readonly string[];
23
+ /**
24
+ * The headers this response declares, as the document publishes them.
25
+ *
26
+ * **Two names, because two different things need them.** `name` is the WIRE name, which is what
27
+ * the response sets; `property` is the name on the value the handler returned, which is where the
28
+ * value is read from. `@header("x-correlation-id") correlationId: string` is `x-correlation-id`
29
+ * on the wire and `correlationId` in the result, and they differ for any header with a hyphen.
30
+ *
31
+ * Absent where the response declares none.
32
+ */
33
+ readonly headers?: readonly {
34
+ readonly name: string;
35
+ readonly property: string;
36
+ }[];
15
37
  readonly when?: {
16
38
  readonly property: string;
17
39
  readonly value: boolean | string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespec-hono",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "TypeSpec emitter: generate a Hono server, and the Zod validators it enforces, from an HTTP service definition, agreeing with the OpenAPI document @typespec/openapi3 publishes from the same source.",
5
5
  "keywords": [
6
6
  "cloudflare-workers",
@@ -44,7 +44,7 @@
44
44
  "provenance": true
45
45
  },
46
46
  "dependencies": {
47
- "typespec-http-zod": "^0.10.0"
47
+ "typespec-http-zod": "^0.12.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@hono/zod-openapi": "^1.4.0",
package/src/runtime.ts CHANGED
@@ -14,6 +14,25 @@ import type { input, output, ZodType } from "zod";
14
14
  export interface ResponseArm {
15
15
  readonly status: number | "default" | `${1 | 2 | 3 | 4 | 5}XX`;
16
16
  readonly schema: ZodType | undefined;
17
+ /**
18
+ * The media types this response offers, where the document names MORE than one.
19
+ *
20
+ * Absent where it names one, which is what an application already assumes, so "one type" and
21
+ * "not carried" are the same state rather than two to tell apart. Present, it is the set to
22
+ * negotiate against: `selectContentType` takes the caller's `Accept` and these.
23
+ */
24
+ readonly contentTypes?: readonly string[];
25
+ /**
26
+ * The headers this response declares, as the document publishes them.
27
+ *
28
+ * **Two names, because two different things need them.** `name` is the WIRE name, which is what
29
+ * the response sets; `property` is the name on the value the handler returned, which is where the
30
+ * value is read from. `@header("x-correlation-id") correlationId: string` is `x-correlation-id`
31
+ * on the wire and `correlationId` in the result, and they differ for any header with a hyphen.
32
+ *
33
+ * Absent where the response declares none.
34
+ */
35
+ readonly headers?: readonly { readonly name: string; readonly property: string }[];
17
36
  readonly when?: {
18
37
  readonly property: string;
19
38
  readonly value: boolean | string;