/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ "use strict"; var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var util = require("util");

















var profile = require("../../../util/profile");
var utils = require("../../../util/utils");
var dataLakeAnalyticsUtils = require("./datalakeanalytics.utils");
var tagUtils = require("../tag/tagUtils");
var path = require("path");
var fs = require("fs");

var $ = utils.getLocaleString;

exports.init = function(cli) {
  var log = cli.output;
  var withProgress = cli.interaction.withProgress.bind(cli.interaction);





  var dataLakeCommands = cli.category("datalake").description($("Commands to manage your Data Lake objects"));


  var dataLakeAnalyticsCommands = dataLakeCommands.category("analytics").description($("Commands to manage your Data Lake Analytics objects"));


  var dataLakeAnalyticsJob = dataLakeAnalyticsCommands.category("job").description($("Commands to manage your Data Lake Analytics Jobs"));


  dataLakeAnalyticsJob.command("create [accountName] [jobName] [script] [runtime] [compileMode] [compileOnly] [degreeOfParallelism] [priority]").description($("Submits a job to the specified Data Lake Analytics account.")).usage("[options] <accountName> <jobName> <script>").option("-n --accountName <accountName>", $("the Data Lake Analytics account name to execute the action on")).option("-j --jobName <jobName>", $("the name for this job submission")).option("-t --script <script>", $("the script to run. This can be either the script contents, a relative path or the full path to a UTF-8 encoded script file")).option("-r --runtime <runtime>", $(("optionally indicates the runtime to use. The default runtime is the currently deployed production runtime." + "Use this if you have uploaded a custom runtime to your account and want job execution to go through that one instead of the one deployed by Microsoft."))).option("-m --compileMode <compileMode>", $("optionally specify the type of compilation to do. Valid values are 'Semantic', 'Full', and 'SingleBox' Default is Full.")).option("-c --compileOnly <compileOnly>", $("optionally indicates that this job should only be compiled and not run.")).option("-d --degreeOfParallelism <degreeOfParallelism>", $("optionally specify the degree of parallelism for the job in a range from 1 to 50. Default value is 1.")).option("-p --priority <priority>", $("optionally specify the priority for the job. Default value is 1000, with lower, positive, non-zero values having higher priority. 1 is the highest priority and int.maxValue is the lowest.")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __1(accountName, jobName, script, runtime, compileMode, compileOnly, degreeOfParallelism, priority, options, _) { var subscription, client, scriptAsPath, scriptContents, normalPath, job, properties, jobResponse; var __frame = { name: "__1", line: 58 }; return __func(_, this, arguments, __1, 9, __frame, function __$__1() {













      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeAnalyticsJobManagementClient(subscription);

      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!jobName) {
        return _(null, cli.missingArgument("jobName")); } ;


      if (!script) {
        return _(null, cli.missingArgument("script")); } ;


      scriptAsPath = true; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() {



            normalPath = path.normalize(script);
            return fs.readFile(normalPath, "utf8", __cb(_, __frame, 21, 28, function ___(__0, __1) { scriptContents = __1; __then(); }, true)); }); })(function ___(err, __result) { __catch(function __$__1() { if (err) {




              scriptAsPath = false; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__1() {


          if (!scriptAsPath) {
            scriptContents = script; } ;


          if (!degreeOfParallelism) {
            degreeOfParallelism = 1; }

           else {
            degreeOfParallelism = parseInt(degreeOfParallelism); } ;


          if (!priority) {
            priority = 1000; }

           else {
            priority = parseInt(priority); } ;


          if ((priority < 1)) {
            return _(new Error(("priority (-p or --priority) must be >= 1. Priority passed in: " + priority))); } ;


          job = {
            jobId: utils.uuidGen(),
            name: jobName,
            type: "USql",
            degreeOfParallelism: degreeOfParallelism,
            priority: priority };


          properties = {
            type: "USql",
            script: scriptContents };


          if (compileMode) {
            properties.compileMode = compileMode; } ;


          if (runtime) {
            properties.runtimeVersion = runtime; } ;


          job.properties = properties;
          jobResponse = { }; return (function __$__1(__then) {
            if (compileOnly) {
              return client.job.build(accountName, job, __cb(_, __frame, 75, 33, function ___(__0, __2) { jobResponse = __2; __then(); }, true)); } else {


              return client.job.create(accountName, job.jobId, job, __cb(_, __frame, 78, 33, function ___(__0, __3) { jobResponse = __3; __then(); }, true)); } ; })(function __$__1() {


            dataLakeAnalyticsUtils.formatOutput(cli, log, options, jobResponse); _(); }); }); }); }); });


  dataLakeAnalyticsJob.command("show [accountName] [jobId] [includeDebugInfo] [includeStatistics]").description($("shows the specified job and additional data if desired.")).usage("[options] <accountName> <jobId>").option("-n --accountName <accountName>", $("the Data Lake Analytics account name to execute the action on")).option("-j --jobId <jobId>", $("the job ID of the job to retrieve.")).option("-d --includeDebugInfo", $("optionally indicates that debug info should be output for the job as well.")).option("-t --includeStatistics", $("optionally indicates that statistics for the job should be output as well.")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __2(accountName, jobId, includeDebugInfo, includeStatistics, options, _) { var subscription, client, jobResponse, statistics, debugData; var __frame = { name: "__2", line: 150 }; return __func(_, this, arguments, __2, 5, __frame, function __$__2() {








      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeAnalyticsJobManagementClient(subscription);

      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!jobId) {
        return _(null, cli.missingArgument("jobId")); } ;


      return client.job.get(accountName, jobId, __cb(_, __frame, 12, 35, function ___(__0, __1) { jobResponse = __1; return (function __$__2(__then) {

          if (includeStatistics) { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() {

                  return client.job.getStatistics(accountName, jobId, __cb(_, __frame, 16, 38, function ___(__0, __2) { statistics = __2;
                    jobResponse.properties.statistics = statistics; __then(); }, true)); }); })(function ___(err, __result) { __catch(function __$__2() { if (err) {


                    log.info(("Could not recover statistics info for the job. This happens if the job failed to start. Error reported: " + err)); __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, __then); }); } else { __then(); } ; })(function __$__2() { return (function __$__2(__then) {



            if (includeDebugInfo) { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() {

                    return client.job.getDebugDataPath(accountName, jobId, __cb(_, __frame, 26, 37, function ___(__0, __3) { debugData = __3.paths;
                      jobResponse.properties.debugData = debugData; __then(); }, true)); }); })(function ___(err, __result) { __catch(function __$__2() { if (err) {


                      log.info("Could not recover debug info for the job. This happens if the job completed successfully. If the job did not complete successfully, please run with verbose output for more details."); __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, __then); }); } else { __then(); } ; })(function __$__2() {



            dataLakeAnalyticsUtils.formatOutput(cli, log, options, jobResponse); _(); }); }); }, true)); }); });


  dataLakeAnalyticsJob.command("cancel [accountName] [jobId]").description($("cancels the specified job.")).usage("[options] <accountName> <jobId>").option("-n --accountName <accountName>", $("the Data Lake Analytics account name to execute the action on")).option("-j --jobId <jobId>", $("the job ID of the job to retrieve.")).option("-q, --quiet", $("quiet mode (do not ask for cancel confirmation)")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __3(accountName, jobId, includeDebugInfo, includeStatistics, options, _) { var subscription, client; var __frame = { name: "__3", line: 194 }; return __func(_, this, arguments, __3, 5, __frame, function __$__3() {







      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeAnalyticsJobManagementClient(subscription);

      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!jobId) {
        return _(null, cli.missingArgument("jobId")); } ; return (function __$__3(_) {


        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Cancel Job with id %s in account %s? [y/n] "), jobId, accountName), __cb(_, __frame, 12, 45, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -193, 17, function ___(__0, __2) { return (function __$__3(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$__3() {



          return client.job.cancel(accountName, jobId, __cb(_, __frame, 16, 17, function __$__3() {

            log.data($(("Successfully canceled the job with ID: " + jobId))); _(); }, true)); }); }, true)); }); });


  dataLakeAnalyticsJob.command("list [accountName] [jobName] [submitter] [submittedAfter] [submittedBefore] [state] [result]").description($("lists the jobs in the specified account given the specified filters and criteria.")).usage("[options] <accountName>").option("-n --accountName <accountName>", $("the Data Lake Analytics account name to execute the action on")).option("-j --jobName <jobName>", $("An optional filter which returns jobs with only the specified friendly name.")).option("-u, --submitter <submitter>", $("An optional filter which returns jobs only by the specified submitter in the format user@domain")).option("-a, --submittedAfter <submittedAfter>", $("An optional filter which returns jobs only submitted after the specified time (as a date time offset).")).option("-b, --submittedBefore <submittedAfter>", $("An optional filter which returns jobs only submitted before the specified time (as a date time offset).")).option("-t, --state <comma delmited string of states>", $(("An optional filter which returns jobs with only the specified states (as comma delmited string). Valid states are: " + "accepted, compiling, ended, new, queued, running, scheduling, starting and paused"))).option("-r, --result <comma delmited string of results>", $(("An optional filter which returns jobs with only the specified results (as comma delmited string). Valid results are: " + "none, succeeded, cancelled and failed"))).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __4(accountName, jobName, submitter, submittedAfter, submittedBefore, state, result, options, _) { var subscription, client, filter, intermediateStateArray, stateString, stateArray, i, intermediateResultArray, resultString, resultArray, j, parameters, filterString, jobList; var __frame = { name: "__4", line: 228 }; return __func(_, this, arguments, __4, 8, __frame, function __$__4() {













      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeAnalyticsJobManagementClient(subscription);
      log.info("client created");
      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      filter = [];
      if (submitter) {
        filter.push((("submitter eq '" + submitter) + "'")); } ;


      if (jobName) {
        filter.push((("name eq '" + jobName) + "'")); } ;


      if (submittedAfter) {
        filter.push((("submitTime ge datetimeoffset'" + submittedAfter) + "'")); } ;


      if (submittedBefore) {
        filter.push((("submitTime lt datetimeoffset'" + submittedBefore) + "'")); } ;


      if ((state && (state.length > 0))) {
        intermediateStateArray = state.split(",");
        stateString = "(";
        stateArray = [];
        for (i = 0; (i < intermediateStateArray.length); i++) {
          stateArray.push((("state eq '" + intermediateStateArray[i]) + "'")); };


        stateString += (stateArray.join(" or ") + ")");
        filter.push(stateString); } ;


      if ((result && (result.length > 0))) {
        intermediateResultArray = result.split(",");
        resultString = "(";
        resultArray = [];
        for (j = 0; (j < intermediateResultArray.length); j++) {
          resultArray.push((("result eq '" + intermediateResultArray[j]) + "'")); };


        resultString += (resultArray.join(" or ") + ")");
        filter.push(resultString); } ;



      if ((filter && (filter.length > 0))) {
        filterString = filter.join(" and ");
        parameters = {
          filter: filterString }; } ;



      jobList = [];

      return withProgress(util.format($("Retrieving job list for account: %s"), accountName), function __1(log, _) { var response, pushJobs; var __frame = { name: "__1", line: 288 }; return __func(_, this, arguments, __1, 1, __frame, function __$__1() {

          return client.job.list(accountName, parameters, __cb(_, __frame, 1, 36, function ___(__0, __1) { response = __1;
            jobList = response;
            pushJobs = function(eachValue) { jobList.push(eachValue); }; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$__1() { __more = false;
                var __4 = (response.nextLink && (response.nextLink.length > 0)); if (__4) {
                  return client.job.listNext(response.nextLink, __cb(_, __frame, 5, 34, function ___(__0, __2) { response = __2;
                    response.forEach(pushJobs, jobList); while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(_); }, true)); }); }, __cb(_, __frame, 59, 6, function __$__4() {



        dataLakeAnalyticsUtils.formatOutputList(cli, log, options, jobList); _(); }, true)); }); });


  var dataLakeAnalyticsCatalog = dataLakeAnalyticsCommands.category("catalog").description($("Commands to manage your Data Lake Analytics Catalog"));


  dataLakeAnalyticsCatalog.command("list [accountName] [itemType] [itemPath]").description($("Lists all of the specified catalog item types under the path or, if the full path is given, just the single catalog item at that path.")).usage("[options] <accountName> <itemType> <itemPath>").option("-n --accountName <accountName>", $("The Data Lake Analytics account name to perform the action on.")).option("-t --itemType <itemType>", $("The catalog item type to return. Valid values are (case insensitive): database, schema, secret, credential, assembly, externaldatasource, table, tablevaluedfunction, view, procedure, types, tablepartition or tablestatistics")).option("-p --itemPath <itemPath>", $("The path to the catalog item(s) to get or list in the format: <FirstPart>.<OptionalSecondPart>.<OptionalThirdPart>.<OptionalFourthPart>. This MUST be null when listing all databases.")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __5(accountName, itemType, itemPath, options, _) { var subscription, output; var __frame = { name: "__5", line: 311 }; return __func(_, this, arguments, __5, 4, __frame, function __$__5() {







      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!itemType) {
        return _(null, cli.missingArgument("itemType")); } ;


      subscription = profile.current.getSubscription(options.subscription);

      return getCatalogItem(subscription, accountName, itemPath, itemType, __cb(_, __frame, 11, 19, function ___(__0, __1) { output = __1;
        dataLakeAnalyticsUtils.formatOutputList(cli, log, options, output); _(); }, true)); }); });


  var dataLakeAnalyticsCatalogSecret = dataLakeAnalyticsCatalog.category("secret").description($("Commands to manage your Data Lake Analytics Catalog secrets"));


  dataLakeAnalyticsCatalogSecret.command("create [accountName] [databaseName] [hostUri] [secretName]").description($("Creates the specified secret for the specified database.")).usage("[options] <accountName> <databaseName> <hostUri> <secretName>").option("-n --accountName <accountName>", $("The Data Lake Analytics account name to perform the action on.")).option("-d --databaseName <databaseName>", $("The name of the database in which the secret will be created.")).option("-u --hostUri <hostUri>", $("The full host URI associated with the external data source. The secret will be used with this host URI.")).option("-e --secretName <secretName>", $("secret name, will prompt if not given")).option("-p --password <password>", $("secret password, will prompt if not given")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __6(accountName, databaseName, hostUri, secretName, options, _) { var subscription, password, client, params, response; var __frame = { name: "__6", line: 338 }; return __func(_, this, arguments, __6, 5, __frame, function __$__6() {









      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!databaseName) {
        return _(null, cli.missingArgument("databaseName")); } ;


      if (!hostUri) {
        return _(null, cli.missingArgument("hostUri")); } ;


      subscription = profile.current.getSubscription(options.subscription);

      return cli.interaction.promptIfNotGiven("SecretName: ", secretName, __cb(_, __frame, 15, 35, function ___(__0, __1) { secretName = __1;
        return cli.interaction.promptPasswordOnceIfNotGiven("Password: ", options.password, __cb(_, __frame, 16, 37, function ___(__0, __2) { password = __2;

          client = utils.createDataLakeAnalyticsCatalogManagementClient(subscription);
          params = {
            secretName: secretName,
            password: password,
            uri: hostUri };


          return client.catalog.createSecret(accountName, databaseName, params.secretName, params, __cb(_, __frame, 25, 36, function ___(__0, __3) { response = __3;
            dataLakeAnalyticsUtils.formatOutput(cli, log, options, response); _(); }, true)); }, true)); }, true)); }); });


  dataLakeAnalyticsCatalogSecret.command("set [accountName] [databaseName] [hostUri] [secretName]").description($("Updates the password and/or hostUri of the specified secret in the specified database.")).usage("[options] <accountName> <databaseName> <hostUri> <secretName>").option("-n --accountName <accountName>", $("The Data Lake Analytics account name to perform the action on.")).option("-d --databaseName <databaseName>", $("The name of the database in which the secret will be updated.")).option("-u --hostUri <hostUri>", $("The full host URI associated with the external data source. The secret will be used with this host URI.")).option("-e --secretName <secretName>", $("secret name, will prompt if not given")).option("-p --password <password>", $("secret password, will prompt if not given")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __7(accountName, databaseName, hostUri, secretName, options, _) { var subscription, password, client, params, response; var __frame = { name: "__7", line: 376 }; return __func(_, this, arguments, __7, 5, __frame, function __$__7() {









      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!databaseName) {
        return _(null, cli.missingArgument("databaseName")); } ;


      if (!hostUri) {
        return _(null, cli.missingArgument("hostUri")); } ;


      subscription = profile.current.getSubscription(options.subscription);

      return cli.interaction.promptIfNotGiven("SecretName: ", secretName, __cb(_, __frame, 15, 35, function ___(__0, __1) { secretName = __1;
        return cli.interaction.promptPasswordOnceIfNotGiven("Password: ", options.password, __cb(_, __frame, 16, 37, function ___(__0, __2) { password = __2;

          client = utils.createDataLakeAnalyticsCatalogManagementClient(subscription);
          params = {
            secretName: secretName,
            password: password,
            uri: hostUri };


          return client.catalog.updateSecret(accountName, databaseName, params.secretName, params, __cb(_, __frame, 25, 36, function ___(__0, __3) { response = __3;
            dataLakeAnalyticsUtils.formatOutput(cli, log, options, response); _(); }, true)); }, true)); }, true)); }); });


  dataLakeAnalyticsCatalogSecret.command("delete [accountName] [databaseName] [secretName]").description($("Updates the password and/or hostUri of the specified secret in the specified database.")).usage("[options] <accountName> <databaseName> <hostUri> <secretName>").option("-n --accountName <accountName>", $("The Data Lake Analytics account name to perform the action on.")).option("-d --databaseName <databaseName>", $("The name of the database in which the secret(s) will be deleted.")).option("-e --secretName <secretName>", $("Optional secret name to delete, if not specified will delete all secrets in the specified database")).option("-q, --quiet", $("quiet mode (do not ask for delete confirmation)")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __8(accountName, databaseName, secretName, options, _) { var subscription, client; var __frame = { name: "__8", line: 413 }; return __func(_, this, arguments, __8, 4, __frame, function __$__8() {








      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      if (!databaseName) {
        return _(null, cli.missingArgument("databaseName")); } ; return (function __$__8(_) {


        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Delete Secret(s) in database %s? [y/n] "), databaseName), __cb(_, __frame, 9, 45, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -412, 17, function ___(__0, __2) { return (function __$__8(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$__8() {



          subscription = profile.current.getSubscription(options.subscription);

          client = utils.createDataLakeAnalyticsCatalogManagementClient(subscription); return (function __$__8(__then) {

            if (!secretName) {
              return client.catalog.deleteAllSecrets(accountName, databaseName, __cb(_, __frame, 18, 23, __then, true)); } else {


              return client.catalog.deleteSecret(accountName, databaseName, secretName, __cb(_, __frame, 21, 23, __then, true)); } ; })(_); }); }, true)); }); });



  var dataLakeAnalyticsAccount = dataLakeAnalyticsCommands.category("account").description($("Commands to manage your Data Lake Analytics accounts"));


  dataLakeAnalyticsAccount.command("list [resource-group]").description($("List all Data Lake Analytics accounts available for your subscription or subscription and resource group")).usage("[options]").option("-g --resource-group <resource-group>", $("the optional resource group to list the accounts in")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __9(resourceGroup, options, _) { var subscription, accounts; var __frame = { name: "__9", line: 446 }; return __func(_, this, arguments, __9, 2, __frame, function __$__9() {





      subscription = profile.current.getSubscription(options.subscription);
      return listAllDataLakeAnalyticsAccounts(subscription, resourceGroup, __cb(_, __frame, 2, 21, function ___(__0, __1) { accounts = __1;
        dataLakeAnalyticsUtils.formatOutputList(cli, log, options, accounts); _(); }, true)); }); });


  dataLakeAnalyticsAccount.command("show [accountName] [resource-group]").description($("Shows a Data Lake Analytics account based on account name")).usage("[options] <accountName>").option("-n --accountName <accountName>", $("the Data Lake Analytics account name to retrieve")).option("-g --resource-group <resource-group>", $("the optional resource group to list the accounts in")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __10(accountName, resourceGroup, options, _) { var subscription, client, dataLakeAnalyticsAccount; var __frame = { name: "__10", line: 458 }; return __func(_, this, arguments, __10, 3, __frame, function __$__10() {






      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;


      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeAnalyticsManagementClient(subscription); return (function __$__10(__then) {

        if (!resourceGroup) {
          return getResrouceGroupByAccountName(subscription, resourceGroup, accountName, __cb(_, __frame, 9, 24, function ___(__0, __1) { resourceGroup = __1; __then(); }, true)); } else { __then(); } ; })(function __$__10() {


        return client.account.get(resourceGroup, accountName, __cb(_, __frame, 12, 52, function ___(__0, __2) { dataLakeAnalyticsAccount = __2;
          dataLakeAnalyticsUtils.formatOutput(cli, log, options, dataLakeAnalyticsAccount); _(); }, true)); }); }); });


  dataLakeAnalyticsAccount.command("delete [accountName] [resource-group]").description($("Deletes a Data Lake Analytics Account based on account name")).usage("[options] <accountName>").option("-n --accountName <accountName>", $("the Data Lake Analytics account name to delete")).option("-g --resource-group <resource-group>", $("the optional resource group to force the command to find the Data Lake Analytics account to delete in.")).option("-q, --quiet", $("quiet mode (do not ask for delete confirmation)")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __11(accountName, resourceGroup, options, _) { var subscription, client; var __frame = { name: "__11", line: 481 }; return __func(_, this, arguments, __11, 3, __frame, function __$__11() {







      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ; return (function __$__11(_) {


        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Delete Data Lake Analytics Account %s? [y/n] "), accountName), __cb(_, __frame, 5, 45, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -480, 17, function ___(__0, __2) { return (function __$__11(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$__11() {



          subscription = profile.current.getSubscription(options.subscription);
          client = utils.createDataLakeAnalyticsManagementClient(subscription); return (function __$__11(__then) {

            if (!resourceGroup) {
              return getResrouceGroupByAccountName(subscription, resourceGroup, accountName, __cb(_, __frame, 13, 24, function ___(__0, __3) { resourceGroup = __3; __then(); }, true)); } else { __then(); } ; })(function __$__11() {


            return client.account.deleteMethod(resourceGroup, accountName, __cb(_, __frame, 16, 21, function __$__11() {
              log.info($("Successfully deleted the specified Data Lake Analytics Account.")); _(); }, true)); }); }); }, true)); }); });


  dataLakeAnalyticsAccount.command("create [accountName] [location] [resource-group] [defaultDataLakeStore]").description($("Creates a Data Lake Analytics Account")).usage("[options] <accountName> <location> <resource-group> <defaultDataLakeStore>").option("-n --accountName <accountName>", $("The Data Lake Analytics account name to create")).option("-l --location <location>", $("the location the Data Lake Analytics account will be created in. Valid values are: North Central US, South Central US, Central US, West Europe, North Europe, West US, East US, East US 2, Japan East, Japan West, Brazil South, Southeast Asia, East Asia, Australia East, Australia Southeast")).option("-g --resource-group <resource-group>", $("the resource group to create the account in")).option("-d --defaultDataLakeStore <defaultDataLakeStore>", $("the default Data Lake Store to associate with this account.")).option("-t --tags <tags>", $(("Tags to set to the the Data Lake Analytics account. Can be mutliple. " + "In the format of 'name=value'. Name is required and value is optional. For example, -t tag1=value1;tag2"))).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __12(accountName, location, resourceGroup, defaultDataLakeStore, options, _) { var subscription, tags, dataLakeAnalyticsAccount; var __frame = { name: "__12", line: 511 }; return __func(_, this, arguments, __12, 5, __frame, function __$__12() {










      subscription = profile.current.getSubscription(options.subscription);
      tags = { };
      tags = tagUtils.buildTagsParameter(tags, options);
      return createOrUpdateDataLakeAnalyticsAccount(subscription, accountName, resourceGroup, location, defaultDataLakeStore, tags, __cb(_, __frame, 4, 37, function ___(__0, __1) { dataLakeAnalyticsAccount = __1;
        dataLakeAnalyticsUtils.formatOutput(cli, log, options, dataLakeAnalyticsAccount); _(); }, true)); }); });


  dataLakeAnalyticsAccount.command("set [accountName] [resource-group] [defaultDataLakeStore]").description($("Updates the properties of an existing Data Lake Analytics Account")).usage("[options] <accountName> <defaultDataLakeStore>").option("-n --accountName <accountName>", $("The Data Lake Analytics Account name to perform the action on.")).option("-g --resource-group <resource-group>", $("the optional resource group to forcibly look for the account to update in")).option("-g --resource-group <resource-group>", $("the optional resource group to forcibly look for the account to update in")).option("-d --defaultDataLakeStore <defaultDataLakeStore>", $("the optional new default Data Lake Store account to set for this account")).option("-t --tags <tags>", $(("Tags to set to the Data Lake Analytics account group. Can be mutliple. " + "In the format of 'name=value'. Name is required and value is optional. For example, -t tag1=value1;tag2"))).option("--no-tags", $("remove all existing tags")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __13(accountName, resourceGroup, defaultDataLakeStore, options, _) { var subscription, client, dataLakeAnalyticsAccount, tags; var __frame = { name: "__13", line: 530 }; return __func(_, this, arguments, __13, 4, __frame, function __$__13() {











      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeAnalyticsManagementClient(subscription); return (function __$__13(__then) {

        if (!resourceGroup) {
          return getResrouceGroupByAccountName(subscription, resourceGroup, accountName, __cb(_, __frame, 5, 24, function ___(__0, __1) { resourceGroup = __1; __then(); }, true)); } else { __then(); } ; })(function __$__13() {


        return client.account.get(resourceGroup, accountName, __cb(_, __frame, 8, 52, function ___(__0, __2) { dataLakeAnalyticsAccount = __2;

          if (!defaultDataLakeStore) {
            defaultDataLakeStore = dataLakeAnalyticsAccount.properties.defaultDataLakeStoreAccount; } ;


          tags = { };
          if ((!options.tags && (!options.no - tags))) {
            tags = dataLakeAnalyticsAccount.tags; }

           else {
            tags = tagUtils.buildTagsParameter(tags, options); } ;


          return createOrUpdateDataLakeAnalyticsAccount(subscription, accountName, resourceGroup, dataLakeAnalyticsAccount.location, defaultDataLakeStore, tags, __cb(_, __frame, 22, 34, function ___(__0, __3) { dataLakeAnalyticsAccount = __3;
            dataLakeAnalyticsUtils.formatOutput(cli, log, options, dataLakeAnalyticsAccount); _(); }, true)); }, true)); }); }); });


  var dataLakeAnalyticsAccountDataSource = dataLakeAnalyticsAccount.category("datasource").description($("Commands to manage your Data Lake Analytics account data sources"));


  dataLakeAnalyticsAccountDataSource.command("add [accountName] [dataLakeStore] [isDefaultDataLakeStore] [azureBlob] [accessKey] [resource-group]").description($("Adds an existing data source (Data Lake Store or Azure Blob) to the Data Lake Analytics Account")).usage("[options] <accountName>").option("-n --accountName <accountName>", $("The Data Lake Analytics Account name to perform the action on.")).option("-l --dataLakeStore <dataLakeStore>", $("the Data Lake Store account to add. NOTE: this argument and --isDefaultDataLakeStore are part of a parameter set, and cannot be specified with --azureBlob and --accessKey.")).option("-d --isDefaultDataLakeStore", $("the optional switch to indicate that the Data Lake being added should be the default Data Lake. NOTE: this argument and --dataLakeStore are part of a parameter set, and cannot be specified with --azureBlob and --accessKey.")).option("-b --azureBlob <azureBlob>", $("the azure blob to add to the account. NOTE: this argument and --accessKey are part of a parameter set, and cannot be specified with --dataLakeStore and --isDefaultDataLakeStore.")).option("-k --accessKey <accessKey>", $("the access key associated with the azureBlob. NOTE: this argument and --azureBlob are part of a parameter set, and cannot be specified with --dataLakeStore and --isDefaultDataLakeStore.")).option("-g --resource-group <resource-group>", $("the optional resource group to forcibly look for the account to update in")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __14(accountName, dataLakeStore, isDefaultDataLakeStore, azureBlob, accessKey, resourceGroup, options, _) { var subscription, client, parameters; var __frame = { name: "__14", line: 569 }; return __func(_, this, arguments, __14, 7, __frame, function __$__14() {










      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeAnalyticsManagementClient(subscription);

      if ((!dataLakeStore && !azureBlob)) {
        return _(new Error($("Either --dataLakeStore or --azureBlob and --accessKey must be specified. They are two separate options and cannot all be specified at once."))); } ;


      if ((dataLakeStore && azureBlob)) {
        return _(new Error($("Either --dataLakeStore or --azureBlob and --accessKey must be specified. They are two separate options and cannot all be specified at once."))); } ;


      if ((dataLakeStore && accessKey)) {
        return _(new Error($("--accessKey can only be specified with --azureBlob."))); } ;


      if ((azureBlob && !accessKey)) {
        return _(new Error($("--accessKey must be specified with --azureBlob."))); } ;


      if ((azureBlob && isDefaultDataLakeStore)) {
        return _(new Error($("--isDefaultDataLakeStore can only be specified with the --dataLakeStore parameter."))); } ; return (function __$__14(__then) {


        if (!resourceGroup) {
          return getResrouceGroupByAccountName(subscription, resourceGroup, accountName, __cb(_, __frame, 25, 24, function ___(__0, __1) { resourceGroup = __1; __then(); }, true)); } else { __then(); } ; })(function __$__14() {

        parameters = { }; return (function __$__14(__then) {
          if (dataLakeStore) {

            parameters.properties = { };
            return client.account.addDataLakeStoreAccount(resourceGroup, accountName, dataLakeStore, parameters, __cb(_, __frame, 31, 23, __then, true)); } else {


            parameters.properties = {
              accessKey: accessKey };


            return client.account.addStorageAccount(resourceGroup, accountName, azureBlob, parameters, __cb(_, __frame, 38, 23, __then, true)); } ; })(function __$__14() { return (function __$__14(__then) {


            if (isDefaultDataLakeStore) {
              return createOrUpdateDataLakeAnalyticsAccount(subscription, accountName, resourceGroup, null, dataLakeStore, null, __cb(_, __frame, 42, 8, __then, true)); } else { __then(); } ; })(function __$__14() {


            log.info($(("Successfully added the storage account specified to the Data Lake Analytics account: " + accountName))); _(); }); }); }); }); });


  dataLakeAnalyticsAccountDataSource.command("delete [accountName] [dataLakeStore] [azureBlob] [resource-group]").description($("removes a data source (Data Lake Store or Azure Blob) from the Data Lake Analytics Account")).usage("[options] <accountName>").option("-n --accountName <accountName>", $("The Data Lake Analytics Account name to perform the action on.")).option("-l --dataLakeStore <dataLakeStore>", $("the Data Lake to remove from the account. NOTE: this argument is part of a parameter set, and cannot be specified with --azureBlob.")).option("-b --azureBlob <azureBlob>", $("the azure blob to remove from the account. NOTE: this argument is part of a parameter set, and cannot be specified with --dataLakeStore.")).option("-g --resource-group <resource-group>", $("the optional resource group to forcibly look for the account to update in")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __15(accountName, dataLakeStore, azureBlob, resourceGroup, options, _) { var subscription, client; var __frame = { name: "__15", line: 625 }; return __func(_, this, arguments, __15, 5, __frame, function __$__15() {








      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeAnalyticsManagementClient(subscription);

      if ((!dataLakeStore && !azureBlob)) {
        return _(new Error($("Either --dataLakeStore or --azureBlob and --accessKey must be specified. They are two separate options and cannot all be specified at once."))); } ;


      if ((dataLakeStore && azureBlob)) {
        return _(new Error($("Either --dataLakeStore or --azureBlob and --accessKey must be specified. They are two separate options and cannot all be specified at once."))); } ; return (function __$__15(__then) {


        if (!resourceGroup) {
          return getResrouceGroupByAccountName(subscription, resourceGroup, accountName, __cb(_, __frame, 13, 24, function ___(__0, __1) { resourceGroup = __1; __then(); }, true)); } else { __then(); } ; })(function __$__15() { return (function __$__15(__then) {


          if (dataLakeStore) {
            return client.account.deleteDataLakeStoreAccount(resourceGroup, accountName, dataLakeStore, __cb(_, __frame, 17, 23, __then, true)); } else {


            return client.account.deleteStorageAccount(resourceGroup, accountName, azureBlob, __cb(_, __frame, 20, 23, __then, true)); } ; })(function __$__15() {


          log.info($(("Successfully removed the storage account specified from Data Lake Analytics account: " + accountName))); _(); }); }); }); });


  dataLakeAnalyticsAccountDataSource.command("set [accountName] [dataLakeStore] [isDefaultDataLakeStore] [azureBlob] [accessKey] [resource-group]").description($("Sets an existing data source (Data Lake Store or Azure Blob) in the Data Lake Analytics Account. Typically used to set the data source as default (for Data Lake) or update the access key (for Azure Blob)")).usage("[options] <accountName>").option("-n --accountName <accountName>", $("The Data Lake Analytics Account name to perform the action on.")).option("-l --dataLakeStore <dataLakeStore>", $("the Data Lake Store account to set. NOTE: this argument and --isDefaultDataLakeStore are part of a parameter set, and cannot be specified with --azureBlob and --accessKey.")).option("-d --isDefaultDataLakeStore", $("the optional switch to indicate that the Data Lake being set should be the default Data Lake. NOTE: this argument and --dataLakeStore are part of a parameter set, and cannot be specified with --azureBlob and --accessKey.")).option("-b --azureBlob <azureBlob>", $("the azure blob to set in the account. NOTE: this argument and --accessKey are part of a parameter set, and cannot be specified with --dataLakeStore and --isDefaultDataLakeStore.")).option("-k --accessKey <accessKey>", $("the access key associated with the azureBlob to update. NOTE: this argument and --azureBlob are part of a parameter set, and cannot be specified with --dataLakeStore and --isDefaultDataLakeStore.")).option("-g --resource-group <resource-group>", $("the optional resource group to forcibly look for the account to update in")).option("-s, --subscription <id>", $("the subscription identifier")).execute(function __16(accountName, dataLakeStore, isDefaultDataLakeStore, azureBlob, accessKey, resourceGroup, options, _) { var subscription, client, parameters; var __frame = { name: "__16", line: 661 }; return __func(_, this, arguments, __16, 7, __frame, function __$__16() {










      subscription = profile.current.getSubscription(options.subscription);
      client = utils.createDataLakeAnalyticsManagementClient(subscription);

      if ((!dataLakeStore && !azureBlob)) {
        return _(new Error($("Either --dataLakeStore or --azureBlob and --accessKey must be specified. They are two separate options and cannot all be specified at once."))); } ;


      if ((dataLakeStore && azureBlob)) {
        return _(new Error($("Either --dataLakeStore or --azureBlob and --accessKey must be specified. They are two separate options and cannot all be specified at once."))); } ;


      if ((dataLakeStore && accessKey)) {
        return _(new Error($("--accessKey can only be specified with --azureBlob."))); } ;


      if ((azureBlob && !accessKey)) {
        return _(new Error($("--accessKey must be specified with --azureBlob."))); } ;


      if ((azureBlob && isDefaultDataLakeStore)) {
        return _(new Error($("--isDefaultDataLakeStore can only be specified with the --dataLakeStore parameter."))); } ; return (function __$__16(__then) {


        if (!resourceGroup) {
          return getResrouceGroupByAccountName(subscription, resourceGroup, accountName, __cb(_, __frame, 25, 24, function ___(__0, __1) { resourceGroup = __1; __then(); }, true)); } else { __then(); } ; })(function __$__16() { return (function __$__16(__then) {


          if (dataLakeStore) { return (function __$__16(__then) {
              if (isDefaultDataLakeStore) {
                return createOrUpdateDataLakeAnalyticsAccount(subscription, accountName, resourceGroup, null, dataLakeStore, null, __cb(_, __frame, 30, 10, __then, true)); } else {


                log.warning($("Data Lake Store Accounts can only be modified by indicating that they are now the Default Data Lake Store account. Otherwise only Add and Remove are supported for Data Lake Store accounts associated with a Data Lake Analytics account.")); __then(); } ; })(__then); } else {



            parameters = {
              properties: {
                accessKey: accessKey } };



            return client.account.updateStorageAccount(resourceGroup, accountName, azureBlob, parameters, __cb(_, __frame, 43, 23, __then, true)); } ; })(function __$__16() {


          log.info($(("Successfully updated the storage account specified for Data Lake Analytics account: " + accountName))); _(); }); }); }); });


  function createOrUpdateDataLakeAnalyticsAccount(subscription, accountName, resourceGroup, location, defaultDataLakeStore, tags, _) { var client, create, accountParams; var __frame = { name: "createOrUpdateDataLakeAnalyticsAccount", line: 710 }; return __func(_, this, arguments, createOrUpdateDataLakeAnalyticsAccount, 6, __frame, function __$createOrUpdateDataLakeAnalyticsAccount() {
      if (!accountName) {
        return _(null, cli.missingArgument("accountName")); } ;

      if (!resourceGroup) {
        return _(null, cli.missingArgument("resourceGroup")); } ;


      client = utils.createDataLakeAnalyticsManagementClient(subscription);
      create = false; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createOrUpdateDataLakeAnalyticsAccount() {

            return client.account.get(resourceGroup, accountName, __cb(_, __frame, 11, 23, __then, true)); }); })(function ___(err, __result) { __catch(function __$createOrUpdateDataLakeAnalyticsAccount() { if (err) {


              create = true; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$createOrUpdateDataLakeAnalyticsAccount() {


          accountParams = {
            name: accountName,
            properties: { },
            tags: tags }; return (function __$createOrUpdateDataLakeAnalyticsAccount(__then) {


            if (create) {
              if (!location) {
                return _(null, cli.missingArgument("location")); } ;

              if (!defaultDataLakeStore) {
                return _(null, cli.missingArgument("defaultDataLakeStore")); } ;


              accountParams.properties.defaultDataLakeStoreAccount = defaultDataLakeStore;
              accountParams.properties.dataLakeStoreAccounts = [{ name: defaultDataLakeStore },];
              accountParams.location = location;

              return client.account.create(resourceGroup, accountParams.name, accountParams, __cb(_, __frame, 35, 23, __then, true)); } else {


              if (defaultDataLakeStore) {
                accountParams.properties.defaultDataLakeStoreAccount = defaultDataLakeStore; } ;


              return client.account.update(resourceGroup, accountParams.name, accountParams, __cb(_, __frame, 42, 23, __then, true)); } ; })(function __$createOrUpdateDataLakeAnalyticsAccount() {


            return client.account.get(resourceGroup, accountName, __cb(_, __frame, 45, 28, _, true)); }); }); }); }); };


  function getCatalogItem(subscription, accountName, itemPath, itemType, _) { var isList, client, catalogItem, toReturn; var __frame = { name: "getCatalogItem", line: 758 }; return __func(_, this, arguments, getCatalogItem, 4, __frame, function __$getCatalogItem() {
      isList = isCatalogItemOrList(itemPath, itemType);
      client = utils.createDataLakeAnalyticsCatalogManagementClient(subscription);
      catalogItem = getCatalogItemObject(itemPath);
      toReturn = []; return (function __$getCatalogItem(__break) {

        switch (itemType.toLowerCase()) {
        case "database": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listDatabases(accountName, __cb(_, __frame, 9, 38, function ___(__0, __1) {
                toReturn = __1; __then(); }, true)); } else { return client.catalog.getDatabase(accountName, catalogItem.databaseName, __cb(_, __frame, 12, 41, function ___(__0, __2) {


                toReturn.push(__2); __then(); }, true)); } ; })(__break);


        case "schema": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listSchemas(accountName, catalogItem.databaseName, __cb(_, __frame, 17, 38, function ___(__0, __3) {
                toReturn = __3; __then(); }, true)); } else { return client.catalog.getSchema(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, __cb(_, __frame, 20, 41, function ___(__0, __4) {


                toReturn.push(__4); __then(); }, true)); } ; })(__break);


        case "secret": return (function __$getCatalogItem(__then) { if (isList) {
              return _(new Error($("U-SQL Secrets can only be returned by specific database secret name combination. There is no list support.")));
            } else { return client.catalog.getSecret(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, __cb(_, __frame, 28, 41, function ___(__0, __5) {


                toReturn.push(__5); __then(); }, true)); } ; })(__break);



        case "assembly": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listAssemblies(accountName, catalogItem.databaseName, __cb(_, __frame, 34, 38, function ___(__0, __6) {
                toReturn = __6; __then(); }, true)); } else { return client.catalog.getAssembly(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, __cb(_, __frame, 37, 41, function ___(__0, __7) {


                toReturn.push(__7); __then(); }, true)); } ; })(__break);


        case "externaldatasource": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listExternalDataSources(accountName, catalogItem.databaseName, __cb(_, __frame, 42, 38, function ___(__0, __8) {
                toReturn = __8; __then(); }, true)); } else { return client.catalog.getExternalDataSource(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, __cb(_, __frame, 45, 41, function ___(__0, __9) {


                toReturn.push(__9); __then(); }, true)); } ; })(__break);


        case "credential": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listCredentials(accountName, catalogItem.databaseName, __cb(_, __frame, 50, 38, function ___(__0, __10) {
                toReturn = __10; __then(); }, true)); } else { return client.catalog.getCredential(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, __cb(_, __frame, 53, 41, function ___(__0, __11) {


                toReturn.push(__11); __then(); }, true)); } ; })(__break);


        case "table": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listTables(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, __cb(_, __frame, 58, 38, function ___(__0, __12) {
                toReturn = __12; __then(); }, true)); } else { return client.catalog.getTable(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, catalogItem.tableOrTableValuedFunctionName, __cb(_, __frame, 61, 41, function ___(__0, __13) {


                toReturn.push(__13); __then(); }, true)); } ; })(__break);


        case "tablevaluedfunction": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listTableValuedFunctions(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, __cb(_, __frame, 66, 38, function ___(__0, __14) {
                toReturn = __14; __then(); }, true)); } else { return client.catalog.getTableValuedFunction(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, catalogItem.tableOrTableValuedFunctionName, __cb(_, __frame, 69, 41, function ___(__0, __15) {


                toReturn.push(__15); __then(); }, true)); } ; })(__break);


        case "tablestatistics": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listTableStatistics(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, catalogItem.tableOrTableValuedFunctionName, __cb(_, __frame, 74, 38, function ___(__0, __16) {
                toReturn = __16; __then(); }, true)); } else { return client.catalog.getTableStatistic(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, catalogItem.tableOrTableValuedFunctionName, catalogItem.tableStatisticsName, __cb(_, __frame, 77, 41, function ___(__0, __17) {


                toReturn.push(__17); __then(); }, true)); } ; })(__break);


        case "tablepartition": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listTablePartitions(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, catalogItem.tableOrTableValuedFunctionName, __cb(_, __frame, 82, 38, function ___(__0, __18) {
                toReturn = __18; __then(); }, true)); } else { return client.catalog.getTablePartition(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, catalogItem.tableOrTableValuedFunctionName, catalogItem.tableStatisticsName, __cb(_, __frame, 85, 41, function ___(__0, __19) {


                toReturn.push(__19); __then(); }, true)); } ; })(__break);


        case "view": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listViews(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, __cb(_, __frame, 90, 38, function ___(__0, __20) {
                toReturn = __20; __then(); }, true)); } else { return client.catalog.getView(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, catalogItem.tableOrTableValuedFunctionName, __cb(_, __frame, 93, 41, function ___(__0, __21) {


                toReturn.push(__21); __then(); }, true)); } ; })(__break);


        case "procedure": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listProcedures(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, __cb(_, __frame, 98, 38, function ___(__0, __22) {
                toReturn = __22; __then(); }, true)); } else { return client.catalog.getProcedure(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, catalogItem.tableOrTableValuedFunctionName, __cb(_, __frame, 101, 41, function ___(__0, __23) {


                toReturn.push(__23); __then(); }, true)); } ; })(__break);


        case "types": return (function __$getCatalogItem(__then) { if (isList) {
              return client.catalog.listTypes(accountName, catalogItem.databaseName, catalogItem.schemaAssemblyOrExternalDataSourceName, __cb(_, __frame, 106, 38, function ___(__0, __24) {
                toReturn = __24; __then(); }, true)); } else { return _(new Error($("U-SQL Types can only be returned in a list of all types within a database and schema combination.")));


            } ; })(__break); default:


          return _(new Error($((("Invalid catalog item type: " + itemType) + " specified. Valid values are (case insensitive): database, schema, assembly, externaldatasource, table, tablevaluedfunction or tablestatistics"))));
        }; })(function __$getCatalogItem() {


        return _(null, toReturn); }); }); };


  function isCatalogItemOrList(itemPath, itemType) {
    var isList = false;
    if ((!itemPath || (itemPath === ""))) {

      return true; } ;


    var catalogItem = getCatalogItemObject(itemPath);
    switch (itemType.toLowerCase()) {
    case "database": if (!catalogItem.databaseName) {
        isList = true;
      } ; break;

    case "schema":
    
    case "assembly": 
    case "externaldatasource": 
    case "credential": 
    case "secret": if (!catalogItem.databaseName) {
        throw new Error($(((("Invalid catalog path: " + itemPath) + ". A catalog path must be in the following format with no empty internal elements:") + " <FirstPart>.<OptionalSecondPart>.<OptionalThirdPart>.<OptionalFourthPart>. For example: Master.dbo.tableName.tableStatisticsName")));
      } ; if (!catalogItem.schemaAssemblyOrExternalDataSourceName) {




        isList = true;
      } ; break;

    case "table":
    
    case "tablevaluedfunction": 
    case "procedure": 
    case "view": 
    case "types": if ((!catalogItem.databaseName || !catalogItem.schemaAssemblyOrExternalDataSourceName)) {
        throw new Error($(((("Invalid catalog path: " + itemPath) + ". A catalog path must be in the following format with no empty internal elements:") + " <FirstPart>.<OptionalSecondPart>.<OptionalThirdPart>.<OptionalFourthPart>. For example: Master.dbo.tableName.tableStatisticsName")));
      } ; if (!catalogItem.tableOrTableValuedFunctionName) {




        isList = true;
      } ; break;

    case "tablestatistics":
    
    case "tablepartition": if (((!catalogItem.databaseName || !catalogItem.schemaAssemblyOrExternalDataSourceName) || !catalogItem.tableOrTableValuedFunctionName)) {
        throw new Error($(((("Invalid catalog path: " + itemPath) + ". A catalog path must be in the following format with no empty internal elements:") + " <FirstPart>.<OptionalSecondPart>.<OptionalThirdPart>.<OptionalFourthPart>. For example: Master.dbo.tableName.tableStatisticsName")));
      } ; if (!catalogItem.tableStatisticsName) {




        isList = true;
      } ; break;

    };


    return isList; };


  function getCatalogItemObject(itemPath) {
    var toReturn = {
      fullitemPath: itemPath };


    if ((!itemPath || (itemPath.indexOf(".") < 0))) {
      toReturn.databaseName = itemPath;
      return toReturn; } ;


    var regexPattern = /^(\w+|\[.+\])?(\.(\w+|\[.+\]))?(\.(\w+|\[.+\]))?(\.(\w+|\[.+\]))?$/;
    var matches = regexPattern.exec(itemPath);
    if (!matches) {
      throw new Error($(((("Invalid catalog path: " + itemPath) + ". A catalog path must be in the following format with no empty internal elements:") + " <FirstPart>.<OptionalSecondPart>.<OptionalThirdPart>.<OptionalFourthPart>. For example: Master.dbo.tableName.tableStatisticsName"))); } ;




    var firstPart = sanitizeitemPath(matches[1], itemPath);
    var secondPart = sanitizeitemPath(matches[3], itemPath);
    var thirdPart = sanitizeitemPath(matches[5], itemPath);
    var fourthPart = sanitizeitemPath(matches[7], itemPath);

    toReturn.databaseName = firstPart;
    toReturn.schemaAssemblyOrExternalDataSourceName = secondPart;
    toReturn.tableOrTableValuedFunctionName = thirdPart;
    toReturn.tableStatisticsName = fourthPart;

    return toReturn; };


  function sanitizeitemPath(path, fullPath) {
    if (!path) {
      return path; } ;


    if (((path.indexOf("[") === 0) && (path.lastIndexOf("]") === (path.length - 1)))) {
      path = path.substring(1);
      path = path.substring(0, (path.length - 1)); } ;


    if ((path.length < 1)) {
      throw new Error($(((("Invalid catalog path: " + fullPath) + ". A catalog path must be in the following format with no empty internal elements:") + " <FirstPart>.<OptionalSecondPart>.<OptionalThirdPart>.<OptionalFourthPart>. For example: Master.dbo.tableName.tableStatisticsName"))); } ;




    return path; };


  function listAllDataLakeAnalyticsAccounts(subscription, resourceGroup, _) { var client, accounts, response; var __frame = { name: "listAllDataLakeAnalyticsAccounts", line: 988 }; return __func(_, this, arguments, listAllDataLakeAnalyticsAccounts, 2, __frame, function __$listAllDataLakeAnalyticsAccounts() {
      client = utils.createDataLakeAnalyticsManagementClient(subscription); return (function __$listAllDataLakeAnalyticsAccounts(__then) {


        if (!resourceGroup) {
          return client.account.list(__cb(_, __frame, 5, 32, function ___(__0, __1) { response = __1;
            log.info(util.inspect(response));
            accounts = response;
            while (response.nextLink) {
              response = client.account.listNext(response.nextLink);
              accounts.push.apply(accounts, response); }; __then(); }, true)); } else {



          return client.account.listByResourceGroup(resourceGroup, __cb(_, __frame, 14, 32, function ___(__0, __2) { response = __2;
            accounts = response;
            while (response.nextLink) {
              response = client.account.listByResourceGroupNext(response.nextLink);
              accounts.push.apply(accounts, response); }; __then(); }, true)); } ; })(function __$listAllDataLakeAnalyticsAccounts() {



        return _(null, accounts); }); }); };


  function getResrouceGroupByAccountName(subscription, resourceGroup, name, _) { var accounts, i, acctId, rgStart, rgEnd; var __frame = { name: "getResrouceGroupByAccountName", line: 1013 }; return __func(_, this, arguments, getResrouceGroupByAccountName, 3, __frame, function __$getResrouceGroupByAccountName() {
      return listAllDataLakeAnalyticsAccounts(subscription, resourceGroup, __cb(_, __frame, 1, 19, function ___(__0, __1) { accounts = __1;
        for (i = 0; (i < accounts.length); i++) {
          if ((accounts[i].name === name)) {
            acctId = accounts[i].id;
            rgStart = (acctId.indexOf("resourceGroups/") + ("resourceGroups/".length));
            rgEnd = acctId.indexOf("/providers/");
            return _(null, acctId.substring(rgStart, rgEnd)); } ; };



        return _(new Error($(((((("Could not find account: " + name) + " in any resource group in subscription: ") + subscription.name) + " with id: ") + subscription.id)))); }, true)); }); };};
