@fabrika/check 0.9.0-dev.31 → 0.9.0-dev.33
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/package.json +6 -6
- package/src/check.ts +8 -7
- package/src/rules/structure.ts +9 -5
- package/types/src/rules/structure.d.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/check",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.33",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@babel/parser": "8.0.7",
|
|
55
|
-
"@fabrika/app": "0.9.0-dev.
|
|
56
|
-
"@fabrika/auth-core": "0.9.0-dev.
|
|
57
|
-
"@fabrika/db": "0.9.0-dev.
|
|
58
|
-
"@fabrika/operations-contract": "0.9.0-dev.
|
|
59
|
-
"@fabrika/platform-node": "0.9.0-dev.
|
|
55
|
+
"@fabrika/app": "0.9.0-dev.33",
|
|
56
|
+
"@fabrika/auth-core": "0.9.0-dev.33",
|
|
57
|
+
"@fabrika/db": "0.9.0-dev.33",
|
|
58
|
+
"@fabrika/operations-contract": "0.9.0-dev.33",
|
|
59
|
+
"@fabrika/platform-node": "0.9.0-dev.33",
|
|
60
60
|
"zod": "^3.25.76"
|
|
61
61
|
}
|
|
62
62
|
}
|
package/src/check.ts
CHANGED
|
@@ -330,14 +330,8 @@ export const checkApplication = async (input: CheckInput): Promise<Finding[]> =>
|
|
|
330
330
|
if (isToolModule(path)) checkToolModule(parsed.module, isGenerated, findings)
|
|
331
331
|
else checkSourceModule(parsed.module, isGenerated, referencesOfModule, mappings, tree.files, findings, dependent)
|
|
332
332
|
}
|
|
333
|
-
const structure = { files: tree.files, mappings, referencesOf: (path: string) => references.get(path) ?? [] }
|
|
334
|
-
for (const path of modules.keys()) {
|
|
335
|
-
checkStructureReferences(structure, structurePlace(path, path === GENERATED_ENTRY_FILE, generated.has(path)), reporter(path, findings))
|
|
336
|
-
}
|
|
337
|
-
findings.push(...checkSingleSliceQueries(structure, new Map([...modules].map(([path, module]) => [path, module.program]))))
|
|
338
|
-
|
|
339
333
|
// The contract rules read each module's shell slice: a colocated handler, and what only it uses, is application
|
|
340
|
-
// code, which the rules
|
|
334
|
+
// code, which the other rules check in full.
|
|
341
335
|
const shell = new Map([...modules].map(([path, module]) => [path, shellModule(module, tree.files.get(path) ?? '')]))
|
|
342
336
|
const graph = new ModuleGraph(new Map([...shell].map(([path, slice]) => [path, slice.module])))
|
|
343
337
|
const contract = graph.module(CONTRACT_FILE)
|
|
@@ -345,6 +339,13 @@ export const checkApplication = async (input: CheckInput): Promise<Finding[]> =>
|
|
|
345
339
|
const shellGraph = new Set(
|
|
346
340
|
[contract, tables].flatMap((entry) => (entry === undefined ? [] : contractModules(graph, entry))).map((module) => module.file),
|
|
347
341
|
)
|
|
342
|
+
|
|
343
|
+
const structure = { files: tree.files, mappings, referencesOf: (path: string) => references.get(path) ?? [], shellModules: shellGraph }
|
|
344
|
+
for (const path of modules.keys()) {
|
|
345
|
+
checkStructureReferences(structure, structurePlace(path, path === GENERATED_ENTRY_FILE, generated.has(path)), reporter(path, findings))
|
|
346
|
+
}
|
|
347
|
+
findings.push(...checkSingleSliceQueries(structure, new Map([...modules].map(([path, module]) => [path, module.program]))))
|
|
348
|
+
|
|
348
349
|
const literal = [
|
|
349
350
|
...[...shellGraph].flatMap((path) => shell.get(path)?.refusals ?? []),
|
|
350
351
|
...checkLiteralGraph([CONTRACT_FILE, TABLES_FILE], graph),
|
package/src/rules/structure.ts
CHANGED
|
@@ -75,6 +75,8 @@ export interface StructureGraph {
|
|
|
75
75
|
readonly files: ReadonlyMap<string, string>
|
|
76
76
|
readonly mappings: ImportMappings
|
|
77
77
|
readonly referencesOf: (path: string) => readonly ModuleReference[]
|
|
78
|
+
/** The shell graph: the modules the SPA build plugins load as their slices, without handlers. */
|
|
79
|
+
readonly shellModules: ReadonlySet<string>
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
interface Targets {
|
|
@@ -146,18 +148,20 @@ const SPA_PACKAGES: ReadonlySet<string> = new Set([
|
|
|
146
148
|
])
|
|
147
149
|
|
|
148
150
|
const SPA_ALLOWED =
|
|
149
|
-
'@fabrika/app/client, @fabrika/app/react, @fabrika/app/schema, @fabrika/ui, @fabrika/ui/challenge, fabrika.contract.ts, src/schemas.ts, modules under src/shared/ and modules under web/; a type-only import of anything else'
|
|
151
|
+
'@fabrika/app/client, @fabrika/app/react, @fabrika/app/schema, @fabrika/ui, @fabrika/ui/challenge, fabrika.contract.ts, the src/<slice>/endpoints.ts of a group fabrika.contract.ts mounts (for createGroupClient), src/schemas.ts, modules under src/shared/ and modules under web/; a type-only import of anything else'
|
|
150
152
|
|
|
151
153
|
const isSchemaModule = (path: string): boolean => path === SCHEMAS_FILE || path.startsWith(SCHEMAS_DIR)
|
|
152
154
|
|
|
153
155
|
const isSharedModule = (path: string): boolean => path.startsWith(SHARED_DIR)
|
|
154
156
|
|
|
155
157
|
/**
|
|
156
|
-
* The application modules a bundle of the SPA may load
|
|
157
|
-
*
|
|
158
|
+
* The application modules a bundle of the SPA may load. `fabrika.contract.ts` and a slice's `endpoints.ts` in the shell
|
|
159
|
+
* graph (a group client's group) are loaded without their handlers; an `endpoints.ts` outside it would load whole. A
|
|
160
|
+
* shared module is checked on its own (`checkSharedReference`), so it is not followed.
|
|
158
161
|
*/
|
|
159
|
-
const isSpaModule = (path: string): boolean =>
|
|
162
|
+
const isSpaModule = (graph: StructureGraph, path: string): boolean =>
|
|
160
163
|
path.startsWith(SPA_DIR) || path === CONTRACT_FILE || isSchemaModule(path) || isSharedModule(path) || !isSourceFile(path)
|
|
164
|
+
|| (slicePart(path) === 'endpoints' && graph.shellModules.has(path))
|
|
161
165
|
|
|
162
166
|
/** A runtime package the browser has not: the framework's server side, Bun, and Node's builtins in either spelling. */
|
|
163
167
|
const isServerPackage = (specifier: string): boolean => specifier.startsWith('@fabrika/') ? !SPA_PACKAGES.has(specifier) : isBuiltin(specifier)
|
|
@@ -169,7 +173,7 @@ const viaMessage = (reference: ModuleReference, loaded: string, what: string, in
|
|
|
169
173
|
/** The SPA's own modules are checked one by one; a schema module it loads is followed, since nothing else checks it. */
|
|
170
174
|
const checkSpaReference = (graph: StructureGraph, reference: ModuleReference, targets: Targets, report: Report): void => {
|
|
171
175
|
const reached = runtimeClosure(graph, targets, isSchemaModule)
|
|
172
|
-
const server = reached.packages.find(isServerPackage) ?? reached.files.find((path) => !isSpaModule(path))
|
|
176
|
+
const server = reached.packages.find(isServerPackage) ?? reached.files.find((path) => !isSpaModule(graph, path))
|
|
173
177
|
if (server !== undefined) report(reference.node, 'spa-server-import', viaMessage(reference, server, 'server code', 'the SPA'), SPA_ALLOWED)
|
|
174
178
|
}
|
|
175
179
|
|
|
@@ -21,6 +21,8 @@ export interface StructureGraph {
|
|
|
21
21
|
readonly files: ReadonlyMap<string, string>;
|
|
22
22
|
readonly mappings: ImportMappings;
|
|
23
23
|
readonly referencesOf: (path: string) => readonly ModuleReference[];
|
|
24
|
+
/** The shell graph: the modules the SPA build plugins load as their slices, without handlers. */
|
|
25
|
+
readonly shellModules: ReadonlySet<string>;
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* `single-slice-queries`: a function of `src/<a>/queries.ts` that exactly one other slice `src/<b>/` uses belongs in
|