@grest-ts/http 0.0.23 → 0.0.25

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.
Files changed (49) hide show
  1. package/README.md +45 -0
  2. package/dist/src/client/GGHttpSchema.createClient.d.ts +26 -0
  3. package/dist/src/client/GGHttpSchema.createClient.d.ts.map +1 -1
  4. package/dist/src/client/GGHttpSchema.createClient.js +11 -3
  5. package/dist/src/client/GGHttpSchema.createClient.js.map +1 -1
  6. package/dist/src/index-node.d.ts +2 -0
  7. package/dist/src/index-node.d.ts.map +1 -1
  8. package/dist/src/index-node.js +2 -0
  9. package/dist/src/index-node.js.map +1 -1
  10. package/dist/src/rpc/GGHttpRouteRPC.d.ts +19 -6
  11. package/dist/src/rpc/GGHttpRouteRPC.d.ts.map +1 -1
  12. package/dist/src/rpc/GGHttpRouteRPC.js +27 -5
  13. package/dist/src/rpc/GGHttpRouteRPC.js.map +1 -1
  14. package/dist/src/rpc/openApiHelpers.d.ts +21 -0
  15. package/dist/src/rpc/openApiHelpers.d.ts.map +1 -0
  16. package/dist/src/rpc/openApiHelpers.js +70 -0
  17. package/dist/src/rpc/openApiHelpers.js.map +1 -0
  18. package/dist/src/rpc/openApiSuccessResponse.d.ts +15 -0
  19. package/dist/src/rpc/openApiSuccessResponse.d.ts.map +1 -0
  20. package/dist/src/rpc/openApiSuccessResponse.js +32 -0
  21. package/dist/src/rpc/openApiSuccessResponse.js.map +1 -0
  22. package/dist/src/schema/GGHttpSchema.d.ts +66 -1
  23. package/dist/src/schema/GGHttpSchema.d.ts.map +1 -1
  24. package/dist/src/schema/GGHttpSchema.js.map +1 -1
  25. package/dist/src/schema/httpSchema.d.ts.map +1 -1
  26. package/dist/src/schema/httpSchema.js +14 -3
  27. package/dist/src/schema/httpSchema.js.map +1 -1
  28. package/dist/src/server/GGHttp.d.ts +6 -1
  29. package/dist/src/server/GGHttp.d.ts.map +1 -1
  30. package/dist/src/server/GGHttp.js +5 -0
  31. package/dist/src/server/GGHttp.js.map +1 -1
  32. package/dist/src/server/GGHttpSchema.startServer.js +15 -0
  33. package/dist/src/server/GGHttpSchema.startServer.js.map +1 -1
  34. package/dist/src/server/GGHttpServer.d.ts +43 -0
  35. package/dist/src/server/GGHttpServer.d.ts.map +1 -1
  36. package/dist/src/server/GGHttpServer.js +70 -2
  37. package/dist/src/server/GGHttpServer.js.map +1 -1
  38. package/dist/tsconfig.publish.tsbuildinfo +1 -1
  39. package/package.json +10 -10
  40. package/src/client/GGHttpSchema.createClient.ts +45 -4
  41. package/src/index-node.ts +2 -0
  42. package/src/rpc/GGHttpRouteRPC.ts +34 -6
  43. package/src/rpc/openApiHelpers.ts +87 -0
  44. package/src/rpc/openApiSuccessResponse.ts +38 -0
  45. package/src/schema/GGHttpSchema.ts +73 -1
  46. package/src/schema/httpSchema.ts +16 -4
  47. package/src/server/GGHttp.ts +6 -1
  48. package/src/server/GGHttpSchema.startServer.ts +14 -0
  49. package/src/server/GGHttpServer.ts +84 -2
package/README.md CHANGED
@@ -235,6 +235,8 @@ export const GG_CLIENT_INFO = new GGContextKey<ClientInfo>('clientInfo', IsObjec
235
235
  }))
236
236
 
237
237
  export const ClientInfoMiddleware: GGHttpTransportMiddleware = {
238
+ headers: ['x-client-version', 'x-client-platform'],
239
+ responseHeaders: [],
238
240
  updateRequest(req: GGHttpRequest): void {
239
241
  const info = GG_CLIENT_INFO.get()
240
242
  if (info) {
@@ -409,6 +411,49 @@ protected compose(): void {
409
411
  }
410
412
  ```
411
413
 
414
+ ### CORS Headers
415
+
416
+ CORS `Access-Control-Allow-Headers` are auto-discovered from middleware and codecs.
417
+ Only `Content-Type` is included by default (it's set by the framework's RPC layer).
418
+ All other headers — including `Authorization` — are registered automatically when
419
+ middleware declares them via `headers` or when `useHeader()` extracts them from codecs.
420
+
421
+ When using `useHeader()`, header names are extracted from the codec's input schema automatically:
422
+
423
+ ```typescript
424
+ const HeaderType = IsObject({
425
+ "x-org-token": IsString.orUndefined // Auto-discovered as CORS header
426
+ })
427
+ GG_ORG_TOKEN.addCodec("http", HeaderType.codecTo(...))
428
+
429
+ httpSchema(Contract)
430
+ .useHeader(GG_ORG_TOKEN) // "x-org-token" added to CORS Allow-Headers
431
+ .routes({ ... })
432
+ ```
433
+
434
+ Both `headers` (request) and `responseHeaders` (response) are required on middleware and codecs —
435
+ TypeScript enforces this at compile time. Use `[]` when not applicable:
436
+
437
+ ```typescript
438
+ export const MyMiddleware: GGHttpTransportMiddleware = {
439
+ headers: ['x-custom-header'],
440
+ responseHeaders: [],
441
+ updateRequest(req) { ... },
442
+ parseRequest(req) { ... }
443
+ }
444
+ ```
445
+
446
+ Codecs also declare `responseHeaders`. For example, `GGFileDownload` declares
447
+ `['Content-Disposition']` which is automatically added to `Access-Control-Expose-Headers`.
448
+
449
+ You can also register headers manually on the server:
450
+
451
+ ```typescript
452
+ const httpServer = new GGHttpServer()
453
+ httpServer.registerCorsHeaders(['x-custom-header'])
454
+ httpServer.registerCorsExposeHeaders(['x-custom-response-header'])
455
+ ```
456
+
412
457
  ## HTTP Client
413
458
 
414
459
  ### Creating Clients
@@ -5,10 +5,36 @@ declare module "../schema/GGHttpSchema" {
5
5
  createClient(config?: GGHttpClientConfig): GGContractClient<TContract>;
6
6
  }
7
7
  }
8
+ /**
9
+ * HTTP transport function. The signature mirrors `fetch` (URL string + init bag),
10
+ * which lets the default implementation just be `fetch`. Pass a custom transport
11
+ * to plug in pinned-TLS dialing, custom dispatchers, signed-request proxies,
12
+ * or any other wire-layer concern that `fetch` can't accommodate.
13
+ *
14
+ * The `url` arg is `(config.url ?? "") + path-built-from-schema`, so when you
15
+ * pass `url: ""` (or rely on transport-implies-empty), your transport receives
16
+ * just the request path and decides the host itself.
17
+ *
18
+ * The init bag is a fetch-compatible subset: only the fields createClient
19
+ * actually populates. Extending it later is a non-breaking change.
20
+ */
21
+ export type GGHttpTransport = (url: string, init: {
22
+ method: string;
23
+ headers: Record<string, string>;
24
+ body: string | FormData | undefined;
25
+ signal: AbortSignal;
26
+ }) => Promise<Response>;
8
27
  export interface GGHttpClientConfig {
9
28
  url?: string;
10
29
  timeout?: number;
11
30
  noValidation?: boolean;
31
+ /**
32
+ * Override the wire-layer call. Defaults to `fetch`. When provided,
33
+ * service discovery is skipped (the transport is presumed to know how
34
+ * to reach the target) and `url` defaults to `""` so the transport sees
35
+ * just the schema-built path.
36
+ */
37
+ transport?: GGHttpTransport;
12
38
  }
13
39
  export declare function createClient<TContract extends GGContractApiDefinition, TContext>(httpSchema: GGHttpSchema<TContract, TContext>, config?: GGHttpClientConfig): GGContractClient<TContract>;
14
40
  //# sourceMappingURL=GGHttpSchema.createClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GGHttpSchema.createClient.d.ts","sourceRoot":"","sources":["../../../src/client/GGHttpSchema.createClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,uBAAuB,EAAE,gBAAgB,EAA4E,MAAM,kBAAkB,CAAA;AACvK,OAAO,EAAwD,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAI3G,OAAO,QAAQ,wBAAwB,CAAC;IACpC,UAAU,YAAY,CAAC,SAAS,SAAS,uBAAuB,EAAE,QAAQ,GAAG,EAAE;QAC3E,YAAY,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAA;KACzE;CACJ;AAED,MAAM,WAAW,kBAAkB;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAA;CACzB;AASD,wBAAgB,YAAY,CAAC,SAAS,SAAS,uBAAuB,EAAE,QAAQ,EAC5E,UAAU,EAAE,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,EAC7C,MAAM,CAAC,EAAE,kBAAkB,GAC5B,gBAAgB,CAAC,SAAS,CAAC,CA+E7B"}
1
+ {"version":3,"file":"GGHttpSchema.createClient.d.ts","sourceRoot":"","sources":["../../../src/client/GGHttpSchema.createClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,uBAAuB,EAAE,gBAAgB,EAA4E,MAAM,kBAAkB,CAAA;AACvK,OAAO,EAAwD,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAI3G,OAAO,QAAQ,wBAAwB,CAAC;IACpC,UAAU,YAAY,CAAC,SAAS,SAAS,uBAAuB,EAAE,QAAQ,GAAG,EAAE;QAC3E,YAAY,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAA;KACzE;CACJ;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,eAAe,GAAG,CAC1B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE;IACF,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;IACnC,MAAM,EAAE,WAAW,CAAA;CACtB,KACA,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtB,MAAM,WAAW,kBAAkB;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,eAAe,CAAA;CAC9B;AASD,wBAAgB,YAAY,CAAC,SAAS,SAAS,uBAAuB,EAAE,QAAQ,EAC5E,UAAU,EAAE,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,EAC7C,MAAM,CAAC,EAAE,kBAAkB,GAC5B,gBAAgB,CAAC,SAAS,CAAC,CAuF7B"}
@@ -7,6 +7,13 @@ GGHttpSchema.prototype.createClient = function (config) {
7
7
  export function createClient(httpSchema, config) {
8
8
  config ??= {};
9
9
  config.timeout ??= 15000;
10
+ // A custom transport implies "I take over the wire layer" — discovery is
11
+ // off the table (the transport knows how to find the target), and the
12
+ // default base URL becomes "" so the transport sees just the request path.
13
+ const transport = config.transport ?? defaultFetchTransport;
14
+ if (config.transport && config.url === undefined) {
15
+ config.url = "";
16
+ }
10
17
  if (config.url === undefined && isBrowser()) {
11
18
  throw new Error("Must define URL for GGHttpClient when running in browser! Use empty string for same-origin requests.");
12
19
  }
@@ -41,7 +48,7 @@ export function createClient(httpSchema, config) {
41
48
  const fetchRequest = await wireFormat.createRequest(validatedInput);
42
49
  const controller = new AbortController();
43
50
  const timeoutId = setTimeout(() => controller.abort(), config.timeout);
44
- const wireResponse = await fetch(baseUrl + fetchRequest.url, {
51
+ const wireResponse = await transport(baseUrl + fetchRequest.url, {
45
52
  method: fetchRequest.method,
46
53
  signal: controller.signal,
47
54
  headers: fetchRequest.headers,
@@ -73,8 +80,9 @@ export function createClient(httpSchema, config) {
73
80
  return new GGPromise(implementation(data));
74
81
  };
75
82
  }
76
- // @TODO Next line is just so test would register it correctly.
77
- httpSchema.contract.implement(transportImplementation);
83
+ // Per-client stub doesn't belong in the callOn registry (server's impl does).
84
+ httpSchema.contract.implement(transportImplementation, { skipLocatorRegistration: true });
78
85
  return transportImplementation;
79
86
  }
87
+ const defaultFetchTransport = (url, init) => fetch(url, init);
80
88
  //# sourceMappingURL=GGHttpSchema.createClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GGHttpSchema.createClient.js","sourceRoot":"","sources":["../../../src/client/GGHttpSchema.createClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,EAA6C,kBAAkB,EAA4B,SAAS,EAAM,YAAY,EAAC,MAAM,kBAAkB,CAAA;AACvK,OAAO,EAAwD,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAC3G,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAe3C,YAAY,CAAC,SAAS,CAAC,YAAY,GAAG,UAElC,MAA2B;IAE3B,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC,CAAA;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QUEST";
3
3
  export * from "./schema/GGHttpSchema";
4
4
  export * from "./schema/httpSchema";
5
5
  export * from "./rpc/GGHttpRouteRPC";
6
+ export * from "./rpc/openApiSuccessResponse";
7
+ export * from "./rpc/openApiHelpers";
6
8
  export * from "./rpc/RpcRequest/GGRpcRequestBuilder";
7
9
  export * from "./rpc/RpcRequest/GGRpcRequestParser";
8
10
  export * from "./rpc/RpcResponse/GGRpcResponseBuilder";
@@ -1 +1 @@
1
- {"version":3,"file":"index-node.d.ts","sourceRoot":"","sources":["../../src/index-node.ts"],"names":[],"mappings":"AAUA,cAAc,wBAAwB,CAAC;AAGvC,cAAc,0BAA0B,CAAC;AAGzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AAGtD,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AAGxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAIlD,OAAO,oCAAoC,CAAC;AAC5C,OAAO,mCAAmC,CAAC"}
1
+ {"version":3,"file":"index-node.d.ts","sourceRoot":"","sources":["../../src/index-node.ts"],"names":[],"mappings":"AAUA,cAAc,wBAAwB,CAAC;AAGvC,cAAc,0BAA0B,CAAC;AAGzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AAGtD,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AAGxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAIlD,OAAO,oCAAoC,CAAC;AAC5C,OAAO,mCAAmC,CAAC"}
@@ -14,6 +14,8 @@ export * from "./server/GG_HTTP_REQUEST.js";
14
14
  export * from "./schema/GGHttpSchema.js";
15
15
  export * from "./schema/httpSchema.js";
16
16
  export * from "./rpc/GGHttpRouteRPC.js";
17
+ export * from "./rpc/openApiSuccessResponse.js";
18
+ export * from "./rpc/openApiHelpers.js";
17
19
  export * from "./rpc/RpcRequest/GGRpcRequestBuilder.js";
18
20
  export * from "./rpc/RpcRequest/GGRpcRequestParser.js";
19
21
  export * from "./rpc/RpcResponse/GGRpcResponseBuilder.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index-node.js","sourceRoot":"","sources":["../../src/index-node.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,OAAO,EAAC,8BAA8B,EAAC,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAC,kBAAkB,EAAC,MAAM,qCAAqC,CAAC;AACvE,8BAA8B,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACtD,YAAY,EAAE,IAAI,kBAAkB,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,YAAY;IACvE,YAAY,EAAE,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC,YAAY;CAC9D,CAAC,CAAC,CAAC;AAEJ,UAAU;AACV,cAAc,wBAAwB,CAAC;AAEvC,UAAU;AACV,cAAc,0BAA0B,CAAC;AAEzC,aAAa;AACb,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC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AACtC,cAAc,yBAAyB,CAAC;AAExC,SAAS;AACT,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAGlD,aAAa;AACb,OAAO,oCAAoC,CAAC;AAC5C,OAAO,mCAAmC,CAAC"}
@@ -1,19 +1,32 @@
1
1
  import { HttpMethod } from "@grest-ts/common";
2
- import { ClientHttpRouteToRpcTransformClientCodec, ClientHttpRouteToRpcTransformClientConfig, ClientHttpRouteToRpcTransformServerCodec, ClientHttpRouteToRpcTransformServerConfig, GGHttpCodec } from "../schema/GGHttpSchema";
2
+ import { ClientHttpRouteToRpcTransformClientCodec, ClientHttpRouteToRpcTransformClientConfig, ClientHttpRouteToRpcTransformServerCodec, ClientHttpRouteToRpcTransformServerConfig, GGHttpCodec, GGHttpCodecOpenApiConfig } from "../schema/GGHttpSchema";
3
+ import type { OpenAPIV3_1 } from "openapi-types";
4
+ import { GGSchema } from "@grest-ts/schema";
3
5
  export type GGRpcServerCodecFactory = (method: HttpMethod, path: string, config: ClientHttpRouteToRpcTransformServerConfig) => ClientHttpRouteToRpcTransformServerCodec;
4
6
  export declare function _registerRpcServerCodecFactory(factory: GGRpcServerCodecFactory): void;
5
7
  export declare const GGRpc: {
6
- GET: (path: string) => GGHttpRpcCodec;
7
- DELETE: (path: string) => GGHttpRpcCodec;
8
- POST: (path: string) => GGHttpRpcCodec;
9
- PUT: (path: string) => GGHttpRpcCodec;
8
+ GET: (path: string, opts?: {
9
+ deprecated?: boolean;
10
+ }) => GGHttpRpcCodec;
11
+ DELETE: (path: string, opts?: {
12
+ deprecated?: boolean;
13
+ }) => GGHttpRpcCodec;
14
+ POST: (path: string, opts?: {
15
+ deprecated?: boolean;
16
+ }) => GGHttpRpcCodec;
17
+ PUT: (path: string, opts?: {
18
+ deprecated?: boolean;
19
+ }) => GGHttpRpcCodec;
10
20
  };
11
21
  declare class GGHttpRpcCodec implements GGHttpCodec {
12
22
  readonly method: HttpMethod;
13
23
  readonly path: string;
14
- constructor(method: HttpMethod, path: string);
24
+ readonly deprecated: boolean | undefined;
25
+ readonly responseHeaders: Record<string, GGSchema<string | undefined>>;
26
+ constructor(method: HttpMethod, path: string, deprecated?: boolean);
15
27
  createForClient(config: ClientHttpRouteToRpcTransformClientConfig): ClientHttpRouteToRpcTransformClientCodec;
16
28
  createForServer(config: ClientHttpRouteToRpcTransformServerConfig): ClientHttpRouteToRpcTransformServerCodec;
29
+ toOpenApiOperation(config: GGHttpCodecOpenApiConfig): Partial<OpenAPIV3_1.OperationObject>;
17
30
  }
18
31
  export {};
19
32
  //# sourceMappingURL=GGHttpRouteRPC.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GGHttpRouteRPC.d.ts","sourceRoot":"","sources":["../../../src/rpc/GGHttpRouteRPC.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAC,wCAAwC,EAAE,yCAAyC,EAAE,wCAAwC,EAAE,yCAAyC,EAAE,WAAW,EAAC,MAAM,wBAAwB,CAAA;AAI5N,MAAM,MAAM,uBAAuB,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,yCAAyC,KAAK,wCAAwC,CAAC;AAIxK,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAErF;AAED,eAAO,MAAM,KAAK;gBACF,MAAM;mBACH,MAAM;iBACR,MAAM;gBACP,MAAM;CACrB,CAAA;AAED,cAAM,cAAe,YAAW,WAAW;IAEvC,SAAgB,MAAM,EAAE,UAAU,CAAA;IAClC,SAAgB,IAAI,EAAE,MAAM,CAAA;gBAEhB,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM;IAKrC,eAAe,CAAC,MAAM,EAAE,yCAAyC,GAAG,wCAAwC;IAO5G,eAAe,CAAC,MAAM,EAAE,yCAAyC,GAAG,wCAAwC;CAItH"}
1
+ {"version":3,"file":"GGHttpRouteRP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AC,MAAM,EAAE,yCAAyC,GAAG,wCAAwC;IAK5G,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,WAAW,CAAC,eAAe,CAAC;CAoBpG"}
@@ -1,21 +1,26 @@
1
1
  import { GGRpcRequestBuilder } from "./RpcRequest/GGRpcRequestBuilder.js";
2
2
  import { GGRpcResponseParser } from "./RpcResponse/GGRpcResponseParser.js";
3
+ import { buildRpcSuccessResponses } from "./openApiSuccessResponse.js";
4
+ import { buildOpenApiParameters } from "./openApiHelpers.js";
3
5
  let _serverCodecFactory;
4
6
  export function _registerRpcServerCodecFactory(factory) {
5
7
  _serverCodecFactory = factory;
6
8
  }
7
9
  export const GGRpc = {
8
- GET: (path) => new GGHttpRpcCodec("GET", path),
9
- DELETE: (path) => new GGHttpRpcCodec("DELETE", path),
10
- POST: (path) => new GGHttpRpcCodec("POST", path),
11
- PUT: (path) => new GGHttpRpcCodec("PUT", path),
10
+ GET: (path, opts) => new GGHttpRpcCodec("GET", path, opts?.deprecated),
11
+ DELETE: (path, opts) => new GGHttpRpcCodec("DELETE", path, opts?.deprecated),
12
+ POST: (path, opts) => new GGHttpRpcCodec("POST", path, opts?.deprecated),
13
+ PUT: (path, opts) => new GGHttpRpcCodec("PUT", path, opts?.deprecated),
12
14
  };
13
15
  class GGHttpRpcCodec {
14
16
  method;
15
17
  path;
16
- constructor(method, path) {
18
+ deprecated;
19
+ responseHeaders = {};
20
+ constructor(method, path, deprecated) {
17
21
  this.method = method;
18
22
  this.path = path;
23
+ this.deprecated = deprecated;
19
24
  }
20
25
  createForClient(config) {
21
26
  return {
@@ -28,5 +33,22 @@ class GGHttpRpcCodec {
28
33
  throw new Error("Server RPC codec not available. Ensure @grest-ts/http server entry is imported.");
29
34
  return _serverCodecFactory(this.method, this.path, config);
30
35
  }
36
+ toOpenApiOperation(config) {
37
+ const hasBody = this.method === "POST" || this.method === "PUT" || this.method === "PATCH";
38
+ const operationId = config.methodName;
39
+ const parameters = buildOpenApiParameters(this.path, hasBody, config.contract.input ?? undefined, config.schemaResolver);
40
+ const operation = {
41
+ operationId,
42
+ parameters,
43
+ responses: buildRpcSuccessResponses(config.contract, config.schemaResolver)
44
+ };
45
+ if (hasBody && config.contract.input) {
46
+ operation.requestBody = {
47
+ required: true,
48
+ content: { 'application/json': { schema: config.schemaResolver(config.contract.input.toSchemaDescription()) } }
49
+ };
50
+ }
51
+ return operation;
52
+ }
31
53
  }
32
54
  //# sourceMappingURL=GGHttpRouteRPC.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GGHttpRouteRPC.js","sourceRoot":"","sources":["../../../src/rpc/GGHttpRouteRPC.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,mBAAmB,EAAC,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAC,mBAAmB,EAAC,MAAM,mCAAmC,CAAC;AAItE,IAAI,mBAAwD,CAAC;AAE7D,MAAM,UAAU,8BAA8B,CAAC,OAAgC;IAC3E,mBAAmB,GAAG,OAAO,CAAC;AAClC,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG;IACjB,GAAG,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC;IACtD,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC;IAC5D,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC;IACxD,GAAG,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC;CACzD,CAAA;AAED,MAAM,cAAc;IAEA,MAAM,CAAY;IAClB,IAAI,CAAQ;IAE5B,YAAY,MAAkB,EAAE,IAAY;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACpB,CAA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,QAAQ,CAAC,KAAK,IAAI,SAAS,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC;QACzH,MAAM,SAAS,GAAyC;YACpD,WAAW;YACX,UAAU;YACV,SAAS,EAAE,wBAAwB,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC;SAC9E,CAAC;QAEF,IAAI,OAAO,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YACnC,SAAS,CAAC,WAAW,GAAG;gBACpB,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,EAAC,kBAAkB,EAAE,EAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,EAAC,EAAC;aAC9G,CAAC;QACN,CAAC;QAED,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ"}
@@ -0,0 +1,21 @@
1
+ import type { GGSchema } from "@grest-ts/schema";
2
+ import type { GGOpenApiSchemaResolver } from "../schema/GGHttpSchema";
3
+ import type { OpenAPIV3_1 } from "openapi-types";
4
+ /**
5
+ * Build OpenAPI parameter objects for a route from the contract's input schema.
6
+ *
7
+ * Path parameters are extracted from the path template (:id → {id}).
8
+ * For GET/DELETE (no body), remaining input fields become query parameters.
9
+ *
10
+ * Uses toSchemaDescription() to walk the input object's fields as
11
+ * GGSchemaDescription instances, then passes each to schemaResolver so named
12
+ * schemas are emitted as $ref where applicable.
13
+ *
14
+ * Type-cast note: openapi-types@12 defines OpenAPIV3_1.ParameterObject as a
15
+ * direct alias of OpenAPIV3.ParameterObject, whose `schema` field resolves to
16
+ * V3 schema types (missing `type:"null"` as a valid NonArraySchemaObjectType).
17
+ * The casts to ParameterObject["schema"] are the precise boundary of that
18
+ * typedef limitation — runtime objects are fully valid OpenAPI 3.1 parameters.
19
+ */
20
+ export declare function buildOpenApiParameters(pathTemplate: string, hasBody: boolean, inputSchema: GGSchema<unknown> | undefined, schemaResolver: GGOpenApiSchemaResolver): OpenAPIV3_1.ParameterObject[];
21
+ //# sourceMappingURL=openApiHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openApiHelpers.d.ts","sourceRoot":"","sources":["../../../src/rpc/openApiHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAsB,MAAM,kBAAkB,CAAC;AACpE,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE/C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAClC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,EAC1C,cAAc,EAAE,uBAAuB,GACxC,WAAW,CAAC,eAAe,EAAE,CAuC/B"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Build OpenAPI parameter objects for a route from the contract's input schema.
3
+ *
4
+ * Path parameters are extracted from the path template (:id → {id}).
5
+ * For GET/DELETE (no body), remaining input fields become query parameters.
6
+ *
7
+ * Uses toSchemaDescription() to walk the input object's fields as
8
+ * GGSchemaDescription instances, then passes each to schemaResolver so named
9
+ * schemas are emitted as $ref where applicable.
10
+ *
11
+ * Type-cast note: openapi-types@12 defines OpenAPIV3_1.ParameterObject as a
12
+ * direct alias of OpenAPIV3.ParameterObject, whose `schema` field resolves to
13
+ * V3 schema types (missing `type:"null"` as a valid NonArraySchemaObjectType).
14
+ * The casts to ParameterObject["schema"] are the precise boundary of that
15
+ * typedef limitation — runtime objects are fully valid OpenAPI 3.1 parameters.
16
+ */
17
+ export function buildOpenApiParameters(pathTemplate, hasBody, inputSchema, schemaResolver) {
18
+ const pathParams = (pathTemplate.match(/:(\w+)/g) || []).map(m => m.slice(1));
19
+ if (!inputSchema)
20
+ return pathParams.map(name => buildPathParam(name, undefined, schemaResolver));
21
+ // Use toSchemaDescription() to get GGSchemaDescription instances per field.
22
+ // This gives us the format-agnostic tree without coupling to internal def structure.
23
+ const desc = inputSchema.toSchemaDescription();
24
+ if (desc.node.kind !== 'object') {
25
+ // Input schemas must be object schemas so their fields can be mapped to
26
+ // path/query parameters. Any other kind is a contract definition error.
27
+ throw new Error(`buildOpenApiParameters: input schema must be an object schema (kind='object'), ` +
28
+ `got kind='${desc.node.kind}'. Contract input schemas must use IsObject({...}).`);
29
+ }
30
+ const properties = desc.node.properties;
31
+ const params = pathParams.map(name => buildPathParam(name, properties[name], schemaResolver));
32
+ if (!hasBody) {
33
+ for (const [name, fieldDesc] of Object.entries(properties)) {
34
+ if (pathParams.includes(name))
35
+ continue;
36
+ const resolved = schemaResolver(fieldDesc);
37
+ const { description, ...schemaWithoutDescription } = resolved;
38
+ const isRequired = !fieldDesc.optional && resolved.default === undefined;
39
+ const param = {
40
+ name,
41
+ in: 'query',
42
+ required: isRequired,
43
+ schema: schemaWithoutDescription
44
+ };
45
+ if (description)
46
+ param.description = description;
47
+ params.push(param);
48
+ }
49
+ }
50
+ return params;
51
+ }
52
+ function buildPathParam(name, fieldDesc, schemaResolver) {
53
+ if (!fieldDesc) {
54
+ // Path params are always non-empty — an empty segment cannot be routed.
55
+ return { name, in: 'path', required: true,
56
+ schema: { type: 'string', minLength: 1 } };
57
+ }
58
+ const resolved = schemaResolver(fieldDesc);
59
+ const { description, ...schemaWithoutDescription } = resolved;
60
+ const param = {
61
+ name,
62
+ in: 'path',
63
+ required: true,
64
+ schema: schemaWithoutDescription
65
+ };
66
+ if (description)
67
+ param.description = description;
68
+ return param;
69
+ }
70
+ //# sourceMappingURL=openApiHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openApiHelpers.js","sourceRoot":"","sources":["../../../src/rpc/openApiHelpers.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CAClC,YAAoB,EACpB,OAAgB,EAChB,WAA0C,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AAC,OAAO,KAAK,SAAS,CAAC;YAClF,MAAM,KAAK,GAAgC;gBACvC,IAAI;gBACJ,EAAE,EAAE,OAAgB;gBACpB,QAAQ,EAAE,UAAU;gBACpB,MAAM,EAAE,wBAAiE;aAC5E,CAAC;YACF,IAAI,WAAW;gBAAE,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;YACjD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,cAAc,CACnB,IAAY,EACZ,SAA0C,EAC1C,cAAuC;IAEvC,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,wEAAwE;QACxE,OAAO,EAAC,IAAI,EAAE,EAAE,EAAE,MAAe,EAAE,QAAQ,EAAE,IAAa;YACtD,MAAM,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAA0C,EAAC,CAAC;IACzF,CAAC;IACD,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3C,MAAM,EAAC,WAAW,EAAE,GAAG,wBAAwB,EAAC,GAAG,QAAe,CAAC;IACnE,MAAM,KAAK,GAAgC;QACvC,IAAI;QACJ,EAAE,EAAE,MAAe;QACnB,QAAQ,EAAE,IAAa;QACvB,MAAM,EAAE,wBAAiE;KAC5E,CAAC;IACF,IAAI,WAAW;QAAE,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;IACjD,OAAO,KAAK,CAAC;AACjB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { GGContractMethod } from "@grest-ts/schema";
2
+ import type { OpenAPIV3_1 } from "openapi-types";
3
+ import type { GGOpenApiSchemaResolver } from "../schema/GGHttpSchema";
4
+ /**
5
+ * Builds the standard GGRpc JSON-envelope success response for OpenAPI.
6
+ *
7
+ * On-wire the response is always:
8
+ * { success: true, type: "OK", data: <success schema> } (200)
9
+ * or no body (204 when no success schema)
10
+ *
11
+ * The resolver is used to emit $ref for named success schemas rather than
12
+ * inlining them. Pass config.schemaResolver from toOpenApiOperation().
13
+ */
14
+ export declare function buildRpcSuccessResponses(contract: GGContractMethod, resolver: GGOpenApiSchemaResolver): OpenAPIV3_1.ResponsesObject;
15
+ //# sourceMappingURL=openApiSuccessResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openApiSuccessResponse.d.ts","sourceRoot":"","sources":["../../../src/rpc/openApiSuccessResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,wBAAwB,CAAC;AAEpE;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACpC,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,uBAAuB,GAClC,WAAW,CAAC,eAAe,CAoB7B"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Builds the standard GGRpc JSON-envelope success response for OpenAPI.
3
+ *
4
+ * On-wire the response is always:
5
+ * { success: true, type: "OK", data: <success schema> } (200)
6
+ * or no body (204 when no success schema)
7
+ *
8
+ * The resolver is used to emit $ref for named success schemas rather than
9
+ * inlining them. Pass config.schemaResolver from toOpenApiOperation().
10
+ */
11
+ export function buildRpcSuccessResponses(contract, resolver) {
12
+ if (contract.success) {
13
+ const dataSchema = resolver(contract.success.toSchemaDescription());
14
+ const successSchema = {
15
+ type: "object",
16
+ properties: {
17
+ success: { type: "boolean", enum: [true] },
18
+ type: { type: "string", enum: ["OK"] },
19
+ data: dataSchema
20
+ },
21
+ required: ["success", "type", "data"]
22
+ };
23
+ return {
24
+ "200": {
25
+ description: "Success",
26
+ content: { "application/json": { schema: successSchema } }
27
+ }
28
+ };
29
+ }
30
+ return { "204": { description: "No content" } };
31
+ }
32
+ //# sourceMappingURL=openApiSuccessResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openApiSuccessResponse.js","sourceRoot":"","sources":["../../../src/rpc/openApiSuccessResponse.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CACpC,QAA0B,EAC1B,QAAiC;IAEjC,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,UAAU,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC;QACpE,MAAM,aAAa,GAAqC;YACpD,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACR,OAAO,EAAE,EAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAC;gBACxC,IAAI,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAC;gBACpC,IAAI,EAAE,UAAU;aACnB;YACD,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC;SACxC,CAAC;QACF,OAAO;YACH,KAAK,EAAE;gBACH,WAAW,EAAE,SAAS;gBACtB,OAAO,EAAE,EAAC,kBAAkB,EAAE,EAAC,MAAM,EAAE,aAAa,EAAC,EAAC;aACzD;SACJ,CAAC;IACN,CAAC;IACD,OAAO,EAAC,KAAK,EAAE,EAAC,WAAW,EAAE,YAAY,EAAC,EAAC,CAAC;AAChD,CAAC"}
@@ -1,7 +1,8 @@
1
- import { ERROR, ERROR_JSON, GGContractApiDefinition, GGContractClass, GGContractMethod, OK } from "@grest-ts/schema";
1
+ import { ERROR, ERROR_JSON, GGContractApiDefinition, GGContractClass, GGContractMethod, GGSchema, GGSchemaDescription, OK } from "@grest-ts/schema";
2
2
  import type { HttpMethod } from "@grest-ts/common";
3
3
  import type http from "http";
4
4
  import type { GGHttpServerMiddleware } from "../server/GGHttpSchema.startServer";
5
+ import type { OpenAPIV3_1 } from "openapi-types";
5
6
  export declare class GGHttpSchema<TContract extends GGContractApiDefinition, TContext> {
6
7
  readonly name: string;
7
8
  readonly pathPrefix: string;
@@ -34,13 +35,77 @@ export interface ClientHttpRouteToRpcTransformServerCodec {
34
35
  parseRequest: (req: http.IncomingMessage) => Promise<unknown>;
35
36
  sendResponse: (res: http.ServerResponse, rpcResult: ERROR<string, unknown> | OK<unknown>) => Promise<void>;
36
37
  }
38
+ /**
39
+ * Config passed to toOpenApiOperation? — gives the codec access to the contract and route context
40
+ * so it can produce accurate OpenAPI operation metadata.
41
+ */
42
+ /**
43
+ * Resolves a GGSchemaDescription to an OpenAPI SchemaObject or ReferenceObject.
44
+ * When provided via GGHttpCodecOpenApiConfig, codecs should use this for all schema
45
+ * conversions — it enables $ref extraction for named schemas.
46
+ * For standalone use (tests, custom tools), use inlineSchemaResolver from @grest-ts/openapi.
47
+ */
48
+ export type GGOpenApiSchemaResolver = (desc: GGSchemaDescription) => OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject;
49
+ export interface GGHttpCodecOpenApiConfig {
50
+ readonly pathPrefix: string;
51
+ readonly methodName: string;
52
+ readonly contract: GGContractMethod;
53
+ /**
54
+ * Resolves a GGSchema to an OpenAPI SchemaObject or ReferenceObject.
55
+ * Provided by the document builder (toOpenApi) as registry.schemaOrRef.
56
+ * For standalone codec use or tests, pass inlineSchemaResolver from @grest-ts/openapi.
57
+ */
58
+ readonly schemaResolver: GGOpenApiSchemaResolver;
59
+ }
37
60
  export interface GGHttpCodec {
38
61
  readonly method: HttpMethod;
39
62
  readonly path: string;
63
+ /**
64
+ * Mark this operation as deprecated in the OpenAPI spec.
65
+ * Swagger UI renders deprecated operations with a strikethrough.
66
+ * @default false
67
+ */
68
+ readonly deprecated?: boolean;
69
+ /**
70
+ * Response headers this codec sets, mapped to their value schemas.
71
+ * Keys are header names; values describe the header value format.
72
+ * Used for CORS Access-Control-Expose-Headers and OpenAPI response header docs.
73
+ * Use {} if the codec sets no custom response headers.
74
+ */
75
+ readonly responseHeaders: Record<string, GGSchema<string | undefined>>;
40
76
  createForClient(config: ClientHttpRouteToRpcTransformClientConfig): ClientHttpRouteToRpcTransformClientCodec;
41
77
  createForServer(config: ClientHttpRouteToRpcTransformServerConfig): ClientHttpRouteToRpcTransformServerCodec;
78
+ /**
79
+ * Optional hook for custom codecs to describe their OpenAPI operation semantics.
80
+ * The returned partial is merged on top of the auto-generated operation object,
81
+ * allowing overrides for requestBody content type, security schemes, etc.
82
+ *
83
+ * Built-in GGRpc.* codecs implement this automatically.
84
+ * Custom codec authors (e.g. GGFileUpload) may implement it for accurate docs.
85
+ */
86
+ toOpenApiOperation?(config: GGHttpCodecOpenApiConfig): Partial<OpenAPIV3_1.OperationObject>;
42
87
  }
43
88
  export interface GGHttpTransportMiddleware {
89
+ /**
90
+ * Request headers this middleware reads or writes, mapped to their value schemas.
91
+ * Keys are header names; values describe the header value format for validation and docs.
92
+ * Used for CORS Access-Control-Allow-Headers and OpenAPI parameter docs.
93
+ * Use {} if the middleware touches no custom request headers.
94
+ *
95
+ * @example
96
+ * headers: {
97
+ * "authorization": IsString.nonEmpty.docs({title: "Bearer token", example: "Bearer ..."}),
98
+ * "accept-language": IsLocale.orUndefined
99
+ * }
100
+ */
101
+ readonly headers: Record<string, GGSchema<string | undefined>>;
102
+ /**
103
+ * Response headers this middleware sets, mapped to their value schemas.
104
+ * Keys are header names; values describe the header value format for validation and docs.
105
+ * Used for CORS Access-Control-Expose-Headers and OpenAPI response header docs.
106
+ * Use {} if the middleware sets no custom response headers.
107
+ */
108
+ readonly responseHeaders: Record<string, GGSchema<string | undefined>>;
44
109
  /**
45
110
  * Client-side: modify outgoing request (add headers, etc.)
46
111
  */
@@ -1 +1 @@
1
- {"version":3,"file":"GGHttpSchema.d.ts","sourceRoot":"","sources":["../../../src/schema/GGHttpSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,eAAe,EAAE,gBAAgB,EAAE,EAAE,EAAC,MAAM,kB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WAAW,aAAa;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,cAAc;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CAC9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"GGHttpSchema.js","sourceRoot":"","sources":["../../../src/schema/GGHttpSchema.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,YAAY;IAEL,IAAI,CAAQ;IACZ,UAAU,CAAQ;IAClB,cAAc,CAAsC;IACpD,KAAK,CAAsC;IAC3C,QAAQ,GAAsC,IAAI,CAAA;IAElE,YACI,UAAkB,EAClB,QAAoC,EACpC,SAA+C,EAC/C,cAAoD,EAAE;QAEtD,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,cAAc,GAAG,WAAW,CAAA;QACjC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAClC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACzB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;CACJ"}
1
+ {"version":3,"file":"GGHttpSchema.js","sourceRoot":"","sources":["../../../src/schema/GGHttpSchema.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,YAAY;IAEL,IAAI,CAAQ;IACZ,UAAU,CAAQ;IAClB,cAAc,CAAsC;IACpD,KAAK,CAAsC;IAC3C,QAAQ,GAAsC,IAAI,CAA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CAAC,SAAS,EAAE,QAAQ,GAAG,CAAC,CAAC;IAKrG,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,YAAY,CAAC,KAAK,CAAC,GAAG,mBAAmB,CAAC,SAAS,EAAE,QAAQ,GAAG,KAAK,CAAC;IAmDnG,MAAM,CAAC,OAAO,EAAE;SAAG,CAAC,IAAI,MAAM,SAAS,GAAG,WAAW;KAAE,GAAG,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC;CAG9F"}
@@ -46,9 +46,22 @@ class GGHttpSchemaBuilder {
46
46
  if (!codec) {
47
47
  throw new Error(`Context key '${contextKey.name}' does not have an 'http-header' codec registered.`);
48
48
  }
49
+ // Build the typed header map from codec.inputSchema — the IsObject({headerName: schema})
50
+ // that describes which headers this codec reads and what format each value has.
51
+ const inputSchema = codec.inputSchema;
52
+ const headers = {};
53
+ if (inputSchema) {
54
+ const desc = inputSchema.toSchemaDescription();
55
+ if (desc.node.kind === 'object') {
56
+ for (const [k, fieldDesc] of Object.entries(desc.node.properties)) {
57
+ headers[k] = fieldDesc.schema;
58
+ }
59
+ }
60
+ }
49
61
  const middleware = {
62
+ headers,
63
+ responseHeaders: {},
50
64
  updateRequest(req) {
51
- // Client-side: context -> headers
52
65
  const contextValue = contextKey.get();
53
66
  if (contextValue !== undefined) {
54
67
  const result = codec.decode(contextValue);
@@ -57,7 +70,6 @@ class GGHttpSchemaBuilder {
57
70
  }
58
71
  }
59
72
  else {
60
- // Clear any default headers by decoding an empty context
61
73
  const emptyResult = codec.decode({});
62
74
  if (emptyResult.success) {
63
75
  for (const key of Object.keys(emptyResult.value)) {
@@ -67,7 +79,6 @@ class GGHttpSchemaBuilder {
67
79
  }
68
80
  },
69
81
  parseRequest(req) {
70
- // Server-side: headers -> context
71
82
  const headers = req.headers;
72
83
  const result = codec.encode(headers);
73
84
  if (result.success) {