convex
Version:
Client for the Convex Cloud
70 lines (69 loc) • 1.83 kB
JavaScript
;
const functionName = Symbol.for("functionName");
export function getFunctionName(functionReference) {
if (typeof functionReference === "string")
return functionReference;
const name = functionReference[functionName];
if (!name) {
throw new Error(`${functionReference} is not a functionReference`);
}
return name;
}
export function makeFunctionReference(name) {
return { [functionName]: name };
}
function createApi(pathParts = []) {
const handler = {
get(_, prop) {
if (typeof prop === "string") {
const newParts = [...pathParts, prop];
return createApi(newParts);
} else if (prop === functionName) {
if (pathParts.length < 2) {
const found = ["api", ...pathParts].join(".");
throw new Error(
`API path is expected to be of the form \`api.moduleName.functionName\`. Found: \`${found}\``
);
}
const path = pathParts.slice(0, -1).join("/");
const exportName = pathParts[pathParts.length - 1];
if (exportName === "default") {
return path;
} else {
return path + ":" + exportName;
}
} else if (prop === Symbol.toStringTag) {
return "FunctionReference";
} else {
return void 0;
}
}
};
return new Proxy({}, handler);
}
export function filterApi(api) {
return api;
}
export function justInternal(api) {
return api;
}
export function justPublic(api) {
return api;
}
export function justQueries(api) {
return api;
}
export function justMutations(api) {
return api;
}
export function justActions(api) {
return api;
}
export function justPaginatedQueries(api) {
return api;
}
export function justSchedulable(api) {
return api;
}
export const anyApi = createApi();
//# sourceMappingURL=api.js.map