@mostajs/orm-cli 0.2.0 → 0.2.1

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 +31 -14
  2. 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 adapter_path=""
263
+ local adapter_base=""
264
264
 
265
265
  # 1. Try local project install
266
- if [[ -f "$PROJECT_ROOT/node_modules/@mostajs/orm-adapter/dist/index.js" ]]; then
267
- adapter_path="$PROJECT_ROOT/node_modules/@mostajs/orm-adapter/dist/index.js"
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 [[ -f "$cli_dir/../mosta-orm-adapter/dist/index.js" ]]; then
274
- adapter_path="$cli_dir/../mosta-orm-adapter/dist/index.js"
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
- adapter_path="$PROJECT_ROOT/node_modules/@mostajs/orm-adapter/dist/index.js"
281
- if [[ ! -f "$adapter_path" ]]; then
282
- # Try via require.resolve
283
- adapter_path=$(resolve_pkg_path "@mostajs/orm-adapter") || {
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('$adapter_path');
320
+ adapterModule = await import('$adapter_file');
310
321
  } catch (e) {
311
- console.error('Failed to import adapter from $adapter_path');
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostajs/orm-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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
  }