@fabrika/check 0.9.0-dev.32 → 0.9.0-dev.34

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/check",
3
- "version": "0.9.0-dev.32",
3
+ "version": "0.9.0-dev.34",
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.32",
56
- "@fabrika/auth-core": "0.9.0-dev.32",
57
- "@fabrika/db": "0.9.0-dev.32",
58
- "@fabrika/operations-contract": "0.9.0-dev.32",
59
- "@fabrika/platform-node": "0.9.0-dev.32",
55
+ "@fabrika/app": "0.9.0-dev.34",
56
+ "@fabrika/auth-core": "0.9.0-dev.34",
57
+ "@fabrika/db": "0.9.0-dev.34",
58
+ "@fabrika/operations-contract": "0.9.0-dev.34",
59
+ "@fabrika/platform-node": "0.9.0-dev.34",
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 above checked in full.
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),
@@ -154,6 +154,11 @@ const checkPackage = (reference: ModuleReference, specifier: string, report: Rep
154
154
  }
155
155
  const takesEnvironment = reference.names.some((imported) => imported === 'env' || imported === '*' || imported === 'default')
156
156
  if (name === 'process' && takesEnvironment && !isGeneratedEntry) report(node, 'env-read', `'${specifier}' loaded for its environment`, ALLOWED_ENV)
157
+ // On Cloudflare `env` of `cloudflare:workers` is every binding and secret of the Worker, the framework's included.
158
+ // The platform sets `disallow_importable_env`, which leaves it empty; an import of it is a read nonetheless.
159
+ if (specifier === 'cloudflare:workers' && takesEnvironment && !isGeneratedEntry) {
160
+ report(node, 'env-read', `'${specifier}' loaded for its environment, every binding of the Worker`, ALLOWED_ENV)
161
+ }
157
162
  }
158
163
 
159
164
  export const checkModuleReferences = (
@@ -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; `fabrika.contract.ts` is loaded without its handlers. A shared
157
- * module is checked on its own (`checkSharedReference`), so it is not followed.
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