@kamaalio/hono-standard-openapi 0.0.1

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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -0
  3. package/dist/app.d.ts +44 -0
  4. package/dist/app.d.ts.map +1 -0
  5. package/dist/app.js +169 -0
  6. package/dist/app.js.map +1 -0
  7. package/dist/errors.d.ts +17 -0
  8. package/dist/errors.d.ts.map +1 -0
  9. package/dist/errors.js +29 -0
  10. package/dist/errors.js.map +1 -0
  11. package/dist/generator.d.ts +25 -0
  12. package/dist/generator.d.ts.map +1 -0
  13. package/dist/generator.js +231 -0
  14. package/dist/generator.js.map +1 -0
  15. package/dist/index.d.ts +11 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +10 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/json-schema.d.ts +65 -0
  20. package/dist/json-schema.d.ts.map +1 -0
  21. package/dist/json-schema.js +248 -0
  22. package/dist/json-schema.js.map +1 -0
  23. package/dist/registry.d.ts +44 -0
  24. package/dist/registry.d.ts.map +1 -0
  25. package/dist/registry.js +78 -0
  26. package/dist/registry.js.map +1 -0
  27. package/dist/route.d.ts +24 -0
  28. package/dist/route.d.ts.map +1 -0
  29. package/dist/route.js +19 -0
  30. package/dist/route.js.map +1 -0
  31. package/dist/standard-schema.d.ts +17 -0
  32. package/dist/standard-schema.d.ts.map +1 -0
  33. package/dist/standard-schema.js +16 -0
  34. package/dist/standard-schema.js.map +1 -0
  35. package/dist/type-inference.d.ts +80 -0
  36. package/dist/type-inference.d.ts.map +1 -0
  37. package/dist/type-inference.js +2 -0
  38. package/dist/type-inference.js.map +1 -0
  39. package/dist/types.d.ts +54 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +8 -0
  42. package/dist/types.js.map +1 -0
  43. package/dist/validator.d.ts +30 -0
  44. package/dist/validator.d.ts.map +1 -0
  45. package/dist/validator.js +31 -0
  46. package/dist/validator.js.map +1 -0
  47. package/package.json +73 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,+BAA+B,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAoD,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEvH,OAAO,EAAkC,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EAEL,iBAAiB,GAKlB,MAAM,YAAY,CAAC;AA4BpB,MAAM,OAAO,GAA6C;IACxD,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,eAAe;CACvB,CAAC;AAEF,oEAAoE;AACpE,MAAM,OAAO,gBAAgB;IAClB,YAAY,CAAsB;IAClC,QAAQ,CAAmB;IAC3B,WAAW,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAChD,6FAA6F;IACpF,MAAM,GAAG,IAAI,OAAO,EAAkB,CAAC;IAEhD,YAAY,WAAkD,EAAE,OAAO,GAAqB,EAAE;QAC5F,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC;QACvF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YAC3C,IAAI,UAAU,CAAC,IAAI,KAAK,QAAQ;gBAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QACxF,CAAC;IACH,CAAC;IAED,gBAAgB,CAAC,MAAsB;QACrC,MAAM,KAAK,GAAkB,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAkB,EAAE,CAAC;QACnC,MAAM,aAAa,GAA2C,EAAE,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;YAAE,OAAO;QAE5B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC;QAC5B,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;YAClC,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAC7F,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAAE,OAAO;YAEhD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAErB,OAAO;QACT,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC,CAAC;IAEF,KAAK,CAAC,KAAK,CAAC,CAAC;IAEb,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC"}
@@ -0,0 +1,11 @@
1
+ export { $, type HonoToStandardOpenAPIHono, StandardOpenAPIHono, type StandardOpenAPIHonoOptions } from './app.ts';
2
+ export { ComponentNameConflictError, StandardOpenAPIError, UnsupportedParameterSchemaError, UnsupportedSchemaError, } from './errors.ts';
3
+ export { type DocumentConfig, type GeneratorOptions, OpenAPIGenerator, type OpenAPIVersion } from './generator.ts';
4
+ export { ComponentCollector, type ConvertOptions, type JSONSchemaTarget, type NormalizationOptions, convertSchema, } from './json-schema.ts';
5
+ export { type ComponentType, type OpenAPIDefinition, OpenAPIRegistry } from './registry.ts';
6
+ export { type RouteConfig, createRoute, toRoutingPath } from './route.ts';
7
+ export { type JSONSchema, type SchemaIO, type StandardJSONSchemaV1, type StandardSchema, type StandardSchemaV1, isStandardJSONSchema, isStandardSchema, } from './standard-schema.ts';
8
+ export { type ComputeInput, type ConvertPathType, type RouteConfigToTypedResponse, type RouteHandler, type RouteHandlerResponse, } from './type-inference.ts';
9
+ export type { ContentObject, MediaTypeObject, ParameterLocation, ReferenceObject, RequestBody, ResponseConfig, RouteConfigBase, RouteMethod, RouteRequest, SchemaObject, SchemaOrReference, } from './types.ts';
10
+ export { type Hook, type ValidationResult, standardValidator } from './validator.ts';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,yBAAyB,EAAE,mBAAmB,EAAE,KAAK,0BAA0B,EAAE,MAAM,UAAU,CAAC;AACnH,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,+BAA+B,EAC/B,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACnH,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,iBAAiB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,KAAK,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EACL,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,0BAA0B,EAC/B,KAAK,YAAY,EACjB,KAAK,oBAAoB,GAC1B,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,cAAc,EACd,eAAe,EACf,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export { $, StandardOpenAPIHono } from './app.js';
2
+ export { ComponentNameConflictError, StandardOpenAPIError, UnsupportedParameterSchemaError, UnsupportedSchemaError, } from './errors.js';
3
+ export { OpenAPIGenerator } from './generator.js';
4
+ export { ComponentCollector, convertSchema, } from './json-schema.js';
5
+ export { OpenAPIRegistry } from './registry.js';
6
+ export { createRoute, toRoutingPath } from './route.js';
7
+ export { isStandardJSONSchema, isStandardSchema, } from './standard-schema.js';
8
+ export {} from './type-inference.js';
9
+ export { standardValidator } from './validator.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAkC,mBAAmB,EAAmC,MAAM,UAAU,CAAC;AACnH,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,+BAA+B,EAC/B,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAA8C,gBAAgB,EAAuB,MAAM,gBAAgB,CAAC;AACnH,OAAO,EACL,kBAAkB,EAIlB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAA8C,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAoB,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAML,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAMN,MAAM,qBAAqB,CAAC;AAc7B,OAAO,EAAoC,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,65 @@
1
+ import { type JSONSchema, type SchemaIO } from './standard-schema.ts';
2
+ /** The JSON Schema dialect asked of the schema library. */
3
+ export type JSONSchemaTarget = 'draft-2020-12' | 'draft-07' | 'openapi-3.0';
4
+ /**
5
+ * Adjustments applied to converted JSON Schema so it reads as an idiomatic OpenAPI document.
6
+ *
7
+ * Each rule is opt-out on its own: they are conveniences, not corrections, and a document that wants
8
+ * the schema library's output verbatim can switch any of them off.
9
+ */
10
+ export interface NormalizationOptions {
11
+ /**
12
+ * Drop `additionalProperties: false`, which schema libraries emit for objects that strip unknown
13
+ * keys. `additionalProperties: {}` from a permissive object is left alone.
14
+ */
15
+ readonly dropStrictAdditionalProperties?: boolean;
16
+ /** Drop `pattern` when a `format` is present, since the format already implies it. */
17
+ readonly dropFormatImpliedPatterns?: boolean;
18
+ /** Collapse `anyOf: [<schema>, { type: 'null' }]` into a nullable type array. */
19
+ readonly collapseNullableUnions?: boolean;
20
+ /** Rewrite `const: <value>` as `enum: [<value>]`, which more OpenAPI tooling understands. */
21
+ readonly constToEnum?: boolean;
22
+ /**
23
+ * Emit each schema's keywords in the conventional order — what a value is, then how it is
24
+ * constrained, then how it is described — instead of the order the schema library happened to
25
+ * produce, which varies with where the metadata was attached.
26
+ */
27
+ readonly orderKeywords?: boolean;
28
+ }
29
+ /**
30
+ * Collects the named schemas a document refers to.
31
+ *
32
+ * Names arrive from two places — a `$defs` key or an explicit `$id` — and both land here, so a schema
33
+ * referenced from several routes is emitted once and shared.
34
+ */
35
+ export declare class ComponentCollector {
36
+ #private;
37
+ get schemas(): Record<string, JSONSchema>;
38
+ has(name: string): boolean;
39
+ /** Holds a place for a schema that is about to be generated, keeping the document's order stable. */
40
+ reserve(name: string): void;
41
+ register(name: string, schema: JSONSchema): void;
42
+ }
43
+ export interface ConvertOptions {
44
+ readonly io: SchemaIO;
45
+ readonly target: JSONSchemaTarget;
46
+ readonly components: ComponentCollector;
47
+ readonly normalization?: NormalizationOptions | undefined;
48
+ /** Name for the schema itself, for schemas that don't name themselves through `$id`. */
49
+ readonly name?: string | undefined;
50
+ /**
51
+ * Whether a self-naming schema becomes a component and a `$ref`.
52
+ *
53
+ * Parameters and headers are described in place rather than referenced, because the document needs
54
+ * their properties spread across separate parameter entries.
55
+ */
56
+ readonly hoistRoot?: boolean | undefined;
57
+ }
58
+ /**
59
+ * Turns a schema into the fragment an OpenAPI document holds, registering every named schema it
60
+ * carries as a component along the way.
61
+ *
62
+ * The returned value is a `$ref` when the schema names itself, and the schema body when it doesn't.
63
+ */
64
+ export declare function convertSchema(schema: unknown, options: ConvertOptions): JSONSchema;
65
+ //# sourceMappingURL=json-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAA6C,MAAM,sBAAsB,CAAC;AAEjH,2DAA2D;AAC3D,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG,UAAU,GAAG,aAAa,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,QAAQ,CAAC,8BAA8B,CAAC,EAAE,OAAO,CAAC;IAClD,sFAAsF;IACtF,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,CAAC;IAC7C,iFAAiF;IACjF,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAC1C,6FAA6F;IAC7F,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;CAClC;AA0DD;;;;;GAKG;AACH,qBAAa,kBAAkB;;IAI7B,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAOxC;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzB;IAED,qGAAqG;IACrG,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE1B;IAED,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAS/C;CACF;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC,QAAQ,CAAC,aAAa,CAAC,EAAE,oBAAoB,GAAG,SAAS,CAAC;IAC1D,wFAAwF;IACxF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC1C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,UAAU,CAuBlF"}
@@ -0,0 +1,248 @@
1
+ import { ComponentNameConflictError, UnsupportedSchemaError } from './errors.js';
2
+ import { isStandardJSONSchema } from './standard-schema.js';
3
+ const DEFAULT_NORMALIZATION = {
4
+ dropStrictAdditionalProperties: true,
5
+ dropFormatImpliedPatterns: true,
6
+ collapseNullableUnions: true,
7
+ constToEnum: true,
8
+ orderKeywords: true,
9
+ };
10
+ /** The order OpenAPI documents conventionally present a schema's keywords in. */
11
+ const KEYWORD_ORDER = [
12
+ '$ref',
13
+ 'type',
14
+ 'format',
15
+ 'enum',
16
+ 'const',
17
+ 'pattern',
18
+ 'minLength',
19
+ 'maxLength',
20
+ 'minimum',
21
+ 'maximum',
22
+ 'exclusiveMinimum',
23
+ 'exclusiveMaximum',
24
+ 'multipleOf',
25
+ 'items',
26
+ 'prefixItems',
27
+ 'minItems',
28
+ 'maxItems',
29
+ 'uniqueItems',
30
+ 'properties',
31
+ 'patternProperties',
32
+ 'required',
33
+ 'additionalProperties',
34
+ 'allOf',
35
+ 'anyOf',
36
+ 'oneOf',
37
+ 'not',
38
+ 'discriminator',
39
+ 'title',
40
+ 'description',
41
+ 'example',
42
+ 'examples',
43
+ 'default',
44
+ 'readOnly',
45
+ 'writeOnly',
46
+ 'deprecated',
47
+ ];
48
+ const KEYWORD_RANK = new Map(KEYWORD_ORDER.map((keyword, index) => [keyword, index]));
49
+ /** Keywords whose values are data rather than subschemas, so the walk must not descend into them. */
50
+ const DATA_KEYWORDS = new Set(['example', 'examples', 'default', 'const', 'enum']);
51
+ const DEFINITIONS_KEYWORDS = ['$defs', 'definitions'];
52
+ const COMPONENT_SCHEMAS_POINTER = '#/components/schemas';
53
+ /**
54
+ * Collects the named schemas a document refers to.
55
+ *
56
+ * Names arrive from two places — a `$defs` key or an explicit `$id` — and both land here, so a schema
57
+ * referenced from several routes is emitted once and shared.
58
+ */
59
+ export class ComponentCollector {
60
+ /** Reserved-but-not-yet-generated names hold `undefined`, which keeps their place in the order. */
61
+ #schemas = new Map();
62
+ get schemas() {
63
+ const generated = {};
64
+ for (const [name, schema] of this.#schemas) {
65
+ if (schema != null)
66
+ generated[name] = schema;
67
+ }
68
+ return generated;
69
+ }
70
+ has(name) {
71
+ return this.#schemas.get(name) != null;
72
+ }
73
+ /** Holds a place for a schema that is about to be generated, keeping the document's order stable. */
74
+ reserve(name) {
75
+ if (!this.#schemas.has(name))
76
+ this.#schemas.set(name, undefined);
77
+ }
78
+ register(name, schema) {
79
+ const existing = this.#schemas.get(name);
80
+ if (existing != null) {
81
+ if (!deepEquals(existing, schema))
82
+ throw new ComponentNameConflictError(name);
83
+ return;
84
+ }
85
+ this.#schemas.set(name, schema);
86
+ }
87
+ }
88
+ /**
89
+ * Turns a schema into the fragment an OpenAPI document holds, registering every named schema it
90
+ * carries as a component along the way.
91
+ *
92
+ * The returned value is a `$ref` when the schema names itself, and the schema body when it doesn't.
93
+ */
94
+ export function convertSchema(schema, options) {
95
+ if (!isStandardJSONSchema(schema)) {
96
+ throw new UnsupportedSchemaError(isStandardSchemaLike(schema) ? schema['~standard'].vendor : undefined);
97
+ }
98
+ const raw = describe(schema, options.io, options.target);
99
+ const context = {
100
+ components: options.components,
101
+ normalization: { ...DEFAULT_NORMALIZATION, ...options.normalization },
102
+ pointers: new Map(),
103
+ };
104
+ const { definitions, root } = splitDefinitions(raw);
105
+ const named = options.name == null ? root : { $id: options.name, ...root };
106
+ // A schema claims its own place in the document before the schemas it refers to, so a composite
107
+ // reads ahead of its parts rather than after them.
108
+ reserve(named, context);
109
+ registerDefinitions(definitions, context);
110
+ if (options.hoistRoot === false)
111
+ return prepare(stripIdentity(root), context);
112
+ return walk(named, context);
113
+ }
114
+ function describe(schema, io, target) {
115
+ const converted = schema['~standard'].jsonSchema[io]({ target });
116
+ const { $schema: _dialect, ...rest } = converted;
117
+ return rest;
118
+ }
119
+ function splitDefinitions(raw) {
120
+ const root = { ...raw };
121
+ const definitions = {};
122
+ for (const keyword of DEFINITIONS_KEYWORDS) {
123
+ const block = root[keyword];
124
+ if (!isRecord(block))
125
+ continue;
126
+ delete root[keyword];
127
+ for (const [key, value] of Object.entries(block)) {
128
+ if (isRecord(value))
129
+ definitions[key] = value;
130
+ }
131
+ }
132
+ return { definitions, root };
133
+ }
134
+ /**
135
+ * Registers every definition as a component.
136
+ *
137
+ * Pointers are mapped first so that definitions referring to each other — in either direction —
138
+ * resolve, however they happen to be ordered.
139
+ */
140
+ function registerDefinitions(definitions, context) {
141
+ const named = Object.entries(definitions).map(([key, definition]) => ({
142
+ definition,
143
+ key,
144
+ name: typeof definition.$id === 'string' ? definition.$id : key,
145
+ }));
146
+ for (const { key, name } of named) {
147
+ for (const keyword of DEFINITIONS_KEYWORDS) {
148
+ context.pointers.set(`#/${keyword}/${key}`, `${COMPONENT_SCHEMAS_POINTER}/${name}`);
149
+ }
150
+ }
151
+ for (const { definition, name } of named) {
152
+ context.components.register(name, stripIdentity(prepare(definition, context)));
153
+ }
154
+ }
155
+ /** Claims a component slot for a self-naming schema, to be filled once the schema is walked. */
156
+ function reserve(node, context) {
157
+ if (typeof node.$id === 'string')
158
+ context.components.reserve(node.$id);
159
+ }
160
+ /** Walks a node, hoisting it into components when it names itself. */
161
+ function walk(node, context) {
162
+ const prepared = prepare(node, context);
163
+ const name = prepared.$id;
164
+ if (typeof name !== 'string')
165
+ return prepared;
166
+ context.components.register(name, stripIdentity(prepared));
167
+ return { $ref: `${COMPONENT_SCHEMAS_POINTER}/${name}` };
168
+ }
169
+ /** Rewrites references, descends into subschemas, then normalizes — but leaves `$id` in place. */
170
+ function prepare(node, context) {
171
+ const reference = node.$ref;
172
+ if (typeof reference === 'string') {
173
+ return { ...node, $ref: context.pointers.get(reference) ?? reference };
174
+ }
175
+ const walked = {};
176
+ for (const [key, value] of Object.entries(node)) {
177
+ walked[key] = DATA_KEYWORDS.has(key) ? value : walkChild(value, context);
178
+ }
179
+ return normalize(walked, context.normalization);
180
+ }
181
+ function walkChild(value, context) {
182
+ if (Array.isArray(value))
183
+ return value.map(entry => walkChild(entry, context));
184
+ if (!isRecord(value))
185
+ return value;
186
+ return walk(value, context);
187
+ }
188
+ function stripIdentity(schema) {
189
+ const { $id: _identity, ...rest } = schema;
190
+ return rest;
191
+ }
192
+ function normalize(schema, options) {
193
+ const collapsed = options.collapseNullableUnions ? collapseNullableUnion(schema) : schema;
194
+ const normalized = {};
195
+ for (const [key, value] of Object.entries(collapsed)) {
196
+ if (options.dropStrictAdditionalProperties && key === 'additionalProperties' && value === false)
197
+ continue;
198
+ if (options.dropFormatImpliedPatterns && key === 'pattern' && typeof collapsed.format === 'string')
199
+ continue;
200
+ if (options.constToEnum && key === 'const') {
201
+ normalized.enum = [value];
202
+ continue;
203
+ }
204
+ normalized[key] = value;
205
+ }
206
+ return options.orderKeywords ? orderKeywords(normalized) : normalized;
207
+ }
208
+ /** Sorts a schema's keywords into `KEYWORD_ORDER`, leaving anything unrecognized at the end. */
209
+ function orderKeywords(schema) {
210
+ const entries = Object.entries(schema);
211
+ const ranked = entries.map((entry, index) => ({
212
+ entry,
213
+ index,
214
+ rank: KEYWORD_RANK.get(entry[0]) ?? KEYWORD_ORDER.length,
215
+ }));
216
+ ranked.sort((left, right) => left.rank - right.rank || left.index - right.index);
217
+ return Object.fromEntries(ranked.map(({ entry }) => entry));
218
+ }
219
+ /**
220
+ * Rewrites the two-branch nullable union schema libraries produce into OpenAPI 3.1's nullable type
221
+ * array, so `string | null` reads as one schema instead of a union.
222
+ */
223
+ function collapseNullableUnion(schema) {
224
+ const branches = schema.anyOf;
225
+ if (!Array.isArray(branches) || branches.length !== 2)
226
+ return schema;
227
+ const nullBranchIndex = branches.findIndex(branch => isRecord(branch) && branch.type === 'null');
228
+ if (nullBranchIndex === -1)
229
+ return schema;
230
+ const valueBranch = branches[nullBranchIndex === 0 ? 1 : 0];
231
+ if (!isRecord(valueBranch) || typeof valueBranch.type !== 'string')
232
+ return schema;
233
+ if (Object.keys(valueBranch).some(key => key === '$ref' || key === '$id'))
234
+ return schema;
235
+ const { type, ...valueRest } = valueBranch;
236
+ const { anyOf: _branches, ...rest } = schema;
237
+ return { type: [null, type], ...valueRest, ...rest };
238
+ }
239
+ function isStandardSchemaLike(value) {
240
+ return isRecord(value) && isRecord(value['~standard']) && typeof value['~standard'].vendor === 'string';
241
+ }
242
+ function isRecord(value) {
243
+ return typeof value === 'object' && value != null && !Array.isArray(value);
244
+ }
245
+ function deepEquals(left, right) {
246
+ return JSON.stringify(left) === JSON.stringify(right);
247
+ }
248
+ //# sourceMappingURL=json-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EA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AAC,KAAK,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { ReferenceObject } from 'openapi3-ts/oas31';
2
+ import type { StandardSchema } from './standard-schema.ts';
3
+ import type { RouteConfigBase } from './types.ts';
4
+ export declare const COMPONENT_TYPES: readonly ['schemas', 'responses', 'parameters', 'examples', 'requestBodies', 'headers', 'securitySchemes', 'links', 'callbacks', 'pathItems'];
5
+ export type ComponentType = (typeof COMPONENT_TYPES)[number];
6
+ export type OpenAPIDefinition = {
7
+ readonly type: 'component';
8
+ readonly componentType: ComponentType;
9
+ readonly name: string;
10
+ readonly component: object;
11
+ } | {
12
+ readonly type: 'schema';
13
+ readonly schema: StandardSchema;
14
+ readonly name: string;
15
+ } | {
16
+ readonly type: 'route';
17
+ readonly route: RouteConfigBase;
18
+ } | {
19
+ readonly type: 'webhook';
20
+ readonly webhook: RouteConfigBase;
21
+ };
22
+ /**
23
+ * Collects what a document is made of.
24
+ *
25
+ * The registry only records; nothing here inspects a schema. Generation happens later, in one pass,
26
+ * so that a schema referenced from several routes still resolves to a single component.
27
+ */
28
+ export declare class OpenAPIRegistry {
29
+ #private;
30
+ constructor(parents?: OpenAPIRegistry[]);
31
+ get definitions(): OpenAPIDefinition[];
32
+ /** Names a schema so it becomes a component even when it carries no `$id`. */
33
+ register(name: string, schema: StandardSchema): StandardSchema;
34
+ nameOf(schema: StandardSchema): string | undefined;
35
+ registerPath(route: RouteConfigBase): void;
36
+ registerWebhook(webhook: RouteConfigBase): void;
37
+ registerComponent<T extends ComponentType>(componentType: T, name: string, component: object): {
38
+ name: string;
39
+ ref: ReferenceObject;
40
+ };
41
+ /** Copies another registry's definitions into this one, optionally re-rooting its routes. */
42
+ absorb(registry: OpenAPIRegistry, mapPath: (path: string) => string): void;
43
+ }
44
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAA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UjD;IAED,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAEzC;IAED,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAE9C;IAED,iBAAiB,CAAC,CAAC,SAAS,aAAa,EACvC,aAAa,EAAE,CAAC,EAChB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,eAAe,CAAA;KAAE,CAIxC;IAED,6FAA6F;IAC7F,MAAM,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAiBzE;CACF"}
@@ -0,0 +1,78 @@
1
+ export const COMPONENT_TYPES = [
2
+ 'schemas',
3
+ 'responses',
4
+ 'parameters',
5
+ 'examples',
6
+ 'requestBodies',
7
+ 'headers',
8
+ 'securitySchemes',
9
+ 'links',
10
+ 'callbacks',
11
+ 'pathItems',
12
+ ];
13
+ /**
14
+ * Collects what a document is made of.
15
+ *
16
+ * The registry only records; nothing here inspects a schema. Generation happens later, in one pass,
17
+ * so that a schema referenced from several routes still resolves to a single component.
18
+ */
19
+ export class OpenAPIRegistry {
20
+ #definitions = [];
21
+ #parents;
22
+ /** Names given to schemas out of band, for schemas that don't name themselves through `$id`. */
23
+ #names = new WeakMap();
24
+ constructor(parents = []) {
25
+ this.#parents = parents;
26
+ }
27
+ get definitions() {
28
+ const fromParents = this.#parents.flatMap(parent => parent.definitions);
29
+ return [...fromParents, ...this.#definitions];
30
+ }
31
+ /** Names a schema so it becomes a component even when it carries no `$id`. */
32
+ register(name, schema) {
33
+ this.#names.set(schema, name);
34
+ this.#definitions.push({ name, schema, type: 'schema' });
35
+ return schema;
36
+ }
37
+ nameOf(schema) {
38
+ const own = this.#names.get(schema);
39
+ if (own != null)
40
+ return own;
41
+ for (const parent of this.#parents) {
42
+ const inherited = parent.nameOf(schema);
43
+ if (inherited != null)
44
+ return inherited;
45
+ }
46
+ return undefined;
47
+ }
48
+ registerPath(route) {
49
+ this.#definitions.push({ route, type: 'route' });
50
+ }
51
+ registerWebhook(webhook) {
52
+ this.#definitions.push({ type: 'webhook', webhook });
53
+ }
54
+ registerComponent(componentType, name, component) {
55
+ this.#definitions.push({ component, componentType, name, type: 'component' });
56
+ return { name, ref: { $ref: `#/components/${componentType}/${name}` } };
57
+ }
58
+ /** Copies another registry's definitions into this one, optionally re-rooting its routes. */
59
+ absorb(registry, mapPath) {
60
+ for (const definition of registry.definitions) {
61
+ switch (definition.type) {
62
+ case 'component':
63
+ this.registerComponent(definition.componentType, definition.name, definition.component);
64
+ break;
65
+ case 'schema':
66
+ this.register(definition.name, definition.schema);
67
+ break;
68
+ case 'route':
69
+ this.registerPath({ ...definition.route, path: mapPath(definition.route.path) });
70
+ break;
71
+ case 'webhook':
72
+ this.registerWebhook({ ...definition.webhook, path: mapPath(definition.webhook.path) });
73
+ break;
74
+ }
75
+ }
76
+ }
77
+ }
78
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,SAAS;IACT,WAAW;IACX,YAAY;IACZ,UAAU;IACV,eAAe;IACf,SAAS;IACT,iBAAiB;IACjB,OAAO;IACP,WAAW;IACX,WAAW;CACH,CAAC;AAeX;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IACjB,YAAY,GAAwB,EAAE,CAAC;IACvC,QAAQ,CAAoB;IACrC,gGAAgG;IACvF,MAAM,GAAG,IAAI,OAAO,EAA0B,CAAC;IAExD,YAAY,OAAO,GAAsB,EAAE;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,IAAI,WAAW;QACb,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,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I,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,gBAAgB,aAAa,IAAI,IAAI,EAAE,EAAE,EAAE,CAAC;IAC1E,CAAC;IAED,6FAA6F;IAC7F,MAAM,CAAC,QAAyB,EAAE,OAAiC;QACjE,KAAK,MAAM,UAAU,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;YAC9C,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;gBACxB,KAAK,WAAW;oBACd,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,aAAa,EAAE,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;oBACxF,MAAM;gBACR,KAAK,QAAQ;oBACX,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;oBAClD,MAAM;gBACR,KAAK,OAAO;oBACV,IAAI,CAAC,YAAY,CAAC,EAAE,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBACjF,MAAM;gBACR,KAAK,SAAS;oBACZ,IAAI,CAAC,eAAe,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBACxF,MAAM;YACV,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ import type { Env, MiddlewareHandler } from 'hono';
2
+ import type { ConvertPathType } from './type-inference.ts';
3
+ import type { RouteConfigBase } from './types.ts';
4
+ export interface RouteConfig extends RouteConfigBase {
5
+ /** Middleware to run before this route's validators and handler. */
6
+ readonly middleware?: MiddlewareHandler<Env> | readonly MiddlewareHandler<Env>[] | undefined;
7
+ /** Keeps the route out of the generated document while still serving it. */
8
+ readonly hide?: boolean | undefined;
9
+ }
10
+ /**
11
+ * Describes a route once, for both the router and the document.
12
+ *
13
+ * The returned config carries a non-enumerable `getRoutingPath()`, so the OpenAPI path stays exactly
14
+ * as written while Hono gets the `:param` form it needs, and neither the document nor an equality
15
+ * check on the config ever sees the extra key.
16
+ */
17
+ export declare function createRoute<P extends string, R extends Omit<RouteConfig, 'path'> & {
18
+ path: P;
19
+ }>(routeConfig: R): R & {
20
+ getRoutingPath(): ConvertPathType<P>;
21
+ };
22
+ /** Rewrites `/cards/{cardId}` as `/cards/:cardId`, the same rewrite `ConvertPathType` describes. */
23
+ export declare function toRoutingPath<P extends string>(path: P): ConvertPathType<P>;
24
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD,oEAAoE;IACpE,QAAQ,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC,GAAG,CAAC,GAAG,SAAS,iBAAiB,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,CAAC;IAC7F,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACrC;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,EAC7F,WAAW,EAAE,CAAC,GACb,CAAC,GAAG;IAAE,cAAc,IAAI,eAAe,CAAC,CAAC,CAAC,CAAA;CAAE,CAO9C;AAED,oGAAoG;AACpG,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAG3E"}
package/dist/route.js ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Describes a route once, for both the router and the document.
3
+ *
4
+ * The returned config carries a non-enumerable `getRoutingPath()`, so the OpenAPI path stays exactly
5
+ * as written while Hono gets the `:param` form it needs, and neither the document nor an equality
6
+ * check on the config ever sees the extra key.
7
+ */
8
+ export function createRoute(routeConfig) {
9
+ const routingPath = toRoutingPath(routeConfig.path);
10
+ const route = { ...routeConfig, getRoutingPath: () => routingPath };
11
+ Object.defineProperty(route, 'getRoutingPath', { enumerable: false });
12
+ return route;
13
+ }
14
+ /** Rewrites `/cards/{cardId}` as `/cards/:cardId`, the same rewrite `ConvertPathType` describes. */
15
+ export function toRoutingPath(path) {
16
+ // @ts-expect-error: the runtime rewrite is the one `ConvertPathType` performs in the type system.
17
+ return path.replaceAll(/\/{(.+?)}/g, '/:$1');
18
+ }
19
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../src/route.ts"],"names":[],"mappings":"AAYA;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,WAAc;IAEd,MAAM,WAAW,GAAG,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,EAAE,GAAG,WAAW,EAAE,cAAc,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;IAEpE,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAEtE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,aAAa,CAAmB,IAAO;IACrD,kGAAkG;IAClG,OAAO,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';
2
+ export type { StandardJSONSchemaV1, StandardSchemaV1 };
3
+ /**
4
+ * A schema that can both validate values and describe itself as JSON Schema.
5
+ *
6
+ * Every schema handed to a route needs both halves: validation drives the request middleware and the
7
+ * JSON Schema conversion drives the OpenAPI document.
8
+ */
9
+ export type StandardSchema = StandardSchemaV1 & StandardJSONSchemaV1;
10
+ /** A JSON Schema document fragment, as produced by a Standard JSON Schema converter. */
11
+ export type JSONSchema = Record<string, unknown>;
12
+ /** Which side of a schema to describe: what a request accepts, or what a response produces. */
13
+ export type SchemaIO = 'input' | 'output';
14
+ export declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
15
+ export declare function isStandardJSONSchema(value: unknown): value is StandardSchema;
16
+ export declare function validateWithStandardSchema(schema: StandardSchemaV1, value: unknown): StandardSchemaV1.Result<unknown> | Promise<StandardSchemaV1.Result<unknown>>;
17
+ //# sourceMappingURL=standard-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-schema.d.ts","sourceRoot":"","sources":["../src/standard-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEpF,YAAY,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,gBAAgB,GAAG,oBAAoB,CAAC;AAErE,wFAAwF;AACxF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,+FAA+F;AAC/F,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE1C,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAM1E;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAM5E;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,OAAO,GACb,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAE9E"}
@@ -0,0 +1,16 @@
1
+ export function isStandardSchema(value) {
2
+ if (typeof value !== 'object' || value == null || !('~standard' in value))
3
+ return false;
4
+ const props = value['~standard'];
5
+ return typeof props === 'object' && props != null && 'version' in props && props.version === 1;
6
+ }
7
+ export function isStandardJSONSchema(value) {
8
+ if (!isStandardSchema(value))
9
+ return false;
10
+ const props = value['~standard'];
11
+ return typeof props.jsonSchema === 'object' && props.jsonSchema != null;
12
+ }
13
+ export function validateWithStandardSchema(schema, value) {
14
+ return schema['~standard'].validate(value);
15
+ }
16
+ //# sourceMappingURL=standard-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-schema.js","sourceRoot":"","sources":["../src/standard-schema.ts"],"names":[],"mappings":"AAkBA,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAExF,MAAM,KAAK,GAAY,KAAK,CAAC,WAAW,CAAC,CAAC;IAE1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,IAAI,IAAI,SAAS,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC;AACjG,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAE3C,MAAM,KAAK,GAAsD,KAAK,CAAC,WAAW,CAAC,CAAC;IAEpF,OAAO,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,MAAwB,EACxB,KAAc;IAEd,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC"}