jats-xml 1.0.0 → 1.0.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.
@@ -1,10 +1,10 @@
1
- import type { ISession, Options } from '../types.js';
1
+ import type { ISession, ResolutionOptions } from '../types.js';
2
2
  /**
3
3
  * https://www.ncbi.nlm.nih.gov/pmc/tools/id-converter-api/
4
4
  */
5
- export declare function convertPMID2PMCID(session: ISession, PMID: string, opts: Options): Promise<string | undefined>;
6
- export declare function checkIfPubMedCentralHasJats(session: ISession, urlOrDoi: string, opts: Options): Promise<string | undefined>;
7
- export declare function downloadJatsFromUrl(session: ISession, urlOrDoi: string, opts?: Options): Promise<{
5
+ export declare function convertPMID2PMCID(session: ISession, PMID: string, opts: ResolutionOptions): Promise<string | undefined>;
6
+ export declare function checkIfPubMedCentralHasJats(session: ISession, urlOrDoi: string, opts: ResolutionOptions): Promise<string | undefined>;
7
+ export declare function downloadJatsFromUrl(session: ISession, urlOrDoi: string, opts?: ResolutionOptions): Promise<{
8
8
  success: boolean;
9
9
  source: string;
10
10
  data?: string;
@@ -1,5 +1,5 @@
1
1
  import { Command } from 'commander';
2
- import type { ISession, Options } from '../types.js';
2
+ import type { ISession, ResolutionOptions } from '../types.js';
3
3
  import { Jats } from '../jats.js';
4
- export declare function parseJats(session: ISession, file: string, opts?: Options): Promise<Jats>;
4
+ export declare function parseJats(session: ISession, file: string, opts?: ResolutionOptions): Promise<Jats>;
5
5
  export declare function addDownloadCLI(program: Command): void;
package/dist/jats.cjs CHANGED
@@ -28100,7 +28100,7 @@ var {
28100
28100
  } = import_index.default;
28101
28101
 
28102
28102
  // src/version.ts
28103
- var version = "1.0.0";
28103
+ var version = "1.0.2";
28104
28104
  var version_default = version;
28105
28105
 
28106
28106
  // src/cli/parse.ts
@@ -31951,9 +31951,9 @@ async function ensureDtdExists(session, opts) {
31951
31951
  }
31952
31952
  }
31953
31953
  function isXmllintAvailable() {
31954
- return (0, import_which.sync)("xmllint", { nothrow: true });
31954
+ return import_which.default.sync("xmllint", { nothrow: true });
31955
31955
  }
31956
- async function validateJatsAgainstDtd(session, file, opts) {
31956
+ async function xmllintValidate(session, file, dtd) {
31957
31957
  if (!isXmllintAvailable()) {
31958
31958
  session.log.error(
31959
31959
  `JATS validation against DTD requires xmllint
@@ -31964,20 +31964,24 @@ ${source_default.dim(
31964
31964
  );
31965
31965
  return;
31966
31966
  }
31967
- const inferredOpts = inferOptions(file);
31968
- const validatedOpts = validateOptions(session, opts != null ? opts : {}, inferredOpts);
31969
- await ensureDtdExists(session, validatedOpts);
31970
- session.log.debug(`Validating against: ${localDtdFile(validatedOpts)}`);
31971
- session.log.info(`\u{1F9D0} Validating against: ${dtdFolder(validatedOpts)}`);
31972
31967
  try {
31973
31968
  const dropDtdCommand = `xmllint --dropdtd`;
31974
- const validateCommand = `xmllint --noout --dtdvalid ${localDtdFile(validatedOpts)}`;
31969
+ const validateCommand = `xmllint --noout --dtdvalid ${dtd}`;
31975
31970
  await makeExecutable(`${dropDtdCommand} ${file} | ${validateCommand} -`, session.log)();
31976
31971
  } catch {
31977
31972
  return false;
31978
31973
  }
31979
31974
  return true;
31980
31975
  }
31976
+ async function validateJatsAgainstDtd(session, file, opts) {
31977
+ const inferredOpts = inferOptions(file);
31978
+ const validatedOpts = validateOptions(session, opts != null ? opts : {}, inferredOpts);
31979
+ await ensureDtdExists(session, validatedOpts);
31980
+ session.log.debug(`Validating against: ${localDtdFile(validatedOpts)}`);
31981
+ session.log.info(`\u{1F9D0} Validating against: ${dtdFolder(validatedOpts)}`);
31982
+ const valid = await xmllintValidate(session, file, localDtdFile(validatedOpts));
31983
+ return valid;
31984
+ }
31981
31985
  async function validateJatsAgainstDtdWrapper(session, file, opts) {
31982
31986
  const success = await validateJatsAgainstDtd(session, file, opts);
31983
31987
  if (success) {
@@ -1,4 +1,4 @@
1
- import type { ISession, Options, Resolver } from './types.js';
1
+ import type { ISession, ResolutionOptions, Resolver } from './types.js';
2
2
  export declare const elife: Resolver;
3
3
  export declare const plos: Resolver;
4
4
  export declare const joss: Resolver;
@@ -6,4 +6,4 @@ export declare const DEFAULT_RESOLVERS: Resolver[];
6
6
  /**
7
7
  * Use the known custom resolvers to pick where the JATS should be downloaded from.
8
8
  */
9
- export declare function customResolveJatsUrlFromDoi(session: ISession, doiString: string, opts?: Options): Promise<string>;
9
+ export declare function customResolveJatsUrlFromDoi(session: ISession, doiString: string, opts?: ResolutionOptions): Promise<string>;
package/dist/types.d.ts CHANGED
@@ -4,7 +4,7 @@ export interface Resolver {
4
4
  test: (url: string) => boolean;
5
5
  jatsUrl: (url: string) => string;
6
6
  }
7
- export type Options = {
7
+ export type ResolutionOptions = {
8
8
  resolvers?: Resolver[];
9
9
  fetcher?: (url: string, contentType?: 'json' | 'xml') => Promise<Pick<Response, 'ok' | 'headers' | 'text' | 'json' | 'status' | 'statusText' | 'url'>>;
10
10
  };
@@ -1,5 +1,5 @@
1
1
  import type { ISession } from '../types.js';
2
- type Options = {
2
+ export type JatsOptions = {
3
3
  jats: string;
4
4
  mathml: '2' | '3';
5
5
  oasis: boolean;
@@ -11,17 +11,24 @@ type Options = {
11
11
  *
12
12
  * This looks at DTD file name in DOCTYPE as well as dtd-version in article element
13
13
  */
14
- export declare function inferOptions(file: string): Partial<Options>;
14
+ export declare function inferOptions(file: string): Partial<JatsOptions>;
15
+ /**
16
+ * Test if xmllint is available as a cli command
17
+ */
18
+ export declare function isXmllintAvailable(): string | null;
19
+ /**
20
+ * Run xmllint validation
21
+ */
22
+ export declare function xmllintValidate(session: ISession, file: string, dtd: string): Promise<boolean | undefined>;
15
23
  /**
16
24
  * Check if JATS file is valid based on JATS version/library/etc.
17
25
  *
18
26
  * Returns true if valid and false if invalid.
19
27
  */
20
- export declare function validateJatsAgainstDtd(session: ISession, file: string, opts?: Partial<Options>): Promise<boolean | undefined>;
28
+ export declare function validateJatsAgainstDtd(session: ISession, file: string, opts?: Partial<JatsOptions>): Promise<boolean | undefined>;
21
29
  /**
22
30
  * Check if JATS file is valid based on JATS version/library/etc.
23
31
  *
24
32
  * Logs confirmation message if valid and throws an error if invalid.
25
33
  */
26
- export declare function validateJatsAgainstDtdWrapper(session: ISession, file: string, opts?: Partial<Options>): Promise<void>;
27
- export {};
34
+ export declare function validateJatsAgainstDtdWrapper(session: ISession, file: string, opts?: Partial<JatsOptions>): Promise<void>;
@@ -2,7 +2,7 @@ import fs, { createReadStream } from 'fs';
2
2
  import path from 'path';
3
3
  import fetch from 'node-fetch';
4
4
  import unzipper from 'unzipper';
5
- import { sync as which } from 'which';
5
+ import which from 'which';
6
6
  import { makeExecutable, writeFileToFolder } from 'myst-cli-utils';
7
7
  import chalk from 'chalk';
8
8
  const JATS_VERSIONS = [
@@ -224,28 +224,21 @@ async function ensureDtdExists(session, opts) {
224
224
  /**
225
225
  * Test if xmllint is available as a cli command
226
226
  */
227
- function isXmllintAvailable() {
228
- return which('xmllint', { nothrow: true });
227
+ export function isXmllintAvailable() {
228
+ return which.sync('xmllint', { nothrow: true });
229
229
  }
230
230
  /**
231
- * Check if JATS file is valid based on JATS version/library/etc.
232
- *
233
- * Returns true if valid and false if invalid.
231
+ * Run xmllint validation
234
232
  */
235
- export async function validateJatsAgainstDtd(session, file, opts) {
233
+ export async function xmllintValidate(session, file, dtd) {
236
234
  if (!isXmllintAvailable()) {
237
235
  session.log.error(`JATS validation against DTD requires xmllint\n\n${chalk.dim('To install:\n mac: brew install xmlstarlet\n debian: apt install libxml2-utils')}`);
238
236
  return;
239
237
  }
240
- const inferredOpts = inferOptions(file);
241
- const validatedOpts = validateOptions(session, opts !== null && opts !== void 0 ? opts : {}, inferredOpts);
242
- await ensureDtdExists(session, validatedOpts);
243
- session.log.debug(`Validating against: ${localDtdFile(validatedOpts)}`);
244
- session.log.info(`🧐 Validating against: ${dtdFolder(validatedOpts)}`);
245
238
  try {
246
239
  // First drop DOCTYPE with DTD in it - we have already fetched the DTD
247
240
  const dropDtdCommand = `xmllint --dropdtd`;
248
- const validateCommand = `xmllint --noout --dtdvalid ${localDtdFile(validatedOpts)}`;
241
+ const validateCommand = `xmllint --noout --dtdvalid ${dtd}`;
249
242
  await makeExecutable(`${dropDtdCommand} ${file} | ${validateCommand} -`, session.log)();
250
243
  }
251
244
  catch {
@@ -253,6 +246,20 @@ export async function validateJatsAgainstDtd(session, file, opts) {
253
246
  }
254
247
  return true;
255
248
  }
249
+ /**
250
+ * Check if JATS file is valid based on JATS version/library/etc.
251
+ *
252
+ * Returns true if valid and false if invalid.
253
+ */
254
+ export async function validateJatsAgainstDtd(session, file, opts) {
255
+ const inferredOpts = inferOptions(file);
256
+ const validatedOpts = validateOptions(session, opts !== null && opts !== void 0 ? opts : {}, inferredOpts);
257
+ await ensureDtdExists(session, validatedOpts);
258
+ session.log.debug(`Validating against: ${localDtdFile(validatedOpts)}`);
259
+ session.log.info(`🧐 Validating against: ${dtdFolder(validatedOpts)}`);
260
+ const valid = await xmllintValidate(session, file, localDtdFile(validatedOpts));
261
+ return valid;
262
+ }
256
263
  /**
257
264
  * Check if JATS file is valid based on JATS version/library/etc.
258
265
  *
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const version = "1.0.0";
1
+ declare const version = "1.0.2";
2
2
  export default version;
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- const version = '1.0.0';
1
+ const version = '1.0.2';
2
2
  export default version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jats-xml",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Types and utilities for working with JATS in Typescript",
5
5
  "author": "Rowan Cockett <rowan@curvenote.com>",
6
6
  "homepage": "https://github.com/curvenote/jats-xml",
@@ -47,7 +47,7 @@
47
47
  "dependencies": {
48
48
  "doi-utils": "^2.0.0",
49
49
  "fair-principles": "^2.0.0",
50
- "jats-tags": "^1.0.0",
50
+ "jats-tags": "^1.0.2",
51
51
  "js-yaml": "^4.1.0",
52
52
  "node-fetch": "^3.3.1",
53
53
  "unist-util-is": "^5.2.1",