@dogsbay/corpus 0.2.0-beta.133 → 0.2.0-beta.135

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 CHANGED
@@ -40,9 +40,36 @@ export declare function corpusFromMap(files: CorpusFiles, opts?: MapCorpusOption
40
40
  export interface Unfetched {
41
41
  read: string[];
42
42
  copy: string[];
43
+ /**
44
+ * `copy` with where each file goes in `files` (its output path), in the same order: the host
45
+ * adds the fetched bytes itself, without converting again.
46
+ */
47
+ copyTo: {
48
+ from: string;
49
+ to: string;
50
+ }[];
43
51
  }
52
+ /** `copyTo`'s pairs sorted by source path, and `copy` (the sources) in the same order. */
53
+ export declare function pendingCopies(pairs: {
54
+ from: string;
55
+ to: string;
56
+ }[]): Pick<Unfetched, "copy" | "copyTo">;
44
57
  /**
45
58
  * The ledger message for a conversion that still needs files (undefined when none), with the
46
59
  * error the import stopped on, when it stopped.
47
60
  */
48
61
  export declare function unfetchedMessage(read: string[], stoppedOn?: unknown): string | undefined;
62
+ /**
63
+ * Each written page's source file → its path in the project, from the pages in the order they
64
+ * were written: a later page at the same path replaces an earlier one, whose file then has no
65
+ * page (its notes would otherwise open another file's page).
66
+ */
67
+ export declare function pageSources(written: Iterable<{
68
+ file: string;
69
+ path: string;
70
+ }>): Map<string, string>;
71
+ /** The ledger, each entry about a written page's source file given its `page`. */
72
+ export declare function withPages<E extends {
73
+ file?: string;
74
+ page?: string;
75
+ }>(ledger: E[], pageOf: ReadonlyMap<string, string>): E[];
package/dist/index.js CHANGED
@@ -32,6 +32,11 @@ export function corpusFromMap(files, opts = {}) {
32
32
  missing: () => [...missing].sort(),
33
33
  };
34
34
  }
35
+ /** `copyTo`'s pairs sorted by source path, and `copy` (the sources) in the same order. */
36
+ export function pendingCopies(pairs) {
37
+ const copyTo = [...pairs].sort((a, b) => (a.from < b.from ? -1 : a.from > b.from ? 1 : 0));
38
+ return { copy: copyTo.map((p) => p.from), copyTo };
39
+ }
35
40
  /**
36
41
  * The ledger message for a conversion that still needs files (undefined when none), with the
37
42
  * error the import stopped on, when it stopped.
@@ -43,3 +48,24 @@ export function unfetchedMessage(read, stoppedOn) {
43
48
  const stopped = stoppedOn instanceof Error ? ` It stopped on: ${stoppedOn.message}` : "";
44
49
  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
50
  }
51
+ /**
52
+ * Each written page's source file → its path in the project, from the pages in the order they
53
+ * were written: a later page at the same path replaces an earlier one, whose file then has no
54
+ * page (its notes would otherwise open another file's page).
55
+ */
56
+ export function pageSources(written) {
57
+ const fileAt = new Map();
58
+ for (const { file, path } of written)
59
+ fileAt.set(path, file);
60
+ const pageOf = new Map();
61
+ for (const [path, file] of fileAt)
62
+ pageOf.set(file, path);
63
+ return pageOf;
64
+ }
65
+ /** The ledger, each entry about a written page's source file given its `page`. */
66
+ export function withPages(ledger, pageOf) {
67
+ return ledger.map((e) => {
68
+ const page = e.file === undefined ? undefined : pageOf.get(e.file);
69
+ return page === undefined ? e : { ...e, page };
70
+ });
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dogsbay/corpus",
3
- "version": "0.2.0-beta.133",
3
+ "version": "0.2.0-beta.135",
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.133"
23
+ "@dogsbay/detect": "0.2.0-beta.135"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/node": "^22.20.1",