@dreamlake/dreamlake-cli 0.97.2 → 0.98.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 +1 -1
- package/dist/api/client.js +4 -4
- package/dist/api/http.d.ts +48 -1
- package/dist/api/http.js +111 -4
- package/dist/api/index.d.ts +17 -513
- package/dist/api/index.js +6 -2
- package/dist/api/note-edits.d.ts +40 -2
- package/dist/api/note-edits.js +197 -2
- package/dist/api/note-events.d.ts +40 -4
- package/dist/api/note-events.js +55 -2
- package/dist/api/note-facade.d.ts +268 -0
- package/dist/api/note-facade.js +376 -0
- package/dist/api/note-reading.d.ts +27 -0
- package/dist/api/note-reading.js +27 -0
- package/dist/api/note-write.d.ts +110 -0
- package/dist/api/note-write.js +217 -0
- package/dist/api/notes.d.ts +33 -44
- package/dist/api/notes.js +44 -34
- package/dist/api/sessions.d.ts +5 -5
- package/dist/cli/client.d.ts +2 -41
- package/dist/cli/client.js +13 -90
- package/dist/cli/help-examples.generated.js +1 -1
- package/dist/cli/notes/api-transport.js +6 -6
- package/dist/cli/notes/document.d.ts +32 -26
- package/dist/cli/notes/document.js +150 -95
- package/dist/cli/notes/edit-commands.d.ts +26 -5
- package/dist/cli/notes/edit-commands.js +163 -36
- package/dist/cli/notes/events.d.ts +3 -33
- package/dist/cli/notes/events.js +4 -51
- package/dist/cli/notes/html-read.d.ts +6 -0
- package/dist/cli/notes/html-read.js +12 -0
- package/dist/cli/notes/index.d.ts +10 -1
- package/dist/cli/notes/index.js +98 -27
- package/dist/cli/notes/move-command.d.ts +4 -0
- package/dist/cli/notes/move-command.js +7 -0
- package/dist/cli/sessions/runner/serve.d.ts +1 -1
- package/dist/cli/vault/sshTransfer.d.ts +1 -1
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type HttpRequestOptions } from "./http.js";
|
|
2
|
-
export { HttpError } from "./http.js";
|
|
2
|
+
export { HttpError, RequestNotSent } from "./http.js";
|
|
3
3
|
/** DreamLake TypeScript API client.
|
|
4
4
|
*
|
|
5
5
|
* One thin transport shared by every operation: the same HTTP paths, bodies,
|
package/dist/api/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpError, httpJson, httpResponse, requestUrl, } from "./http.js";
|
|
2
|
-
export { HttpError } from "./http.js";
|
|
1
|
+
import { HttpError, RequestNotSent, httpJson, httpResponse, requestUrl, } from "./http.js";
|
|
2
|
+
export { HttpError, RequestNotSent } from "./http.js";
|
|
3
3
|
/** A non-2xx response. `code` is the server's stable error identifier. */
|
|
4
4
|
export class ApiError extends Error {
|
|
5
5
|
status;
|
|
@@ -46,7 +46,7 @@ export function createTransport(options) {
|
|
|
46
46
|
catch {
|
|
47
47
|
return true;
|
|
48
48
|
} }))
|
|
49
|
-
throw new
|
|
49
|
+
throw new RequestNotSent("path must be absolute and inside the API");
|
|
50
50
|
const response = await httpResponse(requestUrl(base, path, request.query), {
|
|
51
51
|
...request,
|
|
52
52
|
method,
|
|
@@ -66,7 +66,7 @@ export function createTransport(options) {
|
|
|
66
66
|
catch {
|
|
67
67
|
return true;
|
|
68
68
|
} }))
|
|
69
|
-
throw new
|
|
69
|
+
throw new RequestNotSent("path must be absolute and inside the API");
|
|
70
70
|
try {
|
|
71
71
|
return await httpJson(base, path, {
|
|
72
72
|
...request,
|
package/dist/api/http.d.ts
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
/** Shared HTTP implementation. No login files, telemetry, stdout or process state. */
|
|
2
|
-
export
|
|
2
|
+
export declare class HttpError extends Error {
|
|
3
|
+
status: number;
|
|
4
|
+
body: string;
|
|
5
|
+
/**
|
|
6
|
+
* The typed fields of a Source v1 error envelope, absent on every other
|
|
7
|
+
* shape.
|
|
8
|
+
*
|
|
9
|
+
* Kept as fields rather than folded into the message because they are what a
|
|
10
|
+
* caller BRANCHES on. `code` is the stable identity of a failure — the
|
|
11
|
+
* message is a human sentence the server is free to reword — and `retryable`
|
|
12
|
+
* is the server's own answer to "would repeating this identical request
|
|
13
|
+
* help", which no client can derive from a status alone: a 503 from a rate
|
|
14
|
+
* limiter and a 503 from a misconfigured binding look the same on the wire.
|
|
15
|
+
*
|
|
16
|
+
* `undefined` means "this response was not a v1 envelope", never "the server
|
|
17
|
+
* said no". A caller that must fail closed has to treat undefined as
|
|
18
|
+
* unknown rather than as false.
|
|
19
|
+
*/
|
|
20
|
+
code?: string;
|
|
21
|
+
retryable?: boolean;
|
|
22
|
+
requestId?: string;
|
|
23
|
+
constructor(status: number, body: string);
|
|
24
|
+
/**
|
|
25
|
+
* Pull a human message, and any typed fields, out of an error body.
|
|
26
|
+
*
|
|
27
|
+
* Three shapes reach here and they are not variations of one another:
|
|
28
|
+
*
|
|
29
|
+
* Source v1 {"error": {"code", "message", "retryable", "requestId"}}
|
|
30
|
+
* legacy flat {"error": "..."} or {"message": "..."}
|
|
31
|
+
* not JSON an HTML 404 page, a proxy's plain-text 502
|
|
32
|
+
*
|
|
33
|
+
* The v1 branch is tested FIRST and by type, not by presence. Both envelopes
|
|
34
|
+
* key on `error`, so the old `if (parsed.error) return parsed.error` matched
|
|
35
|
+
* the v1 object too and interpolated it — a real defect, measured before this
|
|
36
|
+
* was written: a 503 carrying a code, a message and a requestId rendered as
|
|
37
|
+
* `(503) [object Object]`, and the three fields a caller could have acted on
|
|
38
|
+
* were gone. Ordering alone does not prevent that; the `typeof` check is what
|
|
39
|
+
* does, because it is the only thing that distinguishes the two.
|
|
40
|
+
*/
|
|
41
|
+
private static parse;
|
|
42
|
+
}
|
|
3
43
|
export interface HttpRequestOptions {
|
|
4
44
|
method?: "GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
5
45
|
token?: string | null;
|
|
@@ -13,6 +53,13 @@ export interface HttpRequestOptions {
|
|
|
13
53
|
onHeaders?: (headers: Headers) => void;
|
|
14
54
|
fetch?: typeof fetch;
|
|
15
55
|
}
|
|
56
|
+
/** Thrown before any bytes leave: the request could not be built (origin, path).
|
|
57
|
+
* A caller that must decide "was this sent?" treats it as a plain refusal, never an uncertain outcome. */
|
|
58
|
+
export declare class RequestNotSent extends Error {
|
|
59
|
+
constructor(message: string, options?: {
|
|
60
|
+
cause?: unknown;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
16
63
|
export declare function requestUrl(base: string, path: string, query?: HttpRequestOptions["query"]): string;
|
|
17
64
|
export declare function httpResponse(url: string, options?: HttpRequestOptions): Promise<Response>;
|
|
18
65
|
export declare function responseValue<T = unknown>(response: Response): Promise<T>;
|
package/dist/api/http.js
CHANGED
|
@@ -1,8 +1,112 @@
|
|
|
1
1
|
/** Shared HTTP implementation. No login files, telemetry, stdout or process state. */
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
// A non-2xx response. Callers that branch on status (404/409) catch HttpError
|
|
3
|
+
// and inspect `.status`; the CLI re-exports it from `src/cli/client.ts`.
|
|
4
|
+
export class HttpError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
body;
|
|
7
|
+
/**
|
|
8
|
+
* The typed fields of a Source v1 error envelope, absent on every other
|
|
9
|
+
* shape.
|
|
10
|
+
*
|
|
11
|
+
* Kept as fields rather than folded into the message because they are what a
|
|
12
|
+
* caller BRANCHES on. `code` is the stable identity of a failure — the
|
|
13
|
+
* message is a human sentence the server is free to reword — and `retryable`
|
|
14
|
+
* is the server's own answer to "would repeating this identical request
|
|
15
|
+
* help", which no client can derive from a status alone: a 503 from a rate
|
|
16
|
+
* limiter and a 503 from a misconfigured binding look the same on the wire.
|
|
17
|
+
*
|
|
18
|
+
* `undefined` means "this response was not a v1 envelope", never "the server
|
|
19
|
+
* said no". A caller that must fail closed has to treat undefined as
|
|
20
|
+
* unknown rather than as false.
|
|
21
|
+
*/
|
|
22
|
+
code;
|
|
23
|
+
retryable;
|
|
24
|
+
requestId;
|
|
25
|
+
constructor(status, body) {
|
|
26
|
+
const parsed = HttpError.parse(body);
|
|
27
|
+
super(`(${status}) ${parsed.message}`);
|
|
28
|
+
this.name = "HttpError";
|
|
29
|
+
this.status = status;
|
|
30
|
+
this.body = body;
|
|
31
|
+
this.code = parsed.code;
|
|
32
|
+
this.retryable = parsed.retryable;
|
|
33
|
+
this.requestId = parsed.requestId;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Pull a human message, and any typed fields, out of an error body.
|
|
37
|
+
*
|
|
38
|
+
* Three shapes reach here and they are not variations of one another:
|
|
39
|
+
*
|
|
40
|
+
* Source v1 {"error": {"code", "message", "retryable", "requestId"}}
|
|
41
|
+
* legacy flat {"error": "..."} or {"message": "..."}
|
|
42
|
+
* not JSON an HTML 404 page, a proxy's plain-text 502
|
|
43
|
+
*
|
|
44
|
+
* The v1 branch is tested FIRST and by type, not by presence. Both envelopes
|
|
45
|
+
* key on `error`, so the old `if (parsed.error) return parsed.error` matched
|
|
46
|
+
* the v1 object too and interpolated it — a real defect, measured before this
|
|
47
|
+
* was written: a 503 carrying a code, a message and a requestId rendered as
|
|
48
|
+
* `(503) [object Object]`, and the three fields a caller could have acted on
|
|
49
|
+
* were gone. Ordering alone does not prevent that; the `typeof` check is what
|
|
50
|
+
* does, because it is the only thing that distinguishes the two.
|
|
51
|
+
*/
|
|
52
|
+
static parse(body) {
|
|
53
|
+
if (!body)
|
|
54
|
+
return { message: "request failed" };
|
|
55
|
+
try {
|
|
56
|
+
const parsed = JSON.parse(body);
|
|
57
|
+
// Source v1 (§15): one nested envelope for every Source route.
|
|
58
|
+
if (typeof parsed.error === "object" && parsed.error !== null) {
|
|
59
|
+
const e = parsed.error;
|
|
60
|
+
// Each field is carried only when it has the type the contract gives
|
|
61
|
+
// it. A malformed envelope degrades to whatever it did supply rather
|
|
62
|
+
// than to a wrong value of the right shape.
|
|
63
|
+
const out = {
|
|
64
|
+
message: typeof e.message === "string" && e.message !== "" ? e.message : "request failed",
|
|
65
|
+
};
|
|
66
|
+
if (typeof e.code === "string")
|
|
67
|
+
out.code = e.code;
|
|
68
|
+
if (typeof e.retryable === "boolean")
|
|
69
|
+
out.retryable = e.retryable;
|
|
70
|
+
if (typeof e.requestId === "string")
|
|
71
|
+
out.requestId = e.requestId;
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
// Email-allowlist rejections put the human text in `message`
|
|
75
|
+
// (`error` is just "Forbidden").
|
|
76
|
+
if (parsed.code === "email_domain_not_allowed" && parsed.message) {
|
|
77
|
+
return { message: parsed.message };
|
|
78
|
+
}
|
|
79
|
+
if (typeof parsed.error === "string" && parsed.error) {
|
|
80
|
+
const detail = typeof parsed.message === "string" && parsed.message && parsed.message !== parsed.error
|
|
81
|
+
? `: ${parsed.message}` : "";
|
|
82
|
+
return { message: parsed.error + detail };
|
|
83
|
+
}
|
|
84
|
+
if (parsed.message)
|
|
85
|
+
return { message: parsed.message };
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// not JSON
|
|
89
|
+
}
|
|
90
|
+
const oneLine = body.replace(/\s+/g, " ").trim();
|
|
91
|
+
return { message: oneLine.length > 200 ? oneLine.slice(0, 200) + "\u2026" : oneLine };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Thrown before any bytes leave: the request could not be built (origin, path).
|
|
95
|
+
* A caller that must decide "was this sent?" treats it as a plain refusal, never an uncertain outcome. */
|
|
96
|
+
export class RequestNotSent extends Error {
|
|
97
|
+
constructor(message, options) {
|
|
98
|
+
super(message, options);
|
|
99
|
+
this.name = "RequestNotSent";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
4
102
|
export function requestUrl(base, path, query) {
|
|
5
|
-
|
|
103
|
+
let url;
|
|
104
|
+
try {
|
|
105
|
+
url = new URL(base.replace(/\/+$/, "") + path);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
throw new RequestNotSent(`invalid request URL: ${base.replace(/\/+$/, "")}${path}`, { cause: error });
|
|
109
|
+
}
|
|
6
110
|
for (const [key, value] of Object.entries(query ?? {}))
|
|
7
111
|
if (value !== undefined && value !== null)
|
|
8
112
|
url.searchParams.set(key, String(value));
|
|
@@ -10,7 +114,10 @@ export function requestUrl(base, path, query) {
|
|
|
10
114
|
}
|
|
11
115
|
export async function httpResponse(url, options = {}) {
|
|
12
116
|
if (options.json !== undefined && options.body !== undefined)
|
|
13
|
-
throw new
|
|
117
|
+
throw new RequestNotSent("give json or body, not both");
|
|
118
|
+
// AbortSignal.timeout accepts a positive integer up to 2**31 - 1 ms; anything else throws after the window opens.
|
|
119
|
+
if (options.timeoutMs !== undefined && !(Number.isSafeInteger(options.timeoutMs) && options.timeoutMs > 0 && options.timeoutMs <= 2 ** 31 - 1))
|
|
120
|
+
throw new RequestNotSent(`timeoutMs must be an integer between 1 and ${2 ** 31 - 1}, got ${options.timeoutMs}`);
|
|
14
121
|
const init = {
|
|
15
122
|
method: options.method ?? "GET",
|
|
16
123
|
redirect: options.redirect ?? "error",
|