@azure-tools/typespec-ts 0.30.1 → 0.31.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 +19 -0
- package/dist/src/contextManager.d.ts +4 -0
- package/dist/src/contextManager.d.ts.map +1 -1
- package/dist/src/contextManager.js.map +1 -1
- package/dist/src/framework/declaration.d.ts +9 -0
- package/dist/src/framework/declaration.d.ts.map +1 -0
- package/dist/src/framework/declaration.js +28 -0
- package/dist/src/framework/declaration.js.map +1 -0
- package/dist/src/framework/hooks/binder.d.ts +25 -0
- package/dist/src/framework/hooks/binder.d.ts.map +1 -0
- package/dist/src/framework/hooks/binder.js +168 -0
- package/dist/src/framework/hooks/binder.js.map +1 -0
- package/dist/src/framework/hooks/sdkTypes.d.ts +12 -0
- package/dist/src/framework/hooks/sdkTypes.d.ts.map +1 -0
- package/dist/src/framework/hooks/sdkTypes.js +67 -0
- package/dist/src/framework/hooks/sdkTypes.js.map +1 -0
- package/dist/src/framework/reference.d.ts +2 -0
- package/dist/src/framework/reference.d.ts.map +1 -0
- package/dist/src/framework/reference.js +8 -0
- package/dist/src/framework/reference.js.map +1 -0
- package/dist/src/framework/refkey.d.ts +7 -0
- package/dist/src/framework/refkey.d.ts.map +1 -0
- package/dist/src/framework/refkey.js +22 -0
- package/dist/src/framework/refkey.js.map +1 -0
- package/dist/src/framework/sample.d.ts +2 -0
- package/dist/src/framework/sample.d.ts.map +1 -0
- package/dist/src/framework/sample.js +71 -0
- package/dist/src/framework/sample.js.map +1 -0
- package/dist/src/framework/utils/tsmorph-helpers.d.ts +2 -0
- package/dist/src/framework/utils/tsmorph-helpers.d.ts.map +1 -0
- package/dist/src/framework/utils/tsmorph-helpers.js +2 -0
- package/dist/src/framework/utils/tsmorph-helpers.js.map +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +10 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +6 -0
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +6 -5
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +8 -4
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +22 -11
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +1 -2
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +3 -9
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildRootIndex.js +1 -1
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/buildSerializeUtils.d.ts.map +1 -1
- package/dist/src/modular/buildSerializeUtils.js +2 -1
- package/dist/src/modular/buildSerializeUtils.js.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.d.ts +4 -0
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +15 -1
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.d.ts +1 -0
- package/dist/src/modular/helpers/namingHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/namingHelpers.js +3 -1
- package/dist/src/modular/helpers/namingHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +60 -40
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +6 -1
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/modularCodeModel.d.ts +2 -0
- package/dist/src/modular/modularCodeModel.d.ts.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.d.ts.map +1 -1
- package/dist/src/transform/transformApiVersionInfo.js +3 -5
- package/dist/src/transform/transformApiVersionInfo.js.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.d.ts.map +1 -1
- package/dist/src/transform/transformHelperFunctionDetails.js +7 -10
- package/dist/src/transform/transformHelperFunctionDetails.js.map +1 -1
- package/dist/src/transform/transformParameters.d.ts.map +1 -1
- package/dist/src/transform/transformParameters.js +5 -7
- package/dist/src/transform/transformParameters.js.map +1 -1
- package/dist/src/transform/transformPaths.d.ts.map +1 -1
- package/dist/src/transform/transformPaths.js +4 -6
- package/dist/src/transform/transformPaths.js.map +1 -1
- package/dist/src/transform/transformResponses.d.ts.map +1 -1
- package/dist/src/transform/transformResponses.js +70 -16
- package/dist/src/transform/transformResponses.js.map +1 -1
- package/dist/src/transform/transformSchemas.d.ts.map +1 -1
- package/dist/src/transform/transformSchemas.js +5 -6
- package/dist/src/transform/transformSchemas.js.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.d.ts.map +1 -1
- package/dist/src/transform/transformTelemetryInfo.js +3 -6
- package/dist/src/transform/transformTelemetryInfo.js.map +1 -1
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +5 -6
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts +3 -3
- package/dist/src/utils/modelUtils.d.ts.map +1 -1
- package/dist/src/utils/modelUtils.js +42 -24
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts +2 -2
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +5 -7
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -23
- package/src/contextManager.ts +4 -0
- package/src/framework/declaration.ts +100 -0
- package/src/framework/hooks/binder.ts +259 -0
- package/src/framework/hooks/sdkTypes.ts +101 -0
- package/src/framework/reference.ts +9 -0
- package/src/framework/refkey.ts +28 -0
- package/src/framework/sample.ts +92 -0
- package/src/framework/utils/tsmorph-helpers.ts +0 -0
- package/src/index.ts +8 -10
- package/src/lib.ts +6 -0
- package/src/modular/buildClassicalClient.ts +11 -4
- package/src/modular/buildClientContext.ts +11 -5
- package/src/modular/buildCodeModel.ts +25 -21
- package/src/modular/buildOperations.ts +13 -41
- package/src/modular/buildRootIndex.ts +1 -1
- package/src/modular/buildSerializeUtils.ts +2 -1
- package/src/modular/helpers/clientHelpers.ts +25 -1
- package/src/modular/helpers/namingHelpers.ts +4 -1
- package/src/modular/helpers/operationHelpers.ts +86 -45
- package/src/modular/helpers/typeHelpers.ts +6 -1
- package/src/modular/modularCodeModel.ts +2 -0
- package/src/transform/transformApiVersionInfo.ts +3 -6
- package/src/transform/transformHelperFunctionDetails.ts +9 -9
- package/src/transform/transformParameters.ts +5 -6
- package/src/transform/transformPaths.ts +5 -9
- package/src/transform/transformResponses.ts +92 -19
- package/src/transform/transformSchemas.ts +6 -5
- package/src/transform/transformTelemetryInfo.ts +3 -5
- package/src/transform/transfromRLCOptions.ts +5 -10
- package/src/utils/modelUtils.ts +49 -39
- package/src/utils/operationUtil.ts +6 -12
- package/dist/src/modular/serialization/collectionUtils.d.ts +0 -3
- package/dist/src/modular/serialization/collectionUtils.d.ts.map +0 -1
- package/dist/src/modular/serialization/collectionUtils.js +0 -17
- package/dist/src/modular/serialization/collectionUtils.js.map +0 -1
- package/dist/src/modular/serialization/index.d.ts +0 -5
- package/dist/src/modular/serialization/index.d.ts.map +0 -1
- package/dist/src/modular/serialization/index.js +0 -155
- package/dist/src/modular/serialization/index.js.map +0 -1
- package/dist/src/modular/serialization/operationHelpers.d.ts +0 -37
- package/dist/src/modular/serialization/operationHelpers.d.ts.map +0 -1
- package/dist/src/modular/serialization/operationHelpers.js +0 -457
- package/dist/src/modular/serialization/operationHelpers.js.map +0 -1
- package/dist/src/modular/serialization/serializeArray.d.ts +0 -5
- package/dist/src/modular/serialization/serializeArray.d.ts.map +0 -1
- package/dist/src/modular/serialization/serializeArray.js +0 -33
- package/dist/src/modular/serialization/serializeArray.js.map +0 -1
- package/dist/src/modular/serialization/serializeDateTime.d.ts +0 -4
- package/dist/src/modular/serialization/serializeDateTime.d.ts.map +0 -1
- package/dist/src/modular/serialization/serializeDateTime.js +0 -19
- package/dist/src/modular/serialization/serializeDateTime.js.map +0 -1
- package/dist/src/modular/serialization/serializeHeaders.d.ts +0 -7
- package/dist/src/modular/serialization/serializeHeaders.d.ts.map +0 -1
- package/dist/src/modular/serialization/serializeHeaders.js +0 -44
- package/dist/src/modular/serialization/serializeHeaders.js.map +0 -1
- package/dist/src/modular/serialization/serializers.d.ts +0 -17
- package/dist/src/modular/serialization/serializers.d.ts.map +0 -1
- package/dist/src/modular/serialization/serializers.js +0 -175
- package/dist/src/modular/serialization/serializers.js.map +0 -1
- package/dist/src/modular/serialization/util.d.ts +0 -27
- package/dist/src/modular/serialization/util.d.ts.map +0 -1
- package/dist/src/modular/serialization/util.js +0 -115
- package/dist/src/modular/serialization/util.js.map +0 -1
- package/dist/src/reify/index.d.ts +0 -12
- package/dist/src/reify/index.d.ts.map +0 -1
- package/dist/src/reify/index.js +0 -22
- package/dist/src/reify/index.js.map +0 -1
- package/src/modular/serialization/collectionUtils.ts +0 -20
- package/src/modular/serialization/index.ts +0 -267
- package/src/modular/serialization/operationHelpers.ts +0 -659
- package/src/modular/serialization/serializeArray.ts +0 -51
- package/src/modular/serialization/serializeDateTime.ts +0 -22
- package/src/modular/serialization/serializeHeaders.ts +0 -64
- package/src/modular/serialization/serializers.ts +0 -304
- package/src/modular/serialization/util.ts +0 -171
- package/src/modular/static/karma.conf.cjs +0 -120
- package/src/reify/index.ts +0 -41
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## 0.31.0 (2024-07-23)
|
|
2
|
+
|
|
3
|
+
- [Feature] Set user agent prefix at different layer for modular. Please refer to [#2616](https://github.com/Azure/autorest.typescript/pull/2616).
|
|
4
|
+
- [Feature] Spread is spread support. Please refer to [#2653](https://github.com/Azure/autorest.typescript/pull/2653).
|
|
5
|
+
- [Feature] Upgrade TypeSpec compiler version to 0.58.x. Please refer to [#2679](https://github.com/Azure/autorest.typescript/pull/2679).
|
|
6
|
+
- [Feature] Support Modular readme.md generation. Please refer to [#2655](https://github.com/Azure/autorest.typescript/pull/2655).
|
|
7
|
+
- [Feature] Engineering system related improvements.
|
|
8
|
+
- Bump typescript version to ~5.5.3, please refer to [#2646](https://github.com/Azure/autorest.typescript/pull/2646);
|
|
9
|
+
- vitest timeout config, please refer to [#2632](https://github.com/Azure/autorest.typescript/pull/2632);
|
|
10
|
+
- recorded client for esm package improve, please refer to [#2632](https://github.com/Azure/autorest.typescript/pull/2632);
|
|
11
|
+
- skip sample validation if generateSample is false, please refer to [#2650](https://github.com/Azure/autorest.typescript/pull/2650);
|
|
12
|
+
- remove unused configuration files, please refer to [#2655](https://github.com/Azure/autorest.typescript/pull/2655);
|
|
13
|
+
- add and refine document for generated code, please refer to [#2661](https://github.com/Azure/autorest.typescript/pull/2661) and [#2621](https://github.com/Azure/autorest.typescript/pull/2621).
|
|
14
|
+
- [Bugfix] Fix the isUnexpected narrowing issue in Modular. Please refer to [#2654](https://github.com/Azure/autorest.typescript/pull/2654).
|
|
15
|
+
- [Bugfix] Fix the extensible enum with null union generation failure in RLC. Please refer to [#2682](https://github.com/Azure/autorest.typescript/pull/2682).
|
|
16
|
+
- [Bugfix] Remove hard code for lro in patch operation. Please refer to [#2583](https://github.com/Azure/autorest.typescript/pull/2583).
|
|
17
|
+
- [Bugfix] Fix client option interface name inconsistent issue. Please refer to [#2671](https://github.com/Azure/autorest.typescript/pull/2671).
|
|
18
|
+
- [Bugfix] Fix nullable dictionaries and array element nullable serialization issues. Please refer to [#2631](https://github.com/Azure/autorest.typescript/pull/2631) and [#2643](https://github.com/Azure/autorest.typescript/pull/2643).
|
|
19
|
+
|
|
1
20
|
## 0.30.1 (2024-06-29)
|
|
2
21
|
|
|
3
22
|
- [Bugfix] Remove runtime references to @azure/core-util devDependency. Please refer to [#2634](https://github.com/Azure/autorest.typescript/pull/2634/files).
|
|
@@ -2,6 +2,8 @@ import { Project, SourceFile } from "ts-morph";
|
|
|
2
2
|
import { ModularMetaTree, RlcMetaTree } from "./metaTree.js";
|
|
3
3
|
import { EmitContext } from "@typespec/compiler";
|
|
4
4
|
import { SdkContext } from "@azure-tools/typespec-client-generator-core";
|
|
5
|
+
import { SdkTypeContext } from "./framework/hooks/sdkTypes.js";
|
|
6
|
+
import { Binder } from "./framework/hooks/binder.js";
|
|
5
7
|
/**
|
|
6
8
|
* Contexts Object Guidelines
|
|
7
9
|
* --------------------------
|
|
@@ -20,10 +22,12 @@ type Contexts = {
|
|
|
20
22
|
modularMetaTree: ModularMetaTree;
|
|
21
23
|
outputProject: Project;
|
|
22
24
|
symbolMap: Map<string, SourceFile>;
|
|
25
|
+
sdkTypes: SdkTypeContext;
|
|
23
26
|
emitContext: {
|
|
24
27
|
compilerContext: EmitContext;
|
|
25
28
|
tcgcContext: SdkContext;
|
|
26
29
|
};
|
|
30
|
+
binder: Binder;
|
|
27
31
|
};
|
|
28
32
|
type ContextKey = keyof Contexts;
|
|
29
33
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextManager.d.ts","sourceRoot":"","sources":["../../src/contextManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"contextManager.d.ts","sourceRoot":"","s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AKG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAMpE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,UAAU,EACjD,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GACjB,IAAI,CAEN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextManager.js","sourceRoot":"","sources":["../../src/contextManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"contextManager.js","sourceRoot":"","sources":["../../src/contextManager.ts"],"names":[],"mappings":"AAmCA;;;GAGG;AACH,MAAM,cAAc;IAIlB;QAFQ,aAAQ,GAAyB,IAAI,GAAG,EAAE,CAAC;IAE5B,CAAC;IAExB;;;OAGG;IACI,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC7B,cAAc,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;QACjD,CAAC;QACD,OAAO,cAAc,CAAC,QAAQ,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,UAAU,CAAuB,GAAM,EAAE,KAAkB;QAChE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,UAAU,CAAuB,GAAM;QAC5C,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAA4B,CAAC;IAC3D,CAAC;CACF;AAED,wDAAwD;AACxD,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAuB,GAAM;IACrD,MAAM,OAAO,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,WAAW,GAAG,YAAY,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAM,EACN,KAAkB;IAElB,cAAc,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SourceFile, ClassDeclarationStructure, EnumDeclarationStructure, FunctionDeclarationStructure, InterfaceDeclarationStructure, TypeAliasDeclarationStructure, ClassDeclaration, EnumDeclaration, FunctionDeclaration, InterfaceDeclaration, TypeAliasDeclaration } from "ts-morph";
|
|
2
|
+
export type DeclarationStructures = ClassDeclarationStructure | EnumDeclarationStructure | FunctionDeclarationStructure | InterfaceDeclarationStructure | TypeAliasDeclarationStructure;
|
|
3
|
+
export type Declarations = ClassDeclaration | EnumDeclaration | FunctionDeclaration | InterfaceDeclaration | TypeAliasDeclaration;
|
|
4
|
+
export declare function addDeclaration(sourceFile: SourceFile, declaration: ClassDeclarationStructure, refkey: unknown): ClassDeclaration;
|
|
5
|
+
export declare function addDeclaration(sourceFile: SourceFile, declaration: EnumDeclarationStructure, refkey: unknown): EnumDeclaration;
|
|
6
|
+
export declare function addDeclaration(sourceFile: SourceFile, declaration: FunctionDeclarationStructure, refkey: unknown): FunctionDeclaration;
|
|
7
|
+
export declare function addDeclaration(sourceFile: SourceFile, declaration: InterfaceDeclarationStructure, refkey: unknown): InterfaceDeclaration;
|
|
8
|
+
export declare function addDeclaration(sourceFile: SourceFile, declaration: TypeAliasDeclarationStructure, refkey: unknown): TypeAliasDeclaration;
|
|
9
|
+
//# sourceMappingURL=declaration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.d.ts","sourceRoot":"","sources":["../../../src/framework/declaration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,yBAAyB,EACzB,wBAAwB,EACxB,4BAA4B,EAC5B,6BAA6B,EAC7B,6BAA6B,EAE7B,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAGlB,MAAM,MAAM,qBAAqB,GAC7B,yBAAyB,GACzB,wBAAwB,GACxB,4BAA4B,GAC5B,6BAA6B,GAC7B,6BAA6B,CAAC;AAElC,MAAM,MAAM,YAAY,GACpB,gBAAgB,GAChB,eAAe,GACf,mBAAmB,GACnB,oBAAoB,GACpB,oBAAoB,CAAC;AAEzB,wBAAgB,cAAc,CAC5B,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,yBAAyB,EACtC,MAAM,EAAE,OAAO,GACd,gBAAgB,CAAC;AAEpB,wBAAgB,cAAc,CAC5B,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,wBAAwB,EACrC,MAAM,EAAE,OAAO,GACd,eAAe,CAAC;AAEnB,wBAAgB,cAAc,CAC5B,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,4BAA4B,EACzC,MAAM,EAAE,OAAO,GACd,mBAAmB,CAAC;AAEvB,wBAAgB,cAAc,CAC5B,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,6BAA6B,EAC1C,MAAM,EAAE,OAAO,GACd,oBAAoB,CAAC;AAExB,wBAAgB,cAAc,CAC5B,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,6BAA6B,EAC1C,MAAM,EAAE,OAAO,GACd,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { StructureKind } from "ts-morph";
|
|
2
|
+
import { useBinder } from "./hooks/binder.js";
|
|
3
|
+
import { refkey as getRefKey } from "./refkey.js";
|
|
4
|
+
export function addDeclaration(sourceFile, declaration, refkey) {
|
|
5
|
+
const binder = useBinder();
|
|
6
|
+
if (!declaration.name) {
|
|
7
|
+
throw new Error(`Declaration must have a name ${JSON.stringify(declaration)}`);
|
|
8
|
+
}
|
|
9
|
+
const stringRefkey = typeof refkey === "string" ? refkey : getRefKey(refkey);
|
|
10
|
+
const trackedDeclarationName = binder.trackDeclaration(stringRefkey, declaration.name, sourceFile);
|
|
11
|
+
// Update the declaration name to be unique
|
|
12
|
+
const trackedDeclaration = { ...declaration, name: trackedDeclarationName };
|
|
13
|
+
switch (trackedDeclaration.kind) {
|
|
14
|
+
case StructureKind.Class:
|
|
15
|
+
return sourceFile.addClass(trackedDeclaration);
|
|
16
|
+
case StructureKind.Enum:
|
|
17
|
+
return sourceFile.addEnum(trackedDeclaration);
|
|
18
|
+
case StructureKind.Function:
|
|
19
|
+
return sourceFile.addFunction(trackedDeclaration);
|
|
20
|
+
case StructureKind.Interface:
|
|
21
|
+
return sourceFile.addInterface(trackedDeclaration);
|
|
22
|
+
case StructureKind.TypeAlias:
|
|
23
|
+
return sourceFile.addTypeAlias(trackedDeclaration);
|
|
24
|
+
default:
|
|
25
|
+
throw new Error(`Unsupported declaration kind ${trackedDeclaration.kind}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=declaration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declaration.js","sourceRoot":"","sources":["../../../src/framework/declaration.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,aAAa,EAMd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AA4ClD,MAAM,UAAU,cAAc,CAC5B,UAAsB,EACtB,WAAkC,EAClC,MAAe;IAEf,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,gCAAgC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAC9D,CAAC;IACJ,CAAC;IAED,MAAM,YAAY,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAE7E,MAAM,sBAAsB,GAAG,MAAM,CAAC,gBAAgB,CACpD,YAAY,EACZ,WAAW,CAAC,IAAI,EAChB,UAAU,CACX,CAAC;IAEF,2CAA2C;IAC3C,MAAM,kBAAkB,GAAG,EAAE,GAAG,WAAW,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC;IAE5E,QAAQ,kBAAkB,CAAC,IAAI,EAAE,CAAC;QAChC,KAAK,aAAa,CAAC,KAAK;YACtB,OAAO,UAAU,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;QACjD,KAAK,aAAa,CAAC,IAAI;YACrB,OAAO,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAChD,KAAK,aAAa,CAAC,QAAQ;YACzB,OAAO,UAAU,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;QACpD,KAAK,aAAa,CAAC,SAAS;YAC1B,OAAO,UAAU,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;QACrD,KAAK,aAAa,CAAC,SAAS;YAC1B,OAAO,UAAU,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;QACrD;YACE,MAAM,IAAI,KAAK,CACb,gCAAiC,kBAA0B,CAAC,IAAI,EAAE,CACnE,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SourceFile, Project } from "ts-morph";
|
|
2
|
+
export interface DeclarationInfo {
|
|
3
|
+
name: string;
|
|
4
|
+
sourceFile: SourceFile;
|
|
5
|
+
alias?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Binder {
|
|
8
|
+
/**
|
|
9
|
+
* Tracks a new declaration.
|
|
10
|
+
* @param refkey - A unique reference key for the declaration.
|
|
11
|
+
* @param name - The name of the declaration.
|
|
12
|
+
* @param sourceFile - The source file where the declaration is made.
|
|
13
|
+
* @returns The tracked declaration name.
|
|
14
|
+
*/
|
|
15
|
+
trackDeclaration(refkey: unknown, name: string, sourceFile: SourceFile): string;
|
|
16
|
+
resolveReference(refkey: unknown): string;
|
|
17
|
+
applyImports(): void;
|
|
18
|
+
}
|
|
19
|
+
export declare function provideBinder(project?: Project): void;
|
|
20
|
+
/**
|
|
21
|
+
* Hook to use the binder context.
|
|
22
|
+
* @returns The binder instance.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useBinder(): Binder;
|
|
25
|
+
//# sourceMappingURL=binder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binder.d.ts","sourceRoot":"","sources":["../../../../src/framework/hooks/binder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAIV,OAAO,EACR,MAAM,UAAU,CAAC;AAGlB,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,MAAM;IACrB;;;;;;OAMG;IACH,gBAAgB,CACd,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,UAAU,GACrB,MAAM,CAAC;IACV,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IAC1C,YAAY,IAAI,IAAI,CAAC;CACtB;AAgMD,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAErD;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAElC"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { StructureKind, Project } from "ts-morph";
|
|
2
|
+
import { provideContext, useContext } from "../../contextManager.js";
|
|
3
|
+
class BinderImp {
|
|
4
|
+
constructor(project) {
|
|
5
|
+
this.declarations = new Map();
|
|
6
|
+
this.imports = new Map();
|
|
7
|
+
this.symbolsBySourceFile = new Map();
|
|
8
|
+
this.project = project !== null && project !== void 0 ? project : new Project();
|
|
9
|
+
}
|
|
10
|
+
trackDeclaration(refkey, name, sourceFile) {
|
|
11
|
+
const uniqueName = this.generateLocallyUniqueDeclarationName(name, sourceFile);
|
|
12
|
+
const declarationInfo = { name: uniqueName, sourceFile };
|
|
13
|
+
this.declarations.set(refkey, declarationInfo);
|
|
14
|
+
// Ensure symbolsBySourceFile has an entry for this sourceFile
|
|
15
|
+
if (!this.symbolsBySourceFile.has(sourceFile)) {
|
|
16
|
+
this.symbolsBySourceFile.set(sourceFile, new Set());
|
|
17
|
+
}
|
|
18
|
+
this.symbolsBySourceFile.get(sourceFile).add(uniqueName);
|
|
19
|
+
return uniqueName;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Generates a locally unique name for a declaration within a source file.
|
|
23
|
+
* @param name - The base name of the declaration.
|
|
24
|
+
* @param sourceFile - The source file where the declaration is made.
|
|
25
|
+
* @returns A unique name for the declaration within the file.
|
|
26
|
+
*/
|
|
27
|
+
generateLocallyUniqueDeclarationName(name, sourceFile) {
|
|
28
|
+
var _a;
|
|
29
|
+
const existingNamesInFile = (_a = this.symbolsBySourceFile.get(sourceFile)) !== null && _a !== void 0 ? _a : new Set();
|
|
30
|
+
return this.generateLocallyUniqueName(name, existingNamesInFile);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generates a locally unique name for an import within a source file.
|
|
34
|
+
* @param name - The base name of the import.
|
|
35
|
+
* @param sourceFile - The source file where the import is made.
|
|
36
|
+
* @returns A unique name for the import within the file.
|
|
37
|
+
*/
|
|
38
|
+
generateLocallyUniqueImportName(name, sourceFile) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
const existingImports = ((_a = this.imports.get(sourceFile)) !== null && _a !== void 0 ? _a : [])
|
|
41
|
+
.flatMap((i) => i.namedImports)
|
|
42
|
+
.map((i) => { var _a; return (_a = i.alias) !== null && _a !== void 0 ? _a : i.name; });
|
|
43
|
+
const existingDeclarations = (_b = this.symbolsBySourceFile.get(sourceFile)) !== null && _b !== void 0 ? _b : new Set();
|
|
44
|
+
return this.generateLocallyUniqueName(name, new Set([...existingImports, ...existingDeclarations]));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Generates a locally unique name within a set of existing names.
|
|
48
|
+
* @param name - The base name.
|
|
49
|
+
* @param existingNames - A set of names already in use.
|
|
50
|
+
* @returns A unique name not present in the existing names set.
|
|
51
|
+
*/
|
|
52
|
+
generateLocallyUniqueName(name, existingNames) {
|
|
53
|
+
let uniqueName = name;
|
|
54
|
+
let counter = 1;
|
|
55
|
+
while (existingNames.has(uniqueName)) {
|
|
56
|
+
uniqueName = `${name}_${counter}`;
|
|
57
|
+
counter++;
|
|
58
|
+
}
|
|
59
|
+
return uniqueName;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Resolves a reference to a declaration.
|
|
63
|
+
* If a declaration is not ready yet, a placeholder is added to the source file.
|
|
64
|
+
* Placeholders will be resolved when the imports are applied.
|
|
65
|
+
* @param refkey - The reference key for the declaration.
|
|
66
|
+
* @param currentSourceFile - The current source file where the reference is being resolved.
|
|
67
|
+
* @returns The declaration information if resolved, or a placeholder if not found.
|
|
68
|
+
*/
|
|
69
|
+
resolveReference(refkey) {
|
|
70
|
+
return this.serializePlaceholder(refkey);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Serializes a placeholder reference key to a string.
|
|
74
|
+
* @param refkey - The reference key.
|
|
75
|
+
* @returns The serialized placeholder string.
|
|
76
|
+
*/
|
|
77
|
+
serializePlaceholder(refkey) {
|
|
78
|
+
return `PLACEHOLDER:${String(refkey)}`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Adds an import declaration to a source file.
|
|
82
|
+
* @param fileWhereImportIsAdded - The source file where the import is added.
|
|
83
|
+
* @param fileWhereImportPointsTo - The source file being imported.
|
|
84
|
+
* @param name - The name of the import.
|
|
85
|
+
* @returns The import specifier structure.
|
|
86
|
+
*/
|
|
87
|
+
addImport(fileWhereImportIsAdded, fileWhereImportPointsTo, name) {
|
|
88
|
+
const importAlias = this.generateLocallyUniqueImportName(name, fileWhereImportIsAdded);
|
|
89
|
+
const relativePath = fileWhereImportIsAdded.getRelativePathAsModuleSpecifierTo(fileWhereImportPointsTo);
|
|
90
|
+
const importStructures = this.imports.get(fileWhereImportIsAdded) || [];
|
|
91
|
+
let importStructure = importStructures.find((imp) => imp.moduleSpecifier === relativePath);
|
|
92
|
+
if (!importStructure) {
|
|
93
|
+
importStructure = {
|
|
94
|
+
kind: StructureKind.ImportDeclaration,
|
|
95
|
+
moduleSpecifier: relativePath,
|
|
96
|
+
namedImports: []
|
|
97
|
+
};
|
|
98
|
+
importStructures.push(importStructure);
|
|
99
|
+
}
|
|
100
|
+
const namedImports = importStructure.namedImports;
|
|
101
|
+
let importSpecifier = namedImports.find((n) => n.name === importAlias);
|
|
102
|
+
if (!importSpecifier) {
|
|
103
|
+
importSpecifier = {
|
|
104
|
+
name: name,
|
|
105
|
+
alias: name === importAlias ? undefined : importAlias,
|
|
106
|
+
kind: StructureKind.ImportSpecifier
|
|
107
|
+
};
|
|
108
|
+
namedImports.push(importSpecifier);
|
|
109
|
+
}
|
|
110
|
+
importStructure.namedImports = namedImports;
|
|
111
|
+
this.imports.set(fileWhereImportIsAdded, importStructures);
|
|
112
|
+
return importSpecifier;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Applies all tracked imports to their respective source files.
|
|
116
|
+
*/
|
|
117
|
+
applyImports() {
|
|
118
|
+
var _a;
|
|
119
|
+
for (const file of this.project.getSourceFiles()) {
|
|
120
|
+
for (const [declarationKey, declaration] of this.declarations) {
|
|
121
|
+
const placeholderKey = this.serializePlaceholder(declarationKey);
|
|
122
|
+
let name = declaration.name;
|
|
123
|
+
if (file !== declaration.sourceFile) {
|
|
124
|
+
const importDec = this.addImport(file, declaration.sourceFile, declaration.name);
|
|
125
|
+
name = (_a = importDec.alias) !== null && _a !== void 0 ? _a : declaration.name;
|
|
126
|
+
}
|
|
127
|
+
replacePlaceholder(file, placeholderKey, name);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
for (const [sourceFile, importStructures] of this.imports) {
|
|
131
|
+
for (const importStructure of importStructures) {
|
|
132
|
+
sourceFile.addImportDeclaration(importStructure);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Provide the binder context to be used globally
|
|
138
|
+
export function provideBinder(project) {
|
|
139
|
+
return provideContext("binder", new BinderImp(project));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Hook to use the binder context.
|
|
143
|
+
* @returns The binder instance.
|
|
144
|
+
*/
|
|
145
|
+
export function useBinder() {
|
|
146
|
+
return useContext("binder");
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Replaces all instances of a placeholder in a source file with a given value.
|
|
150
|
+
* @param sourceFile - The source file where the replacement occurs.
|
|
151
|
+
* @param placeholder - The placeholder string to replace.
|
|
152
|
+
* @param value - The value to replace the placeholder with.
|
|
153
|
+
*/
|
|
154
|
+
function replacePlaceholder(sourceFile, placeholder, value) {
|
|
155
|
+
const fileText = sourceFile.getFullText();
|
|
156
|
+
const regex = new RegExp(escapeRegExp(placeholder), "g");
|
|
157
|
+
const updatedText = fileText.replace(regex, value);
|
|
158
|
+
sourceFile.replaceWithText(updatedText);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Escapes special characters in a string to be used in a regular expression.
|
|
162
|
+
* @param string - The input string.
|
|
163
|
+
* @returns The escaped string.
|
|
164
|
+
*/
|
|
165
|
+
function escapeRegExp(string) {
|
|
166
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=binder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binder.js","sourceRoot":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,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAC1C,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnD,UAAU,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,SAAS,YAAY,CAAC,MAAc;IAClC,OAAO,MAAM,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SdkHttpOperation, SdkPackage, SdkServiceMethod, SdkType } from "@azure-tools/typespec-client-generator-core";
|
|
2
|
+
import { Operation, Type } from "@typespec/compiler";
|
|
3
|
+
export interface SdkTypeContext {
|
|
4
|
+
operations: Map<Type, SdkServiceMethod<SdkHttpOperation>>;
|
|
5
|
+
types: Map<Type, SdkType>;
|
|
6
|
+
}
|
|
7
|
+
export declare function useSdkTypes(): {
|
|
8
|
+
(type: Operation): SdkServiceMethod<SdkHttpOperation>;
|
|
9
|
+
(type: Type): SdkType;
|
|
10
|
+
};
|
|
11
|
+
export declare function provideSdkTypes(sdkPackage: SdkPackage<SdkHttpOperation>): void;
|
|
12
|
+
//# sourceMappingURL=sdkTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkTypes.d.ts","sourceRoot":"","sources":["../../../../src/framework/hooks/sdkTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,OAAO,EAER,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAwB,MAAM,oBAAoB,CAAC;AAG3E,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,GAAG,CAAC,IAAI,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC1D,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;CAC3B;AAED,wBAAgB,WAAW;WAIC,SAAS,GAAG,gBAAgB,CAAC,gBAAgB,CAAC;WAC9C,IAAI,GAAG,OAAO;EA6BzC;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,gBAAgB,CAAC,QAiCvE"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getClientType } from "@azure-tools/typespec-client-generator-core";
|
|
2
|
+
import { getNamespaceFullName } from "@typespec/compiler";
|
|
3
|
+
import { provideContext, useContext } from "../../contextManager.js";
|
|
4
|
+
export function useSdkTypes() {
|
|
5
|
+
const sdkTypesContext = useContext("sdkTypes");
|
|
6
|
+
const { tcgcContext } = useContext("emitContext");
|
|
7
|
+
function getSdkType(type) {
|
|
8
|
+
var _a;
|
|
9
|
+
let sdkType;
|
|
10
|
+
if (type.kind === "Operation") {
|
|
11
|
+
sdkType = sdkTypesContext.operations.get(type);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
sdkType =
|
|
15
|
+
(_a = sdkTypesContext.types.get(type)) !== null && _a !== void 0 ? _a : getClientType(tcgcContext, type);
|
|
16
|
+
}
|
|
17
|
+
if (!sdkType) {
|
|
18
|
+
throw new Error(`SdkType not found for type: ${type.kind} ${"name" in type && typeof type.name == "string" ? type.name : ""} ${"namespace" in type && type.namespace
|
|
19
|
+
? ` in ${getNamespaceFullName(type.namespace)}`
|
|
20
|
+
: ""}`);
|
|
21
|
+
}
|
|
22
|
+
return sdkType;
|
|
23
|
+
}
|
|
24
|
+
return getSdkType;
|
|
25
|
+
}
|
|
26
|
+
export function provideSdkTypes(sdkPackage) {
|
|
27
|
+
const sdkTypesContext = {
|
|
28
|
+
operations: new Map(),
|
|
29
|
+
types: new Map()
|
|
30
|
+
};
|
|
31
|
+
for (const sdkEnum of sdkPackage.enums) {
|
|
32
|
+
if (!sdkEnum.__raw) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
sdkTypesContext.types.set(sdkEnum.__raw, sdkEnum);
|
|
36
|
+
}
|
|
37
|
+
for (const sdkModel of sdkPackage.models) {
|
|
38
|
+
if (!sdkModel.__raw) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
sdkTypesContext.types.set(sdkModel.__raw, sdkModel);
|
|
42
|
+
}
|
|
43
|
+
for (const client of sdkPackage.clients) {
|
|
44
|
+
for (const method of getAllOperationsFromClient(client)) {
|
|
45
|
+
if (!method.__raw) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
sdkTypesContext.operations.set(method.__raw, method);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
provideContext("sdkTypes", sdkTypesContext);
|
|
52
|
+
}
|
|
53
|
+
function getAllOperationsFromClient(client) {
|
|
54
|
+
const methodQueue = [...client.methods];
|
|
55
|
+
const operations = [];
|
|
56
|
+
while (methodQueue.length > 0) {
|
|
57
|
+
const method = methodQueue.pop();
|
|
58
|
+
if (method.kind === "clientaccessor") {
|
|
59
|
+
method.response.methods.forEach((m) => methodQueue.push(m));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
operations.push(method);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return operations;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=sdkTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdkTypes.js","sourceRoot":"","sources":["../../../../src/framework/hooks/sdkTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,aAAa,EACd,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAmB,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAOrE,MAAM,UAAU,WAAW;IACzB,MAAM,eAAe,GAAG,UAAU,C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
|
+
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/framework/reference.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAKpE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useBinder } from "./hooks/binder.js";
|
|
2
|
+
import { refkey as getRefKey } from "./refkey.js";
|
|
3
|
+
export function resolveReference(refkey) {
|
|
4
|
+
const binder = useBinder();
|
|
5
|
+
const stringRefkey = typeof refkey === "string" ? refkey : getRefKey(refkey);
|
|
6
|
+
return binder.resolveReference(stringRefkey);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=reference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference.js","sourceRoot":"","sources":["../../../src/framework/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,UAAU,gBAAgB,CAAC,MAAe;IAC9C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,YAAY,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAE7E,OAAO,MAAM,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refkey.d.ts","sourceRoot":"","sources":["../../../src/framework/refkey.ts"],"names":[],"mappings":"AAcA,OAAO,CAAC,MAAM,SAAS,EAAE,OAAO,MAAM,CAAC;AACvC,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG;IAAE,CAAC,SAAS,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAUpD,wBAAgB,MAAM,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,UAExC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const objectIds = new WeakMap();
|
|
2
|
+
let objId = 0;
|
|
3
|
+
function getObjectKey(value) {
|
|
4
|
+
if (objectIds.has(value)) {
|
|
5
|
+
return `${objectIds.get(value)}`;
|
|
6
|
+
}
|
|
7
|
+
const key = `o${objId++}`;
|
|
8
|
+
objectIds.set(value, key);
|
|
9
|
+
return key;
|
|
10
|
+
}
|
|
11
|
+
function getKey(value) {
|
|
12
|
+
if (typeof value === "object" && value !== null) {
|
|
13
|
+
return getObjectKey(value);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return `s${String(value)}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function refkey(...args) {
|
|
20
|
+
return args.map((v) => getKey(v)).join("\u2063");
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=refkey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refkey.js","sourceRoot":"","sources":["../../../src/framework/refkey.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,IAAI,OAAO,EAAmB,CAAC;AACjD,IAAI,KAAK,GAAG,CAAC,CAAC;AAEd,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,EAAE,CAAC;IAC1B,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE1B,OAAO,GAAG,CAAC;AACb,CAAC;AAKD,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,YAAY,CAAC,KAAK,CAAW,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAY,CAAC;IACvC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,GAAG,IAAe;IACvC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample.d.ts","sourceRoot":"","sources":["../../../src/framework/sample.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Project, StructureKind } from "ts-morph";
|
|
2
|
+
import { useBinder } from "./hooks/binder.js";
|
|
3
|
+
import { addDeclaration } from "./declaration.js";
|
|
4
|
+
import { resolveReference } from "./reference.js";
|
|
5
|
+
// Create a new ts-morph project
|
|
6
|
+
const project = new Project();
|
|
7
|
+
// Create a source file
|
|
8
|
+
const sourceFile = project.createSourceFile("test.ts", "", { overwrite: true });
|
|
9
|
+
// Initialize the binder
|
|
10
|
+
const binder = useBinder();
|
|
11
|
+
// Define an interface model. In practice this would be a type object (e.g. from TypeSpec, TCGC, modelerfour, etc.)
|
|
12
|
+
// At this framework level, we're just using a simple object, there is no coupling with the actual type system, but this is flexible so any object can be used.
|
|
13
|
+
const modelType = {
|
|
14
|
+
name: "MyInterface",
|
|
15
|
+
properties: [{ name: "id", type: "number" }]
|
|
16
|
+
};
|
|
17
|
+
// Define a function model
|
|
18
|
+
const functionType = {
|
|
19
|
+
name: "MyFunction",
|
|
20
|
+
returnType: "void",
|
|
21
|
+
body: `console.log("Hello World");`
|
|
22
|
+
};
|
|
23
|
+
// Create an interface declaration structure. This illustrates a similar pattern to the one used in the emitter. Transorming a model into a structure for ts-morph.
|
|
24
|
+
const interfaceDeclaration = {
|
|
25
|
+
kind: StructureKind.Interface,
|
|
26
|
+
name: modelType.name,
|
|
27
|
+
properties: modelType.properties.map((p) => ({
|
|
28
|
+
name: p.name,
|
|
29
|
+
type: p.type
|
|
30
|
+
}))
|
|
31
|
+
};
|
|
32
|
+
// Create a function declaration structure
|
|
33
|
+
const functionDeclaration = {
|
|
34
|
+
kind: StructureKind.Function,
|
|
35
|
+
name: functionType.name,
|
|
36
|
+
returnType: functionType.returnType,
|
|
37
|
+
statements: functionType.body
|
|
38
|
+
};
|
|
39
|
+
// Helper functions to add the declarations to the source file. These are needed to be able to leverage the binder to track the declarations.
|
|
40
|
+
// We'll be moving from sourceFile.addInterface(interfaceDeclaration) to addDeclaration(sourceFile, interfaceDeclaration, interfaceModel)
|
|
41
|
+
addDeclaration(sourceFile, interfaceDeclaration, modelType);
|
|
42
|
+
addDeclaration(sourceFile, functionDeclaration, functionType);
|
|
43
|
+
// Create another source file
|
|
44
|
+
const sourceFile2 = project.createSourceFile("test2.ts", "", {
|
|
45
|
+
overwrite: true
|
|
46
|
+
});
|
|
47
|
+
// Add statements referencing the tracked declarations
|
|
48
|
+
const functionReference = resolveReference(functionType);
|
|
49
|
+
const modelReference = resolveReference(modelType);
|
|
50
|
+
sourceFile2.addStatements(`${functionReference}();`);
|
|
51
|
+
sourceFile2.addStatements(`let obj: ${modelReference} = { id: 1 };`);
|
|
52
|
+
// Apply imports to ensure correct references
|
|
53
|
+
binder.applyImports();
|
|
54
|
+
// Output the generated files
|
|
55
|
+
console.log("// test.ts");
|
|
56
|
+
console.log(sourceFile.getFullText());
|
|
57
|
+
console.log("// test2.ts");
|
|
58
|
+
console.log(sourceFile2.getFullText());
|
|
59
|
+
// Output
|
|
60
|
+
// test.ts
|
|
61
|
+
// interface MyInterface {
|
|
62
|
+
// id: number;
|
|
63
|
+
// }
|
|
64
|
+
// function MyFunction(): void {
|
|
65
|
+
// console.log("Hello World");
|
|
66
|
+
// }
|
|
67
|
+
// // test2.ts
|
|
68
|
+
// import { MyFunction, MyInterface } from "./test";
|
|
69
|
+
// MyFunction();
|
|
70
|
+
// let obj: MyInterface = { id: 1 };
|
|
71
|
+
//# sourceMappingURL=sample.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample.js","sourceRoot":"","sources":["../../../src/framework/sample.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,aAAa,EAGd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,gCAAgC;AAChC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,uBAAuB;AACvB,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAEhF,wBAAwB;AACxB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAE3B,mHAAmH;AACnH,+JAA+J;AAC/J,MAAM,SAAS,GAAG;IAChB,IAAI,EAAE,aAAa;IACnB,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;CAC7C,CAAC;AAEF,0BAA0B;AAC1B,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,YAAY;IAClB,UAAU,EAAE,MAAM;IAClB,IAAI,EAAE,6BAA6B;CACpC,CAAC;AAEF,mKAAmK;AACnK,MAAM,oBAAoB,GAAkC;IAC1D,IAAI,EAAE,aAAa,CAAC,SAAS;IAC7B,IAAI,EAAE,SAAS,CAAC,IAAI;IACpB,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC3C,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,IAAI,EAAE,CAAC,CAAC,IAAI;KACb,CAAC,CAAC;CAC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-0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsmorph-helpers.d.ts","sourceRoot":"","sources":["../../../../src/framework/utils/tsmorph-helpers.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsmorph-helpers.js","sourceRoot":"","sources":["../../../../src/framework/utils/tsmorph-helpers.ts"],"names":[],"mappings":""}
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAE,WAAW,EAAW,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAE,WAAW,EAAW,MAAM,oBAAoB,CAAC;AAiC1D,OAAO,EAAuB,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAKxE,cAAc,UAAU,CAAC;AAEzB,wBAAsB,OAAO,CAAC,OAAO,EAAE,WAAW,iBAsQjD;AAED,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GACxC,UAAU,CAkBZ"}
|