@ir-kit/openapi 0.1.0 → 0.3.0
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.
- package/README.md +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/operation/body.d.ts +23 -31
- package/dist/operation/body.d.ts.map +1 -1
- package/dist/operation/body.js +24 -17
- package/dist/operation/body.js.map +1 -1
- package/dist/operation/iter.d.ts +1 -1
- package/dist/operation/iter.d.ts.map +1 -1
- package/dist/operation/iter.js +2 -1
- package/dist/operation/iter.js.map +1 -1
- package/dist/operation/responses.d.ts +14 -34
- package/dist/operation/responses.d.ts.map +1 -1
- package/dist/operation/responses.js +21 -21
- package/dist/operation/responses.js.map +1 -1
- package/dist/operation/signature.d.ts +1 -1
- package/dist/operation/signature.js +1 -1
- package/dist/spec/constants.d.ts +20 -0
- package/dist/spec/constants.d.ts.map +1 -0
- package/dist/spec/constants.js +37 -0
- package/dist/spec/constants.js.map +1 -0
- package/dist/spec/normalize/allOf.d.ts +3 -0
- package/dist/spec/normalize/allOf.d.ts.map +1 -0
- package/dist/spec/normalize/allOf.js +42 -0
- package/dist/spec/normalize/allOf.js.map +1 -0
- package/dist/spec/normalize/enums.d.ts +10 -0
- package/dist/spec/normalize/enums.d.ts.map +1 -0
- package/dist/spec/normalize/enums.js +121 -0
- package/dist/spec/normalize/enums.js.map +1 -0
- package/dist/spec/normalize/index.d.ts +20 -0
- package/dist/spec/normalize/index.d.ts.map +1 -0
- package/dist/spec/normalize/index.js +37 -0
- package/dist/spec/normalize/index.js.map +1 -0
- package/dist/spec/normalize/metadata.d.ts +12 -0
- package/dist/spec/normalize/metadata.d.ts.map +1 -0
- package/dist/spec/normalize/metadata.js +49 -0
- package/dist/spec/normalize/metadata.js.map +1 -0
- package/dist/spec/normalize/name.d.ts +8 -0
- package/dist/spec/normalize/name.d.ts.map +1 -0
- package/dist/spec/normalize/name.js +24 -0
- package/dist/spec/normalize/name.js.map +1 -0
- package/dist/spec/normalize/objects.d.ts +14 -0
- package/dist/spec/normalize/objects.d.ts.map +1 -0
- package/dist/spec/normalize/objects.js +229 -0
- package/dist/spec/normalize/objects.js.map +1 -0
- package/dist/spec/normalize/prune.d.ts +15 -0
- package/dist/spec/normalize/prune.d.ts.map +1 -0
- package/dist/spec/normalize/prune.js +87 -0
- package/dist/spec/normalize/prune.js.map +1 -0
- package/dist/spec/normalize/walk.d.ts +21 -0
- package/dist/spec/normalize/walk.d.ts.map +1 -0
- package/dist/spec/normalize/walk.js +91 -0
- package/dist/spec/normalize/walk.js.map +1 -0
- package/dist/spec/ref.d.ts +7 -0
- package/dist/spec/ref.d.ts.map +1 -0
- package/dist/spec/ref.js +18 -0
- package/dist/spec/ref.js.map +1 -0
- package/dist/spec/security.d.ts +22 -0
- package/dist/spec/security.d.ts.map +1 -0
- package/dist/spec/security.js +47 -0
- package/dist/spec/security.js.map +1 -0
- package/dist/type/dispatch.d.ts +36 -64
- package/dist/type/dispatch.d.ts.map +1 -1
- package/dist/type/dispatch.js +31 -54
- package/dist/type/dispatch.js.map +1 -1
- package/package.json +2 -2
- package/dist/type/enum.d.ts +0 -42
- package/dist/type/enum.d.ts.map +0 -1
- package/dist/type/enum.js +0 -49
- package/dist/type/enum.js.map +0 -1
- package/dist/type/object.d.ts +0 -53
- package/dist/type/object.d.ts.map +0 -1
- package/dist/type/object.js +0 -36
- package/dist/type/object.js.map +0 -1
- package/dist/type/union.d.ts +0 -35
- package/dist/type/union.d.ts.map +0 -1
- package/dist/type/union.js +0 -29
- package/dist/type/union.js.map +0 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { refToName } from "@hey-api/shared";
|
|
2
|
+
import { getSchemasObject, schemasPointerPrefix } from "./walk.js";
|
|
3
|
+
/**
|
|
4
|
+
* Drop unreferenced `components.schemas` entries. Scoped to `targets`
|
|
5
|
+
* when supplied; otherwise performs a global reachability sweep
|
|
6
|
+
* (operations + non-schema components, then transitive closure).
|
|
7
|
+
*/
|
|
8
|
+
export function pruneUnusedSchemas(spec, opts = {}) {
|
|
9
|
+
if (opts.targets && opts.targets.size === 0)
|
|
10
|
+
return;
|
|
11
|
+
const schemas = getSchemasObject(spec);
|
|
12
|
+
if (!schemas)
|
|
13
|
+
return;
|
|
14
|
+
const pointerPrefix = schemasPointerPrefix(spec);
|
|
15
|
+
if (!pointerPrefix)
|
|
16
|
+
return;
|
|
17
|
+
const reachable = new Set();
|
|
18
|
+
if (opts.targets) {
|
|
19
|
+
// Any reference anywhere — even from a dead authored schema — keeps
|
|
20
|
+
// a hoisted target alive, otherwise the surviving authored schema
|
|
21
|
+
// would carry a dangling `$ref`.
|
|
22
|
+
collectRefs(spec, reachable,
|
|
23
|
+
/* skipComponentsSchemas */ false, pointerPrefix);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
collectRefs(spec, reachable,
|
|
27
|
+
/* skipComponentsSchemas */ true, pointerPrefix);
|
|
28
|
+
let frontier = new Set(reachable);
|
|
29
|
+
while (frontier.size > 0) {
|
|
30
|
+
const next = new Set();
|
|
31
|
+
for (const name of frontier) {
|
|
32
|
+
const schema = schemas[name];
|
|
33
|
+
if (!schema)
|
|
34
|
+
continue;
|
|
35
|
+
const refs = new Set();
|
|
36
|
+
collectRefs(schema, refs,
|
|
37
|
+
/* skipComponentsSchemas */ false, pointerPrefix);
|
|
38
|
+
for (const ref of refs) {
|
|
39
|
+
if (!reachable.has(ref)) {
|
|
40
|
+
reachable.add(ref);
|
|
41
|
+
next.add(ref);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
frontier = next;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
for (const name of Object.keys(schemas)) {
|
|
49
|
+
if (reachable.has(name))
|
|
50
|
+
continue;
|
|
51
|
+
if (opts.targets && !opts.targets.has(name))
|
|
52
|
+
continue;
|
|
53
|
+
delete schemas[name];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function collectRefs(node, out, skipComponentsSchemas, pointerPrefix, inComponents = false) {
|
|
57
|
+
if (!node || typeof node !== "object")
|
|
58
|
+
return;
|
|
59
|
+
if (Array.isArray(node)) {
|
|
60
|
+
for (const item of node) {
|
|
61
|
+
collectRefs(item, out, skipComponentsSchemas, pointerPrefix, inComponents);
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const value = node;
|
|
66
|
+
for (const [k, v] of Object.entries(value)) {
|
|
67
|
+
if (k === "$ref" && typeof v === "string" && v.startsWith(pointerPrefix)) {
|
|
68
|
+
out.add(refToName(v));
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (skipComponentsSchemas && !inComponents && k === "components") {
|
|
72
|
+
collectRefsInComponents(v, out, pointerPrefix);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
collectRefs(v, out, skipComponentsSchemas, pointerPrefix, inComponents);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function collectRefsInComponents(node, out, pointerPrefix) {
|
|
79
|
+
if (!node || typeof node !== "object" || Array.isArray(node))
|
|
80
|
+
return;
|
|
81
|
+
for (const [k, v] of Object.entries(node)) {
|
|
82
|
+
if (k === "schemas")
|
|
83
|
+
continue;
|
|
84
|
+
collectRefs(v, out, /* skip */ false, pointerPrefix, true);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=prune.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prune.js","sourceRoot":"","sources":["../../../src/spec/normalize/prune.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAWnE;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAa,EACb,OAAqB,EA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;YACjE,uBAAuB,CAAC,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;YAC/C,SAAS;QACX,CAAC;QACD,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,qBAAqB,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC;AAED,SAAS,uBAAuB,CAC9B,IAAa,EACb,GAAgB,EAChB,aAAqB;IAErB,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO;IACrE,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1C,IAAI,CAAC,KAAK,SAAS;YAAE,SAAS;QAC9B,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern adapted from @hey-api/openapi-ts (MIT) —
|
|
3
|
+
* `packages/shared/src/openApi/shared/transforms/enums.ts`.
|
|
4
|
+
* Walker, root-path detection, and pointer-prefix logic mirror the
|
|
5
|
+
* upstream private helpers, which aren't re-exported.
|
|
6
|
+
*/
|
|
7
|
+
export interface SchemaNode {
|
|
8
|
+
key: string | number | null;
|
|
9
|
+
node: unknown;
|
|
10
|
+
parent: unknown;
|
|
11
|
+
path: ReadonlyArray<string | number>;
|
|
12
|
+
}
|
|
13
|
+
/** Visit every schema-shaped object in `spec`. */
|
|
14
|
+
export declare function walkSchemas(spec: unknown, visit: (n: SchemaNode) => void): void;
|
|
15
|
+
/** True when `path` points at `components.schemas.<X>` or `definitions.<X>`. */
|
|
16
|
+
export declare function isRootSchemaPath(path: ReadonlyArray<string | number>): boolean;
|
|
17
|
+
/** Pointer prefix for shared schemas (OpenAPI 3.x or Swagger 2.0). */
|
|
18
|
+
export declare function schemasPointerPrefix(spec: unknown): string;
|
|
19
|
+
/** Live handle on the spec's shared-schema map; creates containers if absent. */
|
|
20
|
+
export declare function getSchemasObject(spec: unknown): Record<string, unknown> | undefined;
|
|
21
|
+
//# sourceMappingURL=walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../../src/spec/normalize/walk.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoBH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CACtC;AAED,kDAAkD;AAClD,wBAAgB,WAAW,CACzB,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,GAC7B,IAAI,CAEN;AAgCD,gFAAgF;AAChF,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,GACnC,OAAO,CAKT;AAED,sEAAsE;AACtE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAK1D;AAED,iFAAiF;AACjF,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAgBrC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern adapted from @hey-api/openapi-ts (MIT) —
|
|
3
|
+
* `packages/shared/src/openApi/shared/transforms/enums.ts`.
|
|
4
|
+
* Walker, root-path detection, and pointer-prefix logic mirror the
|
|
5
|
+
* upstream private helpers, which aren't re-exported.
|
|
6
|
+
*/
|
|
7
|
+
/** JSON Schema keywords that hold child schemas. */
|
|
8
|
+
const CHILD_SCHEMA_KEYWORDS = [
|
|
9
|
+
"additionalProperties",
|
|
10
|
+
"allOf",
|
|
11
|
+
"anyOf",
|
|
12
|
+
"contains",
|
|
13
|
+
"dependentSchemas",
|
|
14
|
+
"else",
|
|
15
|
+
"if",
|
|
16
|
+
"items",
|
|
17
|
+
"oneOf",
|
|
18
|
+
"patternProperties",
|
|
19
|
+
"properties",
|
|
20
|
+
"propertyNames",
|
|
21
|
+
"then",
|
|
22
|
+
"unevaluatedProperties",
|
|
23
|
+
];
|
|
24
|
+
/** Visit every schema-shaped object in `spec`. */
|
|
25
|
+
export function walkSchemas(spec, visit) {
|
|
26
|
+
walk({ key: null, node: spec, parent: null, path: [] }, visit);
|
|
27
|
+
}
|
|
28
|
+
function walk(n, visit) {
|
|
29
|
+
const { node, path } = n;
|
|
30
|
+
if (!node || typeof node !== "object" || Array.isArray(node))
|
|
31
|
+
return;
|
|
32
|
+
const value = node;
|
|
33
|
+
if (isSchemaShaped(value))
|
|
34
|
+
visit(n);
|
|
35
|
+
for (const [k, v] of Object.entries(value)) {
|
|
36
|
+
if (v === null || typeof v !== "object")
|
|
37
|
+
continue;
|
|
38
|
+
if (Array.isArray(v)) {
|
|
39
|
+
v.forEach((item, index) => walk({ key: index, node: item, parent: v, path: [...path, k, index] }, visit));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
walk({ key: k, node: v, parent: node, path: [...path, k] }, visit);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function isSchemaShaped(value) {
|
|
47
|
+
if ("type" in value || "enum" in value)
|
|
48
|
+
return true;
|
|
49
|
+
for (const keyword of CHILD_SCHEMA_KEYWORDS) {
|
|
50
|
+
if (keyword in value)
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
/** True when `path` points at `components.schemas.<X>` or `definitions.<X>`. */
|
|
56
|
+
export function isRootSchemaPath(path) {
|
|
57
|
+
if (path.length === 3 && path[0] === "components" && path[1] === "schemas") {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return path.length === 2 && path[0] === "definitions";
|
|
61
|
+
}
|
|
62
|
+
/** Pointer prefix for shared schemas (OpenAPI 3.x or Swagger 2.0). */
|
|
63
|
+
export function schemasPointerPrefix(spec) {
|
|
64
|
+
if (!spec || typeof spec !== "object")
|
|
65
|
+
return "";
|
|
66
|
+
if ("openapi" in spec)
|
|
67
|
+
return "#/components/schemas/";
|
|
68
|
+
if ("swagger" in spec)
|
|
69
|
+
return "#/definitions/";
|
|
70
|
+
return "";
|
|
71
|
+
}
|
|
72
|
+
/** Live handle on the spec's shared-schema map; creates containers if absent. */
|
|
73
|
+
export function getSchemasObject(spec) {
|
|
74
|
+
if (!spec || typeof spec !== "object")
|
|
75
|
+
return undefined;
|
|
76
|
+
const s = spec;
|
|
77
|
+
if ("openapi" in s) {
|
|
78
|
+
const components = (s.components ?? {});
|
|
79
|
+
s.components = components;
|
|
80
|
+
const schemas = (components.schemas ?? {});
|
|
81
|
+
components.schemas = schemas;
|
|
82
|
+
return schemas;
|
|
83
|
+
}
|
|
84
|
+
if ("swagger" in s) {
|
|
85
|
+
const defs = (s.definitions ?? {});
|
|
86
|
+
s.definitions = defs;
|
|
87
|
+
return defs;
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=walk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"walk.js","sourceRoot":"","sources":["../../../src/spec/normalize/walk.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,oDAAoD;AACpD,MAAM,qBAAqB,GAA0B;IACnD,sBAAsB;IACtB,OAAO;IACP,OAAO;IACP,UAAU;IACV,kBAAkB;IAClB,MAAM;IACN,IAAI;IACJ,OAAO;IACP,OAAO;IACP,mBAAmB;IACnB,YAAY;IACZ,eAAe;IACf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AAC,CAAC,UAAU,GAAG,UAAU,CAAC;QAC1B,MAAM,OAAO,GAAG,CAAC,UAAU,CAAC,OAAO,IAAI,EAAE,CAA4B,CAAC;QACtE,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,IAAI,EAAE,CAA4B,CAAC;QAC9D,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Schema } from "@ir-kit/schema";
|
|
2
|
+
/**
|
|
3
|
+
* Empty / unknown / void schemas — short-circuits a 2xx response to a
|
|
4
|
+
* no-payload return (Kotlin `Unit`, Swift `Void`, Go's absent return).
|
|
5
|
+
*/
|
|
6
|
+
export declare function isMeaningless(s: Schema): boolean;
|
|
7
|
+
//# sourceMappingURL=ref.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/spec/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAOhD"}
|
package/dist/spec/ref.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Empty / unknown / void schemas — short-circuits a 2xx response to a
|
|
3
|
+
* no-payload return (Kotlin `Unit`, Swift `Void`, Go's absent return).
|
|
4
|
+
*/
|
|
5
|
+
export function isMeaningless(s) {
|
|
6
|
+
if (s.$ref || s.const !== undefined)
|
|
7
|
+
return false;
|
|
8
|
+
if (s.items)
|
|
9
|
+
return false;
|
|
10
|
+
if (s.properties && Object.keys(s.properties).length > 0)
|
|
11
|
+
return false;
|
|
12
|
+
if (s.oneOf?.length || s.anyOf?.length || s.allOf?.length)
|
|
13
|
+
return false;
|
|
14
|
+
if (s.enum && s.enum.length > 0)
|
|
15
|
+
return false;
|
|
16
|
+
return s.type === undefined;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/spec/ref.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,CAAS;IACrC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAClD,IAAI,CAAC,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IAC1B,IAAI,CAAC,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACvE,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM;QAAE,OAAO,KAAK,CAAC;IACxE,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9C,OAAO,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-operation security-scheme NAME extraction. hey-api's IR drops
|
|
3
|
+
* scheme names from `op.security` (it inlines the resolved scheme
|
|
4
|
+
* objects into a different shape), leaving downstream generators with
|
|
5
|
+
* no way to wire `client.auth["<name>"]`. So we walk the raw bundled
|
|
6
|
+
* spec instead and key results by `${path}|${method}` for fast
|
|
7
|
+
* lookups during the IR pass.
|
|
8
|
+
*
|
|
9
|
+
* Map shape: `"/me|get" → ["bearerAuth", "apiKeyAuth"]`.
|
|
10
|
+
*
|
|
11
|
+
* An operation with `security: [{a: []}, {b: []}]` (logical OR — any
|
|
12
|
+
* scheme satisfies the requirement) and an operation with
|
|
13
|
+
* `security: [{a: [], b: []}]` (logical AND — both required) both
|
|
14
|
+
* collapse to the same name set here. Generators currently apply
|
|
15
|
+
* every scheme that has a matching `client.auth` entry; if we ever
|
|
16
|
+
* need to honour OR/AND semantics, this map needs to grow shape.
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractSecuritySchemeNames(spec: Record<string, unknown>): Map<string, ReadonlyArray<string>>;
|
|
19
|
+
/** Key used in the security-scheme map for one (path, method) pair.
|
|
20
|
+
* The pipe is non-URL-safe so it can't collide with a path segment. */
|
|
21
|
+
export declare const securityKey: (path: string, method: string) => string;
|
|
22
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/spec/security.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAuBpC;AAED;wEACwE;AACxE,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,MACtC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-operation security-scheme NAME extraction. hey-api's IR drops
|
|
3
|
+
* scheme names from `op.security` (it inlines the resolved scheme
|
|
4
|
+
* objects into a different shape), leaving downstream generators with
|
|
5
|
+
* no way to wire `client.auth["<name>"]`. So we walk the raw bundled
|
|
6
|
+
* spec instead and key results by `${path}|${method}` for fast
|
|
7
|
+
* lookups during the IR pass.
|
|
8
|
+
*
|
|
9
|
+
* Map shape: `"/me|get" → ["bearerAuth", "apiKeyAuth"]`.
|
|
10
|
+
*
|
|
11
|
+
* An operation with `security: [{a: []}, {b: []}]` (logical OR — any
|
|
12
|
+
* scheme satisfies the requirement) and an operation with
|
|
13
|
+
* `security: [{a: [], b: []}]` (logical AND — both required) both
|
|
14
|
+
* collapse to the same name set here. Generators currently apply
|
|
15
|
+
* every scheme that has a matching `client.auth` entry; if we ever
|
|
16
|
+
* need to honour OR/AND semantics, this map needs to grow shape.
|
|
17
|
+
*/
|
|
18
|
+
export function extractSecuritySchemeNames(spec) {
|
|
19
|
+
const map = new Map();
|
|
20
|
+
const paths = (spec.paths ?? {});
|
|
21
|
+
for (const [pathStr, pathItem] of Object.entries(paths)) {
|
|
22
|
+
if (!pathItem || typeof pathItem !== "object")
|
|
23
|
+
continue;
|
|
24
|
+
for (const [method, op] of Object.entries(pathItem)) {
|
|
25
|
+
if (!op || typeof op !== "object")
|
|
26
|
+
continue;
|
|
27
|
+
const security = op.security;
|
|
28
|
+
if (!Array.isArray(security))
|
|
29
|
+
continue;
|
|
30
|
+
const names = new Set();
|
|
31
|
+
for (const requirement of security) {
|
|
32
|
+
if (requirement && typeof requirement === "object") {
|
|
33
|
+
for (const name of Object.keys(requirement))
|
|
34
|
+
names.add(name);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (names.size > 0) {
|
|
38
|
+
map.set(securityKey(pathStr, method), [...names]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return map;
|
|
43
|
+
}
|
|
44
|
+
/** Key used in the security-scheme map for one (path, method) pair.
|
|
45
|
+
* The pipe is non-URL-safe so it can't collide with a path segment. */
|
|
46
|
+
export const securityKey = (path, method) => `${path}|${method}`;
|
|
47
|
+
//# sourceMappingURL=security.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.js","sourceRoot":"","sources":["../../src/spec/security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AM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,MAAc,EAAU,EAAE,CAClE,GAAG,IAAI,IAAI,MAAM,EAAE,CAAC"}
|
package/dist/type/dispatch.d.ts
CHANGED
|
@@ -1,86 +1,58 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ObjectProperty, type Schema } from "@ir-kit/schema";
|
|
2
2
|
import type { TypeCtx } from "./context.js";
|
|
3
|
-
import { assertNoEnumCollisions } from "./enum.js";
|
|
4
|
-
import { classifyObjectShape, iterateObjectProperties, type ObjectProperty } from "./object.js";
|
|
5
|
-
import { classifyUnion } from "./union.js";
|
|
6
3
|
/**
|
|
7
|
-
* Per-target leaf operations the shared dispatchers (schemaToType
|
|
8
|
-
* unionToType
|
|
9
|
-
*
|
|
10
|
-
* decl type (GoDecl / KtDecl / SwDecl).
|
|
4
|
+
* Per-target leaf operations the shared dispatchers (`schemaToType`,
|
|
5
|
+
* `unionToType`, `inlineObjectType`) call into. `T` is the emitter's
|
|
6
|
+
* target type (`GoType` / `KtType` / `SwType`), `D` its decl type.
|
|
11
7
|
*
|
|
12
|
-
* Each emitter writes one of these records.
|
|
13
|
-
* (pointer vs nullable, naming conventions, synthName joiner,
|
|
14
|
-
*
|
|
15
|
-
* stay neutral.
|
|
8
|
+
* Each emitter writes one of these records. All per-target rendering
|
|
9
|
+
* (pointer vs nullable, naming conventions, synthName joiner, decl
|
|
10
|
+
* construction) lives here; the dispatchers stay neutral.
|
|
16
11
|
*/
|
|
17
12
|
export interface SchemaToTypeOps<T, D> {
|
|
18
|
-
/** `$ref` → named target type. */
|
|
19
13
|
refType(name: string): T;
|
|
20
|
-
/** Array element → target array/slice/list type. */
|
|
21
14
|
arrayType(elem: T): T;
|
|
22
|
-
/** Open object's value type — target map's value-of-Any. */
|
|
23
15
|
mapType(valueType: T): T;
|
|
24
|
-
/** "
|
|
16
|
+
/** Caller's "no return" analog — `goAny` (drops the result slot),
|
|
25
17
|
* `ktUnit`, `swVoid`. */
|
|
26
18
|
voidType(): T;
|
|
27
|
-
/**
|
|
19
|
+
/** Caller's untyped fallback — `goAny` / `ktAny` / `swAny`. */
|
|
28
20
|
anyType(): T;
|
|
29
|
-
/** Standalone nullable-any — what `null`-typed primitives become.
|
|
30
|
-
* Go wraps any in pointer; Kotlin / Swift wrap in nullable/optional. */
|
|
21
|
+
/** Standalone nullable-any — what `null`-typed primitives become. */
|
|
31
22
|
nullableAnyType(): T;
|
|
32
|
-
/** Wrap a known type in the target's optional wrapper for the
|
|
33
|
-
*
|
|
34
|
-
* (`isPointerable`
|
|
35
|
-
*
|
|
23
|
+
/** Wrap a known type in the target's optional wrapper for the union
|
|
24
|
+
* "single + nullable" path. Go's choice is conditional
|
|
25
|
+
* (`isPointerable`), so the hook receives both the inner type and
|
|
26
|
+
* the nullable bit. */
|
|
36
27
|
wrapForUnionSingle(inner: T, nullable: boolean): T;
|
|
37
|
-
/** Fallback type for unions with 2+ non-null branches.
|
|
38
|
-
*
|
|
39
|
-
* Swift wrap if nullable. */
|
|
28
|
+
/** Fallback type for unions with 2+ non-null branches. Go ignores
|
|
29
|
+
* `nullable` (interface already holds nil); Kotlin / Swift wrap. */
|
|
40
30
|
unionFallback(nullable: boolean): T;
|
|
41
|
-
/** Primitive dispatch
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
* Swift / TypeScript use `"_"`. */
|
|
31
|
+
/** Primitive dispatch. Returns `undefined` for non-primitive schemas
|
|
32
|
+
* so the outer dispatcher can fall through. */
|
|
33
|
+
primitiveType(schema: Schema): T | undefined;
|
|
34
|
+
/** Build a synth name from `ctx.ownerName` + `propPath`. Joiner is
|
|
35
|
+
* per-target — Go uses `""` to keep `go vet` quiet, Kotlin / Swift
|
|
36
|
+
* use `"_"`. */
|
|
48
37
|
synthName(ownerName: string, propPath: ReadonlyArray<string>): string;
|
|
49
|
-
|
|
50
|
-
* property list. Per-target work: property identifier transform,
|
|
51
|
-
* optional wrapping, target field construction, annotation /
|
|
52
|
-
* coding-key emission. Returns the decl; the caller chooses to
|
|
53
|
-
* `emit` it (dispatcher does this; schema.ts also calls this
|
|
54
|
-
* directly for top-level component schemas). */
|
|
55
|
-
buildStructDecl(name: string, properties: ReadonlyArray<ObjectProperty>, ctx: TypeCtx<D>, dispatch: (s: IR.SchemaObject, c: TypeCtx<D>) => T): D;
|
|
56
|
-
/** Emit a string-typed enum decl and return a ref. Per-target work:
|
|
57
|
-
* case-identifier transform (Go `<Type><Raw>`, Kotlin
|
|
58
|
-
* `SCREAMING_SNAKE`, Swift `camel`), decl construction, runtime
|
|
59
|
-
* bookkeeping (`@SerialName`, `Codable` conformance). */
|
|
38
|
+
buildStructDecl(name: string, properties: ReadonlyArray<ObjectProperty>, ctx: TypeCtx<D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): D;
|
|
60
39
|
emitStringEnum(name: string, raws: ReadonlyArray<string>, emit: (d: D) => void): T;
|
|
61
|
-
/** Same for integer-typed enums. */
|
|
62
40
|
emitIntegerEnum(name: string, raws: ReadonlyArray<number>, emit: (d: D) => void): T;
|
|
63
41
|
}
|
|
42
|
+
export declare function unionToType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): T;
|
|
43
|
+
export declare function inlineObjectType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): T;
|
|
64
44
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Resolve an inline object schema to a target type. Three-way
|
|
71
|
-
* dispatch via `classifyObjectShape`, then per-target rendering:
|
|
45
|
+
* Top-level dispatch from a canonical {@link Schema} to a target type.
|
|
46
|
+
* Routes each schema shape to the appropriate handler (`unionToType` /
|
|
47
|
+
* `inlineObjectType` / per-target enum emitter / target leaf constructor).
|
|
48
|
+
* Per-target leaf decisions live in `ops`.
|
|
72
49
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* Top-level dispatch from `IR.SchemaObject` to a target type. Routes
|
|
80
|
-
* each schema shape to the appropriate handler (`unionToType` /
|
|
81
|
-
* `inlineObjectType` / per-target enum emitter / target leaf
|
|
82
|
-
* constructor). The per-target leaf decisions live in `ops`.
|
|
50
|
+
* Dispatch order:
|
|
51
|
+
* 1. `$ref` → named ref
|
|
52
|
+
* 2. enum (`enum: [...]` or `oneOf`-of-consts)
|
|
53
|
+
* 3. union shape (`oneOf` / `anyOf` / `allOf` / array-form `type`)
|
|
54
|
+
* 4. primitive (per-target hook decides)
|
|
55
|
+
* 5. compound by `type` (array / object / null)
|
|
83
56
|
*/
|
|
84
|
-
export declare function schemaToType<T, D>(schema:
|
|
85
|
-
export { assertNoEnumCollisions, classifyObjectShape, classifyUnion, iterateObjectProperties, };
|
|
57
|
+
export declare function schemaToType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>): T;
|
|
86
58
|
//# sourceMappingURL=dispatch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,cAAc,EAEnB,KAAK,MAAM,EACZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,CAAC;IACnC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC;IACzB,SAAS,CAAC,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,EACf,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GACxC,CAAC,CAYH;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,EACnC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EACf,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GACxC,CAAC,CAcH;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC/B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EACf,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GACzB,CAAC,CA0CH"}
|
package/dist/type/dispatch.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import { refName } from "@ir-kit/
|
|
2
|
-
import { assertNoEnumCollisions, classifyEnumLiterals, } from "./enum.js";
|
|
3
|
-
import { classifyObjectShape, iterateObjectProperties, } from "./object.js";
|
|
4
|
-
import { classifyUnion } from "./union.js";
|
|
5
|
-
/**
|
|
6
|
-
* Resolve a union-shaped `IR.SchemaObject` to a target type. Wraps
|
|
7
|
-
* `classifyUnion` with per-target hooks for each branch.
|
|
8
|
-
*/
|
|
1
|
+
import { classifyEnumLiterals, classifyObject, classifyUnion, extractEnumValues, isSchemaObject, isUnionShape, iterateObjectProperties, refName, } from "@ir-kit/schema";
|
|
9
2
|
export function unionToType(schema, ctx, ops, dispatch) {
|
|
10
3
|
const shape = classifyUnion(schema);
|
|
11
4
|
switch (shape.kind) {
|
|
@@ -19,16 +12,8 @@ export function unionToType(schema, ctx, ops, dispatch) {
|
|
|
19
12
|
return ops.unionFallback(shape.nullable);
|
|
20
13
|
}
|
|
21
14
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Resolve an inline object schema to a target type. Three-way
|
|
24
|
-
* dispatch via `classifyObjectShape`, then per-target rendering:
|
|
25
|
-
*
|
|
26
|
-
* - named-struct → synth a name, build + emit struct, return ref
|
|
27
|
-
* - map → wrap value type in the target's map
|
|
28
|
-
* - open-map → map<string, any>
|
|
29
|
-
*/
|
|
30
15
|
export function inlineObjectType(schema, ctx, ops, dispatch) {
|
|
31
|
-
const shape =
|
|
16
|
+
const shape = classifyObject(schema);
|
|
32
17
|
switch (shape.kind) {
|
|
33
18
|
case "named-struct": {
|
|
34
19
|
const name = ops.synthName(ctx.ownerName, ctx.propPath);
|
|
@@ -43,60 +28,52 @@ export function inlineObjectType(schema, ctx, ops, dispatch) {
|
|
|
43
28
|
}
|
|
44
29
|
}
|
|
45
30
|
/**
|
|
46
|
-
* Top-level dispatch from
|
|
47
|
-
* each schema shape to the appropriate handler (`unionToType` /
|
|
48
|
-
* `inlineObjectType` / per-target enum emitter / target leaf
|
|
49
|
-
*
|
|
31
|
+
* Top-level dispatch from a canonical {@link Schema} to a target type.
|
|
32
|
+
* Routes each schema shape to the appropriate handler (`unionToType` /
|
|
33
|
+
* `inlineObjectType` / per-target enum emitter / target leaf constructor).
|
|
34
|
+
* Per-target leaf decisions live in `ops`.
|
|
35
|
+
*
|
|
36
|
+
* Dispatch order:
|
|
37
|
+
* 1. `$ref` → named ref
|
|
38
|
+
* 2. enum (`enum: [...]` or `oneOf`-of-consts)
|
|
39
|
+
* 3. union shape (`oneOf` / `anyOf` / `allOf` / array-form `type`)
|
|
40
|
+
* 4. primitive (per-target hook decides)
|
|
41
|
+
* 5. compound by `type` (array / object / null)
|
|
50
42
|
*/
|
|
51
43
|
export function schemaToType(schema, ctx, ops) {
|
|
52
44
|
const dispatch = (s, c) => schemaToType(s, c, ops);
|
|
53
45
|
if (schema.$ref)
|
|
54
46
|
return ops.refType(refName(schema.$ref));
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
47
|
+
const enumValues = extractEnumValues(schema);
|
|
48
|
+
if (enumValues && enumValues.length > 0) {
|
|
49
|
+
const name = ops.synthName(ctx.ownerName, ctx.propPath);
|
|
50
|
+
const filtered = enumValues.filter((v) => typeof v === "string" ||
|
|
51
|
+
typeof v === "number" ||
|
|
52
|
+
typeof v === "boolean");
|
|
53
|
+
const kind = classifyEnumLiterals(filtered, name);
|
|
54
|
+
if (kind === "integer")
|
|
55
|
+
return ops.emitIntegerEnum(name, filtered, ctx.emit);
|
|
56
|
+
return ops.emitStringEnum(name, filtered, ctx.emit);
|
|
58
57
|
}
|
|
58
|
+
if (isUnionShape(schema))
|
|
59
|
+
return unionToType(schema, ctx, ops, dispatch);
|
|
59
60
|
const primitive = ops.primitiveType(schema);
|
|
60
61
|
if (primitive !== undefined)
|
|
61
62
|
return primitive;
|
|
62
|
-
|
|
63
|
+
const t = Array.isArray(schema.type) ? schema.type[0] : schema.type;
|
|
64
|
+
switch (t) {
|
|
63
65
|
case "array": {
|
|
64
|
-
const
|
|
65
|
-
return ops.arrayType(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return ops.arrayType(ops.anyType());
|
|
69
|
-
case "enum": {
|
|
70
|
-
const name = ops.synthName(ctx.ownerName, ctx.propPath);
|
|
71
|
-
// Caller's emit walks the schema's `items[].const`; we surface
|
|
72
|
-
// the typed list via the helper rather than re-defining the
|
|
73
|
-
// literal-extraction here (lives in @ir-kit/openapi-tools).
|
|
74
|
-
const rawValues = (schema.items ?? [])
|
|
75
|
-
.map((i) => i.const)
|
|
76
|
-
.filter((v) => typeof v === "string" ||
|
|
77
|
-
typeof v === "number" ||
|
|
78
|
-
typeof v === "boolean");
|
|
79
|
-
// Collision enforcement is per-target (the identifiers differ),
|
|
80
|
-
// so we hand off to the target's emitStringEnum / emitIntegerEnum
|
|
81
|
-
// hook with the raw values; they call assertNoEnumCollisions
|
|
82
|
-
// internally after computing their identifiers.
|
|
83
|
-
const kind = classifyEnumLiterals(rawValues, name);
|
|
84
|
-
if (kind === "integer")
|
|
85
|
-
return ops.emitIntegerEnum(name, rawValues, ctx.emit);
|
|
86
|
-
return ops.emitStringEnum(name, rawValues, ctx.emit);
|
|
66
|
+
const items = schema.items;
|
|
67
|
+
return ops.arrayType(items && isSchemaObject(items)
|
|
68
|
+
? dispatch(items, ctx)
|
|
69
|
+
: ops.anyType());
|
|
87
70
|
}
|
|
88
71
|
case "object":
|
|
89
72
|
return inlineObjectType(schema, ctx, ops, dispatch);
|
|
90
73
|
case "null":
|
|
91
74
|
return ops.nullableAnyType();
|
|
92
|
-
case "never":
|
|
93
|
-
case "void":
|
|
94
|
-
case "undefined":
|
|
95
|
-
return ops.voidType();
|
|
96
75
|
default:
|
|
97
76
|
return ops.anyType();
|
|
98
77
|
}
|
|
99
78
|
}
|
|
100
|
-
// Re-export so emitters can import everything from one place.
|
|
101
|
-
export { assertNoEnumCollisions, classifyObjectShape, classifyUnion, iterateObjectProperties, };
|
|
102
79
|
//# sourceMappingURL=dispatch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,aAAa,EAEb,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,uBAAuB,EAEvB,OAAO,GAER,MAAM,gBAAgB,CAAC;AAyDxB,MAAM,UAAU,WAAW,CACzB,MAAc,EACd,GAAe,EACf,GAA0B,EAC1B,QAAyC;IAEzC,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,8BAA8B;YACjC,O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