@sincpro/client-framework 2.8.0 → 2.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/dist/codegen/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
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.
|
|
6
6
|
*/
|
|
7
7
|
export type { Bindings, Metamodel, Operation, RestBinding, Schema, } from "./domain/metamodel.js";
|
|
8
|
-
export { CheckError, checkImports, type Place, placeOf, type Violation, violationOf, } from "./services/check.js";
|
|
8
|
+
export { CheckError, checkImports, type Place, placeOf, placeViolationOf, type Violation, violationOf, } from "./services/check.js";
|
|
9
9
|
export { clientFileOf } from "./services/client.js";
|
|
10
10
|
export { domainFilesOf } from "./services/domain.js";
|
|
11
11
|
export { entitiesFileOf } from "./services/entities.js";
|
package/dist/codegen/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CheckError, checkImports, placeOf, violationOf, } from "./services/check.js";
|
|
1
|
+
export { CheckError, checkImports, placeOf, placeViolationOf, violationOf, } from "./services/check.js";
|
|
2
2
|
export { clientFileOf } from "./services/client.js";
|
|
3
3
|
export { domainFilesOf } from "./services/domain.js";
|
|
4
4
|
export { entitiesFileOf } from "./services/entities.js";
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* | infrastructure | its own components |
|
|
15
15
|
* | components | composer, a router |
|
|
16
16
|
* | common | any bounded context |
|
|
17
|
-
* |
|
|
17
|
+
* | domain, services | another bounded context — it is injected (`infrastructure/dependencies`)|
|
|
18
|
+
* | any layer | another bounded context's insides — only its doors, where they are used |
|
|
18
19
|
* | entrypoints/ root | a bounded context's insides — only its doors (and `common`) |
|
|
19
20
|
* | entrypoints/<face>| another face's door: `index.ts` or its own (`sales/admin.ts`) |
|
|
20
21
|
*
|
|
@@ -42,8 +43,10 @@ export type Place = {
|
|
|
42
43
|
context: string;
|
|
43
44
|
layer: string | null;
|
|
44
45
|
index: boolean;
|
|
45
|
-
/** A file in the context's root is one of its doors: `index`, or a face's (`admin`). */
|
|
46
|
+
/** A file in the context's root is one of its doors: `index`, `react`, or a face's (`admin`). */
|
|
46
47
|
door: string | null;
|
|
48
|
+
/** Inside its `entrypoints/<face>/`: that face. */
|
|
49
|
+
face?: string;
|
|
47
50
|
}
|
|
48
51
|
/** An entrypoint, and the face of the application it belongs to (`entrypoints/admin/…`). */
|
|
49
52
|
| {
|
|
@@ -53,11 +56,20 @@ export type Place = {
|
|
|
53
56
|
kind: "other";
|
|
54
57
|
};
|
|
55
58
|
export declare function placeOf(path: string): Place;
|
|
59
|
+
/**
|
|
60
|
+
* Why a file may not be where it is, whatever it imports — said once per file, or nothing.
|
|
61
|
+
* `common` orchestrates nothing and nothing comes in through it: no services, no screens.
|
|
62
|
+
*/
|
|
63
|
+
export declare function placeViolationOf(from: Place): string | undefined;
|
|
56
64
|
/**
|
|
57
65
|
* Why `from` may not import `specifier`, which resolves to `to` (`null`: a package), or nothing
|
|
58
66
|
* when it may.
|
|
59
67
|
*/
|
|
60
|
-
export declare function violationOf(from: Place, specifier: string, to: Place | null
|
|
68
|
+
export declare function violationOf(from: Place, specifier: string, to: Place | null,
|
|
69
|
+
/** Only types are imported (`import type`): they decide nothing at run time. */
|
|
70
|
+
how?: {
|
|
71
|
+
typeOnly?: boolean;
|
|
72
|
+
}): string | undefined;
|
|
61
73
|
/** What stops the check before it starts: no root, no config, a config that does not parse. */
|
|
62
74
|
export declare class CheckError extends Error {
|
|
63
75
|
}
|
|
@@ -33,7 +33,15 @@ export function placeOf(path) {
|
|
|
33
33
|
const first = inside[0] ?? "";
|
|
34
34
|
const door = inside.length === 1 ? first.replace(SOURCE, "") : null;
|
|
35
35
|
const index = door === "index";
|
|
36
|
-
|
|
36
|
+
const face = first === "entrypoints" && inside.length > 2 ? inside[1] : undefined;
|
|
37
|
+
return {
|
|
38
|
+
kind: "context",
|
|
39
|
+
context,
|
|
40
|
+
layer: LAYERS.has(first) ? first : null,
|
|
41
|
+
index,
|
|
42
|
+
door,
|
|
43
|
+
...(face === undefined ? {} : { face }),
|
|
44
|
+
};
|
|
37
45
|
}
|
|
38
46
|
const REACT = /^(react|react-dom|react-native)(\/|$)/;
|
|
39
47
|
const DRAWING = /^@sincpro\/(web-ui|web-composer)(\/|$)/;
|
|
@@ -49,19 +57,38 @@ const NEVER_OWN = {
|
|
|
49
57
|
adapters: ["services", "components", "entrypoints"],
|
|
50
58
|
services: ["components", "entrypoints"],
|
|
51
59
|
infrastructure: ["components", "entrypoints"],
|
|
60
|
+
// A component is drawn by screens, never the other way: what a screen defines stays its own.
|
|
61
|
+
components: ["entrypoints"],
|
|
52
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* Why a file may not be where it is, whatever it imports — said once per file, or nothing.
|
|
65
|
+
* `common` orchestrates nothing and nothing comes in through it: no services, no screens.
|
|
66
|
+
*/
|
|
67
|
+
export function placeViolationOf(from) {
|
|
68
|
+
if (from.kind !== "context" || from.context !== "common")
|
|
69
|
+
return undefined;
|
|
70
|
+
if (from.layer === "entrypoints")
|
|
71
|
+
return "common holds no entrypoints: a screen is a bounded context's, a face's frame is entrypoints/<face>/";
|
|
72
|
+
if (from.layer === "services")
|
|
73
|
+
return "common holds no services: a use case is a bounded context's";
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
53
76
|
/**
|
|
54
77
|
* Why `from` may not import `specifier`, which resolves to `to` (`null`: a package), or nothing
|
|
55
78
|
* when it may.
|
|
56
79
|
*/
|
|
57
|
-
export function violationOf(from, specifier, to
|
|
80
|
+
export function violationOf(from, specifier, to,
|
|
81
|
+
/** Only types are imported (`import type`): they decide nothing at run time. */
|
|
82
|
+
how = {}) {
|
|
58
83
|
if (to === null) {
|
|
59
84
|
if (from.kind !== "context" || from.layer === null)
|
|
60
85
|
return undefined;
|
|
61
86
|
if (PLAIN.has(from.layer) &&
|
|
62
87
|
(REACT.test(specifier) || DRAWING.test(specifier) || SCREENS.test(specifier)))
|
|
63
88
|
return `${from.layer}/ is plain logic: it never imports a screen's library (React, web-ui, composer, web-framework but its core)`;
|
|
64
|
-
if (from.layer === "components" &&
|
|
89
|
+
if (from.layer === "components" &&
|
|
90
|
+
how.typeOnly !== true &&
|
|
91
|
+
(COMPOSER.test(specifier) || ROUTER.test(specifier)))
|
|
65
92
|
return "a component never decides where things open: no composer, no router";
|
|
66
93
|
return undefined;
|
|
67
94
|
}
|
|
@@ -76,7 +103,7 @@ export function violationOf(from, specifier, to) {
|
|
|
76
103
|
// index.ts, or the door of the face it belongs to (`sales/admin.ts` for `entrypoints/admin/`).
|
|
77
104
|
// Another face's door would bring that face's screens into this face's bundle.
|
|
78
105
|
if (from.kind !== "context") {
|
|
79
|
-
if (to.context === "common" || to.index)
|
|
106
|
+
if (to.context === "common" || to.index || to.door === "react")
|
|
80
107
|
return undefined;
|
|
81
108
|
if (to.door !== null) {
|
|
82
109
|
// A module that is neither a face nor a context (a helper, `main.tsx`) opens no face's door:
|
|
@@ -94,18 +121,32 @@ export function violationOf(from, specifier, to) {
|
|
|
94
121
|
return to.context === "common" ? undefined : "common never imports a bounded context";
|
|
95
122
|
if (to.context === "common")
|
|
96
123
|
return undefined;
|
|
124
|
+
// A door of the context: `index.ts` and `react.ts` never re-export a face — what a portal screen
|
|
125
|
+
// defines would reach the site through them —; a face's door re-exports its own face only.
|
|
126
|
+
if (to.context === from.context && from.door !== null && to.layer === "entrypoints") {
|
|
127
|
+
if (from.door === "index" || from.door === "react")
|
|
128
|
+
return `${from.door}.ts never re-exports a face: what it publishes lives in components/ (a face's screens go through its own door, <face>.ts)`;
|
|
129
|
+
if (to.face !== undefined && to.face !== from.door)
|
|
130
|
+
return `${from.door}.ts re-exports another face (${to.face}): a face's door holds its own face only`;
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
97
133
|
if (to.context === from.context) {
|
|
98
134
|
const never = from.layer === null ? undefined : NEVER_OWN[from.layer];
|
|
99
135
|
return to.layer !== null && never?.includes(to.layer) === true
|
|
100
136
|
? `${from.layer}/ never imports its own ${to.layer}/`
|
|
101
137
|
: undefined;
|
|
102
138
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
139
|
+
// Another context by its doors, where it is used: a file that only re-exports it says nothing.
|
|
140
|
+
if (!to.index && to.door !== "react")
|
|
141
|
+
return `a bounded context never imports another's insides («${to.context}»): only its doors, index.ts or react.ts`;
|
|
142
|
+
if (from.layer === null)
|
|
143
|
+
return `a door never re-exports another bounded context («${to.context}»): it publishes its own`;
|
|
144
|
+
if (INJECTED.includes(from.layer))
|
|
145
|
+
return `${from.layer}/ never names another bounded context («${to.context}»): it is injected (infrastructure/dependencies.ts)`;
|
|
146
|
+
return undefined;
|
|
108
147
|
}
|
|
148
|
+
/** What a context is and does: another context reaches it injected, never imported. */
|
|
149
|
+
const INJECTED = ["generated", "domain", "adapters", "services"];
|
|
109
150
|
function sources(root) {
|
|
110
151
|
const found = [];
|
|
111
152
|
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
@@ -173,7 +214,19 @@ export async function checkImports(root, options = {}) {
|
|
|
173
214
|
for (const file of sources(root)) {
|
|
174
215
|
const name = relative(root, file).split(sep).join("/");
|
|
175
216
|
const from = placeOf(name);
|
|
176
|
-
|
|
217
|
+
const source = readFileSync(file, "utf8");
|
|
218
|
+
// What a file imports only as types (`import type { … } from "x"`): a type opens nothing.
|
|
219
|
+
const asValues = new Set([
|
|
220
|
+
...source.matchAll(/^(?:import|export)\s+(?!type\b)[^;]*?from\s+["']([^"']+)["']/gms),
|
|
221
|
+
].map((m) => m[1]));
|
|
222
|
+
const typeOnly = new Set([...source.matchAll(/^import type [^;]*?from\s+["']([^"']+)["']/gms)]
|
|
223
|
+
.map((m) => m[1])
|
|
224
|
+
.filter((specifier) => !asValues.has(specifier)));
|
|
225
|
+
const misplaced = placeViolationOf(from);
|
|
226
|
+
if (misplaced !== undefined)
|
|
227
|
+
violations.push({ file: name, imports: "", why: misplaced });
|
|
228
|
+
for (const { fileName: specifier } of ts.preProcessFile(source, true, true)
|
|
229
|
+
.importedFiles) {
|
|
177
230
|
if (ASSET.test(specifier))
|
|
178
231
|
continue;
|
|
179
232
|
// The first config that finds it inside the application, else any that finds it.
|
|
@@ -205,7 +258,7 @@ export async function checkImports(root, options = {}) {
|
|
|
205
258
|
// A bounded context that is a package, named whole (`@acme/ventas`): its index.
|
|
206
259
|
if (to?.kind === "context" && BARE.test(specifier))
|
|
207
260
|
to = { ...to, index: true };
|
|
208
|
-
const why = violationOf(from, specifier, to);
|
|
261
|
+
const why = violationOf(from, specifier, to, { typeOnly: typeOnly.has(specifier) });
|
|
209
262
|
if (why !== undefined)
|
|
210
263
|
violations.push({ file: name, imports: specifier, why });
|
|
211
264
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/client-framework",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "The client side of sincpro_framework, for every platform: Feature and ApplicationService traced and reported by default, applications made of domains, and the typed client generated from a service's contract. No React, no DOM.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|