@manuscripts/transform 2.3.20 → 2.3.22-LEAN-3772.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.
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; } });
@@ -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;
@@ -61,33 +61,6 @@ exports.section = {
61
61
  },
62
62
  },
63
63
  ],
64
- toDOM: (node) => {
65
- const sectionNode = node;
66
- const { id, category, titleSuppressed, generatedLabel, pageBreakStyle } = sectionNode.attrs;
67
- const classnames = [];
68
- if (titleSuppressed) {
69
- classnames.push('title-suppressed');
70
- }
71
- if (typeof generatedLabel === 'undefined' || generatedLabel) {
72
- classnames.push('generated-label');
73
- }
74
- if (pageBreakStyle === exports.PAGE_BREAK_BEFORE ||
75
- pageBreakStyle === exports.PAGE_BREAK_BEFORE_AND_AFTER) {
76
- classnames.push('page-break-before');
77
- }
78
- if (pageBreakStyle === exports.PAGE_BREAK_AFTER ||
79
- pageBreakStyle === exports.PAGE_BREAK_BEFORE_AND_AFTER) {
80
- classnames.push('page-break-after');
81
- }
82
- const attrs = { id };
83
- if (classnames.length) {
84
- attrs['class'] = classnames.join(' ');
85
- }
86
- if (category) {
87
- attrs['data-category'] = node.attrs.category;
88
- }
89
- return ['section', attrs, 0];
90
- },
91
64
  };
92
65
  const isSectionNode = (node) => node.type === node.type.schema.nodes.section;
93
66
  exports.isSectionNode = isSectionNode;
@@ -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.20";
4
+ exports.VERSION = "2.3.22-LEAN-3772.0";
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';
@@ -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;
@@ -58,32 +58,5 @@ export const section = {
58
58
  },
59
59
  },
60
60
  ],
61
- toDOM: (node) => {
62
- const sectionNode = node;
63
- const { id, category, titleSuppressed, generatedLabel, pageBreakStyle } = sectionNode.attrs;
64
- const classnames = [];
65
- if (titleSuppressed) {
66
- classnames.push('title-suppressed');
67
- }
68
- if (typeof generatedLabel === 'undefined' || generatedLabel) {
69
- classnames.push('generated-label');
70
- }
71
- if (pageBreakStyle === PAGE_BREAK_BEFORE ||
72
- pageBreakStyle === PAGE_BREAK_BEFORE_AND_AFTER) {
73
- classnames.push('page-break-before');
74
- }
75
- if (pageBreakStyle === PAGE_BREAK_AFTER ||
76
- pageBreakStyle === PAGE_BREAK_BEFORE_AND_AFTER) {
77
- classnames.push('page-break-after');
78
- }
79
- const attrs = { id };
80
- if (classnames.length) {
81
- attrs['class'] = classnames.join(' ');
82
- }
83
- if (category) {
84
- attrs['data-category'] = node.attrs.category;
85
- }
86
- return ['section', attrs, 0];
87
- },
88
61
  };
89
62
  export const isSectionNode = (node) => node.type === node.type.schema.nodes.section;
@@ -1 +1 @@
1
- export const VERSION = "2.3.20";
1
+ export const VERSION = "2.3.22-LEAN-3772.0";
@@ -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;
@@ -1 +1 @@
1
- export declare const VERSION = "2.3.20";
1
+ export declare const VERSION = "2.3.22-LEAN-3772.0";
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.20",
4
+ "version": "2.3.22-LEAN-3772.0",
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
+ }