@azure-tools/typespec-ts 0.33.0 → 0.34.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/CHANGELOG.md +37 -0
- package/dist/src/framework/declaration.js.map +1 -1
- package/dist/src/framework/dependency.d.ts +25 -0
- package/dist/src/framework/dependency.d.ts.map +1 -1
- package/dist/src/framework/hooks/binder.d.ts +1 -1
- package/dist/src/framework/hooks/binder.d.ts.map +1 -1
- package/dist/src/framework/hooks/binder.js +16 -12
- package/dist/src/framework/hooks/binder.js.map +1 -1
- package/dist/src/framework/hooks/sdkTypes.d.ts +4 -2
- package/dist/src/framework/hooks/sdkTypes.d.ts.map +1 -1
- package/dist/src/framework/hooks/sdkTypes.js +43 -8
- package/dist/src/framework/hooks/sdkTypes.js.map +1 -1
- package/dist/src/framework/refkey.js +1 -1
- package/dist/src/framework/refkey.js.map +1 -1
- package/dist/src/framework/sample.js +1 -1
- package/dist/src/framework/sample.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +81 -24
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +37 -3
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +26 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts +2 -2
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +25 -61
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.js +0 -7
- package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts +7 -3
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +58 -38
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts +18 -0
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +95 -42
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +3 -4
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +24 -45
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildProjectFiles.d.ts.map +1 -1
- package/dist/src/modular/buildProjectFiles.js +3 -1
- package/dist/src/modular/buildProjectFiles.js.map +1 -1
- package/dist/src/modular/buildRestorePoller.js +1 -1
- package/dist/src/modular/buildRestorePoller.js.map +1 -1
- package/dist/src/modular/buildRootIndex.d.ts +5 -0
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +62 -17
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts +1 -1
- package/dist/src/modular/buildSubpathIndex.d.ts.map +1 -1
- package/dist/src/modular/buildSubpathIndex.js +11 -10
- package/dist/src/modular/buildSubpathIndex.js.map +1 -1
- package/dist/src/modular/emitModels.d.ts +13 -28
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +435 -240
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/emitModelsOptions.d.ts +26 -0
- package/dist/src/modular/emitModelsOptions.d.ts.map +1 -0
- package/dist/src/modular/emitModelsOptions.js +106 -0
- package/dist/src/modular/emitModelsOptions.js.map +1 -0
- package/dist/src/modular/emitSamples.d.ts +7 -0
- package/dist/src/modular/emitSamples.d.ts.map +1 -0
- package/dist/src/modular/emitSamples.js +354 -0
- package/dist/src/modular/emitSamples.js.map +1 -0
- package/dist/src/modular/external-dependencies.d.ts +7 -0
- package/dist/src/modular/external-dependencies.d.ts.map +1 -1
- package/dist/src/modular/external-dependencies.js +58 -1
- package/dist/src/modular/external-dependencies.js.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/classicalOperationHelpers.js +2 -2
- package/dist/src/modular/helpers/classicalOperationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.d.ts +13 -6
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +117 -48
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.d.ts +3 -2
- package/dist/src/modular/helpers/namingHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.js +3 -0
- package/dist/src/modular/helpers/namingHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +9 -11
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +255 -408
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts +12 -0
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +30 -6
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +2 -1
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildDeserializerFunction.d.ts +5 -0
- package/dist/src/modular/serialization/buildDeserializerFunction.d.ts.map +1 -0
- package/dist/src/modular/serialization/buildDeserializerFunction.js +327 -0
- package/dist/src/modular/serialization/buildDeserializerFunction.js.map +1 -0
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts +4 -3
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.js +285 -102
- package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
- package/dist/src/modular/serialization/serializeUtils.d.ts +15 -0
- package/dist/src/modular/serialization/serializeUtils.d.ts.map +1 -0
- package/dist/src/modular/serialization/serializeUtils.js +102 -0
- package/dist/src/modular/serialization/serializeUtils.js.map +1 -0
- package/dist/src/modular/type-expressions/get-credential-expression.d.ts +3 -0
- package/dist/src/modular/type-expressions/get-credential-expression.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/get-credential-expression.js +17 -0
- package/dist/src/modular/type-expressions/get-credential-expression.js.map +1 -0
- package/dist/src/modular/type-expressions/get-enum-expression.d.ts +6 -0
- package/dist/src/modular/type-expressions/get-enum-expression.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/get-enum-expression.js +18 -0
- package/dist/src/modular/type-expressions/get-enum-expression.js.map +1 -0
- package/dist/src/modular/type-expressions/get-model-expression.d.ts +9 -0
- package/dist/src/modular/type-expressions/get-model-expression.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/get-model-expression.js +42 -0
- package/dist/src/modular/type-expressions/get-model-expression.js.map +1 -0
- package/dist/src/modular/type-expressions/get-type-expression.d.ts +8 -0
- package/dist/src/modular/type-expressions/get-type-expression.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/get-type-expression.js +94 -0
- package/dist/src/modular/type-expressions/get-type-expression.js.map +1 -0
- package/dist/src/modular/type-expressions/get-union-expression.d.ts +5 -0
- package/dist/src/modular/type-expressions/get-union-expression.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/get-union-expression.js +13 -0
- package/dist/src/modular/type-expressions/get-union-expression.js.map +1 -0
- package/dist/src/modular/type-expressions/utils.d.ts +5 -0
- package/dist/src/modular/type-expressions/utils.d.ts.map +1 -0
- package/dist/src/modular/type-expressions/utils.js +9 -0
- package/dist/src/modular/type-expressions/utils.js.map +1 -0
- package/dist/src/transform/transform.js +1 -1
- package/dist/src/transform/transform.js.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.js +1 -1
- package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
- package/dist/src/transform/transformParameters.js +1 -1
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js +3 -3
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/utils/clientUtils.d.ts.map +1 -1
- package/dist/src/utils/clientUtils.js +1 -4
- package/dist/src/utils/clientUtils.js.map +1 -1
- package/dist/src/utils/credentialUtils.d.ts +5 -0
- package/dist/src/utils/credentialUtils.d.ts.map +1 -1
- package/dist/src/utils/credentialUtils.js +36 -4
- package/dist/src/utils/credentialUtils.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +28 -43
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +26 -26
- package/src/framework/declaration.ts +0 -1
- package/src/framework/dependency.ts +25 -0
- package/src/framework/hooks/binder.ts +19 -14
- package/src/framework/hooks/sdkTypes.ts +53 -13
- package/src/framework/refkey.ts +1 -1
- package/src/framework/sample.ts +1 -1
- package/src/index.ts +96 -25
- package/src/lib.ts +26 -3
- package/src/modular/buildClassicalClient.ts +30 -97
- package/src/modular/buildClassicalOperationGroups.ts +0 -14
- package/src/modular/buildClientContext.ts +90 -50
- package/src/modular/buildCodeModel.ts +118 -47
- package/src/modular/buildOperations.ts +41 -76
- package/src/modular/buildProjectFiles.ts +4 -2
- package/src/modular/buildRestorePoller.ts +1 -1
- package/src/modular/buildRootIndex.ts +75 -35
- package/src/modular/buildSubpathIndex.ts +13 -11
- package/src/modular/emitModels.ts +588 -326
- package/src/modular/emitModelsOptions.ts +161 -0
- package/src/modular/emitSamples.ts +481 -0
- package/src/modular/external-dependencies.ts +59 -1
- package/src/modular/helpers/classicalOperationHelpers.ts +6 -2
- package/src/modular/helpers/clientHelpers.ts +182 -76
- package/src/modular/helpers/namingHelpers.ts +14 -2
- package/src/modular/helpers/operationHelpers.ts +356 -638
- package/src/modular/helpers/typeHelpers.ts +38 -6
- package/src/modular/modularCodeModel.ts +3 -0
- package/src/modular/serialization/buildDeserializerFunction.ts +492 -0
- package/src/modular/serialization/buildSerializerFunction.ts +434 -141
- package/src/modular/serialization/serializeUtils.ts +143 -0
- package/src/modular/type-expressions/get-credential-expression.ts +18 -0
- package/src/modular/type-expressions/get-enum-expression.ts +28 -0
- package/src/modular/type-expressions/get-model-expression.ts +63 -0
- package/src/modular/type-expressions/get-type-expression.ts +111 -0
- package/src/modular/type-expressions/get-union-expression.ts +20 -0
- package/src/modular/type-expressions/utils.ts +15 -0
- package/src/transform/transform.ts +2 -2
- package/src/transform/transformApiVersionInfo.ts +2 -2
- package/src/transform/transformParameters.ts +1 -1
- package/src/transform/transformSchemas.ts +9 -8
- package/src/utils/clientUtils.ts +2 -12
- package/src/utils/credentialUtils.ts +43 -3
- package/src/utils/modelUtils.ts +32 -41
- package/static/static-helpers/serialization/serializers.ts +60 -0
- package/dist/src/modular/buildSerializeUtils.d.ts +0 -14
- package/dist/src/modular/buildSerializeUtils.d.ts.map +0 -1
- package/dist/src/modular/buildSerializeUtils.js +0 -534
- package/dist/src/modular/buildSerializeUtils.js.map +0 -1
- package/src/modular/buildSerializeUtils.ts +0 -749
|
@@ -1,102 +1,55 @@
|
|
|
1
|
+
import { StructureKind } from "ts-morph";
|
|
2
|
+
import { UsageFlags } from "@azure-tools/typespec-client-generator-core";
|
|
1
3
|
import { toCamelCase, toPascalCase } from "../../utils/casingUtils.js";
|
|
2
4
|
import { getRequestModelMapping } from "../helpers/operationHelpers.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export function buildModelSerializer(type, runtimeImports) {
|
|
12
|
-
const modelTcgcType = getTcgcType(type);
|
|
13
|
-
if (modelTcgcType.usage !== undefined &&
|
|
14
|
-
(modelTcgcType.usage & UsageFlags.Input) !== UsageFlags.Input) {
|
|
5
|
+
import { getType } from "../buildCodeModel.js";
|
|
6
|
+
import { normalizeModelName } from "../emitModels.js";
|
|
7
|
+
import { NameType } from "@azure-tools/rlc-common";
|
|
8
|
+
import { isAzureCoreErrorType } from "../../utils/modelUtils.js";
|
|
9
|
+
import { isDiscriminatedUnion, isSupportedSerializeType } from "./serializeUtils.js";
|
|
10
|
+
export function buildModelSerializer(context, type, skipDiscriminatedUnion = false, nameOnly = false) {
|
|
11
|
+
// const modelTcgcType = getTcgcType(type) as SdkModelType;
|
|
12
|
+
if (!isSupportedSerializeType(type)) {
|
|
15
13
|
return undefined;
|
|
16
14
|
}
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!isDiscriminatedUnion(type) &&
|
|
23
|
-
type.type === "combined" &&
|
|
24
|
-
type.discriminator) {
|
|
25
|
-
return buildPolymorphicSerializer(type);
|
|
26
|
-
}
|
|
27
|
-
if (isDiscriminatedUnion(type)) {
|
|
28
|
-
const discriminatedTgcType = getTcgcType(type);
|
|
29
|
-
const cases = [];
|
|
30
|
-
const baseSerializerName = `${toCamelCase(discriminatedTgcType.name)}Serializer`;
|
|
31
|
-
for (const key in discriminatedTgcType.discriminatedSubtypes) {
|
|
32
|
-
const subType = discriminatedTgcType.discriminatedSubtypes[key];
|
|
33
|
-
const discriminatedValue = subType.discriminatorValue;
|
|
34
|
-
const union = subType.discriminatedSubtypes ? "Union" : "";
|
|
35
|
-
const subTypeName = `${toPascalCase(subType.name)}${union}`;
|
|
36
|
-
const subtypeSerializerName = toCamelCase(`${subTypeName}Serializer`);
|
|
37
|
-
cases.push(`
|
|
38
|
-
case "${discriminatedValue}":
|
|
39
|
-
return ${subtypeSerializerName}(item as ${subTypeName});
|
|
40
|
-
`);
|
|
15
|
+
if (type.kind === "model" || type.kind === "union" || type.kind === "enum") {
|
|
16
|
+
if (!type.usage ||
|
|
17
|
+
(type.usage !== undefined &&
|
|
18
|
+
(type.usage & UsageFlags.Input) !== UsageFlags.Input)) {
|
|
19
|
+
return undefined;
|
|
41
20
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
default:
|
|
47
|
-
return ${baseSerializerName}(item);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
`);
|
|
51
|
-
serializerName = baseSerializerName;
|
|
52
|
-
}
|
|
53
|
-
if (type.type === "model" || type.type === "dict") {
|
|
54
|
-
const nullabilityPrefix = "";
|
|
55
|
-
// getPropertySerializationPrefix({
|
|
56
|
-
// clientName: "item",
|
|
57
|
-
// type
|
|
58
|
-
// });
|
|
59
|
-
// This is only handling the compatibility mode, will need to update when we handle additionalProperties property.
|
|
60
|
-
const additionalPropertiesSpread = hasAdditionalProperties(type.tcgcType)
|
|
61
|
-
? "...item,"
|
|
62
|
-
: "";
|
|
63
|
-
const { propertiesStr, directAssignment } = getRequestModelMapping(type, "item", runtimeImports);
|
|
64
|
-
const propertiesSerialization = propertiesStr.filter((p) => p.trim());
|
|
65
|
-
// don't emit a serializer if there is nothing to serialize
|
|
66
|
-
if (propertiesSerialization.length || additionalPropertiesSpread) {
|
|
67
|
-
const spreadSerialized = directAssignment ? "..." : "";
|
|
68
|
-
const fnBody = `{
|
|
69
|
-
${additionalPropertiesSpread}
|
|
70
|
-
${nullabilityPrefix} ${spreadSerialized} ${propertiesSerialization.join(",\n")}
|
|
71
|
-
}`;
|
|
72
|
-
output.push(`
|
|
73
|
-
export function ${serializerName}(item: ${toPascalCase(type.name)}): Record<string, unknown> {
|
|
74
|
-
return ${fnBody}
|
|
75
|
-
}
|
|
76
|
-
`);
|
|
21
|
+
if (!type.name) {
|
|
22
|
+
// TODO: https://github.com/Azure/typespec-azure/issues/1713 and https://github.com/microsoft/typespec/issues/4815
|
|
23
|
+
// throw new Error(`NYI Serialization of anonymous types`);
|
|
24
|
+
return undefined;
|
|
77
25
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
export function ${serializerName}(item: ${toPascalCase(type.name)}) {
|
|
81
|
-
return item as any;
|
|
82
|
-
}
|
|
83
|
-
`);
|
|
26
|
+
if (isAzureCoreErrorType(context.program, type.__raw)) {
|
|
27
|
+
return undefined;
|
|
84
28
|
}
|
|
85
29
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
30
|
+
if (!isDiscriminatedUnion(type) &&
|
|
31
|
+
type.kind === "model" &&
|
|
32
|
+
type.discriminatorProperty) {
|
|
33
|
+
return buildPolymorphicSerializer(context, type, nameOnly);
|
|
90
34
|
}
|
|
91
|
-
|
|
35
|
+
if (isDiscriminatedUnion(type) && !skipDiscriminatedUnion) {
|
|
36
|
+
return buildDiscriminatedUnionSerializer(context, type, nameOnly);
|
|
37
|
+
}
|
|
38
|
+
switch (type.kind) {
|
|
39
|
+
case "model":
|
|
40
|
+
return buildModelTypeSerializer(context, type, {
|
|
41
|
+
nameOnly,
|
|
42
|
+
skipDiscriminatedUnionSuffix: skipDiscriminatedUnion
|
|
43
|
+
});
|
|
44
|
+
case "union": // for non-discriminated union, we just return whatever we get
|
|
45
|
+
return buildUnionSerializer(context, type, nameOnly);
|
|
46
|
+
case "dict":
|
|
47
|
+
return buildDictTypeSerializer(context, type, nameOnly);
|
|
48
|
+
case "array":
|
|
49
|
+
return buildArrayTypeSerializer(context, type, nameOnly);
|
|
50
|
+
default:
|
|
51
|
+
return undefined;
|
|
92
52
|
}
|
|
93
|
-
return output.join("\n");
|
|
94
|
-
}
|
|
95
|
-
function isDiscriminatedUnion(type) {
|
|
96
|
-
const { tcgcType } = type;
|
|
97
|
-
return Boolean((tcgcType === null || tcgcType === void 0 ? void 0 : tcgcType.kind) === "model" &&
|
|
98
|
-
tcgcType.discriminatorProperty &&
|
|
99
|
-
tcgcType.discriminatedSubtypes);
|
|
100
53
|
}
|
|
101
54
|
function hasAdditionalProperties(type) {
|
|
102
55
|
if (!type || !("additionalProperties" in type)) {
|
|
@@ -110,33 +63,263 @@ function hasAdditionalProperties(type) {
|
|
|
110
63
|
}
|
|
111
64
|
return false;
|
|
112
65
|
}
|
|
113
|
-
function buildPolymorphicSerializer(type) {
|
|
114
|
-
|
|
115
|
-
|
|
66
|
+
function buildPolymorphicSerializer(context, type, nameOnly = false) {
|
|
67
|
+
if (!type.name) {
|
|
68
|
+
throw new Error(`NYI Serialization of anonymous types`);
|
|
69
|
+
}
|
|
70
|
+
const serializeFunctionName = `${normalizeModelName(context, type, NameType.Operation)}Serializer`;
|
|
71
|
+
if (nameOnly) {
|
|
72
|
+
return serializeFunctionName;
|
|
73
|
+
}
|
|
74
|
+
const serializerFunction = {
|
|
75
|
+
kind: StructureKind.Function,
|
|
76
|
+
name: serializeFunctionName,
|
|
77
|
+
isExported: true,
|
|
78
|
+
parameters: [
|
|
79
|
+
{
|
|
80
|
+
name: "item",
|
|
81
|
+
type: normalizeModelName(context, type)
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
returnType: "any",
|
|
85
|
+
statements: []
|
|
86
|
+
};
|
|
87
|
+
if (!type.discriminatorProperty) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const statements = [];
|
|
91
|
+
const subTypes = type.discriminatedSubtypes;
|
|
92
|
+
if (!subTypes) {
|
|
116
93
|
return;
|
|
117
94
|
}
|
|
118
|
-
const output = [];
|
|
119
|
-
const subTypes = (_a = type.types) !== null && _a !== void 0 ? _a : [];
|
|
120
95
|
const cases = [];
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
96
|
+
Object.keys(subTypes).forEach((discriminatedValue) => {
|
|
97
|
+
const subType = subTypes[discriminatedValue];
|
|
98
|
+
if (!(subType === null || subType === void 0 ? void 0 : subType.usage) ||
|
|
99
|
+
((subType === null || subType === void 0 ? void 0 : subType.usage) !== undefined &&
|
|
100
|
+
(subType.usage & UsageFlags.Input) !== UsageFlags.Input)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const union = (subType === null || subType === void 0 ? void 0 : subType.discriminatedSubtypes) ? "Union" : "";
|
|
104
|
+
if (!subType || (subType === null || subType === void 0 ? void 0 : subType.name)) {
|
|
105
|
+
throw new Error(`NYI Serialization of anonymous types`);
|
|
106
|
+
}
|
|
124
107
|
const subTypeName = `${toPascalCase(subType.name)}${union}`;
|
|
125
108
|
const subtypeSerializerName = toCamelCase(`${subTypeName}Serializer`);
|
|
126
109
|
cases.push(`
|
|
127
110
|
case "${discriminatedValue}":
|
|
128
111
|
return ${subtypeSerializerName}(item as ${subTypeName});
|
|
129
112
|
`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
switch (item.${type.discriminator}) {
|
|
113
|
+
});
|
|
114
|
+
statements.push(`
|
|
115
|
+
switch (item.${type.discriminatorProperty.name}) {
|
|
134
116
|
${cases.join("\n")}
|
|
135
117
|
default:
|
|
136
118
|
return item;
|
|
137
119
|
}
|
|
120
|
+
`);
|
|
121
|
+
serializerFunction.statements = statements.join("\n");
|
|
122
|
+
return serializerFunction;
|
|
123
|
+
}
|
|
124
|
+
function buildDiscriminatedUnionSerializer(context, type, nameOnly = false) {
|
|
125
|
+
var _a;
|
|
126
|
+
if (!type.name) {
|
|
127
|
+
throw new Error(`NYI Serialization of anonymous types`);
|
|
138
128
|
}
|
|
129
|
+
const cases = [];
|
|
130
|
+
const output = [];
|
|
131
|
+
const serializeFunctionName = `${normalizeModelName(context, type, NameType.Operation)}Serializer`;
|
|
132
|
+
if (nameOnly) {
|
|
133
|
+
return serializeFunctionName;
|
|
134
|
+
}
|
|
135
|
+
const baseSerializerName = `${normalizeModelName(context, type, NameType.Operation, true)}Serializer`;
|
|
136
|
+
for (const key in type.discriminatedSubtypes) {
|
|
137
|
+
const subType = type.discriminatedSubtypes[key];
|
|
138
|
+
if (!subType.usage ||
|
|
139
|
+
(subType.usage !== undefined &&
|
|
140
|
+
(subType.usage & UsageFlags.Input) !== UsageFlags.Input)) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const discriminatedValue = subType.discriminatorValue;
|
|
144
|
+
const union = subType.discriminatedSubtypes ? "Union" : "";
|
|
145
|
+
const subTypeName = `${toPascalCase(subType.name)}${union}`;
|
|
146
|
+
const subtypeSerializerName = toCamelCase(`${subTypeName}Serializer`);
|
|
147
|
+
cases.push(`
|
|
148
|
+
case "${discriminatedValue}":
|
|
149
|
+
return ${subtypeSerializerName}(item as ${subTypeName});
|
|
139
150
|
`);
|
|
140
|
-
|
|
151
|
+
}
|
|
152
|
+
output.push(`
|
|
153
|
+
switch (item.${(_a = type.discriminatorProperty) === null || _a === void 0 ? void 0 : _a.name}) {
|
|
154
|
+
${cases.join("\n")}
|
|
155
|
+
default:
|
|
156
|
+
return ${baseSerializerName}(item);
|
|
157
|
+
}
|
|
158
|
+
`);
|
|
159
|
+
const serializerFunction = {
|
|
160
|
+
kind: StructureKind.Function,
|
|
161
|
+
name: serializeFunctionName,
|
|
162
|
+
isExported: true,
|
|
163
|
+
parameters: [
|
|
164
|
+
{
|
|
165
|
+
name: "item",
|
|
166
|
+
type: normalizeModelName(context, type)
|
|
167
|
+
}
|
|
168
|
+
],
|
|
169
|
+
returnType: "any",
|
|
170
|
+
statements: output.join("\n")
|
|
171
|
+
};
|
|
172
|
+
return serializerFunction;
|
|
173
|
+
}
|
|
174
|
+
function buildUnionSerializer(context, type, nameOnly = false) {
|
|
175
|
+
if (!type.name) {
|
|
176
|
+
throw new Error(`NYI Serialization of anonymous types`);
|
|
177
|
+
}
|
|
178
|
+
const serializerFunctionName = `${normalizeModelName(context, type, NameType.Operation)}Serializer`;
|
|
179
|
+
if (nameOnly) {
|
|
180
|
+
return serializerFunctionName;
|
|
181
|
+
}
|
|
182
|
+
const serializerFunction = {
|
|
183
|
+
kind: StructureKind.Function,
|
|
184
|
+
name: `${normalizeModelName(context, type, NameType.Operation)}Serializer`,
|
|
185
|
+
isExported: true,
|
|
186
|
+
parameters: [
|
|
187
|
+
{
|
|
188
|
+
name: "item",
|
|
189
|
+
type: normalizeModelName(context, type)
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
returnType: "any",
|
|
193
|
+
statements: ["return item;"]
|
|
194
|
+
};
|
|
195
|
+
return serializerFunction;
|
|
196
|
+
}
|
|
197
|
+
function buildModelTypeSerializer(context, type, options = {
|
|
198
|
+
nameOnly: false,
|
|
199
|
+
skipDiscriminatedUnionSuffix: false
|
|
200
|
+
}) {
|
|
201
|
+
if (!type.name) {
|
|
202
|
+
throw new Error(`NYI Deserialization of anonymous types`);
|
|
203
|
+
}
|
|
204
|
+
const serializerFunctionName = `${normalizeModelName(context, type, NameType.Operation, options.skipDiscriminatedUnionSuffix)}Serializer`;
|
|
205
|
+
if (options.nameOnly) {
|
|
206
|
+
return serializerFunctionName;
|
|
207
|
+
}
|
|
208
|
+
const serializerFunction = {
|
|
209
|
+
kind: StructureKind.Function,
|
|
210
|
+
name: serializerFunctionName,
|
|
211
|
+
isExported: true,
|
|
212
|
+
parameters: [
|
|
213
|
+
{
|
|
214
|
+
name: "item",
|
|
215
|
+
type: normalizeModelName(context, type, NameType.Interface, options.skipDiscriminatedUnionSuffix)
|
|
216
|
+
}
|
|
217
|
+
],
|
|
218
|
+
returnType: "any",
|
|
219
|
+
statements: ["return item;"]
|
|
220
|
+
};
|
|
221
|
+
// This is only handling the compatibility mode, will need to update when we handle additionalProperties property.
|
|
222
|
+
const additionalPropertiesSpread = hasAdditionalProperties(type)
|
|
223
|
+
? "...item"
|
|
224
|
+
: "";
|
|
225
|
+
const { directAssignment, propertiesStr } = getRequestModelMapping(context, getType(context, type.__raw), "item");
|
|
226
|
+
if (additionalPropertiesSpread) {
|
|
227
|
+
propertiesStr.unshift(additionalPropertiesSpread);
|
|
228
|
+
}
|
|
229
|
+
const serializeContent = directAssignment === true
|
|
230
|
+
? propertiesStr.join(",")
|
|
231
|
+
: `{${propertiesStr.join(",")}}`;
|
|
232
|
+
const output = [];
|
|
233
|
+
// don't emit a serializer if there is nothing to serialize
|
|
234
|
+
if (propertiesStr.length) {
|
|
235
|
+
output.push(`
|
|
236
|
+
return ${serializeContent}
|
|
237
|
+
`);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
output.push(`
|
|
241
|
+
return item;
|
|
242
|
+
`);
|
|
243
|
+
}
|
|
244
|
+
serializerFunction.statements = output;
|
|
245
|
+
return serializerFunction;
|
|
246
|
+
}
|
|
247
|
+
function buildDictTypeSerializer(context, type, nameOnly = false) {
|
|
248
|
+
var _a;
|
|
249
|
+
const valueSerializer = buildModelSerializer(context, type.valueType, false, true);
|
|
250
|
+
if (!valueSerializer) {
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
if (!isSupportedSerializeType(type.valueType)) {
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
if (typeof valueSerializer !== "string") {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
const valueTypeName = toCamelCase(valueSerializer ? valueSerializer.replace("Serializer", "") : "");
|
|
260
|
+
const serializerFunctionName = `${valueTypeName}RecordSerializer`;
|
|
261
|
+
if (nameOnly) {
|
|
262
|
+
return serializerFunctionName;
|
|
263
|
+
}
|
|
264
|
+
const serializerFunction = {
|
|
265
|
+
kind: StructureKind.Function,
|
|
266
|
+
name: serializerFunctionName,
|
|
267
|
+
isExported: true,
|
|
268
|
+
parameters: [
|
|
269
|
+
{
|
|
270
|
+
name: "item",
|
|
271
|
+
type: `Record<string, ${(_a = normalizeModelName(context, type.valueType)) !== null && _a !== void 0 ? _a : "any"}>`
|
|
272
|
+
}
|
|
273
|
+
],
|
|
274
|
+
returnType: "Record<string, any>",
|
|
275
|
+
statements: [
|
|
276
|
+
`
|
|
277
|
+
const result: Record<string, any> = {};
|
|
278
|
+
Object.keys(item).map((key) => {
|
|
279
|
+
result[key] = !item[key]? item[key]: ${valueSerializer}(item[key])
|
|
280
|
+
});
|
|
281
|
+
return result;
|
|
282
|
+
`
|
|
283
|
+
]
|
|
284
|
+
};
|
|
285
|
+
return serializerFunction;
|
|
286
|
+
}
|
|
287
|
+
function buildArrayTypeSerializer(context, type, nameOnly = false) {
|
|
288
|
+
var _a;
|
|
289
|
+
const valueSerializer = buildModelSerializer(context, type.valueType, false, true);
|
|
290
|
+
if (!valueSerializer) {
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
if (!isSupportedSerializeType(type.valueType)) {
|
|
294
|
+
return undefined;
|
|
295
|
+
}
|
|
296
|
+
if (typeof valueSerializer !== "string") {
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
const valueTypeName = toCamelCase(valueSerializer ? valueSerializer.replace("Serializer", "") : "");
|
|
300
|
+
const serializerFunctionName = `${valueTypeName}ArraySerializer`;
|
|
301
|
+
if (nameOnly) {
|
|
302
|
+
return serializerFunctionName;
|
|
303
|
+
}
|
|
304
|
+
const serializerFunction = {
|
|
305
|
+
kind: StructureKind.Function,
|
|
306
|
+
name: serializerFunctionName,
|
|
307
|
+
isExported: true,
|
|
308
|
+
parameters: [
|
|
309
|
+
{
|
|
310
|
+
name: "result",
|
|
311
|
+
type: `Array<${(_a = normalizeModelName(context, type.valueType)) !== null && _a !== void 0 ? _a : "any"}>`
|
|
312
|
+
}
|
|
313
|
+
],
|
|
314
|
+
returnType: "any[]",
|
|
315
|
+
statements: [
|
|
316
|
+
`
|
|
317
|
+
return result.map((item) => {
|
|
318
|
+
return ${valueSerializer}(item)
|
|
319
|
+
});
|
|
320
|
+
`
|
|
321
|
+
]
|
|
322
|
+
};
|
|
323
|
+
return serializerFunction;
|
|
141
324
|
}
|
|
142
325
|
//# sourceMappingURL=buildSerializerFunction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSerializerFunction.js","sourceRoot":"","sources":["../../../../src/modular/serialization/buildSerializerFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"buildSerializerFunction.js","sourceRoot":"","sources":["../../../../src/modular/serialization/buildSerializerFunction.ts"],"names":[],"mappings":"AAAA,OA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-0,0 +1,15 @@
|
|
|
1
|
+
import { Type } from "../modularCodeModel.js";
|
|
2
|
+
import { SdkModelType, SdkType } from "@azure-tools/typespec-client-generator-core";
|
|
3
|
+
export declare function isSupportedSerializeType(type: SdkType): boolean;
|
|
4
|
+
export declare function isSpecialUnionVariant(t: Type, variantStack?: Type[]): boolean;
|
|
5
|
+
export declare function isNormalUnion(t: Type): boolean;
|
|
6
|
+
export declare function isDiscriminatedUnion(type: SdkType): type is SdkModelType & {
|
|
7
|
+
discriminatorProperty: SdkType;
|
|
8
|
+
};
|
|
9
|
+
export declare function isSpecialHandledUnion(t: Type): boolean;
|
|
10
|
+
export declare function isPolymorphicUnion(t: Type): boolean;
|
|
11
|
+
export interface ModelSerializeOptions {
|
|
12
|
+
nameOnly: boolean;
|
|
13
|
+
skipDiscriminatedUnionSuffix: boolean;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=serializeUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializeUtils.d.ts","sourceRoot":"","sources":["../../../../src/modular/serialization/serializeUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9C,OAAO,EACL,YAAY,EACZ,OAAO,EACR,MAAM,6CAA6C,CAAC;AAErD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAO/D;AAeD,wBAAgB,qBAAqB,CACnC,CAAC,EAAE,IAAI,EACP,YAAY,GAAE,IAAI,EAAO,GACxB,OAAO,CAqDT;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAS9C;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,YAAY,GAAG;IAAE,qBAAqB,EAAE,OAAO,CAAA;CAAE,CAS3D;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAEtD;AAGD,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAqBnD;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,OAAO,CAAC;IAClB,4BAA4B,EAAE,OAAO,CAAC;CACvC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getAllAncestors } from "../helpers/operationHelpers.js";
|
|
2
|
+
export function isSupportedSerializeType(type) {
|
|
3
|
+
return (type.kind === "model" ||
|
|
4
|
+
type.kind === "dict" ||
|
|
5
|
+
type.kind === "array" ||
|
|
6
|
+
type.kind === "union");
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* In general, we have two kinds of basic special union variants.
|
|
11
|
+
* 1. datetime type
|
|
12
|
+
* 2. bytes type
|
|
13
|
+
* If we consider model type, we have the following three type.
|
|
14
|
+
* 3. model with property of datetime type.
|
|
15
|
+
* 4. model with property of binary array type.
|
|
16
|
+
* 5. model that has different property name between rest layer and modular layer.
|
|
17
|
+
* 6. nested model i.e. model with property that is a model with one of the above three conditions.
|
|
18
|
+
* If we consider array type, with all the above 6 types as the element types.
|
|
19
|
+
*/
|
|
20
|
+
const specialVariantMap = new Map();
|
|
21
|
+
export function isSpecialUnionVariant(t, variantStack = []) {
|
|
22
|
+
var _a, _b, _c, _d, _e;
|
|
23
|
+
if (variantStack.length <= 0) {
|
|
24
|
+
variantStack.push(t);
|
|
25
|
+
}
|
|
26
|
+
const ancestors = getAllAncestors(t);
|
|
27
|
+
if (specialVariantMap.has(t)) {
|
|
28
|
+
variantStack.pop();
|
|
29
|
+
return (_a = specialVariantMap.get(t)) !== null && _a !== void 0 ? _a : false;
|
|
30
|
+
}
|
|
31
|
+
if (t.type === "datetime" ||
|
|
32
|
+
t.type === "byte-array" ||
|
|
33
|
+
(t.type === "model" &&
|
|
34
|
+
((_c = (_b = t.properties) === null || _b === void 0 ? void 0 : _b.filter((p) => {
|
|
35
|
+
return !(variantStack.includes(p.type) ||
|
|
36
|
+
ancestors.includes(p.type) ||
|
|
37
|
+
(p.type.type === "list" &&
|
|
38
|
+
p.type.elementType &&
|
|
39
|
+
(variantStack.includes(p.type.elementType) ||
|
|
40
|
+
ancestors.includes(p.type.elementType))));
|
|
41
|
+
})) === null || _c === void 0 ? void 0 : _c.some((p) => p.clientName !== p.restApiName ||
|
|
42
|
+
isSpecialUnionVariant(p.type, [...variantStack, p.type])))) ||
|
|
43
|
+
isPolymorphicUnion(t) ||
|
|
44
|
+
(t.type === "list" &&
|
|
45
|
+
t.elementType &&
|
|
46
|
+
!variantStack.includes(t.elementType) &&
|
|
47
|
+
!ancestors.includes(t.elementType) &&
|
|
48
|
+
isSpecialUnionVariant(t.elementType, [...variantStack, t.elementType])) ||
|
|
49
|
+
(t.type === "combined" &&
|
|
50
|
+
((_e = (_d = t.types) === null || _d === void 0 ? void 0 : _d.filter((p) => {
|
|
51
|
+
return !(variantStack.includes(p) || ancestors.includes(p));
|
|
52
|
+
})) === null || _e === void 0 ? void 0 : _e.some((p) => {
|
|
53
|
+
return isSpecialUnionVariant(p, [...variantStack, p]);
|
|
54
|
+
}))) ||
|
|
55
|
+
(t.type === "enum" && !(t.isFixed || t.isNonExhaustive))) {
|
|
56
|
+
specialVariantMap.set(t, true);
|
|
57
|
+
variantStack.pop();
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
variantStack.pop();
|
|
61
|
+
specialVariantMap.set(t, false);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
export function isNormalUnion(t) {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
return (t.type === "combined" &&
|
|
67
|
+
!((_b = (_a = t.types) === null || _a === void 0 ? void 0 : _a.some((p) => {
|
|
68
|
+
return isSpecialUnionVariant(p);
|
|
69
|
+
})) !== null && _b !== void 0 ? _b : false));
|
|
70
|
+
}
|
|
71
|
+
export function isDiscriminatedUnion(type) {
|
|
72
|
+
if (!type) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return Boolean((type === null || type === void 0 ? void 0 : type.kind) === "model" &&
|
|
76
|
+
type.discriminatorProperty &&
|
|
77
|
+
type.discriminatedSubtypes);
|
|
78
|
+
}
|
|
79
|
+
export function isSpecialHandledUnion(t) {
|
|
80
|
+
return isDiscriminatedUnion(t.tcgcType) || isPolymorphicUnion(t);
|
|
81
|
+
}
|
|
82
|
+
const polymorphicUnionMap = new Map();
|
|
83
|
+
export function isPolymorphicUnion(t) {
|
|
84
|
+
var _a, _b, _c;
|
|
85
|
+
if (polymorphicUnionMap.has(t)) {
|
|
86
|
+
return (_a = polymorphicUnionMap.get(t)) !== null && _a !== void 0 ? _a : false;
|
|
87
|
+
}
|
|
88
|
+
const ancestors = getAllAncestors(t);
|
|
89
|
+
if (t.type === "model" &&
|
|
90
|
+
t.isPolymorphicBaseModel &&
|
|
91
|
+
((_c = (_b = t.types) === null || _b === void 0 ? void 0 : _b.filter((p) => {
|
|
92
|
+
return !ancestors.includes(p);
|
|
93
|
+
})) === null || _c === void 0 ? void 0 : _c.some((p) => {
|
|
94
|
+
return isSpecialUnionVariant(p);
|
|
95
|
+
}))) {
|
|
96
|
+
polymorphicUnionMap.set(t, true);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
polymorphicUnionMap.set(t, false);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=serializeUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializeUtils.js","sourceRoot":"","sources":["../../../../src/modular/serialization/serializeUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAMjE,MAAM,UAAU,wBAAwB,CAAC,IAAa;IACpD,OAAO,CACL,IAAI,CAAC,IAAI,KAAK,OAAO;QACrB,IAAI,CAAC,IAAI,KAAK,MAAM;QACpB,IAAI,CAAC,IAAI,KAAK,OAAO;QACrB,IAAI,CAAC,IAAI,KAAK,OAAO,CACtB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EAAE,EAAE;YACX,OAAO,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC,CAAC,CAAA,EACJ,CAAC;QACD,mBAAmB,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,mBAAmB,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-credential-expression.d.ts","sourceRoot":"","sources":["../../../../src/modular/type-expressions/get-credential-expression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AAIhF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAavE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolveReference } from "../../framework/reference.js";
|
|
2
|
+
import { useDependencies } from "../../framework/hooks/useDependencies.js";
|
|
3
|
+
export function getCredentialExpression(type) {
|
|
4
|
+
const dependencies = useDependencies();
|
|
5
|
+
switch (type.scheme.type) {
|
|
6
|
+
case "apiKey":
|
|
7
|
+
case "http":
|
|
8
|
+
return resolveReference(dependencies.KeyCredential);
|
|
9
|
+
case "oauth2":
|
|
10
|
+
case "openIdConnect":
|
|
11
|
+
return resolveReference(dependencies.TokenCredential);
|
|
12
|
+
default:
|
|
13
|
+
// TODO: Add diagnostics about unknown credential type
|
|
14
|
+
return "any";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=get-credential-expression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-credential-expression.js","sourceRoot":"","sources":["../../../../src/modular/type-expressions/get-credential-expression.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAE3E,MAAM,UAAU,uBAAuB,CAAC,IAAuB;IAC7D,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,QAAQ,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACzB,KAAK,QAAQ,CAAC;QACd,KAAK,MAAM;YACT,OAAO,gBAAgB,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;QACtD,KAAK,QAAQ,CAAC;QACd,KAAK,eAAe;YAClB,OAAO,gBAAgB,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;QACxD;YACE,sDAAsD;YACtD,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SdkEnumType } from "@azure-tools/typespec-client-generator-core";
|
|
2
|
+
import { EmitTypeOptions } from "./get-type-expression.js";
|
|
3
|
+
import { SdkContext } from "../../utils/interfaces.js";
|
|
4
|
+
export declare function getEnumExpression(context: SdkContext, type: SdkEnumType, options?: EmitTypeOptions): string;
|
|
5
|
+
export declare function isExtensibleEnum(context: SdkContext, type: SdkEnumType): boolean;
|
|
6
|
+
//# sourceMappingURL=get-enum-expression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-enum-expression.d.ts","sourceRoot":"","sources":["../../../../src/modular/type-expressions/get-enum-expression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAE1E,OAAO,EAAqB,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE,eAAoB,GAC5B,MAAM,CAQR;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,WAAW,GAChB,OAAO,CAIT"}
|