dsh-cite 0.8.1 → 0.9.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.
- package/CHANGELOG.md +12 -0
- package/lib/client.js +1232 -221
- package/lib/index.d.ts +4 -0
- package/lib/index.js +29 -7
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -16,6 +16,10 @@ export interface CitePluginContext {
|
|
|
16
16
|
tools: {
|
|
17
17
|
register(definition: CiteToolDefinition): () => void;
|
|
18
18
|
};
|
|
19
|
+
effect?(fn: () => (() => void) | void, label?: string): void;
|
|
20
|
+
logger?: {
|
|
21
|
+
warn?(message: string): void;
|
|
22
|
+
};
|
|
19
23
|
on?(event: string, listener: () => void): () => void;
|
|
20
24
|
inject?(services: string[], callback: (host: any) => void): unknown;
|
|
21
25
|
}
|
package/lib/index.js
CHANGED
|
@@ -21,24 +21,46 @@ export function apply(ctx, config) {
|
|
|
21
21
|
cfg = resolveConfig(config);
|
|
22
22
|
}
|
|
23
23
|
catch (error) {
|
|
24
|
-
|
|
24
|
+
const msg = '[dsh-cite] ' + (error instanceof Error ? error.message : String(error));
|
|
25
|
+
if (typeof ctx.logger?.warn === 'function')
|
|
26
|
+
ctx.logger.warn(msg);
|
|
27
|
+
else
|
|
28
|
+
console.warn(msg);
|
|
25
29
|
cfg = resolveConfig(null);
|
|
26
30
|
}
|
|
27
31
|
const disposers = [];
|
|
28
32
|
const workbench = new CitationWorkbench(cfg);
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
let disposed = false;
|
|
34
|
+
const dispose = () => {
|
|
35
|
+
if (disposed)
|
|
36
|
+
return;
|
|
37
|
+
disposed = true;
|
|
38
|
+
workbench.dispose();
|
|
39
|
+
for (const fn of disposers.splice(0).reverse())
|
|
40
|
+
fn?.();
|
|
41
|
+
};
|
|
31
42
|
try {
|
|
32
43
|
for (const definition of [...buildCiteTools(cfg), buildBatchTool(workbench)])
|
|
33
44
|
disposers.push(ctx.tools.register(definition));
|
|
34
45
|
ctx.inject?.(['connection'], host => {
|
|
35
46
|
const remove = host.connection?.fetch?.register({ path: workbench.route, methods: ['GET', 'POST'], requestBody: 'buffered', fetch: (request) => workbench.fetch(request) });
|
|
36
|
-
if (typeof remove === 'function')
|
|
37
|
-
disposers.push(remove);
|
|
38
47
|
const preferences = host.connection?.fetch?.register({ path: '/api/dsh-cite/preferences', methods: ['GET'], requestBody: 'buffered', fetch: () => Response.json({ hideWorkbench: cfg.hideWorkbench }, { headers: { 'cache-control': 'no-store' } }) });
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
let routeDisposed = false;
|
|
49
|
+
const releaseRoutes = () => {
|
|
50
|
+
if (routeDisposed)
|
|
51
|
+
return;
|
|
52
|
+
routeDisposed = true;
|
|
53
|
+
if (typeof preferences === 'function')
|
|
54
|
+
preferences();
|
|
55
|
+
if (typeof remove === 'function')
|
|
56
|
+
remove();
|
|
57
|
+
};
|
|
58
|
+
disposers.push(releaseRoutes);
|
|
59
|
+
if (typeof host?.effect === 'function')
|
|
60
|
+
host.effect(() => releaseRoutes, 'dsh-cite: connection routes');
|
|
41
61
|
});
|
|
62
|
+
if (typeof ctx.effect === 'function')
|
|
63
|
+
ctx.effect(() => dispose, 'dsh-cite: lifecycle');
|
|
42
64
|
ctx.on?.('dispose', dispose);
|
|
43
65
|
}
|
|
44
66
|
catch (e) {
|