UNPKG

@azure-tools/typespec-powershell

Version:

An experimental TypeSpec emitter for PowerShell codegen

49 lines 2.19 kB
import { listAllServiceNamespaces, listClients } from "@azure-tools/typespec-client-generator-core"; import { getNamespaceFullName, isTemplateDeclarationOrInstance, isTemplateDeclaration } from "@typespec/compiler"; export function getClients(psContext) { const services = new Set(); listClients(psContext).forEach((c) => services.add(c.service)); const rawServiceNamespaces = listAllServiceNamespaces(psContext); if (services.size === 0 && rawServiceNamespaces.length > 0) { // If no clients are found, fall back to raw service namespaces [...rawServiceNamespaces.values()].forEach((ns) => services.add(ns)); } return [...services.values()].map((service) => { const clientName = service.name + "Client"; return { kind: "SdkClient", name: clientName, service: service, type: service, arm: Boolean(psContext.arm), crossLanguageDefinitionId: `${getNamespaceFullName(service)}.${clientName}`, subOperationGroups: [] }; }); } function isArm(service) { return service.decorators.some((decorator) => decorator.decorator.name === "$armProviderNamespace"); } export function listOperations(client) { const operations = []; const queue = [client.service]; while (queue.length > 0) { const current = queue.shift(); if (current.decorators.some((d) => d.definition?.name === "@client" && getNamespaceFullName(d.definition?.namespace) === "Azure.ClientGenerator.Core") && current !== client.service) { continue; } operations.push(...[...current.operations.values()].filter((op) => isTemplateDeclarationOrInstance(op) === false)); if (current.kind === "Namespace") { queue.push(...current.namespaces.values()); queue.push(...[...current.interfaces.values()].filter((i) => isTemplateDeclaration(i) === false)); } } return operations; } // export function isRLCMultiEndpoint(dpgContext: SdkContext): boolean { // return getRLCClients(dpgContext).length > 1; // } //# sourceMappingURL=clientUtils.js.map