@domain-first/project-structure 8.3.0 → 8.5.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.
package/README.md CHANGED
@@ -88,7 +88,8 @@ All settings and saved implementation types live in `domain-first.project-struct
88
88
  "layers": true,
89
89
  "dependencies": true,
90
90
  "react": true,
91
- "clock": true
91
+ "clock": true,
92
+ "config": true
92
93
  }
93
94
  }
94
95
  },
@@ -269,7 +270,7 @@ admin/panel/users → pages/admin/panel/admin-panel-users-page.tsx (AdminPane
269
270
 
270
271
  With Next.js, a new page also gets its App Router route, `app/admin/panel/users/page.tsx`, which renders `AdminPanelUsersPage`. An existing route is never overwritten.
271
272
 
272
- **Move or rename page** and **Move or rename widget** move the files and update every import in the project. **Delete page** and **Delete widget** remove them once nothing imports them, a Next.js page's own route included if you say so. With Next.js, moving a page also offers to move its route, `app/admin/users/` → `app/backoffice/users/`, since its URL changes with it.
273
+ **Move or rename page** and **Move or rename widget** move the files and update every import in the project. **Delete page** and **Delete widget** remove them once nothing imports them, a Next.js page's own route included if you say so. UI-kit components and shared hooks can be moved, renamed and deleted the same way. With Next.js, moving a page also offers to move its route, `app/admin/users/` → `app/backoffice/users/`, since its URL changes with it.
273
274
 
274
275
  ### How to add tooling
275
276
 
@@ -283,13 +284,13 @@ The endpoint generator and the in-memory DB are what `df-init` scaffolds; as int
283
284
  npx df-lint
284
285
  ```
285
286
 
286
- It reports what breaks the Domain-First rules: forbidden imports between bounded contexts, imports against the layers, modules using kinds the dependency rules don't allow (in imports and in wiring), React modules importing what they shouldn't, and reading the time without the clock port. It exits with 1 when something is found, so you can run it in CI.
287
+ It reports what breaks the Domain-First rules: forbidden imports between bounded contexts, imports against the layers, modules using kinds the dependency rules don't allow (in imports and in wiring), React modules importing what they shouldn't, and reading the time or environment variables without the clock and config ports. It exits with 1 when something is found, so you can run it in CI.
287
288
 
288
289
  `df-init` scaffolds all standard rules into `backend.rules` during backend setup. Teams can edit these entries directly: what each kind of module may depend on (`backend.rules.dependencies`) and which checks run (`backend.rules.lint`). `df-scaffold` offers dependencies by the same rules. For older or manually shortened configs without `backend.rules`, the defaults apply and every check runs; kinds and checks you don't mention keep their defaults.
289
290
 
290
291
  - Kinds in `backend.rules.dependencies` (as keys and in lists): `repositories`, `domain-services`, `application-ports`, `application-services`, `use-cases`, `commands`, `queries`, `infrastructure-services`, `presentation-services`.
291
292
  - A kind's value: a list that replaces its defaults, or `{ "add": [...], "remove": [...] }`.
292
- - Checks in `backend.rules.lint`: `context-isolation`, `shared-kernel`, `layers`, `dependencies`, `react`, `clock`.
293
+ - Checks in `backend.rules.lint`: `context-isolation`, `shared-kernel`, `layers`, `dependencies`, `react`, `clock`, `config`.
293
294
 
294
295
  Defaults and details: [Dependency rules](API.md#dependency-rules), [`df-lint`](API.md#df-lint).
295
296
 
package/dist/287.js CHANGED
@@ -2853,6 +2853,66 @@ const inMemoryRepositoryWiring = (ownerFolder, unit, wireFile)=>(implementation,
2853
2853
  wireInMemoryDb(wireFile, implementation.className);
2854
2854
  return true;
2855
2855
  };
2856
+ const reactKindLayouts = {
2857
+ page: {
2858
+ folder: 'pages',
2859
+ nested: true,
2860
+ inFolder: false,
2861
+ ownFile: (fileBase)=>new RegExp(`^${escapeRegExp(fileBase)}-page(?:\\.|$)`),
2862
+ target: (reactFolder, { folders, fileName })=>node_path.join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`),
2863
+ classPrefix: '(use)?',
2864
+ classSuffix: 'Page'
2865
+ },
2866
+ widget: {
2867
+ folder: 'widgets',
2868
+ nested: true,
2869
+ inFolder: true,
2870
+ target: (reactFolder, { folders, folderName })=>node_path.join(reactFolder, 'widgets', ...folders, folderName),
2871
+ classPrefix: '(use)?',
2872
+ classSuffix: 'Widget|UIModel',
2873
+ storyTitle: (segments)=>[
2874
+ 'Widgets',
2875
+ ...segments
2876
+ ].join('/')
2877
+ },
2878
+ 'ui-kit': {
2879
+ folder: 'ui-kit',
2880
+ nested: false,
2881
+ inFolder: true,
2882
+ target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'ui-kit', fileName),
2883
+ classPrefix: '()',
2884
+ classSuffix: 'Props(?![\\w$])|(?![\\w$])',
2885
+ storyTitle: (segments)=>`UI-kit/${segments.join('')}`
2886
+ },
2887
+ hook: {
2888
+ folder: 'hooks',
2889
+ nested: false,
2890
+ inFolder: false,
2891
+ ownFile: (fileBase)=>new RegExp(`^use-${escapeRegExp(fileBase)}(?:\\.|$)`),
2892
+ target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'hooks', `use-${fileName}.ts`),
2893
+ classPrefix: '(use)',
2894
+ classSuffix: '(?![\\w$])'
2895
+ }
2896
+ };
2897
+ const reactKindTitles = {
2898
+ page: [
2899
+ 'Page',
2900
+ 'pages'
2901
+ ],
2902
+ widget: [
2903
+ 'Widget',
2904
+ 'widgets'
2905
+ ],
2906
+ 'ui-kit': [
2907
+ 'UI-kit component',
2908
+ 'UI-kit components'
2909
+ ],
2910
+ hook: [
2911
+ 'Shared hook',
2912
+ 'shared hooks'
2913
+ ]
2914
+ };
2915
+ const reactModuleName = (kind, rawName)=>'hook' === kind ? rawName.trim().replace(/^use-/, '') : rawName;
2856
2916
  const react_module_move_nestedName = (folders, fileBase)=>{
2857
2917
  const prefix = `${folders.join('-')}-`;
2858
2918
  const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
@@ -2866,8 +2926,36 @@ const declaredClassName = (filePath, suffix, name)=>{
2866
2926
  const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
2867
2927
  return declared ?? new NestedName(name).ClassName;
2868
2928
  };
2929
+ const findUiKit = (reactFolder)=>{
2930
+ const root = node_path.join(reactFolder, 'ui-kit');
2931
+ if (!node_fs.existsSync(root)) return [];
2932
+ return node_fs.readdirSync(root, {
2933
+ withFileTypes: true
2934
+ }).filter((entry)=>entry.isDirectory() && node_fs.existsSync(node_path.join(root, entry.name, `${entry.name}.tsx`))).map(({ name })=>({
2935
+ kind: 'ui-kit',
2936
+ name,
2937
+ path: node_path.join(root, name),
2938
+ fileBase: name,
2939
+ ClassName: declaredClassName(node_path.join(root, name, `${name}.tsx`), '', name)
2940
+ }));
2941
+ };
2942
+ const findHooks = (reactFolder)=>{
2943
+ const root = node_path.join(reactFolder, 'hooks');
2944
+ if (!node_fs.existsSync(root)) return [];
2945
+ return node_fs.readdirSync(root).filter((file)=>/^use-.+\.tsx?$/.test(file) && !/\.(spec|test)\./.test(file)).map((file)=>{
2946
+ const name = file.replace(/^use-/, '').replace(/\.tsx?$/, '');
2947
+ const content = node_fs.readFileSync(node_path.join(root, file), 'utf8');
2948
+ return {
2949
+ kind: 'hook',
2950
+ name,
2951
+ path: node_path.join(root, file),
2952
+ fileBase: name,
2953
+ ClassName: content.match(/export\s+(?:const|function)\s+use(\w+)\b/)?.[1] ?? new NestedName(name).ClassName
2954
+ };
2955
+ });
2956
+ };
2869
2957
  const findReactModules = (reactFolder, kind)=>{
2870
- const modules = 'page' === kind ? walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
2958
+ const modules = 'ui-kit' === kind ? findUiKit(reactFolder) : 'hook' === kind ? findHooks(reactFolder) : 'page' === kind ? walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
2871
2959
  const folders = node_path.relative(node_path.join(reactFolder, 'pages'), node_path.dirname(file)).split(node_path.sep).filter((segment)=>!!segment);
2872
2960
  const fileBase = node_path.basename(file, '-page.tsx');
2873
2961
  const name = react_module_move_nestedName(folders, fileBase);
@@ -2891,13 +2979,11 @@ const findReactModules = (reactFolder, kind)=>{
2891
2979
  });
2892
2980
  return modules.sort((a, b)=>a.name.localeCompare(b.name));
2893
2981
  };
2894
- const targetPath = (reactFolder, module, rawName)=>{
2895
- const { folders, folderName, fileName } = new NestedName(rawName);
2896
- return 'page' === module.kind ? node_path.join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`) : node_path.join(reactFolder, 'widgets', ...folders, folderName);
2897
- };
2982
+ const targetPath = (reactFolder, module, rawName)=>reactKindLayouts[module.kind].target(reactFolder, new NestedName(reactModuleName(module.kind, rawName)));
2898
2983
  const validateMove = (reactFolder, module, rawName)=>{
2899
2984
  const nameError = NestedName.validate(rawName);
2900
2985
  if (true !== nameError) return nameError;
2986
+ if (!reactKindLayouts[module.kind].nested && /[\\/]/.test(rawName)) return 'UI-kit components and shared hooks have no folders: enter a name without "/"';
2901
2987
  const target = targetPath(reactFolder, module, rawName);
2902
2988
  if (target !== module.path && node_fs.existsSync(target)) return `${node_path.relative(reactFolder, target)} already exists`;
2903
2989
  if (target.startsWith(`${module.path}${node_path.sep}`)) return 'A widget cannot be moved into itself';
@@ -2911,13 +2997,14 @@ const routeFiles = (folder)=>node_fs.existsSync(folder) ? node_fs.readdirSync(fo
2911
2997
  withFileTypes: true
2912
2998
  }).filter((entry)=>entry.isFile()).map((entry)=>node_path.join(folder, entry.name)) : [];
2913
2999
  const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
2914
- const newName = new NestedName(rawName);
3000
+ const layout = reactKindLayouts[module.kind];
3001
+ const newName = new NestedName(reactModuleName(module.kind, rawName));
2915
3002
  const target = targetPath(reactFolder, module, rawName);
2916
3003
  const newClassName = newName.ClassName;
2917
- const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.])`), (_, use = '')=>`${use}${newName.fileName}`);
2918
- const oldFolder = 'page' === module.kind ? node_path.dirname(module.path) : module.path;
2919
- const newFolder = 'page' === module.kind ? node_path.dirname(target) : target;
2920
- const ownsPath = (candidate)=>'page' === module.kind ? node_path.dirname(candidate) === oldFolder && new RegExp(`^${escapeRegExp(module.fileBase)}-page(?:\\.|$)`).test(node_path.basename(candidate)) : candidate === oldFolder || candidate.startsWith(`${oldFolder}${node_path.sep}`);
3004
+ const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.]|$)`), (_, use = '')=>`${use}${newName.fileName}`);
3005
+ const oldFolder = layout.inFolder ? module.path : node_path.dirname(module.path);
3006
+ const newFolder = layout.inFolder ? target : node_path.dirname(target);
3007
+ const ownsPath = (candidate)=>layout.inFolder ? candidate === oldFolder || candidate.startsWith(`${oldFolder}${node_path.sep}`) : node_path.dirname(candidate) === oldFolder && layout.ownFile(module.fileBase).test(node_path.basename(candidate));
2921
3008
  const routeFileSet = new Set(route ? routeFiles(route.from) : []);
2922
3009
  const routeTarget = (candidate)=>{
2923
3010
  if (!route) return;
@@ -2937,7 +3024,7 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
2937
3024
  segments[last] = renameFile(segments[last]);
2938
3025
  return node_path.join(newFolder, ...segments);
2939
3026
  };
2940
- const moduleFiles = 'page' === module.kind ? node_fs.readdirSync(oldFolder).map((name)=>node_path.join(oldFolder, name)).filter((file)=>node_fs.statSync(file).isFile() && ownsPath(file)) : walk(oldFolder);
3027
+ const moduleFiles = reactModuleFiles(module);
2941
3028
  const moves = new Map([
2942
3029
  ...moduleFiles,
2943
3030
  ...routeFileSet
@@ -2945,14 +3032,14 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
2945
3032
  file,
2946
3033
  movedPath(file) ?? file
2947
3034
  ]));
2948
- const suffixes = 'page' === module.kind ? 'Page' : 'Widget|UIModel';
2949
- const classPattern = new RegExp(`(?<![\\w$])(use)?${escapeRegExp(module.ClassName)}(?=${suffixes})`, 'g');
2950
- const oldTitle = `Widgets/${module.name.split('/').map((segment)=>new NestedName(segment).ClassName).join('/')}`;
2951
- const titlePattern = new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
2952
- const newTitle = [
2953
- 'Widgets',
2954
- ...newName.classNameSegments
2955
- ].join('/');
3035
+ const classPattern = new RegExp(`(?<![\\w$])${layout.classPrefix}${escapeRegExp(module.ClassName)}(?=${layout.classSuffix})`, 'g');
3036
+ const oldTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
3037
+ module.ClassName
3038
+ ] : module.name.split('/').map((segment)=>new NestedName(segment).ClassName));
3039
+ const titlePattern = oldTitle && new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
3040
+ const newTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
3041
+ newClassName
3042
+ ] : newName.classNameSegments);
2956
3043
  return stageModuleMove({
2957
3044
  projectRoot,
2958
3045
  stopAt: reactFolder,
@@ -2960,8 +3047,8 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
2960
3047
  moves,
2961
3048
  movedPath,
2962
3049
  rename: (content, { moved })=>{
2963
- const renamed = content.replace(classPattern, (_, use = '')=>`${use}${newClassName}`);
2964
- return moved && 'widget' === module.kind ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
3050
+ const renamed = content.replace(classPattern, (_, use)=>`${use ?? ''}${newClassName}`);
3051
+ return moved && titlePattern ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
2965
3052
  }
2966
3053
  });
2967
3054
  };
@@ -2971,9 +3058,10 @@ const pageRouteFolder = (appFolder, page)=>{
2971
3058
  return node_fs.existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(node_fs.readFileSync(routePage, 'utf8')) ? folder : void 0;
2972
3059
  };
2973
3060
  const reactModuleFiles = (module)=>{
2974
- if ('widget' === module.kind) return walk(module.path);
3061
+ const layout = reactKindLayouts[module.kind];
3062
+ if (layout.inFolder) return walk(module.path);
2975
3063
  const folder = node_path.dirname(module.path);
2976
- const own = new RegExp(`^${escapeRegExp(module.fileBase)}-page(?:\\.|$)`);
3064
+ const own = layout.ownFile(module.fileBase);
2977
3065
  return node_fs.readdirSync(folder, {
2978
3066
  withFileTypes: true
2979
3067
  }).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>node_path.join(folder, entry.name));
@@ -2987,7 +3075,7 @@ const deleteReactModule = (projectRoot, reactFolder, module, route)=>{
2987
3075
  ...routeFileList
2988
3076
  ]);
2989
3077
  const stems = new Set(moduleFiles.map((file)=>file.replace(codeExtension, '')));
2990
- const isModule = (resolved)=>stems.has(resolved) || 'widget' === module.kind && (resolved === module.path || resolved.startsWith(`${module.path}${node_path.sep}`));
3078
+ const isModule = (resolved)=>stems.has(resolved) || reactKindLayouts[module.kind].inFolder && (resolved === module.path || resolved.startsWith(`${module.path}${node_path.sep}`));
2991
3079
  const { codeFiles, resolve } = projectImports(projectRoot);
2992
3080
  const relative = (file)=>toPosix(node_path.relative(projectRoot, file));
2993
3081
  const usedBy = [];
@@ -3078,11 +3166,11 @@ const deleteBackendUnitUseCase = async (ownerFolder)=>{
3078
3166
  const deleteReactModuleUseCase = async (presentationReactFolder, kind)=>{
3079
3167
  const reactFolder = presentationReactFolder.path;
3080
3168
  const modules = findReactModules(reactFolder, kind);
3081
- if (!modules.length) return void report(`No ${kind}s generated by df-react were found.`);
3169
+ if (!modules.length) return void report(`No ${reactKindTitles[kind][1]} generated by df-react were found.`);
3082
3170
  const module = await interaction_select({
3083
3171
  key: 'module',
3084
3172
  id: (value)=>value.name,
3085
- message: 'page' === kind ? 'Page to delete:' : 'Widget to delete:',
3173
+ message: `${reactKindTitles[kind][0]} to delete:`,
3086
3174
  choices: modules.map((value)=>({
3087
3175
  name: value.name,
3088
3176
  value,
@@ -3524,11 +3612,11 @@ const promptRouteMove = async (root, page, newName)=>{
3524
3612
  const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
3525
3613
  const reactFolder = presentationReactFolder.path;
3526
3614
  const modules = findReactModules(reactFolder, kind);
3527
- if (!modules.length) return void report(`No ${kind}s generated by df-react were found.`);
3615
+ if (!modules.length) return void report(`No ${reactKindTitles[kind][1]} generated by df-react were found.`);
3528
3616
  const module = await interaction_select({
3529
3617
  key: 'module',
3530
3618
  id: (value)=>value.name,
3531
- message: 'page' === kind ? 'Page:' : 'Widget:',
3619
+ message: `${reactKindTitles[kind][0]}:`,
3532
3620
  choices: modules.map((value)=>({
3533
3621
  name: value.name,
3534
3622
  value,
@@ -3537,7 +3625,7 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
3537
3625
  });
3538
3626
  const name = await interaction_input({
3539
3627
  key: 'name',
3540
- message: 'New name (folders split by "/"):',
3628
+ message: reactKindLayouts[kind].nested ? 'New name (folders split by "/"):' : 'New name:',
3541
3629
  default: module.name,
3542
3630
  validate: (value)=>validateMove(reactFolder, module, value)
3543
3631
  });
@@ -4794,4 +4882,4 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
4794
4882
  break;
4795
4883
  }
4796
4884
  };
4797
- export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, deleteBackendUnitUseCase, deleteReactModuleUseCase, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, initializeUseCase, integrationDescriptions, integrationIds, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
4885
+ export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, deleteBackendUnitUseCase, deleteReactModuleUseCase, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, initializeUseCase, integrationDescriptions, integrationIds, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, reactKindTitles, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
package/dist/38.js CHANGED
@@ -225,7 +225,19 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
225
225
  }
226
226
  return violations;
227
227
  };
228
- const clockViolations = (projectRoot, rootFolder)=>{
228
+ const directReadChecks = [
229
+ {
230
+ check: 'clock',
231
+ pattern: /\bnew\s+Date\s*\(\s*\)|\bDate\.now\s*\(/g,
232
+ rule: 'domain or application reads the current time directly (use the clock port):'
233
+ },
234
+ {
235
+ check: 'config',
236
+ pattern: /\bprocess\s*\??\.\s*env\b|\bprocess\s*\[\s*(['"`])env\1\s*\]|\bimport\.meta\.env\b/g,
237
+ rule: 'domain or application reads environment variables directly (use the config port):'
238
+ }
239
+ ];
240
+ const directReadViolations = (projectRoot, rootFolder)=>{
229
241
  const root = node_path.resolve(projectRoot, rootFolder);
230
242
  const folders = [
231
243
  node_path.join(root, 'shared-kernel'),
@@ -236,21 +248,21 @@ const clockViolations = (projectRoot, rootFolder)=>{
236
248
  ]);
237
249
  return folders.flatMap(sourceFiles).filter((file)=>!isSpec(file)).flatMap((file)=>{
238
250
  const source = node_fs.readFileSync(file, 'utf8');
239
- return [
240
- ...source.matchAll(/\bnew\s+Date\s*\(\s*\)|\bDate\.now\s*\(/g)
241
- ].map((match)=>({
242
- check: 'clock',
243
- rule: 'domain or application reads the current time directly (use the clock port):',
244
- file,
245
- line: lineAt(source, match.index),
246
- text: match[0]
247
- }));
251
+ return directReadChecks.flatMap(({ check, pattern, rule })=>[
252
+ ...source.matchAll(pattern)
253
+ ].map((match)=>({
254
+ check,
255
+ rule,
256
+ file,
257
+ line: lineAt(source, match.index),
258
+ text: match[0]
259
+ })));
248
260
  });
249
261
  };
250
262
  const lintProject = (projectRoot, rootFolder, { rules = defaultDependencyRules, checks = {} } = {})=>[
251
263
  ...importViolations(projectRoot, rootFolder, rules),
252
264
  ...wiringViolations(projectRoot, rootFolder, rules),
253
- ...clockViolations(projectRoot, rootFolder)
265
+ ...directReadViolations(projectRoot, rootFolder)
254
266
  ].filter((x)=>false !== checks[x.check]);
255
267
  const formatViolations = (violations, projectRoot)=>{
256
268
  const groups = new Map();
package/dist/561.js CHANGED
@@ -3,7 +3,7 @@ import node_path from "node:path";
3
3
  import { parseArgs } from "node:util";
4
4
  import zod from "zod";
5
5
  import { implementationLabelSchema, discardPendingChanges, filesToOverwrite, ConfigFile, Folder, implementationKinds, ProjectRoot, pendingChanges } from "./870.js";
6
- import { scaffoldNewHandlersRestEndpoint, addIntegration, findContracts, scaffoldNewAggregateUseCase, scaffoldNewInfrastructureService, scaffoldNewQuery, runWithAnswers, scaffoldNewCommand, moveBackendUnitUseCase, findReactModules, scaffoldReactUIKitComponent, scaffoldReactSharedHook, moveReactModuleUseCase, deleteBackendUnitUseCase, integrationIds, scaffoldNewImplementation, scaffoldNewApplicationService, savedImplementations, RequestError, deleteReactModuleUseCase, moduleId, assertAnswersConsumed, scaffoldNewDomainService, findRestEndpointGenerator, scaffoldNewErrorUseCase, scaffoldReactWidget, savePendingChanges, systemImplementationChoices, unitId, scaffoldReactPage, scaffoldNewPresentationService, findBackendUnits, scaffoldNewUseCase, integrationDescriptions, wireDependency, scaffoldNewDomainObject, scaffoldNewBoundedContextUseCase, scaffoldNewApplicationPort } from "./287.js";
6
+ import { scaffoldNewHandlersRestEndpoint, addIntegration, findContracts, scaffoldNewAggregateUseCase, scaffoldNewInfrastructureService, scaffoldNewQuery, runWithAnswers, scaffoldNewCommand, moveBackendUnitUseCase, findReactModules, scaffoldReactUIKitComponent, scaffoldReactSharedHook, moveReactModuleUseCase, reactKindTitles, deleteBackendUnitUseCase, integrationIds, scaffoldNewImplementation, scaffoldNewApplicationService, savedImplementations, RequestError, deleteReactModuleUseCase, moduleId, assertAnswersConsumed, scaffoldNewDomainService, findRestEndpointGenerator, scaffoldNewErrorUseCase, scaffoldReactWidget, savePendingChanges, unitId, systemImplementationChoices, scaffoldReactPage, scaffoldNewPresentationService, findBackendUnits, scaffoldNewUseCase, integrationDescriptions, wireDependency, scaffoldNewDomainObject, scaffoldNewBoundedContextUseCase, scaffoldNewApplicationPort } from "./287.js";
7
7
  import { findWiredModules, availableDependencies, hasNeighboringBoundedContext } from "./201.js";
8
8
  const agent_requests_name = implementationLabelSchema;
9
9
  const nestedName = zod.string().regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*(?:\/[a-z][a-z0-9]*(?:-[a-z0-9]+)*)*$/);
@@ -33,68 +33,68 @@ const named = {
33
33
  ...agent_requests_owner,
34
34
  name: agent_requests_name
35
35
  };
36
- const operation = (value, shape)=>zod.strictObject({
36
+ const agent_requests_operation = (value, shape)=>zod.strictObject({
37
37
  operation: zod.literal(value),
38
38
  ...shape
39
39
  });
40
40
  const scaffoldRequestSchema = zod.discriminatedUnion('operation', [
41
- operation('bounded-context', {
41
+ agent_requests_operation('bounded-context', {
42
42
  ...common,
43
43
  name: agent_requests_name.refine((value)=>'shared-kernel' !== value, 'shared-kernel is reserved for the Shared Kernel.')
44
44
  }),
45
- operation('aggregate', {
45
+ agent_requests_operation('aggregate', {
46
46
  ...named,
47
47
  withRepository: zod.boolean().optional(),
48
48
  implementation: agent_requests_implementation.optional(),
49
49
  testImplementation: agent_requests_implementation.optional(),
50
50
  ...wired
51
51
  }),
52
- operation('entity', {
52
+ agent_requests_operation('entity', {
53
53
  ...named,
54
54
  aggregate: agent_requests_name.optional()
55
55
  }),
56
- operation('value-object', {
56
+ agent_requests_operation('value-object', {
57
57
  ...named,
58
58
  aggregate: agent_requests_name.optional()
59
59
  }),
60
- operation('error', {
60
+ agent_requests_operation('error', {
61
61
  ...named,
62
62
  namespace: agent_requests_name.optional()
63
63
  }),
64
- operation('error-namespace', named),
65
- operation('domain-service', {
64
+ agent_requests_operation('error-namespace', named),
65
+ agent_requests_operation('domain-service', {
66
66
  ...named,
67
67
  ...wired
68
68
  }),
69
- operation('application-service', {
69
+ agent_requests_operation('application-service', {
70
70
  ...named,
71
71
  ...wired
72
72
  }),
73
- operation('infrastructure-service', {
73
+ agent_requests_operation('infrastructure-service', {
74
74
  ...named,
75
75
  ...wired
76
76
  }),
77
- operation('presentation-service', {
77
+ agent_requests_operation('presentation-service', {
78
78
  ...named,
79
79
  ...wired
80
80
  }),
81
- operation('use-case', {
81
+ agent_requests_operation('use-case', {
82
82
  ...named,
83
83
  ...wired
84
84
  }),
85
- operation('command', {
85
+ agent_requests_operation('command', {
86
86
  ...named,
87
87
  ...implementations
88
88
  }),
89
- operation('query', {
89
+ agent_requests_operation('query', {
90
90
  ...named,
91
91
  ...implementations
92
92
  }),
93
- operation('port', {
93
+ agent_requests_operation('port', {
94
94
  ...named,
95
95
  ...implementations
96
96
  }),
97
- operation('implementation', {
97
+ agent_requests_operation('implementation', {
98
98
  ...common,
99
99
  ...agent_requests_owner,
100
100
  contract: id.describe('Exact contract ID from --describe.'),
@@ -102,7 +102,7 @@ const scaffoldRequestSchema = zod.discriminatedUnion('operation', [
102
102
  environments: zod.array(agent_requests_name).min(1).optional().describe('Required when the contract wire is envBranchedWire; omit it otherwise.'),
103
103
  ...wired
104
104
  }),
105
- operation('endpoint', {
105
+ agent_requests_operation('endpoint', {
106
106
  ...common,
107
107
  ...agent_requests_owner,
108
108
  controller: agent_requests_name,
@@ -116,18 +116,18 @@ const scaffoldRequestSchema = zod.discriminatedUnion('operation', [
116
116
  path: zod.string().regex(/^(?:\/?(?:[a-zA-Z0-9_-]+|:[a-zA-Z][a-zA-Z0-9_]*))*\/?$/),
117
117
  handler: id.optional().describe('Exact handler module ID from --describe. Required when the context has wired queries, commands or use cases; omit it otherwise.')
118
118
  }),
119
- operation('wire-dependency', {
119
+ agent_requests_operation('wire-dependency', {
120
120
  ...common,
121
121
  ...agent_requests_owner,
122
122
  module: id.describe('Exact wiring target ID, including implementation class, from --describe.'),
123
123
  dependencies: dependencies
124
124
  }),
125
- operation('delete', {
125
+ agent_requests_operation('delete', {
126
126
  ...common,
127
127
  ...agent_requests_owner,
128
128
  module: id.describe('Exact unit ID from --describe. Refused while other files use it.')
129
129
  }),
130
- operation('move', {
130
+ agent_requests_operation('move', {
131
131
  ...common,
132
132
  ...agent_requests_owner,
133
133
  module: id.describe('Exact unit ID from --describe.'),
@@ -137,11 +137,11 @@ const scaffoldRequestSchema = zod.discriminatedUnion('operation', [
137
137
  })
138
138
  ]);
139
139
  const reactRequestSchema = zod.discriminatedUnion('operation', [
140
- operation('page', {
140
+ agent_requests_operation('page', {
141
141
  ...common,
142
142
  name: nestedName
143
143
  }),
144
- operation('widget', {
144
+ agent_requests_operation('widget', {
145
145
  ...common,
146
146
  name: nestedName,
147
147
  widgetType: zod["enum"]([
@@ -150,37 +150,55 @@ const reactRequestSchema = zod.discriminatedUnion('operation', [
150
150
  'headless'
151
151
  ]).optional()
152
152
  }),
153
- operation('ui-kit-component', {
153
+ agent_requests_operation('ui-kit-component', {
154
154
  ...common,
155
155
  name: agent_requests_name
156
156
  }),
157
- operation('shared-hook', {
157
+ agent_requests_operation('shared-hook', {
158
158
  ...common,
159
159
  name: agent_requests_name
160
160
  }),
161
- operation('move-page', {
161
+ agent_requests_operation('move-page', {
162
162
  ...common,
163
163
  module: nestedName,
164
164
  name: nestedName,
165
165
  moveRoute: zod.boolean().optional().describe('With Next.js and a route at the page path: move it too (default true). Omit it without such a route.')
166
166
  }),
167
- operation('delete-page', {
167
+ agent_requests_operation('delete-page', {
168
168
  ...common,
169
169
  module: nestedName,
170
170
  deleteRoute: zod.boolean().optional().describe("With Next.js and the page's own route: delete it too (default true). Omit it without such a route.")
171
171
  }),
172
- operation('delete-widget', {
172
+ agent_requests_operation('delete-widget', {
173
173
  ...common,
174
174
  module: nestedName
175
175
  }),
176
- operation('move-widget', {
176
+ agent_requests_operation('move-ui-kit-component', {
177
+ ...common,
178
+ module: agent_requests_name,
179
+ name: agent_requests_name
180
+ }),
181
+ agent_requests_operation('move-shared-hook', {
182
+ ...common,
183
+ module: agent_requests_name,
184
+ name: agent_requests_name
185
+ }),
186
+ agent_requests_operation('delete-ui-kit-component', {
187
+ ...common,
188
+ module: agent_requests_name
189
+ }),
190
+ agent_requests_operation('delete-shared-hook', {
191
+ ...common,
192
+ module: agent_requests_name
193
+ }),
194
+ agent_requests_operation('move-widget', {
177
195
  ...common,
178
196
  module: nestedName,
179
197
  name: nestedName
180
198
  })
181
199
  ]);
182
200
  const relativePath = zod.string().regex(/^[a-zA-Z0-9_.-]+(?:\/[a-zA-Z0-9_.-]+)*$/).refine((value)=>!value.split('/').some((part)=>'.' === part || '..' === part), 'Use a project-relative path without . or .. segments.');
183
- const integrationRequestSchema = operation('add', {
201
+ const integrationRequestSchema = agent_requests_operation('add', {
184
202
  ...common,
185
203
  integrations: zod.array(zod["enum"](integrationIds)).min(1),
186
204
  nextAdapter: zod.boolean().optional(),
@@ -306,7 +324,9 @@ const describeAgentCommand = (command)=>{
306
324
  integrations: integrationDescriptionsSafe(configured),
307
325
  reactModules: config?.frontend?.react ? [
308
326
  'page',
309
- 'widget'
327
+ 'widget',
328
+ 'ui-kit',
329
+ 'hook'
310
330
  ].flatMap((kind)=>findReactModules(node_path.join(root, config.project.rootFolder, 'presentation/react'), kind).map((module)=>({
311
331
  kind,
312
332
  name: module.name,
@@ -416,7 +436,9 @@ const executeReact = async (request)=>{
416
436
  ConfigFile.Instance.data.project.rootFolder,
417
437
  'presentation/react'
418
438
  ]);
419
- if (/^(move|delete)-/.test(request.operation) && !findReactModules(folder.path, request.operation.endsWith('-page') ? 'page' : 'widget').length) throw new RequestError('TARGET_NOT_FOUND', `No React ${request.operation.endsWith('-page') ? 'pages' : 'widgets'} here.`);
439
+ const kindOf = (operation)=>operation.endsWith('-page') ? 'page' : operation.endsWith('-widget') ? 'widget' : operation.endsWith('-ui-kit-component') ? 'ui-kit' : operation.endsWith('-shared-hook') ? 'hook' : void 0;
440
+ const kind = /^(move|delete)-/.test(request.operation) ? kindOf(request.operation) : void 0;
441
+ if (kind && !findReactModules(folder.path, kind).length) throw new RequestError('TARGET_NOT_FOUND', `No React ${reactKindTitles[kind][1]} here.`);
420
442
  const actions = {
421
443
  page: ()=>scaffoldReactPage(folder),
422
444
  widget: ()=>scaffoldReactWidget(folder),
@@ -425,7 +447,11 @@ const executeReact = async (request)=>{
425
447
  'move-page': ()=>moveReactModuleUseCase(folder, 'page'),
426
448
  'move-widget': ()=>moveReactModuleUseCase(folder, 'widget'),
427
449
  'delete-page': ()=>deleteReactModuleUseCase(folder, 'page'),
428
- 'delete-widget': ()=>deleteReactModuleUseCase(folder, 'widget')
450
+ 'delete-widget': ()=>deleteReactModuleUseCase(folder, 'widget'),
451
+ 'move-ui-kit-component': ()=>moveReactModuleUseCase(folder, 'ui-kit'),
452
+ 'move-shared-hook': ()=>moveReactModuleUseCase(folder, 'hook'),
453
+ 'delete-ui-kit-component': ()=>deleteReactModuleUseCase(folder, 'ui-kit'),
454
+ 'delete-shared-hook': ()=>deleteReactModuleUseCase(folder, 'hook')
429
455
  };
430
456
  return actions[request.operation]();
431
457
  };
package/dist/870.js CHANGED
@@ -316,7 +316,8 @@ const lintChecks = [
316
316
  'layers',
317
317
  'dependencies',
318
318
  'react',
319
- 'clock'
319
+ 'clock',
320
+ 'config'
320
321
  ];
321
322
  const configFileName = 'domain-first.project-structure.config.json';
322
323
  const projectConfigSchema = zod.object({
@@ -241,6 +241,28 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
241
241
  module: z.ZodString;
242
242
  overwrite: z.ZodOptional<z.ZodBoolean>;
243
243
  dryRun: z.ZodOptional<z.ZodBoolean>;
244
+ }, z.core.$strict>, z.ZodObject<{
245
+ operation: z.ZodLiteral<"move-ui-kit-component">;
246
+ module: z.ZodString;
247
+ name: z.ZodString;
248
+ overwrite: z.ZodOptional<z.ZodBoolean>;
249
+ dryRun: z.ZodOptional<z.ZodBoolean>;
250
+ }, z.core.$strict>, z.ZodObject<{
251
+ operation: z.ZodLiteral<"move-shared-hook">;
252
+ module: z.ZodString;
253
+ name: z.ZodString;
254
+ overwrite: z.ZodOptional<z.ZodBoolean>;
255
+ dryRun: z.ZodOptional<z.ZodBoolean>;
256
+ }, z.core.$strict>, z.ZodObject<{
257
+ operation: z.ZodLiteral<"delete-ui-kit-component">;
258
+ module: z.ZodString;
259
+ overwrite: z.ZodOptional<z.ZodBoolean>;
260
+ dryRun: z.ZodOptional<z.ZodBoolean>;
261
+ }, z.core.$strict>, z.ZodObject<{
262
+ operation: z.ZodLiteral<"delete-shared-hook">;
263
+ module: z.ZodString;
264
+ overwrite: z.ZodOptional<z.ZodBoolean>;
265
+ dryRun: z.ZodOptional<z.ZodBoolean>;
244
266
  }, z.core.$strict>, z.ZodObject<{
245
267
  operation: z.ZodLiteral<"move-widget">;
246
268
  module: z.ZodString;
@@ -309,7 +331,7 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
309
331
  add?: ("queries" | "commands" | "use-cases" | "application-ports" | "repositories" | "domain-services" | "application-services" | "infrastructure-services" | "presentation-services")[] | undefined;
310
332
  remove?: ("queries" | "commands" | "use-cases" | "application-ports" | "repositories" | "domain-services" | "application-services" | "infrastructure-services" | "presentation-services")[] | undefined;
311
333
  }>> | undefined;
312
- lint?: Partial<Record<"context-isolation" | "shared-kernel" | "layers" | "dependencies" | "react" | "clock", boolean>> | undefined;
334
+ lint?: Partial<Record<"context-isolation" | "shared-kernel" | "layers" | "dependencies" | "react" | "clock" | "config", boolean>> | undefined;
313
335
  } | undefined;
314
336
  } | undefined;
315
337
  frontend?: {
@@ -363,7 +385,7 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
363
385
  available: boolean;
364
386
  }[];
365
387
  reactModules: {
366
- kind: string;
388
+ kind: "page" | "widget" | "ui-kit" | "hook";
367
389
  name: string;
368
390
  file: string;
369
391
  }[];