@manuscripts/transform 2.3.19 → 2.3.21-JSR

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 (40) hide show
  1. package/dist/cjs/__tests__/data/project-dump.json +825 -0
  2. package/dist/cjs/index.js +3 -1
  3. package/dist/cjs/jats/jats-exporter.js +1 -1
  4. package/dist/cjs/schema/migration/migrate.js +50 -0
  5. package/dist/cjs/schema/migration/migration-script.js +17 -0
  6. package/dist/cjs/schema/migration/migration-scripts/1.2.5.js +30 -0
  7. package/dist/cjs/schema/migration/migration-scripts/index.js +23 -0
  8. package/dist/cjs/schema/nodes/manuscript.js +3 -0
  9. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +37 -0
  10. package/dist/cjs/transformer/decode.js +7 -3
  11. package/dist/cjs/transformer/html.js +1 -2
  12. package/dist/cjs/transformer/index.js +3 -0
  13. package/dist/cjs/transformer/labels.js +3 -16
  14. package/dist/cjs/version.js +1 -1
  15. package/dist/es/__tests__/data/project-dump.json +825 -0
  16. package/dist/es/index.js +1 -0
  17. package/dist/es/jats/jats-exporter.js +1 -1
  18. package/dist/es/schema/migration/migrate.js +42 -0
  19. package/dist/es/schema/migration/migration-script.js +16 -0
  20. package/dist/es/schema/migration/migration-scripts/1.2.5.js +28 -0
  21. package/dist/es/schema/migration/migration-scripts/index.js +18 -0
  22. package/dist/es/schema/nodes/manuscript.js +3 -0
  23. package/dist/es/transformer/__tests__/__helpers__/doc.js +29 -0
  24. package/dist/es/transformer/decode.js +7 -3
  25. package/dist/es/transformer/html.js +1 -2
  26. package/dist/es/transformer/index.js +1 -0
  27. package/dist/es/transformer/labels.js +3 -16
  28. package/dist/es/version.js +1 -1
  29. package/dist/types/index.d.ts +1 -0
  30. package/dist/types/schema/migration/migrate.d.ts +15 -0
  31. package/dist/types/schema/migration/migration-script.d.ts +21 -0
  32. package/dist/types/schema/migration/migration-scripts/1.2.5.d.ts +23 -0
  33. package/dist/types/schema/migration/migration-scripts/index.d.ts +18 -0
  34. package/dist/types/schema/nodes/manuscript.d.ts +3 -0
  35. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +18 -0
  36. package/dist/types/transformer/decode.d.ts +1 -1
  37. package/dist/types/transformer/index.d.ts +1 -0
  38. package/dist/types/transformer/labels.d.ts +1 -2
  39. package/dist/types/version.d.ts +1 -1
  40. package/package.json +6 -3
package/dist/cjs/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.isSectionLabelNode = exports.getVersion = void 0;
17
+ exports.isSectionLabelNode = exports.migrateFor = exports.getVersion = void 0;
18
18
  __exportStar(require("./lib/section-group-type"), exports);
19
19
  __exportStar(require("./lib/table-cell-styles"), exports);
20
20
  __exportStar(require("./lib/utils"), exports);
@@ -25,5 +25,7 @@ __exportStar(require("./types"), exports);
25
25
  __exportStar(require("./errors"), exports);
26
26
  var getVersion_1 = require("./getVersion");
27
27
  Object.defineProperty(exports, "getVersion", { enumerable: true, get: function () { return getVersion_1.getVersion; } });
28
+ var migrate_1 = require("./schema/migration/migrate");
29
+ Object.defineProperty(exports, "migrateFor", { enumerable: true, get: function () { return migrate_1.migrateFor; } });
28
30
  var section_label_1 = require("./schema/nodes/section_label");
29
31
  Object.defineProperty(exports, "isSectionLabelNode", { enumerable: true, get: function () { return section_label_1.isSectionLabelNode; } });
@@ -143,7 +143,7 @@ class JATSExporter {
143
143
  const manuscript = (0, project_bundle_1.findManuscriptById)(this.modelMap, manuscriptID);
144
144
  article.setAttribute('article-type', manuscript.articleType || 'other');
145
145
  if (!frontMatterOnly) {
146
- this.labelTargets = (0, labels_1.buildTargets)(fragment, manuscript);
146
+ this.labelTargets = (0, labels_1.buildTargets)(fragment);
147
147
  const body = this.buildBody(fragment);
148
148
  article.appendChild(body);
149
149
  const back = this.buildBack(body);
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.migrateFor = void 0;
7
+ const lodash_1 = require("lodash");
8
+ const semver_1 = __importDefault(require("semver"));
9
+ const __1 = require("..");
10
+ const migration_scripts_1 = __importDefault(require("./migration-scripts"));
11
+ function migrate(oldDoc, migrationScript) {
12
+ function migrateNode(node) {
13
+ const migrated = migrationScript(node, oldDoc);
14
+ if (migrated.content) {
15
+ migrated.content = migrated.content.map((m) => migrateNode(m));
16
+ }
17
+ return migrated;
18
+ }
19
+ return migrateNode(oldDoc);
20
+ }
21
+ exports.default = migrate;
22
+ function migrateFor(oldDoc, baseVersion) {
23
+ const migrationScripts = ensureVersionAscOrder();
24
+ let migratedDoc = (0, lodash_1.cloneDeep)(oldDoc);
25
+ for (let i = 0; i < migrationScripts.length; i++) {
26
+ const script = migrationScripts[i];
27
+ if (semver_1.default.lt(script.fromVersion, baseVersion)) {
28
+ continue;
29
+ }
30
+ console.log('Migrating doc with script to version ' + script.toVersion);
31
+ migratedDoc = migrate(migratedDoc, script.migrateNode);
32
+ }
33
+ return testDoc(migratedDoc, baseVersion);
34
+ }
35
+ exports.migrateFor = migrateFor;
36
+ const ensureVersionAscOrder = () => migration_scripts_1.default.sort((a, b) => semver_1.default.compare(a.toVersion, b.toVersion));
37
+ function testDoc(doc, fromVersion) {
38
+ try {
39
+ const resultDoc = __1.schema.nodeFromJSON(doc);
40
+ resultDoc.check();
41
+ return resultDoc;
42
+ }
43
+ catch (e) {
44
+ const error = 'Migration application from version ' +
45
+ fromVersion +
46
+ ' did not produce a valid document with ' +
47
+ e;
48
+ throw new Error(error);
49
+ }
50
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2024 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 });
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2024 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
+ class Migration125 {
19
+ constructor() {
20
+ this.fromVersion = '1.2.3';
21
+ this.toVersion = '1.2.5';
22
+ }
23
+ migrateNode(node, doc) {
24
+ if (node.type === 'paragraph') {
25
+ return Object.assign(Object.assign({}, node), { attrs: Object.assign(Object.assign({}, node.attrs), { someNewFanctAttribute: 'example-value' }) });
26
+ }
27
+ return node;
28
+ }
29
+ }
30
+ exports.default = Migration125;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2024 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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ const _1_2_5_1 = __importDefault(require("./1.2.5"));
22
+ const migrations = [new _1_2_5_1.default()];
23
+ exports.default = migrations;
@@ -21,6 +21,9 @@ exports.manuscript = {
21
21
  attrs: {
22
22
  id: { default: '' },
23
23
  doi: { default: '' },
24
+ prototype: { default: '' },
25
+ primaryLanguageCode: { default: '' },
26
+ articleType: { default: '' },
24
27
  },
25
28
  group: 'block',
26
29
  parseDOM: [
@@ -0,0 +1,37 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.createTestDoc = exports.createTestModelMap = void 0;
22
+ const project_dump_json_1 = __importDefault(require("../../../__tests__/data/project-dump.json"));
23
+ const decode_1 = require("../../decode");
24
+ const createTestModelMap = () => {
25
+ const modelMap = new Map();
26
+ for (const component of project_dump_json_1.default.data) {
27
+ modelMap.set(component._id, component);
28
+ }
29
+ return modelMap;
30
+ };
31
+ exports.createTestModelMap = createTestModelMap;
32
+ const createTestDoc = () => {
33
+ const modelMap = (0, exports.createTestModelMap)();
34
+ const decoder = new decode_1.Decoder(modelMap);
35
+ return decoder.createArticleNode();
36
+ };
37
+ exports.createTestDoc = createTestDoc;
@@ -727,9 +727,13 @@ class Decoder {
727
727
  this.createCommentsNode(),
728
728
  ];
729
729
  const contents = nodes.filter((node) => node !== false);
730
+ const props = this.getManuscript();
730
731
  return schema_1.schema.nodes.manuscript.create({
731
732
  id: manuscriptID || this.getManuscriptID(),
732
- doi: this.getManuscriptDOI() || '',
733
+ doi: (props === null || props === void 0 ? void 0 : props.DOI) || '',
734
+ articleType: props === null || props === void 0 ? void 0 : props.articleType,
735
+ prototype: props === null || props === void 0 ? void 0 : props.prototype,
736
+ primaryLanguageCode: props === null || props === void 0 ? void 0 : props.primaryLanguageCode,
733
737
  }, contents);
734
738
  };
735
739
  this.addGeneratedLabels = (sections) => {
@@ -775,10 +779,10 @@ class Decoder {
775
779
  }
776
780
  }
777
781
  };
778
- this.getManuscriptDOI = () => {
782
+ this.getManuscript = () => {
779
783
  for (const item of this.modelMap.values()) {
780
784
  if ((0, object_types_1.isManuscript)(item)) {
781
- return item.DOI;
785
+ return item;
782
786
  }
783
787
  }
784
788
  };
@@ -75,8 +75,7 @@ class HTMLTransformer {
75
75
  this.serializeToHTML = async (fragment, modelMap, options = {}) => {
76
76
  const { idGenerator, mediaPathGenerator } = options;
77
77
  this.modelMap = modelMap;
78
- const manuscript = (0, project_bundle_1.findManuscript)(this.modelMap);
79
- this.labelTargets = (0, labels_1.buildTargets)(fragment, manuscript);
78
+ this.labelTargets = (0, labels_1.buildTargets)(fragment);
80
79
  this.document = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', document.implementation.createDocumentType('html', '', ''));
81
80
  const article = this.document.createElement('article');
82
81
  this.document.documentElement.appendChild(article);
@@ -29,6 +29,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
29
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.createTestDoc = void 0;
32
33
  __exportStar(require("./builders"), exports);
33
34
  __exportStar(require("./decode"), exports);
34
35
  __exportStar(require("./document-object-types"), exports);
@@ -49,3 +50,5 @@ __exportStar(require("./section-category"), exports);
49
50
  __exportStar(require("./serializer"), exports);
50
51
  __exportStar(require("./timestamp"), exports);
51
52
  __exportStar(require("./update-identifiers"), exports);
53
+ var doc_1 = require("./__tests__/__helpers__/doc");
54
+ Object.defineProperty(exports, "createTestDoc", { enumerable: true, get: function () { return doc_1.createTestDoc; } });
@@ -24,28 +24,15 @@ const labelledNodeTypes = [
24
24
  schema_1.schema.nodes.equation_element,
25
25
  schema_1.schema.nodes.listing_element,
26
26
  ];
27
- const labelProperties = new Map([
28
- [schema_1.schema.nodes.figure_element, 'figureElementLabel'],
29
- [schema_1.schema.nodes.table_element, 'tableElementLabel'],
30
- [schema_1.schema.nodes.equation_element, 'equationElementLabel'],
31
- [schema_1.schema.nodes.listing_element, 'listingElementLabel'],
32
- ]);
33
27
  const excludedTypes = [schema_1.schema.nodes.graphical_abstract_section];
34
- const chooseLabel = (nodeType, manuscript) => {
35
- const labelProperty = labelProperties.get(nodeType);
36
- if (labelProperty) {
37
- const label = manuscript[labelProperty];
38
- if (label) {
39
- return label;
40
- }
41
- }
28
+ const chooseLabel = (nodeType) => {
42
29
  return node_names_1.nodeNames.get(nodeType);
43
30
  };
44
- const buildTargets = (fragment, manuscript) => {
31
+ const buildTargets = (fragment) => {
45
32
  const counters = {};
46
33
  for (const nodeType of labelledNodeTypes) {
47
34
  counters[nodeType.name] = {
48
- label: chooseLabel(nodeType, manuscript),
35
+ label: chooseLabel(nodeType),
49
36
  index: 0,
50
37
  };
51
38
  }
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "2.3.19";
4
+ exports.VERSION = "2.3.21-JSR";