@devbro/pashmak 0.1.6 → 0.1.8
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/app/console/KeyGenerateCommand.js +4 -4
- package/dist/app/console/KeyGenerateCommand.js.map +1 -1
- package/dist/app/console/generate/GenerateControllerCommand.js +1 -0
- package/dist/app/console/generate/GenerateControllerCommand.js.map +1 -1
- package/dist/app/console/generate/controller.tpl +14 -3
- package/dist/app/console/index.d.ts +1 -1
- package/dist/app/console/migrate/{MakeMigrateCommand.d.ts → GenerateMigrateCommand.d.ts} +2 -2
- package/dist/app/console/migrate/{MakeMigrateCommand.js → GenerateMigrateCommand.js} +7 -7
- package/dist/app/console/migrate/GenerateMigrateCommand.js.map +1 -0
- package/dist/app/console/migrate/index.d.ts +1 -1
- package/dist/app/console/migrate/index.js +1 -1
- package/dist/app/console/migrate/index.js.map +1 -1
- package/dist/app/console/project/CreateProjectCommand.js +1 -4
- package/dist/app/console/project/CreateProjectCommand.js.map +1 -1
- package/dist/app/console/project/base_project/package.json.tpl +1 -1
- package/dist/bin/pashmak_cli.cjs +1 -4
- package/dist/middlewares.d.ts +8 -0
- package/dist/middlewares.js +41 -0
- package/dist/middlewares.js.map +1 -0
- package/dist/router.d.ts +1 -1
- package/dist/router.js +1 -1
- package/dist/router.js.map +1 -1
- package/package.json +6 -1
- package/dist/app/console/migrate/MakeMigrateCommand.js.map +0 -1
|
@@ -11,8 +11,8 @@ class KeyGenerateCommand extends Command {
|
|
|
11
11
|
}
|
|
12
12
|
static paths = [
|
|
13
13
|
[
|
|
14
|
-
`
|
|
15
|
-
"
|
|
14
|
+
`generate`,
|
|
15
|
+
"key"
|
|
16
16
|
]
|
|
17
17
|
];
|
|
18
18
|
static usage = Command.Usage({
|
|
@@ -25,11 +25,11 @@ class KeyGenerateCommand extends Command {
|
|
|
25
25
|
examples: [
|
|
26
26
|
[
|
|
27
27
|
`Generate new keys`,
|
|
28
|
-
`key
|
|
28
|
+
`generate key`
|
|
29
29
|
],
|
|
30
30
|
[
|
|
31
31
|
`Rotate existing keys`,
|
|
32
|
-
`key
|
|
32
|
+
`generate key --rotate`
|
|
33
33
|
]
|
|
34
34
|
]
|
|
35
35
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/app/console/KeyGenerateCommand.ts"],"sourcesContent":["import { Command, Option } from \"clipanion\";\nimport { generateKeyPairSync } from \"crypto\";\nimport fs from \"fs/promises\";\nimport path from \"path\";\nimport { logger, cli } from \"../../facades\";\n\nexport class KeyGenerateCommand extends Command {\n static paths = [[`
|
|
1
|
+
{"version":3,"sources":["../../../src/app/console/KeyGenerateCommand.ts"],"sourcesContent":["import { Command, Option } from \"clipanion\";\nimport { generateKeyPairSync } from \"crypto\";\nimport fs from \"fs/promises\";\nimport path from \"path\";\nimport { logger, cli } from \"../../facades\";\n\nexport class KeyGenerateCommand extends Command {\n static paths = [[`generate`, \"key\"]];\n\n static usage = Command.Usage({\n category: `Main`,\n description: `generate keys`,\n details: `\n This command generates RSA key pair for JWT signing.\n Use --rotate flag to preserve old public key.\n `,\n examples: [\n [`Generate new keys`, `generate key`],\n [`Rotate existing keys`, `generate key --rotate`],\n ],\n });\n\n rotate = Option.Boolean(`--rotate`, false, {\n description: `Rotate existing keys (backup old keys before replacement)`,\n });\n\n async execute() {\n logger().info(\"generating keys for jwt token and adding to .env file\");\n const { publicKey, privateKey } = generateKeyPairSync(\"rsa\", {\n modulusLength: 2048, // 2048-bit key is standard for RS256\n publicKeyEncoding: {\n type: \"spki\",\n format: \"pem\",\n },\n privateKeyEncoding: {\n type: \"pkcs8\",\n format: \"pem\",\n },\n });\n\n let envfile = \"\";\n try {\n envfile = await fs.readFile(path.join(process.cwd(), \".env\"), \"utf-8\");\n } catch {}\n let old_public_key = envfile.match(/^jwt_secret_public=(.*)/m);\n\n envfile = this.addEnvParam(\n envfile,\n \"jwt_secret_public\",\n this.stripPemHeaders(publicKey),\n );\n envfile = this.addEnvParam(\n envfile,\n \"jwt_secret_private\",\n this.stripPemHeaders(privateKey),\n );\n\n if (this.rotate && old_public_key && old_public_key[1]) {\n envfile = this.addEnvParam(\n envfile,\n \"jwt_secret_public_retired\",\n old_public_key[1],\n );\n }\n\n await fs.writeFile(path.join(process.cwd(), \".env\"), envfile, \"utf-8\");\n }\n\n addEnvParam(file: string, key: string, value: string) {\n let regex = new RegExp(`^${key}=.*`, \"gm\");\n file = file.replace(regex, `${key}=${value}`);\n const match = file.match(regex);\n\n if (!match) {\n file = file + `\\n${key}=${value}`;\n }\n return file;\n }\n\n stripPemHeaders(pem: string) {\n return pem\n .replace(/-----BEGIN [\\w\\s]+-----/g, \"\")\n .replace(/-----END [\\w\\s]+-----/g, \"\")\n .replace(/\\r?\\n|\\r/g, \"\");\n }\n}\n\ncli().register(KeyGenerateCommand);\n"],"mappings":";;AAAA,SAASA,SAASC,cAAc;AAChC,SAASC,2BAA2B;AACpC,OAAOC,QAAQ;AACf,OAAOC,UAAU;AACjB,SAASC,QAAQC,WAAW;AAErB,MAAMC,2BAA2BP,QAAAA;EANxC,OAMwCA;;;EACtC,OAAOQ,QAAQ;IAAC;MAAC;MAAY;;;EAE7B,OAAOC,QAAQT,QAAQU,MAAM;IAC3BC,UAAU;IACVC,aAAa;IACbC,SAAS;;;;IAITC,UAAU;MACR;QAAC;QAAqB;;MACtB;QAAC;QAAwB;;;EAE7B,CAAA;EAEAC,SAASd,OAAOe,QAAQ,YAAY,OAAO;IACzCJ,aAAa;EACf,CAAA;EAEA,MAAMK,UAAU;AACdZ,WAAAA,EAASa,KAAK,uDAAA;AACd,UAAM,EAAEC,WAAWC,WAAU,IAAKlB,oBAAoB,OAAO;MAC3DmB,eAAe;MACfC,mBAAmB;QACjBC,MAAM;QACNC,QAAQ;MACV;MACAC,oBAAoB;QAClBF,MAAM;QACNC,QAAQ;MACV;IACF,CAAA;AAEA,QAAIE,UAAU;AACd,QAAI;AACFA,gBAAU,MAAMvB,GAAGwB,SAASvB,KAAKwB,KAAKC,QAAQC,IAAG,GAAI,MAAA,GAAS,OAAA;IAChE,QAAQ;IAAC;AACT,QAAIC,iBAAiBL,QAAQM,MAAM,0BAAA;AAEnCN,cAAU,KAAKO,YACbP,SACA,qBACA,KAAKQ,gBAAgBf,SAAAA,CAAAA;AAEvBO,cAAU,KAAKO,YACbP,SACA,sBACA,KAAKQ,gBAAgBd,UAAAA,CAAAA;AAGvB,QAAI,KAAKL,UAAUgB,kBAAkBA,eAAe,CAAA,GAAI;AACtDL,gBAAU,KAAKO,YACbP,SACA,6BACAK,eAAe,CAAA,CAAE;IAErB;AAEA,UAAM5B,GAAGgC,UAAU/B,KAAKwB,KAAKC,QAAQC,IAAG,GAAI,MAAA,GAASJ,SAAS,OAAA;EAChE;EAEAO,YAAYG,MAAcC,KAAaC,OAAe;AACpD,QAAIC,QAAQ,IAAIC,OAAO,IAAIH,GAAAA,OAAU,IAAA;AACrCD,WAAOA,KAAKK,QAAQF,OAAO,GAAGF,GAAAA,IAAOC,KAAAA,EAAO;AAC5C,UAAMN,QAAQI,KAAKJ,MAAMO,KAAAA;AAEzB,QAAI,CAACP,OAAO;AACVI,aAAOA,OAAO;EAAKC,GAAAA,IAAOC,KAAAA;IAC5B;AACA,WAAOF;EACT;EAEAF,gBAAgBQ,KAAa;AAC3B,WAAOA,IACJD,QAAQ,4BAA4B,EAAA,EACpCA,QAAQ,0BAA0B,EAAA,EAClCA,QAAQ,aAAa,EAAA;EAC1B;AACF;AAEAnC,IAAAA,EAAMqC,SAASpC,kBAAAA;","names":["Command","Option","generateKeyPairSync","fs","path","logger","cli","KeyGenerateCommand","paths","usage","Usage","category","description","details","examples","rotate","Boolean","execute","info","publicKey","privateKey","modulusLength","publicKeyEncoding","type","format","privateKeyEncoding","envfile","readFile","join","process","cwd","old_public_key","match","addEnvParam","stripPemHeaders","writeFile","file","key","value","regex","RegExp","replace","pem","register"]}
|
|
@@ -47,6 +47,7 @@ class GenerateControllerCommand extends Command {
|
|
|
47
47
|
const compiledTemplate = handlebars.compile((await fs.readFile(path.join(dirname, "./controller.tpl"))).toString());
|
|
48
48
|
const template = await compiledTemplate({
|
|
49
49
|
className: Case.pascal(this.name),
|
|
50
|
+
classNameLower: Case.snake(this.name),
|
|
50
51
|
routeName: Case.kebab(pluralize(this.name))
|
|
51
52
|
});
|
|
52
53
|
await fs.writeFile(path.join(rootDir, "src/app/controllers", filename), template);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/generate/GenerateControllerCommand.ts"],"sourcesContent":["import { cli } from \"../../../facades\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport handlebars from \"handlebars\";\nimport { fileURLToPath } from \"url\";\nimport pluralize from \"pluralize\";\n\nexport class GenerateControllerCommand extends Command {\n static paths = [\n [`make`, `controller`],\n [`generate`, `controller`],\n ];\n\n name = Option.String({ required: true });\n\n async execute() {\n const rootDir = process.cwd();\n\n const date = new Date();\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const secondsOfDay = String(\n date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds(),\n ).padStart(5, \"0\");\n\n const fixed_name = Case.snake(this.name);\n const filename = `${Case.capital(this.name)}Controller.ts`;\n this.context.stdout.write(`creating migration file ${filename}\\n`);\n\n await fs.mkdir(config.get(\"migration.path\"), { recursive: true });\n\n let dirname = typeof __dirname === \"string\" ? __dirname : undefined;\n if (!dirname) {\n dirname = path.dirname(fileURLToPath(import.meta.url));\n }\n\n const compiledTemplate = handlebars.compile(\n (await fs.readFile(path.join(dirname, \"./controller.tpl\"))).toString(),\n );\n const template = await compiledTemplate({\n className: Case.pascal(this.name),\n routeName: Case.kebab(pluralize(this.name)),\n });\n\n await fs.writeFile(\n path.join(rootDir, \"src/app/controllers\", filename),\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jC,MAAM1C,GAAG2C,SAAS5C,KAAK6C,KAAKP,SAAS,kBAAA,CAAA,GAAsBQ,SAAQ,CAAA;AAEtE,UAAMC,WAAW,MAAML,iBAAiB;MACtCM,WAAWjD,KAAKkD,OAAO,KAAKzC,IAAI;MAChC0C,
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/generate/GenerateControllerCommand.ts"],"sourcesContent":["import { cli } from \"../../../facades\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport handlebars from \"handlebars\";\nimport { fileURLToPath } from \"url\";\nimport pluralize from \"pluralize\";\n\nexport class GenerateControllerCommand extends Command {\n static paths = [\n [`make`, `controller`],\n [`generate`, `controller`],\n ];\n\n name = Option.String({ required: true });\n\n async execute() {\n const rootDir = process.cwd();\n\n const date = new Date();\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const secondsOfDay = String(\n date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds(),\n ).padStart(5, \"0\");\n\n const fixed_name = Case.snake(this.name);\n const filename = `${Case.capital(this.name)}Controller.ts`;\n this.context.stdout.write(`creating migration file ${filename}\\n`);\n\n await fs.mkdir(config.get(\"migration.path\"), { recursive: true });\n\n let dirname = typeof __dirname === \"string\" ? __dirname : undefined;\n if (!dirname) {\n dirname = path.dirname(fileURLToPath(import.meta.url));\n }\n\n const compiledTemplate = handlebars.compile(\n (await fs.readFile(path.join(dirname, \"./controller.tpl\"))).toString(),\n );\n const template = await compiledTemplate({\n className: Case.pascal(this.name),\n classNameLower: Case.snake(this.name),\n routeName: Case.kebab(pluralize(this.name)),\n });\n\n await fs.writeFile(\n path.join(rootDir, \"src/app/controllers\", filename),\n template,\n );\n }\n}\n\ncli().register(GenerateControllerCommand);\n"],"mappings":";;AAAA,SAASA,WAAW;AACpB,SAASC,SAAS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;AAEtE,UAAMC,WAAW,MAAML,iBAAiB;MACtCM,WAAWjD,KAAKkD,OAAO,KAAKzC,IAAI;MAChC0C,gBAAgBnD,KAAK8B,MAAM,KAAKrB,IAAI;MACpC2C,WAAWpD,KAAKqD,MAAM/C,UAAU,KAAKG,IAAI,CAAA;IAC3C,CAAA;AAEA,UAAMP,GAAGoD,UACPrD,KAAK6C,KAAKjC,SAAS,uBAAuBkB,QAAAA,GAC1CiB,QAAAA;EAEJ;AACF;AAEAnD,IAAAA,EAAM0D,SAAShD,yBAAAA;","names":["cli","Command","Option","Case","path","fs","config","handlebars","fileURLToPath","pluralize","GenerateControllerCommand","paths","name","String","required","execute","rootDir","process","cwd","date","Date","year","getFullYear","month","getMonth","padStart","day","getDate","secondsOfDay","getHours","getMinutes","getSeconds","fixed_name","snake","filename","capital","context","stdout","write","mkdir","get","recursive","dirname","__dirname","undefined","url","compiledTemplate","compile","readFile","join","toString","template","className","pascal","classNameLower","routeName","kebab","writeFile","register"]}
|
|
@@ -2,6 +2,13 @@ import { db, storage, logger } from "@devbro/pashmak/facades";
|
|
|
2
2
|
import { ctx } from "@devbro/pashmak/context";
|
|
3
3
|
import { Request, Response, Model, Param, ValidatedRequest, BaseController, Controller, Get, Post, Put, Delete } from "@devbro/pashmak/router";
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
const {{classNameLower}}Validation = yup.object({
|
|
7
|
+
name: yup.string().required().min(2).max(255),
|
|
8
|
+
active: yup.boolean().required().default(true),
|
|
9
|
+
});
|
|
10
|
+
type {{className}}ValidationType = yup.InferType<typeof {{classNameLower}}Validation>;
|
|
11
|
+
|
|
5
12
|
@Controller("/api/v1/{{routeName}}")
|
|
6
13
|
export class {{className}}Controller extends BaseController {
|
|
7
14
|
@Get()
|
|
@@ -10,17 +17,21 @@ export class {{className}}Controller extends BaseController {
|
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
@Post()
|
|
13
|
-
async create() {
|
|
20
|
+
async create(@ValidatedRequest({{classNameLower}}Validation) body: {{className}}ValidationType) {
|
|
14
21
|
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
@Get({ path: "/:id" })
|
|
18
|
-
async get(@Param("id") id: string) {
|
|
25
|
+
async get(@Param("id") id: string, @Model({{className}}, 'id') {{classNameLower}}: {{className}}) {
|
|
19
26
|
|
|
27
|
+
return {{classNameLower}};
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
@Put({ path: "/:id" })
|
|
23
|
-
async update(
|
|
31
|
+
async update(
|
|
32
|
+
@Model({{className}}, 'id') dealer: Dealer,
|
|
33
|
+
@ValidatedRequest({{classNameLower}}Validation) body: {{className}}ValidationType
|
|
34
|
+
) {
|
|
24
35
|
|
|
25
36
|
}
|
|
26
37
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { MigrateCommand } from './migrate/MigrateCommand.js';
|
|
2
|
-
export {
|
|
2
|
+
export { GenerateMigrateCommand } from './migrate/GenerateMigrateCommand.js';
|
|
3
3
|
export { MigrateRollbackCommand } from './migrate/MigrateRollbackCommand.js';
|
|
4
4
|
export { StartCommand } from './StartCommand.js';
|
|
5
5
|
export { DefaultCommand } from './DefaultCommand.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Command } from 'clipanion';
|
|
2
2
|
|
|
3
|
-
declare class
|
|
3
|
+
declare class GenerateMigrateCommand extends Command {
|
|
4
4
|
static paths: string[][];
|
|
5
5
|
name: string;
|
|
6
6
|
execute(): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export {
|
|
9
|
+
export { GenerateMigrateCommand };
|
|
@@ -8,17 +8,17 @@ import * as fs from "fs/promises";
|
|
|
8
8
|
import { config } from "@devbro/neko-config";
|
|
9
9
|
import handlebars from "handlebars";
|
|
10
10
|
import { fileURLToPath } from "url";
|
|
11
|
-
class
|
|
11
|
+
class GenerateMigrateCommand extends Command {
|
|
12
12
|
static {
|
|
13
|
-
__name(this, "
|
|
13
|
+
__name(this, "GenerateMigrateCommand");
|
|
14
14
|
}
|
|
15
15
|
static paths = [
|
|
16
16
|
[
|
|
17
|
-
`
|
|
17
|
+
`generate`,
|
|
18
18
|
`migrate`
|
|
19
19
|
],
|
|
20
20
|
[
|
|
21
|
-
"
|
|
21
|
+
"generate",
|
|
22
22
|
"migration"
|
|
23
23
|
]
|
|
24
24
|
];
|
|
@@ -50,8 +50,8 @@ class MakeMigrateCommand extends Command {
|
|
|
50
50
|
await fs.writeFile(path.join(config.get("migration.path"), filename), template);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
cli().register(
|
|
53
|
+
cli().register(GenerateMigrateCommand);
|
|
54
54
|
export {
|
|
55
|
-
|
|
55
|
+
GenerateMigrateCommand
|
|
56
56
|
};
|
|
57
|
-
//# sourceMappingURL=
|
|
57
|
+
//# sourceMappingURL=GenerateMigrateCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/migrate/GenerateMigrateCommand.ts"],"sourcesContent":["import { cli } from \"../../../facades\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport handlebars from \"handlebars\";\nimport { fileURLToPath } from \"url\";\nimport { table } from \"console\";\n\nexport class GenerateMigrateCommand extends Command {\n static paths = [\n [`generate`, `migrate`],\n [\"generate\", \"migration\"],\n ];\n\n name = Option.String({ required: true });\n\n async execute() {\n const date = new Date();\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const secondsOfDay = String(\n date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds(),\n ).padStart(5, \"0\");\n\n const fixed_name = Case.snake(this.name);\n const filename = `${year}_${month}_${day}_${secondsOfDay}_${fixed_name}.ts`;\n this.context.stdout.write(`creating migration file ${filename}\\n`);\n\n await fs.mkdir(config.get(\"migration.path\"), { recursive: true });\n\n let dirname = typeof __dirname === \"string\" ? __dirname : undefined;\n if (!dirname) {\n dirname = path.dirname(fileURLToPath(import.meta.url));\n }\n\n const compiledTemplate = handlebars.compile(\n (\n await fs.readFile(path.join(dirname, \"./make_migration.tpl\"))\n ).toString(),\n );\n const template = await compiledTemplate({\n className: Case.pascal(this.name) + \"Migration\",\n tableName: Case.snake(this.name),\n });\n\n await fs.writeFile(\n path.join(config.get(\"migration.path\"), filename),\n template,\n );\n }\n}\n\ncli().register(GenerateMigrateCommand);\n"],"mappings":";;AAAA,SAASA,WAAW;AACpB,SAASC,SAASC,cAAc;AAChC,SAASC,YAAY;AACrB,OAAOC,UAAU;AACjB,YAAYC,QAAQ;AACpB,SAASC,cAAc;AACvB,OAAOC,gBAAgB;AACvB,SAASC,qBAAqB;AAGvB,MAAMC,+BAA+BR,QAAAA;EAV5C,OAU4CA;;;EAC1C,OAAOS,QAAQ;IACb;MAAC;MAAY;;IACb;MAAC;MAAY;;;EAGfC,OAAOT,OAAOU,OAAO;IAAEC,UAAU;EAAK,CAAA;EAEtC,MAAMC,UAAU;AACd,UAAMC,OAAO,oBAAIC,KAAAA;AACjB,UAAMC,OAAOF,KAAKG,YAAW;AAC7B,UAAMC,QAAQP,OAAOG,KAAKK,SAAQ,IAAK,CAAA,EAAGC,SAAS,GAAG,GAAA;AACtD,UAAMC,MAAMV,OAAOG,KAAKQ,QAAO,CAAA,EAAIF,SAAS,GAAG,GAAA;AAC/C,UAAMG,eAAeZ,OACnBG,KAAKU,SAAQ,IAAK,OAAOV,KAAKW,WAAU,IAAK,KAAKX,KAAKY,WAAU,CAAA,EACjEN,SAAS,GAAG,GAAA;AAEd,UAAMO,aAAazB,KAAK0B,MAAM,KAAKlB,IAAI;AACvC,UAAMmB,WAAW,GAAGb,IAAAA,IAAQE,KAAAA,IAASG,GAAAA,IAAOE,YAAAA,IAAgBI,UAAAA;AAC5D,SAAKG,QAAQC,OAAOC,MAAM,2BAA2BH,QAAAA;CAAY;AAEjE,UAAMzB,GAAG6B,MAAM5B,OAAO6B,IAAI,gBAAA,GAAmB;MAAEC,WAAW;IAAK,CAAA;AAE/D,QAAIC,UAAU,OAAOC,cAAc,WAAWA,YAAYC;AAC1D,QAAI,CAACF,SAAS;AACZA,gBAAUjC,KAAKiC,QAAQ7B,cAAc,YAAYgC,GAAG,CAAA;IACtD;AAEA,UAAMC,mBAAmBlC,WAAWmC,SAEhC,MAAMrC,GAAGsC,SAASvC,KAAKwC,KAAKP,SAAS,sBAAA,CAAA,GACrCQ,SAAQ,CAAA;AAEZ,UAAMC,WAAW,MAAML,iBAAiB;MACtCM,WAAW5C,KAAK6C,OAAO,KAAKrC,IAAI,IAAI;MACpCsC,WAAW9C,KAAK0B,MAAM,KAAKlB,IAAI;IACjC,CAAA;AAEA,UAAMN,GAAG6C,UACP9C,KAAKwC,KAAKtC,OAAO6B,IAAI,gBAAA,GAAmBL,QAAAA,GACxCgB,QAAAA;EAEJ;AACF;AAEA9C,IAAAA,EAAMmD,SAAS1C,sBAAAA;","names":["cli","Command","Option","Case","path","fs","config","handlebars","fileURLToPath","GenerateMigrateCommand","paths","name","String","required","execute","date","Date","year","getFullYear","month","getMonth","padStart","day","getDate","secondsOfDay","getHours","getMinutes","getSeconds","fixed_name","snake","filename","context","stdout","write","mkdir","get","recursive","dirname","__dirname","undefined","url","compiledTemplate","compile","readFile","join","toString","template","className","pascal","tableName","writeFile","register"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { MigrateCommand } from './MigrateCommand.js';
|
|
2
|
-
export {
|
|
2
|
+
export { GenerateMigrateCommand } from './GenerateMigrateCommand.js';
|
|
3
3
|
export { MigrateRollbackCommand } from './MigrateRollbackCommand.js';
|
|
4
4
|
import 'clipanion';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/migrate/index.ts"],"sourcesContent":["export * from \"./MigrateCommand\";\nexport * from \"./
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/migrate/index.ts"],"sourcesContent":["export * from \"./MigrateCommand\";\nexport * from \"./GenerateMigrateCommand\";\nexport * from \"./MigrateRollbackCommand\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -64,10 +64,7 @@ class CreateProjectCommand extends Command {
|
|
|
64
64
|
recursive: true
|
|
65
65
|
});
|
|
66
66
|
console.log(`Created project directory at: ${projectPath}`);
|
|
67
|
-
let dirname = __dirname;
|
|
68
|
-
if (!dirname) {
|
|
69
|
-
dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
70
|
-
}
|
|
67
|
+
let dirname = typeof __dirname === "undefined" ? path.dirname(fileURLToPath(import.meta.url)) : __dirname;
|
|
71
68
|
let basePath = path.join(dirname, `./base_project`);
|
|
72
69
|
if (await this.folderExists(basePath) === false) {
|
|
73
70
|
basePath = path.join(dirname, `../app/console/project/base_project`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/project/CreateProjectCommand.ts"],"sourcesContent":["import { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { fileURLToPath } from \"url\";\nimport handlebars from \"handlebars\";\nimport { execSync } from \"child_process\";\n\nexport class CreateProjectCommand extends Command {\n static paths = [[`create`, `project`]];\n\n static usage = Command.Usage({\n category: `Project`,\n description: `Create a new project`,\n details: `\n This command creates a new project with the specified name at the given path.\n If no path is provided, the project will be created in the current directory.\n `,\n examples: [\n [\n `Create a new project in specified directory`,\n `create project --path /path/to/my-project --git`,\n ],\n [\n `Create a new project at a specific path with git initialized`,\n `create project --path /path/to/my-project --git`,\n ],\n ],\n });\n\n projectPath = Option.String(\"--path\", { required: true });\n\n git = Option.Boolean(`--git`, false, {\n description: `Initialize a git repository in the new project`,\n });\n\n async folderExists(folderPath: string): Promise<boolean> {\n try {\n const stats = await fs.stat(folderPath);\n return stats.isDirectory();\n } catch (error: any) {\n if (error.code === \"ENOENT\") {\n return false; // Folder does not exist\n }\n throw error; // Other errors (e.g., permission issues)\n }\n }\n\n async execute() {\n // Create the project directory path by joining the specified path and project name\n const projectPath = path.join(this.projectPath);\n // Check if directory already exists\n try {\n await fs.access(projectPath);\n console.error(`Error: Directory ${projectPath} already exists.`);\n return 1;\n } catch {\n // Directory doesn't exist, we can proceed\n }\n\n await fs.mkdir(projectPath, { recursive: true });\n console.log(`Created project directory at: ${projectPath}`);\n\n let dirname
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/project/CreateProjectCommand.ts"],"sourcesContent":["import { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { fileURLToPath } from \"url\";\nimport handlebars from \"handlebars\";\nimport { execSync } from \"child_process\";\n\nexport class CreateProjectCommand extends Command {\n static paths = [[`create`, `project`]];\n\n static usage = Command.Usage({\n category: `Project`,\n description: `Create a new project`,\n details: `\n This command creates a new project with the specified name at the given path.\n If no path is provided, the project will be created in the current directory.\n `,\n examples: [\n [\n `Create a new project in specified directory`,\n `create project --path /path/to/my-project --git`,\n ],\n [\n `Create a new project at a specific path with git initialized`,\n `create project --path /path/to/my-project --git`,\n ],\n ],\n });\n\n projectPath = Option.String(\"--path\", { required: true });\n\n git = Option.Boolean(`--git`, false, {\n description: `Initialize a git repository in the new project`,\n });\n\n async folderExists(folderPath: string): Promise<boolean> {\n try {\n const stats = await fs.stat(folderPath);\n return stats.isDirectory();\n } catch (error: any) {\n if (error.code === \"ENOENT\") {\n return false; // Folder does not exist\n }\n throw error; // Other errors (e.g., permission issues)\n }\n }\n\n async execute() {\n // Create the project directory path by joining the specified path and project name\n const projectPath = path.join(this.projectPath);\n // Check if directory already exists\n try {\n await fs.access(projectPath);\n console.error(`Error: Directory ${projectPath} already exists.`);\n return 1;\n } catch {\n // Directory doesn't exist, we can proceed\n }\n\n await fs.mkdir(projectPath, { recursive: true });\n console.log(`Created project directory at: ${projectPath}`);\n\n let dirname =\n typeof __dirname === \"undefined\"\n ? path.dirname(fileURLToPath(import.meta.url))\n : __dirname;\n\n let basePath = path.join(dirname, `./base_project`);\n if ((await this.folderExists(basePath)) === false) {\n // we are running a compiled code that was bundled and the code is running from ./dist/bin/ folder.\n basePath = path.join(dirname, `../app/console/project/base_project`);\n }\n\n console.log(`Using base project path: ${basePath}`);\n //copy content of ./base_project to the new project directory\n const baseProjectPath = basePath;\n\n await this.processTplFolder(baseProjectPath, projectPath, {});\n console.log(`Copied base project files to: ${projectPath}`);\n\n //modify package.json with foldername\n const packageJsonPath = path.join(projectPath, `package.json`);\n const packageJson = JSON.parse(await fs.readFile(packageJsonPath, `utf-8`));\n packageJson.name = Case.snake(path.basename(projectPath));\n await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));\n console.log(`Updated package.json with project name: ${packageJson.name}`);\n\n if (this.git) {\n try {\n execSync(\n 'git init; git add --all; git commit --allow-empty -m \"chore: first commit for pashmak\"',\n {\n cwd: projectPath,\n },\n );\n } catch (error) {\n console.error(`Failed to create project.`, error);\n return 1;\n }\n }\n }\n\n async processTplFolder(src: string, dest: string, data: any = {}) {\n const files = await fs.readdir(src, { withFileTypes: true });\n for (const file of files) {\n const srcPath = path.join(src, file.name);\n const destPath =\n file.isFile() && file.name.endsWith(\".tpl\")\n ? path.join(dest, file.name.substring(0, file.name.length - 4))\n : path.join(dest, file.name);\n\n if (file.isDirectory()) {\n await fs.mkdir(destPath, { recursive: true });\n await this.processTplFolder(srcPath, destPath, data);\n } else if (file.name.endsWith(\".tpl\")) {\n await this.processTplFile(srcPath, destPath, {});\n } else {\n throw new Error(\n \"unexpected non tpl file: \" + srcPath + \" \" + file.name,\n );\n }\n }\n }\n\n async processTplFile(src: string, dest: string, data: any = {}) {\n const compiledTemplate = handlebars.compile(\n (await fs.readFile(src)).toString(),\n );\n const template = await compiledTemplate(data);\n await fs.writeFile(dest, template);\n }\n}\n"],"mappings":";;AAAA,SAASA,S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AAM,KAAKO,iBAAiBmB,SAASC,UAAUN,IAAAA;MACjD,WAAWI,KAAKZ,KAAKgB,SAAS,MAAA,GAAS;AACrC,cAAM,KAAKG,eAAeN,SAASC,UAAU,CAAC,CAAA;MAChD,OAAO;AACL,cAAM,IAAIM,MACR,8BAA8BP,UAAU,MAAMD,KAAKZ,IAAI;MAE3D;IACF;EACF;EAEA,MAAMmB,eAAeb,KAAaC,MAAcC,OAAY,CAAC,GAAG;AAC9D,UAAMa,mBAAmB7D,WAAW8D,SACjC,MAAMhE,GAAGyC,SAASO,GAAAA,GAAMiB,SAAQ,CAAA;AAEnC,UAAMC,WAAW,MAAMH,iBAAiBb,IAAAA;AACxC,UAAMlD,GAAG6C,UAAUI,MAAMiB,QAAAA;EAC3B;AACF;","names":["Command","Option","Case","path","fs","fileURLToPath","handlebars","execSync","CreateProjectCommand","paths","usage","Usage","category","description","details","examples","projectPath","String","required","git","Boolean","folderExists","folderPath","stats","stat","isDirectory","error","code","execute","join","access","console","mkdir","recursive","log","dirname","__dirname","url","basePath","baseProjectPath","processTplFolder","packageJsonPath","packageJson","JSON","parse","readFile","name","snake","basename","writeFile","stringify","cwd","src","dest","data","files","readdir","withFileTypes","file","srcPath","destPath","isFile","endsWith","substring","length","processTplFile","Error","compiledTemplate","compile","toString","template"]}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"prepare": "husky",
|
|
20
20
|
"prettier": "prettier --write .",
|
|
21
21
|
"dev": "nodemon --watch src --ext ts,tsx,json --signal SIGTERM --exec \"clear && tsx -r tsconfig-paths/register src/index.ts start --all | npx pino-pretty\"",
|
|
22
|
-
"
|
|
22
|
+
"pashmak": "tsx -r tsconfig-paths/register src/index.ts",
|
|
23
23
|
"clean": "rm -rf dist"
|
|
24
24
|
},
|
|
25
25
|
"author": "???",
|
package/dist/bin/pashmak_cli.cjs
CHANGED
|
@@ -93,10 +93,7 @@ var CreateProjectCommand = class extends import_clipanion.Command {
|
|
|
93
93
|
recursive: true
|
|
94
94
|
});
|
|
95
95
|
console.log(`Created project directory at: ${projectPath}`);
|
|
96
|
-
let dirname = __dirname;
|
|
97
|
-
if (!dirname) {
|
|
98
|
-
dirname = import_path.default.dirname((0, import_url.fileURLToPath)(import_meta.url));
|
|
99
|
-
}
|
|
96
|
+
let dirname = typeof __dirname === "undefined" ? import_path.default.dirname((0, import_url.fileURLToPath)(import_meta.url)) : __dirname;
|
|
100
97
|
let basePath = import_path.default.join(dirname, `./base_project`);
|
|
101
98
|
if (await this.folderExists(basePath) === false) {
|
|
102
99
|
basePath = import_path.default.join(dirname, `../app/console/project/base_project`);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Request, Response } from '@devbro/neko-router';
|
|
2
|
+
|
|
3
|
+
declare function cors(options?: {
|
|
4
|
+
allowedOrigins?: (string | RegExp)[];
|
|
5
|
+
}): (req: Request, res: Response, next: () => Promise<void>) => Promise<void>;
|
|
6
|
+
declare function dbTransaction(req: Request, res: Response, next: () => Promise<void>): Promise<void>;
|
|
7
|
+
|
|
8
|
+
export { cors, dbTransaction };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { db } from "./facades";
|
|
4
|
+
function cors(options = {}) {
|
|
5
|
+
return async (req, res, next) => {
|
|
6
|
+
const allowedOrigins = options.allowedOrigins || [
|
|
7
|
+
"*"
|
|
8
|
+
];
|
|
9
|
+
const origin = req.headers.origin || "*";
|
|
10
|
+
for (const allowedOrigin of allowedOrigins) {
|
|
11
|
+
if (typeof allowedOrigin === "string" && allowedOrigin === origin) {
|
|
12
|
+
res.setHeader("Access-Control-Allow-Origin", allowedOrigin);
|
|
13
|
+
break;
|
|
14
|
+
} else if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {
|
|
15
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
16
|
+
break;
|
|
17
|
+
} else if (allowedOrigin === "*") {
|
|
18
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
23
|
+
await next();
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
__name(cors, "cors");
|
|
27
|
+
async function dbTransaction(req, res, next) {
|
|
28
|
+
try {
|
|
29
|
+
await db().beginTransaction();
|
|
30
|
+
await next();
|
|
31
|
+
await db().commit();
|
|
32
|
+
} finally {
|
|
33
|
+
await db().rollback();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
__name(dbTransaction, "dbTransaction");
|
|
37
|
+
export {
|
|
38
|
+
cors,
|
|
39
|
+
dbTransaction
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=middlewares.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/middlewares.ts"],"sourcesContent":["import { Request, Response } from \"@devbro/neko-router\";\nimport { logger, db } from \"./facades\";\n\nexport function cors(\n options: { allowedOrigins?: (string | RegExp)[] } = {},\n): (req: Request, res: Response, next: () => Promise<void>) => Promise<void> {\n return async (\n req: Request,\n res: Response,\n next: () => Promise<void>,\n ): Promise<void> => {\n const allowedOrigins = options.allowedOrigins || [\"*\"];\n const origin = req.headers.origin || \"*\";\n\n for (const allowedOrigin of allowedOrigins) {\n if (typeof allowedOrigin === \"string\" && allowedOrigin === origin) {\n res.setHeader(\"Access-Control-Allow-Origin\", allowedOrigin);\n break;\n } else if (\n allowedOrigin instanceof RegExp &&\n allowedOrigin.test(origin)\n ) {\n res.setHeader(\"Access-Control-Allow-Origin\", origin);\n break;\n } else if (allowedOrigin === \"*\") {\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n break;\n }\n }\n\n res.setHeader(\"Access-Control-Allow-Headers\", \"*\");\n await next();\n };\n}\n\nexport async function dbTransaction(\n req: Request,\n res: Response,\n next: () => Promise<void>,\n): Promise<void> {\n try {\n await db().beginTransaction();\n await next();\n await db().commit();\n } finally {\n await db().rollback();\n }\n}\n"],"mappings":";;AACA,SAAiBA,UAAU;AAEpB,SAASC,KACdC,UAAoD,CAAC,GAAC;AAEtD,SAAO,OACLC,KACAC,KACAC,SAAAA;AAEA,UAAMC,iBAAiBJ,QAAQI,kBAAkB;MAAC;;AAClD,UAAMC,SAASJ,IAAIK,QAAQD,UAAU;AAErC,eAAWE,iBAAiBH,gBAAgB;AAC1C,UAAI,OAAOG,kBAAkB,YAAYA,kBAAkBF,QAAQ;AACjEH,YAAIM,UAAU,+BAA+BD,aAAAA;AAC7C;MACF,WACEA,yBAAyBE,UACzBF,cAAcG,KAAKL,MAAAA,GACnB;AACAH,YAAIM,UAAU,+BAA+BH,MAAAA;AAC7C;MACF,WAAWE,kBAAkB,KAAK;AAChCL,YAAIM,UAAU,+BAA+B,GAAA;AAC7C;MACF;IACF;AAEAN,QAAIM,UAAU,gCAAgC,GAAA;AAC9C,UAAML,KAAAA;EACR;AACF;AA9BgBJ;AAgChB,eAAsBY,cACpBV,KACAC,KACAC,MAAyB;AAEzB,MAAI;AACF,UAAML,GAAAA,EAAKc,iBAAgB;AAC3B,UAAMT,KAAAA;AACN,UAAML,GAAAA,EAAKe,OAAM;EACnB,UAAA;AACE,UAAMf,GAAAA,EAAKgB,SAAQ;EACrB;AACF;AAZsBH;","names":["db","cors","options","req","res","next","allowedOrigins","origin","headers","allowedOrigin","setHeader","RegExp","test","dbTransaction","beginTransaction","commit","rollback"]}
|
package/dist/router.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export * from '@devbro/neko-router';
|
|
|
4
4
|
|
|
5
5
|
declare function Model(model: typeof BaseModel, paramName: string): ParameterDecorator;
|
|
6
6
|
declare function Param(paramName: string): ParameterDecorator;
|
|
7
|
-
declare function ValidatedRequest(validationRules: yup.ObjectSchema<any>): ParameterDecorator;
|
|
7
|
+
declare function ValidatedRequest(validationRules: yup.ObjectSchema<any> | (() => yup.ObjectSchema<any>)): ParameterDecorator;
|
|
8
8
|
|
|
9
9
|
export { Model, Param, ValidatedRequest };
|
package/dist/router.js
CHANGED
|
@@ -22,7 +22,7 @@ function Param(paramName) {
|
|
|
22
22
|
__name(Param, "Param");
|
|
23
23
|
function ValidatedRequest(validationRules) {
|
|
24
24
|
return createParamDecorator(async () => {
|
|
25
|
-
const rc = await validationRules.noUnknown().validate(ctx().get("request").body, {
|
|
25
|
+
const rc = await (typeof validationRules === "function" ? validationRules() : validationRules).noUnknown().validate(ctx().get("request").body, {
|
|
26
26
|
abortEarly: false
|
|
27
27
|
});
|
|
28
28
|
return rc;
|
package/dist/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/router.ts"],"sourcesContent":["import { ctx } from \"@devbro/neko-context\";\nimport { BaseModel } from \"@devbro/neko-orm\";\nimport { Request } from \"@devbro/neko-router\";\nimport { HttpNotFoundError } from \"@devbro/neko-http/errors\";\nimport { createParamDecorator } from \"@devbro/neko-router\";\nimport * as yup from \"yup\";\nexport * from \"@devbro/neko-router\";\n\nexport function Model(\n model: typeof BaseModel,\n paramName: string,\n): ParameterDecorator {\n return createParamDecorator(async () => {\n let rc = await model.find(ctx().get<Request>(\"request\").params[paramName]);\n if (!rc) {\n throw new HttpNotFoundError(\"Object not found\");\n }\n\n return rc;\n });\n}\n\nexport function Param(paramName: string): ParameterDecorator {\n return createParamDecorator(() => {\n return ctx().get<Request>(\"request\").params[paramName];\n });\n}\n\nexport function ValidatedRequest(\n validationRules: yup.ObjectSchema<any
|
|
1
|
+
{"version":3,"sources":["../src/router.ts"],"sourcesContent":["import { ctx } from \"@devbro/neko-context\";\nimport { BaseModel } from \"@devbro/neko-orm\";\nimport { Request } from \"@devbro/neko-router\";\nimport { HttpNotFoundError } from \"@devbro/neko-http/errors\";\nimport { createParamDecorator } from \"@devbro/neko-router\";\nimport * as yup from \"yup\";\nexport * from \"@devbro/neko-router\";\n\nexport function Model(\n model: typeof BaseModel,\n paramName: string,\n): ParameterDecorator {\n return createParamDecorator(async () => {\n let rc = await model.find(ctx().get<Request>(\"request\").params[paramName]);\n if (!rc) {\n throw new HttpNotFoundError(\"Object not found\");\n }\n\n return rc;\n });\n}\n\nexport function Param(paramName: string): ParameterDecorator {\n return createParamDecorator(() => {\n return ctx().get<Request>(\"request\").params[paramName];\n });\n}\n\nexport function ValidatedRequest(\n validationRules: yup.ObjectSchema<any> | (() => yup.ObjectSchema<any>),\n): ParameterDecorator {\n return createParamDecorator(async () => {\n const rc = await (\n typeof validationRules === \"function\"\n ? validationRules()\n : validationRules\n )\n .noUnknown()\n .validate(ctx().get<Request>(\"request\").body, { abortEarly: false });\n\n return rc;\n });\n}\n"],"mappings":";;AAAA,SAASA,WAAW;AAGpB,SAASC,yBAAyB;AAClC,SAASC,4BAA4B;AAErC,cAAc;AAEP,SAASC,MACdC,OACAC,WAAiB;AAEjB,SAAOH,qBAAqB,YAAA;AAC1B,QAAII,KAAK,MAAMF,MAAMG,KAAKP,IAAAA,EAAMQ,IAAa,SAAA,EAAWC,OAAOJ,SAAAA,CAAU;AACzE,QAAI,CAACC,IAAI;AACP,YAAM,IAAIL,kBAAkB,kBAAA;IAC9B;AAEA,WAAOK;EACT,CAAA;AACF;AAZgBH;AAcT,SAASO,MAAML,WAAiB;AACrC,SAAOH,qBAAqB,MAAA;AAC1B,WAAOF,IAAAA,EAAMQ,IAAa,SAAA,EAAWC,OAAOJ,SAAAA;EAC9C,CAAA;AACF;AAJgBK;AAMT,SAASC,iBACdC,iBAAsE;AAEtE,SAAOV,qBAAqB,YAAA;AAC1B,UAAMI,KAAK,OACT,OAAOM,oBAAoB,aACvBA,gBAAAA,IACAA,iBAEHC,UAAS,EACTC,SAASd,IAAAA,EAAMQ,IAAa,SAAA,EAAWO,MAAM;MAAEC,YAAY;IAAM,CAAA;AAEpE,WAAOV;EACT,CAAA;AACF;AAdgBK;","names":["ctx","HttpNotFoundError","createParamDecorator","Model","model","paramName","rc","find","get","params","Param","ValidatedRequest","validationRules","noUnknown","validate","body","abortEarly"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devbro/pashmak",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "testing application for the entire repo",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -73,6 +73,11 @@
|
|
|
73
73
|
"import": "./dist/mailer.js",
|
|
74
74
|
"require": "./dist/mailer.js"
|
|
75
75
|
},
|
|
76
|
+
"./middlewares": {
|
|
77
|
+
"types": "./dist/middlewares.d.ts",
|
|
78
|
+
"import": "./dist/middlewares.js",
|
|
79
|
+
"require": "./dist/middlewares.js"
|
|
80
|
+
},
|
|
76
81
|
"./package.json": "./package.json"
|
|
77
82
|
},
|
|
78
83
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/migrate/MakeMigrateCommand.ts"],"sourcesContent":["import { cli } from \"../../../facades\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport handlebars from \"handlebars\";\nimport { fileURLToPath } from \"url\";\nimport { table } from \"console\";\n\nexport class MakeMigrateCommand extends Command {\n static paths = [\n [`make`, `migrate`],\n [\"make\", \"migration\"],\n ];\n\n name = Option.String({ required: true });\n\n async execute() {\n const date = new Date();\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const secondsOfDay = String(\n date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds(),\n ).padStart(5, \"0\");\n\n const fixed_name = Case.snake(this.name);\n const filename = `${year}_${month}_${day}_${secondsOfDay}_${fixed_name}.ts`;\n this.context.stdout.write(`creating migration file ${filename}\\n`);\n\n await fs.mkdir(config.get(\"migration.path\"), { recursive: true });\n\n let dirname = typeof __dirname === \"string\" ? __dirname : undefined;\n if (!dirname) {\n dirname = path.dirname(fileURLToPath(import.meta.url));\n }\n\n const compiledTemplate = handlebars.compile(\n (\n await fs.readFile(path.join(dirname, \"./make_migration.tpl\"))\n ).toString(),\n );\n const template = await compiledTemplate({\n className: Case.pascal(this.name) + \"Migration\",\n tableName: Case.snake(this.name),\n });\n\n await fs.writeFile(\n path.join(config.get(\"migration.path\"), filename),\n template,\n );\n }\n}\n\ncli().register(MakeMigrateCommand);\n"],"mappings":";;AAAA,SAASA,WAAW;AACpB,SAASC,SAASC,cAAc;AAChC,SAASC,YAAY;AACrB,OAAOC,UAAU;AACjB,YAAYC,QAAQ;AACpB,SAASC,cAAc;AACvB,OAAOC,gBAAgB;AACvB,SAASC,qBAAqB;AAGvB,MAAMC,2BAA2BR,QAAAA;EAVxC,OAUwCA;;;EACtC,OAAOS,QAAQ;IACb;MAAC;MAAQ;;IACT;MAAC;MAAQ;;;EAGXC,OAAOT,OAAOU,OAAO;IAAEC,UAAU;EAAK,CAAA;EAEtC,MAAMC,UAAU;AACd,UAAMC,OAAO,oBAAIC,KAAAA;AACjB,UAAMC,OAAOF,KAAKG,YAAW;AAC7B,UAAMC,QAAQP,OAAOG,KAAKK,SAAQ,IAAK,CAAA,EAAGC,SAAS,GAAG,GAAA;AACtD,UAAMC,MAAMV,OAAOG,KAAKQ,QAAO,CAAA,EAAIF,SAAS,GAAG,GAAA;AAC/C,UAAMG,eAAeZ,OACnBG,KAAKU,SAAQ,IAAK,OAAOV,KAAKW,WAAU,IAAK,KAAKX,KAAKY,WAAU,CAAA,EACjEN,SAAS,GAAG,GAAA;AAEd,UAAMO,aAAazB,KAAK0B,MAAM,KAAKlB,IAAI;AACvC,UAAMmB,WAAW,GAAGb,IAAAA,IAAQE,KAAAA,IAASG,GAAAA,IAAOE,YAAAA,IAAgBI,UAAAA;AAC5D,SAAKG,QAAQC,OAAOC,MAAM,2BAA2BH,QAAAA;CAAY;AAEjE,UAAMzB,GAAG6B,MAAM5B,OAAO6B,IAAI,gBAAA,GAAmB;MAAEC,WAAW;IAAK,CAAA;AAE/D,QAAIC,UAAU,OAAOC,cAAc,WAAWA,YAAYC;AAC1D,QAAI,CAACF,SAAS;AACZA,gBAAUjC,KAAKiC,QAAQ7B,cAAc,YAAYgC,GAAG,CAAA;IACtD;AAEA,UAAMC,mBAAmBlC,WAAWmC,SAEhC,MAAMrC,GAAGsC,SAASvC,KAAKwC,KAAKP,SAAS,sBAAA,CAAA,GACrCQ,SAAQ,CAAA;AAEZ,UAAMC,WAAW,MAAML,iBAAiB;MACtCM,WAAW5C,KAAK6C,OAAO,KAAKrC,IAAI,IAAI;MACpCsC,WAAW9C,KAAK0B,MAAM,KAAKlB,IAAI;IACjC,CAAA;AAEA,UAAMN,GAAG6C,UACP9C,KAAKwC,KAAKtC,OAAO6B,IAAI,gBAAA,GAAmBL,QAAAA,GACxCgB,QAAAA;EAEJ;AACF;AAEA9C,IAAAA,EAAMmD,SAAS1C,kBAAAA;","names":["cli","Command","Option","Case","path","fs","config","handlebars","fileURLToPath","MakeMigrateCommand","paths","name","String","required","execute","date","Date","year","getFullYear","month","getMonth","padStart","day","getDate","secondsOfDay","getHours","getMinutes","getSeconds","fixed_name","snake","filename","context","stdout","write","mkdir","get","recursive","dirname","__dirname","undefined","url","compiledTemplate","compile","readFile","join","toString","template","className","pascal","tableName","writeFile","register"]}
|