@domain-first/project-structure 8.9.0 → 8.9.2

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/upgrade.cjs CHANGED
@@ -172,7 +172,7 @@ class FileSystemItem {
172
172
  return external_node_fs_default().existsSync(this.path);
173
173
  }
174
174
  }
175
- class File extends FileSystemItem {
175
+ class file_system_File extends FileSystemItem {
176
176
  get exists() {
177
177
  return pendingFiles.has(this.path) || pendingMoves.has(this.path) || external_node_fs_default().existsSync(this.path) && !pendingDeletions.has(this.path);
178
178
  }
@@ -237,7 +237,7 @@ const implementationOptionsSchema = external_zod_default().object({
237
237
  ])),
238
238
  integrationTests: external_zod_default().array(implementationLabelSchema).optional()
239
239
  }).strict();
240
- class ProjectRoot {
240
+ class project_root_ProjectRoot {
241
241
  path;
242
242
  constructor(){
243
243
  let dir = process.cwd();
@@ -319,7 +319,7 @@ class ConfigOutdatedError extends Error {
319
319
  class config_file_ConfigFile {
320
320
  data;
321
321
  constructor(){
322
- const raw = JSON.parse(new File(config_file_ConfigFile.path).data);
322
+ const raw = JSON.parse(new file_system_File(config_file_ConfigFile.path).data);
323
323
  if (isOutdatedConfig(raw)) throw new ConfigOutdatedError();
324
324
  this.data = configSchema.parse(raw);
325
325
  }
@@ -332,15 +332,15 @@ class config_file_ConfigFile {
332
332
  return backend;
333
333
  }
334
334
  static get path() {
335
- return external_node_path_default().resolve(new ProjectRoot().path, configFileName);
335
+ return external_node_path_default().resolve(new project_root_ProjectRoot().path, configFileName);
336
336
  }
337
337
  static get exists() {
338
- return new File(config_file_ConfigFile.path).exists;
338
+ return new file_system_File(config_file_ConfigFile.path).exists;
339
339
  }
340
340
  static get outdated() {
341
341
  if (!config_file_ConfigFile.exists) return false;
342
342
  try {
343
- return isOutdatedConfig(JSON.parse(new File(config_file_ConfigFile.path).data));
343
+ return isOutdatedConfig(JSON.parse(new file_system_File(config_file_ConfigFile.path).data));
344
344
  } catch {
345
345
  return false;
346
346
  }
@@ -355,11 +355,11 @@ class config_file_ConfigFile {
355
355
  }));
356
356
  };
357
357
  static stage(config) {
358
- new File(config_file_ConfigFile.path).update(`${JSON.stringify(config, null, 4)}\n`);
358
+ new file_system_File(config_file_ConfigFile.path).update(`${JSON.stringify(config, null, 4)}\n`);
359
359
  }
360
360
  }
361
361
  const hasDependency = (name)=>{
362
- const manifestFile = new File(external_node_path_default().join(new ProjectRoot().path, 'package.json'));
362
+ const manifestFile = new file_system_File(external_node_path_default().join(new project_root_ProjectRoot().path, 'package.json'));
363
363
  if (!manifestFile.exists) return false;
364
364
  const manifest = JSON.parse(manifestFile.data);
365
365
  return [
@@ -368,6 +368,71 @@ const hasDependency = (name)=>{
368
368
  manifest.optionalDependencies
369
369
  ].some((dependencies)=>dependencies && Object.hasOwn(dependencies, name));
370
370
  };
371
+ new Map([
372
+ [
373
+ 'prisma',
374
+ 'prisma-infrastructure-service'
375
+ ],
376
+ [
377
+ 'drizzle',
378
+ 'drizzle-infrastructure-service'
379
+ ],
380
+ [
381
+ 'in-memory',
382
+ 'in-memory-db-infrastructure-service'
383
+ ]
384
+ ]);
385
+ const legacyWithIdLookup = ` withId: (id: TId): T | null =>
386
+ items().find(
387
+ (x: T) => hasId(x) && idsAreEqual(x.id as TId, id)
388
+ ) ?? null,
389
+ `;
390
+ const legacyHasId = `const hasId = (x: unknown): x is { id: unknown } =>
391
+ typeof x === 'object' && x !== null && 'id' in x;
392
+
393
+ `;
394
+ const withIdLookup = ` withId: (id: TId): T | null =>
395
+ globalThis.___SHARED_IN_MEMORY_DB___![key].find((entry) =>
396
+ idsAreEqual(entry.id as TId, id)
397
+ )?.item ?? null,
398
+ `;
399
+ const uncountableEndings = [
400
+ 'data',
401
+ 'info',
402
+ 'usage',
403
+ 'feedback',
404
+ 'media',
405
+ 'ware',
406
+ 'equipment',
407
+ 'information',
408
+ 'knowledge',
409
+ 'traffic',
410
+ 'telemetry',
411
+ 'analytics',
412
+ 'series'
413
+ ];
414
+ new RegExp(`(${uncountableEndings.join('|')})$`, 'i');
415
+ const upgrade_in_memory_db_serviceFile = ({ config })=>{
416
+ const project = config.project;
417
+ const rootFolder = 'object' == typeof project && null !== project ? project.rootFolder : void 0;
418
+ if ('string' != typeof rootFolder) return;
419
+ const file = new file_system_File(external_node_path_default().join(new project_root_ProjectRoot().path, rootFolder, 'shared-kernel/infrastructure/services/in-memory-db-infrastructure-service.ts'));
420
+ return file.exists ? file : void 0;
421
+ };
422
+ const inMemoryDbWithIdStep = {
423
+ id: 'in-memory-db-with-id',
424
+ kind: 'optional',
425
+ title: 'Let withId of the in-memory DB find items saved as [id, item]',
426
+ detect: (context)=>upgrade_in_memory_db_serviceFile(context)?.data.includes(legacyWithIdLookup) ?? false,
427
+ plan: (context)=>[
428
+ `${external_node_path_default().relative(new project_root_ProjectRoot().path, upgrade_in_memory_db_serviceFile(context).path).split(external_node_path_default().sep).join('/')}: withId looks up the id saved with the item`
429
+ ],
430
+ apply: (context)=>{
431
+ const file = upgrade_in_memory_db_serviceFile(context);
432
+ const fixed = file.data.replace(legacyWithIdLookup, withIdLookup);
433
+ file.update(/\bhasId\b/.test(fixed.replace(legacyHasId, '')) ? fixed : fixed.replace(legacyHasId, ''));
434
+ }
435
+ };
371
436
  const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
372
437
  const rootFolderSegments = (rootFolder, indent = 20)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n${' '.repeat(indent)}`).join('');
373
438
  const legacyEndpointFileLookup = (rootFolder)=>` // The controller, if any, is the first folder of the path:
@@ -426,13 +491,13 @@ const ignoredFolders = new Set([
426
491
  'storybook-static'
427
492
  ]);
428
493
  const codeExtension = /\.(?:tsx?|mts|cts|jsx?|mjs|cjs|mdx)$/;
429
- const walk = (folder)=>{
494
+ const module_move_walk = (folder)=>{
430
495
  if (!external_node_fs_default().existsSync(folder)) return [];
431
496
  return external_node_fs_default().readdirSync(folder, {
432
497
  withFileTypes: true
433
498
  }).flatMap((entry)=>{
434
499
  const entryPath = external_node_path_default().join(folder, entry.name);
435
- if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] : walk(entryPath);
500
+ if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] : module_move_walk(entryPath);
436
501
  return entry.isFile() ? [
437
502
  entryPath
438
503
  ] : [];
@@ -483,7 +548,7 @@ const projectImports = (projectRoot)=>{
483
548
  const relative = toPosix(external_node_path_default().relative(external_node_path_default().dirname(fromFile), toPath));
484
549
  return relative.startsWith('.') ? relative : `./${relative}`;
485
550
  };
486
- const codeFiles = new Map(walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
551
+ const codeFiles = new Map(module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
487
552
  file,
488
553
  external_node_fs_default().readFileSync(file, 'utf8')
489
554
  ]));
@@ -535,16 +600,16 @@ const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyF
535
600
  moved: moves.has(oldFile)
536
601
  });
537
602
  };
538
- for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile, stopFor(file));
603
+ for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile, stopFor(file));
539
604
  const updated = [];
540
605
  for (const [file, content] of codeFiles){
541
606
  const newFile = moves.get(file);
542
607
  const next = rewrite(content, file, newFile ?? file);
543
608
  if (newFile && newFile !== file) {
544
- new File(newFile).data = next;
545
- new File(file).delete(stopFor(file));
609
+ new file_system_File(newFile).data = next;
610
+ new file_system_File(file).delete(stopFor(file));
546
611
  } else if (next !== content) {
547
- new File(file).update(next);
612
+ new file_system_File(file).update(next);
548
613
  if (!newFile) updated.push(file);
549
614
  }
550
615
  }
@@ -588,13 +653,13 @@ const rootFolderOf = ({ config })=>{
588
653
  const contextFolders = (context)=>{
589
654
  const rootFolder = rootFolderOf(context);
590
655
  if (!rootFolder) return [];
591
- const contexts = external_node_path_default().join(new ProjectRoot().path, rootFolder, 'bounded-contexts');
656
+ const contexts = external_node_path_default().join(new project_root_ProjectRoot().path, rootFolder, 'bounded-contexts');
592
657
  return external_node_fs_default().existsSync(contexts) ? external_node_fs_default().readdirSync(contexts, {
593
658
  withFileTypes: true
594
659
  }).filter((entry)=>entry.isDirectory()).map((entry)=>external_node_path_default().join(contexts, entry.name)) : [];
595
660
  };
596
661
  const legacyContexts = (context)=>contextFolders(context).filter(hasLegacyRootEndpoints);
597
- const upgrade_rest_root_relative = (file)=>toPosix(external_node_path_default().relative(new ProjectRoot().path, file));
662
+ const upgrade_rest_root_relative = (file)=>toPosix(external_node_path_default().relative(new project_root_ProjectRoot().path, file));
598
663
  const intoRoot = (folder, file)=>external_node_path_default().join(folder, "(root)", external_node_path_default().relative(folder, file));
599
664
  const rootMoves = (contextFolder)=>{
600
665
  const { presentation, wiring } = restFolders(contextFolder);
@@ -603,7 +668,7 @@ const rootMoves = (contextFolder)=>{
603
668
  files: [
604
669
  ...[
605
670
  ...endpointFiles,
606
- ...parameterFolders.flatMap(walk)
671
+ ...parameterFolders.flatMap(module_move_walk)
607
672
  ].map((file)=>[
608
673
  file,
609
674
  intoRoot(presentation, file)
@@ -649,14 +714,14 @@ const restRootControllerStep = {
649
714
  ...files.map(([from, to])=>`${upgrade_rest_root_relative(from)} → ${upgrade_rest_root_relative(to)}`),
650
715
  ...wired ? [
651
716
  `${upgrade_rest_root_relative(external_node_path_default().join(wiring, 'index.ts'))}: the context-root lines → one line for ./(root)`,
652
- `${upgrade_rest_root_relative(external_node_path_default().join(new ProjectRoot().path, rootFolderOf(context), 'presentation', 'rest', 'wires.ts'))}: the ${name} context-root lines → one line for (root), added if missing`
717
+ `${upgrade_rest_root_relative(external_node_path_default().join(new project_root_ProjectRoot().path, rootFolderOf(context), 'presentation', 'rest', 'wires.ts'))}: the ${name} context-root lines → one line for (root), added if missing`
653
718
  ] : [],
654
719
  'Imports of the moved files are rewritten'
655
720
  ];
656
721
  }),
657
722
  apply: (context)=>{
658
723
  const contexts = legacyContexts(context);
659
- const projectRoot = new ProjectRoot().path;
724
+ const projectRoot = new project_root_ProjectRoot().path;
660
725
  const moves = new Map();
661
726
  const folders = [];
662
727
  for (const contextFolder of contexts){
@@ -686,15 +751,15 @@ const restRootControllerStep = {
686
751
  },
687
752
  rename: (content)=>content
688
753
  });
689
- const sharedWires = new File(external_node_path_default().join(projectRoot, rootFolderOf(context), 'presentation', 'rest', 'wires.ts'));
754
+ const sharedWires = new file_system_File(external_node_path_default().join(projectRoot, rootFolderOf(context), 'presentation', 'rest', 'wires.ts'));
690
755
  for (const contextFolder of contexts){
691
756
  const name = external_node_path_default().basename(contextFolder);
692
757
  const { wiring } = restFolders(contextFolder);
693
758
  const movedWires = legacyRootEndpoints(contextFolder).wireFiles;
694
759
  if (!movedWires.length) continue;
695
- const listed = regroupExports(new File(external_node_path_default().join(wiring, 'index.ts')), (specifier)=>specifier.startsWith("./(root)/"), "./(root)").map((line)=>line.replace("./(root)/", './'));
760
+ const listed = regroupExports(new file_system_File(external_node_path_default().join(wiring, 'index.ts')), (specifier)=>specifier.startsWith("./(root)/"), "./(root)").map((line)=>line.replace("./(root)/", './'));
696
761
  const unlisted = movedWires.map((file)=>`./${external_node_path_default().basename(file, '.ts')}`).filter((specifier)=>!listed.some((line)=>exportedSpecifier(line) === specifier)).map((specifier)=>`export * from '${specifier}'`);
697
- new File(external_node_path_default().join(wiring, "(root)", 'index.ts')).data = [
762
+ new file_system_File(external_node_path_default().join(wiring, "(root)", 'index.ts')).data = [
698
763
  ...listed,
699
764
  ...unlisted
700
765
  ].join('\n');
@@ -703,7 +768,7 @@ const restRootControllerStep = {
703
768
  }
704
769
  }
705
770
  };
706
- const extractorFile = ()=>new File(external_node_path_default().join(new ProjectRoot().path, openapiExtractorPath));
771
+ const extractorFile = ()=>new file_system_File(external_node_path_default().join(new project_root_ProjectRoot().path, openapiExtractorPath));
707
772
  const openapiExtractorRootStep = {
708
773
  id: 'openapi-extractor-root',
709
774
  kind: 'optional',
@@ -856,7 +921,8 @@ const upgradeSteps = [
856
921
  persistenceStep,
857
922
  restRootControllerStep,
858
923
  openapiExtractorRootStep,
859
- openapiExtractorManualStep
924
+ openapiExtractorManualStep,
925
+ inMemoryDbWithIdStep
860
926
  ];
861
927
  const skillsNote = 'Update the agent skills to this version: npx df-skills';
862
928
  const planUpgrade = async (config, acceptOptional = ()=>true, steps = upgradeSteps)=>{
@@ -923,7 +989,7 @@ const printStep = ({ step, changes })=>{
923
989
  for (const change of changes)console.log(` ${change}`);
924
990
  };
925
991
  const run = async ()=>{
926
- const root = new ProjectRoot().path;
992
+ const root = new project_root_ProjectRoot().path;
927
993
  const configPath = external_node_path_default().join(root, configFileName);
928
994
  if (!config_file_ConfigFile.exists) {
929
995
  console.log(`No ${configFileName} found: run df-init to initialize the project.`);
@@ -931,7 +997,7 @@ const run = async ()=>{
931
997
  }
932
998
  let raw;
933
999
  try {
934
- raw = JSON.parse(new File(configPath).data);
1000
+ raw = JSON.parse(new file_system_File(configPath).data);
935
1001
  } catch {
936
1002
  console.log(`${configFileName} is not valid JSON: fix it first.`);
937
1003
  process.exit(1);
package/dist/upgrade.js CHANGED
@@ -4,8 +4,29 @@ import { parseArgs } from "node:util";
4
4
  import { confirm as prompts_confirm } from "@inquirer/prompts";
5
5
  import zod from "zod";
6
6
  import node_fs from "node:fs";
7
- import { implementationLabelSchema, domainFirstPackages as config_file_domainFirstPackages, discardPendingChanges, configSchema, rulesSchema, ConfigFile, isOutdatedConfig, writePendingChanges, File, configFileName, ProjectRoot } from "./780.js";
8
- import { restFolders, openapiExtractorPath, legacyEndpointFileLookup, walk, hasLegacyRootEndpoints, endpointFileLookup, hasDependency, stageModuleMove, legacyRootEndpoints, toPosix, codeExtension } from "./526.js";
7
+ import { implementationLabelSchema, domainFirstPackages as config_file_domainFirstPackages, discardPendingChanges, configSchema, rulesSchema, ConfigFile, isOutdatedConfig, writePendingChanges, File, configFileName, ProjectRoot } from "./201.js";
8
+ import { restFolders, withIdLookup, openapiExtractorPath, legacyEndpointFileLookup, walk, legacyHasId, legacyWithIdLookup, hasLegacyRootEndpoints, endpointFileLookup, hasDependency, stageModuleMove, legacyRootEndpoints, toPosix, codeExtension } from "./115.js";
9
+ const serviceFile = ({ config })=>{
10
+ const project = config.project;
11
+ const rootFolder = 'object' == typeof project && null !== project ? project.rootFolder : void 0;
12
+ if ('string' != typeof rootFolder) return;
13
+ const file = new File(node_path.join(new ProjectRoot().path, rootFolder, 'shared-kernel/infrastructure/services/in-memory-db-infrastructure-service.ts'));
14
+ return file.exists ? file : void 0;
15
+ };
16
+ const inMemoryDbWithIdStep = {
17
+ id: 'in-memory-db-with-id',
18
+ kind: 'optional',
19
+ title: 'Let withId of the in-memory DB find items saved as [id, item]',
20
+ detect: (context)=>serviceFile(context)?.data.includes(legacyWithIdLookup) ?? false,
21
+ plan: (context)=>[
22
+ `${node_path.relative(new ProjectRoot().path, serviceFile(context).path).split(node_path.sep).join('/')}: withId looks up the id saved with the item`
23
+ ],
24
+ apply: (context)=>{
25
+ const file = serviceFile(context);
26
+ const fixed = file.data.replace(legacyWithIdLookup, withIdLookup);
27
+ file.update(/\bhasId\b/.test(fixed.replace(legacyHasId, '')) ? fixed : fixed.replace(legacyHasId, ''));
28
+ }
29
+ };
9
30
  const rootFolderOf = ({ config })=>{
10
31
  const project = config.project;
11
32
  const rootFolder = 'object' == typeof project && null !== project ? project.rootFolder : void 0;
@@ -282,7 +303,8 @@ const upgradeSteps = [
282
303
  persistenceStep,
283
304
  restRootControllerStep,
284
305
  openapiExtractorRootStep,
285
- openapiExtractorManualStep
306
+ openapiExtractorManualStep,
307
+ inMemoryDbWithIdStep
286
308
  ];
287
309
  const skillsNote = 'Update the agent skills to this version: npx df-skills';
288
310
  const planUpgrade = async (config, acceptOptional = ()=>true, steps = upgradeSteps)=>{
@@ -1,4 +1,5 @@
1
1
  import { type Folder } from '../file-system';
2
+ import { NestedName } from '../nested-name';
2
3
  /**
3
4
  * Content of `<file>-page.tsx`: imports go before React's, `body` is
4
5
  * what the page returns.
@@ -9,4 +10,10 @@ export declare const reactPageContent: (ClassName: string, { imports, body }?: {
9
10
  }) => string;
10
11
  /** A thin App Router route that renders the page component. */
11
12
  export declare const nextRouteContent: (ClassName: string, pageImport: string) => string;
13
+ /**
14
+ * With Next.js, the page also gets its App Router route at the same path,
15
+ * e.g. `admin/users` → `app/admin/users/page.tsx`. An existing route is
16
+ * kept: it may hold the user's code, and the returned hint says so.
17
+ */
18
+ export declare const scaffoldNextRoute: (name: NestedName, pagePath: string) => string | undefined;
12
19
  export declare const scaffoldReactPage: (presentationReactFolder: Folder) => Promise<void>;
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": "8.9.0",
4
+ "version": "8.9.2",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",