@dreamlake/dreamlake-cli 0.104.7 → 0.105.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/api/content.d.ts +4 -3
- package/dist/api/index.d.ts +33 -23
- package/dist/api/index.js +25 -16
- package/dist/api/memo-character-plan.d.ts +2 -0
- package/dist/api/memo-character-plan.js +2 -0
- package/dist/api/memo-editing.d.ts +2 -0
- package/dist/api/memo-editing.js +2 -0
- package/dist/api/memo-edits.d.ts +63 -0
- package/dist/api/memo-edits.js +206 -0
- package/dist/api/memo-events.d.ts +44 -0
- package/dist/api/memo-events.js +65 -0
- package/dist/api/memo-facade.d.ts +294 -0
- package/dist/api/memo-facade.js +382 -0
- package/dist/api/memo-files.d.ts +111 -0
- package/dist/api/memo-files.js +110 -0
- package/dist/api/memo-html-read.d.ts +2 -0
- package/dist/api/memo-html-read.js +2 -0
- package/dist/api/memo-html.d.ts +2 -0
- package/dist/api/memo-html.js +2 -0
- package/dist/api/memo-linger.d.ts +85 -0
- package/dist/api/memo-linger.js +271 -0
- package/dist/api/memo-presence.d.ts +109 -0
- package/dist/api/memo-presence.js +75 -0
- package/dist/api/memo-reading.d.ts +55 -0
- package/dist/api/memo-reading.js +43 -0
- package/dist/api/memo-toc.d.ts +2 -0
- package/dist/api/memo-toc.js +2 -0
- package/dist/api/memo-write.d.ts +119 -0
- package/dist/api/memo-write.js +221 -0
- package/dist/api/memos.d.ts +344 -0
- package/dist/api/memos.js +231 -0
- package/dist/api/note-character-plan.d.ts +2 -2
- package/dist/api/note-character-plan.js +2 -2
- package/dist/api/note-editing.d.ts +2 -2
- package/dist/api/note-editing.js +2 -2
- package/dist/api/note-edits.d.ts +2 -59
- package/dist/api/note-edits.js +2 -205
- package/dist/api/note-events.d.ts +2 -41
- package/dist/api/note-events.js +2 -64
- package/dist/api/note-facade.d.ts +2 -268
- package/dist/api/note-facade.js +2 -376
- package/dist/api/note-files.d.ts +2 -102
- package/dist/api/note-files.js +2 -107
- package/dist/api/note-html-read.d.ts +2 -2
- package/dist/api/note-html-read.js +2 -2
- package/dist/api/note-html.d.ts +2 -2
- package/dist/api/note-html.js +2 -2
- package/dist/api/note-linger.d.ts +2 -83
- package/dist/api/note-linger.js +2 -270
- package/dist/api/note-presence.d.ts +2 -100
- package/dist/api/note-presence.js +2 -73
- package/dist/api/note-reading.d.ts +2 -51
- package/dist/api/note-reading.js +2 -42
- package/dist/api/note-toc.d.ts +2 -2
- package/dist/api/note-toc.js +2 -2
- package/dist/api/note-write.d.ts +2 -110
- package/dist/api/note-write.js +2 -217
- package/dist/api/notes.d.ts +2 -335
- package/dist/api/notes.js +2 -230
- package/dist/api/open-resources.js +3 -3
- package/dist/api/workspace.d.ts +3 -2
- package/dist/api/workspace.js +7 -6
- package/dist/cli/artifact/index.js +3 -3
- package/dist/cli/folders/index.d.ts +1 -1
- package/dist/cli/folders/index.js +4 -4
- package/dist/cli/help-examples.generated.js +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/cli/{notes → memos}/api-transport.d.ts +1 -1
- package/dist/cli/{notes → memos}/api-transport.js +1 -1
- package/dist/cli/{notes → memos}/archive-command.d.ts +1 -1
- package/dist/cli/{notes → memos}/archive-command.js +5 -5
- package/dist/cli/{notes → memos}/character-plan.d.ts +3 -1
- package/dist/cli/{notes → memos}/character-plan.js +7 -5
- package/dist/cli/{notes → memos}/document.d.ts +9 -9
- package/dist/cli/{notes → memos}/document.js +12 -12
- package/dist/cli/{notes → memos}/edit-commands.d.ts +8 -8
- package/dist/cli/{notes → memos}/edit-commands.js +14 -14
- package/dist/cli/{notes → memos}/events.d.ts +3 -3
- package/dist/cli/{notes → memos}/events.js +2 -2
- package/dist/cli/{notes → memos}/files-commands.d.ts +2 -2
- package/dist/cli/{notes → memos}/files-commands.js +5 -5
- package/dist/cli/{notes → memos}/index.d.ts +16 -16
- package/dist/cli/{notes → memos}/index.js +53 -53
- package/dist/cli/{notes → memos}/linger.d.ts +3 -3
- package/dist/cli/{notes → memos}/linger.js +5 -5
- package/dist/cli/{notes → memos}/move-command.d.ts +5 -5
- package/dist/cli/{notes → memos}/move-command.js +6 -6
- package/dist/cli/{notes → memos}/rm-command.d.ts +2 -2
- package/dist/cli/{notes → memos}/rm-command.js +2 -2
- package/dist/cli/{notes → memos}/select-command.d.ts +1 -1
- package/dist/cli/{notes → memos}/select-command.js +4 -4
- package/dist/cli/{notes → memos}/suggest-diff.d.ts +1 -1
- package/dist/cli/{notes → memos}/suggest-diff.js +2 -2
- package/dist/cli/{notes → memos}/transfer-command.d.ts +2 -2
- package/dist/cli/{notes → memos}/transfer-command.js +2 -2
- package/dist/cli/share.d.ts +1 -1
- package/dist/cli/share.js +10 -6
- package/dist/cli/update/index.js +3 -3
- package/dist/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/package.json +9 -9
- /package/dist/cli/{notes → memos}/editing.d.ts +0 -0
- /package/dist/cli/{notes → memos}/editing.js +0 -0
- /package/dist/cli/{notes → memos}/html-read.d.ts +0 -0
- /package/dist/cli/{notes → memos}/html-read.js +0 -0
- /package/dist/cli/{notes → memos}/html.d.ts +0 -0
- /package/dist/cli/{notes → memos}/html.js +0 -0
- /package/dist/cli/{notes → memos}/media-commands.d.ts +0 -0
- /package/dist/cli/{notes → memos}/media-commands.js +0 -0
- /package/dist/cli/{notes → memos}/toc.d.ts +0 -0
- /package/dist/cli/{notes → memos}/toc.js +0 -0
- /package/dist/cli/{notes → memos}/version-commands.d.ts +0 -0
- /package/dist/cli/{notes → memos}/version-commands.js +0 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { type Transport } from "./client.js";
|
|
2
|
+
import { type MemoSource } from "./memo-edits.js";
|
|
3
|
+
import * as editing from "./memo-editing.js";
|
|
4
|
+
import { type MemoFocusedRead } from "./memo-reading.js";
|
|
5
|
+
import { type MemoCommandStatus, type MemoWriteMode, type MemoWriteReceipt } from "./memo-write.js";
|
|
6
|
+
import { type MemoRow, type MemosApi, type MemoVersion } from "./memos.js";
|
|
7
|
+
/** `{note, content, hash, revision}`: four distinct values. A hash describes text; a revision is the write baseline. */
|
|
8
|
+
export type MemoSnapshot = MemoSource;
|
|
9
|
+
/** A qualified reference: the first `/` separates the lookup namespace from a 24-hex id or a slug. */
|
|
10
|
+
export type MemoRef = `${string}/${string}`;
|
|
11
|
+
/** Where an edit was planned from: the snapshot it was read from (preferred) or its bare revision string. */
|
|
12
|
+
export type MemoRevisionRef = MemoSnapshot | string;
|
|
13
|
+
type Hex = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f" | "A" | "B" | "C" | "D" | "E" | "F";
|
|
14
|
+
/** True for a 24-hex literal type (one character per recursion step; no union expansion). */
|
|
15
|
+
type IsHexId<S extends string, N extends unknown[] = []> = N["length"] extends 24 ? (S extends "" ? true : false) : S extends `${Hex}${infer Rest}` ? IsHexId<Rest, [...N, 0]> : false;
|
|
16
|
+
/** What `dl.notes(x)` returns at the type level, matching the runtime dispatch: a 24-hex literal or a
|
|
17
|
+
* literal with a `/` is a NoteHandle, any other literal is the namespace-scoped API, and a plain `string`
|
|
18
|
+
* may be either, so narrow it (`"ref" in value`) or use `dl.notes.open(id)` / `dl.notes.namespace(ns)`. */
|
|
19
|
+
export type MemosFor<S extends string> = S extends MemoRef ? MemoHandle : string extends S ? MemoHandle | MemosApi : IsHexId<S> extends true ? MemoHandle : MemosApi;
|
|
20
|
+
export declare class MemoReferenceInvalid extends Error {
|
|
21
|
+
constructor(ref: string);
|
|
22
|
+
}
|
|
23
|
+
export declare class RevisionExpected extends Error {
|
|
24
|
+
constructor(message: string);
|
|
25
|
+
}
|
|
26
|
+
export declare class ModeRequired extends Error {
|
|
27
|
+
constructor(received: unknown);
|
|
28
|
+
}
|
|
29
|
+
/** The Note's metadata was created but its initial source was not written (`definite`) or not confirmed
|
|
30
|
+
* (`uncertain`). Retry by writing or appending to `note`; creating again would make a second Note. */
|
|
31
|
+
export declare class MemoCreatedWithoutSource extends Error {
|
|
32
|
+
readonly note: string;
|
|
33
|
+
readonly namespace: string;
|
|
34
|
+
readonly outcome: "definite" | "uncertain";
|
|
35
|
+
constructor(note: string, namespace: string, outcome: "definite" | "uncertain", options?: {
|
|
36
|
+
cause?: unknown;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** A write through a handle with an explicit namespace found the note elsewhere: the asserted scope no longer
|
|
40
|
+
* holds it. Nothing was written; reopen the note by id (or with the discovered owner) and reconcile. */
|
|
41
|
+
export declare class MemoMoved extends Error {
|
|
42
|
+
readonly note: string;
|
|
43
|
+
readonly namespace: string;
|
|
44
|
+
readonly owner: string;
|
|
45
|
+
constructor(note: string, namespace: string, owner: string, options?: {
|
|
46
|
+
cause?: unknown;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** A documented target this client (or the current server) does not implement; nothing is invented in its place. */
|
|
50
|
+
export declare class UnsupportedTarget extends Error {
|
|
51
|
+
constructor(what: string);
|
|
52
|
+
}
|
|
53
|
+
export interface MemoReadOptions {
|
|
54
|
+
/** `source` (default) returns the exact snapshot; `mapped` the addressed Markdown reading view. */
|
|
55
|
+
view?: "source" | "mapped";
|
|
56
|
+
/** Read a retained revision instead of the current one. */
|
|
57
|
+
at?: MemoRevisionRef;
|
|
58
|
+
/** Two integers, 1-based and inclusive: only that exact source slice, with its global address. */
|
|
59
|
+
lines?: [number, number];
|
|
60
|
+
/** Mapped scope: one section (`s1`) ... */
|
|
61
|
+
section?: string;
|
|
62
|
+
/** ... or one observed element (`s1.p2`). */
|
|
63
|
+
address?: string;
|
|
64
|
+
}
|
|
65
|
+
/** The reading view is read-only: its hints are generated and must never be written back. */
|
|
66
|
+
export interface MemoMappedRead {
|
|
67
|
+
note: string;
|
|
68
|
+
hash: string;
|
|
69
|
+
revision: string;
|
|
70
|
+
view: "mapped";
|
|
71
|
+
sourceType: "markdown" | "html";
|
|
72
|
+
scope: string;
|
|
73
|
+
text: string;
|
|
74
|
+
}
|
|
75
|
+
interface Identified {
|
|
76
|
+
at: MemoRevisionRef;
|
|
77
|
+
mode?: MemoWriteMode;
|
|
78
|
+
commandId?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface MemoAppendInput extends Identified {
|
|
81
|
+
text: string;
|
|
82
|
+
}
|
|
83
|
+
export interface MemoReplaceInput extends Identified {
|
|
84
|
+
text: string;
|
|
85
|
+
lines?: [number, number];
|
|
86
|
+
address?: string;
|
|
87
|
+
}
|
|
88
|
+
export interface MemoInsertInput extends Identified {
|
|
89
|
+
text: string;
|
|
90
|
+
before?: string;
|
|
91
|
+
after?: string;
|
|
92
|
+
cursor?: number;
|
|
93
|
+
}
|
|
94
|
+
export interface MemoRemoveInput extends Identified {
|
|
95
|
+
lines?: [number, number];
|
|
96
|
+
address?: string;
|
|
97
|
+
}
|
|
98
|
+
export interface MemoWriteInput {
|
|
99
|
+
text: string;
|
|
100
|
+
at: MemoRevisionRef;
|
|
101
|
+
mode: MemoWriteMode;
|
|
102
|
+
commandId?: string;
|
|
103
|
+
}
|
|
104
|
+
export interface MemoPatchInput {
|
|
105
|
+
patch: string;
|
|
106
|
+
format: "inline-dff" | "diff";
|
|
107
|
+
at: MemoRevisionRef;
|
|
108
|
+
mode: MemoWriteMode;
|
|
109
|
+
commandId?: string;
|
|
110
|
+
}
|
|
111
|
+
export interface MemoFindInput {
|
|
112
|
+
text?: string;
|
|
113
|
+
regex?: string;
|
|
114
|
+
flags?: string;
|
|
115
|
+
caseSensitive?: boolean;
|
|
116
|
+
limit?: number;
|
|
117
|
+
at?: MemoRevisionRef;
|
|
118
|
+
}
|
|
119
|
+
export interface MemoFindResult {
|
|
120
|
+
note: string;
|
|
121
|
+
hash: string;
|
|
122
|
+
revision: string;
|
|
123
|
+
matches: editing.Match[];
|
|
124
|
+
}
|
|
125
|
+
export interface MemoOutline {
|
|
126
|
+
note: string;
|
|
127
|
+
revision: string;
|
|
128
|
+
hash: string;
|
|
129
|
+
entries: ReturnType<typeof import("./memo-toc.js").markdownToc>;
|
|
130
|
+
}
|
|
131
|
+
/** The v2 incremental read: `patch` applies to source whose hash is `base` (retained at `baseRevision` when
|
|
132
|
+
* `since` named a revision) and yields `hash` at `revision`; `since` echoes a resolved time/hash reference. */
|
|
133
|
+
export interface MemoDiff {
|
|
134
|
+
note: string;
|
|
135
|
+
base: string;
|
|
136
|
+
/** The retained revision the patch applies from; present when `since` was an RTC revision. */
|
|
137
|
+
baseRevision?: string;
|
|
138
|
+
hash: string;
|
|
139
|
+
revision: string;
|
|
140
|
+
format: "diff" | "inline-dff";
|
|
141
|
+
patch: string;
|
|
142
|
+
since?: string;
|
|
143
|
+
}
|
|
144
|
+
export interface MemoMoveInput {
|
|
145
|
+
toNamespace?: string;
|
|
146
|
+
toProject?: string;
|
|
147
|
+
toFolder?: string;
|
|
148
|
+
name?: string;
|
|
149
|
+
dryRun?: boolean;
|
|
150
|
+
}
|
|
151
|
+
export interface MemoVisitInput {
|
|
152
|
+
intent?: string;
|
|
153
|
+
address?: string;
|
|
154
|
+
cursor?: number;
|
|
155
|
+
at?: MemoRevisionRef;
|
|
156
|
+
}
|
|
157
|
+
export interface MemoHandle {
|
|
158
|
+
readonly ref: string;
|
|
159
|
+
/** The lookup namespace, once known (given, qualified, or read from the note's metadata). */
|
|
160
|
+
readonly namespace: string | undefined;
|
|
161
|
+
/** The id or slug the handle was opened with. */
|
|
162
|
+
readonly note: string;
|
|
163
|
+
read(options: MemoReadOptions & {
|
|
164
|
+
lines: [number, number];
|
|
165
|
+
}): Promise<MemoFocusedRead>;
|
|
166
|
+
read(options?: MemoReadOptions & {
|
|
167
|
+
view?: "source";
|
|
168
|
+
lines?: undefined;
|
|
169
|
+
}): Promise<MemoSnapshot>;
|
|
170
|
+
read(options: MemoReadOptions & {
|
|
171
|
+
view: "mapped";
|
|
172
|
+
lines?: undefined;
|
|
173
|
+
}): Promise<MemoMappedRead>;
|
|
174
|
+
/** Append `text` verbatim at the original document end (no separator is added). Merge unless `mode: "exact"`. */
|
|
175
|
+
append(input: MemoAppendInput): Promise<MemoWriteReceipt>;
|
|
176
|
+
/** Replace the exact span selected by `lines` or `address` with `text` (empty text deletes it). */
|
|
177
|
+
replace(input: MemoReplaceInput): Promise<MemoWriteReceipt>;
|
|
178
|
+
/** Insert `text` verbatim before/after an element's full original span, or at a code-point `cursor`. */
|
|
179
|
+
insert(input: MemoInsertInput): Promise<MemoWriteReceipt>;
|
|
180
|
+
/** Remove the exact span selected by `lines` or `address`; never the Note resource. */
|
|
181
|
+
remove(input: MemoRemoveInput): Promise<MemoWriteReceipt>;
|
|
182
|
+
/** Replace the whole source read at `at` with `text`, as a code-point diff; `mode` is explicit. */
|
|
183
|
+
write(input: MemoWriteInput): Promise<MemoWriteReceipt>;
|
|
184
|
+
/** Apply an explicit source patch (`inline-dff` or unified `diff`) against `at`; `mode` is explicit. */
|
|
185
|
+
patch(input: MemoPatchInput): Promise<MemoWriteReceipt>;
|
|
186
|
+
outline(options?: {
|
|
187
|
+
at?: MemoRevisionRef;
|
|
188
|
+
}): Promise<MemoOutline>;
|
|
189
|
+
find(input: MemoFindInput): Promise<MemoFindResult>;
|
|
190
|
+
diff(input: {
|
|
191
|
+
since: string;
|
|
192
|
+
format?: "diff" | "inline-dff";
|
|
193
|
+
}): Promise<MemoDiff>;
|
|
194
|
+
presence(): Promise<unknown>;
|
|
195
|
+
/** Announce the caller once. `address`/`cursor` locations are a documented target (UnsupportedTarget today). */
|
|
196
|
+
visit(input?: MemoVisitInput): Promise<unknown>;
|
|
197
|
+
versions: {
|
|
198
|
+
list(options?: {
|
|
199
|
+
before?: string;
|
|
200
|
+
}): Promise<{
|
|
201
|
+
versions: MemoVersion[];
|
|
202
|
+
nextCursor?: string | null;
|
|
203
|
+
}>;
|
|
204
|
+
read(input: {
|
|
205
|
+
versionId: string;
|
|
206
|
+
}): Promise<MemoVersion>;
|
|
207
|
+
};
|
|
208
|
+
files: {
|
|
209
|
+
move(input: {
|
|
210
|
+
file: string;
|
|
211
|
+
toFolder?: string;
|
|
212
|
+
name?: string;
|
|
213
|
+
}): Promise<unknown>;
|
|
214
|
+
};
|
|
215
|
+
/** Workspace/project filing through the existing move contract; `toFolder` and `name` are documented targets (UnsupportedTarget today). */
|
|
216
|
+
move(input: MemoMoveInput): Promise<unknown>;
|
|
217
|
+
/** The durable record behind a `commandId` sent earlier. */
|
|
218
|
+
commandStatus(commandId: string): Promise<MemoCommandStatus>;
|
|
219
|
+
}
|
|
220
|
+
export type CreatedMemo = MemoHandle & {
|
|
221
|
+
id: string;
|
|
222
|
+
created: MemoRow;
|
|
223
|
+
};
|
|
224
|
+
export interface MemosFacade {
|
|
225
|
+
/** With explicit namespace context any reference (id or bare slug) opens a handle; the slug resolves lazily in that namespace. */
|
|
226
|
+
(ref: string, context: {
|
|
227
|
+
namespace: string;
|
|
228
|
+
}): MemoHandle;
|
|
229
|
+
<S extends string>(ref: S, context?: {
|
|
230
|
+
namespace?: string;
|
|
231
|
+
}): MemosFor<S>;
|
|
232
|
+
/** A handle for a dynamic `string` id or qualified reference, typed as a handle. */
|
|
233
|
+
open(ref: string, context?: {
|
|
234
|
+
namespace?: string;
|
|
235
|
+
}): MemoHandle;
|
|
236
|
+
list(options: {
|
|
237
|
+
namespace: string;
|
|
238
|
+
q?: string;
|
|
239
|
+
limit?: number;
|
|
240
|
+
offset?: number;
|
|
241
|
+
includeArchived?: boolean;
|
|
242
|
+
}): Promise<{
|
|
243
|
+
notes: MemoRow[];
|
|
244
|
+
}>;
|
|
245
|
+
/** Create a Note (title defaults to Untitled) and, with `text`, initialize its source. Returns a usable handle.
|
|
246
|
+
* If the metadata is created but the source write fails, the error is a NoteCreatedWithoutSource carrying the id. */
|
|
247
|
+
create(options: {
|
|
248
|
+
namespace: string;
|
|
249
|
+
name?: string;
|
|
250
|
+
text?: string;
|
|
251
|
+
visibility?: "private" | "public";
|
|
252
|
+
projects?: string[];
|
|
253
|
+
}): Promise<CreatedMemo>;
|
|
254
|
+
/** The namespace-scoped API for a dynamic namespace (a bare literal, `dl.notes("fortyfive")`, is the same object). */
|
|
255
|
+
namespace(namespace: string): MemosApi;
|
|
256
|
+
}
|
|
257
|
+
export declare function parseMemoRef(ref: string): {
|
|
258
|
+
namespace: string;
|
|
259
|
+
note: string;
|
|
260
|
+
};
|
|
261
|
+
/** The baseline an edit was planned from: a snapshot's own revision, or the bare string. */
|
|
262
|
+
export declare function revisionOf(at: MemoRevisionRef): string;
|
|
263
|
+
export declare function memoHandle(t: Transport, ref: string, context?: {
|
|
264
|
+
namespace?: string;
|
|
265
|
+
}): MemoHandle;
|
|
266
|
+
/** `dl.notes`: open one note by stable id or `"namespace/note"`, or reach the namespace API with a bare namespace literal. */
|
|
267
|
+
export declare function memosFacade(t: Transport): MemosFacade;
|
|
268
|
+
export type { MemoSnapshot as NoteSnapshot };
|
|
269
|
+
export type { MemoRef as NoteRef };
|
|
270
|
+
export type { MemoRevisionRef as NoteRevisionRef };
|
|
271
|
+
export type { MemosFor as NotesFor };
|
|
272
|
+
export { MemoReferenceInvalid as NoteReferenceInvalid };
|
|
273
|
+
export { MemoCreatedWithoutSource as NoteCreatedWithoutSource };
|
|
274
|
+
export { MemoMoved as NoteMoved };
|
|
275
|
+
export type { MemoReadOptions as NoteReadOptions };
|
|
276
|
+
export type { MemoMappedRead as NoteMappedRead };
|
|
277
|
+
export type { MemoAppendInput as NoteAppendInput };
|
|
278
|
+
export type { MemoReplaceInput as NoteReplaceInput };
|
|
279
|
+
export type { MemoInsertInput as NoteInsertInput };
|
|
280
|
+
export type { MemoRemoveInput as NoteRemoveInput };
|
|
281
|
+
export type { MemoWriteInput as NoteWriteInput };
|
|
282
|
+
export type { MemoPatchInput as NotePatchInput };
|
|
283
|
+
export type { MemoFindInput as NoteFindInput };
|
|
284
|
+
export type { MemoFindResult as NoteFindResult };
|
|
285
|
+
export type { MemoOutline as NoteOutline };
|
|
286
|
+
export type { MemoDiff as NoteDiff };
|
|
287
|
+
export type { MemoMoveInput as NoteMoveInput };
|
|
288
|
+
export type { MemoVisitInput as NoteVisitInput };
|
|
289
|
+
export type { MemoHandle as NoteHandle };
|
|
290
|
+
export type { CreatedMemo as CreatedNote };
|
|
291
|
+
export type { MemosFacade as NotesFacade };
|
|
292
|
+
export { parseMemoRef as parseNoteRef };
|
|
293
|
+
export { memoHandle as noteHandle };
|
|
294
|
+
export { memosFacade as notesFacade };
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/** The Notes API facade (Notes API contract, "Shared rules"):
|
|
2
|
+
*
|
|
3
|
+
* const note = dl.notes(noteId) // local and synchronous; IDs are primary
|
|
4
|
+
* const snapshot = await note.read()
|
|
5
|
+
* const receipt = await note.append({ text: "\nHello\n", at: snapshot })
|
|
6
|
+
* const page = await dl.notes.list({ namespace: "fortyfive", limit: 20, offset: 0 })
|
|
7
|
+
* const created = await dl.notes.create({ namespace: "fortyfive", name: "Review", text: "# Review\n" })
|
|
8
|
+
*
|
|
9
|
+
* `notes` is callable and carries the collection operations. Every operation
|
|
10
|
+
* takes one named object. A handle opened by stable ID needs no namespace: the
|
|
11
|
+
* owner is read from the note's metadata on first use; `{ namespace }` or a
|
|
12
|
+
* qualified `"namespace/slug"` reference supplies lookup context for slugs.
|
|
13
|
+
* `at` is a snapshot or a bare revision; a content hash is never accepted in
|
|
14
|
+
* its place. Edits compile to the same PATCH as the CLI through note-write.ts. */
|
|
15
|
+
import { createHash } from "node:crypto";
|
|
16
|
+
import { seg } from "./client.js";
|
|
17
|
+
import { RequestNotSent } from "./http.js";
|
|
18
|
+
import { documentInsertion, memoEdits } from "./memo-edits.js";
|
|
19
|
+
import * as editing from "./memo-editing.js";
|
|
20
|
+
import { focusedRead, lineRange, readMemoView } from "./memo-reading.js";
|
|
21
|
+
import { appendPlan, failureInfo, refuseReadingView, validateCommandId, writePlan } from "./memo-write.js";
|
|
22
|
+
import { memosApi } from "./memos.js";
|
|
23
|
+
export class MemoReferenceInvalid extends Error {
|
|
24
|
+
constructor(ref) { super(`memo reference must be a 24-hex id or "namespace/note", got ${JSON.stringify(ref)}`); this.name = "MemoReferenceInvalid"; }
|
|
25
|
+
}
|
|
26
|
+
export class RevisionExpected extends Error {
|
|
27
|
+
constructor(message) { super(message); this.name = "RevisionExpected"; }
|
|
28
|
+
}
|
|
29
|
+
export class ModeRequired extends Error {
|
|
30
|
+
constructor(received) { super(`mode must be "exact" or "merge" (received ${JSON.stringify(received)})`); this.name = "ModeRequired"; }
|
|
31
|
+
}
|
|
32
|
+
/** The Note's metadata was created but its initial source was not written (`definite`) or not confirmed
|
|
33
|
+
* (`uncertain`). Retry by writing or appending to `note`; creating again would make a second Note. */
|
|
34
|
+
export class MemoCreatedWithoutSource extends Error {
|
|
35
|
+
note;
|
|
36
|
+
namespace;
|
|
37
|
+
outcome;
|
|
38
|
+
constructor(note, namespace, outcome, options) {
|
|
39
|
+
super(`memo ${note} was created in ${namespace} but its initial source was ${outcome === "definite" ? "not written" : "not confirmed"}; retry by writing or appending to that id, never by creating again`, options);
|
|
40
|
+
this.note = note;
|
|
41
|
+
this.namespace = namespace;
|
|
42
|
+
this.outcome = outcome;
|
|
43
|
+
this.name = "MemoCreatedWithoutSource";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** A write through a handle with an explicit namespace found the note elsewhere: the asserted scope no longer
|
|
47
|
+
* holds it. Nothing was written; reopen the note by id (or with the discovered owner) and reconcile. */
|
|
48
|
+
export class MemoMoved extends Error {
|
|
49
|
+
note;
|
|
50
|
+
namespace;
|
|
51
|
+
owner;
|
|
52
|
+
constructor(note, namespace, owner, options) {
|
|
53
|
+
super(`memo ${note} is not in the asserted namespace ${namespace}; its owner is ${owner}. Nothing was written: reopen it by id or with {namespace: "${owner}"} and reconcile`, options);
|
|
54
|
+
this.note = note;
|
|
55
|
+
this.namespace = namespace;
|
|
56
|
+
this.owner = owner;
|
|
57
|
+
this.name = "MemoMoved";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** A documented target this client (or the current server) does not implement; nothing is invented in its place. */
|
|
61
|
+
export class UnsupportedTarget extends Error {
|
|
62
|
+
constructor(what) { super(`${what} is a documented Memos API target without an implementation in this client; nothing was sent`); this.name = "UnsupportedTarget"; }
|
|
63
|
+
}
|
|
64
|
+
const isId = (value) => /^[a-f0-9]{24}$/i.test(value);
|
|
65
|
+
export function parseMemoRef(ref) {
|
|
66
|
+
const slash = typeof ref === "string" ? ref.indexOf("/") : -1;
|
|
67
|
+
if (slash < 1 || slash === ref.length - 1 || /\s/.test(ref))
|
|
68
|
+
throw new MemoReferenceInvalid(ref);
|
|
69
|
+
return { namespace: ref.slice(0, slash), note: ref.slice(slash + 1) };
|
|
70
|
+
}
|
|
71
|
+
function validRevision(value, what) {
|
|
72
|
+
if (typeof value !== "string" || !value.trim() || value === "*" || /[\r\n]/.test(value))
|
|
73
|
+
throw new RevisionExpected(`${what} must be a retained revision string`);
|
|
74
|
+
if (/^sha256:/.test(value))
|
|
75
|
+
throw new RevisionExpected(`${what} is a sha256: content hash, not a revision; pass the snapshot or its revision`);
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
/** The baseline an edit was planned from: a snapshot's own revision, or the bare string. */
|
|
79
|
+
export function revisionOf(at) {
|
|
80
|
+
if (at !== null && typeof at === "object")
|
|
81
|
+
return validRevision(at.revision, "at.revision");
|
|
82
|
+
return validRevision(at, "at");
|
|
83
|
+
}
|
|
84
|
+
function validSnapshot(at, note) {
|
|
85
|
+
if (at.note !== note)
|
|
86
|
+
throw new RevisionExpected(`snapshot belongs to memo ${at.note}, not ${note}`);
|
|
87
|
+
if (typeof at.content !== "string" || at.hash !== `sha256:${createHash("sha256").update(at.content, "utf8").digest("hex")}`)
|
|
88
|
+
throw new RevisionExpected("snapshot content does not match its hash");
|
|
89
|
+
validRevision(at.revision, "at.revision");
|
|
90
|
+
return at;
|
|
91
|
+
}
|
|
92
|
+
function modeOf(mode, fallback) {
|
|
93
|
+
if (mode === undefined && fallback)
|
|
94
|
+
return fallback;
|
|
95
|
+
if (mode !== "exact" && mode !== "merge")
|
|
96
|
+
throw new ModeRequired(mode);
|
|
97
|
+
return mode;
|
|
98
|
+
}
|
|
99
|
+
function exactlyOne(input, keys, what) {
|
|
100
|
+
const given = keys.filter(key => input[key] !== undefined);
|
|
101
|
+
if (given.length !== 1)
|
|
102
|
+
throw new TypeError(`${what} takes exactly one of ${keys.join(", ")}`);
|
|
103
|
+
return given[0];
|
|
104
|
+
}
|
|
105
|
+
/** A write that compiles to nothing is reported, not sent: the server observed nothing. */
|
|
106
|
+
function localNoWrite(snapshot, mode, commandId) {
|
|
107
|
+
return { note: snapshot.note, hash: snapshot.hash, revision: snapshot.revision, baseRevision: snapshot.revision, mode, outcome: "no-write", commandId: commandId ?? null, replayed: false };
|
|
108
|
+
}
|
|
109
|
+
const withCommand = (request, commandId) => commandId === undefined ? request : { ...request, commandId };
|
|
110
|
+
export function memoHandle(t, ref, context = {}) {
|
|
111
|
+
if (typeof ref !== "string")
|
|
112
|
+
throw new MemoReferenceInvalid(String(ref));
|
|
113
|
+
// An id needs no namespace; a slug needs one, qualified ("ns/slug") or given as context.
|
|
114
|
+
const parsed = isId(ref) ? { namespace: context.namespace, note: ref }
|
|
115
|
+
: ref.includes("/") ? parseMemoRef(ref)
|
|
116
|
+
: context.namespace !== undefined ? { namespace: context.namespace, note: ref }
|
|
117
|
+
: parseMemoRef(ref);
|
|
118
|
+
if (ref.includes("/") && context.namespace !== undefined && context.namespace !== parsed.namespace)
|
|
119
|
+
throw new MemoReferenceInvalid(ref);
|
|
120
|
+
let namespace = parsed.namespace;
|
|
121
|
+
/** An explicit scope (context or qualified reference) is an assertion: writes never cross it. */
|
|
122
|
+
const explicitScope = parsed.namespace !== undefined;
|
|
123
|
+
let resolved = isId(parsed.note) ? parsed.note : undefined;
|
|
124
|
+
const owner = async () => {
|
|
125
|
+
const row = await t.request("GET", `/notes/${resolved}`, { redirect: "error" });
|
|
126
|
+
if (!row || row.id !== resolved || typeof row.namespaceSlug !== "string" || !row.namespaceSlug)
|
|
127
|
+
throw new Error("memo metadata did not name the owning namespace");
|
|
128
|
+
return row.namespaceSlug;
|
|
129
|
+
};
|
|
130
|
+
/** The namespace-scoped API; a bare id learns its owner from the note's metadata (one GET, cached). */
|
|
131
|
+
const scope = async () => memosApi(t, (namespace ??= await owner()));
|
|
132
|
+
const id = async (api) => (resolved ??= await api.resolve(parsed.note));
|
|
133
|
+
/** Run against the scope; on a 404 re-read the owner once. A handle opened by bare id follows a changed
|
|
134
|
+
* owner (cache updated, one retry, reads and writes alike). With an explicit scope a read may follow the
|
|
135
|
+
* discovered owner for this call only, while a write surfaces NoteMoved: nothing crosses the assertion. */
|
|
136
|
+
const guarded = async (run, kind = "read") => {
|
|
137
|
+
try {
|
|
138
|
+
return await run(await scope());
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
if (failureInfo(error).status !== 404 || resolved === undefined)
|
|
142
|
+
throw error;
|
|
143
|
+
const current = await owner();
|
|
144
|
+
if (current === namespace)
|
|
145
|
+
throw error;
|
|
146
|
+
if (explicitScope) {
|
|
147
|
+
if (kind === "write")
|
|
148
|
+
throw new MemoMoved(resolved, namespace, current, { cause: error });
|
|
149
|
+
return run(memosApi(t, current));
|
|
150
|
+
}
|
|
151
|
+
namespace = current;
|
|
152
|
+
return run(await scope());
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
/** The snapshot an edit is planned from: the one given, or the retained revision read now. */
|
|
156
|
+
const baseline = async (api, at) => at !== null && typeof at === "object" ? validSnapshot(at, await id(api)) : api.source(await id(api), revisionOf(at));
|
|
157
|
+
/** The exact span a selector names in this snapshot: source lines, or an element's full original span. */
|
|
158
|
+
const span = async (api, snapshot, selector) => {
|
|
159
|
+
if (selector.lines !== undefined)
|
|
160
|
+
return lineRange(snapshot.content, selector.lines).chars;
|
|
161
|
+
const range = await api.addressRange(snapshot.note, selector.address, snapshot.revision);
|
|
162
|
+
return [range.start, range.end];
|
|
163
|
+
};
|
|
164
|
+
const submit = (api, snapshot, request, commandId) => {
|
|
165
|
+
if (commandId !== undefined)
|
|
166
|
+
validateCommandId(commandId);
|
|
167
|
+
return api.patch(snapshot.note, withCommand(request, commandId), { baseline: snapshot });
|
|
168
|
+
};
|
|
169
|
+
const read = async (options = {}) => {
|
|
170
|
+
if (options.view !== undefined && options.view !== "source" && options.view !== "mapped")
|
|
171
|
+
throw new Error('view must be "source" or "mapped"');
|
|
172
|
+
const selectors = [options.lines, options.section, options.address].filter(v => v !== undefined).length;
|
|
173
|
+
if (selectors > 1)
|
|
174
|
+
throw new Error("select lines, section or address: exactly one");
|
|
175
|
+
if ((options.section !== undefined || options.address !== undefined) && options.view !== "mapped")
|
|
176
|
+
throw new Error('section and address select a mapped scope: pass view: "mapped"');
|
|
177
|
+
const at = options.at === undefined ? undefined : revisionOf(options.at);
|
|
178
|
+
return guarded(async (api) => {
|
|
179
|
+
const noteId = await id(api);
|
|
180
|
+
if (options.lines !== undefined)
|
|
181
|
+
return focusedRead(await api.source(noteId, at), options.lines);
|
|
182
|
+
if (options.view !== "mapped")
|
|
183
|
+
return api.source(noteId, at);
|
|
184
|
+
let start = 0, revision = at, text = "", first;
|
|
185
|
+
for (;;) {
|
|
186
|
+
const page = await readMemoView(t, namespace, noteId, { at: revision, start, section: options.section, tag: options.address });
|
|
187
|
+
first ??= page;
|
|
188
|
+
if (page.hash !== first.hash || page.total !== first.total)
|
|
189
|
+
throw new Error("Memo reading view changed during pagination");
|
|
190
|
+
revision = page.revision;
|
|
191
|
+
text += page.text;
|
|
192
|
+
if (page.complete)
|
|
193
|
+
break;
|
|
194
|
+
start = page.next;
|
|
195
|
+
}
|
|
196
|
+
return { note: noteId, hash: first.hash, revision: first.revision, view: "mapped", sourceType: first.sourceType, scope: first.scope, text };
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
ref, note: parsed.note,
|
|
201
|
+
get namespace() { return namespace; },
|
|
202
|
+
read: read,
|
|
203
|
+
async append(input) {
|
|
204
|
+
const mode = modeOf(input.mode, "merge");
|
|
205
|
+
if (typeof input.text !== "string")
|
|
206
|
+
throw new TypeError("text must be a string");
|
|
207
|
+
refuseReadingView(input.text, "append text");
|
|
208
|
+
return guarded(async (api) => {
|
|
209
|
+
const snapshot = await baseline(api, input.at), plan = appendPlan(snapshot, input.text, mode);
|
|
210
|
+
if (plan.request.patch === "")
|
|
211
|
+
return localNoWrite(snapshot, mode, input.commandId);
|
|
212
|
+
return submit(api, snapshot, plan.request, input.commandId);
|
|
213
|
+
}, "write");
|
|
214
|
+
},
|
|
215
|
+
async replace(input) {
|
|
216
|
+
const mode = modeOf(input.mode, "merge");
|
|
217
|
+
if (typeof input.text !== "string")
|
|
218
|
+
throw new TypeError("text must be a string");
|
|
219
|
+
exactlyOne(input, ["lines", "address"], "replace");
|
|
220
|
+
return guarded(async (api) => {
|
|
221
|
+
const snapshot = await baseline(api, input.at), [start, end] = await span(api, snapshot, input);
|
|
222
|
+
return submit(api, snapshot, memoEdits(snapshot, [{ start, end, text: input.text }], mode), input.commandId);
|
|
223
|
+
}, "write");
|
|
224
|
+
},
|
|
225
|
+
async insert(input) {
|
|
226
|
+
const mode = modeOf(input.mode, "merge");
|
|
227
|
+
if (typeof input.text !== "string")
|
|
228
|
+
throw new TypeError("text must be a string");
|
|
229
|
+
const placement = exactlyOne(input, ["before", "after", "cursor"], "insert");
|
|
230
|
+
return guarded(async (api) => {
|
|
231
|
+
const snapshot = await baseline(api, input.at);
|
|
232
|
+
let at;
|
|
233
|
+
if (placement === "cursor") {
|
|
234
|
+
const length = Array.from(snapshot.content).length;
|
|
235
|
+
if (!Number.isSafeInteger(input.cursor) || input.cursor < 0 || input.cursor > length)
|
|
236
|
+
throw new RangeError(`cursor must be a code-point position between 0 and ${length}`);
|
|
237
|
+
at = input.cursor;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const [start, end] = await span(api, snapshot, { address: placement === "before" ? input.before : input.after });
|
|
241
|
+
at = placement === "before" ? start : end;
|
|
242
|
+
}
|
|
243
|
+
return submit(api, snapshot, documentInsertion(snapshot, at, input.text, mode === "exact"), input.commandId);
|
|
244
|
+
}, "write");
|
|
245
|
+
},
|
|
246
|
+
async remove(input) {
|
|
247
|
+
const mode = modeOf(input.mode, "merge");
|
|
248
|
+
if ("text" in input)
|
|
249
|
+
throw new TypeError("remove takes no text; use replace to substitute a span");
|
|
250
|
+
exactlyOne(input, ["lines", "address"], "remove");
|
|
251
|
+
return guarded(async (api) => {
|
|
252
|
+
const snapshot = await baseline(api, input.at), [start, end] = await span(api, snapshot, input);
|
|
253
|
+
return submit(api, snapshot, memoEdits(snapshot, [{ start, end, text: "" }], mode), input.commandId);
|
|
254
|
+
}, "write");
|
|
255
|
+
},
|
|
256
|
+
async write(input) {
|
|
257
|
+
const mode = modeOf(input.mode);
|
|
258
|
+
if (typeof input.text !== "string")
|
|
259
|
+
throw new TypeError("text must be a string");
|
|
260
|
+
return guarded(async (api) => {
|
|
261
|
+
const snapshot = await baseline(api, input.at), request = writePlan(snapshot, input.text, mode);
|
|
262
|
+
// As the CLI: an unchanged merge write sends nothing, an unchanged exact write still asks the server to validate the baseline.
|
|
263
|
+
if (request.patch === "" && mode === "merge")
|
|
264
|
+
return localNoWrite(snapshot, mode, input.commandId);
|
|
265
|
+
return submit(api, snapshot, request, input.commandId);
|
|
266
|
+
}, "write");
|
|
267
|
+
},
|
|
268
|
+
async patch(input) {
|
|
269
|
+
const mode = modeOf(input.mode);
|
|
270
|
+
if (typeof input.patch !== "string" || !input.patch.trim())
|
|
271
|
+
throw new Error("patch is empty; nothing to send");
|
|
272
|
+
if (input.format !== "inline-dff" && input.format !== "diff")
|
|
273
|
+
throw new Error('format must be "inline-dff" or "diff"');
|
|
274
|
+
return guarded(async (api) => {
|
|
275
|
+
const snapshot = await baseline(api, input.at);
|
|
276
|
+
return submit(api, snapshot, { format: input.format, patch: input.patch, baseRevision: snapshot.revision, mode }, input.commandId);
|
|
277
|
+
}, "write");
|
|
278
|
+
},
|
|
279
|
+
async outline(options = {}) {
|
|
280
|
+
const at = options.at === undefined ? undefined : revisionOf(options.at);
|
|
281
|
+
return guarded(async (api) => api.outline(await id(api), at));
|
|
282
|
+
},
|
|
283
|
+
async find(input) {
|
|
284
|
+
const at = input.at === undefined || typeof input.at === "object" ? undefined : revisionOf(input.at);
|
|
285
|
+
return guarded(async (api) => {
|
|
286
|
+
const snapshot = input.at !== undefined && typeof input.at === "object" ? validSnapshot(input.at, await id(api)) : await api.source(await id(api), at);
|
|
287
|
+
// Literal searches are case-sensitive unless caseSensitive: false, which searches the escaped literal with the i flag.
|
|
288
|
+
const matches = input.text !== undefined && input.caseSensitive === false
|
|
289
|
+
? editing.find(snapshot.content, undefined, { regex: input.text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), flags: "i", limit: input.limit })
|
|
290
|
+
: editing.find(snapshot.content, input.text, { regex: input.regex, flags: input.flags, limit: input.limit });
|
|
291
|
+
return { note: snapshot.note, hash: snapshot.hash, revision: snapshot.revision, matches };
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
/** The same v2 incremental read as `notes read --since`: `since` is a retained revision, content hash or time reference. */
|
|
295
|
+
async diff(input) {
|
|
296
|
+
if (typeof input.since !== "string" || !input.since.trim())
|
|
297
|
+
throw new RevisionExpected("since must be a retained revision, content hash or time reference");
|
|
298
|
+
const format = input.format ?? "diff";
|
|
299
|
+
if (format !== "diff" && format !== "inline-dff")
|
|
300
|
+
throw new Error('format must be "diff" or "inline-dff"');
|
|
301
|
+
return guarded(async (api) => {
|
|
302
|
+
const noteId = await id(api);
|
|
303
|
+
const result = (await api.read(noteId, { since: input.since, format }));
|
|
304
|
+
if (!result || result.note !== noteId || result.format !== format || typeof result.patch !== "string" || !/^sha256:[a-f0-9]{64}$/.test(result.base ?? "")
|
|
305
|
+
|| !/^sha256:[a-f0-9]{64}$/.test(result.hash ?? "") || typeof result.revision !== "string" || !result.revision.trim() || /^sha256:/.test(result.revision)
|
|
306
|
+
|| (result.baseRevision !== undefined && (typeof result.baseRevision !== "string" || !result.baseRevision.trim() || /^sha256:/.test(result.baseRevision)))
|
|
307
|
+
|| (result.since !== undefined && typeof result.since !== "string"))
|
|
308
|
+
throw new Error("invalid incremental Memos v2 response");
|
|
309
|
+
return result;
|
|
310
|
+
});
|
|
311
|
+
},
|
|
312
|
+
async presence() { return guarded(async (api) => api.presence(await id(api))); },
|
|
313
|
+
async visit(input = {}) {
|
|
314
|
+
if (input.address !== undefined || input.cursor !== undefined)
|
|
315
|
+
throw new UnsupportedTarget("visit with a location (address/cursor)");
|
|
316
|
+
return guarded(async (api) => api.visit(await id(api), { intent: input.intent }), "write");
|
|
317
|
+
},
|
|
318
|
+
versions: {
|
|
319
|
+
list: async (options = {}) => guarded(async (api) => api.versions(await id(api), options)),
|
|
320
|
+
read: async ({ versionId }) => guarded(async (api) => api.version(await id(api), versionId)),
|
|
321
|
+
},
|
|
322
|
+
files: {
|
|
323
|
+
/** Destination = (`toFolder` or the file's current folder) / (`name` or the file's current name). */
|
|
324
|
+
move: async ({ file, toFolder, name }) => {
|
|
325
|
+
if (toFolder === undefined && name === undefined)
|
|
326
|
+
throw new TypeError("files.move needs toFolder, name or both");
|
|
327
|
+
return guarded(async (api) => {
|
|
328
|
+
const files = api.files(await id(api)), current = await files.resolve(file);
|
|
329
|
+
const segments = current.path.split("/"), currentName = segments.pop();
|
|
330
|
+
const folder = toFolder ?? segments.join("/"), base = name ?? currentName;
|
|
331
|
+
return files.move(current.id, folder ? `${folder}/${base}` : base);
|
|
332
|
+
}, "write");
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
async move(input) {
|
|
336
|
+
if (input.name !== undefined)
|
|
337
|
+
throw new UnsupportedTarget("move with a display-name change");
|
|
338
|
+
if (input.toFolder !== undefined)
|
|
339
|
+
throw new UnsupportedTarget("move into a deep project folder through the API");
|
|
340
|
+
if (input.toNamespace === undefined && input.toProject === undefined)
|
|
341
|
+
throw new TypeError("move needs at least one of toNamespace, toProject");
|
|
342
|
+
return guarded(async (api) => {
|
|
343
|
+
const noteId = await id(api);
|
|
344
|
+
const receipt = (await api.move(noteId, { namespace: input.toNamespace ?? namespace, projects: input.toProject === undefined ? [] : [input.toProject], dryRun: input.dryRun }));
|
|
345
|
+
// The note now lives in the destination: later calls through this handle target it.
|
|
346
|
+
if (!input.dryRun && input.toNamespace !== undefined && receipt?.moved !== false)
|
|
347
|
+
namespace = input.toNamespace;
|
|
348
|
+
return receipt;
|
|
349
|
+
}, "write");
|
|
350
|
+
},
|
|
351
|
+
commandStatus: async (commandId) => guarded(async (api) => api.commandStatus(await id(api), commandId)),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/** `dl.notes`: open one note by stable id or `"namespace/note"`, or reach the namespace API with a bare namespace literal. */
|
|
355
|
+
export function memosFacade(t) {
|
|
356
|
+
const open = ((ref, context) => typeof ref === "string" && (isId(ref) || ref.includes("/") || context?.namespace !== undefined) ? memoHandle(t, ref, context) : memosApi(t, ref));
|
|
357
|
+
open.open = (ref, context) => memoHandle(t, ref, context);
|
|
358
|
+
open.list = ({ namespace, ...query }) => memosApi(t, namespace).list(query);
|
|
359
|
+
open.namespace = namespace => memosApi(t, namespace);
|
|
360
|
+
open.create = async ({ namespace, name, text, visibility, projects }) => {
|
|
361
|
+
const created = await memosApi(t, namespace).create({ name: name ?? "Untitled", visibility, projects });
|
|
362
|
+
// Initial source is a second, unconditional write (as the CLI does); atomic creation is a server target.
|
|
363
|
+
if (text !== undefined) {
|
|
364
|
+
try {
|
|
365
|
+
await t.request("PUT", `/namespaces/${seg(namespace)}/notes/${created.note.id}/body`, { json: { text }, redirect: "error" });
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
const status = failureInfo(error).status;
|
|
369
|
+
const outcome = error instanceof RequestNotSent || (status !== undefined && status >= 400 && status < 500) ? "definite" : "uncertain";
|
|
370
|
+
throw new MemoCreatedWithoutSource(created.note.id, namespace, outcome, { cause: error });
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return Object.assign(memoHandle(t, created.note.id, { namespace }), { id: created.note.id, created: created.note });
|
|
374
|
+
};
|
|
375
|
+
return open;
|
|
376
|
+
}
|
|
377
|
+
export { MemoReferenceInvalid as NoteReferenceInvalid };
|
|
378
|
+
export { MemoCreatedWithoutSource as NoteCreatedWithoutSource };
|
|
379
|
+
export { MemoMoved as NoteMoved };
|
|
380
|
+
export { parseMemoRef as parseNoteRef };
|
|
381
|
+
export { memoHandle as noteHandle };
|
|
382
|
+
export { memosFacade as notesFacade };
|