@r_masseater/msch 0.64.0 → 0.65.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,172 @@
1
+ import { a as groupOf, n as RepositoryFiles } from "./repository-files-B5sRbxlz.mjs";
2
+ import { o as positionOf } from "./lookup-DmifnzVb.mjs";
3
+ import { t as startedOnce } from "./started-once-muJbvD_I.mjs";
4
+ import { Array, Effect, Match, Option, Result, Schema, String as String$1, pipe } from "effect";
5
+ import { fileURLToPath } from "node:url";
6
+ import treeSitter from "@vscode/tree-sitter-wasm";
7
+ import remarkParse from "remark-parse";
8
+ import { unified } from "unified";
9
+ import { visit } from "unist-util-visit";
10
+ // src/shared/lib/tree-sitter.ts
11
+ const taggedError = Schema.TaggedError;
12
+ var GrammarUnreadable = class extends taggedError()("GrammarUnreadable", {
13
+ grammar: Schema.String,
14
+ message: Schema.String
15
+ }) {};
16
+ const PARSER_KEY = "parser";
17
+ const initParser = startedOnce();
18
+ const loadOnce = startedOnce();
19
+ const grammarFile = (grammar) => fileURLToPath(import.meta.resolve(`@vscode/tree-sitter-wasm/wasm/tree-sitter-${grammar}.wasm`));
20
+ const loadLanguage = (grammar) => {
21
+ const unreadable = (cause) => GrammarUnreadable.make({
22
+ grammar,
23
+ message: String(cause)
24
+ });
25
+ return Effect.tryPromise({
26
+ try: () => initParser(PARSER_KEY, () => treeSitter.Parser.init()),
27
+ catch: unreadable
28
+ }).pipe(Effect.andThen(Effect.tryPromise({
29
+ try: () => loadOnce(grammar, () => treeSitter.Language.load(grammarFile(grammar))),
30
+ catch: unreadable
31
+ })));
32
+ };
33
+ const readTree = ({ language, source, read }) => {
34
+ const parser = new treeSitter.Parser();
35
+ parser.setLanguage(language);
36
+ const tree = parser.parse(source);
37
+ parser.delete();
38
+ return Option.map(Option.fromNullishOr(tree), (parsed) => {
39
+ const result = read(parsed.rootNode);
40
+ parsed.delete();
41
+ return result;
42
+ });
43
+ };
44
+ // src/features/check-references/model/reference.ts
45
+ const REFERENCE_SCHEME = /^(?<scheme>github|npm):/u;
46
+ const BRANCH_LINK = /^https:\/\/github\.com\/(?<owner>[A-Za-z\d](?:[A-Za-z\d-]*[A-Za-z\d])?)\/(?<repo>[\w.-]+)\/(?:tree|blob)\/(?<ref>[^/#?]+)(?:\/(?<path>[^#?]*[^/#?]))?(?:[#?].*)?$/u;
47
+ const COMMIT = /^[0-9a-f]{40}$/u;
48
+ const GITHUB_REFERENCE = /^github:(?<owner>[A-Za-z\d](?:[A-Za-z\d-]*[A-Za-z\d])?)\/(?<repo>[\w.-]+)(?:\/(?<path>[^#]+))?(?:#(?<symbol>.+))?$/u;
49
+ const NPM_REFERENCE = /^npm:(?<name>(?:@[a-z\d~-][a-z\d._~-]*\/)?[a-z\d~-][a-z\d._~-]*)$/u;
50
+ const SYMBOL = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/u;
51
+ const LINE_ANCHOR = /^L\d+(?:-L\d+)?$/u;
52
+ const UNUSABLE_SEGMENT = /^\.{0,2}$/u;
53
+ const SEPARATOR = "/";
54
+ const GRAMMAR = "`github:<owner>/<repo>[/<path>][#<symbol>]` or `npm:<package>`, where the path names a file or directory of the default branch and the symbol is a declared name such as `Config` or `Config.validate`";
55
+ const pathProblem = (path) => {
56
+ const segments = String$1.split(path, SEPARATOR);
57
+ return Option.liftPredicate(`The path ${path} has an empty, \`.\` or \`..\` segment or a trailing slash. Write the path from the repository root without a trailing slash.`, () => pipe(segments, Array.some((segment) => UNUSABLE_SEGMENT.test(segment))));
58
+ };
59
+ const symbolProblem = (symbol) => {
60
+ if (LINE_ANCHOR.test(symbol)) return Option.some(`#${symbol} is a line number, and a line number goes stale as soon as the file changes. Name the declaration instead, such as #Config.`);
61
+ return Option.liftPredicate(`#${symbol} is not a declared name. Write a name such as #Config or #Config.validate.`, () => !SYMBOL.test(symbol));
62
+ };
63
+ const pathlessSymbol = (path, symbol) => Option.liftPredicate("A symbol needs the file that declares it. Write github:<owner>/<repo>/<path>#<symbol>.", () => Option.isNone(path) && Option.isSome(symbol));
64
+ const githubReference = (destination) => {
65
+ const found = GITHUB_REFERENCE.exec(destination);
66
+ const path = groupOf("path")(found);
67
+ const symbol = groupOf("symbol")(found);
68
+ const problem = pipe(path, Option.flatMap(pathProblem), Option.orElse(() => pipe(symbol, Option.flatMap(symbolProblem))), Option.orElse(() => pathlessSymbol(path, symbol)));
69
+ if (Option.isSome(problem)) return Result.fail(problem.value);
70
+ return pipe(Option.all({
71
+ owner: groupOf("owner")(found),
72
+ repo: groupOf("repo")(found)
73
+ }), Option.map(({ owner, repo }) => ({
74
+ kind: "github",
75
+ owner,
76
+ repo,
77
+ path: Option.getOrElse(path, () => ""),
78
+ symbol,
79
+ ref: Option.none()
80
+ })), Result.fromOption(() => `${destination} is not a repository path. Write ${GRAMMAR}.`));
81
+ };
82
+ const npmReference = (destination) => pipe(groupOf("name")(NPM_REFERENCE.exec(destination)), Option.map((name) => ({
83
+ kind: "npm",
84
+ name
85
+ })), Result.fromOption(() => `${destination} is not a package name. Write ${GRAMMAR}.`));
86
+ const parseReference = (destination) => {
87
+ if (Option.contains(groupOf("scheme")(REFERENCE_SCHEME.exec(destination)), "npm")) return npmReference(destination);
88
+ return githubReference(destination);
89
+ };
90
+ const githubDescription = ({ owner, repo, path, symbol, ref }) => {
91
+ return `github:${Option.match(Option.liftPredicate(path, String$1.isNonEmpty), {
92
+ onNone: () => `${owner}/${repo}`,
93
+ onSome: (found) => `${owner}/${repo}/${found}`
94
+ })}${Option.match(symbol, {
95
+ onNone: () => "",
96
+ onSome: (found) => `#${found}`
97
+ })}${Option.match(ref, {
98
+ onNone: () => "",
99
+ onSome: (found) => ` on ${found}`
100
+ })}`;
101
+ };
102
+ const describeReference = (reference) => Match.value(reference).pipe(Match.discriminatorsExhaustive("kind")({
103
+ github: githubDescription,
104
+ npm: ({ name }) => `npm:${name}`
105
+ }));
106
+ const branchLinkReference = (destination) => {
107
+ const found = BRANCH_LINK.exec(destination);
108
+ const branch = pipe(groupOf("ref")(found), Option.filter((ref) => !COMMIT.test(ref)));
109
+ return pipe(Option.all({
110
+ owner: groupOf("owner")(found),
111
+ repo: groupOf("repo")(found),
112
+ ref: branch
113
+ }), Option.map(({ owner, repo, ref }) => ({
114
+ kind: "github",
115
+ owner,
116
+ repo,
117
+ path: Option.getOrElse(groupOf("path")(found), () => ""),
118
+ symbol: Option.none(),
119
+ ref: Option.some(ref)
120
+ })));
121
+ };
122
+ // src/features/check-references/model/reference-links.ts
123
+ const RULE = "reference-link";
124
+ const MARKDOWN = ".md";
125
+ const FIXTURE = /(?:^|\/)fixtures\//u;
126
+ const READ_CONCURRENCY = 16;
127
+ const parser = unified().use(remarkParse);
128
+ const linkAt = (node) => pipe(Option.fromNullishOr(node.position), Option.flatMap(({ start }) => Option.fromNullishOr(start.offset)), Option.map((index) => ({
129
+ destination: node.url,
130
+ index
131
+ })));
132
+ /** @internal */
133
+ const linksIn = (source) => {
134
+ const found = [];
135
+ const tree = parser.parse(source);
136
+ visit(tree, (node) => {
137
+ if (node.type === "link" || node.type === "definition") found.push(...Option.toArray(linkAt(node)));
138
+ });
139
+ return found;
140
+ };
141
+ /** @internal */
142
+ const referenceMessage = (destination) => pipe(Option.liftPredicate(destination, (text) => REFERENCE_SCHEME.test(text)), Option.flatMap((text) => Result.match(parseReference(text), {
143
+ onFailure: Option.some,
144
+ onSuccess: () => Option.none()
145
+ })));
146
+ /** @internal */
147
+ const referenceOf = (destination) => pipe(Option.liftPredicate(destination, (text) => REFERENCE_SCHEME.test(text)), Option.flatMap((text) => Result.getSuccess(parseReference(text))), Option.orElse(() => branchLinkReference(destination)));
148
+ /** @internal */
149
+ const markdownTexts = Effect.fn("markdownTexts")(function* markdownTexts(root) {
150
+ const files = yield* RepositoryFiles;
151
+ const listed = yield* files.listedFiles(root);
152
+ const documents = pipe(listed, Array.filter((file) => String$1.endsWith(MARKDOWN)(file) && !FIXTURE.test(file)), Array.map((file) => files.join(root, file)));
153
+ const read = yield* Effect.forEach(documents, (file) => Effect.map(files.readFile(file), Option.map((source) => ({
154
+ file,
155
+ source
156
+ }))), { concurrency: READ_CONCURRENCY });
157
+ return Array.getSomes(read);
158
+ });
159
+ const problemsIn = ({ file, source }) => Array.flatMap(linksIn(source), ({ destination, index }) => pipe(referenceMessage(destination), Option.map((message) => ({
160
+ file,
161
+ ...positionOf(source)(index),
162
+ rule: RULE,
163
+ message
164
+ })), Option.toArray));
165
+ /** @internal */
166
+ const checkReferenceLinks = Effect.fn("checkReferenceLinks")(function* checkReferenceLinks(root) {
167
+ const texts = yield* markdownTexts(root);
168
+ return pipe(texts, Array.flatMap(problemsIn));
169
+ });
170
+ export { describeReference as a, referenceOf as i, linksIn as n, loadLanguage as o, markdownTexts as r, readTree as s, checkReferenceLinks as t };
171
+
172
+ //# sourceMappingURL=reference-links-B9NZUUF8.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference-links-B9NZUUF8.mjs","names":["Str","Arr","Arr","Str"],"sources":["../src/shared/lib/tree-sitter.ts","../src/features/check-references/model/reference.ts","../src/features/check-references/model/reference-links.ts"],"sourcesContent":["import { fileURLToPath } from \"node:url\";\n\nimport treeSitter from \"@vscode/tree-sitter-wasm\";\nimport { Effect, Option, Schema } from \"effect\";\n\nimport { startedOnce } from \"./started-once.ts\";\n\nexport type Language = treeSitter.Language;\n\nexport type SyntaxNode = treeSitter.Node;\n\nexport interface TreeReading<Result> {\n readonly language: Language;\n readonly source: string;\n readonly read: (root: SyntaxNode) => Result;\n}\n\nconst taggedError = Schema.TaggedError;\n\nexport class GrammarUnreadable extends taggedError<\n GrammarUnreadable,\n { readonly brand: unique symbol }\n>()(\"GrammarUnreadable\", { grammar: Schema.String, message: Schema.String }) {}\n\nconst PARSER_KEY = \"parser\";\n\nconst initParser = startedOnce<unknown>();\n\nconst loadOnce = startedOnce<Language>();\n\nconst grammarFile = (grammar: string): string =>\n fileURLToPath(import.meta.resolve(`@vscode/tree-sitter-wasm/wasm/tree-sitter-${grammar}.wasm`));\n\nexport const loadLanguage = (grammar: string): Effect.Effect<Language, GrammarUnreadable> => {\n const unreadable = (cause: unknown): GrammarUnreadable =>\n GrammarUnreadable.make({ grammar, message: String(cause) });\n return Effect.tryPromise({\n try: () => initParser(PARSER_KEY, () => treeSitter.Parser.init()),\n catch: unreadable,\n }).pipe(\n Effect.andThen(\n Effect.tryPromise({\n try: () => loadOnce(grammar, () => treeSitter.Language.load(grammarFile(grammar))),\n catch: unreadable,\n }),\n ),\n );\n};\n\nexport const readTree = <Result>({\n language,\n source,\n read,\n}: TreeReading<Result>): Option.Option<Result> => {\n const parser = new treeSitter.Parser();\n parser.setLanguage(language);\n const tree = parser.parse(source);\n parser.delete();\n return Option.map(Option.fromNullishOr(tree), (parsed) => {\n const result = read(parsed.rootNode);\n parsed.delete();\n return result;\n });\n};\n","import { Array as Arr, Match, Option, Result, String as Str, pipe } from \"effect\";\n\nimport { groupOf } from \"#/shared/lib/match-groups.ts\";\n\nexport interface GithubReference {\n readonly kind: \"github\";\n readonly owner: string;\n readonly repo: string;\n readonly path: string;\n readonly symbol: Option.Option<string>;\n readonly ref: Option.Option<string>;\n}\n\nexport interface NpmReference {\n readonly kind: \"npm\";\n readonly name: string;\n}\n\nexport type Reference = GithubReference | NpmReference;\n\nexport const REFERENCE_SCHEME = /^(?<scheme>github|npm):/u;\nconst BRANCH_LINK =\n /^https:\\/\\/github\\.com\\/(?<owner>[A-Za-z\\d](?:[A-Za-z\\d-]*[A-Za-z\\d])?)\\/(?<repo>[\\w.-]+)\\/(?:tree|blob)\\/(?<ref>[^/#?]+)(?:\\/(?<path>[^#?]*[^/#?]))?(?:[#?].*)?$/u;\nconst COMMIT = /^[0-9a-f]{40}$/u;\nconst GITHUB_REFERENCE =\n /^github:(?<owner>[A-Za-z\\d](?:[A-Za-z\\d-]*[A-Za-z\\d])?)\\/(?<repo>[\\w.-]+)(?:\\/(?<path>[^#]+))?(?:#(?<symbol>.+))?$/u;\nconst NPM_REFERENCE = /^npm:(?<name>(?:@[a-z\\d~-][a-z\\d._~-]*\\/)?[a-z\\d~-][a-z\\d._~-]*)$/u;\nconst SYMBOL = /^[A-Za-z_$][\\w$]*(?:\\.[A-Za-z_$][\\w$]*)*$/u;\nconst LINE_ANCHOR = /^L\\d+(?:-L\\d+)?$/u;\nconst UNUSABLE_SEGMENT = /^\\.{0,2}$/u;\nconst SEPARATOR = \"/\";\n\nexport const NO_PATH = \"\";\n\nexport const GRAMMAR =\n \"`github:<owner>/<repo>[/<path>][#<symbol>]` or `npm:<package>`, where the path names a file or directory of the default branch and the symbol is a declared name such as `Config` or `Config.validate`\";\n\nconst pathProblem = (path: string): Option.Option<string> => {\n const segments = Str.split(path, SEPARATOR);\n return Option.liftPredicate(\n `The path ${path} has an empty, \\`.\\` or \\`..\\` segment or a trailing slash. Write the path from the repository root without a trailing slash.`,\n () =>\n pipe(\n segments,\n Arr.some((segment) => UNUSABLE_SEGMENT.test(segment)),\n ),\n );\n};\n\nconst symbolProblem = (symbol: string): Option.Option<string> => {\n if (LINE_ANCHOR.test(symbol)) {\n return Option.some(\n `#${symbol} is a line number, and a line number goes stale as soon as the file changes. Name the declaration instead, such as #Config.`,\n );\n }\n return Option.liftPredicate(\n `#${symbol} is not a declared name. Write a name such as #Config or #Config.validate.`,\n () => !SYMBOL.test(symbol),\n );\n};\n\nconst pathlessSymbol = (\n path: Option.Option<string>,\n symbol: Option.Option<string>,\n): Option.Option<string> =>\n Option.liftPredicate(\n \"A symbol needs the file that declares it. Write github:<owner>/<repo>/<path>#<symbol>.\",\n () => Option.isNone(path) && Option.isSome(symbol),\n );\n\nconst githubReference = (destination: string): Result.Result<Reference, string> => {\n const found = GITHUB_REFERENCE.exec(destination);\n const path = groupOf(\"path\")(found);\n const symbol = groupOf(\"symbol\")(found);\n const problem = pipe(\n path,\n Option.flatMap(pathProblem),\n Option.orElse(() => pipe(symbol, Option.flatMap(symbolProblem))),\n Option.orElse(() => pathlessSymbol(path, symbol)),\n );\n if (Option.isSome(problem)) {\n return Result.fail(problem.value);\n }\n return pipe(\n Option.all({ owner: groupOf(\"owner\")(found), repo: groupOf(\"repo\")(found) }),\n Option.map(({ owner, repo }): Reference => ({\n kind: \"github\",\n owner,\n repo,\n path: Option.getOrElse(path, () => NO_PATH),\n symbol,\n ref: Option.none(),\n })),\n Result.fromOption(() => `${destination} is not a repository path. Write ${GRAMMAR}.`),\n );\n};\n\nconst npmReference = (destination: string): Result.Result<Reference, string> =>\n pipe(\n groupOf(\"name\")(NPM_REFERENCE.exec(destination)),\n Option.map((name): Reference => ({ kind: \"npm\", name })),\n Result.fromOption(() => `${destination} is not a package name. Write ${GRAMMAR}.`),\n );\n\nexport const parseReference = (destination: string): Result.Result<Reference, string> => {\n if (Option.contains(groupOf(\"scheme\")(REFERENCE_SCHEME.exec(destination)), \"npm\")) {\n return npmReference(destination);\n }\n return githubReference(destination);\n};\n\nconst githubDescription = ({ owner, repo, path, symbol, ref }: GithubReference): string => {\n const place = Option.match(Option.liftPredicate(path, Str.isNonEmpty), {\n onNone: () => `${owner}/${repo}`,\n onSome: (found) => `${owner}/${repo}/${found}`,\n });\n const fragment = Option.match(symbol, {\n onNone: () => \"\",\n onSome: (found) => `#${found}`,\n });\n const branch = Option.match(ref, {\n onNone: () => \"\",\n onSome: (found) => ` on ${found}`,\n });\n return `github:${place}${fragment}${branch}`;\n};\n\nexport const describeReference = (reference: Reference): string =>\n Match.value(reference).pipe(\n Match.discriminatorsExhaustive(\"kind\")({\n github: githubDescription,\n npm: ({ name }) => `npm:${name}`,\n }),\n );\n\nexport const branchLinkReference = (destination: string): Option.Option<Reference> => {\n const found = BRANCH_LINK.exec(destination);\n const branch = pipe(\n groupOf(\"ref\")(found),\n Option.filter((ref) => !COMMIT.test(ref)),\n );\n return pipe(\n Option.all({ owner: groupOf(\"owner\")(found), repo: groupOf(\"repo\")(found), ref: branch }),\n Option.map(({ owner, repo, ref }): Reference => ({\n kind: \"github\",\n owner,\n repo,\n path: Option.getOrElse(groupOf(\"path\")(found), () => NO_PATH),\n symbol: Option.none(),\n ref: Option.some(ref),\n })),\n );\n};\n","import { Array as Arr, Effect, Option, Result, String as Str, pipe } from \"effect\";\nimport type { Definition, Link, Root } from \"mdast\";\nimport remarkParse from \"remark-parse\";\nimport { unified } from \"unified\";\nimport { visit } from \"unist-util-visit\";\n\nimport type { Problem, RuleName } from \"#/shared/lib/problem.ts\";\nimport { RepositoryFiles } from \"#/shared/lib/repository-files.ts\";\nimport { positionOf } from \"#/shared/lib/text-position.ts\";\n\nimport { REFERENCE_SCHEME, branchLinkReference, parseReference } from \"./reference.ts\";\nimport type { Reference } from \"./reference.ts\";\n\nconst RULE: RuleName = \"reference-link\";\nconst MARKDOWN = \".md\";\nconst FIXTURE = /(?:^|\\/)fixtures\\//u;\nconst READ_CONCURRENCY = 16;\n\nconst parser = unified().use(remarkParse);\n\n/** @internal */\nexport interface LinkAt {\n readonly destination: string;\n readonly index: number;\n}\n\n/** @internal */\nexport interface MarkdownText {\n readonly file: string;\n readonly source: string;\n}\n\nconst linkAt = (node: Link | Definition): Option.Option<LinkAt> =>\n pipe(\n Option.fromNullishOr(node.position),\n Option.flatMap(({ start }) => Option.fromNullishOr(start.offset)),\n Option.map((index): LinkAt => ({ destination: node.url, index })),\n );\n\n/** @internal */\nexport const linksIn = (source: string): readonly LinkAt[] => {\n const found: LinkAt[] = [];\n const tree: Root = parser.parse(source);\n visit(tree, (node) => {\n if (node.type === \"link\" || node.type === \"definition\") {\n found.push(...Option.toArray(linkAt(node)));\n }\n });\n return found;\n};\n\n/** @internal */\nexport const referenceMessage = (destination: string): Option.Option<string> =>\n pipe(\n Option.liftPredicate(destination, (text) => REFERENCE_SCHEME.test(text)),\n Option.flatMap((text) =>\n Result.match(parseReference(text), {\n onFailure: Option.some,\n onSuccess: () => Option.none(),\n }),\n ),\n );\n\n/** @internal */\nexport const referenceOf = (destination: string): Option.Option<Reference> =>\n pipe(\n Option.liftPredicate(destination, (text) => REFERENCE_SCHEME.test(text)),\n Option.flatMap((text) => Result.getSuccess(parseReference(text))),\n Option.orElse(() => branchLinkReference(destination)),\n );\n\n/** @internal */\nexport const markdownTexts = Effect.fn(\"markdownTexts\")(function* markdownTexts(root: string) {\n const files = yield* RepositoryFiles;\n const listed = yield* files.listedFiles(root);\n const documents = pipe(\n listed,\n Arr.filter((file) => Str.endsWith(MARKDOWN)(file) && !FIXTURE.test(file)),\n Arr.map((file) => files.join(root, file)),\n );\n const read = yield* Effect.forEach(\n documents,\n (file) =>\n Effect.map(\n files.readFile(file),\n Option.map((source): MarkdownText => ({ file, source })),\n ),\n { concurrency: READ_CONCURRENCY },\n );\n return Arr.getSomes(read);\n});\n\nconst problemsIn = ({ file, source }: MarkdownText): readonly Problem[] =>\n Arr.flatMap(linksIn(source), ({ destination, index }) =>\n pipe(\n referenceMessage(destination),\n Option.map((message): Problem => ({\n file,\n ...positionOf(source)(index),\n rule: RULE,\n message,\n })),\n Option.toArray,\n ),\n );\n\n/** @internal */\nexport const checkReferenceLinks = Effect.fn(\"checkReferenceLinks\")(function* checkReferenceLinks(\n root: string,\n) {\n const texts = yield* markdownTexts(root);\n return pipe(texts, Arr.flatMap(problemsIn));\n});\n"],"mappings":";;;;;;;;;;AAiBA,MAAM,cAAc,OAAO;AAE3B,IAAa,oBAAb,cAAuC,YAGrC,CAAC,CAAC,qBAAqB;CAAE,SAAS,OAAO;CAAQ,SAAS,OAAO;AAAO,CAAC,CAAC,CAAC,CAAC;AAE9E,MAAM,aAAa;AAEnB,MAAM,aAAa,YAAqB;AAExC,MAAM,WAAW,YAAsB;AAEvC,MAAM,eAAe,YACnB,cAAc,YAAY,QAAQ,6CAA6C,QAAQ,MAAM,CAAC;AAEhG,MAAa,gBAAgB,YAAgE;CAC3F,MAAM,cAAc,UAClB,kBAAkB,KAAK;EAAE;EAAS,SAAS,OAAO,KAAK;CAAE,CAAC;CAC5D,OAAO,OAAO,WAAW;EACvB,WAAW,WAAW,kBAAkB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WAAW,MAAM,CAAC,CAAC,KAAK;CAC3B,MAAM;CACN;AACF,EAAE,GACF,OAAO,OACT,CACF;;AAGF,MAAa,sBAAsB,OAAO,GAAG,qBAAqB,CAAC,CAAC,UAAU,oBAC5E,MACA;CACA,MAAM,QAAQ,OAAO,cAAc,IAAI;CACvC,OAAO,KAAK,OAAOA,MAAI,QAAQ,UAAU,CAAC;AAC5C,CAAC"}
@@ -0,0 +1 @@
1
+ export {}
package/dist/refs.mjs ADDED
@@ -0,0 +1,209 @@
1
+ #!/usr/bin/env node
2
+ import { t as lookupReport } from "./lookup-report-ARfHc4ey.mjs";
3
+ import { t as runCli } from "./runtime-A2p57njU.mjs";
4
+ import { a as groupOf, n as RepositoryFiles } from "./repository-files-B5sRbxlz.mjs";
5
+ import { a as sent, i as publicLookup, n as githubToken, o as positionOf, r as jsonLookup } from "./lookup-DmifnzVb.mjs";
6
+ import { a as describeReference, i as referenceOf, n as linksIn, o as loadLanguage, r as markdownTexts, s as readTree } from "./reference-links-B9NZUUF8.mjs";
7
+ import { Array, Effect, HashMap, HashSet, Match, Option, Record, Schema, String as String$1, pipe } from "effect";
8
+ import { HttpClientResponse } from "effect/http";
9
+ // src/features/check-references/model/declared-symbols.ts
10
+ const GRAMMAR_OF = {
11
+ ts: "typescript",
12
+ mts: "typescript",
13
+ cts: "typescript",
14
+ tsx: "tsx",
15
+ js: "javascript",
16
+ mjs: "javascript",
17
+ cjs: "javascript",
18
+ jsx: "javascript",
19
+ rs: "rust",
20
+ py: "python",
21
+ go: "go",
22
+ java: "java",
23
+ rb: "ruby",
24
+ php: "php",
25
+ cs: "c-sharp",
26
+ cpp: "cpp"
27
+ };
28
+ const IMPLEMENTATION = "impl_item";
29
+ const NAME_FIELD = "name";
30
+ const TYPE_FIELD = "type";
31
+ const SEPARATOR$1 = ".";
32
+ const EXTENSION = /\.(?<extension>[^./]+)$/u;
33
+ const FIRST = 0;
34
+ const ONE = 1;
35
+ const supportedExtensions = Record.keys(GRAMMAR_OF);
36
+ const grammarOf = (path) => pipe(groupOf("extension")(EXTENSION.exec(path)), Option.flatMap((extension) => Record.get(GRAMMAR_OF, extension)));
37
+ const implementedType = (node) => pipe(Option.liftPredicate(node, ({ type }) => type === IMPLEMENTATION), Option.flatMap((implementation) => Option.fromNullishOr(implementation.childForFieldName(TYPE_FIELD))));
38
+ const nameNodeOf = (node) => pipe(Option.fromNullishOr(node.childForFieldName(NAME_FIELD)), Option.orElse(() => implementedType(node)));
39
+ const suffixesOf = (chain) => pipe(Array.range(FIRST, chain.length - ONE), Array.map((from) => Array.join(Array.drop(chain, from), SEPARATOR$1)));
40
+ const childrenOf = (node) => pipe(node.namedChildren, Array.flatMap((child) => Option.toArray(Option.fromNullishOr(child))));
41
+ const namesUnder = (node, enclosing) => {
42
+ const own = Option.map(nameNodeOf(node), ({ text }) => text);
43
+ const chain = Option.match(own, {
44
+ onNone: () => enclosing,
45
+ onSome: (name) => [...enclosing, name]
46
+ });
47
+ return [...Option.match(own, {
48
+ onNone: () => [],
49
+ onSome: () => suffixesOf(chain)
50
+ }), ...Array.flatMap(childrenOf(node), (child) => namesUnder(child, chain))];
51
+ };
52
+ const declaredSymbols = Effect.fn("declaredSymbols")(function* declaredSymbols(grammar, source) {
53
+ const language = yield* loadLanguage(grammar);
54
+ return pipe(readTree({
55
+ language,
56
+ source,
57
+ read: (root) => HashSet.fromIterable(namesUnder(root, []))
58
+ }), Option.getOrElse(() => HashSet.empty()));
59
+ });
60
+ // src/features/check-references/model/resolve-reference.ts
61
+ const GITHUB = "https://api.github.com/repos/";
62
+ const NPM = "https://registry.npmjs.org/";
63
+ const RAW = "application/vnd.github.raw+json";
64
+ const ABBREVIATED = "application/vnd.npm.install-v1+json";
65
+ const NOT_FOUND = 404;
66
+ const MULTIPLE_CHOICES = 300;
67
+ const SEPARATOR = "/";
68
+ const found = { kind: "found" };
69
+ const broken = (reason) => ({
70
+ kind: "broken",
71
+ reason
72
+ });
73
+ const unchecked = (reason) => ({
74
+ kind: "unchecked",
75
+ reason
76
+ });
77
+ const Repository = Schema.Struct({
78
+ full_name: Schema.String,
79
+ archived: Schema.Boolean,
80
+ default_branch: Schema.String
81
+ });
82
+ const Version = Schema.Struct({ deprecated: Schema.optional(Schema.String) });
83
+ const Packument = Schema.Struct({
84
+ "dist-tags": Schema.Struct({ latest: Schema.String }),
85
+ versions: Schema.Record(Schema.String, Version)
86
+ });
87
+ const answered = (lookup, missing, next) => Effect.flatMap(sent(lookup), (response) => {
88
+ if (response.status === NOT_FOUND) return Effect.succeed(broken(missing));
89
+ if (response.status >= MULTIPLE_CHOICES) return Effect.succeed(unchecked(`the lookup answered HTTP ${String(response.status)}`));
90
+ return next(response);
91
+ });
92
+ const encodedPath = (path) => pipe(String$1.split(path, SEPARATOR), Array.map(encodeURIComponent), Array.join(SEPARATOR));
93
+ const repositoryOutcome = ({ owner, repo }, repository) => {
94
+ if (String$1.toLowerCase(repository.full_name) !== String$1.toLowerCase(`${owner}/${repo}`)) return broken(`${owner}/${repo} has moved to ${repository.full_name}. Point at the new name.`);
95
+ if (repository.archived) return broken(`${owner}/${repo} is archived. Point at the repository that replaced it, or drop the pointer.`);
96
+ return found;
97
+ };
98
+ const symbolOutcome = Effect.fn("symbolOutcome")(function* symbolOutcome({ path }, symbol, source) {
99
+ const grammar = grammarOf(path);
100
+ if (Option.isNone(grammar)) return broken(`${path} is not a file msch can read symbols from. Drop #${symbol}, or point at a file with one of the extensions ${Array.join(supportedExtensions, ", ")}.`);
101
+ const declared = yield* Effect.option(declaredSymbols(grammar.value, source));
102
+ return Option.match(declared, {
103
+ onNone: () => unchecked(`the ${grammar.value} grammar could not read ${path}`),
104
+ onSome: (names) => {
105
+ if (HashSet.has(names, symbol)) return found;
106
+ return broken(`${path} declares no ${symbol}. Fix the name or point at where it lives now.`);
107
+ }
108
+ });
109
+ });
110
+ const pathOutcome = (reference, defaultBranch, token) => {
111
+ const branch = Option.getOrElse(reference.ref, () => defaultBranch);
112
+ const url = `${GITHUB}${reference.owner}/${reference.repo}/contents/${encodedPath(reference.path)}?ref=${encodeURIComponent(branch)}`;
113
+ const missing = `${reference.path} does not exist on ${branch} of ${reference.owner}/${reference.repo}. Point at where it lives now.`;
114
+ return Option.match(reference.symbol, {
115
+ onNone: () => answered(jsonLookup({
116
+ url,
117
+ token
118
+ }), missing, () => Effect.succeed(found)),
119
+ onSome: (symbol) => answered({
120
+ url,
121
+ token,
122
+ accept: RAW
123
+ }, missing, (response) => response.text.pipe(Effect.flatMap((source) => symbolOutcome(reference, symbol, source))))
124
+ });
125
+ };
126
+ const repositoryStep = (reference, token) => (response) => Effect.flatMap(HttpClientResponse.schemaBodyJson(Repository)(response), (repository) => {
127
+ const checked = repositoryOutcome(reference, repository);
128
+ if (checked.kind !== "found" || reference.path === "") return Effect.succeed(checked);
129
+ return pathOutcome(reference, repository.default_branch, token);
130
+ });
131
+ const githubOutcome = Effect.fn("githubOutcome")(function* githubOutcome(reference) {
132
+ const token = yield* githubToken;
133
+ const lookup = jsonLookup({
134
+ url: `${GITHUB}${reference.owner}/${reference.repo}`,
135
+ token
136
+ });
137
+ const missing = `${reference.owner}/${reference.repo} does not exist, or the token in GH_TOKEN cannot read it.`;
138
+ return yield* answered(lookup, missing, repositoryStep(reference, token));
139
+ });
140
+ const deprecation = ({ "dist-tags": tags, versions }) => pipe(Option.fromNullishOr(versions[tags.latest]), Option.flatMap(({ deprecated }) => Option.fromNullishOr(deprecated)));
141
+ const npmOutcome = ({ name }) => answered({
142
+ ...publicLookup(`${NPM}${String$1.replace("/", "%2f")(name)}`),
143
+ accept: ABBREVIATED
144
+ }, `${name} is not published on npm.`, (response) => Effect.map(HttpClientResponse.schemaBodyJson(Packument)(response), (packument) => Option.match(deprecation(packument), {
145
+ onNone: () => found,
146
+ onSome: (message) => broken(`${name} is deprecated: ${message}`)
147
+ })));
148
+ /** @internal */
149
+ const resolveReference = (reference) => Match.value(reference).pipe(Match.discriminatorsExhaustive("kind")({
150
+ github: githubOutcome,
151
+ npm: npmOutcome
152
+ }), Effect.match({
153
+ onFailure: (failure) => unchecked(`the lookup failed: ${String(failure)}`),
154
+ onSuccess: (outcome) => outcome
155
+ }));
156
+ // src/features/check-references/model/unresolved-references.ts
157
+ const LOOKUP_CONCURRENCY = 4;
158
+ const occurrencesIn = (file, source) => pipe(linksIn(source), Array.flatMap(({ destination, index }) => pipe(referenceOf(destination), Option.map((reference) => ({
159
+ file,
160
+ line: positionOf(source)(index).line,
161
+ reference
162
+ })), Option.toArray)));
163
+ const unresolvedAt = (place) => (outcome) => {
164
+ if (outcome.kind === "found") return Option.none();
165
+ return Option.some({
166
+ ...place,
167
+ outcome: outcome.kind,
168
+ reason: outcome.reason
169
+ });
170
+ };
171
+ const unresolvedOf = (outcomes) => ({ file, line, reference }) => {
172
+ const described = describeReference(reference);
173
+ return pipe(outcomes, HashMap.get(described), Option.flatMap(unresolvedAt({
174
+ file,
175
+ line,
176
+ reference: described
177
+ })), Option.toArray);
178
+ };
179
+ /** @internal */
180
+ const unresolvedReferences = Effect.fn("unresolvedReferences")(function* unresolvedReferences(root) {
181
+ const files = yield* RepositoryFiles;
182
+ const texts = yield* markdownTexts(root);
183
+ const occurrences = pipe(texts, Array.flatMap(({ file, source }) => occurrencesIn(files.relative(root, file), source)));
184
+ const distinct = pipe(occurrences, Array.dedupeWith((left, right) => describeReference(left.reference) === describeReference(right.reference)), Array.map(({ reference }) => reference));
185
+ const resolved = yield* Effect.forEach(distinct, (reference) => Effect.map(resolveReference(reference), (outcome) => [describeReference(reference), outcome]), { concurrency: LOOKUP_CONCURRENCY });
186
+ const outcomes = HashMap.fromIterable(resolved);
187
+ return pipe(occurrences, Array.flatMap(unresolvedOf(outcomes)));
188
+ });
189
+ // bin/msch-refs.ts
190
+ const Row = Schema.Struct({
191
+ file: Schema.String,
192
+ line: Schema.Finite,
193
+ reference: Schema.String,
194
+ outcome: Schema.Literals(["broken", "unchecked"]),
195
+ reason: Schema.String
196
+ });
197
+ const VERDICTS = {
198
+ broken: "is stale:",
199
+ unchecked: "could not be checked:"
200
+ };
201
+ const describeRow = (row) => `${row.file}:${String(row.line)} ${row.reference} ${VERDICTS[row.outcome]} ${row.reason}`;
202
+ runCli(lookupReport({
203
+ row: Row,
204
+ rows: unresolvedReferences,
205
+ describe: describeRow
206
+ }));
207
+ export {};
208
+
209
+ //# sourceMappingURL=refs.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refs.mjs","names":["SEPARATOR","Rec","Arr","Str","Arr","Arr"],"sources":["../src/features/check-references/model/declared-symbols.ts","../src/features/check-references/model/resolve-reference.ts","../src/features/check-references/model/unresolved-references.ts","../bin/msch-refs.ts"],"sourcesContent":["import { Array as Arr, Effect, HashSet, Option, Record as Rec, pipe } from \"effect\";\n\nimport { groupOf } from \"#/shared/lib/match-groups.ts\";\nimport { loadLanguage, readTree } from \"#/shared/lib/tree-sitter.ts\";\nimport type { SyntaxNode } from \"#/shared/lib/tree-sitter.ts\";\n\nconst GRAMMAR_OF: Readonly<Record<string, string>> = {\n ts: \"typescript\",\n mts: \"typescript\",\n cts: \"typescript\",\n tsx: \"tsx\",\n js: \"javascript\",\n mjs: \"javascript\",\n cjs: \"javascript\",\n jsx: \"javascript\",\n rs: \"rust\",\n py: \"python\",\n go: \"go\",\n java: \"java\",\n rb: \"ruby\",\n php: \"php\",\n cs: \"c-sharp\",\n cpp: \"cpp\",\n};\nconst IMPLEMENTATION = \"impl_item\";\nconst NAME_FIELD = \"name\";\nconst TYPE_FIELD = \"type\";\nconst SEPARATOR = \".\";\nconst EXTENSION = /\\.(?<extension>[^./]+)$/u;\nconst FIRST = 0;\nconst ONE = 1;\n\nexport const supportedExtensions: readonly string[] = Rec.keys(GRAMMAR_OF);\n\nexport const grammarOf = (path: string): Option.Option<string> =>\n pipe(\n groupOf(\"extension\")(EXTENSION.exec(path)),\n Option.flatMap((extension) => Rec.get(GRAMMAR_OF, extension)),\n );\n\nconst implementedType = (node: SyntaxNode): Option.Option<SyntaxNode> =>\n pipe(\n Option.liftPredicate(node, ({ type }) => type === IMPLEMENTATION),\n Option.flatMap((implementation) =>\n Option.fromNullishOr(implementation.childForFieldName(TYPE_FIELD)),\n ),\n );\n\nconst nameNodeOf = (node: SyntaxNode): Option.Option<SyntaxNode> =>\n pipe(\n Option.fromNullishOr(node.childForFieldName(NAME_FIELD)),\n Option.orElse(() => implementedType(node)),\n );\n\nconst suffixesOf = (chain: readonly string[]): readonly string[] =>\n pipe(\n Arr.range(FIRST, chain.length - ONE),\n Arr.map((from) => Arr.join(Arr.drop(chain, from), SEPARATOR)),\n );\n\nconst childrenOf = (node: SyntaxNode): readonly SyntaxNode[] =>\n pipe(\n node.namedChildren,\n Arr.flatMap((child) => Option.toArray(Option.fromNullishOr(child))),\n );\n\nconst namesUnder = (node: SyntaxNode, enclosing: readonly string[]): readonly string[] => {\n const own = Option.map(nameNodeOf(node), ({ text }) => text);\n const chain = Option.match(own, {\n onNone: () => enclosing,\n onSome: (name) => [...enclosing, name],\n });\n const declared = Option.match(own, { onNone: () => [], onSome: () => suffixesOf(chain) });\n return [...declared, ...Arr.flatMap(childrenOf(node), (child) => namesUnder(child, chain))];\n};\n\nexport const declaredSymbols = Effect.fn(\"declaredSymbols\")(function* declaredSymbols(\n grammar: string,\n source: string,\n) {\n const language = yield* loadLanguage(grammar);\n return pipe(\n readTree({ language, source, read: (root) => HashSet.fromIterable(namesUnder(root, [])) }),\n Option.getOrElse(() => HashSet.empty<string>()),\n );\n});\n","import { Array as Arr, Effect, HashSet, Match, Option, Schema, String as Str, pipe } from \"effect\";\nimport { HttpClientResponse } from \"effect/http\";\nimport type { HttpClient, HttpClientError } from \"effect/http\";\n\nimport { githubToken, jsonLookup, publicLookup, sent } from \"#/shared/lib/lookup.ts\";\nimport type { Lookup } from \"#/shared/lib/lookup.ts\";\n\nimport { declaredSymbols, grammarOf, supportedExtensions } from \"./declared-symbols.ts\";\nimport { NO_PATH } from \"./reference.ts\";\nimport type { GithubReference, NpmReference, Reference } from \"./reference.ts\";\n\nconst GITHUB = \"https://api.github.com/repos/\";\nconst NPM = \"https://registry.npmjs.org/\";\nconst RAW = \"application/vnd.github.raw+json\";\nconst ABBREVIATED = \"application/vnd.npm.install-v1+json\";\nconst NOT_FOUND = 404;\nconst MULTIPLE_CHOICES = 300;\nconst SEPARATOR = \"/\";\n\n/** @internal */\nexport type Outcome =\n | { readonly kind: \"found\" }\n | { readonly kind: \"broken\"; readonly reason: string }\n | { readonly kind: \"unchecked\"; readonly reason: string };\n\nconst found: Outcome = { kind: \"found\" };\nconst broken = (reason: string): Outcome => ({ kind: \"broken\", reason });\nconst unchecked = (reason: string): Outcome => ({ kind: \"unchecked\", reason });\n\nconst Repository = Schema.Struct({\n full_name: Schema.String,\n archived: Schema.Boolean,\n default_branch: Schema.String,\n});\nconst Version = Schema.Struct({ deprecated: Schema.optional(Schema.String) });\nconst Packument = Schema.Struct({\n \"dist-tags\": Schema.Struct({ latest: Schema.String }),\n versions: Schema.Record(Schema.String, Version),\n});\n\ntype Failure = HttpClientError.HttpClientError | Schema.SchemaError;\ntype Lookups = Effect.Effect<Outcome, Failure, HttpClient.HttpClient>;\n\nconst answered = (\n lookup: Lookup,\n missing: string,\n next: (response: HttpClientResponse.HttpClientResponse) => Lookups,\n): Lookups =>\n Effect.flatMap(sent(lookup), (response) => {\n if (response.status === NOT_FOUND) {\n return Effect.succeed(broken(missing));\n }\n if (response.status >= MULTIPLE_CHOICES) {\n return Effect.succeed(unchecked(`the lookup answered HTTP ${String(response.status)}`));\n }\n return next(response);\n });\n\nconst encodedPath = (path: string): string =>\n pipe(Str.split(path, SEPARATOR), Arr.map(encodeURIComponent), Arr.join(SEPARATOR));\n\nconst repositoryOutcome = (\n { owner, repo }: GithubReference,\n repository: typeof Repository.Type,\n): Outcome => {\n if (Str.toLowerCase(repository.full_name) !== Str.toLowerCase(`${owner}/${repo}`)) {\n return broken(`${owner}/${repo} has moved to ${repository.full_name}. Point at the new name.`);\n }\n if (repository.archived) {\n return broken(\n `${owner}/${repo} is archived. Point at the repository that replaced it, or drop the pointer.`,\n );\n }\n return found;\n};\n\nconst symbolOutcome = Effect.fn(\"symbolOutcome\")(function* symbolOutcome(\n { path }: GithubReference,\n symbol: string,\n source: string,\n) {\n const grammar = grammarOf(path);\n if (Option.isNone(grammar)) {\n return broken(\n `${path} is not a file msch can read symbols from. Drop #${symbol}, or point at a file with one of the extensions ${Arr.join(supportedExtensions, \", \")}.`,\n );\n }\n const declared = yield* Effect.option(declaredSymbols(grammar.value, source));\n return Option.match(declared, {\n onNone: () => unchecked(`the ${grammar.value} grammar could not read ${path}`),\n onSome: (names) => {\n if (HashSet.has(names, symbol)) {\n return found;\n }\n return broken(`${path} declares no ${symbol}. Fix the name or point at where it lives now.`);\n },\n });\n});\n\nconst pathOutcome = (\n reference: GithubReference,\n defaultBranch: string,\n token: Option.Option<string>,\n): Lookups => {\n const branch = Option.getOrElse(reference.ref, () => defaultBranch);\n const url = `${GITHUB}${reference.owner}/${reference.repo}/contents/${encodedPath(reference.path)}?ref=${encodeURIComponent(branch)}`;\n const missing = `${reference.path} does not exist on ${branch} of ${reference.owner}/${reference.repo}. Point at where it lives now.`;\n return Option.match(reference.symbol, {\n onNone: () => answered(jsonLookup({ url, token }), missing, () => Effect.succeed(found)),\n onSome: (symbol) =>\n answered({ url, token, accept: RAW }, missing, (response) =>\n response.text.pipe(Effect.flatMap((source) => symbolOutcome(reference, symbol, source))),\n ),\n });\n};\n\nconst repositoryStep =\n (reference: GithubReference, token: Option.Option<string>) =>\n (response: HttpClientResponse.HttpClientResponse): Lookups =>\n Effect.flatMap(HttpClientResponse.schemaBodyJson(Repository)(response), (repository) => {\n const checked = repositoryOutcome(reference, repository);\n if (checked.kind !== \"found\" || reference.path === NO_PATH) {\n return Effect.succeed(checked);\n }\n return pathOutcome(reference, repository.default_branch, token);\n });\n\nconst githubOutcome = Effect.fn(\"githubOutcome\")(function* githubOutcome(\n reference: GithubReference,\n) {\n const token = yield* githubToken;\n const lookup = jsonLookup({ url: `${GITHUB}${reference.owner}/${reference.repo}`, token });\n const missing = `${reference.owner}/${reference.repo} does not exist, or the token in GH_TOKEN cannot read it.`;\n return yield* answered(lookup, missing, repositoryStep(reference, token));\n});\n\nconst deprecation = ({\n \"dist-tags\": tags,\n versions,\n}: typeof Packument.Type): Option.Option<string> =>\n pipe(\n Option.fromNullishOr(versions[tags.latest]),\n Option.flatMap(({ deprecated }) => Option.fromNullishOr(deprecated)),\n );\n\nconst npmOutcome = ({ name }: NpmReference): Lookups =>\n answered(\n {\n ...publicLookup(`${NPM}${Str.replace(\"/\", \"%2f\")(name)}`),\n accept: ABBREVIATED,\n },\n `${name} is not published on npm.`,\n (response) =>\n Effect.map(HttpClientResponse.schemaBodyJson(Packument)(response), (packument) =>\n Option.match(deprecation(packument), {\n onNone: () => found,\n onSome: (message) => broken(`${name} is deprecated: ${message}`),\n }),\n ),\n );\n\n/** @internal */\nexport const resolveReference = (\n reference: Reference,\n): Effect.Effect<Outcome, never, HttpClient.HttpClient> =>\n Match.value(reference).pipe(\n Match.discriminatorsExhaustive(\"kind\")({ github: githubOutcome, npm: npmOutcome }),\n Effect.match({\n onFailure: (failure) => unchecked(`the lookup failed: ${String(failure)}`),\n onSuccess: (outcome) => outcome,\n }),\n );\n","import { Array as Arr, Effect, HashMap, Option, pipe } from \"effect\";\n\nimport { RepositoryFiles } from \"#/shared/lib/repository-files.ts\";\nimport { positionOf } from \"#/shared/lib/text-position.ts\";\n\nimport { linksIn, markdownTexts, referenceOf } from \"./reference-links.ts\";\nimport { describeReference } from \"./reference.ts\";\nimport type { Reference } from \"./reference.ts\";\nimport { resolveReference } from \"./resolve-reference.ts\";\nimport type { Outcome } from \"./resolve-reference.ts\";\n\nconst LOOKUP_CONCURRENCY = 4;\n\n/** @internal */\nexport interface UnresolvedReference {\n readonly file: string;\n readonly line: number;\n readonly reference: string;\n readonly outcome: \"broken\" | \"unchecked\";\n readonly reason: string;\n}\n\ninterface Occurrence {\n readonly file: string;\n readonly line: number;\n readonly reference: Reference;\n}\n\nconst occurrencesIn = (file: string, source: string): readonly Occurrence[] =>\n pipe(\n linksIn(source),\n Arr.flatMap(({ destination, index }) =>\n pipe(\n referenceOf(destination),\n Option.map((reference): Occurrence => ({\n file,\n line: positionOf(source)(index).line,\n reference,\n })),\n Option.toArray,\n ),\n ),\n );\n\ninterface Place {\n readonly file: string;\n readonly line: number;\n readonly reference: string;\n}\n\nconst unresolvedAt =\n (place: Place) =>\n (outcome: Outcome): Option.Option<UnresolvedReference> => {\n if (outcome.kind === \"found\") {\n return Option.none();\n }\n return Option.some({ ...place, outcome: outcome.kind, reason: outcome.reason });\n };\n\nconst unresolvedOf =\n (outcomes: HashMap.HashMap<string, Outcome>) =>\n ({ file, line, reference }: Occurrence): readonly UnresolvedReference[] => {\n const described = describeReference(reference);\n return pipe(\n outcomes,\n HashMap.get(described),\n Option.flatMap(unresolvedAt({ file, line, reference: described })),\n Option.toArray,\n );\n };\n\n/** @internal */\nexport const unresolvedReferences = Effect.fn(\"unresolvedReferences\")(\n function* unresolvedReferences(root: string) {\n const files = yield* RepositoryFiles;\n const texts = yield* markdownTexts(root);\n const occurrences = pipe(\n texts,\n Arr.flatMap(({ file, source }) => occurrencesIn(files.relative(root, file), source)),\n );\n const distinct = pipe(\n occurrences,\n Arr.dedupeWith(\n (left, right) => describeReference(left.reference) === describeReference(right.reference),\n ),\n Arr.map(({ reference }) => reference),\n );\n const resolved = yield* Effect.forEach(\n distinct,\n (reference) =>\n Effect.map(\n resolveReference(reference),\n (outcome) => [describeReference(reference), outcome] as const,\n ),\n { concurrency: LOOKUP_CONCURRENCY },\n );\n const outcomes = HashMap.fromIterable(resolved);\n return pipe(occurrences, Arr.flatMap(unresolvedOf(outcomes)));\n },\n);\n","#!/usr/bin/env node\nimport { Schema } from \"effect\";\n\nimport { lookupReport } from \"#/app/lookup-report.ts\";\nimport { runCli } from \"#/app/runtime.ts\";\nimport { unresolvedReferences } from \"#/features/check-references/index.ts\";\n\nconst Row = Schema.Struct({\n file: Schema.String,\n line: Schema.Finite,\n reference: Schema.String,\n outcome: Schema.Literals([\"broken\", \"unchecked\"]),\n reason: Schema.String,\n});\n\ntype RowType = typeof Row.Type;\n\nconst VERDICTS: Readonly<Record<RowType[\"outcome\"], string>> = {\n broken: \"is stale:\",\n unchecked: \"could not be checked:\",\n};\n\nconst describeRow = (row: RowType): string =>\n `${row.file}:${String(row.line)} ${row.reference} ${VERDICTS[row.outcome]} ${row.reason}`;\n\nrunCli(lookupReport({ row: Row, rows: unresolvedReferences, describe: describeRow }));\n"],"mappings":";;;;;;;;;AAMA,MAAM,aAA+C;CACnD,IAAI;CACJ,KAAK;CACL,KAAK;CACL,KAAK;CACL,IAAI;CACJ,KAAK;CACL,KAAK;CACL,KAAK;CACL,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,IAAI;CACJ,KAAK;CACL,IAAI;CACJ,KAAK;AACP;AACA,MAAM,iBAAiB;AACvB,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,MAAMA,cAAY;AAClB,MAAM,YAAY;AAClB,MAAM,QAAQ;AACd,MAAM,MAAM;AAEZ,MAAa,sBAAyCC,OAAI,KAAK,UAAU;AAEzE,MAAa,aAAa,SACxB,KACE,QAAQ,WAAW,CAAC,CAAC,UAAU,KAAK,IAAI,CAAC,GACzC,OAAO,SAAS,cAAcA,OAAI,IAAI,YAAY,SAAS,CAAC,CAC9D;AAEF,MAAM,mBAAmB,SACvB,KACE,OAAO,cAAc,OAAO,EAAE,WAAW,SAAS,cAAc,GAChE,OAAO,SAAS,mBACd,OAAO,cAAc,eAAe,kBAAkB,UAAU,CAAC,CACnE,CACF;AAEF,MAAM,cAAc,SAClB,KACE,OAAO,cAAc,KAAK,kBAAkB,UAAU,CAAC,GACvD,OAAO,aAAa,gBAAgB,IAAI,CAAC,CAC3C;AAEF,MAAM,cAAc,UAClB,KACEC,MAAI,MAAM,OAAO,MAAM,SAAS,GAAG,GACnCA,MAAI,KAAK,SAASA,M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E,KAAK;CAAK,MAAM;CAAsB,UAAU;AAAY,CAAC,CAAC"}
@@ -1,22 +1,10 @@
1
1
  import { a as groupOf, n as RepositoryFiles } from "./repository-files-B5sRbxlz.mjs";
2
- import { Array, Config, Effect, HashMap, HashSet, Match, Option, Record, Schema, String as String$1, pipe } from "effect";
2
+ import { i as publicLookup, n as githubToken, o as positionOf, r as jsonLookup, t as fetched } from "./lookup-DmifnzVb.mjs";
3
+ import { Array, Effect, HashMap, HashSet, Match, Option, Record, Schema, String as String$1, pipe } from "effect";
3
4
  import { Parser, parseDocument } from "yaml";
4
5
  import semver from "semver";
5
6
  import { parseTOML } from "toml-eslint-parser";
6
- import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
7
- // src/shared/lib/text-position.ts
8
- const START = 0;
9
- const FIRST_COLUMN = 1;
10
- const positionOf = (source) => (index) => {
11
- const before = pipe(source, String$1.slice(START, index), String$1.split("\n"));
12
- return {
13
- line: before.length,
14
- column: pipe(Array.last(before), Option.match({
15
- onNone: () => FIRST_COLUMN,
16
- onSome: (last) => last.length + FIRST_COLUMN
17
- }))
18
- };
19
- };
7
+ import { HttpClientResponse } from "effect/http";
20
8
  // src/shared/lib/config-comments.ts
21
9
  const isRecord = (value) => typeof value === "object" && value !== null;
22
10
  const childrenOf = (value) => {
@@ -226,7 +214,6 @@ const isUnused = (condition) => condition.kind === "unused";
226
214
  const NPM = "https://registry.npmjs.org/";
227
215
  const CRATES = "https://crates.io/api/v1/crates/";
228
216
  const GITHUB = "https://api.github.com/repos/";
229
- const USER_AGENT = "msch-exits (https://github.com/masseater/ecosystems/tree/main/libs/msch)";
230
217
  const LOOKUP_CONCURRENCY = 4;
231
218
  const RANGE_OPTIONS = { includePrerelease: true };
232
219
  const DECLARING_SECTIONS = [
@@ -256,18 +243,6 @@ const CrateDependencies = Schema.Struct({ dependencies: Schema.Array(Schema.Stru
256
243
  req: Schema.String
257
244
  })) });
258
245
  const Issue = Schema.Struct({ state: Schema.String });
259
- const requestOf = ({ url, token }) => {
260
- const request = HttpClientRequest.get(url).pipe(HttpClientRequest.setHeader("user-agent", USER_AGENT), HttpClientRequest.acceptJson);
261
- return Option.match(token, {
262
- onNone: () => request,
263
- onSome: (value) => HttpClientRequest.bearerToken(value)(request)
264
- });
265
- };
266
- const fetched = (lookup) => HttpClient.HttpClient.pipe(Effect.flatMap((client) => HttpClient.filterStatusOk(client).execute(requestOf(lookup))));
267
- const publicLookup = (url) => ({
268
- url,
269
- token: Option.none()
270
- });
271
246
  const declaredBy = (version) => pipe(DECLARING_SECTIONS, Array.flatMap((section) => pipe(decodeDependencies(version[section]), Option.map(Record.toEntries), Option.getOrElse(() => []))), Record.fromEntries);
272
247
  const npmRelease = (name) => fetched(publicLookup(`${NPM}${String$1.replace("/", "%2f")(name)}`)).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(NpmPackument)), Effect.map(({ "dist-tags": tags, versions }) => ({
273
248
  versions: Record.keys(versions),
@@ -303,11 +278,11 @@ const isMet = (release) => (condition) => Match.value(condition).pipe(Match.disc
303
278
  declares: declaresMet(release)
304
279
  }));
305
280
  const issueClosed = Effect.fn("issueClosed")(function* lookupIssue(condition) {
306
- const token = yield* Config.option(Config.String("GH_TOKEN").pipe(Config.orElse(() => Config.String("GITHUB_TOKEN")))).pipe(Effect.orElseSucceed(() => Option.none()));
307
- return (yield* fetched({
281
+ const token = yield* githubToken;
282
+ return (yield* fetched(jsonLookup({
308
283
  url: `${GITHUB}${condition.owner}/${condition.repo}/issues/${String(condition.number)}`,
309
284
  token
310
- }).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Issue)))).state === "closed";
285
+ })).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Issue)))).state === "closed";
311
286
  });
312
287
  const conditionMet = (condition) => Match.value(condition).pipe(Match.discriminatorsExhaustive("kind")({
313
288
  unused: () => Effect.succeed(false),
@@ -412,6 +387,6 @@ const upstreamExitsMet = Effect.fn("upstreamExitsMet")(function* upstreamExitsMe
412
387
  }, { concurrency: 1 });
413
388
  return Array.flatten(perFile);
414
389
  });
415
- export { workspaceDeviations as a, tomlSourceComments as c, cargoDeviations as i, yamlSourceComments as l, upstreamExitsMet as n, collectNodes as o, WORKSPACE_SECTIONS as r, isRecord as s, checkUpstreamExits as t, positionOf as u };
390
+ export { workspaceDeviations as a, tomlSourceComments as c, cargoDeviations as i, yamlSourceComments as l, upstreamExitsMet as n, collectNodes as o, WORKSPACE_SECTIONS as r, isRecord as s, checkUpstreamExits as t };
416
391
 
417
- //# sourceMappingURL=upstream-exits-DitN-yYH.mjs.map
392
+ //# sourceMappingURL=upstream-exits-Dp0EeI5D.mjs.map