dsh-source-cnki 0.0.0-stage → 0.1.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 +48 -0
- package/LICENSE +201 -0
- package/README-zh.md +106 -0
- package/README.md +105 -2
- package/cordis.patch.yml +17 -0
- package/lib/cite.d.ts +33 -0
- package/lib/cite.d.ts.map +1 -0
- package/lib/cite.js +117 -0
- package/lib/cite.js.map +1 -0
- package/lib/config.d.ts +32 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +44 -0
- package/lib/config.js.map +1 -0
- package/lib/formats.d.ts +61 -0
- package/lib/formats.d.ts.map +1 -0
- package/lib/formats.js +217 -0
- package/lib/formats.js.map +1 -0
- package/lib/index.d.ts +39 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +51 -0
- package/lib/index.js.map +1 -0
- package/lib/runtime.d.ts +84 -0
- package/lib/runtime.d.ts.map +1 -0
- package/lib/runtime.js +228 -0
- package/lib/runtime.js.map +1 -0
- package/lib/tools/cnki-check.d.ts +12 -0
- package/lib/tools/cnki-check.d.ts.map +1 -0
- package/lib/tools/cnki-check.js +56 -0
- package/lib/tools/cnki-check.js.map +1 -0
- package/lib/tools/cnki-cite.d.ts +12 -0
- package/lib/tools/cnki-cite.d.ts.map +1 -0
- package/lib/tools/cnki-cite.js +62 -0
- package/lib/tools/cnki-cite.js.map +1 -0
- package/lib/tools/cnki-import.d.ts +12 -0
- package/lib/tools/cnki-import.d.ts.map +1 -0
- package/lib/tools/cnki-import.js +75 -0
- package/lib/tools/cnki-import.js.map +1 -0
- package/lib/tools/shared.d.ts +20 -0
- package/lib/tools/shared.d.ts.map +1 -0
- package/lib/tools/shared.js +14 -0
- package/lib/tools/shared.js.map +1 -0
- package/lib/validate.d.ts +29 -0
- package/lib/validate.d.ts.map +1 -0
- package/lib/validate.js +51 -0
- package/lib/validate.js.map +1 -0
- package/lib/version.d.ts +7 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +7 -0
- package/lib/version.js.map +1 -0
- package/package.json +79 -4
- package/src/cite.ts +124 -0
- package/src/config.ts +64 -0
- package/src/formats.ts +236 -0
- package/src/index.ts +62 -0
- package/src/runtime.ts +254 -0
- package/src/tools/cnki-check.ts +56 -0
- package/src/tools/cnki-cite.ts +62 -0
- package/src/tools/cnki-import.ts +74 -0
- package/src/tools/shared.ts +14 -0
- package/src/validate.ts +65 -0
- package/src/version.ts +7 -0
package/lib/runtime.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime: workspace-safe export loading, import with REP evidence, citation and
|
|
3
|
+
* validation. No network: CNKI has no public API here and the plugin neither
|
|
4
|
+
* logs in nor scrapes.
|
|
5
|
+
* @module dsh-source-cnki/runtime
|
|
6
|
+
*/
|
|
7
|
+
import { mkdir, readFile, realpath, stat, writeFile } from 'node:fs/promises';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { EvidenceStore, RepStoreError, stableId, validateRep, } from '@perrylink/dsh-research-core';
|
|
10
|
+
import { formatBibliography } from "./cite.js";
|
|
11
|
+
import { importRecords, ImportError } from "./formats.js";
|
|
12
|
+
import { validateRecords } from "./validate.js";
|
|
13
|
+
import { VERSION } from "./version.js";
|
|
14
|
+
/** A typed failure. */
|
|
15
|
+
export class SourceError extends Error {
|
|
16
|
+
/** Stable code. */
|
|
17
|
+
code;
|
|
18
|
+
constructor(code, message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = 'SourceError';
|
|
21
|
+
this.code = code;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** True when `candidate` is inside `root`. */
|
|
25
|
+
function isInside(root, candidate) {
|
|
26
|
+
return candidate === root || candidate.startsWith(root.endsWith(path.sep) ? root : `${root}${path.sep}`);
|
|
27
|
+
}
|
|
28
|
+
/** Validate record objects arriving from the tool's JSON boundary. */
|
|
29
|
+
function assertRecords(value) {
|
|
30
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
31
|
+
throw new SourceError('INVALID_INPUT', 'pass at least one record');
|
|
32
|
+
for (const item of value) {
|
|
33
|
+
if (typeof item !== 'object' || item === null)
|
|
34
|
+
throw new SourceError('INVALID_INPUT', 'every record must be an object from cnki_import');
|
|
35
|
+
const record = item;
|
|
36
|
+
if (typeof record.recordId !== 'string' || typeof record.title !== 'string') {
|
|
37
|
+
throw new SourceError('INVALID_INPUT', 'every record needs recordId and title strings');
|
|
38
|
+
}
|
|
39
|
+
if (!Array.isArray(record.authors) || !record.authors.every(author => typeof author === 'string')) {
|
|
40
|
+
throw new SourceError('INVALID_INPUT', 'record.authors must be an array of strings');
|
|
41
|
+
}
|
|
42
|
+
if (record.type !== 'journal' && record.type !== 'thesis' && record.type !== 'conference' && record.type !== 'book' && record.type !== 'other') {
|
|
43
|
+
throw new SourceError('INVALID_INPUT', 'record.type must be journal, thesis, conference, book or other');
|
|
44
|
+
}
|
|
45
|
+
if (record.language !== 'zh' && record.language !== 'en' && record.language !== 'unknown') {
|
|
46
|
+
throw new SourceError('INVALID_INPUT', 'record.language must be zh, en or unknown');
|
|
47
|
+
}
|
|
48
|
+
for (const field of ['journal', 'volume', 'issue', 'pages', 'doi', 'abstract']) {
|
|
49
|
+
if (record[field] !== undefined && typeof record[field] !== 'string')
|
|
50
|
+
throw new SourceError('INVALID_INPUT', `record.${field} must be a string when present`);
|
|
51
|
+
}
|
|
52
|
+
if (record.year !== undefined && typeof record.year !== 'number')
|
|
53
|
+
throw new SourceError('INVALID_INPUT', 'record.year must be a number when present');
|
|
54
|
+
if (record.keywords !== undefined && (!Array.isArray(record.keywords) || !record.keywords.every(keyword => typeof keyword === 'string'))) {
|
|
55
|
+
throw new SourceError('INVALID_INPUT', 'record.keywords must be an array of strings when present');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
/** The runtime. */
|
|
61
|
+
export class SourceRuntime {
|
|
62
|
+
config;
|
|
63
|
+
#service;
|
|
64
|
+
#now;
|
|
65
|
+
#store;
|
|
66
|
+
constructor(options) {
|
|
67
|
+
this.config = options.config;
|
|
68
|
+
this.#service = options.service;
|
|
69
|
+
this.#now = options.now ?? (() => new Date());
|
|
70
|
+
}
|
|
71
|
+
/** Current ISO timestamp. */
|
|
72
|
+
iso() {
|
|
73
|
+
return this.#now().toISOString();
|
|
74
|
+
}
|
|
75
|
+
/** The evidence port. */
|
|
76
|
+
port() {
|
|
77
|
+
if (this.#service !== undefined)
|
|
78
|
+
return this.#service;
|
|
79
|
+
this.#store ??= new EvidenceStore(path.join(this.config.root, 'store'));
|
|
80
|
+
return this.#store;
|
|
81
|
+
}
|
|
82
|
+
/** Resolve a file inside the workspace. */
|
|
83
|
+
async resolveFile(input) {
|
|
84
|
+
if (typeof input !== 'string' || input.trim() === '')
|
|
85
|
+
throw new SourceError('INVALID_INPUT', 'path must be a non-empty string');
|
|
86
|
+
let realRoot;
|
|
87
|
+
try {
|
|
88
|
+
realRoot = await realpath(this.config.workspaceRoot);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
throw new SourceError('NOT_FOUND', `workspace root does not exist: ${this.config.workspaceRoot}`);
|
|
92
|
+
}
|
|
93
|
+
const candidate = path.resolve(realRoot, input);
|
|
94
|
+
if (!isInside(realRoot, candidate))
|
|
95
|
+
throw new SourceError('PATH_ESCAPE', 'path resolves outside the workspace root');
|
|
96
|
+
let real;
|
|
97
|
+
try {
|
|
98
|
+
real = await realpath(candidate);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
throw new SourceError('NOT_FOUND', `file not found: ${input}`);
|
|
102
|
+
}
|
|
103
|
+
if (!isInside(realRoot, real))
|
|
104
|
+
throw new SourceError('PATH_ESCAPE', 'path escapes the workspace root through a symlink');
|
|
105
|
+
if (!(await stat(real)).isFile())
|
|
106
|
+
throw new SourceError('NOT_A_FILE', `not a regular file: ${input}`);
|
|
107
|
+
return { absolute: real, id: path.relative(realRoot, real).split(path.sep).join('/') };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Import exported records and optionally persist the export as evidence.
|
|
111
|
+
* @param request - text/path, format and persistence.
|
|
112
|
+
* @returns records and validation.
|
|
113
|
+
*/
|
|
114
|
+
async import(request) {
|
|
115
|
+
if ((request.text === undefined) === (request.path === undefined))
|
|
116
|
+
throw new SourceError('INVALID_INPUT', 'pass exactly one of text or path');
|
|
117
|
+
if (request.text !== undefined && typeof request.text !== 'string')
|
|
118
|
+
throw new SourceError('INVALID_INPUT', 'text must be a string');
|
|
119
|
+
const format = request.format ?? 'auto';
|
|
120
|
+
if (format !== 'auto' && format !== 'ris' && format !== 'labeled')
|
|
121
|
+
throw new SourceError('INVALID_INPUT', 'format must be auto, ris or labeled');
|
|
122
|
+
let text;
|
|
123
|
+
let sourceRef;
|
|
124
|
+
let id;
|
|
125
|
+
if (request.text !== undefined) {
|
|
126
|
+
if (request.text.length > this.config.maxChars)
|
|
127
|
+
throw new SourceError('TOO_LARGE', `export is ${request.text.length} characters, the cap is ${this.config.maxChars}`);
|
|
128
|
+
text = request.text;
|
|
129
|
+
sourceRef = { kind: 'other', id: 'inline:cnki-export', retrievedAt: this.iso() };
|
|
130
|
+
id = 'inline:cnki-export';
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const file = await this.resolveFile(request.path);
|
|
134
|
+
if (/\.(docx?|pdf)$/iu.test(file.id))
|
|
135
|
+
throw new SourceError('UNSUPPORTED_FILE', 'docx/pdf is not parsed here; export RIS or labeled text (.txt/.ris/.md)');
|
|
136
|
+
text = await readFile(file.absolute, 'utf8');
|
|
137
|
+
if (text.length > this.config.maxChars)
|
|
138
|
+
throw new SourceError('TOO_LARGE', `export is ${text.length} characters, the cap is ${this.config.maxChars}`);
|
|
139
|
+
sourceRef = { kind: 'file', id: file.id, retrievedAt: this.iso() };
|
|
140
|
+
id = file.id;
|
|
141
|
+
}
|
|
142
|
+
let records;
|
|
143
|
+
try {
|
|
144
|
+
records = importRecords(text, format);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (error instanceof ImportError)
|
|
148
|
+
throw new SourceError(error.code === 'NO_RECORDS' ? 'NO_RECORDS' : 'INVALID_INPUT', error.message);
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
const validation = validateRecords(records);
|
|
152
|
+
const persist = request.persist ?? this.config.persist;
|
|
153
|
+
if (!persist)
|
|
154
|
+
return { records, validation };
|
|
155
|
+
const checks = [
|
|
156
|
+
{
|
|
157
|
+
checkId: 'chk-import-count',
|
|
158
|
+
check: 'other',
|
|
159
|
+
status: 'pass',
|
|
160
|
+
severity: 'info',
|
|
161
|
+
detail: `imported ${records.length} record(s)`,
|
|
162
|
+
},
|
|
163
|
+
...validation.issues
|
|
164
|
+
.filter(issue => issue.severity !== 'info')
|
|
165
|
+
.map((issue, index) => ({
|
|
166
|
+
checkId: `chk-record-${index + 1}`,
|
|
167
|
+
check: 'other',
|
|
168
|
+
status: issue.severity === 'error' ? 'fail' : 'warn',
|
|
169
|
+
severity: issue.severity === 'error' ? 'error' : 'warning',
|
|
170
|
+
detail: `${issue.recordId}: ${issue.code} — ${issue.detail}`,
|
|
171
|
+
})),
|
|
172
|
+
];
|
|
173
|
+
const port = this.port();
|
|
174
|
+
try {
|
|
175
|
+
const captured = await port.capture({ bytes: text, mediaType: 'text/plain', sourceRef, capturedAt: this.iso() });
|
|
176
|
+
const evidence = (await port.addEvidence({
|
|
177
|
+
evidenceId: stableId('ev', ['source-cnki', id, captured.snapshot.snapshotId]),
|
|
178
|
+
title: `CNKI export (${records.length} records)`,
|
|
179
|
+
sourceRef,
|
|
180
|
+
snapshotIds: [captured.snapshot.snapshotId],
|
|
181
|
+
anchors: [{ snapshotId: captured.snapshot.snapshotId, kind: 'record', value: 'field:recordId' }],
|
|
182
|
+
provenance: { plugin: 'dsh-source-cnki', version: VERSION, method: 'export-import', retrievedAt: this.iso() },
|
|
183
|
+
checks,
|
|
184
|
+
notes: validation.ok ? 'structural validation passed' : 'structural validation found errors',
|
|
185
|
+
})).evidence;
|
|
186
|
+
const record = await port.buildRecord({ evidenceIds: [evidence.evidenceId] });
|
|
187
|
+
if (!validateRep(record).ok)
|
|
188
|
+
throw new SourceError('STORE_ERROR', 'refusing to write an invalid REP record');
|
|
189
|
+
const directory = path.join(this.config.root, 'records');
|
|
190
|
+
await mkdir(directory, { recursive: true });
|
|
191
|
+
const file = path.join(directory, `${evidence.evidenceId}.rep.json`);
|
|
192
|
+
await writeFile(file, `${JSON.stringify(record, null, 2)}\n`, 'utf8');
|
|
193
|
+
return { records, validation, evidenceId: evidence.evidenceId, recordPath: file };
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
if (error instanceof SourceError)
|
|
197
|
+
throw error;
|
|
198
|
+
if (error instanceof RepStoreError)
|
|
199
|
+
throw new SourceError('STORE_ERROR', error.message);
|
|
200
|
+
throw new SourceError('STORE_ERROR', `could not store the evidence: ${error.message}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Format citations.
|
|
205
|
+
* @param records - records to cite.
|
|
206
|
+
* @param options - style and starting number.
|
|
207
|
+
* @returns the formatted citations.
|
|
208
|
+
*/
|
|
209
|
+
cite(records, options = {}) {
|
|
210
|
+
const safeRecords = assertRecords(records);
|
|
211
|
+
const style = options.style ?? this.config.style;
|
|
212
|
+
if (style !== 'gbt7714' && style !== 'gbt7714-numeric' && style !== 'apa')
|
|
213
|
+
throw new SourceError('INVALID_INPUT', 'style must be gbt7714, gbt7714-numeric or apa');
|
|
214
|
+
if (options.startIndex !== undefined && (!Number.isSafeInteger(options.startIndex) || options.startIndex < 1)) {
|
|
215
|
+
throw new SourceError('INVALID_INPUT', 'startIndex must be a positive integer');
|
|
216
|
+
}
|
|
217
|
+
return formatBibliography(safeRecords, { ...options, style });
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Validate records.
|
|
221
|
+
* @param records - records to check.
|
|
222
|
+
* @returns the validation result.
|
|
223
|
+
*/
|
|
224
|
+
check(records) {
|
|
225
|
+
return validateRecords(assertRecords(records));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC7E,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EACL,aAAa,EACb,aAAa,EACb,QAAQ,EACR,WAAW,GAOZ,MAAM,8BAA8B,CAAA;AAErC,OAAO,EAAE,kBAAkB,EAAoB,MAAM,WAAW,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAkB,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,eAAe,EAAyB,MAAM,eAAe,CAAA;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAKtC,uBAAuB;AACvB,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,mBAAmB;IACV,IAAI,CAAiB;IAE9B,YAAY,IAAqB,EAAE,OAAe;QAChD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAwBD,8CAA8C;AAC9C,SAAS,QAAQ,CAAC,IAAY,EAAE,SAAiB;IAC/C,OAAO,SAAS,KAAK,IAAI,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAA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MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC;YAC9G,MAAM,IAAI,WAAW,CAAC,eAAe,EAAE,uCAAuC,CAAC,CAAA;QACjF,CAAC;QACD,OAAO,kBAAkB,CAAC,WAAW,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA;IAC/D,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAA6B;QACjC,OAAO,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;IAChD,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `cnki_check` — structural metadata validation.
|
|
3
|
+
* @module dsh-source-cnki/tools/cnki-check
|
|
4
|
+
*/
|
|
5
|
+
import { type SourceRuntime } from '../runtime.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Build the `cnki_check` tool.
|
|
8
|
+
* @param runtime - the runtime.
|
|
9
|
+
* @returns the tool definition.
|
|
10
|
+
*/
|
|
11
|
+
export declare function makeCnkiCheckTool(runtime: SourceRuntime): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
12
|
+
//# sourceMappingURL=cnki-check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cnki-check.d.ts","sourceRoot":"","sources":["../../src/tools/cnki-check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,eAAe,CAAA;AAc/D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,aAAa,mDA8BvD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `cnki_check` — structural metadata validation.
|
|
3
|
+
* @module dsh-source-cnki/tools/cnki-check
|
|
4
|
+
*/
|
|
5
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
6
|
+
import { SourceError } from "../runtime.js";
|
|
7
|
+
import { ERROR_SCHEMA } from "./shared.js";
|
|
8
|
+
const OUTPUT_SCHEMA = {
|
|
9
|
+
type: 'object',
|
|
10
|
+
additionalProperties: false,
|
|
11
|
+
properties: {
|
|
12
|
+
ok: { type: 'boolean', required: true },
|
|
13
|
+
validation: { type: 'json' },
|
|
14
|
+
error: ERROR_SCHEMA,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Build the `cnki_check` tool.
|
|
19
|
+
* @param runtime - the runtime.
|
|
20
|
+
* @returns the tool definition.
|
|
21
|
+
*/
|
|
22
|
+
export function makeCnkiCheckTool(runtime) {
|
|
23
|
+
return defineTool({
|
|
24
|
+
name: 'cnki_check',
|
|
25
|
+
description: [
|
|
26
|
+
'Validate imported Chinese-literature records (dsh-source-cnki).',
|
|
27
|
+
'',
|
|
28
|
+
'Structural checks only: missing title/journal/year/authors, implausible year, malformed DOI, non-numeric pages, duplicate records, and journal records without volume or issue. It does not verify that the record matches the real paper (use dsh-cite-verify for DOIs).',
|
|
29
|
+
].join('\n'),
|
|
30
|
+
parameters: {
|
|
31
|
+
records: { type: 'json', required: true, description: 'Records from cnki_import.' },
|
|
32
|
+
},
|
|
33
|
+
output: {
|
|
34
|
+
schema: OUTPUT_SCHEMA,
|
|
35
|
+
render: (_args, value) => {
|
|
36
|
+
const result = value;
|
|
37
|
+
if (!result.ok)
|
|
38
|
+
return [{ type: 'text', text: `cnki_check failed (${result.error.code}): ${result.error.message}` }];
|
|
39
|
+
const errors = result.validation.issues.filter(issue => issue.severity === 'error').length;
|
|
40
|
+
return [{ type: 'text', text: `cnki_check: ${result.validation.records} record(s), ${errors} error(s), ${result.validation.issues.length - errors} warning(s)` }];
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
async execute(args) {
|
|
44
|
+
const request = args;
|
|
45
|
+
try {
|
|
46
|
+
return { ok: true, validation: runtime.check(request.records ?? []) };
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error instanceof SourceError)
|
|
50
|
+
return { ok: false, error: { code: error.code, message: error.message } };
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=cnki-check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cnki-check.js","sourceRoot":"","sources":["../../src/tools/cnki-check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAsB,MAAM,eAAe,CAAA;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE;QACvC,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QAC5B,KAAK,EAAE,YAAY;KACpB;CACO,CAAA;AAEV;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAsB;IACtD,OAAO,UAAU,CAAC;QAChB,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE;YACX,iEAAiE;YACjE,EAAE;YACF,2QAA2Q;SAC5Q,CAAC,IAAI,CAAC,IAAI,CAAC;QACZ,UAAU,EAAE;YACV,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,2BAA2B,EAAE;SACpF;QACD,MAAM,EAAE;YACN,MAAM,EAAE,aAAa;YACrB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;gBACvB,MAAM,MAAM,GAAG,KAAkK,CAAA;gBACjL,IAAI,CAAC,MAAM,CAAC,EAAE;oBAAE,O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+
* Build the `cnki_cite` tool.
|
|
8
|
+
* @param runtime - the runtime.
|
|
9
|
+
* @returns the tool definition.
|
|
10
|
+
*/
|
|
11
|
+
export declare function makeCnkiCiteTool(runtime: SourceRuntime): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
12
|
+
//# sourceMappingURL=cnki-cite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cnki-cite.d.ts","sourceRoot":"","sources":["../../src/tools/cnki-cite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,eAAe,CAAA;AAe/D;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,mDAmCtD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `cnki_cite` — GB/T 7714 or APA citations.
|
|
3
|
+
* @module dsh-source-cnki/tools/cnki-cite
|
|
4
|
+
*/
|
|
5
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
6
|
+
import { SourceError } from "../runtime.js";
|
|
7
|
+
import { ERROR_SCHEMA } from "./shared.js";
|
|
8
|
+
const OUTPUT_SCHEMA = {
|
|
9
|
+
type: 'object',
|
|
10
|
+
additionalProperties: false,
|
|
11
|
+
properties: {
|
|
12
|
+
ok: { type: 'boolean', required: true },
|
|
13
|
+
citations: { type: 'array', items: { type: 'string' } },
|
|
14
|
+
text: { type: 'string' },
|
|
15
|
+
error: ERROR_SCHEMA,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Build the `cnki_cite` tool.
|
|
20
|
+
* @param runtime - the runtime.
|
|
21
|
+
* @returns the tool definition.
|
|
22
|
+
*/
|
|
23
|
+
export function makeCnkiCiteTool(runtime) {
|
|
24
|
+
return defineTool({
|
|
25
|
+
name: 'cnki_cite',
|
|
26
|
+
description: [
|
|
27
|
+
'Format imported records as a bibliography (dsh-source-cnki).',
|
|
28
|
+
'',
|
|
29
|
+
'Styles: `gbt7714-numeric` (顺序编码制, default), `gbt7714` (same without the [n] prefix), `apa` (7th). Only fields present in the record are emitted — no publisher, place or page range is invented; author lists follow GB/T (≤3 all, otherwise first 3 + 等/et al) and APA (Surname, I.) rules.',
|
|
30
|
+
].join('\n'),
|
|
31
|
+
parameters: {
|
|
32
|
+
records: { type: 'json', required: true, description: 'Records from cnki_import.' },
|
|
33
|
+
style: { type: 'string', enum: ['gbt7714', 'gbt7714-numeric', 'apa'], description: 'Citation style.' },
|
|
34
|
+
startIndex: { type: 'integer', description: 'First number for the numeric style (default 1).' },
|
|
35
|
+
},
|
|
36
|
+
output: {
|
|
37
|
+
schema: OUTPUT_SCHEMA,
|
|
38
|
+
render: (_args, value) => {
|
|
39
|
+
const result = value;
|
|
40
|
+
if (!result.ok)
|
|
41
|
+
return [{ type: 'text', text: `cnki_cite failed (${result.error.code}): ${result.error.message}` }];
|
|
42
|
+
return [{ type: 'text', text: result.text }];
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
async execute(args) {
|
|
46
|
+
const request = args;
|
|
47
|
+
try {
|
|
48
|
+
const citations = runtime.cite(request.records ?? [], {
|
|
49
|
+
...(request.style === undefined ? {} : { style: request.style }),
|
|
50
|
+
...(request.startIndex === undefined ? {} : { startIndex: request.startIndex }),
|
|
51
|
+
});
|
|
52
|
+
return { ok: true, citations: [...citations], text: citations.join('\n') };
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof SourceError)
|
|
56
|
+
return { ok: false, error: { code: error.code, message: error.message } };
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=cnki-cite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cnki-cite.js","sourceRoot":"","sources":["../../src/tools/cnki-cite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA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.
|
|
3
|
+
* @module dsh-source-cnki/tools/cnki-import
|
|
4
|
+
*/
|
|
5
|
+
import { type SourceRuntime } from '../runtime.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Build the `cnki_import` tool.
|
|
8
|
+
* @param runtime - the runtime.
|
|
9
|
+
* @returns the tool definition.
|
|
10
|
+
*/
|
|
11
|
+
export declare function makeCnkiImportTool(runtime: SourceRuntime): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
|
12
|
+
//# sourceMappingURL=cnki-import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cnki-import.d.ts","sourceRoot":"","sources":["../../src/tools/cnki-import.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,eAAe,CAAA;AAgB/D;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,mDA8CxD"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `cnki_import` — import exported records.
|
|
3
|
+
* @module dsh-source-cnki/tools/cnki-import
|
|
4
|
+
*/
|
|
5
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
6
|
+
import { SourceError } from "../runtime.js";
|
|
7
|
+
import { ERROR_SCHEMA } from "./shared.js";
|
|
8
|
+
const OUTPUT_SCHEMA = {
|
|
9
|
+
type: 'object',
|
|
10
|
+
additionalProperties: false,
|
|
11
|
+
properties: {
|
|
12
|
+
ok: { type: 'boolean', required: true },
|
|
13
|
+
records: { type: 'json' },
|
|
14
|
+
validation: { type: 'json' },
|
|
15
|
+
evidenceId: { type: 'string' },
|
|
16
|
+
recordPath: { type: 'string' },
|
|
17
|
+
error: ERROR_SCHEMA,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Build the `cnki_import` tool.
|
|
22
|
+
* @param runtime - the runtime.
|
|
23
|
+
* @returns the tool definition.
|
|
24
|
+
*/
|
|
25
|
+
export function makeCnkiImportTool(runtime) {
|
|
26
|
+
return defineTool({
|
|
27
|
+
name: 'cnki_import',
|
|
28
|
+
description: [
|
|
29
|
+
'Import Chinese-literature records from a user export (dsh-source-cnki).',
|
|
30
|
+
'',
|
|
31
|
+
'Reads RIS/EndNote-style tagged text or a labeled text export (题名:/作者:/来源:), assigns stable record ids, and validates structure. It does NOT log in to CNKI, does NOT scrape, and does NOT call a CNKI API (none is public for this purpose): you export the records yourself.',
|
|
32
|
+
'',
|
|
33
|
+
'Missing fields are reported as missing, never guessed. The export is stored as REP evidence when persist is on.',
|
|
34
|
+
].join('\n'),
|
|
35
|
+
parameters: {
|
|
36
|
+
text: { type: 'string', description: 'Export text (mutually exclusive with path).' },
|
|
37
|
+
path: { type: 'string', description: 'Workspace-relative .ris/.txt/.md export file.' },
|
|
38
|
+
format: { type: 'string', enum: ['auto', 'ris', 'labeled'], description: 'Force a format instead of auto-detecting.' },
|
|
39
|
+
persist: { type: 'boolean', description: 'Store the export as REP evidence + record (default true).' },
|
|
40
|
+
},
|
|
41
|
+
output: {
|
|
42
|
+
schema: OUTPUT_SCHEMA,
|
|
43
|
+
render: (_args, value) => {
|
|
44
|
+
const result = value;
|
|
45
|
+
if (!result.ok)
|
|
46
|
+
return [{ type: 'text', text: `cnki_import failed (${result.error.code}): ${result.error.message}` }];
|
|
47
|
+
return [{ type: 'text', text: `cnki_import: ${result.records.length} record(s); ${result.validation.issues.length} validation issue(s); structural ${result.validation.ok ? 'ok' : 'has errors'}` }];
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
async execute(args) {
|
|
51
|
+
const request = args;
|
|
52
|
+
try {
|
|
53
|
+
const result = await runtime.import({
|
|
54
|
+
...(request.text === undefined ? {} : { text: request.text }),
|
|
55
|
+
...(request.path === undefined ? {} : { path: request.path }),
|
|
56
|
+
...(request.format === undefined ? {} : { format: request.format }),
|
|
57
|
+
...(request.persist === undefined ? {} : { persist: request.persist }),
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
ok: true,
|
|
61
|
+
records: result.records,
|
|
62
|
+
validation: result.validation,
|
|
63
|
+
...(result.evidenceId === undefined ? {} : { evidenceId: result.evidenceId }),
|
|
64
|
+
...(result.recordPath === undefined ? {} : { recordPath: result.recordPath }),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error instanceof SourceError)
|
|
69
|
+
return { ok: false, error: { code: error.code, message: error.message } };
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=cnki-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cnki-import.js","sourceRoot":"","sources":["../../src/tools/cnki-import.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAsB,MAAM,eAAe,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE;QACvC,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QACzB,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QAC5B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,KAAK,EAAE,YAAY;KACpB;CACO,CAAA;AAEV;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAsB;IACvD,OAAO,UAAU,CAAC;QAChB,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE;YACX,yEAAyE;YACzE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H,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared tool schema fragments.
|
|
3
|
+
* @module dsh-source-cnki/tools/shared
|
|
4
|
+
*/
|
|
5
|
+
/** The failure branch. */
|
|
6
|
+
export declare const ERROR_SCHEMA: {
|
|
7
|
+
readonly type: "object";
|
|
8
|
+
readonly additionalProperties: false;
|
|
9
|
+
readonly properties: {
|
|
10
|
+
readonly code: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
readonly required: true;
|
|
13
|
+
};
|
|
14
|
+
readonly message: {
|
|
15
|
+
readonly type: "string";
|
|
16
|
+
readonly required: true;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/tools/shared.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0BAA0B;AAC1B,eAAO,MAAM,YAAY;;;;;;;;;;;;;CAOf,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared tool schema fragments.
|
|
3
|
+
* @module dsh-source-cnki/tools/shared
|
|
4
|
+
*/
|
|
5
|
+
/** The failure branch. */
|
|
6
|
+
export const ERROR_SCHEMA = {
|
|
7
|
+
type: 'object',
|
|
8
|
+
additionalProperties: false,
|
|
9
|
+
properties: {
|
|
10
|
+
code: { type: 'string', required: true },
|
|
11
|
+
message: { type: 'string', required: true },
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/tools/shared.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0BAA0B;AAC1B,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;QACxC,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;KAC5C;CACO,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata completeness checks for imported records.
|
|
3
|
+
*
|
|
4
|
+
* These are structural checks (missing fields, impossible dates, malformed DOI,
|
|
5
|
+
* duplicates), not a judgement about whether the record is the right paper.
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-source-cnki/validate
|
|
8
|
+
*/
|
|
9
|
+
import type { BibRecord } from './formats.ts';
|
|
10
|
+
/** One issue. */
|
|
11
|
+
export interface RecordIssue {
|
|
12
|
+
readonly recordId: string;
|
|
13
|
+
readonly code: string;
|
|
14
|
+
readonly severity: 'info' | 'warning' | 'error';
|
|
15
|
+
readonly detail: string;
|
|
16
|
+
}
|
|
17
|
+
/** Validation result. */
|
|
18
|
+
export interface ValidationResult {
|
|
19
|
+
readonly records: number;
|
|
20
|
+
readonly issues: readonly RecordIssue[];
|
|
21
|
+
readonly ok: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Validate imported records.
|
|
25
|
+
* @param records - the records.
|
|
26
|
+
* @returns issues and whether any error-level issue exists.
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateRecords(records: readonly BibRecord[]): ValidationResult;
|
|
29
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,iBAAiB;AACjB,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAA;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,yBAAyB;AACzB,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAA;IACvC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAA;CACrB;AAID;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,SAAS,SAAS,EAAE,GAAG,gBAAgB,CA+B/E"}
|
package/lib/validate.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata completeness checks for imported records.
|
|
3
|
+
*
|
|
4
|
+
* These are structural checks (missing fields, impossible dates, malformed DOI,
|
|
5
|
+
* duplicates), not a judgement about whether the record is the right paper.
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-source-cnki/validate
|
|
8
|
+
*/
|
|
9
|
+
const DOI_PATTERN = /^10\.\d{4,9}\/\S+$/u;
|
|
10
|
+
/**
|
|
11
|
+
* Validate imported records.
|
|
12
|
+
* @param records - the records.
|
|
13
|
+
* @returns issues and whether any error-level issue exists.
|
|
14
|
+
*/
|
|
15
|
+
export function validateRecords(records) {
|
|
16
|
+
const issues = [];
|
|
17
|
+
const seen = new Map();
|
|
18
|
+
// Accept the current year plus one for in-press records, and reject anything
|
|
19
|
+
// further out instead of using a fixed far-future bound.
|
|
20
|
+
const currentYear = new Date().getUTCFullYear() + 1;
|
|
21
|
+
for (const record of records) {
|
|
22
|
+
const count = (seen.get(record.recordId) ?? 0) + 1;
|
|
23
|
+
seen.set(record.recordId, count);
|
|
24
|
+
if (count > 1)
|
|
25
|
+
issues.push({ recordId: record.recordId, code: 'duplicate', severity: 'warning', detail: `the same record appears ${count} times` });
|
|
26
|
+
if (record.title.trim() === '')
|
|
27
|
+
issues.push({ recordId: record.recordId, code: 'missing_title', severity: 'error', detail: 'the title is empty' });
|
|
28
|
+
if (record.authors.length === 0)
|
|
29
|
+
issues.push({ recordId: record.recordId, code: 'missing_authors', severity: 'warning', detail: 'no author was imported' });
|
|
30
|
+
if (record.type === 'journal' && record.journal === undefined) {
|
|
31
|
+
issues.push({ recordId: record.recordId, code: 'missing_journal', severity: 'error', detail: 'a journal article has no journal name' });
|
|
32
|
+
}
|
|
33
|
+
if (record.year === undefined) {
|
|
34
|
+
issues.push({ recordId: record.recordId, code: 'missing_year', severity: 'warning', detail: 'no publication year' });
|
|
35
|
+
}
|
|
36
|
+
else if (!Number.isInteger(record.year) || record.year < 1900 || record.year > currentYear) {
|
|
37
|
+
issues.push({ recordId: record.recordId, code: 'implausible_year', severity: 'error', detail: `year ${record.year} is outside 1900–${currentYear}` });
|
|
38
|
+
}
|
|
39
|
+
if (record.pages !== undefined && !/^\d+([–-]\d+)?$/u.test(record.pages)) {
|
|
40
|
+
issues.push({ recordId: record.recordId, code: 'odd_pages', severity: 'warning', detail: `page range "${record.pages}" is not numeric` });
|
|
41
|
+
}
|
|
42
|
+
if (record.doi !== undefined && !DOI_PATTERN.test(record.doi)) {
|
|
43
|
+
issues.push({ recordId: record.recordId, code: 'malformed_doi', severity: 'warning', detail: `DOI "${record.doi}" does not look like 10.xxxx/…` });
|
|
44
|
+
}
|
|
45
|
+
if (record.type === 'journal' && record.volume === undefined && record.issue === undefined) {
|
|
46
|
+
issues.push({ recordId: record.recordId, code: 'missing_volume_issue', severity: 'info', detail: 'neither volume nor issue was imported' });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { records: records.length, issues, ok: !issues.some(issue => issue.severity === 'error') };
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=validate.js.map
|