tailjnx 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/bin/tailjnx.js +90 -16
- package/dist/cli/bin/tailjnx.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/bin/tailjnx.js
CHANGED
|
@@ -2506,6 +2506,10 @@ var require_init_app = __commonJS({
|
|
|
2506
2506
|
} catch (installError) {
|
|
2507
2507
|
const msg = installError instanceof Error ? installError.message : String(installError);
|
|
2508
2508
|
consoleHelper4.error({ message: `No se pudieron instalar dependencias: ${msg}` });
|
|
2509
|
+
console.log(import_chalk4.default.yellow("\n Si usas tailjnx v\xEDa file:.tgz y ves EINTEGRITY / tarball corrupted:"));
|
|
2510
|
+
console.log(import_chalk4.default.gray(" 1. Det\xE9n npm run dev (Windows bloquea node_modules/tailjnx si est\xE1 activo)"));
|
|
2511
|
+
console.log(import_chalk4.default.gray(" 2. Desde la ra\xEDz del monorepo: npm run sync:demo-tgz"));
|
|
2512
|
+
console.log(import_chalk4.default.gray(" o: npm install file:packages/tailjnx/tailjnx-0.1.0.tgz -w demo-backend --force"));
|
|
2509
2513
|
console.log(import_chalk4.default.yellow("\n Inst\xE1lalas manualmente en este proyecto:"));
|
|
2510
2514
|
console.log(import_chalk4.default.gray(` npm install ${runtimeDeps.join(" ")}`));
|
|
2511
2515
|
console.log(import_chalk4.default.gray(` npm install -D ${devDeps.join(" ")}
|
|
@@ -4819,7 +4823,7 @@ ${LABEL}
|
|
|
4819
4823
|
// EndPoints
|
|
4820
4824
|
|
|
4821
4825
|
// Ejemplo de endpoint personalizado
|
|
4822
|
-
router.get("/example/:id", ${Capital}Controller.example)
|
|
4826
|
+
${multiDatabase ? `router.get("/example/:id", verifyCompany, ${Capital}Controller.example);` : `router.get("/example/:id", ${Capital}Controller.example);`}
|
|
4823
4827
|
|
|
4824
4828
|
// Mantener este endpoint al final para no sobreescribir los personalizados, si este se encuentra al inicio las redirecciones se har\xE1n a este endpoint gen\xE9rico y no a los personalizados, por eso se recomienda mantenerlo al final.
|
|
4825
4829
|
${crudMount}
|
|
@@ -4827,8 +4831,47 @@ ${crudMount}
|
|
|
4827
4831
|
export default router;
|
|
4828
4832
|
`.trimStart();
|
|
4829
4833
|
};
|
|
4830
|
-
var generateController = (entity, baseImportPath) => {
|
|
4834
|
+
var generateController = (entity, baseImportPath, multiDatabase) => {
|
|
4831
4835
|
const Capital = toPascalCasePreservingUnderscores(entity);
|
|
4836
|
+
if (multiDatabase) {
|
|
4837
|
+
return `
|
|
4838
|
+
import { JController, JRequest } from 'tailjnx/api';
|
|
4839
|
+
|
|
4840
|
+
import ${entity}Service, { ${Capital}Service } from "@/${baseImportPath}/${entity}/${entity}.service";
|
|
4841
|
+
import { jCrudController } from 'tailjnx/api';
|
|
4842
|
+
import { Company } from '@/src/core/middleware/company.middleware';
|
|
4843
|
+
|
|
4844
|
+
// =============================================================================
|
|
4845
|
+
${LABEL}
|
|
4846
|
+
// =============================================================================
|
|
4847
|
+
|
|
4848
|
+
// Cruds genericos
|
|
4849
|
+
export const crud = jCrudController({ service: ${entity}Service.crud });
|
|
4850
|
+
|
|
4851
|
+
// =============================================================================
|
|
4852
|
+
|
|
4853
|
+
export class ${Capital}Controller {
|
|
4854
|
+
|
|
4855
|
+
/**
|
|
4856
|
+
* Controlador de ejemplo (multi-empresa).
|
|
4857
|
+
* Pasa req.company al servicio \u2014 requerido para jDatabaseMode en @JService.
|
|
4858
|
+
*/
|
|
4859
|
+
@JController({
|
|
4860
|
+
service: ${Capital}Service.example,
|
|
4861
|
+
extractParams: (req: JRequest) => [
|
|
4862
|
+
req.params.id,
|
|
4863
|
+
req.company as Company,
|
|
4864
|
+
],
|
|
4865
|
+
messages: {
|
|
4866
|
+
success: "Ejemplo obtenido exitosamente.",
|
|
4867
|
+
notFound: "Ejemplo no encontrado.",
|
|
4868
|
+
},
|
|
4869
|
+
})
|
|
4870
|
+
static example(): void { }
|
|
4871
|
+
|
|
4872
|
+
}
|
|
4873
|
+
`.trimStart();
|
|
4874
|
+
}
|
|
4832
4875
|
return `
|
|
4833
4876
|
import { Request } from "express";
|
|
4834
4877
|
import { JController } from 'tailjnx/api';
|
|
@@ -4848,8 +4891,8 @@ export const crud = jCrudController({ service: ${entity}Service.crud });
|
|
|
4848
4891
|
export class ${Capital}Controller {
|
|
4849
4892
|
|
|
4850
4893
|
/**
|
|
4851
|
-
* Controlador de ejemplo para personalizar un endpoint.
|
|
4852
|
-
*
|
|
4894
|
+
* Controlador de ejemplo para personalizar un endpoint (monolito).
|
|
4895
|
+
* En multi-empresa, a\xF1ade req.company y verifyCompany en la ruta; en el servicio usa jDatabaseMode.
|
|
4853
4896
|
*/
|
|
4854
4897
|
@JController({
|
|
4855
4898
|
service: ${Capital}Service.example,
|
|
@@ -4870,8 +4913,48 @@ export class ${Capital}Controller {
|
|
|
4870
4913
|
const Capital = toPascalCasePreservingUnderscores(entity);
|
|
4871
4914
|
const databaseModeLine = multiDatabase ? `
|
|
4872
4915
|
jDatabaseMode: 'selected',` : "";
|
|
4916
|
+
const exampleMethod = multiDatabase ? `
|
|
4917
|
+
/**
|
|
4918
|
+
* Ejemplo de endpoint personalizado con jDatabaseMode (multi-empresa).
|
|
4919
|
+
* En servicios @JService nuevos, usa jDatabaseMode para operar en la BD de x-company.
|
|
4920
|
+
* Modos: "selected" (empresa del header), "all" (replica en todas), "default" (primaria).
|
|
4921
|
+
*/
|
|
4922
|
+
@JService
|
|
4923
|
+
static async example(id_${entity}: string, company: Company, reqMsg: Record<string, string>) {
|
|
4924
|
+
if (!id_${entity}) return JHttpResponse.badRequest({ message: reqMsg.notFound });
|
|
4925
|
+
|
|
4926
|
+
const { results, dbs } = await jDatabaseMode({
|
|
4927
|
+
deps: { jDatabaseMode: 'selected' },
|
|
4928
|
+
company,
|
|
4929
|
+
operation: async (ctx) => {
|
|
4930
|
+
const { models } = ctx;
|
|
4931
|
+
const row = await models.${Capital}.findByPk(id_${entity});
|
|
4932
|
+
if (!row) {
|
|
4933
|
+
throw JHttpResponse.notFound({ message: reqMsg.notFound, dbs: ctx.dbName });
|
|
4934
|
+
}
|
|
4935
|
+
return { data: row };
|
|
4936
|
+
},
|
|
4937
|
+
});
|
|
4938
|
+
|
|
4939
|
+
return JHttpResponse.success({
|
|
4940
|
+
message: reqMsg.success,
|
|
4941
|
+
data: results[0]?.data,
|
|
4942
|
+
dbs: dbs.join(', '),
|
|
4943
|
+
});
|
|
4944
|
+
}` : `
|
|
4945
|
+
/**
|
|
4946
|
+
* Servicio de ejemplo para personalizar un endpoint (monolito).
|
|
4947
|
+
* En multi-empresa, usa jDatabaseMode + company (ver plantilla generate:entities).
|
|
4948
|
+
*/
|
|
4949
|
+
@JService
|
|
4950
|
+
static async example(id_${entity}: string, reqMsg: Record<string, string>) {
|
|
4951
|
+
if (!id_${entity}) return JHttpResponse.badRequest({ message: reqMsg.notFound });
|
|
4952
|
+
return JHttpResponse.success({ message: reqMsg.success });
|
|
4953
|
+
}`;
|
|
4954
|
+
const serviceImports = multiDatabase ? `import { JConsole, JHttpResponse, JService, jCrudService, jDatabaseMode } from 'tailjnx/api';
|
|
4955
|
+
import { Company } from '@/src/core/middleware/company.middleware';` : `import { JConsole, JHttpResponse, JService, jCrudService } from 'tailjnx/api';`;
|
|
4873
4956
|
return `
|
|
4874
|
-
|
|
4957
|
+
${serviceImports}
|
|
4875
4958
|
|
|
4876
4959
|
// Interface de la entidad
|
|
4877
4960
|
import { ${Capital} } from "${interfaceImportPath}";
|
|
@@ -4893,16 +4976,7 @@ export default {
|
|
|
4893
4976
|
// =============================================================================
|
|
4894
4977
|
|
|
4895
4978
|
export class ${Capital}Service {
|
|
4896
|
-
|
|
4897
|
-
/**
|
|
4898
|
-
* Servicio de ejemplo para personalizar un endpoint.
|
|
4899
|
-
* Este es un ejemplo de c\xF3mo personalizar un endpoint, puedes crear los tuyos propios siguiendo esta estructura, recuerda mantener el decorador @JService con la configuraci\xF3n necesaria para que funcione correctamente, tambi\xE9n puedes agregar validaciones personalizadas a los endpoints gen\xE9ricos utilizando los m\xE9todos del servicio en el archivo del controlador correspondiente.
|
|
4900
|
-
*/
|
|
4901
|
-
@JService
|
|
4902
|
-
static async example(id_${entity}: string, reqMsg: Record<string, string>) {
|
|
4903
|
-
if (!id_${entity}) return JHttpResponse.badRequest({ message: reqMsg.notFound });
|
|
4904
|
-
return JHttpResponse.success({ message: reqMsg.success });
|
|
4905
|
-
}
|
|
4979
|
+
${exampleMethod}
|
|
4906
4980
|
|
|
4907
4981
|
}
|
|
4908
4982
|
`.trimStart();
|
|
@@ -4916,7 +4990,7 @@ export class ${Capital}Service {
|
|
|
4916
4990
|
serviceTs: import_path12.default.join(entityDir, `${entity}.service.ts`)
|
|
4917
4991
|
};
|
|
4918
4992
|
if (!import_fs11.default.existsSync(files.controllerTs)) {
|
|
4919
|
-
import_fs11.default.writeFileSync(files.controllerTs, generateController(entity, baseImportPath));
|
|
4993
|
+
import_fs11.default.writeFileSync(files.controllerTs, generateController(entity, baseImportPath, multiDatabase));
|
|
4920
4994
|
}
|
|
4921
4995
|
if (!import_fs11.default.existsSync(files.routesTs)) {
|
|
4922
4996
|
import_fs11.default.writeFileSync(files.routesTs, generateRoutes(entity, baseImportPath, multiDatabase));
|