@supa-media/tex-contract 0.0.0-stage → 0.2.7

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 (212) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -2
  3. package/package.json +16 -4
  4. package/texContract/aboutLines.cjs +117 -0
  5. package/texContract/aboutLines.d.cts +14 -0
  6. package/texContract/aboutNoteLimits.cjs +41 -0
  7. package/texContract/aboutNoteLimits.d.cts +5 -0
  8. package/texContract/actionManual.cjs +104 -0
  9. package/texContract/activityHint.cjs +40 -0
  10. package/texContract/activityHint.d.cts +4 -0
  11. package/texContract/asks.cjs +16 -0
  12. package/texContract/asks.d.cts +6 -0
  13. package/texContract/asksToFile.cjs +20 -0
  14. package/texContract/asksToFile.d.cts +2 -0
  15. package/texContract/attention.cjs +138 -0
  16. package/texContract/attention.d.cts +20 -0
  17. package/texContract/browserHandback.cjs +13 -0
  18. package/texContract/browserHandback.d.cts +3 -0
  19. package/texContract/browserOwner.cjs +31 -0
  20. package/texContract/browserOwner.d.cts +2 -0
  21. package/texContract/bytes.cjs +12 -0
  22. package/texContract/chatHistoryPath.cjs +38 -0
  23. package/texContract/chatHistoryPath.d.cts +5 -0
  24. package/texContract/chatLedger.cjs +91 -0
  25. package/texContract/chatLedger.d.cts +21 -0
  26. package/texContract/computerTool.cjs +102 -0
  27. package/texContract/computerTool.d.cts +16 -0
  28. package/texContract/consentYes.cjs +22 -0
  29. package/texContract/consentYes.d.cts +5 -0
  30. package/texContract/contextGateway.cjs +52 -0
  31. package/texContract/contextGateway.d.cts +19 -0
  32. package/texContract/deskEligible.cjs +20 -0
  33. package/texContract/deskEligible.d.cts +3 -0
  34. package/texContract/downloads.cjs +129 -0
  35. package/texContract/downloads.d.cts +15 -0
  36. package/texContract/egressLedger.cjs +114 -0
  37. package/texContract/egressLedger.d.cts +14 -0
  38. package/texContract/emailRead.cjs +38 -0
  39. package/texContract/emailRead.d.cts +5 -0
  40. package/texContract/eventWords.cjs +35 -0
  41. package/texContract/eventWords.d.cts +4 -0
  42. package/texContract/fileParts.cjs +43 -0
  43. package/texContract/fileParts.d.cts +6 -0
  44. package/texContract/fileTables.cjs +243 -0
  45. package/texContract/fileWords.cjs +169 -0
  46. package/texContract/folded.cjs +16 -0
  47. package/texContract/folded.d.cts +3 -0
  48. package/texContract/googleAiAccess.cjs +12 -0
  49. package/texContract/googleAiAccess.d.cts +2 -0
  50. package/texContract/graphWires.cjs +18 -0
  51. package/texContract/graphWires.d.cts +5 -0
  52. package/texContract/groupSession.cjs +28 -0
  53. package/texContract/groupSession.d.cts +7 -0
  54. package/texContract/guestNames.cjs +136 -0
  55. package/texContract/guestNames.d.cts +35 -0
  56. package/texContract/heard.cjs +19 -0
  57. package/texContract/heard.d.cts +4 -0
  58. package/texContract/heldOffer.cjs +57 -0
  59. package/texContract/heldOffer.d.cts +8 -0
  60. package/texContract/helperCallers.cjs +29 -0
  61. package/texContract/helperCallers.d.cts +4 -0
  62. package/texContract/identity.cjs +179 -0
  63. package/texContract/identity.d.cts +8 -0
  64. package/texContract/jobLogEntries.cjs +93 -0
  65. package/texContract/jobLogEntries.d.cts +12 -0
  66. package/texContract/judgedActions.cjs +20 -0
  67. package/texContract/judgedActions.d.cts +4 -0
  68. package/texContract/labSandboxGate.cjs +63 -0
  69. package/texContract/labSandboxGate.d.cts +9 -0
  70. package/texContract/ledgerReadChars.cjs +4 -0
  71. package/texContract/ledgerReadChars.d.cts +3 -0
  72. package/texContract/mailCheck.cjs +90 -0
  73. package/texContract/mailCheck.d.cts +12 -0
  74. package/texContract/mailEntries.cjs +64 -0
  75. package/texContract/mailEntries.d.cts +13 -0
  76. package/texContract/mailHealth.cjs +60 -0
  77. package/texContract/mailHealth.d.cts +10 -0
  78. package/texContract/notePath.cjs +99 -0
  79. package/texContract/notePath.d.cts +4 -0
  80. package/texContract/noteRunFacts.cjs +136 -0
  81. package/texContract/noteRunFacts.d.cts +32 -0
  82. package/texContract/objectEtag.cjs +84 -0
  83. package/texContract/objectEtag.d.cts +4 -0
  84. package/texContract/objectPlace.cjs +32 -0
  85. package/texContract/objectPlace.d.cts +5 -0
  86. package/texContract/pageJobs.cjs +226 -0
  87. package/texContract/pageJobs.d.cts +13 -0
  88. package/texContract/pdfLinks.cjs +135 -0
  89. package/texContract/pdfLinks.d.cts +4 -0
  90. package/texContract/personHub.cjs +38 -0
  91. package/texContract/personHub.d.cts +5 -0
  92. package/texContract/personNameText.cjs +18 -0
  93. package/texContract/personNameText.d.cts +3 -0
  94. package/texContract/pinnedContext.cjs +12 -0
  95. package/texContract/pinnedContext.d.cts +3 -0
  96. package/texContract/quietHoursWindow.cjs +36 -0
  97. package/texContract/quietHoursWindow.d.cts +3 -0
  98. package/texContract/scopeClamp.cjs +117 -0
  99. package/texContract/scopeClamp.d.cts +5 -0
  100. package/texContract/scopes.cjs +29 -0
  101. package/texContract/scopes.d.cts +7 -0
  102. package/texContract/searchSettings.cjs +54 -0
  103. package/texContract/searchSettings.d.cts +6 -0
  104. package/texContract/settingHabits.cjs +87 -0
  105. package/texContract/settingHabits.d.cts +20 -0
  106. package/texContract/settingsNotes.cjs +217 -0
  107. package/texContract/settingsNotes.d.cts +26 -0
  108. package/texContract/shownEmail.cjs +181 -0
  109. package/texContract/texClients.cjs +53 -0
  110. package/texContract/texClients.d.cts +12 -0
  111. package/texContract/texGraph.cjs +593 -0
  112. package/texContract/texGraph.d.cts +55 -0
  113. package/texContract/texKeys.cjs +100 -0
  114. package/texContract/texKeys.d.cts +13 -0
  115. package/texContract/texOwnSources.cjs +9 -0
  116. package/texContract/texOwnSources.d.cts +3 -0
  117. package/texContract/texStoreNames.cjs +26 -0
  118. package/texContract/texStoreNames.d.cts +12 -0
  119. package/texContract/texStoreWire.cjs +306 -0
  120. package/texContract/texStoreWire.d.cts +32 -0
  121. package/texContract/threadsFold.cjs +75 -0
  122. package/texContract/threadsFold.d.cts +22 -0
  123. package/texContract/toolActions.cjs +253 -0
  124. package/texContract/toolCatalog.cjs +49 -0
  125. package/texContract/toolCatalog.generated.json +90 -0
  126. package/texContract/toolContract.cjs +52 -0
  127. package/texContract/toolContract.d.cts +12 -0
  128. package/texContract/toolShapes.cjs +14 -0
  129. package/texContract/transcription.cjs +101 -0
  130. package/texContract/transcription.d.cts +3 -0
  131. package/texContract/treeJobs.cjs +31 -0
  132. package/texContract/treeJobs.d.cts +3 -0
  133. package/texContract/turnSession.cjs +90 -0
  134. package/texContract/turnSession.d.cts +19 -0
  135. package/texContract/turnWords.cjs +90 -0
  136. package/texContract/turnWords.d.cts +9 -0
  137. package/texContract/uploadImages.cjs +131 -0
  138. package/texContract/uploadImages.d.cts +13 -0
  139. package/texContract/v2Names.cjs +41 -0
  140. package/texContract/v2SearchFetch.cjs +316 -0
  141. package/texContract/v2Translate.cjs +123 -0
  142. package/texContract/vaultTools.cjs +112 -0
  143. package/texContract/vaultTools.d.cts +15 -0
  144. package/texContract/yesWords.cjs +91 -0
  145. package/texShared/argumentCoercion.cjs +93 -0
  146. package/texShared/cellComments.cjs +122 -0
  147. package/texShared/cellComments.d.cts +21 -0
  148. package/texShared/comments.cjs +586 -0
  149. package/texShared/comments.d.cts +115 -0
  150. package/texShared/contentTypes.cjs +85 -0
  151. package/texShared/fileKinds.cjs +123 -0
  152. package/texShared/flags.cjs +124 -0
  153. package/texShared/flags.d.cts +21 -0
  154. package/texShared/folderJobInfo.cjs +301 -0
  155. package/texShared/folderJobInfo.d.cts +40 -0
  156. package/texShared/folderRoles.cjs +512 -0
  157. package/texShared/folderRoles.d.cts +73 -0
  158. package/texShared/githubOidc.ts +98 -0
  159. package/texShared/groupRunQuestions.cjs +98 -0
  160. package/texShared/groupRunQuestions.d.cts +4 -0
  161. package/texShared/inboxFolders.cjs +49 -0
  162. package/texShared/inboxFolders.d.cts +5 -0
  163. package/texShared/ink/drawing.cjs +474 -0
  164. package/texShared/ink/texFigure.cjs +252 -0
  165. package/texShared/ink/texFigure.d.cts +36 -0
  166. package/texShared/ink/texPoses.cjs +180 -0
  167. package/texShared/ink/texPoses.d.cts +20 -0
  168. package/texShared/jobPartEnd.cjs +133 -0
  169. package/texShared/jobPartEnd.d.cts +13 -0
  170. package/texShared/jobResume.cjs +31 -0
  171. package/texShared/jobResume.d.cts +5 -0
  172. package/texShared/jobSplit.cjs +90 -0
  173. package/texShared/jobSplit.d.cts +6 -0
  174. package/texShared/jobStart.cjs +56 -0
  175. package/texShared/jobStart.d.cts +9 -0
  176. package/texShared/mail.cjs +400 -0
  177. package/texShared/mail.d.cts +56 -0
  178. package/texShared/messageAnchors.cjs +38 -0
  179. package/texShared/models/aiKeys.cjs +137 -0
  180. package/texShared/models/aiKeys.d.cts +42 -0
  181. package/texShared/models/aiKeys.json +56 -0
  182. package/texShared/models/creditRest.cjs +269 -0
  183. package/texShared/models/promptBudget.cjs +295 -0
  184. package/texShared/models/promptSections.cjs +29 -0
  185. package/texShared/noteAppLink.cjs +23 -0
  186. package/texShared/notePreview.cjs +219 -0
  187. package/texShared/notePreview.d.cts +21 -0
  188. package/texShared/pages/blocks.cjs +215 -0
  189. package/texShared/pages/cover.cjs +164 -0
  190. package/texShared/pages/css.cjs +181 -0
  191. package/texShared/pages/cssBlocks.cjs +264 -0
  192. package/texShared/pages/draw.cjs +212 -0
  193. package/texShared/pages/drawRich.cjs +232 -0
  194. package/texShared/pages/html.cjs +168 -0
  195. package/texShared/pages/inline.cjs +251 -0
  196. package/texShared/pages/layout.cjs +76 -0
  197. package/texShared/pages/parse.cjs +418 -0
  198. package/texShared/pages/render.cjs +200 -0
  199. package/texShared/pages/skill.cjs +147 -0
  200. package/texShared/pages/skill.d.cts +5 -0
  201. package/texShared/pages/templates.cjs +336 -0
  202. package/texShared/r2Store.cjs +163 -0
  203. package/texShared/remoteImage.cjs +177 -0
  204. package/texShared/routines.cjs +656 -0
  205. package/texShared/routines.d.cts +86 -0
  206. package/texShared/servedListing.cjs +250 -0
  207. package/texShared/servedListing.d.cts +17 -0
  208. package/texShared/sheetCsv.cjs +566 -0
  209. package/texShared/sheetCsv.d.cts +91 -0
  210. package/texShared/storageLayout.cjs +88 -0
  211. package/texShared/storeKeys.cjs +144 -0
  212. package/texShared/toolArguments.cjs +323 -0
@@ -0,0 +1,86 @@
1
+ /** Types for `routines.cjs`; see that file for the format and the reasons. */
2
+
3
+ export type RoutineUnit = "minute" | "hour" | "day" | "week" | "month" | "once";
4
+
5
+ export interface RoutineCadence {
6
+ unit: RoutineUnit;
7
+ every: number;
8
+ }
9
+
10
+ export interface ClockTime {
11
+ hour: number;
12
+ minute: number;
13
+ }
14
+
15
+ export type RoutinePath =
16
+ | { kind: "routine"; cadence: RoutineCadence; folder: string; name: string }
17
+ | { kind: "unscheduled"; reason: string };
18
+
19
+ export interface RoutineSettings {
20
+ at: ClockTime | null;
21
+ /** Day numbers, 0 = Sunday. */
22
+ days: number[] | null;
23
+ /** Day of the month, -1 for the last. */
24
+ monthDay: number | null;
25
+ send: "text" | "note" | "both";
26
+ /** Handles without the @, lower-cased. */
27
+ to: string[];
28
+ /** The group chat a shared workspace's routine answers into: 16 hex (`chatRoutineId`). */
29
+ chat: string | null;
30
+ /** `wake: new mail`: a chat routine also runs soon after new mail in a mailbox shared with its chat. */
31
+ wake: "mail" | null;
32
+ until: string | null;
33
+ paused: boolean;
34
+ timeZone: string | null;
35
+ /** A one-off's day (`tex/routines/once/`, or `routines/once/`). */
36
+ date: CivilDate | null;
37
+ /** When a one-off ran, as the gateway wrote it; set means it never runs again. */
38
+ done: string | null;
39
+ }
40
+
41
+ export interface CivilDate {
42
+ year: number;
43
+ month: number;
44
+ day: number;
45
+ }
46
+
47
+ export const ROUTINES_FOLDER: "routines/";
48
+ export const TEX_ROUTINES_FOLDER: "tex/routines/";
49
+ export type RoutineRoot = "tex/routines/" | "routines/";
50
+ export const ROUTINE_ROOTS: readonly RoutineRoot[];
51
+ export const ROUTINE_RUNS_PREFIX: string;
52
+ export const ROUTINE_RUNS_PREFIXES: Readonly<Record<RoutineRoot, string>>;
53
+ export const MIN_INTERVAL_MINUTES: number;
54
+ export const DEFAULT_AT: Readonly<ClockTime>;
55
+ export const DEFAULT_ROUTINE_TIME_ZONE: string;
56
+
57
+ export function cadenceFromFolder(folder: string): RoutineCadence | null;
58
+ export function routineFromPath(path: string): RoutinePath | null;
59
+ export function routineRootOf(path: string): RoutineRoot | null;
60
+ export function isRoutinePath(path: unknown): boolean;
61
+ /** A group chat's home routines folder or a path under it: the home's words and the path read under `tex/routines/`. */
62
+ export function homeRoutineOf(path: unknown): { words: string; routinePath: string } | null;
63
+ export function isHomeRoutinePath(path: unknown): boolean;
64
+ export function frontMatter(text: string): Record<string, string>;
65
+ export function parseTime(value: string): ClockTime | null;
66
+ export function parseWeekdays(value: string): number[] | null;
67
+ export function parseMonthDay(value: string): number | null;
68
+ export function parseDate(value: string): CivilDate | null;
69
+ export function parseDateTime(value: string): { date: CivilDate; time: ClockTime | null } | null;
70
+ export function routineSettings(
71
+ text: string,
72
+ cadence: RoutineCadence | null,
73
+ ): { settings: RoutineSettings; problems: string[] };
74
+ export function nextRunAt(
75
+ cadence: RoutineCadence,
76
+ settings: Partial<RoutineSettings> | null,
77
+ timeZone: string,
78
+ afterMs: number,
79
+ ): number | null;
80
+ export function chatRoutineId(groupKey: string): string | null;
81
+ export function describeSchedule(cadence: RoutineCadence, settings: Partial<RoutineSettings> | null): string;
82
+ export function routineRunsKey(path: string): string;
83
+ export function wallClock(
84
+ ms: number,
85
+ timeZone: string,
86
+ ): { year: number; month: number; day: number; hour: number; minute: number; weekday: number };
@@ -0,0 +1,250 @@
1
+ /**
2
+ * Moved verbatim from `apps/mcp/src/tree/served.js`, which re-exports it: a
3
+ * listing over the store it is handed, with no I/O of its own, which Tex's
4
+ * check-ins read too (`agent/lookTree.js`).
5
+ *
6
+ * The Convex tree, as a listing, for the agent tools that list.
7
+ *
8
+ * `list_notes`, `orient`'s map and counts, `list_contacts`, `list_meetings`,
9
+ * `list_channel_days` and `evaluate_lists` list from the keys the control
10
+ * plane sends (`/gateway/tree/manifest`,
11
+ * `apps/convex/functions/lib/nodes/gatewayManifest.ts`): one request per few
12
+ * thousand keys, read once per tool call and reused by every listing in it.
13
+ * Storage is never listed for them (decided by the owner, 2026-10-13: "the
14
+ * only thing that should be reading from storage directly should be actually
15
+ * opening and editing a note ... I don't want to see even fallbacks").
16
+ *
17
+ * Three things hold it:
18
+ *
19
+ * - **Privacy is decided twice, never once less.** The control plane hands
20
+ * back only what this grant's clearance sees, through the unchanged
21
+ * `syncManifest`; every tool then filters with `canSee` over the
22
+ * workspace's rules, exactly as it filtered the bucket's own listing. A key
23
+ * reaches an agent only if both agree.
24
+ * - **Only `list` changes, and only for note keys.** A listing of plumbing
25
+ * (`.context/`, a dot folder) is Context's own small data, which the tree
26
+ * never holds, and every read and write is the bucket's: note text still
27
+ * comes from the bucket.
28
+ * - **No tree, no listing.** A workspace the tree does not serve
29
+ * (`served: false`), and a request that failed, timed out or came back
30
+ * malformed, are both told the list could not be read just now. Nothing
31
+ * walks the bucket instead (`TreeUnavailable`).
32
+ *
33
+ * Every session has a control plane (decided by the owner, 2026-10-15: there
34
+ * is no mode without one), so a store with no `treeManifest` refuses every
35
+ * listing of names rather than walking storage for them.
36
+ */
37
+ "use strict";
38
+
39
+
40
+ /** Why a listing could not be answered: the control plane could not be asked for the tree. */
41
+ class TreeUnavailable extends Error {
42
+ /** @param {string} [code] why, for logs: `not_served`, `timed_out`, `failed`, `malformed` or `endless` */
43
+ constructor(code = "unreachable") {
44
+ super(TREE_UNREACHABLE);
45
+ this.name = "TreeUnavailable";
46
+ this.reason = "unreachable";
47
+ this.code = code;
48
+ }
49
+ }
50
+
51
+ /** A failed manifest request as a log code: the control plane's own words never leave here. */
52
+ function failureCode(error) {
53
+ if (error instanceof TreeUnavailable) return error.code;
54
+ return /timed out/.test(String(error?.message)) ? "timed_out" : "failed";
55
+ }
56
+
57
+ /** What an agent is told when the control plane could not be asked for the list. */
58
+ const TREE_UNREACHABLE = "this workspace's file list could not be read just now; try again in a moment.";
59
+
60
+ /** Pages of a few thousand keys one call may read: 50 is 200k keys, past the largest workspace. */
61
+ const MANIFEST_PAGES = 50;
62
+
63
+ /**
64
+ * S3 lists in UTF-8 byte order, which is not JavaScript's string order. UTF-8 byte order is code point order, and
65
+ * code point order differs from UTF-16 order only where a surrogate (half of a character past U+FFFF) meets a
66
+ * character from U+E000 to U+FFFF: the surrogate's character is the larger. `unitRank` moves surrogates above that
67
+ * range, so comparing code units gives the byte order without encoding either key. Encoding both on every comparison
68
+ * was most of `orient`'s map in a workspace of 10,000 notes (a sort makes about 140,000 comparisons).
69
+ */
70
+ function unitRank(unit) {
71
+ if (unit < 0xd800) return unit;
72
+ return unit < 0xe000 ? unit + 0x2000 : unit - 0x800;
73
+ }
74
+
75
+ function compareKeys(a, b) {
76
+ const shared = Math.min(a.length, b.length);
77
+ for (let index = 0; index < shared; index += 1) {
78
+ const x = a.charCodeAt(index);
79
+ const y = b.charCodeAt(index);
80
+ if (x !== y) return unitRank(x) - unitRank(y);
81
+ }
82
+ return a.length - b.length;
83
+ }
84
+
85
+ /** A listing the tree never answers: Context's plumbing and every dot folder. */
86
+ function plumbingPrefix(prefix) {
87
+ return prefix.startsWith(".") || prefix.includes("/.");
88
+ }
89
+
90
+ /** The folder whose subtree holds every key under `prefix`, `""` for the whole tree. */
91
+ function folderOf(prefix) {
92
+ const slash = prefix.lastIndexOf("/");
93
+ return slash === -1 ? "" : prefix.slice(0, slash);
94
+ }
95
+
96
+ function covers(folder, wanted) {
97
+ return folder === "" || wanted === folder || wanted.startsWith(`${folder}/`);
98
+ }
99
+
100
+ /**
101
+ * `store`, with `list` answered from the Convex tree. A note listing the tree
102
+ * cannot answer throws `TreeUnavailable`, and so does every later one in the
103
+ * same call; a store with no way to ask the control plane cannot list notes
104
+ * at all.
105
+ *
106
+ * @param {object} store a session-bound store
107
+ * @param {{timeoutMs?: number}} [options] how long each page may take, where nobody waits on it (a check-in)
108
+ */
109
+ function servedListingStore(store, { timeoutMs } = {}) {
110
+ if (typeof store?.treeManifest !== "function") return store?.treeListing ? barrierListing(store) : refusedListing(store);
111
+ /** Folder → its keys, sorted (a promise of them), for each subtree read so far in this call. */
112
+ const subtrees = new Map();
113
+ /** The first refusal, repeated for the rest of the call. */
114
+ let refused = null;
115
+
116
+ async function read(folder) {
117
+ const entries = [];
118
+ let cursor;
119
+ for (let page = 0; page < MANIFEST_PAGES; page += 1) {
120
+ const answer = await store.treeManifest(
121
+ {
122
+ ...(folder === "" ? {} : { folder }),
123
+ ...(cursor === undefined ? {} : { cursor }),
124
+ },
125
+ ...(timeoutMs === undefined ? [] : [{ timeoutMs }])
126
+ );
127
+ if (!answer || answer.served !== true) throw new TreeUnavailable("not_served");
128
+ if (!Array.isArray(answer.entries)) throw new TreeUnavailable("malformed");
129
+ for (const entry of answer.entries) {
130
+ if (entry && typeof entry.path === "string" && entry.path !== "") entries.push(entry);
131
+ }
132
+ if (answer.cursor === null) {
133
+ entries.sort((a, b) => compareKeys(a.path, b.path));
134
+ return entries;
135
+ }
136
+ if (answer.cursor === cursor) throw new TreeUnavailable("endless");
137
+ cursor = answer.cursor;
138
+ }
139
+ // More pages than any workspace holds is a walk that is not ending.
140
+ throw new TreeUnavailable("endless");
141
+ }
142
+
143
+ /** The keys under `prefix`, or null for plumbing, which the bucket lists. */
144
+ async function keysUnder(prefix) {
145
+ if (plumbingPrefix(prefix)) return null;
146
+ if (refused !== null) throw refused;
147
+ const folder = folderOf(prefix);
148
+ for (const [held, entries] of subtrees) {
149
+ if (covers(held, folder)) return await entries;
150
+ }
151
+ // The promise is held, not its answer, so listings started side by side
152
+ // (orient's map and its chaos score) share one request.
153
+ const reading = (async () => {
154
+ try {
155
+ return await read(folder);
156
+ } catch (error) {
157
+ refused = error instanceof TreeUnavailable ? error : new TreeUnavailable(failureCode(error));
158
+ throw refused;
159
+ }
160
+ })();
161
+ subtrees.set(folder, reading);
162
+ return await reading;
163
+ }
164
+
165
+ const listing = Object.create(store);
166
+ /** Every key the tree holds for this grant; throws `TreeUnavailable` where it cannot answer. */
167
+ listing.treeKeys = async () => (await keysUnder("")).map((entry) => entry.path);
168
+ /** Every key the tree holds for this grant, as listed objects (`orient`'s survey); throws likewise. */
169
+ listing.treeEntries = async () => (await keysUnder("")).map(objectOf);
170
+ listing.list = async (options = {}) => {
171
+ const prefix = options.prefix ?? "";
172
+ const entries = await keysUnder(prefix);
173
+ if (entries === null) return await store.list(options);
174
+ const cursor = typeof options.cursor === "string" && options.cursor !== "" ? options.cursor : options.startAfter;
175
+ const inside = entries.filter(
176
+ (entry) => entry.path.startsWith(prefix) && (cursor === undefined || compareKeys(entry.path, cursor) > 0)
177
+ );
178
+ if (options.delimiter === "/") {
179
+ // One level, the whole of it in one answer: the immediate keys, and the
180
+ // folders below as `delimitedPrefixes`, the way the S3 adapter returns them.
181
+ const objects = [];
182
+ const delimitedPrefixes = new Set();
183
+ for (const entry of inside) {
184
+ const rest = entry.path.slice(prefix.length);
185
+ const slash = rest.indexOf("/");
186
+ if (slash === -1) objects.push(objectOf(entry));
187
+ else delimitedPrefixes.add(`${prefix}${rest.slice(0, slash + 1)}`);
188
+ }
189
+ return { objects, delimitedPrefixes: [...delimitedPrefixes], truncated: false };
190
+ }
191
+ const limit = Number.isInteger(options.limit) && options.limit > 0 ? options.limit : 1000;
192
+ const page = inside.slice(0, limit);
193
+ const truncated = inside.length > page.length;
194
+ return {
195
+ objects: page.map(objectOf),
196
+ truncated,
197
+ ...(truncated ? { cursor: page[page.length - 1].path } : {}),
198
+ };
199
+ };
200
+ return listing;
201
+ }
202
+
203
+ /** A manifest entry as a listed object. */
204
+ function objectOf(entry) {
205
+ return {
206
+ key: entry.path,
207
+ ...(typeof entry.etag === "string" && entry.etag !== "" ? { etag: entry.etag } : {}),
208
+ ...(Number.isFinite(entry.size) ? { size: entry.size } : {}),
209
+ ...(Number.isFinite(entry.updatedAt) ? { uploaded: new Date(entry.updatedAt) } : {}),
210
+ // The row's note id: search by meaning files a note's passages under it,
211
+ // so a move or rename keeps them (`search/meaning/project.js`).
212
+ ...(typeof entry.noteId === "string" && entry.noteId !== "" ? { noteId: entry.noteId } : {}),
213
+ };
214
+ }
215
+
216
+ /**
217
+ * A store inside the Convex credential barrier, which reads the tree's rows directly and attaches them as
218
+ * `treeListing` (`lib/nodes/treeNames.ts`): its listing is that one, never the bucket's.
219
+ */
220
+ function barrierListing(store) {
221
+ const listing = Object.create(store);
222
+ // Plumbing (`.context/`) is Context's own small data, which the tree never holds: the bucket lists it.
223
+ listing.list = async (options = {}) =>
224
+ plumbingPrefix(options.prefix ?? "") ? await store.list(options) : await store.treeListing.list(options);
225
+ listing.treeEntries = async () => {
226
+ const objects = [];
227
+ for (let cursor; ; ) {
228
+ const page = await store.treeListing.list({ ...(cursor === undefined ? {} : { cursor }), limit: 1000 });
229
+ objects.push(...(page.objects ?? []).filter((object) => !plumbingPrefix(object.key)));
230
+ if (!page.truncated || !page.cursor || page.cursor === cursor) return objects;
231
+ cursor = page.cursor;
232
+ }
233
+ };
234
+ listing.treeKeys = async () => (await listing.treeEntries()).map((object) => object.key);
235
+ return listing;
236
+ }
237
+
238
+ /** A store with no control plane (see the header): every listing of names is refused. */
239
+ function refusedListing(store) {
240
+ const listing = Object.create(store);
241
+ const refuse = async () => {
242
+ throw new TreeUnavailable();
243
+ };
244
+ listing.treeKeys = refuse;
245
+ listing.treeEntries = refuse;
246
+ listing.list = refuse;
247
+ return listing;
248
+ }
249
+
250
+ module.exports = { TreeUnavailable, TREE_UNREACHABLE, compareKeys, servedListingStore, objectOf };
@@ -0,0 +1,17 @@
1
+ /** Types for `servedListing.cjs`; see that file. */
2
+
3
+ export declare class TreeUnavailable extends Error {
4
+ constructor(code?: string);
5
+ reason: "unreachable";
6
+ code: string;
7
+ }
8
+ export declare const TREE_UNREACHABLE: string;
9
+ export declare function compareKeys(a: string, b: string): number;
10
+ export declare function servedListingStore(store: any, options?: { timeoutMs?: number }): any;
11
+ export declare function objectOf(entry: { path: string; etag?: string; size?: number; updatedAt?: number; noteId?: string }): {
12
+ key: string;
13
+ etag?: string;
14
+ size?: number;
15
+ uploaded?: Date;
16
+ noteId?: string;
17
+ };