@kaito-http/core 4.0.0-beta.21 → 4.0.0-beta.24

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.
@@ -295,6 +295,8 @@ var KString = class _KString extends BaseSchema {
295
295
  }
296
296
  return result.result;
297
297
  }
298
+ visit() {
299
+ }
298
300
  };
299
301
  var KNumber = class _KNumber extends BaseSchema {
300
302
  static create = () => new _KNumber({});
@@ -401,6 +403,8 @@ var KNumber = class _KNumber extends BaseSchema {
401
403
  }
402
404
  return result.result;
403
405
  }
406
+ visit() {
407
+ }
404
408
  };
405
409
  var KBoolean = class _KBoolean extends BaseSchema {
406
410
  static create = () => new _KBoolean({});
@@ -429,6 +433,8 @@ var KBoolean = class _KBoolean extends BaseSchema {
429
433
  }
430
434
  return result.result;
431
435
  }
436
+ visit() {
437
+ }
432
438
  };
433
439
  var KArray = class _KArray extends BaseSchema {
434
440
  static create = (items) => new _KArray({ items });
@@ -495,6 +501,11 @@ var KArray = class _KArray extends BaseSchema {
495
501
  }
496
502
  return result.result;
497
503
  }
504
+ visit(visitor) {
505
+ const child = this.def.items;
506
+ visitor(child);
507
+ child.visit(visitor);
508
+ }
498
509
  };
499
510
  var KNull = class _KNull extends BaseSchema {
500
511
  static create = () => new _KNull({});
@@ -523,6 +534,8 @@ var KNull = class _KNull extends BaseSchema {
523
534
  }
524
535
  return result.result;
525
536
  }
537
+ visit() {
538
+ }
526
539
  };
527
540
  var KObject = class _KObject extends BaseSchema {
528
541
  static create = (shape) => new _KObject({ shape });
@@ -585,6 +598,12 @@ var KObject = class _KObject extends BaseSchema {
585
598
  get shape() {
586
599
  return this.def.shape;
587
600
  }
601
+ visit(visitor) {
602
+ for (const child of Object.values(this.def.shape)) {
603
+ visitor(child);
604
+ child.visit(visitor);
605
+ }
606
+ }
588
607
  };
589
608
  var KObjectFromURLSearchParams = class _KObjectFromURLSearchParams extends KObject {
590
609
  static create = (shape) => new _KObjectFromURLSearchParams({ shape });
@@ -632,6 +651,12 @@ var KRef = class _KRef extends BaseSchema {
632
651
  }
633
652
  return result;
634
653
  }
654
+ visit(visitor) {
655
+ for (const child of Object.values(this.def.shape)) {
656
+ visitor(child);
657
+ child.visit(visitor);
658
+ }
659
+ }
635
660
  example() {
636
661
  throw new Error("Cannot set an example on a KRef");
637
662
  }
@@ -687,13 +712,21 @@ var KRef = class _KRef extends BaseSchema {
687
712
  var KScalar = class _KScalar extends BaseSchema {
688
713
  static create = (options) => new _KScalar(options);
689
714
  constructor(def) {
690
- super(def);
715
+ super({
716
+ ...def,
717
+ example: def.schema.example(),
718
+ description: def.schema.description()
719
+ });
691
720
  }
692
721
  serialize(value) {
693
722
  return this.def.toClient(value);
694
723
  }
695
724
  toOpenAPI() {
696
- return this.def.schema.toOpenAPI();
725
+ return {
726
+ ...this.def.schema.toOpenAPI(),
727
+ ...this.def.description ? { description: this.def.description } : {},
728
+ ...this.def.example ? { example: this.def.example } : {}
729
+ };
697
730
  }
698
731
  parseSafe(json) {
699
732
  return ParseContext.result((ctx) => {
@@ -708,18 +741,6 @@ var KScalar = class _KScalar extends BaseSchema {
708
741
  }
709
742
  });
710
743
  }
711
- example(example) {
712
- if (example === void 0) {
713
- return this.def.example;
714
- }
715
- return this.clone({ example });
716
- }
717
- description(description) {
718
- if (description === void 0) {
719
- return this.def.schema.description();
720
- }
721
- return this.clone({ description });
722
- }
723
744
  parse(json) {
724
745
  const result = this.parseSafe(json);
725
746
  if (!result.success) {
@@ -727,6 +748,11 @@ var KScalar = class _KScalar extends BaseSchema {
727
748
  }
728
749
  return result.result;
729
750
  }
751
+ visit(visitor) {
752
+ const child = this.def.schema;
753
+ visitor(child);
754
+ child.visit(visitor);
755
+ }
730
756
  };
731
757
  var KUnion = class _KUnion extends BaseSchema {
732
758
  static create = (items) => new _KUnion({ items });
@@ -765,6 +791,12 @@ var KUnion = class _KUnion extends BaseSchema {
765
791
  }
766
792
  return result.result;
767
793
  }
794
+ visit(visitor) {
795
+ for (const child of this.def.items) {
796
+ visitor(child);
797
+ child.visit(visitor);
798
+ }
799
+ }
768
800
  };
769
801
  var KLiteral = class _KLiteral extends BaseSchema {
770
802
  parse(json) {
@@ -795,6 +827,8 @@ var KLiteral = class _KLiteral extends BaseSchema {
795
827
  return this.def.value;
796
828
  });
797
829
  }
830
+ visit() {
831
+ }
798
832
  };
799
833
  var k = {
800
834
  string: KString.create,
package/dist/index.cjs CHANGED
@@ -453,6 +453,8 @@ var KString = class _KString extends BaseSchema {
453
453
  }
454
454
  return result.result;
455
455
  }
456
+ visit() {
457
+ }
456
458
  };
457
459
  var KNumber = class _KNumber extends BaseSchema {
458
460
  static create = () => new _KNumber({});
@@ -559,6 +561,8 @@ var KNumber = class _KNumber extends BaseSchema {
559
561
  }
560
562
  return result.result;
561
563
  }
564
+ visit() {
565
+ }
562
566
  };
563
567
  var KBoolean = class _KBoolean extends BaseSchema {
564
568
  static create = () => new _KBoolean({});
@@ -587,6 +591,8 @@ var KBoolean = class _KBoolean extends BaseSchema {
587
591
  }
588
592
  return result.result;
589
593
  }
594
+ visit() {
595
+ }
590
596
  };
591
597
  var KArray = class _KArray extends BaseSchema {
592
598
  static create = (items) => new _KArray({ items });
@@ -653,6 +659,11 @@ var KArray = class _KArray extends BaseSchema {
653
659
  }
654
660
  return result.result;
655
661
  }
662
+ visit(visitor) {
663
+ const child = this.def.items;
664
+ visitor(child);
665
+ child.visit(visitor);
666
+ }
656
667
  };
657
668
  var KNull = class _KNull extends BaseSchema {
658
669
  static create = () => new _KNull({});
@@ -681,6 +692,8 @@ var KNull = class _KNull extends BaseSchema {
681
692
  }
682
693
  return result.result;
683
694
  }
695
+ visit() {
696
+ }
684
697
  };
685
698
  var KObject = class _KObject extends BaseSchema {
686
699
  static create = (shape) => new _KObject({ shape });
@@ -743,6 +756,12 @@ var KObject = class _KObject extends BaseSchema {
743
756
  get shape() {
744
757
  return this.def.shape;
745
758
  }
759
+ visit(visitor) {
760
+ for (const child of Object.values(this.def.shape)) {
761
+ visitor(child);
762
+ child.visit(visitor);
763
+ }
764
+ }
746
765
  };
747
766
  var KObjectFromURLSearchParams = class _KObjectFromURLSearchParams extends KObject {
748
767
  static create = (shape) => new _KObjectFromURLSearchParams({ shape });
@@ -790,6 +809,12 @@ var KRef = class _KRef extends BaseSchema {
790
809
  }
791
810
  return result;
792
811
  }
812
+ visit(visitor) {
813
+ for (const child of Object.values(this.def.shape)) {
814
+ visitor(child);
815
+ child.visit(visitor);
816
+ }
817
+ }
793
818
  example() {
794
819
  throw new Error("Cannot set an example on a KRef");
795
820
  }
@@ -845,13 +870,21 @@ var KRef = class _KRef extends BaseSchema {
845
870
  var KScalar = class _KScalar extends BaseSchema {
846
871
  static create = (options) => new _KScalar(options);
847
872
  constructor(def) {
848
- super(def);
873
+ super({
874
+ ...def,
875
+ example: def.schema.example(),
876
+ description: def.schema.description()
877
+ });
849
878
  }
850
879
  serialize(value) {
851
880
  return this.def.toClient(value);
852
881
  }
853
882
  toOpenAPI() {
854
- return this.def.schema.toOpenAPI();
883
+ return {
884
+ ...this.def.schema.toOpenAPI(),
885
+ ...this.def.description ? { description: this.def.description } : {},
886
+ ...this.def.example ? { example: this.def.example } : {}
887
+ };
855
888
  }
856
889
  parseSafe(json) {
857
890
  return ParseContext.result((ctx) => {
@@ -866,18 +899,6 @@ var KScalar = class _KScalar extends BaseSchema {
866
899
  }
867
900
  });
868
901
  }
869
- example(example) {
870
- if (example === void 0) {
871
- return this.def.example;
872
- }
873
- return this.clone({ example });
874
- }
875
- description(description) {
876
- if (description === void 0) {
877
- return this.def.schema.description();
878
- }
879
- return this.clone({ description });
880
- }
881
902
  parse(json) {
882
903
  const result = this.parseSafe(json);
883
904
  if (!result.success) {
@@ -885,6 +906,11 @@ var KScalar = class _KScalar extends BaseSchema {
885
906
  }
886
907
  return result.result;
887
908
  }
909
+ visit(visitor) {
910
+ const child = this.def.schema;
911
+ visitor(child);
912
+ child.visit(visitor);
913
+ }
888
914
  };
889
915
  var KUnion = class _KUnion extends BaseSchema {
890
916
  static create = (items) => new _KUnion({ items });
@@ -923,6 +949,12 @@ var KUnion = class _KUnion extends BaseSchema {
923
949
  }
924
950
  return result.result;
925
951
  }
952
+ visit(visitor) {
953
+ for (const child of this.def.items) {
954
+ visitor(child);
955
+ child.visit(visitor);
956
+ }
957
+ }
926
958
  };
927
959
  var KLiteral = class _KLiteral extends BaseSchema {
928
960
  parse(json) {
@@ -953,6 +985,8 @@ var KLiteral = class _KLiteral extends BaseSchema {
953
985
  return this.def.value;
954
986
  });
955
987
  }
988
+ visit() {
989
+ }
956
990
  };
957
991
  var k = {
958
992
  string: KString.create,
@@ -1173,6 +1207,33 @@ var Router = class _Router {
1173
1207
  servers
1174
1208
  }) => {
1175
1209
  const OPENAPI_VERSION = "3.1.0";
1210
+ const componentsSchemas = {};
1211
+ const addSchemaForRef = (ref) => {
1212
+ const name = ref.name;
1213
+ const properties = Object.fromEntries(Object.entries(ref.shape).map(([key, value]) => [key, value.toOpenAPI()]));
1214
+ const schemaObject = {
1215
+ type: "object",
1216
+ properties,
1217
+ required: Object.keys(ref.shape),
1218
+ ...ref.description() ? { description: ref.description() } : {}
1219
+ };
1220
+ const existing = componentsSchemas[name];
1221
+ if (existing) {
1222
+ if (JSON.stringify(existing) !== JSON.stringify(schemaObject)) {
1223
+ throw new Error(
1224
+ `Conflicting KRef definitions detected for "${name}". OpenAPI components require a single schema per name.`
1225
+ );
1226
+ }
1227
+ return;
1228
+ }
1229
+ componentsSchemas[name] = schemaObject;
1230
+ };
1231
+ function visit(schema, seen = /* @__PURE__ */ new Set()) {
1232
+ if (seen.has(schema)) return;
1233
+ seen.add(schema);
1234
+ if (schema instanceof KRef) addSchemaForRef(schema);
1235
+ schema.visit((child) => visit(child, seen));
1236
+ }
1176
1237
  const paths = {};
1177
1238
  for (const route of this.#state.routes) {
1178
1239
  if (!route.openapi) {
@@ -1194,6 +1255,8 @@ var Router = class _Router {
1194
1255
  default:
1195
1256
  throw new Error(`Unknown output type in route ${route.method} ${route.path}: ${type}`);
1196
1257
  }
1258
+ if (route.openapi.schema) visit(route.openapi.schema);
1259
+ if (route.body) visit(route.body);
1197
1260
  const item = {
1198
1261
  description: route.openapi?.description ?? "Successful response",
1199
1262
  responses: {
@@ -1223,6 +1286,7 @@ var Router = class _Router {
1223
1286
  openapi: OPENAPI_VERSION,
1224
1287
  info,
1225
1288
  paths,
1289
+ ...Object.keys(componentsSchemas).length > 0 ? { components: { schemas: componentsSchemas } } : {},
1226
1290
  servers: Object.entries(servers ?? {}).map((entry) => {
1227
1291
  const [url, description] = entry;
1228
1292
  return {
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  SchemaError,
17
17
  isPrimitiveJSONValue,
18
18
  k
19
- } from "./chunk-TL3E52YN.js";
19
+ } from "./chunk-IEGYJT4R.js";
20
20
 
21
21
  // src/router/router.ts
22
22
  import "openapi3-ts/oas31";
@@ -328,6 +328,33 @@ var Router = class _Router {
328
328
  servers
329
329
  }) => {
330
330
  const OPENAPI_VERSION = "3.1.0";
331
+ const componentsSchemas = {};
332
+ const addSchemaForRef = (ref) => {
333
+ const name = ref.name;
334
+ const properties = Object.fromEntries(Object.entries(ref.shape).map(([key, value]) => [key, value.toOpenAPI()]));
335
+ const schemaObject = {
336
+ type: "object",
337
+ properties,
338
+ required: Object.keys(ref.shape),
339
+ ...ref.description() ? { description: ref.description() } : {}
340
+ };
341
+ const existing = componentsSchemas[name];
342
+ if (existing) {
343
+ if (JSON.stringify(existing) !== JSON.stringify(schemaObject)) {
344
+ throw new Error(
345
+ `Conflicting KRef definitions detected for "${name}". OpenAPI components require a single schema per name.`
346
+ );
347
+ }
348
+ return;
349
+ }
350
+ componentsSchemas[name] = schemaObject;
351
+ };
352
+ function visit(schema, seen = /* @__PURE__ */ new Set()) {
353
+ if (seen.has(schema)) return;
354
+ seen.add(schema);
355
+ if (schema instanceof KRef) addSchemaForRef(schema);
356
+ schema.visit((child) => visit(child, seen));
357
+ }
331
358
  const paths = {};
332
359
  for (const route of this.#state.routes) {
333
360
  if (!route.openapi) {
@@ -349,6 +376,8 @@ var Router = class _Router {
349
376
  default:
350
377
  throw new Error(`Unknown output type in route ${route.method} ${route.path}: ${type}`);
351
378
  }
379
+ if (route.openapi.schema) visit(route.openapi.schema);
380
+ if (route.body) visit(route.body);
352
381
  const item = {
353
382
  description: route.openapi?.description ?? "Successful response",
354
383
  responses: {
@@ -378,6 +407,7 @@ var Router = class _Router {
378
407
  openapi: OPENAPI_VERSION,
379
408
  info,
380
409
  paths,
410
+ ...Object.keys(componentsSchemas).length > 0 ? { components: { schemas: componentsSchemas } } : {},
381
411
  servers: Object.entries(servers ?? {}).map((entry) => {
382
412
  const [url, description] = entry;
383
413
  return {
@@ -335,6 +335,8 @@ var KString = class _KString extends BaseSchema {
335
335
  }
336
336
  return result.result;
337
337
  }
338
+ visit() {
339
+ }
338
340
  };
339
341
  var KNumber = class _KNumber extends BaseSchema {
340
342
  static create = () => new _KNumber({});
@@ -441,6 +443,8 @@ var KNumber = class _KNumber extends BaseSchema {
441
443
  }
442
444
  return result.result;
443
445
  }
446
+ visit() {
447
+ }
444
448
  };
445
449
  var KBoolean = class _KBoolean extends BaseSchema {
446
450
  static create = () => new _KBoolean({});
@@ -469,6 +473,8 @@ var KBoolean = class _KBoolean extends BaseSchema {
469
473
  }
470
474
  return result.result;
471
475
  }
476
+ visit() {
477
+ }
472
478
  };
473
479
  var KArray = class _KArray extends BaseSchema {
474
480
  static create = (items) => new _KArray({ items });
@@ -535,6 +541,11 @@ var KArray = class _KArray extends BaseSchema {
535
541
  }
536
542
  return result.result;
537
543
  }
544
+ visit(visitor) {
545
+ const child = this.def.items;
546
+ visitor(child);
547
+ child.visit(visitor);
548
+ }
538
549
  };
539
550
  var KNull = class _KNull extends BaseSchema {
540
551
  static create = () => new _KNull({});
@@ -563,6 +574,8 @@ var KNull = class _KNull extends BaseSchema {
563
574
  }
564
575
  return result.result;
565
576
  }
577
+ visit() {
578
+ }
566
579
  };
567
580
  var KObject = class _KObject extends BaseSchema {
568
581
  static create = (shape) => new _KObject({ shape });
@@ -625,6 +638,12 @@ var KObject = class _KObject extends BaseSchema {
625
638
  get shape() {
626
639
  return this.def.shape;
627
640
  }
641
+ visit(visitor) {
642
+ for (const child of Object.values(this.def.shape)) {
643
+ visitor(child);
644
+ child.visit(visitor);
645
+ }
646
+ }
628
647
  };
629
648
  var KObjectFromURLSearchParams = class _KObjectFromURLSearchParams extends KObject {
630
649
  static create = (shape) => new _KObjectFromURLSearchParams({ shape });
@@ -672,6 +691,12 @@ var KRef = class _KRef extends BaseSchema {
672
691
  }
673
692
  return result;
674
693
  }
694
+ visit(visitor) {
695
+ for (const child of Object.values(this.def.shape)) {
696
+ visitor(child);
697
+ child.visit(visitor);
698
+ }
699
+ }
675
700
  example() {
676
701
  throw new Error("Cannot set an example on a KRef");
677
702
  }
@@ -727,13 +752,21 @@ var KRef = class _KRef extends BaseSchema {
727
752
  var KScalar = class _KScalar extends BaseSchema {
728
753
  static create = (options) => new _KScalar(options);
729
754
  constructor(def) {
730
- super(def);
755
+ super({
756
+ ...def,
757
+ example: def.schema.example(),
758
+ description: def.schema.description()
759
+ });
731
760
  }
732
761
  serialize(value) {
733
762
  return this.def.toClient(value);
734
763
  }
735
764
  toOpenAPI() {
736
- return this.def.schema.toOpenAPI();
765
+ return {
766
+ ...this.def.schema.toOpenAPI(),
767
+ ...this.def.description ? { description: this.def.description } : {},
768
+ ...this.def.example ? { example: this.def.example } : {}
769
+ };
737
770
  }
738
771
  parseSafe(json) {
739
772
  return ParseContext.result((ctx) => {
@@ -748,18 +781,6 @@ var KScalar = class _KScalar extends BaseSchema {
748
781
  }
749
782
  });
750
783
  }
751
- example(example) {
752
- if (example === void 0) {
753
- return this.def.example;
754
- }
755
- return this.clone({ example });
756
- }
757
- description(description) {
758
- if (description === void 0) {
759
- return this.def.schema.description();
760
- }
761
- return this.clone({ description });
762
- }
763
784
  parse(json) {
764
785
  const result = this.parseSafe(json);
765
786
  if (!result.success) {
@@ -767,6 +788,11 @@ var KScalar = class _KScalar extends BaseSchema {
767
788
  }
768
789
  return result.result;
769
790
  }
791
+ visit(visitor) {
792
+ const child = this.def.schema;
793
+ visitor(child);
794
+ child.visit(visitor);
795
+ }
770
796
  };
771
797
  var KUnion = class _KUnion extends BaseSchema {
772
798
  static create = (items) => new _KUnion({ items });
@@ -805,6 +831,12 @@ var KUnion = class _KUnion extends BaseSchema {
805
831
  }
806
832
  return result.result;
807
833
  }
834
+ visit(visitor) {
835
+ for (const child of this.def.items) {
836
+ visitor(child);
837
+ child.visit(visitor);
838
+ }
839
+ }
808
840
  };
809
841
  var KLiteral = class _KLiteral extends BaseSchema {
810
842
  parse(json) {
@@ -835,6 +867,8 @@ var KLiteral = class _KLiteral extends BaseSchema {
835
867
  return this.def.value;
836
868
  });
837
869
  }
870
+ visit() {
871
+ }
838
872
  };
839
873
  var k = {
840
874
  string: KString.create,
@@ -61,6 +61,10 @@ declare abstract class BaseSchema<Input extends JSONValue, Output, Def extends B
61
61
  example(): Input | undefined;
62
62
  description(description: string): this;
63
63
  description(): string | undefined;
64
+ /**
65
+ * Traverse immediate children schemas.
66
+ */
67
+ abstract visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
64
68
  }
65
69
  type Check<T extends string, P extends {} = {}> = {
66
70
  type: T;
@@ -142,6 +146,7 @@ declare class KString extends BaseSchema<string, string, StringDef> {
142
146
  hostname(message?: string): this;
143
147
  parseSafe(json: unknown): ParseResult<string>;
144
148
  parse(json: unknown): string;
149
+ visit(): void;
145
150
  }
146
151
  type NumberFormat = 'float' | 'double' | 'int32' | 'int64';
147
152
  interface NumberChecks {
@@ -176,6 +181,7 @@ declare class KNumber extends BaseSchema<number, number, NumberDef> {
176
181
  int64(): this;
177
182
  parseSafe(json: unknown): ParseResult<number>;
178
183
  parse(json: unknown): number;
184
+ visit(): void;
179
185
  }
180
186
  interface BooleanDef extends BaseSchemaDef<boolean> {
181
187
  }
@@ -185,6 +191,7 @@ declare class KBoolean extends BaseSchema<boolean, boolean, BooleanDef> {
185
191
  toOpenAPI(): SchemaObject | ReferenceObject;
186
192
  parseSafe(json: unknown): ParseResult<boolean>;
187
193
  parse(json: unknown): boolean;
194
+ visit(): void;
188
195
  }
189
196
  interface ArrayChecks {
190
197
  minItems?: Check<'minItems', {
@@ -211,6 +218,7 @@ declare class KArray<Input extends JSONValue, Output> extends BaseSchema<Input[]
211
218
  notUnique(): this;
212
219
  parseSafe(json: unknown): ParseResult<Output[]>;
213
220
  parse(json: unknown): Output[];
221
+ visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
214
222
  }
215
223
  interface NullDef extends BaseSchemaDef<null> {
216
224
  }
@@ -220,6 +228,7 @@ declare class KNull extends BaseSchema<null, null, NullDef> {
220
228
  toOpenAPI(): SchemaObject | ReferenceObject;
221
229
  parseSafe(json: unknown): ParseResult<null>;
222
230
  parse(json: unknown): null;
231
+ visit(): void;
223
232
  }
224
233
  interface ObjectDef<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>> extends BaseSchemaDef<Input> {
225
234
  shape: {
@@ -233,6 +242,7 @@ declare class KObject<Input extends Record<keyof Output, JSONValue>, Output exte
233
242
  parseSafe(json: unknown): ParseResult<Output>;
234
243
  parse(json: unknown): Output;
235
244
  get shape(): { [K in keyof Input]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; };
245
+ visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
236
246
  }
237
247
  declare class KObjectFromURLSearchParams<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>> extends KObject<Input, Output> {
238
248
  static create: <Input_1 extends Record<keyof Output_1, JSONValue>, Output_1 extends Record<keyof Input_1, JSONValue>>(shape: { [K in keyof Input_1 | keyof Output_1]: BaseSchema<Input_1[K], Output_1[K], BaseSchemaDef<Input_1[K]>>; }) => KObjectFromURLSearchParams<Input_1, Output_1>;
@@ -244,9 +254,10 @@ interface RefDef<Input extends Record<keyof Output, JSONValue>, Output extends R
244
254
  name: string;
245
255
  summary?: string | undefined;
246
256
  }
247
- declare class KRef<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>> extends BaseSchema<Input, Output, RefDef<Input, Output>> {
248
- static create: <Input_1 extends Record<keyof Output_1, JSONValue>, Output_1 extends Record<keyof Input_1, JSONValue>>(name: string, shape: { [K in keyof Input_1 | keyof Output_1]: BaseSchema<Input_1[K], Output_1[K], BaseSchemaDef<Input_1[K]>>; }) => KRef<Input_1, Output_1>;
257
+ declare class KRef<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, any>> extends BaseSchema<Input, Output, RefDef<Input, Output>> {
258
+ static create: <Input_1 extends Record<keyof Output_1, JSONValue>, Output_1 extends Record<keyof Input_1, any>>(name: string, shape: { [K in keyof Input_1 | keyof Output_1]: BaseSchema<Input_1[K], Output_1[K], BaseSchemaDef<Input_1[K]>>; }) => KRef<Input_1, Output_1>;
249
259
  serialize(value: Output): Input;
260
+ visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
250
261
  example(): never;
251
262
  toOpenAPI(): ReferenceObject;
252
263
  parseSafe(json: unknown): ParseResult<Output>;
@@ -282,11 +293,8 @@ declare class KScalar<ClientRepresentation extends JSONPrimitive, ServerRepresen
282
293
  serialize(value: ServerRepresentation): ClientRepresentation;
283
294
  toOpenAPI(): SchemaObject | ReferenceObject;
284
295
  parseSafe(json: unknown): ParseResult<ServerRepresentation>;
285
- example(example: ClientRepresentation): this;
286
- example(): ClientRepresentation | undefined;
287
- description(description: string): this;
288
- description(): string | undefined;
289
296
  parse(json: unknown): ServerRepresentation;
297
+ visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
290
298
  }
291
299
  interface UnionDef<Input extends JSONValue, Output> extends BaseSchemaDef<Input> {
292
300
  items: [
@@ -301,6 +309,7 @@ declare class KUnion<Input extends JSONValue, Output> extends BaseSchema<Input,
301
309
  toOpenAPI(): SchemaObject | ReferenceObject;
302
310
  parseSafe(json: unknown): ParseResult<Output>;
303
311
  parse(json: unknown): Output;
312
+ visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
304
313
  }
305
314
  interface LiteralDef<Value extends string | number | boolean> extends BaseSchemaDef<Value> {
306
315
  value: Value;
@@ -311,6 +320,7 @@ declare class KLiteral<Value extends string | number | boolean> extends BaseSche
311
320
  serialize(value: Value): Value;
312
321
  toOpenAPI(): SchemaObject;
313
322
  parseSafe(json: unknown): ParseResult<Value>;
323
+ visit(): void;
314
324
  }
315
325
  declare const k: {
316
326
  string: () => KString;
@@ -318,7 +328,7 @@ declare const k: {
318
328
  boolean: () => KBoolean;
319
329
  array: <ItemsInput extends JSONValue, ItemsOutput, Def extends BaseSchemaDef<ItemsInput>>(items: BaseSchema<ItemsInput, ItemsOutput, Def>) => KArray<ItemsInput, ItemsOutput>;
320
330
  null: () => KNull;
321
- ref: <Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>>(name: string, shape: { [K in keyof Input | keyof Output]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; }) => KRef<Input, Output>;
331
+ ref: <Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, any>>(name: string, shape: { [K in keyof Input | keyof Output]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; }) => KRef<Input, Output>;
322
332
  object: <Input extends Record<keyof Output, any>, Output extends Record<keyof Input, any>>(shape: { [K in keyof Input | keyof Output]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; }) => KObject<Input, Output>;
323
333
  scalar: <ClientRepresentation extends JSONPrimitive, ServerRepresentation>(options: ScalarOptions<ClientRepresentation, ServerRepresentation>) => KScalar<ClientRepresentation, ServerRepresentation>;
324
334
  literal: <Value extends string | number | boolean>(value: Value) => KLiteral<Value>;
@@ -61,6 +61,10 @@ declare abstract class BaseSchema<Input extends JSONValue, Output, Def extends B
61
61
  example(): Input | undefined;
62
62
  description(description: string): this;
63
63
  description(): string | undefined;
64
+ /**
65
+ * Traverse immediate children schemas.
66
+ */
67
+ abstract visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
64
68
  }
65
69
  type Check<T extends string, P extends {} = {}> = {
66
70
  type: T;
@@ -142,6 +146,7 @@ declare class KString extends BaseSchema<string, string, StringDef> {
142
146
  hostname(message?: string): this;
143
147
  parseSafe(json: unknown): ParseResult<string>;
144
148
  parse(json: unknown): string;
149
+ visit(): void;
145
150
  }
146
151
  type NumberFormat = 'float' | 'double' | 'int32' | 'int64';
147
152
  interface NumberChecks {
@@ -176,6 +181,7 @@ declare class KNumber extends BaseSchema<number, number, NumberDef> {
176
181
  int64(): this;
177
182
  parseSafe(json: unknown): ParseResult<number>;
178
183
  parse(json: unknown): number;
184
+ visit(): void;
179
185
  }
180
186
  interface BooleanDef extends BaseSchemaDef<boolean> {
181
187
  }
@@ -185,6 +191,7 @@ declare class KBoolean extends BaseSchema<boolean, boolean, BooleanDef> {
185
191
  toOpenAPI(): SchemaObject | ReferenceObject;
186
192
  parseSafe(json: unknown): ParseResult<boolean>;
187
193
  parse(json: unknown): boolean;
194
+ visit(): void;
188
195
  }
189
196
  interface ArrayChecks {
190
197
  minItems?: Check<'minItems', {
@@ -211,6 +218,7 @@ declare class KArray<Input extends JSONValue, Output> extends BaseSchema<Input[]
211
218
  notUnique(): this;
212
219
  parseSafe(json: unknown): ParseResult<Output[]>;
213
220
  parse(json: unknown): Output[];
221
+ visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
214
222
  }
215
223
  interface NullDef extends BaseSchemaDef<null> {
216
224
  }
@@ -220,6 +228,7 @@ declare class KNull extends BaseSchema<null, null, NullDef> {
220
228
  toOpenAPI(): SchemaObject | ReferenceObject;
221
229
  parseSafe(json: unknown): ParseResult<null>;
222
230
  parse(json: unknown): null;
231
+ visit(): void;
223
232
  }
224
233
  interface ObjectDef<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>> extends BaseSchemaDef<Input> {
225
234
  shape: {
@@ -233,6 +242,7 @@ declare class KObject<Input extends Record<keyof Output, JSONValue>, Output exte
233
242
  parseSafe(json: unknown): ParseResult<Output>;
234
243
  parse(json: unknown): Output;
235
244
  get shape(): { [K in keyof Input]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; };
245
+ visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
236
246
  }
237
247
  declare class KObjectFromURLSearchParams<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>> extends KObject<Input, Output> {
238
248
  static create: <Input_1 extends Record<keyof Output_1, JSONValue>, Output_1 extends Record<keyof Input_1, JSONValue>>(shape: { [K in keyof Input_1 | keyof Output_1]: BaseSchema<Input_1[K], Output_1[K], BaseSchemaDef<Input_1[K]>>; }) => KObjectFromURLSearchParams<Input_1, Output_1>;
@@ -244,9 +254,10 @@ interface RefDef<Input extends Record<keyof Output, JSONValue>, Output extends R
244
254
  name: string;
245
255
  summary?: string | undefined;
246
256
  }
247
- declare class KRef<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>> extends BaseSchema<Input, Output, RefDef<Input, Output>> {
248
- static create: <Input_1 extends Record<keyof Output_1, JSONValue>, Output_1 extends Record<keyof Input_1, JSONValue>>(name: string, shape: { [K in keyof Input_1 | keyof Output_1]: BaseSchema<Input_1[K], Output_1[K], BaseSchemaDef<Input_1[K]>>; }) => KRef<Input_1, Output_1>;
257
+ declare class KRef<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, any>> extends BaseSchema<Input, Output, RefDef<Input, Output>> {
258
+ static create: <Input_1 extends Record<keyof Output_1, JSONValue>, Output_1 extends Record<keyof Input_1, any>>(name: string, shape: { [K in keyof Input_1 | keyof Output_1]: BaseSchema<Input_1[K], Output_1[K], BaseSchemaDef<Input_1[K]>>; }) => KRef<Input_1, Output_1>;
249
259
  serialize(value: Output): Input;
260
+ visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
250
261
  example(): never;
251
262
  toOpenAPI(): ReferenceObject;
252
263
  parseSafe(json: unknown): ParseResult<Output>;
@@ -282,11 +293,8 @@ declare class KScalar<ClientRepresentation extends JSONPrimitive, ServerRepresen
282
293
  serialize(value: ServerRepresentation): ClientRepresentation;
283
294
  toOpenAPI(): SchemaObject | ReferenceObject;
284
295
  parseSafe(json: unknown): ParseResult<ServerRepresentation>;
285
- example(example: ClientRepresentation): this;
286
- example(): ClientRepresentation | undefined;
287
- description(description: string): this;
288
- description(): string | undefined;
289
296
  parse(json: unknown): ServerRepresentation;
297
+ visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
290
298
  }
291
299
  interface UnionDef<Input extends JSONValue, Output> extends BaseSchemaDef<Input> {
292
300
  items: [
@@ -301,6 +309,7 @@ declare class KUnion<Input extends JSONValue, Output> extends BaseSchema<Input,
301
309
  toOpenAPI(): SchemaObject | ReferenceObject;
302
310
  parseSafe(json: unknown): ParseResult<Output>;
303
311
  parse(json: unknown): Output;
312
+ visit(visitor: (schema: BaseSchema<any, any, any>) => void): void;
304
313
  }
305
314
  interface LiteralDef<Value extends string | number | boolean> extends BaseSchemaDef<Value> {
306
315
  value: Value;
@@ -311,6 +320,7 @@ declare class KLiteral<Value extends string | number | boolean> extends BaseSche
311
320
  serialize(value: Value): Value;
312
321
  toOpenAPI(): SchemaObject;
313
322
  parseSafe(json: unknown): ParseResult<Value>;
323
+ visit(): void;
314
324
  }
315
325
  declare const k: {
316
326
  string: () => KString;
@@ -318,7 +328,7 @@ declare const k: {
318
328
  boolean: () => KBoolean;
319
329
  array: <ItemsInput extends JSONValue, ItemsOutput, Def extends BaseSchemaDef<ItemsInput>>(items: BaseSchema<ItemsInput, ItemsOutput, Def>) => KArray<ItemsInput, ItemsOutput>;
320
330
  null: () => KNull;
321
- ref: <Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>>(name: string, shape: { [K in keyof Input | keyof Output]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; }) => KRef<Input, Output>;
331
+ ref: <Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, any>>(name: string, shape: { [K in keyof Input | keyof Output]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; }) => KRef<Input, Output>;
322
332
  object: <Input extends Record<keyof Output, any>, Output extends Record<keyof Input, any>>(shape: { [K in keyof Input | keyof Output]: BaseSchema<Input[K], Output[K], BaseSchemaDef<Input[K]>>; }) => KObject<Input, Output>;
323
333
  scalar: <ClientRepresentation extends JSONPrimitive, ServerRepresentation>(options: ScalarOptions<ClientRepresentation, ServerRepresentation>) => KScalar<ClientRepresentation, ServerRepresentation>;
324
334
  literal: <Value extends string | number | boolean>(value: Value) => KLiteral<Value>;
@@ -16,7 +16,7 @@ import {
16
16
  SchemaError,
17
17
  isPrimitiveJSONValue,
18
18
  k
19
- } from "../chunk-TL3E52YN.js";
19
+ } from "../chunk-IEGYJT4R.js";
20
20
  export {
21
21
  BaseSchema,
22
22
  KArray,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaito-http/core",
3
3
  "type": "module",
4
- "version": "4.0.0-beta.21",
4
+ "version": "4.0.0-beta.24",
5
5
  "author": "Alistair Smith <hi@alistair.sh>",
6
6
  "repository": "https://github.com/kaito-http/kaito",
7
7
  "dependencies": {