convex
Version:
Client for the Convex Cloud
75 lines (74 loc) • 2.93 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 common_exports = {};
__export(common_exports, {
isSimpleObject: () => isSimpleObject,
parseArgs: () => parseArgs,
validateDeploymentUrl: () => validateDeploymentUrl
});
module.exports = __toCommonJS(common_exports);
function parseArgs(args) {
if (args === void 0) {
return {};
}
if (!isSimpleObject(args)) {
throw new Error(
`The arguments to a Convex function must be an object. Received: ${args}`
);
}
return args;
}
function validateDeploymentUrl(deploymentUrl) {
if (typeof deploymentUrl === "undefined") {
throw new Error(
`Client created with undefined deployment address. If you used an environment variable, check that it's set.`
);
}
if (typeof deploymentUrl !== "string") {
throw new Error(
`Invalid deployment address: found ${deploymentUrl}".`
);
}
if (!(deploymentUrl.startsWith("http:") || deploymentUrl.startsWith("https:"))) {
throw new Error(
`Invalid deployment address: Must start with "https://" or "http://". Found "${deploymentUrl}".`
);
}
try {
new URL(deploymentUrl);
} catch {
throw new Error(
`Invalid deployment address: "${deploymentUrl}" is not a valid URL. If you believe this URL is correct, use the \`skipConvexDeploymentUrlCheck\` option to bypass this.`
);
}
if (deploymentUrl.endsWith(".convex.site")) {
throw new Error(
`Invalid deployment address: "${deploymentUrl}" ends with .convex.site, which is used for HTTP Actions. Convex deployment URLs typically end with .convex.cloud? If you believe this URL is correct, use the \`skipConvexDeploymentUrlCheck\` option to bypass this.`
);
}
}
function isSimpleObject(value) {
const isObject = typeof value === "object";
const prototype = Object.getPrototypeOf(value);
const isSimple = prototype === null || prototype === Object.prototype || // Objects generated from other contexts (e.g. across Node.js `vm` modules) will not satisfy the previous
// conditions but are still simple objects.
prototype?.constructor?.name === "Object";
return isObject && isSimple;
}
//# sourceMappingURL=index.js.map
;