@mostajs/orm-cli 0.2.0 → 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.
- package/bin/mostajs.sh +104 -17
- package/package.json +6 -2
package/bin/mostajs.sh
CHANGED
|
@@ -260,30 +260,31 @@ run_adapter_convert() {
|
|
|
260
260
|
|
|
261
261
|
# Ensure @mostajs/orm-adapter is available — auto-install if missing
|
|
262
262
|
info "Checking @mostajs/orm-adapter..."
|
|
263
|
-
local
|
|
263
|
+
local adapter_base=""
|
|
264
264
|
|
|
265
265
|
# 1. Try local project install
|
|
266
|
-
if [[ -
|
|
267
|
-
|
|
266
|
+
if [[ -d "$PROJECT_ROOT/node_modules/@mostajs/orm-adapter/dist" ]]; then
|
|
267
|
+
adapter_base="$PROJECT_ROOT/node_modules/@mostajs/orm-adapter/dist"
|
|
268
268
|
ok "Using local install"
|
|
269
269
|
else
|
|
270
270
|
# 2. Try sibling (dev setup)
|
|
271
271
|
local cli_dir
|
|
272
272
|
cli_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
273
|
-
if [[ -
|
|
274
|
-
|
|
273
|
+
if [[ -d "$cli_dir/../mosta-orm-adapter/dist" ]]; then
|
|
274
|
+
adapter_base="$cli_dir/../mosta-orm-adapter/dist"
|
|
275
275
|
info "Using sibling dev install"
|
|
276
276
|
else
|
|
277
277
|
# 3. Offer auto-install
|
|
278
278
|
warn "Not installed locally"
|
|
279
279
|
if ensure_pkg "@mostajs/orm-adapter" "@mostajs/orm"; then
|
|
280
|
-
|
|
281
|
-
if [[ ! -
|
|
282
|
-
|
|
283
|
-
|
|
280
|
+
adapter_base="$PROJECT_ROOT/node_modules/@mostajs/orm-adapter/dist"
|
|
281
|
+
if [[ ! -d "$adapter_base" ]]; then
|
|
282
|
+
local resolved
|
|
283
|
+
resolved=$(resolve_pkg_path "@mostajs/orm-adapter") || {
|
|
284
284
|
err "Install reported success but module cannot be resolved."
|
|
285
285
|
return 1
|
|
286
286
|
}
|
|
287
|
+
adapter_base="$(dirname "$resolved")"
|
|
287
288
|
fi
|
|
288
289
|
ok "Installed"
|
|
289
290
|
else
|
|
@@ -293,23 +294,39 @@ run_adapter_convert() {
|
|
|
293
294
|
fi
|
|
294
295
|
fi
|
|
295
296
|
|
|
297
|
+
# Use subpath-specific import to avoid loading ALL adapters (and their
|
|
298
|
+
# transitive deps : ajv, ref-parser, openapi-parser...). For example,
|
|
299
|
+
# importing only prisma.adapter.js avoids pulling in ajv-draft-04 issues
|
|
300
|
+
# when the project only needs Prisma conversion.
|
|
301
|
+
local adapter_file
|
|
296
302
|
local adapter_class
|
|
297
303
|
case "$input_type" in
|
|
298
|
-
prisma) adapter_class="PrismaAdapter" ;;
|
|
299
|
-
openapi) adapter_class="OpenApiAdapter" ;;
|
|
300
|
-
jsonschema) adapter_class="JsonSchemaAdapter" ;;
|
|
304
|
+
prisma) adapter_file="$adapter_base/adapters/prisma.adapter.js" ; adapter_class="PrismaAdapter" ;;
|
|
305
|
+
openapi) adapter_file="$adapter_base/adapters/openapi.adapter.js" ; adapter_class="OpenApiAdapter" ;;
|
|
306
|
+
jsonschema) adapter_file="$adapter_base/adapters/jsonschema.adapter.js" ; adapter_class="JsonSchemaAdapter" ;;
|
|
301
307
|
*) err "Unknown input type: $input_type"; return 1 ;;
|
|
302
308
|
esac
|
|
303
309
|
|
|
310
|
+
if [[ ! -f "$adapter_file" ]]; then
|
|
311
|
+
warn "Subpath import $adapter_file not found — falling back to root index.js"
|
|
312
|
+
adapter_file="$adapter_base/index.js"
|
|
313
|
+
fi
|
|
314
|
+
|
|
304
315
|
cat > "$CONFIG_DIR/convert.mjs" << EOF
|
|
305
316
|
import { readFileSync, writeFileSync } from 'fs';
|
|
306
317
|
|
|
307
318
|
let adapterModule;
|
|
308
319
|
try {
|
|
309
|
-
adapterModule = await import('$
|
|
320
|
+
adapterModule = await import('$adapter_file');
|
|
310
321
|
} catch (e) {
|
|
311
|
-
console.error('Failed to import adapter from $
|
|
322
|
+
console.error('Failed to import adapter from $adapter_file');
|
|
312
323
|
console.error('Reason :', e.message);
|
|
324
|
+
// Common issue : ajv/ref-parser/yaml resolution problems
|
|
325
|
+
if (e.message?.includes('ajv') || e.message?.includes('ref-parser') || e.message?.includes('yaml')) {
|
|
326
|
+
console.error();
|
|
327
|
+
console.error('Hint : this adapter requires peer deps that may be missing.');
|
|
328
|
+
console.error('Try : $PKG_MANAGER install ajv@^8 @apidevtools/json-schema-ref-parser@^11');
|
|
329
|
+
}
|
|
313
330
|
process.exit(2);
|
|
314
331
|
}
|
|
315
332
|
const { $adapter_class } = adapterModule;
|
|
@@ -1127,9 +1144,79 @@ svc_start_dev() {
|
|
|
1127
1144
|
}
|
|
1128
1145
|
|
|
1129
1146
|
svc_start_mostanet() {
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
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"
|
|
1133
1220
|
}
|
|
1134
1221
|
|
|
1135
1222
|
svc_stop_all() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mostajs/orm-cli",
|
|
3
|
-
"version": "0.2.
|
|
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",
|
|
@@ -40,5 +40,9 @@
|
|
|
40
40
|
"linux",
|
|
41
41
|
"darwin",
|
|
42
42
|
"win32"
|
|
43
|
-
]
|
|
43
|
+
],
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@mostajs/orm": "^1.9.2",
|
|
46
|
+
"better-sqlite3": "^12.9.0"
|
|
47
|
+
}
|
|
44
48
|
}
|