@typerighter/rpc-client 0.40.0 → 0.40.2

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.
@@ -0,0 +1,54 @@
1
+ /**
2
+ * JSON-RPC 2.0 client with Content-Length framing
3
+ * Simplified from vscode-jsonrpc (MIT, Microsoft Corporation)
4
+ * Ref: https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L506-L591
5
+ */
6
+ import type { Readable, Writable } from 'node:stream';
7
+ interface Disposable {
8
+ dispose(): void;
9
+ }
10
+ /**
11
+ * Simplified MessageConnection interface
12
+ * https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L506-L591
13
+ */
14
+ export interface MessageConnection extends Disposable {
15
+ /** Send a JSON-RPC request and wait for the response */
16
+ sendRequest<R>(method: string, params?: any[] | object): Promise<R>;
17
+ /** Send a one-way JSON-RPC notification (no response expected) */
18
+ sendNotification(method: string, params?: any[] | object): void;
19
+ /** Register a handler for server-sent notifications, returns an unsubscribe handle */
20
+ onNotification(method: string, handler: (params: any) => void): Disposable;
21
+ /** Register a listener for connection close, returns an unsubscribe handle */
22
+ onClose(listener: () => void): Disposable;
23
+ /** Reject all pending requests and stop listening */
24
+ dispose(): void;
25
+ }
26
+ export declare class JsonRpcClient implements MessageConnection {
27
+ private reader;
28
+ private writer;
29
+ private sequenceNumber;
30
+ private responsePromises;
31
+ private notificationHandlers;
32
+ private chunks;
33
+ private chunksLength;
34
+ private contentLength;
35
+ private disposed;
36
+ private closeHandlers;
37
+ constructor(reader: Readable, writer: Writable);
38
+ static connectTcp(host: string, port: number): Promise<JsonRpcClient>;
39
+ static connectStdio(stdin: Readable, stdout: Writable): JsonRpcClient;
40
+ dispose(): void;
41
+ onClose(listener: () => void): Disposable;
42
+ sendRequest<R>(method: string, params?: any[] | object): Promise<R>;
43
+ sendNotification(method: string, params?: any[] | object): void;
44
+ onNotification(method: string, handler: (params: any) => void): Disposable;
45
+ private onData;
46
+ private handleResponse;
47
+ private handleNotification;
48
+ private rejectAllPending;
49
+ private handleStreamClose;
50
+ private writeMessage;
51
+ private compact;
52
+ private consume;
53
+ }
54
+ export {};
@@ -0,0 +1,209 @@
1
+ /**
2
+ * JSON-RPC 2.0 client with Content-Length framing
3
+ * Simplified from vscode-jsonrpc (MIT, Microsoft Corporation)
4
+ * Ref: https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L506-L591
5
+ */
6
+ import { createConnection } from 'node:net';
7
+ import { Message as MessageGuards, ErrorCodes, ResponseError } from './types.js';
8
+ const HEADER_SEPARATOR = Buffer.from('\r\n\r\n', 'ascii');
9
+ const HEADER_SEPARATOR_LENGTH = 4; // \r\n\r\n
10
+ export class JsonRpcClient {
11
+ // Transport
12
+ reader;
13
+ writer;
14
+ // Request/response matching
15
+ sequenceNumber = 1;
16
+ responsePromises = new Map();
17
+ notificationHandlers = new Map();
18
+ // Inbound buffer, raw chunks to avoid corrupting multi-byte UTF-8
19
+ chunks = [];
20
+ chunksLength = 0;
21
+ contentLength = -1; // -1 = waiting for header
22
+ // Lifecycle
23
+ disposed = false;
24
+ closeHandlers = [];
25
+ constructor(reader, writer) {
26
+ this.reader = reader;
27
+ this.writer = writer;
28
+ this.reader.on('data', (chunk) => this.onData(chunk));
29
+ this.reader.on('end', () => this.handleStreamClose());
30
+ this.reader.on('close', () => this.handleStreamClose());
31
+ }
32
+ static connectTcp(host, port) {
33
+ return new Promise((resolve, reject) => {
34
+ const socket = createConnection({ host, port }, () => {
35
+ resolve(new JsonRpcClient(socket, socket));
36
+ });
37
+ socket.on('error', reject);
38
+ });
39
+ }
40
+ static connectStdio(stdin, stdout) {
41
+ return new JsonRpcClient(stdin, stdout);
42
+ }
43
+ // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L1563-L1590
44
+ dispose() {
45
+ if (this.disposed)
46
+ return;
47
+ this.disposed = true;
48
+ this.rejectAllPending('Connection disposed');
49
+ // Close the streams so the server detects the disconnect
50
+ this.reader.destroy();
51
+ this.writer.destroy();
52
+ }
53
+ // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L565
54
+ onClose(listener) {
55
+ this.closeHandlers.push(listener);
56
+ return {
57
+ dispose: () => {
58
+ const index = this.closeHandlers.indexOf(listener);
59
+ if (index >= 0)
60
+ this.closeHandlers.splice(index, 1);
61
+ },
62
+ };
63
+ }
64
+ // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L537
65
+ sendRequest(method, params) {
66
+ const id = this.sequenceNumber++;
67
+ const message = { jsonrpc: '2.0', id, method, params };
68
+ return new Promise((resolve, reject) => {
69
+ this.responsePromises.set(id, { resolve: resolve, reject });
70
+ this.writeMessage(message);
71
+ });
72
+ }
73
+ // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L549
74
+ sendNotification(method, params) {
75
+ const message = { jsonrpc: '2.0', method, params };
76
+ this.writeMessage(message);
77
+ }
78
+ // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L557
79
+ onNotification(method, handler) {
80
+ const handlers = this.notificationHandlers.get(method) ?? [];
81
+ handlers.push(handler);
82
+ this.notificationHandlers.set(method, handlers);
83
+ return {
84
+ dispose: () => {
85
+ const list = this.notificationHandlers.get(method);
86
+ if (list) {
87
+ const idx = list.indexOf(handler);
88
+ if (idx !== -1)
89
+ list.splice(idx, 1);
90
+ }
91
+ },
92
+ };
93
+ }
94
+ // Accumulate chunk and parse as many complete messages as possible
95
+ // A single chunk can contain multiple messages
96
+ // Ref: vscode-jsonrpc ReadableStreamMessageReader.nextMessage
97
+ onData(chunk) {
98
+ this.chunks.push(chunk);
99
+ this.chunksLength += chunk.length;
100
+ while (true) {
101
+ if (this.contentLength < 0) {
102
+ const buffer = this.compact();
103
+ const separatorIndex = buffer.indexOf(HEADER_SEPARATOR);
104
+ if (separatorIndex < 0)
105
+ return;
106
+ const header = buffer.subarray(0, separatorIndex).toString('ascii');
107
+ const match = header.match(/Content-Length:\s*(\d+)/i);
108
+ if (!match) {
109
+ this.consume(separatorIndex + HEADER_SEPARATOR_LENGTH);
110
+ continue;
111
+ }
112
+ this.contentLength = Number(match[1]);
113
+ this.consume(separatorIndex + HEADER_SEPARATOR_LENGTH);
114
+ }
115
+ if (this.chunksLength < this.contentLength)
116
+ return;
117
+ const buffer = this.compact();
118
+ const body = buffer.subarray(0, this.contentLength).toString('utf-8');
119
+ this.consume(this.contentLength);
120
+ this.contentLength = -1;
121
+ try {
122
+ const message = JSON.parse(body);
123
+ if (MessageGuards.isResponse(message)) {
124
+ this.handleResponse(message);
125
+ }
126
+ else if (MessageGuards.isNotification(message)) {
127
+ this.handleNotification(message);
128
+ }
129
+ }
130
+ catch (error) {
131
+ console.error('[jsonrpc] Failed to parse message:', error);
132
+ }
133
+ }
134
+ }
135
+ // Ref: vscode-jsonrpc connection.ts
136
+ handleResponse(response) {
137
+ if (typeof response.id !== 'number')
138
+ return;
139
+ const pending = this.responsePromises.get(response.id);
140
+ if (!pending)
141
+ return;
142
+ this.responsePromises.delete(response.id);
143
+ if (response.error) {
144
+ pending.reject(new ResponseError(response.error.code, response.error.message, response.error.data));
145
+ }
146
+ else if (response.result !== undefined) {
147
+ pending.resolve(response.result);
148
+ }
149
+ }
150
+ handleNotification(notification) {
151
+ const handlers = this.notificationHandlers.get(notification.method);
152
+ if (!handlers?.length)
153
+ return;
154
+ for (const handler of handlers) {
155
+ try {
156
+ handler(notification.params);
157
+ }
158
+ catch (error) {
159
+ console.error(`[jsonrpc] Notification handler for '${notification.method}' threw:`, error);
160
+ }
161
+ }
162
+ }
163
+ // Cleanup
164
+ rejectAllPending(reason) {
165
+ for (const [, pending] of this.responsePromises) {
166
+ pending.reject(new ResponseError(ErrorCodes.PendingResponseRejected, reason));
167
+ }
168
+ this.responsePromises.clear();
169
+ }
170
+ // Fires once on stream end/close
171
+ handleStreamClose() {
172
+ if (this.disposed)
173
+ return;
174
+ this.disposed = true;
175
+ this.rejectAllPending('Server disconnected');
176
+ for (const handler of this.closeHandlers) {
177
+ handler();
178
+ }
179
+ }
180
+ /* Helpers */
181
+ // Single buffer write to prevent interleaving under concurrent requests
182
+ writeMessage(message) {
183
+ const body = Buffer.from(JSON.stringify(message), 'utf-8');
184
+ const header = Buffer.from(`Content-Length: ${body.length}\r\n\r\n`, 'ascii');
185
+ this.writer.write(Buffer.concat([header, body]));
186
+ }
187
+ // Concat all chunks into 1 buffer
188
+ compact() {
189
+ if (this.chunks.length === 1)
190
+ return this.chunks[0];
191
+ const buffer = Buffer.concat(this.chunks);
192
+ this.chunks = [buffer];
193
+ this.chunksLength = buffer.length;
194
+ return buffer;
195
+ }
196
+ // Consume n bytes from buffer
197
+ consume(bytes) {
198
+ const buffer = this.compact();
199
+ const remaining = buffer.subarray(bytes);
200
+ if (remaining.length > 0) {
201
+ this.chunks = [remaining];
202
+ this.chunksLength = remaining.length;
203
+ }
204
+ else {
205
+ this.chunks = [];
206
+ this.chunksLength = 0;
207
+ }
208
+ }
209
+ }
@@ -0,0 +1,2 @@
1
+ export { JsonRpcClient, type MessageConnection } from './client.js';
2
+ export { type RequestMessage, type ResponseMessage, type NotificationMessage, type ResponseErrorLiteral, Message, ErrorCodes, ResponseError, } from './types.js';
@@ -0,0 +1,2 @@
1
+ export { JsonRpcClient } from './client.js';
2
+ export { Message, ErrorCodes, ResponseError, } from './types.js';
@@ -0,0 +1,53 @@
1
+ /**
2
+ * JSON-RPC 2.0 message types and error codes
3
+ * Copied from vscode-jsonrpc (MIT, Microsoft Corporation)
4
+ * Ref: https://github.com/microsoft/vscode-languageserver-node/tree/main/jsonrpc/src/common/messages
5
+ */
6
+ export interface Message {
7
+ jsonrpc: string;
8
+ }
9
+ export interface RequestMessage extends Message {
10
+ id: number | string | null;
11
+ method: string;
12
+ params?: any[] | object;
13
+ }
14
+ export interface ResponseMessage extends Message {
15
+ id: number | string | null;
16
+ result?: string | number | boolean | object | any[] | null;
17
+ error?: ResponseErrorLiteral<any>;
18
+ }
19
+ export interface NotificationMessage extends Message {
20
+ method: string;
21
+ params?: any[] | object;
22
+ }
23
+ export interface ResponseErrorLiteral<D = void> {
24
+ code: number;
25
+ message: string;
26
+ data?: D;
27
+ }
28
+ export declare namespace Message {
29
+ function isRequest(message: Message | undefined): message is RequestMessage;
30
+ function isNotification(message: Message | undefined): message is NotificationMessage;
31
+ function isResponse(message: Message | undefined): message is ResponseMessage;
32
+ }
33
+ export declare namespace ErrorCodes {
34
+ const ParseError: -32700;
35
+ const InvalidRequest: -32600;
36
+ const MethodNotFound: -32601;
37
+ const InvalidParams: -32602;
38
+ const InternalError: -32603;
39
+ const jsonrpcReservedErrorRangeStart: -32099;
40
+ const MessageWriteError: -32099;
41
+ const MessageReadError: -32098;
42
+ const PendingResponseRejected: -32097;
43
+ const ConnectionInactive: -32096;
44
+ const ServerNotInitialized: -32002;
45
+ const UnknownErrorCode: -32001;
46
+ const jsonrpcReservedErrorRangeEnd: -32000;
47
+ }
48
+ export declare class ResponseError<D = void> extends Error {
49
+ readonly code: number;
50
+ readonly data: D | undefined;
51
+ constructor(code: number, message: string, data?: D);
52
+ toJson(): ResponseErrorLiteral<D>;
53
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * JSON-RPC 2.0 message types and error codes
3
+ * Copied from vscode-jsonrpc (MIT, Microsoft Corporation)
4
+ * Ref: https://github.com/microsoft/vscode-languageserver-node/tree/main/jsonrpc/src/common/messages
5
+ */
6
+ // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/messages.ts#L298-L323
7
+ export var Message;
8
+ (function (Message) {
9
+ function isRequest(message) {
10
+ const candidate = message;
11
+ return candidate !== undefined && typeof candidate.method === 'string'
12
+ && (typeof candidate.id === 'string' || typeof candidate.id === 'number');
13
+ }
14
+ Message.isRequest = isRequest;
15
+ function isNotification(message) {
16
+ const candidate = message;
17
+ return candidate !== undefined && typeof candidate.method === 'string'
18
+ && candidate.id === undefined;
19
+ }
20
+ Message.isNotification = isNotification;
21
+ function isResponse(message) {
22
+ const candidate = message;
23
+ return candidate !== undefined
24
+ && (candidate.result !== undefined || !!candidate.error)
25
+ && (typeof candidate.id === 'string' || typeof candidate.id === 'number' || candidate.id === null);
26
+ }
27
+ Message.isResponse = isResponse;
28
+ })(Message || (Message = {}));
29
+ // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/messages.ts#L32-L83
30
+ export var ErrorCodes;
31
+ (function (ErrorCodes) {
32
+ ErrorCodes.ParseError = -32700;
33
+ ErrorCodes.InvalidRequest = -32600;
34
+ ErrorCodes.MethodNotFound = -32601;
35
+ ErrorCodes.InvalidParams = -32602;
36
+ ErrorCodes.InternalError = -32603;
37
+ // JSON-RPC reserved error range (-32099 to -32000)
38
+ ErrorCodes.jsonrpcReservedErrorRangeStart = -32099;
39
+ ErrorCodes.MessageWriteError = -32099;
40
+ ErrorCodes.MessageReadError = -32098;
41
+ ErrorCodes.PendingResponseRejected = -32097;
42
+ ErrorCodes.ConnectionInactive = -32096;
43
+ ErrorCodes.ServerNotInitialized = -32002;
44
+ ErrorCodes.UnknownErrorCode = -32001;
45
+ ErrorCodes.jsonrpcReservedErrorRangeEnd = -32000;
46
+ })(ErrorCodes || (ErrorCodes = {}));
47
+ // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/messages.ts#L128-L148
48
+ export class ResponseError extends Error {
49
+ code;
50
+ data;
51
+ constructor(code, message, data) {
52
+ super(message);
53
+ this.code = typeof code === 'number' ? code : ErrorCodes.UnknownErrorCode;
54
+ this.data = data;
55
+ Object.setPrototypeOf(this, ResponseError.prototype);
56
+ }
57
+ toJson() {
58
+ const result = {
59
+ code: this.code,
60
+ message: this.message,
61
+ };
62
+ if (this.data !== undefined) {
63
+ result.data = this.data;
64
+ }
65
+ return result;
66
+ }
67
+ }
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Typedown RPC client
3
+ *
4
+ * Thin wrapper over JsonRpcClient that provides typed methods
5
+ * matching the Rust RPC server's contract (rpc/contract.rs)
6
+ *
7
+ * The server (typedown-rpc binary) sends notifications for FS changes;
8
+ * register handlers via onContentChanged/onSchemaChanged/onConfigChanged
9
+ */
10
+ import type { Readable, Writable } from 'node:stream';
11
+ export { JsonRpcClient, Message, ResponseError, ErrorCodes } from './core/index.js';
12
+ export type { RequestMessage, ResponseMessage, NotificationMessage, ResponseErrorLiteral } from './core/index.js';
13
+ export interface TdDiagnosticItem {
14
+ filepath: string;
15
+ line: number;
16
+ column: number;
17
+ severity: string;
18
+ code: string;
19
+ message: string;
20
+ }
21
+ export interface TdContentNotification {
22
+ filepath: string;
23
+ affectedFiles?: string[];
24
+ }
25
+ export interface TdFileMetadata {
26
+ mtime: number;
27
+ ctime: number;
28
+ }
29
+ export interface TdHeading {
30
+ level: number;
31
+ title: string;
32
+ titleHtml: string;
33
+ slug: string;
34
+ }
35
+ export interface TdSidebarItem {
36
+ filepath: string;
37
+ schema?: string;
38
+ schemaLabel?: string;
39
+ label?: string;
40
+ icon?: TdIcon;
41
+ excerpt?: string;
42
+ metadata: TdFileMetadata;
43
+ }
44
+ export interface TdContentSummary {
45
+ filepath: string;
46
+ schema?: string;
47
+ schemaLabel?: string;
48
+ label?: string;
49
+ icon?: TdIcon;
50
+ header: Record<string, any>;
51
+ excerpt?: string;
52
+ metadata: TdFileMetadata;
53
+ }
54
+ export interface TdNavItem {
55
+ title: string;
56
+ link: string;
57
+ icon?: string;
58
+ }
59
+ export interface TdIcon {
60
+ name: string;
61
+ }
62
+ export interface TdDiagnosticReport {
63
+ diagnostics: TdDiagnosticItem[];
64
+ fileCount: number;
65
+ errorCount: number;
66
+ warningCount: number;
67
+ }
68
+ export interface TdFormatResult {
69
+ content: string;
70
+ changed: boolean;
71
+ }
72
+ export interface TdSchemaNotification {
73
+ schema: string;
74
+ }
75
+ export interface TdSchemaInfo {
76
+ schema: string;
77
+ label: string;
78
+ properties: Record<string, any>;
79
+ }
80
+ export interface TdSiteConfig {
81
+ version: string;
82
+ basePath: string;
83
+ origin: string | undefined;
84
+ lang: string;
85
+ rootDir: string;
86
+ siteTitle: string;
87
+ siteDescription: string;
88
+ repo: string | undefined;
89
+ author: string | undefined;
90
+ license: string | undefined;
91
+ publicDir: string;
92
+ nav: TdNavItem[];
93
+ }
94
+ export interface TdPageMeta {
95
+ title?: string;
96
+ description?: string;
97
+ image?: string;
98
+ }
99
+ export interface TdBuiltResource {
100
+ schema?: string;
101
+ schemaLabel?: string;
102
+ label?: string;
103
+ icon?: TdIcon;
104
+ header: Record<string, any>;
105
+ content: string;
106
+ headings: TdHeading[];
107
+ title?: string;
108
+ metadata: TdFileMetadata;
109
+ meta?: TdPageMeta;
110
+ }
111
+ export declare const RPC_CANCELLED_CODE = -32002;
112
+ /**
113
+ * Typed RPC client for the Typedown build server
114
+ *
115
+ * Wraps a generic JsonRpcClient with typed request methods
116
+ * and notification handlers matching the Rust RPC contract
117
+ */
118
+ export declare class RpcClient {
119
+ private rpc;
120
+ private constructor();
121
+ static connectTcp(host: string, port: number): Promise<RpcClient>;
122
+ static connectStdio(stdin: Readable, stdout: Writable): RpcClient;
123
+ /** Send exit notification and close the connection
124
+ * The detached server will detect the disconnect and save its cache */
125
+ dispose(): void;
126
+ onClose(callback: () => void): {
127
+ dispose: () => void;
128
+ };
129
+ requestFile(path: string): Promise<TdBuiltResource>;
130
+ requestFiles(paths: string[]): Promise<TdBuiltResource[]>;
131
+ listVault(): Promise<string[]>;
132
+ listFilesGroupedBySchema(): Promise<Record<string, TdContentSummary[]>>;
133
+ listSidebar(): Promise<TdSidebarItem[]>;
134
+ listSchemas(): Promise<string[]>;
135
+ getSchema(schema: string): Promise<TdSchemaInfo>;
136
+ getVersion(): Promise<string>;
137
+ getConfig(): Promise<TdSiteConfig>;
138
+ checkVault(): Promise<TdDiagnosticReport>;
139
+ formatFile(path: string): Promise<TdFormatResult>;
140
+ onContentUpdated(callback: (notification: TdContentNotification) => void): void;
141
+ onContentDeleted(callback: (notification: TdContentNotification) => void): void;
142
+ onSchemaUpdated(callback: (notification: TdSchemaNotification) => void): void;
143
+ onSchemaDeleted(callback: (notification: TdSchemaNotification) => void): void;
144
+ onConfigChanged(callback: (config: TdSiteConfig) => void): void;
145
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@typerighter/rpc-client",
4
- "version": "0.40.0",
4
+ "version": "0.40.2",
5
5
  "description": "JSON-RPC client for Typedown over TCP/stdio.",
6
6
  "repository": {
7
7
  "type": "git",
@@ -9,6 +9,9 @@
9
9
  "directory": "packages/rpc-client"
10
10
  },
11
11
  "type": "module",
12
+ "files": [
13
+ "dist"
14
+ ],
12
15
  "main": "./dist/index.js",
13
16
  "types": "./dist/index.d.ts",
14
17
  "exports": {
package/.gitignore DELETED
@@ -1 +0,0 @@
1
- dist/
@@ -1,273 +0,0 @@
1
- /**
2
- * JSON-RPC 2.0 client with Content-Length framing
3
- * Simplified from vscode-jsonrpc (MIT, Microsoft Corporation)
4
- * Ref: https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L506-L591
5
- */
6
-
7
- import { createConnection } from 'node:net';
8
- import type { Readable, Writable } from 'node:stream';
9
- import type { Message, RequestMessage, NotificationMessage, ResponseMessage } from './types.js';
10
- import { Message as MessageGuards, ErrorCodes, ResponseError } from './types.js';
11
-
12
- type PendingRequest = {
13
- resolve: (value: unknown) => void;
14
- reject: (error: ResponseError) => void;
15
- };
16
-
17
- // A Disposable interface to undo a previous side-effectful step
18
- interface Disposable {
19
- dispose (): void;
20
- }
21
-
22
- const HEADER_SEPARATOR = Buffer.from('\r\n\r\n', 'ascii');
23
- const HEADER_SEPARATOR_LENGTH = 4; // \r\n\r\n
24
-
25
- /**
26
- * Simplified MessageConnection interface
27
- * https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L506-L591
28
- */
29
- export interface MessageConnection extends Disposable {
30
- /** Send a JSON-RPC request and wait for the response */
31
- sendRequest<R> (method: string, params?: any[] | object): Promise<R>;
32
- /** Send a one-way JSON-RPC notification (no response expected) */
33
- sendNotification (method: string, params?: any[] | object): void;
34
- /** Register a handler for server-sent notifications, returns an unsubscribe handle */
35
- onNotification (method: string, handler: (params: any) => void): Disposable;
36
- /** Register a listener for connection close, returns an unsubscribe handle */
37
- onClose (listener: () => void): Disposable;
38
- /** Reject all pending requests and stop listening */
39
- dispose (): void;
40
- }
41
-
42
- export class JsonRpcClient implements MessageConnection {
43
- // Transport
44
- private reader: Readable;
45
- private writer: Writable;
46
-
47
- // Request/response matching
48
- private sequenceNumber = 1;
49
- private responsePromises = new Map<number, PendingRequest>();
50
- private notificationHandlers = new Map<string, Array<(params: unknown) => void>>();
51
-
52
- // Inbound buffer, raw chunks to avoid corrupting multi-byte UTF-8
53
- private chunks: Buffer[] = [];
54
- private chunksLength = 0;
55
- private contentLength = -1; // -1 = waiting for header
56
-
57
- // Lifecycle
58
- private disposed = false;
59
- private closeHandlers: Array<() => void> = [];
60
-
61
- constructor (reader: Readable, writer: Writable) {
62
- this.reader = reader;
63
- this.writer = writer;
64
-
65
- this.reader.on('data', (chunk: Buffer) => this.onData(chunk));
66
- this.reader.on('end', () => this.handleStreamClose());
67
- this.reader.on('close', () => this.handleStreamClose());
68
- }
69
-
70
- static connectTcp (host: string, port: number): Promise<JsonRpcClient> {
71
- return new Promise((resolve, reject) => {
72
- const socket = createConnection({ host, port }, () => {
73
- resolve(new JsonRpcClient(socket, socket));
74
- });
75
- socket.on('error', reject);
76
- });
77
- }
78
-
79
- static connectStdio (stdin: Readable, stdout: Writable): JsonRpcClient {
80
- return new JsonRpcClient(stdin, stdout);
81
- }
82
-
83
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L1563-L1590
84
- dispose (): void {
85
- if (this.disposed) return;
86
- this.disposed = true;
87
-
88
- this.rejectAllPending('Connection disposed');
89
- // Close the streams so the server detects the disconnect
90
- this.reader.destroy();
91
- this.writer.destroy();
92
- }
93
-
94
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L565
95
- onClose (listener: () => void): Disposable {
96
- this.closeHandlers.push(listener);
97
- return {
98
- dispose: () => {
99
- const index = this.closeHandlers.indexOf(listener);
100
- if (index >= 0) this.closeHandlers.splice(index, 1);
101
- },
102
- };
103
- }
104
-
105
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L537
106
- sendRequest<R> (method: string, params?: any[] | object): Promise<R> {
107
- const id = this.sequenceNumber++;
108
- const message: RequestMessage = { jsonrpc: '2.0', id, method, params };
109
-
110
- return new Promise<R>((resolve, reject) => {
111
- this.responsePromises.set(id, { resolve: resolve as (v: unknown) => void, reject });
112
- this.writeMessage(message);
113
- });
114
- }
115
-
116
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L549
117
- sendNotification (method: string, params?: any[] | object): void {
118
- const message: NotificationMessage = { jsonrpc: '2.0', method, params };
119
- this.writeMessage(message);
120
- }
121
-
122
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L557
123
- onNotification (method: string, handler: (params: any) => void): Disposable {
124
- const handlers = this.notificationHandlers.get(method) ?? [];
125
- handlers.push(handler);
126
- this.notificationHandlers.set(method, handlers);
127
- return {
128
- dispose: () => {
129
- const list = this.notificationHandlers.get(method);
130
- if (list) {
131
- const idx = list.indexOf(handler);
132
- if (idx !== -1) list.splice(idx, 1);
133
- }
134
- },
135
- };
136
- }
137
-
138
- // Accumulate chunk and parse as many complete messages as possible
139
- // A single chunk can contain multiple messages
140
- // Ref: vscode-jsonrpc ReadableStreamMessageReader.nextMessage
141
- private onData (chunk: Buffer): void {
142
- this.chunks.push(chunk);
143
- this.chunksLength += chunk.length;
144
-
145
- while (true) {
146
- if (this.contentLength < 0) {
147
- const buffer = this.compact();
148
- const separatorIndex = buffer.indexOf(HEADER_SEPARATOR);
149
-
150
- if (separatorIndex < 0) return;
151
-
152
- const header = buffer.subarray(0, separatorIndex).toString('ascii');
153
- const match = header.match(/Content-Length:\s*(\d+)/i);
154
-
155
- if (!match) {
156
- this.consume(separatorIndex + HEADER_SEPARATOR_LENGTH);
157
- continue;
158
- }
159
-
160
- this.contentLength = Number(match[1]);
161
- this.consume(separatorIndex + HEADER_SEPARATOR_LENGTH);
162
- }
163
-
164
- if (this.chunksLength < this.contentLength) return;
165
-
166
- const buffer = this.compact();
167
- const body = buffer.subarray(0, this.contentLength).toString('utf-8');
168
-
169
- this.consume(this.contentLength);
170
- this.contentLength = -1;
171
-
172
- try {
173
- const message = JSON.parse(body);
174
-
175
- if (MessageGuards.isResponse(message)) {
176
- this.handleResponse(message);
177
- } else if (MessageGuards.isNotification(message)) {
178
- this.handleNotification(message);
179
- }
180
- } catch (error) {
181
- console.error('[jsonrpc] Failed to parse message:', error);
182
- }
183
- }
184
- }
185
-
186
- // Ref: vscode-jsonrpc connection.ts
187
-
188
- private handleResponse (response: ResponseMessage): void {
189
- if (typeof response.id !== 'number') return;
190
-
191
- const pending = this.responsePromises.get(response.id);
192
-
193
- if (!pending) return;
194
- this.responsePromises.delete(response.id);
195
-
196
- if (response.error) {
197
- pending.reject(new ResponseError(response.error.code, response.error.message, response.error.data));
198
- } else if (response.result !== undefined) {
199
- pending.resolve(response.result);
200
- }
201
- }
202
-
203
- private handleNotification (notification: NotificationMessage): void {
204
- const handlers = this.notificationHandlers.get(notification.method);
205
-
206
- if (!handlers?.length) return;
207
-
208
- for (const handler of handlers) {
209
- try {
210
- handler(notification.params);
211
- } catch (error) {
212
- console.error(`[jsonrpc] Notification handler for '${notification.method}' threw:`, error);
213
- }
214
- }
215
- }
216
-
217
- // Cleanup
218
-
219
- private rejectAllPending (reason: string): void {
220
- for (const [, pending] of this.responsePromises) {
221
- pending.reject(new ResponseError(ErrorCodes.PendingResponseRejected, reason));
222
- }
223
- this.responsePromises.clear();
224
- }
225
-
226
- // Fires once on stream end/close
227
- private handleStreamClose (): void {
228
- if (this.disposed) return;
229
- this.disposed = true;
230
-
231
- this.rejectAllPending('Server disconnected');
232
-
233
- for (const handler of this.closeHandlers) {
234
- handler();
235
- }
236
- }
237
-
238
- /* Helpers */
239
-
240
- // Single buffer write to prevent interleaving under concurrent requests
241
- private writeMessage (message: Message): void {
242
- const body = Buffer.from(JSON.stringify(message), 'utf-8');
243
- const header = Buffer.from(`Content-Length: ${body.length}\r\n\r\n`, 'ascii');
244
-
245
- this.writer.write(Buffer.concat([header, body]));
246
- }
247
-
248
- // Concat all chunks into 1 buffer
249
- private compact (): Buffer {
250
- if (this.chunks.length === 1) return this.chunks[0];
251
-
252
- const buffer = Buffer.concat(this.chunks);
253
-
254
- this.chunks = [buffer];
255
- this.chunksLength = buffer.length;
256
-
257
- return buffer;
258
- }
259
-
260
- // Consume n bytes from buffer
261
- private consume (bytes: number): void {
262
- const buffer = this.compact();
263
- const remaining = buffer.subarray(bytes);
264
-
265
- if (remaining.length > 0) {
266
- this.chunks = [remaining];
267
- this.chunksLength = remaining.length;
268
- } else {
269
- this.chunks = [];
270
- this.chunksLength = 0;
271
- }
272
- }
273
- }
package/src/core/index.ts DELETED
@@ -1,10 +0,0 @@
1
- export { JsonRpcClient, type MessageConnection } from './client.js';
2
- export {
3
- type RequestMessage,
4
- type ResponseMessage,
5
- type NotificationMessage,
6
- type ResponseErrorLiteral,
7
- Message,
8
- ErrorCodes,
9
- ResponseError,
10
- } from './types.js';
package/src/core/types.ts DELETED
@@ -1,104 +0,0 @@
1
- /**
2
- * JSON-RPC 2.0 message types and error codes
3
- * Copied from vscode-jsonrpc (MIT, Microsoft Corporation)
4
- * Ref: https://github.com/microsoft/vscode-languageserver-node/tree/main/jsonrpc/src/common/messages
5
- */
6
-
7
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/messages.ts#L11
8
- export interface Message {
9
- jsonrpc: string;
10
- }
11
-
12
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/messages.ts#L18
13
- export interface RequestMessage extends Message {
14
- id: number | string | null;
15
- method: string;
16
- params?: any[] | object;
17
- }
18
-
19
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/messages.ts#L150-L165
20
- export interface ResponseMessage extends Message {
21
- id: number | string | null;
22
- result?: string | number | boolean | object | any[] | null;
23
- error?: ResponseErrorLiteral<any>;
24
- }
25
-
26
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/messages.ts#L283-L292
27
- export interface NotificationMessage extends Message {
28
- method: string;
29
- params?: any[] | object;
30
- }
31
-
32
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/messages.ts#L105-L122
33
- export interface ResponseErrorLiteral<D = void> {
34
- code: number;
35
- message: string;
36
- data?: D;
37
- }
38
-
39
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/messages.ts#L298-L323
40
- export namespace Message {
41
- export function isRequest (message: Message | undefined): message is RequestMessage {
42
- const candidate = message as RequestMessage;
43
- return candidate !== undefined && typeof candidate.method === 'string'
44
- && (typeof candidate.id === 'string' || typeof candidate.id === 'number');
45
- }
46
-
47
- export function isNotification (message: Message | undefined): message is NotificationMessage {
48
- const candidate = message as NotificationMessage;
49
- return candidate !== undefined && typeof candidate.method === 'string'
50
- && (candidate as any).id === undefined;
51
- }
52
-
53
- export function isResponse (message: Message | undefined): message is ResponseMessage {
54
- const candidate = message as ResponseMessage;
55
- return candidate !== undefined
56
- && (candidate.result !== undefined || !!candidate.error)
57
- && (typeof candidate.id === 'string' || typeof candidate.id === 'number' || candidate.id === null);
58
- }
59
- }
60
-
61
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/messages.ts#L32-L83
62
- export namespace ErrorCodes {
63
- export const ParseError: -32700 = -32700;
64
- export const InvalidRequest: -32600 = -32600;
65
- export const MethodNotFound: -32601 = -32601;
66
- export const InvalidParams: -32602 = -32602;
67
- export const InternalError: -32603 = -32603;
68
-
69
- // JSON-RPC reserved error range (-32099 to -32000)
70
- export const jsonrpcReservedErrorRangeStart: -32099 = -32099;
71
- export const MessageWriteError: -32099 = -32099;
72
- export const MessageReadError: -32098 = -32098;
73
- export const PendingResponseRejected: -32097 = -32097;
74
- export const ConnectionInactive: -32096 = -32096;
75
- export const ServerNotInitialized: -32002 = -32002;
76
- export const UnknownErrorCode: -32001 = -32001;
77
- export const jsonrpcReservedErrorRangeEnd: -32000 = -32000;
78
- }
79
-
80
- // https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/messages.ts#L128-L148
81
- export class ResponseError<D = void> extends Error {
82
- readonly code: number;
83
- readonly data: D | undefined;
84
-
85
- constructor (code: number, message: string, data?: D) {
86
- super(message);
87
- this.code = typeof code === 'number' ? code : ErrorCodes.UnknownErrorCode;
88
- this.data = data;
89
- Object.setPrototypeOf(this, ResponseError.prototype);
90
- }
91
-
92
- toJson (): ResponseErrorLiteral<D> {
93
- const result: ResponseErrorLiteral<D> = {
94
- code: this.code,
95
- message: this.message,
96
- };
97
-
98
- if (this.data !== undefined) {
99
- result.data = this.data;
100
- }
101
-
102
- return result;
103
- }
104
- }
package/src/index.ts DELETED
@@ -1,257 +0,0 @@
1
- /**
2
- * Typedown RPC client
3
- *
4
- * Thin wrapper over JsonRpcClient that provides typed methods
5
- * matching the Rust RPC server's contract (rpc/contract.rs)
6
- *
7
- * The server (typedown-rpc binary) sends notifications for FS changes;
8
- * register handlers via onContentChanged/onSchemaChanged/onConfigChanged
9
- */
10
-
11
- import type { Readable, Writable } from 'node:stream';
12
- import { JsonRpcClient } from './core/index.js';
13
-
14
- export { JsonRpcClient, Message, ResponseError, ErrorCodes } from './core/index.js';
15
- export type { RequestMessage, ResponseMessage, NotificationMessage, ResponseErrorLiteral } from './core/index.js';
16
-
17
- /* Types contract
18
- * WARNING: must match the Rust contract in rpc/contract.rs */
19
-
20
- export interface TdDiagnosticItem {
21
- filepath: string;
22
- line: number;
23
- column: number;
24
- severity: string;
25
- code: string;
26
- message: string;
27
- }
28
-
29
- export interface TdContentNotification {
30
- filepath: string;
31
- affectedFiles?: string[];
32
- }
33
-
34
- export interface TdFileMetadata {
35
- mtime: number;
36
- ctime: number;
37
- }
38
-
39
- export interface TdHeading {
40
- level: number;
41
- title: string;
42
- titleHtml: string;
43
- slug: string;
44
- }
45
-
46
- export interface TdSidebarItem {
47
- filepath: string;
48
- schema?: string;
49
- schemaLabel?: string;
50
- label?: string;
51
- icon?: TdIcon;
52
- excerpt?: string;
53
- metadata: TdFileMetadata;
54
- }
55
-
56
- export interface TdContentSummary {
57
- filepath: string;
58
- schema?: string;
59
- schemaLabel?: string;
60
- label?: string;
61
- icon?: TdIcon;
62
- header: Record<string, any>;
63
- excerpt?: string;
64
- metadata: TdFileMetadata;
65
- }
66
-
67
- export interface TdNavItem {
68
- title: string;
69
- link: string;
70
- icon?: string;
71
- }
72
-
73
- export interface TdIcon {
74
- name: string;
75
- }
76
-
77
- export interface TdDiagnosticReport {
78
- diagnostics: TdDiagnosticItem[];
79
- fileCount: number;
80
- errorCount: number;
81
- warningCount: number;
82
- }
83
-
84
- export interface TdFormatResult {
85
- content: string;
86
- changed: boolean;
87
- }
88
-
89
- export interface TdSchemaNotification {
90
- schema: string;
91
- }
92
-
93
- export interface TdSchemaInfo {
94
- schema: string;
95
- label: string;
96
- properties: Record<string, any>;
97
- }
98
-
99
- export interface TdSiteConfig {
100
- version: string;
101
- basePath: string;
102
- origin: string | undefined;
103
- lang: string;
104
- rootDir: string;
105
- siteTitle: string;
106
- siteDescription: string;
107
- repo: string | undefined;
108
- author: string | undefined;
109
- license: string | undefined;
110
- publicDir: string;
111
- nav: TdNavItem[];
112
- }
113
-
114
- export interface TdPageMeta {
115
- title?: string;
116
- description?: string;
117
- image?: string;
118
- }
119
-
120
- export interface TdBuiltResource {
121
- schema?: string;
122
- schemaLabel?: string;
123
- label?: string;
124
- icon?: TdIcon;
125
- header: Record<string, any>;
126
- content: string;
127
- headings: TdHeading[];
128
- title?: string;
129
- metadata: TdFileMetadata;
130
- meta?: TdPageMeta;
131
- }
132
-
133
- // Server-reserved JSON-RPC error code for cancelled queries (-32000 to -32099)
134
- export const RPC_CANCELLED_CODE = -32002;
135
-
136
- /* Method names
137
- * WARNING: must match Rust contract constants in rpc/contract.rs */
138
-
139
- const METHOD_REQUEST_FILE = 'typedown_build.request_file';
140
- const METHOD_REQUEST_FILES = 'typedown_build.request_files';
141
- const METHOD_LIST_VAULT = 'typedown_build.list_vault';
142
- const METHOD_LIST_FILES_GROUPED_BY_SCHEMA = 'typedown_build.list_files_grouped_by_schema';
143
- const METHOD_LIST_SIDEBAR = 'typedown_build.list_sidebar';
144
- const METHOD_LIST_SCHEMAS = 'typedown_build.list_schemas';
145
- const METHOD_GET_SCHEMA = 'typedown_build.get_schema';
146
- const METHOD_GET_VERSION = 'typedown_build.get_version';
147
- const METHOD_GET_CONFIG = 'typedown_build.get_config';
148
- const METHOD_CHECK_VAULT = 'typedown_build.check_vault';
149
- const METHOD_FORMAT_FILE = 'typedown_build.format_file';
150
-
151
- const NOTIF_CONTENT_UPDATED = 'typedown_build.content_updated';
152
- const NOTIF_CONTENT_DELETED = 'typedown_build.content_deleted';
153
- const NOTIF_SCHEMA_UPDATED = 'typedown_build.schema_updated';
154
- const NOTIF_SCHEMA_DELETED = 'typedown_build.schema_deleted';
155
- const NOTIF_CONFIG_CHANGED = 'typedown_build.config_changed';
156
-
157
- /**
158
- * Typed RPC client for the Typedown build server
159
- *
160
- * Wraps a generic JsonRpcClient with typed request methods
161
- * and notification handlers matching the Rust RPC contract
162
- */
163
- export class RpcClient {
164
- private rpc: JsonRpcClient;
165
-
166
- private constructor (rpc: JsonRpcClient) {
167
- this.rpc = rpc;
168
- }
169
-
170
- static async connectTcp (host: string, port: number): Promise<RpcClient> {
171
- const rpc = await JsonRpcClient.connectTcp(host, port);
172
- return new RpcClient(rpc);
173
- }
174
-
175
- static connectStdio (stdin: Readable, stdout: Writable): RpcClient {
176
- return new RpcClient(JsonRpcClient.connectStdio(stdin, stdout));
177
- }
178
-
179
- /** Send exit notification and close the connection
180
- * The detached server will detect the disconnect and save its cache */
181
- dispose (): void {
182
- this.rpc.sendNotification('exit');
183
- this.rpc.dispose();
184
- }
185
-
186
- onClose (callback: () => void): { dispose: () => void } {
187
- return this.rpc.onClose(callback);
188
- }
189
-
190
- /* Request methods */
191
-
192
- requestFile (path: string): Promise<TdBuiltResource> {
193
- return this.rpc.sendRequest(METHOD_REQUEST_FILE, { filePath: path });
194
- }
195
-
196
- requestFiles (paths: string[]): Promise<TdBuiltResource[]> {
197
- return this.rpc.sendRequest(METHOD_REQUEST_FILES, { filePaths: paths });
198
- }
199
-
200
- listVault (): Promise<string[]> {
201
- return this.rpc.sendRequest(METHOD_LIST_VAULT, {});
202
- }
203
-
204
- listFilesGroupedBySchema (): Promise<Record<string, TdContentSummary[]>> {
205
- return this.rpc.sendRequest(METHOD_LIST_FILES_GROUPED_BY_SCHEMA, {});
206
- }
207
-
208
- listSidebar (): Promise<TdSidebarItem[]> {
209
- return this.rpc.sendRequest(METHOD_LIST_SIDEBAR, {});
210
- }
211
-
212
- listSchemas (): Promise<string[]> {
213
- return this.rpc.sendRequest(METHOD_LIST_SCHEMAS, {});
214
- }
215
-
216
- getSchema (schema: string): Promise<TdSchemaInfo> {
217
- return this.rpc.sendRequest(METHOD_GET_SCHEMA, { schema });
218
- }
219
-
220
- getVersion (): Promise<string> {
221
- return this.rpc.sendRequest(METHOD_GET_VERSION, {});
222
- }
223
-
224
- getConfig (): Promise<TdSiteConfig> {
225
- return this.rpc.sendRequest(METHOD_GET_CONFIG, {});
226
- }
227
-
228
- checkVault (): Promise<TdDiagnosticReport> {
229
- return this.rpc.sendRequest(METHOD_CHECK_VAULT, {});
230
- }
231
-
232
- formatFile (path: string): Promise<TdFormatResult> {
233
- return this.rpc.sendRequest(METHOD_FORMAT_FILE, { filePath: path });
234
- }
235
-
236
- /* Notification handlers, server pushes these when FS changes are detected */
237
-
238
- onContentUpdated (callback: (notification: TdContentNotification) => void): void {
239
- this.rpc.onNotification(NOTIF_CONTENT_UPDATED, callback);
240
- }
241
-
242
- onContentDeleted (callback: (notification: TdContentNotification) => void): void {
243
- this.rpc.onNotification(NOTIF_CONTENT_DELETED, callback);
244
- }
245
-
246
- onSchemaUpdated (callback: (notification: TdSchemaNotification) => void): void {
247
- this.rpc.onNotification(NOTIF_SCHEMA_UPDATED, callback);
248
- }
249
-
250
- onSchemaDeleted (callback: (notification: TdSchemaNotification) => void): void {
251
- this.rpc.onNotification(NOTIF_SCHEMA_DELETED, callback);
252
- }
253
-
254
- onConfigChanged (callback: (config: TdSiteConfig) => void): void {
255
- this.rpc.onNotification(NOTIF_CONFIG_CHANGED, callback);
256
- }
257
- }
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "NodeNext",
4
- "moduleResolution": "NodeNext",
5
- "target": "ES2022",
6
- "lib": ["ES2022"],
7
- "types": ["node"],
8
- "strict": true,
9
- "skipLibCheck": true,
10
- "declaration": true,
11
- "outDir": "./dist",
12
- "rootDir": "./src"
13
- },
14
- "include": ["src"]
15
- }