@sincpro/client-framework 2.8.0 → 2.9.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";
|
|
@@ -42,8 +42,10 @@ export type Place = {
|
|
|
42
42
|
context: string;
|
|
43
43
|
layer: string | null;
|
|
44
44
|
index: boolean;
|
|
45
|
-
/** A file in the context's root is one of its doors: `index`, or a face's (`admin`). */
|
|
45
|
+
/** A file in the context's root is one of its doors: `index`, `react`, or a face's (`admin`). */
|
|
46
46
|
door: string | null;
|
|
47
|
+
/** Inside its `entrypoints/<face>/`: that face. */
|
|
48
|
+
face?: string;
|
|
47
49
|
}
|
|
48
50
|
/** An entrypoint, and the face of the application it belongs to (`entrypoints/admin/…`). */
|
|
49
51
|
| {
|
|
@@ -53,11 +55,20 @@ export type Place = {
|
|
|
53
55
|
kind: "other";
|
|
54
56
|
};
|
|
55
57
|
export declare function placeOf(path: string): Place;
|
|
58
|
+
/**
|
|
59
|
+
* Why a file may not be where it is, whatever it imports — said once per file, or nothing.
|
|
60
|
+
* `common` orchestrates nothing and nothing comes in through it: no services, no screens.
|
|
61
|
+
*/
|
|
62
|
+
export declare function placeViolationOf(from: Place): string | undefined;
|
|
56
63
|
/**
|
|
57
64
|
* Why `from` may not import `specifier`, which resolves to `to` (`null`: a package), or nothing
|
|
58
65
|
* when it may.
|
|
59
66
|
*/
|
|
60
|
-
export declare function violationOf(from: Place, specifier: string, to: Place | null
|
|
67
|
+
export declare function violationOf(from: Place, specifier: string, to: Place | null,
|
|
68
|
+
/** Only types are imported (`import type`): they decide nothing at run time. */
|
|
69
|
+
how?: {
|
|
70
|
+
typeOnly?: boolean;
|
|
71
|
+
}): string | undefined;
|
|
61
72
|
/** What stops the check before it starts: no root, no config, a config that does not parse. */
|
|
62
73
|
export declare class CheckError extends Error {
|
|
63
74
|
}
|
|
@@ -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,13 +121,22 @@ 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
|
-
if (to.index && from.layer === "infrastructure")
|
|
139
|
+
if ((to.index || to.door === "react") && from.layer === "infrastructure")
|
|
104
140
|
return undefined;
|
|
105
141
|
return to.index
|
|
106
142
|
? `another bounded context («${to.context}») is a dependency: added in infrastructure/, never imported here`
|
|
@@ -173,7 +209,19 @@ export async function checkImports(root, options = {}) {
|
|
|
173
209
|
for (const file of sources(root)) {
|
|
174
210
|
const name = relative(root, file).split(sep).join("/");
|
|
175
211
|
const from = placeOf(name);
|
|
176
|
-
|
|
212
|
+
const source = readFileSync(file, "utf8");
|
|
213
|
+
// What a file imports only as types (`import type { … } from "x"`): a type opens nothing.
|
|
214
|
+
const asValues = new Set([
|
|
215
|
+
...source.matchAll(/^(?:import|export)\s+(?!type\b)[^;]*?from\s+["']([^"']+)["']/gms),
|
|
216
|
+
].map((m) => m[1]));
|
|
217
|
+
const typeOnly = new Set([...source.matchAll(/^import type [^;]*?from\s+["']([^"']+)["']/gms)]
|
|
218
|
+
.map((m) => m[1])
|
|
219
|
+
.filter((specifier) => !asValues.has(specifier)));
|
|
220
|
+
const misplaced = placeViolationOf(from);
|
|
221
|
+
if (misplaced !== undefined)
|
|
222
|
+
violations.push({ file: name, imports: "", why: misplaced });
|
|
223
|
+
for (const { fileName: specifier } of ts.preProcessFile(source, true, true)
|
|
224
|
+
.importedFiles) {
|
|
177
225
|
if (ASSET.test(specifier))
|
|
178
226
|
continue;
|
|
179
227
|
// The first config that finds it inside the application, else any that finds it.
|
|
@@ -205,7 +253,7 @@ export async function checkImports(root, options = {}) {
|
|
|
205
253
|
// A bounded context that is a package, named whole (`@acme/ventas`): its index.
|
|
206
254
|
if (to?.kind === "context" && BARE.test(specifier))
|
|
207
255
|
to = { ...to, index: true };
|
|
208
|
-
const why = violationOf(from, specifier, to);
|
|
256
|
+
const why = violationOf(from, specifier, to, { typeOnly: typeOnly.has(specifier) });
|
|
209
257
|
if (why !== undefined)
|
|
210
258
|
violations.push({ file: name, imports: specifier, why });
|
|
211
259
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/client-framework",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.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",
|