ddd-express 0.0.0-stage → 1.0.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.
Files changed (77) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/LICENSE +21 -0
  3. package/README.ar.md +117 -0
  4. package/README.md +314 -2
  5. package/dist/analyze/check.d.ts +74 -0
  6. package/dist/analyze/check.js +503 -0
  7. package/dist/analyze/document.d.ts +26 -0
  8. package/dist/analyze/document.js +126 -0
  9. package/dist/analyze/map.d.ts +19 -0
  10. package/dist/analyze/map.js +283 -0
  11. package/dist/analyze/openapi.d.ts +7 -0
  12. package/dist/analyze/openapi.js +236 -0
  13. package/dist/cli.d.ts +2 -0
  14. package/dist/cli.js +12 -0
  15. package/dist/core/errors.d.ts +5 -0
  16. package/dist/core/errors.js +13 -0
  17. package/dist/core/fields.d.ts +38 -0
  18. package/dist/core/fields.js +233 -0
  19. package/dist/core/markers.d.ts +25 -0
  20. package/dist/core/markers.js +60 -0
  21. package/dist/core/names.d.ts +30 -0
  22. package/dist/core/names.js +168 -0
  23. package/dist/core/output.d.ts +21 -0
  24. package/dist/core/output.js +29 -0
  25. package/dist/core/project.d.ts +135 -0
  26. package/dist/core/project.js +287 -0
  27. package/dist/core/writer.d.ts +39 -0
  28. package/dist/core/writer.js +138 -0
  29. package/dist/generators/analyze.d.ts +16 -0
  30. package/dist/generators/analyze.js +174 -0
  31. package/dist/generators/apply.d.ts +28 -0
  32. package/dist/generators/apply.js +234 -0
  33. package/dist/generators/common.d.ts +49 -0
  34. package/dist/generators/common.js +173 -0
  35. package/dist/generators/domain.d.ts +30 -0
  36. package/dist/generators/domain.js +198 -0
  37. package/dist/generators/engine.d.ts +71 -0
  38. package/dist/generators/engine.js +552 -0
  39. package/dist/generators/project.d.ts +10 -0
  40. package/dist/generators/project.js +214 -0
  41. package/dist/index.d.ts +10 -0
  42. package/dist/index.js +14 -0
  43. package/dist/model/commands.d.ts +28 -0
  44. package/dist/model/commands.js +228 -0
  45. package/dist/model/examples.d.ts +6 -0
  46. package/dist/model/examples.js +152 -0
  47. package/dist/model/parser.d.ts +28 -0
  48. package/dist/model/parser.js +222 -0
  49. package/dist/model/types.d.ts +98 -0
  50. package/dist/model/types.js +2 -0
  51. package/dist/model/validate.d.ts +30 -0
  52. package/dist/model/validate.js +215 -0
  53. package/dist/run.d.ts +4 -0
  54. package/dist/run.js +506 -0
  55. package/dist/scan/project-scan.d.ts +77 -0
  56. package/dist/scan/project-scan.js +226 -0
  57. package/dist/scan/source.d.ts +60 -0
  58. package/dist/scan/source.js +274 -0
  59. package/dist/templates/aggregate.d.ts +51 -0
  60. package/dist/templates/aggregate.js +407 -0
  61. package/dist/templates/building-blocks.d.ts +30 -0
  62. package/dist/templates/building-blocks.js +155 -0
  63. package/dist/templates/code.d.ts +14 -0
  64. package/dist/templates/code.js +51 -0
  65. package/dist/templates/command.d.ts +47 -0
  66. package/dist/templates/command.js +376 -0
  67. package/dist/templates/context.d.ts +16 -0
  68. package/dist/templates/context.js +43 -0
  69. package/dist/templates/field-code.d.ts +47 -0
  70. package/dist/templates/field-code.js +227 -0
  71. package/dist/templates/postgres.d.ts +25 -0
  72. package/dist/templates/postgres.js +113 -0
  73. package/dist/templates/project.d.ts +20 -0
  74. package/dist/templates/project.js +153 -0
  75. package/dist/templates/shared-kernel.d.ts +6 -0
  76. package/dist/templates/shared-kernel.js +44 -0
  77. package/package.json +58 -4
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasDefault = exports.inputFields = exports.SUPPORTED_TYPES_HELP = exports.JS_KEYWORDS = void 0;
4
+ exports.splitTopLevel = splitTopLevel;
5
+ exports.fieldNames = fieldNames;
6
+ exports.parseLiteral = parseLiteral;
7
+ exports.parseField = parseField;
8
+ exports.parseFields = parseFields;
9
+ const errors_1 = require("./errors");
10
+ const names_1 = require("./names");
11
+ const TYPE_ALIASES = {
12
+ string: 'string',
13
+ str: 'string',
14
+ text: 'string',
15
+ number: 'number',
16
+ float: 'number',
17
+ decimal: 'number',
18
+ double: 'number',
19
+ integer: 'integer',
20
+ int: 'integer',
21
+ boolean: 'boolean',
22
+ bool: 'boolean',
23
+ date: 'date',
24
+ datetime: 'date',
25
+ timestamp: 'date',
26
+ };
27
+ exports.JS_KEYWORDS = new Set(('arguments await break case catch class const continue debugger default delete do else enum eval ' +
28
+ 'export extends false finally for function if implements import in instanceof interface let new null ' +
29
+ 'package private protected public return static super switch this throw true try typeof var void while with yield').split(' '));
30
+ exports.SUPPORTED_TYPES_HELP = 'string, number, integer, boolean, date, or a list of values like "draft | sent | paid" — ' +
31
+ 'add "?" for optional ("notes?: string") and "= value" for a default ("paid: boolean = false")';
32
+ /** Splits on `separator` when it is not inside parentheses or quotes. */
33
+ function splitTopLevel(input, separator = ',') {
34
+ const parts = [];
35
+ let depth = 0;
36
+ let quote = null;
37
+ let current = '';
38
+ for (const char of input) {
39
+ if (quote) {
40
+ if (char === quote)
41
+ quote = null;
42
+ current += char;
43
+ continue;
44
+ }
45
+ if (char === '"' || char === "'")
46
+ quote = char;
47
+ if (char === '(')
48
+ depth += 1;
49
+ if (char === ')')
50
+ depth = Math.max(0, depth - 1);
51
+ if (char === separator && depth === 0 && !quote) {
52
+ parts.push(current);
53
+ current = '';
54
+ }
55
+ else {
56
+ current += char;
57
+ }
58
+ }
59
+ parts.push(current);
60
+ return parts.map((part) => part.trim()).filter(Boolean);
61
+ }
62
+ /** Index of the first `char` outside parentheses and quotes, or -1. */
63
+ function indexOfTopLevel(input, char) {
64
+ let depth = 0;
65
+ let quote = null;
66
+ for (let i = 0; i < input.length; i += 1) {
67
+ const c = input[i];
68
+ if (quote) {
69
+ if (c === quote)
70
+ quote = null;
71
+ continue;
72
+ }
73
+ if (c === '"' || c === "'")
74
+ quote = c;
75
+ else if (c === '(')
76
+ depth += 1;
77
+ else if (c === ')')
78
+ depth = Math.max(0, depth - 1);
79
+ else if (c === char && depth === 0)
80
+ return i;
81
+ }
82
+ return -1;
83
+ }
84
+ function fieldNames(raw) {
85
+ const words = (0, names_1.splitWords)(raw);
86
+ if (words.length === 0 || !/^[a-z]/.test(words[0]) || !/^[A-Za-z][A-Za-z0-9_-]*$/.test(raw.trim())) {
87
+ throw new errors_1.CliError(`Invalid field name "${raw}".`, 'Field names start with a letter, e.g. "clientId".');
88
+ }
89
+ const names = (0, names_1.namesFromWords)(words);
90
+ if (exports.JS_KEYWORDS.has(names.camel)) {
91
+ throw new errors_1.CliError(`"${names.camel}" is a JavaScript keyword and cannot be a field name.`);
92
+ }
93
+ return names;
94
+ }
95
+ function parseEnumValues(list, fieldName) {
96
+ const values = [...new Set(list.split('|').map((value) => value.trim()).filter(Boolean))];
97
+ if (values.length === 0) {
98
+ throw new errors_1.CliError(`Field "${fieldName}" needs at least one value, e.g. "status: draft | sent".`);
99
+ }
100
+ const bad = values.find((value) => !/^[A-Za-z][A-Za-z0-9_-]*$/.test(value));
101
+ if (bad) {
102
+ throw new errors_1.CliError(`Invalid value "${bad}" for field "${fieldName}".`, 'Values start with a letter and may contain letters, digits, "_" and "-".');
103
+ }
104
+ return values;
105
+ }
106
+ function unquote(value) {
107
+ const trimmed = value.trim();
108
+ if (trimmed.length >= 2 &&
109
+ ((trimmed.startsWith('"') && trimmed.endsWith('"')) || (trimmed.startsWith("'") && trimmed.endsWith("'")))) {
110
+ return trimmed.slice(1, -1);
111
+ }
112
+ return trimmed;
113
+ }
114
+ /** A literal for a field ("= value" in a model): null is allowed for optional fields. */
115
+ function parseLiteral(raw, field) {
116
+ if (raw.trim() === 'null') {
117
+ if (!field.optional)
118
+ throw new errors_1.CliError(`"${field.names.camel}" is required, so it cannot be set to null.`);
119
+ return null;
120
+ }
121
+ return parseDefault(raw, field);
122
+ }
123
+ function parseDefault(raw, field) {
124
+ const value = raw.trim();
125
+ const name = field.names.camel;
126
+ const fail = (expected) => {
127
+ throw new errors_1.CliError(`Invalid default "${value}" for field "${name}": expected ${expected}.`);
128
+ };
129
+ switch (field.type) {
130
+ case 'boolean':
131
+ if (value === 'true')
132
+ return true;
133
+ if (value === 'false')
134
+ return false;
135
+ return fail('true or false');
136
+ case 'number': {
137
+ const number = Number(value);
138
+ return value !== '' && Number.isFinite(number) ? number : fail('a number');
139
+ }
140
+ case 'integer': {
141
+ const number = Number(value);
142
+ return value !== '' && Number.isInteger(number) ? number : fail('a whole number');
143
+ }
144
+ case 'string': {
145
+ const text = unquote(value);
146
+ return text.trim() !== '' ? text : fail('a non-empty text');
147
+ }
148
+ case 'enum': {
149
+ const text = unquote(value);
150
+ return field.values.includes(text) ? text : fail(`one of ${field.values.join(', ')}`);
151
+ }
152
+ case 'date':
153
+ return value === 'now' ? { now: true } : fail('"now"');
154
+ }
155
+ }
156
+ /**
157
+ * Parses one field: "name[?]: type [= default]".
158
+ * Types: string number integer boolean date, "a | b | c" or "enum(a|b|c)".
159
+ */
160
+ function parseField(token, reserved = []) {
161
+ const colon = indexOfTopLevel(token, ':');
162
+ let rawName = (colon === -1 ? token : token.slice(0, colon)).trim();
163
+ let rest = colon === -1 ? 'string' : token.slice(colon + 1).trim();
164
+ let optional = false;
165
+ if (rawName.endsWith('?')) {
166
+ optional = true;
167
+ rawName = rawName.slice(0, -1).trim();
168
+ }
169
+ const names = fieldNames(rawName);
170
+ let rawDefault;
171
+ const equals = indexOfTopLevel(rest, '=');
172
+ if (equals !== -1) {
173
+ rawDefault = rest.slice(equals + 1).trim();
174
+ rest = rest.slice(0, equals).trim();
175
+ if (rawDefault === '')
176
+ throw new errors_1.CliError(`Missing default value after "=" for field "${names.camel}".`);
177
+ }
178
+ if (rest.endsWith('?')) {
179
+ optional = true;
180
+ rest = rest.slice(0, -1).trim();
181
+ }
182
+ let type;
183
+ let values = [];
184
+ const enumMatch = /^enum\s*\((.*)\)$/i.exec(rest);
185
+ if (enumMatch) {
186
+ type = 'enum';
187
+ values = parseEnumValues(enumMatch[1], names.camel);
188
+ }
189
+ else if (rest.includes('|')) {
190
+ type = 'enum';
191
+ values = parseEnumValues(rest, names.camel);
192
+ }
193
+ else {
194
+ const key = rest.toLowerCase();
195
+ if (!Object.hasOwn(TYPE_ALIASES, key)) {
196
+ throw new errors_1.CliError(`Unknown type "${rest}" for field "${names.camel}".`, `Supported: ${exports.SUPPORTED_TYPES_HELP}.`);
197
+ }
198
+ type = TYPE_ALIASES[key];
199
+ }
200
+ if (reserved.includes(names.camel)) {
201
+ throw new errors_1.CliError(`Field "${names.camel}" is managed by the generated code and cannot be declared.`, `Reserved names: ${reserved.join(', ')}.`);
202
+ }
203
+ const field = { names, type, optional, values };
204
+ if (rawDefault !== undefined) {
205
+ if (optional) {
206
+ throw new errors_1.CliError(`Field "${names.camel}" has a default, so it cannot also be optional ("?").`);
207
+ }
208
+ field.defaultValue = parseDefault(rawDefault, field);
209
+ }
210
+ return field;
211
+ }
212
+ /**
213
+ * Parses --fields "clientId:string, scheduledStart:date, notes?:string, status:enum(planned|done)".
214
+ * `reserved` lists names the target class already uses (id, createdAt, ...).
215
+ */
216
+ function parseFields(input, reserved = []) {
217
+ if (input === undefined || input.trim() === '')
218
+ return [];
219
+ const fields = [];
220
+ for (const token of splitTopLevel(input)) {
221
+ const field = parseField(token, reserved);
222
+ if (fields.some((existing) => existing.names.camel === field.names.camel)) {
223
+ throw new errors_1.CliError(`Field "${field.names.camel}" is declared twice.`);
224
+ }
225
+ fields.push(field);
226
+ }
227
+ return fields;
228
+ }
229
+ /** Fields that callers provide (state-machine fields are changed by commands only). */
230
+ const inputFields = (fields) => fields.filter((field) => !field.managed);
231
+ exports.inputFields = inputFields;
232
+ const hasDefault = (field) => field.defaultValue !== undefined;
233
+ exports.hasDefault = hasDefault;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Generated files contain marker comments (e.g. "// ddd-express:wiring"). New code is inserted
3
+ * right above them, so the CLI can keep editing a file safely after the developer changed it.
4
+ */
5
+ export declare const MARKERS: {
6
+ readonly imports: 'ddd-express:imports';
7
+ readonly wiring: 'ddd-express:wiring';
8
+ readonly contexts: 'ddd-express:contexts';
9
+ readonly behaviour: 'ddd-express:behaviour';
10
+ readonly useCases: 'ddd-express:use-cases';
11
+ readonly routes: 'ddd-express:routes';
12
+ };
13
+ export declare function hasMarker(content: string, marker: string): boolean;
14
+ /**
15
+ * Inserts `snippet` above the marker line.
16
+ * - gap "blank": the snippet is followed by an empty line (for multi-line blocks)
17
+ * - gap "none": the snippet joins the lines right above the marker; when an empty line
18
+ * separates them from the marker, it stays between the snippet and the marker
19
+ * Returns null when the marker is missing.
20
+ */
21
+ export declare function insertAboveMarker(content: string, marker: string, snippet: string, gap: 'blank' | 'none'): string | null;
22
+ /** Adds each import line above the imports marker unless the exact line is already present. */
23
+ export declare function addImports(content: string, imports: string[]): string | null;
24
+ /** Appends `line` to a file's content unless an identical line already exists. */
25
+ export declare function ensureLine(content: string, line: string): string;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MARKERS = void 0;
4
+ exports.hasMarker = hasMarker;
5
+ exports.insertAboveMarker = insertAboveMarker;
6
+ exports.addImports = addImports;
7
+ exports.ensureLine = ensureLine;
8
+ /**
9
+ * Generated files contain marker comments (e.g. "// ddd-express:wiring"). New code is inserted
10
+ * right above them, so the CLI can keep editing a file safely after the developer changed it.
11
+ */
12
+ exports.MARKERS = {
13
+ imports: 'ddd-express:imports',
14
+ wiring: 'ddd-express:wiring',
15
+ contexts: 'ddd-express:contexts',
16
+ behaviour: 'ddd-express:behaviour',
17
+ useCases: 'ddd-express:use-cases',
18
+ routes: 'ddd-express:routes',
19
+ };
20
+ function hasMarker(content, marker) {
21
+ return content.split('\n').some((line) => line.includes(marker));
22
+ }
23
+ /**
24
+ * Inserts `snippet` above the marker line.
25
+ * - gap "blank": the snippet is followed by an empty line (for multi-line blocks)
26
+ * - gap "none": the snippet joins the lines right above the marker; when an empty line
27
+ * separates them from the marker, it stays between the snippet and the marker
28
+ * Returns null when the marker is missing.
29
+ */
30
+ function insertAboveMarker(content, marker, snippet, gap) {
31
+ const lines = content.split('\n');
32
+ const index = lines.findIndex((line) => line.includes(marker));
33
+ if (index === -1)
34
+ return null;
35
+ const block = snippet.replace(/\n+$/, '').split('\n');
36
+ if (gap === 'blank') {
37
+ lines.splice(index, 0, ...block, '');
38
+ }
39
+ else {
40
+ const at = index > 0 && lines[index - 1].trim() === '' ? index - 1 : index;
41
+ lines.splice(at, 0, ...block);
42
+ }
43
+ return lines.join('\n');
44
+ }
45
+ /** Adds each import line above the imports marker unless the exact line is already present. */
46
+ function addImports(content, imports) {
47
+ const existing = new Set(content.split('\n').map((line) => line.trim()));
48
+ const missing = imports.filter((line) => !existing.has(line.trim()));
49
+ if (missing.length === 0)
50
+ return content;
51
+ return insertAboveMarker(content, exports.MARKERS.imports, missing.join('\n'), 'none');
52
+ }
53
+ /** Appends `line` to a file's content unless an identical line already exists. */
54
+ function ensureLine(content, line) {
55
+ const lines = content.split('\n').map((current) => current.trim());
56
+ if (lines.includes(line.trim()))
57
+ return content;
58
+ const base = content.length === 0 || content.endsWith('\n') ? content : `${content}\n`;
59
+ return `${base}${line}\n`;
60
+ }
@@ -0,0 +1,30 @@
1
+ /** One name in every casing the generated code needs. */
2
+ export interface Names {
3
+ /** lower-case words: ["medication", "task"] */
4
+ words: string[];
5
+ /** medication-task */
6
+ kebab: string;
7
+ /** MedicationTask */
8
+ pascal: string;
9
+ /** medicationTask */
10
+ camel: string;
11
+ /** MEDICATION_TASK */
12
+ constant: string;
13
+ /** medication task */
14
+ human: string;
15
+ }
16
+ /** Splits "MedicationTask", "medication-task", "medication_task" or "medication task" into words. */
17
+ export declare function splitWords(input: string): string[];
18
+ export declare function namesFromWords(words: string[]): Names;
19
+ /**
20
+ * Parses a user-given name. `what` is used in error messages ("module name", ...).
21
+ * `stripSuffix` removes a redundant suffix, e.g. "VisitCompletedEvent" → "VisitCompleted".
22
+ */
23
+ export declare function toNames(input: string | undefined, what: string, stripSuffix?: string[]): Names;
24
+ export declare function pluralizeWord(word: string): string;
25
+ export declare function pluralize(names: Names): Names;
26
+ /** Names the generated code itself uses; an aggregate/class with one of them would not compile. */
27
+ export declare const RESERVED_TYPE_NAMES: Set<string>;
28
+ export declare function assertNotReserved(names: Names, what: string): void;
29
+ /** True when an event name reads like a command instead of a fact that happened. */
30
+ export declare function readsLikeCommand(words: string[]): boolean;
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RESERVED_TYPE_NAMES = void 0;
4
+ exports.splitWords = splitWords;
5
+ exports.namesFromWords = namesFromWords;
6
+ exports.toNames = toNames;
7
+ exports.pluralizeWord = pluralizeWord;
8
+ exports.pluralize = pluralize;
9
+ exports.assertNotReserved = assertNotReserved;
10
+ exports.readsLikeCommand = readsLikeCommand;
11
+ const errors_1 = require("./errors");
12
+ /** Splits "MedicationTask", "medication-task", "medication_task" or "medication task" into words. */
13
+ function splitWords(input) {
14
+ return input
15
+ .trim()
16
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
17
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
18
+ .split(/[^A-Za-z0-9]+/)
19
+ .filter(Boolean)
20
+ .map((word) => word.toLowerCase());
21
+ }
22
+ const capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
23
+ function namesFromWords(words) {
24
+ return {
25
+ words,
26
+ kebab: words.join('-'),
27
+ pascal: words.map(capitalize).join(''),
28
+ camel: words[0] + words.slice(1).map(capitalize).join(''),
29
+ constant: words.join('_').toUpperCase(),
30
+ human: words.join(' '),
31
+ };
32
+ }
33
+ /**
34
+ * Parses a user-given name. `what` is used in error messages ("module name", ...).
35
+ * `stripSuffix` removes a redundant suffix, e.g. "VisitCompletedEvent" → "VisitCompleted".
36
+ */
37
+ function toNames(input, what, stripSuffix) {
38
+ if (!input || input.trim() === '') {
39
+ throw new errors_1.CliError(`Missing ${what}.`);
40
+ }
41
+ let words = splitWords(input);
42
+ if (stripSuffix && words.length > stripSuffix.length) {
43
+ const tail = words.slice(-stripSuffix.length).join(' ');
44
+ if (tail === stripSuffix.join(' '))
45
+ words = words.slice(0, -stripSuffix.length);
46
+ }
47
+ if (words.length === 0 || !/^[a-z]/.test(words[0])) {
48
+ throw new errors_1.CliError(`Invalid ${what}: "${input}".`, 'Use letters and digits, starting with a letter, e.g. "medication-task" or "MedicationTask".');
49
+ }
50
+ return namesFromWords(words);
51
+ }
52
+ // ---------------------------------------------------------------------------------------------
53
+ // Plurals (for routes and collection names). Only the last word is pluralized.
54
+ // ---------------------------------------------------------------------------------------------
55
+ const IRREGULAR = {
56
+ person: 'people',
57
+ child: 'children',
58
+ man: 'men',
59
+ woman: 'women',
60
+ mouse: 'mice',
61
+ goose: 'geese',
62
+ tooth: 'teeth',
63
+ foot: 'feet',
64
+ ox: 'oxen',
65
+ datum: 'data',
66
+ criterion: 'criteria',
67
+ phenomenon: 'phenomena',
68
+ analysis: 'analyses',
69
+ diagnosis: 'diagnoses',
70
+ thesis: 'theses',
71
+ crisis: 'crises',
72
+ leaf: 'leaves',
73
+ life: 'lives',
74
+ wife: 'wives',
75
+ knife: 'knives',
76
+ half: 'halves',
77
+ shelf: 'shelves',
78
+ wolf: 'wolves',
79
+ calf: 'calves',
80
+ thief: 'thieves',
81
+ hero: 'heroes',
82
+ potato: 'potatoes',
83
+ tomato: 'tomatoes',
84
+ echo: 'echoes',
85
+ quiz: 'quizzes',
86
+ index: 'indexes',
87
+ matrix: 'matrices',
88
+ vertex: 'vertices',
89
+ appendix: 'appendices',
90
+ };
91
+ const UNCOUNTABLE = new Set([
92
+ 'data',
93
+ 'equipment',
94
+ 'information',
95
+ 'news',
96
+ 'series',
97
+ 'species',
98
+ 'sheep',
99
+ 'fish',
100
+ 'staff',
101
+ 'feedback',
102
+ 'software',
103
+ 'hardware',
104
+ 'metadata',
105
+ 'personnel',
106
+ 'inventory',
107
+ ]);
108
+ function pluralizeWord(word) {
109
+ if (UNCOUNTABLE.has(word))
110
+ return word;
111
+ if (Object.hasOwn(IRREGULAR, word))
112
+ return IRREGULAR[word];
113
+ if (/(s|x|z|ch|sh)$/.test(word))
114
+ return `${word}es`;
115
+ if (/[^aeiou]y$/.test(word))
116
+ return `${word.slice(0, -1)}ies`;
117
+ return `${word}s`;
118
+ }
119
+ function pluralize(names) {
120
+ const words = [...names.words];
121
+ words[words.length - 1] = pluralizeWord(words[words.length - 1]);
122
+ return namesFromWords(words);
123
+ }
124
+ /** Names the generated code itself uses; an aggregate/class with one of them would not compile. */
125
+ exports.RESERVED_TYPE_NAMES = new Set([
126
+ 'AggregateRoot',
127
+ 'Array',
128
+ 'Boolean',
129
+ 'ConflictError',
130
+ 'Date',
131
+ 'DomainError',
132
+ 'DomainEvent',
133
+ 'Entity',
134
+ 'Error',
135
+ 'EventBus',
136
+ 'Express',
137
+ 'Guard',
138
+ 'InMemoryEventBus',
139
+ 'Map',
140
+ 'NotFoundError',
141
+ 'Number',
142
+ 'Object',
143
+ 'Page',
144
+ 'PageQuery',
145
+ 'Promise',
146
+ 'RecordingEventBus',
147
+ 'RequestBody',
148
+ 'Router',
149
+ 'Set',
150
+ 'String',
151
+ 'ValueObject',
152
+ ]);
153
+ function assertNotReserved(names, what) {
154
+ if (exports.RESERVED_TYPE_NAMES.has(names.pascal)) {
155
+ throw new errors_1.CliError(`"${names.pascal}" cannot be used as a ${what}: the generated code already uses that name.`, 'Pick a more specific name from your domain, e.g. "VisitPage" instead of "Page".');
156
+ }
157
+ }
158
+ /** Verbs people often use in event names by mistake ("OrderCreate", "CreateOrder" instead of "OrderCreated"). */
159
+ const PRESENT_TENSE_VERBS = new Set(('add approve assign book cancel change close complete create delete finish open pay place publish ' +
160
+ 'reject register remove schedule send ship start submit update').split(' '));
161
+ /** True when an event name reads like a command instead of a fact that happened. */
162
+ function readsLikeCommand(words) {
163
+ if (words.length === 0)
164
+ return false;
165
+ const first = words[0];
166
+ const last = words[words.length - 1];
167
+ return PRESENT_TENSE_VERBS.has(last) || last.endsWith('ing') || PRESENT_TENSE_VERBS.has(first);
168
+ }
@@ -0,0 +1,21 @@
1
+ /** Where the CLI writes. Tests pass their own to capture output. */
2
+ export interface Io {
3
+ out: (text: string) => void;
4
+ err: (text: string) => void;
5
+ color: boolean;
6
+ }
7
+ export declare function defaultIo(): Io;
8
+ declare const CODES: {
9
+ readonly bold: readonly [1, 22];
10
+ readonly dim: readonly [2, 22];
11
+ readonly red: readonly [31, 39];
12
+ readonly green: readonly [32, 39];
13
+ readonly yellow: readonly [33, 39];
14
+ readonly blue: readonly [34, 39];
15
+ readonly magenta: readonly [35, 39];
16
+ readonly cyan: readonly [36, 39];
17
+ readonly gray: readonly [90, 39];
18
+ };
19
+ export type Style = keyof typeof CODES;
20
+ export declare function paint(io: Io, style: Style, text: string): string;
21
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultIo = defaultIo;
4
+ exports.paint = paint;
5
+ function defaultIo() {
6
+ const color = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR && process.env.TERM !== 'dumb';
7
+ return {
8
+ out: (text) => process.stdout.write(`${text}\n`),
9
+ err: (text) => process.stderr.write(`${text}\n`),
10
+ color,
11
+ };
12
+ }
13
+ const CODES = {
14
+ bold: [1, 22],
15
+ dim: [2, 22],
16
+ red: [31, 39],
17
+ green: [32, 39],
18
+ yellow: [33, 39],
19
+ blue: [34, 39],
20
+ magenta: [35, 39],
21
+ cyan: [36, 39],
22
+ gray: [90, 39],
23
+ };
24
+ function paint(io, style, text) {
25
+ if (!io.color)
26
+ return text;
27
+ const [open, close] = CODES[style];
28
+ return `\u001b[${open}m${text}\u001b[${close}m`;
29
+ }