convex
Version:
Client for the Convex Cloud
84 lines (81 loc) • 2.87 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 api_exports = {};
__export(api_exports, {
apiCodegen: () => apiCodegen,
importPath: () => importPath,
moduleIdentifier: () => moduleIdentifier
});
module.exports = __toCommonJS(api_exports);
var import_common = require("./common.js");
function importPath(modulePath) {
const filePath = modulePath.replace(/\\/g, "/");
const lastDot = filePath.lastIndexOf(".");
return filePath.slice(0, lastDot === -1 ? void 0 : lastDot);
}
function moduleIdentifier(modulePath) {
let safeModulePath = importPath(modulePath).replace(/\//g, "_").replace(/-/g, "_");
if (["fullApi", "api", "internal", "components"].includes(safeModulePath)) {
safeModulePath = `${safeModulePath}_`;
}
return safeModulePath;
}
function apiCodegen(modulePaths) {
const apiDTS = `${(0, import_common.header)("Generated `api` utility.")}
import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
${modulePaths.map(
(modulePath) => `import type * as ${moduleIdentifier(modulePath)} from "../${importPath(
modulePath
)}.js";`
).join("\n")}
/**
* A utility for referencing Convex functions in your app's API.
*
* Usage:
* \`\`\`js
* const myFunctionReference = api.myModule.myFunction;
* \`\`\`
*/
declare const fullApi: ApiFromModules<{
${modulePaths.map(
(modulePath) => `"${importPath(modulePath)}": typeof ${moduleIdentifier(modulePath)},`
).join("\n")}
}>;
export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
`;
const apiJS = `${(0, import_common.header)("Generated `api` utility.")}
import { anyApi } from "convex/server";
/**
* A utility for referencing Convex functions in your app's API.
*
* Usage:
* \`\`\`js
* const myFunctionReference = api.myModule.myFunction;
* \`\`\`
*/
export const api = anyApi;
export const internal = anyApi;
`;
return {
DTS: apiDTS,
JS: apiJS
};
}
//# sourceMappingURL=api.js.map