dsh-cite 0.8.0 → 0.9.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/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
- console.warn('[dsh-cite] ' + (error instanceof Error ? error.message : String(error)));
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
- const dispose = () => { workbench.dispose(); for (const fn of disposers.splice(0).reverse())
30
- fn?.(); };
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
- if (typeof preferences === 'function')
40
- disposers.push(preferences);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cite",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "DeepSeek Harness 引文工作台。支持 DOI / BibTeX 导入去重、Crossref 核查与补全、引文导出和原始来源备份。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -78,7 +78,7 @@
78
78
  "@citation-js/core": "0.9.0",
79
79
  "@citation-js/plugin-bibtex": "0.9.0",
80
80
  "proper-lockfile": "4.1.2",
81
- "@stardustlc/dsh-updates": "0.1.4"
81
+ "@stardustlc/dsh-updates": "0.2.0"
82
82
  },
83
83
  "icon": "./assets/plugin-icon.webp"
84
84
  }