@distilled.cloud/core 1.0.0-rc.15 → 1.0.0-rc.17
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/lib/_bundle/aws.js +2 -0
- package/lib/_bundle/aws.js.map +1 -0
- package/lib/_bundle/base.js +5 -0
- package/lib/_bundle/base.js.map +1 -0
- package/lib/_bundle/graphql.js +3 -0
- package/lib/_bundle/graphql.js.map +1 -0
- package/lib/_bundle/rest.js +2 -0
- package/lib/_bundle/rest.js.map +1 -0
- package/lib/_bundle/xml.js +4 -0
- package/lib/_bundle/xml.js.map +1 -0
- package/lib/api.d.ts +118 -13
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -188
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +1 -278
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +1 -0
- package/lib/codegen/boolean-string-enums.js +36 -36
- package/lib/codegen/chunk.d.ts +7 -0
- package/lib/codegen/chunk.d.ts.map +1 -0
- package/lib/codegen/chunk.js +139 -0
- package/lib/codegen/chunk.js.map +1 -0
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +28 -14
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/datafy.d.ts +14 -0
- package/lib/codegen/datafy.d.ts.map +1 -0
- package/lib/codegen/datafy.js +853 -0
- package/lib/codegen/datafy.js.map +1 -0
- package/lib/codegen/dedupe.d.ts +5 -0
- package/lib/codegen/dedupe.d.ts.map +1 -0
- package/lib/codegen/dedupe.js +153 -0
- package/lib/codegen/dedupe.js.map +1 -0
- package/lib/codegen/emit.js +56 -56
- package/lib/codegen/format.js +18 -18
- package/lib/codegen/generated-at.js +29 -29
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +92 -84
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/graph.js +36 -36
- package/lib/codegen/graphql-client.d.ts +2 -0
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +55 -26
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql.js +113 -113
- package/lib/codegen/latin1.d.ts +3 -0
- package/lib/codegen/latin1.d.ts.map +1 -0
- package/lib/codegen/latin1.js +126 -0
- package/lib/codegen/latin1.js.map +1 -0
- package/lib/codegen/members.d.ts +7 -0
- package/lib/codegen/members.d.ts.map +1 -1
- package/lib/codegen/members.js +26 -19
- package/lib/codegen/members.js.map +1 -1
- package/lib/codegen/model-diff.js +6 -6
- package/lib/codegen/naming.js +19 -19
- package/lib/codegen/openapi-cli.js +15 -15
- package/lib/codegen/openapi.d.ts +17 -0
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +323 -169
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.js +14 -14
- package/lib/codegen/pagination.js +11 -11
- package/lib/codegen/patch-audit.js +57 -57
- package/lib/codegen/patches.js +79 -79
- package/lib/codegen/prelude.js +19 -19
- package/lib/codegen/privatize.d.ts +21 -0
- package/lib/codegen/privatize.d.ts.map +1 -0
- package/lib/codegen/privatize.js +176 -0
- package/lib/codegen/privatize.js.map +1 -0
- package/lib/codegen/proto.js +25 -25
- package/lib/codegen/pure.d.ts +6 -0
- package/lib/codegen/pure.d.ts.map +1 -0
- package/lib/codegen/pure.js +91 -0
- package/lib/codegen/pure.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.js +108 -108
- package/lib/codegen/spec-path.js +57 -57
- package/lib/codegen/table.d.ts +5 -0
- package/lib/codegen/table.d.ts.map +1 -0
- package/lib/codegen/table.js +249 -0
- package/lib/codegen/table.js.map +1 -0
- package/lib/config.d.ts +27 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +1 -0
- package/lib/crypto.d.ts +76 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +1 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.d.ts.map +1 -0
- package/lib/debug.js +1 -0
- package/lib/error-category.d.ts +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +1 -46
- package/lib/errors.d.ts +62 -62
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -195
- package/lib/graphql.d.ts +31 -20
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +1 -1027
- package/lib/graphql.types.js +1 -5
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -15
- package/lib/json-patch.d.ts +2 -2
- package/lib/json-patch.js +1 -226
- package/lib/json-patch.js.map +1 -1
- package/lib/pagination.d.ts +9 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -266
- package/lib/plain-values.d.ts +10 -0
- package/lib/plain-values.d.ts.map +1 -0
- package/lib/plain-values.js +2 -0
- package/lib/plain-values.js.map +1 -0
- package/lib/protocol-http.d.ts +50 -14
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -639
- package/lib/protocol-rest.d.ts +38 -25
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -267
- package/lib/query.js +1 -27
- package/lib/response-validation-strict.d.ts +48 -0
- package/lib/response-validation-strict.d.ts.map +1 -0
- package/lib/response-validation-strict.js +1 -0
- package/lib/response-validation.d.ts +43 -25
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +1 -76
- package/lib/retry-after.d.ts +3 -3
- package/lib/retry-after.js +1 -112
- package/lib/retry.d.ts +48 -29
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -209
- package/lib/schema-lite-impl.d.ts +158 -0
- package/lib/schema-lite-impl.d.ts.map +1 -0
- package/lib/schema-lite-impl.js +1 -0
- package/lib/schema-lite-typed.d.ts +41 -0
- package/lib/schema-lite-typed.d.ts.map +1 -0
- package/lib/schema-lite-typed.js +2 -0
- package/lib/schema-lite-typed.js.map +1 -0
- package/lib/schema-lite.d.ts +40 -0
- package/lib/schema-lite.d.ts.map +1 -0
- package/lib/schema-lite.js +1 -0
- package/lib/schema.d.ts +20 -6
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +1 -48
- package/lib/testing.d.ts +3 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +1 -40
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts +13 -13
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +1 -131
- package/lib/xml.d.ts +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +1 -311
- package/package.json +9 -7
- package/src/api.ts +1080 -180
- package/src/category.ts +33 -33
- package/src/chunks.ts +30 -0
- package/src/codegen/chunk.ts +147 -0
- package/src/codegen/cli.ts +27 -1
- package/src/codegen/datafy.ts +874 -0
- package/src/codegen/dedupe.ts +173 -0
- package/src/codegen/generator.ts +10 -3
- package/src/codegen/graphql-client.ts +49 -15
- package/src/codegen/latin1.ts +131 -0
- package/src/codegen/members.ts +8 -0
- package/src/codegen/openapi.ts +194 -3
- package/src/codegen/privatize.ts +200 -0
- package/src/codegen/pure.ts +94 -0
- package/src/codegen/table.ts +254 -0
- package/src/config.ts +216 -0
- package/src/crypto.ts +202 -0
- package/src/debug.ts +8 -0
- package/src/error-category.ts +2 -1
- package/src/errors.ts +65 -56
- package/src/graphql.ts +109 -62
- package/src/graphql.types.ts +9 -7
- package/src/index.ts +3 -2
- package/src/json-patch.ts +2 -2
- package/src/pagination.ts +37 -18
- package/src/plain-values.ts +41 -0
- package/src/protocol-http.ts +378 -145
- package/src/protocol-rest.ts +337 -169
- package/src/response-validation-strict.ts +327 -0
- package/src/response-validation.ts +101 -50
- package/src/retry-after.ts +3 -3
- package/src/retry.ts +94 -93
- package/src/schema-lite-impl.ts +550 -0
- package/src/schema-lite-typed.ts +44 -0
- package/src/schema-lite.ts +44 -0
- package/src/schema.ts +258 -14
- package/src/testing.ts +4 -2
- package/src/trait.ts +36 -28
- package/src/xml.ts +31 -17
- package/lib/api.js.map +0 -1
- package/lib/category.js.map +0 -1
- package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
- package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.test.js +0 -275
- package/lib/codegen/boolean-string-enums.test.js.map +0 -1
- package/lib/codegen/defer-naming.test.d.ts +0 -2
- package/lib/codegen/defer-naming.test.d.ts.map +0 -1
- package/lib/codegen/defer-naming.test.js +0 -105
- package/lib/codegen/defer-naming.test.js.map +0 -1
- package/lib/codegen/generated-at.test.d.ts +0 -2
- package/lib/codegen/generated-at.test.d.ts.map +0 -1
- package/lib/codegen/generated-at.test.js +0 -81
- package/lib/codegen/generated-at.test.js.map +0 -1
- package/lib/codegen/generator.test.d.ts +0 -2
- package/lib/codegen/generator.test.d.ts.map +0 -1
- package/lib/codegen/generator.test.js +0 -121
- package/lib/codegen/generator.test.js.map +0 -1
- package/lib/codegen/graphql-client.test.d.ts +0 -2
- package/lib/codegen/graphql-client.test.d.ts.map +0 -1
- package/lib/codegen/graphql-client.test.js +0 -171
- package/lib/codegen/graphql-client.test.js.map +0 -1
- package/lib/codegen/openapi-binary.test.d.ts +0 -2
- package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
- package/lib/codegen/openapi-binary.test.js +0 -67
- package/lib/codegen/openapi-binary.test.js.map +0 -1
- package/lib/codegen/patch-audit.test.d.ts +0 -2
- package/lib/codegen/patch-audit.test.d.ts.map +0 -1
- package/lib/codegen/patch-audit.test.js +0 -141
- package/lib/codegen/patch-audit.test.js.map +0 -1
- package/lib/codegen/patches.test.d.ts +0 -2
- package/lib/codegen/patches.test.d.ts.map +0 -1
- package/lib/codegen/patches.test.js +0 -155
- package/lib/codegen/patches.test.js.map +0 -1
- package/lib/codegen/protocol-imports.test.d.ts +0 -2
- package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
- package/lib/codegen/protocol-imports.test.js +0 -36
- package/lib/codegen/protocol-imports.test.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
- package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.js +0 -451
- package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
- package/lib/codegen/untagged-unions.test.d.ts +0 -2
- package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
- package/lib/codegen/untagged-unions.test.js +0 -80
- package/lib/codegen/untagged-unions.test.js.map +0 -1
- package/lib/error-category.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/fixtures/xml/upstream-validator.json +0 -397
- package/lib/graphql.js.map +0 -1
- package/lib/graphql.test.d.ts +0 -2
- package/lib/graphql.test.d.ts.map +0 -1
- package/lib/graphql.test.js +0 -151
- package/lib/graphql.test.js.map +0 -1
- package/lib/graphql.types.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/json-patch.test.d.ts +0 -2
- package/lib/json-patch.test.d.ts.map +0 -1
- package/lib/json-patch.test.js +0 -65
- package/lib/json-patch.test.js.map +0 -1
- package/lib/pagination.js.map +0 -1
- package/lib/pagination.test.d.ts +0 -2
- package/lib/pagination.test.d.ts.map +0 -1
- package/lib/pagination.test.js +0 -131
- package/lib/pagination.test.js.map +0 -1
- package/lib/protocol-http.js.map +0 -1
- package/lib/protocol-http.test.d.ts +0 -2
- package/lib/protocol-http.test.d.ts.map +0 -1
- package/lib/protocol-http.test.js +0 -228
- package/lib/protocol-http.test.js.map +0 -1
- package/lib/protocol-rest.js.map +0 -1
- package/lib/protocol-rest.test.d.ts +0 -2
- package/lib/protocol-rest.test.d.ts.map +0 -1
- package/lib/protocol-rest.test.js +0 -498
- package/lib/protocol-rest.test.js.map +0 -1
- package/lib/query.js.map +0 -1
- package/lib/response-validation.js.map +0 -1
- package/lib/response-validation.test.d.ts +0 -2
- package/lib/response-validation.test.d.ts.map +0 -1
- package/lib/response-validation.test.js +0 -72
- package/lib/response-validation.test.js.map +0 -1
- package/lib/retry-after.js.map +0 -1
- package/lib/retry-after.test.d.ts +0 -2
- package/lib/retry-after.test.d.ts.map +0 -1
- package/lib/retry-after.test.js +0 -204
- package/lib/retry-after.test.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/retry.test.d.ts +0 -2
- package/lib/retry.test.d.ts.map +0 -1
- package/lib/retry.test.js +0 -407
- package/lib/retry.test.js.map +0 -1
- package/lib/schema.js.map +0 -1
- package/lib/sdks.test.d.ts +0 -2
- package/lib/sdks.test.d.ts.map +0 -1
- package/lib/sdks.test.js +0 -76
- package/lib/sdks.test.js.map +0 -1
- package/lib/trait.js.map +0 -1
- package/lib/xml.js.map +0 -1
- package/lib/xml.test.d.ts +0 -2
- package/lib/xml.test.d.ts.map +0 -1
- package/lib/xml.test.js +0 -210
- package/lib/xml.test.js.map +0 -1
- package/src/codegen/boolean-string-enums.test.ts +0 -299
- package/src/codegen/defer-naming.test.ts +0 -113
- package/src/codegen/generated-at.test.ts +0 -89
- package/src/codegen/generator.test.ts +0 -137
- package/src/codegen/graphql-client.test.ts +0 -189
- package/src/codegen/openapi-binary.test.ts +0 -91
- package/src/codegen/patch-audit.test.ts +0 -160
- package/src/codegen/patches.test.ts +0 -188
- package/src/codegen/protocol-imports.test.ts +0 -39
- package/src/codegen/rewrite-operation-ids.test.ts +0 -472
- package/src/codegen/untagged-unions.test.ts +0 -85
- package/src/fixtures/xml/upstream-validator.json +0 -397
- package/src/graphql.test.ts +0 -198
- package/src/json-patch.test.ts +0 -77
- package/src/pagination.test.ts +0 -169
- package/src/protocol-http.test.ts +0 -276
- package/src/protocol-rest.test.ts +0 -703
- package/src/response-validation.test.ts +0 -89
- package/src/retry-after.test.ts +0 -267
- package/src/retry.test.ts +0 -566
- package/src/sdks.test.ts +0 -87
- package/src/xml.test.ts +0 -251
package/src/codegen/openapi.ts
CHANGED
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
* (with the non-standard `mode` member the core runtime dispatches on)
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
|
+
import { ADDITIONAL_PROPERTIES_TRAIT } from "./members.ts";
|
|
47
48
|
import {
|
|
48
49
|
isMechanicalOperationId,
|
|
49
50
|
isVerbatimRouteId,
|
|
@@ -178,6 +179,23 @@ export interface OpenApiConvertOptions {
|
|
|
178
179
|
* otherwise generate as a `void` output.
|
|
179
180
|
*/
|
|
180
181
|
readonly successStatuses?: readonly string[];
|
|
182
|
+
/**
|
|
183
|
+
* Response headers (matched case-insensitively) to add to an operation's
|
|
184
|
+
* output as optional `smithy.api#httpHeader` members wherever one of its
|
|
185
|
+
* 2xx responses declares them -- bodiless ones such as `202 Accepted`
|
|
186
|
+
* included. An allowlist for the same reason as {@link headerParams}:
|
|
187
|
+
* specs declare noise headers (request ids, ETags) on most responses.
|
|
188
|
+
* Azure lists its long-running-operation status monitor
|
|
189
|
+
* (`Azure-AsyncOperation`, `Location`, `Retry-After`), which callers need
|
|
190
|
+
* to follow the operation themselves.
|
|
191
|
+
*
|
|
192
|
+
* An operation whose output reuses a named component gets its own output
|
|
193
|
+
* structure (the component's members plus the headers), so the headers
|
|
194
|
+
* never leak into other operations sharing that component. A header whose
|
|
195
|
+
* member name a body member already uses is suffixed `Header`
|
|
196
|
+
* (`Location` → `locationHeader` next to ARM's `location` region).
|
|
197
|
+
*/
|
|
198
|
+
readonly responseHeaders?: readonly string[];
|
|
181
199
|
/**
|
|
182
200
|
* Azure-style fixed `api-version`: drops `api-version` query params and
|
|
183
201
|
* stamps {@link API_VERSION_TRAIT} on every operation.
|
|
@@ -781,7 +799,10 @@ const convertSchema = (
|
|
|
781
799
|
}
|
|
782
800
|
const members = buildMembers(ctx, flat.properties, flat.required, hint, depth + 1, dir);
|
|
783
801
|
return {
|
|
784
|
-
target: emit(
|
|
802
|
+
target: emit(
|
|
803
|
+
{ type: "structure", members, traits: structTraits(docTraits, flat.additionalProperties) },
|
|
804
|
+
hint,
|
|
805
|
+
),
|
|
785
806
|
nullable,
|
|
786
807
|
};
|
|
787
808
|
}
|
|
@@ -862,7 +883,14 @@ const convertSchema = (
|
|
|
862
883
|
const required = new Set<string>(Array.isArray(def.required) ? def.required : []);
|
|
863
884
|
const members = buildMembers(ctx, def.properties, required, hint, depth + 1, dir);
|
|
864
885
|
return {
|
|
865
|
-
target: emit(
|
|
886
|
+
target: emit(
|
|
887
|
+
{
|
|
888
|
+
type: "structure",
|
|
889
|
+
members,
|
|
890
|
+
traits: structTraits(docTraits, def.additionalProperties),
|
|
891
|
+
},
|
|
892
|
+
hint,
|
|
893
|
+
),
|
|
866
894
|
nullable,
|
|
867
895
|
};
|
|
868
896
|
}
|
|
@@ -911,6 +939,17 @@ const convertSchema = (
|
|
|
911
939
|
}
|
|
912
940
|
};
|
|
913
941
|
|
|
942
|
+
/**
|
|
943
|
+
* A structure's traits: its docs, plus the open-object marker when the spec
|
|
944
|
+
* explicitly allows keys beyond `properties` (`additionalProperties: true`
|
|
945
|
+
* or a schema). An absent `additionalProperties` stays closed: most specs
|
|
946
|
+
* omit it without meaning "any key".
|
|
947
|
+
*/
|
|
948
|
+
const structTraits = (docTraits: Record<string, unknown>, ap: unknown): Record<string, unknown> =>
|
|
949
|
+
ap !== undefined && ap !== false
|
|
950
|
+
? { ...docTraits, [ADDITIONAL_PROPERTIES_TRAIT]: {} }
|
|
951
|
+
: docTraits;
|
|
952
|
+
|
|
914
953
|
/** Whether a property is a sensitive string (x-sensitive or name pattern). */
|
|
915
954
|
const isSensitiveProperty = (ctx: Ctx, name: string, def: any): boolean => {
|
|
916
955
|
const r = deref(ctx, def);
|
|
@@ -1081,6 +1120,58 @@ const opDoc = (op: any): string | undefined => {
|
|
|
1081
1120
|
// Responses
|
|
1082
1121
|
// ============================================================================
|
|
1083
1122
|
|
|
1123
|
+
/**
|
|
1124
|
+
* The allowed headers any 2xx response declares, in status order; the first
|
|
1125
|
+
* declaration of a header (case-insensitively) wins. Swagger 2.0 headers are
|
|
1126
|
+
* schemas themselves; OpenAPI 3 headers carry a `schema`.
|
|
1127
|
+
*/
|
|
1128
|
+
const successHeaders = (
|
|
1129
|
+
ctx: Ctx,
|
|
1130
|
+
responses: any,
|
|
1131
|
+
allowed: ReadonlySet<string>,
|
|
1132
|
+
): Array<{ name: string; schema: any; description?: string }> => {
|
|
1133
|
+
const out: Array<{ name: string; schema: any; description?: string }> = [];
|
|
1134
|
+
const seen = new Set<string>();
|
|
1135
|
+
for (const code of Object.keys(responses ?? {}).sort()) {
|
|
1136
|
+
if (!/^2\d\d$/.test(code)) continue;
|
|
1137
|
+
const raw = responses[code];
|
|
1138
|
+
const resp = raw?.$ref ? resolvePointer(ctx.spec, raw.$ref) : raw;
|
|
1139
|
+
for (const [name, rawHeader] of Object.entries<any>(resp?.headers ?? {})) {
|
|
1140
|
+
const lower = name.toLowerCase();
|
|
1141
|
+
if (!allowed.has(lower) || seen.has(lower)) continue;
|
|
1142
|
+
seen.add(lower);
|
|
1143
|
+
const header = rawHeader?.$ref ? resolvePointer(ctx.spec, rawHeader.$ref) : rawHeader;
|
|
1144
|
+
if (!header || typeof header !== "object") continue;
|
|
1145
|
+
out.push({
|
|
1146
|
+
name,
|
|
1147
|
+
schema: ctx.version === "2.0" ? header : (header.schema ?? {}),
|
|
1148
|
+
...(typeof header.description === "string" ? { description: header.description } : {}),
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
return out;
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
/** How many times each shape id is the `target` of a member or op input/output. */
|
|
1156
|
+
const targetCounts = (shapes: Record<string, any>): Map<string, number> => {
|
|
1157
|
+
const counts = new Map<string, number>();
|
|
1158
|
+
const visit = (node: any): void => {
|
|
1159
|
+
if (node === null || typeof node !== "object") return;
|
|
1160
|
+
if (Array.isArray(node)) {
|
|
1161
|
+
for (const item of node) visit(item);
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
if (typeof node.target === "string") {
|
|
1165
|
+
counts.set(node.target, (counts.get(node.target) ?? 0) + 1);
|
|
1166
|
+
}
|
|
1167
|
+
for (const [key, value] of Object.entries(node)) {
|
|
1168
|
+
if (key !== "traits") visit(value);
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
for (const shape of Object.values(shapes)) visit(shape);
|
|
1172
|
+
return counts;
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1084
1175
|
/** First declared status wins; resolve response refs and preserve JSON or binary bodies. */
|
|
1085
1176
|
const successSchema = (
|
|
1086
1177
|
ctx: Ctx,
|
|
@@ -1306,6 +1397,14 @@ const convertOnce = (spec: unknown, options: OpenApiConvertOptions): SmithyModel
|
|
|
1306
1397
|
|
|
1307
1398
|
const usedErrors = new Map<string, number>(); // class name → first status
|
|
1308
1399
|
const serviceOps: Array<{ target: string }> = [];
|
|
1400
|
+
const componentHeaders: Array<{
|
|
1401
|
+
readonly opId: string;
|
|
1402
|
+
readonly opName: string;
|
|
1403
|
+
readonly members: Record<string, any>;
|
|
1404
|
+
}> = [];
|
|
1405
|
+
const allowedResponseHeaders = new Set(
|
|
1406
|
+
(options.responseHeaders ?? []).map((name) => name.toLowerCase()),
|
|
1407
|
+
);
|
|
1309
1408
|
|
|
1310
1409
|
for (const [rawPath, pathItem] of Object.entries(doc.paths ?? {})) {
|
|
1311
1410
|
if (!pathItem || typeof pathItem !== "object") continue;
|
|
@@ -1436,7 +1535,9 @@ const convertOnce = (spec: unknown, options: OpenApiConvertOptions): SmithyModel
|
|
|
1436
1535
|
bodySchema = bodyParam?.schema;
|
|
1437
1536
|
bodyRequired = bodyParam?.required === true;
|
|
1438
1537
|
} else if (op.requestBody) {
|
|
1439
|
-
|
|
1538
|
+
// A components/requestBodies entry can itself be a $ref to another
|
|
1539
|
+
// (1Password Events: AuditEventsRequest → CursorRequest).
|
|
1540
|
+
const rb = deref(ctx, op.requestBody);
|
|
1440
1541
|
bodyRequired = rb?.required === true;
|
|
1441
1542
|
const content = rb?.content ?? {};
|
|
1442
1543
|
if (content["application/json"]) {
|
|
@@ -1559,6 +1660,58 @@ const convertOnce = (spec: unknown, options: OpenApiConvertOptions): SmithyModel
|
|
|
1559
1660
|
}
|
|
1560
1661
|
}
|
|
1561
1662
|
|
|
1663
|
+
// ---- Response headers (opt-in) ----
|
|
1664
|
+
let pendingHeaders: Record<string, any> | undefined;
|
|
1665
|
+
if (allowedResponseHeaders.size > 0 && method !== "head") {
|
|
1666
|
+
const headers = successHeaders(ctx, op.responses, allowedResponseHeaders);
|
|
1667
|
+
const current = outputTarget === PRELUDE.Unit ? undefined : ctx.shapes[outputTarget];
|
|
1668
|
+
// A raw-root wrapper collapses to its payload, so it has nowhere to
|
|
1669
|
+
// carry headers.
|
|
1670
|
+
const rawRoot = Object.values<any>(current?.members ?? {}).some(
|
|
1671
|
+
(m) => m?.traits?.[RAW_RESPONSE_TRAIT] !== undefined,
|
|
1672
|
+
);
|
|
1673
|
+
if (
|
|
1674
|
+
headers.length > 0 &&
|
|
1675
|
+
(current === undefined || current.type === "structure") &&
|
|
1676
|
+
!rawRoot
|
|
1677
|
+
) {
|
|
1678
|
+
const taken = new Set(Object.keys(current?.members ?? {}));
|
|
1679
|
+
const members: Record<string, any> = {};
|
|
1680
|
+
for (const header of headers) {
|
|
1681
|
+
let name = headerMemberName(header.name);
|
|
1682
|
+
if (taken.has(name)) name = `${name}Header`;
|
|
1683
|
+
if (taken.has(name)) continue;
|
|
1684
|
+
taken.add(name);
|
|
1685
|
+
members[name] = {
|
|
1686
|
+
target: convertSchema(
|
|
1687
|
+
ctx,
|
|
1688
|
+
header.schema,
|
|
1689
|
+
`${opName}Response${pascal(header.name)}`,
|
|
1690
|
+
0,
|
|
1691
|
+
"out",
|
|
1692
|
+
).target,
|
|
1693
|
+
traits: {
|
|
1694
|
+
"smithy.api#httpHeader": header.name,
|
|
1695
|
+
...(header.description ? { "smithy.api#documentation": header.description } : {}),
|
|
1696
|
+
},
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
if (current === undefined) {
|
|
1700
|
+
outputTarget = addShape(ctx, `${opName}Response`, {
|
|
1701
|
+
type: "structure",
|
|
1702
|
+
members,
|
|
1703
|
+
traits: { "smithy.api#output": {} },
|
|
1704
|
+
});
|
|
1705
|
+
} else if (current.traits?.["smithy.api#output"] !== undefined) {
|
|
1706
|
+
current.members = { ...current.members, ...members };
|
|
1707
|
+
} else {
|
|
1708
|
+
// A named component: whether it can take the headers itself
|
|
1709
|
+
// depends on what else uses it, known once every op is converted.
|
|
1710
|
+
pendingHeaders = members;
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1562
1715
|
// ---- Errors ----
|
|
1563
1716
|
const errors: Array<{ target: string }> = [];
|
|
1564
1717
|
for (const status of Object.keys(op.responses ?? {})) {
|
|
@@ -1598,6 +1751,44 @@ const convertOnce = (spec: unknown, options: OpenApiConvertOptions): SmithyModel
|
|
|
1598
1751
|
traits,
|
|
1599
1752
|
});
|
|
1600
1753
|
serviceOps.push({ target: opId });
|
|
1754
|
+
if (pendingHeaders !== undefined) {
|
|
1755
|
+
componentHeaders.push({ opId, opName, members: pendingHeaders });
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
// ---- Response headers on named components ----
|
|
1761
|
+
// A component returned only by ops that declare headers takes them itself
|
|
1762
|
+
// (all optional) and keeps its name. A component that other shapes, or ops
|
|
1763
|
+
// without those headers, also use is copied into an op-specific output, so
|
|
1764
|
+
// the headers never leak into them.
|
|
1765
|
+
if (componentHeaders.length > 0) {
|
|
1766
|
+
const uses = targetCounts(ctx.shapes);
|
|
1767
|
+
const outputs = new Map<string, number>();
|
|
1768
|
+
for (const { opId } of componentHeaders) {
|
|
1769
|
+
const id: string = ctx.shapes[opId].output.target;
|
|
1770
|
+
outputs.set(id, (outputs.get(id) ?? 0) + 1);
|
|
1771
|
+
}
|
|
1772
|
+
for (const { opId, opName, members } of componentHeaders) {
|
|
1773
|
+
const opShape = ctx.shapes[opId];
|
|
1774
|
+
const componentId: string = opShape.output.target;
|
|
1775
|
+
const component = ctx.shapes[componentId];
|
|
1776
|
+
if (uses.get(componentId) === outputs.get(componentId)) {
|
|
1777
|
+
component.members = { ...component.members, ...members };
|
|
1778
|
+
} else {
|
|
1779
|
+
opShape.output.target = addShape(ctx, `${opName}Response`, {
|
|
1780
|
+
type: "structure",
|
|
1781
|
+
members: { ...component.members, ...members },
|
|
1782
|
+
traits: {
|
|
1783
|
+
...(component.traits?.["smithy.api#documentation"]
|
|
1784
|
+
? {
|
|
1785
|
+
"smithy.api#documentation": component.traits["smithy.api#documentation"],
|
|
1786
|
+
}
|
|
1787
|
+
: {}),
|
|
1788
|
+
"smithy.api#output": {},
|
|
1789
|
+
},
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1601
1792
|
}
|
|
1602
1793
|
}
|
|
1603
1794
|
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make schema consts module-private and drop the ones nothing uses
|
|
3
|
+
* (dev-time only).
|
|
4
|
+
*
|
|
5
|
+
* Every `export` costs memory in each process that imports the module: V8
|
|
6
|
+
* keeps a binding cell, a namespace accessor and the export's name string
|
|
7
|
+
* for it, about 280 bytes each. Stripe's service module exported 14,224
|
|
8
|
+
* names; exporting only its operations and errors cut its import heap from
|
|
9
|
+
* 6.6 MB to 2.7 MB. The types (`export interface` / `export type`) stay
|
|
10
|
+
* exported -- they cost nothing at runtime -- and an operation's schemas
|
|
11
|
+
* stay reachable as `op.input` / `op.output`.
|
|
12
|
+
*
|
|
13
|
+
* After un-exporting, a schema const that no operation, error class or
|
|
14
|
+
* other remaining code references is deleted, repeated to a fixpoint.
|
|
15
|
+
*/
|
|
16
|
+
import { parseAst } from "rolldown/parseAst";
|
|
17
|
+
|
|
18
|
+
type Node = { readonly type: string; readonly start: number; readonly end: number } & Record<
|
|
19
|
+
string,
|
|
20
|
+
unknown
|
|
21
|
+
>;
|
|
22
|
+
|
|
23
|
+
const isNode = (value: unknown): value is Node =>
|
|
24
|
+
value !== null && typeof value === "object" && typeof (value as Node).type === "string";
|
|
25
|
+
|
|
26
|
+
/** Value-position identifier names under `node` (type annotations, keys and member names excluded). */
|
|
27
|
+
export const valueRefs = (
|
|
28
|
+
node: unknown,
|
|
29
|
+
out: Set<string>,
|
|
30
|
+
parent?: Node,
|
|
31
|
+
parentKey?: string,
|
|
32
|
+
): Set<string> => {
|
|
33
|
+
if (Array.isArray(node)) {
|
|
34
|
+
for (const child of node) valueRefs(child, out, parent, parentKey);
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
if (!isNode(node)) return out;
|
|
38
|
+
if (node.type.startsWith("TS")) {
|
|
39
|
+
// Only the expression side of a cast or assertion is a value.
|
|
40
|
+
if (
|
|
41
|
+
node.type === "TSAsExpression" ||
|
|
42
|
+
node.type === "TSSatisfiesExpression" ||
|
|
43
|
+
node.type === "TSNonNullExpression"
|
|
44
|
+
)
|
|
45
|
+
valueRefs(node.expression, out, node, "expression");
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
if (node.type === "Identifier") {
|
|
49
|
+
const isKey =
|
|
50
|
+
parent?.type === "Property" && parentKey === "key" && !parent.computed && !parent.shorthand;
|
|
51
|
+
const isMember =
|
|
52
|
+
parent?.type === "MemberExpression" && parentKey === "property" && !parent.computed;
|
|
53
|
+
if (!isKey && !isMember) out.add(node.name as string);
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
for (const [key, value] of Object.entries(node)) {
|
|
57
|
+
if (
|
|
58
|
+
key === "type" ||
|
|
59
|
+
key === "start" ||
|
|
60
|
+
key === "end" ||
|
|
61
|
+
key === "typeAnnotation" ||
|
|
62
|
+
key === "typeArguments" ||
|
|
63
|
+
key === "typeParameters" ||
|
|
64
|
+
key === "returnType"
|
|
65
|
+
)
|
|
66
|
+
continue;
|
|
67
|
+
if (value !== null && typeof value === "object") valueRefs(value, out, node, key);
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const isOperation = (init: Node, code: string) =>
|
|
73
|
+
/\bAPI\.make(Paginated)?\(/.test(code.slice(init.start, init.end));
|
|
74
|
+
|
|
75
|
+
export const privatizeSchemas = (
|
|
76
|
+
code: string,
|
|
77
|
+
filename = "generated.ts",
|
|
78
|
+
): { code: string; privatized: number; removed: number } => {
|
|
79
|
+
const program = parseAst(code, { sourceType: "module", lang: "ts" }, filename);
|
|
80
|
+
interface Decl {
|
|
81
|
+
name: string;
|
|
82
|
+
stmt: Node;
|
|
83
|
+
exportStart: number;
|
|
84
|
+
refs: Set<string>;
|
|
85
|
+
}
|
|
86
|
+
const schemaDecls = new Map<string, Decl>();
|
|
87
|
+
const roots = new Set<string>();
|
|
88
|
+
|
|
89
|
+
// Operation names, so an operation alias (`export const listObjects =
|
|
90
|
+
// listBucketObjects`) stays an exported operation and is not taken for a schema.
|
|
91
|
+
const operations = new Set<string>();
|
|
92
|
+
for (const raw of program.body as unknown as Node[]) {
|
|
93
|
+
if (raw.type !== "ExportNamedDeclaration" || !isNode(raw.declaration)) continue;
|
|
94
|
+
const stmt = raw.declaration as Node;
|
|
95
|
+
if (stmt.type !== "VariableDeclaration") continue;
|
|
96
|
+
for (const d of stmt.declarations as Node[]) {
|
|
97
|
+
const id = d.id as Node;
|
|
98
|
+
if (id.type === "Identifier" && isNode(d.init) && isOperation(d.init, code))
|
|
99
|
+
operations.add(id.name as string);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const isOperationAlias = (init: Node) =>
|
|
103
|
+
init.type === "Identifier" && operations.has(init.name as string);
|
|
104
|
+
|
|
105
|
+
for (const raw of program.body as unknown as Node[]) {
|
|
106
|
+
const exported = raw.type === "ExportNamedDeclaration" && isNode(raw.declaration);
|
|
107
|
+
const stmt = exported ? (raw.declaration as Node) : raw;
|
|
108
|
+
if (
|
|
109
|
+
exported &&
|
|
110
|
+
stmt.type === "VariableDeclaration" &&
|
|
111
|
+
(stmt.declarations as Node[]).length === 1
|
|
112
|
+
) {
|
|
113
|
+
const d = (stmt.declarations as Node[])[0]!;
|
|
114
|
+
const id = d.id as Node;
|
|
115
|
+
if (
|
|
116
|
+
id.type === "Identifier" &&
|
|
117
|
+
isNode(d.init) &&
|
|
118
|
+
!isOperation(d.init, code) &&
|
|
119
|
+
!isOperationAlias(d.init)
|
|
120
|
+
) {
|
|
121
|
+
schemaDecls.set(id.name as string, {
|
|
122
|
+
name: id.name as string,
|
|
123
|
+
stmt: raw,
|
|
124
|
+
exportStart: raw.start,
|
|
125
|
+
refs: valueRefs(d.init, new Set()),
|
|
126
|
+
});
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Everything else (operations, classes, imports, plain statements) keeps what it references alive.
|
|
131
|
+
if (
|
|
132
|
+
stmt.type === "ImportDeclaration" ||
|
|
133
|
+
stmt.type === "TSInterfaceDeclaration" ||
|
|
134
|
+
stmt.type === "TSTypeAliasDeclaration"
|
|
135
|
+
)
|
|
136
|
+
continue;
|
|
137
|
+
if (raw.type === "ExportNamedDeclaration" && !isNode(raw.declaration)) {
|
|
138
|
+
// `export { A, B }` / `export type { ... }`
|
|
139
|
+
if (raw.exportKind !== "type")
|
|
140
|
+
for (const s of raw.specifiers as Node[])
|
|
141
|
+
roots.add(((s.local as Node).name as string) ?? "");
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
for (const r of valueRefs(stmt, new Set())) roots.add(r);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Reachability from the roots through schema references.
|
|
148
|
+
const live = new Set<string>();
|
|
149
|
+
const stack = [...roots].filter((n) => schemaDecls.has(n));
|
|
150
|
+
while (stack.length) {
|
|
151
|
+
const n = stack.pop()!;
|
|
152
|
+
if (live.has(n)) continue;
|
|
153
|
+
live.add(n);
|
|
154
|
+
for (const r of schemaDecls.get(n)!.refs) if (schemaDecls.has(r) && !live.has(r)) stack.push(r);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Rewrite back to front: drop dead consts (with their leading doc comment), un-export live ones.
|
|
158
|
+
const decls = [...schemaDecls.values()].sort((a, b) => b.stmt.start - a.stmt.start);
|
|
159
|
+
let out = code;
|
|
160
|
+
let removed = 0;
|
|
161
|
+
for (const d of decls) {
|
|
162
|
+
if (live.has(d.name)) {
|
|
163
|
+
out = out.slice(0, d.stmt.start) + out.slice(d.stmt.start).replace(/^export\s+/, "");
|
|
164
|
+
} else {
|
|
165
|
+
let start = d.stmt.start;
|
|
166
|
+
const before = out.slice(0, start);
|
|
167
|
+
const doc = /\/\*\*(?:(?!\*\/)[\s\S])*\*\/\s*$/.exec(before);
|
|
168
|
+
if (doc) start = doc.index;
|
|
169
|
+
let end = d.stmt.end;
|
|
170
|
+
while (out[end] === "\n") end++;
|
|
171
|
+
out = out.slice(0, start) + out.slice(end);
|
|
172
|
+
removed++;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return { code: out, privatized: live.size, removed };
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* `import * as X` whose namespace is used only in type positions becomes
|
|
180
|
+
* `import type * as X`. The generator's `oxlint --fix` otherwise deletes it
|
|
181
|
+
* as unused once the schema consts that used it as a value are gone, and the
|
|
182
|
+
* types that still name it stop compiling.
|
|
183
|
+
*/
|
|
184
|
+
export const typeOnlyNamespaceImports = (code: string, filename = "generated.ts"): string => {
|
|
185
|
+
const program = parseAst(code, { sourceType: "module", lang: "ts" }, filename);
|
|
186
|
+
const body = program.body as unknown as Node[];
|
|
187
|
+
const used = new Set<string>();
|
|
188
|
+
for (const st of body) if (st.type !== "ImportDeclaration") valueRefs(st, used);
|
|
189
|
+
let out = code;
|
|
190
|
+
for (const st of [...body].reverse()) {
|
|
191
|
+
if (st.type !== "ImportDeclaration" || st.importKind === "type") continue;
|
|
192
|
+
const specs = st.specifiers as Node[];
|
|
193
|
+
if (specs.length !== 1 || specs[0]!.type !== "ImportNamespaceSpecifier") continue;
|
|
194
|
+
const name = (specs[0]!.local as Node).name as string;
|
|
195
|
+
if (used.has(name)) continue;
|
|
196
|
+
const text = code.slice(st.start, st.end).replace(/^import \*/, "import type *");
|
|
197
|
+
out = out.slice(0, st.start) + text + out.slice(st.end);
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep `/*@__PURE__*/` annotation for generated modules (dev-time only).
|
|
3
|
+
*
|
|
4
|
+
* A PURE marker lets a bundler drop a call whose result is unused — but the
|
|
5
|
+
* call's ARGUMENTS are still evaluated, and an unannotated call among them
|
|
6
|
+
* counts as a side effect. So
|
|
7
|
+
*
|
|
8
|
+
* export const TagList = /*@__PURE__*/ S.Array(Tag.pipe(T.XmlName("item")));
|
|
9
|
+
*
|
|
10
|
+
* keeps `Tag` (and everything `Tag` references) alive in every bundle that
|
|
11
|
+
* imports the module, even when nothing uses `TagList`. In EC2 that chain
|
|
12
|
+
* retained 1,695 schemas — 62 KB gzip — for a program calling one
|
|
13
|
+
* operation.
|
|
14
|
+
*
|
|
15
|
+
* {@link annotateNestedCalls} marks every call and `new` inside a top-level
|
|
16
|
+
* initializer (and class `extends` clause), skipping function bodies: code
|
|
17
|
+
* in a thunk only runs when called, so it never pins anything at import.
|
|
18
|
+
* One marker per start position covers a whole method chain
|
|
19
|
+
* (`X.pipe(a).annotate(b)`).
|
|
20
|
+
*/
|
|
21
|
+
import { parseAst } from "rolldown/parseAst";
|
|
22
|
+
|
|
23
|
+
const MARKER = "/*@__PURE__*/ ";
|
|
24
|
+
const ALREADY_MARKED = /\/\*\s*[@#]__PURE__\s*\*\/\s*$/;
|
|
25
|
+
|
|
26
|
+
type Node = { readonly type: string; readonly start: number; readonly end: number } & Record<
|
|
27
|
+
string,
|
|
28
|
+
unknown
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
const isNode = (value: unknown): value is Node =>
|
|
32
|
+
value !== null && typeof value === "object" && typeof (value as Node).type === "string";
|
|
33
|
+
|
|
34
|
+
/** Call/new positions in an initializer expression, outside function bodies. */
|
|
35
|
+
const collectCalls = (node: unknown, out: Set<number>): void => {
|
|
36
|
+
if (Array.isArray(node)) {
|
|
37
|
+
for (const child of node) collectCalls(child, out);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!isNode(node)) return;
|
|
41
|
+
switch (node.type) {
|
|
42
|
+
case "ArrowFunctionExpression":
|
|
43
|
+
case "FunctionExpression":
|
|
44
|
+
case "ClassBody":
|
|
45
|
+
return;
|
|
46
|
+
case "TSAsExpression":
|
|
47
|
+
case "TSSatisfiesExpression":
|
|
48
|
+
case "TSNonNullExpression":
|
|
49
|
+
collectCalls(node.expression, out);
|
|
50
|
+
return;
|
|
51
|
+
case "CallExpression": {
|
|
52
|
+
const callee = node.callee as Node;
|
|
53
|
+
// An IIFE runs its body at import; leave it alone.
|
|
54
|
+
if (callee.type !== "ArrowFunctionExpression" && callee.type !== "FunctionExpression") {
|
|
55
|
+
out.add(callee.start);
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case "NewExpression":
|
|
60
|
+
out.add(node.start);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
for (const [key, value] of Object.entries(node)) {
|
|
64
|
+
if (key === "type" || key === "start" || key === "end") continue;
|
|
65
|
+
if (value !== null && typeof value === "object") collectCalls(value, out);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns `code` with a PURE marker before every unmarked call in a
|
|
71
|
+
* top-level `const`/`let`/`var` initializer or class `extends` clause.
|
|
72
|
+
*/
|
|
73
|
+
export const annotateNestedCalls = (code: string, filename = "generated.ts"): string => {
|
|
74
|
+
const program = parseAst(code, { sourceType: "module", lang: "ts" }, filename);
|
|
75
|
+
const positions = new Set<number>();
|
|
76
|
+
for (let statement of program.body as unknown as Node[]) {
|
|
77
|
+
if (statement.type === "ExportNamedDeclaration" && isNode(statement.declaration)) {
|
|
78
|
+
statement = statement.declaration;
|
|
79
|
+
}
|
|
80
|
+
if (statement.type === "VariableDeclaration") {
|
|
81
|
+
for (const declaration of statement.declarations as Node[]) {
|
|
82
|
+
collectCalls(declaration.init, positions);
|
|
83
|
+
}
|
|
84
|
+
} else if (statement.type === "ClassDeclaration") {
|
|
85
|
+
collectCalls(statement.superClass, positions);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
let out = code;
|
|
89
|
+
for (const position of [...positions].sort((a, b) => b - a)) {
|
|
90
|
+
if (ALREADY_MARKED.test(out.slice(Math.max(0, position - 32), position))) continue;
|
|
91
|
+
out = `${out.slice(0, position)}${MARKER}${out.slice(position)}`;
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
};
|