@sdk-it/core 0.46.11 → 0.47.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 +22 -12
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/derived-type.d.ts +3 -0
- package/dist/lib/derived-type.d.ts.map +1 -0
- package/dist/lib/derived-type.js +7 -0
- package/dist/lib/derived-type.js.map +7 -0
- package/dist/lib/deriver.d.ts +13 -9
- package/dist/lib/deriver.d.ts.map +1 -1
- package/dist/lib/deriver.js +193 -243
- package/dist/lib/deriver.js.map +3 -3
- package/dist/lib/file-system.d.ts +0 -8
- package/dist/lib/file-system.d.ts.map +1 -1
- package/dist/lib/file-system.js +8 -39
- package/dist/lib/file-system.js.map +2 -2
- package/dist/lib/json-pointer.d.ts +13 -0
- package/dist/lib/json-pointer.d.ts.map +1 -0
- package/dist/lib/json-pointer.js +20 -0
- package/dist/lib/json-pointer.js.map +7 -0
- package/dist/lib/paths.d.ts +27 -8
- package/dist/lib/paths.d.ts.map +1 -1
- package/dist/lib/paths.js +165 -96
- package/dist/lib/paths.js.map +3 -3
- package/dist/lib/program.d.ts +19 -6
- package/dist/lib/program.d.ts.map +1 -1
- package/dist/lib/program.js +61 -62
- package/dist/lib/program.js.map +2 -2
- package/dist/lib/ref.d.ts +5 -5
- package/dist/lib/ref.d.ts.map +1 -1
- package/dist/lib/ref.js +28 -8
- package/dist/lib/ref.js.map +2 -2
- package/dist/lib/security.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +9 -6
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +1 -1
- package/dist/lib/utils.js.map +2 -2
- package/dist/lib/zod-jsonschema.d.ts.map +1 -1
- package/dist/lib/zod-jsonschema.js +111 -93
- package/dist/lib/zod-jsonschema.js.map +2 -2
- package/package.json +17 -12
- package/dist/lib/spec-json.d.ts +0 -23
- package/dist/lib/spec-json.d.ts.map +0 -1
- package/dist/lib/spec-json.js +0 -11
- package/dist/lib/spec-json.js.map +0 -7
package/dist/lib/paths.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { $types } from "./
|
|
1
|
+
import { $types } from "./derived-type.js";
|
|
2
|
+
import { isRef } from "./ref.js";
|
|
2
3
|
import { sortArray, sortObjectKeys } from "./utils.js";
|
|
3
4
|
import { evalZod } from "./zod-jsonschema.js";
|
|
4
5
|
const methods = [
|
|
@@ -10,16 +11,46 @@ const methods = [
|
|
|
10
11
|
"trace",
|
|
11
12
|
"head"
|
|
12
13
|
];
|
|
14
|
+
const semanticSources = [
|
|
15
|
+
"query",
|
|
16
|
+
"queries",
|
|
17
|
+
"body",
|
|
18
|
+
"params",
|
|
19
|
+
"headers"
|
|
20
|
+
];
|
|
21
|
+
const semanticSourceSet = new Set(semanticSources);
|
|
22
|
+
function isSemanticSource(value) {
|
|
23
|
+
return semanticSourceSet.has(value);
|
|
24
|
+
}
|
|
13
25
|
const semanticSourceToOpenAPI = {
|
|
14
26
|
queries: "query",
|
|
15
27
|
query: "query",
|
|
16
28
|
headers: "header",
|
|
17
29
|
params: "path"
|
|
18
30
|
};
|
|
31
|
+
function fieldsBody(fields) {
|
|
32
|
+
const entries = Object.entries(sortObjectKeys(fields));
|
|
33
|
+
if (entries.length === 0) {
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
const required = entries.filter(([, field]) => field.required).map(([name]) => name);
|
|
37
|
+
return {
|
|
38
|
+
required: required.length > 0,
|
|
39
|
+
schema: {
|
|
40
|
+
required: required.length ? sortArray(required) : void 0,
|
|
41
|
+
type: "object",
|
|
42
|
+
properties: Object.fromEntries(
|
|
43
|
+
entries.map(([name, field]) => [name, field.schema])
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
19
48
|
class Paths {
|
|
20
49
|
#imports = [];
|
|
21
50
|
#onOperation;
|
|
22
51
|
#sharedResponses = /* @__PURE__ */ new Map();
|
|
52
|
+
/** The schemas zod names with `.meta({ id })`, by id, across every operation. */
|
|
53
|
+
#components = /* @__PURE__ */ new Map();
|
|
23
54
|
#operations = [];
|
|
24
55
|
constructor(config) {
|
|
25
56
|
this.#imports = config.imports;
|
|
@@ -43,71 +74,112 @@ class Paths {
|
|
|
43
74
|
const responsesObject = {};
|
|
44
75
|
for (const item of responses) {
|
|
45
76
|
const ct = item.contentType;
|
|
46
|
-
let schema = item.response ? toSchema(item.response) : {};
|
|
77
|
+
let schema = item.schema ?? (item.response ? toSchema(item.response) : {});
|
|
47
78
|
if (item.middlewareName) {
|
|
48
79
|
const sanitizedCt = ct.replace(/\//g, "_");
|
|
49
80
|
const sharedKey = `${item.middlewareName}${item.statusCode}_${sanitizedCt}`;
|
|
50
|
-
|
|
81
|
+
const shared = this.#sharedResponses.get(sharedKey);
|
|
82
|
+
const incoming2 = JSON.stringify(schema);
|
|
83
|
+
if (!shared) {
|
|
51
84
|
this.#sharedResponses.set(sharedKey, schema);
|
|
85
|
+
} else if (shared.oneOf) {
|
|
86
|
+
if (!shared.oneOf.some((it) => JSON.stringify(it) === incoming2)) {
|
|
87
|
+
shared.oneOf.push(schema);
|
|
88
|
+
}
|
|
89
|
+
} else if (JSON.stringify(shared) !== incoming2) {
|
|
90
|
+
this.#sharedResponses.set(sharedKey, { oneOf: [shared, schema] });
|
|
52
91
|
}
|
|
53
92
|
schema = { $ref: `#/components/schemas/${sharedKey}` };
|
|
54
93
|
}
|
|
55
|
-
|
|
94
|
+
const contentSchema = ct === "application/octet-stream" ? { type: "string", format: "binary" } : schema;
|
|
95
|
+
const existingResponse = responsesObject[item.statusCode];
|
|
96
|
+
if (!existingResponse) {
|
|
97
|
+
const headers = item.headers.flatMap(
|
|
98
|
+
(header) => typeof header === "string" ? [[header, []]] : Object.entries(sortObjectKeys(header))
|
|
99
|
+
).filter(([name]) => name.toLowerCase() !== "content-type");
|
|
56
100
|
responsesObject[item.statusCode] = {
|
|
57
101
|
description: `Response for ${item.statusCode}`,
|
|
58
|
-
content: ct !== "empty" ? {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
enum: value.length ? value : void 0
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
return { ...subAcc, ...header };
|
|
75
|
-
},
|
|
76
|
-
acc
|
|
77
|
-
);
|
|
78
|
-
}, {}) : void 0
|
|
102
|
+
content: ct !== "empty" ? { [ct]: { schema: contentSchema } } : void 0,
|
|
103
|
+
headers: headers.length ? Object.fromEntries(
|
|
104
|
+
headers.map(([name, values]) => [
|
|
105
|
+
name,
|
|
106
|
+
{
|
|
107
|
+
schema: {
|
|
108
|
+
type: "string",
|
|
109
|
+
enum: values.length ? values : void 0
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
])
|
|
113
|
+
) : void 0
|
|
79
114
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (ct === "empty") {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
existingResponse.content ??= {};
|
|
121
|
+
const media = existingResponse.content[ct];
|
|
122
|
+
if (!media) {
|
|
123
|
+
existingResponse.content[ct] = { schema: contentSchema };
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const existing = media.schema;
|
|
127
|
+
if (!existing) {
|
|
128
|
+
media.schema = contentSchema;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const incoming = JSON.stringify(contentSchema);
|
|
132
|
+
if (!isRef(existing) && existing.oneOf) {
|
|
133
|
+
if (!existing.oneOf.some((it) => JSON.stringify(it) === incoming)) {
|
|
134
|
+
existing.oneOf.push(contentSchema);
|
|
96
135
|
}
|
|
136
|
+
} else if (JSON.stringify(existing) !== incoming) {
|
|
137
|
+
media.schema = { oneOf: [existing, contentSchema] };
|
|
97
138
|
}
|
|
98
139
|
}
|
|
99
140
|
return responsesObject;
|
|
100
141
|
}
|
|
101
|
-
|
|
142
|
+
/** Converts a selector's zod schema, keeping the components it names. */
|
|
143
|
+
async #evalSelector(selector, operation) {
|
|
144
|
+
const site = selector.kind === "field" ? `${operation} ${selector.source} field ${selector.name}` : `${operation} body`;
|
|
145
|
+
let evaluated;
|
|
146
|
+
try {
|
|
147
|
+
evaluated = await evalZod(selector.against, this.#imports);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (!Error.isError(error)) {
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`${site}: ${error.message}`, { cause: error });
|
|
153
|
+
}
|
|
154
|
+
for (const [id, component] of Object.entries(evaluated.components)) {
|
|
155
|
+
const existing = this.#components.get(id);
|
|
156
|
+
if (existing && JSON.stringify(existing) !== JSON.stringify(component)) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
`${site}: two different schemas share the id "${id}"; give each its own .meta({ id }).`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
this.#components.set(id, component);
|
|
162
|
+
}
|
|
163
|
+
return evaluated;
|
|
164
|
+
}
|
|
165
|
+
async #selectosToParameters(selectors, operation) {
|
|
102
166
|
const parameters = [];
|
|
103
|
-
const
|
|
167
|
+
const bodyFields = {};
|
|
168
|
+
let wholeBody;
|
|
104
169
|
for (const selector of selectors) {
|
|
105
|
-
const { optional, schema } = await
|
|
106
|
-
selector
|
|
107
|
-
|
|
170
|
+
const { optional, schema } = await this.#evalSelector(
|
|
171
|
+
selector,
|
|
172
|
+
operation
|
|
108
173
|
);
|
|
174
|
+
if (selector.kind === "body") {
|
|
175
|
+
if (wholeBody) {
|
|
176
|
+
throw new Error(`${operation} selects payload.body more than once.`);
|
|
177
|
+
}
|
|
178
|
+
wholeBody = { required: !optional, schema };
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
109
181
|
if (selector.source === "body") {
|
|
110
|
-
|
|
182
|
+
bodyFields[selector.name] = {
|
|
111
183
|
required: !optional,
|
|
112
184
|
schema
|
|
113
185
|
};
|
|
@@ -121,7 +193,12 @@ class Paths {
|
|
|
121
193
|
};
|
|
122
194
|
parameters.push(parameter);
|
|
123
195
|
}
|
|
124
|
-
|
|
196
|
+
if (wholeBody && Object.keys(bodyFields).length > 0) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
`${operation} selects both payload.body and body fields; select one or the other.`
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
return { parameters, body: wholeBody ?? fieldsBody(bodyFields) };
|
|
125
202
|
}
|
|
126
203
|
getTags() {
|
|
127
204
|
const tags = /* @__PURE__ */ new Set();
|
|
@@ -134,25 +211,21 @@ class Paths {
|
|
|
134
211
|
}
|
|
135
212
|
return Array.from(tags);
|
|
136
213
|
}
|
|
214
|
+
/** The shared response schemas and every zod schema named with `.meta({ id })`; read it after {@link getPaths}, which converts them. */
|
|
137
215
|
getSharedSchemas() {
|
|
138
|
-
return
|
|
216
|
+
return {
|
|
217
|
+
...Object.fromEntries(this.#sharedResponses),
|
|
218
|
+
...Object.fromEntries(this.#components)
|
|
219
|
+
};
|
|
139
220
|
}
|
|
140
221
|
async getPaths() {
|
|
141
222
|
const operations = {};
|
|
142
223
|
for (const operation of this.#operations) {
|
|
143
224
|
const { path, method, selectors } = operation;
|
|
144
|
-
const { parameters,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const sortedBodySchemaProps = Object.entries(
|
|
148
|
-
sortObjectKeys(bodySchemaProps)
|
|
225
|
+
const { parameters, body } = await this.#selectosToParameters(
|
|
226
|
+
selectors,
|
|
227
|
+
`${method.toUpperCase()} ${path}`
|
|
149
228
|
);
|
|
150
|
-
for (const [key, value] of sortedBodySchemaProps) {
|
|
151
|
-
if (value.required) {
|
|
152
|
-
required.push(key);
|
|
153
|
-
}
|
|
154
|
-
bodySchema[key] = value.schema;
|
|
155
|
-
}
|
|
156
229
|
const operationObject = {
|
|
157
230
|
operationId: operation.name,
|
|
158
231
|
parameters,
|
|
@@ -165,15 +238,11 @@ class Paths {
|
|
|
165
238
|
name: operation.info.tool || void 0,
|
|
166
239
|
description: operation.info.toolDescription || void 0
|
|
167
240
|
} : void 0,
|
|
168
|
-
requestBody:
|
|
169
|
-
required: required
|
|
241
|
+
requestBody: body ? {
|
|
242
|
+
required: body.required,
|
|
170
243
|
content: {
|
|
171
244
|
[operation.contentType || "application/json"]: {
|
|
172
|
-
schema:
|
|
173
|
-
required: required.length ? sortArray(required) : void 0,
|
|
174
|
-
type: "object",
|
|
175
|
-
properties: bodySchema
|
|
176
|
-
}
|
|
245
|
+
schema: body.schema
|
|
177
246
|
}
|
|
178
247
|
}
|
|
179
248
|
} : void 0,
|
|
@@ -202,15 +271,34 @@ class Paths {
|
|
|
202
271
|
return path.replace(/:([^/]+)/g, "{$1}");
|
|
203
272
|
}
|
|
204
273
|
}
|
|
274
|
+
function isDateType(data) {
|
|
275
|
+
return $types in data;
|
|
276
|
+
}
|
|
205
277
|
function toSchema(data) {
|
|
206
|
-
if (data === null || data === void 0) {
|
|
207
|
-
return {
|
|
278
|
+
if (data === null || data === void 0 || data === "any") {
|
|
279
|
+
return {};
|
|
208
280
|
} else if (typeof data === "string") {
|
|
209
|
-
const
|
|
210
|
-
if (
|
|
281
|
+
const isRef2 = data.startsWith("#");
|
|
282
|
+
if (isRef2) {
|
|
211
283
|
return { $ref: data };
|
|
212
284
|
}
|
|
213
285
|
return { type: data };
|
|
286
|
+
} else if (!isDateType(data)) {
|
|
287
|
+
const props = {};
|
|
288
|
+
const required = [];
|
|
289
|
+
const sortedEntries = Object.entries(sortObjectKeys(data));
|
|
290
|
+
for (const [key, value] of sortedEntries) {
|
|
291
|
+
props[key] = toSchema(value);
|
|
292
|
+
if (!value.optional) {
|
|
293
|
+
required.push(key);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
type: "object",
|
|
298
|
+
properties: props,
|
|
299
|
+
required: sortArray(required),
|
|
300
|
+
additionalProperties: false
|
|
301
|
+
};
|
|
214
302
|
} else if (data.kind === "date") {
|
|
215
303
|
return { type: "string", format: "date-time" };
|
|
216
304
|
} else if (data.kind === "never") {
|
|
@@ -234,34 +322,14 @@ function toSchema(data) {
|
|
|
234
322
|
];
|
|
235
323
|
return unique.length === 1 ? unique[0] : { anyOf: unique };
|
|
236
324
|
} else if (data.kind === "intersection") {
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const node = m;
|
|
241
|
-
return !(!node.kind && node[$types]?.length === 1 && node[$types][0] === ANON_OBJECT);
|
|
242
|
-
});
|
|
325
|
+
const meaningful = data[$types].filter(
|
|
326
|
+
(m) => !(m?.kind === "object" && m[$types].length === 1 && Object.keys(m[$types][0]).length === 0)
|
|
327
|
+
);
|
|
243
328
|
if (meaningful.length === 0) return {};
|
|
244
|
-
if (meaningful.length === 1)
|
|
245
|
-
return toSchema(meaningful[0]);
|
|
329
|
+
if (meaningful.length === 1) return toSchema(meaningful[0]);
|
|
246
330
|
return { allOf: meaningful.map((m) => toSchema(m)) };
|
|
247
|
-
} else if ($types in data) {
|
|
248
|
-
return data[$types].map(toSchema)[0] ?? {};
|
|
249
331
|
} else {
|
|
250
|
-
|
|
251
|
-
const required = [];
|
|
252
|
-
const sortedEntries = Object.entries(sortObjectKeys(data));
|
|
253
|
-
for (const [key, value] of sortedEntries) {
|
|
254
|
-
props[key] = toSchema(value);
|
|
255
|
-
if (!value.optional) {
|
|
256
|
-
required.push(key);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return {
|
|
260
|
-
type: "object",
|
|
261
|
-
properties: props,
|
|
262
|
-
required: sortArray(required),
|
|
263
|
-
additionalProperties: false
|
|
264
|
-
};
|
|
332
|
+
return data[$types].map(toSchema)[0] ?? {};
|
|
265
333
|
}
|
|
266
334
|
}
|
|
267
335
|
function isHttpMethod(name) {
|
|
@@ -270,6 +338,7 @@ function isHttpMethod(name) {
|
|
|
270
338
|
export {
|
|
271
339
|
Paths,
|
|
272
340
|
isHttpMethod,
|
|
341
|
+
isSemanticSource,
|
|
273
342
|
methods,
|
|
274
343
|
toSchema
|
|
275
344
|
};
|
package/dist/lib/paths.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/paths.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n HeadersObject,\n OperationObject,\n ParameterObject,\n PathsObject,\n ResponseObject,\n ResponsesObject,\n SchemaObject,\n SecurityRequirementObject,\n} from 'openapi3-ts/oas31';\n\nimport { $types } from './deriver.js';\nimport { sortArray, sortObjectKeys } from './utils.js';\nimport { type InjectImport, evalZod } from './zod-jsonschema.js';\n\nexport type OperationInfo = {\n tool?: string;\n toolDescription?: string;\n summary?: string;\n description?: string;\n tags?: string[];\n security?: SecurityRequirementObject[];\n};\nexport type Method =\n 'get' | 'post' | 'put' | 'patch' | 'delete' | 'trace' | 'head';\n\nexport const methods = [\n 'get',\n 'post',\n 'put',\n 'patch',\n 'delete',\n 'trace',\n 'head',\n] as const;\nexport type SemanticSource =\n 'query' | 'queries' | 'body' | 'params' | 'headers';\n\nconst semanticSourceToOpenAPI = {\n queries: 'query',\n query: 'query',\n headers: 'header',\n params: 'path',\n} as const;\nexport interface Selector {\n name: string;\n against: string;\n source: SemanticSource;\n}\n\nexport interface ResponseItem {\n statusCode: string;\n response?: DateType;\n contentType: string;\n headers: (string | Record<string, string[]>)[];\n middlewareName?: string;\n}\n\nexport type OnOperation = (\n sourceFile: string,\n method: Method,\n path: string,\n operation: OperationObject,\n) => PathsObject;\nexport class Paths {\n #imports: InjectImport[] = [];\n #onOperation?: OnOperation;\n #sharedResponses = new Map<string, SchemaObject>();\n #operations: Array<{\n sourceFile: string;\n name: string;\n path: string;\n method: Method;\n selectors: Selector[];\n responses: ResponsesObject;\n contentType?: string;\n info: OperationInfo;\n }> = [];\n\n constructor(config: { imports: InjectImport[]; onOperation?: OnOperation }) {\n this.#imports = config.imports;\n this.#onOperation = config.onOperation;\n }\n\n addPath(\n name: string,\n path: string,\n method: Method,\n contentType: string | undefined,\n selectors: Selector[],\n responses: ResponseItem[],\n sourceFile: string,\n info: OperationInfo,\n ) {\n const responsesObject = this.#responseItemToResponses(responses);\n\n this.#operations.push({\n name,\n path: this.#tunePath(path),\n sourceFile,\n contentType: contentType,\n method,\n selectors,\n responses: responsesObject,\n info,\n });\n return this;\n }\n\n #responseItemToResponses(responses: ResponseItem[]): ResponsesObject {\n const responsesObject: ResponsesObject = {};\n for (const item of responses) {\n const ct = item.contentType;\n let schema = item.response ? toSchema(item.response) : {};\n\n // Deduplicate named middleware responses via $ref\n if (item.middlewareName) {\n const sanitizedCt = ct.replace(/\\//g, '_');\n const sharedKey = `${item.middlewareName}${item.statusCode}_${sanitizedCt}`;\n if (!this.#sharedResponses.has(sharedKey)) {\n this.#sharedResponses.set(sharedKey, schema);\n }\n schema = { $ref: `#/components/schemas/${sharedKey}` };\n }\n\n if (!responsesObject[item.statusCode]) {\n responsesObject[item.statusCode] = {\n description: `Response for ${item.statusCode}`,\n content:\n ct !== 'empty'\n ? {\n [ct]:\n ct === 'application/octet-stream'\n ? { schema: { type: 'string', format: 'binary' } }\n : { schema },\n }\n : undefined,\n headers: item.headers.length\n ? item.headers.reduce<HeadersObject>((acc, current) => {\n const headers =\n typeof current === 'string' ? { [current]: [] } : current;\n const sortedHeaders = Object.entries(sortObjectKeys(headers));\n return sortedHeaders.reduce<HeadersObject>(\n (subAcc, [key, value]) => {\n const header: HeadersObject = {\n [key]: {\n schema: {\n type: 'string',\n enum: value.length ? value : undefined,\n },\n },\n };\n return { ...subAcc, ...header };\n },\n acc,\n );\n }, {})\n : undefined,\n } satisfies ResponseObject;\n } else {\n if (!responsesObject[item.statusCode].content[ct]) {\n responsesObject[item.statusCode].content[ct] = { schema };\n } else {\n const existing = responsesObject[item.statusCode].content[ct]\n .schema as SchemaObject;\n if (existing.oneOf) {\n if (\n !existing.oneOf.find(\n (it) => JSON.stringify(it) === JSON.stringify(schema),\n )\n ) {\n existing.oneOf.push(schema);\n }\n } else if (JSON.stringify(existing) !== JSON.stringify(schema)) {\n responsesObject[item.statusCode].content[ct].schema = {\n oneOf: [existing, schema],\n };\n }\n }\n }\n }\n return responsesObject;\n }\n\n async #selectosToParameters(selectors: Selector[]) {\n const parameters: ParameterObject[] = [];\n const bodySchemaProps: Record<\n string,\n { required: boolean; schema: SchemaObject }\n > = {};\n for (const selector of selectors) {\n const { optional, schema } = await evalZod(\n selector.against,\n this.#imports,\n );\n if (selector.source === 'body') {\n bodySchemaProps[selector.name] = {\n required: !optional,\n schema,\n };\n continue;\n }\n const parameter: ParameterObject = {\n in: semanticSourceToOpenAPI[selector.source],\n name: selector.name,\n required: !optional,\n schema,\n };\n parameters.push(parameter);\n }\n return { parameters, bodySchemaProps };\n }\n\n getTags(): string[] {\n const tags = new Set<string>();\n\n for (const operation of this.#operations) {\n if (operation.info.tags) {\n for (const tag of operation.info.tags) {\n tags.add(tag);\n }\n }\n }\n\n return Array.from(tags);\n }\n\n getSharedSchemas(): Record<string, SchemaObject> {\n return Object.fromEntries(this.#sharedResponses);\n }\n\n async getPaths() {\n const operations: PathsObject = {};\n\n for (const operation of this.#operations) {\n const { path, method, selectors } = operation;\n const { parameters, bodySchemaProps } =\n await this.#selectosToParameters(selectors);\n const bodySchema: Record<string, SchemaObject> = {};\n const required: string[] = [];\n const sortedBodySchemaProps = Object.entries(\n sortObjectKeys(bodySchemaProps),\n );\n for (const [key, value] of sortedBodySchemaProps) {\n if (value.required) {\n required.push(key);\n }\n bodySchema[key] = value.schema;\n }\n\n const operationObject: OperationObject = {\n operationId: operation.name,\n parameters,\n tags: operation.info.tags,\n // || undefined would omit the value from final openapi spec\n description: operation.info.description || undefined,\n summary: operation.info.summary || undefined,\n security: operation.info.security,\n 'x-tool': operation.info.tool\n ? {\n name: operation.info.tool || undefined,\n description: operation.info.toolDescription || undefined,\n }\n : undefined,\n requestBody: Object.keys(bodySchema).length\n ? {\n required: required.length ? true : false,\n content: {\n [operation.contentType || 'application/json']: {\n schema: {\n required: required.length ? sortArray(required) : undefined,\n type: 'object',\n properties: bodySchema,\n },\n },\n },\n }\n : undefined,\n responses:\n Object.keys(operation.responses).length === 0\n ? undefined\n : operation.responses,\n };\n if (!operations[path]) {\n operations[path] = {};\n }\n operations[path][method] = operationObject;\n if (this.#onOperation) {\n const paths = this.#onOperation?.(\n operation.sourceFile,\n method,\n path,\n operationObject,\n );\n Object.assign(operations, paths ?? {});\n }\n }\n return operations;\n }\n\n /**\n * Converts Express/Node.js style path parameters (/path/:param) to OpenAPI style (/path/{param})\n */\n #tunePath(path: string): string {\n return path.replace(/:([^/]+)/g, '{$1}');\n }\n}\n\ninterface DateType {\n [$types]: any[];\n kind: string;\n optional: boolean;\n value?: string;\n}\n\nexport function toSchema(data: DateType | string | null | undefined): any {\n if (data === null || data === undefined) {\n return { type: 'any' };\n } else if (typeof data === 'string') {\n const isRef = data.startsWith('#');\n if (isRef) {\n return { $ref: data };\n }\n return { type: data };\n } else if (data.kind === 'date') {\n return { type: 'string', format: 'date-time' };\n } else if (data.kind === 'never') {\n return { not: {} };\n } else if (data.kind === 'literal') {\n return { enum: [data.value], type: data[$types][0] };\n } else if (data.kind === 'record') {\n return {\n type: 'object',\n additionalProperties: toSchema(data[$types][0]),\n };\n } else if (data.kind === 'array') {\n const items = data[$types].map(toSchema);\n return { type: 'array', items: data[$types].length ? items[0] : {} };\n } else if (data.kind === 'union') {\n const schemas = data[$types].map(toSchema);\n const unique = [\n ...new Map(\n schemas.map((schema) => [JSON.stringify(schema), schema]),\n ).values(),\n ];\n return unique.length === 1 ? unique[0] : { anyOf: unique };\n } else if (data.kind === 'intersection') {\n // TS gives anonymous/empty object types the synthetic symbol name \"__type\".\n // Members like `& {}` (the autocomplete-trick wrapper) contribute no schema\n // info \u2014 drop them so `(string & {})` emits as plain `{type:'string'}`.\n const ANON_OBJECT = '__type';\n const meaningful = (data[$types] as unknown[]).filter((m) => {\n if (!m || typeof m !== 'object') return true;\n const node = m as { kind?: unknown; [$types]?: readonly unknown[] };\n return !(\n !node.kind &&\n node[$types]?.length === 1 &&\n node[$types][0] === ANON_OBJECT\n );\n });\n if (meaningful.length === 0) return {};\n if (meaningful.length === 1)\n return toSchema(meaningful[0] as DateType | string);\n return { allOf: meaningful.map((m) => toSchema(m as DateType | string)) };\n } else if ($types in data) {\n return data[$types].map(toSchema)[0] ?? {};\n } else {\n const props: Record<string, unknown> = {};\n const required: string[] = [];\n const sortedEntries = Object.entries(sortObjectKeys(data));\n for (const [key, value] of sortedEntries) {\n props[key] = toSchema(value as any);\n if (!(value as any).optional) {\n required.push(key);\n }\n }\n return {\n type: 'object',\n properties: props,\n required: sortArray(required),\n additionalProperties: false,\n };\n }\n}\n\nexport function isHttpMethod(name: string): name is Method {\n return ['get', 'post', 'put', 'delete', 'patch'].includes(name);\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import type {\n HeaderObject,\n OperationObject,\n ParameterObject,\n PathsObject,\n ReferenceObject,\n ResponseObject,\n ResponsesObject,\n SchemaObject,\n SecurityRequirementObject,\n} from 'openapi3-ts/oas31';\n\nimport { $types } from './derived-type.js';\nimport { isRef } from './ref.js';\nimport { sortArray, sortObjectKeys } from './utils.js';\nimport { type InjectImport, evalZod } from './zod-jsonschema.js';\n\nexport type OperationInfo = {\n tool?: string;\n toolDescription?: string;\n summary?: string;\n description?: string;\n tags?: string[];\n security?: SecurityRequirementObject[];\n};\nexport type Method =\n 'get' | 'post' | 'put' | 'patch' | 'delete' | 'trace' | 'head';\n\nexport const methods = [\n 'get',\n 'post',\n 'put',\n 'patch',\n 'delete',\n 'trace',\n 'head',\n] as const;\nconst semanticSources = [\n 'query',\n 'queries',\n 'body',\n 'params',\n 'headers',\n] as const;\nexport type SemanticSource = (typeof semanticSources)[number];\n\nconst semanticSourceSet: ReadonlySet<string> = new Set(semanticSources);\n\nexport function isSemanticSource(value: string): value is SemanticSource {\n return semanticSourceSet.has(value);\n}\n\nconst semanticSourceToOpenAPI = {\n queries: 'query',\n query: 'query',\n headers: 'header',\n params: 'path',\n} as const;\n/** A validator entry that selects one named value, such as `payload.params.id`. */\nexport interface FieldSelector {\n kind: 'field';\n source: SemanticSource;\n name: string;\n against: string;\n}\n\n/** A validator entry that selects the whole request body: `payload.body`. */\nexport interface BodySelector {\n kind: 'body';\n against: string;\n}\n\nexport type Selector = FieldSelector | BodySelector;\n\ninterface RequestBody {\n required: boolean;\n schema: SchemaObject;\n}\n\n/** The object body a validator's body-field selections describe, if it selects any. */\nfunction fieldsBody(\n fields: Record<string, RequestBody>,\n): RequestBody | undefined {\n const entries = Object.entries(sortObjectKeys(fields));\n if (entries.length === 0) {\n return undefined;\n }\n const required = entries\n .filter(([, field]) => field.required)\n .map(([name]) => name);\n return {\n required: required.length > 0,\n schema: {\n required: required.length ? sortArray(required) : undefined,\n type: 'object',\n properties: Object.fromEntries(\n entries.map(([name, field]) => [name, field.schema]),\n ),\n },\n };\n}\n\ninterface ResponseItemBase {\n statusCode: string;\n contentType: string;\n headers: (string | Record<string, string[]>)[];\n middlewareName?: string;\n}\n\n/** A response body is either derived from source or given as an OpenAPI schema, never both. */\nexport type ResponseItem = ResponseItemBase &\n (\n | { response?: DateType; schema?: never }\n | { schema: SchemaObject; response?: never }\n );\n\nexport type OnOperation = (\n sourceFile: string,\n method: Method,\n path: string,\n operation: OperationObject,\n) => PathsObject;\nexport class Paths {\n #imports: InjectImport[] = [];\n #onOperation?: OnOperation;\n #sharedResponses = new Map<string, SchemaObject>();\n /** The schemas zod names with `.meta({ id })`, by id, across every operation. */\n #components = new Map<string, SchemaObject>();\n #operations: Array<{\n sourceFile: string;\n name: string;\n path: string;\n method: Method;\n selectors: Selector[];\n responses: ResponsesObject;\n contentType?: string;\n info: OperationInfo;\n }> = [];\n\n constructor(config: { imports: InjectImport[]; onOperation?: OnOperation }) {\n this.#imports = config.imports;\n this.#onOperation = config.onOperation;\n }\n\n addPath(\n name: string,\n path: string,\n method: Method,\n contentType: string | undefined,\n selectors: Selector[],\n responses: ResponseItem[],\n sourceFile: string,\n info: OperationInfo,\n ) {\n const responsesObject = this.#responseItemToResponses(responses);\n\n this.#operations.push({\n name,\n path: this.#tunePath(path),\n sourceFile,\n contentType: contentType,\n method,\n selectors,\n responses: responsesObject,\n info,\n });\n return this;\n }\n\n #responseItemToResponses(responses: ResponseItem[]): ResponsesObject {\n const responsesObject: Record<string, ResponseObject> = {};\n for (const item of responses) {\n const ct = item.contentType;\n let schema =\n item.schema ?? (item.response ? toSchema(item.response) : {});\n\n // Every route points at one shared schema per middleware, status and\n // content type; each distinct body the middleware sends joins its oneOf,\n // as the merge below does for one route's responses.\n if (item.middlewareName) {\n const sanitizedCt = ct.replace(/\\//g, '_');\n const sharedKey = `${item.middlewareName}${item.statusCode}_${sanitizedCt}`;\n const shared = this.#sharedResponses.get(sharedKey);\n const incoming = JSON.stringify(schema);\n if (!shared) {\n this.#sharedResponses.set(sharedKey, schema);\n } else if (shared.oneOf) {\n if (!shared.oneOf.some((it) => JSON.stringify(it) === incoming)) {\n shared.oneOf.push(schema);\n }\n } else if (JSON.stringify(shared) !== incoming) {\n this.#sharedResponses.set(sharedKey, { oneOf: [shared, schema] });\n }\n schema = { $ref: `#/components/schemas/${sharedKey}` };\n }\n\n const contentSchema: SchemaObject | ReferenceObject =\n ct === 'application/octet-stream'\n ? { type: 'string', format: 'binary' }\n : schema;\n\n const existingResponse = responsesObject[item.statusCode];\n if (!existingResponse) {\n const headers = item.headers\n .flatMap<[string, string[]]>((header) =>\n typeof header === 'string'\n ? [[header, []]]\n : Object.entries(sortObjectKeys(header)),\n )\n // OpenAPI 3.2 Response Object: a response header named Content-Type SHALL be ignored.\n .filter(([name]) => name.toLowerCase() !== 'content-type');\n responsesObject[item.statusCode] = {\n description: `Response for ${item.statusCode}`,\n content:\n ct !== 'empty' ? { [ct]: { schema: contentSchema } } : undefined,\n headers: headers.length\n ? Object.fromEntries(\n headers.map(([name, values]): [string, HeaderObject] => [\n name,\n {\n schema: {\n type: 'string',\n enum: values.length ? values : undefined,\n },\n },\n ]),\n )\n : undefined,\n } satisfies ResponseObject;\n continue;\n }\n if (ct === 'empty') {\n continue;\n }\n existingResponse.content ??= {};\n const media = existingResponse.content[ct];\n if (!media) {\n existingResponse.content[ct] = { schema: contentSchema };\n continue;\n }\n const existing = media.schema;\n if (!existing) {\n media.schema = contentSchema;\n continue;\n }\n // Different bodies for one status and content type become a oneOf; the\n // shared middleware schemas above repeat this rule.\n const incoming = JSON.stringify(contentSchema);\n if (!isRef(existing) && existing.oneOf) {\n if (!existing.oneOf.some((it) => JSON.stringify(it) === incoming)) {\n existing.oneOf.push(contentSchema);\n }\n } else if (JSON.stringify(existing) !== incoming) {\n media.schema = { oneOf: [existing, contentSchema] };\n }\n }\n return responsesObject;\n }\n\n /** Converts a selector's zod schema, keeping the components it names. */\n async #evalSelector(selector: Selector, operation: string) {\n const site =\n selector.kind === 'field'\n ? `${operation} ${selector.source} field ${selector.name}`\n : `${operation} body`;\n let evaluated: {\n optional: boolean;\n schema: SchemaObject;\n components: Record<string, SchemaObject>;\n };\n try {\n evaluated = await evalZod(selector.against, this.#imports);\n } catch (error) {\n if (!Error.isError(error)) {\n throw error;\n }\n throw new Error(`${site}: ${error.message}`, { cause: error });\n }\n for (const [id, component] of Object.entries(evaluated.components)) {\n const existing = this.#components.get(id);\n if (existing && JSON.stringify(existing) !== JSON.stringify(component)) {\n throw new Error(\n `${site}: two different schemas share the id \"${id}\"; give each its own .meta({ id }).`,\n );\n }\n this.#components.set(id, component);\n }\n return evaluated;\n }\n\n async #selectosToParameters(selectors: Selector[], operation: string) {\n const parameters: ParameterObject[] = [];\n const bodyFields: Record<string, RequestBody> = {};\n let wholeBody: RequestBody | undefined;\n for (const selector of selectors) {\n const { optional, schema } = await this.#evalSelector(\n selector,\n operation,\n );\n if (selector.kind === 'body') {\n if (wholeBody) {\n throw new Error(`${operation} selects payload.body more than once.`);\n }\n wholeBody = { required: !optional, schema };\n continue;\n }\n if (selector.source === 'body') {\n bodyFields[selector.name] = {\n required: !optional,\n schema,\n };\n continue;\n }\n const parameter: ParameterObject = {\n in: semanticSourceToOpenAPI[selector.source],\n name: selector.name,\n required: !optional,\n schema,\n };\n parameters.push(parameter);\n }\n if (wholeBody && Object.keys(bodyFields).length > 0) {\n throw new Error(\n `${operation} selects both payload.body and body fields; select one or the other.`,\n );\n }\n return { parameters, body: wholeBody ?? fieldsBody(bodyFields) };\n }\n\n getTags(): string[] {\n const tags = new Set<string>();\n\n for (const operation of this.#operations) {\n if (operation.info.tags) {\n for (const tag of operation.info.tags) {\n tags.add(tag);\n }\n }\n }\n\n return Array.from(tags);\n }\n\n /** The shared response schemas and every zod schema named with `.meta({ id })`; read it after {@link getPaths}, which converts them. */\n getSharedSchemas(): Record<string, SchemaObject> {\n return {\n ...Object.fromEntries(this.#sharedResponses),\n ...Object.fromEntries(this.#components),\n };\n }\n\n async getPaths() {\n const operations: PathsObject = {};\n\n for (const operation of this.#operations) {\n const { path, method, selectors } = operation;\n const { parameters, body } = await this.#selectosToParameters(\n selectors,\n `${method.toUpperCase()} ${path}`,\n );\n\n const operationObject: OperationObject = {\n operationId: operation.name,\n parameters,\n tags: operation.info.tags,\n // || undefined would omit the value from final openapi spec\n description: operation.info.description || undefined,\n summary: operation.info.summary || undefined,\n security: operation.info.security,\n 'x-tool': operation.info.tool\n ? {\n name: operation.info.tool || undefined,\n description: operation.info.toolDescription || undefined,\n }\n : undefined,\n requestBody: body\n ? {\n required: body.required,\n content: {\n [operation.contentType || 'application/json']: {\n schema: body.schema,\n },\n },\n }\n : undefined,\n responses:\n Object.keys(operation.responses).length === 0\n ? undefined\n : operation.responses,\n };\n if (!operations[path]) {\n operations[path] = {};\n }\n operations[path][method] = operationObject;\n if (this.#onOperation) {\n const paths = this.#onOperation?.(\n operation.sourceFile,\n method,\n path,\n operationObject,\n );\n Object.assign(operations, paths ?? {});\n }\n }\n return operations;\n }\n\n /**\n * Converts Express/Node.js style path parameters (/path/:param) to OpenAPI style (/path/{param})\n */\n #tunePath(path: string): string {\n return path.replace(/:([^/]+)/g, '{$1}');\n }\n}\n\ninterface DateType {\n [$types]: any[];\n kind: string;\n optional: boolean;\n value?: string;\n}\n\ntype DerivedProps = Record<string, DateType>;\n\nfunction isDateType(data: DateType | DerivedProps): data is DateType {\n return $types in data;\n}\n\nexport function toSchema(\n data: DateType | DerivedProps | string | null | undefined,\n): any {\n // JSON Schema has no type 'any'; the empty schema accepts any value, and it is\n // the schema OpenAPI 3.2 gives a raw binary body.\n if (data === null || data === undefined || data === 'any') {\n return {};\n } else if (typeof data === 'string') {\n const isRef = data.startsWith('#');\n if (isRef) {\n return { $ref: data };\n }\n return { type: data };\n } else if (!isDateType(data)) {\n const props: Record<string, unknown> = {};\n const required: string[] = [];\n const sortedEntries = Object.entries(sortObjectKeys(data));\n for (const [key, value] of sortedEntries) {\n props[key] = toSchema(value);\n if (!value.optional) {\n required.push(key);\n }\n }\n return {\n type: 'object',\n properties: props,\n required: sortArray(required),\n additionalProperties: false,\n };\n } else if (data.kind === 'date') {\n return { type: 'string', format: 'date-time' };\n } else if (data.kind === 'never') {\n return { not: {} };\n } else if (data.kind === 'literal') {\n return { enum: [data.value], type: data[$types][0] };\n } else if (data.kind === 'record') {\n return {\n type: 'object',\n additionalProperties: toSchema(data[$types][0]),\n };\n } else if (data.kind === 'array') {\n const items = data[$types].map(toSchema);\n return { type: 'array', items: data[$types].length ? items[0] : {} };\n } else if (data.kind === 'union') {\n const schemas = data[$types].map(toSchema);\n const unique = [\n ...new Map(\n schemas.map((schema) => [JSON.stringify(schema), schema]),\n ).values(),\n ];\n return unique.length === 1 ? unique[0] : { anyOf: unique };\n } else if (data.kind === 'intersection') {\n // An empty object (the `& {}` autocomplete-trick wrapper) adds no\n // constraint, so `(string & {})` emits as plain `{type:'string'}`.\n const meaningful = data[$types].filter(\n (m) =>\n !(\n m?.kind === 'object' &&\n m[$types].length === 1 &&\n Object.keys(m[$types][0]).length === 0\n ),\n );\n if (meaningful.length === 0) return {};\n if (meaningful.length === 1) return toSchema(meaningful[0]);\n return { allOf: meaningful.map((m) => toSchema(m)) };\n } else {\n return data[$types].map(toSchema)[0] ?? {};\n }\n}\n\nexport function isHttpMethod(name: string): name is Method {\n return ['get', 'post', 'put', 'delete', 'patch'].includes(name);\n}\n"],
|
|
5
|
+
"mappings": "AAYA,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB,SAAS,WAAW,sBAAsB;AAC1C,SAA4B,eAAe;AAapC,MAAM,UAAU;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGA,MAAM,oBAAyC,IAAI,IAAI,eAAe;AAE/D,SAAS,iBAAiB,OAAwC;AACvE,SAAO,kBAAkB,IAAI,KAAK;AACpC;AAEA,MAAM,0BAA0B;AAAA,EAC9B,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AACV;AAuBA,SAAS,WACP,QACyB;AACzB,QAAM,UAAU,OAAO,QAAQ,eAAe,MAAM,CAAC;AACrD,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;AACA,QAAM,WAAW,QACd,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,MAAM,QAAQ,EACpC,IAAI,CAAC,CAAC,IAAI,MAAM,IAA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|
+
import type { CallExpression, Node, SourceFile } from '@typescript/native/ast';
|
|
2
|
+
import { type Checker, type Diagnostic, type Program } from '@typescript/native/sync';
|
|
3
|
+
/** A program opened to read source. It never emits. */
|
|
4
|
+
export type AnalysisProgram = Omit<Program, 'emit' | 'emitToString' | 'getJavaScriptEmit' | 'getDeclarationEmit'>;
|
|
5
|
+
export interface AnalysisProject extends Disposable {
|
|
6
|
+
readonly program: AnalysisProgram;
|
|
7
|
+
readonly checker: Checker;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Opens the project a tsconfig describes for static analysis. The project owns
|
|
11
|
+
* a native TypeScript process: dispose it once analysis is done. The program
|
|
12
|
+
* names its files by real path, even when `tsconfigPath` goes through a symlink.
|
|
13
|
+
*/
|
|
14
|
+
export declare function openAnalysisProject(tsconfigPath: string): AnalysisProject;
|
|
15
|
+
/** The diagnostics a compile reports before it emits. */
|
|
16
|
+
export declare function preEmitDiagnostics(program: AnalysisProgram): readonly Diagnostic[];
|
|
17
|
+
/** The program's source files, declaration files excluded. */
|
|
18
|
+
export declare function sourceFiles(program: AnalysisProgram): Generator<SourceFile>;
|
|
19
|
+
export declare function isCallExpression(node: Node, name: string): node is CallExpression;
|
|
7
20
|
//# sourceMappingURL=program.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.d.ts","
|
|
1
|
+
{"version":3,"file":"program.d.ts","sources":["../../src/lib/program.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAK/E,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,OAAO,EAEb,MAAM,yBAAyB,CAAC;AAIjC,uDAAuD;AACvD,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,OAAO,EACP,MAAM,GAAG,cAAc,GAAG,mBAAmB,GAAG,oBAAoB,CACrE,CAAC;AAEF,MAAM,WAAW,eAAgB,SAAQ,UAAU;IACjD,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAiBD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,eAAe,CAgCzE;AAED,yDAAyD;AACzD,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,eAAe,GACvB,SAAS,UAAU,EAAE,CAWvB;AAED,8DAA8D;AAC9D,wBAAiB,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,SAAS,CAAC,UAAU,CAAC,CAO5E;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,GACX,IAAI,IAAI,cAAc,CAMxB"}
|