@domain-first/project-structure 8.9.2 → 8.10.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/dist/561.js CHANGED
@@ -2,7 +2,7 @@ import node_fs from "node:fs";
2
2
  import node_path from "node:path";
3
3
  import { parseArgs } from "node:util";
4
4
  import zod from "zod";
5
- import { implementationLabelSchema, availableDependencies, discardPendingChanges, findWiredModules, filesToOverwrite, ConfigFile, Folder, implementationKinds, ProjectRoot, pendingChanges, hasNeighboringBoundedContext } from "./201.js";
5
+ import { implementationLabelSchema, availableDependencies, discardPendingChanges, findWiredModules, filesToOverwrite, ConfigFile, Folder, implementationKinds, ProjectRoot, pendingChanges, hasNeighboringBoundedContext, boundedContextNames } from "./201.js";
6
6
  import { scaffoldNewHandlersRestEndpoint, addIntegration, findContracts, helperImplementationTypes, scaffoldNewAggregateUseCase, scaffoldNewInfrastructureService, runWithAnswers, scaffoldNewCommand, scaffoldNewQuery, findReactModules, moveBackendUnitUseCase, scaffoldReactUIKitComponent, scaffoldReactSharedHook, moveReactModuleUseCase, reactKindTitles, deleteBackendUnitUseCase, integrationIds, scaffoldNewApplicationService, scaffoldNewImplementation, savedImplementations, RequestError, deleteReactModuleUseCase, rootControllerChoice, moduleId, assertAnswersConsumed, scaffoldNewDomainService, findRestEndpointGenerator, scaffoldNewErrorUseCase, scaffoldReactWidget, savePendingChanges, unitId, systemImplementationChoices, scaffoldReactPage, scaffoldNewPresentationService, scaffoldNewInfrastructureHelper, integrationSpecsAvailable, integrationSpecFile, findBackendUnits, scaffoldNewUseCase, integrationDescriptions, wireDependency, scaffoldNewDomainObject, scaffoldNewBoundedContextUseCase, scaffoldNewApplicationPort } from "./287.js";
7
7
  import { restControllers } from "./115.js";
8
8
  const agent_requests_name = implementationLabelSchema;
@@ -19,7 +19,7 @@ const common = {
19
19
  dryRun: zod.boolean().optional()
20
20
  };
21
21
  const agent_requests_owner = {
22
- context: agent_requests_name.describe('A bounded-context name, or shared-kernel.')
22
+ context: nestedName.describe('A bounded-context name (nested ones as paths, e.g. sales/orders), or shared-kernel.')
23
23
  };
24
24
  const wired = {
25
25
  dependencies: dependencies.optional()
@@ -41,7 +41,7 @@ const agent_requests_operation = (value, shape)=>zod.strictObject({
41
41
  const scaffoldRequestSchema = zod.discriminatedUnion('operation', [
42
42
  agent_requests_operation('bounded-context', {
43
43
  ...common,
44
- name: agent_requests_name.refine((value)=>'shared-kernel' !== value, 'shared-kernel is reserved for the Shared Kernel.')
44
+ name: nestedName.describe('Folders split by "/", e.g. sales/orders.').refine((value)=>'shared-kernel' !== value, 'shared-kernel is reserved for the Shared Kernel.')
45
45
  }),
46
46
  agent_requests_operation('aggregate', {
47
47
  ...named,
@@ -139,7 +139,7 @@ const scaffoldRequestSchema = zod.discriminatedUnion('operation', [
139
139
  ...common,
140
140
  ...agent_requests_owner,
141
141
  module: id.describe('Exact unit ID from --describe.'),
142
- targetContext: agent_requests_name.optional(),
142
+ targetContext: nestedName.optional(),
143
143
  name: agent_requests_name.optional(),
144
144
  aggregate: agent_requests_name.optional()
145
145
  })
@@ -252,13 +252,13 @@ const ownerFolders = (root)=>{
252
252
  'shared-kernel'
253
253
  ])
254
254
  },
255
- ...source.subitem([
255
+ ...boundedContextNames(source.subitem([
256
256
  'bounded-contexts'
257
- ]).content.subfolderNames.sort().map((name)=>({
257
+ ]).path).map((name)=>({
258
258
  name,
259
259
  folder: source.subitem([
260
260
  'bounded-contexts',
261
- name
261
+ ...name.split('/')
262
262
  ])
263
263
  }))
264
264
  ];
@@ -0,0 +1,33 @@
1
+ export declare const boundedContextsFolderName = "bounded-contexts";
2
+ /**
3
+ * Folders right in a bounded context. A context name can't use them as a
4
+ * segment: they tell a context from a folder grouping contexts.
5
+ */
6
+ export declare const contextLayerFolders: string[];
7
+ /**
8
+ * A bounded context has a layer folder or no folders yet; any other
9
+ * folder groups contexts, like the folders of React pages and widgets.
10
+ */
11
+ export declare const isBoundedContextFolder: (folder: string) => boolean;
12
+ /**
13
+ * Names of the bounded contexts in `<rootFolder>/bounded-contexts`,
14
+ * nested ones as paths (`sales/orders`), sorted.
15
+ */
16
+ export declare const boundedContextNames: (contextsFolder: string) => string[];
17
+ export declare const boundedContextPath: (contextsFolder: string, name: string) => string;
18
+ /** `sales/orders` → `SalesOrders`, for names shared across contexts. */
19
+ export declare const contextClassName: (name: string) => string;
20
+ /**
21
+ * The context of the path segments below `bounded-contexts`: up to the
22
+ * first layer folder. Without one, the first segment, as before nesting.
23
+ */
24
+ export declare const splitContextSegments: (segments: string[]) => {
25
+ name: string;
26
+ segments: string[];
27
+ };
28
+ /**
29
+ * Where a context of the given name could be created: names are checked
30
+ * like page names, segments can't be layer folders, and a context can't
31
+ * hold or be part of another context.
32
+ */
33
+ export declare const validateBoundedContextName: (contextsFolder: string, name: string) => string | true;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,12 +1,23 @@
1
1
  export declare const crossContextImplementation = "cross-context";
2
- /** Context folders follow the same directory layout as the CLI context menu. */
2
+ /**
3
+ * Whether another bounded context exists anywhere under `bounded-contexts`,
4
+ * nested ones included.
5
+ */
3
6
  export declare const hasNeighboringBoundedContext: (ownerPath: string) => boolean;
4
- /** A file inside a bounded context, including its project source root. */
7
+ /**
8
+ * A file inside a bounded context, including its project source root.
9
+ * A nested context is named by its path, e.g. `sales/orders`.
10
+ */
5
11
  export declare const boundedContextLocation: (file: string) => {
6
- root: string;
7
12
  name: string;
8
13
  segments: string[];
14
+ root: string;
9
15
  } | undefined;
16
+ /**
17
+ * The name of the context in the folder (`sales/orders` when nested), or
18
+ * undefined for the Shared Kernel.
19
+ */
20
+ export declare const boundedContextName: (folder: string) => string | undefined;
10
21
  /** The reserved implementation type, determined by its infrastructure folder. */
11
22
  export declare const isCrossContextImplementation: (file: string) => boolean;
12
23
  /**
package/dist/graph.cjs CHANGED
@@ -324,6 +324,36 @@ class ConfigFile {
324
324
  new file_system_File(ConfigFile.path).update(`${JSON.stringify(config, null, 4)}\n`);
325
325
  }
326
326
  }
327
+ const contextLayerFolders = [
328
+ 'domain',
329
+ 'application',
330
+ 'infrastructure',
331
+ 'presentation',
332
+ 'wiring'
333
+ ];
334
+ const subfolders = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
335
+ withFileTypes: true
336
+ }).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name) : [];
337
+ const isBoundedContextFolder = (folder)=>{
338
+ const names = subfolders(folder);
339
+ return !names.length || names.some((name)=>contextLayerFolders.includes(name));
340
+ };
341
+ const bounded_contexts_boundedContextNames = (contextsFolder)=>{
342
+ const walk = (folder, prefix)=>subfolders(folder).flatMap((name)=>{
343
+ const child = external_node_path_default().join(folder, name);
344
+ return isBoundedContextFolder(child) ? [
345
+ [
346
+ ...prefix,
347
+ name
348
+ ].join('/')
349
+ ] : walk(child, [
350
+ ...prefix,
351
+ name
352
+ ]);
353
+ });
354
+ return walk(contextsFolder, []).sort();
355
+ };
356
+ const bounded_contexts_boundedContextPath = (contextsFolder, name)=>external_node_path_default().join(contextsFolder, ...name.split('/'));
327
357
  const external_node_module_namespaceObject = require("node:module");
328
358
  const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
329
359
  const resolveExtends = (fromFile, target)=>{
@@ -358,7 +388,7 @@ const compilerOption = (configFile, name, seen = new Set())=>{
358
388
  if (void 0 !== value) return value;
359
389
  }
360
390
  };
361
- class unknown_format_naming_UnknownFormatNaming {
391
+ class UnknownFormatNaming {
362
392
  rawSource;
363
393
  camelCase;
364
394
  PascalCase;
@@ -453,7 +483,7 @@ const wiring_readWiredModule = (wireFile, contextPath)=>{
453
483
  const wiringRelativePath = external_node_path_default().relative(external_node_path_default().join(contextPath, 'wiring'), wireFile);
454
484
  if (isEndpointWire(wiringRelativePath)) return;
455
485
  const source = new file_system_File(wireFile).data;
456
- const wireName = `wire${new unknown_format_naming_UnknownFormatNaming(external_node_path_default().basename(wireFile, '.ts').replace(/^wire-/, '')).ClassName}`;
486
+ const wireName = `wire${new UnknownFormatNaming(external_node_path_default().basename(wireFile, '.ts').replace(/^wire-/, '')).ClassName}`;
457
487
  const exportMatch = new RegExp(`export\\s+const\\s+${wireName}\\s*=\\s*`).exec(source);
458
488
  if (!exportMatch) return;
459
489
  const branched = source.slice(exportMatch.index + exportMatch[0].length).startsWith('envBranchedWire(');
@@ -623,9 +653,7 @@ const resolveSpecifier = (specifier, fromFile, aliases)=>{
623
653
  for (const { prefix, wildcard, target } of aliases)if (wildcard ? specifier.startsWith(prefix) : specifier === prefix) return external_node_path_default().join(target, wildcard ? specifier.slice(prefix.length) : '');
624
654
  };
625
655
  const sharedKernel = 'shared-kernel';
626
- const contextsOf = (contextsFolder)=>external_node_fs_default().existsSync(contextsFolder) ? external_node_fs_default().readdirSync(contextsFolder, {
627
- withFileTypes: true
628
- }).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name).sort() : [];
656
+ const contextsOf = bounded_contexts_boundedContextNames;
629
657
  const projectGraph = (projectRoot, rootFolder)=>{
630
658
  const root = external_node_path_default().resolve(projectRoot, rootFolder);
631
659
  const contextsFolder = external_node_path_default().join(root, 'bounded-contexts');
@@ -633,7 +661,7 @@ const projectGraph = (projectRoot, rootFolder)=>{
633
661
  sharedKernel,
634
662
  ...contextsOf(contextsFolder)
635
663
  ];
636
- const ownerPath = (owner)=>owner === sharedKernel ? external_node_path_default().join(root, sharedKernel) : external_node_path_default().join(contextsFolder, owner);
664
+ const ownerPath = (owner)=>owner === sharedKernel ? external_node_path_default().join(root, sharedKernel) : bounded_contexts_boundedContextPath(contextsFolder, owner);
637
665
  const byWireFile = new Map();
638
666
  const wired = [];
639
667
  for (const owner of owners)for (const module of wiring_findWiredModules(ownerPath(owner))){
package/dist/graph.js CHANGED
@@ -4,12 +4,10 @@ import node_fs from "node:fs";
4
4
  import node_os from "node:os";
5
5
  import node_path from "node:path";
6
6
  import { parseArgs } from "node:util";
7
- import { namedImportFiles, wiring_layers, findWiredModules, outdatedConfigMessage, ConfigFile, File, ProjectRoot, wiredDependencyNames } from "./201.js";
7
+ import { namedImportFiles, wiring_layers, findWiredModules, ConfigFile, boundedContextPath, outdatedConfigMessage, File, ProjectRoot, wiredDependencyNames, boundedContextNames } from "./201.js";
8
8
  import { readAliases, resolveSpecifier } from "./38.js";
9
9
  const sharedKernel = 'shared-kernel';
10
- const contextsOf = (contextsFolder)=>node_fs.existsSync(contextsFolder) ? node_fs.readdirSync(contextsFolder, {
11
- withFileTypes: true
12
- }).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name).sort() : [];
10
+ const contextsOf = boundedContextNames;
13
11
  const projectGraph = (projectRoot, rootFolder)=>{
14
12
  const root = node_path.resolve(projectRoot, rootFolder);
15
13
  const contextsFolder = node_path.join(root, 'bounded-contexts');
@@ -17,7 +15,7 @@ const projectGraph = (projectRoot, rootFolder)=>{
17
15
  sharedKernel,
18
16
  ...contextsOf(contextsFolder)
19
17
  ];
20
- const ownerPath = (owner)=>owner === sharedKernel ? node_path.join(root, sharedKernel) : node_path.join(contextsFolder, owner);
18
+ const ownerPath = (owner)=>owner === sharedKernel ? node_path.join(root, sharedKernel) : boundedContextPath(contextsFolder, owner);
21
19
  const byWireFile = new Map();
22
20
  const wired = [];
23
21
  for (const owner of owners)for (const module of findWiredModules(ownerPath(owner))){