@mostajs/orm-cli 0.4.6 → 0.4.7

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 (2) hide show
  1. package/bin/mostajs.sh +67 -0
  2. package/package.json +1 -1
package/bin/mostajs.sh CHANGED
@@ -457,6 +457,7 @@ menu_main() {
457
457
  echo -e " ${CYAN}8${RESET}) Health checks"
458
458
  echo -e " ${CYAN}9${RESET}) Generate boilerplate (src/db.ts with bridge)"
459
459
  echo -e " ${CYAN}s${RESET}) ${BOLD}Seeding${RESET} (upload / validate / apply seed data)"
460
+ echo -e " ${CYAN}e${RESET}) ${BOLD}Export entities${RESET} → Prisma / JSON Schema / OpenAPI / Native"
460
461
  echo -e " ${GREEN}b${RESET}) ${BOLD}Bootstrap${RESET} — one-shot migration of a Prisma project"
461
462
  echo -e " ${GREEN}i${RESET}) ${BOLD}Install bridge${RESET} — codemod PrismaClient → bridge (dry-run / apply / restore)"
462
463
  echo -e " ${CYAN}0${RESET}) About / Help"
@@ -476,6 +477,7 @@ menu_main() {
476
477
  8) action_healthcheck ;;
477
478
  9) action_generate_boilerplate ;;
478
479
  s|S) menu_seeding ;;
480
+ e|E) action_export_entities ;;
479
481
  b|B) menu_bootstrap ;;
480
482
  i|I) menu_install_bridge ;;
481
483
  0) action_about ;;
@@ -1700,6 +1702,71 @@ menu_seeding() {
1700
1702
  menu_seeding
1701
1703
  }
1702
1704
 
1705
+ # ------------------------------------------------------------
1706
+ # Export entities → Prisma / JSON Schema / OpenAPI / Native TS
1707
+ # ------------------------------------------------------------
1708
+ action_export_entities() {
1709
+ header
1710
+ echo -e "${BOLD}${MAGENTA}▶ Export entities to another schema format${RESET}"
1711
+ echo
1712
+ local ent_json="$GENERATED_DIR/entities.json"
1713
+ if [[ ! -f "$ent_json" ]]; then
1714
+ err "No entities.json found — run menu 1 (Convert) first."
1715
+ pause; return
1716
+ fi
1717
+ local count
1718
+ count=$(node -e "console.log(JSON.parse(require('fs').readFileSync('$ent_json','utf8')).length)" 2>/dev/null || echo 0)
1719
+ echo -e " Source : ${DIM}${ent_json}${RESET} (${CYAN}${count}${RESET} entities)"
1720
+ echo
1721
+ echo -e " ${CYAN}1${RESET}) Prisma → ${DIM}schema.prisma${RESET}"
1722
+ echo -e " ${CYAN}2${RESET}) JSON Schema → ${DIM}schema.json${RESET} (2020-12)"
1723
+ echo -e " ${CYAN}3${RESET}) OpenAPI 3.1 → ${DIM}openapi.json${RESET}"
1724
+ echo -e " ${CYAN}4${RESET}) Native (TS) → ${DIM}src/schemas.ts${RESET}"
1725
+ echo
1726
+ echo -e " ${CYAN}b${RESET}) Back"
1727
+ echo
1728
+ local choice
1729
+ choice=$(ask "Format" "1")
1730
+ local format="" default_out=""
1731
+ case "$choice" in
1732
+ 1) format="prisma"; default_out="$PROJECT_ROOT/prisma/schema.prisma" ;;
1733
+ 2) format="jsonschema"; default_out="$PROJECT_ROOT/schema.json" ;;
1734
+ 3) format="openapi"; default_out="$PROJECT_ROOT/openapi.json" ;;
1735
+ 4) format="native"; default_out="$PROJECT_ROOT/src/schemas.ts" ;;
1736
+ b|B) return ;;
1737
+ *) warn "Unknown"; pause; return ;;
1738
+ esac
1739
+ local out
1740
+ out=$(ask "Output file" "$default_out")
1741
+ mkdir -p "$(dirname "$out")"
1742
+
1743
+ # Spawn Node to run the adapter's fromEntitySchema
1744
+ node --input-type=module -e "
1745
+ import('@mostajs/orm-adapter').then(async ({ PrismaAdapter, JsonSchemaAdapter, OpenApiAdapter, NativeAdapter }) => {
1746
+ const entities = JSON.parse(await (await import('fs/promises')).readFile('$ent_json', 'utf8'));
1747
+ let out;
1748
+ switch ('$format') {
1749
+ case 'prisma': out = await new PrismaAdapter().fromEntitySchema(entities); break;
1750
+ case 'jsonschema': out = JSON.stringify(await new JsonSchemaAdapter().fromEntitySchema(entities), null, 2); break;
1751
+ case 'openapi': out = JSON.stringify(await new OpenApiAdapter().fromEntitySchema(entities), null, 2); break;
1752
+ case 'native':
1753
+ out = '// Auto-generated by mostajs export → Native (EntitySchema TS)\n'
1754
+ + '// Author: @mostajs/orm-cli\n\n'
1755
+ + \"import type { EntitySchema } from '@mostajs/orm';\n\n\"
1756
+ + 'export const schemas: EntitySchema[] = '
1757
+ + JSON.stringify(entities, null, 2) + ';\n\n'
1758
+ + '// Named exports for convenience\n'
1759
+ + entities.map(e => 'export const ' + e.name + 'Schema: EntitySchema = schemas.find(s => s.name === \"' + e.name + '\")!;').join('\n')
1760
+ + '\n';
1761
+ break;
1762
+ }
1763
+ await (await import('fs/promises')).writeFile('$out', out);
1764
+ console.log(' ✓ written ' + '$out' + ' (' + (out.length/1024).toFixed(1) + ' KB)');
1765
+ }).catch(e => { console.error(' ✗', e.message); process.exit(1); });
1766
+ " 2>&1
1767
+ pause
1768
+ }
1769
+
1703
1770
  # ------------------------------------------------------------
1704
1771
  # seed : drop tables (interactive picker)
1705
1772
  # ------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostajs/orm-cli",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "Universal CLI to integrate @mostajs/orm into any project — one-shot `mostajs bootstrap` migrates a Prisma project (codemod + deps + schema convert + DDL) to 13 databases with zero code change.",
5
5
  "author": "Dr Hamid MADANI <drmdh@msn.com>",
6
6
  "license": "AGPL-3.0-or-later",