@superbee/core 0.2.0-pre.52 → 0.2.0-pre.54

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.
Files changed (69) hide show
  1. package/README.md +39 -1
  2. package/dist/backend.d.ts +9 -0
  3. package/dist/backend.d.ts.map +1 -1
  4. package/dist/backend.js +9 -0
  5. package/dist/backend.js.map +1 -1
  6. package/dist/body-replace-guards.d.ts +1 -1
  7. package/dist/body-replace-guards.d.ts.map +1 -1
  8. package/dist/body-replace-guards.js.map +1 -1
  9. package/dist/dependencies.d.ts +107 -1
  10. package/dist/dependencies.d.ts.map +1 -1
  11. package/dist/dependencies.js +160 -0
  12. package/dist/dependencies.js.map +1 -1
  13. package/dist/document-mutation.d.ts.map +1 -1
  14. package/dist/document-mutation.js +6 -3
  15. package/dist/document-mutation.js.map +1 -1
  16. package/dist/document-replace-rules.d.ts +44 -0
  17. package/dist/document-replace-rules.d.ts.map +1 -0
  18. package/dist/document-replace-rules.js +41 -0
  19. package/dist/document-replace-rules.js.map +1 -0
  20. package/dist/engine.d.ts.map +1 -1
  21. package/dist/engine.js +3 -2
  22. package/dist/engine.js.map +1 -1
  23. package/dist/filesystem-identity.d.ts +10 -0
  24. package/dist/filesystem-identity.d.ts.map +1 -1
  25. package/dist/filesystem-identity.js +28 -9
  26. package/dist/filesystem-identity.js.map +1 -1
  27. package/dist/hosted-transport/carrier.d.ts +3 -0
  28. package/dist/hosted-transport/carrier.d.ts.map +1 -1
  29. package/dist/hosted-transport/carrier.js +6 -1
  30. package/dist/hosted-transport/carrier.js.map +1 -1
  31. package/dist/hosted-transport/whole-document-transport.d.ts.map +1 -1
  32. package/dist/hosted-transport/whole-document-transport.js +2 -0
  33. package/dist/hosted-transport/whole-document-transport.js.map +1 -1
  34. package/dist/index.d.ts +7 -2
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +5 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/kind-authoring.d.ts +2 -0
  39. package/dist/kind-authoring.d.ts.map +1 -1
  40. package/dist/kind-authoring.js +31 -3
  41. package/dist/kind-authoring.js.map +1 -1
  42. package/dist/kinds.js +3 -3
  43. package/dist/kinds.js.map +1 -1
  44. package/dist/link-add.d.ts +81 -0
  45. package/dist/link-add.d.ts.map +1 -0
  46. package/dist/link-add.js +94 -0
  47. package/dist/link-add.js.map +1 -0
  48. package/dist/local-search-index.d.ts +62 -0
  49. package/dist/local-search-index.d.ts.map +1 -0
  50. package/dist/local-search-index.js +690 -0
  51. package/dist/local-search-index.js.map +1 -0
  52. package/dist/okf-authoring.d.ts +1 -1
  53. package/dist/okf-authoring.d.ts.map +1 -1
  54. package/dist/okf-authoring.js +10 -3
  55. package/dist/okf-authoring.js.map +1 -1
  56. package/dist/recipe-lifecycle/evolution.d.ts.map +1 -1
  57. package/dist/recipe-lifecycle/evolution.js +5 -2
  58. package/dist/recipe-lifecycle/evolution.js.map +1 -1
  59. package/dist/recipe-lifecycle/install.d.ts +4 -3
  60. package/dist/recipe-lifecycle/install.d.ts.map +1 -1
  61. package/dist/recipe-lifecycle/install.js +22 -20
  62. package/dist/recipe-lifecycle/install.js.map +1 -1
  63. package/dist/search-index.d.ts +7 -0
  64. package/dist/search-index.d.ts.map +1 -0
  65. package/dist/search-index.js +7 -0
  66. package/dist/search-index.js.map +1 -0
  67. package/dist/source-profiles/index.d.ts +1 -1
  68. package/dist/source-profiles/index.js +1 -1
  69. package/package.json +13 -1
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The rules for adding one link to a document body: which targets and texts a link writer refuses,
3
+ * and the href it writes. Pure and browser-safe. Each refusal is a {@link LinkAddRefusedError} with
4
+ * a stable `reason` and the facts a caller needs to word its own error.
5
+ */
6
+ import { InvalidInputError } from "./errors.js";
7
+ import { emitLinkHref } from "./link-emit.js";
8
+ import { extractMarkdownLinks, relativeHref, resolveConceptId } from "./links.js";
9
+ import { pathFromConceptId, isReservedFile } from "./paths.js";
10
+ import { isQualifiedHref, parseQualifiedHref } from "./qualified-links.js";
11
+ /** A link add the engine refuses. `refusal` carries the reason and its facts. */
12
+ export class LinkAddRefusedError extends InvalidInputError {
13
+ reason;
14
+ refusal;
15
+ constructor(refusal) {
16
+ super(linkAddRefusalMessage(refusal));
17
+ this.name = "LinkAddRefusedError";
18
+ this.reason = refusal.reason;
19
+ this.refusal = refusal;
20
+ }
21
+ }
22
+ function linkAddRefusalMessage(refusal) {
23
+ switch (refusal.reason) {
24
+ case "reserved_target":
25
+ return `'${refusal.to}' names a reserved OKF file (index.md/log.md), which cannot be a link target.`;
26
+ case "text_not_writable":
27
+ return "Link text must not contain '[', ']', '\\' or a line break.";
28
+ case "href_not_readable":
29
+ return `'${refusal.to}' cannot be written as a link from '${refusal.from}' that resolves back to it (href '${refusal.href}').`;
30
+ case "qualified_href_invalid":
31
+ return `'${refusal.target}' is not a valid cross-bundle target: ${refusal.detail}`;
32
+ case "alias_mismatch":
33
+ return `The alias '${refusal.alias}' disagrees with the alias '${refusal.hrefAlias}' in '${refusal.target}'.`;
34
+ case "alias_missing":
35
+ return "A cross-bundle link needs a non-empty bundle alias.";
36
+ case "qualified_target_invalid":
37
+ return `'${refusal.target}' in bundle '${refusal.alias}' is not a valid cross-bundle target: ${refusal.detail}`;
38
+ }
39
+ }
40
+ /** Refuse link text the link scanner cannot read back verbatim: it honors no backslash escapes. */
41
+ export function assertLinkTextWritable(text) {
42
+ if (/[[\]\\\r\n]/.test(text))
43
+ throw new LinkAddRefusedError({ reason: "text_not_writable", text });
44
+ }
45
+ /**
46
+ * Check a link from `from` to `to` in the same bundle and return the href to write. Refuses a
47
+ * reserved target, unwritable text, and a target whose href would not read back as this one edge
48
+ * (for example one that reads as an external or in-page href, such as `mailto:`).
49
+ */
50
+ export function planLocalLinkAdd(from, to, text) {
51
+ const href = relativeHref(from, to);
52
+ const normalizedTo = resolveConceptId(from, href) ?? to;
53
+ if (isReservedFile(pathFromConceptId(normalizedTo)))
54
+ throw new LinkAddRefusedError({ reason: "reserved_target", to });
55
+ assertLinkTextWritable(text);
56
+ const readBack = extractMarkdownLinks(`[${text}](${href})`);
57
+ if (readBack.length !== 1 || readBack[0].href !== href || resolveConceptId(from, href) !== to) {
58
+ throw new LinkAddRefusedError({ reason: "href_not_readable", from, to, href });
59
+ }
60
+ return { href, normalizedTo };
61
+ }
62
+ /**
63
+ * Check a cross-bundle link target and return the `okf:` href to write. `target` is an id
64
+ * (optionally ending `.md`) under `alias`, or a whole `okf://<alias>/<id>.md` href, in which case
65
+ * `alias`, when given, must agree. Link text is checked separately by {@link assertLinkTextWritable}.
66
+ */
67
+ export function planQualifiedLinkAdd(target, alias) {
68
+ let id = target.replace(/\.md$/, "");
69
+ let fragment;
70
+ if (isQualifiedHref(target)) {
71
+ const parsed = parseQualifiedHref(target);
72
+ if (!parsed.ok)
73
+ throw new LinkAddRefusedError({ reason: "qualified_href_invalid", target, detail: parsed.detail });
74
+ if (alias !== undefined && alias !== parsed.ref.alias) {
75
+ throw new LinkAddRefusedError({ reason: "alias_mismatch", target, alias, hrefAlias: parsed.ref.alias });
76
+ }
77
+ alias = parsed.ref.alias;
78
+ id = parsed.ref.id;
79
+ fragment = parsed.fragment;
80
+ }
81
+ if (!alias)
82
+ throw new LinkAddRefusedError({ reason: "alias_missing" });
83
+ let href;
84
+ try {
85
+ href = emitLinkHref({ kind: "qualified", alias, id, ...(fragment === undefined ? {} : { fragment }) });
86
+ }
87
+ catch (err) {
88
+ if (!(err instanceof InvalidInputError))
89
+ throw err;
90
+ throw new LinkAddRefusedError({ reason: "qualified_target_invalid", target, alias, detail: err.message });
91
+ }
92
+ return { alias, id, href };
93
+ }
94
+ //# sourceMappingURL=link-add.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link-add.js","sourceRoot":"","sources":["../src/link-add.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAg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AAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5G,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,62 @@
1
+ import type { SearchSource } from "./search/source.js";
2
+ import type { StorageBackend } from "./types.js";
3
+ /**
4
+ * Names what an index file was built by: this file's schema and `textVersion()` (the ranking
5
+ * algorithm, the text revision and the runtime's normalizer fingerprint). Two builds with different
6
+ * keys cannot share a file; put the key in the index file name so two tool versions or two Node
7
+ * versions sharing a state folder each keep their own index instead of rebuilding each other's.
8
+ * Sixteen lowercase hex characters. The file still records and checks these inputs itself.
9
+ */
10
+ export declare function localSearchIndexFileKey(): string;
11
+ export type LocalSearchIndexUnavailableReason =
12
+ /** This Node has no `node:sqlite` (older than 22.13, or built without it). */
13
+ "sqlite-unavailable"
14
+ /** The SQLite this Node links has no FTS5, or an FTS5 older than contentless delete (3.43). */
15
+ | "fts5-unavailable"
16
+ /** The index path is inside the bundle folder, where an index must never be written. */
17
+ | "index-inside-bundle"
18
+ /** The index file cannot be created, opened or replaced (permissions, a read-only disk, a
19
+ * corrupt file another process holds open). */
20
+ | "index-unusable";
21
+ /** The local index cannot be used here. A caller can fall back to the in-memory source. */
22
+ export declare class LocalSearchIndexUnavailableError extends Error {
23
+ readonly reason: LocalSearchIndexUnavailableReason;
24
+ constructor(reason: LocalSearchIndexUnavailableReason, options?: {
25
+ cause?: unknown;
26
+ });
27
+ }
28
+ export interface LocalSearchIndexOptionsV1 {
29
+ /** Reads the bundle's documents; the index derives every row from these reads. */
30
+ readonly backend: Pick<StorageBackend, "list" | "read" | "readMany" | "readReserved">;
31
+ /** The bundle folder the backend reads; the index must lie outside it. With a
32
+ * `FilesystemBackend`, files whose content stamp still stands are not read again. */
33
+ readonly root: string;
34
+ /** The index file, outside `root`. Its folder is created (private) when missing. */
35
+ readonly indexPath: string;
36
+ }
37
+ export interface LocalSearchIndexV1 extends SearchSource {
38
+ /** Releases the database handle; the source cannot be used afterwards. */
39
+ close(): void;
40
+ }
41
+ /** A file's content stamp: equal stamps mean equal bytes once the stamp has settled. */
42
+ export interface ContentStampV1 {
43
+ readonly value: string;
44
+ readonly settled: boolean;
45
+ }
46
+ /** Replaceable host edges, for tests. */
47
+ export interface LocalSearchIndexSeams {
48
+ /** Resolves to the `node:sqlite` module. Typed loosely so the published declarations need no
49
+ * `node:sqlite` types. */
50
+ readonly loadSqlite?: () => Promise<unknown>;
51
+ /** How long a write waits for another process's write transaction. */
52
+ readonly busyTimeoutMs?: number;
53
+ /** A document's stamp by id; `undefined` when none is trustworthy: it is then read on every search. */
54
+ readonly contentStamp?: (id: string) => Promise<ContentStampV1 | undefined>;
55
+ }
56
+ /**
57
+ * Opens (creating or rebuilding as needed) the index for one bundle. Throws
58
+ * `LocalSearchIndexUnavailableError` when this host cannot keep one.
59
+ */
60
+ export declare function openLocalSearchIndex(options: LocalSearchIndexOptionsV1): Promise<LocalSearchIndexV1>;
61
+ export declare function openLocalSearchIndexWith(options: LocalSearchIndexOptionsV1, seams: LocalSearchIndexSeams): Promise<LocalSearchIndexV1>;
62
+ //# sourceMappingURL=local-search-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-search-index.d.ts","sourceRoot":"","sources":["../src/local-search-index.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EAIV,YAAY,EAEb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAQjD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD;AAkBD,MAAM,MAAM,iCAAiC;AAC3C,8EAA8E;AAC5E,oBAAoB;AACtB,+FAA+F;GAC7F,kBAAkB;AACpB,wFAAwF;GACtF,qBAAqB;AACvB;+CAC+C;GAC7C,gBAAgB,CAAC;AAErB,2FAA2F;AAC3F,qBAAa,gCAAiC,SAAQ,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