{"version":3,"sources":["../../../packages/core/data/gateway-url-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,2CAA2C;AAC3C,oBAAY,UAAU;IAClB,2CAA2C;IAE3C,WAAW,eAAe;IAE1B,2CAA2C;IAE3C,WAAW,eAAe;IAE1B,gDAAgD;IAChD,OAAO,eAAc;IAErB,gDAAgD;IAChD,MAAM,eAAc;CACvB;AAED,8DAA8D;AAC9D,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,OAAO,CAAa;IAE5B;;;OAGG;gBACS,GAAG,EAAE,MAAM,GAAG,GAAG;IAM7B;;;;OAIG;IACI,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,iBAAiB;IAK/D;;;;OAIG;IACI,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc;CAQ5C;AAED,sEAAsE;AACtE,qBAAa,cAAc;IAMX,OAAO,CAAC,OAAO;IAL3B;;;;OAIG;gBACiB,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM;IAKrD,sEAAsE;IAC/D,YAAY,IAAI,cAAc;IASrC,qDAAqD;IAC9C,YAAY,IAAI,sBAAsB;CAGhD;AAED,gEAAgE;AAChE,qBAAa,aAAa;IAKV,OAAO,CAAC,OAAO;IAJ3B;;;OAGG;gBACiB,OAAO,EAAE,UAAU;IAGvC,0CAA0C;IACnC,KAAK,IAAI,MAAM;CAGzB;AAED,yEAAyE;AACzE,8BAAsB,iBAAiB;IAMvB,SAAS,CAAC,OAAO,EAAE,UAAU;IALzC;;;;OAIG;gBACmB,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM;CAI1D;AAED,mEAAmE;AACnE,qBAAa,sBAAuB,SAAQ,iBAAiB;IACzD;;;OAGG;gBACS,OAAO,EAAE,UAAU;IAI/B;;;OAGG;IACI,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;CAW3C","file":"gateway-url-builder.d.ts","sourcesContent":["import { Strings } from '../generated/strings';\r\nimport { Net } from './net';\r\nimport { UriBuilder } from './uri-builder';\r\n\r\n/** Represents the defined API versions. */\r\nexport enum ApiVersion {\r\n    /** Gets the API version for 2018-04-01. */\r\n    // eslint-disable-next-line @typescript-eslint/naming-convention\r\n    v2018_04_01 = '2018-04-01',\r\n\r\n    /** Gets the API version for 2019-02-01. */\r\n    // eslint-disable-next-line @typescript-eslint/naming-convention\r\n    v2019_02_01 = '2019-02-01',\r\n\r\n    /** Gets the intial API version (2018-04-01). */\r\n    Initial = v2018_04_01,\r\n\r\n    /** Gets the latest API version (2019-02-01). */\r\n    Latest = v2019_02_01,\r\n}\r\n\r\n/** Represents an object that can build URL to the gateway. */\r\nexport class GatewayUrlBuilder {\r\n    private builder: UriBuilder;\r\n\r\n    /**\r\n     * Initializes a new instance of the GatewayUrlBuilder class.\r\n     * @param uri The string or URL to initialize the builder from.\r\n     */\r\n    constructor(uri: string | URL) {\r\n        this.builder = new UriBuilder(uri);\r\n        this.builder.appendSegment('api');\r\n        this.builder.setQueryParameter('api-version', ApiVersion.Latest);\r\n    }\r\n\r\n    /**\r\n     * Indicates the builder should use a specified API version.\r\n     * @param apiVersion The API version to use.\r\n     * @returns The original builder.\r\n     */\r\n    public useApiVersion(apiVersion: ApiVersion): GatewayUrlBuilder {\r\n        this.builder.setQueryParameter('api-version', apiVersion);\r\n        return this;\r\n    }\r\n\r\n    /**\r\n     * Creates and returns a builder for a specific node.\r\n     * @param name The name of the node to create a builder for.\r\n     * @returns A new node URL builder.\r\n     */\r\n    public node(name: string): NodeUrlBuilder {\r\n        if (!name) {\r\n            const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.ArgumentNullError.message;\r\n            throw new Error(message.format('NodeUrlBuilder/node', 'name'));\r\n        }\r\n\r\n        return new NodeUrlBuilder(this.builder.clone(), name);\r\n    }\r\n}\r\n\r\n/** Represents an object that can build URLs for a particular node. */\r\nexport class NodeUrlBuilder {\r\n    /**\r\n     * Initializes a new instance of the NodeUrlBuilder class.\r\n     * @param builder The current UriBuilder.\r\n     * @param node The name of the node the URL is being built for.\r\n     */\r\n    constructor(private builder: UriBuilder, node: string) {\r\n        this.builder.appendSegment('nodes');\r\n        this.builder.appendSegment(node);\r\n    }\r\n\r\n    /** Makes the current URL builder relative from this point forward. */\r\n    public makeRelative(): NodeUrlBuilder {\r\n        const newBuilder = new UriBuilder();\r\n\r\n        newBuilder.fragment = this.builder.fragment;\r\n        newBuilder.query = this.builder.query;\r\n        this.builder = newBuilder;\r\n        return this;\r\n    }\r\n\r\n    /** Gets a builder for the file transfer feature. **/\r\n    public fileTransfer(): FileTransferUrlBuilder {\r\n        return new FileTransferUrlBuilder(this.builder.clone());\r\n    }\r\n}\r\n\r\n/** Represents an object that builds the file URL for an API. */\r\nexport class ApiUrlBuilder {\r\n    /**\r\n     * Initializes a new instance of the ApiUrlBuilder class.\r\n     * @param builder The current UriBuilder.\r\n     */\r\n    constructor(private builder: UriBuilder) {\r\n    }\r\n\r\n    /** Builds and returns the current URL. */\r\n    public build(): string {\r\n        return this.builder.toString();\r\n    }\r\n}\r\n\r\n/** Represents an object that can build URLs for a particular feature. */\r\nexport abstract class FeatureUrlBuilder {\r\n    /**\r\n     * Initializes a new instance of the FeatureUrlBuilder class.\r\n     * @param builder The current UriBuilder.\r\n     * @param node The name of the feature the URL is being built for.\r\n     */\r\n    constructor(protected builder: UriBuilder, name: string) {\r\n        this.builder.appendSegment('features');\r\n        this.builder.appendSegment(name);\r\n    }\r\n}\r\n\r\n/** Represents an object that can build URLs for file transfers. */\r\nexport class FileTransferUrlBuilder extends FeatureUrlBuilder {\r\n    /**\r\n     * Initializes a new instance of the FileTransferUrlBuilder class.\r\n     * @param builder The current UriBuilder.\r\n     */\r\n    constructor(builder: UriBuilder) {\r\n        super(builder, 'fileTransfer');\r\n    }\r\n\r\n    /**\r\n     * Adds the specified file path to the URL.\r\n     * @param path The path of the file to use.\r\n     */\r\n    public file(path: string): ApiUrlBuilder {\r\n        if (!path) {\r\n            const message = MsftSme.getStrings<Strings>().MsftSmeShell.Core.Error.ArgumentNullError.message;\r\n            throw new Error(message.format('FileTransferUrlBuilder/file', 'path'));\r\n        }\r\n\r\n        const temp = this.builder.clone();\r\n        temp.appendSegment('files');\r\n        temp.appendSegment(Net.toSegmentedBase64Url(path));\r\n        return new ApiUrlBuilder(temp);\r\n    }\r\n}\r\n"]}