@autotelic/joggle 0.0.0-stage → 0.1.2

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.
Files changed (101) hide show
  1. package/JOGGLE.md +634 -0
  2. package/LICENSE +21 -0
  3. package/README.md +88 -2
  4. package/bin/joggle.js +6 -0
  5. package/dist/answer-store.js +305 -0
  6. package/dist/architecture.js +190 -0
  7. package/dist/ask.js +184 -0
  8. package/dist/astro.js +75 -0
  9. package/dist/atoms.js +76 -0
  10. package/dist/bundles.js +156 -0
  11. package/dist/calibration.js +60 -0
  12. package/dist/candidates.js +561 -0
  13. package/dist/canonical.js +24 -0
  14. package/dist/cascade.js +98 -0
  15. package/dist/check.js +854 -0
  16. package/dist/cluster.js +69 -0
  17. package/dist/config.js +195 -0
  18. package/dist/content-mappers.js +83 -0
  19. package/dist/decision.js +203 -0
  20. package/dist/fingerprint.js +61 -0
  21. package/dist/git.js +127 -0
  22. package/dist/gitignore.js +65 -0
  23. package/dist/glob.js +51 -0
  24. package/dist/imports.js +153 -0
  25. package/dist/jsonc.js +95 -0
  26. package/dist/main.js +630 -0
  27. package/dist/manifest.js +42 -0
  28. package/dist/meta.js +170 -0
  29. package/dist/moves.js +47 -0
  30. package/dist/operation.js +133 -0
  31. package/dist/parsecache.js +264 -0
  32. package/dist/plans.js +425 -0
  33. package/dist/plugin.js +71 -0
  34. package/dist/plugins.js +136 -0
  35. package/dist/policy.js +676 -0
  36. package/dist/presets/composition.js +32 -0
  37. package/dist/report.js +474 -0
  38. package/dist/reporting.js +132 -0
  39. package/dist/result.js +28 -0
  40. package/dist/roles.js +303 -0
  41. package/dist/rule.js +194 -0
  42. package/dist/rules/append-only-honoured.js +190 -0
  43. package/dist/rules/bundle-conformance.js +245 -0
  44. package/dist/rules/call-pattern.js +209 -0
  45. package/dist/rules/cluster-verdict.js +700 -0
  46. package/dist/rules/compose-types.js +250 -0
  47. package/dist/rules/data-error-as-outage.js +482 -0
  48. package/dist/rules/declared-staleness.js +242 -0
  49. package/dist/rules/dependency-fit.js +297 -0
  50. package/dist/rules/deviation-has-a-shape.js +225 -0
  51. package/dist/rules/doc-matches-code.js +191 -0
  52. package/dist/rules/duplicate-call-run.js +240 -0
  53. package/dist/rules/duplicate-implementation.js +89 -0
  54. package/dist/rules/duplicate-meaning.js +130 -0
  55. package/dist/rules/fact-or-derivation.js +202 -0
  56. package/dist/rules/field-type-drift.js +373 -0
  57. package/dist/rules/generic-carries-a-caller.js +198 -0
  58. package/dist/rules/hoist-to-domain.js +288 -0
  59. package/dist/rules/import-architecture.js +393 -0
  60. package/dist/rules/index.js +105 -0
  61. package/dist/rules/inferred-over-recorded.js +214 -0
  62. package/dist/rules/intent-drift.js +286 -0
  63. package/dist/rules/invariant-has-a-reconciler.js +190 -0
  64. package/dist/rules/language-drift.js +234 -0
  65. package/dist/rules/meaning-switched-by-flag.js +189 -0
  66. package/dist/rules/module-direction.js +231 -0
  67. package/dist/rules/name-as-address.js +216 -0
  68. package/dist/rules/name-the-primitive.js +203 -0
  69. package/dist/rules/naming-drift.js +218 -0
  70. package/dist/rules/nullability-drift.js +220 -0
  71. package/dist/rules/object-shape.js +280 -0
  72. package/dist/rules/one-concept-one-type.js +243 -0
  73. package/dist/rules/page-needs-composition.js +227 -0
  74. package/dist/rules/reimplemented-primitive.js +283 -0
  75. package/dist/rules/reversal.js +264 -0
  76. package/dist/rules/rule-judgment.js +252 -0
  77. package/dist/rules/schema-excludes-domain-value.js +190 -0
  78. package/dist/rules/shallow-module.js +204 -0
  79. package/dist/rules/single-path.js +237 -0
  80. package/dist/rules/structural-collapse.js +198 -0
  81. package/dist/rules/temporal-coupling.js +205 -0
  82. package/dist/rules/types-over-logic.js +198 -0
  83. package/dist/rules/unaccounted-drop.js +190 -0
  84. package/dist/rules/unbounded-default-read.js +227 -0
  85. package/dist/run-cache.js +132 -0
  86. package/dist/schema.js +285 -0
  87. package/dist/similarity.js +119 -0
  88. package/dist/source.js +30 -0
  89. package/dist/sql.js +34 -0
  90. package/dist/stages.js +39 -0
  91. package/dist/state.js +65 -0
  92. package/dist/testing.js +131 -0
  93. package/dist/tsconfig-scope.js +32 -0
  94. package/dist/tsgo.js +127 -0
  95. package/dist/typefacts.js +455 -0
  96. package/dist/typetrace.js +283 -0
  97. package/dist/verdict.js +65 -0
  98. package/dist/vocabulary.js +365 -0
  99. package/dist/workspace.js +1963 -0
  100. package/extensions/joggle.ts +454 -0
  101. package/package.json +85 -3
@@ -0,0 +1,455 @@
1
+ import { Effect, FileSystem, Path, Predicate, Result, Schema, SchemaParser } from "effect";
2
+ import { resolve } from "node:path";
3
+ import { API, TypeFlags } from "@typescript/native/unstable/async";
4
+ import { shortHash } from "./state.js";
5
+ /**
6
+ * Index node types by file and position.
7
+ *
8
+ * @param entries - what {@link typesAtPositions} returned.
9
+ * @returns a lookup a rule can call.
10
+ */
11
+ export const indexOfNodeTypes = (entries) => {
12
+ const byKey = new Map();
13
+ for (const entry of entries)
14
+ byKey.set(entry.file + "\u0000" + String(entry.position), entry.type);
15
+ return (file, position) => byKey.get(file + "\u0000" + String(position));
16
+ };
17
+ /**
18
+ * One program, one snapshot, closed whatever happens.
19
+ *
20
+ * `.finally`, not `try/finally`: the checker is a child process and it must be
21
+ * closed on the error path too, and `.finally` does not swallow the failure.
22
+ */
23
+ const withSnapshot = async (source, use) => {
24
+ const api = new API({ cwd: source.cwd });
25
+ // The identifier is a PATH, and it must be absolute: a relative one is not found.
26
+ const collect = async () => use(await api.updateSnapshot({ openProjects: [resolve(source.cwd, source.tsconfig)] }));
27
+ return await collect().finally(() => api.close());
28
+ };
29
+ /** The project that owns a file, or undefined when no tsconfig covers it. */
30
+ const projectOf = async (input) => input.snapshot.getDefaultProjectForFile(resolve(input.cwd, input.file));
31
+ /**
32
+ * Ask the checker for the type at each position, in one program.
33
+ *
34
+ * @param input - The project root, the tsconfig to open, and the positions.
35
+ * @returns The resolved entries, in request order, and how many positions the
36
+ * checker had no project or no type for.
37
+ */
38
+ export const typesAtPositions = async (input) => {
39
+ if (input.requests.length === 0)
40
+ return { found: [], unresolved: 0 };
41
+ return await withSnapshot(input, async (snapshot) => {
42
+ const found = [];
43
+ let unresolved = 0;
44
+ for (const request of input.requests) {
45
+ const project = await projectOf({ snapshot, cwd: input.cwd, file: request.file });
46
+ const type = project === undefined
47
+ ? undefined
48
+ : await project.checker.getTypeAtPosition(resolve(input.cwd, request.file), request.position);
49
+ if (project === undefined || type === undefined) {
50
+ unresolved += 1;
51
+ continue;
52
+ }
53
+ found.push({
54
+ file: request.file,
55
+ position: request.position,
56
+ type: await project.checker.typeToString(type),
57
+ });
58
+ }
59
+ return { found, unresolved };
60
+ });
61
+ };
62
+ /* -------------------------------------------------------------------------- */
63
+ /* A declaration's type (the fact layer rules read) */
64
+ /* -------------------------------------------------------------------------- */
65
+ /** One member of a resolved object type, and what the checker resolved it to. */
66
+ export const MemberFact = Schema.Struct({
67
+ name: Schema.String,
68
+ type: Schema.String,
69
+ /**
70
+ * The exact values a member allows, when its type is a union of literals.
71
+ *
72
+ * This is what separates one vocabulary written incompletely from two
73
+ * vocabularies that share a field name: `"admin" | "owner"` and
74
+ * `"admin" | "owner" | "viewer"` print alike enough to argue about, and their
75
+ * VALUES do not. Empty when any member is not a literal, because a half-read
76
+ * set is worse than none.
77
+ */
78
+ variants: Schema.Array(Schema.String),
79
+ });
80
+ /**
81
+ * What a declaration is, as the compiler sees it.
82
+ *
83
+ * `structural` is the part that makes identity a fact rather than a comparison of
84
+ * printed names: it is built from the members' OWN resolved types, sorted, so two
85
+ * differently named declarations with the same members have the same fingerprint
86
+ * and an alias never compares equal to its expansion by accident.
87
+ *
88
+ * `identicalGroup` is the proven version of the same statement: two declarations
89
+ * in one group are mutually assignable in both directions AND share the
90
+ * fingerprint. A fingerprint alone is not enough -- every `any` would share one --
91
+ * so a group is only assigned when the type has content and the checker agrees.
92
+ */
93
+ export const ResolvedType = Schema.Struct({
94
+ /** The checker's printed form, which keeps alias names. */
95
+ display: Schema.String,
96
+ /** Member-sorted `name:type` fingerprint, complete only when not truncated. */
97
+ structural: Schema.String,
98
+ /** The checker's own vocabulary: `Object`, `Union`, `Any`, `Conditional`, ... */
99
+ flags: Schema.Array(Schema.String),
100
+ members: Schema.Array(MemberFact),
101
+ /** Union members, printed, in the checker's order. */
102
+ variants: Schema.Array(Schema.String),
103
+ /** Base types of a class or interface, printed. */
104
+ bases: Schema.Array(Schema.String),
105
+ /** The alias this type was declared through, when the checker attributed one. */
106
+ alias: Schema.NullOr(Schema.String),
107
+ /** The literal's value, printed, when the type is a literal. */
108
+ value: Schema.NullOr(Schema.String),
109
+ /** A group id shared by declarations the compiler proves identical. */
110
+ identicalGroup: Schema.NullOr(Schema.String),
111
+ /** True when the member list was cut to the budget, so `structural` is partial. */
112
+ truncated: Schema.Boolean,
113
+ });
114
+ const FLAG_TABLE = [
115
+ ["Any", TypeFlags.Any],
116
+ ["Unknown", TypeFlags.Unknown],
117
+ ["Never", TypeFlags.Never],
118
+ ["Void", TypeFlags.Void],
119
+ ["Undefined", TypeFlags.Undefined],
120
+ ["Null", TypeFlags.Null],
121
+ ["String", TypeFlags.String],
122
+ ["Number", TypeFlags.Number],
123
+ ["Boolean", TypeFlags.Boolean],
124
+ ["BigInt", TypeFlags.BigInt],
125
+ ["ESSymbol", TypeFlags.ESSymbol],
126
+ ["StringLiteral", TypeFlags.StringLiteral],
127
+ ["NumberLiteral", TypeFlags.NumberLiteral],
128
+ ["BooleanLiteral", TypeFlags.BooleanLiteral],
129
+ ["BigIntLiteral", TypeFlags.BigIntLiteral],
130
+ ["TypeParameter", TypeFlags.TypeParameter],
131
+ ["Object", TypeFlags.Object],
132
+ ["Union", TypeFlags.Union],
133
+ ["Intersection", TypeFlags.Intersection],
134
+ ["IndexedAccess", TypeFlags.IndexedAccess],
135
+ ["Conditional", TypeFlags.Conditional],
136
+ ["TemplateLiteral", TypeFlags.TemplateLiteral],
137
+ ["NonPrimitive", TypeFlags.NonPrimitive],
138
+ ];
139
+ /**
140
+ * The flags that name one kind of type.
141
+ *
142
+ * A composite flag (`Literal`, `Primitive`, ...) is a union of other bits, so
143
+ * reporting it would label every literal twice. Only single-bit flags survive.
144
+ */
145
+ const FLAG_LABELS = FLAG_TABLE.filter((entry) => Predicate.isNumber(entry[1]) && entry[1] > 0 && (entry[1] & (entry[1] - 1)) === 0);
146
+ const labelsOf = (flags) => FLAG_LABELS.filter(([, bit]) => (flags & bit) !== 0).map(([label]) => label);
147
+ const squash = (value) => value.replace(/\s+/g, " ").trim();
148
+ /** The structural fingerprint of one resolved type. */
149
+ const structuralOf = (input) => {
150
+ if (input.flags.includes("Union") && input.variants.length > 0) {
151
+ const parts = [...input.variants].map(squash).sort((left, right) => left.localeCompare(right));
152
+ return "union(" + parts.join("|") + ")";
153
+ }
154
+ if (input.members.length > 0) {
155
+ const parts = [...input.members]
156
+ .map((member) => squash(member.name) + ":" + squash(member.type))
157
+ .sort((left, right) => left.localeCompare(right));
158
+ return "object{" + parts.join(";") + "}";
159
+ }
160
+ if (input.value !== null)
161
+ return "literal:" + input.value;
162
+ return "intrinsic:" + squash(input.display);
163
+ };
164
+ /** True when a fingerprint has content, so a group is not "every any is an any". */
165
+ const contentful = (facts) => !facts.truncated &&
166
+ !facts.flags.includes("Any") &&
167
+ !facts.flags.includes("Unknown") &&
168
+ (facts.members.length > 0 || facts.variants.length >= 2);
169
+ /** The facts of one declaration, with the group it was later placed in. */
170
+ const withGroup = (facts, identicalGroup) => ({
171
+ display: facts.display,
172
+ structural: facts.structural,
173
+ flags: facts.flags,
174
+ members: facts.members,
175
+ variants: facts.variants,
176
+ bases: facts.bases,
177
+ alias: facts.alias,
178
+ value: facts.value,
179
+ identicalGroup: identicalGroup === undefined ? null : identicalGroup,
180
+ truncated: facts.truncated,
181
+ });
182
+ /** One declaration, described. */
183
+ const describe = async (checker, type, budget, maxMembers) => {
184
+ const printed = async (value) => {
185
+ if (budget.strings >= budget.maxStrings)
186
+ return undefined;
187
+ budget.strings += 1;
188
+ return squash(await checker.typeToString(value));
189
+ };
190
+ const display = (await printed(type)) ?? "";
191
+ const flags = labelsOf(type.flags);
192
+ const aliasSymbol = await type.getAliasSymbol();
193
+ const alias = aliasSymbol === undefined ? null : aliasSymbol.name;
194
+ const literalValue = type.isLiteralType() ? String(type.value) : null;
195
+ let variants = [];
196
+ if (type.isUnionType()) {
197
+ const parts = (await type.getTypes()) ?? [];
198
+ variants = (await Promise.all(parts.map((part) => printed(part)))).filter((part) => part !== undefined);
199
+ }
200
+ let bases = [];
201
+ if (type.isClassOrInterface()) {
202
+ const parts = (await type.getBaseTypes()) ?? [];
203
+ bases = (await Promise.all(parts.map((part) => printed(part)))).filter((part) => part !== undefined);
204
+ }
205
+ const members = [];
206
+ let truncated = false;
207
+ if (type.isObjectType()) {
208
+ // An array is an object with ninety methods; its members are the runtime's,
209
+ // not the repository's, and printing them is how a tuple looks like a
210
+ // vocabulary.
211
+ const container = (await checker.isArrayType(type)) || (await checker.isTupleType(type));
212
+ if (!container) {
213
+ const symbols = await checker.getPropertiesOfType(type);
214
+ const kept = symbols.slice(0, maxMembers);
215
+ if (symbols.length > kept.length)
216
+ truncated = true;
217
+ const types = await checker.getTypeOfSymbol(kept);
218
+ for (const [index, symbol] of kept.entries()) {
219
+ const member = types[index];
220
+ const memberType = member === undefined ? undefined : await printed(member);
221
+ if (memberType === undefined || member === undefined) {
222
+ truncated = true;
223
+ continue;
224
+ }
225
+ // The value set, only when every alternative is a literal. A union of
226
+ // object types is not a vocabulary, and reporting its members as values
227
+ // would make two different sets look alike.
228
+ let variants = [];
229
+ if (member.isUnionType()) {
230
+ const parts = (await member.getTypes()) ?? [];
231
+ const literals = [];
232
+ let allLiteral = parts.length >= 2;
233
+ for (const part of parts) {
234
+ if (!part.isLiteralType()) {
235
+ allLiteral = false;
236
+ break;
237
+ }
238
+ const text = await printed(part);
239
+ if (text === undefined) {
240
+ allLiteral = false;
241
+ break;
242
+ }
243
+ literals.push(text);
244
+ }
245
+ if (allLiteral)
246
+ variants = literals;
247
+ }
248
+ members.push({ name: symbol.name, type: memberType, variants });
249
+ }
250
+ }
251
+ }
252
+ return {
253
+ display,
254
+ structural: structuralOf({ flags, display, members, variants, value: literalValue }),
255
+ flags,
256
+ members,
257
+ variants,
258
+ bases,
259
+ alias,
260
+ value: literalValue,
261
+ identicalGroup: null,
262
+ truncated,
263
+ };
264
+ };
265
+ /**
266
+ * What each declaration is, by the compiler's answer.
267
+ *
268
+ * One `getTypeAtPosition` call per file (the API takes a list), then one property
269
+ * walk per declaration. The expensive call is `typeToString`, so it is budgeted
270
+ * and the truncation is reported rather than hidden.
271
+ *
272
+ * @param input - the project, the tsconfig, and one request per declaration name.
273
+ * @returns the facts, how many positions had no type, and how many were cut.
274
+ */
275
+ export const resolveDeclarations = async (input) => {
276
+ if (input.requests.length === 0)
277
+ return { found: [], unresolved: 0, truncated: 0 };
278
+ const budget = { strings: 0, maxStrings: input.maxStrings };
279
+ return await withSnapshot(input, async (snapshot) => {
280
+ // Grouped by file, so the batch overload answers a whole file in one round
281
+ // trip instead of one per declaration.
282
+ const byFile = new Map();
283
+ for (const request of input.requests) {
284
+ const existing = byFile.get(request.file);
285
+ if (existing === undefined)
286
+ byFile.set(request.file, [request]);
287
+ else
288
+ existing.push(request);
289
+ }
290
+ const described = [];
291
+ let unresolved = 0;
292
+ for (const [file, requests] of byFile) {
293
+ const project = await projectOf({ snapshot, cwd: input.cwd, file });
294
+ if (project === undefined) {
295
+ unresolved += requests.length;
296
+ continue;
297
+ }
298
+ const positions = requests.map((request) => request.position);
299
+ const types = await project.checker.getTypeAtPosition(resolve(input.cwd, file), positions);
300
+ for (const [index, request] of requests.entries()) {
301
+ const type = types[index];
302
+ if (type === undefined) {
303
+ unresolved += 1;
304
+ continue;
305
+ }
306
+ described.push({
307
+ request,
308
+ checker: project.checker,
309
+ type,
310
+ facts: await describe(project.checker, type, budget, input.maxMembers),
311
+ });
312
+ }
313
+ }
314
+ // The groups, after every declaration is described. Same fingerprint first,
315
+ // then the checker has to agree in both directions -- a fingerprint of
316
+ // printed member types can collide where assignability cannot.
317
+ const byStructural = new Map();
318
+ for (const entry of described) {
319
+ if (!contentful(entry.facts))
320
+ continue;
321
+ const existing = byStructural.get(entry.facts.structural);
322
+ if (existing === undefined)
323
+ byStructural.set(entry.facts.structural, [entry]);
324
+ else
325
+ existing.push(entry);
326
+ }
327
+ let truncated = described.filter((entry) => entry.facts.truncated).length;
328
+ if (budget.strings >= budget.maxStrings)
329
+ truncated += 1;
330
+ const groupOf = new Map();
331
+ for (const [structural, group] of byStructural) {
332
+ if (group.length < 2)
333
+ continue;
334
+ const first = group[0];
335
+ if (first === undefined)
336
+ continue;
337
+ const checker = first.checker;
338
+ let identical = true;
339
+ for (const other of group.slice(1)) {
340
+ const forward = await checker.isTypeAssignableTo(first.type, other.type);
341
+ const backward = forward && (await checker.isTypeAssignableTo(other.type, first.type));
342
+ if (!backward) {
343
+ identical = false;
344
+ break;
345
+ }
346
+ }
347
+ if (!identical)
348
+ continue;
349
+ groupOf.set(structural, "g" + shortHash(structural));
350
+ }
351
+ return {
352
+ found: described.map((entry) => ({
353
+ file: entry.request.file,
354
+ position: entry.request.position,
355
+ facts: withGroup(entry.facts, groupOf.get(entry.facts.structural)),
356
+ })),
357
+ unresolved,
358
+ truncated,
359
+ };
360
+ });
361
+ };
362
+ /* -------------------------------------------------------------------------- */
363
+ /* Reading and caching */
364
+ /* -------------------------------------------------------------------------- */
365
+ /** Bumped when the shape of a fact changes: an old entry is not a hit. */
366
+ const DECLARATION_TYPES_VERSION = "2";
367
+ const CachedDeclaration = Schema.Struct({
368
+ file: Schema.String,
369
+ position: Schema.Number,
370
+ facts: ResolvedType,
371
+ });
372
+ const CachedFacts = Schema.Struct({
373
+ version: Schema.String,
374
+ tool: Schema.String,
375
+ manifest: Schema.String,
376
+ entries: Schema.Array(CachedDeclaration),
377
+ });
378
+ const decodeCache = SchemaParser.decodeUnknownResult(Schema.fromJsonString(CachedFacts));
379
+ /** The key a declaration's facts are looked up by: the file and the name offset. */
380
+ export const declarationKey = (file, position) => file + "\u0000" + String(position);
381
+ const emptyDeclarations = (issues) => ({
382
+ index: new Map(),
383
+ resolvedFrom: "none",
384
+ unresolved: 0,
385
+ truncated: 0,
386
+ issues,
387
+ });
388
+ /**
389
+ * Resolve every declaration's type, from the cache or from the checker.
390
+ *
391
+ * The cache key is the run manifest the caller already computed, because the
392
+ * facts depend on the whole program -- the compiler, the tsconfig, every file --
393
+ * and a manifest is content, not mtimes. An unchanged repository reuses the
394
+ * answer it already paid for; a changed one asks again.
395
+ */
396
+ export const loadDeclarationTypes = (input) => Effect.gen(function* () {
397
+ const fs = yield* FileSystem.FileSystem;
398
+ const path = yield* Path.Path;
399
+ if (input.requests.length === 0)
400
+ return emptyDeclarations([]);
401
+ const store = path.join(input.cacheDir, "declaration-types.json");
402
+ const exists = yield* Effect.orElseSucceed(fs.exists(store), () => false);
403
+ if (exists) {
404
+ const body = yield* Effect.orElseSucceed(fs.readFileString(store), () => "");
405
+ const decoded = decodeCache(body);
406
+ if (Result.isSuccess(decoded) &&
407
+ decoded.success.version === DECLARATION_TYPES_VERSION &&
408
+ decoded.success.tool === input.tool &&
409
+ decoded.success.manifest === input.manifest) {
410
+ const index = new Map();
411
+ for (const entry of decoded.success.entries) {
412
+ index.set(declarationKey(entry.file, entry.position), entry.facts);
413
+ }
414
+ return { index, resolvedFrom: "cache", unresolved: 0, truncated: 0, issues: [] };
415
+ }
416
+ }
417
+ const ran = yield* Effect.tryPromise(() => resolveDeclarations({
418
+ cwd: input.root,
419
+ tsconfig: input.tsconfig,
420
+ requests: input.requests,
421
+ maxMembers: input.maxMembers,
422
+ maxStrings: input.maxStrings,
423
+ })).pipe(Effect.map((result) => ({ ok: true, result })), Effect.orElseSucceed((error) => ({ ok: false, reason: String(error) })));
424
+ if (!ran.ok) {
425
+ return emptyDeclarations(["the checker could not resolve declaration types: " + ran.reason]);
426
+ }
427
+ const index = new Map();
428
+ for (const entry of ran.result.found) {
429
+ index.set(declarationKey(entry.file, entry.position), entry.facts);
430
+ }
431
+ // Only a run that resolved something is worth storing: an empty answer is a
432
+ // tsconfig that covers none of these files, and caching that would make the
433
+ // miss permanent.
434
+ if (ran.result.found.length > 0) {
435
+ const body = JSON.stringify({
436
+ version: DECLARATION_TYPES_VERSION,
437
+ tool: input.tool,
438
+ manifest: input.manifest,
439
+ entries: ran.result.found.map((entry) => ({
440
+ file: entry.file,
441
+ position: entry.position,
442
+ facts: entry.facts,
443
+ })),
444
+ });
445
+ yield* Effect.orElseSucceed(fs.makeDirectory(input.cacheDir, { recursive: true }), () => undefined);
446
+ yield* Effect.orElseSucceed(fs.writeFileString(store, body), () => undefined);
447
+ }
448
+ return {
449
+ index,
450
+ resolvedFrom: "checker",
451
+ unresolved: ran.result.unresolved,
452
+ truncated: ran.result.truncated,
453
+ issues: [],
454
+ };
455
+ });