@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/es/index.js CHANGED
@@ -7,4 +7,5 @@ export * from './jats';
7
7
  export * from './types';
8
8
  export * from './errors';
9
9
  export { getVersion } from './getVersion';
10
+ export { migrateFor } from './schema/migration/migrate';
10
11
  export { isSectionLabelNode } from './schema/nodes/section_label';
@@ -135,7 +135,7 @@ export class JATSExporter {
135
135
  const manuscript = findManuscriptById(this.modelMap, manuscriptID);
136
136
  article.setAttribute('article-type', manuscript.articleType || 'other');
137
137
  if (!frontMatterOnly) {
138
- this.labelTargets = buildTargets(fragment, manuscript);
138
+ this.labelTargets = buildTargets(fragment);
139
139
  const body = this.buildBody(fragment);
140
140
  article.appendChild(body);
141
141
  const back = this.buildBack(body);
@@ -0,0 +1,42 @@
1
+ import { cloneDeep } from 'lodash';
2
+ import semver from 'semver';
3
+ import { schema } from '..';
4
+ import migrationScripts from './migration-scripts';
5
+ export default function migrate(oldDoc, migrationScript) {
6
+ function migrateNode(node) {
7
+ const migrated = migrationScript(node, oldDoc);
8
+ if (migrated.content) {
9
+ migrated.content = migrated.content.map((m) => migrateNode(m));
10
+ }
11
+ return migrated;
12
+ }
13
+ return migrateNode(oldDoc);
14
+ }
15
+ export function migrateFor(oldDoc, baseVersion) {
16
+ const migrationScripts = ensureVersionAscOrder();
17
+ let migratedDoc = cloneDeep(oldDoc);
18
+ for (let i = 0; i < migrationScripts.length; i++) {
19
+ const script = migrationScripts[i];
20
+ if (semver.lt(script.fromVersion, baseVersion)) {
21
+ continue;
22
+ }
23
+ console.log('Migrating doc with script to version ' + script.toVersion);
24
+ migratedDoc = migrate(migratedDoc, script.migrateNode);
25
+ }
26
+ return testDoc(migratedDoc, baseVersion);
27
+ }
28
+ const ensureVersionAscOrder = () => migrationScripts.sort((a, b) => semver.compare(a.toVersion, b.toVersion));
29
+ function testDoc(doc, fromVersion) {
30
+ try {
31
+ const resultDoc = schema.nodeFromJSON(doc);
32
+ resultDoc.check();
33
+ return resultDoc;
34
+ }
35
+ catch (e) {
36
+ const error = 'Migration application from version ' +
37
+ fromVersion +
38
+ ' did not produce a valid document with ' +
39
+ e;
40
+ throw new Error(error);
41
+ }
42
+ }
@@ -0,0 +1,16 @@
1
+ /*!
2
+ * © 2024 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
+ */
16
+ export {};
@@ -0,0 +1,28 @@
1
+ /*!
2
+ * © 2024 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
+ */
16
+ class Migration125 {
17
+ constructor() {
18
+ this.fromVersion = '1.2.3';
19
+ this.toVersion = '1.2.5';
20
+ }
21
+ migrateNode(node, doc) {
22
+ if (node.type === 'paragraph') {
23
+ return Object.assign(Object.assign({}, node), { attrs: Object.assign(Object.assign({}, node.attrs), { someNewFanctAttribute: 'example-value' }) });
24
+ }
25
+ return node;
26
+ }
27
+ }
28
+ export default Migration125;
@@ -0,0 +1,18 @@
1
+ /*!
2
+ * © 2024 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
+ */
16
+ import Migration125 from './1.2.5';
17
+ const migrations = [new Migration125()];
18
+ export default migrations;
@@ -18,6 +18,9 @@ export const manuscript = {
18
18
  attrs: {
19
19
  id: { default: '' },
20
20
  doi: { default: '' },
21
+ prototype: { default: '' },
22
+ primaryLanguageCode: { default: '' },
23
+ articleType: { default: '' },
21
24
  },
22
25
  group: 'block',
23
26
  parseDOM: [
@@ -0,0 +1,29 @@
1
+ /*!
2
+ * © 2019 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
+ */
16
+ import projectDump from '../../../__tests__/data/project-dump.json';
17
+ import { Decoder } from '../../decode';
18
+ export const createTestModelMap = () => {
19
+ const modelMap = new Map();
20
+ for (const component of projectDump.data) {
21
+ modelMap.set(component._id, component);
22
+ }
23
+ return modelMap;
24
+ };
25
+ export const createTestDoc = () => {
26
+ const modelMap = createTestModelMap();
27
+ const decoder = new Decoder(modelMap);
28
+ return decoder.createArticleNode();
29
+ };
@@ -718,9 +718,13 @@ export class Decoder {
718
718
  this.createCommentsNode(),
719
719
  ];
720
720
  const contents = nodes.filter((node) => node !== false);
721
+ const props = this.getManuscript();
721
722
  return schema.nodes.manuscript.create({
722
723
  id: manuscriptID || this.getManuscriptID(),
723
- doi: this.getManuscriptDOI() || '',
724
+ doi: (props === null || props === void 0 ? void 0 : props.DOI) || '',
725
+ articleType: props === null || props === void 0 ? void 0 : props.articleType,
726
+ prototype: props === null || props === void 0 ? void 0 : props.prototype,
727
+ primaryLanguageCode: props === null || props === void 0 ? void 0 : props.primaryLanguageCode,
724
728
  }, contents);
725
729
  };
726
730
  this.addGeneratedLabels = (sections) => {
@@ -766,10 +770,10 @@ export class Decoder {
766
770
  }
767
771
  }
768
772
  };
769
- this.getManuscriptDOI = () => {
773
+ this.getManuscript = () => {
770
774
  for (const item of this.modelMap.values()) {
771
775
  if (isManuscript(item)) {
772
- return item.DOI;
776
+ return item;
773
777
  }
774
778
  }
775
779
  };
@@ -69,8 +69,7 @@ export class HTMLTransformer {
69
69
  this.serializeToHTML = async (fragment, modelMap, options = {}) => {
70
70
  const { idGenerator, mediaPathGenerator } = options;
71
71
  this.modelMap = modelMap;
72
- const manuscript = findManuscript(this.modelMap);
73
- this.labelTargets = buildTargets(fragment, manuscript);
72
+ this.labelTargets = buildTargets(fragment);
74
73
  this.document = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', document.implementation.createDocumentType('html', '', ''));
75
74
  const article = this.document.createElement('article');
76
75
  this.document.documentElement.appendChild(article);
@@ -33,3 +33,4 @@ export * from './section-category';
33
33
  export * from './serializer';
34
34
  export * from './timestamp';
35
35
  export * from './update-identifiers';
36
+ export { createTestDoc } from './__tests__/__helpers__/doc';
@@ -21,28 +21,15 @@ const labelledNodeTypes = [
21
21
  schema.nodes.equation_element,
22
22
  schema.nodes.listing_element,
23
23
  ];
24
- const labelProperties = new Map([
25
- [schema.nodes.figure_element, 'figureElementLabel'],
26
- [schema.nodes.table_element, 'tableElementLabel'],
27
- [schema.nodes.equation_element, 'equationElementLabel'],
28
- [schema.nodes.listing_element, 'listingElementLabel'],
29
- ]);
30
24
  const excludedTypes = [schema.nodes.graphical_abstract_section];
31
- const chooseLabel = (nodeType, manuscript) => {
32
- const labelProperty = labelProperties.get(nodeType);
33
- if (labelProperty) {
34
- const label = manuscript[labelProperty];
35
- if (label) {
36
- return label;
37
- }
38
- }
25
+ const chooseLabel = (nodeType) => {
39
26
  return nodeNames.get(nodeType);
40
27
  };
41
- export const buildTargets = (fragment, manuscript) => {
28
+ export const buildTargets = (fragment) => {
42
29
  const counters = {};
43
30
  for (const nodeType of labelledNodeTypes) {
44
31
  counters[nodeType.name] = {
45
- label: chooseLabel(nodeType, manuscript),
32
+ label: chooseLabel(nodeType),
46
33
  index: 0,
47
34
  };
48
35
  }
@@ -1 +1 @@
1
- export const VERSION = "2.3.19";
1
+ export const VERSION = "2.3.21-JSR";
@@ -7,4 +7,5 @@ export * from './jats';
7
7
  export * from './types';
8
8
  export * from './errors';
9
9
  export { getVersion } from './getVersion';
10
+ export { migrateFor, JSONNode } from './schema/migration/migrate';
10
11
  export { isSectionLabelNode } from './schema/nodes/section_label';
@@ -0,0 +1,15 @@
1
+ import { MigrationScript } from './migration-script';
2
+ export type JSONNode = {
3
+ type: string;
4
+ attrs: {
5
+ [key: string]: any;
6
+ };
7
+ content?: JSONNode[];
8
+ text?: string;
9
+ marks?: Array<{
10
+ type: string;
11
+ attrs?: Record<string, any>;
12
+ }>;
13
+ };
14
+ export default function migrate(oldDoc: JSONNode, migrationScript: MigrationScript['migrateNode']): JSONNode;
15
+ export declare function migrateFor(oldDoc: JSONNode, baseVersion: string): import("prosemirror-model").Node;
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * © 2024 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
+ */
16
+ import { JSONNode } from './migrate';
17
+ export interface MigrationScript {
18
+ fromVersion: string;
19
+ toVersion: string;
20
+ migrateNode: (node: JSONNode, doc: JSONNode) => JSONNode;
21
+ }
@@ -0,0 +1,23 @@
1
+ /*!
2
+ * © 2024 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
+ */
16
+ import { JSONNode } from '../migrate';
17
+ import { MigrationScript } from '../migration-script';
18
+ declare class Migration125 implements MigrationScript {
19
+ fromVersion: string;
20
+ toVersion: string;
21
+ migrateNode(node: JSONNode, doc: JSONNode): JSONNode;
22
+ }
23
+ export default Migration125;
@@ -0,0 +1,18 @@
1
+ /*!
2
+ * © 2024 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
+ */
16
+ import Migration125 from './1.2.5';
17
+ declare const migrations: Migration125[];
18
+ export default migrations;
@@ -19,6 +19,9 @@ export interface ActualManuscriptNode extends ManuscriptNode {
19
19
  attrs: {
20
20
  id: string;
21
21
  doi: string;
22
+ articleType: string;
23
+ prototype: string;
24
+ primaryLanguageCode: string;
22
25
  };
23
26
  }
24
27
  export declare const manuscript: NodeSpec;
@@ -0,0 +1,18 @@
1
+ /*!
2
+ * © 2019 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
+ */
16
+ import { Model } from '@manuscripts/json-schema';
17
+ export declare const createTestModelMap: () => Map<string, Model>;
18
+ export declare const createTestDoc: () => import("prosemirror-model").Node;
@@ -42,7 +42,7 @@ export declare class Decoder {
42
42
  addGeneratedLabels: (sections: Section[]) => Section[];
43
43
  parseContents: (contents: string, wrapper?: string, commentAnnotations?: CommentAnnotation[], options?: ParseOptions) => ManuscriptNode;
44
44
  private getManuscriptID;
45
- private getManuscriptDOI;
45
+ private getManuscript;
46
46
  private getFigcaption;
47
47
  private createTable;
48
48
  private createTableColGroup;
@@ -33,3 +33,4 @@ export * from './section-category';
33
33
  export * from './serializer';
34
34
  export * from './timestamp';
35
35
  export * from './update-identifiers';
36
+ export { createTestDoc } from './__tests__/__helpers__/doc';
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Manuscript } from '@manuscripts/json-schema';
17
16
  import { ManuscriptFragment } from '../schema';
18
17
  export interface Target {
19
18
  type: string;
@@ -21,4 +20,4 @@ export interface Target {
21
20
  label: string;
22
21
  caption: string;
23
22
  }
24
- export declare const buildTargets: (fragment: ManuscriptFragment, manuscript: Manuscript) => Map<string, Target>;
23
+ export declare const buildTargets: (fragment: ManuscriptFragment) => Map<string, Target>;
@@ -1 +1 @@
1
- export declare const VERSION = "2.3.19";
1
+ export declare const VERSION = "2.3.21-JSR";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@manuscripts/transform",
3
3
  "description": "ProseMirror transformer for Manuscripts applications",
4
- "version": "2.3.19",
4
+ "version": "2.3.21-JSR",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -34,9 +34,11 @@
34
34
  "@manuscripts/library": "1.3.10",
35
35
  "debug": "^4.3.4",
36
36
  "jszip": "^3.10.1",
37
+ "lodash": "^4.17.21",
37
38
  "mime": "^3.0.0",
38
39
  "prosemirror-model": "^1.18.3",
39
40
  "prosemirror-tables": "^1.3.5",
41
+ "semver": "^7.6.2",
40
42
  "uuid": "^9.0.0",
41
43
  "w3c-xmlserializer": "^4.0.0"
42
44
  },
@@ -47,7 +49,7 @@
47
49
  "@jats4r/dtds": "^0.0.8",
48
50
  "@manuscripts/eslint-config": "^0.5.1",
49
51
  "@types/debug": "^4.1.7",
50
- "@types/jest": "^29.2.4",
52
+ "@types/jest": "^29.5.12",
51
53
  "@types/lodash.pickby": "^4.6.7",
52
54
  "@types/mime": "^3.0.1",
53
55
  "@types/node": "^18.11.18",
@@ -72,6 +74,7 @@
72
74
  "jest": "^29.3.1",
73
75
  "jest-environment-jsdom": "^29.3.1",
74
76
  "libxmljs2": "^0.33.0",
77
+ "migration-base": "npm:@manuscripts/transform@2.3.20",
75
78
  "npm-run-all": "^4.1.5",
76
79
  "prettier": "^2.8.1",
77
80
  "prosemirror-state": "^1.4.2",
@@ -79,4 +82,4 @@
79
82
  "rimraf": "^3.0.2",
80
83
  "typescript": "^4.0.5"
81
84
  }
82
- }
85
+ }