@azure-tools/typespec-providerhub-controller 0.27.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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/dist/src/generate.d.ts +13 -0
  3. package/dist/src/generate.d.ts.map +1 -0
  4. package/dist/src/generate.js +1592 -0
  5. package/dist/src/generate.js.map +1 -0
  6. package/dist/src/index.d.ts +3 -0
  7. package/dist/src/index.d.ts.map +1 -0
  8. package/dist/src/index.js +3 -0
  9. package/dist/src/index.js.map +1 -0
  10. package/dist/src/lib.d.ts +202 -0
  11. package/dist/src/lib.d.ts.map +1 -0
  12. package/dist/src/lib.js +143 -0
  13. package/dist/src/lib.js.map +1 -0
  14. package/dist/src/testing/index.d.ts +3 -0
  15. package/dist/src/testing/index.d.ts.map +1 -0
  16. package/dist/src/testing/index.js +29 -0
  17. package/dist/src/testing/index.js.map +1 -0
  18. package/package.json +74 -0
  19. package/readme.md +66 -0
  20. package/templates/liftr/closedEnum.sq +27 -0
  21. package/templates/liftr/model.sq +43 -0
  22. package/templates/liftr/openEnum.sq +34 -0
  23. package/templates/liftr/resourceControllerBase.sq +140 -0
  24. package/templates/liftr/serviceRoutingConstants.sq +35 -0
  25. package/templates/liftr/single/Operation.sq +40 -0
  26. package/templates/liftr/single/OperationAction.sq +31 -0
  27. package/templates/liftr/single/OperationControllerBase.sq +38 -0
  28. package/templates/liftr/single/OperationDisplay.sq +35 -0
  29. package/templates/liftr/single/OperationListResult.sq +17 -0
  30. package/templates/liftr/single/OperationOrigin.sq +31 -0
  31. package/templates/providerhub/closedEnum.sq +24 -0
  32. package/templates/providerhub/model.sq +103 -0
  33. package/templates/providerhub/modelCopy.sq +98 -0
  34. package/templates/providerhub/modelCopyExtension.sq +39 -0
  35. package/templates/providerhub/modelVersionComposite.sq +69 -0
  36. package/templates/providerhub/modelVersionStandard.sq +62 -0
  37. package/templates/providerhub/openEnum.sq +34 -0
  38. package/templates/providerhub/resourceController.sq +20 -0
  39. package/templates/providerhub/resourceControllerBase.Logger.sq +48 -0
  40. package/templates/providerhub/resourceControllerBase.sq +154 -0
  41. package/templates/providerhub/resourceProviderRegistration.sq +11 -0
  42. package/templates/providerhub/resourceRegistration.sq +27 -0
  43. package/templates/providerhub/serviceRoutingConstants.sq +38 -0
  44. package/templates/providerhub/single/OperationControllerBase.sq +52 -0
  45. package/templates/providerhub/versionCollection.sq +28 -0
  46. package/templates/providerhub/versionedContractResolver.sq +57 -0
  47. package/templates/providerhub/versionedSerializer.sq +38 -0
@@ -0,0 +1,28 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ // <auto-generated />
5
+
6
+
7
+ using System;
8
+ using System.Collections.Generic;
9
+ using Microsoft.TypeSpec.ProviderHub.Controller;
10
+
11
+ namespace {{nameSpace}}.Service
12
+ {
13
+ public class {{serviceName}}ServiceVersions : VersionCollection
14
+ {
15
+ {{#each versions}}
16
+ public const string {{versionName this}} = "{{this}}";
17
+ {{/each}}
18
+ public {{serviceName}}ServiceVersions()
19
+ {
20
+ var versions = new List<string>();
21
+ Versions = versions;
22
+ {{#each versions as |version index |}}
23
+ versions.Add("{{version}}");
24
+ {{/each}}
25
+ }
26
+ protected override IReadOnlyList<string> Versions { get; }
27
+ }
28
+ }
@@ -0,0 +1,57 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ // <auto-generated />
5
+
6
+ using System;
7
+ using System.Collections.Generic;
8
+ using System.Runtime.Serialization;
9
+ using Microsoft.TypeSpec.ProviderHub.Controller;
10
+
11
+ namespace {{nameSpace}}.Service
12
+ {
13
+ /// <summary>
14
+ /// Contract resolver for the service. This is generated to allow extensibility only.
15
+ /// </summary>
16
+ public partial class VersionedContractResolver : VersionedContractResolverBase
17
+ {
18
+ Func<Type, string> VersionLookup { get; set; }
19
+
20
+ /// <summary>
21
+ /// Extensibility point, allows performing actions befofe the VersionLookup function is initialized.
22
+ /// </summary>
23
+ /// <param name="version">The service version</param>
24
+ /// <param name="versionLookup">The function to look up versioned class information using the service version.</param>
25
+ partial void OnBeforeInitialize(string version, Func<Type, string> versionLookup);
26
+
27
+ /// <summary>
28
+ /// Extensibility point, allows performing actions after the VersionLookup function is initialized.
29
+ /// </summary>
30
+ /// <param name="version">The service version</param>
31
+ /// <param name="versionLookup">The function to look up versioned class information using the service version.</param>
32
+ partial void OnAfterInitialize(string version, Func<Type, string> versionLookup);
33
+
34
+ /// <summary>
35
+ /// Construct a contract resolver, using the given version and class version mapping function.
36
+ /// This constructor is used by the VersionedSerializer to construct the contract.
37
+ /// </summary>
38
+ /// <param name="version"></param>
39
+ /// <param name="versionLookup"></param>
40
+ public VersionedContractResolver(string version, Func<Type, string> versionLookup) : base(version)
41
+ {
42
+ OnBeforeInitialize(version, versionLookup);
43
+ VersionLookup = versionLookup;
44
+ OnAfterInitialize(version, versionLookup);
45
+ }
46
+
47
+ /// <summary>
48
+ /// Implementing contract resolvers must provide a type-> version dictionary for types they support.
49
+ /// This allows the service to implement service version -> library version type mappings, based on
50
+ /// the versioned dependency in the API specification.
51
+ /// </summary>
52
+ /// <param name="objectType">The Type of the class to provide versioning for</param>
53
+ /// <returns>The version for the given class</returns>
54
+ protected override string GetModelVersion(Type objectType) => VersionLookup(objectType);
55
+ }
56
+ }
57
+
@@ -0,0 +1,38 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ // <auto-generated />
5
+
6
+ using System;
7
+ using System.Collections.Generic;
8
+ using System.Linq;
9
+ using Microsoft.TypeSpec.ProviderHub.Controller;
10
+
11
+ namespace {{nameSpace}}.Service
12
+ {
13
+ /// <summary>
14
+ /// The main entry point for serialization
15
+ /// </summary>
16
+ public class VersionedSerializer : VersionedSerializerBase<VersionedContractResolver>
17
+ {
18
+ /// <summary>
19
+ /// The main entry point for serialization
20
+ /// </summary>
21
+ public static VersionedSerializer Instance { get; } = new VersionedSerializer();
22
+ public IReadOnlyList<string> ServiceVersions { get; }
23
+ public VersionComparer ServiceVersionComparer { get; }
24
+
25
+ private VersionedSerializer()
26
+ {
27
+ ServiceVersions = new {{serviceName}}ServiceVersions();
28
+ ServiceVersionComparer = new VersionComparer(new {{serviceName}}ServiceVersions());
29
+ }
30
+
31
+ protected override VersionedContractResolver GetResolver(string version)
32
+ {
33
+ if (ServiceVersions.Contains(version, ServiceVersionComparer))
34
+ return UpdateResolver(new VersionedContractResolver(version, (t) => GetModelVersion(t, version)));
35
+ throw new ArgumentException($"Version '{version}' is not valid. Please choose from '{string.Join(", ", ServiceVersions)}'");
36
+ }
37
+ }
38
+ }