@dogsbay/corpus 0.2.0-beta.132 → 0.2.0-beta.133
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +31 -1
- package/dist/index.js +20 -3
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,38 @@ export interface Corpus {
|
|
|
11
11
|
contains?(path: string, dir: string): boolean;
|
|
12
12
|
}
|
|
13
13
|
export type CorpusFiles = Map<string, string | Uint8Array>;
|
|
14
|
+
export interface MapCorpusOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Every path of the repo (relative to the same root as `files`), when the host knows more
|
|
17
|
+
* files than it has fetched — the playground lists a GitHub tree and fetches as it goes.
|
|
18
|
+
* The corpus lists them all, so the import sees the repo as it is; reading one that `files`
|
|
19
|
+
* does not hold returns undefined and is recorded (`missing`).
|
|
20
|
+
*/
|
|
21
|
+
paths?: Iterable<string>;
|
|
22
|
+
}
|
|
23
|
+
export interface MapCorpus extends Corpus {
|
|
24
|
+
/** Listed paths the import read but `files` did not hold, sorted: fetch them and run it again. */
|
|
25
|
+
missing(): string[];
|
|
26
|
+
}
|
|
14
27
|
/**
|
|
15
28
|
* A corpus over a map of files; bytes are read as UTF-8. A key that is not a plain path
|
|
16
29
|
* (`../x`, `/etc/x`, `a/./b`, a backslash) is left out: the keys come from someone else's repo.
|
|
17
30
|
*/
|
|
18
|
-
export declare function corpusFromMap(files: CorpusFiles):
|
|
31
|
+
export declare function corpusFromMap(files: CorpusFiles, opts?: MapCorpusOptions): MapCorpus;
|
|
32
|
+
/**
|
|
33
|
+
* What a browser conversion still needs, when the host listed more paths than it fetched:
|
|
34
|
+
* `read` the import read (fetch them and convert again: the result changes), `copy` the
|
|
35
|
+
* output copies as they are (fetch them for the finished files; nothing is converted again).
|
|
36
|
+
* Both empty: the result is complete. Each round can find one more level of an include or
|
|
37
|
+
* `require` chain, so a host caps the rounds; a result with `read` not empty is not a
|
|
38
|
+
* conversion (its `files` may be empty: the import could not go on without them).
|
|
39
|
+
*/
|
|
40
|
+
export interface Unfetched {
|
|
41
|
+
read: string[];
|
|
42
|
+
copy: string[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The ledger message for a conversion that still needs files (undefined when none), with the
|
|
46
|
+
* error the import stopped on, when it stopped.
|
|
47
|
+
*/
|
|
48
|
+
export declare function unfetchedMessage(read: string[], stoppedOn?: unknown): string | undefined;
|
package/dist/index.js
CHANGED
|
@@ -12,17 +12,34 @@ import { isPlainPath } from "@dogsbay/detect";
|
|
|
12
12
|
* A corpus over a map of files; bytes are read as UTF-8. A key that is not a plain path
|
|
13
13
|
* (`../x`, `/etc/x`, `a/./b`, a backslash) is left out: the keys come from someone else's repo.
|
|
14
14
|
*/
|
|
15
|
-
export function corpusFromMap(files) {
|
|
15
|
+
export function corpusFromMap(files, opts = {}) {
|
|
16
16
|
const decoder = new TextDecoder();
|
|
17
|
-
const paths = [...files.keys()].filter(isPlainPath).sort();
|
|
17
|
+
const paths = [...new Set([...files.keys(), ...(opts.paths ?? [])])].filter(isPlainPath).sort();
|
|
18
18
|
const listed = new Set(paths);
|
|
19
|
+
const missing = new Set();
|
|
19
20
|
return {
|
|
20
21
|
paths,
|
|
21
22
|
text(path) {
|
|
22
23
|
if (!listed.has(path))
|
|
23
24
|
return undefined;
|
|
24
25
|
const v = files.get(path);
|
|
25
|
-
|
|
26
|
+
if (v === undefined) {
|
|
27
|
+
missing.add(path);
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return typeof v === "string" ? v : decoder.decode(v);
|
|
26
31
|
},
|
|
32
|
+
missing: () => [...missing].sort(),
|
|
27
33
|
};
|
|
28
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* The ledger message for a conversion that still needs files (undefined when none), with the
|
|
37
|
+
* error the import stopped on, when it stopped.
|
|
38
|
+
*/
|
|
39
|
+
export function unfetchedMessage(read, stoppedOn) {
|
|
40
|
+
if (!read.length)
|
|
41
|
+
return undefined;
|
|
42
|
+
const names = `${read.slice(0, 3).join(", ")}${read.length > 3 ? ", …" : ""}`;
|
|
43
|
+
const stopped = stoppedOn instanceof Error ? ` It stopped on: ${stoppedOn.message}` : "";
|
|
44
|
+
return `${read.length} file${read.length === 1 ? "" : "s"} the conversion reads ${read.length === 1 ? "was" : "were"} not given (${names}): fetch them and convert again.${stopped}`;
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dogsbay/corpus",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.133",
|
|
4
4
|
"description": "A documentation repository as its importers read it, in the browser or in Node: plain paths plus text on demand, from a map of files or from a folder whose symlinks are kept inside it",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"README.md"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dogsbay/detect": "0.2.0-beta.
|
|
23
|
+
"@dogsbay/detect": "0.2.0-beta.133"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^22.20.1",
|