proskomma-core 0.9.12 → 0.9.13

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 (167) hide show
  1. package/esm/wrapper.mjs +1 -1
  2. package/{index.js → index.cjs} +1 -1
  3. package/package.json +2 -2
  4. package/babel.config.js +0 -18
  5. package/test/code/main/bad.cjs +0 -79
  6. package/test/code/main/basics.cjs +0 -534
  7. package/test/code/main/block.cjs +0 -586
  8. package/test/code/main/block_scope_numbers.cjs +0 -31
  9. package/test/code/main/blocks_with_atts.cjs +0 -150
  10. package/test/code/main/blocks_with_cv.cjs +0 -250
  11. package/test/code/main/break.cjs +0 -73
  12. package/test/code/main/checksum.cjs +0 -36
  13. package/test/code/main/cl_global.cjs +0 -35
  14. package/test/code/main/class_for_fragment.cjs +0 -18
  15. package/test/code/main/clean_usfm.cjs +0 -46
  16. package/test/code/main/cp_vp.cjs +0 -158
  17. package/test/code/main/custom.cjs +0 -124
  18. package/test/code/main/cv.cjs +0 -249
  19. package/test/code/main/cvMatching.cjs +0 -155
  20. package/test/code/main/cv_indexes.cjs +0 -189
  21. package/test/code/main/cv_navigation.cjs +0 -124
  22. package/test/code/main/document.cjs +0 -382
  23. package/test/code/main/empty_blocks.cjs +0 -71
  24. package/test/code/main/entries.cjs +0 -402
  25. package/test/code/main/export_lexing_regexes.cjs +0 -19
  26. package/test/code/main/fig.cjs +0 -67
  27. package/test/code/main/filter.cjs +0 -222
  28. package/test/code/main/glossary.cjs +0 -36
  29. package/test/code/main/graft_headings.cjs +0 -36
  30. package/test/code/main/graft_introduction.cjs +0 -96
  31. package/test/code/main/graft_note.cjs +0 -104
  32. package/test/code/main/graft_rems.cjs +0 -34
  33. package/test/code/main/graft_sidebars.cjs +0 -62
  34. package/test/code/main/graft_title.cjs +0 -36
  35. package/test/code/main/hello.cjs +0 -105
  36. package/test/code/main/import_document.cjs +0 -22
  37. package/test/code/main/import_usfm_int.cjs +0 -48
  38. package/test/code/main/item_groups.cjs +0 -133
  39. package/test/code/main/items_with_cv.cjs +0 -311
  40. package/test/code/main/milestone_attributes.cjs +0 -163
  41. package/test/code/main/mixed_sequence_documents.cjs +0 -137
  42. package/test/code/main/mixed_sequences.cjs +0 -217
  43. package/test/code/main/modify_sequence.cjs +0 -29
  44. package/test/code/main/multiple_chapters.cjs +0 -58
  45. package/test/code/main/multiple_content.cjs +0 -105
  46. package/test/code/main/mutate_add.cjs +0 -180
  47. package/test/code/main/mutate_delete.cjs +0 -236
  48. package/test/code/main/mutate_rehash.cjs +0 -68
  49. package/test/code/main/mutate_tags.cjs +0 -90
  50. package/test/code/main/mutate_update.cjs +0 -538
  51. package/test/code/main/selectors.cjs +0 -289
  52. package/test/code/main/sequence.cjs +0 -361
  53. package/test/code/main/serialize.cjs +0 -104
  54. package/test/code/main/spans.cjs +0 -51
  55. package/test/code/main/split_long_tokens.cjs +0 -30
  56. package/test/code/main/standard_vrs.cjs +0 -76
  57. package/test/code/main/subclass.cjs +0 -25
  58. package/test/code/main/table.cjs +0 -119
  59. package/test/code/main/tags.cjs +0 -248
  60. package/test/code/main/token_alignment.cjs +0 -84
  61. package/test/code/main/trees.cjs +0 -211
  62. package/test/code/main/tribos.cjs +0 -865
  63. package/test/code/main/tsv.cjs +0 -385
  64. package/test/code/main/usx_ref.cjs +0 -65
  65. package/test/code/main/verse_mapping.cjs +0 -252
  66. package/test/code/main/verse_range.cjs +0 -31
  67. package/test/code/main/word_likes.cjs +0 -41
  68. package/test/code/utils/byte_array.cjs +0 -271
  69. package/test/code/utils/canons.cjs +0 -20
  70. package/test/code/utils/generate_id.cjs +0 -17
  71. package/test/code/utils/graft_defs.cjs +0 -16
  72. package/test/code/utils/inspect.cjs +0 -130
  73. package/test/code/utils/items.cjs +0 -56
  74. package/test/code/utils/push_succinct.cjs +0 -69
  75. package/test/code/utils/scope_defs.cjs +0 -79
  76. package/test/code/utils/serialize.cjs +0 -28
  77. package/test/code/utils/splice.cjs +0 -67
  78. package/test/code/utils/tags.cjs +0 -69
  79. package/test/code/utils/versification.cjs +0 -249
  80. package/test/lib/load.js +0 -110
  81. package/test/skipped_code/diff.js +0 -53
  82. package/test/test_data/inputBlockSpec/dodson.json +0 -1654
  83. package/test/test_data/inputBlockSpec/kv.json +0 -326
  84. package/test/test_data/inputBlockSpec/mk1.json +0 -1019
  85. package/test/test_data/inputBlockSpec/table.json +0 -170
  86. package/test/test_data/tree/genealogy.json +0 -55
  87. package/test/test_data/tree/jude.json +0 -15965
  88. package/test/test_data/tsv/en_tn_66-JUD.tsv +0 -75
  89. package/test/test_data/tsv/twl_JUD.tsv +0 -144
  90. package/test/test_data/usfm/1pe_webbe.usfm +0 -13
  91. package/test/test_data/usfm/66-JUD-ust.usfm +0 -1089
  92. package/test/test_data/usfm/78-GALspavbl.usfm +0 -10
  93. package/test/test_data/usfm/add_test.usfm +0 -15
  94. package/test/test_data/usfm/backslash.usfm +0 -4
  95. package/test/test_data/usfm/cl.usfm +0 -14
  96. package/test/test_data/usfm/cp_vp.usfm +0 -8
  97. package/test/test_data/usfm/custom.usfm +0 -13
  98. package/test/test_data/usfm/en_ust_oba.usfm +0 -875
  99. package/test/test_data/usfm/en_ust_psa_1.usfm +0 -20
  100. package/test/test_data/usfm/fig.usfm +0 -3
  101. package/test/test_data/usfm/filter.usfm +0 -7
  102. package/test/test_data/usfm/footnote.usfm +0 -11
  103. package/test/test_data/usfm/frt.usfm +0 -4
  104. package/test/test_data/usfm/headings.usfm +0 -7
  105. package/test/test_data/usfm/hello.usfm +0 -8
  106. package/test/test_data/usfm/int.usfm +0 -7
  107. package/test/test_data/usfm/milestone_attributes.usfm +0 -7
  108. package/test/test_data/usfm/milestone_attributes_default.usfm +0 -7
  109. package/test/test_data/usfm/no_break_space.usfm +0 -4
  110. package/test/test_data/usfm/no_mt.usfm +0 -6
  111. package/test/test_data/usfm/rems.usfm +0 -6
  112. package/test/test_data/usfm/section_intros.usfm +0 -26
  113. package/test/test_data/usfm/sidebars.usfm +0 -25
  114. package/test/test_data/usfm/slash_in_att.usfm +0 -6
  115. package/test/test_data/usfm/soft_line_break.usfm +0 -4
  116. package/test/test_data/usfm/spans.usfm +0 -5
  117. package/test/test_data/usfm/split_long_tokens.usfm +0 -6
  118. package/test/test_data/usfm/table.usfm +0 -18
  119. package/test/test_data/usfm/table_at_end.usfm +0 -11
  120. package/test/test_data/usfm/table_in_intro.usfm +0 -22
  121. package/test/test_data/usfm/table_no_end_cells.usfm +0 -18
  122. package/test/test_data/usfm/tit_kitchen_sink.usfm +0 -73
  123. package/test/test_data/usfm/titus_template.usfm +0 -58
  124. package/test/test_data/usfm/ugnt_3jn.usfm +0 -265
  125. package/test/test_data/usfm/ult_3jn.usfm +0 -335
  126. package/test/test_data/usfm/unknown.usfm +0 -5
  127. package/test/test_data/usfm/ust_psa.usfm +0 -29
  128. package/test/test_data/usfm/ust_psa_verse_ranges.usfm +0 -24
  129. package/test/test_data/usfm/ust_psa_with_ts.usfm +0 -29
  130. package/test/test_data/usfm/verse_breaks_in_blocks.usfm +0 -20
  131. package/test/test_data/usfm/verse_range.usfm +0 -7
  132. package/test/test_data/usfm/web_ecc.usfm +0 -391
  133. package/test/test_data/usfm/web_psa51.usfm +0 -71
  134. package/test/test_data/usfm/whitespace.usfm +0 -12
  135. package/test/test_data/usfm/xref.usfm +0 -11
  136. package/test/test_data/usx/bad_element.usx +0 -2
  137. package/test/test_data/usx/cp_vp.usx +0 -12
  138. package/test/test_data/usx/diff1.usx +0 -59
  139. package/test/test_data/usx/diff2.usx +0 -74
  140. package/test/test_data/usx/douay_rheims_ecc.usx +0 -58
  141. package/test/test_data/usx/douay_rheims_psa.usx +0 -5366
  142. package/test/test_data/usx/douay_rheims_psa_40_60.usx +0 -666
  143. package/test/test_data/usx/douay_rheims_rut.usx +0 -26
  144. package/test/test_data/usx/esg3.usx +0 -47
  145. package/test/test_data/usx/fig.usx +0 -6
  146. package/test/test_data/usx/milestone_attributes.usx +0 -11
  147. package/test/test_data/usx/not_nfc18_glo.usx +0 -9
  148. package/test/test_data/usx/not_nfc18_phm.usx +0 -24
  149. package/test/test_data/usx/opt_break.usx +0 -10
  150. package/test/test_data/usx/sidebars.usx +0 -29
  151. package/test/test_data/usx/table.usx +0 -23
  152. package/test/test_data/usx/web_psa.usx +0 -8489
  153. package/test/test_data/usx/web_psa150.usx +0 -33
  154. package/test/test_data/usx/web_psa_40_60.usx +0 -1079
  155. package/test/test_data/usx/web_rut.usx +0 -95
  156. package/test/test_data/usx/web_rut_1.usx +0 -17
  157. package/test/test_data/utils/douay_rheims.vrs +0 -520
  158. package/test/test_data/utils/douay_rheims_PSA.usx +0 -5366
  159. package/test/test_data/utils/serialize_example.json +0 -91
  160. package/test/test_data/utils/truncated_versification.vrs +0 -29
  161. package/test/test_data/utils/web_rut_items.json +0 -2977
  162. package/test/test_data/utils/webbe.vrs +0 -395
  163. package/test/test_data/utils/webbe_PSA.usx +0 -8489
  164. package/test/test_data/vrs/douay_rheims.vrs +0 -520
  165. package/test/test_data/vrs/truncated_versification.vrs +0 -27
  166. package/test/test_data/vrs/webbe.vrs +0 -397
  167. package/webpack.prod.js +0 -50
@@ -1,163 +0,0 @@
1
- const test = require('tape');
2
-
3
- const { pkWithDoc } = require('../../lib/load.js');
4
-
5
- const testGroup = 'Milestones & Attributes';
6
-
7
- const pk = pkWithDoc('../test_data/usfm/milestone_attributes.usfm', {
8
- lang: 'fra',
9
- abbr: 'hello',
10
- })[0];
11
- const pk2 = pkWithDoc('../test_data/usx/milestone_attributes.usx', {
12
- lang: 'fra',
13
- abbr: 'hello',
14
- })[0];
15
- const pk3 = pkWithDoc('../test_data/usfm/milestone_attributes_default.usfm', {
16
- lang: 'fra',
17
- abbr: 'hello',
18
- })[0];
19
-
20
- const topItems = items => {
21
- if (items.length === 0) {
22
- return [];
23
- } else if (items[0].subType === 'start' && items[0].payload === 'milestone/zaln') {
24
- return items;
25
- } else {
26
- return topItems(items.slice(1));
27
- }
28
- };
29
-
30
- const tailItems = items => {
31
- if (items.length === 0) {
32
- return [];
33
- } else if (items[items.length - 1].subType === 'end' && items[items.length - 1].payload === 'milestone/zaln') {
34
- return items;
35
- } else {
36
- return tailItems(items.slice(0, items.length - 2));
37
- }
38
- };
39
-
40
- const topNTailItems = items => tailItems(topItems(items));
41
-
42
- const zalnScopes = ['x-strong/0/H5662', 'x-lemma/0/עֹבַדְיָה', 'x-morph/0/He', 'x-morph/1/Np', 'x-occurrence/0/1', 'x-occurrences/0/1'];
43
- const wScopes = ['x-occurrence/0/1', 'x-occurrences/0/1'];
44
- const query =
45
- '{ documents { mainSequence { id } sequences { id blocks { items { type subType payload } } } } }';
46
-
47
- const checkResult = (t, result) => {
48
- const mainSequenceItems = result.data.documents[0].sequences.filter(s => s.id === result.data.documents[0].mainSequence.id)[0].blocks[0].items;
49
- const content = topNTailItems(mainSequenceItems);
50
- const zalnAtt = suffix => `attribute/milestone/zaln/${suffix}`;
51
- const wAtt = suffix => `attribute/spanWithAtts/w/${suffix}`;
52
- t.equal(mainSequenceItems[0].subType, 'start');
53
- t.equal(mainSequenceItems[0].payload, 'milestone/ts');
54
- t.equal(mainSequenceItems[1].subType, 'end');
55
- t.equal(mainSequenceItems[1].payload, 'milestone/ts');
56
- t.equal(content.length, 23);
57
- t.equal(content[0].subType, 'start');
58
- t.equal(content[0].payload, 'milestone/zaln');
59
-
60
- for (const [n, s] of zalnScopes.entries()) {
61
- t.equal(content[n + 1].subType, 'start');
62
- t.equal(content[n + 1].payload, zalnAtt(s));
63
- }
64
- t.equal(content[8].subType, 'start');
65
- t.equal(content[8].payload, 'spanWithAtts/w');
66
-
67
- for (const [n, s] of wScopes.entries()) {
68
- t.equal(content[n + 9].subType, 'start');
69
- t.equal(content[n + 9].payload, wAtt(s));
70
- }
71
- t.equal(content[11].subType, 'wordLike');
72
- t.equal(content[11].payload, 'Obadiah');
73
-
74
- for (const [n, s] of wScopes.entries()) {
75
- t.equal(content[13 - n].subType, 'end');
76
- t.equal(content[13 - n].payload, wAtt(s));
77
- }
78
- t.equal(content[14].subType, 'end');
79
- t.equal(content[14].payload, 'spanWithAtts/w');
80
- t.equal(content[22].subType, 'end');
81
-
82
- for (const [n, s] of zalnScopes.entries()) {
83
- t.equal(content[21 - n].subType, 'end');
84
- t.equal(content[21 - n].payload, zalnAtt(s));
85
- }
86
- t.equal(content[22].payload, 'milestone/zaln');
87
- };
88
-
89
- test(
90
- `USFM (${testGroup})`,
91
- async function (t) {
92
- try {
93
- t.plan(16 + (4 * zalnScopes.length) + (4 * wScopes.length));
94
- const result = await pk.gqlQuery(query);
95
- t.equal(result.errors, undefined);
96
- checkResult(t, result);
97
- } catch (err) {
98
- console.log(err);
99
- }
100
- },
101
- );
102
-
103
- test(
104
- `USFM with default attribute(${testGroup})`,
105
- async function (t) {
106
- try {
107
- t.plan(2);
108
- const result = await pk3.gqlQuery(query);
109
- t.equal(result.errors, undefined);
110
- t.equal(
111
- result.data.documents[0].sequences
112
- .filter(s => s.id === result.data.documents[0].mainSequence.id)[0]
113
- .blocks[0].items.filter(
114
- i => i.payload === 'attribute/spanWithAtts/w/lemma/0/O-bi-di-ah' && i.subType === 'start',
115
- ).length,
116
- 1);
117
- } catch (err) {
118
- console.log(err);
119
- }
120
- },
121
- );
122
-
123
- test(
124
- `USX (${testGroup})`,
125
- async function (t) {
126
- try {
127
- t.plan(16 + (4 * zalnScopes.length) + (4 * wScopes.length));
128
- const result = await pk2.gqlQuery(query);
129
- t.equal(result.errors, undefined);
130
- checkResult(t, result);
131
- } catch (err) {
132
- console.log(err);
133
- }
134
- },
135
- );
136
-
137
- test(
138
- `Literal slash in attribute value (${testGroup})`,
139
- async function (t) {
140
- try {
141
- t.plan(5);
142
- let pk;
143
-
144
- t.doesNotThrow(() => {
145
- pk = pkWithDoc('../test_data/usfm/slash_in_att.usfm', {
146
- lang: 'fra',
147
- abbr: 'hello',
148
- })[0];
149
- });
150
-
151
- t.equal(pk.nDocuments(), 1);
152
- const query = '{documents { headers { key value } sequences { type text } } }';
153
- const result = await pk.gqlQuery(query);
154
- t.equal(result.errors, undefined);
155
- const firstDoc = result.data.documents[0];
156
- const headerKeys = firstDoc.headers.map(h => h.key);
157
- t.ok(headerKeys.includes('id'));
158
- t.ok(headerKeys.includes('bookCode'));
159
- } catch (err) {
160
- console.log(err);
161
- }
162
- },
163
- );
@@ -1,137 +0,0 @@
1
- const path = require('path');
2
- const fse = require('fs-extra');
3
- const test = require('tape');
4
-
5
- const { pkWithDoc } = require('../../lib/load.js');
6
-
7
- const pk = pkWithDoc('../test_data/usfm/66-JUD-ust.usfm', {
8
- lang: 'eng',
9
- abbr: 'ust',
10
- })[0];
11
-
12
- const tsvToTable = (tsv, hasHeadings) => {
13
- const ret = {
14
- headings: [],
15
- rows: [],
16
- };
17
- let rows = tsv.split(/[\n\r]+/);
18
-
19
- if (hasHeadings) {
20
- ret.headings = rows[0].split('\t');
21
- rows = rows.slice(1);
22
- }
23
-
24
- for (const row of rows) {
25
- ret.rows.push(row.split('\t'));
26
- }
27
- return ret;
28
- };
29
-
30
- const importTSV = (pk, tsvPath, hasHeadings) => {
31
- pk.importDocument({
32
- lang: 'eng',
33
- abbr: 'ust',
34
- }, 'tsv',
35
- JSON.stringify(
36
- tsvToTable(
37
- fse.readFileSync(
38
- path.resolve(__dirname, tsvPath),
39
- )
40
- .toString(),
41
- hasHeadings,
42
- ),
43
- {},
44
- ),
45
- null,
46
- 2,
47
- );
48
- };
49
-
50
- const importNodes = pk => {
51
- pk.importDocument({
52
- lang: 'eng',
53
- abbr: 'ust',
54
- }, 'nodes',
55
- fse.readFileSync(path.resolve(__dirname, '../../test_data/tree/jude.json')),
56
- {},
57
- );
58
- };
59
-
60
- importNodes(pk);
61
- importTSV(pk, '../../test_data/tsv/en_tn_66-JUD.tsv', true);
62
-
63
- const testGroup = 'Mixed Sequence Documents';
64
-
65
- test(
66
- `As vanilla sequences (${testGroup})`,
67
- async function (t) {
68
- try {
69
- t.plan(1);
70
- let query = '{documents { mainSequence { id } sequences { id type tags blocks { bs { payload} bg { payload } is { payload } tokens { type subType payload } } } } }';
71
- let result = await pk.gqlQuery(query);
72
- t.equal(result.errors, undefined);
73
- } catch (err) {
74
- console.log(err);
75
- }
76
- },
77
- );
78
-
79
- test(
80
- `As cast sequences (${testGroup})`,
81
- async function (t) {
82
- try {
83
- t.plan(2);
84
- let query = `{
85
- docSets {
86
- tableDoc: document(bookCode:"T00") { sequences(types:"table") { id } }
87
- treeDoc: document(bookCode:"N00") { sequences(types:"tree") { id } }
88
- }
89
- }`;
90
- let result = await pk.gqlQuery(query);
91
- t.equal(result.errors, undefined);
92
- const tableSequenceId = result.data.docSets[0].tableDoc.sequences[0].id;
93
- const treeSequenceId = result.data.docSets[0].treeDoc.sequences[0].id;
94
- const bookN = 65;
95
- const chapterN = 1;
96
- const verseN = 23;
97
-
98
- const padInt = n => {
99
- const padded = `00${n}`;
100
- return padded.substring(padded.length -3);
101
- };
102
-
103
- query = `{
104
- docSets {
105
- scripture: document(bookCode:"JUD") {
106
- cv (chapter:"${chapterN}" verses:["${verseN}"]) { text(normalizeSpace:true) }
107
- }
108
- table: document(bookCode:"T00") {
109
- tableSequence(id:"${tableSequenceId}") { rows(equals:[{colN:1 values:"${chapterN}"}, {colN:2 values:"${verseN}"}] columns:[3, 4, 5, 6, 7, 8]) { text } }
110
- }
111
- tree: document(bookCode:"N00") {
112
- treeSequence(id:"${treeSequenceId}") {
113
- tribos(
114
- query:"nodes[and(==(content('elementType'), 'Node'), startsWith(content('morphId'), '${bookN}${padInt(chapterN)}${padInt(verseN)}'))]/node{@Cat, @text, @English}") }
115
- }
116
- }}`;
117
- result = await pk.gqlQuery(query);
118
- t.equal(result.errors, undefined);
119
- /*
120
- const docSet = result.data.docSets[0];
121
- const scripture = docSet.scripture.cv[0].text;
122
- const table = docSet.table.tableSequence.rows.map(r => r.map(c => c.text));
123
- const tree = JSON.parse(docSet.tree.treeSequence.tribos).data.map(n => n.content);
124
-
125
- console.log(
126
- JSON.stringify({
127
- scripture,
128
- table,
129
- tree,
130
- },
131
- null,
132
- 2));*/
133
- } catch (err) {
134
- console.log(err);
135
- }
136
- },
137
- );
@@ -1,217 +0,0 @@
1
- const path = require('path');
2
- const fse = require('fs-extra');
3
- const test = require('tape');
4
-
5
- const { pkWithDoc } = require('../../lib/load.js');
6
- const {
7
- blocksSpec2Query,
8
- tsvToInputBlock,
9
- treeToInputBlock,
10
- } = require('../../../src/util/scriptlike/blocksSpec.cjs');
11
-
12
- const [pk, pkDoc] = pkWithDoc('../test_data/usfm/66-JUD-ust.usfm', {
13
- lang: 'eng',
14
- abbr: 'ust',
15
- });
16
-
17
- const testGroup = 'Mixed Sequences';
18
-
19
- test(
20
- `TN Table mutation (${testGroup})`,
21
- async function (t) {
22
- try {
23
- t.plan(2);
24
- const tableQuery = blocksSpec2Query(
25
- tsvToInputBlock(
26
- fse.readFileSync(path.resolve(__dirname, '../../test_data/tsv/en_tn_66-JUD.tsv')).toString(),
27
- ),
28
- );
29
-
30
- let query = `mutation { newSequence(` +
31
- ` documentId: "${pkDoc.id}"` +
32
- ` type: "table"` +
33
- ` blocksSpec: ${tableQuery}` +
34
- ` graftToMain: true) }`;
35
-
36
- let result = await pk.gqlQuery(query);
37
- t.equal(result.errors, undefined);
38
- const newSeqId = result.data.newSequence;
39
- query = `mutation { addSequenceTags(docSetId: "eng_ust", documentId: "${pkDoc.id}", sequenceId: "${newSeqId}", tags: ["tnotes"]) }`;
40
- result = await pk.gqlQuery(query);
41
- t.equal(result.errors, undefined);
42
- } catch (err) {
43
- console.log(err);
44
- }
45
- },
46
- );
47
-
48
- test(
49
- `TWL Table mutation (${testGroup})`,
50
- async function (t) {
51
- try {
52
- t.plan(2);
53
- const tableQuery = blocksSpec2Query(
54
- tsvToInputBlock(
55
- fse.readFileSync(path.resolve(__dirname, '../../test_data/tsv/twl_JUD.tsv')).toString(),
56
- ),
57
- );
58
-
59
- let query = `mutation { newSequence(` +
60
- ` documentId: "${pkDoc.id}"` +
61
- ` type: "table"` +
62
- ` blocksSpec: ${tableQuery}` +
63
- ` graftToMain: true) }`;
64
-
65
- let result = await pk.gqlQuery(query);
66
- t.equal(result.errors, undefined);
67
- const newSeqId = result.data.newSequence;
68
- query = `mutation { addSequenceTags(docSetId: "eng_ust", documentId: "${pkDoc.id}", sequenceId: "${newSeqId}", tags: ["twords"]) }`;
69
- result = await pk.gqlQuery(query);
70
- t.equal(result.errors, undefined);
71
- } catch (err) {
72
- console.log(err);
73
- }
74
- },
75
- );
76
-
77
- test(
78
- `Tree mutation (${testGroup})`,
79
- async function (t) {
80
- try {
81
- t.plan(2);
82
- const treeQuery = blocksSpec2Query(
83
- treeToInputBlock(
84
- fse.readJSONSync(path.resolve(__dirname, '../../test_data/tree/jude.json')),
85
- ),
86
- );
87
-
88
- let query = `mutation { newSequence(` +
89
- ` documentId: "${pkDoc.id}"` +
90
- ` type: "tree"` +
91
- ` blocksSpec: ${treeQuery}` +
92
- ` graftToMain: true) }`;
93
-
94
- let result = await pk.gqlQuery(query);
95
- t.equal(result.errors, undefined);
96
- const newSeqId = result.data.newSequence;
97
- query = `mutation { addSequenceTags(docSetId: "eng_ust", documentId: "${pkDoc.id}", sequenceId: "${newSeqId}", tags: ["stree"]) }`;
98
- result = await pk.gqlQuery(query);
99
- t.equal(result.errors, undefined);
100
- } catch (err) {
101
- console.log(err);
102
- }
103
- },
104
- );
105
-
106
- test(
107
- `kv mutation (${testGroup})`,
108
- async function (t) {
109
- try {
110
- t.plan(2);
111
- const kvQuery = blocksSpec2Query(
112
- fse.readJSONSync(path.resolve(__dirname, '../../test_data/inputBlockSpec/kv.json')),
113
- );
114
-
115
- let query = `mutation { newSequence(` +
116
- ` documentId: "${pkDoc.id}"` +
117
- ` type: "kv"` +
118
- ` blocksSpec: ${kvQuery}` +
119
- ` graftToMain: true) }`;
120
-
121
- let result = await pk.gqlQuery(query);
122
- t.equal(result.errors, undefined);
123
- const newSeqId = result.data.newSequence;
124
- query = `mutation { addSequenceTags(docSetId: "eng_ust", documentId: "${pkDoc.id}", sequenceId: "${newSeqId}", tags: ["kv"]) }`;
125
- result = await pk.gqlQuery(query);
126
- t.equal(result.errors, undefined);
127
- } catch (err) {
128
- console.log(err);
129
- }
130
- },
131
- );
132
-
133
- test(
134
- `As vanilla sequences (${testGroup})`,
135
- async function (t) {
136
- try {
137
- t.plan(6);
138
- let query = '{documents { mainSequence { id } sequences { id type tags blocks { bs { payload} bg { payload } is { payload } tokens { type subType payload } } } } }';
139
- let result = await pk.gqlQuery(query);
140
-
141
- for (const sType of ['main', 'title', 'table', 'tree', 'kv']) {
142
- t.ok(result.data.documents[0].sequences.map(s => s.type).includes(sType));
143
- }
144
- t.equal(result.errors, undefined);
145
- } catch (err) {
146
- console.log(err);
147
- }
148
- },
149
- );
150
-
151
-
152
- test(
153
- `As cast sequences (${testGroup})`,
154
- async function (t) {
155
- try {
156
- t.plan(1);
157
- const bookN = 65;
158
- const chapterN = 1;
159
- const verseN = 23;
160
-
161
- const padInt = n => {
162
- const padded = `00${n}`;
163
- return padded.substring(padded.length -3);
164
- };
165
-
166
- const query = `{
167
- docSets {
168
- document(bookCode:"JUD") {
169
- cv (chapter:"${chapterN}" verses:["${verseN}"]) { tokens {subType payload scopes} }
170
- tnTable: tableSequences(withTags:"tnotes") { tags rows(equals:[{colN:1 values:"${chapterN}"}, {colN:2 values:"${verseN}"}] columns:[3, 4, 5, 6, 7, 8]) { text } }
171
- twlTable: tableSequences(withTags:"twords") { tags rows(equals:[{colN:0 values:"${chapterN}:${verseN}"}] columns:[1, 2, 3, 4, 5]) { text } }
172
- kv: kvSequences(withTags:"kv") { nEntries, entries(secondaryEquals:[{key:"service", values:"dessert"}, {key:"color", values:"green"}]) { key secondaryKeys { key value } itemGroups { scopeLabels(startsWith:"kvField") text } } }
173
- sTree: treeSequences(withTags:"stree") {
174
- tribos(
175
- query:"nodes[and(==(content('elementType'), 'Node'), startsWith(content('morphId'), '${bookN}${padInt(chapterN)}${padInt(verseN)}'))]/node{@Cat, @text, @English}"
176
- )
177
- }
178
- }
179
- }}`;
180
- const result = await pk.gqlQuery(query);
181
- t.equal(result.errors, undefined);
182
-
183
- // const document = result.data.docSets[0].document;
184
- // const scripture = document.cv[0].tokens;
185
- // const tNotes = document.tnTable[0].rows.map(r => r.map(c => c.text));
186
- // const tWords = document.twlTable[0].rows.map(r => r.map(c => c.text));
187
- // const sTree = JSON.parse(document.sTree[0].tribos).data.map(n => n.content);
188
- /*
189
- const cleanKV = entry => {
190
- const fields = {};
191
- entry.itemGroups.forEach(ig => fields[ig.scopeLabels[0].split('/')[1]] = ig.text);
192
- const secondaryKeys = {};
193
- entry.secondaryKeys.forEach(k => secondaryKeys[k.key] = k.value);
194
- return {
195
- key: entry.key,
196
- secondaryKeys,
197
- fields,
198
- };
199
- };
200
- const kv = document.kv[0].entries.map(kv => cleanKV(kv));
201
-
202
- console.log(
203
- JSON.stringify({
204
- scripture,
205
- sTree,
206
- tNotes,
207
- tWords,
208
- kv,
209
- },
210
- null,
211
- 2));
212
- */
213
- } catch (err) {
214
- console.log(err);
215
- }
216
- },
217
- );
@@ -1,29 +0,0 @@
1
- const test = require('tape');
2
- const deepCopy = require('deep-copy-all');
3
- const deepEqual = require('deep-equal');
4
-
5
- const { pkWithDoc } = require('../../lib/load.js');
6
-
7
- const testGroup = 'Modify Sequence Method';
8
-
9
- const pk = pkWithDoc('../test_data/usfm/hello.usfm', {
10
- lang: 'eng',
11
- abbr: 'web',
12
- })[0];
13
-
14
- test(
15
- `Identity Transform (${testGroup})`,
16
- function (t) {
17
- try {
18
- t.plan(1);
19
- const myPk = deepCopy(pk);
20
- const document = Object.values(myPk.documents)[0];
21
- const oldSequence = deepCopy(document.sequences[document.mainId]);
22
- document.modifySequence(oldSequence.id);
23
- const newSequence = document.sequences[document.mainId];
24
- t.ok(deepEqual(oldSequence, newSequence));
25
- } catch (err) {
26
- console.log(err);
27
- }
28
- },
29
- );
@@ -1,58 +0,0 @@
1
- const test = require('tape');
2
-
3
- const { pkWithDoc } = require('../../lib/load.js');
4
-
5
- const testGroup = 'Multiple Chapters';
6
-
7
- const pk = pkWithDoc(
8
- '../test_data/usfm/1pe_webbe.usfm',
9
- {
10
- lang: 'fra',
11
- abbr: 'hello',
12
- },
13
- {
14
- includeScopes: ['chapter', 'verse/'],
15
- includeGrafts: [],
16
- })[0];
17
-
18
- test(
19
- `Chapter Closing (${testGroup})`,
20
- async function (t) {
21
- try {
22
- const scopeRecords = [
23
- {
24
- os: [],
25
- is: ['chapter/1', 'verse/1'],
26
- },
27
- {
28
- os: [],
29
- is: ['chapter/2', 'verse/1', 'verse/2'],
30
- },
31
- {
32
- os: ['chapter/2', 'verse/2'],
33
- is: ['verse/3'],
34
- },
35
- ];
36
- t.plan(2 + (2 * scopeRecords.length) + 8);
37
- const query =
38
- '{ documents { mainSequence { blocks { os { payload } is { payload } } } } }';
39
- const result = await pk.gqlQuery(query);
40
- t.equal(result.errors, undefined);
41
- const blocks = result.data.documents[0].mainSequence.blocks;
42
- t.equal(scopeRecords.length, blocks.length);
43
-
44
- for (const [n, scopeRecord] of scopeRecords.entries()) {
45
- for (const blockField of ['os', 'is']) {
46
- t.equal(blocks[n][blockField].length, scopeRecord[blockField].length);
47
- const blockScopes = blocks[n][blockField].map(f => f.payload);
48
-
49
- for (const scopeField of scopeRecord[blockField]) {
50
- t.ok(blockScopes.includes(scopeField));
51
- }
52
- }
53
- }
54
- } catch (err) {
55
- console.log(err);
56
- }
57
- },
58
- );
@@ -1,105 +0,0 @@
1
- const test = require('tape');
2
-
3
- const {
4
- pkWithDocs,
5
- pkWithDocSetDocs,
6
- } = require('../../lib/load.js');
7
-
8
- const testGroup = 'Multiple Content';
9
-
10
- test(
11
- `DocSets (${testGroup})`,
12
- async function (t) {
13
- try {
14
- const expected = [
15
- {
16
- 'lang': 'fra',
17
- 'abbr': 'hello',
18
- 'nDocs': 1,
19
- },
20
- {
21
- 'lang': 'fra',
22
- 'abbr': 'cp_vp',
23
- 'nDocs': 1,
24
- },
25
- ];
26
- t.plan(2 + (3 * expected.length));
27
- const pk = pkWithDocs([
28
- ['../test_data/usfm/hello.usfm', {
29
- lang: 'fra',
30
- abbr: 'hello',
31
- }],
32
- ['../test_data/usfm/cp_vp.usfm', {
33
- lang: 'fra',
34
- abbr: 'cp_vp',
35
- }],
36
- ]);
37
- const query = '{ docSets { lang: selector(id:"lang") abbr: selector(id:"abbr") documents { id } } }';
38
- const result = await pk.gqlQuery(query);
39
- t.equal(result.errors, undefined);
40
- t.equal(result.data.docSets.length, 2);
41
-
42
- for (const [n, docSet] of result.data.docSets.entries()) {
43
- t.equal(docSet.lang, expected[n].lang);
44
- t.equal(docSet.abbr, expected[n].abbr);
45
- t.equal(docSet.documents.length, expected[n].nDocs);
46
- }
47
- } catch (err) {
48
- console.log(err);
49
- }
50
- },
51
- );
52
-
53
- test(
54
- `Documents (${testGroup})`,
55
- async function (t) {
56
- try {
57
- t.plan(5);
58
- const pk = pkWithDocSetDocs(
59
- [
60
- '../test_data/usfm/hello.usfm',
61
- '../test_data/usfm/cp_vp.usfm',
62
- ],
63
- {
64
- lang: 'eng',
65
- abbr: 'ust',
66
- },
67
- {},
68
- )[0];
69
- const query = '{ docSets { lang: selector(id:"lang") abbr: selector(id:"abbr") documents { header(id:"id") mainSequence { blocks { text } } } } }';
70
- const result = await pk.gqlQuery(query);
71
- t.equal(result.errors, undefined);
72
- const documents = result.data.docSets[0].documents;
73
- t.ok(documents[0].header.startsWith('MRK'));
74
- t.ok(documents[0].mainSequence.blocks[0].text.startsWith('This is how'));
75
- t.ok(documents[1].header.startsWith('ESG'));
76
- t.ok(documents[1].mainSequence.blocks[0].text.startsWith('Here is the text'));
77
- } catch (err) {
78
- console.log(err);
79
- }
80
- },
81
- );
82
-
83
- test(
84
- `Duplicate Documents (${testGroup})`,
85
- function (t) {
86
- try {
87
- t.plan(1);
88
- t.throws(() => pkWithDocSetDocs(
89
- [
90
- '../test_data/usfm/hello.usfm',
91
- '../test_data/usfm/hello.usfm',
92
- ],
93
- {
94
- lang: 'eng',
95
- abbr: 'ust',
96
- },
97
- {},
98
- ),
99
- /MRK.+already exists/,
100
- );
101
- } catch (err) {
102
- console.log(err);
103
- }
104
- },
105
- );