@mostajs/setup 2.1.11 → 2.1.12

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/dist/index.js CHANGED
@@ -13,7 +13,7 @@ export { discoverNpmModules } from './lib/discover-modules.js';
13
13
  export { loadSetupJson } from './lib/load-setup-json.js';
14
14
  // Catch-all route factory (replaces individual route files in host app)
15
15
  export { createSetupRoutes } from './api/routes.js';
16
- // NET client (for setup via @mostajs/net)
16
+ // NET client (setup-specific, with loadCollectionMap + resolveCollection)
17
17
  export { NetClient } from './lib/net-client.js';
18
18
  // API route factories (individual — still available for granular use)
19
19
  export { createTestDbHandler } from './api/test-db.route.js';
package/dist/lib/setup.js CHANGED
@@ -137,14 +137,9 @@ async function runNetInstall(installConfig, setupConfig) {
137
137
  port: setupConfig.defaultPort,
138
138
  });
139
139
  const seeded = [];
140
- // 2. Verify NET server is reachable + load collection mapping
140
+ // 2. Verify NET server is reachable
141
141
  const health = await net.health();
142
- if (!health.entities?.length) {
143
- return { ok: false, error: 'Serveur NET accessible mais aucun schema chargé', needsRestart: false };
144
- }
145
- await net.loadCollectionMap();
146
- // 3. Seed RBAC via NET REST
147
- // Read setup.json directly to get RBAC definitions
142
+ // 3. Read setup.json for RBAC definitions
148
143
  const fs = await import('fs');
149
144
  const path = await import('path');
150
145
  let setupJson = null;
@@ -155,6 +150,48 @@ async function runNetInstall(installConfig, setupConfig) {
155
150
  }
156
151
  catch { }
157
152
  }
153
+ // 4. If server has no entities, try sending schemas via POST /api/upload-schemas-json
154
+ if (!health.entities?.length) {
155
+ let schemasToSend = [];
156
+ // Try schemas.json local
157
+ const schemasJsonPath = path.resolve(process.cwd(), 'schemas.json');
158
+ if (fs.existsSync(schemasJsonPath)) {
159
+ try {
160
+ schemasToSend = JSON.parse(fs.readFileSync(schemasJsonPath, 'utf-8'));
161
+ }
162
+ catch { }
163
+ }
164
+ // Fallback: ORM registry
165
+ if (schemasToSend.length === 0) {
166
+ try {
167
+ const { getAllSchemas } = await import('@mostajs/orm');
168
+ schemasToSend = getAllSchemas();
169
+ }
170
+ catch { }
171
+ }
172
+ if (schemasToSend.length > 0) {
173
+ // Send schemas to NET server so it can register + create tables
174
+ try {
175
+ const res = await fetch(`${installConfig.net.url}/api/upload-schemas-json`, {
176
+ method: 'POST',
177
+ headers: { 'Content-Type': 'application/json' },
178
+ body: JSON.stringify({ schemas: schemasToSend }),
179
+ });
180
+ const result = await res.json();
181
+ if (result.ok)
182
+ seeded.push(`schemas (${schemasToSend.length})`);
183
+ }
184
+ catch (e) {
185
+ console.error('[Setup] Failed to upload schemas to NET server:', e);
186
+ }
187
+ }
188
+ // Re-check
189
+ const health2 = await net.health();
190
+ if (!health2.entities?.length) {
191
+ return { ok: false, error: 'Serveur NET accessible mais aucun schema charge. Placez un schemas.json dans le repertoire du serveur NET et redemarrez-le.', needsRestart: false };
192
+ }
193
+ }
194
+ await net.loadCollectionMap();
158
195
  if (setupJson?.rbac) {
159
196
  const rbac = setupJson.rbac;
160
197
  // 3a. Upsert categories
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostajs/setup",
3
- "version": "2.1.11",
3
+ "version": "2.1.12",
4
4
  "description": "Reusable setup wizard module — multi-dialect DB configuration, .env.local writer, seed runner",
5
5
  "author": "Dr Hamid MADANI <drmdh@msn.com>",
6
6
  "license": "MIT",
@@ -104,7 +104,8 @@
104
104
  "prepublishOnly": "npm run build"
105
105
  },
106
106
  "dependencies": {
107
- "@mostajs/orm": "^1.4.15",
107
+ "@mostajs/net": "^2.0.0",
108
+ "@mostajs/orm": "^1.7.0",
108
109
  "bcryptjs": "^2.4.3"
109
110
  },
110
111
  "devDependencies": {