@domain-first/project-structure 7.1.0 → 7.2.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/dist/init.cjs CHANGED
@@ -550,6 +550,22 @@ const in_memory_db_scaffoldInMemoryDb = (shared)=>{
550
550
  'infrastructure-services'
551
551
  ]).createFile('wire-in-memory-db-infrastructure-service.ts', inMemoryDbWiring);
552
552
  };
553
+ const uncountableEndings = [
554
+ 'data',
555
+ 'info',
556
+ 'usage',
557
+ 'feedback',
558
+ 'media',
559
+ 'ware',
560
+ 'equipment',
561
+ 'information',
562
+ 'knowledge',
563
+ 'traffic',
564
+ 'telemetry',
565
+ 'analytics',
566
+ 'series'
567
+ ];
568
+ new RegExp(`(${uncountableEndings.join('|')})$`, 'i');
553
569
  const hasDependency = (name)=>{
554
570
  const manifestFile = new file_system_File(external_node_path_default().join(new project_root_ProjectRoot().path, 'package.json'));
555
571
  if (!manifestFile.exists) return false;
@@ -497,6 +497,22 @@ const in_memory_db_scaffoldInMemoryDb = (shared)=>{
497
497
  ]).createFile('wire-in-memory-db-infrastructure-service.ts', inMemoryDbWiring);
498
498
  };
499
499
  const inMemoryDbScaffolded = ()=>serviceFile().exists && (!in_memory_db_withWiring() || in_memory_db_wireFile().exists);
500
+ const uncountableEndings = [
501
+ 'data',
502
+ 'info',
503
+ 'usage',
504
+ 'feedback',
505
+ 'media',
506
+ 'ware',
507
+ 'equipment',
508
+ 'information',
509
+ 'knowledge',
510
+ 'traffic',
511
+ 'telemetry',
512
+ 'analytics',
513
+ 'series'
514
+ ];
515
+ new RegExp(`(${uncountableEndings.join('|')})$`, 'i');
500
516
  const addInMemoryDb = ()=>{
501
517
  const config = config_file_ConfigFile.Instance.data;
502
518
  if (!config.withInMemoryDb) config_file_ConfigFile.write({
package/dist/lint.cjs CHANGED
@@ -522,9 +522,9 @@ const closingIndex = (source, openIndex)=>{
522
522
  }
523
523
  return -1;
524
524
  };
525
- const splitTopLevel = (content)=>{
525
+ const topLevelItemRanges = (content)=>{
526
526
  const code = codeOnly(content);
527
- const items = [];
527
+ const ranges = [];
528
528
  let depth = 0;
529
529
  let itemStart = 0;
530
530
  for(let index = 0; index <= code.length; index++){
@@ -532,16 +532,19 @@ const splitTopLevel = (content)=>{
532
532
  if (void 0 !== char && char in brackets) depth++;
533
533
  else if (Object.values(brackets).includes(char)) depth--;
534
534
  if (index === code.length || ',' === char && 0 === depth) {
535
- const item = content.slice(itemStart, index);
536
535
  const itemCode = code.slice(itemStart, index);
537
536
  const first = itemCode.search(/\S/);
538
537
  const last = itemCode.search(/\S\s*$/);
539
- if (-1 !== first) items.push(item.slice(first, last + 1));
538
+ if (-1 !== first) ranges.push({
539
+ start: itemStart + first,
540
+ end: itemStart + last + 1
541
+ });
540
542
  itemStart = index + 1;
541
543
  }
542
544
  }
543
- return items;
545
+ return ranges;
544
546
  };
547
+ const splitTopLevel = (content)=>topLevelItemRanges(content).map(({ start, end })=>content.slice(start, end));
545
548
  const wireListRange = (source, className)=>{
546
549
  const match = new RegExp(`wireClass\\(\\s*${className}\\s*,\\s*\\[`).exec(codeOnly(source));
547
550
  if (!match) throw new Error(`wireClass(${className}, [...]) not found`);
package/dist/react.cjs CHANGED
@@ -340,6 +340,22 @@ const save_pending_changes_savePendingChanges = async ()=>{
340
340
  writePendingChanges();
341
341
  return true;
342
342
  };
343
+ const uncountableEndings = [
344
+ 'data',
345
+ 'info',
346
+ 'usage',
347
+ 'feedback',
348
+ 'media',
349
+ 'ware',
350
+ 'equipment',
351
+ 'information',
352
+ 'knowledge',
353
+ 'traffic',
354
+ 'telemetry',
355
+ 'analytics',
356
+ 'series'
357
+ ];
358
+ new RegExp(`(${uncountableEndings.join('|')})$`, 'i');
343
359
  require("node:module");
344
360
  const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
345
361
  class unknown_format_naming_UnknownFormatNaming {
@@ -11,6 +11,7 @@ export * from './scaffold-new-domain-object';
11
11
  export * from './scaffold-new-domain-service';
12
12
  export * from './scaffold-new-error';
13
13
  export * from './scaffold-new-handlers-rest-endpoint';
14
+ export * from './scaffold-new-implementation';
14
15
  export * from './scaffold-new-infrastructure-service';
15
16
  export * from './scaffold-new-presentation-service';
16
17
  export * from './scaffold-new-query';
@@ -1,2 +1,2 @@
1
- import { type Folder } from '../file-system';
1
+ import type { Folder } from '../file-system';
2
2
  export declare const scaffoldNewAggregateUseCase: (boundedContextFolder: Folder) => Promise<void>;
@@ -0,0 +1,6 @@
1
+ import { type Folder } from '../file-system';
2
+ /**
3
+ * Adds one more implementation to an existing repository, command,
4
+ * query or port, and with wiring picks the environments that use it.
5
+ */
6
+ export declare const scaffoldNewImplementation: (ownerFolder: Folder) => Promise<void>;
@@ -9,6 +9,11 @@ export type CustomWiring = (implementation: WiredClass, dependency: WiredModule)
9
9
  * The last step of generators that create a wire.
10
10
  */
11
11
  export declare const wireNewModuleDependencies: (boundedContextFolder: Folder, wireFile: File, customWiring?: CustomWiring) => Promise<void>;
12
+ /**
13
+ * The last step of adding an implementation to a branched wire: only
14
+ * the new implementation is asked about.
15
+ */
16
+ export declare const wireNewImplementationDependencies: (boundedContextFolder: Folder, wireFile: File, className: string, customWiring?: CustomWiring) => Promise<void>;
12
17
  export declare const wireDependency: (boundedContextFolder: Folder) => Promise<void>;
13
18
  /**
14
19
  * The endpoint's handler, from the context's queries, commands, and use
package/dist/wiring.d.ts CHANGED
@@ -93,3 +93,24 @@ export declare const addWireDependencies: (source: string, className: string, wi
93
93
  * the same order.
94
94
  */
95
95
  export declare const wireDependencies: (consumer: WiredModule, implementation: WiredClass, dependencies: WiredModule[]) => void;
96
+ /**
97
+ * Environment → the wire it uses, as written in the module's
98
+ * `envBranchedWire({...})`.
99
+ */
100
+ export declare const wireBranches: (source: string, wireName: string) => Map<string, string>;
101
+ /**
102
+ * Points the environments of the module's `envBranchedWire` at the wire,
103
+ * adding the environments it doesn't have yet.
104
+ */
105
+ export declare const setWireBranches: (source: string, wireName: string, environments: string[], branchWire: string) => string;
106
+ /**
107
+ * Adds an implementation to a branched wire: its import and its own
108
+ * `wireClass` before the module's wire, which it serves in the given
109
+ * environments.
110
+ */
111
+ export declare const addBranchedImplementation: (source: string, wireName: string, implementation: {
112
+ importLine: string;
113
+ className: string;
114
+ wireName: string;
115
+ environments: string[];
116
+ }) => 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": "7.1.0",
4
+ "version": "7.2.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -104,6 +104,7 @@ One file per unit in `references/units/`: when to choose it, how to generate it
104
104
  | Use case | `use-case.md` | Application → New Use Case |
105
105
  | Command, query | `command-query.md` | Application → New Command / New Query |
106
106
  | Port + adapters | `port.md` | Application → New Port |
107
+ | One more implementation of a repository, command, query or port | `implementation.md` | Infrastructure → New Implementation |
107
108
  | REST endpoint | `endpoint.md` | Presentation → New Handlers-REST Endpoint |
108
109
  | Dependency of an existing module | `wire-dependency.md` | Wire dependency |
109
110
  | Moving or renaming a module | `move-or-rename.md` | Move or rename |
@@ -141,11 +142,11 @@ Check every run: exit code 0, no `WARNING`/`ABORTED`, and exactly the planned fi
141
142
  | -------------- | ---------------------------------------------------------------- | ------------------------------------------------- |
142
143
  | Domain | New Aggregate, New Entity, New Value Object, Errors, New Service | New Entity, New Value Object, Errors, New Service |
143
144
  | Application | New Query, New Command, New Use Case, New Port, New Service | New Port, New Service |
144
- | Infrastructure | New Service | New Service |
145
+ | Infrastructure | New Service, New Implementation | New Service, New Implementation |
145
146
  | Presentation | New Handlers-REST Endpoint (needs handlers-rest), New Service | New Service |
146
147
 
147
148
  With `@domain-first/wire`, the layer menu of a context and of the Shared Kernel also has `Wire dependency`: it adds dependencies to an existing wired module. Every layer menu has `Move or rename`.
148
149
 
149
150
  The main menu also has `Scaffold new bounded context`. React modules come from a separate CLI, `df-react`: see `df-ps-react`.
150
151
 
151
- Run order in a plan: new contexts → domain (aggregates before their entities and value objects) → application (ports, commands/queries, use cases) → endpoints → React (`df-ps-react`).
152
+ Run order in a plan: new contexts → domain (aggregates before their entities and value objects) → application (ports, commands/queries, use cases) → new implementations of existing contracts → endpoints → React (`df-ps-react`).
@@ -32,6 +32,7 @@ Split the request into pieces of logic (one responsibility each). For each piece
32
32
  - A rule about a **set** of aggregates (uniqueness, "at most N per day") = a repository method that queries it, plus a check and a domain error in the use case. No separate component.
33
33
  - Steps 9–10 beat 11–15. The other-context or external part becomes a query/command or a port. What remains may be a service that **receives it in its constructor**.
34
34
  - Another context (step 9): input/output are this context's own models, duplicated in its terms, never the other context's. The implementation reaches the other context the simplest available way: a shared database → directly (the persistence label, e.g. `prisma`); otherwise the way chosen by `df-ps-plan-feature` (step 3, rule 4): if the project has several ways to reach a context (REST, message queue, RPC…), ask the user; with REST only, its REST endpoint (`http`). The test implementation returns fixed data. No imports from the other context.
35
+ - Another way to perform an **existing** repository, command, query or port (another storage, provider or environment) is a new implementation of it (Infrastructure → New Implementation, `units/implementation.md`), not a new contract.
35
36
  - Don't create components "just in case": a command only when storage access deserves its own contract, an application service only when reused.
36
37
 
37
38
  ## Port or service?
@@ -0,0 +1,20 @@
1
+ # Implementation of an existing contract
2
+
3
+ When: a repository, command, query or port already exists and needs one more implementation, e.g. a third adapter of a port so that test, development and production each use their own. A new contract is its own generator (`aggregate.md`, `command-query.md`, `port.md`); never copy an implementation file by hand.
4
+
5
+ ## Generate (context and Shared Kernel)
6
+
7
+ Prompts: `Contract:` (select, grouped: Repositories, Commands, Queries, Ports; each with its implementations: `file-storage (in-memory, s3)`) → `Implementation type:` (kebab-case, one the contract doesn't have) → {wire} `Environments:` (checkbox `test`, `development`, `production`, each shown with its current implementation: `development (now: s3)`; at least one) → {wire} `Dependencies for <Implementation>:` for the new implementation only (`../generators.md`).
8
+
9
+ `… pick:Infrastructure "pick:New Implementation" pick:file-storage text:local toggle:2`
10
+
11
+ `toggle:` numbers the environments top to bottom: 1 `test`, 2 `development`, 3 `production`.
12
+
13
+ - `<C>/infrastructure/<kind>/I/I-n….ts` as the contract's generator creates it (in-memory DB included)
14
+ - {wire} `~ <C>/wiring/<kind>/wire-n….ts`: import, `const wireIImplementation = wireClass(IN…, [])` before the module's wire, the chosen environments of `envBranchedWire` point at it
15
+
16
+ An implementation left without environments stays in the wire file; the CLI prints `<Class> is no longer used in any environment.` Specs don't change.
17
+
18
+ ## Implement and test
19
+
20
+ As the implementations of the contract's unit file. The spec of the contract wires what `NODE_ENV=test` uses: only a new `test` implementation changes what it tests.