@domain-first/project-structure 2.15.0 → 2.15.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.
package/README.md CHANGED
@@ -347,8 +347,11 @@ which passes `restHandlers` from `<rootFolder>/presentation/rest` to
347
347
 
348
348
  `.env` is loaded because wiring imported through `restHandlers` may read the
349
349
  environment. Script conflicts and overwrite confirmation work as in the other
350
- integrations. After writing, the CLI prints `npm install --save-dev tsx` and
351
- `npm install @domain-first/handlers-rest` for missing packages. `restHandlers`
350
+ integrations. After writing, the CLI prints `npm install --save-dev tsx` when
351
+ `tsx` is missing. The script needs `@domain-first/handlers-rest` 7.0.2+, where
352
+ OpenAPI paths start with `/` without a leading empty prefix segment; when the
353
+ package is missing or older (the installed version is checked first, then the
354
+ declared range), the CLI prints `npm install @domain-first/handlers-rest@^7.0.2`. `restHandlers`
352
355
  are created with the first REST endpoint generated with `@domain-first/wire`;
353
356
  until then, the CLI reminds you about it. Run `npm run openapi` after adding or
354
357
  changing endpoints, then regenerate your API client, if you have one.
package/dist/index.cjs CHANGED
@@ -274,20 +274,30 @@ const apiTitle = (packageName)=>{
274
274
  const openapiGenerator = (rootFolder, title, routePrefix, outputPath)=>{
275
275
  const restFolder = external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/rest');
276
276
  const restImport = external_node_path_default().posix.relative(external_node_path_default().posix.dirname(openapiScriptPath), restFolder);
277
- const apiRoutePrefix = [
278
- '',
279
- ...splitPath(routePrefix)
280
- ].map((segment)=>`'${segment}'`).join(', ');
277
+ const prefixSegments = splitPath(routePrefix);
278
+ const apiRoutePrefix = prefixSegments.length ? `\n apiRoutePrefix: [${prefixSegments.map((segment)=>`'${segment}'`).join(', ')}],` : '';
281
279
  return `import { generateOpenAPI } from '@domain-first/handlers-rest';
282
280
  import { restHandlers } from '${restImport.startsWith('.') ? restImport : `./${restImport}`}';
283
281
 
284
282
  generateOpenAPI(restHandlers, {
285
- document: { info: { title: '${title}', version: '1.0.0' } },
286
- apiRoutePrefix: [${apiRoutePrefix}],
283
+ document: { info: { title: '${title}', version: '1.0.0' } },${apiRoutePrefix}
287
284
  outputFile: { path: '${outputPath}' }
288
285
  });
289
286
  `;
290
287
  };
288
+ const minimalHandlersRest = [
289
+ 7,
290
+ 0,
291
+ 2
292
+ ];
293
+ const parseVersion = (value)=>String(value ?? '').match(/(\d+)\.(\d+)\.(\d+)/)?.slice(1).map(Number);
294
+ const handlersRestUpToDate = (root, declared)=>{
295
+ const installed = new File(external_node_path_default().join(root, 'node_modules/@domain-first/handlers-rest/package.json'));
296
+ const version = parseVersion(installed.exists ? JSON.parse(installed.data).version : declared);
297
+ if (!version) return false;
298
+ for (const [index, part] of minimalHandlersRest.entries())if (version[index] !== part) return version[index] > part;
299
+ return true;
300
+ };
291
301
  const addOpenapi = async ()=>{
292
302
  const { rootFolder } = ConfigFile.Instance.data;
293
303
  const root = new ProjectRoot().path;
@@ -312,8 +322,8 @@ const addOpenapi = async ()=>{
312
322
  if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
313
323
  const hasRestHandlers = new File(external_node_path_default().join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
314
324
  return [
315
- ...dependencies['@domain-first/handlers-rest'] ? [] : [
316
- 'npm install @domain-first/handlers-rest'
325
+ ...handlersRestUpToDate(root, dependencies['@domain-first/handlers-rest']) ? [] : [
326
+ `npm install @domain-first/handlers-rest@^${minimalHandlersRest.join('.')}`
317
327
  ],
318
328
  ...dependencies.tsx ? [] : [
319
329
  'npm install --save-dev tsx'
package/dist/index.js CHANGED
@@ -244,20 +244,30 @@ const apiTitle = (packageName)=>{
244
244
  const openapiGenerator = (rootFolder, title, routePrefix, outputPath)=>{
245
245
  const restFolder = node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/rest');
246
246
  const restImport = node_path.posix.relative(node_path.posix.dirname(openapiScriptPath), restFolder);
247
- const apiRoutePrefix = [
248
- '',
249
- ...splitPath(routePrefix)
250
- ].map((segment)=>`'${segment}'`).join(', ');
247
+ const prefixSegments = splitPath(routePrefix);
248
+ const apiRoutePrefix = prefixSegments.length ? `\n apiRoutePrefix: [${prefixSegments.map((segment)=>`'${segment}'`).join(', ')}],` : '';
251
249
  return `import { generateOpenAPI } from '@domain-first/handlers-rest';
252
250
  import { restHandlers } from '${restImport.startsWith('.') ? restImport : `./${restImport}`}';
253
251
 
254
252
  generateOpenAPI(restHandlers, {
255
- document: { info: { title: '${title}', version: '1.0.0' } },
256
- apiRoutePrefix: [${apiRoutePrefix}],
253
+ document: { info: { title: '${title}', version: '1.0.0' } },${apiRoutePrefix}
257
254
  outputFile: { path: '${outputPath}' }
258
255
  });
259
256
  `;
260
257
  };
258
+ const minimalHandlersRest = [
259
+ 7,
260
+ 0,
261
+ 2
262
+ ];
263
+ const parseVersion = (value)=>String(value ?? '').match(/(\d+)\.(\d+)\.(\d+)/)?.slice(1).map(Number);
264
+ const handlersRestUpToDate = (root, declared)=>{
265
+ const installed = new File(node_path.join(root, 'node_modules/@domain-first/handlers-rest/package.json'));
266
+ const version = parseVersion(installed.exists ? JSON.parse(installed.data).version : declared);
267
+ if (!version) return false;
268
+ for (const [index, part] of minimalHandlersRest.entries())if (version[index] !== part) return version[index] > part;
269
+ return true;
270
+ };
261
271
  const addOpenapi = async ()=>{
262
272
  const { rootFolder } = ConfigFile.Instance.data;
263
273
  const root = new ProjectRoot().path;
@@ -282,8 +292,8 @@ const addOpenapi = async ()=>{
282
292
  if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
283
293
  const hasRestHandlers = new File(node_path.join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
284
294
  return [
285
- ...dependencies['@domain-first/handlers-rest'] ? [] : [
286
- 'npm install @domain-first/handlers-rest'
295
+ ...handlersRestUpToDate(root, dependencies['@domain-first/handlers-rest']) ? [] : [
296
+ `npm install @domain-first/handlers-rest@^${minimalHandlersRest.join('.')}`
287
297
  ],
288
298
  ...dependencies.tsx ? [] : [
289
299
  'npm install --save-dev tsx'
@@ -5,4 +5,9 @@ export declare const openapiScripts: {
5
5
  };
6
6
  export declare const apiTitle: (packageName: unknown) => string;
7
7
  export declare const openapiGenerator: (rootFolder: string, title: string, routePrefix: string, outputPath: string) => string;
8
+ /**
9
+ * The installed version wins over the declared range, which only gives
10
+ * the lowest version allowed.
11
+ */
12
+ export declare const handlersRestUpToDate: (root: string, declared: unknown) => boolean;
8
13
  export declare const addOpenapi: () => Promise<string[]>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@domain-first/project-structure",
3
3
  "description": "Build and manage your Domain-First project structure with CLI",
4
- "version": "2.15.0",
4
+ "version": "2.15.1",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",