convex
Version:
Client for the Convex Cloud
103 lines (102 loc) • 3.12 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 meta_impl_exports = {};
__export(meta_impl_exports, {
setupActionMeta: () => setupActionMeta,
setupMutationMeta: () => setupMutationMeta,
setupQueryMeta: () => setupQueryMeta
});
module.exports = __toCommonJS(meta_impl_exports);
var import_values = require("../../values/index.js");
var import_syscall = require("./syscall.js");
async function getTransactionMetrics() {
let syscallJSON;
try {
syscallJSON = await (0, import_syscall.performAsyncSyscall)("1.0/getTransactionMetrics", {});
} catch (e) {
if (e.message?.includes("Unknown async operation")) {
throw new Error(
"getTransactionMetrics() can only be called from a query or mutation. It is not available in actions or outside of a Convex function."
);
}
throw e;
}
return (0, import_values.jsonToConvex)(syscallJSON);
}
async function getFunctionMetadata() {
const { name, componentPath } = await (0, import_syscall.performAsyncSyscall)(
"1.0/getFunctionMetadata",
{}
);
return { name, componentPath };
}
async function getDeploymentMetadata() {
const syscallJSON = await (0, import_syscall.performAsyncSyscall)(
"1.0/getDeploymentMetadata",
{}
);
const result = (0, import_values.jsonToConvex)(syscallJSON);
return {
name: result.name,
region: result.region ?? null,
class: result.class
};
}
async function getRequestMetadata() {
const { ip, userAgent, requestId } = await (0, import_syscall.performAsyncSyscall)(
"1.0/getRequestMetadata",
{}
);
return { ip, userAgent, requestId };
}
function setupQueryMeta(visibility) {
return {
getFunctionMetadata: async () => ({
...await getFunctionMetadata(),
type: "query",
visibility
}),
getTransactionMetrics,
getDeploymentMetadata
};
}
function setupMutationMeta(visibility) {
return {
getFunctionMetadata: async () => ({
...await getFunctionMetadata(),
type: "mutation",
visibility
}),
getTransactionMetrics,
getDeploymentMetadata,
getRequestMetadata
};
}
function setupActionMeta(visibility) {
return {
getFunctionMetadata: async () => ({
...await getFunctionMetadata(),
type: "action",
visibility
}),
getDeploymentMetadata,
getRequestMetadata
};
}
//# sourceMappingURL=meta_impl.js.map