@devbro/pashmak 0.1.9 → 0.1.11

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.
Files changed (48) hide show
  1. package/dist/app/console/DefaultCommand.mjs +3 -1
  2. package/dist/app/console/DefaultCommand.mjs.map +1 -1
  3. package/dist/app/console/KeyGenerateCommand.mjs +19 -17
  4. package/dist/app/console/KeyGenerateCommand.mjs.map +1 -1
  5. package/dist/app/console/StartCommand.mjs +9 -13
  6. package/dist/app/console/StartCommand.mjs.map +1 -1
  7. package/dist/app/console/generate/GenerateControllerCommand.mjs +14 -17
  8. package/dist/app/console/generate/GenerateControllerCommand.mjs.map +1 -1
  9. package/dist/app/console/generate/index.mjs +1 -1
  10. package/dist/app/console/generate/index.mjs.map +1 -1
  11. package/dist/app/console/index.mjs +7 -7
  12. package/dist/app/console/index.mjs.map +1 -1
  13. package/dist/app/console/migrate/GenerateMigrateCommand.mjs +14 -17
  14. package/dist/app/console/migrate/GenerateMigrateCommand.mjs.map +1 -1
  15. package/dist/app/console/migrate/MigrateCommand.d.mts +1 -0
  16. package/dist/app/console/migrate/MigrateCommand.mjs +38 -26
  17. package/dist/app/console/migrate/MigrateCommand.mjs.map +1 -1
  18. package/dist/app/console/migrate/MigrateRollbackCommand.d.mts +1 -1
  19. package/dist/app/console/migrate/MigrateRollbackCommand.mjs +7 -15
  20. package/dist/app/console/migrate/MigrateRollbackCommand.mjs.map +1 -1
  21. package/dist/app/console/migrate/index.mjs +3 -3
  22. package/dist/app/console/migrate/index.mjs.map +1 -1
  23. package/dist/app/console/project/CreateProjectCommand.mjs +17 -23
  24. package/dist/app/console/project/CreateProjectCommand.mjs.map +1 -1
  25. package/dist/bin/app/console/DefaultCommand.cjs +99 -7
  26. package/dist/bin/app/console/KeyGenerateCommand.cjs +117 -25
  27. package/dist/bin/app/console/StartCommand.cjs +105 -19
  28. package/dist/bin/app/console/generate/GenerateControllerCommand.cjs +114 -27
  29. package/dist/bin/app/console/generate/index.cjs +114 -27
  30. package/dist/bin/app/console/index.cjs +241 -159
  31. package/dist/bin/app/console/migrate/GenerateMigrateCommand.cjs +113 -26
  32. package/dist/bin/app/console/migrate/MigrateCommand.cjs +136 -34
  33. package/dist/bin/app/console/migrate/MigrateRollbackCommand.cjs +105 -23
  34. package/dist/bin/app/console/migrate/index.cjs +164 -73
  35. package/dist/bin/app/console/project/CreateProjectCommand.cjs +21 -27
  36. package/dist/bin/bin/pashmak_cli.cjs +21 -27
  37. package/dist/bin/facades.cjs +94 -4
  38. package/dist/bin/index.cjs +257 -176
  39. package/dist/bin/middlewares.cjs +94 -4
  40. package/dist/bin/pashmak_cli.mjs +2 -2
  41. package/dist/bin/pashmak_cli.mjs.map +1 -1
  42. package/dist/bin/router.cjs +95 -5
  43. package/dist/index.d.mts +1 -0
  44. package/dist/index.mjs +2 -5
  45. package/dist/index.mjs.map +1 -1
  46. package/dist/router.mjs +1 -1
  47. package/dist/router.mjs.map +1 -1
  48. package/package.json +4 -3
@@ -1184,7 +1184,7 @@ var require_lib = __commonJS({
1184
1184
  }
1185
1185
  });
1186
1186
 
1187
- // src/app/console/index.ts
1187
+ // src/app/console/index.mts
1188
1188
  var console_exports = {};
1189
1189
  __export(console_exports, {
1190
1190
  CreateProjectCommand: () => CreateProjectCommand,
@@ -1202,6 +1202,9 @@ module.exports = __toCommonJS(console_exports);
1202
1202
  var import_neko_context = require("@devbro/neko-context");
1203
1203
  var import_errors = require("@devbro/neko-http/errors");
1204
1204
 
1205
+ // ../neko-router/dist/CompiledRoute.mjs
1206
+ var import_stream = require("stream");
1207
+
1205
1208
  // ../neko-router/dist/Middleware.mjs
1206
1209
  var Middleware = class {
1207
1210
  static {
@@ -1279,6 +1282,9 @@ var CompiledRoute = class {
1279
1282
  if (typeof value.toJson === "function") {
1280
1283
  return traverse(value.toJson());
1281
1284
  }
1285
+ if (typeof value.toJSON === "function") {
1286
+ return traverse(value.toJSON());
1287
+ }
1282
1288
  if (Array.isArray(value)) {
1283
1289
  return value.map(traverse);
1284
1290
  }
@@ -1303,7 +1309,7 @@ var CompiledRoute = class {
1303
1309
  }
1304
1310
  return String(obj);
1305
1311
  }
1306
- processResponseBody(res, controller_rc) {
1312
+ async processResponseBody(res, controller_rc) {
1307
1313
  if (controller_rc && res.writableEnded) {
1308
1314
  throw new Error("cannot write to response, response has already ended");
1309
1315
  }
@@ -1312,18 +1318,36 @@ var CompiledRoute = class {
1312
1318
  }
1313
1319
  if (controller_rc) {
1314
1320
  const header_content_type = res.getHeader("Content-Type");
1315
- if (!header_content_type && typeof controller_rc === "object") {
1321
+ if (controller_rc instanceof import_stream.Stream || Buffer.isBuffer(controller_rc)) {
1322
+ await this.writeAsync(res, controller_rc);
1323
+ res.end();
1324
+ } else if (!header_content_type && typeof controller_rc === "object") {
1316
1325
  res.setHeader("Content-Type", "application/json");
1326
+ res.end(this.convertToString(controller_rc));
1317
1327
  } else if (!header_content_type) {
1318
1328
  res.setHeader("Content-Type", "text/plain");
1329
+ res.end(this.convertToString(controller_rc));
1330
+ } else {
1331
+ res.end(this.convertToString(controller_rc));
1319
1332
  }
1320
- res.end(this.convertToString(controller_rc));
1321
1333
  return;
1322
1334
  } else {
1323
1335
  res.statusCode = [200].includes(res.statusCode) ? 204 : res.statusCode;
1324
1336
  res.end();
1325
1337
  }
1326
1338
  }
1339
+ async writeAsync(res, chunk) {
1340
+ return new Promise((resolve, reject) => {
1341
+ const ok = res.write(chunk, (err) => {
1342
+ if (err) reject(err);
1343
+ });
1344
+ if (ok) {
1345
+ resolve(0);
1346
+ } else {
1347
+ res.once("drain", resolve);
1348
+ }
1349
+ });
1350
+ }
1327
1351
  async runMiddlewares(middlewares, req, res) {
1328
1352
  let index = 0;
1329
1353
  const me = this;
@@ -1381,7 +1405,7 @@ var Route = class {
1381
1405
  i = start;
1382
1406
  } else if (char === "*") {
1383
1407
  let start = i + 1;
1384
- while (start < path8.length && /[a-zA-Z0-9_]/.test(path8[start])) {
1408
+ while (start < path8.length && /[a-zA-Z0-9_\.]/.test(path8[start])) {
1385
1409
  start++;
1386
1410
  }
1387
1411
  tokens.push({ type: "WILDCARD", value: path8.slice(i + 1, start) });
@@ -1451,6 +1475,10 @@ var Route = class {
1451
1475
  params: r.groups || {}
1452
1476
  };
1453
1477
  }
1478
+ prependMiddleware(middlewares) {
1479
+ this.middlewares = [].concat(middlewares, this.middlewares);
1480
+ return this;
1481
+ }
1454
1482
  addMiddleware(middlewares) {
1455
1483
  this.middlewares = this.middlewares.concat(middlewares);
1456
1484
  return this;
@@ -1465,6 +1493,62 @@ var Route = class {
1465
1493
 
1466
1494
  // ../neko-router/dist/Router.mjs
1467
1495
  var import_path = __toESM(require("path"), 1);
1496
+
1497
+ // ../node_modules/url-join/lib/url-join.js
1498
+ function normalize(strArray) {
1499
+ var resultArray = [];
1500
+ if (strArray.length === 0) {
1501
+ return "";
1502
+ }
1503
+ if (typeof strArray[0] !== "string") {
1504
+ throw new TypeError("Url must be a string. Received " + strArray[0]);
1505
+ }
1506
+ if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
1507
+ var first = strArray.shift();
1508
+ strArray[0] = first + strArray[0];
1509
+ }
1510
+ if (strArray[0].match(/^file:\/\/\//)) {
1511
+ strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1:///");
1512
+ } else {
1513
+ strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, "$1://");
1514
+ }
1515
+ for (var i = 0; i < strArray.length; i++) {
1516
+ var component = strArray[i];
1517
+ if (typeof component !== "string") {
1518
+ throw new TypeError("Url must be a string. Received " + component);
1519
+ }
1520
+ if (component === "") {
1521
+ continue;
1522
+ }
1523
+ if (i > 0) {
1524
+ component = component.replace(/^[\/]+/, "");
1525
+ }
1526
+ if (i < strArray.length - 1) {
1527
+ component = component.replace(/[\/]+$/, "");
1528
+ } else {
1529
+ component = component.replace(/[\/]+$/, "/");
1530
+ }
1531
+ resultArray.push(component);
1532
+ }
1533
+ var str = resultArray.join("/");
1534
+ str = str.replace(/\/(\?|&|#[^!])/g, "$1");
1535
+ var parts = str.split("?");
1536
+ str = parts.shift() + (parts.length > 0 ? "?" : "") + parts.join("&");
1537
+ return str;
1538
+ }
1539
+ __name(normalize, "normalize");
1540
+ function urlJoin() {
1541
+ var input;
1542
+ if (typeof arguments[0] === "object") {
1543
+ input = arguments[0];
1544
+ } else {
1545
+ input = [].slice.call(arguments);
1546
+ }
1547
+ return normalize(input);
1548
+ }
1549
+ __name(urlJoin, "urlJoin");
1550
+
1551
+ // ../neko-router/dist/Router.mjs
1468
1552
  var Router = class {
1469
1553
  static {
1470
1554
  __name(this, "Router");
@@ -1489,6 +1573,12 @@ var Router = class {
1489
1573
  }).addMiddleware([...controller.baseMiddlewares, ...route.middlewares]);
1490
1574
  }
1491
1575
  }
1576
+ addRouter(path22, router2) {
1577
+ for (const route of router2.routes) {
1578
+ let path222 = urlJoin("/", path22, route.path);
1579
+ this.addRoute(route.methods, path222, route.handler).addMiddleware(router2.getMiddlewares()).addMiddleware(route.getMiddlewares());
1580
+ }
1581
+ }
1492
1582
  addGlobalMiddleware(middlewares) {
1493
1583
  this.middlewares = this.middlewares.concat(middlewares);
1494
1584
  }
@@ -1634,44 +1724,57 @@ var mailer = (0, import_neko_helper.createSingleton)((label) => {
1634
1724
  return rc;
1635
1725
  });
1636
1726
 
1637
- // src/app/console/migrate/MigrateCommand.ts
1727
+ // src/app/console/migrate/MigrateCommand.mts
1638
1728
  var import_clipanion2 = require("clipanion");
1639
1729
  var import_neko_context3 = require("@devbro/neko-context");
1640
- var import_path2 = __toESM(require("path"));
1641
- var import_promises = __toESM(require("fs/promises"));
1730
+ var import_path2 = __toESM(require("path"), 1);
1731
+ var import_promises = __toESM(require("fs/promises"), 1);
1642
1732
  var import_neko_config2 = require("@devbro/neko-config");
1643
1733
  var MigrateCommand = class extends import_clipanion2.Command {
1644
1734
  static {
1645
1735
  __name(this, "MigrateCommand");
1646
1736
  }
1647
- static paths = [
1648
- [
1649
- `migrate`
1650
- ]
1651
- ];
1652
- fresh = import_clipanion2.Option.Boolean("--fresh", false);
1737
+ static paths = [[`migrate`]];
1738
+ fresh = import_clipanion2.Option.Boolean(`--fresh`, false, {
1739
+ description: `whether to delete and recreate database`
1740
+ });
1741
+ refresh = import_clipanion2.Option.Boolean(`--refresh`, false, {
1742
+ description: `whether to drop all tables before running migrations by using rollback function`
1743
+ });
1653
1744
  async execute() {
1654
1745
  await import_neko_context3.context_provider.run(async () => {
1655
1746
  const db2 = db();
1656
1747
  const schema = db2.getSchema();
1657
1748
  if (this.fresh) {
1658
- logger().info("dropping all tables!!");
1659
- let retry = true;
1660
- let retry_count = 0;
1661
- while (retry && retry_count < 10) {
1662
- retry = false;
1663
- retry_count++;
1664
- const tables = await schema.tables();
1665
- for (const table of tables) {
1666
- logger().info(`dropping table ${table.name}`);
1667
- try {
1668
- await schema.dropTable(table.name);
1669
- } catch {
1670
- logger().info(`failed to drop ${table.name}`);
1671
- retry = true;
1672
- }
1749
+ throw new Error("not implemented");
1750
+ }
1751
+ if (this.refresh) {
1752
+ logger().info("reverting all migrations!!");
1753
+ const existing_migrations = await db2.runQuery({
1754
+ sql: "select * from migrations order by created_at DESC",
1755
+ bindings: []
1756
+ });
1757
+ const migrationsDir2 = import_neko_config2.config.get("migration.path");
1758
+ for (const migration_record of existing_migrations) {
1759
+ logger().info(`rolling back ${migration_record.filename}`);
1760
+ try {
1761
+ const MigrationClass = (await import(import_path2.default.join(migrationsDir2, migration_record.filename))).default;
1762
+ const migrationInstance = new MigrationClass();
1763
+ await migrationInstance.down(db2.getSchema());
1764
+ await db2.runQuery({
1765
+ sql: "delete from migrations where filename = $1",
1766
+ bindings: [migration_record.filename]
1767
+ });
1768
+ } catch (error) {
1769
+ logger().error(
1770
+ `Failed to rollback migration ${migration_record.filename}: ${error}`
1771
+ );
1772
+ throw error;
1673
1773
  }
1674
1774
  }
1775
+ logger().info(
1776
+ `rolled back ${existing_migrations.length} migrations successfully!`
1777
+ );
1675
1778
  }
1676
1779
  if (!await schema.tableExists("migrations")) {
1677
1780
  await schema.createTable("migrations", (blueprint) => {
@@ -1696,7 +1799,9 @@ var MigrateCommand = class extends import_clipanion2.Command {
1696
1799
  bindings: []
1697
1800
  });
1698
1801
  const completed_migrations = migrations.map((r) => r.filename);
1699
- const pending_migrations = files.filter((file) => !completed_migrations.includes(file));
1802
+ const pending_migrations = files.filter(
1803
+ (file) => !completed_migrations.includes(file)
1804
+ );
1700
1805
  let migrated_count = 0;
1701
1806
  for (const class_to_migrate of pending_migrations) {
1702
1807
  logger().info(`migrating up ${class_to_migrate}`);
@@ -1705,10 +1810,7 @@ var MigrateCommand = class extends import_clipanion2.Command {
1705
1810
  await c.up(db2.getSchema());
1706
1811
  await db2.runQuery({
1707
1812
  sql: "insert into migrations (filename, batch) values ($1,$2)",
1708
- bindings: [
1709
- class_to_migrate,
1710
- batch_number
1711
- ]
1813
+ bindings: [class_to_migrate, batch_number]
1712
1814
  });
1713
1815
  migrated_count++;
1714
1816
  }
@@ -1722,13 +1824,13 @@ var MigrateCommand = class extends import_clipanion2.Command {
1722
1824
  };
1723
1825
  cli().register(MigrateCommand);
1724
1826
 
1725
- // src/app/console/migrate/GenerateMigrateCommand.ts
1827
+ // src/app/console/migrate/GenerateMigrateCommand.mts
1726
1828
  var import_clipanion3 = require("clipanion");
1727
1829
  var import_change_case_all = require("change-case-all");
1728
- var import_path3 = __toESM(require("path"));
1729
- var fs2 = __toESM(require("fs/promises"));
1830
+ var import_path3 = __toESM(require("path"), 1);
1831
+ var fs2 = __toESM(require("fs/promises"), 1);
1730
1832
  var import_neko_config3 = require("@devbro/neko-config");
1731
- var import_handlebars = __toESM(require("handlebars"));
1833
+ var import_handlebars = __toESM(require("handlebars"), 1);
1732
1834
  var import_url = require("url");
1733
1835
  var import_meta = {};
1734
1836
  var GenerateMigrateCommand = class extends import_clipanion3.Command {
@@ -1736,63 +1838,55 @@ var GenerateMigrateCommand = class extends import_clipanion3.Command {
1736
1838
  __name(this, "GenerateMigrateCommand");
1737
1839
  }
1738
1840
  static paths = [
1739
- [
1740
- `generate`,
1741
- `migrate`
1742
- ],
1743
- [
1744
- "generate",
1745
- "migration"
1746
- ]
1841
+ [`generate`, `migrate`],
1842
+ ["generate", "migration"]
1747
1843
  ];
1748
- name = import_clipanion3.Option.String({
1749
- required: true
1750
- });
1844
+ name = import_clipanion3.Option.String({ required: true });
1751
1845
  async execute() {
1752
1846
  const date = /* @__PURE__ */ new Date();
1753
1847
  const year = date.getFullYear();
1754
1848
  const month = String(date.getMonth() + 1).padStart(2, "0");
1755
1849
  const day = String(date.getDate()).padStart(2, "0");
1756
- const secondsOfDay = String(date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()).padStart(5, "0");
1850
+ const secondsOfDay = String(
1851
+ date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()
1852
+ ).padStart(5, "0");
1757
1853
  const fixed_name = import_change_case_all.Case.snake(this.name);
1758
1854
  const filename = `${year}_${month}_${day}_${secondsOfDay}_${fixed_name}.ts`;
1759
1855
  this.context.stdout.write(`creating migration file ${filename}
1760
1856
  `);
1761
- await fs2.mkdir(import_neko_config3.config.get("migration.path"), {
1762
- recursive: true
1763
- });
1857
+ await fs2.mkdir(import_neko_config3.config.get("migration.path"), { recursive: true });
1764
1858
  let dirname = typeof __dirname === "string" ? __dirname : void 0;
1765
1859
  if (!dirname) {
1766
1860
  dirname = import_path3.default.dirname((0, import_url.fileURLToPath)(import_meta.url));
1767
1861
  }
1768
- const compiledTemplate = import_handlebars.default.compile((await fs2.readFile(import_path3.default.join(dirname, "./make_migration.tpl"))).toString());
1862
+ const compiledTemplate = import_handlebars.default.compile(
1863
+ (await fs2.readFile(import_path3.default.join(dirname, "./make_migration.tpl"))).toString()
1864
+ );
1769
1865
  const template = await compiledTemplate({
1770
1866
  className: import_change_case_all.Case.pascal(this.name) + "Migration",
1771
1867
  tableName: import_change_case_all.Case.snake(this.name)
1772
1868
  });
1773
- await fs2.writeFile(import_path3.default.join(import_neko_config3.config.get("migration.path"), filename), template);
1869
+ await fs2.writeFile(
1870
+ import_path3.default.join(import_neko_config3.config.get("migration.path"), filename),
1871
+ template
1872
+ );
1774
1873
  }
1775
1874
  };
1776
1875
  cli().register(GenerateMigrateCommand);
1777
1876
 
1778
- // src/app/console/migrate/MigrateRollbackCommand.ts
1877
+ // src/app/console/migrate/MigrateRollbackCommand.mts
1779
1878
  var import_clipanion4 = require("clipanion");
1780
1879
  var import_neko_context4 = require("@devbro/neko-context");
1781
- var import_path4 = __toESM(require("path"));
1782
- var import_promises2 = __toESM(require("fs/promises"));
1880
+ var import_path4 = __toESM(require("path"), 1);
1881
+ var import_promises2 = __toESM(require("fs/promises"), 1);
1783
1882
  var import_neko_config4 = require("@devbro/neko-config");
1784
- var t = __toESM(require_lib());
1883
+ var t = __toESM(require_lib(), 1);
1785
1884
  var MigrateRollbackCommand = class extends import_clipanion4.Command {
1786
1885
  static {
1787
1886
  __name(this, "MigrateRollbackCommand");
1788
1887
  }
1789
- static paths = [
1790
- [
1791
- `migrate`,
1792
- "rollback"
1793
- ]
1794
- ];
1795
- steps = import_clipanion4.Option.String(`--steps`, {
1888
+ static paths = [[`migrate`, "rollback"]];
1889
+ steps = import_clipanion4.Option.String(`--steps`, "1", {
1796
1890
  description: `how many migrations to rollback`,
1797
1891
  validator: t.isNumber()
1798
1892
  });
@@ -1805,21 +1899,18 @@ var MigrateRollbackCommand = class extends import_clipanion4.Command {
1805
1899
  const dirEntries = await import_promises2.default.readdir(migrationsDir);
1806
1900
  files = dirEntries.filter((entry) => entry.endsWith(".ts")).sort();
1807
1901
  const migrations = await db2.runQuery({
1808
- sql: "select * from migrations order by created_at DESC",
1809
- bindings: []
1902
+ sql: "select * from migrations order by created_at DESC limit $1",
1903
+ bindings: [this.steps]
1810
1904
  });
1811
- const count = 0;
1812
1905
  for (const migration of migrations) {
1813
1906
  const class_to_migrate = migration.filename;
1814
- this.context.stdout.write(`rolling back ${class_to_migrate}`);
1907
+ logger().info(`rolling back ${class_to_migrate}`);
1815
1908
  const ClassToMigrate = (await import(import_path4.default.join(migrationsDir, class_to_migrate))).default;
1816
1909
  const c = new ClassToMigrate();
1817
1910
  await c.down(db2.getSchema());
1818
1911
  await db2.runQuery({
1819
1912
  sql: "delete from migrations where id = $1",
1820
- bindings: [
1821
- migration.id
1822
- ]
1913
+ bindings: [migration.id]
1823
1914
  });
1824
1915
  }
1825
1916
  });
@@ -1827,7 +1918,7 @@ var MigrateRollbackCommand = class extends import_clipanion4.Command {
1827
1918
  };
1828
1919
  cli().register(MigrateRollbackCommand);
1829
1920
 
1830
- // src/app/console/StartCommand.ts
1921
+ // src/app/console/StartCommand.mts
1831
1922
  var import_clipanion5 = require("clipanion");
1832
1923
  var import_neko_config5 = require("@devbro/neko-config");
1833
1924
  var import_neko_sql = require("@devbro/neko-sql");
@@ -1838,19 +1929,13 @@ var StartCommand = class extends import_clipanion5.Command {
1838
1929
  scheduler = import_clipanion5.Option.Boolean(`--scheduler`, false);
1839
1930
  http = import_clipanion5.Option.Boolean(`--http`, false);
1840
1931
  all = import_clipanion5.Option.Boolean("--all", false);
1841
- static paths = [
1842
- [
1843
- `start`
1844
- ]
1845
- ];
1932
+ static paths = [[`start`]];
1846
1933
  async execute() {
1847
- if ([
1848
- this.all,
1849
- this.http,
1850
- this.scheduler
1851
- ].filter((x) => x).length == 0) {
1852
- this.context.stdout.write(`No service was selected. please check -h for details
1853
- `);
1934
+ if ([this.all, this.http, this.scheduler].filter((x) => x).length == 0) {
1935
+ this.context.stdout.write(
1936
+ `No service was selected. please check -h for details
1937
+ `
1938
+ );
1854
1939
  return;
1855
1940
  }
1856
1941
  logger().info(`Starting Server
@@ -1864,14 +1949,16 @@ var StartCommand = class extends import_clipanion5.Command {
1864
1949
  if (this.http || this.all) {
1865
1950
  const server = httpServer();
1866
1951
  await server.listen(import_neko_config5.config.get("port"), () => {
1867
- logger().info("Server is running on http://localhost:" + import_neko_config5.config.get("port"));
1952
+ logger().info(
1953
+ "Server is running on http://localhost:" + import_neko_config5.config.get("port")
1954
+ );
1868
1955
  });
1869
1956
  }
1870
1957
  }
1871
1958
  };
1872
1959
  cli().register(StartCommand);
1873
1960
 
1874
- // src/app/console/DefaultCommand.ts
1961
+ // src/app/console/DefaultCommand.mts
1875
1962
  var import_clipanion6 = require("clipanion");
1876
1963
  var DefaultCommand = class extends import_clipanion6.Command {
1877
1964
  static {
@@ -1890,7 +1977,9 @@ var DefaultCommand = class extends import_clipanion6.Command {
1890
1977
  async execute() {
1891
1978
  const commandList = cli().registrations;
1892
1979
  const paths = [];
1893
- commandList.forEach((index, val) => paths.push(index.builder.paths[0]?.join(" ") || ""));
1980
+ commandList.forEach(
1981
+ (index, val) => paths.push(index.builder.paths[0]?.join(" ") || "")
1982
+ );
1894
1983
  console.log("Available commands:");
1895
1984
  for (const cmd of paths) {
1896
1985
  if (cmd) {
@@ -1901,21 +1990,16 @@ var DefaultCommand = class extends import_clipanion6.Command {
1901
1990
  };
1902
1991
  cli().register(DefaultCommand);
1903
1992
 
1904
- // src/app/console/KeyGenerateCommand.ts
1993
+ // src/app/console/KeyGenerateCommand.mts
1905
1994
  var import_clipanion7 = require("clipanion");
1906
1995
  var import_crypto = require("crypto");
1907
- var import_promises3 = __toESM(require("fs/promises"));
1908
- var import_path5 = __toESM(require("path"));
1996
+ var import_promises3 = __toESM(require("fs/promises"), 1);
1997
+ var import_path5 = __toESM(require("path"), 1);
1909
1998
  var KeyGenerateCommand = class extends import_clipanion7.Command {
1910
1999
  static {
1911
2000
  __name(this, "KeyGenerateCommand");
1912
2001
  }
1913
- static paths = [
1914
- [
1915
- `generate`,
1916
- "key"
1917
- ]
1918
- ];
2002
+ static paths = [[`generate`, "key"]];
1919
2003
  static usage = import_clipanion7.Command.Usage({
1920
2004
  category: `Main`,
1921
2005
  description: `generate keys`,
@@ -1924,14 +2008,8 @@ var KeyGenerateCommand = class extends import_clipanion7.Command {
1924
2008
  Use --rotate flag to preserve old public key.
1925
2009
  `,
1926
2010
  examples: [
1927
- [
1928
- `Generate new keys`,
1929
- `generate key`
1930
- ],
1931
- [
1932
- `Rotate existing keys`,
1933
- `generate key --rotate`
1934
- ]
2011
+ [`Generate new keys`, `generate key`],
2012
+ [`Rotate existing keys`, `generate key --rotate`]
1935
2013
  ]
1936
2014
  });
1937
2015
  rotate = import_clipanion7.Option.Boolean(`--rotate`, false, {
@@ -1941,6 +2019,7 @@ var KeyGenerateCommand = class extends import_clipanion7.Command {
1941
2019
  logger().info("generating keys for jwt token and adding to .env file");
1942
2020
  const { publicKey, privateKey } = (0, import_crypto.generateKeyPairSync)("rsa", {
1943
2021
  modulusLength: 2048,
2022
+ // 2048-bit key is standard for RS256
1944
2023
  publicKeyEncoding: {
1945
2024
  type: "spki",
1946
2025
  format: "pem"
@@ -1956,10 +2035,22 @@ var KeyGenerateCommand = class extends import_clipanion7.Command {
1956
2035
  } catch {
1957
2036
  }
1958
2037
  let old_public_key = envfile.match(/^jwt_secret_public=(.*)/m);
1959
- envfile = this.addEnvParam(envfile, "jwt_secret_public", this.stripPemHeaders(publicKey));
1960
- envfile = this.addEnvParam(envfile, "jwt_secret_private", this.stripPemHeaders(privateKey));
2038
+ envfile = this.addEnvParam(
2039
+ envfile,
2040
+ "jwt_secret_public",
2041
+ this.stripPemHeaders(publicKey)
2042
+ );
2043
+ envfile = this.addEnvParam(
2044
+ envfile,
2045
+ "jwt_secret_private",
2046
+ this.stripPemHeaders(privateKey)
2047
+ );
1961
2048
  if (this.rotate && old_public_key && old_public_key[1]) {
1962
- envfile = this.addEnvParam(envfile, "jwt_secret_public_retired", old_public_key[1]);
2049
+ envfile = this.addEnvParam(
2050
+ envfile,
2051
+ "jwt_secret_public_retired",
2052
+ old_public_key[1]
2053
+ );
1963
2054
  }
1964
2055
  await import_promises3.default.writeFile(import_path5.default.join(process.cwd(), ".env"), envfile, "utf-8");
1965
2056
  }
@@ -1979,81 +2070,73 @@ ${key}=${value}`;
1979
2070
  };
1980
2071
  cli().register(KeyGenerateCommand);
1981
2072
 
1982
- // src/app/console/generate/GenerateControllerCommand.ts
2073
+ // src/app/console/generate/GenerateControllerCommand.mts
1983
2074
  var import_clipanion8 = require("clipanion");
1984
2075
  var import_change_case_all2 = require("change-case-all");
1985
- var import_path6 = __toESM(require("path"));
1986
- var fs5 = __toESM(require("fs/promises"));
2076
+ var import_path6 = __toESM(require("path"), 1);
2077
+ var fs5 = __toESM(require("fs/promises"), 1);
1987
2078
  var import_neko_config6 = require("@devbro/neko-config");
1988
- var import_handlebars2 = __toESM(require("handlebars"));
2079
+ var import_handlebars2 = __toESM(require("handlebars"), 1);
1989
2080
  var import_url2 = require("url");
1990
- var import_pluralize = __toESM(require("pluralize"));
2081
+ var import_pluralize = __toESM(require("pluralize"), 1);
1991
2082
  var import_meta2 = {};
1992
2083
  var GenerateControllerCommand = class extends import_clipanion8.Command {
1993
2084
  static {
1994
2085
  __name(this, "GenerateControllerCommand");
1995
2086
  }
1996
2087
  static paths = [
1997
- [
1998
- `make`,
1999
- `controller`
2000
- ],
2001
- [
2002
- `generate`,
2003
- `controller`
2004
- ]
2088
+ [`make`, `controller`],
2089
+ [`generate`, `controller`]
2005
2090
  ];
2006
- name = import_clipanion8.Option.String({
2007
- required: true
2008
- });
2091
+ name = import_clipanion8.Option.String({ required: true });
2009
2092
  async execute() {
2010
2093
  const rootDir = process.cwd();
2011
2094
  const date = /* @__PURE__ */ new Date();
2012
2095
  const year = date.getFullYear();
2013
2096
  const month = String(date.getMonth() + 1).padStart(2, "0");
2014
2097
  const day = String(date.getDate()).padStart(2, "0");
2015
- const secondsOfDay = String(date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()).padStart(5, "0");
2098
+ const secondsOfDay = String(
2099
+ date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()
2100
+ ).padStart(5, "0");
2016
2101
  const fixed_name = import_change_case_all2.Case.snake(this.name);
2017
2102
  const filename = `${import_change_case_all2.Case.capital(this.name)}Controller.ts`;
2018
2103
  this.context.stdout.write(`creating migration file ${filename}
2019
2104
  `);
2020
- await fs5.mkdir(import_neko_config6.config.get("migration.path"), {
2021
- recursive: true
2022
- });
2105
+ await fs5.mkdir(import_neko_config6.config.get("migration.path"), { recursive: true });
2023
2106
  let dirname = typeof __dirname === "string" ? __dirname : void 0;
2024
2107
  if (!dirname) {
2025
2108
  dirname = import_path6.default.dirname((0, import_url2.fileURLToPath)(import_meta2.url));
2026
2109
  }
2027
- const compiledTemplate = import_handlebars2.default.compile((await fs5.readFile(import_path6.default.join(dirname, "./controller.tpl"))).toString());
2110
+ const compiledTemplate = import_handlebars2.default.compile(
2111
+ (await fs5.readFile(import_path6.default.join(dirname, "./controller.tpl"))).toString()
2112
+ );
2028
2113
  const template = await compiledTemplate({
2029
2114
  className: import_change_case_all2.Case.pascal(this.name),
2030
2115
  classNameLower: import_change_case_all2.Case.snake(this.name),
2031
2116
  routeName: import_change_case_all2.Case.kebab((0, import_pluralize.default)(this.name))
2032
2117
  });
2033
- await fs5.writeFile(import_path6.default.join(rootDir, "src/app/controllers", filename), template);
2118
+ await fs5.writeFile(
2119
+ import_path6.default.join(rootDir, "src/app/controllers", filename),
2120
+ template
2121
+ );
2034
2122
  }
2035
2123
  };
2036
2124
  cli().register(GenerateControllerCommand);
2037
2125
 
2038
- // src/app/console/project/CreateProjectCommand.ts
2126
+ // src/app/console/project/CreateProjectCommand.mts
2039
2127
  var import_clipanion9 = require("clipanion");
2040
2128
  var import_change_case_all3 = require("change-case-all");
2041
- var import_path7 = __toESM(require("path"));
2042
- var fs6 = __toESM(require("fs/promises"));
2129
+ var import_path7 = __toESM(require("path"), 1);
2130
+ var fs6 = __toESM(require("fs/promises"), 1);
2043
2131
  var import_url3 = require("url");
2044
- var import_handlebars3 = __toESM(require("handlebars"));
2132
+ var import_handlebars3 = __toESM(require("handlebars"), 1);
2045
2133
  var import_child_process = require("child_process");
2046
2134
  var import_meta3 = {};
2047
2135
  var CreateProjectCommand = class extends import_clipanion9.Command {
2048
2136
  static {
2049
2137
  __name(this, "CreateProjectCommand");
2050
2138
  }
2051
- static paths = [
2052
- [
2053
- `create`,
2054
- `project`
2055
- ]
2056
- ];
2139
+ static paths = [[`create`, `project`]];
2057
2140
  static usage = import_clipanion9.Command.Usage({
2058
2141
  category: `Project`,
2059
2142
  description: `Create a new project`,
@@ -2072,9 +2155,7 @@ var CreateProjectCommand = class extends import_clipanion9.Command {
2072
2155
  ]
2073
2156
  ]
2074
2157
  });
2075
- projectPath = import_clipanion9.Option.String("--path", {
2076
- required: true
2077
- });
2158
+ projectPath = import_clipanion9.Option.String("--path", { required: true });
2078
2159
  git = import_clipanion9.Option.Boolean(`--git`, false, {
2079
2160
  description: `Initialize a git repository in the new project`
2080
2161
  });
@@ -2097,9 +2178,7 @@ var CreateProjectCommand = class extends import_clipanion9.Command {
2097
2178
  return 1;
2098
2179
  } catch {
2099
2180
  }
2100
- await fs6.mkdir(projectPath, {
2101
- recursive: true
2102
- });
2181
+ await fs6.mkdir(projectPath, { recursive: true });
2103
2182
  console.log(`Created project directory at: ${projectPath}`);
2104
2183
  const dirname = typeof __dirname === "undefined" ? import_path7.default.dirname((0, import_url3.fileURLToPath)(import_meta3.url)) : __dirname;
2105
2184
  let basePath = import_path7.default.join(dirname, `./base_project`);
@@ -2117,9 +2196,12 @@ var CreateProjectCommand = class extends import_clipanion9.Command {
2117
2196
  console.log(`Updated package.json with project name: ${packageJson.name}`);
2118
2197
  if (this.git) {
2119
2198
  try {
2120
- (0, import_child_process.execSync)('git init; git add --all; git commit --allow-empty -m "chore: first commit for pashmak"', {
2121
- cwd: projectPath
2122
- });
2199
+ (0, import_child_process.execSync)(
2200
+ 'git init; git add --all; git commit --allow-empty -m "chore: first commit for pashmak"',
2201
+ {
2202
+ cwd: projectPath
2203
+ }
2204
+ );
2123
2205
  } catch (error) {
2124
2206
  console.error(`Failed to create project.`, error);
2125
2207
  return 1;
@@ -2127,32 +2209,32 @@ var CreateProjectCommand = class extends import_clipanion9.Command {
2127
2209
  }
2128
2210
  }
2129
2211
  async processTplFolder(src, dest, data = {}) {
2130
- const files = await fs6.readdir(src, {
2131
- withFileTypes: true
2132
- });
2212
+ const files = await fs6.readdir(src, { withFileTypes: true });
2133
2213
  for (const file of files) {
2134
2214
  const srcPath = import_path7.default.join(src, file.name);
2135
2215
  const destPath = file.isFile() && file.name.endsWith(".tpl") ? import_path7.default.join(dest, file.name.substring(0, file.name.length - 4)) : import_path7.default.join(dest, file.name);
2136
2216
  if (file.isDirectory()) {
2137
- await fs6.mkdir(destPath, {
2138
- recursive: true
2139
- });
2217
+ await fs6.mkdir(destPath, { recursive: true });
2140
2218
  await this.processTplFolder(srcPath, destPath, data);
2141
2219
  } else if (file.name.endsWith(".tpl")) {
2142
2220
  await this.processTplFile(srcPath, destPath, {});
2143
2221
  } else {
2144
- throw new Error("unexpected non tpl file: " + srcPath + " " + file.name);
2222
+ throw new Error(
2223
+ "unexpected non tpl file: " + srcPath + " " + file.name
2224
+ );
2145
2225
  }
2146
2226
  }
2147
2227
  }
2148
2228
  async processTplFile(src, dest, data = {}) {
2149
- const compiledTemplate = import_handlebars3.default.compile((await fs6.readFile(src)).toString());
2229
+ const compiledTemplate = import_handlebars3.default.compile(
2230
+ (await fs6.readFile(src)).toString()
2231
+ );
2150
2232
  const template = await compiledTemplate(data);
2151
2233
  await fs6.writeFile(dest, template);
2152
2234
  }
2153
2235
  };
2154
2236
 
2155
- // src/app/console/index.ts
2237
+ // src/app/console/index.mts
2156
2238
  cli().register(CreateProjectCommand);
2157
2239
  // Annotate the CommonJS export names for ESM import in node:
2158
2240
  0 && (module.exports = {