lens-content-processor 0.78.0 → 0.80.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.
- package/dist/authoring-markup.d.ts +22 -0
- package/dist/authoring-markup.js +24 -0
- package/dist/authoring-markup.js.map +1 -1
- package/dist/cache.d.ts +10 -0
- package/dist/cache.js +6 -5
- package/dist/cache.js.map +1 -1
- package/dist/cli-steps.d.ts +37 -0
- package/dist/cli-steps.js +80 -0
- package/dist/cli-steps.js.map +1 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +52 -70
- package/dist/cli.js.map +1 -1
- package/dist/course-graph.d.ts +2 -2
- package/dist/course-graph.js +7 -2
- package/dist/course-graph.js.map +1 -1
- package/dist/criticmarkup-forms.d.ts +8 -6
- package/dist/criticmarkup-forms.js +22 -19
- package/dist/criticmarkup-forms.js.map +1 -1
- package/dist/dedupe-errors.d.ts +16 -0
- package/dist/dedupe-errors.js +23 -9
- package/dist/dedupe-errors.js.map +1 -1
- package/dist/dependency-cache.d.ts +15 -5
- package/dist/dependency-cache.js +33 -74
- package/dist/dependency-cache.js.map +1 -1
- package/dist/dropped.d.ts +114 -0
- package/dist/dropped.js +253 -0
- package/dist/dropped.js.map +1 -0
- package/dist/engine/assemble.d.ts +44 -0
- package/dist/engine/assemble.js +132 -0
- package/dist/engine/assemble.js.map +1 -0
- package/dist/engine/build.d.ts +8 -0
- package/dist/engine/build.js +558 -0
- package/dist/engine/build.js.map +1 -0
- package/dist/engine/file-facts.d.ts +26 -0
- package/dist/engine/file-facts.js +63 -0
- package/dist/engine/file-facts.js.map +1 -0
- package/dist/engine/git-source.d.ts +35 -0
- package/dist/engine/git-source.js +242 -0
- package/dist/engine/git-source.js.map +1 -0
- package/dist/engine/overlay.d.ts +43 -0
- package/dist/engine/overlay.js +167 -0
- package/dist/engine/overlay.js.map +1 -0
- package/dist/engine/protocol.d.ts +146 -0
- package/dist/engine/protocol.js +40 -0
- package/dist/engine/protocol.js.map +1 -0
- package/dist/engine/reader.d.ts +133 -0
- package/dist/engine/reader.js +298 -0
- package/dist/engine/reader.js.map +1 -0
- package/dist/engine/sources.d.ts +39 -0
- package/dist/engine/sources.js +137 -0
- package/dist/engine/sources.js.map +1 -0
- package/dist/engine/sqlite-store.d.ts +99 -0
- package/dist/engine/sqlite-store.js +452 -0
- package/dist/engine/sqlite-store.js.map +1 -0
- package/dist/engine/store.d.ts +85 -0
- package/dist/engine/store.js +31 -0
- package/dist/engine/store.js.map +1 -0
- package/dist/engine/tables.d.ts +15 -0
- package/dist/engine/tables.js +70 -0
- package/dist/engine/tables.js.map +1 -0
- package/dist/engine/units.d.ts +58 -0
- package/dist/engine/units.js +186 -0
- package/dist/engine/units.js.map +1 -0
- package/dist/engine/version.d.ts +6 -0
- package/dist/engine/version.js +21 -0
- package/dist/engine/version.js.map +1 -0
- package/dist/engine/worker.d.ts +1 -0
- package/dist/engine/worker.js +220 -0
- package/dist/engine/worker.js.map +1 -0
- package/dist/flattener/index.d.ts +34 -17
- package/dist/flattener/index.js +247 -116
- package/dist/flattener/index.js.map +1 -1
- package/dist/flattener/resolve-text-links.d.ts +15 -14
- package/dist/flattener/resolve-text-links.js +24 -25
- package/dist/flattener/resolve-text-links.js.map +1 -1
- package/dist/glossary.d.ts +2 -2
- package/dist/glossary.js.map +1 -1
- package/dist/index.d.ts +168 -2
- package/dist/index.js +888 -616
- package/dist/index.js.map +1 -1
- package/dist/markdown-parse.d.ts +6 -0
- package/dist/markdown-parse.js +14 -0
- package/dist/markdown-parse.js.map +1 -1
- package/dist/parser/learning-outcome.js +11 -2
- package/dist/parser/learning-outcome.js.map +1 -1
- package/dist/parser/lens.d.ts +15 -2
- package/dist/parser/lens.js +38 -11
- package/dist/parser/lens.js.map +1 -1
- package/dist/parser/meeting-doc.d.ts +2 -1
- package/dist/parser/meeting-doc.js +2 -1
- package/dist/parser/meeting-doc.js.map +1 -1
- package/dist/parser/module.d.ts +3 -1
- package/dist/parser/module.js +7 -5
- package/dist/parser/module.js.map +1 -1
- package/dist/parser/question-embeds.d.ts +46 -0
- package/dist/parser/question-embeds.js +302 -0
- package/dist/parser/question-embeds.js.map +1 -0
- package/dist/parser/response-segments.js +12 -0
- package/dist/parser/response-segments.js.map +1 -1
- package/dist/parser/sections.d.ts +18 -0
- package/dist/parser/sections.js +31 -3
- package/dist/parser/sections.js.map +1 -1
- package/dist/parser/widget.d.ts +2 -1
- package/dist/parser/widget.js.map +1 -1
- package/dist/parser/wikilink.d.ts +13 -3
- package/dist/parser/wikilink.js +55 -34
- package/dist/parser/wikilink.js.map +1 -1
- package/dist/reference-graph.d.ts +21 -3
- package/dist/reference-graph.js +35 -12
- package/dist/reference-graph.js.map +1 -1
- package/dist/same-page-links.d.ts +11 -1
- package/dist/same-page-links.js +9 -0
- package/dist/same-page-links.js.map +1 -1
- package/dist/skill-tree.d.ts +2 -1
- package/dist/skill-tree.js.map +1 -1
- package/dist/source-location.d.ts +0 -4
- package/dist/source-location.js +0 -43
- package/dist/source-location.js.map +1 -1
- package/dist/validator/card-module-membership.d.ts +17 -1
- package/dist/validator/card-module-membership.js +60 -56
- package/dist/validator/card-module-membership.js.map +1 -1
- package/dist/validator/criticmarkup.js +1 -1
- package/dist/validator/criticmarkup.js.map +1 -1
- package/dist/validator/field-typos.d.ts +1 -1
- package/dist/validator/field-typos.js +21 -21
- package/dist/validator/field-typos.js.map +1 -1
- package/dist/validator/output-integrity.d.ts +9 -5
- package/dist/validator/output-integrity.js +43 -45
- package/dist/validator/output-integrity.js.map +1 -1
- package/dist/validator/tier.d.ts +2 -2
- package/dist/validator/tier.js.map +1 -1
- package/dist/validator/uuid.d.ts +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ContentSource } from "./protocol.js";
|
|
2
|
+
/** The Git blob id of a file with this text: what `git hash-object` prints. */
|
|
3
|
+
export declare function blobId(text: string): string;
|
|
4
|
+
/** A source over a file map, as `cli.ts --stdin` takes it (path → text). */
|
|
5
|
+
export declare function mapSource(files: Record<string, string> | Map<string, string>): ContentSource;
|
|
6
|
+
/**
|
|
7
|
+
* `source` with `overlays` applied: a text replaces a file or adds one, null
|
|
8
|
+
* deletes one. Overlaid files keep their place in the order; new ones go last.
|
|
9
|
+
*/
|
|
10
|
+
export declare function overlaySource(source: ContentSource, overlays: Record<string, string | null>): ContentSource;
|
|
11
|
+
/**
|
|
12
|
+
* `source` with each of `paths` that has pending CriticMarkup suggestions in
|
|
13
|
+
* its drafts view (every suggestion accepted), with that text's blob id as its
|
|
14
|
+
* version, so a job rebuilds it and everything that reads it.
|
|
15
|
+
*/
|
|
16
|
+
export declare function draftsSource(source: ContentSource, paths: Iterable<string>): ContentSource;
|
|
17
|
+
/**
|
|
18
|
+
* The texts of a source as a map whose keys come in `order`. Texts are read
|
|
19
|
+
* on first use and kept, so a job that touches a few files reads only those.
|
|
20
|
+
* Units read texts here, so a source that fails (for example `git cat-file`
|
|
21
|
+
* dies) throws a Showstopper: the job fails, and the unit's file is not blamed.
|
|
22
|
+
*/
|
|
23
|
+
export declare class SourceTexts implements ReadonlyMap<string, string> {
|
|
24
|
+
private readonly source;
|
|
25
|
+
private readonly index;
|
|
26
|
+
private readonly memo;
|
|
27
|
+
private everything;
|
|
28
|
+
constructor(source: ContentSource, order: Iterable<string>);
|
|
29
|
+
get(path: string): string | undefined;
|
|
30
|
+
has(path: string): boolean;
|
|
31
|
+
get size(): number;
|
|
32
|
+
keys(): MapIterator<string>;
|
|
33
|
+
values(): MapIterator<string>;
|
|
34
|
+
entries(): MapIterator<[string, string]>;
|
|
35
|
+
[Symbol.iterator](): MapIterator<[string, string]>;
|
|
36
|
+
forEach(callback: (value: string, key: string, map: ReadonlyMap<string, string>) => void, thisArg?: unknown): void;
|
|
37
|
+
/** Every text, in order (iterating the values reads every file). */
|
|
38
|
+
private all;
|
|
39
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Content sources for the engine: an explicit file map, overlays and the
|
|
2
|
+
// drafts view over any source, and a lazy text map over a source. The
|
|
3
|
+
// Git-checkout source is in git-source.ts.
|
|
4
|
+
import { createHash } from "crypto";
|
|
5
|
+
import { acceptAllSuggestions } from "../authoring-markup.js";
|
|
6
|
+
import { isContentTextFile } from "../parser/widget.js";
|
|
7
|
+
import { Showstopper } from "./units.js";
|
|
8
|
+
/** The Git blob id of a file with this text: what `git hash-object` prints. */
|
|
9
|
+
export function blobId(text) {
|
|
10
|
+
const bytes = Buffer.from(text, "utf8");
|
|
11
|
+
return createHash("sha1")
|
|
12
|
+
.update(`blob ${bytes.length}\0`)
|
|
13
|
+
.update(bytes)
|
|
14
|
+
.digest("hex");
|
|
15
|
+
}
|
|
16
|
+
/** A source over a file map, as `cli.ts --stdin` takes it (path → text). */
|
|
17
|
+
export function mapSource(files) {
|
|
18
|
+
const texts = files instanceof Map ? new Map(files) : new Map(Object.entries(files));
|
|
19
|
+
const versions = new Map();
|
|
20
|
+
for (const [path, text] of texts)
|
|
21
|
+
versions.set(path, blobId(text));
|
|
22
|
+
return {
|
|
23
|
+
versions: () => versions,
|
|
24
|
+
read(path) {
|
|
25
|
+
const text = texts.get(path);
|
|
26
|
+
if (text === undefined)
|
|
27
|
+
throw new Error(`No such file: ${path}`);
|
|
28
|
+
return text;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `source` with `overlays` applied: a text replaces a file or adds one, null
|
|
34
|
+
* deletes one. Overlaid files keep their place in the order; new ones go last.
|
|
35
|
+
*/
|
|
36
|
+
export function overlaySource(source, overlays) {
|
|
37
|
+
const versions = new Map(source.versions());
|
|
38
|
+
const texts = new Map();
|
|
39
|
+
for (const [path, text] of Object.entries(overlays)) {
|
|
40
|
+
if (text === null) {
|
|
41
|
+
versions.delete(path);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
versions.set(path, blobId(text));
|
|
45
|
+
texts.set(path, text);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
versions: () => versions,
|
|
50
|
+
read(path) {
|
|
51
|
+
if (!versions.has(path))
|
|
52
|
+
throw new Error(`No such file: ${path}`);
|
|
53
|
+
return texts.get(path) ?? source.read(path);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* `source` with each of `paths` that has pending CriticMarkup suggestions in
|
|
59
|
+
* its drafts view (every suggestion accepted), with that text's blob id as its
|
|
60
|
+
* version, so a job rebuilds it and everything that reads it.
|
|
61
|
+
*/
|
|
62
|
+
export function draftsSource(source, paths) {
|
|
63
|
+
const versions = new Map(source.versions());
|
|
64
|
+
const drafts = new Map();
|
|
65
|
+
for (const path of new Set(paths)) {
|
|
66
|
+
if (!versions.has(path) || !isContentTextFile(path))
|
|
67
|
+
continue;
|
|
68
|
+
const text = source.read(path);
|
|
69
|
+
const accepted = acceptAllSuggestions(text);
|
|
70
|
+
if (accepted === text)
|
|
71
|
+
continue;
|
|
72
|
+
drafts.set(path, accepted);
|
|
73
|
+
versions.set(path, blobId(accepted));
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
versions: () => versions,
|
|
77
|
+
read: (path) => drafts.get(path) ?? source.read(path),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The texts of a source as a map whose keys come in `order`. Texts are read
|
|
82
|
+
* on first use and kept, so a job that touches a few files reads only those.
|
|
83
|
+
* Units read texts here, so a source that fails (for example `git cat-file`
|
|
84
|
+
* dies) throws a Showstopper: the job fails, and the unit's file is not blamed.
|
|
85
|
+
*/
|
|
86
|
+
export class SourceTexts {
|
|
87
|
+
source;
|
|
88
|
+
index;
|
|
89
|
+
memo = new Map();
|
|
90
|
+
everything;
|
|
91
|
+
constructor(source, order) {
|
|
92
|
+
this.source = source;
|
|
93
|
+
this.index = new Map([...order].map((path) => [path, true]));
|
|
94
|
+
}
|
|
95
|
+
get(path) {
|
|
96
|
+
if (!this.index.has(path))
|
|
97
|
+
return undefined;
|
|
98
|
+
let text = this.memo.get(path);
|
|
99
|
+
if (text === undefined) {
|
|
100
|
+
try {
|
|
101
|
+
text = this.source.read(path);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
throw new Showstopper(`The content source could not read ${path}: ${error instanceof Error ? error.message : error}`, { cause: error });
|
|
105
|
+
}
|
|
106
|
+
this.memo.set(path, text);
|
|
107
|
+
}
|
|
108
|
+
return text;
|
|
109
|
+
}
|
|
110
|
+
has(path) {
|
|
111
|
+
return this.index.has(path);
|
|
112
|
+
}
|
|
113
|
+
get size() {
|
|
114
|
+
return this.index.size;
|
|
115
|
+
}
|
|
116
|
+
keys() {
|
|
117
|
+
return this.index.keys();
|
|
118
|
+
}
|
|
119
|
+
values() {
|
|
120
|
+
return this.all().values();
|
|
121
|
+
}
|
|
122
|
+
entries() {
|
|
123
|
+
return this.all().entries();
|
|
124
|
+
}
|
|
125
|
+
[Symbol.iterator]() {
|
|
126
|
+
return this.entries();
|
|
127
|
+
}
|
|
128
|
+
forEach(callback, thisArg) {
|
|
129
|
+
this.all().forEach((text, path) => callback.call(thisArg, text, path, this));
|
|
130
|
+
}
|
|
131
|
+
/** Every text, in order (iterating the values reads every file). */
|
|
132
|
+
all() {
|
|
133
|
+
this.everything ??= new Map([...this.index.keys()].map((path) => [path, this.get(path)]));
|
|
134
|
+
return this.everything;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=sources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.js","sourceRoot":"","sources":["../../src/engine/sources.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,sEAAsE;AACtE,2CAA2C;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBA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,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type BuildStore, type PageRecord, type PageSummary, type UnitRecord } from "./store.js";
|
|
2
|
+
/** Commit a batch after this many writes... */
|
|
3
|
+
export declare const BATCH_WRITES = 1000;
|
|
4
|
+
/** ...or once it is this old. A killed job loses at most this much finished work. */
|
|
5
|
+
export declare const BATCH_MS = 1000;
|
|
6
|
+
/** The part of the driver API the store uses (better-sqlite3; node:sqlite has the same names). */
|
|
7
|
+
interface Statement {
|
|
8
|
+
run(...params: unknown[]): unknown;
|
|
9
|
+
get(...params: unknown[]): unknown;
|
|
10
|
+
all(...params: unknown[]): unknown[];
|
|
11
|
+
}
|
|
12
|
+
interface Database {
|
|
13
|
+
prepare(sql: string): Statement;
|
|
14
|
+
exec(sql: string): void;
|
|
15
|
+
close(): void;
|
|
16
|
+
readonly inTransaction: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** The store file for a validator version: `<dir>/build-<version>.sqlite`. */
|
|
19
|
+
export declare function storePathFor(dir: string, version: string): string;
|
|
20
|
+
/** Delete a store file and the files SQLite and the running record keep beside it. */
|
|
21
|
+
export declare function removeStoreFiles(path: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Delete every other `build-*.sqlite` store in the directory of `path`, once the
|
|
24
|
+
* store at `path` is complete. Returns the names of the stores removed. Does
|
|
25
|
+
* nothing when `path` itself is not named `build-*.sqlite`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function removeOtherStores(path: string): string[];
|
|
28
|
+
/**
|
|
29
|
+
* SQLite's answer when a file is not a database or its structure is broken,
|
|
30
|
+
* also when it is the cause of the error the store threw in its place.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isDamagedStoreError(error: unknown): boolean;
|
|
33
|
+
export interface OpenOptions {
|
|
34
|
+
/** The validator version. A store written by another version counts as foreign. */
|
|
35
|
+
version?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Open for reading only, inside one read transaction, so every read sees the
|
|
38
|
+
* same committed state however long the job runs (overlay jobs). The file must
|
|
39
|
+
* exist, and a damaged or foreign file is an error instead of a fresh start.
|
|
40
|
+
*/
|
|
41
|
+
readonly?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Open the store at `path`. A missing, damaged or foreign file (another schema or
|
|
45
|
+
* validator version) is replaced by an empty store, whose `fresh` is true: the next
|
|
46
|
+
* job builds everything. With `readonly`, such a file is an error instead.
|
|
47
|
+
*/
|
|
48
|
+
export declare function openSqliteStore(path: string, options?: OpenOptions): SqliteStore;
|
|
49
|
+
export declare class SqliteStore implements BuildStore {
|
|
50
|
+
private readonly path;
|
|
51
|
+
private readonly readonly;
|
|
52
|
+
/** True when openSqliteStore started an empty store: the file was missing, damaged or foreign. */
|
|
53
|
+
readonly fresh: boolean;
|
|
54
|
+
private readonly db;
|
|
55
|
+
private readonly q;
|
|
56
|
+
private pending;
|
|
57
|
+
private batchStarted;
|
|
58
|
+
/** Depth of atomically() calls: no batch commits while it is above 0. */
|
|
59
|
+
private holding;
|
|
60
|
+
private runningFd;
|
|
61
|
+
private closed;
|
|
62
|
+
/** The error of a write that failed; the store refuses to write after one. */
|
|
63
|
+
private failure;
|
|
64
|
+
/** Use openSqliteStore. */
|
|
65
|
+
constructor(db: Database, path: string, fresh: boolean, readonly: boolean);
|
|
66
|
+
getMeta(key: string): string | undefined;
|
|
67
|
+
setMeta(key: string, value: string): void;
|
|
68
|
+
getFileVersions(): Map<string, string>;
|
|
69
|
+
setFileVersion(path: string, version: string | null): void;
|
|
70
|
+
getUnit(id: string): UnitRecord | undefined;
|
|
71
|
+
listUnitIds(prefix?: string): string[];
|
|
72
|
+
putUnit(record: UnitRecord): void;
|
|
73
|
+
deleteUnit(id: string): void;
|
|
74
|
+
unitsReading(keys: Iterable<string>): string[];
|
|
75
|
+
listPages(): PageSummary[];
|
|
76
|
+
getPage(sourcePath: string, index: number): PageRecord | undefined;
|
|
77
|
+
putPage(page: PageRecord): void;
|
|
78
|
+
deletePage(sourcePath: string, index: number): void;
|
|
79
|
+
getArtifact(name: string): string | undefined;
|
|
80
|
+
getArtifactHash(name: string): string;
|
|
81
|
+
putArtifact(name: string, json: string): void;
|
|
82
|
+
deleteArtifact(name: string): void;
|
|
83
|
+
setRunning(unitId: string | null): void;
|
|
84
|
+
getRunning(): string | null;
|
|
85
|
+
getFailedUnits(): Map<string, string>;
|
|
86
|
+
setFailedUnit(unitId: string, reason: string | null): void;
|
|
87
|
+
commit(): void;
|
|
88
|
+
atomically<T>(apply: () => T): T;
|
|
89
|
+
close(): void;
|
|
90
|
+
/** Run one write inside the current batch, opening one if needed; commit when the batch is due. */
|
|
91
|
+
private write;
|
|
92
|
+
/**
|
|
93
|
+
* The one batch rule: commit after BATCH_WRITES writes or once the batch is
|
|
94
|
+
* BATCH_MS old, but never inside atomically(), and never after a failed write.
|
|
95
|
+
*/
|
|
96
|
+
private commitIfDue;
|
|
97
|
+
private refuseAfterFailure;
|
|
98
|
+
}
|
|
99
|
+
export {};
|