@manuscripts/transform 2.3.37 → 2.3.38-LEAN-3911.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.
Files changed (123) hide show
  1. package/dist/cjs/index.js +6 -6
  2. package/dist/cjs/jats/{jats-exporter.js → exporter/jats-exporter.js} +263 -390
  3. package/dist/cjs/jats/{jats-versions.js → exporter/jats-versions.js} +1 -3
  4. package/dist/cjs/{transformer → jats/exporter}/labels.js +4 -4
  5. package/dist/cjs/{transformer/filename.js → jats/importer/create-article-node.js} +10 -9
  6. package/dist/cjs/jats/importer/jats-body-transformations.js +73 -0
  7. package/dist/cjs/jats/importer/jats-comments.js +27 -104
  8. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +281 -10
  9. package/dist/cjs/jats/importer/jats-front-transformations.js +79 -0
  10. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
  11. package/dist/cjs/jats/importer/jats-parser-utils.js +43 -5
  12. package/dist/cjs/jats/importer/jats-reference-parser.js +16 -23
  13. package/dist/cjs/jats/importer/jats-references.js +18 -18
  14. package/dist/cjs/jats/importer/parse-jats-article.js +40 -78
  15. package/dist/cjs/jats/index.js +7 -7
  16. package/dist/cjs/{transformer/models.js → lib/deafults.js} +3 -1
  17. package/dist/cjs/lib/utils.js +12 -1
  18. package/dist/cjs/transformer/id.js +10 -5
  19. package/dist/cjs/transformer/index.js +0 -18
  20. package/dist/cjs/version.js +1 -1
  21. package/dist/es/index.js +5 -5
  22. package/dist/es/jats/{jats-exporter.js → exporter/jats-exporter.js} +257 -384
  23. package/dist/es/jats/{jats-versions.js → exporter/jats-versions.js} +0 -1
  24. package/dist/es/{transformer → jats/exporter}/labels.js +4 -4
  25. package/dist/es/{transformer/filename.js → jats/importer/create-article-node.js} +8 -7
  26. package/dist/es/jats/importer/jats-body-transformations.js +73 -0
  27. package/dist/es/jats/importer/jats-comments.js +26 -101
  28. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +282 -11
  29. package/dist/es/jats/importer/jats-front-transformations.js +76 -0
  30. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  31. package/dist/es/jats/importer/jats-parser-utils.js +44 -6
  32. package/dist/es/jats/importer/jats-reference-parser.js +16 -23
  33. package/dist/es/jats/importer/jats-references.js +18 -18
  34. package/dist/es/jats/importer/parse-jats-article.js +41 -77
  35. package/dist/es/jats/index.js +5 -3
  36. package/dist/{types/transformer/timestamp.d.ts → es/lib/deafults.js} +2 -2
  37. package/dist/es/lib/utils.js +9 -0
  38. package/dist/es/transformer/id.js +8 -3
  39. package/dist/es/transformer/index.js +0 -16
  40. package/dist/es/version.js +1 -1
  41. package/dist/types/index.d.ts +6 -6
  42. package/dist/types/jats/{jats-exporter.d.ts → exporter/jats-exporter.d.ts} +15 -29
  43. package/dist/types/jats/{jats-versions.d.ts → exporter/jats-versions.d.ts} +0 -1
  44. package/dist/types/{transformer → jats/exporter}/labels.d.ts +2 -2
  45. package/dist/{es/transformer/footnote-category.js → types/jats/importer/create-article-node.d.ts} +3 -2
  46. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  47. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  48. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  49. package/dist/{cjs/transformer/serializer.js → types/jats/importer/jats-front-transformations.d.ts} +7 -8
  50. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  51. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  52. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  53. package/dist/types/jats/index.d.ts +5 -3
  54. package/dist/types/jats/types.d.ts +1 -0
  55. package/dist/{es/transformer/models.js → types/lib/deafults.d.ts} +2 -2
  56. package/dist/types/lib/utils.d.ts +2 -0
  57. package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
  58. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  59. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  60. package/dist/types/schema/nodes/manuscript.d.ts +8 -7
  61. package/dist/types/schema/nodes/title.d.ts +0 -3
  62. package/dist/types/transformer/id.d.ts +5 -2
  63. package/dist/types/transformer/index.d.ts +0 -16
  64. package/dist/types/version.d.ts +1 -1
  65. package/package.json +2 -1
  66. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  67. package/dist/cjs/jats/importer/index.js +0 -22
  68. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  69. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  70. package/dist/cjs/transformer/builders.js +0 -219
  71. package/dist/cjs/transformer/decode.js +0 -874
  72. package/dist/cjs/transformer/document-object-types.js +0 -31
  73. package/dist/cjs/transformer/encode.js +0 -664
  74. package/dist/cjs/transformer/footnote-category.js +0 -20
  75. package/dist/cjs/transformer/footnotes-order.js +0 -60
  76. package/dist/cjs/transformer/highlight-markers.js +0 -138
  77. package/dist/cjs/transformer/html.js +0 -400
  78. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  79. package/dist/cjs/transformer/model-map.js +0 -26
  80. package/dist/cjs/transformer/object-types.js +0 -57
  81. package/dist/cjs/transformer/project-bundle.js +0 -94
  82. package/dist/cjs/transformer/timestamp.js +0 -20
  83. package/dist/cjs/transformer/update-identifiers.js +0 -93
  84. package/dist/es/__tests__/data/project-dump.json +0 -825
  85. package/dist/es/jats/importer/index.js +0 -16
  86. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  87. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  88. package/dist/es/transformer/builders.js +0 -186
  89. package/dist/es/transformer/decode.js +0 -864
  90. package/dist/es/transformer/document-object-types.js +0 -28
  91. package/dist/es/transformer/encode.js +0 -654
  92. package/dist/es/transformer/footnotes-order.js +0 -55
  93. package/dist/es/transformer/highlight-markers.js +0 -132
  94. package/dist/es/transformer/html.js +0 -393
  95. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  96. package/dist/es/transformer/model-map.js +0 -22
  97. package/dist/es/transformer/object-types.js +0 -52
  98. package/dist/es/transformer/project-bundle.js +0 -85
  99. package/dist/es/transformer/serializer.js +0 -17
  100. package/dist/es/transformer/timestamp.js +0 -16
  101. package/dist/es/transformer/update-identifiers.js +0 -87
  102. package/dist/types/jats/importer/index.d.ts +0 -16
  103. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  104. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  105. package/dist/types/transformer/builders.d.ts +0 -61
  106. package/dist/types/transformer/decode.d.ts +0 -51
  107. package/dist/types/transformer/document-object-types.d.ts +0 -17
  108. package/dist/types/transformer/encode.d.ts +0 -29
  109. package/dist/types/transformer/filename.d.ts +0 -16
  110. package/dist/types/transformer/footnote-category.d.ts +0 -17
  111. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  112. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  113. package/dist/types/transformer/html.d.ts +0 -36
  114. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  115. package/dist/types/transformer/model-map.d.ts +0 -19
  116. package/dist/types/transformer/models.d.ts +0 -48
  117. package/dist/types/transformer/object-types.d.ts +0 -30
  118. package/dist/types/transformer/project-bundle.d.ts +0 -30
  119. package/dist/types/transformer/serializer.d.ts +0 -19
  120. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  121. package/dist/types/types.d.ts +0 -2
  122. /package/dist/cjs/{types.js → jats/types.js} +0 -0
  123. /package/dist/es/{types.js → jats/types.js} +0 -0
@@ -1,57 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2019 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.isKeyword = exports.isCommentAnnotation = exports.isTable = exports.isManuscript = exports.isFigure = exports.hasObjectType = exports.isManuscriptModel = exports.manuscriptObjects = exports.elementObjects = exports.ExtraObjectTypes = void 0;
19
- const json_schema_1 = require("@manuscripts/json-schema");
20
- var ExtraObjectTypes;
21
- (function (ExtraObjectTypes) {
22
- ExtraObjectTypes["PlaceholderElement"] = "MPPlaceholderElement";
23
- ExtraObjectTypes["GeneralTableFootnote"] = "MPGeneralTableFootnote";
24
- })(ExtraObjectTypes = exports.ExtraObjectTypes || (exports.ExtraObjectTypes = {}));
25
- exports.elementObjects = [
26
- json_schema_1.ObjectTypes.BibliographyElement,
27
- json_schema_1.ObjectTypes.EquationElement,
28
- json_schema_1.ObjectTypes.FigureElement,
29
- json_schema_1.ObjectTypes.FootnotesElement,
30
- json_schema_1.ObjectTypes.ListElement,
31
- json_schema_1.ObjectTypes.ListingElement,
32
- json_schema_1.ObjectTypes.ParagraphElement,
33
- json_schema_1.ObjectTypes.TableElement,
34
- json_schema_1.ObjectTypes.TOCElement,
35
- ];
36
- exports.manuscriptObjects = [
37
- json_schema_1.ObjectTypes.Affiliation,
38
- json_schema_1.ObjectTypes.Citation,
39
- json_schema_1.ObjectTypes.CommentAnnotation,
40
- json_schema_1.ObjectTypes.Contributor,
41
- json_schema_1.ObjectTypes.Footnote,
42
- json_schema_1.ObjectTypes.Section,
43
- ].concat(exports.elementObjects);
44
- const isManuscriptModel = (model) => {
45
- if (!model.objectType) {
46
- throw new Error('Model must have objectType');
47
- }
48
- return json_schema_1.manuscriptIDTypes.has(model.objectType);
49
- };
50
- exports.isManuscriptModel = isManuscriptModel;
51
- const hasObjectType = (objectType) => (model) => model.objectType === objectType;
52
- exports.hasObjectType = hasObjectType;
53
- exports.isFigure = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Figure);
54
- exports.isManuscript = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Manuscript);
55
- exports.isTable = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Table);
56
- exports.isCommentAnnotation = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.CommentAnnotation);
57
- exports.isKeyword = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Keyword);
@@ -1,94 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2019 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.findTitles = exports.findManuscriptById = exports.findManuscriptModelByType = exports.findJournal = exports.findManuscript = exports.parseProjectBundle = void 0;
19
- const json_schema_1 = require("@manuscripts/json-schema");
20
- const decode_1 = require("./decode");
21
- const object_types_1 = require("./object-types");
22
- const parseProjectBundle = (projectBundle, manuscriptID) => {
23
- const manuscriptData = manuscriptID
24
- ? projectBundle.data.filter((doc) => !doc.manuscriptID || doc.manuscriptID === manuscriptID)
25
- : projectBundle.data;
26
- const modelMap = new Map();
27
- for (const component of manuscriptData) {
28
- modelMap.set(component._id, component);
29
- }
30
- const decoder = new decode_1.Decoder(modelMap);
31
- const doc = decoder.createArticleNode();
32
- return { doc, modelMap };
33
- };
34
- exports.parseProjectBundle = parseProjectBundle;
35
- const isManuscript = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Manuscript);
36
- const findManuscript = (modelMap) => {
37
- for (const model of modelMap.values()) {
38
- if (isManuscript(model)) {
39
- return model;
40
- }
41
- }
42
- throw new Error('No manuscript found');
43
- };
44
- exports.findManuscript = findManuscript;
45
- const isJournal = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Journal);
46
- const findJournal = (modelMap) => {
47
- for (const model of modelMap.values()) {
48
- if (isJournal(model)) {
49
- return model;
50
- }
51
- }
52
- return null;
53
- };
54
- exports.findJournal = findJournal;
55
- const isManuscriptModel = (model) => 'manuscriptID' in model;
56
- const findManuscriptModelByType = (modelMap, manuscript, objectType) => {
57
- for (const model of modelMap.values()) {
58
- if (model.objectType === objectType &&
59
- isManuscriptModel(model) &&
60
- manuscript._id === model.manuscriptID) {
61
- return model;
62
- }
63
- }
64
- };
65
- exports.findManuscriptModelByType = findManuscriptModelByType;
66
- const findManuscriptById = (modelMap, manuscriptID) => {
67
- const manuscript = modelMap.get(manuscriptID);
68
- if (manuscript && isManuscript(manuscript)) {
69
- return manuscript;
70
- }
71
- throw new Error(`There is no manuscript found for the following _id (${manuscriptID})`);
72
- };
73
- exports.findManuscriptById = findManuscriptById;
74
- const isTitle = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Titles);
75
- const findTitles = (modelMap) => {
76
- for (const model of modelMap.values()) {
77
- if (isTitle(model)) {
78
- return model;
79
- }
80
- }
81
- const defaultTitle = {
82
- _id: 'MPTitles:8EB79C14-9F61-483A-902F-A0B8EF5973C1',
83
- createdAt: 1538472121.690101,
84
- updatedAt: 1538472121.690101,
85
- objectType: 'MPTitles',
86
- title: 'main title',
87
- subtitle: 'subtitle',
88
- runningTitle: 'running title',
89
- manuscriptID: 'MPManuscript:E3830344-E77B-42BA-BD77-3E95489712A0',
90
- containerID: 'MPProject:1',
91
- };
92
- return defaultTitle;
93
- };
94
- exports.findTitles = findTitles;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2019 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.timestamp = void 0;
19
- const timestamp = () => Math.floor(Date.now() / 1000);
20
- exports.timestamp = timestamp;
@@ -1,93 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2020 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.updateAttachments = exports.updateAttachmentPath = exports.updateIdentifiers = void 0;
19
- const id_1 = require("./id");
20
- const updateIdentifiers = async (data) => {
21
- const idMap = new Map();
22
- const updateIDs = (model) => {
23
- const { _id, objectType } = model;
24
- if (!objectType || !_id || !_id.match(/^MP.+:.+/)) {
25
- return;
26
- }
27
- if (idMap.has(_id)) {
28
- model._id = idMap.get(_id);
29
- }
30
- else {
31
- model._id = (0, id_1.generateID)(objectType);
32
- idMap.set(_id, model._id);
33
- }
34
- for (const value of Object.values(model)) {
35
- if (Array.isArray(value)) {
36
- value.forEach(updateIDs);
37
- }
38
- else {
39
- updateIDs(value);
40
- }
41
- }
42
- };
43
- const replaceContent = (content) => {
44
- content = content.replace(/MP\w+:[\w-]+/g, (match) => {
45
- const value = idMap.get(match);
46
- return value !== null && value !== void 0 ? value : match;
47
- });
48
- content = content.replace(/MP\w+_[\w-]+/g, (match) => {
49
- const value = idMap.get(match.replace('_', ':'));
50
- return value ? value.replace(':', '_') : match;
51
- });
52
- return content;
53
- };
54
- const updateContent = (model) => {
55
- for (const [key, value] of Object.entries(model)) {
56
- if (typeof value === 'object') {
57
- updateContent(value);
58
- }
59
- else if (typeof value === 'string') {
60
- model[key] = replaceContent(value);
61
- }
62
- }
63
- };
64
- for (const item of data) {
65
- updateIDs(item);
66
- }
67
- for (const item of data) {
68
- updateContent(item);
69
- }
70
- return { data, idMap };
71
- };
72
- exports.updateIdentifiers = updateIdentifiers;
73
- const updateAttachmentPath = (oldPath, idMap) => {
74
- const matches = oldPath.match(/^Data\/([^.]+)(.*)/);
75
- if (matches) {
76
- const [, prefix, suffix] = matches;
77
- const id = idMap.get(prefix.replace('_', ':'));
78
- if (id) {
79
- const newPrefix = id.replace(':', '_');
80
- return `Data/${newPrefix}${suffix}`;
81
- }
82
- }
83
- };
84
- exports.updateAttachmentPath = updateAttachmentPath;
85
- const updateAttachments = async (zip, idMap) => {
86
- for (const [oldPath, entry] of Object.entries(zip.files)) {
87
- const newPath = (0, exports.updateAttachmentPath)(oldPath, idMap);
88
- if (newPath) {
89
- zip.file(newPath, await entry.async('blob')).remove(oldPath);
90
- }
91
- }
92
- };
93
- exports.updateAttachments = updateAttachments;