@manuscripts/transform 2.3.17 → 2.3.19-LEAN-3577-test

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 (59) 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/schema/migration/migrate.js +50 -0
  4. package/dist/cjs/schema/migration/migration-script.js +17 -0
  5. package/dist/cjs/schema/migration/migration-scripts/1.2.5.js +30 -0
  6. package/dist/cjs/schema/migration/migration-scripts/index.js +23 -0
  7. package/dist/cjs/schema/nodes/equation_element.js +0 -1
  8. package/dist/cjs/schema/nodes/figure_element.js +0 -1
  9. package/dist/cjs/schema/nodes/footnote.js +0 -1
  10. package/dist/cjs/schema/nodes/inline_equation.js +0 -1
  11. package/dist/cjs/schema/nodes/keyword.js +0 -1
  12. package/dist/cjs/schema/nodes/listing.js +0 -1
  13. package/dist/cjs/schema/nodes/listing_element.js +0 -1
  14. package/dist/cjs/schema/nodes/paragraph.js +0 -1
  15. package/dist/cjs/schema/nodes/section.js +0 -1
  16. package/dist/cjs/schema/nodes/table_element.js +0 -1
  17. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +37 -0
  18. package/dist/cjs/transformer/decode.js +0 -13
  19. package/dist/cjs/transformer/index.js +3 -0
  20. package/dist/cjs/version.js +1 -1
  21. package/dist/es/__tests__/data/project-dump.json +825 -0
  22. package/dist/es/index.js +1 -0
  23. package/dist/es/schema/migration/migrate.js +42 -0
  24. package/dist/es/schema/migration/migration-script.js +16 -0
  25. package/dist/es/schema/migration/migration-scripts/1.2.5.js +28 -0
  26. package/dist/es/schema/migration/migration-scripts/index.js +18 -0
  27. package/dist/es/schema/nodes/equation_element.js +0 -1
  28. package/dist/es/schema/nodes/figure_element.js +0 -1
  29. package/dist/es/schema/nodes/footnote.js +0 -1
  30. package/dist/es/schema/nodes/inline_equation.js +0 -1
  31. package/dist/es/schema/nodes/keyword.js +0 -1
  32. package/dist/es/schema/nodes/listing.js +0 -1
  33. package/dist/es/schema/nodes/listing_element.js +0 -1
  34. package/dist/es/schema/nodes/paragraph.js +0 -1
  35. package/dist/es/schema/nodes/section.js +0 -1
  36. package/dist/es/schema/nodes/table_element.js +0 -1
  37. package/dist/es/transformer/__tests__/__helpers__/doc.js +29 -0
  38. package/dist/es/transformer/decode.js +0 -13
  39. package/dist/es/transformer/index.js +1 -0
  40. package/dist/es/version.js +1 -1
  41. package/dist/types/index.d.ts +1 -0
  42. package/dist/types/schema/migration/migrate.d.ts +15 -0
  43. package/dist/types/schema/migration/migration-script.d.ts +21 -0
  44. package/dist/types/schema/migration/migration-scripts/1.2.5.d.ts +23 -0
  45. package/dist/types/schema/migration/migration-scripts/index.d.ts +18 -0
  46. package/dist/types/schema/nodes/equation_element.d.ts +0 -2
  47. package/dist/types/schema/nodes/figure_element.d.ts +0 -2
  48. package/dist/types/schema/nodes/footnote.d.ts +0 -2
  49. package/dist/types/schema/nodes/inline_equation.d.ts +0 -2
  50. package/dist/types/schema/nodes/keyword.d.ts +0 -2
  51. package/dist/types/schema/nodes/listing.d.ts +0 -2
  52. package/dist/types/schema/nodes/listing_element.d.ts +0 -2
  53. package/dist/types/schema/nodes/paragraph.d.ts +0 -2
  54. package/dist/types/schema/nodes/section.d.ts +0 -2
  55. package/dist/types/schema/nodes/table_element.d.ts +0 -2
  56. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +18 -0
  57. package/dist/types/transformer/index.d.ts +1 -0
  58. package/dist/types/version.d.ts +1 -1
  59. 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; } });
@@ -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.4';
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;
@@ -22,7 +22,6 @@ exports.equationElement = {
22
22
  id: { default: '' },
23
23
  label: { default: '' },
24
24
  dataTracked: { default: null },
25
- comments: { default: null },
26
25
  },
27
26
  selectable: false,
28
27
  group: 'block element',
@@ -30,7 +30,6 @@ exports.figureElement = {
30
30
  attribution: { default: undefined },
31
31
  alternatives: { default: undefined },
32
32
  dataTracked: { default: null },
33
- comments: { default: null },
34
33
  },
35
34
  selectable: false,
36
35
  group: 'block element executable',
@@ -25,7 +25,6 @@ exports.footnote = {
25
25
  paragraphStyle: { default: '' },
26
26
  placeholder: { default: '' },
27
27
  dataTracked: { default: null },
28
- comments: { default: null },
29
28
  },
30
29
  parseDOM: [
31
30
  {
@@ -19,7 +19,6 @@ exports.inlineEquation = void 0;
19
19
  exports.inlineEquation = {
20
20
  attrs: {
21
21
  dataTracked: { default: null },
22
- comments: { default: null },
23
22
  id: { default: '' },
24
23
  contents: { default: '' },
25
24
  format: { default: '' },
@@ -22,7 +22,6 @@ exports.keyword = {
22
22
  attrs: {
23
23
  id: { default: '' },
24
24
  dataTracked: { default: null },
25
- comments: { default: null },
26
25
  },
27
26
  group: 'block',
28
27
  selectable: false,
@@ -26,7 +26,6 @@ exports.listing = {
26
26
  isExpanded: { default: false },
27
27
  isExecuting: { default: false },
28
28
  dataTracked: { default: null },
29
- comments: { default: null },
30
29
  },
31
30
  draggable: false,
32
31
  selectable: false,
@@ -23,7 +23,6 @@ exports.listingElement = {
23
23
  suppressCaption: { default: true },
24
24
  suppressTitle: { default: undefined },
25
25
  dataTracked: { default: null },
26
- comments: { default: null },
27
26
  },
28
27
  group: 'block element',
29
28
  selectable: false,
@@ -25,7 +25,6 @@ exports.paragraph = {
25
25
  paragraphStyle: { default: '' },
26
26
  placeholder: { default: '' },
27
27
  dataTracked: { default: null },
28
- comments: { default: null },
29
28
  },
30
29
  group: 'block element',
31
30
  selectable: false,
@@ -43,7 +43,6 @@ exports.section = {
43
43
  generatedLabel: { default: undefined },
44
44
  pageBreakStyle: { default: undefined },
45
45
  dataTracked: { default: null },
46
- comments: { default: null },
47
46
  },
48
47
  group: 'block sections',
49
48
  selectable: false,
@@ -29,7 +29,6 @@ exports.tableElement = {
29
29
  suppressHeader: { default: false },
30
30
  expandListing: { default: false },
31
31
  dataTracked: { default: null },
32
- comments: { default: null },
33
32
  },
34
33
  selectable: false,
35
34
  group: 'block element executable',
@@ -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;
@@ -222,7 +222,6 @@ class Decoder {
222
222
  page: model.page,
223
223
  title: model.title,
224
224
  literal: model.literal,
225
- comments: comments.map((c) => c.attrs.id),
226
225
  });
227
226
  },
228
227
  [object_types_1.ExtraObjectTypes.PlaceholderElement]: (data) => {
@@ -240,7 +239,6 @@ class Decoder {
240
239
  contentType: model.contentType,
241
240
  src: model.src,
242
241
  position: model.position,
243
- comments: comments.map((c) => c.attrs.id),
244
242
  });
245
243
  },
246
244
  [json_schema_1.ObjectTypes.FigureElement]: (data) => {
@@ -291,7 +289,6 @@ class Decoder {
291
289
  suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
292
290
  attribution: model.attribution,
293
291
  alternatives: model.alternatives,
294
- comments: comments.map((c) => c.attrs.id),
295
292
  }, content);
296
293
  },
297
294
  [json_schema_1.ObjectTypes.Equation]: (data) => {
@@ -338,7 +335,6 @@ class Decoder {
338
335
  topNode: schema_1.schema.nodes.footnote.create({
339
336
  id: model._id,
340
337
  kind: model.kind,
341
- comments: comments.map((c) => c.attrs.id),
342
338
  }),
343
339
  });
344
340
  footnotesOfKind.push(footnote);
@@ -359,7 +355,6 @@ class Decoder {
359
355
  topNode: schema_1.schema.nodes.footnote.create({
360
356
  id: footnoteModel._id,
361
357
  kind: footnoteModel.kind,
362
- comments: comments.map((c) => c.attrs.id),
363
358
  }),
364
359
  });
365
360
  },
@@ -381,7 +376,6 @@ class Decoder {
381
376
  return schema_1.schema.nodes.keyword_group.create({
382
377
  id: keywordGroup._id,
383
378
  type: keywordGroup.type,
384
- comments: comments.map((c) => c.attrs.id),
385
379
  }, keywords);
386
380
  },
387
381
  [json_schema_1.ObjectTypes.Keyword]: (data) => {
@@ -391,7 +385,6 @@ class Decoder {
391
385
  return schema_1.schema.nodes.keyword.create({
392
386
  id: keyword._id,
393
387
  contents: keyword.name,
394
- comments: comments.map((c) => c.attrs.id),
395
388
  }, schema_1.schema.text(keyword.name));
396
389
  },
397
390
  [json_schema_1.ObjectTypes.ListElement]: (data) => {
@@ -405,7 +398,6 @@ class Decoder {
405
398
  id: model._id,
406
399
  listStyleType: model.listStyleType || 'order',
407
400
  paragraphStyle: model.paragraphStyle,
408
- comments: comments.map((c) => c.attrs.id),
409
401
  }),
410
402
  });
411
403
  case 'ul':
@@ -429,7 +421,6 @@ class Decoder {
429
421
  contents: model.contents,
430
422
  language: model.language,
431
423
  languageKey: model.languageKey,
432
- comments: comments.map((c) => c.attrs.id),
433
424
  });
434
425
  },
435
426
  [json_schema_1.ObjectTypes.ListingElement]: (data) => {
@@ -455,7 +446,6 @@ class Decoder {
455
446
  id: model._id,
456
447
  suppressCaption: model.suppressCaption,
457
448
  suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
458
- comments: comments.map((c) => c.attrs.id),
459
449
  }, [listing, figcaption]);
460
450
  },
461
451
  [json_schema_1.ObjectTypes.MissingFigure]: (data) => {
@@ -474,7 +464,6 @@ class Decoder {
474
464
  id: model._id,
475
465
  paragraphStyle: model.paragraphStyle,
476
466
  placeholder: model.placeholderInnerHTML,
477
- comments: comments.map((c) => c.attrs.id),
478
467
  }),
479
468
  });
480
469
  },
@@ -603,7 +592,6 @@ class Decoder {
603
592
  titleSuppressed: model.titleSuppressed,
604
593
  pageBreakStyle: model.pageBreakStyle,
605
594
  generatedLabel: model.generatedLabel,
606
- comments: comments.map((c) => c.attrs.id),
607
595
  }, content);
608
596
  if (!sectionNode) {
609
597
  console.error(model);
@@ -648,7 +636,6 @@ class Decoder {
648
636
  suppressHeader: model.suppressHeader,
649
637
  tableStyle: model.tableStyle,
650
638
  paragraphStyle: model.paragraphStyle,
651
- comments: comments.map((c) => c.attrs.id),
652
639
  }, content);
653
640
  },
654
641
  [json_schema_1.ObjectTypes.TOCElement]: (data) => {
@@ -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; } });
@@ -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.17";
4
+ exports.VERSION = "2.3.19-LEAN-3577-test";