@domain-first/project-structure 8.9.1 → 8.10.0

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.
@@ -6,9 +6,17 @@ export declare const openapiExtractorPath = "scripts/extract-open-api-data-from-
6
6
  */
7
7
  export declare const legacyEndpointFileLookup: (rootFolder: string) => string;
8
8
  /**
9
- * A controller is the first folder of the route; any other route belongs
10
- * to the context-root controller in `presentation/rest/(root)/`. The
11
- * generator keeps the two apart, so at most one of the files exists.
9
+ * How 8.6 to 8.9 found the endpoint file, as scaffolded: the context is the first
10
+ * folder of the route, so nested contexts are missed. `df-upgrade`
11
+ * replaces it with `endpointFileLookup`.
12
+ */
13
+ export declare const rootEndpointFileLookup: (rootFolder: string) => string;
14
+ /**
15
+ * The context is a folder path at the start of the route, nested ones
16
+ * included (`/sales/orders/...`). A controller is the next folder; any
17
+ * other route belongs to the context-root controller in
18
+ * `presentation/rest/(root)/`. The generator keeps them apart, so at most
19
+ * one of the files exists.
12
20
  */
13
21
  export declare const endpointFileLookup: (rootFolder: string) => string;
14
22
  export declare const openapiExtractor: (rootFolder: string) => string;
@@ -2,9 +2,11 @@ export declare const openapiScriptPath = "scripts/generate-openapi.ts";
2
2
  export declare const defaultOpenapiPath: (withNext: boolean) => "public/openapi.json" | "openapi.json";
3
3
  export declare const swaggerPagePath: (rootFolder: string) => string;
4
4
  /**
5
- * A React page rendering the OpenAPI document with Swagger UI.
5
+ * A React page rendering the OpenAPI document with Swagger UI. With
6
+ * Next.js it is a client component: Swagger UI keeps state and its App
7
+ * Router route is a server component.
6
8
  */
7
- export declare const swaggerPage: (rootFolder: string, outputPath: string) => string;
9
+ export declare const swaggerPage: (rootFolder: string, outputPath: string, withNext?: boolean) => string;
8
10
  export declare const openapiScripts: {
9
11
  openapi: string;
10
12
  };
package/dist/lint.cjs CHANGED
@@ -348,15 +348,53 @@ class ConfigFile {
348
348
  }
349
349
  }
350
350
  const config_file_configuredDependencyRules = ()=>resolveDependencyRules(ConfigFile.exists ? ConfigFile.Instance.data.backend?.rules?.dependencies : void 0);
351
+ const bounded_contexts_boundedContextsFolderName = 'bounded-contexts';
352
+ const contextLayerFolders = [
353
+ 'domain',
354
+ 'application',
355
+ 'infrastructure',
356
+ 'presentation',
357
+ 'wiring'
358
+ ];
359
+ const subfolders = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
360
+ withFileTypes: true
361
+ }).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name) : [];
362
+ const isBoundedContextFolder = (folder)=>{
363
+ const names = subfolders(folder);
364
+ return !names.length || names.some((name)=>contextLayerFolders.includes(name));
365
+ };
366
+ const bounded_contexts_boundedContextNames = (contextsFolder)=>{
367
+ const walk = (folder, prefix)=>subfolders(folder).flatMap((name)=>{
368
+ const child = external_node_path_default().join(folder, name);
369
+ return isBoundedContextFolder(child) ? [
370
+ [
371
+ ...prefix,
372
+ name
373
+ ].join('/')
374
+ ] : walk(child, [
375
+ ...prefix,
376
+ name
377
+ ]);
378
+ });
379
+ return walk(contextsFolder, []).sort();
380
+ };
381
+ const boundedContextPath = (contextsFolder, name)=>external_node_path_default().join(contextsFolder, ...name.split('/'));
382
+ const splitContextSegments = (segments)=>{
383
+ const layer = segments.findIndex((segment)=>contextLayerFolders.includes(segment));
384
+ const length = layer > 0 ? layer : 1;
385
+ return {
386
+ name: segments.slice(0, length).join('/'),
387
+ segments: segments.slice(length)
388
+ };
389
+ };
351
390
  const crossContextImplementation = 'cross-context';
352
391
  const context_dependencies_boundedContextLocation = (file)=>{
353
392
  const parts = external_node_path_default().resolve(file).split(external_node_path_default().sep);
354
- const index = parts.lastIndexOf('bounded-contexts');
393
+ const index = parts.lastIndexOf(bounded_contexts_boundedContextsFolderName);
355
394
  if (-1 === index || parts.length < index + 3) return;
356
395
  return {
357
396
  root: parts.slice(0, index).join(external_node_path_default().sep),
358
- name: parts[index + 1],
359
- segments: parts.slice(index + 2)
397
+ ...splitContextSegments(parts.slice(index + 1))
360
398
  };
361
399
  };
362
400
  const isCrossContextImplementation = (file)=>{
@@ -419,7 +457,7 @@ const compilerOption = (configFile, name, seen = new Set())=>{
419
457
  if (void 0 !== value) return value;
420
458
  }
421
459
  };
422
- class unknown_format_naming_UnknownFormatNaming {
460
+ class UnknownFormatNaming {
423
461
  rawSource;
424
462
  camelCase;
425
463
  PascalCase;
@@ -532,7 +570,7 @@ const readWiredModule = (wireFile, contextPath)=>{
532
570
  const wiringRelativePath = external_node_path_default().relative(external_node_path_default().join(contextPath, 'wiring'), wireFile);
533
571
  if (isEndpointWire(wiringRelativePath)) return;
534
572
  const source = new file_system_File(wireFile).data;
535
- const wireName = `wire${new unknown_format_naming_UnknownFormatNaming(external_node_path_default().basename(wireFile, '.ts').replace(/^wire-/, '')).ClassName}`;
573
+ const wireName = `wire${new UnknownFormatNaming(external_node_path_default().basename(wireFile, '.ts').replace(/^wire-/, '')).ClassName}`;
536
574
  const exportMatch = new RegExp(`export\\s+const\\s+${wireName}\\s*=\\s*`).exec(source);
537
575
  if (!exportMatch) return;
538
576
  const branched = source.slice(exportMatch.index + exportMatch[0].length).startsWith('envBranchedWire(');
@@ -794,12 +832,16 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
794
832
  const inMemoryDbFile = external_node_path_default().join(sharedFolder, 'infrastructure', 'services', 'in-memory-db-infrastructure-service.ts');
795
833
  const aliases = readAliases(projectRoot);
796
834
  const violations = [];
835
+ const contextOf = (file)=>{
836
+ const segments = inside(contextsFolder, file);
837
+ return segments && splitContextSegments(segments).name;
838
+ };
797
839
  const locate = (file)=>{
798
840
  const inContext = inside(contextsFolder, file);
799
841
  if (inContext && inContext.length > 1) {
800
- const [owner, ...segments] = inContext;
842
+ const { name, segments } = splitContextSegments(inContext);
801
843
  return {
802
- owner,
844
+ owner: name,
803
845
  segments
804
846
  };
805
847
  }
@@ -838,8 +880,8 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
838
880
  line: 1,
839
881
  text: external_node_path_default().basename(file)
840
882
  });
841
- const ownContext = inside(contextsFolder, file)?.[0];
842
- const directWiring = ownContext && from?.segments[0] === 'wiring' && readWiredModule(file, external_node_path_default().join(contextsFolder, ownContext))?.implementations.some((implementation)=>isCrossContextImplementation(implementation.file));
883
+ const ownContext = contextOf(file);
884
+ const directWiring = ownContext && from?.segments[0] === 'wiring' && readWiredModule(file, boundedContextPath(contextsFolder, ownContext))?.implementations.some((implementation)=>isCrossContextImplementation(implementation.file));
843
885
  const report = (check, rule, imported)=>violations.push({
844
886
  check,
845
887
  rule,
@@ -851,7 +893,7 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
851
893
  const target = imported.target;
852
894
  if (!target) continue;
853
895
  const to = locate(target);
854
- const targetContext = inside(contextsFolder, target)?.[0];
896
+ const targetContext = contextOf(target);
855
897
  const crossContextAllowed = true === context_dependencies_crossContextImportAllowed(file, target) && (from?.segments[0] !== 'wiring' || directWiring);
856
898
  if (ownContext) {
857
899
  if (targetContext && targetContext !== ownContext && !crossContextAllowed) report('context-isolation', `[${ownContext}] imports another context:`, imported);
@@ -900,12 +942,10 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
900
942
  name: 'shared-kernel',
901
943
  modules: sharedModules
902
944
  },
903
- ...external_node_fs_default().existsSync(contextsFolder) ? external_node_fs_default().readdirSync(contextsFolder, {
904
- withFileTypes: true
905
- }).filter((entry)=>entry.isDirectory()).map((entry)=>({
906
- name: entry.name,
907
- modules: findWiredModules(external_node_path_default().join(contextsFolder, entry.name))
908
- })) : []
945
+ ...bounded_contexts_boundedContextNames(contextsFolder).map((name)=>({
946
+ name,
947
+ modules: findWiredModules(boundedContextPath(contextsFolder, name))
948
+ }))
909
949
  ];
910
950
  const violations = [];
911
951
  const allModules = new Map(owners.flatMap(({ modules })=>modules).map((module)=>[
@@ -966,7 +1006,7 @@ const directReadViolations = (projectRoot, rootFolder)=>{
966
1006
  const root = external_node_path_default().resolve(projectRoot, rootFolder);
967
1007
  const folders = [
968
1008
  external_node_path_default().join(root, 'shared-kernel'),
969
- ...external_node_fs_default().existsSync(external_node_path_default().join(root, 'bounded-contexts')) ? external_node_fs_default().readdirSync(external_node_path_default().join(root, 'bounded-contexts')).map((name)=>external_node_path_default().join(root, 'bounded-contexts', name)) : []
1009
+ ...bounded_contexts_boundedContextNames(external_node_path_default().join(root, 'bounded-contexts')).map((name)=>boundedContextPath(external_node_path_default().join(root, 'bounded-contexts'), name))
970
1010
  ].flatMap((folder)=>[
971
1011
  external_node_path_default().join(folder, 'domain'),
972
1012
  external_node_path_default().join(folder, 'application')