@azure-tools/typespec-go 0.1.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/LICENSE +21 -0
- package/README.md +16 -0
- package/dist/codegen.go/src/clientFactory.d.ts +3 -0
- package/dist/codegen.go/src/clientFactory.d.ts.map +1 -0
- package/dist/codegen.go/src/clientFactory.js +77 -0
- package/dist/codegen.go/src/clientFactory.js.map +1 -0
- package/dist/codegen.go/src/constants.d.ts +3 -0
- package/dist/codegen.go/src/constants.d.ts.map +1 -0
- package/dist/codegen.go/src/constants.js +59 -0
- package/dist/codegen.go/src/constants.js.map +1 -0
- package/dist/codegen.go/src/fake/factory.d.ts +3 -0
- package/dist/codegen.go/src/fake/factory.d.ts.map +1 -0
- package/dist/codegen.go/src/fake/factory.js +69 -0
- package/dist/codegen.go/src/fake/factory.js.map +1 -0
- package/dist/codegen.go/src/fake/internal.d.ts +14 -0
- package/dist/codegen.go/src/fake/internal.d.ts.map +1 -0
- package/dist/codegen.go/src/fake/internal.js +197 -0
- package/dist/codegen.go/src/fake/internal.js.map +1 -0
- package/dist/codegen.go/src/fake/servers.d.ts +14 -0
- package/dist/codegen.go/src/fake/servers.d.ts.map +1 -0
- package/dist/codegen.go/src/fake/servers.js +1255 -0
- package/dist/codegen.go/src/fake/servers.js.map +1 -0
- package/dist/codegen.go/src/gomod.d.ts +3 -0
- package/dist/codegen.go/src/gomod.d.ts.map +1 -0
- package/dist/codegen.go/src/gomod.js +55 -0
- package/dist/codegen.go/src/gomod.js.map +1 -0
- package/dist/codegen.go/src/helpers.d.ts +32 -0
- package/dist/codegen.go/src/helpers.d.ts.map +1 -0
- package/dist/codegen.go/src/helpers.js +586 -0
- package/dist/codegen.go/src/helpers.js.map +1 -0
- package/dist/codegen.go/src/imports.d.ts +11 -0
- package/dist/codegen.go/src/imports.d.ts.map +1 -0
- package/dist/codegen.go/src/imports.js +65 -0
- package/dist/codegen.go/src/imports.js.map +1 -0
- package/dist/codegen.go/src/interfaces.d.ts +3 -0
- package/dist/codegen.go/src/interfaces.d.ts.map +1 -0
- package/dist/codegen.go/src/interfaces.js +36 -0
- package/dist/codegen.go/src/interfaces.js.map +1 -0
- package/dist/codegen.go/src/models.d.ts +9 -0
- package/dist/codegen.go/src/models.d.ts.map +1 -0
- package/dist/codegen.go/src/models.js +849 -0
- package/dist/codegen.go/src/models.js.map +1 -0
- package/dist/codegen.go/src/operations.d.ts +9 -0
- package/dist/codegen.go/src/operations.d.ts.map +1 -0
- package/dist/codegen.go/src/operations.js +1337 -0
- package/dist/codegen.go/src/operations.js.map +1 -0
- package/dist/codegen.go/src/options.d.ts +3 -0
- package/dist/codegen.go/src/options.d.ts.map +1 -0
- package/dist/codegen.go/src/options.js +64 -0
- package/dist/codegen.go/src/options.js.map +1 -0
- package/dist/codegen.go/src/polymorphics.d.ts +3 -0
- package/dist/codegen.go/src/polymorphics.d.ts.map +1 -0
- package/dist/codegen.go/src/polymorphics.js +169 -0
- package/dist/codegen.go/src/polymorphics.js.map +1 -0
- package/dist/codegen.go/src/responses.d.ts +7 -0
- package/dist/codegen.go/src/responses.d.ts.map +1 -0
- package/dist/codegen.go/src/responses.js +167 -0
- package/dist/codegen.go/src/responses.js.map +1 -0
- package/dist/codegen.go/src/time.d.ts +8 -0
- package/dist/codegen.go/src/time.d.ts.map +1 -0
- package/dist/codegen.go/src/time.js +511 -0
- package/dist/codegen.go/src/time.js.map +1 -0
- package/dist/codemodel.go/src/client.d.ts +96 -0
- package/dist/codemodel.go/src/client.d.ts.map +1 -0
- package/dist/codemodel.go/src/client.js +114 -0
- package/dist/codemodel.go/src/client.js.map +1 -0
- package/dist/codemodel.go/src/index.d.ts +6 -0
- package/dist/codemodel.go/src/index.d.ts.map +1 -0
- package/dist/codemodel.go/src/index.js +10 -0
- package/dist/codemodel.go/src/index.js.map +1 -0
- package/dist/codemodel.go/src/package.d.ts +49 -0
- package/dist/codemodel.go/src/package.d.ts.map +1 -0
- package/dist/codemodel.go/src/package.js +86 -0
- package/dist/codemodel.go/src/package.js.map +1 -0
- package/dist/codemodel.go/src/param.d.ts +162 -0
- package/dist/codemodel.go/src/param.d.ts.map +1 -0
- package/dist/codemodel.go/src/param.js +189 -0
- package/dist/codemodel.go/src/param.js.map +1 -0
- package/dist/codemodel.go/src/result.d.ts +102 -0
- package/dist/codemodel.go/src/result.d.ts.map +1 -0
- package/dist/codemodel.go/src/result.js +119 -0
- package/dist/codemodel.go/src/result.js.map +1 -0
- package/dist/codemodel.go/src/type.d.ts +181 -0
- package/dist/codemodel.go/src/type.d.ts.map +1 -0
- package/dist/codemodel.go/src/type.js +242 -0
- package/dist/codemodel.go/src/type.js.map +1 -0
- package/dist/naming.go/src/mappings.d.ts +3 -0
- package/dist/naming.go/src/mappings.d.ts.map +1 -0
- package/dist/naming.go/src/mappings.js +128 -0
- package/dist/naming.go/src/mappings.js.map +1 -0
- package/dist/naming.go/src/naming.d.ts +10 -0
- package/dist/naming.go/src/naming.d.ts.map +1 -0
- package/dist/naming.go/src/naming.js +114 -0
- package/dist/naming.go/src/naming.js.map +1 -0
- package/dist/typespec-go/src/emitter.d.ts +5 -0
- package/dist/typespec-go/src/emitter.d.ts.map +1 -0
- package/dist/typespec-go/src/emitter.js +122 -0
- package/dist/typespec-go/src/emitter.js.map +1 -0
- package/dist/typespec-go/src/index.d.ts +3 -0
- package/dist/typespec-go/src/index.d.ts.map +1 -0
- package/dist/typespec-go/src/index.js +7 -0
- package/dist/typespec-go/src/index.js.map +1 -0
- package/dist/typespec-go/src/lib.d.ts +25 -0
- package/dist/typespec-go/src/lib.d.ts.map +1 -0
- package/dist/typespec-go/src/lib.js +36 -0
- package/dist/typespec-go/src/lib.js.map +1 -0
- package/dist/typespec-go/src/tcgcadapter/adapter.d.ts +5 -0
- package/dist/typespec-go/src/tcgcadapter/adapter.d.ts.map +1 -0
- package/dist/typespec-go/src/tcgcadapter/adapter.js +119 -0
- package/dist/typespec-go/src/tcgcadapter/adapter.js.map +1 -0
- package/dist/typespec-go/src/tcgcadapter/clients.d.ts +26 -0
- package/dist/typespec-go/src/tcgcadapter/clients.d.ts.map +1 -0
- package/dist/typespec-go/src/tcgcadapter/clients.js +621 -0
- package/dist/typespec-go/src/tcgcadapter/clients.js.map +1 -0
- package/dist/typespec-go/src/tcgcadapter/types.d.ts +29 -0
- package/dist/typespec-go/src/tcgcadapter/types.d.ts.map +1 -0
- package/dist/typespec-go/src/tcgcadapter/types.js +975 -0
- package/dist/typespec-go/src/tcgcadapter/types.js.map +1 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# TypeSpec Go Generator
|
|
2
|
+
|
|
3
|
+
The TypeSpec Go generator is intended to be used with the TypeSpec compiler.
|
|
4
|
+
|
|
5
|
+
# Contributing
|
|
6
|
+
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
|
7
|
+
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
|
8
|
+
the rights to use your contribution. For details, visit https://cla.microsoft.com.
|
|
9
|
+
|
|
10
|
+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
|
|
11
|
+
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
|
|
12
|
+
provided by the bot. You will only need to do this once across all repos using our CLA.
|
|
13
|
+
|
|
14
|
+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
15
|
+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
|
16
|
+
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientFactory.d.ts","sourceRoot":"","sources":["../../../../codegen.go/src/clientFactory.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAOtD,wBAAsB,qBAAqB,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CA4EpF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { values } from '@azure-tools/linq';
|
|
6
|
+
import { contentPreamble, formatCommentAsBulletItem, formatParameterTypeName, sortParametersByRequired } from './helpers.js';
|
|
7
|
+
import { ImportManager } from './imports.js';
|
|
8
|
+
// Creates the content for client_factory.go (ARM only)
|
|
9
|
+
export async function generateClientFactory(codeModel) {
|
|
10
|
+
// generate client factory only for ARM
|
|
11
|
+
if (codeModel.type !== 'azure-arm' || codeModel.clients.length === 0) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
let result = '';
|
|
15
|
+
// the list of packages to import
|
|
16
|
+
const imports = new ImportManager();
|
|
17
|
+
const allClientParams = new Array();
|
|
18
|
+
for (const clients of codeModel.clients) {
|
|
19
|
+
for (const clientParam of values(clients.parameters)) {
|
|
20
|
+
if (values(allClientParams).where(param => param.name === clientParam.name).any()) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
allClientParams.push(clientParam);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
allClientParams.sort(sortParametersByRequired);
|
|
27
|
+
// add factory type
|
|
28
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore');
|
|
29
|
+
result += '// ClientFactory is a client factory used to create any client in this module.\n';
|
|
30
|
+
result += '// Don\'t use this type directly, use NewClientFactory instead.\n';
|
|
31
|
+
result += 'type ClientFactory struct {\n';
|
|
32
|
+
for (const clientParam of values(allClientParams)) {
|
|
33
|
+
result += `\t${clientParam.name} ${formatParameterTypeName(clientParam)}\n`;
|
|
34
|
+
}
|
|
35
|
+
result += '\tinternal *arm.Client\n';
|
|
36
|
+
result += '}\n\n';
|
|
37
|
+
// add factory CTOR
|
|
38
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/arm');
|
|
39
|
+
result += '// NewClientFactory creates a new instance of ClientFactory with the specified values.\n';
|
|
40
|
+
result += '// The parameter values will be propagated to any client created from this factory.\n';
|
|
41
|
+
for (const clientParam of values(allClientParams)) {
|
|
42
|
+
result += `${formatCommentAsBulletItem(`${clientParam.name} - ${clientParam.description}`)}\n`;
|
|
43
|
+
}
|
|
44
|
+
result += `${formatCommentAsBulletItem('credential - used to authorize requests. Usually a credential from azidentity.')}\n`;
|
|
45
|
+
result += `${formatCommentAsBulletItem('options - pass nil to accept the default values.')}\n`;
|
|
46
|
+
result += `func NewClientFactory(${allClientParams.map(param => { return `${param.name} ${formatParameterTypeName(param)}`; }).join(', ')}${allClientParams.length > 0 ? ',' : ''} credential azcore.TokenCredential, options *arm.ClientOptions) (*ClientFactory, error) {\n`;
|
|
47
|
+
result += '\tinternal, err := arm.NewClient(moduleName, moduleVersion, credential, options)\n';
|
|
48
|
+
result += '\tif err != nil {\n';
|
|
49
|
+
result += '\t\treturn nil, err\n';
|
|
50
|
+
result += '\t}\n';
|
|
51
|
+
result += '\treturn &ClientFactory{\n';
|
|
52
|
+
for (const clientParam of values(allClientParams)) {
|
|
53
|
+
result += `\t\t${clientParam.name}: ${clientParam.name},\n`;
|
|
54
|
+
}
|
|
55
|
+
result += '\t\tinternal: internal,\n';
|
|
56
|
+
result += '\t}, nil\n';
|
|
57
|
+
result += '}\n\n';
|
|
58
|
+
// add new sub client method for all operation groups
|
|
59
|
+
for (const client of codeModel.clients) {
|
|
60
|
+
const ctorName = `New${client.name}`;
|
|
61
|
+
result += `// ${ctorName} creates a new instance of ${client.name}.\n`;
|
|
62
|
+
result += `func (c *ClientFactory) ${ctorName}() *${client.name} {\n`;
|
|
63
|
+
result += `\treturn &${client.name}{\n`;
|
|
64
|
+
// some clients (e.g. operations client) don't utilize the client params
|
|
65
|
+
if (client.parameters.length > 0) {
|
|
66
|
+
for (const clientParam of values(allClientParams)) {
|
|
67
|
+
result += `\t\t${clientParam.name}: c.${clientParam.name},\n`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
result += '\t\tinternal: c.internal,\n';
|
|
71
|
+
result += '\t}\n';
|
|
72
|
+
result += '}\n\n';
|
|
73
|
+
}
|
|
74
|
+
result = contentPreamble(codeModel) + imports.text() + result;
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=clientFactory.js.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I,KAAK,WAAW,CAAC,IAAI,KAAK,CAAC;KAC7D;IACD,MAAM,IAAI,2BAA2B,CAAC;IACtC,MAAM,IAAI,YAAY,CAAC;IACvB,MAAM,IAAI,OAAO,CAAC;IAElB,qDAAqD;IACrD,KAAK,MAAM,MAAM,IAAI,SAAS,CAAC,OAAO,EAAE;QACtC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACrC,MAAM,IAAI,MAAM,QAAQ,8BAA8B,MAAM,CAAC,IAAI,KAAK,CAAC;QACvE,MAAM,IAAI,2BAA2B,QAAQ,OAAO,MAAM,CAAC,IAAI,MAAM,CAAC;QACtE,MAAM,IAAI,aAAa,MAAM,CAAC,IAAI,KAAK,CAAC;QAExC,wEAAwE;QACxE,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;YAChC,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,eAAe,CAAC,EAAE;gBACjD,MAAM,IAAI,OAAO,WAAW,CAAC,IAAI,OAAO,WAAW,CAAC,IAAI,KAAK,CAAC;aAC/D;SACF;QAED,MAAM,IAAI,6BAA6B,CAAC;QACxC,MAAM,IAAI,OAAO,CAAC;QAClB,MAAM,IAAI,OAAO,CAAC;KACnB;IAED,MAAM,GAAG,eAAe,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC;IAC9D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../codegen.go/src/constants.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAGtD,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAiDhF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { comment } from '@azure-tools/codegen';
|
|
6
|
+
import { values } from '@azure-tools/linq';
|
|
7
|
+
import { commentLength, contentPreamble } from './helpers.js';
|
|
8
|
+
// Creates the content in constants.go
|
|
9
|
+
export async function generateConstants(codeModel) {
|
|
10
|
+
// lack of operation groups indicates model-only mode.
|
|
11
|
+
if (!codeModel.clients || (codeModel.constants.length === 0 && !codeModel.host && codeModel.type !== 'azure-arm')) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
let text = contentPreamble(codeModel);
|
|
15
|
+
if (codeModel.host) {
|
|
16
|
+
text += `const host = "${codeModel.host}"\n\n`;
|
|
17
|
+
}
|
|
18
|
+
// data-plane clients must manage their own constants for these values
|
|
19
|
+
if (codeModel.type === 'azure-arm') {
|
|
20
|
+
if (!codeModel.options.module) {
|
|
21
|
+
throw new Error('--module and --module-version are required parameters when --azure-arm is set');
|
|
22
|
+
}
|
|
23
|
+
text += 'const (\n';
|
|
24
|
+
// strip off any major version suffix
|
|
25
|
+
text += `\tmoduleName = "${codeModel.options.module.name.replace(/\/v\d+$/, '')}"\n`;
|
|
26
|
+
text += `\tmoduleVersion = "v${codeModel.options.module.version}"\n`;
|
|
27
|
+
text += ')\n\n';
|
|
28
|
+
}
|
|
29
|
+
for (const enm of values(codeModel.constants)) {
|
|
30
|
+
if (enm.description) {
|
|
31
|
+
text += `${comment(`${enm.name} - ${enm.description}`, '// ', undefined, commentLength)}\n`;
|
|
32
|
+
}
|
|
33
|
+
text += `type ${enm.name} ${enm.type}\n\n`;
|
|
34
|
+
const vals = new Array();
|
|
35
|
+
text += 'const (\n';
|
|
36
|
+
for (const val of values(enm.values)) {
|
|
37
|
+
if (val.description) {
|
|
38
|
+
text += `\t${comment(`${val.name} - ${val.description}`, '//', undefined, commentLength)}\n`;
|
|
39
|
+
}
|
|
40
|
+
let formatValue = `"${val.value}"`;
|
|
41
|
+
if (enm.type !== 'string') {
|
|
42
|
+
formatValue = `${val.value}`;
|
|
43
|
+
}
|
|
44
|
+
text += `\t${val.name} ${enm.name} = ${formatValue}\n`;
|
|
45
|
+
vals.push(val.name);
|
|
46
|
+
}
|
|
47
|
+
text += ')\n\n';
|
|
48
|
+
text += `// ${enm.valuesFuncName} returns the possible values for the ${enm.name} const type.\n`;
|
|
49
|
+
text += `func ${enm.valuesFuncName}() []${enm.name} {\n`;
|
|
50
|
+
text += `\treturn []${enm.name}{\t\n`;
|
|
51
|
+
for (const val of values(vals)) {
|
|
52
|
+
text += `\t\t${val},\n`;
|
|
53
|
+
}
|
|
54
|
+
text += '\t}\n';
|
|
55
|
+
text += '}\n\n';
|
|
56
|
+
}
|
|
57
|
+
return text;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../codegen.go/src/constants.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG9D,sCAAsC;AACtC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,SAAuB;IAC7D,sDAAsD;IACtD,IAAI,CAAC,SAAS,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,KAAK,WAAW,CAAC,EAAE;QACjH,OAAO,EAAE,CAAC;KACX;IACD,IAAI,IAAI,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IACtC,IAAI,SAAS,CAAC,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IAAI,GAAG,CAAC,KAAK,GAAG,CAAC;YACnC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;gBACzB,WAAW,GAAG,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;aAC9B;YACD,IAAI,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,MAAM,WAAW,IAAI,CAAC;YACvD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SACrB;QACD,IAAI,IAAI,OAAO,CAAC;QAChB,IAAI,IAAI,MAAM,GAAG,CAAC,cAAc,wCAAwC,GAAG,CAAC,IAAI,gBAAgB,CAAC;QACjG,IAAI,IAAI,QAAQ,GAAG,CAAC,cAAc,QAAQ,GAAG,CAAC,IAAI,MAAM,CAAC;QACzD,IAAI,IAAI,cAAc,GAAG,CAAC,IAAI,OAAO,CAAC;QACtC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE;YAC9B,IAAI,IAAI,OAAO,GAAG,KAAK,CAAC;SACzB;QACD,IAAI,IAAI,OAAO,CAAC;QAChB,IAAI,IAAI,OAAO,CAAC;KACjB;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../codegen.go/src/fake/factory.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAKzD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,GAAG,MAAM,CAmErE"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { getServerName } from './servers.js';
|
|
6
|
+
import { contentPreamble } from '../helpers.js';
|
|
7
|
+
import { ImportManager } from '../imports.js';
|
|
8
|
+
export function generateServerFactory(codeModel) {
|
|
9
|
+
// generate server factory only for ARM
|
|
10
|
+
if (codeModel.type !== 'azure-arm' || !codeModel.clients) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
const imports = new ImportManager();
|
|
14
|
+
imports.add('errors');
|
|
15
|
+
imports.add('fmt');
|
|
16
|
+
imports.add('net/http');
|
|
17
|
+
imports.add('strings');
|
|
18
|
+
imports.add('sync');
|
|
19
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime');
|
|
20
|
+
let text = contentPreamble(codeModel, 'fake');
|
|
21
|
+
text += imports.text();
|
|
22
|
+
text += `// ServerFactory is a fake server for instances of the ${codeModel.packageName}.ClientFactory type.\n`;
|
|
23
|
+
text += 'type ServerFactory struct {\n';
|
|
24
|
+
for (const client of codeModel.clients) {
|
|
25
|
+
const serverName = getServerName(client);
|
|
26
|
+
text += `\t// ${serverName} contains the fakes for client ${client.name}\n`;
|
|
27
|
+
text += `\t${serverName} ${serverName}\n\n`;
|
|
28
|
+
}
|
|
29
|
+
text += '}\n\n';
|
|
30
|
+
text += '// NewServerFactoryTransport creates a new instance of ServerFactoryTransport with the provided implementation.\n';
|
|
31
|
+
text += `// The returned ServerFactoryTransport instance is connected to an instance of ${codeModel.packageName}.ClientFactory via the\n`;
|
|
32
|
+
text += '// azcore.ClientOptions.Transporter field in the client\'s constructor parameters.\n';
|
|
33
|
+
text += 'func NewServerFactoryTransport(srv *ServerFactory) *ServerFactoryTransport {\n';
|
|
34
|
+
text += '\treturn &ServerFactoryTransport{\n\t\tsrv: srv,\n\t}\n}\n\n';
|
|
35
|
+
text += `// ServerFactoryTransport connects instances of ${codeModel.packageName}.ClientFactory to instances of ServerFactory.\n`;
|
|
36
|
+
text += '// Don\'t use this type directly, use NewServerFactoryTransport instead.\n';
|
|
37
|
+
text += 'type ServerFactoryTransport struct {\n';
|
|
38
|
+
text += '\tsrv *ServerFactory\n';
|
|
39
|
+
text += '\ttrMu sync.Mutex\n';
|
|
40
|
+
for (const client of codeModel.clients) {
|
|
41
|
+
const serverName = getServerName(client);
|
|
42
|
+
text += `\ttr${serverName} *${serverName}Transport\n`;
|
|
43
|
+
}
|
|
44
|
+
text += '}\n\n';
|
|
45
|
+
text += '// Do implements the policy.Transporter interface for ServerFactoryTransport.\n';
|
|
46
|
+
text += 'func (s *ServerFactoryTransport) Do(req *http.Request) (*http.Response, error) {\n';
|
|
47
|
+
text += '\trawMethod := req.Context().Value(runtime.CtxAPINameKey{})\n';
|
|
48
|
+
text += '\tmethod, ok := rawMethod.(string)\n';
|
|
49
|
+
text += '\tif !ok {\n\t\treturn nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")}\n\t}\n\n';
|
|
50
|
+
text += '\tclient := method[:strings.Index(method, ".")]\n';
|
|
51
|
+
text += '\tvar resp *http.Response\n\tvar err error\n\n';
|
|
52
|
+
text += '\tswitch client {\n';
|
|
53
|
+
for (const client of codeModel.clients) {
|
|
54
|
+
text += `\tcase "${client.name}":\n`;
|
|
55
|
+
const serverName = getServerName(client);
|
|
56
|
+
text += `\t\tinitServer(s, &s.tr${serverName}, func() *${serverName}Transport { return New${serverName}Transport(&s.srv.${serverName}) })\n`;
|
|
57
|
+
text += `\t\tresp, err = s.tr${serverName}.Do(req)\n`;
|
|
58
|
+
}
|
|
59
|
+
text += '\tdefault:\n\t\terr = fmt.Errorf("unhandled client %s", client)\n';
|
|
60
|
+
text += '\t}\n\n';
|
|
61
|
+
text += '\tif err != nil {\n\t\treturn nil, err\n\t}\n\n';
|
|
62
|
+
text += '\treturn resp, nil\n}\n\n';
|
|
63
|
+
text += 'func initServer[T any](s *ServerFactoryTransport, dst **T, src func() *T) {\n';
|
|
64
|
+
text += '\ts.trMu.Lock()\n';
|
|
65
|
+
text += '\tif *dst == nil {\n\t\t*dst = src()\n\t}\n';
|
|
66
|
+
text += '\ts.trMu.Unlock()\n}\n';
|
|
67
|
+
return text;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../codegen.go/src/fake/factory.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,UAAU,qBAAqB,CAAC,SAAuB;IAC3D,uCAAuC;IACvC,IAAI,SAAS,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;QACxD,OAAO,EAAE,CAAC;KACX;IAED,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC;IACpC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACvB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC;IAEpE,IAAI,IAAI,GAAG,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC9C,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAEvB,IAAI,IAAI,0DAA0D,SAAS,CAAC,WAAW,wBAAwB,CAAC;IAChH,IAAI,IAAI,+BAA+B,CAAC;IACxC,KAAK,MAAM,MAAM,IAAI,SAAS,CAAC,OAAO,EAAE;QACtC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,IAAI,QAAQ,UAAU,kCAAkC,MAAM,CAAC,IA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B,UAAU,YAAY,CAAC;KACvD;IACD,IAAI,IAAI,mEAAmE,CAAC;IAC5E,IAAI,IAAI,SAAS,CAAC;IAClB,IAAI,IAAI,iDAAiD,CAAC;IAC1D,IAAI,IAAI,2BAA2B,CAAC;IAEpC,IAAI,IAAI,+EAA+E,CAAC;IACxF,IAAI,IAAI,mBAAmB,CAAC;IAC5B,IAAI,IAAI,6CAA6C,CAAC;IACtD,IAAI,IAAI,wBAAwB,CAAC;IACjC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as go from '../../../codemodel.go/src/index.js';
|
|
2
|
+
export declare class RequiredHelpers {
|
|
3
|
+
getHeaderValue: boolean;
|
|
4
|
+
getOptional: boolean;
|
|
5
|
+
initServer: boolean;
|
|
6
|
+
parseOptional: boolean;
|
|
7
|
+
parseWithCast: boolean;
|
|
8
|
+
readRequestBody: boolean;
|
|
9
|
+
splitHelper: boolean;
|
|
10
|
+
tracker: boolean;
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
export declare function generateServerInternal(codeModel: go.CodeModel, requiredHelpers: RequiredHelpers): string;
|
|
14
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../../../codegen.go/src/fake/internal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAIzD,qBAAa,eAAe;IAC1B,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;;CAYlB;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,eAAe,EAAE,eAAe,GAAG,MAAM,CAkCxG"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { contentPreamble } from '../helpers.js';
|
|
6
|
+
import { ImportManager } from '../imports.js';
|
|
7
|
+
export class RequiredHelpers {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.getHeaderValue = false;
|
|
10
|
+
this.getOptional = false;
|
|
11
|
+
this.initServer = false;
|
|
12
|
+
this.parseOptional = false;
|
|
13
|
+
this.parseWithCast = false;
|
|
14
|
+
this.readRequestBody = false;
|
|
15
|
+
this.splitHelper = false;
|
|
16
|
+
this.tracker = false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function generateServerInternal(codeModel, requiredHelpers) {
|
|
20
|
+
if (codeModel.clients.length === 0) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
const text = contentPreamble(codeModel, 'fake');
|
|
24
|
+
const imports = new ImportManager();
|
|
25
|
+
let body = alwaysUsed;
|
|
26
|
+
if (requiredHelpers.getHeaderValue) {
|
|
27
|
+
body += emitGetHeaderValue(imports);
|
|
28
|
+
}
|
|
29
|
+
if (requiredHelpers.getOptional) {
|
|
30
|
+
body += emitGetOptional(imports);
|
|
31
|
+
}
|
|
32
|
+
if (requiredHelpers.initServer) {
|
|
33
|
+
body += emitInitServer(imports);
|
|
34
|
+
}
|
|
35
|
+
if (requiredHelpers.parseOptional) {
|
|
36
|
+
body += emitParseOptional();
|
|
37
|
+
}
|
|
38
|
+
if (requiredHelpers.parseWithCast) {
|
|
39
|
+
body += emitParseWithCast();
|
|
40
|
+
}
|
|
41
|
+
if (requiredHelpers.readRequestBody) {
|
|
42
|
+
body += emitReadRequestBody(imports);
|
|
43
|
+
}
|
|
44
|
+
if (requiredHelpers.splitHelper) {
|
|
45
|
+
body += emitSplitHelper(imports);
|
|
46
|
+
}
|
|
47
|
+
if (requiredHelpers.tracker) {
|
|
48
|
+
body += emitTracker(imports);
|
|
49
|
+
}
|
|
50
|
+
return text + imports.text() + body;
|
|
51
|
+
}
|
|
52
|
+
// contains helpers that are used in all servers
|
|
53
|
+
const alwaysUsed = `
|
|
54
|
+
type nonRetriableError struct {
|
|
55
|
+
error
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
func (nonRetriableError) NonRetriable() {
|
|
59
|
+
// marker method
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func contains[T comparable](s []T, v T) bool {
|
|
63
|
+
for _, vv := range s {
|
|
64
|
+
if vv == v {
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
function emitGetOptional(imports) {
|
|
72
|
+
imports.add('reflect');
|
|
73
|
+
return `
|
|
74
|
+
func getOptional[T any](v T) *T {
|
|
75
|
+
if reflect.ValueOf(v).IsZero() {
|
|
76
|
+
return nil
|
|
77
|
+
}
|
|
78
|
+
return &v
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
function emitGetHeaderValue(imports) {
|
|
83
|
+
imports.add('net/http');
|
|
84
|
+
return `
|
|
85
|
+
func getHeaderValue(h http.Header, k string) string {
|
|
86
|
+
v := h[k]
|
|
87
|
+
if len(v) == 0 {
|
|
88
|
+
return ""
|
|
89
|
+
}
|
|
90
|
+
return v[0]
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
function emitInitServer(imports) {
|
|
95
|
+
imports.add('sync');
|
|
96
|
+
return `
|
|
97
|
+
func initServer[T any](mu *sync.Mutex, dst **T, src func() *T) {
|
|
98
|
+
mu.Lock()
|
|
99
|
+
if *dst == nil {
|
|
100
|
+
*dst = src()
|
|
101
|
+
}
|
|
102
|
+
mu.Unlock()
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
function emitParseOptional() {
|
|
107
|
+
return `
|
|
108
|
+
func parseOptional[T any](v string, parse func(v string) (T, error)) (*T, error) {
|
|
109
|
+
if v == "" {
|
|
110
|
+
return nil, nil
|
|
111
|
+
}
|
|
112
|
+
t, err := parse(v)
|
|
113
|
+
if err != nil {
|
|
114
|
+
return nil, err
|
|
115
|
+
}
|
|
116
|
+
return &t, err
|
|
117
|
+
}
|
|
118
|
+
`;
|
|
119
|
+
}
|
|
120
|
+
function emitParseWithCast() {
|
|
121
|
+
return `
|
|
122
|
+
func parseWithCast[T any](v string, parse func(v string) (T, error)) (T, error) {
|
|
123
|
+
t, err := parse(v)
|
|
124
|
+
if err != nil {
|
|
125
|
+
return *new(T), err
|
|
126
|
+
}
|
|
127
|
+
return t, err
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
}
|
|
131
|
+
function emitReadRequestBody(imports) {
|
|
132
|
+
imports.add('net/http');
|
|
133
|
+
imports.add('io');
|
|
134
|
+
return `
|
|
135
|
+
func readRequestBody(req *http.Request) ([]byte, error) {
|
|
136
|
+
if req.Body == nil {
|
|
137
|
+
return nil, nil
|
|
138
|
+
}
|
|
139
|
+
body, err := io.ReadAll(req.Body)
|
|
140
|
+
if err != nil {
|
|
141
|
+
return nil, err
|
|
142
|
+
}
|
|
143
|
+
req.Body.Close()
|
|
144
|
+
return body, nil
|
|
145
|
+
}
|
|
146
|
+
`;
|
|
147
|
+
}
|
|
148
|
+
function emitSplitHelper(imports) {
|
|
149
|
+
imports.add('strings');
|
|
150
|
+
return `
|
|
151
|
+
func splitHelper(s, sep string) []string {
|
|
152
|
+
if s == "" {
|
|
153
|
+
return nil
|
|
154
|
+
}
|
|
155
|
+
return strings.Split(s, sep)
|
|
156
|
+
}
|
|
157
|
+
`;
|
|
158
|
+
}
|
|
159
|
+
function emitTracker(imports) {
|
|
160
|
+
imports.add('net/http');
|
|
161
|
+
imports.add('sync');
|
|
162
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server');
|
|
163
|
+
return `
|
|
164
|
+
func newTracker[T any]() *tracker[T] {
|
|
165
|
+
return &tracker[T]{
|
|
166
|
+
items: map[string]*T{},
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
type tracker[T any] struct {
|
|
171
|
+
items map[string]*T
|
|
172
|
+
mu sync.Mutex
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
func (p *tracker[T]) get(req *http.Request) *T {
|
|
176
|
+
p.mu.Lock()
|
|
177
|
+
defer p.mu.Unlock()
|
|
178
|
+
if item, ok := p.items[server.SanitizePagerPollerPath(req.URL.Path)]; ok {
|
|
179
|
+
return item
|
|
180
|
+
}
|
|
181
|
+
return nil
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
func (p *tracker[T]) add(req *http.Request, item *T) {
|
|
185
|
+
p.mu.Lock()
|
|
186
|
+
defer p.mu.Unlock()
|
|
187
|
+
p.items[server.SanitizePagerPollerPath(req.URL.Path)] = item
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
func (p *tracker[T]) remove(req *http.Request) {
|
|
191
|
+
p.mu.Lock()
|
|
192
|
+
defer p.mu.Unlock()
|
|
193
|
+
delete(p.items, server.SanitizePagerPollerPath(req.URL.Path))
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../../../codegen.go/src/fake/internal.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,OAAO,eAAe;IAU1B;QACE,IAAI,CA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;IACxE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCR,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as go from '../../../codemodel.go/src/index.js';
|
|
2
|
+
export declare class ServerContent {
|
|
3
|
+
readonly servers: Array<OperationGroupContent>;
|
|
4
|
+
readonly internals: string;
|
|
5
|
+
constructor(servers: Array<OperationGroupContent>, internals: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class OperationGroupContent {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly content: string;
|
|
10
|
+
constructor(name: string, content: string);
|
|
11
|
+
}
|
|
12
|
+
export declare function getServerName(client: go.Client): string;
|
|
13
|
+
export declare function generateServers(codeModel: go.CodeModel): Promise<ServerContent>;
|
|
14
|
+
//# sourceMappingURL=servers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"servers.d.ts","sourceRoot":"","sources":["../../../../../codegen.go/src/fake/servers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,oCAAoC,CAAC;AASzD,qBAAa,aAAa;IACxB,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC/C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,OAAO,EAAE,KAAK,CAAC,qBAAqB,CAAC,EAAE,SAAS,EAAE,MAAM;CAIrE;AAGD,qBAAa,qBAAqB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI1C;AAKD,wBAAgB,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,GAAG,MAAM,CAGvD;AAMD,wBAAsB,eAAe,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,CA2KrF"}
|