siyuan 1.2.0 → 1.2.2-alpha.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/CHANGELOG.md +8 -1
- package/kernel.d.ts +970 -0
- package/package.json +42 -17
- package/siyuan.d.ts +5 -0
- package/types/protyle.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## v1.2.
|
|
3
|
+
## v1.2.2 2026
|
|
4
|
+
|
|
5
|
+
* [:art: add kernel type definitions and update package exports](https://github.com/siyuan-note/petal/pull/49)
|
|
6
|
+
|
|
7
|
+
## v1.2.1 2026-04-21
|
|
8
|
+
|
|
9
|
+
* [Add `switchMode` method to Protyle instance](https://github.com/siyuan-note/siyuan/issues/17552)
|
|
10
|
+
* [Add doc.mode to openTab for opening in document mode](https://github.com/siyuan-note/siyuan/issues/17523)
|
|
4
11
|
|
|
5
12
|
## v1.2.0 2026-04-14
|
|
6
13
|
|
package/kernel.d.ts
ADDED
|
@@ -0,0 +1,970 @@
|
|
|
1
|
+
/// <reference types="@dop251/types-goja_nodejs-buffer" />
|
|
2
|
+
/// <reference types="@dop251/types-goja_nodejs-global" />
|
|
3
|
+
/// <reference types="@dop251/types-goja_nodejs-url" />
|
|
4
|
+
|
|
5
|
+
export { };
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
const siyuan: ISiyuan;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// ── Primitives ────────────────────────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* WebSocket connection ready-state values.
|
|
15
|
+
*
|
|
16
|
+
* @remarks Mirrors the browser `WebSocket.readyState` constants:
|
|
17
|
+
* - `0`: CONNECTING
|
|
18
|
+
* - `1`: OPEN
|
|
19
|
+
* - `2`: CLOSING
|
|
20
|
+
* - `3`: CLOSED
|
|
21
|
+
*/
|
|
22
|
+
export type TWebSocketReadyState = 0 | 1 | 2 | 3;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Server-Sent Events connection ready-state values.
|
|
26
|
+
*
|
|
27
|
+
* @remarks Mirrors the browser `EventSource.readyState` constants:
|
|
28
|
+
* - `0`: CONNECTING
|
|
29
|
+
* - `1`: OPEN
|
|
30
|
+
* - `2`: CLOSED
|
|
31
|
+
*/
|
|
32
|
+
export type TEventSourceReadyState = 0 | 1 | 2;
|
|
33
|
+
|
|
34
|
+
/** An absolute URL path that must start with `/`. */
|
|
35
|
+
export type TRequestPath = `/${string}`;
|
|
36
|
+
|
|
37
|
+
/** A standard UUID in hyphenated 8-4-4-4-12 format. */
|
|
38
|
+
export type UUID = `${string}-${string}-${string}-${string}-${string}`;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A single directory entry returned by {@link IStorage.list}.
|
|
42
|
+
*/
|
|
43
|
+
export interface IStorageEntry {
|
|
44
|
+
/** File or directory name (not the full path). */
|
|
45
|
+
name: string;
|
|
46
|
+
/** `true` if this entry is a directory. */
|
|
47
|
+
isDir: boolean;
|
|
48
|
+
/** `true` if this entry is a symbolic link. */
|
|
49
|
+
isSymlink: boolean;
|
|
50
|
+
/** Last-modified time as a Unix timestamp (seconds since epoch). */
|
|
51
|
+
updated: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A lazy data accessor returned by {@link IStorage.get} and {@link IFetchResponse}.
|
|
56
|
+
*
|
|
57
|
+
* @remarks Each method decodes the same underlying byte slice; call at most
|
|
58
|
+
* once per method per instance.
|
|
59
|
+
*/
|
|
60
|
+
export interface IDataObject {
|
|
61
|
+
/**
|
|
62
|
+
* Decodes the data as a UTF-8 string.
|
|
63
|
+
*
|
|
64
|
+
* @returns The text content.
|
|
65
|
+
*/
|
|
66
|
+
text(): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Parses the data as JSON.
|
|
69
|
+
*
|
|
70
|
+
* @returns The parsed value.
|
|
71
|
+
*/
|
|
72
|
+
json(): Promise<any>;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the raw bytes as a node.js compatible `Buffer`.
|
|
75
|
+
*
|
|
76
|
+
* @returns The binary content.
|
|
77
|
+
*/
|
|
78
|
+
buffer(): Promise<Buffer>;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the raw bytes as an `ArrayBuffer`.
|
|
81
|
+
*
|
|
82
|
+
* @returns The binary content.
|
|
83
|
+
*/
|
|
84
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Response object returned by {@link ISiyuan.fetch}.
|
|
89
|
+
*
|
|
90
|
+
* @remarks Extends {@link IDataObject} so the response body can be read
|
|
91
|
+
* as text, JSON, or raw bytes.
|
|
92
|
+
*/
|
|
93
|
+
export interface IFetchResponse extends IDataObject {
|
|
94
|
+
/** The final URL after any redirects. */
|
|
95
|
+
url: string;
|
|
96
|
+
/** `true` when `status` is in the range 200–299. */
|
|
97
|
+
ok: boolean;
|
|
98
|
+
/** HTTP status code, e.g. `200`. */
|
|
99
|
+
status: number;
|
|
100
|
+
/** HTTP status text, e.g. `"OK"`. */
|
|
101
|
+
statusText: string;
|
|
102
|
+
/** Response headers as a flat string-to-string map. */
|
|
103
|
+
headers: Record<string, string>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Options accepted by {@link ISiyuan.fetch}.
|
|
108
|
+
*/
|
|
109
|
+
export interface IRequestInit {
|
|
110
|
+
/** HTTP method. Defaults to `"GET"` when omitted. */
|
|
111
|
+
method?: string;
|
|
112
|
+
/** Additional request headers. */
|
|
113
|
+
headers?: Record<string, string>;
|
|
114
|
+
/** Request body. Omit for methods that carry no body (e.g. GET, HEAD). */
|
|
115
|
+
body?: string | ArrayBuffer;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* An event message delivered to {@link IEvent.handler}.
|
|
120
|
+
*/
|
|
121
|
+
export interface IEventMessage {
|
|
122
|
+
/** Unique event identifier. */
|
|
123
|
+
id: UUID;
|
|
124
|
+
/** Event type name, e.g. `"ws"`. */
|
|
125
|
+
type: string;
|
|
126
|
+
/** Event-specific payload; the shape depends on `type`. */
|
|
127
|
+
detail: any;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ── WebSocket ─────────────────────────────────────────────────────────────────
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Event fired when the WebSocket connection is established.
|
|
134
|
+
*
|
|
135
|
+
* @see {@link IWebSocket.onopen}
|
|
136
|
+
*/
|
|
137
|
+
export interface IWebSocketOpenEvent {
|
|
138
|
+
type: 'open';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Event fired when the WebSocket connection is closed.
|
|
143
|
+
*
|
|
144
|
+
* @see {@link IWebSocket.onclose}
|
|
145
|
+
*/
|
|
146
|
+
export interface IWebSocketCloseEvent {
|
|
147
|
+
type: 'close';
|
|
148
|
+
/** WebSocket close code per RFC 6455, e.g. `1000` (normal closure). */
|
|
149
|
+
code: number;
|
|
150
|
+
/** Human-readable reason string supplied by the closing peer. */
|
|
151
|
+
reason: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Event fired when a WebSocket transport error occurs.
|
|
156
|
+
*
|
|
157
|
+
* @see {@link IWebSocket.onerror}
|
|
158
|
+
*/
|
|
159
|
+
export interface IWebSocketErrorEvent {
|
|
160
|
+
type: 'error';
|
|
161
|
+
/** The underlying error. */
|
|
162
|
+
error: Error;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Event fired when a WebSocket ping frame is received.
|
|
167
|
+
*
|
|
168
|
+
* @see {@link IWebSocket.onping}
|
|
169
|
+
*/
|
|
170
|
+
export interface IWebSocketPingEvent {
|
|
171
|
+
type: 'ping';
|
|
172
|
+
/** Application data carried in the ping frame. */
|
|
173
|
+
data: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Event fired when a WebSocket pong frame is received.
|
|
178
|
+
*
|
|
179
|
+
* @see {@link IWebSocket.onpong}
|
|
180
|
+
*/
|
|
181
|
+
export interface IWebSocketPongEvent {
|
|
182
|
+
type: 'pong';
|
|
183
|
+
/** Application data carried in the pong frame. */
|
|
184
|
+
data: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Event fired when the WebSocket data frame is received.
|
|
189
|
+
*
|
|
190
|
+
* @see {@link IWebSocket.onmessage}
|
|
191
|
+
*/
|
|
192
|
+
export interface IWebSocketMessageEvent {
|
|
193
|
+
type: 'message';
|
|
194
|
+
/** Payload: `string` for text frames, `ArrayBuffer` for binary frames. */
|
|
195
|
+
data: string | ArrayBuffer;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ── EventSource ───────────────────────────────────────────────────────────────
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Event fired when the EventSource connection is established.
|
|
202
|
+
*
|
|
203
|
+
* @see {@link IEventSource.onopen}
|
|
204
|
+
*/
|
|
205
|
+
export interface IEventSourceOpenEvent {
|
|
206
|
+
type: 'open';
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Event fired when an SSE message is received.
|
|
211
|
+
*
|
|
212
|
+
* @remarks The `type` field reflects the SSE `event:` field value;
|
|
213
|
+
* defaults to `"message"` when the field is absent.
|
|
214
|
+
*
|
|
215
|
+
* @see {@link IEventSource.onmessage}
|
|
216
|
+
*/
|
|
217
|
+
export interface IEventSourceMessageEvent {
|
|
218
|
+
/** Event type; mirrors the SSE `event:` field, defaulting to `"message"`. */
|
|
219
|
+
type: string;
|
|
220
|
+
/** UTF-8 decoded SSE `data:` field value. */
|
|
221
|
+
data: string;
|
|
222
|
+
/** Value of the SSE `id:` field, or an empty string if absent. */
|
|
223
|
+
lastEventId: string;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Event fired when the EventSource connection is closed.
|
|
228
|
+
*
|
|
229
|
+
* @see {@link IEventSource.onclose}
|
|
230
|
+
*/
|
|
231
|
+
export interface IEventSourceCloseEvent {
|
|
232
|
+
type: 'close';
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Event fired when an EventSource transport error occurs.
|
|
237
|
+
*
|
|
238
|
+
* @see {@link IEventSource.onerror}
|
|
239
|
+
*/
|
|
240
|
+
export interface IEventSourceErrorEvent {
|
|
241
|
+
type: 'error';
|
|
242
|
+
/** The underlying error. */
|
|
243
|
+
error: Error;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* A kernel-proxied WebSocket connection returned by {@link IClient.socket}.
|
|
248
|
+
*
|
|
249
|
+
* @remarks Unlike the browser `WebSocket`, this object is returned
|
|
250
|
+
* immediately in a disconnected state. Call {@link IWebSocket.open} to
|
|
251
|
+
* initiate the connection. All event callbacks are nullable; assign a
|
|
252
|
+
* function to start receiving events. Every send operation is asynchronous.
|
|
253
|
+
*/
|
|
254
|
+
export interface IWebSocket {
|
|
255
|
+
/**
|
|
256
|
+
* How binary data is returned in {@link IWebSocket.onmessage}.
|
|
257
|
+
*
|
|
258
|
+
* @remarks Always `"arraybuffer"`.
|
|
259
|
+
*/
|
|
260
|
+
readonly binaryType: string;
|
|
261
|
+
/** Number of bytes currently queued for sending but not yet transmitted. */
|
|
262
|
+
readonly bufferedAmount: number;
|
|
263
|
+
/** Negotiated WebSocket extensions, or an empty string if none. */
|
|
264
|
+
readonly extensions: string;
|
|
265
|
+
/** Negotiated sub-protocol, or an empty string if none was negotiated. */
|
|
266
|
+
readonly protocol: string;
|
|
267
|
+
/** Current connection state. See {@link TWebSocketReadyState}. */
|
|
268
|
+
readyState: TWebSocketReadyState;
|
|
269
|
+
/** The WebSocket server URL (e.g. `"ws://127.0.0.1:6806/ws/…"`). */
|
|
270
|
+
readonly url: string;
|
|
271
|
+
/** Called when the connection is established. */
|
|
272
|
+
onopen: ((event: IWebSocketOpenEvent) => void | Promise<void>) | null;
|
|
273
|
+
/** Called when the connection is closed. */
|
|
274
|
+
onclose: ((event: IWebSocketCloseEvent) => void | Promise<void>) | null;
|
|
275
|
+
/** Called when a transport error occurs. */
|
|
276
|
+
onerror: ((event: IWebSocketErrorEvent) => void | Promise<void>) | null;
|
|
277
|
+
/** Called when a ping control frame is received. */
|
|
278
|
+
onping: ((event: IWebSocketPingEvent) => void | Promise<void>) | null;
|
|
279
|
+
/** Called when a pong control frame is received. */
|
|
280
|
+
onpong: ((event: IWebSocketPongEvent) => void | Promise<void>) | null;
|
|
281
|
+
/** Called when a data frame is received. */
|
|
282
|
+
onmessage: ((event: IWebSocketMessageEvent) => void | Promise<void>) | null;
|
|
283
|
+
/**
|
|
284
|
+
* Initiates the WebSocket connection.
|
|
285
|
+
*
|
|
286
|
+
* @remarks The returned `Promise` resolves once the TCP/TLS handshake
|
|
287
|
+
* succeeds and the HTTP upgrade is confirmed. Calling `open()` more than
|
|
288
|
+
* once is a no-op — the second call resolves immediately.
|
|
289
|
+
*/
|
|
290
|
+
open(): Promise<void>;
|
|
291
|
+
/**
|
|
292
|
+
* Sends a text or binary data frame to the remote peer.
|
|
293
|
+
*
|
|
294
|
+
* @param data - UTF-8 string for a text frame; `ArrayBuffer` for a binary frame.
|
|
295
|
+
*/
|
|
296
|
+
send(data: string | ArrayBuffer): Promise<void>;
|
|
297
|
+
/**
|
|
298
|
+
* Sends a ping control frame.
|
|
299
|
+
*
|
|
300
|
+
* @param data - Optional application data to include in the frame.
|
|
301
|
+
*/
|
|
302
|
+
ping(data?: string): Promise<void>;
|
|
303
|
+
/**
|
|
304
|
+
* Sends a pong control frame.
|
|
305
|
+
*
|
|
306
|
+
* @param data - Optional application data to include in the frame.
|
|
307
|
+
*/
|
|
308
|
+
pong(data?: string): Promise<void>;
|
|
309
|
+
/**
|
|
310
|
+
* Initiates a graceful close handshake.
|
|
311
|
+
*
|
|
312
|
+
* @param code - WebSocket close code (default `1000` — normal closure).
|
|
313
|
+
* @param reason - Optional human-readable reason string (max 123 bytes).
|
|
314
|
+
*/
|
|
315
|
+
close(code?: number, reason?: string): Promise<void>;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// ── Sub-namespaces ────────────────────────────────────────────────────────────
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* A kernel-proxied Server-Sent Events connection returned by {@link IClient.event}.
|
|
322
|
+
*
|
|
323
|
+
* @remarks The object is returned in {@link TEventSourceReadyState | CONNECTING} state
|
|
324
|
+
* immediately; the kernel starts the SSE subscription in the background and
|
|
325
|
+
* fires {@link IEventSource.onopen} once the stream is established.
|
|
326
|
+
* Call {@link IEventSource.close} to cancel the subscription.
|
|
327
|
+
*/
|
|
328
|
+
export interface IEventSource {
|
|
329
|
+
/** Current connection state. See {@link TEventSourceReadyState}. */
|
|
330
|
+
readyState: TEventSourceReadyState;
|
|
331
|
+
/** The original path passed to {@link IClient.event}, e.g. `"/api/…"`. */
|
|
332
|
+
readonly url: string;
|
|
333
|
+
/** Called when the connection is established. */
|
|
334
|
+
onopen: ((event: IEventSourceOpenEvent) => void | Promise<void>) | null;
|
|
335
|
+
/** Called when a message is received. */
|
|
336
|
+
onmessage: ((event: IEventSourceMessageEvent) => void | Promise<void>) | null;
|
|
337
|
+
/** Called when the connection is closed by the server or after {@link IEventSource.close}. */
|
|
338
|
+
onclose: ((event: IEventSourceCloseEvent) => void | Promise<void>) | null;
|
|
339
|
+
/** Called when a transport error occurs. */
|
|
340
|
+
onerror: ((event: IEventSourceErrorEvent) => void | Promise<void>) | null;
|
|
341
|
+
/** Cancels the subscription and closes the connection. */
|
|
342
|
+
close(): void;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Network client utilities exposed as `siyuan.client`.
|
|
347
|
+
*
|
|
348
|
+
* @remarks Provides HTTP, WebSocket, and Server-Sent Events access, all
|
|
349
|
+
* tunnelled through the kernel and authenticated with the plugin token.
|
|
350
|
+
*/
|
|
351
|
+
export interface IClient {
|
|
352
|
+
/**
|
|
353
|
+
* Tunnels an HTTP request through the kernel's REST API.
|
|
354
|
+
*
|
|
355
|
+
* @param path - Absolute path starting with `/`, e.g. `"/api/system/version"`.
|
|
356
|
+
* @param init - Optional request options (method, headers, body).
|
|
357
|
+
* @returns A {@link IFetchResponse} with lazy body accessor methods.
|
|
358
|
+
*/
|
|
359
|
+
fetch(path: TRequestPath, init?: IRequestInit): Promise<IFetchResponse>;
|
|
360
|
+
/**
|
|
361
|
+
* Creates a WebSocket connection proxied through the kernel.
|
|
362
|
+
*
|
|
363
|
+
* @remarks The returned object is in {@link TWebSocketReadyState | CONNECTING}
|
|
364
|
+
* state but not yet connected. Call {@link IWebSocket.open} to initiate
|
|
365
|
+
* the handshake.
|
|
366
|
+
*
|
|
367
|
+
* @param path - Absolute path starting with `/`.
|
|
368
|
+
* @param protocols - Optional WebSocket sub-protocol(s) to negotiate.
|
|
369
|
+
* @returns A sealed {@link IWebSocket} handle.
|
|
370
|
+
*/
|
|
371
|
+
socket(path: TRequestPath, protocols?: string | string[]): Promise<IWebSocket>;
|
|
372
|
+
/**
|
|
373
|
+
* Opens a Server-Sent Events stream proxied through the kernel.
|
|
374
|
+
*
|
|
375
|
+
* @param path - Absolute path starting with `/`.
|
|
376
|
+
* @returns A sealed {@link IEventSource} handle.
|
|
377
|
+
*/
|
|
378
|
+
event(path: TRequestPath): Promise<IEventSource>;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// ── Plugin sub-namespaces ─────────────────────────────────────────────────────
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Static metadata for the running plugin instance.
|
|
385
|
+
*
|
|
386
|
+
* @remarks Exposed as `siyuan.plugin`. All properties are read-only at
|
|
387
|
+
* runtime; the values are set by the kernel before `onload` is called.
|
|
388
|
+
*/
|
|
389
|
+
export interface IPlugin {
|
|
390
|
+
/** Internal plugin identifier (matches the plugin directory name). */
|
|
391
|
+
readonly name: string;
|
|
392
|
+
/** Semantic version string, e.g. `"1.0.0"`. */
|
|
393
|
+
readonly version: string;
|
|
394
|
+
/** Human-readable display name shown in the plugin marketplace. */
|
|
395
|
+
readonly displayName: string;
|
|
396
|
+
/** Backend platform identifier, e.g. `"windows"`, `"linux"`, `"darwin"`. */
|
|
397
|
+
readonly platform: string;
|
|
398
|
+
/** Localization strings loaded from the plugin's `i18n/` directory. */
|
|
399
|
+
readonly i18n: Record<string, any>;
|
|
400
|
+
/** Kernel lifecycle hooks for this plugin. */
|
|
401
|
+
readonly lifecycle: IPluginLifecycle;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Optional lifecycle callbacks invoked by the kernel at state transitions.
|
|
406
|
+
*
|
|
407
|
+
* @remarks Exposed as `siyuan.plugin.lifecycle`. Assign a function to any
|
|
408
|
+
* property to subscribe; the kernel awaits any returned `Promise` before
|
|
409
|
+
* advancing to the next lifecycle stage. Unset callbacks (`null`) are skipped.
|
|
410
|
+
*/
|
|
411
|
+
export interface IPluginLifecycle {
|
|
412
|
+
/** Called when the plugin script is first evaluated (before the runtime is fully ready). */
|
|
413
|
+
onload: (() => void | Promise<void>) | null;
|
|
414
|
+
/** Called after the plugin has fully loaded and its runtime is initialized. */
|
|
415
|
+
onloaded: (() => void | Promise<void>) | null;
|
|
416
|
+
/** Called when the plugin transitions to the `running` state. */
|
|
417
|
+
onrunning: (() => void | Promise<void>) | null;
|
|
418
|
+
/** Called when the plugin is being unloaded (e.g. on shutdown or hot-reload). */
|
|
419
|
+
onunload: (() => void | Promise<void>) | null;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Kernel event bridge.
|
|
424
|
+
*
|
|
425
|
+
* @remarks Exposed as `siyuan.event`. Allows the plugin to receive kernel
|
|
426
|
+
* broadcast events and publish events to the in-process bus.
|
|
427
|
+
*/
|
|
428
|
+
export interface IEvent {
|
|
429
|
+
/**
|
|
430
|
+
* Inbound kernel event handler.
|
|
431
|
+
*
|
|
432
|
+
* @remarks Assign a function to receive every kernel broadcast event.
|
|
433
|
+
* If the function returns a `Promise`, the kernel awaits its resolution
|
|
434
|
+
* before delivering the next event. Set to `null` to stop receiving events.
|
|
435
|
+
*/
|
|
436
|
+
handler: ((event: IEventMessage) => void | Promise<void>) | null;
|
|
437
|
+
/**
|
|
438
|
+
* Publishes an event to the in-process event bus.
|
|
439
|
+
*
|
|
440
|
+
* @param topic - Event topic string used to route the event to subscribers.
|
|
441
|
+
* @param event - Arbitrary serializable payload.
|
|
442
|
+
*/
|
|
443
|
+
emit(topic: string, event: IEventMessage): Promise<void>;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Structured logger for the plugin.
|
|
448
|
+
*
|
|
449
|
+
* @remarks Exposed as `siyuan.logger`. Level semantics mirror the browser
|
|
450
|
+
* `console` API (`trace` < `debug` < `info` < `warn` < `error`). Output is
|
|
451
|
+
* written to the kernel log file and prefixed with the plugin name.
|
|
452
|
+
*/
|
|
453
|
+
export interface ILogger {
|
|
454
|
+
/** Emits a `TRACE`-level log entry. */
|
|
455
|
+
readonly trace: (...args: any[]) => Promise<void>;
|
|
456
|
+
/** Emits a `DEBUG`-level log entry. */
|
|
457
|
+
readonly debug: (...args: any[]) => Promise<void>;
|
|
458
|
+
/** Emits an `INFO`-level log entry. */
|
|
459
|
+
readonly info: (...args: any[]) => Promise<void>;
|
|
460
|
+
/** Emits a `WARN`-level log entry. */
|
|
461
|
+
readonly warn: (...args: any[]) => Promise<void>;
|
|
462
|
+
/** Emits an `ERROR`-level log entry. */
|
|
463
|
+
readonly error: (...args: any[]) => Promise<void>;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Scoped file storage for the plugin.
|
|
468
|
+
*
|
|
469
|
+
* @remarks Exposed as `siyuan.storage`. All paths are relative to the
|
|
470
|
+
* plugin's data directory at `data/plugins/<name>/`. Forward slashes are
|
|
471
|
+
* accepted on all platforms.
|
|
472
|
+
*/
|
|
473
|
+
export interface IStorage {
|
|
474
|
+
/**
|
|
475
|
+
* Reads a file and returns a lazy data accessor.
|
|
476
|
+
*
|
|
477
|
+
* @param path - Path relative to the plugin data directory.
|
|
478
|
+
* @returns A {@link IDataObject} wrapping the file contents.
|
|
479
|
+
* @throws Rejects if the file does not exist.
|
|
480
|
+
*/
|
|
481
|
+
get(path: string): Promise<IDataObject>;
|
|
482
|
+
/**
|
|
483
|
+
* Creates or overwrites a file with the provided UTF-8 string content.
|
|
484
|
+
*
|
|
485
|
+
* @param path - Path relative to the plugin data directory.
|
|
486
|
+
* @param content - UTF-8 encoded content to write.
|
|
487
|
+
*/
|
|
488
|
+
put(path: string, content: string): Promise<void>;
|
|
489
|
+
/**
|
|
490
|
+
* Deletes a file or recursively removes a directory tree.
|
|
491
|
+
*
|
|
492
|
+
* @param path - Path relative to the plugin data directory.
|
|
493
|
+
*/
|
|
494
|
+
remove(path: string): Promise<void>;
|
|
495
|
+
/**
|
|
496
|
+
* Lists the entries in a directory.
|
|
497
|
+
*
|
|
498
|
+
* @param path - Path relative to the plugin data directory.
|
|
499
|
+
* @returns An array of {@link IStorageEntry} descriptors.
|
|
500
|
+
*/
|
|
501
|
+
list(path: string): Promise<IStorageEntry[]>;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* JSON-RPC method registry for the plugin.
|
|
506
|
+
*
|
|
507
|
+
* @remarks Exposed as `siyuan.rpc`. Registered methods are callable by
|
|
508
|
+
* external clients via `GET /api/plugin/rpc`, `POST /api/plugin/rpc`, or
|
|
509
|
+
* the WebSocket endpoint `GET /ws/plugin/rpc`.
|
|
510
|
+
*/
|
|
511
|
+
export interface IRpc {
|
|
512
|
+
/**
|
|
513
|
+
* Registers a named RPC method callable by external clients.
|
|
514
|
+
*
|
|
515
|
+
* @param name - Unique method name used to dispatch the call.
|
|
516
|
+
* @param fn - Handler function; may be async.
|
|
517
|
+
* @param descriptions - Optional human-readable description strings.
|
|
518
|
+
*/
|
|
519
|
+
bind(
|
|
520
|
+
name: string,
|
|
521
|
+
fn: (...args: any[]) => any | Promise<any>,
|
|
522
|
+
...descriptions: string[]
|
|
523
|
+
): Promise<void>;
|
|
524
|
+
/**
|
|
525
|
+
* Unregisters a previously registered RPC method.
|
|
526
|
+
*
|
|
527
|
+
* @param name - The method name originally passed to {@link IRpc.bind}.
|
|
528
|
+
*/
|
|
529
|
+
unbind(name: string): Promise<void>;
|
|
530
|
+
/**
|
|
531
|
+
* Broadcasts a JSON-RPC notification to all connected clients.
|
|
532
|
+
*
|
|
533
|
+
* @param method - Notification method name.
|
|
534
|
+
* @param params - Optional notification parameters.
|
|
535
|
+
*/
|
|
536
|
+
broadcast(method: string, params?: any): Promise<void>;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// ── Server request types ─────────────────────────────────────────────────────
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Serialization format for a structured {@link IResponseBody.data} payload.
|
|
543
|
+
*
|
|
544
|
+
* @remarks The kernel delegates to the corresponding Gin writer:
|
|
545
|
+
* JSON variants map to `c.JSON` / `c.JSONP` / `c.AsciiJSON` / etc.;
|
|
546
|
+
* `XML` → `c.XML`; `YAML` → `c.YAML`; `TOML` → `c.TOML`;
|
|
547
|
+
* `ProtoBuf` → `c.ProtoBuf`.
|
|
548
|
+
*/
|
|
549
|
+
export type TSerializedType =
|
|
550
|
+
| 'JSON' | 'JSONP' | 'AsciiJSON' | 'IndentedJSON' | 'PureJSON' | 'SecureJSON'
|
|
551
|
+
| 'XML' | 'YAML' | 'TOML' | 'ProtoBuf';
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* HTTP Basic authentication credentials extracted from the request URL.
|
|
555
|
+
*/
|
|
556
|
+
export interface IRequestUser {
|
|
557
|
+
/** Decoded username. */
|
|
558
|
+
username: string;
|
|
559
|
+
/** Decoded password. */
|
|
560
|
+
password: string;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Parsed URL components of an incoming server request.
|
|
565
|
+
*
|
|
566
|
+
* @remarks Field names mirror the browser `URL` / `Location` API where
|
|
567
|
+
* applicable (`pathname`, `hash`, `search`).
|
|
568
|
+
*/
|
|
569
|
+
export interface IRequestUrl {
|
|
570
|
+
/** Basic-auth credentials, or `null` if the request carries none. */
|
|
571
|
+
user: IRequestUser | null;
|
|
572
|
+
/** Value of the `Host` request header, e.g. `"127.0.0.1:6806"`. */
|
|
573
|
+
host: string;
|
|
574
|
+
/** URL-decoded path, e.g. `"/plugin/private/sample/api/hello/a space"`. */
|
|
575
|
+
path: string;
|
|
576
|
+
/** Percent-encoded path, e.g. `"/plugin/private/sample/api/hello/a%20space"`. */
|
|
577
|
+
pathname: string;
|
|
578
|
+
/** URL-decoded fragment without the leading `#`. */
|
|
579
|
+
fragment: string;
|
|
580
|
+
/** Percent-encoded fragment without the leading `#`. */
|
|
581
|
+
hash: string;
|
|
582
|
+
/** Raw query string without the leading `?`, e.g. `"a=1&b=2"`. */
|
|
583
|
+
search: string;
|
|
584
|
+
/** Parsed query parameters, e.g. `{ a: ["1"], b: ["2"] }`. */
|
|
585
|
+
query: Record<string, string[]>;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* An uploaded file part within a `multipart/form-data` request.
|
|
590
|
+
*/
|
|
591
|
+
export interface IRequestFile {
|
|
592
|
+
/** Original filename provided by the client. */
|
|
593
|
+
filename: string;
|
|
594
|
+
/** MIME part headers (e.g. `Content-Disposition`, `Content-Type`). */
|
|
595
|
+
headers: Record<string, string[]>;
|
|
596
|
+
/** File size in bytes. */
|
|
597
|
+
size: number;
|
|
598
|
+
/**
|
|
599
|
+
* File contents as a lazy {@link IDataObject}.
|
|
600
|
+
*
|
|
601
|
+
* @remarks `null` if the file could not be read during request parsing.
|
|
602
|
+
*/
|
|
603
|
+
data: IDataObject | null;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Parsed form data from an `application/x-www-form-urlencoded` or
|
|
608
|
+
* `multipart/form-data` request.
|
|
609
|
+
*/
|
|
610
|
+
export interface IRequestForm {
|
|
611
|
+
/**
|
|
612
|
+
* String form fields keyed by field name.
|
|
613
|
+
*
|
|
614
|
+
* @remarks Each key maps to an array to support repeated fields with the
|
|
615
|
+
* same name, e.g. `{ tags: ["a", "b"] }`.
|
|
616
|
+
*/
|
|
617
|
+
values: Record<string, string[]>;
|
|
618
|
+
/** Uploaded file parts keyed by field name. */
|
|
619
|
+
files: Record<string, IRequestFile[]>;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Body of an incoming server request.
|
|
624
|
+
*
|
|
625
|
+
* @remarks Exactly one of `form` or `data` is non-null:
|
|
626
|
+
* `form` is set for `application/x-www-form-urlencoded` and
|
|
627
|
+
* `multipart/form-data`; `data` is set for all other content types and is
|
|
628
|
+
* `null` when the request carries no body.
|
|
629
|
+
*/
|
|
630
|
+
export interface IRequestBody {
|
|
631
|
+
/**
|
|
632
|
+
* Parsed form data.
|
|
633
|
+
*
|
|
634
|
+
* @remarks `null` for non-form requests.
|
|
635
|
+
*/
|
|
636
|
+
form: IRequestForm | null;
|
|
637
|
+
/**
|
|
638
|
+
* Raw request body as a lazy {@link IDataObject}.
|
|
639
|
+
*
|
|
640
|
+
* @remarks `null` when `form` is non-null or the request carries no body.
|
|
641
|
+
*/
|
|
642
|
+
data: IDataObject | null;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* HTTP request-line and header fields.
|
|
647
|
+
*
|
|
648
|
+
* @remarks The `Cookie` and `Authorization` headers are stripped from
|
|
649
|
+
* `headers` before the request is forwarded to the plugin handler.
|
|
650
|
+
*/
|
|
651
|
+
export interface IRequestContent {
|
|
652
|
+
/** HTTP method in upper-case, e.g. `"GET"`, `"POST"`. */
|
|
653
|
+
method: string;
|
|
654
|
+
/** Full request URI including the query string, e.g. `"/plugin/private/sample/api/hello?a=1"`. */
|
|
655
|
+
uri: string;
|
|
656
|
+
/** HTTP protocol version string, e.g. `"HTTP/1.1"`. */
|
|
657
|
+
proto: string;
|
|
658
|
+
/** Major protocol version number, e.g. `1`. */
|
|
659
|
+
protoMajor: number;
|
|
660
|
+
/** Minor protocol version number, e.g. `1`. */
|
|
661
|
+
protoMinor: number;
|
|
662
|
+
/**
|
|
663
|
+
* Request headers with `Cookie` and `Authorization` redacted.
|
|
664
|
+
*
|
|
665
|
+
* @remarks Each header name maps to an array of values to handle
|
|
666
|
+
* repeated headers, e.g. `{ "Accept-Encoding": ["gzip", "br"] }`.
|
|
667
|
+
*/
|
|
668
|
+
headers: Record<string, string[]>;
|
|
669
|
+
/**
|
|
670
|
+
* Request cookies keyed by cookie name.
|
|
671
|
+
*
|
|
672
|
+
* @remarks Each name maps to an array to handle duplicate cookie names.
|
|
673
|
+
*/
|
|
674
|
+
cookies: Record<string, string[]>;
|
|
675
|
+
/** Media type from the `Content-Type` header (parameters stripped), e.g. `"application/json"`. */
|
|
676
|
+
contentType: string;
|
|
677
|
+
/** Value of the `Content-Length` header in bytes; `-1` if unknown. */
|
|
678
|
+
contentLength: number;
|
|
679
|
+
/** Value of the `Referer` header, or an empty string if absent. */
|
|
680
|
+
referer: string;
|
|
681
|
+
/** Value of the `User-Agent` header. */
|
|
682
|
+
userAgent: string;
|
|
683
|
+
/** Parsed request body. */
|
|
684
|
+
body: IRequestBody;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Gin routing context for an incoming server request.
|
|
689
|
+
*/
|
|
690
|
+
export interface IRequestContext {
|
|
691
|
+
/**
|
|
692
|
+
* The sub-path captured by the `*path` wildcard parameter.
|
|
693
|
+
*
|
|
694
|
+
* @example `"/api/hello"` for a request to `/plugin/private/sample/api/hello`.
|
|
695
|
+
*/
|
|
696
|
+
path: string;
|
|
697
|
+
/** Full Gin route template, e.g. `"/plugin/private/:name/*path"`. */
|
|
698
|
+
fullPath: string;
|
|
699
|
+
/** Best-guess client IP address (honors `X-Forwarded-For` / `X-Real-IP`). */
|
|
700
|
+
clientIp: string;
|
|
701
|
+
/** Remote IP of the TCP connection (proxy headers are not considered). */
|
|
702
|
+
remoteIp: string;
|
|
703
|
+
/** `host:port` of the remote TCP endpoint, e.g. `"127.0.0.1:54321"`. */
|
|
704
|
+
remoteAddr: string;
|
|
705
|
+
/**
|
|
706
|
+
* Named route parameters extracted by Gin.
|
|
707
|
+
*
|
|
708
|
+
* @example `{ name: ["plugin-sample"], path: ["/api/hello"] }`
|
|
709
|
+
*/
|
|
710
|
+
params: Record<string, string[]>;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* The complete request object passed as the sole argument to server handlers.
|
|
715
|
+
*/
|
|
716
|
+
export interface IServerRequest {
|
|
717
|
+
/** Parsed URL components. */
|
|
718
|
+
url: IRequestUrl;
|
|
719
|
+
/** HTTP request-line, headers, and body. */
|
|
720
|
+
request: IRequestContent;
|
|
721
|
+
/** Gin routing context. */
|
|
722
|
+
context: IRequestContext;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// ── Server response types ─────────────────────────────────────────────────────
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* A structured-data response body serialized by the kernel.
|
|
729
|
+
*
|
|
730
|
+
* @remarks The kernel selects the Gin writer that corresponds to `type`
|
|
731
|
+
* (e.g. `c.JSON` for `"JSON"`, `c.XML` for `"XML"`).
|
|
732
|
+
*/
|
|
733
|
+
export interface IResponseSerializedData {
|
|
734
|
+
/** Serialization format to use. */
|
|
735
|
+
type: TSerializedType;
|
|
736
|
+
/** The value to serialize; must be compatible with the chosen format. */
|
|
737
|
+
data: any;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* A file response body served directly from the local filesystem.
|
|
742
|
+
*
|
|
743
|
+
* @remarks When `name` is non-empty the kernel sends the file as a
|
|
744
|
+
* downloadable attachment (`Content-Disposition: attachment; filename="<name>"`).
|
|
745
|
+
* When `name` is empty or omitted the file is served inline via `c.File`.
|
|
746
|
+
*/
|
|
747
|
+
export interface IResponseFile {
|
|
748
|
+
/**
|
|
749
|
+
* Download filename for the `Content-Disposition` header.
|
|
750
|
+
*
|
|
751
|
+
* @remarks Omit or leave empty to serve the file inline.
|
|
752
|
+
*/
|
|
753
|
+
name?: string;
|
|
754
|
+
/** Absolute filesystem path to the file on the server host. */
|
|
755
|
+
path: string;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* A formatted-string response body.
|
|
760
|
+
*
|
|
761
|
+
* @remarks The kernel passes `format` and `values` to Go's `fmt.Sprintf`
|
|
762
|
+
* and writes the resulting string via `c.String`.
|
|
763
|
+
*/
|
|
764
|
+
export interface IResponseString {
|
|
765
|
+
/** Go `fmt.Sprintf`-style format string, e.g. `"Hello, %s!"`. */
|
|
766
|
+
format: string;
|
|
767
|
+
/** Positional arguments interpolated into `format`. */
|
|
768
|
+
values?: any[];
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* A raw-bytes response body with an explicit `Content-Type`.
|
|
773
|
+
*
|
|
774
|
+
* @remarks Written to the response via `c.Data`. `data` accepts a UTF-8
|
|
775
|
+
* string, a Node.js `Buffer`, or an `ArrayBuffer`; the kernel converts all
|
|
776
|
+
* three forms to `[]byte` before writing.
|
|
777
|
+
*/
|
|
778
|
+
export interface IResponseRawData {
|
|
779
|
+
/** MIME type for the `Content-Type` response header, e.g. `"image/png"`. */
|
|
780
|
+
contentType: string;
|
|
781
|
+
/** Raw response body bytes. */
|
|
782
|
+
data: string | ArrayBuffer;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* A redirect response body.
|
|
787
|
+
*
|
|
788
|
+
* @remarks The kernel issues the redirect via `c.Redirect` using the
|
|
789
|
+
* `statusCode` from the enclosing {@link IHttpResponse}.
|
|
790
|
+
*/
|
|
791
|
+
export interface IResponseRedirect {
|
|
792
|
+
/** Target URL; may be absolute or relative. */
|
|
793
|
+
location: string;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* The body of an HTTP response returned by a server handler.
|
|
798
|
+
*
|
|
799
|
+
* @remarks Set exactly one field; the kernel inspects `data`, `file`,
|
|
800
|
+
* `string`, `raw`, and `redirect` in that order and uses the first
|
|
801
|
+
* non-null value. Returning an empty object (all fields absent or null)
|
|
802
|
+
* results in a status-only response via `c.Status`.
|
|
803
|
+
*/
|
|
804
|
+
export interface IResponseBody {
|
|
805
|
+
/** Structured data serialized by the kernel (JSON, XML, YAML, …). */
|
|
806
|
+
data?: IResponseSerializedData | null;
|
|
807
|
+
/** File served from the local filesystem. */
|
|
808
|
+
file?: IResponseFile | null;
|
|
809
|
+
/** Formatted string written via `fmt.Sprintf`. */
|
|
810
|
+
string?: IResponseString | null;
|
|
811
|
+
/** Raw bytes with an explicit `Content-Type`. */
|
|
812
|
+
raw?: IResponseRawData | null;
|
|
813
|
+
/** HTTP redirect. */
|
|
814
|
+
redirect?: IResponseRedirect | null;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* A `Set-Cookie` descriptor included in an {@link IHttpResponse}.
|
|
819
|
+
*
|
|
820
|
+
* @remarks Field names use PascalCase because they mirror Go's
|
|
821
|
+
* `net/http.Cookie` struct, which has no JSON tags and therefore serializes
|
|
822
|
+
* its exported field names verbatim.
|
|
823
|
+
*/
|
|
824
|
+
export interface IResponseCookie {
|
|
825
|
+
/** Cookie name. */
|
|
826
|
+
Name: string;
|
|
827
|
+
/** Cookie value. */
|
|
828
|
+
Value: string;
|
|
829
|
+
/** `true` if the value should be wrapped in double-quotes in the header. */
|
|
830
|
+
Quoted?: boolean;
|
|
831
|
+
/** Cookie path scope, e.g. `"/plugin/private/my-plugin/"`. */
|
|
832
|
+
Path?: string;
|
|
833
|
+
/** Cookie domain scope. */
|
|
834
|
+
Domain?: string;
|
|
835
|
+
/** Absolute expiry time as an ISO 8601 string. */
|
|
836
|
+
Expires?: string;
|
|
837
|
+
/** Raw, unparsed `Expires` attribute string (informational). */
|
|
838
|
+
RawExpires?: string;
|
|
839
|
+
/** `Max-Age` in seconds. `0` deletes the cookie; negative values are not sent. */
|
|
840
|
+
MaxAge?: number;
|
|
841
|
+
/** Restricts the cookie to HTTPS connections. */
|
|
842
|
+
Secure?: boolean;
|
|
843
|
+
/** Hides the cookie from JavaScript (`HttpOnly` flag). */
|
|
844
|
+
HttpOnly?: boolean;
|
|
845
|
+
/**
|
|
846
|
+
* `SameSite` cookie policy.
|
|
847
|
+
*
|
|
848
|
+
* @remarks Maps to Go `http.SameSite` constants:
|
|
849
|
+
* `0` = default (browser-defined), `1` = None, `2` = Lax, `3` = Strict.
|
|
850
|
+
*/
|
|
851
|
+
SameSite?: number;
|
|
852
|
+
/** Sets the `Partitioned` (CHIPS) cookie attribute. */
|
|
853
|
+
Partitioned?: boolean;
|
|
854
|
+
/** Raw `Set-Cookie` line as sent by the server (informational). */
|
|
855
|
+
Raw?: string;
|
|
856
|
+
/** Unparsed attribute strings not recognized by the Go cookie parser. */
|
|
857
|
+
Unparsed?: string[] | null;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* The return value expected from an HTTP server handler.
|
|
862
|
+
*/
|
|
863
|
+
export interface IHttpResponse {
|
|
864
|
+
/** HTTP status code to send, e.g. `200`, `404`. */
|
|
865
|
+
statusCode: number;
|
|
866
|
+
/**
|
|
867
|
+
* Additional response headers.
|
|
868
|
+
*
|
|
869
|
+
* @remarks Each header name maps to an array of values to support
|
|
870
|
+
* multi-value headers such as `Link` or repeated `Set-Cookie` entries.
|
|
871
|
+
*/
|
|
872
|
+
headers?: Record<string, string[]>;
|
|
873
|
+
/** Cookies to attach to the response via `Set-Cookie` headers. */
|
|
874
|
+
cookies?: IResponseCookie[];
|
|
875
|
+
/** Response body. Omit or set to `null` for a header-only response. */
|
|
876
|
+
body?: IResponseBody | null;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
// ── Server handler interfaces ─────────────────────────────────────────────────
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Handler slot for one request type within a server scope.
|
|
883
|
+
*
|
|
884
|
+
* @remarks The object is sealed by the kernel; only the `handler` property
|
|
885
|
+
* may be reassigned. Set `handler` to `null` to leave the slot empty — the
|
|
886
|
+
* kernel will return `500 Internal Server Error` for any unhandled request.
|
|
887
|
+
*
|
|
888
|
+
* @typeParam TRes - Expected return type of the handler function.
|
|
889
|
+
*/
|
|
890
|
+
export interface IServerRequestHandler<TRes> {
|
|
891
|
+
/**
|
|
892
|
+
* The function invoked for each incoming request of this type.
|
|
893
|
+
*
|
|
894
|
+
* @remarks The kernel passes the parsed {@link IServerRequest} as the
|
|
895
|
+
* sole argument and awaits any returned `Promise` before writing the
|
|
896
|
+
* response.
|
|
897
|
+
*/
|
|
898
|
+
handler: ((request: IServerRequest) => TRes | Promise<TRes>) | null;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* All request-type handler slots for one access scope.
|
|
903
|
+
*
|
|
904
|
+
* @remarks The object is frozen by the kernel; only the `handler` property
|
|
905
|
+
* on each child object may be reassigned.
|
|
906
|
+
*/
|
|
907
|
+
export interface IServerScope {
|
|
908
|
+
/**
|
|
909
|
+
* HTTP request handler.
|
|
910
|
+
*
|
|
911
|
+
* @remarks Handles all HTTP methods at `ANY /plugin/private/<name>/*path`.
|
|
912
|
+
* The handler must return an {@link IHttpResponse}.
|
|
913
|
+
*/
|
|
914
|
+
readonly http: IServerRequestHandler<IHttpResponse>;
|
|
915
|
+
/**
|
|
916
|
+
* WebSocket upgrade handler.
|
|
917
|
+
*
|
|
918
|
+
* @remarks Reserved — not yet implemented by the kernel.
|
|
919
|
+
*/
|
|
920
|
+
readonly ws: IServerRequestHandler<void>;
|
|
921
|
+
/**
|
|
922
|
+
* Server-Sent Events handler.
|
|
923
|
+
*
|
|
924
|
+
* @remarks Reserved — not yet implemented by the kernel.
|
|
925
|
+
*/
|
|
926
|
+
readonly es: IServerRequestHandler<void>;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* Web server handler registry for the plugin.
|
|
931
|
+
*
|
|
932
|
+
* @remarks Exposed as `siyuan.server`. The kernel creates one frozen scope
|
|
933
|
+
* object per access level. Only the `handler` properties inside each scope
|
|
934
|
+
* object are writable.
|
|
935
|
+
*/
|
|
936
|
+
export interface IServer {
|
|
937
|
+
/**
|
|
938
|
+
* Private-scope handler group.
|
|
939
|
+
*
|
|
940
|
+
* @remarks Routes under `/plugin/private/<name>/*path` require kernel
|
|
941
|
+
* authentication and admin role before the request reaches the handler.
|
|
942
|
+
* The `<name>` segment must match the running plugin's `name`.
|
|
943
|
+
*/
|
|
944
|
+
readonly private: IServerScope;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// ── Top-level interface ───────────────────────────────────────────────────────
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* The root `siyuan` global exposed to every kernel plugin script.
|
|
951
|
+
*
|
|
952
|
+
* @remarks Available as the global constant `siyuan`. All async operations
|
|
953
|
+
* return `Promise`s resolved on the plugin's JavaScript runtime event loop.
|
|
954
|
+
*/
|
|
955
|
+
export interface ISiyuan {
|
|
956
|
+
/** Static metadata about this plugin instance. */
|
|
957
|
+
readonly plugin: IPlugin;
|
|
958
|
+
/** Kernel event bridge. */
|
|
959
|
+
readonly event: IEvent;
|
|
960
|
+
/** Structured logger. */
|
|
961
|
+
readonly logger: ILogger;
|
|
962
|
+
/** Scoped persistent file storage. */
|
|
963
|
+
readonly storage: IStorage;
|
|
964
|
+
/** JSON-RPC method registry. */
|
|
965
|
+
readonly rpc: IRpc;
|
|
966
|
+
/** Network client utilities (HTTP, WebSocket, SSE). */
|
|
967
|
+
readonly client: IClient;
|
|
968
|
+
/** Web request handler registry. */
|
|
969
|
+
readonly server: IServer;
|
|
970
|
+
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"siyuan.d.ts"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
"name": "siyuan",
|
|
3
|
+
"version": "1.2.2-alpha.0",
|
|
4
|
+
"contributors": [
|
|
5
|
+
"zuoez02",
|
|
6
|
+
"Vanessa",
|
|
7
|
+
"Zuoqiu-Yingyi"
|
|
8
|
+
],
|
|
9
|
+
"types": "siyuan.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./siyuan.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./siyuan.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./kernel": {
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./kernel.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./kernel.d.ts"
|
|
25
|
+
}
|
|
19
26
|
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"types",
|
|
30
|
+
"CHANGELOG.md",
|
|
31
|
+
"kernel.d.ts",
|
|
32
|
+
"package.json",
|
|
33
|
+
"README.md",
|
|
34
|
+
"siyuan.d.ts"
|
|
35
|
+
],
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/siyuan-note/petal.git"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@dop251/types-goja_nodejs-buffer": "latest",
|
|
42
|
+
"@dop251/types-goja_nodejs-global": "latest",
|
|
43
|
+
"@dop251/types-goja_nodejs-url": "latest"
|
|
44
|
+
}
|
|
20
45
|
}
|
package/siyuan.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
TProtyleAction,
|
|
13
13
|
IMenuItem,
|
|
14
14
|
IRefDefs,
|
|
15
|
+
TEditorMode,
|
|
15
16
|
} from "./types";
|
|
16
17
|
import {
|
|
17
18
|
Config,
|
|
@@ -329,12 +330,16 @@ export function expandDocTree(options: {
|
|
|
329
330
|
|
|
330
331
|
export function openMobileFileById(app: App, id: string, action?: TProtyleAction[]): void;
|
|
331
332
|
|
|
333
|
+
/**
|
|
334
|
+
* @param {string} [options.doc.mode="wysiwyg"] - 只在首次打开时生效,切换可调用 switchMode 方法
|
|
335
|
+
*/
|
|
332
336
|
export function openTab(options: {
|
|
333
337
|
app: App,
|
|
334
338
|
doc?: {
|
|
335
339
|
id: string, // 块 id
|
|
336
340
|
action?: TProtyleAction[],
|
|
337
341
|
zoomIn?: boolean, // 是否缩放
|
|
342
|
+
mode?: TEditorMode
|
|
338
343
|
};
|
|
339
344
|
pdf?: {
|
|
340
345
|
path: string,
|
package/types/protyle.d.ts
CHANGED
|
@@ -294,6 +294,8 @@ export class Protyle {
|
|
|
294
294
|
public enable(): void
|
|
295
295
|
|
|
296
296
|
public renderAVAttribute(element: HTMLElement, id: string, cb?: (element: HTMLElement) => void): void
|
|
297
|
+
|
|
298
|
+
public switchMode(mode: TEditorMode): void
|
|
297
299
|
}
|
|
298
300
|
|
|
299
301
|
export class ProtyleMethod {
|