@zhin.js/client 1.1.5 → 1.1.6
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/README.md +25 -19
- package/client/app.test.ts +37 -0
- package/client/app.ts +130 -138
- package/client/bootstrap/loadConsoleEntries.test.ts +0 -15
- package/client/bootstrap/loadConsoleEntries.ts +1 -20
- package/client/console-client-context.ts +24 -0
- package/client/console-client.test.ts +46 -0
- package/client/console-client.ts +70 -0
- package/client/console-events.ts +4 -3
- package/client/console-utils/remoteApi.ts +0 -7
- package/client/index.ts +21 -13
- package/client/persistence/idb-store.test.ts +0 -18
- package/client/persistence/idb-store.ts +3 -6
- package/client/{websocket/manager.test.ts → transport/console-transport.test.ts} +79 -34
- package/client/{websocket/manager.ts → transport/console-transport.ts} +237 -178
- package/client/{websocket → transport}/hooks.ts +240 -23
- package/client/transport/index.ts +23 -0
- package/client/{websocket → transport}/types.ts +11 -17
- package/client/types.ts +0 -3
- package/client/workroom/registerWorkroomConsole.test.ts +0 -1
- package/dist/app.d.ts +17 -52
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +110 -95
- package/dist/app.js.map +1 -1
- package/dist/bootstrap/loadConsoleEntries.d.ts +0 -6
- package/dist/bootstrap/loadConsoleEntries.d.ts.map +1 -1
- package/dist/bootstrap/loadConsoleEntries.js +0 -9
- package/dist/bootstrap/loadConsoleEntries.js.map +1 -1
- package/dist/console-client-context.d.ts +9 -0
- package/dist/console-client-context.d.ts.map +1 -0
- package/dist/console-client-context.js +13 -0
- package/dist/console-client-context.js.map +1 -0
- package/dist/console-client.d.ts +25 -0
- package/dist/console-client.d.ts.map +1 -0
- package/dist/console-client.js +45 -0
- package/dist/console-client.js.map +1 -0
- package/dist/console-events.d.ts +1 -0
- package/dist/console-events.d.ts.map +1 -1
- package/dist/console-events.js +3 -3
- package/dist/console-events.js.map +1 -1
- package/dist/console-utils/remoteApi.d.ts +0 -1
- package/dist/console-utils/remoteApi.d.ts.map +1 -1
- package/dist/console-utils/remoteApi.js +0 -6
- package/dist/console-utils/remoteApi.js.map +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -8
- package/dist/index.js.map +1 -1
- package/dist/persistence/idb-store.d.ts.map +1 -1
- package/dist/persistence/idb-store.js +3 -5
- package/dist/persistence/idb-store.js.map +1 -1
- package/dist/transport/console-transport.d.ts +217 -0
- package/dist/transport/console-transport.d.ts.map +1 -0
- package/dist/{websocket/manager.js → transport/console-transport.js} +147 -165
- package/dist/transport/console-transport.js.map +1 -0
- package/dist/transport/hooks.d.ts +253 -0
- package/dist/transport/hooks.d.ts.map +1 -0
- package/dist/{websocket → transport}/hooks.js +234 -19
- package/dist/transport/hooks.js.map +1 -0
- package/dist/transport/index.d.ts +4 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +4 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/{websocket → transport}/types.d.ts +10 -13
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/{websocket → transport}/types.js +4 -9
- package/dist/transport/types.js.map +1 -0
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/client/runtime/index.ts +0 -12
- package/client/websocket/index.ts +0 -11
- package/client/websocket/instance.ts +0 -24
- package/client/websocket/remote-settings.ts +0 -47
- package/dist/runtime/index.d.ts +0 -6
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/index.js +0 -10
- package/dist/runtime/index.js.map +0 -1
- package/dist/websocket/hooks.d.ts +0 -114
- package/dist/websocket/hooks.d.ts.map +0 -1
- package/dist/websocket/hooks.js.map +0 -1
- package/dist/websocket/index.d.ts +0 -7
- package/dist/websocket/index.d.ts.map +0 -1
- package/dist/websocket/index.js +0 -7
- package/dist/websocket/index.js.map +0 -1
- package/dist/websocket/instance.d.ts +0 -5
- package/dist/websocket/instance.d.ts.map +0 -1
- package/dist/websocket/instance.js +0 -21
- package/dist/websocket/instance.js.map +0 -1
- package/dist/websocket/manager.d.ts +0 -131
- package/dist/websocket/manager.d.ts.map +0 -1
- package/dist/websocket/manager.js.map +0 -1
- package/dist/websocket/remote-settings.d.ts +0 -5
- package/dist/websocket/remote-settings.d.ts.map +0 -1
- package/dist/websocket/remote-settings.js +0 -47
- package/dist/websocket/remote-settings.js.map +0 -1
- package/dist/websocket/types.d.ts.map +0 -1
- package/dist/websocket/types.js.map +0 -1
- /package/client/{websocket → transport}/hooks.test.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
2
|
+
import { useConsoleClient } from "../console-client-context.js";
|
|
3
|
+
import type { UseConsoleTransportOptions } from "./types.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 每次连接会话只对同一 key 自动加载一次:失败后不再零退避死循环
|
|
@@ -20,9 +20,9 @@ function useAutoLoadOnce(connected: boolean, key: unknown, ready: boolean, fire:
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export function
|
|
23
|
+
export function useConsoleTransport(options: UseConsoleTransportOptions = {}) {
|
|
24
24
|
const { autoConnect = true } = options;
|
|
25
|
-
const wsManager =
|
|
25
|
+
const wsManager = useConsoleClient().transport;
|
|
26
26
|
const [connected, setConnected] = useState(wsManager.isConnected());
|
|
27
27
|
|
|
28
28
|
useEffect(() => {
|
|
@@ -58,7 +58,7 @@ export function resolveKeyedValue<T>(
|
|
|
58
58
|
|
|
59
59
|
export function useConfig(pluginName: string, options?: { autoLoad?: boolean; autoLoadSchema?: boolean }) {
|
|
60
60
|
const { autoLoad = true, autoLoadSchema = true } = options ?? {};
|
|
61
|
-
const wsManager =
|
|
61
|
+
const wsManager = useConsoleClient().transport;
|
|
62
62
|
const [connected, setConnected] = useState(wsManager.isConnected());
|
|
63
63
|
const [configEntry, setConfigEntry] = useState<{ key: string; value: unknown } | null>(null);
|
|
64
64
|
const [schemaEntry, setSchemaEntry] = useState<{ key: string; value: unknown } | null>(null);
|
|
@@ -123,11 +123,13 @@ export function useConfig(pluginName: string, options?: { autoLoad?: boolean; au
|
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
export function
|
|
127
|
-
const wsManager =
|
|
126
|
+
export function useConfigSource() {
|
|
127
|
+
const wsManager = useConsoleClient().transport;
|
|
128
128
|
const [connected, setConnected] = useState(wsManager.isConnected());
|
|
129
|
-
const [
|
|
130
|
-
const [
|
|
129
|
+
const [source, setSource] = useState("");
|
|
130
|
+
const [format, setFormat] = useState<'yaml' | 'json'>('yaml');
|
|
131
|
+
const [revision, setRevision] = useState("");
|
|
132
|
+
const [configKeys, setConfigKeys] = useState<string[]>([]);
|
|
131
133
|
const [loading, setLoading] = useState(false);
|
|
132
134
|
const [error, setError] = useState<string | null>(null);
|
|
133
135
|
|
|
@@ -137,9 +139,11 @@ export function useConfigYaml() {
|
|
|
137
139
|
setLoading(true);
|
|
138
140
|
setError(null);
|
|
139
141
|
try {
|
|
140
|
-
const result = await wsManager.
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
const result = await wsManager.getConfigSource();
|
|
143
|
+
setSource(result.source);
|
|
144
|
+
setFormat(result.format);
|
|
145
|
+
setRevision(result.revision);
|
|
146
|
+
setConfigKeys([...result.configKeys]);
|
|
143
147
|
return result;
|
|
144
148
|
} catch (e) {
|
|
145
149
|
setError(e instanceof Error ? e.message : "Unknown error");
|
|
@@ -154,8 +158,10 @@ export function useConfigYaml() {
|
|
|
154
158
|
setLoading(true);
|
|
155
159
|
setError(null);
|
|
156
160
|
try {
|
|
157
|
-
|
|
158
|
-
|
|
161
|
+
if (!revision) throw new Error('Config source must be loaded before it can be replaced');
|
|
162
|
+
const result = await wsManager.replaceConfigSource(content, revision);
|
|
163
|
+
setSource(content);
|
|
164
|
+
setRevision(result.revision);
|
|
159
165
|
return result;
|
|
160
166
|
} catch (e) {
|
|
161
167
|
setError(e instanceof Error ? e.message : "Unknown error");
|
|
@@ -164,20 +170,231 @@ export function useConfigYaml() {
|
|
|
164
170
|
setLoading(false);
|
|
165
171
|
}
|
|
166
172
|
},
|
|
167
|
-
[wsManager],
|
|
173
|
+
[revision, wsManager],
|
|
168
174
|
);
|
|
169
175
|
|
|
170
|
-
useAutoLoadOnce(connected, "config-
|
|
176
|
+
useAutoLoadOnce(connected, "config-source", !!revision || loading, () => {
|
|
171
177
|
load().catch(() => {});
|
|
172
178
|
});
|
|
173
179
|
|
|
174
|
-
return useMemo(
|
|
180
|
+
return useMemo(
|
|
181
|
+
() => ({ source, format, revision, configKeys, loading, error, load, save }),
|
|
182
|
+
[source, format, revision, configKeys, loading, error, load, save],
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Shared Console flow for previewing and committing a plugin installation. */
|
|
187
|
+
export function usePluginInstall() {
|
|
188
|
+
const wsManager = useConsoleClient().transport;
|
|
189
|
+
const [loading, setLoading] = useState(false);
|
|
190
|
+
const [error, setError] = useState<string | null>(null);
|
|
191
|
+
const [plan, setPlan] = useState<Awaited<ReturnType<typeof wsManager.planPluginInstall>> | null>(null);
|
|
192
|
+
|
|
193
|
+
const preview = useCallback(async (packageName: string) => {
|
|
194
|
+
setLoading(true);
|
|
195
|
+
setError(null);
|
|
196
|
+
try {
|
|
197
|
+
const next = await wsManager.planPluginInstall(packageName);
|
|
198
|
+
setPlan(next);
|
|
199
|
+
return next;
|
|
200
|
+
} catch (e) {
|
|
201
|
+
setError(e instanceof Error ? e.message : 'Unknown error');
|
|
202
|
+
throw e;
|
|
203
|
+
} finally {
|
|
204
|
+
setLoading(false);
|
|
205
|
+
}
|
|
206
|
+
}, [wsManager]);
|
|
207
|
+
|
|
208
|
+
const install = useCallback(async (packageName: string, expectedRevision?: string) => {
|
|
209
|
+
setLoading(true);
|
|
210
|
+
setError(null);
|
|
211
|
+
try {
|
|
212
|
+
return await wsManager.installPlugin(packageName, expectedRevision);
|
|
213
|
+
} catch (e) {
|
|
214
|
+
setError(e instanceof Error ? e.message : 'Unknown error');
|
|
215
|
+
throw e;
|
|
216
|
+
} finally {
|
|
217
|
+
setLoading(false);
|
|
218
|
+
}
|
|
219
|
+
}, [wsManager]);
|
|
220
|
+
|
|
221
|
+
return useMemo(() => ({ plan, loading, error, preview, install }), [
|
|
222
|
+
plan, loading, error, preview, install,
|
|
223
|
+
]);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function usePluginConfigValidation(pluginName: string) {
|
|
227
|
+
const wsManager = useConsoleClient().transport;
|
|
228
|
+
const [loading, setLoading] = useState(false);
|
|
229
|
+
const [error, setError] = useState<string | null>(null);
|
|
230
|
+
const validate = useCallback(async (data: unknown) => {
|
|
231
|
+
setLoading(true);
|
|
232
|
+
setError(null);
|
|
233
|
+
try {
|
|
234
|
+
return await wsManager.validatePluginConfig(pluginName, data);
|
|
235
|
+
} catch (e) {
|
|
236
|
+
setError(e instanceof Error ? e.message : 'Unknown error');
|
|
237
|
+
throw e;
|
|
238
|
+
} finally {
|
|
239
|
+
setLoading(false);
|
|
240
|
+
}
|
|
241
|
+
}, [pluginName, wsManager]);
|
|
242
|
+
return useMemo(() => ({ loading, error, validate }), [loading, error, validate]);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function usePluginDiagnostics(pluginName: string) {
|
|
246
|
+
const wsManager = useConsoleClient().transport;
|
|
247
|
+
const [loading, setLoading] = useState(false);
|
|
248
|
+
const [error, setError] = useState<string | null>(null);
|
|
249
|
+
const diagnose = useCallback(async () => {
|
|
250
|
+
setLoading(true);
|
|
251
|
+
setError(null);
|
|
252
|
+
try {
|
|
253
|
+
return await wsManager.diagnosePlugin(pluginName);
|
|
254
|
+
} catch (e) {
|
|
255
|
+
setError(e instanceof Error ? e.message : 'Unknown error');
|
|
256
|
+
throw e;
|
|
257
|
+
} finally {
|
|
258
|
+
setLoading(false);
|
|
259
|
+
}
|
|
260
|
+
}, [pluginName, wsManager]);
|
|
261
|
+
return useMemo(() => ({ loading, error, diagnose }), [loading, error, diagnose]);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function usePluginLifecycle(instanceKey: string) {
|
|
265
|
+
const wsManager = useConsoleClient().transport;
|
|
266
|
+
const [loading, setLoading] = useState(false);
|
|
267
|
+
const [error, setError] = useState<string | null>(null);
|
|
268
|
+
const setEnabled = useCallback(async (enabled: boolean) => {
|
|
269
|
+
setLoading(true);
|
|
270
|
+
setError(null);
|
|
271
|
+
try {
|
|
272
|
+
return await wsManager.setPluginEnabled(instanceKey, enabled);
|
|
273
|
+
} catch (e) {
|
|
274
|
+
setError(e instanceof Error ? e.message : 'Unknown error');
|
|
275
|
+
throw e;
|
|
276
|
+
} finally {
|
|
277
|
+
setLoading(false);
|
|
278
|
+
}
|
|
279
|
+
}, [instanceKey, wsManager]);
|
|
280
|
+
return useMemo(() => ({ loading, error, setEnabled }), [loading, error, setEnabled]);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function usePluginUninstall() {
|
|
284
|
+
const wsManager = useConsoleClient().transport;
|
|
285
|
+
const [loading, setLoading] = useState(false);
|
|
286
|
+
const [error, setError] = useState<string | null>(null);
|
|
287
|
+
const preview = useCallback(async (packageName: string) => {
|
|
288
|
+
setLoading(true);
|
|
289
|
+
setError(null);
|
|
290
|
+
try {
|
|
291
|
+
return await wsManager.planPluginUninstall(packageName);
|
|
292
|
+
} catch (e) {
|
|
293
|
+
setError(e instanceof Error ? e.message : 'Unknown error');
|
|
294
|
+
throw e;
|
|
295
|
+
} finally {
|
|
296
|
+
setLoading(false);
|
|
297
|
+
}
|
|
298
|
+
}, [wsManager]);
|
|
299
|
+
const uninstall = useCallback(async (packageName: string, expectedRevision?: string) => {
|
|
300
|
+
setLoading(true);
|
|
301
|
+
setError(null);
|
|
302
|
+
try {
|
|
303
|
+
return await wsManager.uninstallPlugin(packageName, expectedRevision);
|
|
304
|
+
} catch (e) {
|
|
305
|
+
setError(e instanceof Error ? e.message : 'Unknown error');
|
|
306
|
+
throw e;
|
|
307
|
+
} finally {
|
|
308
|
+
setLoading(false);
|
|
309
|
+
}
|
|
310
|
+
}, [wsManager]);
|
|
311
|
+
return useMemo(() => ({ loading, error, preview, uninstall }), [
|
|
312
|
+
loading, error, preview, uninstall,
|
|
313
|
+
]);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export function usePluginUpdate() {
|
|
317
|
+
const wsManager = useConsoleClient().transport;
|
|
318
|
+
const [loading, setLoading] = useState(false);
|
|
319
|
+
const [error, setError] = useState<string | null>(null);
|
|
320
|
+
const preview = useCallback((packageName: string, targetVersion: string) => {
|
|
321
|
+
setLoading(true);
|
|
322
|
+
setError(null);
|
|
323
|
+
return wsManager.planPluginUpdate(packageName, targetVersion)
|
|
324
|
+
.catch((e) => {
|
|
325
|
+
setError(e instanceof Error ? e.message : 'Unknown error');
|
|
326
|
+
throw e;
|
|
327
|
+
})
|
|
328
|
+
.finally(() => setLoading(false));
|
|
329
|
+
}, [wsManager]);
|
|
330
|
+
const update = useCallback((packageName: string, targetVersion: string, expectedRevision?: string) => {
|
|
331
|
+
setLoading(true);
|
|
332
|
+
setError(null);
|
|
333
|
+
return wsManager.updatePlugin(packageName, targetVersion, expectedRevision)
|
|
334
|
+
.catch((e) => {
|
|
335
|
+
setError(e instanceof Error ? e.message : 'Unknown error');
|
|
336
|
+
throw e;
|
|
337
|
+
})
|
|
338
|
+
.finally(() => setLoading(false));
|
|
339
|
+
}, [wsManager]);
|
|
340
|
+
return useMemo(() => ({ loading, error, preview, update }), [loading, error, preview, update]);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function useEndpointTest(adapter: string, endpointKey: string) {
|
|
344
|
+
const wsManager = useConsoleClient().transport;
|
|
345
|
+
const [loading, setLoading] = useState(false);
|
|
346
|
+
const [error, setError] = useState<string | null>(null);
|
|
347
|
+
const test = useCallback(async () => {
|
|
348
|
+
setLoading(true);
|
|
349
|
+
setError(null);
|
|
350
|
+
try {
|
|
351
|
+
return await wsManager.testEndpoint(adapter, endpointKey);
|
|
352
|
+
} catch (e) {
|
|
353
|
+
setError(e instanceof Error ? e.message : 'Unknown error');
|
|
354
|
+
throw e;
|
|
355
|
+
} finally {
|
|
356
|
+
setLoading(false);
|
|
357
|
+
}
|
|
358
|
+
}, [adapter, endpointKey, wsManager]);
|
|
359
|
+
return useMemo(() => ({ loading, error, test }), [loading, error, test]);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export function usePluginMarketplace() {
|
|
363
|
+
const wsManager = useConsoleClient().transport;
|
|
364
|
+
const [loading, setLoading] = useState(false);
|
|
365
|
+
const [error, setError] = useState<string | null>(null);
|
|
366
|
+
const run = useCallback(async <T>(operation: () => Promise<T>) => {
|
|
367
|
+
setLoading(true);
|
|
368
|
+
setError(null);
|
|
369
|
+
try {
|
|
370
|
+
return await operation();
|
|
371
|
+
} catch (e) {
|
|
372
|
+
setError(e instanceof Error ? e.message : 'Unknown error');
|
|
373
|
+
throw e;
|
|
374
|
+
} finally {
|
|
375
|
+
setLoading(false);
|
|
376
|
+
}
|
|
377
|
+
}, []);
|
|
378
|
+
const search = useCallback(
|
|
379
|
+
(query?: Parameters<typeof wsManager.searchMarketplace>[0]) =>
|
|
380
|
+
run(() => wsManager.searchMarketplace(query)),
|
|
381
|
+
[run, wsManager],
|
|
382
|
+
);
|
|
383
|
+
const detail = useCallback(
|
|
384
|
+
(packageName: string) => run(() => wsManager.getMarketplacePlugin(packageName)),
|
|
385
|
+
[run, wsManager],
|
|
386
|
+
);
|
|
387
|
+
const updates = useCallback(() => run(() => wsManager.getPluginUpdates()), [run, wsManager]);
|
|
388
|
+
const installed = useCallback(() => run(() => wsManager.listPlugins()), [run, wsManager]);
|
|
389
|
+
return useMemo(() => ({ loading, error, search, detail, updates, installed }), [
|
|
390
|
+
loading, error, search, detail, updates, installed,
|
|
391
|
+
]);
|
|
175
392
|
}
|
|
176
393
|
|
|
177
394
|
export function useFiles() {
|
|
178
|
-
const wsManager =
|
|
395
|
+
const wsManager = useConsoleClient().transport;
|
|
179
396
|
const [connected, setConnected] = useState(wsManager.isConnected());
|
|
180
|
-
const [tree, setTree] = useState<import("./types").FileTreeNode[]>([]);
|
|
397
|
+
const [tree, setTree] = useState<import("./types.js").FileTreeNode[]>([]);
|
|
181
398
|
const [loading, setLoading] = useState(false);
|
|
182
399
|
const [error, setError] = useState<string | null>(null);
|
|
183
400
|
|
|
@@ -212,7 +429,7 @@ export function useFiles() {
|
|
|
212
429
|
}
|
|
213
430
|
|
|
214
431
|
export function useEnvFiles() {
|
|
215
|
-
const wsManager =
|
|
432
|
+
const wsManager = useConsoleClient().transport;
|
|
216
433
|
const [connected, setConnected] = useState(wsManager.isConnected());
|
|
217
434
|
const [files, setFiles] = useState<Array<{ name: string; exists: boolean }>>([]);
|
|
218
435
|
const [loading, setLoading] = useState(false);
|
|
@@ -259,10 +476,10 @@ export function useEnvFiles() {
|
|
|
259
476
|
}
|
|
260
477
|
|
|
261
478
|
export function useDatabase() {
|
|
262
|
-
const wsManager =
|
|
479
|
+
const wsManager = useConsoleClient().transport;
|
|
263
480
|
const [connected, setConnected] = useState(wsManager.isConnected());
|
|
264
|
-
const [info, setInfo] = useState<import("./types").DatabaseInfo | null>(null);
|
|
265
|
-
const [tables, setTables] = useState<import("./types").TableInfo[]>([]);
|
|
481
|
+
const [info, setInfo] = useState<import("./types.js").DatabaseInfo | null>(null);
|
|
482
|
+
const [tables, setTables] = useState<import("./types.js").TableInfo[]>([]);
|
|
266
483
|
const [loading, setLoading] = useState(false);
|
|
267
484
|
const [error, setError] = useState<string | null>(null);
|
|
268
485
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export {
|
|
3
|
+
ConsoleTransport,
|
|
4
|
+
type ConsoleEventListener,
|
|
5
|
+
type ConsoleEventRecoveryGap,
|
|
6
|
+
type ConsoleEventRecoveryGapListener,
|
|
7
|
+
} from "./console-transport.js";
|
|
8
|
+
export {
|
|
9
|
+
useConsoleTransport,
|
|
10
|
+
useConfig,
|
|
11
|
+
useConfigSource,
|
|
12
|
+
usePluginInstall,
|
|
13
|
+
usePluginConfigValidation,
|
|
14
|
+
usePluginDiagnostics,
|
|
15
|
+
usePluginLifecycle,
|
|
16
|
+
usePluginUninstall,
|
|
17
|
+
usePluginUpdate,
|
|
18
|
+
useEndpointTest,
|
|
19
|
+
usePluginMarketplace,
|
|
20
|
+
useFiles,
|
|
21
|
+
useEnvFiles,
|
|
22
|
+
useDatabase,
|
|
23
|
+
} from "./hooks.js";
|
|
@@ -10,23 +10,23 @@ export interface BaseMessage {
|
|
|
10
10
|
error?: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export type
|
|
13
|
+
export type ConsoleTransportMessage = BaseMessage & { data?: unknown; [key: string]: unknown };
|
|
14
14
|
|
|
15
|
-
export interface
|
|
16
|
-
|
|
15
|
+
export interface ConsoleTransportConfig {
|
|
16
|
+
fetch?: typeof globalThis.fetch;
|
|
17
17
|
reconnectInterval?: number;
|
|
18
18
|
maxReconnectAttempts?: number;
|
|
19
19
|
requestTimeout?: number;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export interface
|
|
22
|
+
export interface ConsoleTransportCallbacks {
|
|
23
23
|
onConnect?: () => void;
|
|
24
24
|
onDisconnect?: () => void;
|
|
25
|
-
onError?: (error:
|
|
26
|
-
onMessage?: (message:
|
|
25
|
+
onError?: (error: Error) => void;
|
|
26
|
+
onMessage?: (message: ConsoleTransportMessage) => void;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export interface
|
|
29
|
+
export interface UseConsoleTransportOptions {
|
|
30
30
|
autoConnect?: boolean;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -38,30 +38,24 @@ export enum ConnectionState {
|
|
|
38
38
|
ERROR = "error",
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export class
|
|
41
|
+
export class ConsoleTransportError extends Error {
|
|
42
42
|
constructor(
|
|
43
43
|
message: string,
|
|
44
44
|
public code: string,
|
|
45
45
|
public originalError?: Error,
|
|
46
46
|
) {
|
|
47
47
|
super(message);
|
|
48
|
-
this.name = "
|
|
48
|
+
this.name = "ConsoleTransportError";
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export class
|
|
53
|
-
constructor(requestId: number) {
|
|
54
|
-
super(`Request ${requestId} timed out`, "REQUEST_TIMEOUT");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export class ConnectionError extends WebSocketError {
|
|
52
|
+
export class ConnectionError extends ConsoleTransportError {
|
|
59
53
|
constructor(message: string, originalError?: Error) {
|
|
60
54
|
super(message, "CONNECTION_ERROR", originalError);
|
|
61
55
|
}
|
|
62
56
|
}
|
|
63
57
|
|
|
64
|
-
export class MessageError extends
|
|
58
|
+
export class MessageError extends ConsoleTransportError {
|
|
65
59
|
constructor(message: string, originalError?: Error) {
|
|
66
60
|
super(message, "MESSAGE_ERROR", originalError);
|
|
67
61
|
}
|
package/client/types.ts
CHANGED
package/dist/app.d.ts
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
element: React.ReactNode;
|
|
6
|
-
parent?: string | null;
|
|
7
|
-
icon?: React.ReactNode | string;
|
|
8
|
-
requiredPermissions?: string[];
|
|
9
|
-
requiredRoles?: string[];
|
|
10
|
-
meta?: {
|
|
11
|
-
hideInMenu?: boolean;
|
|
12
|
-
order?: number;
|
|
13
|
-
group?: string;
|
|
14
|
-
fullWidth?: boolean;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export type AddToolInput = {
|
|
18
|
-
id?: string;
|
|
19
|
-
name: string;
|
|
20
|
-
icon?: React.ReactNode;
|
|
21
|
-
parent?: string | null;
|
|
22
|
-
path?: string;
|
|
23
|
-
};
|
|
2
|
+
import type { PluginAddRouteInput, PluginAddToolInput } from '@zhin.js/contract';
|
|
3
|
+
export type AddRouteInput = PluginAddRouteInput;
|
|
4
|
+
export type AddToolInput = PluginAddToolInput;
|
|
24
5
|
export type ConsoleRouteRecord = {
|
|
25
6
|
path: string;
|
|
26
7
|
name: string;
|
|
@@ -49,18 +30,18 @@ export type RouteTreeNode = ConsoleRouteRecord & {
|
|
|
49
30
|
export type ToolTreeNode = InternalToolRecord & {
|
|
50
31
|
children: ToolTreeNode[];
|
|
51
32
|
};
|
|
52
|
-
type SidebarRenderer = (options: {
|
|
33
|
+
export type SidebarRenderer = (options: {
|
|
53
34
|
routes: RouteTreeNode[];
|
|
54
35
|
}) => React.ReactNode;
|
|
55
|
-
type ToolbarRenderer = (options: {
|
|
36
|
+
export type ToolbarRenderer = (options: {
|
|
56
37
|
tools: ToolTreeNode[];
|
|
57
38
|
}) => React.ReactNode;
|
|
58
39
|
export type ConsoleRouteRenderer = (route: ConsoleRouteRecord) => React.ReactNode;
|
|
59
|
-
|
|
60
|
-
declare
|
|
61
|
-
|
|
62
|
-
subscribe:
|
|
63
|
-
getVersion:
|
|
40
|
+
/** Owner-scoped registry for one mounted Remote Console application. */
|
|
41
|
+
export declare class ConsoleApp {
|
|
42
|
+
#private;
|
|
43
|
+
readonly subscribe: (listener: () => void) => (() => void);
|
|
44
|
+
readonly getVersion: () => number;
|
|
64
45
|
defineSidebar(render: SidebarRenderer): void;
|
|
65
46
|
defineToolbar(render: ToolbarRenderer): void;
|
|
66
47
|
defineRouter(render: ConsoleRouteRenderer): void;
|
|
@@ -69,27 +50,11 @@ declare function createConsoleApp(): {
|
|
|
69
50
|
addTool(input: AddToolInput): string;
|
|
70
51
|
getRouteTree(): RouteTreeNode[];
|
|
71
52
|
getToolTree(): ToolTreeNode[];
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
export declare
|
|
79
|
-
subscribe: typeof subscribe;
|
|
80
|
-
getVersion: typeof getVersion;
|
|
81
|
-
defineSidebar(render: SidebarRenderer): void;
|
|
82
|
-
defineToolbar(render: ToolbarRenderer): void;
|
|
83
|
-
defineRouter(render: ConsoleRouteRenderer): void;
|
|
84
|
-
addRoute(input: AddRouteInput): void;
|
|
85
|
-
removeRoute(path: string): void;
|
|
86
|
-
addTool(input: AddToolInput): string;
|
|
87
|
-
getRouteTree(): RouteTreeNode[];
|
|
88
|
-
getToolTree(): ToolTreeNode[];
|
|
89
|
-
_getRoutes(): readonly ConsoleRouteRecord[];
|
|
90
|
-
_getSidebarRenderer(): SidebarRenderer | null;
|
|
91
|
-
_getToolbarRenderer(): ToolbarRenderer | null;
|
|
92
|
-
_renderRouteElement(route: ConsoleRouteRecord): React.ReactNode;
|
|
93
|
-
};
|
|
94
|
-
export {};
|
|
53
|
+
getRoutes(): readonly ConsoleRouteRecord[];
|
|
54
|
+
getSidebarRenderer(): SidebarRenderer | null;
|
|
55
|
+
getToolbarRenderer(): ToolbarRenderer | null;
|
|
56
|
+
renderRouteElement(route: ConsoleRouteRecord): React.ReactNode;
|
|
57
|
+
dispose(): void;
|
|
58
|
+
}
|
|
59
|
+
export declare function createConsoleApp(): ConsoleApp;
|
|
95
60
|
//# sourceMappingURL=app.d.ts.map
|
package/dist/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../client/app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../client/app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAChD,MAAM,MAAM,YAAY,GAAG,kBAAkB,CAAC;A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