@azure-tools/typespec-ts-provisioning 0.2.0 → 0.3.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 (70) hide show
  1. package/dist/src/arm/naming/name-resolvable.d.ts +7 -2
  2. package/dist/src/arm/naming/name-resolvable.d.ts.map +1 -1
  3. package/dist/src/arm/naming/name-resolvable.js +11 -3
  4. package/dist/src/arm/naming/name-resolvable.js.map +1 -1
  5. package/dist/src/arm/naming/name-resolver.d.ts +3 -3
  6. package/dist/src/arm/naming/name-resolver.d.ts.map +1 -1
  7. package/dist/src/arm/naming/name-resolver.js +2 -3
  8. package/dist/src/arm/naming/name-resolver.js.map +1 -1
  9. package/dist/src/arm/provisioning-types/context.d.ts +13 -1
  10. package/dist/src/arm/provisioning-types/context.d.ts.map +1 -1
  11. package/dist/src/arm/provisioning-types/context.js +5 -1
  12. package/dist/src/arm/provisioning-types/context.js.map +1 -1
  13. package/dist/src/arm/provisioning-types/type-factory.js +1 -1
  14. package/dist/src/arm/provisioning-types/type-factory.js.map +1 -1
  15. package/dist/src/arm/provisioning-types/types/enum.d.ts +2 -1
  16. package/dist/src/arm/provisioning-types/types/enum.d.ts.map +1 -1
  17. package/dist/src/arm/provisioning-types/types/enum.js +3 -2
  18. package/dist/src/arm/provisioning-types/types/enum.js.map +1 -1
  19. package/dist/src/arm/provisioning-types/types/model/model-like.d.ts +1 -0
  20. package/dist/src/arm/provisioning-types/types/model/model-like.d.ts.map +1 -1
  21. package/dist/src/arm/provisioning-types/types/model/model-like.js +6 -2
  22. package/dist/src/arm/provisioning-types/types/model/model-like.js.map +1 -1
  23. package/dist/src/arm/provisioning-types/types/namespace.d.ts +2 -2
  24. package/dist/src/arm/provisioning-types/types/namespace.d.ts.map +1 -1
  25. package/dist/src/arm/provisioning-types/types/namespace.js +19 -6
  26. package/dist/src/arm/provisioning-types/types/namespace.js.map +1 -1
  27. package/dist/src/arm/provisioning-types/types/resource.d.ts +15 -13
  28. package/dist/src/arm/provisioning-types/types/resource.d.ts.map +1 -1
  29. package/dist/src/arm/provisioning-types/types/resource.js +70 -58
  30. package/dist/src/arm/provisioning-types/types/resource.js.map +1 -1
  31. package/dist/src/arm/provisioning-types/types/union.d.ts +1 -0
  32. package/dist/src/arm/provisioning-types/types/union.d.ts.map +1 -1
  33. package/dist/src/arm/provisioning-types/types/union.js +4 -3
  34. package/dist/src/arm/provisioning-types/types/union.js.map +1 -1
  35. package/dist/src/arm/resource-analysis/analyzer.d.ts +6 -14
  36. package/dist/src/arm/resource-analysis/analyzer.d.ts.map +1 -1
  37. package/dist/src/arm/resource-analysis/analyzer.js +60 -44
  38. package/dist/src/arm/resource-analysis/analyzer.js.map +1 -1
  39. package/dist/src/arm/resource-analysis/http-resource-discovery.d.ts +9 -11
  40. package/dist/src/arm/resource-analysis/http-resource-discovery.d.ts.map +1 -1
  41. package/dist/src/arm/resource-analysis/http-resource-discovery.js +176 -98
  42. package/dist/src/arm/resource-analysis/http-resource-discovery.js.map +1 -1
  43. package/dist/src/arm/resource-analysis/types.d.ts +8 -2
  44. package/dist/src/arm/resource-analysis/types.d.ts.map +1 -1
  45. package/dist/src/arm/resource-analysis/types.js.map +1 -1
  46. package/dist/src/generation.d.ts.map +1 -1
  47. package/dist/src/generation.js +9 -12
  48. package/dist/src/generation.js.map +1 -1
  49. package/dist/src/lib.d.ts.map +1 -1
  50. package/dist/src/lib.js +3 -0
  51. package/dist/src/lib.js.map +1 -1
  52. package/dist/src/renders/components/resource/resource-class.js +1 -1
  53. package/dist/src/renders/components/resource/resource-class.js.map +1 -1
  54. package/dist/src/renders/components/resource/resource-source-file.d.ts.map +1 -1
  55. package/dist/src/renders/components/resource/resource-source-file.js +28 -19
  56. package/dist/src/renders/components/resource/resource-source-file.js.map +1 -1
  57. package/dist/src/renders/components/scaffold/azure-sdk-package-json.d.ts.map +1 -1
  58. package/dist/src/renders/components/scaffold/azure-sdk-package-json.js +1 -1
  59. package/dist/src/renders/components/scaffold/azure-sdk-package-json.js.map +1 -1
  60. package/dist/src/renders/components/scaffold/azure-sdk-scaffold.d.ts.map +1 -1
  61. package/dist/src/renders/components/scaffold/azure-sdk-scaffold.js +2 -1
  62. package/dist/src/renders/components/scaffold/azure-sdk-scaffold.js.map +1 -1
  63. package/dist/src/renders/ts-name-policy.js +1 -1
  64. package/dist/src/renders/ts-name-policy.js.map +1 -1
  65. package/dist/src/utils/refkey-utils.d.ts +7 -15
  66. package/dist/src/utils/refkey-utils.d.ts.map +1 -1
  67. package/dist/src/utils/refkey-utils.js +10 -17
  68. package/dist/src/utils/refkey-utils.js.map +1 -1
  69. package/dist/tsconfig.tsbuildinfo +1 -1
  70. package/package.json +1 -1
@@ -6,68 +6,78 @@
6
6
  * returned analysis in a separate stage.
7
7
  */
8
8
 
9
+ import { getNamespaceFullName } from "@typespec/compiler";
9
10
  import { $ as createTypekit } from "@typespec/compiler/typekit";
10
11
  import { logger } from "../../log/log.js";
11
- import { discoverArmResources } from "./http-resource-discovery.js";
12
+ import { discoverArmResourcesInNamespaces } from "./http-resource-discovery.js";
12
13
  import { discoverArmNamespace, discoverArmNamespaceByName } from "./namespace-discovery.js";
13
14
  import { inferArmUsage } from "./usage-inference.js";
14
15
  import { projectNamespaceToVersion } from "./version-projection.js";
15
16
 
16
- /**
17
- * Analyze a TypeSpec program and return the facts for one ARM namespace.
18
- *
19
- * Resources are discovered by walking every HTTP operation in the
20
- * program and grouping by ARM path (namespace + type segments). See
21
- * `./http-resource-discovery.ts`.
22
- *
23
- * When `targetNamespaceName` is provided (e.g. `"Compute"`, `"ComputeDisk"`),
24
- * only HTTP operations that belong to that TypeSpec namespace are analyzed.
25
- * Use this when a single compiled program unifies multiple sub-service
26
- * namespaces with independent `Versions` enums.
27
- */
28
- export function analyzeArmService(program, targetApiVersion, targetNamespaceName) {
29
- const discoveredNamespace = targetNamespaceName ? discoverArmNamespaceByName(program, targetNamespaceName) : discoverArmNamespace(program);
30
- if (!discoveredNamespace) {
31
- const hint = targetNamespaceName ? ` (looking for namespace "${targetNamespaceName}")` : "";
32
- throw new Error(`No ARM provider namespace found${hint}. Ensure the TypeSpec spec uses @armProviderNamespace.`);
33
- }
34
- const armProviderNamespace = discoveredNamespace.providerNamespace;
35
- const projected = projectNamespaceToVersion(program, discoveredNamespace.namespace, targetApiVersion);
36
- const discovered = discoverArmResources(program, armProviderNamespace, projected.namespace);
37
- logger.debug(`[analyze] discovery produced ${discovered.length} resources`, {
38
- area: "discovery",
39
- target: discoveredNamespace.namespace
17
+ /** Project every selection, then discover and link one shared resource tree. */
18
+ export function analyzeArmServices(program, selections) {
19
+ const projections = selections.map(selection => {
20
+ const discoveredNamespace = selection.namespace ? discoverArmNamespaceByName(program, selection.namespace) : discoverArmNamespace(program);
21
+ if (!discoveredNamespace) {
22
+ const hint = selection.namespace ? ` (looking for namespace "${selection.namespace}")` : "";
23
+ throw new Error(`No ARM provider namespace found${hint}. Ensure the TypeSpec spec uses @armProviderNamespace.`);
24
+ }
25
+ return {
26
+ ...projectNamespaceToVersion(program, discoveredNamespace.namespace, selection.version),
27
+ providerNamespace: discoveredNamespace.providerNamespace
28
+ };
40
29
  });
41
- for (const d of discovered) {
42
- const childNames = d.children.map(c => c.model.name).join(",");
43
- const writeLabel = d.writeMode === "body" ? d.createBodyModel?.name ?? "primary" : d.writeMode;
44
- logger.debug(` [disc] armType=${d.armType} model=${d.model.name} write=${writeLabel} parent=${d.parent?.model.name ?? "-"} singleton=${d.singletonName ?? "-"} children=[${childNames}]`, {
30
+ const discoveredByNamespace = discoverArmResourcesInNamespaces(program, projections.map(({
31
+ providerNamespace,
32
+ namespace
33
+ }) => ({
34
+ providerNamespace,
35
+ namespace
36
+ })));
37
+ const resources = new Map();
38
+ const namespaces = new Map(discoveredByNamespace.flatMap((discovered, index) => discovered.map(resource => [resource, projections[index].namespace])));
39
+ return projections.map((projected, index) => {
40
+ const discovered = discoveredByNamespace[index];
41
+ logger.debug(`[analyze] discovery produced ${discovered.length} resources`, {
45
42
  area: "discovery",
46
- target: d.model
43
+ target: projected.namespace
47
44
  });
48
- }
49
- if (discovered.length === 0) {
50
- throw new Error("No ARM resources found in the TypeSpec program.");
51
- }
52
- return {
53
- realm: projected.realm ?? createTypekit(program).realm,
54
- armProviderNamespace,
55
- apiVersion: projected.apiVersion,
56
- resources: discovered.filter(resource => !resource.parent).map(toResourceAnalysis),
57
- propertyUsage: inferArmUsage(program, discovered)
58
- };
45
+ for (const d of discovered) {
46
+ const childNames = d.children.map(c => c.model.name).join(",");
47
+ const writeLabel = d.writeMode === "body" ? d.createBodyModel?.name ?? "primary" : d.writeMode;
48
+ logger.debug(` [disc] armType=${d.armType} model=${d.model.name} write=${writeLabel} parent=${d.parent?.model.name ?? "-"} singleton=${d.singletonName ?? "-"} children=[${childNames}]`, {
49
+ area: "discovery",
50
+ target: d.model
51
+ });
52
+ }
53
+ if (discovered.length === 0) {
54
+ logger.info(`No ARM resources found in namespace '${getNamespaceFullName(projected.namespace)}' at API version '${projected.apiVersion}'.`);
55
+ }
56
+ const owned = new Set(discovered);
57
+ return {
58
+ namespace: projected.namespace,
59
+ realm: projected.realm ?? createTypekit(program).realm,
60
+ armProviderNamespace: projected.providerNamespace,
61
+ apiVersion: projected.apiVersion,
62
+ resources: discovered.filter(resource => !resource.parent || !owned.has(resource.parent)).map(resource => toResourceAnalysis(resource, resources, namespaces)),
63
+ propertyUsage: inferArmUsage(program, discovered)
64
+ };
65
+ });
59
66
  }
60
67
 
61
68
  // ---------------------------------------------------------------------------
62
69
  // Helpers
63
70
  // ---------------------------------------------------------------------------
64
71
 
65
- function toResourceAnalysis(resource) {
72
+ function toResourceAnalysis(resource, resources, namespaces) {
73
+ const cached = resources.get(resource);
74
+ if (cached) return cached;
66
75
  const operation = resource.lifecycle.create ?? resource.lifecycle.read;
67
76
  const terminalName = operation?.path.match(/\{([^}]+)\}\/?$/)?.[1];
68
77
  const namePropertyFromUriPath = terminalName === undefined ? undefined : operation?.parameters.parameters.find(parameter => parameter.type === "path" && parameter.name === terminalName)?.param;
69
78
  const nameSegments = resource.typeSegments.length - (resource.parent?.typeSegments.length ?? 0);
70
- return {
79
+ const analysis = {
80
+ namespace: namespaces.get(resource),
71
81
  model: resource.model,
72
82
  ...(namePropertyFromUriPath !== undefined ? {
73
83
  namePropertyFromUriPath
@@ -75,7 +85,7 @@ function toResourceAnalysis(resource) {
75
85
  ...(nameSegments > 1 ? {
76
86
  nameSegments
77
87
  } : {}),
78
- children: resource.children.map(toResourceAnalysis),
88
+ children: [],
79
89
  armType: resource.armType,
80
90
  ...(resource.resourceNames ? {
81
91
  resourceNames: resource.resourceNames
@@ -88,5 +98,11 @@ function toResourceAnalysis(resource) {
88
98
  singletonName: resource.singletonName
89
99
  } : {})
90
100
  };
101
+ resources.set(resource, analysis);
102
+ analysis.children = resource.children.map(child => toResourceAnalysis(child, resources, namespaces));
103
+ if (resource.parent) {
104
+ analysis.parent = toResourceAnalysis(resource.parent, resources, namespaces);
105
+ }
106
+ return analysis;
91
107
  }
92
108
  //# sourceMappingURL=analyzer.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["$","createTypekit","logger","discoverArmResources","discoverArmNamespace","discoverArmNamespaceByName","inferArmUsage","projectNamespaceToVersion","analyzeArmService","program","targetApiVersion","targetNamespaceName","discoveredNamespace","hint","Error","armProviderNamespace","providerNamespace","projected","namespace","discovered","debug","length","area","target","d","childNames","children","map","c","model","name","join","writeLabel","writeMode","createBodyModel","armType","parent","singletonName","realm","apiVersion","resources","filter","resource","toResourceAnalysis","propertyUsage","operation","lifecycle","create","read","terminalName","path","match","namePropertyFromUriPath","undefined","parameters","find","parameter","type","param","nameSegments","typeSegments","resourceNames","writeModel"],"sources":["../../../../src/arm/resource-analysis/analyzer.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,CAAC,IAAIC,aAAa,QAAQ,4BAA4B;AAC/D,SAASC,MAAM,QAAQ,kBAAkB;AAEzC,SACEC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,IAAI,KAAK,MAAM,IAAID,SAAS,CAAC1B,IAAI,KAAKmB,YACpD,CAAC,EAAES,KAAK;EACd,MAAMC,YAAY,GAChBjB,QAAQ,CAACkB,YAAY,CAACvC,MAAM,IAAIqB,QAAQ,CAACN,MAAM,EAAEwB,YAAY,CAACvC,MAAM,IAAI,CAAC,CAAC;EAC5E,OAAO;IACLQ,KAAK,EAAEa,QAAQ,CAACb,KAAK;IACrB,IAAIuB,uBAAuB,KAAKC,SAAS,GACrC;MAAED;IAAwB,CAAC,GAC3B,CAAC,CAAC,CAAC;IACP,IAAIO,YAAY,GAAG,CAAC,GAAG;MAAEA;IAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7CjC,QAAQ,EAAEgB,QAAQ,CAAChB,QAAQ,CAACC,GAAG,CAACgB,kBAAkB,CAAC;IACnDR,OAAO,EAAEO,QAAQ,CAACP,OAAO;IACzB,IAAIO,QAAQ,CAACmB,aAAa,GACtB;MAAEA,aAAa,EAAEnB,QAAQ,CAACmB;IAAc,CAAC,GACzC,CAAC,CAAC,CAAC;IACP,IAAInB,QAAQ,CAACR,eAAe,GACxB;MAAE4B,UAAU,EAAEpB,QAAQ,CAACR;IAAgB,CAAC,GACxC,CAAC,CAAC,CAAC;IACPD,SAAS,EAAES,QAAQ,CAACT,SAAS;IAC7B,IAAIS,QAAQ,CAACL,aAAa,GACtB;MAAEA,aAAa,EAAEK,QAAQ,CAACL;IAAc,CAAC,GACzC,CAAC,CAAC;EACR,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["getNamespaceFullName","$","createTypekit","logger","discoverArmResourcesInNamespaces","discoverArmNamespace","discoverArmNamespaceByName","inferArmUsage","projectNamespaceToVersion","analyzeArmServices","program","selections","projections","map","selection","discoveredNamespace","namespace","hint","Error","version","providerNamespace","discoveredByNamespace","resources","Map","namespaces","flatMap","discovered","index","resource","projected","debug","length","area","target","d","childNames","children","c","model","name","join","writeLabel","writeMode","createBodyModel","armType","parent","singletonName","info","apiVersion","owned","Set","realm","armProviderNamespace","filter","has","toResourceAnalysis","propertyUsage","cached","get","operation","lifecycle","create","read","terminalName","path","match","namePropertyFromUriPath","undefined","parameters","find","parameter","type","param","nameSegments","typeSegments","analysis","resourceNames","writeModel","set","child"],"sources":["../../../../src/arm/resource-analysis/analyzer.ts"],"sourcesContent":[null],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,oBAAoB,QAGf,oBAAoB;AAC3B,SAASC,CAAC,IAAIC,aAAa,QAAQ,4BAA4B;AAC/D,SAASC,MAAM,QAAQ,kBAAkB;AAEzC,SACEC,gCAAgC,QAE3B,8BAA8B;AACrC,SACEC,oBAAoB,EACpBC,0BAA0B,QACrB,0BAA0B;AACjC,SAASC,aAAa,QAAQ,sBAAsB;AACpD,SAASC,yBAAyB,QAAQ,yBAAyB;;AAEnE;AACA,OAAO,SAASC,kBAAkBA,CAChCC,OAAgB,EAChBC,UAGG,EACqB;EACxB,MAAMC,WAAW,GAAGD,UAAU,CAACE,GAAG,CAAEC,SAAS,IAAK;IAChD,MAAMC,mBAAmB,GAAGD,SAAS,CAACE,SAAS,GAC3CV,0BAA0B,CAACI,OAAO,EAAEI,SAAS,CAACE,SAAS,CAAC,GACxDX,oBAAoB,CAACK,OAAO,CAAC;IACjC,IAAI,CAACK,mBAAmB,EAAE;MACxB,MAAME,IAAI,GAAGH,SAAS,CAACE,SAAS,GAC5B,4BAA4BF,SAAS,CAACE,SAAS,IAAI,GACnD,EAAE;MACN,MAAM,IAAIE,KAAK,CACb,kCAAkCD,IAAI,wDACxC,CAAC;IACH;IACA,OAAO;MACL,GAAGT,yBAAyB,CAC1BE,OAAO,EACPK,mBAAmB,CAACC,SAAS,EAC7BF,SAAS,CAACK,OACZ,CAAC;MACDC,iBAAiB,EAAEL,mBAAmB,CAACK;IACzC,CAAC;EACH,CAAC,CAAC;EACF,MAAMC,qBAAqB,GAAGjB,gCAAgC,CAC5DM,OAAO,EACPE,WAAW,CAACC,G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CA,QAAQ,CAACvC,QAAQ,GAAGR,QAAQ,CAACQ,QAAQ,CAACvB,GAAG,CAAEkE,KAAK,IAC9CxB,kBAAkB,CAACwB,KAAK,EAAEzD,SAAS,EAAEE,UAAU,CACjD,CAAC;EACD,IAAII,QAAQ,CAACiB,MAAM,EAAE;IACnB8B,QAAQ,CAAC9B,MAAM,GAAGU,kBAAkB,CAClC3B,QAAQ,CAACiB,MAAM,EACfvB,SAAS,EACTE,UACF,CAAC;EACH;EACA,OAAOmD,QAAQ;AACjB","ignoreList":[]}
@@ -67,17 +67,15 @@ export interface DiscoveredArmResource {
67
67
  };
68
68
  }
69
69
  /**
70
- * Discover all ARM resources in a projected namespace that live under the
71
- * given provider namespace.
70
+ * Discover ARM resources in selected projected namespaces and link their shared tree.
72
71
  *
73
- * Only HTTP operations belonging to `namespace` or its descendants are
74
- * considered. The caller projects that namespace to the selected API version
75
- * before discovery, so unavailable and historically changed operations and
76
- * types have already been removed or rewritten by `@typespec/versioning`.
77
- *
78
- * The returned list contains every discovered resource (both top-level
79
- * and children). Parent/child relationships are populated on the
80
- * `parent` / `children` fields.
72
+ * Each selection contributes operations from its namespace and descendants.
73
+ * The caller projects each namespace to its selected API version before discovery.
74
+ * Results follow selection order; each list includes top-level and child resources
75
+ * with shared parent/children links.
81
76
  */
82
- export declare function discoverArmResources(program: Program, providerNamespace: string, namespace: Namespace): DiscoveredArmResource[];
77
+ export declare function discoverArmResourcesInNamespaces(program: Program, namespaces: readonly {
78
+ providerNamespace: string;
79
+ namespace: Namespace;
80
+ }[]): DiscoveredArmResource[][];
83
81
  //# sourceMappingURL=http-resource-discovery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http-resource-discovery.d.ts","sourceRoot":"","sources":["../../../../src/arm/resource-analysis/http-resource-discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAOH,OAAO,EAGL,KAAK,KAAK,EACV,KAAK,SAAS,EAEd,KAAK,O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,UAAU,EAAE,SAAS;IAAE,iBAAiB,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,EAAE,GACzE,qBAAqB,EAAE,EAAE,CA2C3B"}
@@ -29,6 +29,7 @@
29
29
 
30
30
  import { getArmResourceKind, getCustomResourceOptions, isAzureResource } from "@azure-tools/typespec-azure-resource-manager";
31
31
  import { getNamespaceFullName, isArrayModelType } from "@typespec/compiler";
32
+ import { $ as createTypekit } from "@typespec/compiler/typekit";
32
33
  import { listHttpOperationsIn } from "@typespec/http";
33
34
  import { logger } from "../../log/log.js";
34
35
 
@@ -47,27 +48,14 @@ import { logger } from "../../log/log.js";
47
48
  * as a name-discriminated variant set).
48
49
  */
49
50
 
50
- /**
51
- * Discover all ARM resources in a projected namespace that live under the
52
- * given provider namespace.
53
- *
54
- * Only HTTP operations belonging to `namespace` or its descendants are
55
- * considered. The caller projects that namespace to the selected API version
56
- * before discovery, so unavailable and historically changed operations and
57
- * types have already been removed or rewritten by `@typespec/versioning`.
58
- *
59
- * The returned list contains every discovered resource (both top-level
60
- * and children). Parent/child relationships are populated on the
61
- * `parent` / `children` fields.
62
- */
63
- export function discoverArmResources(program, providerNamespace, namespace) {
51
+ function discoverNamespaceRecords(program, providerNamespace, namespace) {
64
52
  const ops = collectOperations(program, namespace);
65
- const byInstancePath = bucketByInstancePath(ops, providerNamespace);
53
+ const byInstancePath = bucketByInstancePath(program, ops, providerNamespace);
66
54
 
67
55
  // Pass 1: build a mutable record per unique instance path.
68
56
  const records = new Map();
69
57
  for (const [key, bucket] of byInstancePath) {
70
- const record = buildRecord(bucket, providerNamespace);
58
+ const record = buildRecord(bucket, providerNamespace, namespace);
71
59
  if (!record) continue;
72
60
  // Filter to the ARM-resource surface. A record is kept iff it has a
73
61
  // PUT (writable resource) *or* a GET (readable resource). This matches
@@ -123,7 +111,7 @@ export function discoverArmResources(program, providerNamespace, namespace) {
123
111
  records.set(key, record);
124
112
  }
125
113
 
126
- // Pass 2: resolve parent/child pointers by armType prefix.
114
+ // Deduplicate within each projected namespace before linking the full batch.
127
115
  // Key by (armType, singletonName) — this matches Bicep's
128
116
  // `getFullyQualifiedType(descriptor)` grouping and the .NET provisioning
129
117
  // generator's one-class-per-parent-chain model. The same TypeSpec Model
@@ -142,16 +130,33 @@ export function discoverArmResources(program, providerNamespace, namespace) {
142
130
  byArmTypeAndSingleton.set(key, record);
143
131
  }
144
132
  }
145
- const deduped = new Set(byArmTypeAndSingleton.values());
146
- const result = [];
133
+ return [...byArmTypeAndSingleton.values()];
134
+ }
135
+
136
+ /**
137
+ * Discover ARM resources in selected projected namespaces and link their shared tree.
138
+ *
139
+ * Each selection contributes operations from its namespace and descendants.
140
+ * The caller projects each namespace to its selected API version before discovery.
141
+ * Results follow selection order; each list includes top-level and child resources
142
+ * with shared parent/children links.
143
+ */
144
+ export function discoverArmResourcesInNamespaces(program, namespaces) {
145
+ const records = namespaces.map(({
146
+ providerNamespace,
147
+ namespace
148
+ }) => discoverNamespaceRecords(program, providerNamespace, namespace));
149
+ const byArmType = new Map();
150
+ for (const record of records.flat()) {
151
+ const key = record.armType.toLowerCase();
152
+ const entries = byArmType.get(key);
153
+ if (entries) entries.push(record);else byArmType.set(key, [record]);
154
+ }
147
155
  const resolved = new Map();
148
156
  const finalize = record => {
149
157
  const cached = resolved.get(record);
150
158
  if (cached) return cached;
151
- const parent = findParentRecord(record, byArmTypeAndSingleton);
152
- // Only attach a parent pointer if the parent survived deduplication;
153
- // otherwise promote this record to top-level.
154
- const parentInUse = parent && deduped.has(parent) ? parent : undefined;
159
+ const parent = findParentRecord(record, byArmType);
155
160
  // Stub insert before recursing into parent so we can build the
156
161
  // `children` array afterwards in a second pass.
157
162
  const resource = {
@@ -168,18 +173,14 @@ export function discoverArmResources(program, providerNamespace, namespace) {
168
173
  lifecycle: record.lifecycle
169
174
  };
170
175
  resolved.set(record, resource);
171
- if (parentInUse) {
172
- const parentResource = finalize(parentInUse);
176
+ if (parent) {
177
+ const parentResource = finalize(parent);
173
178
  resource.parent = parentResource;
174
179
  parentResource.children.push(resource);
175
180
  }
176
181
  return resource;
177
182
  };
178
- for (const record of deduped) {
179
- const resource = finalize(record);
180
- result.push(resource);
181
- }
182
- return result;
183
+ return records.map(entries => entries.map(finalize));
183
184
  }
184
185
  function getExplicitLifecycleResourceNames(lifecycle) {
185
186
  const names = [lifecycle.create, lifecycle.update, lifecycle.read].flatMap(operation => {
@@ -211,34 +212,106 @@ function getExplicitResourceName(operation) {
211
212
  // Internals
212
213
  // ---------------------------------------------------------------------------
213
214
 
214
- function parsePath(path, providerNamespace, operation) {
215
+ function getTypeSegmentChoices(program, type) {
216
+ const typekit = createTypekit(program);
217
+ const values = new Map();
218
+ const active = new Set();
219
+ const visited = new Set();
220
+ let error;
221
+ const addValue = value => {
222
+ if (typeof value !== "string") {
223
+ error = "contains a non-string value";
224
+ } else if (value.length === 0 || value === "." || value === ".." || /[/\\?#{}\s]/u.test(value)) {
225
+ error = `contains invalid path segment ${JSON.stringify(value)}`;
226
+ } else if (!values.has(value.toLowerCase())) {
227
+ values.set(value.toLowerCase(), value);
228
+ }
229
+ };
230
+ const visit = current => {
231
+ if (error || visited.has(current)) return;
232
+ if (active.has(current)) {
233
+ error = "contains a recursive type definition";
234
+ return;
235
+ }
236
+ active.add(current);
237
+ switch (current.kind) {
238
+ case "String":
239
+ addValue(current.value);
240
+ break;
241
+ case "Enum":
242
+ for (const member of current.members.values()) {
243
+ addValue(member.value ?? member.name);
244
+ if (error) break;
245
+ }
246
+ break;
247
+ case "EnumMember":
248
+ addValue(current.value ?? current.name);
249
+ break;
250
+ case "Union":
251
+ for (const variant of current.variants.values()) {
252
+ visit(variant.type);
253
+ if (error) break;
254
+ }
255
+ break;
256
+ case "UnionVariant":
257
+ visit(current.type);
258
+ break;
259
+ case "Scalar":
260
+ // Extensible enums contribute their declared choices, not a wildcard.
261
+ if (!typekit.scalar.extendsString(current)) {
262
+ error = "contains a non-string scalar";
263
+ }
264
+ break;
265
+ default:
266
+ error = `contains unsupported type kind '${current.kind}'`;
267
+ }
268
+ active.delete(current);
269
+ visited.add(current);
270
+ };
271
+ visit(type);
272
+ if (error) return {
273
+ error
274
+ };
275
+ return values.size > 0 ? {
276
+ values: [...values.values()]
277
+ } : {
278
+ error: "does not declare any string choices"
279
+ };
280
+ }
281
+ function parsePaths(program, operation, providerNamespace) {
282
+ const path = operation.path;
215
283
  // Normalise: strip query string and leading/trailing slashes.
216
284
  const clean = path.split("?")[0].replace(/\/+$/, "");
217
285
  // Find the LAST `/providers/<ns>/` segment (extension resources embed the
218
286
  // scope path first and the provider path second).
219
287
  const target = `/providers/${providerNamespace}/`;
220
288
  const idx = clean.toLowerCase().lastIndexOf(target.toLowerCase());
221
- if (idx === -1) return undefined;
289
+ if (idx === -1) return [];
222
290
  const rest = clean.slice(idx + target.length);
223
- if (!rest) return undefined;
291
+ if (!rest) return [];
224
292
  const segs = rest.split("/");
225
- const typeSegments = [];
293
+ let typeAlternatives = [[]];
226
294
  const names = [];
227
295
  for (let i = 0; i < segs.length; i++) {
228
296
  const seg = segs[i];
229
- if (!seg) return undefined;
297
+ if (!seg) return [];
230
298
  if (i % 2 === 0) {
231
- // Type position — must be a literal segment, not a template variable.
232
- // Following Bicep's approach: if a type-position segment is a
233
- // template variable (e.g. "{keyType}") that isn't an enum, the path
234
- // doesn't represent a valid ARM resource type. Skip it.
235
299
  if (seg.startsWith("{") && seg.endsWith("}")) {
236
- logger.warning(`[resource-discovery] Skipping path with template variable "${seg}" ` + `in type position: ${path}`, {
237
- target: operation
238
- });
239
- return undefined;
300
+ const parameterName = seg.slice(1, -1);
301
+ const parameter = operation.parameters.parameters.find(parameter => parameter.type === "path" && parameter.name === parameterName);
302
+ const choices = parameter ? getTypeSegmentChoices(program, parameter.param.type) : {
303
+ error: "has no matching HTTP path parameter"
304
+ };
305
+ if ("error" in choices) {
306
+ logger.warning(`[resource-discovery] Skipping path '${path}': cannot expand ` + `type parameter '${parameterName}': ${choices.error}.`, {
307
+ target: parameter?.param ?? operation.operation
308
+ });
309
+ return [];
310
+ }
311
+ typeAlternatives = typeAlternatives.flatMap(segments => choices.values.map(value => [...segments, value]));
312
+ } else {
313
+ typeAlternatives = typeAlternatives.map(segments => [...segments, seg]);
240
314
  }
241
- typeSegments.push(seg);
242
315
  } else {
243
316
  // Name position.
244
317
  if (seg.startsWith("{") && seg.endsWith("}")) {
@@ -254,12 +327,12 @@ function parsePath(path, providerNamespace, operation) {
254
327
  }
255
328
  }
256
329
  }
257
- return {
330
+ return typeAlternatives.map(typeSegments => ({
258
331
  namespace: providerNamespace,
259
332
  typeSegments,
260
- names,
333
+ names: [...names],
261
334
  isInstancePath: segs.length % 2 === 0
262
- };
335
+ }));
263
336
  }
264
337
 
265
338
  /** Derive a case-insensitive instance-path key for deduping ops across api-versions / clients. */
@@ -274,62 +347,59 @@ function instancePathKey(parsed) {
274
347
  }
275
348
  return `${parsed.namespace.toLowerCase()}/${parts.join("/")}`;
276
349
  }
277
- function bucketByInstancePath(ops, providerNamespace) {
350
+ function bucketByInstancePath(program, ops, providerNamespace) {
278
351
  // Each bucket holds ops sharing the same (type/name...) identity. Instance
279
352
  // ops go under the instance key. Collection ops (odd-length, missing final
280
353
  // name) go under the key of their parent-type instance path with an
281
354
  // implicit `{}` final name — they contribute list ops to the instance bucket.
282
355
  const buckets = new Map();
283
356
  for (const op of ops) {
284
- const parsed = parsePath(op.path, providerNamespace, op.operation);
285
- if (!parsed || parsed.typeSegments.length === 0) continue;
286
- if (parsed.isInstancePath) {
287
- const key = instancePathKey(parsed);
288
- let bucket = buckets.get(key);
289
- if (!bucket) {
290
- bucket = {
291
- parsed,
292
- ops: []
293
- };
294
- buckets.set(key, bucket);
295
- }
296
- bucket.ops.push({
297
- op,
298
- fromCollectionPath: false
299
- });
300
- } else {
301
- // Collection path (e.g. GET /.../storageAccounts). Treat as a list op
302
- // on the instance bucket with an implicit `{}` final name.
303
- if (op.verb !== "get") continue;
304
- const syntheticInstance = {
305
- ...parsed,
306
- names: [...parsed.names, {
307
- kind: "var",
308
- name: "__list"
309
- }],
310
- isInstancePath: true
311
- };
312
- const key = instancePathKey(syntheticInstance);
313
- let bucket = buckets.get(key);
314
- if (!bucket) {
315
- // No matching instance path — synthesise a bucket so list-only
316
- // discovery is possible. The bucket's `parsed` still records this
317
- // as instance-path so downstream uniformly reads typeSegments.
318
- bucket = {
319
- parsed: syntheticInstance,
320
- ops: []
357
+ for (const parsed of parsePaths(program, op, providerNamespace)) {
358
+ if (parsed.typeSegments.length === 0) continue;
359
+ if (parsed.isInstancePath) {
360
+ const key = instancePathKey(parsed);
361
+ let bucket = buckets.get(key);
362
+ if (!bucket) {
363
+ bucket = {
364
+ parsed,
365
+ ops: []
366
+ };
367
+ buckets.set(key, bucket);
368
+ }
369
+ bucket.ops.push({
370
+ op,
371
+ fromCollectionPath: false
372
+ });
373
+ } else {
374
+ // Collection paths contribute list operations, not point reads.
375
+ if (op.verb !== "get") continue;
376
+ const syntheticInstance = {
377
+ ...parsed,
378
+ names: [...parsed.names, {
379
+ kind: "var",
380
+ name: "__list"
381
+ }],
382
+ isInstancePath: true
321
383
  };
322
- buckets.set(key, bucket);
384
+ const key = instancePathKey(syntheticInstance);
385
+ let bucket = buckets.get(key);
386
+ if (!bucket) {
387
+ bucket = {
388
+ parsed: syntheticInstance,
389
+ ops: []
390
+ };
391
+ buckets.set(key, bucket);
392
+ }
393
+ bucket.ops.push({
394
+ op,
395
+ fromCollectionPath: true
396
+ });
323
397
  }
324
- bucket.ops.push({
325
- op,
326
- fromCollectionPath: true
327
- });
328
398
  }
329
399
  }
330
400
  return buckets;
331
401
  }
332
- function buildRecord(bucket, providerNamespace) {
402
+ function buildRecord(bucket, providerNamespace, sourceNamespace) {
333
403
  const {
334
404
  parsed
335
405
  } = bucket;
@@ -417,6 +487,7 @@ function buildRecord(bucket, providerNamespace) {
417
487
  }
418
488
  const armType = `${providerNamespace}/${parsed.typeSegments.join("/")}`;
419
489
  return {
490
+ sourceNamespace,
420
491
  model,
421
492
  armType,
422
493
  namespace: providerNamespace,
@@ -602,7 +673,7 @@ function unwrapArrayIfNeeded(model) {
602
673
  function unwrapListIfNeeded(model) {
603
674
  return unwrapArrayIfNeeded(unwrapPagedIfNeeded(model));
604
675
  }
605
- function findParentRecord(record, byArmTypeAndSingleton) {
676
+ function findParentRecord(record, byArmType) {
606
677
  if (record.typeSegments.length <= 1) return undefined;
607
678
  // Walk up the type-segment chain looking for the nearest ancestor that
608
679
  // is itself a discovered record. Intermediate types are sometimes absent
@@ -619,13 +690,20 @@ function findParentRecord(record, byArmTypeAndSingleton) {
619
690
  // Prefer a collection-child parent (no singletonName) — singleton
620
691
  // parents (e.g. `blobServices/default`) are valid but the collection
621
692
  // form is canonical when both exist.
622
- let fallback;
623
- for (const candidate of byArmTypeAndSingleton.values()) {
624
- if (candidate.armType.toLowerCase() !== parentArmType) continue;
625
- if (!candidate.singletonName) return candidate;
626
- fallback = candidate;
693
+ // TODO: we need to support multiple parent in some way
694
+ // tracked by #660,661
695
+ const candidates = byArmType.get(parentArmType);
696
+ if (!candidates) continue;
697
+ const local = candidates.filter(candidate => candidate.sourceNamespace === record.sourceNamespace);
698
+ if (local.length > 0) {
699
+ return local.find(candidate => !candidate.singletonName) ?? local.at(-1);
700
+ }
701
+ const collections = candidates.filter(candidate => !candidate.singletonName);
702
+ const eligible = collections.length > 0 ? collections : candidates;
703
+ if (eligible.length > 1) {
704
+ throw new Error(`Resource '${record.armType}' has ambiguous parent '${eligible[0].armType}' in namespaces: ` + eligible.map(candidate => getNamespaceFullName(candidate.sourceNamespace)).join(", ") + ".");
627
705
  }
628
- if (fallback) return fallback;
706
+ return eligible[0];
629
707
  }
630
708
  return undefined;
631
709
  }