@dreamlake/dreamlake-cli 0.89.0 → 0.90.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/client.d.ts +2 -1
- package/dist/api/client.js +1 -1
- package/dist/api/index.d.ts +100 -68
- package/dist/api/index.js +2 -0
- package/dist/api/note-files.d.ts +57 -30
- package/dist/api/note-files.js +100 -58
- package/dist/api/note-linger.d.ts +83 -0
- package/dist/api/note-linger.js +270 -0
- package/dist/api/note-presence.d.ts +82 -0
- package/dist/api/note-presence.js +72 -0
- package/dist/api/notes.d.ts +57 -32
- package/dist/api/notes.js +30 -2
- package/dist/cli/notes/api-transport.d.ts +5 -0
- package/dist/cli/notes/api-transport.js +20 -0
- package/dist/cli/notes/files-commands.d.ts +2 -25
- package/dist/cli/notes/files-commands.js +16 -22
- package/dist/cli/notes/index.js +5 -8
- package/dist/cli/notes/linger.d.ts +3 -58
- package/dist/cli/notes/linger.js +56 -299
- package/dist/cli/notes/select-command.js +20 -41
- package/dist/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/package.json +9 -9
package/dist/api/client.d.ts
CHANGED
|
@@ -32,7 +32,8 @@ export interface RequestOptions {
|
|
|
32
32
|
onHeaders?: (headers: Headers) => void;
|
|
33
33
|
query?: Record<string, string | number | boolean | undefined | null>;
|
|
34
34
|
headers?: Record<string, string>;
|
|
35
|
-
|
|
35
|
+
/** null on raw streaming requests uses the caller's signal and idle deadline instead of a total deadline. */
|
|
36
|
+
timeoutMs?: number | null;
|
|
36
37
|
signal?: AbortSignal;
|
|
37
38
|
}
|
|
38
39
|
/** A non-2xx response. `code` is the server's stable error identifier. */
|
package/dist/api/client.js
CHANGED
|
@@ -53,7 +53,7 @@ export function createTransport(options) {
|
|
|
53
53
|
token: options.token,
|
|
54
54
|
fetch: doFetch,
|
|
55
55
|
headers: headers(request),
|
|
56
|
-
timeoutMs: request.timeoutMs ?? options.timeoutMs ?? 30000,
|
|
56
|
+
timeoutMs: request.timeoutMs === null && request.signal ? undefined : request.timeoutMs ?? options.timeoutMs ?? 30000,
|
|
57
57
|
});
|
|
58
58
|
if (!response.ok)
|
|
59
59
|
throw apiFailure(new HttpError(response.status, await response.text().catch(() => "")));
|
package/dist/api/index.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export * from "./content.js";
|
|
|
17
17
|
export * from "./execution.js";
|
|
18
18
|
export * from "./ownership.js";
|
|
19
19
|
export * from "./note-files.js";
|
|
20
|
+
export * from "./note-presence.js";
|
|
21
|
+
export * from "./note-linger.js";
|
|
20
22
|
export * from "./jobs.js";
|
|
21
23
|
export * from "./infra.js";
|
|
22
24
|
import { type ClientOptions, type Transport } from "./client.js";
|
|
@@ -308,9 +310,7 @@ export declare function createApi(transport: Transport): {
|
|
|
308
310
|
serviceAccounts: (namespace: string) => {
|
|
309
311
|
list: (query?: {
|
|
310
312
|
page?: number;
|
|
311
|
-
pageSize
|
|
312
|
-
/** TypeScript operations use an explicit transport; importing does not execute CLI startup. */
|
|
313
|
-
?: number;
|
|
313
|
+
pageSize?: number;
|
|
314
314
|
}) => Promise<unknown>;
|
|
315
315
|
get: (id: string) => Promise<unknown>;
|
|
316
316
|
create: (input: {
|
|
@@ -474,7 +474,17 @@ export declare function createApi(transport: Transport): {
|
|
|
474
474
|
managed: (id: string, action: "status" | "start" | "reconnect" | "stop", input: Record<string, unknown>) => Promise<unknown>;
|
|
475
475
|
};
|
|
476
476
|
notes: (namespace: string) => {
|
|
477
|
+
linger: (noteId: string, options: import("./note-linger.js").NoteLingerOptions, receive: (event: import("./note-linger.js").NoteLingerEvent) => void | Promise<void>) => Promise<void>;
|
|
477
478
|
namespace: string;
|
|
479
|
+
resolve: (ref: string) => Promise<string>;
|
|
480
|
+
selectElement: (noteId: string, css: string) => Promise<{
|
|
481
|
+
etag: string;
|
|
482
|
+
tag: string;
|
|
483
|
+
attrs: Record<string, string | null>;
|
|
484
|
+
outer: [number, number];
|
|
485
|
+
inner: [number, number];
|
|
486
|
+
text: string;
|
|
487
|
+
}>;
|
|
478
488
|
source: (noteId: string, at?: string) => Promise<import("./note-edits.js").NoteSource>;
|
|
479
489
|
patch: (noteId: string, input: import("./note-edits.js").NotePatch) => Promise<{
|
|
480
490
|
note: string;
|
|
@@ -550,25 +560,24 @@ export declare function createApi(transport: Transport): {
|
|
|
550
560
|
remove: (userId: string) => Promise<unknown>;
|
|
551
561
|
};
|
|
552
562
|
files: (noteId: string) => {
|
|
553
|
-
|
|
554
|
-
list: (query?: {
|
|
555
|
-
prefix?: string;
|
|
556
|
-
trash?: boolean;
|
|
557
|
-
limit?: number;
|
|
558
|
-
offset?: number;
|
|
559
|
-
}) => Promise<{
|
|
560
|
-
files: import("./note-files.js").NoteFile[];
|
|
561
|
-
total: number;
|
|
562
|
-
}>;
|
|
563
|
+
list: (query?: import("./note-files.js").NoteFileListOptions) => Promise<import("./note-files.js").NoteFilePage>;
|
|
563
564
|
get: (id: string) => Promise<import("./note-files.js").NoteFile>;
|
|
564
|
-
|
|
565
|
+
resolve: (ref: string, includeTrashed?: boolean) => Promise<import("./note-files.js").NoteFile>;
|
|
566
|
+
text: (ref: string) => Promise<{
|
|
565
567
|
text: string;
|
|
566
568
|
etag: string;
|
|
567
569
|
}>;
|
|
568
|
-
|
|
570
|
+
cat: (ref: string) => Promise<{
|
|
571
|
+
text: string;
|
|
572
|
+
etag: string;
|
|
573
|
+
}>;
|
|
574
|
+
download: (ref: string, signal?: AbortSignal) => Promise<Response>;
|
|
575
|
+
upload: (path: string, body: NonNullable<import("./client.js").RequestOptions["body"]> | import("stream").Readable, options?: {
|
|
569
576
|
contentType?: string;
|
|
570
577
|
overwrite?: boolean;
|
|
571
578
|
ifMatch?: string;
|
|
579
|
+
contentLength?: number;
|
|
580
|
+
signal?: AbortSignal;
|
|
572
581
|
}) => Promise<import("./note-files.js").NoteFile>;
|
|
573
582
|
write: (input: {
|
|
574
583
|
path: string;
|
|
@@ -578,39 +587,34 @@ export declare function createApi(transport: Transport): {
|
|
|
578
587
|
}, options?: {
|
|
579
588
|
ifMatch?: string;
|
|
580
589
|
idempotencyKey?: string;
|
|
581
|
-
}) => Promise<import("./note-files.js").
|
|
582
|
-
move: (
|
|
590
|
+
}) => Promise<import("./note-files.js").NoteFileWriteReceipt>;
|
|
591
|
+
move: (ref: string, path: string, options?: {
|
|
583
592
|
overwrite?: boolean;
|
|
584
593
|
ifMatch?: string;
|
|
585
594
|
}) => Promise<import("./note-files.js").NoteFile>;
|
|
586
|
-
copy: (
|
|
595
|
+
copy: (ref: string, path: string, options?: {
|
|
587
596
|
overwrite?: boolean;
|
|
588
597
|
idempotencyKey?: string;
|
|
589
|
-
}) => Promise<import("./note-files.js").
|
|
590
|
-
operation: (operationId: string, action?: "status" | "reconcile" | "cancel") => Promise<
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}>;
|
|
596
|
-
delete: (id: string, options?: {
|
|
598
|
+
}) => Promise<import("./note-files.js").NoteFileWriteReceipt>;
|
|
599
|
+
operation: (operationId: string, action?: "status" | "reconcile" | "cancel") => Promise<import("./note-files.js").NoteFileOperationReceipt>;
|
|
600
|
+
status: (id: string) => Promise<import("./note-files.js").NoteFileOperationReceipt>;
|
|
601
|
+
reconcile: (id: string) => Promise<import("./note-files.js").NoteFileOperationReceipt>;
|
|
602
|
+
cancel: (id: string) => Promise<import("./note-files.js").NoteFileOperationReceipt>;
|
|
603
|
+
delete: (ref: string, options?: {
|
|
597
604
|
purge?: boolean;
|
|
598
605
|
ifMatch?: string;
|
|
599
606
|
}) => Promise<{
|
|
600
607
|
id: string;
|
|
601
608
|
purged: boolean;
|
|
602
609
|
}>;
|
|
603
|
-
restore: (
|
|
604
|
-
preview: (
|
|
605
|
-
|
|
606
|
-
url: string;
|
|
607
|
-
}>;
|
|
608
|
-
revokePreview: (id: string) => Promise<{
|
|
610
|
+
restore: (ref: string, path?: string) => Promise<import("./note-files.js").NoteFile>;
|
|
611
|
+
preview: (ref: string, share?: boolean) => Promise<import("./note-files.js").NoteFilePreview>;
|
|
612
|
+
revokePreview: (ref: string) => Promise<{
|
|
609
613
|
id: string;
|
|
610
614
|
shared: boolean;
|
|
611
615
|
}>;
|
|
612
616
|
};
|
|
613
|
-
media: (form: FormData) => Promise<
|
|
617
|
+
media: (form: FormData) => Promise<import("./notes.js").NoteMediaReceipt>;
|
|
614
618
|
read: (noteId: string, query?: import("./common.js").Query) => Promise<import("./notes.js").NoteReadResult>;
|
|
615
619
|
html: (noteId: string, options?: {
|
|
616
620
|
at?: string;
|
|
@@ -630,7 +634,6 @@ export declare function createApi(transport: Transport): {
|
|
|
630
634
|
since?: string;
|
|
631
635
|
format?: "diff" | "inline-dff";
|
|
632
636
|
}) => Promise<unknown>;
|
|
633
|
-
presence: (noteId: string, input: import("./common.js").JsonObject) => Promise<unknown>;
|
|
634
637
|
saveVersion: (noteId: string, input: {
|
|
635
638
|
hash: string;
|
|
636
639
|
tag?: string;
|
|
@@ -697,6 +700,20 @@ export declare function createApi(transport: Transport): {
|
|
|
697
700
|
after?: string;
|
|
698
701
|
}, ifMatch?: string) => Promise<import("./notes.js").WriteReceipt>;
|
|
699
702
|
removeSection: (noteId: string, anchor: string, ifMatch?: string) => Promise<import("./notes.js").WriteReceipt>;
|
|
703
|
+
presence: {
|
|
704
|
+
(id: string): Promise<import("./note-presence.js").NotePresenceRoster>;
|
|
705
|
+
(id: string, input: Record<string, unknown>): Promise<import("./note-presence.js").NotePresenceReceipt>;
|
|
706
|
+
};
|
|
707
|
+
presenceText: (id: string) => Promise<string>;
|
|
708
|
+
updatePresence: (id: string, input: Record<string, unknown>, options?: import("./client.js").RequestOptions) => Promise<import("./note-presence.js").NotePresenceReceipt>;
|
|
709
|
+
visit: (id: string, options?: {
|
|
710
|
+
intent?: string;
|
|
711
|
+
}) => Promise<import("./note-presence.js").NotePresenceReceipt>;
|
|
712
|
+
activity: (id: string, options?: import("./client.js").RequestOptions) => Promise<{
|
|
713
|
+
activities: import("./note-presence.js").NoteActivity[];
|
|
714
|
+
}>;
|
|
715
|
+
events: (id: string, signal: AbortSignal, receive: (event: import("./note-events.js").NoteEvent) => void) => Promise<void>;
|
|
716
|
+
selectText: (id: string, options: import("./note-presence.js").NoteSelectionOptions) => Promise<import("./note-presence.js").NoteSelectionReceipt>;
|
|
700
717
|
};
|
|
701
718
|
projects: (namespace: string) => {
|
|
702
719
|
grants: (project: string) => Promise<unknown>;
|
|
@@ -1489,9 +1506,7 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1489
1506
|
serviceAccounts: (namespace: string) => {
|
|
1490
1507
|
list: (query?: {
|
|
1491
1508
|
page?: number;
|
|
1492
|
-
pageSize
|
|
1493
|
-
/** TypeScript operations use an explicit transport; importing does not execute CLI startup. */
|
|
1494
|
-
?: number;
|
|
1509
|
+
pageSize?: number;
|
|
1495
1510
|
}) => Promise<unknown>;
|
|
1496
1511
|
get: (id: string) => Promise<unknown>;
|
|
1497
1512
|
create: (input: {
|
|
@@ -1655,7 +1670,17 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1655
1670
|
managed: (id: string, action: "status" | "start" | "reconnect" | "stop", input: Record<string, unknown>) => Promise<unknown>;
|
|
1656
1671
|
};
|
|
1657
1672
|
notes: (namespace: string) => {
|
|
1673
|
+
linger: (noteId: string, options: import("./note-linger.js").NoteLingerOptions, receive: (event: import("./note-linger.js").NoteLingerEvent) => void | Promise<void>) => Promise<void>;
|
|
1658
1674
|
namespace: string;
|
|
1675
|
+
resolve: (ref: string) => Promise<string>;
|
|
1676
|
+
selectElement: (noteId: string, css: string) => Promise<{
|
|
1677
|
+
etag: string;
|
|
1678
|
+
tag: string;
|
|
1679
|
+
attrs: Record<string, string | null>;
|
|
1680
|
+
outer: [number, number];
|
|
1681
|
+
inner: [number, number];
|
|
1682
|
+
text: string;
|
|
1683
|
+
}>;
|
|
1659
1684
|
source: (noteId: string, at?: string) => Promise<import("./note-edits.js").NoteSource>;
|
|
1660
1685
|
patch: (noteId: string, input: import("./note-edits.js").NotePatch) => Promise<{
|
|
1661
1686
|
note: string;
|
|
@@ -1731,25 +1756,24 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1731
1756
|
remove: (userId: string) => Promise<unknown>;
|
|
1732
1757
|
};
|
|
1733
1758
|
files: (noteId: string) => {
|
|
1734
|
-
|
|
1735
|
-
list: (query?: {
|
|
1736
|
-
prefix?: string;
|
|
1737
|
-
trash?: boolean;
|
|
1738
|
-
limit?: number;
|
|
1739
|
-
offset?: number;
|
|
1740
|
-
}) => Promise<{
|
|
1741
|
-
files: import("./note-files.js").NoteFile[];
|
|
1742
|
-
total: number;
|
|
1743
|
-
}>;
|
|
1759
|
+
list: (query?: import("./note-files.js").NoteFileListOptions) => Promise<import("./note-files.js").NoteFilePage>;
|
|
1744
1760
|
get: (id: string) => Promise<import("./note-files.js").NoteFile>;
|
|
1745
|
-
|
|
1761
|
+
resolve: (ref: string, includeTrashed?: boolean) => Promise<import("./note-files.js").NoteFile>;
|
|
1762
|
+
text: (ref: string) => Promise<{
|
|
1746
1763
|
text: string;
|
|
1747
1764
|
etag: string;
|
|
1748
1765
|
}>;
|
|
1749
|
-
|
|
1766
|
+
cat: (ref: string) => Promise<{
|
|
1767
|
+
text: string;
|
|
1768
|
+
etag: string;
|
|
1769
|
+
}>;
|
|
1770
|
+
download: (ref: string, signal?: AbortSignal) => Promise<Response>;
|
|
1771
|
+
upload: (path: string, body: NonNullable<import("./client.js").RequestOptions["body"]> | import("stream").Readable, options?: {
|
|
1750
1772
|
contentType?: string;
|
|
1751
1773
|
overwrite?: boolean;
|
|
1752
1774
|
ifMatch?: string;
|
|
1775
|
+
contentLength?: number;
|
|
1776
|
+
signal?: AbortSignal;
|
|
1753
1777
|
}) => Promise<import("./note-files.js").NoteFile>;
|
|
1754
1778
|
write: (input: {
|
|
1755
1779
|
path: string;
|
|
@@ -1759,39 +1783,34 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1759
1783
|
}, options?: {
|
|
1760
1784
|
ifMatch?: string;
|
|
1761
1785
|
idempotencyKey?: string;
|
|
1762
|
-
}) => Promise<import("./note-files.js").
|
|
1763
|
-
move: (
|
|
1786
|
+
}) => Promise<import("./note-files.js").NoteFileWriteReceipt>;
|
|
1787
|
+
move: (ref: string, path: string, options?: {
|
|
1764
1788
|
overwrite?: boolean;
|
|
1765
1789
|
ifMatch?: string;
|
|
1766
1790
|
}) => Promise<import("./note-files.js").NoteFile>;
|
|
1767
|
-
copy: (
|
|
1791
|
+
copy: (ref: string, path: string, options?: {
|
|
1768
1792
|
overwrite?: boolean;
|
|
1769
1793
|
idempotencyKey?: string;
|
|
1770
|
-
}) => Promise<import("./note-files.js").
|
|
1771
|
-
operation: (operationId: string, action?: "status" | "reconcile" | "cancel") => Promise<
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
}>;
|
|
1777
|
-
delete: (id: string, options?: {
|
|
1794
|
+
}) => Promise<import("./note-files.js").NoteFileWriteReceipt>;
|
|
1795
|
+
operation: (operationId: string, action?: "status" | "reconcile" | "cancel") => Promise<import("./note-files.js").NoteFileOperationReceipt>;
|
|
1796
|
+
status: (id: string) => Promise<import("./note-files.js").NoteFileOperationReceipt>;
|
|
1797
|
+
reconcile: (id: string) => Promise<import("./note-files.js").NoteFileOperationReceipt>;
|
|
1798
|
+
cancel: (id: string) => Promise<import("./note-files.js").NoteFileOperationReceipt>;
|
|
1799
|
+
delete: (ref: string, options?: {
|
|
1778
1800
|
purge?: boolean;
|
|
1779
1801
|
ifMatch?: string;
|
|
1780
1802
|
}) => Promise<{
|
|
1781
1803
|
id: string;
|
|
1782
1804
|
purged: boolean;
|
|
1783
1805
|
}>;
|
|
1784
|
-
restore: (
|
|
1785
|
-
preview: (
|
|
1786
|
-
|
|
1787
|
-
url: string;
|
|
1788
|
-
}>;
|
|
1789
|
-
revokePreview: (id: string) => Promise<{
|
|
1806
|
+
restore: (ref: string, path?: string) => Promise<import("./note-files.js").NoteFile>;
|
|
1807
|
+
preview: (ref: string, share?: boolean) => Promise<import("./note-files.js").NoteFilePreview>;
|
|
1808
|
+
revokePreview: (ref: string) => Promise<{
|
|
1790
1809
|
id: string;
|
|
1791
1810
|
shared: boolean;
|
|
1792
1811
|
}>;
|
|
1793
1812
|
};
|
|
1794
|
-
media: (form: FormData) => Promise<
|
|
1813
|
+
media: (form: FormData) => Promise<import("./notes.js").NoteMediaReceipt>;
|
|
1795
1814
|
read: (noteId: string, query?: import("./common.js").Query) => Promise<import("./notes.js").NoteReadResult>;
|
|
1796
1815
|
html: (noteId: string, options?: {
|
|
1797
1816
|
at?: string;
|
|
@@ -1811,7 +1830,6 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1811
1830
|
since?: string;
|
|
1812
1831
|
format?: "diff" | "inline-dff";
|
|
1813
1832
|
}) => Promise<unknown>;
|
|
1814
|
-
presence: (noteId: string, input: import("./common.js").JsonObject) => Promise<unknown>;
|
|
1815
1833
|
saveVersion: (noteId: string, input: {
|
|
1816
1834
|
hash: string;
|
|
1817
1835
|
tag?: string;
|
|
@@ -1878,6 +1896,20 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1878
1896
|
after?: string;
|
|
1879
1897
|
}, ifMatch?: string) => Promise<import("./notes.js").WriteReceipt>;
|
|
1880
1898
|
removeSection: (noteId: string, anchor: string, ifMatch?: string) => Promise<import("./notes.js").WriteReceipt>;
|
|
1899
|
+
presence: {
|
|
1900
|
+
(id: string): Promise<import("./note-presence.js").NotePresenceRoster>;
|
|
1901
|
+
(id: string, input: Record<string, unknown>): Promise<import("./note-presence.js").NotePresenceReceipt>;
|
|
1902
|
+
};
|
|
1903
|
+
presenceText: (id: string) => Promise<string>;
|
|
1904
|
+
updatePresence: (id: string, input: Record<string, unknown>, options?: import("./client.js").RequestOptions) => Promise<import("./note-presence.js").NotePresenceReceipt>;
|
|
1905
|
+
visit: (id: string, options?: {
|
|
1906
|
+
intent?: string;
|
|
1907
|
+
}) => Promise<import("./note-presence.js").NotePresenceReceipt>;
|
|
1908
|
+
activity: (id: string, options?: import("./client.js").RequestOptions) => Promise<{
|
|
1909
|
+
activities: import("./note-presence.js").NoteActivity[];
|
|
1910
|
+
}>;
|
|
1911
|
+
events: (id: string, signal: AbortSignal, receive: (event: import("./note-events.js").NoteEvent) => void) => Promise<void>;
|
|
1912
|
+
selectText: (id: string, options: import("./note-presence.js").NoteSelectionOptions) => Promise<import("./note-presence.js").NoteSelectionReceipt>;
|
|
1881
1913
|
};
|
|
1882
1914
|
projects: (namespace: string) => {
|
|
1883
1915
|
grants: (project: string) => Promise<unknown>;
|
package/dist/api/index.js
CHANGED
|
@@ -29,6 +29,8 @@ export * from "./content.js";
|
|
|
29
29
|
export * from "./execution.js";
|
|
30
30
|
export * from "./ownership.js";
|
|
31
31
|
export * from "./note-files.js";
|
|
32
|
+
export * from "./note-presence.js";
|
|
33
|
+
export * from "./note-linger.js";
|
|
32
34
|
export * from "./jobs.js";
|
|
33
35
|
export * from "./infra.js";
|
|
34
36
|
/** `@dreamlake/dreamlake-cli/api` — the DreamLake TypeScript API.
|
package/dist/api/note-files.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/** Note attachments. JSON receipts match `notes files … --json`; bytes remain streams. */
|
|
2
|
+
import { type Transport, type RequestOptions } from './client.js';
|
|
3
|
+
import type { Readable } from 'node:stream';
|
|
2
4
|
export interface NoteFile {
|
|
3
5
|
id: string;
|
|
4
6
|
path: string;
|
|
@@ -12,26 +14,56 @@ export interface NoteFile {
|
|
|
12
14
|
previewKind: string | null;
|
|
13
15
|
text: boolean;
|
|
14
16
|
}
|
|
17
|
+
export interface NoteFilePage {
|
|
18
|
+
files: NoteFile[];
|
|
19
|
+
total: number;
|
|
20
|
+
}
|
|
21
|
+
export interface NoteFileListOptions {
|
|
22
|
+
glob?: string;
|
|
23
|
+
trashed?: boolean;
|
|
24
|
+
contentType?: string;
|
|
25
|
+
limit?: number;
|
|
26
|
+
offset?: number;
|
|
27
|
+
/** @deprecated Use glob. This is interpreted as a literal path prefix. */
|
|
28
|
+
prefix?: string;
|
|
29
|
+
/** @deprecated Use trashed. */
|
|
30
|
+
trash?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export type NoteFileWriteReceipt = NoteFile & {
|
|
33
|
+
operationId?: string;
|
|
34
|
+
};
|
|
35
|
+
export interface NoteFileOperationReceipt {
|
|
36
|
+
operationId: string;
|
|
37
|
+
state: 'admitted' | 'write-started' | 'published' | 'aborted-before-write';
|
|
38
|
+
historicalResult: boolean;
|
|
39
|
+
file?: NoteFile;
|
|
40
|
+
}
|
|
41
|
+
export interface NoteFilePreview {
|
|
42
|
+
url: string;
|
|
43
|
+
kind: 'session' | 'shared';
|
|
44
|
+
previewKind: string | null;
|
|
45
|
+
}
|
|
46
|
+
export declare function noteFileOperationId(value: unknown): string | undefined;
|
|
47
|
+
export declare function validateNoteFileKey(key?: string): void;
|
|
15
48
|
export declare function noteFilesApi(t: Transport, base: string): {
|
|
16
|
-
|
|
17
|
-
list: (query?: {
|
|
18
|
-
prefix?: string;
|
|
19
|
-
trash?: boolean;
|
|
20
|
-
limit?: number;
|
|
21
|
-
offset?: number;
|
|
22
|
-
}) => Promise<{
|
|
23
|
-
files: NoteFile[];
|
|
24
|
-
total: number;
|
|
25
|
-
}>;
|
|
49
|
+
list: (query?: NoteFileListOptions) => Promise<NoteFilePage>;
|
|
26
50
|
get: (id: string) => Promise<NoteFile>;
|
|
27
|
-
|
|
51
|
+
resolve: (ref: string, includeTrashed?: boolean) => Promise<NoteFile>;
|
|
52
|
+
text: (ref: string) => Promise<{
|
|
28
53
|
text: string;
|
|
29
54
|
etag: string;
|
|
30
55
|
}>;
|
|
31
|
-
|
|
56
|
+
cat: (ref: string) => Promise<{
|
|
57
|
+
text: string;
|
|
58
|
+
etag: string;
|
|
59
|
+
}>;
|
|
60
|
+
download: (ref: string, signal?: AbortSignal) => Promise<Response>;
|
|
61
|
+
upload: (path: string, body: NonNullable<RequestOptions["body"]> | Readable, options?: {
|
|
32
62
|
contentType?: string;
|
|
33
63
|
overwrite?: boolean;
|
|
34
64
|
ifMatch?: string;
|
|
65
|
+
contentLength?: number;
|
|
66
|
+
signal?: AbortSignal;
|
|
35
67
|
}) => Promise<NoteFile>;
|
|
36
68
|
write: (input: {
|
|
37
69
|
path: string;
|
|
@@ -41,34 +73,29 @@ export declare function noteFilesApi(t: Transport, base: string): {
|
|
|
41
73
|
}, options?: {
|
|
42
74
|
ifMatch?: string;
|
|
43
75
|
idempotencyKey?: string;
|
|
44
|
-
}) => Promise<
|
|
45
|
-
move: (
|
|
76
|
+
}) => Promise<NoteFileWriteReceipt>;
|
|
77
|
+
move: (ref: string, path: string, options?: {
|
|
46
78
|
overwrite?: boolean;
|
|
47
79
|
ifMatch?: string;
|
|
48
80
|
}) => Promise<NoteFile>;
|
|
49
|
-
copy: (
|
|
81
|
+
copy: (ref: string, path: string, options?: {
|
|
50
82
|
overwrite?: boolean;
|
|
51
83
|
idempotencyKey?: string;
|
|
52
|
-
}) => Promise<
|
|
53
|
-
operation: (operationId: string, action?: "status" | "reconcile" | "cancel") => Promise<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}>;
|
|
59
|
-
delete: (id: string, options?: {
|
|
84
|
+
}) => Promise<NoteFileWriteReceipt>;
|
|
85
|
+
operation: (operationId: string, action?: "status" | "reconcile" | "cancel") => Promise<NoteFileOperationReceipt>;
|
|
86
|
+
status: (id: string) => Promise<NoteFileOperationReceipt>;
|
|
87
|
+
reconcile: (id: string) => Promise<NoteFileOperationReceipt>;
|
|
88
|
+
cancel: (id: string) => Promise<NoteFileOperationReceipt>;
|
|
89
|
+
delete: (ref: string, options?: {
|
|
60
90
|
purge?: boolean;
|
|
61
91
|
ifMatch?: string;
|
|
62
92
|
}) => Promise<{
|
|
63
93
|
id: string;
|
|
64
94
|
purged: boolean;
|
|
65
95
|
}>;
|
|
66
|
-
restore: (
|
|
67
|
-
preview: (
|
|
68
|
-
|
|
69
|
-
url: string;
|
|
70
|
-
}>;
|
|
71
|
-
revokePreview: (id: string) => Promise<{
|
|
96
|
+
restore: (ref: string, path?: string) => Promise<NoteFile>;
|
|
97
|
+
preview: (ref: string, share?: boolean) => Promise<NoteFilePreview>;
|
|
98
|
+
revokePreview: (ref: string) => Promise<{
|
|
72
99
|
id: string;
|
|
73
100
|
shared: boolean;
|
|
74
101
|
}>;
|
package/dist/api/note-files.js
CHANGED
|
@@ -1,65 +1,107 @@
|
|
|
1
|
-
|
|
1
|
+
/** Note attachments. JSON receipts match `notes files … --json`; bytes remain streams. */
|
|
2
|
+
import { ApiError, seg } from './client.js';
|
|
3
|
+
export function noteFileOperationId(value) {
|
|
4
|
+
return typeof value === 'string' && /^[a-f0-9]{24}$/i.test(value) ? value : undefined;
|
|
5
|
+
}
|
|
6
|
+
export function validateNoteFileKey(key) {
|
|
7
|
+
if (key !== undefined && (!/^[\x20-\x7e]{1,256}$/.test(key) || key.trim() !== key))
|
|
8
|
+
throw new Error('--idempotency-key must be 1–256 printable ASCII bytes without surrounding spaces');
|
|
9
|
+
}
|
|
2
10
|
export function noteFilesApi(t, base) {
|
|
3
11
|
const file = (id) => `${base}/files/${seg(id)}`;
|
|
12
|
+
const list = (query = {}) => {
|
|
13
|
+
const { prefix, trash, ...rest } = query;
|
|
14
|
+
// Compatibility aliases previously sent unsupported server fields.
|
|
15
|
+
const glob = rest.glob ?? (prefix === undefined ? undefined : prefix.replace(/[?*\[\]{}()!+@]/g, '\\$&') + '*');
|
|
16
|
+
return t.request('GET', base + '/files', { query: { ...rest, glob, trashed: rest.trashed ?? trash } });
|
|
17
|
+
};
|
|
18
|
+
const get = (id) => t.request('GET', file(id));
|
|
19
|
+
/** Paths are exact names; scan every page instead of treating page one as the whole directory. */
|
|
20
|
+
const resolve = async (ref, includeTrashed = false) => {
|
|
21
|
+
if (/^[a-f0-9]{24}$/i.test(ref))
|
|
22
|
+
return get(ref);
|
|
23
|
+
for (const trashed of includeTrashed ? [false, true] : [false]) {
|
|
24
|
+
let offset = 0;
|
|
25
|
+
for (;;) {
|
|
26
|
+
const page = await list({ trashed, limit: 100, offset });
|
|
27
|
+
if (!Array.isArray(page.files) || !Number.isSafeInteger(page.total) || page.total < 0)
|
|
28
|
+
throw new Error('Attachment listing is unreadable');
|
|
29
|
+
const hit = page.files.find(row => row.path === ref);
|
|
30
|
+
if (hit)
|
|
31
|
+
return hit;
|
|
32
|
+
offset += page.files.length;
|
|
33
|
+
if (offset >= page.total)
|
|
34
|
+
break;
|
|
35
|
+
if (!page.files.length)
|
|
36
|
+
throw new Error('Attachment listing did not advance');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throw new ApiError(404, 'note_file_not_found', { path: ref });
|
|
40
|
+
};
|
|
41
|
+
const resolveId = async (ref, includeTrashed = false) => /^[a-f0-9]{24}$/i.test(ref) ? ref : (await resolve(ref, includeTrashed)).id;
|
|
42
|
+
const publish = async (path, json, options) => {
|
|
43
|
+
validateNoteFileKey(options.idempotencyKey);
|
|
44
|
+
let operationId;
|
|
45
|
+
try {
|
|
46
|
+
const result = await t.request('POST', path, { json,
|
|
47
|
+
headers: { ...(options.ifMatch ? { 'If-Match': options.ifMatch } : {}), ...(options.idempotencyKey !== undefined ? { 'Idempotency-Key': options.idempotencyKey } : {}) },
|
|
48
|
+
redirect: 'manual', onHeaders: headers => { operationId = noteFileOperationId(headers.get('Note-File-Operation-Id')); } });
|
|
49
|
+
if (!result || typeof result.id !== 'string' || typeof result.path !== 'string')
|
|
50
|
+
throw new ApiError(503, 'note_file_publication_unconfirmed', { operationId });
|
|
51
|
+
return { ...result, ...(operationId ? { operationId } : {}) };
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
const body = error instanceof ApiError ? error.body : undefined;
|
|
55
|
+
operationId ??= noteFileOperationId(body?.operationId);
|
|
56
|
+
// Keep the original error type/status/code and the operation identity, including lost-response failures.
|
|
57
|
+
if (error instanceof Error && operationId)
|
|
58
|
+
Object.assign(error, { operationId });
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const operation = async (operationId, action = 'status') => {
|
|
63
|
+
if (!noteFileOperationId(operationId))
|
|
64
|
+
throw new Error('operation must be a 24-character hexadecimal ID');
|
|
65
|
+
const result = await t.request(action === 'status' ? 'GET' : 'POST', base + '/file-publications/' + seg(operationId) + (action === 'status' ? '' : action === 'cancel' ? '/abort' : '/reconcile'), { redirect: 'manual' });
|
|
66
|
+
if (!result || noteFileOperationId(result.operationId)?.toLowerCase() !== operationId.toLowerCase() ||
|
|
67
|
+
!['admitted', 'write-started', 'published', 'aborted-before-write'].includes(result.state) || typeof result.historicalResult !== 'boolean')
|
|
68
|
+
throw new ApiError(503, 'note_file_operation_unconfirmed', { operationId });
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
const text = async (ref) => {
|
|
72
|
+
const row = await resolve(ref);
|
|
73
|
+
if (!row.text)
|
|
74
|
+
throw new ApiError(400, 'note_file_not_text', { id: row.id, contentType: row.contentType });
|
|
75
|
+
return t.request('GET', file(row.id) + '/text');
|
|
76
|
+
};
|
|
4
77
|
return {
|
|
5
|
-
|
|
78
|
+
list, get, resolve, text, cat: text,
|
|
79
|
+
download: async (ref, signal) => {
|
|
6
80
|
if (!t.raw)
|
|
7
|
-
throw new Error(
|
|
8
|
-
return t.raw(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
81
|
+
throw new Error('transport_does_not_support_streaming');
|
|
82
|
+
return t.raw('GET', file(await resolveId(ref)) + '/content', { signal, query: { redirect: false } });
|
|
83
|
+
},
|
|
84
|
+
upload: (path, body, options = {}) => {
|
|
85
|
+
if (options.contentLength !== undefined && (!Number.isSafeInteger(options.contentLength) || options.contentLength < 0))
|
|
86
|
+
throw new Error('contentLength must be a nonnegative safe integer');
|
|
87
|
+
return t.request('PUT', base + '/files/content', { body: body, signal: options.signal,
|
|
88
|
+
query: { path, contentType: options.contentType, overwrite: options.overwrite },
|
|
89
|
+
headers: { 'Content-Type': options.contentType ?? 'application/octet-stream', ...(options.ifMatch ? { 'If-Match': options.ifMatch } : {}),
|
|
90
|
+
...(options.contentLength === undefined ? {} : { 'Content-Length': String(options.contentLength) }) } });
|
|
91
|
+
},
|
|
92
|
+
write: (input, options = {}) => publish(base + '/files', { ...input, overwrite: input.overwrite ?? false }, options),
|
|
93
|
+
move: async (ref, path, options = {}) => t.request('PATCH', file(await resolveId(ref)), { json: { path, overwrite: options.overwrite ?? false }, headers: options.ifMatch ? { 'If-Match': options.ifMatch } : {} }),
|
|
94
|
+
copy: async (ref, path, options = {}) => {
|
|
95
|
+
validateNoteFileKey(options.idempotencyKey);
|
|
96
|
+
return publish(file(await resolveId(ref)) + '/copy', { path, overwrite: options.overwrite ?? false }, options);
|
|
12
97
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
path,
|
|
22
|
-
contentType: options.contentType,
|
|
23
|
-
overwrite: options.overwrite,
|
|
24
|
-
},
|
|
25
|
-
headers: {
|
|
26
|
-
"Content-Type": options.contentType ?? "application/octet-stream",
|
|
27
|
-
...(options.ifMatch ? { "If-Match": options.ifMatch } : {}),
|
|
28
|
-
},
|
|
29
|
-
}),
|
|
30
|
-
write: (input, options = {}) => t.request("POST", base + "/files", {
|
|
31
|
-
json: input,
|
|
32
|
-
headers: {
|
|
33
|
-
...(options.ifMatch ? { "If-Match": options.ifMatch } : {}),
|
|
34
|
-
...(options.idempotencyKey
|
|
35
|
-
? { "Idempotency-Key": options.idempotencyKey }
|
|
36
|
-
: {}),
|
|
37
|
-
},
|
|
38
|
-
redirect: "manual",
|
|
39
|
-
}),
|
|
40
|
-
move: (id, path, options = {}) => t.request("PATCH", file(id), {
|
|
41
|
-
json: { path, overwrite: options.overwrite ?? false },
|
|
42
|
-
headers: options.ifMatch ? { "If-Match": options.ifMatch } : {},
|
|
43
|
-
}),
|
|
44
|
-
copy: (id, path, options = {}) => t.request("POST", file(id) + "/copy", {
|
|
45
|
-
json: { path, overwrite: options.overwrite ?? false },
|
|
46
|
-
headers: options.idempotencyKey
|
|
47
|
-
? { "Idempotency-Key": options.idempotencyKey }
|
|
48
|
-
: {},
|
|
49
|
-
redirect: "manual",
|
|
50
|
-
}),
|
|
51
|
-
operation: (operationId, action = "status") => t.request(action === "status" ? "GET" : "POST", base +
|
|
52
|
-
"/file-publications/" +
|
|
53
|
-
seg(operationId) +
|
|
54
|
-
(action === "status" ? "" : "/" + action)),
|
|
55
|
-
delete: (id, options = {}) => t.request("DELETE", file(id), {
|
|
56
|
-
query: { purge: options.purge ?? false },
|
|
57
|
-
headers: options.ifMatch ? { "If-Match": options.ifMatch } : {},
|
|
58
|
-
}),
|
|
59
|
-
restore: (id, path) => t.request("POST", file(id) + "/restore", {
|
|
60
|
-
json: path ? { path } : {},
|
|
61
|
-
}),
|
|
62
|
-
preview: (id, share = false) => t.request("GET", file(id) + "/preview", { query: share ? { share: true } : {} }),
|
|
63
|
-
revokePreview: (id) => t.request("DELETE", file(id) + "/preview"),
|
|
98
|
+
operation,
|
|
99
|
+
status: (id) => operation(id),
|
|
100
|
+
reconcile: (id) => operation(id, 'reconcile'),
|
|
101
|
+
cancel: (id) => operation(id, 'cancel'),
|
|
102
|
+
delete: async (ref, options = {}) => t.request('DELETE', file(await resolveId(ref, true)), { query: { purge: options.purge ?? false }, headers: options.ifMatch ? { 'If-Match': options.ifMatch } : {} }),
|
|
103
|
+
restore: async (ref, path) => t.request('POST', file(await resolveId(ref, true)) + '/restore', { json: path ? { path } : {} }),
|
|
104
|
+
preview: async (ref, share = false) => t.request('GET', file(await resolveId(ref)) + '/preview', { query: share ? { share: true } : {} }),
|
|
105
|
+
revokePreview: async (ref) => t.request('DELETE', file(await resolveId(ref)) + '/preview'),
|
|
64
106
|
};
|
|
65
107
|
}
|