@azure-tools/typespec-azure-resource-manager 0.72.0-dev.0 → 0.72.0-dev.10
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/README.md +6 -0
- package/dist/src/linter.d.ts.map +1 -1
- package/dist/src/linter.js +12 -0
- package/dist/src/linter.js.map +1 -1
- package/dist/src/operations.d.ts +1 -1
- package/dist/src/operations.d.ts.map +1 -1
- package/dist/src/operations.js +6 -6
- package/dist/src/operations.js.map +1 -1
- package/dist/src/resource.d.ts +10 -6
- package/dist/src/resource.d.ts.map +1 -1
- package/dist/src/resource.js +267 -162
- package/dist/src/resource.js.map +1 -1
- package/dist/src/rules/arm-feature-file-usage-discourage.js +1 -1
- package/dist/src/rules/arm-feature-file-usage-discourage.js.map +1 -1
- package/dist/src/rules/list-operation-missing-pageable.d.ts +4 -0
- package/dist/src/rules/list-operation-missing-pageable.d.ts.map +1 -0
- package/dist/src/rules/list-operation-missing-pageable.js +45 -0
- package/dist/src/rules/list-operation-missing-pageable.js.map +1 -0
- package/dist/src/rules/list-response-envelope.d.ts +4 -0
- package/dist/src/rules/list-response-envelope.d.ts.map +1 -0
- package/dist/src/rules/list-response-envelope.js +94 -0
- package/dist/src/rules/list-response-envelope.js.map +1 -0
- package/dist/src/rules/lro-response-mismatch.d.ts +11 -0
- package/dist/src/rules/lro-response-mismatch.d.ts.map +1 -0
- package/dist/src/rules/lro-response-mismatch.js +265 -0
- package/dist/src/rules/lro-response-mismatch.js.map +1 -0
- package/dist/src/rules/no-query-in-collection.d.ts +4 -0
- package/dist/src/rules/no-query-in-collection.d.ts.map +1 -0
- package/dist/src/rules/no-query-in-collection.js +43 -0
- package/dist/src/rules/no-query-in-collection.js.map +1 -0
- package/dist/src/rules/no-query-in-point-op.d.ts +4 -0
- package/dist/src/rules/no-query-in-point-op.d.ts.map +1 -0
- package/dist/src/rules/no-query-in-point-op.js +50 -0
- package/dist/src/rules/no-query-in-point-op.js.map +1 -0
- package/dist/src/rules/use-application-json-content-type.d.ts +4 -0
- package/dist/src/rules/use-application-json-content-type.d.ts.map +1 -0
- package/dist/src/rules/use-application-json-content-type.js +59 -0
- package/dist/src/rules/use-application-json-content-type.js.map +1 -0
- package/dist/src/rules/utils.d.ts +4 -0
- package/dist/src/rules/utils.d.ts.map +1 -1
- package/dist/src/rules/utils.js +11 -0
- package/dist/src/rules/utils.js.map +1 -1
- package/lib/common-types/billing-data.tsp +1 -1
- package/lib/models.tsp +2 -2
- package/lib/parameters.tsp +3 -6
- package/lib/responses.tsp +4 -5
- package/package.json +12 -12
package/dist/src/resource.js
CHANGED
|
@@ -393,7 +393,7 @@ function getResourceScope(knownResources, resource, resourcesToProcess) {
|
|
|
393
393
|
return undefined;
|
|
394
394
|
}
|
|
395
395
|
function isVariableSegment(segment) {
|
|
396
|
-
return
|
|
396
|
+
return segment.startsWith("{") && segment.endsWith("}");
|
|
397
397
|
}
|
|
398
398
|
/**
|
|
399
399
|
* Extracts the scope prefix from a resource instance path.
|
|
@@ -418,149 +418,210 @@ function normalizePathForScopeComparison(path) {
|
|
|
418
418
|
.map((s) => (isVariableSegment(s) ? "{}" : s.toLowerCase()))
|
|
419
419
|
.join("/");
|
|
420
420
|
}
|
|
421
|
-
function
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
421
|
+
function normalizePathForResourceIdentity(path) {
|
|
422
|
+
return path
|
|
423
|
+
.split("/")
|
|
424
|
+
.map((s) => (isVariableSegment(s) ? "{}" : s.toLowerCase()))
|
|
425
|
+
.join("/");
|
|
426
|
+
}
|
|
427
|
+
function trimScopePrefix(path) {
|
|
428
|
+
const scopePrefix = getScopePrefix(path);
|
|
429
|
+
return scopePrefix === "" ? path : path.slice(scopePrefix.length);
|
|
430
|
+
}
|
|
431
|
+
function isResourceIdentityOperation(kind) {
|
|
432
|
+
return kind === "read" || kind === "createOrUpdate";
|
|
433
|
+
}
|
|
434
|
+
function isInstanceLifecycleOperation(kind) {
|
|
435
|
+
switch (kind) {
|
|
436
|
+
case "read":
|
|
437
|
+
case "createOrUpdate":
|
|
438
|
+
case "update":
|
|
439
|
+
case "delete":
|
|
440
|
+
case "checkExistence":
|
|
441
|
+
return true;
|
|
442
|
+
default:
|
|
443
|
+
return false;
|
|
429
444
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
const fallback = getResourceInfoFromArmOperation(program, operation.httpOperation.path, operation.kind, operation.operation, resourceModel);
|
|
435
|
-
if (fallback === undefined)
|
|
445
|
+
}
|
|
446
|
+
function getResourceInfo(operation) {
|
|
447
|
+
const pathInfo = parseArmResourceInstancePath(operation.httpOperation.path);
|
|
448
|
+
if (pathInfo === undefined)
|
|
436
449
|
return undefined;
|
|
437
450
|
return {
|
|
438
|
-
...
|
|
451
|
+
...pathInfo,
|
|
439
452
|
resourceName: operation.resourceName ?? operation.operationGroup,
|
|
440
453
|
};
|
|
441
454
|
}
|
|
442
|
-
export function
|
|
455
|
+
export function parseArmResourceInstancePath(path) {
|
|
443
456
|
const segments = path.split("/").filter((s) => s.length > 0);
|
|
444
457
|
const providerIndex = segments.findLastIndex((s) => s === "providers");
|
|
445
|
-
if (providerIndex === -1
|
|
458
|
+
if (providerIndex === -1) {
|
|
459
|
+
return parseKnownProviderlessResourcePath(path, segments);
|
|
460
|
+
}
|
|
461
|
+
if (providerIndex === segments.length - 1)
|
|
446
462
|
return undefined;
|
|
447
463
|
const provider = segments[providerIndex + 1];
|
|
464
|
+
if (isVariableSegment(provider))
|
|
465
|
+
return undefined;
|
|
466
|
+
const resourceSegments = segments.slice(providerIndex + 2);
|
|
467
|
+
if (resourceSegments.length === 0 || resourceSegments.length % 2 !== 0)
|
|
468
|
+
return undefined;
|
|
448
469
|
const typeSegments = [];
|
|
449
470
|
const instanceSegments = segments.slice(0, providerIndex + 2);
|
|
450
|
-
for (let i =
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
switch (kind) {
|
|
461
|
-
case "list":
|
|
462
|
-
typeSegments.push(segments[i]);
|
|
463
|
-
instanceSegments.push(segments[i]);
|
|
464
|
-
instanceSegments.push("{name}");
|
|
465
|
-
break;
|
|
466
|
-
default:
|
|
467
|
-
break;
|
|
468
|
-
}
|
|
469
|
-
break;
|
|
470
|
-
}
|
|
471
|
+
for (let i = 0; i < resourceSegments.length; i += 2) {
|
|
472
|
+
const typeSegment = resourceSegments[i];
|
|
473
|
+
const nameSegment = resourceSegments[i + 1];
|
|
474
|
+
if (typeSegment === undefined || nameSegment === undefined)
|
|
475
|
+
return undefined;
|
|
476
|
+
if (isVariableSegment(typeSegment))
|
|
477
|
+
return undefined;
|
|
478
|
+
typeSegments.push(typeSegment);
|
|
479
|
+
instanceSegments.push(typeSegment);
|
|
480
|
+
instanceSegments.push(nameSegment);
|
|
471
481
|
}
|
|
472
|
-
|
|
482
|
+
return {
|
|
483
|
+
resourceType: {
|
|
484
|
+
provider: provider,
|
|
485
|
+
types: typeSegments,
|
|
486
|
+
},
|
|
487
|
+
resourceInstancePath: `/${instanceSegments.join("/")}`,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function parseKnownProviderlessResourcePath(path, segments) {
|
|
491
|
+
if (segments.length === 0) {
|
|
473
492
|
return {
|
|
474
493
|
resourceType: {
|
|
475
|
-
provider:
|
|
476
|
-
types:
|
|
494
|
+
provider: "Microsoft.Resources",
|
|
495
|
+
types: ["tenants"],
|
|
496
|
+
},
|
|
497
|
+
resourceInstancePath: "/",
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
if (segments.length === 2 &&
|
|
501
|
+
segments[0].toLowerCase() === "subscriptions" &&
|
|
502
|
+
isVariableSegment(segments[1])) {
|
|
503
|
+
return {
|
|
504
|
+
resourceType: {
|
|
505
|
+
provider: "Microsoft.Resources",
|
|
506
|
+
types: ["subscriptions"],
|
|
507
|
+
},
|
|
508
|
+
resourceInstancePath: `/${segments.join("/")}`,
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
if (segments.length === 4 &&
|
|
512
|
+
segments[0].toLowerCase() === "subscriptions" &&
|
|
513
|
+
isVariableSegment(segments[1]) &&
|
|
514
|
+
segments[2].toLowerCase() === "resourcegroups" &&
|
|
515
|
+
isVariableSegment(segments[3])) {
|
|
516
|
+
return {
|
|
517
|
+
resourceType: {
|
|
518
|
+
provider: "Microsoft.Resources",
|
|
519
|
+
types: ["resourceGroups"],
|
|
520
|
+
},
|
|
521
|
+
resourceInstancePath: `/${segments.join("/")}`,
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
if (segments.length === 1 && isVariableSegment(segments[0])) {
|
|
525
|
+
return {
|
|
526
|
+
resourceType: {
|
|
527
|
+
provider: "",
|
|
528
|
+
types: [],
|
|
477
529
|
},
|
|
478
|
-
resourceInstancePath:
|
|
530
|
+
resourceInstancePath: path,
|
|
479
531
|
};
|
|
480
532
|
}
|
|
481
533
|
return undefined;
|
|
482
534
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
535
|
+
function isListOperationPrefixMatch(operation, resource) {
|
|
536
|
+
const operationPath = normalizePathForResourceIdentity(operation.httpOperation.path);
|
|
537
|
+
const resourcePath = normalizePathForResourceIdentity(resource.resourceInstancePath);
|
|
538
|
+
return resourcePath.startsWith(`${operationPath}/`);
|
|
539
|
+
}
|
|
540
|
+
function isListOperationResourceTypeMatch(operation, resource) {
|
|
541
|
+
const operationPath = normalizePathForResourceIdentity(operation.httpOperation.path);
|
|
542
|
+
const resourcePath = normalizePathForResourceIdentity(resource.resourceInstancePath);
|
|
543
|
+
return isSameResourceTypePath(operationPath, resourcePath);
|
|
544
|
+
}
|
|
545
|
+
function getListMatchDistance(operation, resource) {
|
|
546
|
+
const operationPath = trimScopePrefix(normalizePathForResourceIdentity(operation.httpOperation.path));
|
|
547
|
+
const resourcePath = trimScopePrefix(normalizePathForResourceIdentity(resource.resourceInstancePath));
|
|
548
|
+
return resourcePath.length - operationPath.length;
|
|
549
|
+
}
|
|
550
|
+
function isSameResourceTypePath(leftPath, rightPath) {
|
|
551
|
+
const left = parseArmResourceCollectionPath(leftPath);
|
|
552
|
+
const right = parseArmResourceInstancePath(rightPath)?.resourceType;
|
|
553
|
+
if (left === undefined || right === undefined)
|
|
554
|
+
return false;
|
|
555
|
+
return (left.provider.toLowerCase() === right.provider.toLowerCase() &&
|
|
556
|
+
left.types.map((x) => x.toLowerCase()).join("/") ===
|
|
557
|
+
right.types.map((x) => x.toLowerCase()).join("/"));
|
|
558
|
+
}
|
|
559
|
+
function parseArmResourceCollectionPath(path) {
|
|
495
560
|
const segments = path.split("/").filter((s) => s.length > 0);
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (!isVariableSegment(segments[i])) {
|
|
502
|
-
if (i + 1 < segments.length && isVariableSegment(segments[i + 1])) {
|
|
503
|
-
// Non-variable followed by variable: this is a resource type/instance pair
|
|
504
|
-
resourceTypeIndex = i;
|
|
505
|
-
}
|
|
506
|
-
else if (i + 1 === segments.length && kind === "list") {
|
|
507
|
-
// Terminal non-variable segment in a list operation: this is the resource type
|
|
508
|
-
resourceTypeIndex = i;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
if (resourceTypeIndex === -1) {
|
|
513
|
-
// For generic resources, the path may consist entirely of variable segments
|
|
514
|
-
// (e.g. /{resourceId}). Use the raw path as the instance path.
|
|
515
|
-
if (segments.length > 0 && segments.every((s) => isVariableSegment(s))) {
|
|
516
|
-
return {
|
|
517
|
-
resourceType: {
|
|
518
|
-
provider: provider,
|
|
519
|
-
types: [],
|
|
520
|
-
},
|
|
521
|
-
resourceInstancePath: path,
|
|
522
|
-
};
|
|
523
|
-
}
|
|
561
|
+
const providerIndex = segments.findLastIndex((s) => s.toLowerCase() === "providers");
|
|
562
|
+
if (providerIndex === -1 || providerIndex === segments.length - 1)
|
|
563
|
+
return undefined;
|
|
564
|
+
const provider = segments[providerIndex + 1];
|
|
565
|
+
if (isVariableSegment(provider))
|
|
524
566
|
return undefined;
|
|
567
|
+
const resourceSegments = segments.slice(providerIndex + 2);
|
|
568
|
+
if (resourceSegments.length === 0)
|
|
569
|
+
return undefined;
|
|
570
|
+
const types = [];
|
|
571
|
+
for (let i = 0; i < resourceSegments.length; i += 2) {
|
|
572
|
+
const typeSegment = resourceSegments[i];
|
|
573
|
+
if (typeSegment === undefined || isVariableSegment(typeSegment))
|
|
574
|
+
return undefined;
|
|
575
|
+
types.push(typeSegment);
|
|
525
576
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
// Derive instance path variable name from the resource model's @key property
|
|
539
|
-
let keyPropName;
|
|
540
|
-
for (const [, prop] of resourceModel.properties) {
|
|
541
|
-
const keyName = getKeyName(program, prop);
|
|
542
|
-
if (keyName !== undefined) {
|
|
543
|
-
keyPropName = keyName;
|
|
544
|
-
break;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
if (keyPropName) {
|
|
548
|
-
instanceSegments.push(`{${keyPropName}}`);
|
|
577
|
+
return { provider, types };
|
|
578
|
+
}
|
|
579
|
+
function getBestListOperationTarget(operation, resources) {
|
|
580
|
+
let best;
|
|
581
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
582
|
+
for (const resource of resources) {
|
|
583
|
+
if (!isListOperationPrefixMatch(operation, resource))
|
|
584
|
+
continue;
|
|
585
|
+
const distance = getListMatchDistance(operation, resource);
|
|
586
|
+
if (distance < bestDistance) {
|
|
587
|
+
best = resource;
|
|
588
|
+
bestDistance = distance;
|
|
549
589
|
}
|
|
550
|
-
|
|
551
|
-
|
|
590
|
+
}
|
|
591
|
+
if (best !== undefined)
|
|
592
|
+
return best;
|
|
593
|
+
// TODO: https://github.com/Azure/typespec-azure/issues/5080
|
|
594
|
+
// Define the complete rule for associating list operations with detected resources.
|
|
595
|
+
// Some ARM resources expose list operations at scopes different from the resource identity,
|
|
596
|
+
// e.g. a resource-group-scoped resource can have subscription- or tenant-level list operations.
|
|
597
|
+
// Direct prefix matching handles list-by-parent paths; concrete provider/type equality handles
|
|
598
|
+
// cross-scope list paths without letting list operations create resource identities.
|
|
599
|
+
for (const resource of resources) {
|
|
600
|
+
if (isListOperationResourceTypeMatch(operation, resource))
|
|
601
|
+
return resource;
|
|
602
|
+
}
|
|
603
|
+
return undefined;
|
|
604
|
+
}
|
|
605
|
+
function isActionOperationMatch(operation, resource) {
|
|
606
|
+
const operationPath = normalizePathForResourceIdentity(operation.httpOperation.path);
|
|
607
|
+
const instancePath = normalizePathForResourceIdentity(resource.resourceInstancePath);
|
|
608
|
+
return operationPath.startsWith(`${instancePath}/`);
|
|
609
|
+
}
|
|
610
|
+
function tryAddOperationToResolvedResource(candidate, target) {
|
|
611
|
+
const { armOperation, resourceInfo } = candidate;
|
|
612
|
+
if (isInstanceLifecycleOperation(armOperation.kind)) {
|
|
613
|
+
if (resourceInfo !== undefined && isResourceIdentityMatch(resourceInfo, target)) {
|
|
614
|
+
tryAddLifecycleOperation(target.resourceType, armOperation, target);
|
|
552
615
|
}
|
|
616
|
+
return;
|
|
553
617
|
}
|
|
554
|
-
|
|
555
|
-
|
|
618
|
+
if (armOperation.kind === "action" && isActionOperationMatch(armOperation, target)) {
|
|
619
|
+
tryAddLifecycleOperation(target.resourceType, armOperation, target);
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
if (armOperation.kind === "other") {
|
|
623
|
+
addAssociatedOperation(armOperation, target);
|
|
556
624
|
}
|
|
557
|
-
return {
|
|
558
|
-
resourceType: {
|
|
559
|
-
provider: provider,
|
|
560
|
-
types: typeSegments,
|
|
561
|
-
},
|
|
562
|
-
resourceInstancePath: `/${instanceSegments.join("/")}`,
|
|
563
|
-
};
|
|
564
625
|
}
|
|
565
626
|
function tryAddLifecycleOperation(resourceType, sourceOperation, targetResource) {
|
|
566
627
|
const opType = sourceOperation.kind;
|
|
@@ -628,6 +689,22 @@ export function isResourceOperationMatch(source, target) {
|
|
|
628
689
|
}
|
|
629
690
|
return true;
|
|
630
691
|
}
|
|
692
|
+
function isResourceIdentityMatch(source, target) {
|
|
693
|
+
if (source.resourceName &&
|
|
694
|
+
target.resourceName &&
|
|
695
|
+
source.resourceName.toLowerCase() !== target.resourceName.toLowerCase())
|
|
696
|
+
return false;
|
|
697
|
+
if (source.resourceType.provider.toLowerCase() !== target.resourceType.provider.toLowerCase())
|
|
698
|
+
return false;
|
|
699
|
+
if (source.resourceType.types.length !== target.resourceType.types.length)
|
|
700
|
+
return false;
|
|
701
|
+
for (let i = 0; i < source.resourceType.types.length; i++) {
|
|
702
|
+
if (source.resourceType.types[i].toLowerCase() !== target.resourceType.types[i].toLowerCase())
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
return (normalizePathForResourceIdentity(source.resourceInstancePath) ===
|
|
706
|
+
normalizePathForResourceIdentity(target.resourceInstancePath));
|
|
707
|
+
}
|
|
631
708
|
export function getUnassociatedOperations(program) {
|
|
632
709
|
return getAllOperations(program)
|
|
633
710
|
.map((op) => getResourceOperation(program, op))
|
|
@@ -694,63 +771,43 @@ function addUniqueOperation(operation, operations) {
|
|
|
694
771
|
}
|
|
695
772
|
export function resolveArmResourceOperations(program, resourceType) {
|
|
696
773
|
const resolvedOperations = new Set();
|
|
697
|
-
const
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
774
|
+
const candidates = [...getArmResourceOperationList(program, resourceType)]
|
|
775
|
+
.map((operation) => resolveArmResourceOperationCandidate(program, resourceType, operation))
|
|
776
|
+
.filter((operation) => operation !== undefined);
|
|
777
|
+
for (const { armOperation, resourceInfo, resourceNameIsExplicit } of candidates) {
|
|
778
|
+
if (!isResourceIdentityOperation(armOperation.kind))
|
|
701
779
|
continue;
|
|
702
|
-
armOperation.kind = operation.kind;
|
|
703
|
-
armOperation.resourceModelName = operation.resource?.name ?? resourceType.name;
|
|
704
|
-
const resourceInfo = getResourceInfo(program, armOperation, operation.resource ?? resourceType);
|
|
705
780
|
if (resourceInfo === undefined)
|
|
706
781
|
continue;
|
|
707
|
-
armOperation.name = operation.name;
|
|
708
|
-
armOperation.resourceKind = operation.resourceKind;
|
|
709
|
-
const resourceNameIsExplicit = operation.resourceName !== undefined;
|
|
710
|
-
resourceInfo.resourceName =
|
|
711
|
-
operation.resourceName ??
|
|
712
|
-
getResourceNameForOperation(program, armOperation, resourceInfo.resourceInstancePath) ??
|
|
713
|
-
armOperation.resourceModelName;
|
|
714
|
-
resourceInfo.resourceNameIsExplicit = resourceNameIsExplicit;
|
|
715
|
-
armOperation.resourceName = resourceInfo.resourceName;
|
|
716
782
|
let matched = false;
|
|
717
|
-
// Check if we already have an operation for this resource
|
|
718
783
|
for (const resolvedOp of resolvedOperations) {
|
|
719
|
-
if (
|
|
784
|
+
if (isResourceIdentityMatch(resourceInfo, resolvedOp)) {
|
|
720
785
|
matched = true;
|
|
721
|
-
|
|
722
|
-
continue;
|
|
723
|
-
}
|
|
724
|
-
addAssociatedOperation(armOperation, resolvedOp);
|
|
786
|
+
tryAddLifecycleOperation(resourceInfo.resourceType, armOperation, resolvedOp);
|
|
725
787
|
continue;
|
|
726
788
|
}
|
|
727
789
|
}
|
|
728
790
|
if (matched)
|
|
729
791
|
continue;
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
resourceType: resourceInfo.resourceType,
|
|
733
|
-
resourceInstancePath: resourceInfo.resourceInstancePath,
|
|
734
|
-
resourceName: resourceInfo.resourceName,
|
|
735
|
-
resourceNameIsExplicit: resourceNameIsExplicit,
|
|
736
|
-
operations: {
|
|
737
|
-
lifecycle: {
|
|
738
|
-
read: undefined,
|
|
739
|
-
createOrUpdate: undefined,
|
|
740
|
-
update: undefined,
|
|
741
|
-
delete: undefined,
|
|
742
|
-
checkExistence: undefined,
|
|
743
|
-
},
|
|
744
|
-
actions: [],
|
|
745
|
-
lists: [],
|
|
746
|
-
},
|
|
747
|
-
associatedOperations: [],
|
|
748
|
-
};
|
|
749
|
-
if (!tryAddLifecycleOperation(resourceInfo.resourceType, armOperation, newResource)) {
|
|
750
|
-
addAssociatedOperation(armOperation, newResource);
|
|
751
|
-
}
|
|
792
|
+
const newResource = createResolvedResourceOperations(resourceInfo, resourceNameIsExplicit);
|
|
793
|
+
tryAddLifecycleOperation(resourceInfo.resourceType, armOperation, newResource);
|
|
752
794
|
resolvedOperations.add(newResource);
|
|
753
795
|
}
|
|
796
|
+
for (const candidate of candidates) {
|
|
797
|
+
if (isResourceIdentityOperation(candidate.armOperation.kind))
|
|
798
|
+
continue;
|
|
799
|
+
if (candidate.armOperation.kind === "list") {
|
|
800
|
+
const target = getBestListOperationTarget(candidate.armOperation, resolvedOperations);
|
|
801
|
+
if (target !== undefined) {
|
|
802
|
+
tryAddLifecycleOperation(target.resourceType, candidate.armOperation, target);
|
|
803
|
+
}
|
|
804
|
+
// TODO: Define how non-prefix list paths should map to detected resource identities.
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
for (const resolvedOp of resolvedOperations) {
|
|
808
|
+
tryAddOperationToResolvedResource(candidate, resolvedOp);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
754
811
|
return [...resolvedOperations.values()].toSorted((a, b) => {
|
|
755
812
|
// Sort by provider, type, then instance path
|
|
756
813
|
if (a.resourceType.types.length < b.resourceType.types.length)
|
|
@@ -770,6 +827,51 @@ export function resolveArmResourceOperations(program, resourceType) {
|
|
|
770
827
|
return 0;
|
|
771
828
|
});
|
|
772
829
|
}
|
|
830
|
+
function resolveArmResourceOperationCandidate(program, resourceType, operation) {
|
|
831
|
+
const armOperation = getResourceOperation(program, operation.operation);
|
|
832
|
+
if (armOperation === undefined)
|
|
833
|
+
return undefined;
|
|
834
|
+
armOperation.kind = operation.kind;
|
|
835
|
+
armOperation.resourceModelName = operation.resource?.name ?? resourceType.name;
|
|
836
|
+
const resourceInfo = getResourceInfo(armOperation);
|
|
837
|
+
if (resourceInfo === undefined && isInstanceLifecycleOperation(armOperation.kind))
|
|
838
|
+
return undefined;
|
|
839
|
+
armOperation.name = operation.name;
|
|
840
|
+
armOperation.resourceKind = operation.resourceKind;
|
|
841
|
+
const resourceNameIsExplicit = operation.resourceName !== undefined;
|
|
842
|
+
if (resourceInfo !== undefined) {
|
|
843
|
+
resourceInfo.resourceName =
|
|
844
|
+
operation.resourceName ??
|
|
845
|
+
getResourceNameForOperation(program, armOperation, resourceInfo.resourceInstancePath) ??
|
|
846
|
+
armOperation.resourceModelName;
|
|
847
|
+
resourceInfo.resourceNameIsExplicit = resourceNameIsExplicit;
|
|
848
|
+
armOperation.resourceName = resourceInfo.resourceName;
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
armOperation.resourceName = operation.resourceName ?? armOperation.resourceModelName;
|
|
852
|
+
}
|
|
853
|
+
return { armOperation, resourceInfo, resourceNameIsExplicit };
|
|
854
|
+
}
|
|
855
|
+
function createResolvedResourceOperations(resourceInfo, resourceNameIsExplicit) {
|
|
856
|
+
return {
|
|
857
|
+
resourceType: resourceInfo.resourceType,
|
|
858
|
+
resourceInstancePath: resourceInfo.resourceInstancePath,
|
|
859
|
+
resourceName: resourceInfo.resourceName,
|
|
860
|
+
resourceNameIsExplicit: resourceNameIsExplicit,
|
|
861
|
+
operations: {
|
|
862
|
+
lifecycle: {
|
|
863
|
+
read: undefined,
|
|
864
|
+
createOrUpdate: undefined,
|
|
865
|
+
update: undefined,
|
|
866
|
+
delete: undefined,
|
|
867
|
+
checkExistence: undefined,
|
|
868
|
+
},
|
|
869
|
+
actions: [],
|
|
870
|
+
lists: [],
|
|
871
|
+
},
|
|
872
|
+
associatedOperations: [],
|
|
873
|
+
};
|
|
874
|
+
}
|
|
773
875
|
export { getArmResource } from "./private.decorators.js";
|
|
774
876
|
export function getArmResourceInfo(program, resourceType) {
|
|
775
877
|
const resourceInfo = getArmResource(program, resourceType);
|
|
@@ -1074,6 +1176,9 @@ export function resolveResourceBaseType(type) {
|
|
|
1074
1176
|
}
|
|
1075
1177
|
export const [getResourceFeature, setResourceFeature] = useStateMap(ArmStateKeys.armFeature);
|
|
1076
1178
|
export const [getResourceFeatureSet, setResourceFeatureSet] = useStateMap(ArmStateKeys.armFeatureSet);
|
|
1179
|
+
/**
|
|
1180
|
+
* Gets the enum configured by `@featureFiles`, or `undefined` when feature files are not configured.
|
|
1181
|
+
*/
|
|
1077
1182
|
export const [getFeatureFileSet, setFeatureFileSet] = useStateMap(ArmStateKeys.armFeatureFileSet);
|
|
1078
1183
|
export const [getResourceFeatureOptions, setResourceFeatureOptions] = useStateMap(ArmStateKeys.armFeatureOptions);
|
|
1079
1184
|
const commonFeatureOptions = {
|
|
@@ -1207,7 +1312,7 @@ export const $featureOptions = (context, entity, options) => {
|
|
|
1207
1312
|
// New Azure.ResourceManager namespace decorators
|
|
1208
1313
|
export const $featureFile = $feature;
|
|
1209
1314
|
export const $featureFiles = (context, entity, features) => {
|
|
1210
|
-
setFeatureFileSet(context.program, entity,
|
|
1315
|
+
setFeatureFileSet(context.program, entity, features);
|
|
1211
1316
|
$features(context, entity, features);
|
|
1212
1317
|
};
|
|
1213
1318
|
export const $featureFileOptions = $featureOptions;
|