zenstack
Version:
FullStack enhancement for Prisma ORM: seamless integration from database to UI
52 lines • 2.98 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.description = exports.name = void 0;
const sdk_1 = require("@zenstackhq/sdk");
const path_1 = __importDefault(require("path"));
const plugin_utils_1 = require("../plugin-utils");
const enhance_1 = require("./enhance");
const model_meta_1 = require("./model-meta");
const policy_1 = require("./policy");
exports.name = 'Prisma Enhancer';
exports.description = 'Generating PrismaClient enhancer';
const run = (model, options, _dmmf, globalOptions) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
let outDir = options.output ? options.output : (0, plugin_utils_1.getDefaultOutputFolder)(globalOptions);
if (!outDir) {
throw new sdk_1.PluginError(exports.name, `Unable to determine output path, not running plugin`);
}
outDir = (0, sdk_1.resolvePath)(outDir, options);
const project = (_a = globalOptions === null || globalOptions === void 0 ? void 0 : globalOptions.tsProject) !== null && _a !== void 0 ? _a : (0, sdk_1.createProject)();
yield (0, model_meta_1.generate)(model, options, project, outDir);
yield (0, policy_1.generate)(model, options, project, outDir);
const { dmmf, newPrismaClientDtsPath } = yield new enhance_1.EnhancerGenerator(model, options, project, outDir).generate();
let prismaClientPath;
if (dmmf) {
// a logical client is generated
if (options.output || (globalOptions === null || globalOptions === void 0 ? void 0 : globalOptions.output)) {
// handle custom output path
// get the absolute path of the prisma client types
const prismaClientPathAbs = path_1.default.resolve(outDir, 'models');
// resolve it relative to the schema path
prismaClientPath = (0, sdk_1.normalizedRelative)(path_1.default.dirname(options.schemaPath), prismaClientPathAbs);
}
else {
prismaClientPath = `${sdk_1.RUNTIME_PACKAGE}/models`;
}
}
return { dmmf, warnings: [], prismaClientPath, prismaClientDtsPath: newPrismaClientDtsPath };
});
exports.default = run;
//# sourceMappingURL=index.js.map
;