@mandujs/core 0.9.39 → 0.9.41

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.ko.md +27 -0
  2. package/README.md +21 -5
  3. package/package.json +1 -1
  4. package/src/config/index.ts +1 -0
  5. package/src/config/mandu.ts +60 -0
  6. package/src/contract/client-safe.test.ts +42 -0
  7. package/src/contract/client-safe.ts +114 -0
  8. package/src/contract/client.ts +12 -11
  9. package/src/contract/handler.ts +10 -11
  10. package/src/contract/index.ts +25 -16
  11. package/src/contract/registry.test.ts +206 -0
  12. package/src/contract/registry.ts +568 -0
  13. package/src/contract/schema.ts +48 -12
  14. package/src/contract/types.ts +58 -35
  15. package/src/contract/validator.ts +32 -17
  16. package/src/filling/context.ts +103 -0
  17. package/src/generator/templates.ts +70 -17
  18. package/src/guard/analyzer.ts +9 -4
  19. package/src/guard/check.ts +66 -30
  20. package/src/guard/contract-guard.ts +9 -9
  21. package/src/guard/file-type.test.ts +24 -0
  22. package/src/guard/presets/index.ts +193 -60
  23. package/src/guard/rules.ts +12 -6
  24. package/src/guard/statistics.ts +6 -0
  25. package/src/guard/suggestions.ts +9 -2
  26. package/src/guard/types.ts +11 -1
  27. package/src/guard/validator.ts +160 -9
  28. package/src/guard/watcher.ts +2 -0
  29. package/src/index.ts +8 -1
  30. package/src/runtime/index.ts +1 -0
  31. package/src/runtime/streaming-ssr.ts +123 -2
  32. package/src/seo/index.ts +214 -0
  33. package/src/seo/integration/ssr.ts +307 -0
  34. package/src/seo/render/basic.ts +427 -0
  35. package/src/seo/render/index.ts +143 -0
  36. package/src/seo/render/jsonld.ts +539 -0
  37. package/src/seo/render/opengraph.ts +191 -0
  38. package/src/seo/render/robots.ts +116 -0
  39. package/src/seo/render/sitemap.ts +137 -0
  40. package/src/seo/render/twitter.ts +126 -0
  41. package/src/seo/resolve/index.ts +353 -0
  42. package/src/seo/resolve/opengraph.ts +143 -0
  43. package/src/seo/resolve/robots.ts +73 -0
  44. package/src/seo/resolve/title.ts +94 -0
  45. package/src/seo/resolve/twitter.ts +73 -0
  46. package/src/seo/resolve/url.ts +97 -0
  47. package/src/seo/routes/index.ts +290 -0
  48. package/src/seo/types.ts +575 -0
  49. package/src/slot/validator.ts +39 -16
@@ -0,0 +1,568 @@
1
+ /**
2
+ * Mandu Contract Registry
3
+ * Build-time contract index for tooling, docs, and guard
4
+ */
5
+
6
+ import type { RoutesManifest } from "../spec/schema";
7
+ import type { ContractSchema, MethodRequestSchema } from "./schema";
8
+ import path from "path";
9
+ import { createHash } from "crypto";
10
+
11
+ const HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"] as const;
12
+
13
+ export interface ContractRegistryEntry {
14
+ id: string;
15
+ routeId: string;
16
+ file: string;
17
+ methods: string[];
18
+ request: Record<string, {
19
+ query: boolean;
20
+ body: boolean;
21
+ params: boolean;
22
+ headers: boolean;
23
+ }>;
24
+ response: number[];
25
+ schemas?: {
26
+ request?: Record<string, {
27
+ query?: SchemaSummary;
28
+ body?: SchemaSummary;
29
+ params?: SchemaSummary;
30
+ headers?: SchemaSummary;
31
+ }>;
32
+ response?: Record<number, SchemaSummary | undefined>;
33
+ };
34
+ hash: string | null;
35
+ description?: string;
36
+ tags?: string[];
37
+ normalize?: ContractSchema["normalize"];
38
+ coerceQueryParams?: ContractSchema["coerceQueryParams"];
39
+ version?: string;
40
+ meta?: Record<string, unknown>;
41
+ }
42
+
43
+ export type SchemaSummary =
44
+ | {
45
+ type: "object";
46
+ keys: string[];
47
+ required: string[];
48
+ }
49
+ | {
50
+ type: "enum";
51
+ values: Array<string | number>;
52
+ }
53
+ | {
54
+ type: "literal";
55
+ value: string | number | boolean | null;
56
+ }
57
+ | {
58
+ type: "other";
59
+ typeName?: string;
60
+ };
61
+
62
+ export interface ContractRegistry {
63
+ version: 1;
64
+ generatedAt: string;
65
+ contracts: ContractRegistryEntry[];
66
+ }
67
+
68
+ export interface ContractRegistryResult {
69
+ registry: ContractRegistry;
70
+ warnings: string[];
71
+ }
72
+
73
+ export interface ContractRegistryChange {
74
+ id: string;
75
+ routeId: string;
76
+ severity: "major" | "minor" | "patch";
77
+ changes: string[];
78
+ before?: ContractRegistryEntry;
79
+ after?: ContractRegistryEntry;
80
+ }
81
+
82
+ export interface ContractRegistryDiff {
83
+ added: ContractRegistryEntry[];
84
+ removed: ContractRegistryEntry[];
85
+ changed: ContractRegistryChange[];
86
+ summary: {
87
+ major: number;
88
+ minor: number;
89
+ patch: number;
90
+ };
91
+ }
92
+
93
+ async function loadContract(contractPath: string, rootDir: string): Promise<ContractSchema | null> {
94
+ try {
95
+ const fullPath = path.join(rootDir, contractPath);
96
+ const module = await import(fullPath);
97
+ return module.default ?? null;
98
+ } catch {
99
+ return null;
100
+ }
101
+ }
102
+
103
+ async function computeFileHash(filePath: string): Promise<string | null> {
104
+ try {
105
+ const content = await Bun.file(filePath).text();
106
+ return createHash("sha256").update(content).digest("hex");
107
+ } catch {
108
+ return null;
109
+ }
110
+ }
111
+
112
+ function extractRequestInfo(contract: ContractSchema): ContractRegistryEntry["request"] {
113
+ const requestInfo: ContractRegistryEntry["request"] = {};
114
+
115
+ for (const method of HTTP_METHODS) {
116
+ const methodSchema = contract.request[method] as MethodRequestSchema | undefined;
117
+ if (!methodSchema) continue;
118
+
119
+ requestInfo[method] = {
120
+ query: Boolean(methodSchema.query),
121
+ body: Boolean(methodSchema.body),
122
+ params: Boolean(methodSchema.params),
123
+ headers: Boolean(methodSchema.headers),
124
+ };
125
+ }
126
+
127
+ return requestInfo;
128
+ }
129
+
130
+ function unwrapSchema(schema: any): any {
131
+ let current = schema;
132
+ let depth = 0;
133
+
134
+ while (current && current._def && depth < 10) {
135
+ const typeName = current._def.typeName as string | undefined;
136
+ if (typeName === "ZodOptional" || typeName === "ZodDefault") {
137
+ current = current._def.innerType;
138
+ } else if (typeName === "ZodEffects") {
139
+ current = current._def.schema;
140
+ } else if (typeName === "ZodNullable") {
141
+ current = current._def.innerType;
142
+ } else if (typeName === "ZodBranded" || typeName === "ZodCatch") {
143
+ current = current._def.type;
144
+ } else {
145
+ break;
146
+ }
147
+ depth += 1;
148
+ }
149
+
150
+ return current;
151
+ }
152
+
153
+ function isOptionalSchema(schema: any): boolean {
154
+ let current = schema;
155
+ let depth = 0;
156
+ while (current && current._def && depth < 10) {
157
+ const typeName = current._def.typeName as string | undefined;
158
+ if (typeName === "ZodOptional" || typeName === "ZodDefault") {
159
+ return true;
160
+ }
161
+ if (typeName === "ZodEffects" || typeName === "ZodNullable" || typeName === "ZodBranded" || typeName === "ZodCatch") {
162
+ current = current._def.schema ?? current._def.innerType ?? current._def.type;
163
+ depth += 1;
164
+ continue;
165
+ }
166
+ break;
167
+ }
168
+ return false;
169
+ }
170
+
171
+ function summarizeSchema(schema: any): SchemaSummary | undefined {
172
+ if (!schema || !schema._def) return undefined;
173
+
174
+ const base = unwrapSchema(schema);
175
+ const def = base?._def;
176
+ if (!def) return undefined;
177
+
178
+ const typeName = def.typeName as string | undefined;
179
+
180
+ if (typeName === "ZodObject") {
181
+ const shape = typeof def.shape === "function" ? def.shape() : def.shape;
182
+ const keys = Object.keys(shape ?? {}).sort();
183
+ const required = keys.filter((key) => !isOptionalSchema(shape[key]));
184
+ return {
185
+ type: "object",
186
+ keys,
187
+ required: required.sort(),
188
+ };
189
+ }
190
+
191
+ if (typeName === "ZodEnum") {
192
+ const values = Array.isArray(def.values) ? def.values.slice() : [];
193
+ values.sort();
194
+ return {
195
+ type: "enum",
196
+ values,
197
+ };
198
+ }
199
+
200
+ if (typeName === "ZodNativeEnum") {
201
+ const rawValues = def.values ? Object.values(def.values) : [];
202
+ const values = rawValues.filter((v: any) => typeof v === "string" || typeof v === "number");
203
+ values.sort();
204
+ return {
205
+ type: "enum",
206
+ values,
207
+ };
208
+ }
209
+
210
+ if (typeName === "ZodLiteral") {
211
+ return {
212
+ type: "literal",
213
+ value: def.value as any,
214
+ };
215
+ }
216
+
217
+ return {
218
+ type: "other",
219
+ typeName,
220
+ };
221
+ }
222
+
223
+ function extractSchemaSummaries(contract: ContractSchema): ContractRegistryEntry["schemas"] {
224
+ const request: Record<string, any> = {};
225
+ const response: Record<number, SchemaSummary> = {};
226
+
227
+ for (const method of HTTP_METHODS) {
228
+ const methodSchema = contract.request[method] as MethodRequestSchema | undefined;
229
+ if (!methodSchema) continue;
230
+
231
+ request[method] = {
232
+ query: methodSchema.query ? summarizeSchema(methodSchema.query) : undefined,
233
+ body: methodSchema.body ? summarizeSchema(methodSchema.body) : undefined,
234
+ params: methodSchema.params ? summarizeSchema(methodSchema.params) : undefined,
235
+ headers: methodSchema.headers ? summarizeSchema(methodSchema.headers) : undefined,
236
+ };
237
+ }
238
+
239
+ for (const [statusCode, schema] of Object.entries(contract.response)) {
240
+ const code = Number(statusCode);
241
+ if (Number.isNaN(code)) continue;
242
+ if (!schema) continue;
243
+
244
+ const actualSchema = (schema as any).schema ?? schema;
245
+ response[code] = summarizeSchema(actualSchema);
246
+ }
247
+
248
+ return {
249
+ request,
250
+ response,
251
+ };
252
+ }
253
+
254
+ function extractMethods(contract: ContractSchema): string[] {
255
+ return HTTP_METHODS.filter((method) => Boolean(contract.request[method]));
256
+ }
257
+
258
+ function extractResponseCodes(contract: ContractSchema): number[] {
259
+ return Object.keys(contract.response)
260
+ .filter((key) => /^\d+$/.test(key))
261
+ .map((key) => Number(key))
262
+ .sort((a, b) => a - b);
263
+ }
264
+
265
+ export async function buildContractRegistry(
266
+ manifest: RoutesManifest,
267
+ rootDir: string
268
+ ): Promise<ContractRegistryResult> {
269
+ const warnings: string[] = [];
270
+ const contracts: ContractRegistryEntry[] = [];
271
+
272
+ for (const route of manifest.routes) {
273
+ if (!route.contractModule) continue;
274
+
275
+ const contract = await loadContract(route.contractModule, rootDir);
276
+ if (!contract) {
277
+ warnings.push(`Failed to load contract: ${route.contractModule} (routeId: ${route.id})`);
278
+ continue;
279
+ }
280
+
281
+ const contractPath = path.join(rootDir, route.contractModule);
282
+ const hash = await computeFileHash(contractPath);
283
+ const id = contract.name ?? route.id;
284
+
285
+ contracts.push({
286
+ id,
287
+ routeId: route.id,
288
+ file: route.contractModule,
289
+ methods: extractMethods(contract),
290
+ request: extractRequestInfo(contract),
291
+ response: extractResponseCodes(contract),
292
+ schemas: extractSchemaSummaries(contract),
293
+ hash,
294
+ description: contract.description,
295
+ tags: contract.tags,
296
+ normalize: contract.normalize,
297
+ coerceQueryParams: contract.coerceQueryParams,
298
+ version: contract.version,
299
+ meta: contract.meta,
300
+ });
301
+ }
302
+
303
+ return {
304
+ registry: {
305
+ version: 1,
306
+ generatedAt: new Date().toISOString(),
307
+ contracts,
308
+ },
309
+ warnings,
310
+ };
311
+ }
312
+
313
+ export async function writeContractRegistry(
314
+ registryPath: string,
315
+ registry: ContractRegistry
316
+ ): Promise<void> {
317
+ await Bun.write(registryPath, JSON.stringify(registry, null, 2));
318
+ }
319
+
320
+ export async function readContractRegistry(
321
+ registryPath: string
322
+ ): Promise<ContractRegistry | null> {
323
+ try {
324
+ const file = Bun.file(registryPath);
325
+ const exists = await file.exists();
326
+ if (!exists) return null;
327
+ const content = await file.text();
328
+ return JSON.parse(content) as ContractRegistry;
329
+ } catch {
330
+ return null;
331
+ }
332
+ }
333
+
334
+ function diffArray<T>(prev: T[], next: T[]): { added: T[]; removed: T[] } {
335
+ const prevSet = new Set(prev);
336
+ const nextSet = new Set(next);
337
+ const added = next.filter((item) => !prevSet.has(item));
338
+ const removed = prev.filter((item) => !nextSet.has(item));
339
+ return { added, removed };
340
+ }
341
+
342
+ function diffRequestShapes(
343
+ prev: ContractRegistryEntry["request"],
344
+ next: ContractRegistryEntry["request"]
345
+ ): { major: string[]; minor: string[] } {
346
+ const major: string[] = [];
347
+ const minor: string[] = [];
348
+ const methods = new Set([...Object.keys(prev), ...Object.keys(next)]);
349
+
350
+ for (const method of methods) {
351
+ const before = prev[method];
352
+ const after = next[method];
353
+ if (!before || !after) continue;
354
+
355
+ for (const key of ["query", "body", "params", "headers"] as const) {
356
+ const beforeHas = Boolean(before[key]);
357
+ const afterHas = Boolean(after[key]);
358
+ if (beforeHas && !afterHas) {
359
+ major.push(`${method}.${key} removed`);
360
+ } else if (!beforeHas && afterHas) {
361
+ minor.push(`${method}.${key} added`);
362
+ }
363
+ }
364
+ }
365
+
366
+ return { major, minor };
367
+ }
368
+
369
+ function diffSchemaSummary(
370
+ prev?: SchemaSummary,
371
+ next?: SchemaSummary
372
+ ): { major: string[]; minor: string[] } {
373
+ if (!prev || !next) return { major: [], minor: [] };
374
+
375
+ if (prev.type !== next.type) {
376
+ return {
377
+ major: [`schema type changed: ${prev.type} -> ${next.type}`],
378
+ minor: [],
379
+ };
380
+ }
381
+
382
+ if (prev.type === "object" && next.type === "object") {
383
+ const prevKeys = new Set(prev.keys);
384
+ const nextKeys = new Set(next.keys);
385
+
386
+ const removed = prev.keys.filter((k) => !nextKeys.has(k));
387
+ const added = next.keys.filter((k) => !prevKeys.has(k));
388
+
389
+ const prevRequired = new Set(prev.required);
390
+ const nextRequired = new Set(next.required);
391
+
392
+ const major: string[] = [];
393
+ const minor: string[] = [];
394
+
395
+ if (removed.length > 0) {
396
+ major.push(`fields removed: ${removed.join(", ")}`);
397
+ }
398
+ if (added.length > 0) {
399
+ minor.push(`fields added: ${added.join(", ")}`);
400
+ }
401
+
402
+ for (const key of prev.keys) {
403
+ if (!nextKeys.has(key)) continue;
404
+ const wasRequired = prevRequired.has(key);
405
+ const nowRequired = nextRequired.has(key);
406
+ if (wasRequired && !nowRequired) {
407
+ minor.push(`field optionalized: ${key}`);
408
+ } else if (!wasRequired && nowRequired) {
409
+ major.push(`field required: ${key}`);
410
+ }
411
+ }
412
+
413
+ return { major, minor };
414
+ }
415
+
416
+ if (prev.type === "enum" && next.type === "enum") {
417
+ const prevValues = new Set(prev.values.map(String));
418
+ const nextValues = new Set(next.values.map(String));
419
+ const removed = prev.values.filter((v) => !nextValues.has(String(v)));
420
+ const added = next.values.filter((v) => !prevValues.has(String(v)));
421
+ return {
422
+ major: removed.length > 0 ? [`enum values removed: ${removed.join(", ")}`] : [],
423
+ minor: added.length > 0 ? [`enum values added: ${added.join(", ")}`] : [],
424
+ };
425
+ }
426
+
427
+ if (prev.type === "literal" && next.type === "literal") {
428
+ if (prev.value !== next.value) {
429
+ return { major: [`literal changed: ${String(prev.value)} -> ${String(next.value)}`], minor: [] };
430
+ }
431
+ }
432
+
433
+ if (prev.type === "other" && next.type === "other") {
434
+ if (prev.typeName !== next.typeName) {
435
+ return { major: [`schema changed: ${prev.typeName ?? "unknown"} -> ${next.typeName ?? "unknown"}`], minor: [] };
436
+ }
437
+ }
438
+
439
+ return { major: [], minor: [] };
440
+ }
441
+
442
+ export function diffContractRegistry(
443
+ prev: ContractRegistry,
444
+ next: ContractRegistry
445
+ ): ContractRegistryDiff {
446
+ const prevMap = new Map(prev.contracts.map((c) => [c.id, c]));
447
+ const nextMap = new Map(next.contracts.map((c) => [c.id, c]));
448
+
449
+ const added: ContractRegistryEntry[] = [];
450
+ const removed: ContractRegistryEntry[] = [];
451
+ const changed: ContractRegistryChange[] = [];
452
+
453
+ for (const [id, nextEntry] of nextMap.entries()) {
454
+ const prevEntry = prevMap.get(id);
455
+ if (!prevEntry) {
456
+ added.push(nextEntry);
457
+ continue;
458
+ }
459
+
460
+ const changes: string[] = [];
461
+ let severity: ContractRegistryChange["severity"] = "patch";
462
+
463
+ const methodDiff = diffArray(prevEntry.methods, nextEntry.methods);
464
+ if (methodDiff.removed.length > 0) {
465
+ changes.push(`methods removed: ${methodDiff.removed.join(", ")}`);
466
+ severity = "major";
467
+ }
468
+ if (methodDiff.added.length > 0) {
469
+ changes.push(`methods added: ${methodDiff.added.join(", ")}`);
470
+ if (severity !== "major") severity = "minor";
471
+ }
472
+
473
+ const responseDiff = diffArray(prevEntry.response, nextEntry.response);
474
+ if (responseDiff.removed.length > 0) {
475
+ changes.push(`responses removed: ${responseDiff.removed.join(", ")}`);
476
+ severity = "major";
477
+ }
478
+ if (responseDiff.added.length > 0) {
479
+ changes.push(`responses added: ${responseDiff.added.join(", ")}`);
480
+ if (severity !== "major") severity = "minor";
481
+ }
482
+
483
+ const requestDiff = diffRequestShapes(prevEntry.request, nextEntry.request);
484
+ if (requestDiff.major.length > 0) {
485
+ changes.push(...requestDiff.major);
486
+ severity = "major";
487
+ }
488
+ if (requestDiff.minor.length > 0) {
489
+ changes.push(...requestDiff.minor);
490
+ if (severity !== "major") severity = "minor";
491
+ }
492
+
493
+ const prevReqSchemas = prevEntry.schemas?.request ?? {};
494
+ const nextReqSchemas = nextEntry.schemas?.request ?? {};
495
+ for (const method of Object.keys(prevReqSchemas)) {
496
+ if (!nextReqSchemas[method]) continue;
497
+ const prevParts = prevReqSchemas[method] ?? {};
498
+ const nextParts = nextReqSchemas[method] ?? {};
499
+ for (const part of ["query", "body", "params", "headers"] as const) {
500
+ if (!prevParts[part] || !nextParts[part]) continue;
501
+ const diff = diffSchemaSummary(prevParts[part], nextParts[part]);
502
+ if (diff.major.length > 0) {
503
+ changes.push(...diff.major.map((msg) => `${method}.${part}: ${msg}`));
504
+ severity = "major";
505
+ }
506
+ if (diff.minor.length > 0) {
507
+ changes.push(...diff.minor.map((msg) => `${method}.${part}: ${msg}`));
508
+ if (severity !== "major") severity = "minor";
509
+ }
510
+ }
511
+ }
512
+
513
+ const prevResSchemas = prevEntry.schemas?.response ?? {};
514
+ const nextResSchemas = nextEntry.schemas?.response ?? {};
515
+ for (const [code, prevSchema] of Object.entries(prevResSchemas)) {
516
+ const status = Number(code);
517
+ const nextSchema = nextResSchemas[status];
518
+ if (!nextSchema) continue;
519
+ const diff = diffSchemaSummary(prevSchema, nextSchema);
520
+ if (diff.major.length > 0) {
521
+ changes.push(...diff.major.map((msg) => `response.${status}: ${msg}`));
522
+ severity = "major";
523
+ }
524
+ if (diff.minor.length > 0) {
525
+ changes.push(...diff.minor.map((msg) => `response.${status}: ${msg}`));
526
+ if (severity !== "major") severity = "minor";
527
+ }
528
+ }
529
+
530
+ if (prevEntry.description !== nextEntry.description) {
531
+ changes.push("description changed");
532
+ }
533
+ if (JSON.stringify(prevEntry.tags ?? []) !== JSON.stringify(nextEntry.tags ?? [])) {
534
+ changes.push("tags changed");
535
+ }
536
+ if (prevEntry.version !== nextEntry.version) {
537
+ changes.push("version changed");
538
+ }
539
+ if (prevEntry.hash !== nextEntry.hash && changes.length === 0) {
540
+ changes.push("contract content changed");
541
+ }
542
+
543
+ if (changes.length > 0) {
544
+ changed.push({
545
+ id,
546
+ routeId: nextEntry.routeId,
547
+ severity,
548
+ changes,
549
+ before: prevEntry,
550
+ after: nextEntry,
551
+ });
552
+ }
553
+ }
554
+
555
+ for (const [id, prevEntry] of prevMap.entries()) {
556
+ if (!nextMap.has(id)) {
557
+ removed.push(prevEntry);
558
+ }
559
+ }
560
+
561
+ const summary = {
562
+ major: changed.filter((c) => c.severity === "major").length + removed.length,
563
+ minor: changed.filter((c) => c.severity === "minor").length + added.length,
564
+ patch: changed.filter((c) => c.severity === "patch").length,
565
+ };
566
+
567
+ return { added, removed, changed, summary };
568
+ }
@@ -5,9 +5,33 @@
5
5
 
6
6
  import type { z } from "zod";
7
7
 
8
- /** HTTP Methods supported in contracts */
9
- export type ContractMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
10
-
8
+ /** HTTP Methods supported in contracts */
9
+ export type ContractMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
10
+
11
+ /**
12
+ * Client-safe schema options
13
+ */
14
+ export type ClientSafeRequestMap = Partial<Record<
15
+ ContractMethod,
16
+ {
17
+ query?: boolean;
18
+ body?: boolean;
19
+ params?: boolean;
20
+ headers?: boolean;
21
+ }
22
+ >>;
23
+
24
+ export type ClientSafeResponseMap = number[] | Partial<Record<number, boolean>>;
25
+
26
+ export interface ClientSafeOptions {
27
+ /** Request schema exposure */
28
+ request?: ClientSafeRequestMap;
29
+ /** Response schema exposure */
30
+ response?: ClientSafeResponseMap;
31
+ /** Include standard error responses if defined */
32
+ includeErrors?: boolean;
33
+ }
34
+
11
35
  /** Example data for request/response documentation */
12
36
  export interface SchemaExamples {
13
37
  /** Example name → example data */
@@ -73,11 +97,19 @@ export interface ContractResponseSchema {
73
97
  export type ContractNormalizeMode = "strip" | "strict" | "passthrough";
74
98
 
75
99
  /** Full contract schema definition */
76
- export interface ContractSchema {
77
- /** API description */
78
- description?: string;
79
- /** Tags for grouping (e.g., OpenAPI tags) */
80
- tags?: string[];
100
+ export interface ContractSchema {
101
+ /** Contract name (optional) */
102
+ name?: string;
103
+ /** Contract version (optional) */
104
+ version?: string;
105
+ /** Contract metadata (optional) */
106
+ meta?: Record<string, unknown>;
107
+ /** Client-safe schema config (optional) */
108
+ clientSafe?: ClientSafeOptions;
109
+ /** API description */
110
+ description?: string;
111
+ /** Tags for grouping (e.g., OpenAPI tags) */
112
+ tags?: string[];
81
113
  /** Request schemas by method */
82
114
  request: ContractRequestSchema;
83
115
  /** Response schemas by status code */
@@ -97,10 +129,14 @@ export interface ContractSchema {
97
129
  }
98
130
 
99
131
  /** Contract definition input (what user provides) */
100
- export interface ContractDefinition {
101
- description?: string;
102
- tags?: string[];
103
- request: ContractRequestSchema;
132
+ export interface ContractDefinition {
133
+ name?: string;
134
+ version?: string;
135
+ meta?: Record<string, unknown>;
136
+ clientSafe?: ClientSafeOptions;
137
+ description?: string;
138
+ tags?: string[];
139
+ request: ContractRequestSchema;
104
140
  response: ContractResponseSchema;
105
141
  /** Normalize mode for request data */
106
142
  normalize?: ContractNormalizeMode;