@manuscripts/transform 2.3.32 → 2.3.34-LEAN-3911.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.
Files changed (115) hide show
  1. package/dist/cjs/jats/importer/create-article-node.js +31 -0
  2. package/dist/cjs/jats/importer/index.js +3 -3
  3. package/dist/cjs/jats/importer/jats-body-transformations.js +70 -0
  4. package/dist/cjs/jats/importer/jats-comments.js +27 -104
  5. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +229 -9
  6. package/dist/cjs/jats/importer/jats-front-transformations.js +262 -0
  7. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
  8. package/dist/cjs/jats/importer/jats-parser-utils.js +39 -5
  9. package/dist/cjs/jats/importer/jats-reference-parser.js +16 -27
  10. package/dist/cjs/jats/importer/jats-references.js +18 -18
  11. package/dist/cjs/jats/importer/parse-jats-article.js +42 -78
  12. package/dist/cjs/jats/index.js +4 -3
  13. package/dist/cjs/jats/jats-exporter.js +251 -354
  14. package/dist/cjs/{transformer → jats}/labels.js +3 -3
  15. package/dist/cjs/lib/utils.js +9 -1
  16. package/dist/cjs/schema/nodes/footnotes_section.js +1 -1
  17. package/dist/cjs/transformer/id.js +6 -6
  18. package/dist/cjs/transformer/index.js +0 -18
  19. package/dist/cjs/version.js +1 -1
  20. package/dist/{cjs/transformer/serializer.js → es/jats/importer/create-article-node.js} +12 -8
  21. package/dist/es/jats/importer/index.js +2 -1
  22. package/dist/es/jats/importer/jats-body-transformations.js +70 -0
  23. package/dist/es/jats/importer/jats-comments.js +26 -101
  24. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +230 -10
  25. package/dist/es/jats/importer/jats-front-transformations.js +259 -0
  26. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  27. package/dist/es/jats/importer/jats-parser-utils.js +40 -6
  28. package/dist/es/jats/importer/jats-reference-parser.js +16 -27
  29. package/dist/es/jats/importer/jats-references.js +18 -18
  30. package/dist/es/jats/importer/parse-jats-article.js +43 -77
  31. package/dist/es/jats/index.js +3 -1
  32. package/dist/es/jats/jats-exporter.js +253 -356
  33. package/dist/es/{transformer → jats}/labels.js +3 -3
  34. package/dist/es/lib/utils.js +7 -0
  35. package/dist/es/schema/nodes/footnotes_section.js +1 -1
  36. package/dist/es/transformer/id.js +5 -4
  37. package/dist/es/transformer/index.js +0 -16
  38. package/dist/es/version.js +1 -1
  39. package/dist/{cjs/transformer/models.js → types/jats/importer/create-article-node.d.ts} +3 -3
  40. package/dist/types/jats/importer/index.d.ts +2 -1
  41. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  42. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  43. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  44. package/dist/types/jats/importer/jats-front-transformations.d.ts +38 -0
  45. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  46. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  47. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  48. package/dist/types/jats/index.d.ts +3 -1
  49. package/dist/types/jats/jats-exporter.d.ts +10 -29
  50. package/dist/types/{transformer → jats}/labels.d.ts +2 -1
  51. package/dist/types/lib/utils.d.ts +3 -0
  52. package/dist/types/schema/nodes/bibliography_item.d.ts +16 -6
  53. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  54. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  55. package/dist/types/transformer/id.d.ts +4 -3
  56. package/dist/types/transformer/index.d.ts +0 -16
  57. package/dist/types/version.d.ts +1 -1
  58. package/package.json +3 -2
  59. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  60. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  61. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  62. package/dist/cjs/transformer/builders.js +0 -219
  63. package/dist/cjs/transformer/decode.js +0 -874
  64. package/dist/cjs/transformer/document-object-types.js +0 -31
  65. package/dist/cjs/transformer/encode.js +0 -664
  66. package/dist/cjs/transformer/footnote-category.js +0 -20
  67. package/dist/cjs/transformer/footnotes-order.js +0 -60
  68. package/dist/cjs/transformer/highlight-markers.js +0 -138
  69. package/dist/cjs/transformer/html.js +0 -400
  70. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  71. package/dist/cjs/transformer/model-map.js +0 -26
  72. package/dist/cjs/transformer/object-types.js +0 -57
  73. package/dist/cjs/transformer/project-bundle.js +0 -94
  74. package/dist/cjs/transformer/update-identifiers.js +0 -93
  75. package/dist/es/__tests__/data/project-dump.json +0 -825
  76. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  77. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  78. package/dist/es/transformer/builders.js +0 -186
  79. package/dist/es/transformer/decode.js +0 -864
  80. package/dist/es/transformer/document-object-types.js +0 -28
  81. package/dist/es/transformer/encode.js +0 -654
  82. package/dist/es/transformer/footnote-category.js +0 -16
  83. package/dist/es/transformer/footnotes-order.js +0 -55
  84. package/dist/es/transformer/highlight-markers.js +0 -132
  85. package/dist/es/transformer/html.js +0 -393
  86. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  87. package/dist/es/transformer/model-map.js +0 -22
  88. package/dist/es/transformer/models.js +0 -16
  89. package/dist/es/transformer/object-types.js +0 -52
  90. package/dist/es/transformer/project-bundle.js +0 -85
  91. package/dist/es/transformer/serializer.js +0 -17
  92. package/dist/es/transformer/update-identifiers.js +0 -87
  93. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  94. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  95. package/dist/types/transformer/builders.d.ts +0 -61
  96. package/dist/types/transformer/decode.d.ts +0 -51
  97. package/dist/types/transformer/document-object-types.d.ts +0 -17
  98. package/dist/types/transformer/encode.d.ts +0 -29
  99. package/dist/types/transformer/footnote-category.d.ts +0 -17
  100. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  101. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  102. package/dist/types/transformer/html.d.ts +0 -36
  103. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  104. package/dist/types/transformer/model-map.d.ts +0 -19
  105. package/dist/types/transformer/models.d.ts +0 -48
  106. package/dist/types/transformer/object-types.d.ts +0 -30
  107. package/dist/types/transformer/project-bundle.d.ts +0 -30
  108. package/dist/types/transformer/serializer.d.ts +0 -19
  109. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  110. /package/dist/cjs/{transformer → jats}/filename.js +0 -0
  111. /package/dist/cjs/{transformer → jats}/timestamp.js +0 -0
  112. /package/dist/es/{transformer → jats}/filename.js +0 -0
  113. /package/dist/es/{transformer → jats}/timestamp.js +0 -0
  114. /package/dist/types/{transformer → jats}/filename.d.ts +0 -0
  115. /package/dist/types/{transformer → jats}/timestamp.d.ts +0 -0
@@ -13,9 +13,9 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { ObjectTypes } from '@manuscripts/json-schema';
16
17
  import { getTrimmedTextContent } from '../../lib/utils';
17
- import { buildBibliographicDate, buildBibliographicName, buildBibliographyItem, } from '../../transformer/builders';
18
- import { isJATSComment, parseJATSComment } from './jats-comments';
18
+ import { generateID } from '../../transformer';
19
19
  import { htmlFromJatsNode } from './jats-parser-utils';
20
20
  import { References } from './jats-references';
21
21
  const chooseBibliographyItemType = (publicationType) => {
@@ -37,23 +37,15 @@ export const jatsReferenceParser = {
37
37
  const authorNodes = [
38
38
  ...element.querySelectorAll('person-group[person-group-type="author"] > *'),
39
39
  ];
40
- const bibliographyItem = buildBibliographyItem({
40
+ const bibliographyItem = {
41
+ id: generateID(ObjectTypes.BibliographyItem),
41
42
  type: chooseBibliographyItemType(publicationType),
42
- });
43
+ };
43
44
  const titleNode = element.querySelector('article-title');
44
45
  if (titleNode) {
45
46
  bibliographyItem.title = (_a = htmlFromJatsNode(titleNode, createElement)) === null || _a === void 0 ? void 0 : _a.trim();
46
47
  }
47
- const comments = [];
48
48
  const mixedCitation = element.querySelector('mixed-citation');
49
- mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
50
- if (isJATSComment(item)) {
51
- const comment = parseJATSComment(item);
52
- if (comment) {
53
- comments.push(comment);
54
- }
55
- }
56
- });
57
49
  if (authorNodes.length <= 0) {
58
50
  mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
59
51
  var _a, _b, _c;
@@ -66,7 +58,7 @@ export const jatsReferenceParser = {
66
58
  }
67
59
  const source = getTrimmedTextContent(element, 'source');
68
60
  if (source) {
69
- bibliographyItem['container-title'] = source;
61
+ bibliographyItem.containerTitle = source;
70
62
  }
71
63
  const volume = getTrimmedTextContent(element, 'volume');
72
64
  if (volume) {
@@ -87,18 +79,22 @@ export const jatsReferenceParser = {
87
79
  }
88
80
  const year = getTrimmedTextContent(element, 'year');
89
81
  if (year) {
90
- bibliographyItem.issued = buildBibliographicDate({
82
+ bibliographyItem.issued = {
91
83
  'date-parts': [[year]],
92
- });
84
+ _id: generateID(ObjectTypes.BibliographicDate),
85
+ objectType: ObjectTypes.BibliographicDate,
86
+ };
93
87
  }
94
88
  const doi = getTrimmedTextContent(element, 'pub-id[pub-id-type="doi"]');
95
89
  if (doi) {
96
- bibliographyItem.DOI = doi;
90
+ bibliographyItem.doi = doi;
97
91
  }
98
92
  const authors = [];
99
93
  authorNodes.forEach((authorNode) => {
100
- var _a;
101
- const name = buildBibliographicName({});
94
+ const name = {
95
+ _id: generateID(ObjectTypes.BibliographicName),
96
+ objectType: ObjectTypes.BibliographicName,
97
+ };
102
98
  const given = getTrimmedTextContent(authorNode, 'given-names');
103
99
  if (given) {
104
100
  name.given = given;
@@ -107,20 +103,13 @@ export const jatsReferenceParser = {
107
103
  if (family) {
108
104
  name.family = family;
109
105
  }
110
- const suffix = getTrimmedTextContent(authorNode, 'suffix');
111
- if (suffix) {
112
- name.suffix = suffix;
113
- }
114
- if (authorNode.nodeName === 'collab') {
115
- name.literal = (_a = authorNode.textContent) === null || _a === void 0 ? void 0 : _a.trim();
116
- }
117
106
  authors.push(name);
118
107
  });
119
108
  if (authors.length) {
120
109
  bibliographyItem.author = authors;
121
110
  }
122
111
  const id = element.getAttribute('id');
123
- references.add(bibliographyItem, id, comments);
112
+ references.add(bibliographyItem, id);
124
113
  });
125
114
  return references;
126
115
  },
@@ -1,30 +1,30 @@
1
+ /*!
2
+ * © 2023 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
  export class References {
2
17
  constructor() {
3
18
  this.items = new Map();
4
19
  this.IDs = new Map();
5
- this.comments = new Map();
6
20
  }
7
- add(item, id, comments) {
8
- this.items.set(item._id, item);
9
- this.comments.set(item._id, comments);
21
+ add(item, id) {
22
+ this.items.set(item.id, item);
10
23
  if (id) {
11
- this.IDs.set(id, item._id);
24
+ this.IDs.set(id, item.id);
12
25
  }
13
26
  }
14
27
  getBibliographyItems() {
15
28
  return [...this.items.values()];
16
29
  }
17
- getComments(id) {
18
- return this.getValue(id, this.comments) || [];
19
- }
20
- getValue(id, map) {
21
- const value = map.get(id);
22
- if (value) {
23
- return value;
24
- }
25
- const id2 = this.IDs.get(id);
26
- if (id2) {
27
- return map.get(id2);
28
- }
29
- }
30
30
  }
@@ -14,44 +14,14 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { InvalidInput } from '../../errors';
17
- import { buildBibliographyElement, buildSection, encode, } from '../../transformer';
18
- import { buildManuscript } from '../../transformer/builders';
19
- import { generateID } from '../../transformer/id';
20
- import { findManuscript } from '../../transformer/project-bundle';
21
- import { jatsBodyDOMParser } from './jats-body-dom-parser';
22
17
  import { jatsBodyTransformations } from './jats-body-transformations';
23
- import { createComments, createReferenceComments, markComments, } from './jats-comments';
24
- import { jatsFrontParser } from './jats-front-parser';
18
+ import { markComments } from './jats-comments';
19
+ import { jatsDOMParser } from './jats-dom-parser';
20
+ import { jatsFrontTransformations } from './jats-front-transformations';
21
+ import { parseJournal } from './jats-journal-meta-parser';
25
22
  import { updateDocumentIDs } from './jats-parser-utils';
26
23
  import { jatsReferenceParser } from './jats-reference-parser';
27
- export const parseJATSFront = (doc, front) => {
28
- const createElement = createElementFn(doc);
29
- const journal = jatsFrontParser.parseJournal(front.querySelector('journal-meta'));
30
- const titles = jatsFrontParser.parseTitles(front.querySelector('article-meta > title-group'), createElement);
31
- const DOI = jatsFrontParser.parseDOI(front);
32
- const { affiliations, affiliationIDs } = jatsFrontParser.parseAffiliations([
33
- ...front.querySelectorAll('article-meta > contrib-group > aff'),
34
- ]);
35
- const { footnotes, footnoteIDs, authorNotes, authorNotesParagraphs, correspondingIDs, correspondingList, } = jatsFrontParser.parseAuthorNotes(front.querySelector('article-meta > author-notes'));
36
- const authors = jatsFrontParser.parseContributors([
37
- ...front.querySelectorAll('article-meta > contrib-group > contrib[contrib-type="author"]'),
38
- ], affiliationIDs, footnoteIDs, correspondingIDs);
39
- const history = jatsFrontParser.parseDates(front.querySelector('article-meta > history'));
40
- const counts = jatsFrontParser.parseCounts(front.querySelector('article-meta counts'));
41
- const manuscript = Object.assign(Object.assign(Object.assign(Object.assign({}, buildManuscript()), counts), history), { DOI });
42
- return generateIDs([
43
- manuscript,
44
- titles,
45
- journal,
46
- ...authorNotesParagraphs,
47
- ...authorNotes,
48
- ...footnotes,
49
- ...authors,
50
- ...affiliations,
51
- ...correspondingList,
52
- ]);
53
- };
54
- export const parseJATSBody = (doc, body, references) => {
24
+ const parseJATSBody = (doc, body, references) => {
55
25
  const createElement = createElementFn(doc);
56
26
  jatsBodyTransformations.ensureSection(body, createElement);
57
27
  jatsBodyTransformations.moveCaptionsToEnd(body);
@@ -62,62 +32,58 @@ export const parseJATSBody = (doc, body, references) => {
62
32
  jatsBodyTransformations.createSuppleMaterials(doc, body, createElement);
63
33
  jatsBodyTransformations.createKeywords(doc, body, createElement);
64
34
  jatsBodyTransformations.orderTableFootnote(doc, body);
65
- const node = jatsBodyDOMParser.parse(body).firstChild;
66
- if (!node) {
67
- throw new Error('No content was parsed from the JATS article body');
68
- }
69
- const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
70
- updateDocumentIDs(node, replacements);
71
- return encode(node).values();
35
+ jatsBodyTransformations.moveReferencesToBackmatter(body, references, createElement);
72
36
  };
73
- const createBibliographyModels = (references) => {
74
- const models = [];
75
- const bibliographyItems = references.getBibliographyItems();
76
- const bibliographyElement = buildBibliographyElement(bibliographyItems);
77
- const bibliographySection = Object.assign(Object.assign({}, buildSection(99)), { category: 'MPSectionCategory:bibliography', elementIDs: [bibliographyElement._id], title: 'References' });
78
- const comments = createReferenceComments(references);
79
- models.push(bibliographySection);
80
- models.push(bibliographyElement);
81
- models.push(...bibliographyItems);
82
- models.push(...comments);
83
- return models;
37
+ const parseJATSFront = (doc, front, template) => {
38
+ var _a;
39
+ const createElement = createElementFn(doc);
40
+ jatsFrontTransformations.setArticleAttrs(doc, template);
41
+ const authorNotes = jatsFrontTransformations.createAuthorNotes(doc, createElement);
42
+ if (authorNotes) {
43
+ doc.documentElement.prepend(authorNotes);
44
+ }
45
+ const affiliations = jatsFrontTransformations.createAffiliations(front, createElement);
46
+ if (affiliations) {
47
+ doc.documentElement.prepend(affiliations);
48
+ }
49
+ const contributors = jatsFrontTransformations.createContributors(front, createElement);
50
+ if (contributors) {
51
+ doc.documentElement.prepend(contributors);
52
+ }
53
+ const title = jatsFrontTransformations.createTitle(front, createElement);
54
+ if (title) {
55
+ doc.documentElement.prepend(title);
56
+ }
57
+ (_a = doc.querySelector('front')) === null || _a === void 0 ? void 0 : _a.remove();
84
58
  };
85
59
  const createElementFn = (doc) => (tagName) => doc.createElement(tagName);
86
- const generateIDs = (models) => models.map((m) => m._id ? m : Object.assign(Object.assign({}, m), { _id: generateID(m.objectType) }));
87
- export const parseJATSArticle = (doc) => {
60
+ export const parseJATSArticle = (doc, template) => {
88
61
  const article = doc.querySelector('article');
89
62
  const front = doc.querySelector('front');
90
63
  const body = doc.querySelector('body');
91
64
  const back = doc.querySelector('back');
92
- if (!front) {
93
- throw new InvalidInput('Invalid JATS format! Missing front element');
94
- }
95
- if (!article) {
96
- throw new InvalidInput('Invalid JATS format! Missing article element');
65
+ if (!article || !front) {
66
+ throw new InvalidInput('invalid JATS format');
97
67
  }
98
- const marks = markComments(doc);
68
+ markComments(doc);
69
+ const journal = parseJournal(front.querySelector('journal-meta'));
99
70
  const createElement = createElementFn(doc);
100
- const models = [];
101
71
  let references;
102
72
  if (back) {
103
73
  references = jatsReferenceParser.parseReferences([...back.querySelectorAll('ref-list > ref')], createElement);
104
74
  }
105
- models.push(...parseJATSFront(doc, front));
75
+ const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
76
+ parseJATSFront(doc, front, template);
106
77
  if (body) {
107
- models.push(...parseJATSBody(doc, body, references));
108
- }
109
- const modelMap = new Map(models.map((model) => [model._id, model]));
110
- const manuscript = findManuscript(modelMap);
111
- if (manuscript) {
112
- const type = article.getAttribute('article-type');
113
- manuscript.articleType = type || 'other';
78
+ parseJATSBody(doc, body, references);
114
79
  }
115
- if (references && references.items.size) {
116
- models.push(...createBibliographyModels(references));
117
- }
118
- if (marks.length) {
119
- const comments = createComments(models, marks);
120
- models.push(...comments);
80
+ const node = jatsDOMParser.parse(doc).firstChild;
81
+ if (!node) {
82
+ throw new Error('No content was parsed from the JATS article body');
121
83
  }
122
- return models;
84
+ updateDocumentIDs(node, replacements);
85
+ return {
86
+ node: node,
87
+ journal,
88
+ };
123
89
  };
@@ -13,6 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export { parseJATSFront, parseJATSBody, parseJATSArticle } from './importer';
16
+ export { parseJATSArticle, createArticleNode } from './importer';
17
17
  export * from './jats-exporter';
18
18
  export * from './jats-versions';
19
+ export * from './timestamp';
20
+ export * from './labels';