@mark1russell7/canon-ontology 0.0.0-bootstrap.0 → 0.2.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.
@@ -0,0 +1,655 @@
1
+ import { Home, HomeAnswer } from "@mark1russell7/conventions";
2
+ import { A as TestGates, C as JsonSchema, D as Ontology, E as LoadedRecord, O as Problem, S as Grammar, T as KindMode, _ as EntityRecord, a as NecessaryGate, b as GateFact, c as SIZES, d as TargetRecord, f as compareTargets, g as EdgeRecord, h as Edge, i as NECESSARY_GATES, k as RelationKindDef, l as Size, m as targetsOf, n as Gap, o as ONTOLOGY_REPOSITORY, p as targetId, s as PLACES_SHOWN, t as Acceptance, u as TargetAttrs, v as Envelope, w as KindDef, x as GateName, y as FacetDef } from "./targets-DkEkvgll.mjs";
3
+ import { Printer } from "@mark1russell7/text/print";
4
+ import { Transport } from "polite-crawler/api";
5
+ import { RestClient } from "@procedures/gh";
6
+ /** The id of the record of kind source for the map of homes. */
7
+ export declare const MAP_SOURCE_ID = "source.conventions-map";
8
+ /** The id of the record of kind source for the lists of the public repositories of each owner on GitHub. */
9
+ export declare const GITHUB_SOURCE_ID = "source.github-repositories";
10
+ /** The ids of the sources of the import. The import writes each record of these sources, and removes the old ones. */
11
+ export declare const IMPORT_SOURCE_IDS: readonly string[];
12
+ /** A public repository of an owner, as GitHub gives it. */
13
+ interface PublicRepository {
14
+ readonly owner: string;
15
+ readonly name: string;
16
+ readonly url: string;
17
+ /** This text is the purpose of the repository, as its owner wrote it on GitHub. */
18
+ readonly description?: string | undefined;
19
+ /** This value is true for a fork of the repository of another account. */
20
+ readonly fork?: boolean | undefined;
21
+ /** This value is true for a repository that its owner archived. */
22
+ readonly archived?: boolean | undefined;
23
+ /** The default branch of the repository. The read of the test gates examines it. */
24
+ readonly defaultBranch?: string | undefined;
25
+ }
26
+ /** The facts of npm for one package name. */
27
+ interface NpmFact {
28
+ /** True when npm has a version of the package. */
29
+ readonly published: boolean;
30
+ /** The repository of the latest version, as `owner/name`, when its `package.json` names a repository on GitHub. */
31
+ readonly repository?: string;
32
+ }
33
+ /** The live facts that the import adds to the map: the public repositories and the facts of npm. */
34
+ interface HomeFacts {
35
+ /** Each public repository of each owner. A repository that is not here is private, or it does not exist. */
36
+ readonly repositories: readonly PublicRepository[];
37
+ /** The facts of npm for each package name of the map. */
38
+ readonly npm: ReadonlyMap<string, NpmFact>;
39
+ /** The version of `@mark1russell7/conventions` that has the map. */
40
+ readonly version: string;
41
+ /** The read of the duplication atlas. With no read, the import gives no candidate. */
42
+ readonly atlas?: AtlasRead | undefined;
43
+ }
44
+ /** The result of an import: the records, in the order of their ids, and a text for each home or repository that it left out. */
45
+ interface HomeImport {
46
+ readonly records: readonly EntityRecord[];
47
+ readonly skipped: readonly string[];
48
+ }
49
+ /**
50
+ * This function gives the public form of a text of the map. It removes the ids of roadmap items, because they mean
51
+ * nothing outside their repositories. The map itself keeps the ids.
52
+ *
53
+ * This function is a shortcut. It ends with the item C28 of `docs/ROADMAP.md`: when the notes of the map have no ids,
54
+ * the import stops this removal.
55
+ */
56
+ export declare function publicText(text: string): string;
57
+ /** This function gives the repository `owner/name` of a repository URL of npm, or undefined when it is not on GitHub. */
58
+ export declare function githubRepositoryOf(url: string): string | undefined;
59
+ /**
60
+ * This function makes the records of the ontology from the map of homes and the live facts. It reads nothing itself.
61
+ *
62
+ * - Each home gives a record of kind area, and its repository gives a record of kind repository with the relation home-of.
63
+ * - The import finds each repository under each owner, so a move between the owners does not wait on the map.
64
+ * - A repository that is not public is left out. A home whose repository is not public is left out, except a planned home:
65
+ * its repository is a record with `exists: false`.
66
+ * - Each package of the map gives a record of kind package. Its repository comes from npm when npm names one.
67
+ * - Each repository of `alsoIn` gives the relation holds-copy to the area: the code of the area moves between it and the home.
68
+ * - Each public repository that is not a fork and not archived gives a record of kind repository, also when the map does
69
+ * not name it. Its source is then the lists of GitHub. A repository record has the description of GitHub.
70
+ */
71
+ export declare function recordsFromHomes(homes: readonly Home[], facts: HomeFacts): HomeImport;
72
+ /** The URL of the data of the duplication atlas. */
73
+ export declare const ATLAS_URL = "https://metrograph-labs.github.io/codeatlas/data/atlas.json";
74
+ /** The id of the record of kind source for the duplication atlas. */
75
+ export declare const ATLAS_SOURCE_ID = "source.codeatlas";
76
+ /** The schema of the atlas that this reader knows. The reader refuses an atlas with a different schema. */
77
+ export declare const ATLAS_SCHEMA = "codeatlas/1";
78
+ /** The largest text of an atlas that the reader accepts, in characters. */
79
+ export declare const ATLAS_LIMIT: number;
80
+ /** A function of a repository that the atlas finds with the names of an area. */
81
+ interface AtlasCopy {
82
+ readonly repo: string;
83
+ readonly file: string;
84
+ readonly line: number;
85
+ readonly name: string;
86
+ }
87
+ /** The functions that the atlas finds for one area of the map of homes. */
88
+ interface AtlasRow {
89
+ readonly area: string;
90
+ readonly copies: readonly AtlasCopy[];
91
+ }
92
+ /** A repository that the atlas read, with its owner and the commit that it read. */
93
+ interface AtlasRepository {
94
+ readonly repo: string;
95
+ readonly owner: string;
96
+ readonly commit: string;
97
+ }
98
+ /** A class of cloned code: functions with the same shape in two or more places. */
99
+ interface AtlasClass {
100
+ /** The count of syntax nodes of one copy. */
101
+ readonly nodes: number;
102
+ /** The areas of the map of homes that the atlas finds for the class. */
103
+ readonly areas: readonly string[];
104
+ /** The copies. A function of a test file is not a copy. A function with no name has the name `<anonymous>`. */
105
+ readonly members: readonly AtlasCopy[];
106
+ }
107
+ /** The parts of the atlas that canon uses. */
108
+ interface Atlas {
109
+ readonly repositories: readonly AtlasRepository[];
110
+ readonly rows: readonly AtlasRow[];
111
+ readonly classes: readonly AtlasClass[];
112
+ }
113
+ /** The result of a read of the atlas: the atlas, or the reason that the import cannot use it. */
114
+ type AtlasRead = {
115
+ readonly atlas: Atlas;
116
+ } | {
117
+ readonly error: string;
118
+ };
119
+ /** The result of the atlas import: the records of kind candidate and the source, and a text for each copy that it left out. */
120
+ interface AtlasImport {
121
+ readonly records: readonly EntityRecord[];
122
+ readonly skipped: readonly string[];
123
+ }
124
+ /**
125
+ * This function reads the answer of the fetch of the atlas. It gives an error for a failed fetch, a text of more than
126
+ * `limit` characters and a text that is not JSON. A schema that is not `ATLAS_SCHEMA` also gives an error. It drops each
127
+ * row with a bad field. An atlas with no list of classes has no classes.
128
+ */
129
+ export declare function readAtlas(answer: HomeAnswer | undefined, limit?: number): AtlasRead;
130
+ /**
131
+ * This function makes a record of kind candidate for each pair of a repository and an area that the atlas finds. It
132
+ * reads nothing itself.
133
+ *
134
+ * - The import finds each repository of the atlas under its owner, or under the one owner that has a repository of that
135
+ * name. It leaves out a name of two owners, a fork, an archived repository and a repository that is not public.
136
+ * - It leaves out an area that the map of homes does not have, and the repositories that hold the own code of the area.
137
+ * - Each candidate has the commit that the atlas read, and each place once, in the order of the file and the line.
138
+ */
139
+ export declare function recordsFromAtlas(atlas: Atlas, repositories: readonly PublicRepository[], mapRecords: readonly EntityRecord[]): AtlasImport;
140
+ /** The label of each issue of the board. */
141
+ export declare const TARGET_LABEL = "target";
142
+ /** The time of a claim with no pull request, in hours. */
143
+ export declare const CLAIM_HOURS = 48;
144
+ /** The most open issues of the board. */
145
+ export declare const BOARD_LIMIT = 20;
146
+ /** An issue of the board, as the API of the issues gives it. */
147
+ interface BoardIssue {
148
+ readonly number: number;
149
+ readonly title: string;
150
+ readonly body: string;
151
+ readonly state: "open" | "closed";
152
+ readonly labels: readonly string[];
153
+ readonly assignees: readonly string[];
154
+ /** This time is the start of the claim of an open issue with an assignee, in milliseconds since 1970. */
155
+ readonly claimedAt?: number | undefined;
156
+ }
157
+ /** The title, the body and the labels of the issue of a target. */
158
+ interface IssueText {
159
+ readonly title: string;
160
+ readonly body: string;
161
+ readonly labels: readonly string[];
162
+ }
163
+ /** A change of an issue. Each field that is not here does not change. */
164
+ interface IssueChange {
165
+ readonly title?: string;
166
+ readonly body?: string;
167
+ readonly labels?: readonly string[];
168
+ readonly state?: "open" | "closed";
169
+ readonly stateReason?: "completed" | "not_planned" | "reopened";
170
+ /** This list replaces the assignees of the issue. */
171
+ readonly assignees?: readonly string[];
172
+ }
173
+ /** The API of the issues of one repository. A test gives a fake, and `githubIssueApi` gives the API of GitHub. */
174
+ interface IssueApi {
175
+ /** This method gives each issue with the label `target`, open and closed, with the start of each claim. */
176
+ issues(): Promise<readonly BoardIssue[]>;
177
+ /** This method tells if an open pull request names the target id. */
178
+ hasOpenPull(targetId: string): Promise<boolean>;
179
+ /** This method makes each label that does not exist. */
180
+ ensureLabels(names: readonly string[]): Promise<void>;
181
+ /** This method opens an issue, and gives its number. */
182
+ create(text: IssueText): Promise<number>;
183
+ /** This method changes an issue, and gives the issue after the change. */
184
+ update(number: number, change: IssueChange): Promise<BoardIssue>;
185
+ /** This method writes a comment on an issue. */
186
+ comment(number: number, text: string): Promise<void>;
187
+ }
188
+ /** One step of the sync of the board. */
189
+ type BoardAction = {
190
+ readonly kind: "create";
191
+ readonly target: string;
192
+ readonly text: IssueText;
193
+ } | {
194
+ readonly kind: "update";
195
+ readonly number: number;
196
+ readonly target: string;
197
+ readonly text: IssueText;
198
+ readonly reopen: boolean;
199
+ } | {
200
+ readonly kind: "close";
201
+ readonly number: number;
202
+ readonly target: string;
203
+ readonly reason: "completed" | "not_planned";
204
+ } | {
205
+ readonly kind: "release";
206
+ readonly number: number;
207
+ readonly target: string;
208
+ readonly users: readonly string[];
209
+ };
210
+ /** The inputs of the plan of the board. */
211
+ interface BoardInput {
212
+ /** Each target of the target query, in the order of `compareTargets`. */
213
+ readonly targets: readonly TargetRecord[];
214
+ readonly issues: readonly BoardIssue[];
215
+ /** This time is the time of the decision, in milliseconds since 1970. */
216
+ readonly now: number;
217
+ /** The ids of the targets that an open pull request names. */
218
+ readonly pulls: ReadonlySet<string>;
219
+ /** The most open issues. The default is `BOARD_LIMIT`. */
220
+ readonly limit?: number | undefined;
221
+ }
222
+ /** This function gives the id of the target of an issue body, or undefined when the body has no hidden line. */
223
+ export declare function targetOfIssue(body: string): string | undefined;
224
+ /** This function gives the time of the end of a claim, as an ISO 8601 text to the minute. */
225
+ export declare function claimEnd(claimedAt: number): string;
226
+ /** This function tells if a claim is older than `CLAIM_HOURS`. A claim with no known start is live. */
227
+ export declare function isExpired(issue: BoardIssue, now: number): boolean;
228
+ /** This function gives the title, the body and the labels of the issue of a target. */
229
+ export declare function issueText(target: TargetRecord, repository?: string): IssueText;
230
+ /**
231
+ * This function gives the steps that make the board agree with the target query.
232
+ *
233
+ * - The board keeps the open issue of each claimable target. It adds other claimable targets, up to the limit. An issue
234
+ * does not close because new targets come before it.
235
+ * - Each added target is the first claimable target of the gap with the fewest targets on the board. So one gap with
236
+ * many targets does not fill the board.
237
+ * - An issue whose target is not claimable closes: `completed` when the target is gone, else `not_planned`.
238
+ * - A claim older than `CLAIM_HOURS` stops when no open pull request names its target.
239
+ * - An issue with no hidden line is not an issue of the board. Of two issues of one target, the board uses the first.
240
+ */
241
+ export declare function planBoard(input: BoardInput): readonly BoardAction[];
242
+ /** The comment of a step of the board, or undefined for a step with no comment. */
243
+ export declare function actionComment(action: BoardAction): string | undefined;
244
+ /** This function applies the steps of the board through the API, in their order. It gives the number of each new issue. */
245
+ export declare function applyBoard(api: IssueApi, actions: readonly BoardAction[]): Promise<readonly number[]>;
246
+ /** The command of a claim comment. */
247
+ type ClaimCommand = "claim" | "unclaim";
248
+ /** This function gives the command of a comment: its first word is `/claim` or `/unclaim`. */
249
+ export declare function claimCommandOf(comment: string): ClaimCommand | undefined;
250
+ /** The inputs of the decision on a claim comment. */
251
+ interface ClaimInput {
252
+ readonly command: ClaimCommand;
253
+ /** The login of the author of the comment. */
254
+ readonly user: string;
255
+ readonly issue: BoardIssue;
256
+ /** The target of the issue, or undefined when the target query does not give it. */
257
+ readonly target: TargetRecord | undefined;
258
+ /** Each issue of the board, with the start of each claim. */
259
+ readonly issues: readonly BoardIssue[];
260
+ /** This time is the time of the decision, in milliseconds since 1970. */
261
+ readonly now: number;
262
+ }
263
+ /** The decision on a claim comment: the new assignees and a comment, or a refusal with its reason. */
264
+ type ClaimDecision = {
265
+ readonly kind: "set";
266
+ readonly assignees: readonly string[];
267
+ readonly comment: string;
268
+ } | {
269
+ readonly kind: "refuse";
270
+ readonly comment: string;
271
+ };
272
+ /**
273
+ * This function decides a claim comment. A contributor claims one target at a time, and a claim stops after
274
+ * `CLAIM_HOURS` with no pull request. A claim that stopped does not block a new claim, also before the board removes it.
275
+ */
276
+ export declare function decideClaim(input: ClaimInput): ClaimDecision;
277
+ /**
278
+ * This function checks the ontology, and gives each problem that it finds, in the order of the paths. No problem means
279
+ * that the data is valid:
280
+ *
281
+ * - The grammar is valid: unique names, known parents and ends, keys of known parts and schemas that compile.
282
+ * - Each record file agrees with `schema/record.schema.json`, and its attributes agree with the schema of its kind.
283
+ * - The id of each record starts with its kind, its file is at the path of its id, and no two records have one id.
284
+ * - Each relation has a relation kind that is not abstract, ends of the correct kinds, and correct qualifiers.
285
+ * - No two live relations of a kind have the same key. For example, an area has at most one home.
286
+ * - Each id of an envelope names a record, and each source is a record of kind source.
287
+ */
288
+ export declare function checkOntology(ontology: Ontology): readonly Problem[];
289
+ /** The fewest copied syntax nodes of a class in the report. A smaller class is too small for a home. */
290
+ export declare const CLONE_FLOOR = 200;
291
+ /** A copy of a class of cloned code, in a repository of the records. */
292
+ interface CloneMember {
293
+ /** The id of the record of the repository. */
294
+ readonly repository: string;
295
+ readonly file: string;
296
+ readonly line: number;
297
+ /** The name of the function, or `<anonymous>`. */
298
+ readonly name: string;
299
+ }
300
+ /** A class of cloned code that no area of the map of homes covers. */
301
+ interface CloneClass {
302
+ /** The syntax nodes of the copies after the first: the nodes of one copy, times the count of copies less one. */
303
+ readonly copied: number;
304
+ /** The copies, in the order of the repository, the file and the line. */
305
+ readonly members: readonly CloneMember[];
306
+ }
307
+ /** The classes of cloned code with no home that have their copies in the same repositories. */
308
+ interface CloneGroup {
309
+ /** The ids of the records of the repositories, in order. */
310
+ readonly repositories: readonly string[];
311
+ /** The sum of the copied syntax nodes of the classes. */
312
+ readonly copied: number;
313
+ /** The classes, the largest first. */
314
+ readonly classes: readonly CloneClass[];
315
+ }
316
+ /**
317
+ * This function gives the classes of cloned code that no area covers, in groups by their repositories. It keeps a
318
+ * class with copies in two or more public repositories of the records and `floor` or more copied syntax nodes.
319
+ *
320
+ * - The atlas names each repository. This function finds it in the records as the import does. A copy in a
321
+ * repository that it cannot find is not a copy of the report.
322
+ * - The largest group comes first. Two groups of the same size are in the order of their repositories.
323
+ */
324
+ export declare function cloneGroups(atlas: Atlas, records: readonly EntityRecord[], floor?: number): readonly CloneGroup[];
325
+ /**
326
+ * This function gives the report of the groups as Markdown, for the maintainer of the map of homes. The report names
327
+ * each repository, the areas whose code it holds, and each file and function of the copies. It names no hash, so a
328
+ * new read of the atlas gives the same keys. Each title of an area is in quotes, because a title can have commas.
329
+ */
330
+ export declare function cloneReport(groups: readonly CloneGroup[], records: readonly EntityRecord[], floor?: number): string;
331
+ /** The answers for a list of URLs: the text of each URL, or the reason why there is no text. */
332
+ type UrlAnswers = ReadonlyMap<string, HomeAnswer>;
333
+ /** A function that reads each URL and gives the answer for each URL. A fake of a test can give the answers at once. */
334
+ type UrlFetch = (urls: readonly string[]) => UrlAnswers | Promise<UrlAnswers>;
335
+ /** The name of the client in each request. The repository is the contact. */
336
+ export declare const USER_AGENT = "canon-import/1 (+https://github.com/metrograph-labs/canon)";
337
+ /** The most requests in progress at one time. Each host has one request in progress at most. */
338
+ export declare const HOSTS_AT_ONCE = 4;
339
+ /** The options of `politeFetch`. */
340
+ interface PoliteFetchOptions {
341
+ /** This value is a GitHub token. Only the requests to `api.github.com` send it, for the rate limit of a token. */
342
+ readonly githubToken?: string | undefined;
343
+ /** This function sends each request. The default is `fetchTransport` of `polite-crawler/api` with `USER_AGENT`. A test gives a fake. */
344
+ readonly transport?: Transport | undefined;
345
+ }
346
+ /**
347
+ * This function gives a fetch that reads each URL through `send` of `polite-crawler/api`. Each host has one request in
348
+ * progress at most, and the policy of the crawler sets the rest between two requests of a host.
349
+ *
350
+ * - An answer 2xx gives its text. Another status gives the error `HTTP <status>`, as `githubFetch` of conventions does.
351
+ * The fetch follows no redirect.
352
+ * - A request with no answer, or a stopped host, gives the text of the error. The text has no token.
353
+ */
354
+ export declare function politeFetch(options?: PoliteFetchOptions): (urls: readonly string[]) => Promise<UrlAnswers>;
355
+ /** The help text of the command line. */
356
+ export declare const USAGE: string;
357
+ /** This function finds the root of the repository: the folder whose `schema` folder has the grammar. */
358
+ export declare function findRoot(from: string): string | undefined;
359
+ /** The services of the commands that read or change GitHub. A test gives fakes. */
360
+ interface CliOptions {
361
+ /** This function gives the API of the issues of the board. It throws when there is no token. */
362
+ readonly issues?: (() => IssueApi) | undefined;
363
+ /** This function gives the current time, in milliseconds since 1970. The default is `Date.now`. */
364
+ readonly now?: (() => number) | undefined;
365
+ /** This function reads the URLs of the commands `import` and `clones`. The default is `politeFetch` with no token. */
366
+ readonly fetch?: UrlFetch | undefined;
367
+ }
368
+ /**
369
+ * This function runs the command line with the arguments `args`, and gives the exit code. It writes only to `printer`.
370
+ * The folder `cwd` is the start of the search for the root. The commands `board` and `claim` use `options.issues`.
371
+ */
372
+ export declare function runCli(args: readonly string[], printer: Printer, cwd: string, options?: CliOptions): Promise<number>;
373
+ /** The most pages of 100 repositories that the read asks for each owner. A full last page is an error. */
374
+ export declare const REPOSITORY_PAGES = 5;
375
+ /** This function gives the URLs of the pages of the public repositories of each owner. */
376
+ export declare function repositoryPageUrls(): readonly string[];
377
+ /** This function gives the URL of the latest version of an npm package in the registry. */
378
+ export declare function npmLatestUrl(name: string): string;
379
+ /** This function reads the public repositories of the answers of the pages. It throws when a page has no answer, or the last page is full. */
380
+ export declare function repositoriesOfPages(answers: UrlAnswers): readonly PublicRepository[];
381
+ /** This function reads the fact of npm for one package from the answer for its latest version. It throws on an error that is not 404. */
382
+ export declare function npmFactOf(name: string, answer: HomeAnswer | undefined): NpmFact;
383
+ /** This function gives the version of the installed `@mark1russell7/conventions`, which has the map. */
384
+ export declare function conventionsVersion(): string;
385
+ /**
386
+ * This function reads the live facts of the homes from GitHub, npm and the duplication atlas. The facts are the public
387
+ * repositories of each owner, the latest version of each package of the map, and the atlas. The default fetch is
388
+ * `politeFetch` with no token. Each request goes at the pace of its host.
389
+ */
390
+ export declare function readHomeFacts(homes: readonly Home[], fetch?: UrlFetch): Promise<HomeFacts>;
391
+ /** This error tells that GitHub refused a request of the board. Its text has no token and no body of an answer. */
392
+ export declare class IssueApiError extends Error {
393
+ override readonly name = "IssueApiError";
394
+ /** This number is the status of the answer of GitHub. */
395
+ readonly status: number;
396
+ constructor(message: string, status: number);
397
+ }
398
+ /** This function gives the issue of an item of the REST API, or undefined for a pull request or an item that is not an issue. */
399
+ export declare function issueOfItem(item: unknown): BoardIssue | undefined;
400
+ /** This function gives the time of the last event that assigned one of the assignees, or undefined when there is none. */
401
+ export declare function claimTimeOf(events: unknown, assignees: readonly string[]): number | undefined;
402
+ /**
403
+ * This function gives the API of the issues of the repository `owner/name` through a REST client of GitHub. Each
404
+ * request stops at `signal`. A status of 400 or more throws an `IssueApiError`.
405
+ */
406
+ export declare function githubIssueApi(client: Pick<RestClient, "request">, repository: string, signal: AbortSignal): IssueApi;
407
+ /** This function gives the kind with the name `name`, or undefined. */
408
+ export declare function kindOf(grammar: Grammar, name: string): KindDef | undefined;
409
+ /** This function gives the relation kind with the name `name`, or undefined. */
410
+ export declare function relationOf(grammar: Grammar, name: string): RelationKindDef | undefined;
411
+ /**
412
+ * This function gives the kind `name` and each ancestor kind, the nearest first. A loop of parents ends the list at the
413
+ * first kind that comes again. A kind that the grammar does not have gives an empty list.
414
+ */
415
+ export declare function lineageOf(grammar: Grammar, name: string): readonly string[];
416
+ /** This function tells if a record of the kind `name` is also a record of one of the kinds `allowed`. */
417
+ export declare function isKindIn(grammar: Grammar, name: string, allowed: readonly string[]): boolean;
418
+ /** This function gives each relation of the ontology with its two ends, in the order of the record files. */
419
+ export declare function edgesOf(ontology: Ontology): readonly Edge[];
420
+ /** This function tells if a relation or a record is live: no other record supersedes it, and nobody retired it. */
421
+ export declare function isLive(item: {
422
+ readonly envelope?: Envelope | undefined;
423
+ }): boolean;
424
+ /** The folder of the record files, relative to the root of the repository. */
425
+ export declare const ONTOLOGY_FOLDER = "ontology";
426
+ /** The file of the grammar, relative to the root of the repository. */
427
+ export declare const GRAMMAR_FILE = "schema/grammar.json";
428
+ /** The file of the JSON Schema of one record file, relative to the root of the repository. */
429
+ export declare const RECORD_SCHEMA_FILE = "schema/record.schema.json";
430
+ /**
431
+ * This function gives one part of an id from a name. The part is in lower case. A hyphen goes before each upper-case
432
+ * letter that follows a lower-case letter or a digit. One hyphen replaces each run of other characters. For example,
433
+ * `greatCircleKm` gives `great-circle-km`, and `@mark1russell7/text` gives `mark1russell7-text`.
434
+ */
435
+ export declare function idPart(name: string): string;
436
+ /** This function gives an id from a kind and the parts of a name. Each part goes through `idPart`. */
437
+ export declare function makeId(kind: string, ...parts: readonly string[]): string;
438
+ /** This function gives the kind at the start of an id: the text before the first dot. */
439
+ export declare function kindOfId(id: string): string;
440
+ /**
441
+ * This function gives the path of the file of a record, relative to the root of the repository. The path is the folder
442
+ * of its kind, then the rest of the id. For example, `area.statistics` is in `ontology/area/statistics.json`.
443
+ */
444
+ export declare function pathOfId(id: string): string;
445
+ /** This function gives the id of the repository `owner/name`. */
446
+ export declare function repositoryId(owner: string, name: string): string;
447
+ /** This function gives the id of the npm package `name`. A scoped name gives the scope and the name as two parts. */
448
+ export declare function npmPackageId(name: string): string;
449
+ /** This function gives the package URL of the npm package `name`, as the purl specification writes it. */
450
+ export declare function npmPurl(name: string): string;
451
+ /** This error tells that a file of the ontology is not valid JSON. The check gives each other problem as a `Problem`. */
452
+ export declare class OntologyReadError extends Error {
453
+ /** The path of the file, relative to the root. */
454
+ readonly path: string;
455
+ constructor(path: string, message: string);
456
+ }
457
+ /**
458
+ * This function reads the grammar, the schema of a record file and each record file of the repository at `root`. The
459
+ * record files are each `.json` file under the folder `ontology`, in sorted order. The function does not check them:
460
+ * `checkOntology` does that.
461
+ */
462
+ export declare function readOntology(root: string): Ontology;
463
+ /** The largest modulus of a scope. A scope lists its residues, so a larger modulus gives a record that is too long. */
464
+ export declare const SCOPE_MODULUS_LIMIT = 1e6;
465
+ /**
466
+ * A scope is a set of integers. A value v of `variable` is in the set when three conditions are true. `from` ≤ v. When
467
+ * `to` has a value, v ≤ `to`. The residue v mod `modulus` is in `residues`.
468
+ */
469
+ interface Scope {
470
+ readonly variable: string;
471
+ readonly from: bigint;
472
+ readonly to: bigint | undefined;
473
+ /** This value is 1 when the scope has no class condition. */
474
+ readonly modulus: number;
475
+ /** These values are the residues modulo `modulus`, the least first, each once. */
476
+ readonly residues: readonly number[];
477
+ }
478
+ /**
479
+ * This function reads the JSON form of a scope. The form has `variable`, `from` and optionally `to`, with the bounds as
480
+ * decimal texts. It can also have `modulus` with one of `residues` and `except`. The function gives the scope, or the
481
+ * text of the problem.
482
+ */
483
+ export declare function readScope(value: unknown): Scope | string;
484
+ /**
485
+ * This function gives the canonical form of a scope, or `undefined` for an empty scope. The canonical form has the
486
+ * least modulus of its classes. Its `from` and `to` are values of the set.
487
+ */
488
+ export declare function canonicalScope(scope: Scope): Scope | undefined;
489
+ /**
490
+ * This function tells if two scopes have the same canonical form. Two equal unbounded sets have the same form. Two
491
+ * equal bounded sets can have different classes, and then the function gives `false`. So a claim of a short range
492
+ * keeps its target open, and a wrong `true` cannot close a target.
493
+ */
494
+ export declare function sameScope(a: Scope, b: Scope): boolean;
495
+ /** This function tells if a value is in a scope. */
496
+ export declare function inScope(scope: Scope, value: bigint): boolean;
497
+ /** This function gives the scope in words, for example `n ≥ 3, n mod 840 not in {1, 121}`. */
498
+ export declare function scopeText(scope: Scope): string;
499
+ /** The problem statuses that are claims. The status `open` claims nothing. */
500
+ export declare const CLAIM_STATUSES: readonly string[];
501
+ /**
502
+ * The state of a claim. `checked`: a result about the claim has the scope of the problem. `partial`: results are about
503
+ * the claim, but none has the scope of the problem. `not checked`: no result is about the claim.
504
+ */
505
+ type ClaimState = "checked" | "partial" | "not checked";
506
+ /** A claim that needs a result record. */
507
+ interface ResultClaim {
508
+ /**
509
+ * `status`: a problem has the status `solved` or `disproved`. `solves`: a function has the relation `solves` to a
510
+ * problem.
511
+ */
512
+ readonly kind: "status" | "solves";
513
+ /** The id of the problem of the claim. */
514
+ readonly problem: string;
515
+ /** The id of the function of a `solves` claim. */
516
+ readonly function?: string | undefined;
517
+ /** The status of the problem, for a `status` claim. */
518
+ readonly status?: string | undefined;
519
+ readonly state: ClaimState;
520
+ /** The ids of the live result records about the claim, in id order. */
521
+ readonly results: readonly string[];
522
+ /** The ids of the results of `results` with the scope of the problem, in id order. */
523
+ readonly full: readonly string[];
524
+ }
525
+ /** This function gives the scope of a record, or `undefined` when the record has no valid scope. */
526
+ export declare function scopeOf(record: EntityRecord | undefined): Scope | undefined;
527
+ /**
528
+ * This function tells if a result has the full scope of a problem. A problem or a result with no valid scope gives
529
+ * `false`, so such a result cannot close a problem.
530
+ */
531
+ export declare function hasFullScope(result: EntityRecord | undefined, problem: EntityRecord | undefined): boolean;
532
+ /**
533
+ * This function gives each claim that needs a result record, with its state. A status claim needs a result about its
534
+ * problem. A `solves` claim needs a result about its function and about its problem. The problem id orders the list.
535
+ * A function can solve a part of a problem, so a partial `solves` claim is true. A partial status claim is not.
536
+ */
537
+ export declare function resultClaimsOf(ontology: Ontology): readonly ResultClaim[];
538
+ /**
539
+ * This function tells if a claim fails the rule of the results. A claim with no result fails. A status claim fails
540
+ * also when none of its results has the scope of the problem: a partial result cannot close a problem.
541
+ */
542
+ export declare function claimFails(claim: ResultClaim): boolean;
543
+ /** The test gates of the read, in the order of the records. */
544
+ export declare const GATE_NAMES: readonly GateName[];
545
+ /** The lane file of the mutation tests, when the caller of the workflow gives no input `lane`. */
546
+ export declare const MUTATION_LANE = "mutation.json";
547
+ /** The file of the rig records of a repository. */
548
+ export declare const RIGS_FILE = "docs/rigs.json";
549
+ /** The packages of property tests. A package file that names one of them in its dependencies has property tests. */
550
+ export declare const PROPERTY_PACKAGES: readonly string[];
551
+ /** The package of the speed gates. */
552
+ export declare const BENCH_PACKAGE = "@mark1russell7/rigor-bench";
553
+ /** The most rules of a branch that the read asks for. A full page is a no read. */
554
+ export declare const RULES_PAGE = 100;
555
+ /** A home repository and the branch that the read examines. */
556
+ interface GateRepository {
557
+ readonly owner: string;
558
+ readonly name: string;
559
+ readonly branch: string;
560
+ }
561
+ /** This function gives the URL of the full tree of the branch of a repository: one request for each repository. */
562
+ export declare function treeUrl(repository: GateRepository): string;
563
+ /** This function gives the URL of the rules of the branch of a repository. GitHub gives them with no token. */
564
+ export declare function rulesUrl(repository: GateRepository): string;
565
+ /** This function gives the URL of the text of one file of the branch. The host of raw files is not the API. */
566
+ export declare function fileUrl(repository: GateRepository, path: string): string;
567
+ /** The files of a tree: the id of the content of each file, by its path. */
568
+ interface Tree {
569
+ readonly files: ReadonlyMap<string, string>;
570
+ }
571
+ /** A read that cannot tell the facts, and its reason. */
572
+ interface NoRead {
573
+ readonly no_read: string;
574
+ }
575
+ /**
576
+ * This function reads the answer for a tree. A tree that GitHub truncated is a no read, because a missing file of such a
577
+ * tree does not show that the file is absent. A 404 and each other error are a no read too.
578
+ */
579
+ export declare function treeOf(answer: HomeAnswer | undefined): Tree | NoRead;
580
+ /** This function reads the names of the necessary checks from the answer for the rules of a branch. */
581
+ export declare function necessaryChecksOf(answer: HomeAnswer | undefined): {
582
+ readonly checks: readonly string[];
583
+ } | NoRead;
584
+ /** This function tells if a path is a workflow of GitHub Actions. GitHub reads only the files at the top of the folder. */
585
+ export declare function isWorkflowPath(path: string): boolean;
586
+ /** This function tells if a path is a package file of the repository: not in `node_modules` and not in a fixture folder. */
587
+ export declare function isPackagePath(path: string): boolean;
588
+ /** This function gives the paths of the files that the read needs from a tree: each workflow and each package file. */
589
+ export declare function filesToRead(tree: Tree): readonly string[];
590
+ /**
591
+ * This function tells if the check `pattern` of a gate gives the check `name`. A `*` and each expression `${{ }}` match
592
+ * any text. A job of a matrix with no name gives its values after its name, in parentheses.
593
+ */
594
+ export declare function checkMatches(pattern: string, name: string): boolean;
595
+ /**
596
+ * This function gives the fact of each test gate from a tree, the answers for its files and the rules of the branch. It
597
+ * reads nothing itself.
598
+ *
599
+ * - mutation: a lane file (`mutation.json`, or the input `lane` of the caller) and a job that calls `reusable-mutation.yml`.
600
+ * - property: a package file that names `fast-check` or `@mark1russell7/rigor-testkit`. Its checks are the checks of
601
+ * each job that calls `reusable-ci.yml` or starts the tests, and of each job that needs such a job.
602
+ * - speed: a package file that names `@mark1russell7/rigor-bench`, and a job that starts a bench. A bench job uses the
603
+ * action `stamp-gate`, the bin `rigor-gate-line` or `rigor-stamp`, or a command with the word `bench`.
604
+ * - rigs: the file `docs/rigs.json` and a job that calls `reusable-rigs.yml`.
605
+ *
606
+ * A file with no answer, or a file that the read cannot parse, gives a no read for each gate that needs it.
607
+ */
608
+ export declare function gatesOf(tree: Tree, answers: ReadonlyMap<string, HomeAnswer | undefined>, rules: {
609
+ readonly checks: readonly string[];
610
+ } | NoRead): Readonly<Record<GateName, GateFact>>;
611
+ /**
612
+ * This function reads the test gates of each repository. The default fetch is `politeFetch` with no token, so each
613
+ * request goes at the pace of its host. The read makes two rounds of requests:
614
+ *
615
+ * 1. the tree and the rules of the branch of each repository, from the API of GitHub,
616
+ * 2. each workflow file and each package file of each tree, from the host of raw files. Two files with the same content
617
+ * id give one request.
618
+ *
619
+ * A repository whose tree has no read gives a no read for each gate. The read does not throw for one repository.
620
+ */
621
+ export declare function readTestGates(repositories: readonly GateRepository[], fetch?: UrlFetch, now?: () => number): Promise<ReadonlyMap<string, TestGates>>;
622
+ /**
623
+ * This function gives the home repositories that the read examines. Each is a record of kind repository that exists
624
+ * and is the home of an area. The lists of GitHub give its default branch. A repository with no known default branch
625
+ * is not in the list.
626
+ */
627
+ export declare function gateRepositoriesOf(records: readonly EntityRecord[], repositories: readonly PublicRepository[]): readonly GateRepository[];
628
+ /**
629
+ * This function adds the test gates of each repository to its record as the attribute `test_gates`. When the earlier
630
+ * record of a repository has the same facts, the new record keeps the earlier time. Thus a read with no change writes
631
+ * no file.
632
+ */
633
+ export declare function withTestGates(records: readonly EntityRecord[], gates: ReadonlyMap<string, TestGates>, earlier?: readonly LoadedRecord[]): readonly EntityRecord[];
634
+ /** This function gives the text of the file of a record: JSON with two spaces and a last line end. */
635
+ export declare function recordText(record: EntityRecord): string;
636
+ /** The changes of the files that make the files agree with a set of records. */
637
+ interface WritePlan {
638
+ /** The text of each file to write, by its path relative to the root. */
639
+ readonly write: ReadonlyMap<string, string>;
640
+ /** The files to remove: each file that a program made before, with no record in the new set. */
641
+ readonly remove: readonly string[];
642
+ /** The files that the plan does not write, because a person wrote their record. The program does not own them. */
643
+ readonly keep: readonly string[];
644
+ }
645
+ /**
646
+ * This function plans the changes that make the files agree with the records `records`. The program that made the
647
+ * records owns each existing record for which `owns` is true. A file of such a record with no new record is removed.
648
+ * The plan writes only the files whose text changes. It does not write over a record that the program does not own.
649
+ */
650
+ export declare function planWrite(root: string, records: readonly EntityRecord[], existing: readonly LoadedRecord[], owns: (record: EntityRecord) => boolean): WritePlan;
651
+ /** This function tells if a plan changes no file. */
652
+ export declare function isEmptyPlan(plan: WritePlan): boolean;
653
+ /** This function applies a plan: it writes each file, with its folder, and removes each file of `remove`. */
654
+ export declare function applyPlan(root: string, plan: WritePlan): void;
655
+ export { type Acceptance, type Atlas, type AtlasClass, type AtlasCopy, type AtlasImport, type AtlasRead, type AtlasRepository, type AtlasRow, type BoardAction, type BoardInput, type BoardIssue, type ClaimCommand, type ClaimDecision, type ClaimInput, type ClaimState, type CliOptions, type CloneClass, type CloneGroup, type CloneMember, type Edge, type EdgeRecord, type EntityRecord, type Envelope, type FacetDef, type Gap, type GateFact, type GateName, type GateRepository, type Grammar, type HomeFacts, type HomeImport, type IssueApi, type IssueChange, type IssueText, type JsonSchema, type KindDef, type KindMode, type LoadedRecord, NECESSARY_GATES, type NecessaryGate, type NoRead, type NpmFact, ONTOLOGY_REPOSITORY, type Ontology, PLACES_SHOWN, type PoliteFetchOptions, type Problem, type PublicRepository, type RelationKindDef, type ResultClaim, SIZES, type Scope, type Size, type TargetAttrs, type TargetRecord, type TestGates, type Tree, type UrlAnswers, type UrlFetch, type WritePlan, compareTargets, targetId, targetsOf };