kizunajs 2.0.0-beta.2 → 2.0.0-beta.21

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 (81) hide show
  1. package/README.md +3 -2
  2. package/dist/{adapter-CZW-unqX.mjs → adapter-BSqNrxhq.mjs} +522 -104
  3. package/dist/adapter-C3WYdSfx.d.cts +2754 -0
  4. package/dist/{adapter-DDR_yo9L.cjs → adapter-ClaFZoab.cjs} +638 -196
  5. package/dist/adapter-D4bTPElA.d.mts +2754 -0
  6. package/dist/adapter.cjs +37 -29
  7. package/dist/adapter.d.cts +3 -5
  8. package/dist/adapter.d.mts +3 -5
  9. package/dist/adapter.mjs +5 -5
  10. package/dist/{error-response-C8Ragjcd.cjs → error-response-C9ymqSU4.cjs} +25 -5
  11. package/dist/{error-response-C839d8By.mjs → error-response-CNQaKVYd.mjs} +20 -6
  12. package/dist/{security-scheme-BrszwGD5.d.cts → error-response-NoOGdh8H.d.mts} +151 -24
  13. package/dist/{security-scheme-D3nb4XKj.d.mts → error-response-YbkRMKno.d.cts} +151 -24
  14. package/dist/generator.cjs +190 -95
  15. package/dist/generator.d.cts +189 -28
  16. package/dist/generator.d.mts +189 -28
  17. package/dist/generator.mjs +151 -60
  18. package/dist/index.cjs +159 -84
  19. package/dist/index.d.cts +193 -253
  20. package/dist/index.d.mts +193 -253
  21. package/dist/index.mjs +112 -38
  22. package/dist/jobs-entry.cjs +12 -11
  23. package/dist/jobs-entry.d.cts +1 -1
  24. package/dist/jobs-entry.d.mts +1 -1
  25. package/dist/jobs-entry.mjs +3 -2
  26. package/dist/plugin-Dw-yCjTY.cjs +233 -0
  27. package/dist/{cache-CLN5y0Xp.mjs → plugin-server-BztlE1fz.mjs} +188 -49
  28. package/dist/{cache-BgohRj0i.cjs → plugin-server-kUsK7thV.cjs} +238 -93
  29. package/dist/plugin-xxCxibmu.mjs +138 -0
  30. package/dist/plugin.cjs +8 -72
  31. package/dist/plugin.d.cts +3 -3
  32. package/dist/plugin.d.mts +3 -3
  33. package/dist/plugin.mjs +2 -68
  34. package/dist/{protected-resource-metadata-CA0v5cjg.d.mts → protected-resource-metadata-B9hMFQ9N.d.cts} +1 -1
  35. package/dist/{protected-resource-metadata-Cprrv0mt.d.cts → protected-resource-metadata-CfBVsqIk.d.mts} +1 -1
  36. package/dist/{schemas-C56no6bv.cjs → schemas-DNPVDvkd.cjs} +28 -1
  37. package/dist/{schemas-CJQcc97N.mjs → schemas-HW2FDsvz.mjs} +23 -2
  38. package/dist/schemas.cjs +3 -2
  39. package/dist/schemas.d.cts +24 -3
  40. package/dist/schemas.d.mts +24 -3
  41. package/dist/schemas.mjs +3 -3
  42. package/package.json +1 -1
  43. package/src/adapter.ts +245 -29
  44. package/src/api-definition.ts +12 -16
  45. package/src/api.ts +7 -3
  46. package/src/brand.ts +29 -0
  47. package/src/config.ts +51 -10
  48. package/src/configured.ts +13 -6
  49. package/src/define-config.ts +118 -39
  50. package/src/generator.ts +363 -46
  51. package/src/group-routes.ts +106 -0
  52. package/src/groups.ts +140 -0
  53. package/src/handler-pipeline.ts +78 -19
  54. package/src/index.ts +15 -6
  55. package/src/job-runner.ts +5 -0
  56. package/src/job-transport.ts +3 -3
  57. package/src/job.ts +8 -6
  58. package/src/jobs-dev-runner.ts +6 -0
  59. package/src/jobs.ts +61 -8
  60. package/src/kizuna.ts +56 -33
  61. package/src/plugin-server.ts +129 -19
  62. package/src/plugin.ts +269 -127
  63. package/src/routes.ts +80 -32
  64. package/src/schemas.ts +1 -0
  65. package/src/tool-answer.ts +21 -0
  66. package/src/tool-definitions.ts +166 -0
  67. package/src/tool-events.ts +90 -18
  68. package/src/tool-records.ts +11 -3
  69. package/src/tool-runner.ts +298 -0
  70. package/src/types.ts +90 -24
  71. package/src/zod-internals.ts +22 -5
  72. package/src/zod-meta.ts +7 -2
  73. package/dist/adapter-BGfMqEkM.d.cts +0 -563
  74. package/dist/adapter-Ci3cfcoT.d.mts +0 -563
  75. package/dist/api-definition-BHnh15zD.d.mts +0 -803
  76. package/dist/api-definition-DQj-ewHy.d.cts +0 -803
  77. package/dist/error-response-BBGSdgYw.d.mts +0 -67
  78. package/dist/error-response-Do38sr-9.d.cts +0 -67
  79. package/dist/plugin-Cz0kn6Lk.d.mts +0 -830
  80. package/dist/plugin-DhKvx_T0.d.cts +0 -830
  81. package/src/tags.ts +0 -67
package/src/config.ts CHANGED
@@ -1,25 +1,56 @@
1
1
  import type { ApiDefinition } from './api-definition.js';
2
2
 
3
3
  /**
4
- * A client generated from a config, created by its generator's own factory so
5
- * the options are typed where the generator lives.
4
+ * A file `kizuna generate` writes and `--check` compares, made by a client's
5
+ * factory, a generator's, or kizuna itself.
6
6
  *
7
7
  * @example
8
- * import { swiftClient } from '@kizunajs/swift';
8
+ * swiftClient({
9
+ * output: './Sources/APIClient/APIClient.swift',
10
+ * });
9
11
  */
10
- export interface ClientTarget {
12
+ export interface GeneratedFile {
11
13
  /**
12
- * The generator that produced this target, for messages and reporting.
14
+ * The language a client generates, like `swift`. A generator has none.
13
15
  */
14
- readonly kind: string;
16
+ readonly target?: string;
15
17
  /**
16
- * Path the generated file is written to.
18
+ * Path the file is written to, resolved against the config's directory.
17
19
  */
18
20
  readonly output: string;
19
21
  /**
20
- * Renders the file this target writes.
22
+ * Renders the file's contents.
21
23
  */
22
- readonly generate: (contract: ApiDefinition) => string;
24
+ readonly render: (api: ApiDefinition) => string;
25
+ }
26
+
27
+ /**
28
+ * What else `kizuna diff` treats as breaking.
29
+ */
30
+ export interface DiffSettings {
31
+ /**
32
+ * Report a renamed dotted key, such as `users.getUser` becoming
33
+ * `users.fetchUser`, as breaking. The key names the method on a generated
34
+ * client, so a rename breaks anyone shipping one as an SDK and leaves the
35
+ * HTTP surface untouched.
36
+ *
37
+ * @default false
38
+ */
39
+ dottedKeys?: boolean;
40
+ /**
41
+ * Report a job key that is gone. A job answers `POST /jobs/run` by its
42
+ * dotted key, so this matters once something outside your own code
43
+ * dispatches them.
44
+ *
45
+ * @default false
46
+ */
47
+ jobs?: boolean;
48
+ /**
49
+ * Report an MCP tool a model can no longer call.
50
+ *
51
+ * @default false
52
+ */
53
+ tools?: boolean;
23
54
  }
24
55
 
25
56
  /**
@@ -28,13 +59,21 @@ export interface ClientTarget {
28
59
  */
29
60
  export interface ApiEntry {
30
61
  api: ApiDefinition;
31
- clients?: readonly ClientTarget[];
62
+ clients?: readonly GeneratedFile[];
63
+ /**
64
+ * The files the config's plugins generate.
65
+ */
66
+ generators?: readonly GeneratedFile[];
32
67
  /**
33
68
  * Where `kizuna generate` writes the `Config`.
34
69
  */
35
70
  typescript?: {
36
71
  outputFile?: string;
37
72
  };
73
+ /**
74
+ * What else `kizuna diff` treats as breaking.
75
+ */
76
+ diff?: DiffSettings;
38
77
  }
39
78
 
40
79
  /**
@@ -50,7 +89,9 @@ export const apiEntries = (module: Record<string, unknown>): [string, ApiEntry][
50
89
  {
51
90
  api: config.api,
52
91
  clients: config.clients ?? [],
92
+ generators: config.generators ?? [],
53
93
  typescript: config.typescript,
94
+ diff: config.diff,
54
95
  },
55
96
  ],
56
97
  ];
package/src/configured.ts CHANGED
@@ -5,7 +5,7 @@ import type { RequestContextValues } from './handler-pipeline.js';
5
5
  import type { RequestContextSchema } from './request-context.js';
6
6
  import type { SecurityScheme } from './security-scheme.js';
7
7
  import type { PluginArgs, PluginList, PluginsBySlug } from './plugin.js';
8
- import type { TagOptions, TagSet } from './tags.js';
8
+ import type { GroupOptions, GroupSet } from './groups.js';
9
9
  import type { z } from 'zod';
10
10
 
11
11
  /**
@@ -18,7 +18,7 @@ import type { z } from 'zod';
18
18
  * // src/kizuna.types.ts, generated
19
19
  * export interface Config {
20
20
  * adapter: ReturnType<typeof expressAdapter>;
21
- * tags: typeof tags;
21
+ * groups: typeof groups;
22
22
  * auth: { identities: { user: typeof user } };
23
23
  * jobs: typeof jobs;
24
24
  * }
@@ -26,7 +26,7 @@ import type { z } from 'zod';
26
26
  */
27
27
  export interface KizunaConfigShape {
28
28
  adapter?: unknown;
29
- tags?: unknown;
29
+ groups?: unknown;
30
30
  auth?: {
31
31
  identities?: unknown;
32
32
  guardSchema?: unknown;
@@ -66,9 +66,12 @@ export type JobsOfTree<Tree> = {
66
66
  : JobsOfTree<Tree[Key]>;
67
67
  };
68
68
 
69
- export type ConfiguredTags<Config> = Config extends { tags: TagSet<infer Tags extends Record<string, TagOptions>> }
70
- ? Tags
71
- : Record<string, never>;
69
+ /**
70
+ * The groups a config declares, or none.
71
+ */
72
+ export type ConfiguredGroups<Config> = Config extends { groups: GroupSet<infer Groups extends Record<string, GroupOptions | string>> }
73
+ ? Groups
74
+ : {};
72
75
  export type ConfiguredCodes<Config> = Config extends { validation: { issueCodes: infer Codes extends string } } ? Codes : never;
73
76
  export type ConfiguredIdentities<Config> = Config extends { auth: { identities: infer Identities extends Record<string, SecurityScheme> } }
74
77
  ? Identities
@@ -85,5 +88,9 @@ export type ConfiguredJobs<Config> = Config extends { jobs: infer Tree } ? { job
85
88
  export type ConfiguredPlugins<Config> = Config extends { plugins: infer Plugins extends PluginList }
86
89
  ? PluginArgs<PluginsBySlug<Plugins>>
87
90
  : {};
91
+ /**
92
+ * The api's jobs and plugins, for a plugin that runs the app's own functions.
93
+ */
94
+ export type ApiContext<Config> = ConfiguredJobs<Config> & ConfiguredPlugins<Config>;
88
95
  export type ConfiguredAdapterContext<Config> = HandlerContextOf<ConfiguredAdapterValue<Config>>;
89
96
  export type ConfiguredRequestContext<Config> = RequestContextValues<ConfiguredRequestContextSchemas<Config>>;
@@ -1,13 +1,16 @@
1
1
  import type { z } from 'zod';
2
2
  import { buildApiDefinition, type ApiDefinition } from './api-definition.js';
3
- import { pluginRouteTree, pluginsBySlug, type PluginArgs, type PluginList, type PluginsBySlug } from './plugin.js';
3
+ import { pluginRouteTree, type PluginArgs, type PluginList, type PluginsBySlug } from './plugin.js';
4
+ import { createApiReference, resolvePlugins } from './plugin-server.js';
4
5
  import { assertNoPathCollisions, routeClaims } from './path-claims.js';
5
6
  import { assertValidDeprecationDates } from './deprecation.js';
6
7
  import { assertValidCache } from './cache.js';
7
8
  import { injectGuardResponses } from './guard-responses.js';
8
9
  import { flattenRoutes, type RoutesWithHandlerContext } from './handler-pipeline.js';
9
- import { jobClaims, type Jobs, type JobsArg, type JobRunnerConfig } from './jobs.js';
10
- import type { TagOptions, TagSet } from './tags.js';
10
+ import { assertJobRunner, jobClaims, type Jobs, type JobsArg, type JobRunnerConfig } from './jobs.js';
11
+ import type { GroupOptions, GroupSet } from './groups.js';
12
+ import type { AssembledRoutes } from './group-routes.js';
13
+ import { assembleRoutes } from './routes.js';
11
14
  import { problemDetails, type GuardBody, type GuardOutput, type GuardSchemaCheck } from './problem-details.js';
12
15
  import { readObjectShape } from './zod-internals.js';
13
16
  import type { Routes, RouteDefinition, RouteAuth, SecurityRequirement, RequiredPermissions } from './types.js';
@@ -18,7 +21,7 @@ import { permissionNames } from './permissions.js';
18
21
  import { GUARD } from './identity-builder.js';
19
22
  import { RESOLVER } from './request-context-builder.js';
20
23
  import { buildApi, type Api } from './api.js';
21
- import type { ClientTarget } from './config.js';
24
+ import type { DiffSettings, GeneratedFile } from './config.js';
22
25
 
23
26
  /**
24
27
  * Kizuna sends the guard body itself when a route's `requires` turns a caller
@@ -144,15 +147,31 @@ const handlersOf = (declarations: Record<string, unknown> | undefined, key: stri
144
147
  return handlers;
145
148
  };
146
149
 
150
+ /**
151
+ * Throw on a route in a group the config does not declare.
152
+ */
153
+ const assertDeclaredGroups = (routes: Routes, groups: GroupSet | undefined): void => {
154
+ for (const { routeKey, routeGroups } of flattenRoutes(routes)) {
155
+ for (const group of routeGroups) {
156
+ if (groups?.groups.has(group)) continue;
157
+ throw new Error(
158
+ groups === undefined
159
+ ? `Route '${routeKey}' is filed under the group '${group}', but the config declares no groups. Pass \`groups\` to defineConfig.`
160
+ : `Route '${routeKey}' is filed under the group '${group}', which \`groups\` does not declare.`
161
+ );
162
+ }
163
+ }
164
+ };
165
+
147
166
  /**
148
167
  * What one API is made of. Everything kizuna knows about an API is written
149
168
  * here: what it declares, and what serves it.
150
169
  */
151
170
  export type KizunaConfigInput<
152
- R extends Routes,
171
+ R extends readonly Routes[],
153
172
  J extends Jobs,
154
173
  P extends PluginList,
155
- Tags extends Record<string, TagOptions>,
174
+ Groups extends Record<string, GroupOptions | string>,
156
175
  Codes extends string,
157
176
  Identities extends Record<string, SecurityScheme>,
158
177
  RequestContext extends Record<string, RequestContextSchema>,
@@ -169,8 +188,10 @@ export type KizunaConfigInput<
169
188
  */
170
189
  adapter?: AdapterValue;
171
190
  /**
172
- * The route groups this API answers, as `k.routes` returned them. Omit it
173
- * while setting up, before there is a route to name.
191
+ * What `k.routes` returned, as a list in any order.
192
+ *
193
+ * @example
194
+ * routes: [userRoutes, memberRoutes, healthRoutes],
174
195
  */
175
196
  routes?: R;
176
197
  jobs?: J;
@@ -182,7 +203,10 @@ export type KizunaConfigInput<
182
203
  * plugins: [mcpPlugin({ name: 'workspace' }), openApiPlugin({ info })],
183
204
  */
184
205
  plugins?: P;
185
- tags?: TagSet<Tags>;
206
+ /**
207
+ * The groups from `k.groups`.
208
+ */
209
+ groups?: GroupSet<Groups>;
186
210
  /**
187
211
  * Who may call this API: the identities a route's `auth` names, and the
188
212
  * body their guards refuse with.
@@ -221,13 +245,6 @@ export type KizunaConfigInput<
221
245
  */
222
246
  issueCodes?: readonly Codes[];
223
247
  };
224
- /**
225
- * How this deployment runs the jobs it declares: where the two endpoints
226
- * sit, what carries queued work out of the process, and where a failure is
227
- * reported. The jobs themselves are declared with `k.jobs` and go under
228
- * `jobs`.
229
- */
230
- jobRunner?: JobRunnerConfig;
231
248
  /**
232
249
  * What `kizuna generate` writes the `Config` to.
233
250
  *
@@ -250,18 +267,44 @@ export type KizunaConfigInput<
250
267
  * }),
251
268
  * ],
252
269
  */
253
- clients?: readonly ClientTarget[];
254
- };
270
+ clients?: readonly GeneratedFile[];
271
+ /**
272
+ * What else `kizuna diff` treats as breaking.
273
+ *
274
+ * @example
275
+ * diff: {
276
+ * dottedKeys: true,
277
+ * }
278
+ */
279
+ diff?: DiffSettings;
280
+ } & JobRunnerInput<J>;
281
+
282
+ /**
283
+ * `jobRunner`, required once `jobs` declares one.
284
+ */
285
+ type JobRunnerInput<J extends Jobs> = string extends keyof J
286
+ ? {
287
+ jobRunner?: JobRunnerConfig;
288
+ }
289
+ : {
290
+ /**
291
+ * How this deployment runs the jobs it declares: over HTTP or in
292
+ * process, what carries queued work out of the process, and where a
293
+ * failure is reported. The jobs themselves are declared with
294
+ * `k.jobs` and go under `jobs`.
295
+ */
296
+ jobRunner: JobRunnerConfig;
297
+ };
255
298
 
256
299
  /**
257
300
  * The api `defineConfig` assembles: the routes it declares, and the `mount`
258
301
  * that serves it.
259
302
  */
260
303
  export type ConfiguredApi<
261
- R extends Routes,
304
+ R extends readonly Routes[],
262
305
  J extends Jobs,
263
306
  P extends PluginList,
264
- Tags extends Record<string, TagOptions>,
307
+ Groups extends Record<string, GroupOptions | string>,
265
308
  Codes extends string,
266
309
  Identities extends Record<string, SecurityScheme>,
267
310
  RequestContext extends Record<string, RequestContextSchema>,
@@ -270,14 +313,14 @@ export type ConfiguredApi<
270
313
  > = Api<
271
314
  ApiDefinition<
272
315
  RoutesWithHandlerContext<
273
- R,
316
+ AssembledRoutes<R>,
274
317
  Identities,
275
318
  RequestContext,
276
319
  PluginArgs<PluginsBySlug<P>> & JobsArg<J>,
277
320
  GuardOutput<GuardSchema>,
278
321
  GuardBody<GuardSchema>
279
322
  >,
280
- Tags,
323
+ Groups,
281
324
  Codes,
282
325
  Identities,
283
326
  RequestContext,
@@ -306,37 +349,60 @@ export type ConfiguredApi<
306
349
  * });
307
350
  */
308
351
  export const defineConfig = <
309
- const R extends Routes = Record<string, never>,
352
+ const R extends readonly Routes[] = readonly [],
310
353
  const J extends Jobs = Record<string, never>,
311
354
  const P extends PluginList = readonly [],
312
- const Tags extends Record<string, TagOptions> = Record<string, never>,
355
+ const Groups extends Record<string, GroupOptions | string> = {},
313
356
  const Codes extends string = never,
314
357
  const Identities extends Record<string, SecurityScheme> = Record<string, never>,
315
358
  const RequestContext extends Record<string, RequestContextSchema> = Record<string, never>,
316
359
  GuardSchema extends z.ZodType | undefined = undefined,
317
360
  const AdapterValue extends AnyAdapter | undefined = undefined,
318
361
  >(
319
- options: KizunaConfigInput<R, J, P, Tags, Codes, Identities, RequestContext, GuardSchema, AdapterValue>
362
+ options: KizunaConfigInput<R, J, P, Groups, Codes, Identities, RequestContext, GuardSchema, AdapterValue>
320
363
  ): {
321
- api: ConfiguredApi<R, J, P, Tags, Codes, Identities, RequestContext, GuardSchema, AdapterValue>;
322
- clients: readonly ClientTarget[];
364
+ api: ConfiguredApi<R, J, P, Groups, Codes, Identities, RequestContext, GuardSchema, AdapterValue>;
365
+ clients: readonly GeneratedFile[];
366
+ generators: readonly GeneratedFile[];
323
367
  typescript: { outputFile?: string } | undefined;
368
+ diff: DiffSettings | undefined;
324
369
  } => {
325
370
  const guardSchema = options.auth?.guardSchema;
326
371
  if (guardSchema) assertFillableGuardSchema(guardSchema);
327
372
 
328
- const routes = (options.routes ?? {}) as Routes;
373
+ const routes = assembleRoutes((options.routes ?? []) as readonly Routes[]);
329
374
  const jobs = options.jobs as Jobs | undefined;
330
375
  const identities = options.auth?.identities as Record<string, SecurityScheme> | undefined;
331
- const plugins = pluginsBySlug(options.plugins);
376
+ const apiReference = createApiReference();
377
+ const plugins = resolvePlugins(options.plugins, apiReference.api);
378
+ const pluginRoutes = pluginRouteTree(plugins);
332
379
 
333
- assertNoPathCollisions([
334
- ...routeClaims(routes),
335
- ...routeClaims(pluginRouteTree(plugins), 'Plugin route'),
336
- ...jobClaims(jobs, options.jobRunner),
337
- ]);
380
+ assertNoPathCollisions([...routeClaims(routes), ...routeClaims(pluginRoutes, 'Plugin route'), ...jobClaims(jobs, options.jobRunner)]);
381
+ assertJobRunner(jobs, options.jobRunner);
338
382
  assertValidDeprecationDates(routes);
339
- assertValidDeprecationDates(pluginRouteTree(plugins));
383
+ assertValidDeprecationDates(pluginRoutes);
384
+ assertDeclaredGroups(routes, options.groups as GroupSet | undefined);
385
+
386
+ for (const { route, routeKey } of flattenRoutes(pluginRoutes)) {
387
+ if (route.tool !== undefined && route.tool !== false) {
388
+ throw new Error(`Plugin route '${routeKey}' declares \`tool\`. Plugin routes are hidden, so they never publish.`);
389
+ }
390
+ // Plugin routes are for outside callers, so none reaches the clients, the OpenAPI document or MCP.
391
+ (route as { hidden?: boolean }).hidden = true;
392
+ }
393
+
394
+ for (const { route, routeKey } of [...flattenRoutes(routes), ...flattenRoutes(pluginRoutes)]) {
395
+ if (route.hidden === true && route.tool !== undefined && route.tool !== false) {
396
+ throw new Error(
397
+ `Route '${routeKey}' is \`hidden\` and declares \`tool\`. A hidden route never publishes, so remove one of them.`
398
+ );
399
+ }
400
+ if (route.rawBody === true && route.contentType === 'multipart/form-data') {
401
+ throw new Error(
402
+ `Route '${routeKey}' declares \`rawBody\` on a \`multipart/form-data\` body. A multipart body is read as a stream of parts, so kizuna cannot keep it as text. Remove \`rawBody\`, or take the body as JSON.`
403
+ );
404
+ }
405
+ }
340
406
 
341
407
  const declaresIdentities = Object.keys(identities ?? {}).length > 0;
342
408
  for (const { route, routeKey } of flattenRoutes(routes)) {
@@ -351,20 +417,29 @@ export const defineConfig = <
351
417
  }
352
418
  resolveRouteAuth(route, route.auth, identities, routeKey);
353
419
  }
420
+ // A plugin route with no `auth` is public: the plugin can't know the app's identities, so one it needs comes in through its options.
421
+ for (const { route, routeKey } of flattenRoutes(pluginRoutes)) {
422
+ if (route.auth === undefined) {
423
+ route.security = [];
424
+ continue;
425
+ }
426
+ resolveRouteAuth(route, route.auth, identities, routeKey);
427
+ }
354
428
  // After every route's `auth` resolves, so both of these can read `security`.
355
429
  injectGuardResponses(routes, identities, guardSchema);
430
+ injectGuardResponses(pluginRoutes, identities, guardSchema);
356
431
  assertValidCache(routes);
357
- assertValidCache(pluginRouteTree(plugins));
432
+ assertValidCache(pluginRoutes);
358
433
 
359
434
  const contract = buildApiDefinition({
360
435
  routes,
361
436
  jobs,
362
- tags: options.tags as TagSet<Record<string, TagOptions>> | undefined,
437
+ groups: options.groups as GroupSet | undefined,
363
438
  securitySchemes: identities,
364
439
  guardSchema,
365
440
  requestContext: options.requestContext as Record<string, RequestContextSchema> | undefined,
366
441
  validation: options.validation?.issueCodes ? { issueCodes: options.validation.issueCodes } : undefined,
367
- plugins,
442
+ plugins: plugins as never,
368
443
  jobsConfig: options.jobRunner,
369
444
  }) as ApiDefinition;
370
445
 
@@ -385,11 +460,15 @@ export const defineConfig = <
385
460
  onJobError: options.jobRunner?.onError,
386
461
  },
387
462
  options.adapter
388
- ) as unknown as ConfiguredApi<R, J, P, Tags, Codes, Identities, RequestContext, GuardSchema, AdapterValue>;
463
+ ) as unknown as ConfiguredApi<R, J, P, Groups, Codes, Identities, RequestContext, GuardSchema, AdapterValue>;
464
+ apiReference.bind(api);
465
+ for (const plugin of Object.values(plugins)) plugin.validate?.();
389
466
 
390
467
  return {
391
468
  api,
392
469
  clients: options.clients ?? [],
470
+ generators: Object.values(plugins).flatMap((plugin) => plugin.generators),
471
+ diff: options.diff,
393
472
  typescript: options.typescript,
394
473
  };
395
474
  };