@sincpro/client-framework 1.8.0 → 1.10.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 +67 -20
- package/dist/client/adapters/memory.d.ts +4 -0
- package/dist/client/adapters/memory.js +25 -21
- package/dist/client/adapters/rest.d.ts +4 -0
- package/dist/client/adapters/rest.js +5 -1
- package/dist/client/domain/changes.d.ts +45 -0
- package/dist/client/domain/changes.js +15 -0
- package/dist/client/index.d.ts +5 -2
- package/dist/client/index.js +5 -2
- package/dist/client/services/changes.d.ts +32 -0
- package/dist/client/services/changes.js +60 -0
- package/dist/codegen/domain/names.d.ts +10 -0
- package/dist/codegen/domain/names.js +13 -1
- package/dist/codegen/entrypoint/cli.js +28 -23
- package/dist/codegen/index.d.ts +5 -3
- package/dist/codegen/index.js +2 -1
- package/dist/codegen/services/domain.d.ts +18 -16
- package/dist/codegen/services/domain.js +140 -61
- package/dist/codegen/services/generated.d.ts +23 -0
- package/dist/codegen/services/generated.js +34 -0
- package/dist/codegen/services/scaffold.d.ts +3 -2
- package/dist/codegen/services/scaffold.js +5 -3
- package/dist/observability/adapters/console.d.ts +23 -2
- package/dist/observability/adapters/console.js +108 -17
- package/package.json +1 -1
package/dist/codegen/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The generator: a bounded context's
|
|
3
|
-
*
|
|
2
|
+
* The generator: a bounded context's types (entities and value objects, Commands and Responses,
|
|
3
|
+
* domain events), client and entities out of the client contract sincpro_framework exports
|
|
4
|
+
* (PRD_01 phase B), each file in its layer (`generatedFilesOf`). A build step that runs in Node — nothing in
|
|
4
5
|
* the runtime imports it (`make doctor`), and the package's root entry does not re-export it. `sincpro-client generate` (`cli.ts`) is the same, from a terminal.
|
|
5
6
|
*/
|
|
6
7
|
export type { Bindings, Metamodel, Operation, RestBinding, Schema, } from "./domain/metamodel.js";
|
|
7
8
|
export { CheckError, checkImports, type Place, placeOf, type Violation, violationOf, } from "./services/check.js";
|
|
8
9
|
export { clientFileOf } from "./services/client.js";
|
|
9
|
-
export {
|
|
10
|
+
export { domainFilesOf } from "./services/domain.js";
|
|
10
11
|
export { entitiesFileOf } from "./services/entities.js";
|
|
12
|
+
export { generatedFilesOf } from "./services/generated.js";
|
|
11
13
|
export type { GenerateOptions } from "./services/rest.js";
|
|
12
14
|
export { scaffoldFilesOf, type ScaffoldOptions, } from "./services/scaffold.js";
|
package/dist/codegen/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { CheckError, checkImports, placeOf, violationOf, } from "./services/check.js";
|
|
2
2
|
export { clientFileOf } from "./services/client.js";
|
|
3
|
-
export {
|
|
3
|
+
export { domainFilesOf } from "./services/domain.js";
|
|
4
4
|
export { entitiesFileOf } from "./services/entities.js";
|
|
5
|
+
export { generatedFilesOf } from "./services/generated.js";
|
|
5
6
|
export { scaffoldFilesOf, } from "./services/scaffold.js";
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import type { Metamodel } from "../domain/metamodel.js";
|
|
2
2
|
/**
|
|
3
|
-
* The TypeScript of every DTO of `metamodel`, as the
|
|
3
|
+
* The TypeScript of every DTO of `metamodel`, as the files of `domain/generated/`, by name.
|
|
4
4
|
*
|
|
5
|
-
* 1.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `<Name
|
|
9
|
-
*
|
|
10
|
-
* what a caller sends follows the contract's `required`;
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
5
|
+
* 1. `models.ts`: the models, by name — an entity's contract, a related model by its own name, a
|
|
6
|
+
* value an entity holds —, and the shared definitions they reach.
|
|
7
|
+
* 2. `commands.ts`: each operation, by its local name (its identity without `<context>.`): its
|
|
8
|
+
* input as `<Name>` and its answer by the backend's own name for it (`answerOf`: `ResponseX`) —
|
|
9
|
+
* or as `<Name>Answer` when it has no name. A model an input carries — and the ones it carries,
|
|
10
|
+
* until none is new — as `<Name>Input`: what a caller sends follows the contract's `required`;
|
|
11
|
+
* the server fills the rest. Then the definitions only they reach.
|
|
12
|
+
* 3. `events.ts`, when the contract carries events: each one by its class's name (`title`), a
|
|
13
|
+
* record as it is received — every field present, `name` its wire name as a literal —, and
|
|
14
|
+
* `DomainEvent`, the union of them all, which a `switch` on `name` narrows. Then the
|
|
15
|
+
* definitions only they reach.
|
|
16
|
+
* 4. `index.ts`: the files above, re-exported.
|
|
17
|
+
* Final: each file with a header that says where it came from and not to edit it, its imports —
|
|
18
|
+
* a package of the stack never typed twice (`Criteria`), a sibling's type imported from it —,
|
|
19
|
+
* then its types, each sorted by name; two of them with one TypeScript name, in any file, are
|
|
20
|
+
* refused, naming both.
|
|
19
21
|
*/
|
|
20
|
-
export declare function
|
|
22
|
+
export declare function domainFilesOf(metamodel: Metamodel): Record<string, string>;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import { aliasOf, answerOf, claimed, contextOf, deprecationOf, docOf, headerOf, identifierOf, keyOf, localOf, sorted, } from "../domain/names.js";
|
|
1
|
+
import { aliasOf, answerOf, claimed, contextOf, deprecationOf, docOf, headerOf, identifierOf, keyOf, localOf, siblingOf, sorted, } from "../domain/names.js";
|
|
2
2
|
/**
|
|
3
|
-
* The
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* The domain of a bounded context as TypeScript, out of the contract sincpro_framework exports —
|
|
4
|
+
* written in the files of `domain/generated/`, one per kind of thing, as the backend keeps them
|
|
5
|
+
* apart:
|
|
6
|
+
*
|
|
7
|
+
* models.ts its entities and value objects — the domain's own words
|
|
8
|
+
* commands.ts every operation's Command and Response, and the `<Name>Input` a caller
|
|
9
|
+
* sends — the application layer's
|
|
10
|
+
* events.ts its domain events and `DomainEvent`, their union — the facts (only when the
|
|
11
|
+
* contract carries them)
|
|
12
|
+
* index.ts the three, re-exported: what the adapters and an application import
|
|
13
|
+
*
|
|
14
|
+
* Only types — nothing in them runs.
|
|
7
15
|
*
|
|
8
16
|
* Context: types, never classes. The wire is JSON, and a type says exactly what it holds — a
|
|
9
17
|
* decimal as text, a page as `{items, count, cursor}` —, where a class would claim more unless
|
|
@@ -11,16 +19,21 @@ import { aliasOf, answerOf, claimed, contextOf, deprecationOf, docOf, headerOf,
|
|
|
11
19
|
* `Command` could be registered and executed locally, the confusion between a remote operation
|
|
12
20
|
* and a local use case this package keeps apart. Events read best as a union narrowed by `name`.
|
|
13
21
|
*
|
|
14
|
-
* Context: the
|
|
22
|
+
* Context: the files are a snapshot for whoever writes code — a person, or an agent reading the
|
|
15
23
|
* repository —, never the truth at runtime: the transport keeps reading the live definition and
|
|
16
|
-
* revalidates it by `model_version`. So
|
|
17
|
-
* key sorted, byte for byte, which is what `make verify-client` compares) and never
|
|
18
|
-
* application extends a type by composition (`Wire & {…}`).
|
|
24
|
+
* revalidates it by `model_version`. So they are written the same way for the same contract
|
|
25
|
+
* (every key sorted, byte for byte, which is what `make verify-client` compares) and never
|
|
26
|
+
* edited; an application extends a type by composition (`Wire & {…}`).
|
|
27
|
+
*
|
|
28
|
+
* A shared definition goes with the first kind that names it — the models, then the operations,
|
|
29
|
+
* then the events —, and a file that names one written elsewhere imports it from there. Every
|
|
30
|
+
* name is claimed once across the files: `index.ts` re-exports them side by side.
|
|
19
31
|
*
|
|
20
32
|
* criteria's grammar comes with every metamodel (`$defs.Criteria`); `@sincpro/criteria` already
|
|
21
33
|
* types it, so it is imported, never written a second time.
|
|
22
34
|
*
|
|
23
|
-
*
|
|
35
|
+
* domainFilesOf(JSON.parse(readFileSync("project.contract.json", "utf8")))
|
|
36
|
+
* -> { "models.ts": "…", "commands.ts": "…", "index.ts": "…" }
|
|
24
37
|
*/
|
|
25
38
|
const MODELS = "#/models/";
|
|
26
39
|
const DEFINITIONS = "#/$defs/";
|
|
@@ -63,6 +76,7 @@ function scopeOf(metamodel, shared, input = false) {
|
|
|
63
76
|
const scope = {
|
|
64
77
|
reached: shared?.reached ?? new Set(),
|
|
65
78
|
imports: shared?.imports ?? new Set(),
|
|
79
|
+
models: shared?.models ?? new Set(),
|
|
66
80
|
inputs: shared?.inputs ?? new Set(),
|
|
67
81
|
refer: (ref) => {
|
|
68
82
|
const model = ref.startsWith(MODELS);
|
|
@@ -73,8 +87,10 @@ function scopeOf(metamodel, shared, input = false) {
|
|
|
73
87
|
if (model || name in metamodel.models) {
|
|
74
88
|
if (!(name in metamodel.models))
|
|
75
89
|
throw new Error(`"${ref}" names no model of ${contextOf(metamodel)}`);
|
|
76
|
-
if (!input)
|
|
90
|
+
if (!input) {
|
|
91
|
+
scope.models.add(name);
|
|
77
92
|
return identifierOf(name);
|
|
93
|
+
}
|
|
78
94
|
scope.inputs.add(name);
|
|
79
95
|
return `${identifierOf(name)}Input`;
|
|
80
96
|
}
|
|
@@ -203,33 +219,86 @@ function eventDoc(metamodel, name, event) {
|
|
|
203
219
|
return docOf([event.description, `${facts.join(" · ")}.`], "");
|
|
204
220
|
}
|
|
205
221
|
/**
|
|
206
|
-
* The
|
|
207
|
-
*
|
|
208
|
-
* 1. The models, by name: an entity's contract, a related model by its own name.
|
|
209
|
-
* 2. Each operation, by its local name (its identity without `<context>.`): its input as
|
|
210
|
-
* `<Name>` and its answer by the backend's own name for it (`answerOf`: `ResponseX`) — or as
|
|
211
|
-
* `<Name>Answer` when it has no name.
|
|
212
|
-
* 3. A model an input carries — and the ones it carries, until none is new — as `<Name>Input`:
|
|
213
|
-
* what a caller sends follows the contract's `required`; the server fills the rest.
|
|
214
|
-
* 4. Each domain event, when the contract carries them, by its class's name (`title`): a record
|
|
215
|
-
* as it is received — every field present, `name` its wire name as a literal —, and
|
|
216
|
-
* `DomainEvent`, the union of them all, which a `switch` on `name` narrows.
|
|
217
|
-
* 5. The shared definitions those reach — and the ones those reach, until none is new —, but
|
|
218
|
-
* never one a package of the stack already types (`Criteria`).
|
|
219
|
-
* Final: a header that says where it came from and not to edit it, the imports, then models,
|
|
220
|
-
* definitions, operations and events, each sorted by name; two of them with one TypeScript
|
|
221
|
-
* name are refused, naming both.
|
|
222
|
+
* The shared definitions `scope` reaches that no other file writes (`elsewhere`) — and the ones
|
|
223
|
+
* those reach, until none is new —, each as its type, by name.
|
|
222
224
|
*/
|
|
223
|
-
|
|
224
|
-
const scope = scopeOf(metamodel);
|
|
225
|
-
const sent = scopeOf(metamodel, scope, true);
|
|
225
|
+
function definitionsOf(metamodel, scope, elsewhere) {
|
|
226
226
|
const definitions = metamodel.$defs ?? {};
|
|
227
|
+
const written = new Map();
|
|
228
|
+
const pending = () => [...scope.reached].filter((name) => !elsewhere.has(name) && !written.has(name));
|
|
229
|
+
for (let next = pending(); next.length > 0; next = pending()) {
|
|
230
|
+
for (const name of next) {
|
|
231
|
+
const schema = definitions[name];
|
|
232
|
+
written.set(name, `${docOf([schema.description], "")}export type ${identifierOf(name)} = ${typeOf(schema, scope, 0, false)};`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return written;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* A file's imports: one line per package of the stack, then one per sibling it names something
|
|
239
|
+
* of (`import type { Issue } from "./models"`), each with its names sorted.
|
|
240
|
+
*/
|
|
241
|
+
function importsOf(scope, siblings) {
|
|
242
|
+
const byPackage = new Map();
|
|
243
|
+
for (const name of [...scope.imports].sort()) {
|
|
244
|
+
const imported = IMPORTED[name];
|
|
245
|
+
byPackage.set(imported.from, [...(byPackage.get(imported.from) ?? []), imported.name]);
|
|
246
|
+
}
|
|
247
|
+
const packages = [...byPackage.keys()]
|
|
248
|
+
.sort()
|
|
249
|
+
.map((from) => `import type { ${byPackage.get(from).join(", ")} } from "${from}";`);
|
|
250
|
+
const own = siblings.flatMap(([file, names]) => {
|
|
251
|
+
const named = [...new Set([...names].map(identifierOf))].sort();
|
|
252
|
+
return named.length === 0
|
|
253
|
+
? []
|
|
254
|
+
: [`import type { ${named.join(", ")} } from "${siblingOf(file)}";`];
|
|
255
|
+
});
|
|
256
|
+
return [packages, own].filter((group) => group.length > 0).map((group) => group.join("\n"));
|
|
257
|
+
}
|
|
258
|
+
/** A file of `domain/generated/`: its header, its imports, then its types. */
|
|
259
|
+
function fileOf(header, imports, types) {
|
|
260
|
+
return `${[header, ...imports, ...types].join("\n\n")}\n`;
|
|
261
|
+
}
|
|
262
|
+
/** The written definitions, sorted by name, each name claimed. */
|
|
263
|
+
function claimedDefinitions(written, claim) {
|
|
264
|
+
return [...written.keys()].sort().map((name) => {
|
|
265
|
+
claim(identifierOf(name), `definition ${name}`);
|
|
266
|
+
return written.get(name);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The TypeScript of every DTO of `metamodel`, as the files of `domain/generated/`, by name.
|
|
271
|
+
*
|
|
272
|
+
* 1. `models.ts`: the models, by name — an entity's contract, a related model by its own name, a
|
|
273
|
+
* value an entity holds —, and the shared definitions they reach.
|
|
274
|
+
* 2. `commands.ts`: each operation, by its local name (its identity without `<context>.`): its
|
|
275
|
+
* input as `<Name>` and its answer by the backend's own name for it (`answerOf`: `ResponseX`) —
|
|
276
|
+
* or as `<Name>Answer` when it has no name. A model an input carries — and the ones it carries,
|
|
277
|
+
* until none is new — as `<Name>Input`: what a caller sends follows the contract's `required`;
|
|
278
|
+
* the server fills the rest. Then the definitions only they reach.
|
|
279
|
+
* 3. `events.ts`, when the contract carries events: each one by its class's name (`title`), a
|
|
280
|
+
* record as it is received — every field present, `name` its wire name as a literal —, and
|
|
281
|
+
* `DomainEvent`, the union of them all, which a `switch` on `name` narrows. Then the
|
|
282
|
+
* definitions only they reach.
|
|
283
|
+
* 4. `index.ts`: the files above, re-exported.
|
|
284
|
+
* Final: each file with a header that says where it came from and not to edit it, its imports —
|
|
285
|
+
* a package of the stack never typed twice (`Criteria`), a sibling's type imported from it —,
|
|
286
|
+
* then its types, each sorted by name; two of them with one TypeScript name, in any file, are
|
|
287
|
+
* refused, naming both.
|
|
288
|
+
*/
|
|
289
|
+
export function domainFilesOf(metamodel) {
|
|
227
290
|
const claim = claimed();
|
|
291
|
+
// 1. The entities and the values they hold.
|
|
292
|
+
const held = scopeOf(metamodel);
|
|
228
293
|
const models = sorted(metamodel.models).map(([name, schema]) => {
|
|
229
294
|
claim(identifierOf(name), `model ${name}`);
|
|
230
|
-
return `${docOf([schema.description], "")}export type ${identifierOf(name)} = ${typeOf(schema,
|
|
295
|
+
return `${docOf([schema.description], "")}export type ${identifierOf(name)} = ${typeOf(schema, held, 0, true)};`;
|
|
231
296
|
});
|
|
232
|
-
|
|
297
|
+
const heldDefinitions = definitionsOf(metamodel, held, new Set());
|
|
298
|
+
// 2. The operations. A Response two Commands share is written once, under the first that
|
|
299
|
+
// answers with it.
|
|
300
|
+
const answering = scopeOf(metamodel);
|
|
301
|
+
const sent = scopeOf(metamodel, answering, true);
|
|
233
302
|
const answered = new Set();
|
|
234
303
|
const operations = sorted(metamodel.operations).flatMap(([identity, operation]) => {
|
|
235
304
|
const local = localOf(metamodel, identity);
|
|
@@ -237,7 +306,8 @@ export function domainFileOf(metamodel) {
|
|
|
237
306
|
claim(local, `operation ${identity}`);
|
|
238
307
|
const answer = operation.output === null
|
|
239
308
|
? "unknown"
|
|
240
|
-
: (streamed(operation.output,
|
|
309
|
+
: (streamed(operation.output, answering) ??
|
|
310
|
+
typeOf(operation.output, answering, 0, false));
|
|
241
311
|
const written = [
|
|
242
312
|
`${operationDoc(metamodel, local, operation)}export type ${local} = ${typeOf(operation.input, sent, 0, false)};`,
|
|
243
313
|
];
|
|
@@ -248,58 +318,67 @@ export function domainFileOf(metamodel) {
|
|
|
248
318
|
}
|
|
249
319
|
return written;
|
|
250
320
|
});
|
|
251
|
-
// An event is a fact received whole: every field is there, as in a record a read
|
|
252
|
-
// event whose class is also a model — a context's base event, when a Feature
|
|
253
|
-
// that model's type, narrowed to its own name: one class, one type.
|
|
321
|
+
// 3. The events. An event is a fact received whole: every field is there, as in a record a read
|
|
322
|
+
// answers. An event whose class is also a model — a context's base event, when a Feature
|
|
323
|
+
// hears it — is that model's type, narrowed to its own name: one class, one type.
|
|
324
|
+
const heard = scopeOf(metamodel);
|
|
254
325
|
const members = [];
|
|
255
326
|
const events = sorted(metamodel.events ?? {}).flatMap(([name, event]) => {
|
|
256
327
|
const type = identifierOf(event.title);
|
|
257
328
|
if (event.title in metamodel.models) {
|
|
329
|
+
heard.models.add(event.title);
|
|
258
330
|
members.push(`(${type} & { name: ${JSON.stringify(name)} })`);
|
|
259
331
|
return [];
|
|
260
332
|
}
|
|
261
333
|
claim(type, `event ${name}`);
|
|
262
334
|
members.push(type);
|
|
263
335
|
return [
|
|
264
|
-
`${eventDoc(metamodel, name, event)}export type ${type} = ${typeOf(event.schema,
|
|
336
|
+
`${eventDoc(metamodel, name, event)}export type ${type} = ${typeOf(event.schema, heard, 0, true)};`,
|
|
265
337
|
];
|
|
266
338
|
});
|
|
267
339
|
if (members.length > 0) {
|
|
268
340
|
claim("DomainEvent", "the union of the domain events");
|
|
269
341
|
events.push(`${docOf([`Every domain event of «${aliasOf(metamodel)}» in the contract: a \`switch\` on \`name\` tells which.`], "")}export type DomainEvent =\n${members.map((one) => ` | ${one}`).join("\n")};`);
|
|
270
342
|
}
|
|
343
|
+
// What a caller sends of a model, and the models those carry, until none is new.
|
|
271
344
|
const inputs = new Map();
|
|
272
|
-
for (let pending = [...
|
|
345
|
+
for (let pending = [...answering.inputs]; pending.length > 0;) {
|
|
273
346
|
for (const name of pending) {
|
|
274
347
|
const schema = metamodel.models[name];
|
|
275
348
|
inputs.set(name, `${docOf([`What a caller sends of a \`${name}\`: what the contract requires; the server fills the rest.`], "")}export type ${identifierOf(name)}Input = ${typeOf(schema, sent, 0, false)};`);
|
|
276
349
|
}
|
|
277
|
-
pending = [...
|
|
350
|
+
pending = [...answering.inputs].filter((name) => !inputs.has(name));
|
|
278
351
|
}
|
|
279
352
|
const sentModels = [...inputs.keys()].sort().map((name) => {
|
|
280
353
|
claim(`${identifierOf(name)}Input`, `what a caller sends of model ${name}`);
|
|
281
354
|
return inputs.get(name);
|
|
282
355
|
});
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
356
|
+
// Each shared definition in the first file that names it: models, operations, events.
|
|
357
|
+
const inModels = new Set(heldDefinitions.keys());
|
|
358
|
+
const operationDefinitions = definitionsOf(metamodel, answering, inModels);
|
|
359
|
+
const inCommands = new Set(operationDefinitions.keys());
|
|
360
|
+
const eventDefinitions = definitionsOf(metamodel, heard, new Set([...inModels, ...inCommands]));
|
|
361
|
+
const ownModels = claimedDefinitions(heldDefinitions, claim);
|
|
362
|
+
const ownOperations = claimedDefinitions(operationDefinitions, claim);
|
|
363
|
+
const ownEvents = claimedDefinitions(eventDefinitions, claim);
|
|
364
|
+
/** What a file names that `models.ts` writes: models as records, and their definitions. */
|
|
365
|
+
const ofModels = (scope) => [
|
|
366
|
+
...scope.models,
|
|
367
|
+
...[...scope.reached].filter((name) => inModels.has(name)),
|
|
368
|
+
];
|
|
369
|
+
const files = {
|
|
370
|
+
"models.ts": fileOf(headerOf("The entities and value objects", metamodel), importsOf(held, []), [...models, ...ownModels]),
|
|
371
|
+
"commands.ts": fileOf(headerOf("The Commands and Responses", metamodel), importsOf(answering, [["models", ofModels(answering)]]), [...sentModels, ...ownOperations, ...operations]),
|
|
372
|
+
};
|
|
373
|
+
if (events.length > 0)
|
|
374
|
+
files["events.ts"] = fileOf(headerOf("The domain events", metamodel), importsOf(heard, [
|
|
375
|
+
["models", ofModels(heard)],
|
|
376
|
+
["commands", [...heard.reached].filter((name) => inCommands.has(name))],
|
|
377
|
+
]), [...ownEvents, ...events]);
|
|
378
|
+
files["index.ts"] = fileOf(headerOf("The domain", metamodel), [], [
|
|
379
|
+
Object.keys(files)
|
|
380
|
+
.map((file) => `export type * from "${siblingOf(file.replace(/.ts$/, ""))}";`)
|
|
381
|
+
.join("\n"),
|
|
382
|
+
]);
|
|
383
|
+
return files;
|
|
305
384
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Metamodel } from "../domain/metamodel.js";
|
|
2
|
+
import type { GenerateOptions } from "./rest.js";
|
|
3
|
+
/**
|
|
4
|
+
* Every file `sincpro-client generate` writes for a bounded context, by its path from the
|
|
5
|
+
* context's folder — each in the layer it belongs to, beside the application's own code of that
|
|
6
|
+
* layer:
|
|
7
|
+
*
|
|
8
|
+
* domain/generated/models.ts entities and value objects
|
|
9
|
+
* domain/generated/commands.ts Commands and Responses
|
|
10
|
+
* domain/generated/events.ts domain events (a contract exported with them)
|
|
11
|
+
* domain/generated/index.ts the three, re-exported
|
|
12
|
+
* adapters/generated/client.ts every operation, over any wire
|
|
13
|
+
* adapters/generated/entities.ts what screens list, read and edit
|
|
14
|
+
*
|
|
15
|
+
* Context: the backend keeps these apart — the domain's words, the application layer's DTOs, the
|
|
16
|
+
* facts, the adapters to another system —, and so does an application laid out like it. Written
|
|
17
|
+
* side by side, the application had to move them itself. A bare metamodel (`export_metamodel`,
|
|
18
|
+
* no bindings) is only a domain: no adapter is written.
|
|
19
|
+
*
|
|
20
|
+
* generatedFilesOf(project, { domain: "project", base: "/v1" })
|
|
21
|
+
* -> { "domain/generated/models.ts": "…", …, "adapters/generated/entities.ts": "…" }
|
|
22
|
+
*/
|
|
23
|
+
export declare function generatedFilesOf(metamodel: Metamodel, options?: GenerateOptions): Record<string, string>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { GENERATED_ADAPTERS, GENERATED_DOMAIN, } from "../domain/names.js";
|
|
2
|
+
import { clientFileOf } from "./client.js";
|
|
3
|
+
import { domainFilesOf } from "./domain.js";
|
|
4
|
+
import { entitiesFileOf } from "./entities.js";
|
|
5
|
+
/**
|
|
6
|
+
* Every file `sincpro-client generate` writes for a bounded context, by its path from the
|
|
7
|
+
* context's folder — each in the layer it belongs to, beside the application's own code of that
|
|
8
|
+
* layer:
|
|
9
|
+
*
|
|
10
|
+
* domain/generated/models.ts entities and value objects
|
|
11
|
+
* domain/generated/commands.ts Commands and Responses
|
|
12
|
+
* domain/generated/events.ts domain events (a contract exported with them)
|
|
13
|
+
* domain/generated/index.ts the three, re-exported
|
|
14
|
+
* adapters/generated/client.ts every operation, over any wire
|
|
15
|
+
* adapters/generated/entities.ts what screens list, read and edit
|
|
16
|
+
*
|
|
17
|
+
* Context: the backend keeps these apart — the domain's words, the application layer's DTOs, the
|
|
18
|
+
* facts, the adapters to another system —, and so does an application laid out like it. Written
|
|
19
|
+
* side by side, the application had to move them itself. A bare metamodel (`export_metamodel`,
|
|
20
|
+
* no bindings) is only a domain: no adapter is written.
|
|
21
|
+
*
|
|
22
|
+
* generatedFilesOf(project, { domain: "project", base: "/v1" })
|
|
23
|
+
* -> { "domain/generated/models.ts": "…", …, "adapters/generated/entities.ts": "…" }
|
|
24
|
+
*/
|
|
25
|
+
export function generatedFilesOf(metamodel, options = {}) {
|
|
26
|
+
const files = {};
|
|
27
|
+
for (const [name, source] of Object.entries(domainFilesOf(metamodel)))
|
|
28
|
+
files[`${GENERATED_DOMAIN}/${name}`] = source;
|
|
29
|
+
if (metamodel.bindings !== undefined) {
|
|
30
|
+
files[`${GENERATED_ADAPTERS}/client.ts`] = clientFileOf(metamodel, options);
|
|
31
|
+
files[`${GENERATED_ADAPTERS}/entities.ts`] = entitiesFileOf(metamodel, options);
|
|
32
|
+
}
|
|
33
|
+
return files;
|
|
34
|
+
}
|
|
@@ -4,7 +4,8 @@ import type { Metamodel } from "../domain/metamodel.js";
|
|
|
4
4
|
* application's from then on, laid out as the backend's (`sincpro_mcp_odoo/domains/helpdesk`):
|
|
5
5
|
*
|
|
6
6
|
* domains/project/
|
|
7
|
-
* generated/
|
|
7
|
+
* domain/generated/ `sincpro-client generate` — regenerated, never edited:
|
|
8
|
+
* adapters/generated/ its types, and its client and entities
|
|
8
9
|
* infrastructure/dependencies.ts what its services count on, and who supplies it
|
|
9
10
|
* infrastructure/framework.ts its Feature and ApplicationService — every dependency
|
|
10
11
|
* typed on `this` — and `projectBoundedContext`
|
|
@@ -16,7 +17,7 @@ import type { Metamodel } from "../domain/metamodel.js";
|
|
|
16
17
|
* imports it to register itself (`@projectBoundedContext.feature(Command)`), and ES modules run
|
|
17
18
|
* their imports first, so `index.ts` importing the services could not also define it. It is the
|
|
18
19
|
* application's to change: the CLI writes a file only when it is not there, and never touches one
|
|
19
|
-
* that is — unlike `generated
|
|
20
|
+
* that is — unlike the `generated/` folders, which are written whole every time.
|
|
20
21
|
*/
|
|
21
22
|
export type ScaffoldOptions = {
|
|
22
23
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { aliasOf, FRAMEWORK } from "../domain/names.js";
|
|
1
|
+
import { aliasOf, FRAMEWORK, GENERATED_ADAPTERS, GENERATED_DOMAIN, } from "../domain/names.js";
|
|
2
2
|
/** `sales-orders` → `SalesOrders`. */
|
|
3
3
|
function pascalOf(alias) {
|
|
4
4
|
const joined = alias
|
|
@@ -29,7 +29,9 @@ export function scaffoldFilesOf(metamodel, options = {}) {
|
|
|
29
29
|
"",
|
|
30
30
|
`import type { OperationTransport } from "${FRAMEWORK}";`,
|
|
31
31
|
`import type { BoundedContext } from "${at(FRAMEWORK, "core")}";`,
|
|
32
|
-
...(client
|
|
32
|
+
...(client
|
|
33
|
+
? ["", `import { clientOf } from "${at("..", GENERATED_ADAPTERS, "client")}";`]
|
|
34
|
+
: []),
|
|
33
35
|
"",
|
|
34
36
|
`/** What every service of «${alias}» finds on \`this\`${client ? ": `this.client`, the service's operations" : ""}. */`,
|
|
35
37
|
`export interface ${Dependencies} {`,
|
|
@@ -76,7 +78,7 @@ export function scaffoldFilesOf(metamodel, options = {}) {
|
|
|
76
78
|
"// with use cases of its own in a folder inside it). Each registers itself with",
|
|
77
79
|
`// \`@${name}.feature(CommandX)\` — or a list: \`@${name}.feature([CommandX, EventY])\` — and is`,
|
|
78
80
|
"// imported here, so it is registered before anyone executes. A generated DTO is a remote",
|
|
79
|
-
`// contract (a type): \`import type * as remote from "${at("..",
|
|
81
|
+
`// contract (a type): \`import type * as remote from "${at("..", GENERATED_DOMAIN)}"\`.`,
|
|
80
82
|
"export {};",
|
|
81
83
|
"",
|
|
82
84
|
].join("\n");
|
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
import { type LogFilter, type Logger } from "../domain/logging.js";
|
|
2
|
-
/**
|
|
1
|
+
import { type LogFilter, type Logger, type LogLevel, type LogRecord } from "../domain/logging.js";
|
|
2
|
+
/**
|
|
3
|
+
* Context: a development console is read by a person, a line at a glance. Each record is ONE
|
|
4
|
+
* line — its time, its level, its layer and use case, its message and the keys worth reading —,
|
|
5
|
+
* never the record object dumped after it, and a run's start and end read as `▶` / `✔` / `✖`.
|
|
6
|
+
* An unexpected failure still goes as an `Error` with its stack, because that is what React
|
|
7
|
+
* Native's LogBox, Expo's terminal and a browser print with a code frame. Production is silent.
|
|
8
|
+
*
|
|
9
|
+
* Colors are ANSI escape codes, and only the platform knows where its console renders them: a
|
|
10
|
+
* terminal and a browser's devtools do; React Native's LogBox, which shows WARN and ERROR in the
|
|
11
|
+
* app, prints them as text. So the platform names the levels to color (`colors`), and the line
|
|
12
|
+
* reads the same without them.
|
|
13
|
+
*/
|
|
14
|
+
/** The console's mode, which INFO and DEBUG lines it prints (`LogFilter`), and their colors. */
|
|
3
15
|
export type ConsoleLoggerOptions = LogFilter & {
|
|
4
16
|
readonly mode: "development" | "production";
|
|
17
|
+
/** The levels whose lines get ANSI colors: `true` every one, none unless said. */
|
|
18
|
+
readonly colors?: boolean | readonly LogLevel[];
|
|
5
19
|
};
|
|
20
|
+
/** One line for a person: time, level, layer, what happened, its keys, the run. */
|
|
21
|
+
export declare function prettyLine(record: LogRecord, colored?: boolean): string;
|
|
22
|
+
/**
|
|
23
|
+
* Built-in console engine: one readable line per record in development, silent in production;
|
|
24
|
+
* which INFO and DEBUG lines it prints is its own filter, WARN and ERROR always. Other sinks are
|
|
25
|
+
* filtered independently.
|
|
26
|
+
*/
|
|
6
27
|
export declare function consoleLogger(options: ConsoleLoggerOptions): Logger;
|