@devbro/pashmak 0.1.7 → 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/base_project/package.json.tpl +1 -1
- package/dist/router.d.ts +1 -1
- package/dist/router.js +1 -1
- package/dist/router.js.map +1 -1
- package/package.json +1 -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),\n template,\n );\n }\n}\n\ncli().register(GenerateControllerCommand);\n"],"mappings":";;AAAA,SAASA,WAAW;AACpB,SAASC,SAASC,cAAc;AAChC,SAASC,YAAY;AACrB,OAAOC,UAAU;AACjB,YAAYC,QAAQ;AACpB,SAASC,cAAc;AACvB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
|
|
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,SAASC,cAAc;AAChC,SAASC,YAAY;AACrB,OAAOC,UAAU;AACjB,YAAYC,QAAQ;AACpB,SAASC,cAAc;AACvB,OAAOC,gBAAgB;AACvB,SAASC,qBAAqB;AAC9B,OAAOC,eAAe;AAEf,MAAMC,kCAAkCT,QAAA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,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":[]}
|
|
@@ -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/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 +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"]}
|