@mostajs/orm-cli 0.2.1 → 0.2.2

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 +73 -3
  2. package/package.json +1 -1
package/bin/mostajs.sh CHANGED
@@ -1144,9 +1144,79 @@ svc_start_dev() {
1144
1144
  }
1145
1145
 
1146
1146
  svc_start_mostanet() {
1147
- warn "mosta-net server not yet installed. Provision with :"
1148
- dim " $PKG_MANAGER install @mostajs/net"
1149
- dim " then run : npx mosta-net --entities .mostajs/generated/entities.ts"
1147
+ load_env
1148
+ cd "$PROJECT_ROOT" || return
1149
+
1150
+ if [[ ! -f "$GENERATED_DIR/entities.json" ]]; then
1151
+ err "No entities.json — run menu 1 (Convert) first"
1152
+ return
1153
+ fi
1154
+
1155
+ # Ensure @mostajs/net AND its peer deps are installed
1156
+ info "Checking @mostajs/net + peer dependencies..."
1157
+ if ! ensure_pkg "@mostajs/net" "@mostajs/orm" "@mostajs/mproject" "@mostajs/replicator"; then
1158
+ err "Cannot start mosta-net server without these packages."
1159
+ return
1160
+ fi
1161
+
1162
+ # Make our entities available to mostajs-net via schemas.json
1163
+ # (mostajs-net's server.js looks for ./schemas.json in CWD)
1164
+ if [[ ! -L schemas.json && ! -f schemas.json ]]; then
1165
+ ln -sf "$GENERATED_DIR/entities.json" "$PROJECT_ROOT/schemas.json" 2>/dev/null \
1166
+ || cp "$GENERATED_DIR/entities.json" "$PROJECT_ROOT/schemas.json"
1167
+ ok "Linked schemas.json → $GENERATED_DIR/entities.json"
1168
+ fi
1169
+
1170
+ # Derive port from MOSTA_NET_URL
1171
+ local mosta_port=14488
1172
+ if [[ "${MOSTA_NET_URL:-}" =~ :([0-9]+) ]]; then
1173
+ mosta_port="${BASH_REMATCH[1]}"
1174
+ fi
1175
+
1176
+ # Prepare env for the child process
1177
+ # - DB vars : DB_DIALECT, SGBD_URI, DB_SCHEMA_STRATEGY, ...
1178
+ # - MOSTA_NET_PORT : derived from MOSTA_NET_URL
1179
+ # - MOSTA_NET_<transport>_ENABLED=true
1180
+ local transport="${MOSTA_NET_TRANSPORT:-rest}"
1181
+ local tr_upper="$(echo "$transport" | tr '[:lower:]' '[:upper:]')"
1182
+
1183
+ info "Launching mostajs-net serve (port $mosta_port, transport $transport)"
1184
+ info "Logs → $LOG_DIR/mostanet.log"
1185
+
1186
+ local launcher
1187
+ if [[ -x "$PROJECT_ROOT/node_modules/.bin/mostajs-net" ]]; then
1188
+ launcher="$PROJECT_ROOT/node_modules/.bin/mostajs-net"
1189
+ else
1190
+ launcher="npx mostajs-net"
1191
+ fi
1192
+
1193
+ # Launch detached with all env vars
1194
+ (
1195
+ export DB_DIALECT="${DB_DIALECT:-sqlite}"
1196
+ export SGBD_URI="${SGBD_URI:-./data.sqlite}"
1197
+ export DB_SCHEMA_STRATEGY="${DB_SCHEMA_STRATEGY:-update}"
1198
+ export DB_POOL_SIZE="${DB_POOL_SIZE:-20}"
1199
+ export DB_SHOW_SQL="${DB_SHOW_SQL:-false}"
1200
+ export MOSTA_NET_PORT="$mosta_port"
1201
+ export "MOSTA_NET_${tr_upper}_ENABLED"="true"
1202
+ # Also enable MCP alongside — commonly wanted for AI integrations
1203
+ [[ "$tr_upper" != "MCP" && "${MOSTA_NET_ALSO_MCP:-true}" == "true" ]] && export MOSTA_NET_MCP_ENABLED=true
1204
+ nohup $launcher serve >> "$LOG_DIR/mostanet.log" 2>&1 &
1205
+ echo "$!" > "$LOG_DIR/mostanet.pid"
1206
+ )
1207
+ local pid
1208
+ pid=$(cat "$LOG_DIR/mostanet.pid" 2>/dev/null || echo "?")
1209
+ ok "Started (PID $pid)"
1210
+ echo
1211
+ info "Endpoints (wait 2-3 seconds then hit them) :"
1212
+ dim " REST CRUD : http://localhost:${mosta_port}/api/v1/<collection>"
1213
+ dim " (collection = snake_case plural, e.g. /api/v1/users)"
1214
+ dim " MCP (AI) : http://localhost:${mosta_port}/mcp"
1215
+ dim " Tail log : tail -f $LOG_DIR/mostanet.log"
1216
+ echo
1217
+ info "Try it :"
1218
+ dim " curl http://localhost:${mosta_port}/api/v1/users"
1219
+ dim " curl http://localhost:${mosta_port}/api/v1/members"
1150
1220
  }
1151
1221
 
1152
1222
  svc_stop_all() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostajs/orm-cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Universal CLI to integrate @mostajs/orm into any project — auto-detects Prisma, OpenAPI, JSON Schema. Interactive menu + subcommands. 13 databases.",
5
5
  "author": "Dr Hamid MADANI <drmdh@msn.com>",
6
6
  "license": "AGPL-3.0-or-later",