@azure-tools/typespec-azure-examples 0.2.0-dev.1 → 0.2.0-dev.2
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 +47 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/migrate/dedup.d.ts +32 -0
- package/dist/src/migrate/dedup.d.ts.map +1 -0
- package/dist/src/migrate/dedup.js +99 -0
- package/dist/src/migrate/dedup.js.map +1 -0
- package/dist/src/migrate/emit.d.ts +28 -0
- package/dist/src/migrate/emit.d.ts.map +1 -0
- package/dist/src/migrate/emit.js +87 -0
- package/dist/src/migrate/emit.js.map +1 -0
- package/dist/src/migrate/index.d.ts +13 -0
- package/dist/src/migrate/index.d.ts.map +1 -0
- package/dist/src/migrate/index.js +12 -0
- package/dist/src/migrate/index.js.map +1 -0
- package/dist/src/migrate/migrate.d.ts +40 -0
- package/dist/src/migrate/migrate.d.ts.map +1 -0
- package/dist/src/migrate/migrate.js +98 -0
- package/dist/src/migrate/migrate.js.map +1 -0
- package/dist/src/migrate/model.d.ts +22 -0
- package/dist/src/migrate/model.d.ts.map +1 -0
- package/dist/src/migrate/model.js +2 -0
- package/dist/src/migrate/model.js.map +1 -0
- package/dist/src/migrate/normalize.d.ts +15 -0
- package/dist/src/migrate/normalize.d.ts.map +1 -0
- package/dist/src/migrate/normalize.js +63 -0
- package/dist/src/migrate/normalize.js.map +1 -0
- package/dist/src/migrate/operation-key.d.ts +12 -0
- package/dist/src/migrate/operation-key.d.ts.map +1 -0
- package/dist/src/migrate/operation-key.js +28 -0
- package/dist/src/migrate/operation-key.js.map +1 -0
- package/dist/src/migrate/swagger-types.d.ts +48 -0
- package/dist/src/migrate/swagger-types.d.ts.map +1 -0
- package/dist/src/migrate/swagger-types.js +7 -0
- package/dist/src/migrate/swagger-types.js.map +1 -0
- package/dist/src/migrate/swagger.d.ts +49 -0
- package/dist/src/migrate/swagger.d.ts.map +1 -0
- package/dist/src/migrate/swagger.js +144 -0
- package/dist/src/migrate/swagger.js.map +1 -0
- package/dist/src/migrate/transform.d.ts +12 -0
- package/dist/src/migrate/transform.d.ts.map +1 -0
- package/dist/src/migrate/transform.js +45 -0
- package/dist/src/migrate/transform.js.map +1 -0
- package/dist/src/migrate/version-order.d.ts +14 -0
- package/dist/src/migrate/version-order.d.ts.map +1 -0
- package/dist/src/migrate/version-order.js +52 -0
- package/dist/src/migrate/version-order.js.map +1 -0
- package/dist/src/migrate-cli.d.ts +3 -0
- package/dist/src/migrate-cli.d.ts.map +1 -0
- package/dist/src/migrate-cli.js +115 -0
- package/dist/src/migrate-cli.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize embedded concrete API-version strings to the `{api-version}` placeholder.
|
|
3
|
+
*
|
|
4
|
+
* `x-ms-examples` frequently bake the api-version into header and body string values
|
|
5
|
+
* (`Location`, `Azure-AsyncOperation`, `nextLink`, ...). Replacing those with `{api-version}`
|
|
6
|
+
* lets otherwise-identical variants across versions collapse into a single lineage entry.
|
|
7
|
+
*/
|
|
8
|
+
/** Recursively replace occurrences of `version` in string values with `{api-version}`. */
|
|
9
|
+
export function normalizeApiVersion(value, version) {
|
|
10
|
+
return normalize(value, buildMatcher([version]));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Normalize using any of the provided versions (longest first, so more specific version strings
|
|
14
|
+
* win over prefixes).
|
|
15
|
+
*/
|
|
16
|
+
export function normalizeApiVersions(value, versions) {
|
|
17
|
+
const ordered = [...new Set(versions)].filter((v) => v.length > 0);
|
|
18
|
+
if (ordered.length === 0)
|
|
19
|
+
return value;
|
|
20
|
+
return normalize(value, buildMatcher(ordered));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A trailing guard so an api-version string is only matched as a whole token. Azure api-versions are
|
|
24
|
+
* `YYYY-MM-DD[-suffix]` and are never immediately followed by a digit or the ISO-8601 time
|
|
25
|
+
* designator `T`, so this prevents corrupting embedded timestamps such as `2023-01-01T09:00:00Z`.
|
|
26
|
+
*/
|
|
27
|
+
const VERSION_BOUNDARY = "(?![T\\d])";
|
|
28
|
+
function buildMatcher(versions) {
|
|
29
|
+
// Longest first so a more specific version (e.g. `...-preview`) wins over a prefix.
|
|
30
|
+
const alternation = [...versions]
|
|
31
|
+
.sort((a, b) => b.length - a.length)
|
|
32
|
+
.map(escapeRegExp)
|
|
33
|
+
.join("|");
|
|
34
|
+
return {
|
|
35
|
+
embedded: new RegExp(`(?:${alternation})${VERSION_BOUNDARY}`, "g"),
|
|
36
|
+
bare: new RegExp(`^(?:${alternation})$`),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function normalize(value, matcher) {
|
|
40
|
+
if (typeof value === "string") {
|
|
41
|
+
// A scalar whose entire value is a bare api-version is real data (e.g. a `date` field), not a
|
|
42
|
+
// version embedded in a URL or header — leave it untouched so migration stays lossless.
|
|
43
|
+
if (matcher.bare.test(value))
|
|
44
|
+
return value;
|
|
45
|
+
matcher.embedded.lastIndex = 0;
|
|
46
|
+
return value.replace(matcher.embedded, "{api-version}");
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
return value.map((item) => normalize(item, matcher));
|
|
50
|
+
}
|
|
51
|
+
if (value !== null && typeof value === "object") {
|
|
52
|
+
const out = {};
|
|
53
|
+
for (const [key, item] of Object.entries(value)) {
|
|
54
|
+
out[key] = normalize(item, matcher);
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
function escapeRegExp(value) {
|
|
61
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,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,QAAQ,EAAE,CAAC;QAC9B,8FAA8F;QAC9F,wFAAwF;QACxF,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS,GAAG,CAAC,CAAC;QAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IAC1D,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,OAAO,KAAK,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive the `examples.yaml` operation key from a Swagger `operationId`.
|
|
3
|
+
*
|
|
4
|
+
* Swagger operation ids follow the `Interface_Method` convention (as emitted by
|
|
5
|
+
* `@azure-tools/typespec-autorest`). The unified format uses the interface-relative key
|
|
6
|
+
* `Interface.method` with a lower-cased first letter on the method (e.g. `CaCertificates_Get`
|
|
7
|
+
* becomes `CaCertificates.get`). Operation ids without an underscore become a bare top-level key.
|
|
8
|
+
*/
|
|
9
|
+
export declare function deriveOperationKey(operationId: string): string;
|
|
10
|
+
/** The interface portion of a derived operation key (everything before the first `.`). */
|
|
11
|
+
export declare function interfaceOf(operationKey: string): string;
|
|
12
|
+
//# sourceMappingURL=operation-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-key.d.ts","sourceRoot":"","sources":["../../../src/migrate/operation-key.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAQ9D;AAED,0FAA0F;AAC1F,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAGxD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive the `examples.yaml` operation key from a Swagger `operationId`.
|
|
3
|
+
*
|
|
4
|
+
* Swagger operation ids follow the `Interface_Method` convention (as emitted by
|
|
5
|
+
* `@azure-tools/typespec-autorest`). The unified format uses the interface-relative key
|
|
6
|
+
* `Interface.method` with a lower-cased first letter on the method (e.g. `CaCertificates_Get`
|
|
7
|
+
* becomes `CaCertificates.get`). Operation ids without an underscore become a bare top-level key.
|
|
8
|
+
*/
|
|
9
|
+
export function deriveOperationKey(operationId) {
|
|
10
|
+
const underscore = operationId.indexOf("_");
|
|
11
|
+
if (underscore < 0) {
|
|
12
|
+
return operationId;
|
|
13
|
+
}
|
|
14
|
+
const iface = operationId.slice(0, underscore);
|
|
15
|
+
const method = operationId.slice(underscore + 1);
|
|
16
|
+
return `${iface}.${lowerFirst(method)}`;
|
|
17
|
+
}
|
|
18
|
+
/** The interface portion of a derived operation key (everything before the first `.`). */
|
|
19
|
+
export function interfaceOf(operationKey) {
|
|
20
|
+
const dot = operationKey.indexOf(".");
|
|
21
|
+
return dot < 0 ? operationKey : operationKey.slice(0, dot);
|
|
22
|
+
}
|
|
23
|
+
function lowerFirst(value) {
|
|
24
|
+
if (value.length === 0)
|
|
25
|
+
return value;
|
|
26
|
+
return value.charAt(0).toLowerCase() + value.slice(1);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=operation-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-key.js","sourceRoot":"","sources":["../../../src/migrate/operation-key.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAmB;IACpD,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;QACnB,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;IACjD,OAAO,GAAG,KAAK,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;AAC1C,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,WAAW,CAAC,YAAoB;IAC9C,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACrC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types describing the *inputs* to `tsp-examples-migrate`: the classic Swagger `x-ms-examples`
|
|
3
|
+
* extension and the referenced example JSON documents.
|
|
4
|
+
*/
|
|
5
|
+
/** Parameter location as declared on a Swagger operation/path parameter. */
|
|
6
|
+
export type ParameterLocation = "path" | "query" | "header" | "body" | "formData";
|
|
7
|
+
/** A Swagger parameter object (or a `$ref` to one). */
|
|
8
|
+
export interface SwaggerParameter {
|
|
9
|
+
readonly name?: string;
|
|
10
|
+
readonly in?: ParameterLocation;
|
|
11
|
+
readonly $ref?: string;
|
|
12
|
+
}
|
|
13
|
+
/** A single Swagger operation carrying `x-ms-examples`. */
|
|
14
|
+
export interface SwaggerOperation {
|
|
15
|
+
readonly operationId?: string;
|
|
16
|
+
readonly parameters?: SwaggerParameter[];
|
|
17
|
+
readonly "x-ms-examples"?: Record<string, {
|
|
18
|
+
readonly $ref?: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
/** The subset of a Swagger document `tsp-examples-migrate` reads. */
|
|
22
|
+
export interface SwaggerDocument {
|
|
23
|
+
readonly info?: {
|
|
24
|
+
readonly title?: string;
|
|
25
|
+
readonly version?: string;
|
|
26
|
+
};
|
|
27
|
+
readonly parameters?: Record<string, SwaggerParameter>;
|
|
28
|
+
readonly paths?: Record<string, SwaggerPathItem>;
|
|
29
|
+
}
|
|
30
|
+
/** A Swagger path item: HTTP methods plus optional path-level `parameters`. */
|
|
31
|
+
export interface SwaggerPathItem {
|
|
32
|
+
readonly parameters?: SwaggerParameter[];
|
|
33
|
+
readonly [method: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
/** The referenced `x-ms-examples` example document. */
|
|
36
|
+
export interface XmsExampleDoc {
|
|
37
|
+
readonly operationId?: string;
|
|
38
|
+
readonly title?: string;
|
|
39
|
+
readonly parameters?: Record<string, unknown>;
|
|
40
|
+
readonly responses?: Record<string, XmsExampleResponse>;
|
|
41
|
+
}
|
|
42
|
+
export interface XmsExampleResponse {
|
|
43
|
+
readonly headers?: Record<string, unknown>;
|
|
44
|
+
readonly body?: unknown;
|
|
45
|
+
}
|
|
46
|
+
/** The HTTP methods that can carry an operation on a Swagger path item. */
|
|
47
|
+
export declare const HTTP_METHODS: readonly ["get", "put", "post", "delete", "options", "head", "patch"];
|
|
48
|
+
//# sourceMappingURL=swagger-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-types.d.ts","sourceRoot":"","sources":["../../../src/migrate/swagger-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4EAA4E;AAC5E,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;AAElF,uDAAuD;AACvD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,CAAC,EAAE,iBAAiB,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,2DAA2D;AAC3D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACzC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvE;AAED,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACvE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACvD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAClD;AAED,+EAA+E;AAC/E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACzC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC;AAED,uDAAuD;AACvD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,2EAA2E;AAC3E,eAAO,MAAM,YAAY,uEAAwE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types describing the *inputs* to `tsp-examples-migrate`: the classic Swagger `x-ms-examples`
|
|
3
|
+
* extension and the referenced example JSON documents.
|
|
4
|
+
*/
|
|
5
|
+
/** The HTTP methods that can carry an operation on a Swagger path item. */
|
|
6
|
+
export const HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch"];
|
|
7
|
+
//# sourceMappingURL=swagger-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-types.js","sourceRoot":"","sources":["../../../src/migrate/swagger-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA6CH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ParameterLocation, SwaggerDocument, SwaggerParameter, XmsExampleDoc } from "./swagger-types.js";
|
|
2
|
+
/** An operation extracted from a Swagger document, with its parameter-location map. */
|
|
3
|
+
export interface ExtractedOperation {
|
|
4
|
+
readonly operationId: string;
|
|
5
|
+
readonly paramLocations: Map<string, ParameterLocation>;
|
|
6
|
+
readonly examples: Record<string, {
|
|
7
|
+
readonly $ref?: string;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
/** One example, fully loaded and associated with an operation and API version. */
|
|
11
|
+
export interface CrawledExample {
|
|
12
|
+
readonly operationId: string;
|
|
13
|
+
readonly version: string;
|
|
14
|
+
readonly exampleName: string;
|
|
15
|
+
/** The original `x-ms-examples` file name (basename of the `$ref`), e.g. `Foo_Get.json`. */
|
|
16
|
+
readonly fileName: string;
|
|
17
|
+
readonly doc: XmsExampleDoc;
|
|
18
|
+
readonly paramLocations: Map<string, ParameterLocation>;
|
|
19
|
+
}
|
|
20
|
+
/** The full result of crawling a spec tree. */
|
|
21
|
+
export interface CrawlResult {
|
|
22
|
+
readonly examples: CrawledExample[];
|
|
23
|
+
readonly namespace?: string;
|
|
24
|
+
readonly versions: string[];
|
|
25
|
+
}
|
|
26
|
+
/** Detect the resource-provider namespace from Swagger path templates (`/providers/<NS>/`). */
|
|
27
|
+
export declare function namespaceFromPaths(pathKeys: Iterable<string>): string | undefined;
|
|
28
|
+
/** Resolve a local `#/parameters/<name>` reference against the document's parameter map. */
|
|
29
|
+
export declare function resolveLocalParam(doc: SwaggerDocument, parameter: SwaggerParameter): SwaggerParameter | undefined;
|
|
30
|
+
/** Build a parameter-name → location map from path-level and operation-level parameters. */
|
|
31
|
+
export declare function collectParamLocations(doc: SwaggerDocument, parameters: readonly SwaggerParameter[] | undefined): Map<string, ParameterLocation>;
|
|
32
|
+
/** Extract every operation that carries `x-ms-examples` from a parsed Swagger document. */
|
|
33
|
+
export declare function extractOperations(doc: SwaggerDocument): ExtractedOperation[];
|
|
34
|
+
/**
|
|
35
|
+
* Extract the API version from a Swagger file path: the path segment immediately following a
|
|
36
|
+
* `stable` or `preview` segment (the Azure spec layout). Returns `undefined` when not found.
|
|
37
|
+
*/
|
|
38
|
+
export declare function versionFromPath(filePath: string): string | undefined;
|
|
39
|
+
/** Resolve an `x-ms-examples` `$ref` (relative file path with optional fragment) to a file path. */
|
|
40
|
+
export declare function resolveRefPath(fromFile: string, ref: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Recursively discover Swagger documents under `root`. A file qualifies when its path contains a
|
|
43
|
+
* `stable`/`preview` version segment and its content has a `paths` object (i.e. it is a service
|
|
44
|
+
* spec, not an example JSON).
|
|
45
|
+
*/
|
|
46
|
+
export declare function discoverSwaggerFiles(root: string): Promise<string[]>;
|
|
47
|
+
/** Crawl `root`, loading every `x-ms-examples` document for every versioned Swagger operation. */
|
|
48
|
+
export declare function crawlExamples(root: string): Promise<CrawlResult>;
|
|
49
|
+
//# sourceMappingURL=swagger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger.d.ts","sourceRoot":"","sources":["../../../src/migrate/swagger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EAEf,gBAAgB,EAChB,aAAa,EACd,MAAM,oBAAoB,CAAC;AAG5B,uFAAuF;AACvF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACxD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC/D;AAED,kFAAkF;AAClF,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;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAW1E;AAOD,kGAAkG;AAClG,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CA0CtE"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { readdir, readFile } from "fs/promises";
|
|
2
|
+
import { basename, dirname, isAbsolute, join, resolve, sep } from "path";
|
|
3
|
+
import { HTTP_METHODS } from "./swagger-types.js";
|
|
4
|
+
/** Detect the resource-provider namespace from Swagger path templates (`/providers/<NS>/`). */
|
|
5
|
+
export function namespaceFromPaths(pathKeys) {
|
|
6
|
+
for (const path of pathKeys) {
|
|
7
|
+
const match = /\/providers\/([^/{}]+)\//.exec(path);
|
|
8
|
+
if (match)
|
|
9
|
+
return match[1];
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
/** Resolve a local `#/parameters/<name>` reference against the document's parameter map. */
|
|
14
|
+
export function resolveLocalParam(doc, parameter) {
|
|
15
|
+
if (parameter.$ref === undefined)
|
|
16
|
+
return parameter;
|
|
17
|
+
const match = /^#\/parameters\/(.+)$/.exec(parameter.$ref);
|
|
18
|
+
if (!match)
|
|
19
|
+
return undefined;
|
|
20
|
+
return doc.parameters?.[decodeURIComponent(match[1])];
|
|
21
|
+
}
|
|
22
|
+
/** Build a parameter-name → location map from path-level and operation-level parameters. */
|
|
23
|
+
export function collectParamLocations(doc, parameters) {
|
|
24
|
+
const map = new Map();
|
|
25
|
+
for (const raw of parameters ?? []) {
|
|
26
|
+
const resolved = resolveLocalParam(doc, raw);
|
|
27
|
+
if (resolved?.name !== undefined && resolved.in !== undefined) {
|
|
28
|
+
map.set(resolved.name, resolved.in);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return map;
|
|
32
|
+
}
|
|
33
|
+
/** Extract every operation that carries `x-ms-examples` from a parsed Swagger document. */
|
|
34
|
+
export function extractOperations(doc) {
|
|
35
|
+
const operations = [];
|
|
36
|
+
for (const pathItem of Object.values(doc.paths ?? {})) {
|
|
37
|
+
const pathParams = pathItem.parameters;
|
|
38
|
+
for (const method of HTTP_METHODS) {
|
|
39
|
+
const operation = pathItem[method];
|
|
40
|
+
if (operation === undefined || typeof operation !== "object")
|
|
41
|
+
continue;
|
|
42
|
+
const examples = operation["x-ms-examples"];
|
|
43
|
+
if (examples === undefined || operation.operationId === undefined)
|
|
44
|
+
continue;
|
|
45
|
+
const paramLocations = collectParamLocations(doc, [
|
|
46
|
+
...(pathParams ?? []),
|
|
47
|
+
...(operation.parameters ?? []),
|
|
48
|
+
]);
|
|
49
|
+
operations.push({ operationId: operation.operationId, paramLocations, examples });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return operations;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Extract the API version from a Swagger file path: the path segment immediately following a
|
|
56
|
+
* `stable` or `preview` segment (the Azure spec layout). Returns `undefined` when not found.
|
|
57
|
+
*/
|
|
58
|
+
export function versionFromPath(filePath) {
|
|
59
|
+
const segments = filePath.split(/[\\/]/);
|
|
60
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
61
|
+
if (segments[i] === "stable" || segments[i] === "preview") {
|
|
62
|
+
return segments[i + 1];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
/** Resolve an `x-ms-examples` `$ref` (relative file path with optional fragment) to a file path. */
|
|
68
|
+
export function resolveRefPath(fromFile, ref) {
|
|
69
|
+
const withoutFragment = ref.split("#")[0];
|
|
70
|
+
if (isAbsolute(withoutFragment))
|
|
71
|
+
return withoutFragment;
|
|
72
|
+
return resolve(dirname(fromFile), withoutFragment);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Recursively discover Swagger documents under `root`. A file qualifies when its path contains a
|
|
76
|
+
* `stable`/`preview` version segment and its content has a `paths` object (i.e. it is a service
|
|
77
|
+
* spec, not an example JSON).
|
|
78
|
+
*/
|
|
79
|
+
export async function discoverSwaggerFiles(root) {
|
|
80
|
+
const entries = await readdir(root, { recursive: true, withFileTypes: true });
|
|
81
|
+
const files = [];
|
|
82
|
+
for (const entry of entries) {
|
|
83
|
+
if (!entry.isFile() || !entry.name.endsWith(".json"))
|
|
84
|
+
continue;
|
|
85
|
+
const full = join(entryDir(entry, root), entry.name);
|
|
86
|
+
if (versionFromPath(full) === undefined)
|
|
87
|
+
continue;
|
|
88
|
+
if (full.split(sep).includes("examples"))
|
|
89
|
+
continue;
|
|
90
|
+
files.push(full);
|
|
91
|
+
}
|
|
92
|
+
return files.sort();
|
|
93
|
+
}
|
|
94
|
+
function entryDir(entry, root) {
|
|
95
|
+
// Node's Dirent exposes `parentPath` (>=20.12) or the older `path`.
|
|
96
|
+
return entry.parentPath ?? entry.path ?? root;
|
|
97
|
+
}
|
|
98
|
+
/** Crawl `root`, loading every `x-ms-examples` document for every versioned Swagger operation. */
|
|
99
|
+
export async function crawlExamples(root) {
|
|
100
|
+
const files = await discoverSwaggerFiles(root);
|
|
101
|
+
const crawled = [];
|
|
102
|
+
const versions = new Set();
|
|
103
|
+
let namespace;
|
|
104
|
+
for (const file of files) {
|
|
105
|
+
let doc;
|
|
106
|
+
try {
|
|
107
|
+
doc = JSON.parse(await readFile(file, "utf-8"));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (doc.paths === undefined)
|
|
113
|
+
continue;
|
|
114
|
+
const version = versionFromPath(file);
|
|
115
|
+
if (version === undefined)
|
|
116
|
+
continue;
|
|
117
|
+
versions.add(version);
|
|
118
|
+
namespace ??= namespaceFromPaths(Object.keys(doc.paths));
|
|
119
|
+
for (const operation of extractOperations(doc)) {
|
|
120
|
+
for (const [exampleName, entry] of Object.entries(operation.examples)) {
|
|
121
|
+
if (entry?.$ref === undefined)
|
|
122
|
+
continue;
|
|
123
|
+
const examplePath = resolveRefPath(file, entry.$ref);
|
|
124
|
+
let exampleDoc;
|
|
125
|
+
try {
|
|
126
|
+
exampleDoc = JSON.parse(await readFile(examplePath, "utf-8"));
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
crawled.push({
|
|
132
|
+
operationId: operation.operationId,
|
|
133
|
+
version,
|
|
134
|
+
exampleName,
|
|
135
|
+
fileName: basename(examplePath),
|
|
136
|
+
doc: exampleDoc,
|
|
137
|
+
paramLocations: operation.paramLocations,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { examples: crawled, namespace, versions: [...versions] };
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=swagger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger.js","sourceRoot":"","sources":["../../../src/migrate/swagger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAQzE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AA2BlD,+FAA+F;AAC/F,MAAM,UAAU,kBAAkB,CAAC,QAA0B;IAC3D,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,iBAAiB,CAC/B,GAAoB,EACpB,SAA2B;IAE3B,IAAI,SAAS,CAAC,IAAI,KAAK,SA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AAG,QAAQ,CAAC,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MigratedVariant } from "./model.js";
|
|
2
|
+
import type { ParameterLocation, XmsExampleDoc } from "./swagger-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Convert one `x-ms-examples` document into a {@link MigratedVariant}, using a map of
|
|
5
|
+
* parameter-name → location (built from the operation's Swagger parameter definitions) to bucket
|
|
6
|
+
* each example parameter into `request.path` / `query` / `headers` / `body`.
|
|
7
|
+
*
|
|
8
|
+
* The implicit `api-version` parameter is dropped. Parameters whose location is unknown (not
|
|
9
|
+
* declared on the operation) default to `query`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function transformExample(doc: XmsExampleDoc, paramLocations: ReadonlyMap<string, ParameterLocation>): MigratedVariant;
|
|
12
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/migrate/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqC,eAAe,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE3E;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,aAAa,EAClB,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,iBAAiB,CAAC,GACrD,eAAe,CAoCjB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert one `x-ms-examples` document into a {@link MigratedVariant}, using a map of
|
|
3
|
+
* parameter-name → location (built from the operation's Swagger parameter definitions) to bucket
|
|
4
|
+
* each example parameter into `request.path` / `query` / `headers` / `body`.
|
|
5
|
+
*
|
|
6
|
+
* The implicit `api-version` parameter is dropped. Parameters whose location is unknown (not
|
|
7
|
+
* declared on the operation) default to `query`.
|
|
8
|
+
*/
|
|
9
|
+
export function transformExample(doc, paramLocations) {
|
|
10
|
+
const request = {};
|
|
11
|
+
for (const [name, value] of Object.entries(doc.parameters ?? {})) {
|
|
12
|
+
if (name.toLowerCase() === "api-version")
|
|
13
|
+
continue;
|
|
14
|
+
const location = paramLocations.get(name) ?? "query";
|
|
15
|
+
switch (location) {
|
|
16
|
+
case "body":
|
|
17
|
+
request.body = value;
|
|
18
|
+
break;
|
|
19
|
+
case "path":
|
|
20
|
+
(request.path ??= {})[name] = value;
|
|
21
|
+
break;
|
|
22
|
+
case "header":
|
|
23
|
+
(request.headers ??= {})[name] = value;
|
|
24
|
+
break;
|
|
25
|
+
case "query":
|
|
26
|
+
case "formData":
|
|
27
|
+
default:
|
|
28
|
+
(request.query ??= {})[name] = value;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const responses = {};
|
|
33
|
+
for (const [code, response] of Object.entries(doc.responses ?? {})) {
|
|
34
|
+
const mapped = {};
|
|
35
|
+
if (response && typeof response === "object") {
|
|
36
|
+
if (response.headers !== undefined)
|
|
37
|
+
mapped.headers = response.headers;
|
|
38
|
+
if (response.body !== undefined)
|
|
39
|
+
mapped.body = response.body;
|
|
40
|
+
}
|
|
41
|
+
responses[code] = mapped;
|
|
42
|
+
}
|
|
43
|
+
return { request, responses };
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/migrate/transform.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAkB,EAClB,cAAsD;IAEtD,MAAM,OAAO,GAAoB,EAAE,CAAC;IAEpC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,CAAC;QACjE,IAAI,IAAI,CAAC,WAA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0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version ordering for migration. Azure API versions are date-based (`YYYY-MM-DD`) with an optional
|
|
3
|
+
* `-preview`/`-beta` suffix. When a `service.yaml` order is available it is authoritative; otherwise
|
|
4
|
+
* this heuristic sorts by date ascending and places a same-dated preview *before* its GA.
|
|
5
|
+
*/
|
|
6
|
+
/** Build a comparator from an explicit, authoritative version order (e.g. from `service.yaml`). */
|
|
7
|
+
export declare function comparatorFromOrder(order: readonly string[]): (a: string, b: string) => number;
|
|
8
|
+
/** Heuristic comparator over date-based Azure version strings. */
|
|
9
|
+
export declare function defaultCompareVersions(a: string, b: string): number;
|
|
10
|
+
/** Return the earliest version under the given comparator. */
|
|
11
|
+
export declare function earliestVersion(versions: readonly string[], compare: (a: string, b: string) => number): string | undefined;
|
|
12
|
+
/** Return the latest version under the given comparator. */
|
|
13
|
+
export declare function latestVersion(versions: readonly string[], compare: (a: string, b: string) => number): string | undefined;
|
|
14
|
+
//# sourceMappingURL=version-order.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-order.d.ts","sourceRoot":"","sources":["../../../src/migrate/version-order.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,mGAAmG;AACnG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAU9F;AAED,kEAAkE;AAClE,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAQnE;AAED,8DAA8D;AAC9D,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,GACxC,MAAM,GAAG,SAAS,CAGpB;AAED,4DAA4D;AAC5D,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,GACxC,MAAM,GAAG,SAAS,CAGpB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version ordering for migration. Azure API versions are date-based (`YYYY-MM-DD`) with an optional
|
|
3
|
+
* `-preview`/`-beta` suffix. When a `service.yaml` order is available it is authoritative; otherwise
|
|
4
|
+
* this heuristic sorts by date ascending and places a same-dated preview *before* its GA.
|
|
5
|
+
*/
|
|
6
|
+
/** Build a comparator from an explicit, authoritative version order (e.g. from `service.yaml`). */
|
|
7
|
+
export function comparatorFromOrder(order) {
|
|
8
|
+
const index = new Map(order.map((version, i) => [version, i]));
|
|
9
|
+
return (a, b) => {
|
|
10
|
+
const ia = index.get(a);
|
|
11
|
+
const ib = index.get(b);
|
|
12
|
+
if (ia !== undefined && ib !== undefined)
|
|
13
|
+
return ia - ib;
|
|
14
|
+
if (ia !== undefined)
|
|
15
|
+
return -1;
|
|
16
|
+
if (ib !== undefined)
|
|
17
|
+
return 1;
|
|
18
|
+
return defaultCompareVersions(a, b);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Heuristic comparator over date-based Azure version strings. */
|
|
22
|
+
export function defaultCompareVersions(a, b) {
|
|
23
|
+
const da = datePart(a);
|
|
24
|
+
const db = datePart(b);
|
|
25
|
+
if (da !== db)
|
|
26
|
+
return da < db ? -1 : 1;
|
|
27
|
+
const pa = isPreview(a) ? 0 : 1;
|
|
28
|
+
const pb = isPreview(b) ? 0 : 1;
|
|
29
|
+
if (pa !== pb)
|
|
30
|
+
return pa - pb;
|
|
31
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
/** Return the earliest version under the given comparator. */
|
|
34
|
+
export function earliestVersion(versions, compare) {
|
|
35
|
+
if (versions.length === 0)
|
|
36
|
+
return undefined;
|
|
37
|
+
return [...versions].sort(compare)[0];
|
|
38
|
+
}
|
|
39
|
+
/** Return the latest version under the given comparator. */
|
|
40
|
+
export function latestVersion(versions, compare) {
|
|
41
|
+
if (versions.length === 0)
|
|
42
|
+
return undefined;
|
|
43
|
+
return [...versions].sort(compare)[versions.length - 1];
|
|
44
|
+
}
|
|
45
|
+
function datePart(version) {
|
|
46
|
+
const match = /^\d{4}-\d{2}-\d{2}/.exec(version);
|
|
47
|
+
return match ? match[0] : version;
|
|
48
|
+
}
|
|
49
|
+
function isPreview(version) {
|
|
50
|
+
return /-(preview|beta|privatepreview)/i.test(version);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=version-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-order.js","sourceRoot":"","sources":["../../../src/migrate/version-order.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,mGAAmG;AACnG,MAAM,UAAU,mBAAmB,CAAC,KAAwB;IAC1D,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAU,CAAC,CAAC,CAAC;IACxE,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACd,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,SAAS;YAAE,OAAO,EAAE,GAAG,EAAE,CAAC;QACzD,IAAI,EAAE,KAAK,SAAS;YAAE,OAAO,CAAC,CAAC,CAAC;QAChC,IAAI,EAAE,KAAK,SAAS;YAAE,OAAO,CAAC,CAAC;QAC/B,OAAO,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC;AACJ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