UNPKG

convex

Version:

Client for the Convex Cloud

47 lines (46 loc) 1.76 kB
"use strict"; export 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; } export 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}".` ); } if (deploymentUrl.indexOf("127.0.0.1") !== -1 || deploymentUrl.indexOf("localhost") !== -1) { return; } if (!deploymentUrl.endsWith(".convex.cloud") && !deploymentUrl.includes("0.0.0.0")) { throw new Error( `Invalid deployment address: Must end with ".convex.cloud". Found "${deploymentUrl}". If you believe this URL is correct, use the \`skipConvexDeploymentUrlCheck\` option to bypass this.` ); } } export 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