UNPKG

@palmares/databases

Version:

Add support for working with databases with palmares framework

146 lines (132 loc) 5.94 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); 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); // src/logging.ts var logging_exports = {}; __export(logging_exports, { databaseLogger: () => databaseLogger }); module.exports = __toCommonJS(logging_exports); var import_logging = require("@palmares/logging"); var databaseLogger = new import_logging.Logger({ domainName: "@palmares/databases" }, { MODELS_NOT_FOUND: { category: "warn", handler: /* @__PURE__ */ __name(({ domainName }) => `Looks like the domain ${domainName} did not define any models. If that's not intended behavior, you should create the 'models.ts'/'models.js' file in the ${domainName} domain or add the 'getModels' to the domain class.`, "handler") }, DATABASE_CLOSING: { category: "info", handler: /* @__PURE__ */ __name(({ databaseName }) => `Closing the '${databaseName}' database connection.`, "handler") }, DATABASE_IS_NOT_CONNECTED: { category: "info", handler: /* @__PURE__ */ __name(({ databaseName }) => `Couldn't connect to the '${databaseName}' database.`, "handler") }, FAILED_TO_GET_LAST_MIGRATION: { category: "error", handler: /* @__PURE__ */ __name(({ databaseName, reason, stack }) => `Failed to get the last migration for the '${databaseName}' database. \x1B[1mReason:\x1B[0m ${reason} \x1B[1mStack:\x1B[0m ${stack}`, "handler") }, FAILED_TO_COMMIT_MIGRATION: { category: "error", handler: /* @__PURE__ */ __name(({ migrationName, databaseName, reason, stack }) => `Failed to get insert ran migration '${migrationName}' for the '${databaseName}' database. \x1B[1mReason:\x1B[0m ${reason} \x1B[1mStack:\x1B[0m ${stack}`, "handler") }, MIGRATIONS_NOT_FOUND: { category: "warn", handler: /* @__PURE__ */ __name(({ domainName }) => `No migrations were found for the '${domainName}', if this is your first time running this command, you can safely ignore this message. You can fully dismiss this message by setting 'DATABASES_DISMISS_NO_MIGRATIONS_LOG = true;' in 'settings.(ts/js)'`, "handler") }, MIGRATIONS_FILE_TITLE: { category: "info", handler: /* @__PURE__ */ __name(({ title }) => `- \x1B[36m${title}`, "handler") }, MIGRATIONS_FILE_DESCRIPTION: { category: "info", handler: /* @__PURE__ */ __name(({ database, lastMigrationName, lastDomainPath }) => `Generating migration on the \x1B[1m'${database}'\x1B[0m database` + (lastMigrationName !== "" && lastDomainPath !== "" ? ` that depends on the migration \x1B[1m'${lastMigrationName}'\x1B[0m that exists on \x1B[1m'${lastDomainPath}'\x1B[0m` : ""), "handler") }, MIGRATIONS_NO_NEW_MIGRATIONS: { category: "info", handler: /* @__PURE__ */ __name(({ databaseName }) => `There are no migrations to run for '${databaseName}'. If you made changes to your models, please run\x1B[1m makemigrations\x1B[0m command first.`, "handler") }, MIGRATIONS_RUNNING_FILE_NAME: { category: "info", handler: /* @__PURE__ */ __name(({ title }) => `Running migration: \x1B[36m${title}\x1B[0m`, "handler") }, MIGRATION_RUNNING_IN_BATCH: { category: "info", handler: /* @__PURE__ */ __name(({ databaseName }) => `The engine that you are using for '${databaseName}' implements a batch migrations, this means that instead of running each migration file one by one, we will let the chosen engine handle the migration runner.`, "handler") }, MIGRATIONS_ACTION_DESCRIPTION: { category: "info", handler: /* @__PURE__ */ __name(({ description }) => ` \u2022 ${description}`, "handler") }, NO_CHANGES_MADE_FOR_MIGRATIONS: { category: "info", handler: /* @__PURE__ */ __name(() => `No changes were found in your models.`, "handler") }, QUERY_NOT_PROPERLY_SET: { category: "warn", handler: /* @__PURE__ */ __name(({ modelName, invalidFields }) => { const errorsByField = Array.from(invalidFields).map(([_, isValidObject]) => { return `- ${isValidObject.reason}`; }).join("\n"); return `The fields on the query to retrieve '${modelName}' data was not set properly and contain wrong or missing data ${errorsByField}`; }, "handler") }, CREATE_PALMARES_DB_APP: { category: "info", handler: /* @__PURE__ */ __name(({ name, template }) => `Creating Palmares database app '${name}' using the template '${template}'`, "handler") }, DONE_CREATING_PALMARES_DB_APP: { category: "info", handler: /* @__PURE__ */ __name(({ name, template }) => `Done creating Palmares database app '${name}' using the template '${template}' Next steps: 1. cd ${name} 2. Install the dependencies with your favorite package manager: - $ pnpm i - $ yarn - $ npm i - $ bun i 3. Create the migrations: - $ pnpm run makemigrations - $ yarn run makemigrations - $ npm run makemigrations - $ bun run makemigrations 4. Apply the migrations: - $ pnpm run migrate - $ yarn run migrate - $ npm run migrate - $ bun run migrate 5. Start the application: - $ pnpm run dev - $ yarn run dev - $ npm run dev - $ bun run dev`, "handler") } }); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { databaseLogger });