jats-xml 0.0.13 → 0.0.14
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/dist/cjs/{download.js → cli/download.js} +10 -20
- package/dist/cjs/cli/parse.js +20 -3
- package/dist/cjs/index.js +1 -3
- package/dist/esm/{download.js → cli/download.js} +10 -20
- package/dist/esm/cli/parse.js +20 -3
- package/dist/esm/index.js +0 -1
- package/dist/jats.js +168 -163
- package/dist/types/{download.d.ts → cli/download.d.ts} +3 -2
- package/dist/types/cli/download.d.ts.map +1 -0
- package/dist/types/cli/parse.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/types/download.d.ts.map +0 -1
|
@@ -14,20 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.downloadJatsFromUrl = exports.checkIfPubMedCentralHasJats = exports.convertPMID2PMCID = void 0;
|
|
16
16
|
const doi_utils_1 = __importDefault(require("doi-utils"));
|
|
17
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
18
17
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
19
18
|
const myst_cli_utils_1 = require("myst-cli-utils");
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
function logAboutJatsFailing(session, jatsUrls) {
|
|
23
|
-
session.log.warn('⛔️ JATS may not be Open Access 😭, you should petition your local representative 🪧');
|
|
24
|
-
session.log.info(`${chalk_1.default.green(`\nThe XML ${chalk_1.default.bold('should')} be here:\n\n${jatsUrls.join('\n')}`)}\n`);
|
|
25
|
-
const FAIR = (0, fair_principles_1.highlightFAIR)('A', { chalk: chalk_1.default });
|
|
26
|
-
session.log.info(`Some publishers aggressively block programmatic access, which isn't ${FAIR}.`);
|
|
27
|
-
session.log.debug((0, fair_principles_1.formatPrinciples)('A*', { chalk: chalk_1.default }));
|
|
28
|
-
session.log.info(`${chalk_1.default.blue('The link may work in a browser.')}\n`);
|
|
29
|
-
}
|
|
30
|
-
function dowloadFromUrl(session, jatsUrl, opts) {
|
|
19
|
+
const resolvers_1 = require("../resolvers");
|
|
20
|
+
function downloadFromUrl(session, jatsUrl, opts) {
|
|
31
21
|
var _a, _b;
|
|
32
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
23
|
const toc = (0, myst_cli_utils_1.tic)();
|
|
@@ -41,7 +31,7 @@ function dowloadFromUrl(session, jatsUrl, opts) {
|
|
|
41
31
|
if (!((contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/xml')) ||
|
|
42
32
|
(contentType === null || contentType === void 0 ? void 0 : contentType.includes('text/xml')) ||
|
|
43
33
|
(contentType === null || contentType === void 0 ? void 0 : contentType.includes('text/plain')))) {
|
|
44
|
-
session.log.warn(`Expected content-type "application/xml" instead we got "${contentType}" for ${jatsUrl}
|
|
34
|
+
session.log.warn(`Expected content-type "application/xml" instead we got "${contentType}" for ${jatsUrl}`);
|
|
45
35
|
}
|
|
46
36
|
const data = yield resp.text();
|
|
47
37
|
session.log.debug(toc(`Fetched document with content-type "${contentType}" in %s`));
|
|
@@ -169,26 +159,26 @@ function downloadJatsFromUrl(session, urlOrDoi, opts = {}) {
|
|
|
169
159
|
for (let index = 0; index < expectedUrls.length; index++) {
|
|
170
160
|
const url = expectedUrls[index];
|
|
171
161
|
try {
|
|
172
|
-
const data = yield
|
|
162
|
+
const data = yield downloadFromUrl(session, url, opts);
|
|
173
163
|
if (data)
|
|
174
|
-
return { source: url, data };
|
|
164
|
+
return { success: true, source: url, data };
|
|
175
165
|
}
|
|
176
166
|
catch (error) {
|
|
177
167
|
session.log.debug(error.message);
|
|
178
168
|
}
|
|
179
169
|
}
|
|
180
170
|
// If there are expected URLs that don't work: see something, say something, etc.
|
|
181
|
-
|
|
171
|
+
return { success: false, source: expectedUrls[0] };
|
|
182
172
|
}
|
|
183
173
|
if (doi_utils_1.default.validate(urlOrDoi)) {
|
|
184
174
|
const jatsUrl = yield (0, resolvers_1.customResolveJatsUrlFromDoi)(session, urlOrDoi, opts);
|
|
185
|
-
const data = yield
|
|
186
|
-
return { source: jatsUrl, data };
|
|
175
|
+
const data = yield downloadFromUrl(session, jatsUrl, opts);
|
|
176
|
+
return { success: true, source: jatsUrl, data };
|
|
187
177
|
}
|
|
188
178
|
if ((0, myst_cli_utils_1.isUrl)(urlOrDoi)) {
|
|
189
179
|
session.log.debug("No resolver matched, and the URL doesn't look like a DOI. We will attempt to download it directly.");
|
|
190
|
-
const data = yield
|
|
191
|
-
return { source: urlOrDoi, data };
|
|
180
|
+
const data = yield downloadFromUrl(session, urlOrDoi, opts);
|
|
181
|
+
return { success: true, source: urlOrDoi, data };
|
|
192
182
|
}
|
|
193
183
|
throw new Error(`Could not find ${urlOrDoi} locally, and it doesn't look like a URL or DOI`);
|
|
194
184
|
});
|
package/dist/cjs/cli/parse.js
CHANGED
|
@@ -19,12 +19,13 @@ const path_1 = require("path");
|
|
|
19
19
|
const myst_cli_utils_1 = require("myst-cli-utils");
|
|
20
20
|
const doi_utils_1 = __importDefault(require("doi-utils"));
|
|
21
21
|
const chalk_1 = __importDefault(require("chalk"));
|
|
22
|
+
const fair_principles_1 = require("fair-principles");
|
|
22
23
|
const session_1 = require("../session");
|
|
23
24
|
const types_1 = require("../types");
|
|
24
25
|
const jats_1 = require("../jats");
|
|
25
26
|
const myst_common_1 = require("myst-common");
|
|
26
27
|
const unist_util_select_1 = require("unist-util-select");
|
|
27
|
-
const download_1 = require("
|
|
28
|
+
const download_1 = require("./download");
|
|
28
29
|
const resolvers_1 = require("../resolvers");
|
|
29
30
|
const utils_1 = require("../utils");
|
|
30
31
|
function hasValidExtension(output) {
|
|
@@ -41,11 +42,23 @@ function downloadAndSaveJats(session, urlOrDoi, output, opts = { resolvers: reso
|
|
|
41
42
|
if (!hasValidExtension(output)) {
|
|
42
43
|
session.log.warn(`The extension ${(0, path_1.extname)(output)} is not a valid extension for JATS, try using ".xml" or ".jats"`);
|
|
43
44
|
}
|
|
44
|
-
const { data } = yield (0, download_1.downloadJatsFromUrl)(session, urlOrDoi, opts);
|
|
45
|
+
const { success, data, source } = yield (0, download_1.downloadJatsFromUrl)(session, urlOrDoi, opts);
|
|
46
|
+
if (!success || !data) {
|
|
47
|
+
logAboutJatsFailing(session, [source]);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
45
50
|
(0, myst_cli_utils_1.writeFileToFolder)(output, data);
|
|
46
51
|
return data;
|
|
47
52
|
});
|
|
48
53
|
}
|
|
54
|
+
function logAboutJatsFailing(session, jatsUrls) {
|
|
55
|
+
session.log.warn('⛔️ JATS may not be Open Access 😭, you should petition your local representative 🪧');
|
|
56
|
+
session.log.info(`${chalk_1.default.green(`\nThe XML ${chalk_1.default.bold('should')} be here:\n\n${jatsUrls.join('\n')}`)}\n`);
|
|
57
|
+
const FAIR = (0, fair_principles_1.highlightFAIR)('A', { chalk: chalk_1.default });
|
|
58
|
+
session.log.info(`Some publishers aggressively block programmatic access, which isn't ${FAIR}.`);
|
|
59
|
+
session.log.debug((0, fair_principles_1.formatPrinciples)('A*', { chalk: chalk_1.default }));
|
|
60
|
+
session.log.info(`\n${chalk_1.default.blue('The link may work in a browser.')}\n`);
|
|
61
|
+
}
|
|
49
62
|
function parseJats(session, file, opts = { resolvers: resolvers_1.DEFAULT_RESOLVERS }) {
|
|
50
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
64
|
const toc = (0, myst_cli_utils_1.tic)();
|
|
@@ -54,7 +67,11 @@ function parseJats(session, file, opts = { resolvers: resolvers_1.DEFAULT_RESOLV
|
|
|
54
67
|
const data = fs_1.default.readFileSync(file).toString();
|
|
55
68
|
return new jats_1.Jats(data, { log: session.log });
|
|
56
69
|
}
|
|
57
|
-
const { source, data } = yield (0, download_1.downloadJatsFromUrl)(session, file, opts);
|
|
70
|
+
const { success, source, data } = yield (0, download_1.downloadJatsFromUrl)(session, file, opts);
|
|
71
|
+
if (!success || !data) {
|
|
72
|
+
logAboutJatsFailing(session, [source]);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
58
75
|
const jats = new jats_1.Jats(data, { source, log: session.log });
|
|
59
76
|
session.log.debug(toc(`Downloaded and parsed JATS file in %s`));
|
|
60
77
|
return jats;
|
package/dist/cjs/index.js
CHANGED
|
@@ -17,11 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.Jats = exports.version = void 0;
|
|
21
21
|
var version_1 = require("./version");
|
|
22
22
|
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return __importDefault(version_1).default; } });
|
|
23
23
|
var jats_1 = require("./jats");
|
|
24
24
|
Object.defineProperty(exports, "Jats", { enumerable: true, get: function () { return jats_1.Jats; } });
|
|
25
|
-
var download_1 = require("./download");
|
|
26
|
-
Object.defineProperty(exports, "downloadJatsFromUrl", { enumerable: true, get: function () { return download_1.downloadJatsFromUrl; } });
|
|
27
25
|
__exportStar(require("./types"), exports);
|
|
@@ -8,20 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import doi from 'doi-utils';
|
|
11
|
-
import chalk from 'chalk';
|
|
12
11
|
import fetch from 'node-fetch';
|
|
13
12
|
import { isUrl, tic } from 'myst-cli-utils';
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
function logAboutJatsFailing(session, jatsUrls) {
|
|
17
|
-
session.log.warn('⛔️ JATS may not be Open Access 😭, you should petition your local representative 🪧');
|
|
18
|
-
session.log.info(`${chalk.green(`\nThe XML ${chalk.bold('should')} be here:\n\n${jatsUrls.join('\n')}`)}\n`);
|
|
19
|
-
const FAIR = highlightFAIR('A', { chalk });
|
|
20
|
-
session.log.info(`Some publishers aggressively block programmatic access, which isn't ${FAIR}.`);
|
|
21
|
-
session.log.debug(formatPrinciples('A*', { chalk }));
|
|
22
|
-
session.log.info(`${chalk.blue('The link may work in a browser.')}\n`);
|
|
23
|
-
}
|
|
24
|
-
function dowloadFromUrl(session, jatsUrl, opts) {
|
|
13
|
+
import { customResolveJatsUrlFromDoi } from '../resolvers';
|
|
14
|
+
function downloadFromUrl(session, jatsUrl, opts) {
|
|
25
15
|
var _a, _b;
|
|
26
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
17
|
const toc = tic();
|
|
@@ -35,7 +25,7 @@ function dowloadFromUrl(session, jatsUrl, opts) {
|
|
|
35
25
|
if (!((contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/xml')) ||
|
|
36
26
|
(contentType === null || contentType === void 0 ? void 0 : contentType.includes('text/xml')) ||
|
|
37
27
|
(contentType === null || contentType === void 0 ? void 0 : contentType.includes('text/plain')))) {
|
|
38
|
-
session.log.warn(`Expected content-type "application/xml" instead we got "${contentType}" for ${jatsUrl}
|
|
28
|
+
session.log.warn(`Expected content-type "application/xml" instead we got "${contentType}" for ${jatsUrl}`);
|
|
39
29
|
}
|
|
40
30
|
const data = yield resp.text();
|
|
41
31
|
session.log.debug(toc(`Fetched document with content-type "${contentType}" in %s`));
|
|
@@ -161,26 +151,26 @@ export function downloadJatsFromUrl(session, urlOrDoi, opts = {}) {
|
|
|
161
151
|
for (let index = 0; index < expectedUrls.length; index++) {
|
|
162
152
|
const url = expectedUrls[index];
|
|
163
153
|
try {
|
|
164
|
-
const data = yield
|
|
154
|
+
const data = yield downloadFromUrl(session, url, opts);
|
|
165
155
|
if (data)
|
|
166
|
-
return { source: url, data };
|
|
156
|
+
return { success: true, source: url, data };
|
|
167
157
|
}
|
|
168
158
|
catch (error) {
|
|
169
159
|
session.log.debug(error.message);
|
|
170
160
|
}
|
|
171
161
|
}
|
|
172
162
|
// If there are expected URLs that don't work: see something, say something, etc.
|
|
173
|
-
|
|
163
|
+
return { success: false, source: expectedUrls[0] };
|
|
174
164
|
}
|
|
175
165
|
if (doi.validate(urlOrDoi)) {
|
|
176
166
|
const jatsUrl = yield customResolveJatsUrlFromDoi(session, urlOrDoi, opts);
|
|
177
|
-
const data = yield
|
|
178
|
-
return { source: jatsUrl, data };
|
|
167
|
+
const data = yield downloadFromUrl(session, jatsUrl, opts);
|
|
168
|
+
return { success: true, source: jatsUrl, data };
|
|
179
169
|
}
|
|
180
170
|
if (isUrl(urlOrDoi)) {
|
|
181
171
|
session.log.debug("No resolver matched, and the URL doesn't look like a DOI. We will attempt to download it directly.");
|
|
182
|
-
const data = yield
|
|
183
|
-
return { source: urlOrDoi, data };
|
|
172
|
+
const data = yield downloadFromUrl(session, urlOrDoi, opts);
|
|
173
|
+
return { success: true, source: urlOrDoi, data };
|
|
184
174
|
}
|
|
185
175
|
throw new Error(`Could not find ${urlOrDoi} locally, and it doesn't look like a URL or DOI`);
|
|
186
176
|
});
|
package/dist/esm/cli/parse.js
CHANGED
|
@@ -13,12 +13,13 @@ import { extname } from 'path';
|
|
|
13
13
|
import { clirun, isUrl, tic, writeFileToFolder } from 'myst-cli-utils';
|
|
14
14
|
import doi from 'doi-utils';
|
|
15
15
|
import chalk from 'chalk';
|
|
16
|
+
import { formatPrinciples, highlightFAIR } from 'fair-principles';
|
|
16
17
|
import { getSession } from '../session';
|
|
17
18
|
import { Tags } from '../types';
|
|
18
19
|
import { Jats } from '../jats';
|
|
19
20
|
import { toText } from 'myst-common';
|
|
20
21
|
import { select, selectAll } from 'unist-util-select';
|
|
21
|
-
import { downloadJatsFromUrl } from '
|
|
22
|
+
import { downloadJatsFromUrl } from './download';
|
|
22
23
|
import { DEFAULT_RESOLVERS } from '../resolvers';
|
|
23
24
|
import { findArticleId, formatDate, toDate } from '../utils';
|
|
24
25
|
function hasValidExtension(output) {
|
|
@@ -35,11 +36,23 @@ function downloadAndSaveJats(session, urlOrDoi, output, opts = { resolvers: DEFA
|
|
|
35
36
|
if (!hasValidExtension(output)) {
|
|
36
37
|
session.log.warn(`The extension ${extname(output)} is not a valid extension for JATS, try using ".xml" or ".jats"`);
|
|
37
38
|
}
|
|
38
|
-
const { data } = yield downloadJatsFromUrl(session, urlOrDoi, opts);
|
|
39
|
+
const { success, data, source } = yield downloadJatsFromUrl(session, urlOrDoi, opts);
|
|
40
|
+
if (!success || !data) {
|
|
41
|
+
logAboutJatsFailing(session, [source]);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
39
44
|
writeFileToFolder(output, data);
|
|
40
45
|
return data;
|
|
41
46
|
});
|
|
42
47
|
}
|
|
48
|
+
function logAboutJatsFailing(session, jatsUrls) {
|
|
49
|
+
session.log.warn('⛔️ JATS may not be Open Access 😭, you should petition your local representative 🪧');
|
|
50
|
+
session.log.info(`${chalk.green(`\nThe XML ${chalk.bold('should')} be here:\n\n${jatsUrls.join('\n')}`)}\n`);
|
|
51
|
+
const FAIR = highlightFAIR('A', { chalk });
|
|
52
|
+
session.log.info(`Some publishers aggressively block programmatic access, which isn't ${FAIR}.`);
|
|
53
|
+
session.log.debug(formatPrinciples('A*', { chalk }));
|
|
54
|
+
session.log.info(`\n${chalk.blue('The link may work in a browser.')}\n`);
|
|
55
|
+
}
|
|
43
56
|
function parseJats(session, file, opts = { resolvers: DEFAULT_RESOLVERS }) {
|
|
44
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
58
|
const toc = tic();
|
|
@@ -48,7 +61,11 @@ function parseJats(session, file, opts = { resolvers: DEFAULT_RESOLVERS }) {
|
|
|
48
61
|
const data = fs.readFileSync(file).toString();
|
|
49
62
|
return new Jats(data, { log: session.log });
|
|
50
63
|
}
|
|
51
|
-
const { source, data } = yield downloadJatsFromUrl(session, file, opts);
|
|
64
|
+
const { success, source, data } = yield downloadJatsFromUrl(session, file, opts);
|
|
65
|
+
if (!success || !data) {
|
|
66
|
+
logAboutJatsFailing(session, [source]);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
52
69
|
const jats = new Jats(data, { source, log: session.log });
|
|
53
70
|
session.log.debug(toc(`Downloaded and parsed JATS file in %s`));
|
|
54
71
|
return jats;
|
package/dist/esm/index.js
CHANGED
package/dist/jats.js
CHANGED
|
@@ -2961,14 +2961,14 @@ var require_templates = __commonJS({
|
|
|
2961
2961
|
}
|
|
2962
2962
|
return results;
|
|
2963
2963
|
}
|
|
2964
|
-
function buildStyle(
|
|
2964
|
+
function buildStyle(chalk3, styles) {
|
|
2965
2965
|
const enabled = {};
|
|
2966
2966
|
for (const layer of styles) {
|
|
2967
2967
|
for (const style of layer.styles) {
|
|
2968
2968
|
enabled[style[0]] = layer.inverse ? null : style.slice(1);
|
|
2969
2969
|
}
|
|
2970
2970
|
}
|
|
2971
|
-
let current =
|
|
2971
|
+
let current = chalk3;
|
|
2972
2972
|
for (const [styleName, styles2] of Object.entries(enabled)) {
|
|
2973
2973
|
if (!Array.isArray(styles2)) {
|
|
2974
2974
|
continue;
|
|
@@ -2980,7 +2980,7 @@ var require_templates = __commonJS({
|
|
|
2980
2980
|
}
|
|
2981
2981
|
return current;
|
|
2982
2982
|
}
|
|
2983
|
-
module2.exports = (
|
|
2983
|
+
module2.exports = (chalk3, temporary) => {
|
|
2984
2984
|
const styles = [];
|
|
2985
2985
|
const chunks = [];
|
|
2986
2986
|
let chunk = [];
|
|
@@ -2990,13 +2990,13 @@ var require_templates = __commonJS({
|
|
|
2990
2990
|
} else if (style) {
|
|
2991
2991
|
const string = chunk.join("");
|
|
2992
2992
|
chunk = [];
|
|
2993
|
-
chunks.push(styles.length === 0 ? string : buildStyle(
|
|
2993
|
+
chunks.push(styles.length === 0 ? string : buildStyle(chalk3, styles)(string));
|
|
2994
2994
|
styles.push({ inverse, styles: parseStyle(style) });
|
|
2995
2995
|
} else if (close) {
|
|
2996
2996
|
if (styles.length === 0) {
|
|
2997
2997
|
throw new Error("Found extraneous } in Chalk template literal");
|
|
2998
2998
|
}
|
|
2999
|
-
chunks.push(buildStyle(
|
|
2999
|
+
chunks.push(buildStyle(chalk3, styles)(chunk.join("")));
|
|
3000
3000
|
chunk = [];
|
|
3001
3001
|
styles.pop();
|
|
3002
3002
|
} else {
|
|
@@ -3044,16 +3044,16 @@ var require_source = __commonJS({
|
|
|
3044
3044
|
}
|
|
3045
3045
|
};
|
|
3046
3046
|
var chalkFactory = (options) => {
|
|
3047
|
-
const
|
|
3048
|
-
applyOptions(
|
|
3049
|
-
|
|
3050
|
-
Object.setPrototypeOf(
|
|
3051
|
-
Object.setPrototypeOf(
|
|
3052
|
-
|
|
3047
|
+
const chalk4 = {};
|
|
3048
|
+
applyOptions(chalk4, options);
|
|
3049
|
+
chalk4.template = (...arguments_) => chalkTag(chalk4.template, ...arguments_);
|
|
3050
|
+
Object.setPrototypeOf(chalk4, Chalk.prototype);
|
|
3051
|
+
Object.setPrototypeOf(chalk4.template, chalk4);
|
|
3052
|
+
chalk4.template.constructor = () => {
|
|
3053
3053
|
throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.");
|
|
3054
3054
|
};
|
|
3055
|
-
|
|
3056
|
-
return
|
|
3055
|
+
chalk4.template.Instance = ChalkClass;
|
|
3056
|
+
return chalk4.template;
|
|
3057
3057
|
};
|
|
3058
3058
|
function Chalk(options) {
|
|
3059
3059
|
return chalkFactory(options);
|
|
@@ -3164,7 +3164,7 @@ var require_source = __commonJS({
|
|
|
3164
3164
|
return openAll + string + closeAll;
|
|
3165
3165
|
};
|
|
3166
3166
|
var template;
|
|
3167
|
-
var chalkTag = (
|
|
3167
|
+
var chalkTag = (chalk4, ...strings) => {
|
|
3168
3168
|
const [firstString] = strings;
|
|
3169
3169
|
if (!isArray(firstString) || !isArray(firstString.raw)) {
|
|
3170
3170
|
return strings.join(" ");
|
|
@@ -3180,14 +3180,14 @@ var require_source = __commonJS({
|
|
|
3180
3180
|
if (template === void 0) {
|
|
3181
3181
|
template = require_templates();
|
|
3182
3182
|
}
|
|
3183
|
-
return template(
|
|
3183
|
+
return template(chalk4, parts.join(""));
|
|
3184
3184
|
};
|
|
3185
3185
|
Object.defineProperties(Chalk.prototype, styles);
|
|
3186
|
-
var
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
module2.exports =
|
|
3186
|
+
var chalk3 = Chalk();
|
|
3187
|
+
chalk3.supportsColor = stdoutColor;
|
|
3188
|
+
chalk3.stderr = Chalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
3189
|
+
chalk3.stderr.supportsColor = stderrColor;
|
|
3190
|
+
module2.exports = chalk3;
|
|
3191
3191
|
}
|
|
3192
3192
|
});
|
|
3193
3193
|
|
|
@@ -3421,6 +3421,99 @@ var require_cjs = __commonJS({
|
|
|
3421
3421
|
}
|
|
3422
3422
|
});
|
|
3423
3423
|
|
|
3424
|
+
// node_modules/fair-principles/dist/cjs/index.js
|
|
3425
|
+
var require_cjs2 = __commonJS({
|
|
3426
|
+
"node_modules/fair-principles/dist/cjs/index.js"(exports) {
|
|
3427
|
+
"use strict";
|
|
3428
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3429
|
+
exports.createPrincipleUrl = exports.formatPrinciples = exports.formatPrinciple = exports.principles = exports.principleNames = exports.highlightFAIR = void 0;
|
|
3430
|
+
function format(text) {
|
|
3431
|
+
return text;
|
|
3432
|
+
}
|
|
3433
|
+
var highlightFAIR2 = (letter, opts) => {
|
|
3434
|
+
var _a, _b, _c;
|
|
3435
|
+
const l = letter.toLowerCase();
|
|
3436
|
+
const color = (_c = (_a = opts === null || opts === void 0 ? void 0 : opts.color) !== null && _a !== void 0 ? _a : (_b = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _b === void 0 ? void 0 : _b.red) !== null && _c !== void 0 ? _c : format;
|
|
3437
|
+
return [
|
|
3438
|
+
l.includes("f") ? color("F") : "F",
|
|
3439
|
+
l.includes("a") ? color("A") : "A",
|
|
3440
|
+
l.includes("i") ? color("I") : "I",
|
|
3441
|
+
l.includes("r") ? color("R") : "R"
|
|
3442
|
+
].join("");
|
|
3443
|
+
};
|
|
3444
|
+
exports.highlightFAIR = highlightFAIR2;
|
|
3445
|
+
exports.principleNames = {
|
|
3446
|
+
F: "Findable",
|
|
3447
|
+
A: "Accessible",
|
|
3448
|
+
I: "Interoperable",
|
|
3449
|
+
R: "Reusable"
|
|
3450
|
+
};
|
|
3451
|
+
exports.principles = {
|
|
3452
|
+
F: "The first step in (re)using data is to find them. Metadata and data should be easy to find for both humans and computers. Machine-readable metadata are essential for automatic discovery of datasets and services, so this is an essential component of the FAIRification process.",
|
|
3453
|
+
F1: "(Meta)data are assigned a globally unique and persistent identifier",
|
|
3454
|
+
F2: "Data are described with rich metadata (defined by R1 below)",
|
|
3455
|
+
F3: "Metadata clearly and explicitly include the identifier of the data they describe",
|
|
3456
|
+
F4: "(Meta)data are registered or indexed in a searchable resource",
|
|
3457
|
+
A: "Once the user finds the required data, she/he/they need to know how they can be accessed, possibly including authentication and authorisation.",
|
|
3458
|
+
A1: "(Meta)data are retrievable by their identifier using a standardised communications protocol",
|
|
3459
|
+
A1_1: "The protocol is open, free, and universally implementable",
|
|
3460
|
+
A1_2: "The protocol allows for an authentication and authorisation procedure, where necessary",
|
|
3461
|
+
A2: "Metadata are accessible, even when the data are no longer available",
|
|
3462
|
+
I: "The data usually need to be integrated with other data. In addition, the data need to interoperate with applications or workflows for analysis, storage, and processing.",
|
|
3463
|
+
I1: "(Meta)data use a formal, accessible, shared, and broadly applicable language for knowledge representation.",
|
|
3464
|
+
I2: "(Meta)data use vocabularies that follow FAIR principles",
|
|
3465
|
+
I3: "(Meta)data include qualified references to other (meta)data",
|
|
3466
|
+
R: "The ultimate goal of FAIR is to optimise the reuse of data. To achieve this, metadata and data should be well-described so that they can be replicated and/or combined in different settings.",
|
|
3467
|
+
R1: "(Meta)data are richly described with a plurality of accurate and relevant attributes",
|
|
3468
|
+
R1_1: "(Meta)data are released with a clear and accessible data usage license",
|
|
3469
|
+
R1_2: "(Meta)data are associated with detailed provenance",
|
|
3470
|
+
R1_3: "(Meta)data meet domain-relevant community standards"
|
|
3471
|
+
};
|
|
3472
|
+
var principleKeys = Object.keys(exports.principles);
|
|
3473
|
+
var mustExist = 'Principle does not exist, try "A1_1"';
|
|
3474
|
+
function formatPrinciple(principle, opts) {
|
|
3475
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3476
|
+
if (!(principle in exports.principles))
|
|
3477
|
+
throw new Error(mustExist);
|
|
3478
|
+
const key = principle.replace(/_/g, ".");
|
|
3479
|
+
const header = exports.principleNames[principle];
|
|
3480
|
+
const colorHeader = (_c = (_a = opts === null || opts === void 0 ? void 0 : opts.header) !== null && _a !== void 0 ? _a : (_b = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _b === void 0 ? void 0 : _b.bold.cyan) !== null && _c !== void 0 ? _c : format;
|
|
3481
|
+
const underline = (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _d === void 0 ? void 0 : _d.underline) !== null && _e !== void 0 ? _e : format;
|
|
3482
|
+
const enumerator = (_h = (_f = opts === null || opts === void 0 ? void 0 : opts.enumerator) !== null && _f !== void 0 ? _f : (_g = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _g === void 0 ? void 0 : _g.bold.blue) !== null && _h !== void 0 ? _h : format;
|
|
3483
|
+
if (header && (opts === null || opts === void 0 ? void 0 : opts.showHeader) !== false) {
|
|
3484
|
+
return [
|
|
3485
|
+
colorHeader(`${underline(header.slice(0, 1))}${header.slice(1)}`),
|
|
3486
|
+
exports.principles[principle]
|
|
3487
|
+
].join("\n");
|
|
3488
|
+
}
|
|
3489
|
+
const indent = principle.includes("_") && (opts === null || opts === void 0 ? void 0 : opts.indent) !== false;
|
|
3490
|
+
return `${indent ? " " : ""}${enumerator(key)} ${exports.principles[principle]}`;
|
|
3491
|
+
}
|
|
3492
|
+
exports.formatPrinciple = formatPrinciple;
|
|
3493
|
+
function formatPrinciples2(keys = "*", opts) {
|
|
3494
|
+
var _a, _b, _c, _d, _e;
|
|
3495
|
+
const input = typeof keys === "string" ? [keys] : keys;
|
|
3496
|
+
const ordered = principleKeys.filter((key) => input.includes("*") || input.includes(key) || input.includes(key.slice(0, 1) + "*"));
|
|
3497
|
+
const colorTitle = (_c = (_a = opts === null || opts === void 0 ? void 0 : opts.title) !== null && _a !== void 0 ? _a : (_b = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _b === void 0 ? void 0 : _b.bold.greenBright) !== null && _c !== void 0 ? _c : format;
|
|
3498
|
+
const underline = (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _d === void 0 ? void 0 : _d.underline) !== null && _e !== void 0 ? _e : format;
|
|
3499
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.showTitle) === false)
|
|
3500
|
+
return ordered.map((k) => formatPrinciple(k, opts)).join("\n");
|
|
3501
|
+
const header = `${colorTitle(`${(0, exports.highlightFAIR)(ordered.join(""), { color: underline })} Principle${ordered.length > 1 ? "s" : ""}`)}:`;
|
|
3502
|
+
return [header, ...ordered.map((k) => formatPrinciple(k, opts))].join("\n");
|
|
3503
|
+
}
|
|
3504
|
+
exports.formatPrinciples = formatPrinciples2;
|
|
3505
|
+
var baseUrl = "https://www.go-fair.org/fair-principles/";
|
|
3506
|
+
function createPrincipleUrl(principle) {
|
|
3507
|
+
if (!principle)
|
|
3508
|
+
return baseUrl;
|
|
3509
|
+
if (!(principle in exports.principles))
|
|
3510
|
+
throw new Error(mustExist);
|
|
3511
|
+
return `${baseUrl}${principle.toLowerCase().replace(/_/g, "-")}`;
|
|
3512
|
+
}
|
|
3513
|
+
exports.createPrincipleUrl = createPrincipleUrl;
|
|
3514
|
+
}
|
|
3515
|
+
});
|
|
3516
|
+
|
|
3424
3517
|
// node_modules/unist-util-map/index.js
|
|
3425
3518
|
var unist_util_map_exports = {};
|
|
3426
3519
|
__export(unist_util_map_exports, {
|
|
@@ -5017,7 +5110,7 @@ var require_templates2 = __commonJS({
|
|
|
5017
5110
|
});
|
|
5018
5111
|
|
|
5019
5112
|
// node_modules/myst-common/dist/cjs/index.js
|
|
5020
|
-
var
|
|
5113
|
+
var require_cjs3 = __commonJS({
|
|
5021
5114
|
"node_modules/myst-common/dist/cjs/index.js"(exports) {
|
|
5022
5115
|
"use strict";
|
|
5023
5116
|
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
@@ -10103,99 +10196,6 @@ var require_lib4 = __commonJS({
|
|
|
10103
10196
|
}
|
|
10104
10197
|
});
|
|
10105
10198
|
|
|
10106
|
-
// node_modules/fair-principles/dist/cjs/index.js
|
|
10107
|
-
var require_cjs3 = __commonJS({
|
|
10108
|
-
"node_modules/fair-principles/dist/cjs/index.js"(exports) {
|
|
10109
|
-
"use strict";
|
|
10110
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10111
|
-
exports.createPrincipleUrl = exports.formatPrinciples = exports.formatPrinciple = exports.principles = exports.principleNames = exports.highlightFAIR = void 0;
|
|
10112
|
-
function format(text) {
|
|
10113
|
-
return text;
|
|
10114
|
-
}
|
|
10115
|
-
var highlightFAIR2 = (letter, opts) => {
|
|
10116
|
-
var _a, _b, _c;
|
|
10117
|
-
const l = letter.toLowerCase();
|
|
10118
|
-
const color = (_c = (_a = opts === null || opts === void 0 ? void 0 : opts.color) !== null && _a !== void 0 ? _a : (_b = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _b === void 0 ? void 0 : _b.red) !== null && _c !== void 0 ? _c : format;
|
|
10119
|
-
return [
|
|
10120
|
-
l.includes("f") ? color("F") : "F",
|
|
10121
|
-
l.includes("a") ? color("A") : "A",
|
|
10122
|
-
l.includes("i") ? color("I") : "I",
|
|
10123
|
-
l.includes("r") ? color("R") : "R"
|
|
10124
|
-
].join("");
|
|
10125
|
-
};
|
|
10126
|
-
exports.highlightFAIR = highlightFAIR2;
|
|
10127
|
-
exports.principleNames = {
|
|
10128
|
-
F: "Findable",
|
|
10129
|
-
A: "Accessible",
|
|
10130
|
-
I: "Interoperable",
|
|
10131
|
-
R: "Reusable"
|
|
10132
|
-
};
|
|
10133
|
-
exports.principles = {
|
|
10134
|
-
F: "The first step in (re)using data is to find them. Metadata and data should be easy to find for both humans and computers. Machine-readable metadata are essential for automatic discovery of datasets and services, so this is an essential component of the FAIRification process.",
|
|
10135
|
-
F1: "(Meta)data are assigned a globally unique and persistent identifier",
|
|
10136
|
-
F2: "Data are described with rich metadata (defined by R1 below)",
|
|
10137
|
-
F3: "Metadata clearly and explicitly include the identifier of the data they describe",
|
|
10138
|
-
F4: "(Meta)data are registered or indexed in a searchable resource",
|
|
10139
|
-
A: "Once the user finds the required data, she/he/they need to know how they can be accessed, possibly including authentication and authorisation.",
|
|
10140
|
-
A1: "(Meta)data are retrievable by their identifier using a standardised communications protocol",
|
|
10141
|
-
A1_1: "The protocol is open, free, and universally implementable",
|
|
10142
|
-
A1_2: "The protocol allows for an authentication and authorisation procedure, where necessary",
|
|
10143
|
-
A2: "Metadata are accessible, even when the data are no longer available",
|
|
10144
|
-
I: "The data usually need to be integrated with other data. In addition, the data need to interoperate with applications or workflows for analysis, storage, and processing.",
|
|
10145
|
-
I1: "(Meta)data use a formal, accessible, shared, and broadly applicable language for knowledge representation.",
|
|
10146
|
-
I2: "(Meta)data use vocabularies that follow FAIR principles",
|
|
10147
|
-
I3: "(Meta)data include qualified references to other (meta)data",
|
|
10148
|
-
R: "The ultimate goal of FAIR is to optimise the reuse of data. To achieve this, metadata and data should be well-described so that they can be replicated and/or combined in different settings.",
|
|
10149
|
-
R1: "(Meta)data are richly described with a plurality of accurate and relevant attributes",
|
|
10150
|
-
R1_1: "(Meta)data are released with a clear and accessible data usage license",
|
|
10151
|
-
R1_2: "(Meta)data are associated with detailed provenance",
|
|
10152
|
-
R1_3: "(Meta)data meet domain-relevant community standards"
|
|
10153
|
-
};
|
|
10154
|
-
var principleKeys = Object.keys(exports.principles);
|
|
10155
|
-
var mustExist = 'Principle does not exist, try "A1_1"';
|
|
10156
|
-
function formatPrinciple(principle, opts) {
|
|
10157
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
10158
|
-
if (!(principle in exports.principles))
|
|
10159
|
-
throw new Error(mustExist);
|
|
10160
|
-
const key = principle.replace(/_/g, ".");
|
|
10161
|
-
const header = exports.principleNames[principle];
|
|
10162
|
-
const colorHeader = (_c = (_a = opts === null || opts === void 0 ? void 0 : opts.header) !== null && _a !== void 0 ? _a : (_b = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _b === void 0 ? void 0 : _b.bold.cyan) !== null && _c !== void 0 ? _c : format;
|
|
10163
|
-
const underline = (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _d === void 0 ? void 0 : _d.underline) !== null && _e !== void 0 ? _e : format;
|
|
10164
|
-
const enumerator = (_h = (_f = opts === null || opts === void 0 ? void 0 : opts.enumerator) !== null && _f !== void 0 ? _f : (_g = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _g === void 0 ? void 0 : _g.bold.blue) !== null && _h !== void 0 ? _h : format;
|
|
10165
|
-
if (header && (opts === null || opts === void 0 ? void 0 : opts.showHeader) !== false) {
|
|
10166
|
-
return [
|
|
10167
|
-
colorHeader(`${underline(header.slice(0, 1))}${header.slice(1)}`),
|
|
10168
|
-
exports.principles[principle]
|
|
10169
|
-
].join("\n");
|
|
10170
|
-
}
|
|
10171
|
-
const indent = principle.includes("_") && (opts === null || opts === void 0 ? void 0 : opts.indent) !== false;
|
|
10172
|
-
return `${indent ? " " : ""}${enumerator(key)} ${exports.principles[principle]}`;
|
|
10173
|
-
}
|
|
10174
|
-
exports.formatPrinciple = formatPrinciple;
|
|
10175
|
-
function formatPrinciples2(keys = "*", opts) {
|
|
10176
|
-
var _a, _b, _c, _d, _e;
|
|
10177
|
-
const input = typeof keys === "string" ? [keys] : keys;
|
|
10178
|
-
const ordered = principleKeys.filter((key) => input.includes("*") || input.includes(key) || input.includes(key.slice(0, 1) + "*"));
|
|
10179
|
-
const colorTitle = (_c = (_a = opts === null || opts === void 0 ? void 0 : opts.title) !== null && _a !== void 0 ? _a : (_b = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _b === void 0 ? void 0 : _b.bold.greenBright) !== null && _c !== void 0 ? _c : format;
|
|
10180
|
-
const underline = (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.chalk) === null || _d === void 0 ? void 0 : _d.underline) !== null && _e !== void 0 ? _e : format;
|
|
10181
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.showTitle) === false)
|
|
10182
|
-
return ordered.map((k) => formatPrinciple(k, opts)).join("\n");
|
|
10183
|
-
const header = `${colorTitle(`${(0, exports.highlightFAIR)(ordered.join(""), { color: underline })} Principle${ordered.length > 1 ? "s" : ""}`)}:`;
|
|
10184
|
-
return [header, ...ordered.map((k) => formatPrinciple(k, opts))].join("\n");
|
|
10185
|
-
}
|
|
10186
|
-
exports.formatPrinciples = formatPrinciples2;
|
|
10187
|
-
var baseUrl = "https://www.go-fair.org/fair-principles/";
|
|
10188
|
-
function createPrincipleUrl(principle) {
|
|
10189
|
-
if (!principle)
|
|
10190
|
-
return baseUrl;
|
|
10191
|
-
if (!(principle in exports.principles))
|
|
10192
|
-
throw new Error(mustExist);
|
|
10193
|
-
return `${baseUrl}${principle.toLowerCase().replace(/_/g, "-")}`;
|
|
10194
|
-
}
|
|
10195
|
-
exports.createPrincipleUrl = createPrincipleUrl;
|
|
10196
|
-
}
|
|
10197
|
-
});
|
|
10198
|
-
|
|
10199
10199
|
// src/cli/index.ts
|
|
10200
10200
|
var import_commander2 = __toESM(require_commander());
|
|
10201
10201
|
|
|
@@ -10343,7 +10343,8 @@ function writeFileToFolder(filename, data, opts) {
|
|
|
10343
10343
|
|
|
10344
10344
|
// src/cli/parse.ts
|
|
10345
10345
|
var import_doi_utils5 = __toESM(require_cjs());
|
|
10346
|
-
var
|
|
10346
|
+
var import_chalk2 = __toESM(require_source());
|
|
10347
|
+
var import_fair_principles = __toESM(require_cjs2());
|
|
10347
10348
|
|
|
10348
10349
|
// src/session.ts
|
|
10349
10350
|
var Session = class {
|
|
@@ -10357,12 +10358,12 @@ function getSession(logger) {
|
|
|
10357
10358
|
}
|
|
10358
10359
|
|
|
10359
10360
|
// src/jats.ts
|
|
10360
|
-
var import_myst_common2 = __toESM(
|
|
10361
|
+
var import_myst_common2 = __toESM(require_cjs3());
|
|
10361
10362
|
var import_xml_js = __toESM(require_lib2());
|
|
10362
10363
|
var import_doi_utils2 = __toESM(require_cjs());
|
|
10363
10364
|
|
|
10364
10365
|
// src/utils.ts
|
|
10365
|
-
var import_myst_common = __toESM(
|
|
10366
|
+
var import_myst_common = __toESM(require_cjs3());
|
|
10366
10367
|
var import_doi_utils = __toESM(require_cjs());
|
|
10367
10368
|
init_unist_util_select();
|
|
10368
10369
|
function convertToUnist(node) {
|
|
@@ -10615,14 +10616,12 @@ function hasSingleArticle(element) {
|
|
|
10615
10616
|
}
|
|
10616
10617
|
|
|
10617
10618
|
// src/cli/parse.ts
|
|
10618
|
-
var import_myst_common3 = __toESM(
|
|
10619
|
+
var import_myst_common3 = __toESM(require_cjs3());
|
|
10619
10620
|
init_unist_util_select();
|
|
10620
10621
|
|
|
10621
|
-
// src/download.ts
|
|
10622
|
+
// src/cli/download.ts
|
|
10622
10623
|
var import_doi_utils4 = __toESM(require_cjs());
|
|
10623
|
-
var import_chalk2 = __toESM(require_source());
|
|
10624
10624
|
var import_node_fetch2 = __toESM(require_lib4());
|
|
10625
|
-
var import_fair_principles = __toESM(require_cjs3());
|
|
10626
10625
|
|
|
10627
10626
|
// src/resolvers.ts
|
|
10628
10627
|
var import_doi_utils3 = __toESM(require_cjs());
|
|
@@ -10673,25 +10672,8 @@ function customResolveJatsUrlFromDoi(_0, _1) {
|
|
|
10673
10672
|
});
|
|
10674
10673
|
}
|
|
10675
10674
|
|
|
10676
|
-
// src/download.ts
|
|
10677
|
-
function
|
|
10678
|
-
session.log.warn(
|
|
10679
|
-
"\u26D4\uFE0F JATS may not be Open Access \u{1F62D}, you should petition your local representative \u{1FAA7}"
|
|
10680
|
-
);
|
|
10681
|
-
session.log.info(
|
|
10682
|
-
`${import_chalk2.default.green(`
|
|
10683
|
-
The XML ${import_chalk2.default.bold("should")} be here:
|
|
10684
|
-
|
|
10685
|
-
${jatsUrls.join("\n")}`)}
|
|
10686
|
-
`
|
|
10687
|
-
);
|
|
10688
|
-
const FAIR = (0, import_fair_principles.highlightFAIR)("A", { chalk: import_chalk2.default });
|
|
10689
|
-
session.log.info(`Some publishers aggressively block programmatic access, which isn't ${FAIR}.`);
|
|
10690
|
-
session.log.debug((0, import_fair_principles.formatPrinciples)("A*", { chalk: import_chalk2.default }));
|
|
10691
|
-
session.log.info(`${import_chalk2.default.blue("The link may work in a browser.")}
|
|
10692
|
-
`);
|
|
10693
|
-
}
|
|
10694
|
-
function dowloadFromUrl(session, jatsUrl, opts) {
|
|
10675
|
+
// src/cli/download.ts
|
|
10676
|
+
function downloadFromUrl(session, jatsUrl, opts) {
|
|
10695
10677
|
return __async(this, null, function* () {
|
|
10696
10678
|
var _a, _b;
|
|
10697
10679
|
const toc = tic();
|
|
@@ -10704,10 +10686,7 @@ function dowloadFromUrl(session, jatsUrl, opts) {
|
|
|
10704
10686
|
const contentType = (_b = resp.headers) == null ? void 0 : _b.get("content-type");
|
|
10705
10687
|
if (!((contentType == null ? void 0 : contentType.includes("application/xml")) || (contentType == null ? void 0 : contentType.includes("text/xml")) || (contentType == null ? void 0 : contentType.includes("text/plain")))) {
|
|
10706
10688
|
session.log.warn(
|
|
10707
|
-
`Expected content-type "application/xml" instead we got "${contentType}" for ${jatsUrl}
|
|
10708
|
-
${import_chalk2.default.dim(
|
|
10709
|
-
"Things may not work, but we are going to try our best..."
|
|
10710
|
-
)}`
|
|
10689
|
+
`Expected content-type "application/xml" instead we got "${contentType}" for ${jatsUrl}`
|
|
10711
10690
|
);
|
|
10712
10691
|
}
|
|
10713
10692
|
const data = yield resp.text();
|
|
@@ -10837,26 +10816,26 @@ function downloadJatsFromUrl(_0, _1) {
|
|
|
10837
10816
|
for (let index = 0; index < expectedUrls.length; index++) {
|
|
10838
10817
|
const url = expectedUrls[index];
|
|
10839
10818
|
try {
|
|
10840
|
-
const data = yield
|
|
10819
|
+
const data = yield downloadFromUrl(session, url, opts);
|
|
10841
10820
|
if (data)
|
|
10842
|
-
return { source: url, data };
|
|
10821
|
+
return { success: true, source: url, data };
|
|
10843
10822
|
} catch (error) {
|
|
10844
10823
|
session.log.debug(error.message);
|
|
10845
10824
|
}
|
|
10846
10825
|
}
|
|
10847
|
-
|
|
10826
|
+
return { success: false, source: expectedUrls[0] };
|
|
10848
10827
|
}
|
|
10849
10828
|
if (import_doi_utils4.default.validate(urlOrDoi)) {
|
|
10850
10829
|
const jatsUrl = yield customResolveJatsUrlFromDoi(session, urlOrDoi, opts);
|
|
10851
|
-
const data = yield
|
|
10852
|
-
return { source: jatsUrl, data };
|
|
10830
|
+
const data = yield downloadFromUrl(session, jatsUrl, opts);
|
|
10831
|
+
return { success: true, source: jatsUrl, data };
|
|
10853
10832
|
}
|
|
10854
10833
|
if (isUrl(urlOrDoi)) {
|
|
10855
10834
|
session.log.debug(
|
|
10856
10835
|
"No resolver matched, and the URL doesn't look like a DOI. We will attempt to download it directly."
|
|
10857
10836
|
);
|
|
10858
|
-
const data = yield
|
|
10859
|
-
return { source: urlOrDoi, data };
|
|
10837
|
+
const data = yield downloadFromUrl(session, urlOrDoi, opts);
|
|
10838
|
+
return { success: true, source: urlOrDoi, data };
|
|
10860
10839
|
}
|
|
10861
10840
|
throw new Error(`Could not find ${urlOrDoi} locally, and it doesn't look like a URL or DOI`);
|
|
10862
10841
|
});
|
|
@@ -10881,11 +10860,33 @@ function downloadAndSaveJats(_0, _1, _2) {
|
|
|
10881
10860
|
)} is not a valid extension for JATS, try using ".xml" or ".jats"`
|
|
10882
10861
|
);
|
|
10883
10862
|
}
|
|
10884
|
-
const { data } = yield downloadJatsFromUrl(session, urlOrDoi, opts);
|
|
10863
|
+
const { success, data, source } = yield downloadJatsFromUrl(session, urlOrDoi, opts);
|
|
10864
|
+
if (!success || !data) {
|
|
10865
|
+
logAboutJatsFailing(session, [source]);
|
|
10866
|
+
process.exit(1);
|
|
10867
|
+
}
|
|
10885
10868
|
writeFileToFolder(output, data);
|
|
10886
10869
|
return data;
|
|
10887
10870
|
});
|
|
10888
10871
|
}
|
|
10872
|
+
function logAboutJatsFailing(session, jatsUrls) {
|
|
10873
|
+
session.log.warn(
|
|
10874
|
+
"\u26D4\uFE0F JATS may not be Open Access \u{1F62D}, you should petition your local representative \u{1FAA7}"
|
|
10875
|
+
);
|
|
10876
|
+
session.log.info(
|
|
10877
|
+
`${import_chalk2.default.green(`
|
|
10878
|
+
The XML ${import_chalk2.default.bold("should")} be here:
|
|
10879
|
+
|
|
10880
|
+
${jatsUrls.join("\n")}`)}
|
|
10881
|
+
`
|
|
10882
|
+
);
|
|
10883
|
+
const FAIR = (0, import_fair_principles.highlightFAIR)("A", { chalk: import_chalk2.default });
|
|
10884
|
+
session.log.info(`Some publishers aggressively block programmatic access, which isn't ${FAIR}.`);
|
|
10885
|
+
session.log.debug((0, import_fair_principles.formatPrinciples)("A*", { chalk: import_chalk2.default }));
|
|
10886
|
+
session.log.info(`
|
|
10887
|
+
${import_chalk2.default.blue("The link may work in a browser.")}
|
|
10888
|
+
`);
|
|
10889
|
+
}
|
|
10889
10890
|
function parseJats(_0, _1) {
|
|
10890
10891
|
return __async(this, arguments, function* (session, file, opts = { resolvers: DEFAULT_RESOLVERS }) {
|
|
10891
10892
|
const toc = tic();
|
|
@@ -10894,7 +10895,11 @@ function parseJats(_0, _1) {
|
|
|
10894
10895
|
const data2 = import_fs2.default.readFileSync(file).toString();
|
|
10895
10896
|
return new Jats(data2, { log: session.log });
|
|
10896
10897
|
}
|
|
10897
|
-
const { source, data } = yield downloadJatsFromUrl(session, file, opts);
|
|
10898
|
+
const { success, source, data } = yield downloadJatsFromUrl(session, file, opts);
|
|
10899
|
+
if (!success || !data) {
|
|
10900
|
+
logAboutJatsFailing(session, [source]);
|
|
10901
|
+
process.exit(1);
|
|
10902
|
+
}
|
|
10898
10903
|
const jats = new Jats(data, { source, log: session.log });
|
|
10899
10904
|
session.log.debug(toc(`Downloaded and parsed JATS file in %s`));
|
|
10900
10905
|
return jats;
|
|
@@ -10920,7 +10925,7 @@ function formatDictionary(dict, opts) {
|
|
|
10920
10925
|
return null;
|
|
10921
10926
|
let wrap = typeof (opts == null ? void 0 : opts.wrap) === "boolean" ? opts.wrap : true;
|
|
10922
10927
|
let value = t;
|
|
10923
|
-
let color =
|
|
10928
|
+
let color = import_chalk2.default.yellow.bold;
|
|
10924
10929
|
if (t && typeof t === "object") {
|
|
10925
10930
|
if (!t.value)
|
|
10926
10931
|
return null;
|
|
@@ -10948,35 +10953,35 @@ function jatsSummaryCLI(session, file) {
|
|
|
10948
10953
|
};
|
|
10949
10954
|
if (jats.body) {
|
|
10950
10955
|
summary.Figures = {
|
|
10951
|
-
label:
|
|
10956
|
+
label: import_chalk2.default.blue.bold,
|
|
10952
10957
|
value: String(selectAll("fig" /* fig */, jats.body).length)
|
|
10953
10958
|
};
|
|
10954
10959
|
summary.Equations = {
|
|
10955
|
-
label:
|
|
10960
|
+
label: import_chalk2.default.blue.bold,
|
|
10956
10961
|
value: String(selectAll("disp-formula" /* dispFormula */, jats.body).length)
|
|
10957
10962
|
};
|
|
10958
10963
|
summary.Tables = {
|
|
10959
|
-
label:
|
|
10964
|
+
label: import_chalk2.default.blue.bold,
|
|
10960
10965
|
value: String(selectAll("table" /* table */, jats.body).length)
|
|
10961
10966
|
};
|
|
10962
10967
|
summary.Code = {
|
|
10963
|
-
label:
|
|
10968
|
+
label: import_chalk2.default.blue.bold,
|
|
10964
10969
|
value: String(selectAll("code" /* code */, jats.body).length)
|
|
10965
10970
|
};
|
|
10966
10971
|
summary.Sections = {
|
|
10967
|
-
label:
|
|
10972
|
+
label: import_chalk2.default.blue.bold,
|
|
10968
10973
|
value: String(selectAll("sec" /* sec */, jats.body).length)
|
|
10969
10974
|
};
|
|
10970
10975
|
summary.Paragraphs = {
|
|
10971
|
-
label:
|
|
10976
|
+
label: import_chalk2.default.blue.bold,
|
|
10972
10977
|
value: String(selectAll("p" /* p */, jats.body).length)
|
|
10973
10978
|
};
|
|
10974
|
-
summary.Citations = { label:
|
|
10979
|
+
summary.Citations = { label: import_chalk2.default.blue.bold, value: String(jats.references.length) };
|
|
10975
10980
|
summary["Cross-References"] = {
|
|
10976
|
-
label:
|
|
10981
|
+
label: import_chalk2.default.blue.bold,
|
|
10977
10982
|
value: String(selectAll("xref" /* xref */, jats.body).length)
|
|
10978
10983
|
};
|
|
10979
|
-
summary["Sub Articles"] = { label:
|
|
10984
|
+
summary["Sub Articles"] = { label: import_chalk2.default.blue.bold, value: String(jats.subArticles.length) };
|
|
10980
10985
|
}
|
|
10981
10986
|
session.log.info(formatDictionary(summary));
|
|
10982
10987
|
if (!jats.body) {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { ISession, Options } from '
|
|
1
|
+
import type { ISession, Options } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* https://www.ncbi.nlm.nih.gov/pmc/tools/id-converter-api/
|
|
4
4
|
*/
|
|
5
5
|
export declare function convertPMID2PMCID(session: ISession, PMID: string, opts: Options): Promise<string | undefined>;
|
|
6
6
|
export declare function checkIfPubMedCentralHasJats(session: ISession, urlOrDoi: string, opts: Options): Promise<string | undefined>;
|
|
7
7
|
export declare function downloadJatsFromUrl(session: ISession, urlOrDoi: string, opts?: Options): Promise<{
|
|
8
|
+
success: boolean;
|
|
8
9
|
source: string;
|
|
9
|
-
data
|
|
10
|
+
data?: string;
|
|
10
11
|
}>;
|
|
11
12
|
//# sourceMappingURL=download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../src/cli/download.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AA+FlD;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAqB7B;AAOD,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,QAAQ,EACjB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgC7B;AAED,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,QAAQ,EACjB,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,OAAY,GACjB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAkC9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/cli/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/cli/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4OpC,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAI9C"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,cAAc,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/download.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AA8GjD;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAqB7B;AAOD,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,QAAQ,EACjB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgC7B;AAED,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,QAAQ,EACjB,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,OAAY,GACjB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAkC3C"}
|