convex
Version:
Client for the Convex Cloud
109 lines (108 loc) • 4.1 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var run_exports = {};
__export(run_exports, {
run: () => run
});
module.exports = __toCommonJS(run_exports);
var import_extra_typings = require("@commander-js/extra-typings");
var import_context = require("../bundler/context.js");
var import_dev = require("./dev.js");
var import_api = require("./lib/api.js");
var import_command = require("./lib/command.js");
var import_run = require("./lib/run.js");
var import_utils = require("./lib/utils/utils.js");
const run = new import_extra_typings.Command("run").description("Run a function (query, mutation, or action) on your deployment").argument(
"functionName",
"identifier of the function to run, like `listMessages` or `dir/file:myFunction`"
).argument(
"[args]",
"JSON-formatted arguments object to pass to the function."
).option(
"-w, --watch",
"Watch a query, printing its result if the underlying data changes. Given function must be a query."
).option("--push", "Push code to deployment before running the function.").addOption(new import_extra_typings.Option("--no-push").hideHelp()).addDeploymentSelectionOptions((0, import_command.actionDescription)("Run the function on")).addOption(
new import_extra_typings.Option(
"--typecheck <mode>",
`Whether to check TypeScript files with \`tsc --noEmit\`.`
).choices(["enable", "try", "disable"]).default("try")
).addOption(
new import_extra_typings.Option("--codegen <mode>", "Regenerate code in `convex/_generated/`").choices(["enable", "disable"]).default("enable")
).addOption(
new import_extra_typings.Option(
"--component-path <path>",
"Path to the component in the component tree defined in convex.config.ts"
// TODO(ENG-6967): Remove hideHelp before launching components
).hideHelp()
).showHelpAfterError().action(async (functionName, argsString, options) => {
const ctx = import_context.oneoffContext;
const deploymentSelection = (0, import_api.deploymentSelectionFromOptions)(options);
const {
adminKey,
url: deploymentUrl,
deploymentType
} = await (0, import_api.fetchDeploymentCredentialsProvisionProd)(ctx, deploymentSelection);
await (0, import_utils.ensureHasConvexDependency)(ctx, "run");
const args = argsString ? JSON.parse(argsString) : {};
if (deploymentType === "prod" && options.push) {
return await ctx.crash({
exitCode: 1,
errorType: "fatal",
printedMessage: `\`convex run\` doesn't support pushing functions to prod deployments. Remove the --push flag. To push to production use \`npx convex deploy\`.`
});
}
if (options.push) {
await (0, import_dev.watchAndPush)(
ctx,
{
adminKey,
verbose: false,
dryRun: false,
typecheck: options.typecheck,
debug: false,
codegen: options.codegen === "enable",
url: deploymentUrl,
cleanupHandle: null
},
{
once: true,
traceEvents: false,
untilSuccess: true
}
);
}
if (options.watch) {
return await (0, import_run.subscribeAndLog)(
ctx,
deploymentUrl,
adminKey,
functionName,
args
);
}
return await (0, import_run.runFunctionAndLog)(
ctx,
deploymentUrl,
adminKey,
functionName,
args,
options.componentPath
);
});
//# sourceMappingURL=run.js.map