proskomma-core 0.9.7 → 0.9.12

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 (300) hide show
  1. package/.eslintrc.json +79 -0
  2. package/.gitattributes +2 -0
  3. package/babel.config.js +18 -0
  4. package/docs/_config.yml +1 -0
  5. package/docs/index.md +3 -0
  6. package/docs/pk_edit_0_9.odt +0 -0
  7. package/docs/pk_edit_0_9.pdf +0 -0
  8. package/docs/proskomma_101_slideshow.odp +0 -0
  9. package/docs/proskomma_101_slideshow.pdf +0 -0
  10. package/docs/proskomma_edit_html.png +0 -0
  11. package/docs/proskomma_edit_html.svg +451 -0
  12. package/docs/proskomma_edit_reference.png +0 -0
  13. package/docs/proskomma_edit_reference.svg +349 -0
  14. package/docs/repo_logo.png +0 -0
  15. package/esm/package.json +3 -0
  16. package/esm/wrapper.mjs +5 -0
  17. package/index.js +6 -0
  18. package/package.json +19 -17
  19. package/src/graph/index.cjs +201 -0
  20. package/src/graph/lib/do_cv.cjs +249 -0
  21. package/src/graph/lib/dump.cjs +40 -0
  22. package/src/graph/lib/remake_blocks.cjs +57 -0
  23. package/src/graph/lib/sequence_chars.cjs +84 -0
  24. package/src/graph/lib/sort.cjs +39 -0
  25. package/src/graph/lib/tribos.cjs +97 -0
  26. package/src/graph/lib/tribos_expression.cjs +556 -0
  27. package/src/graph/lib/tribos_ohm_UNUSED.cjs +37 -0
  28. package/src/graph/lib/tribos_step.cjs +434 -0
  29. package/src/graph/mutations/add.cjs +91 -0
  30. package/src/graph/mutations/delete.cjs +61 -0
  31. package/src/graph/mutations/index.cjs +54 -0
  32. package/src/graph/mutations/rehash.cjs +17 -0
  33. package/src/graph/mutations/tags.cjs +120 -0
  34. package/src/graph/mutations/update.cjs +210 -0
  35. package/src/graph/mutations/versification.cjs +96 -0
  36. package/src/graph/queries/block.cjs +228 -0
  37. package/src/graph/queries/cIndex.cjs +87 -0
  38. package/src/graph/queries/cell.cjs +42 -0
  39. package/src/graph/queries/cv.cjs +19 -0
  40. package/src/graph/queries/cvBook.cjs +16 -0
  41. package/src/graph/queries/cvChapter.cjs +16 -0
  42. package/src/graph/queries/cvIndex.cjs +47 -0
  43. package/src/graph/queries/cvNavigation.cjs +116 -0
  44. package/src/graph/queries/cvVerseElement.cjs +84 -0
  45. package/src/graph/queries/cvVerses.cjs +14 -0
  46. package/src/graph/queries/doc_set.cjs +220 -0
  47. package/src/graph/queries/document.cjs +555 -0
  48. package/src/graph/queries/idParts.cjs +30 -0
  49. package/src/graph/queries/index.cjs +151 -0
  50. package/src/graph/queries/inputBlockSpec.cjs +17 -0
  51. package/src/graph/queries/inputItemObject.cjs +12 -0
  52. package/src/graph/queries/input_att_spec.cjs +14 -0
  53. package/src/graph/queries/input_key_matches.cjs +11 -0
  54. package/src/graph/queries/input_key_value.cjs +11 -0
  55. package/src/graph/queries/input_key_values.cjs +11 -0
  56. package/src/graph/queries/input_selector_spec.cjs +19 -0
  57. package/src/graph/queries/item.cjs +71 -0
  58. package/src/graph/queries/itemGroup.cjs +75 -0
  59. package/src/graph/queries/key_value.cjs +18 -0
  60. package/src/graph/queries/kv_entry.cjs +21 -0
  61. package/src/graph/queries/kv_sequence.cjs +151 -0
  62. package/src/graph/queries/node.cjs +44 -0
  63. package/src/graph/queries/orig.cjs +11 -0
  64. package/src/graph/queries/regex_index.cjs +18 -0
  65. package/src/graph/queries/row_equals_spec.cjs +11 -0
  66. package/src/graph/queries/row_match_spec.cjs +11 -0
  67. package/src/graph/queries/selector_spec.cjs +29 -0
  68. package/src/graph/queries/sequence.cjs +314 -0
  69. package/src/graph/queries/table_sequence.cjs +192 -0
  70. package/src/graph/queries/tree_sequence.cjs +58 -0
  71. package/src/graph/queries/verseNumber.cjs +44 -0
  72. package/src/graph/queries/verseRange.cjs +11 -0
  73. package/src/graph/queries/versification.cjs +25 -0
  74. package/src/index.cjs +583 -0
  75. package/src/model/doc_set.cjs +389 -0
  76. package/src/model/doc_set_helpers/block.cjs +232 -0
  77. package/src/model/doc_set_helpers/enum.cjs +87 -0
  78. package/src/model/doc_set_helpers/item.cjs +198 -0
  79. package/src/model/doc_set_helpers/rehash.cjs +53 -0
  80. package/src/model/doc_set_helpers/selectors.cjs +58 -0
  81. package/src/model/doc_set_helpers/serialize.cjs +22 -0
  82. package/src/model/doc_set_helpers/unsuccinctify.cjs +288 -0
  83. package/src/model/doc_set_helpers/update.cjs +290 -0
  84. package/src/model/document.cjs +369 -0
  85. package/src/model/document_helpers/blocks.cjs +135 -0
  86. package/src/model/document_helpers/chapter_verse.cjs +291 -0
  87. package/src/model/document_helpers/pre_enums.cjs +67 -0
  88. package/src/model/document_helpers/sequences.cjs +205 -0
  89. package/src/model/document_helpers/serialize_succinct.cjs +55 -0
  90. package/src/model/document_helpers/succinct_filter.cjs +102 -0
  91. package/src/model/versifications/eng_vrs.cjs +455 -0
  92. package/src/model/versifications/index.cjs +38 -0
  93. package/src/model/versifications/lxx_vrs.cjs +950 -0
  94. package/src/model/versifications/org_vrs.cjs +155 -0
  95. package/src/model/versifications/rsc_vrs.cjs +342 -0
  96. package/src/model/versifications/rso_vrs.cjs +541 -0
  97. package/src/model/versifications/vul_vrs.cjs +835 -0
  98. package/src/parser/index.cjs +506 -0
  99. package/src/parser/lexers/index.cjs +11 -0
  100. package/src/parser/lexers/lexingRegexes.cjs +45 -0
  101. package/src/parser/lexers/nodes.cjs +123 -0
  102. package/src/parser/lexers/object_for_fragment.cjs +123 -0
  103. package/src/parser/lexers/tsv.cjs +45 -0
  104. package/src/parser/lexers/usfm.cjs +17 -0
  105. package/src/parser/lexers/usx/index.cjs +7 -0
  106. package/src/parser/lexers/usx/usx_lexer.cjs +321 -0
  107. package/src/parser/lib/tokenize.cjs +37 -0
  108. package/src/parser/model/index.cjs +637 -0
  109. package/src/parser/parser_specs.cjs +781 -0
  110. package/src/pipelines/perf2x/index.cjs +7 -0
  111. package/src/pipelines/perf2x/perf2PkJsonPipeline.json +41 -0
  112. package/src/pipelines/perf2x/perf2usfmPipeline.json +65 -0
  113. package/src/transforms/calculateUsfmChapterPositions.cjs +106 -0
  114. package/src/transforms/index.cjs +9 -0
  115. package/src/transforms/perf2PkJson.cjs +534 -0
  116. package/src/transforms/perf2usfm.cjs +294 -0
  117. package/src/util/byteArray.cjs +251 -0
  118. package/src/util/canons.cjs +117 -0
  119. package/src/util/enums.cjs +41 -0
  120. package/src/util/generateId.cjs +6 -0
  121. package/src/util/graftDefs.cjs +15 -0
  122. package/src/util/index.cjs +29 -0
  123. package/src/util/inspectSuccinct.cjs +59 -0
  124. package/src/util/itemDefs.cjs +33 -0
  125. package/src/util/parserConstantDefs.cjs +30 -0
  126. package/src/util/scopeDefs.cjs +173 -0
  127. package/src/util/scriptlike/blocksSpec.cjs +192 -0
  128. package/src/util/scriptlike/dodson_lexicon.xsl +19 -0
  129. package/src/util/scriptlike/dodson_lexicon_to_entries.cjs +85 -0
  130. package/src/util/scriptlike/open_scriptures_hebrew_lexicon.xsl +28 -0
  131. package/src/util/scriptlike/open_scriptures_hebrew_lexicon_to_entries.cjs +85 -0
  132. package/src/util/succinct.cjs +159 -0
  133. package/src/util/tags.cjs +28 -0
  134. package/src/util/tokenDefs.cjs +27 -0
  135. package/src/util/versification.cjs +364 -0
  136. package/test/code/main/bad.cjs +79 -0
  137. package/test/code/main/basics.cjs +534 -0
  138. package/test/code/main/block.cjs +586 -0
  139. package/test/code/main/block_scope_numbers.cjs +31 -0
  140. package/test/code/main/blocks_with_atts.cjs +150 -0
  141. package/test/code/main/blocks_with_cv.cjs +250 -0
  142. package/test/code/main/break.cjs +73 -0
  143. package/test/code/main/checksum.cjs +36 -0
  144. package/test/code/main/cl_global.cjs +35 -0
  145. package/test/code/main/class_for_fragment.cjs +18 -0
  146. package/test/code/main/clean_usfm.cjs +46 -0
  147. package/test/code/main/cp_vp.cjs +158 -0
  148. package/test/code/main/custom.cjs +124 -0
  149. package/test/code/main/cv.cjs +249 -0
  150. package/test/code/main/cvMatching.cjs +155 -0
  151. package/test/code/main/cv_indexes.cjs +189 -0
  152. package/test/code/main/cv_navigation.cjs +124 -0
  153. package/test/code/main/document.cjs +382 -0
  154. package/test/code/main/empty_blocks.cjs +71 -0
  155. package/test/code/main/entries.cjs +402 -0
  156. package/test/code/main/export_lexing_regexes.cjs +19 -0
  157. package/test/code/main/fig.cjs +67 -0
  158. package/test/code/main/filter.cjs +222 -0
  159. package/test/code/main/glossary.cjs +36 -0
  160. package/test/code/main/graft_headings.cjs +36 -0
  161. package/test/code/main/graft_introduction.cjs +96 -0
  162. package/test/code/main/graft_note.cjs +104 -0
  163. package/test/code/main/graft_rems.cjs +34 -0
  164. package/test/code/main/graft_sidebars.cjs +62 -0
  165. package/test/code/main/graft_title.cjs +36 -0
  166. package/test/code/main/hello.cjs +105 -0
  167. package/test/code/main/import_document.cjs +22 -0
  168. package/test/code/main/import_usfm_int.cjs +48 -0
  169. package/test/code/main/item_groups.cjs +133 -0
  170. package/test/code/main/items_with_cv.cjs +311 -0
  171. package/test/code/main/milestone_attributes.cjs +163 -0
  172. package/test/code/main/mixed_sequence_documents.cjs +137 -0
  173. package/test/code/main/mixed_sequences.cjs +217 -0
  174. package/test/code/main/modify_sequence.cjs +29 -0
  175. package/test/code/main/multiple_chapters.cjs +58 -0
  176. package/test/code/main/multiple_content.cjs +105 -0
  177. package/test/code/main/mutate_add.cjs +180 -0
  178. package/test/code/main/mutate_delete.cjs +236 -0
  179. package/test/code/main/mutate_rehash.cjs +68 -0
  180. package/test/code/main/mutate_tags.cjs +90 -0
  181. package/test/code/main/mutate_update.cjs +538 -0
  182. package/test/code/main/selectors.cjs +289 -0
  183. package/test/code/main/sequence.cjs +361 -0
  184. package/test/code/main/serialize.cjs +104 -0
  185. package/test/code/main/spans.cjs +51 -0
  186. package/test/code/main/split_long_tokens.cjs +30 -0
  187. package/test/code/main/standard_vrs.cjs +76 -0
  188. package/test/code/main/subclass.cjs +25 -0
  189. package/test/code/main/table.cjs +119 -0
  190. package/test/code/main/tags.cjs +248 -0
  191. package/test/code/main/token_alignment.cjs +84 -0
  192. package/test/code/main/trees.cjs +211 -0
  193. package/test/code/main/tribos.cjs +865 -0
  194. package/test/code/main/tsv.cjs +385 -0
  195. package/test/code/main/usx_ref.cjs +65 -0
  196. package/test/code/main/verse_mapping.cjs +252 -0
  197. package/test/code/main/verse_range.cjs +31 -0
  198. package/test/code/main/word_likes.cjs +41 -0
  199. package/test/code/utils/byte_array.cjs +271 -0
  200. package/test/code/utils/canons.cjs +20 -0
  201. package/test/code/utils/generate_id.cjs +17 -0
  202. package/test/code/utils/graft_defs.cjs +16 -0
  203. package/test/code/utils/inspect.cjs +130 -0
  204. package/test/code/utils/items.cjs +56 -0
  205. package/test/code/utils/push_succinct.cjs +69 -0
  206. package/test/code/utils/scope_defs.cjs +79 -0
  207. package/test/code/utils/serialize.cjs +28 -0
  208. package/test/code/utils/splice.cjs +67 -0
  209. package/test/code/utils/tags.cjs +69 -0
  210. package/test/code/utils/versification.cjs +249 -0
  211. package/test/lib/load.js +110 -0
  212. package/test/skipped_code/diff.js +53 -0
  213. package/test/test_data/inputBlockSpec/dodson.json +1654 -0
  214. package/test/test_data/inputBlockSpec/kv.json +326 -0
  215. package/test/test_data/inputBlockSpec/mk1.json +1019 -0
  216. package/test/test_data/inputBlockSpec/table.json +170 -0
  217. package/test/test_data/tree/genealogy.json +55 -0
  218. package/test/test_data/tree/jude.json +15965 -0
  219. package/test/test_data/tsv/en_tn_66-JUD.tsv +75 -0
  220. package/test/test_data/tsv/twl_JUD.tsv +144 -0
  221. package/test/test_data/usfm/1pe_webbe.usfm +13 -0
  222. package/test/test_data/usfm/66-JUD-ust.usfm +1089 -0
  223. package/test/test_data/usfm/78-GALspavbl.usfm +10 -0
  224. package/test/test_data/usfm/add_test.usfm +15 -0
  225. package/test/test_data/usfm/backslash.usfm +4 -0
  226. package/test/test_data/usfm/cl.usfm +14 -0
  227. package/test/test_data/usfm/cp_vp.usfm +8 -0
  228. package/test/test_data/usfm/custom.usfm +13 -0
  229. package/test/test_data/usfm/en_ust_oba.usfm +875 -0
  230. package/test/test_data/usfm/en_ust_psa_1.usfm +20 -0
  231. package/test/test_data/usfm/fig.usfm +3 -0
  232. package/test/test_data/usfm/filter.usfm +7 -0
  233. package/test/test_data/usfm/footnote.usfm +11 -0
  234. package/test/test_data/usfm/frt.usfm +4 -0
  235. package/test/test_data/usfm/headings.usfm +7 -0
  236. package/test/test_data/usfm/hello.usfm +8 -0
  237. package/test/test_data/usfm/int.usfm +7 -0
  238. package/test/test_data/usfm/milestone_attributes.usfm +7 -0
  239. package/test/test_data/usfm/milestone_attributes_default.usfm +7 -0
  240. package/test/test_data/usfm/no_break_space.usfm +4 -0
  241. package/test/test_data/usfm/no_mt.usfm +6 -0
  242. package/test/test_data/usfm/rems.usfm +6 -0
  243. package/test/test_data/usfm/section_intros.usfm +26 -0
  244. package/test/test_data/usfm/sidebars.usfm +25 -0
  245. package/test/test_data/usfm/slash_in_att.usfm +6 -0
  246. package/test/test_data/usfm/soft_line_break.usfm +4 -0
  247. package/test/test_data/usfm/spans.usfm +5 -0
  248. package/test/test_data/usfm/split_long_tokens.usfm +6 -0
  249. package/test/test_data/usfm/table.usfm +18 -0
  250. package/test/test_data/usfm/table_at_end.usfm +11 -0
  251. package/test/test_data/usfm/table_in_intro.usfm +22 -0
  252. package/test/test_data/usfm/table_no_end_cells.usfm +18 -0
  253. package/test/test_data/usfm/tit_kitchen_sink.usfm +73 -0
  254. package/test/test_data/usfm/titus_template.usfm +58 -0
  255. package/test/test_data/usfm/ugnt_3jn.usfm +265 -0
  256. package/test/test_data/usfm/ult_3jn.usfm +335 -0
  257. package/test/test_data/usfm/unknown.usfm +5 -0
  258. package/test/test_data/usfm/ust_psa.usfm +29 -0
  259. package/test/test_data/usfm/ust_psa_verse_ranges.usfm +24 -0
  260. package/test/test_data/usfm/ust_psa_with_ts.usfm +29 -0
  261. package/test/test_data/usfm/verse_breaks_in_blocks.usfm +20 -0
  262. package/test/test_data/usfm/verse_range.usfm +7 -0
  263. package/test/test_data/usfm/web_ecc.usfm +391 -0
  264. package/test/test_data/usfm/web_psa51.usfm +71 -0
  265. package/test/test_data/usfm/whitespace.usfm +12 -0
  266. package/test/test_data/usfm/xref.usfm +11 -0
  267. package/test/test_data/usx/bad_element.usx +2 -0
  268. package/test/test_data/usx/cp_vp.usx +12 -0
  269. package/test/test_data/usx/diff1.usx +59 -0
  270. package/test/test_data/usx/diff2.usx +74 -0
  271. package/test/test_data/usx/douay_rheims_ecc.usx +58 -0
  272. package/test/test_data/usx/douay_rheims_psa.usx +5366 -0
  273. package/test/test_data/usx/douay_rheims_psa_40_60.usx +666 -0
  274. package/test/test_data/usx/douay_rheims_rut.usx +26 -0
  275. package/test/test_data/usx/esg3.usx +47 -0
  276. package/test/test_data/usx/fig.usx +6 -0
  277. package/test/test_data/usx/milestone_attributes.usx +11 -0
  278. package/test/test_data/usx/not_nfc18_glo.usx +9 -0
  279. package/test/test_data/usx/not_nfc18_phm.usx +24 -0
  280. package/test/test_data/usx/opt_break.usx +10 -0
  281. package/test/test_data/usx/sidebars.usx +29 -0
  282. package/test/test_data/usx/table.usx +23 -0
  283. package/test/test_data/usx/web_psa.usx +8489 -0
  284. package/test/test_data/usx/web_psa150.usx +33 -0
  285. package/test/test_data/usx/web_psa_40_60.usx +1079 -0
  286. package/test/test_data/usx/web_rut.usx +95 -0
  287. package/test/test_data/usx/web_rut_1.usx +17 -0
  288. package/test/test_data/utils/douay_rheims.vrs +520 -0
  289. package/test/test_data/utils/douay_rheims_PSA.usx +5366 -0
  290. package/test/test_data/utils/serialize_example.json +91 -0
  291. package/test/test_data/utils/truncated_versification.vrs +29 -0
  292. package/test/test_data/utils/web_rut_items.json +2977 -0
  293. package/test/test_data/utils/webbe.vrs +395 -0
  294. package/test/test_data/utils/webbe_PSA.usx +8489 -0
  295. package/test/test_data/vrs/douay_rheims.vrs +520 -0
  296. package/test/test_data/vrs/truncated_versification.vrs +27 -0
  297. package/test/test_data/vrs/webbe.vrs +397 -0
  298. package/webpack.prod.js +50 -0
  299. package/dist/index.js +0 -8
  300. package/dist/index.js.LICENSE.txt +0 -23
@@ -0,0 +1,79 @@
1
+ /* eslint-disable require-await */
2
+ const test = require('tape');
3
+
4
+ const { pkWithDoc } = require('../../lib/load.js');
5
+
6
+ const testGroup = 'Lexing Badness';
7
+
8
+ const pk = pkWithDoc('../test_data/usfm/backslash.usfm', {
9
+ lang: 'fra',
10
+ abbr: 'hello',
11
+ })[0];
12
+ const pk2 = pkWithDoc('../test_data/usfm/unknown.usfm', {
13
+ lang: 'fra',
14
+ abbr: 'hello',
15
+ })[0];
16
+
17
+ test(
18
+ `Bare Backslash (${testGroup})`,
19
+ async function (t) {
20
+ try {
21
+ t.plan(2);
22
+ const query = `{ documents { mainSequence { blocks { items { type subType payload } } } } }`;
23
+ const result = await pk.gqlQuery(query);
24
+ t.equal(result.errors, undefined);
25
+ const firstItem = result.data.documents[0].mainSequence.blocks[0].items[0];
26
+ t.equal(firstItem.subType, 'bareSlash');
27
+ } catch (err) {
28
+ console.log(err);
29
+ }
30
+ },
31
+ );
32
+
33
+ test(
34
+ `Handle exotic symbols (not really ${testGroup})`,
35
+ async function (t) {
36
+ try {
37
+ t.plan(3);
38
+ const query = `{ documents { mainSequence { blocks { items { type subType payload } } } } }`;
39
+ const result = await pk2.gqlQuery(query);
40
+ t.equal(result.errors, undefined);
41
+ const firstItem = result.data.documents[0].mainSequence.blocks[0].items[0];
42
+ t.equal(firstItem.subType, 'punctuation');
43
+ const secondItem = result.data.documents[0].mainSequence.blocks[0].items[1];
44
+ t.equal(secondItem.subType, 'punctuation');
45
+ } catch (err) {
46
+ console.log(err);
47
+ }
48
+ },
49
+ );
50
+
51
+ test(
52
+ `Bad Element in USX (${testGroup})`,
53
+ async function (t) {
54
+ try {
55
+ t.plan(1);
56
+ t.throws(() => pkWithDoc('../test_data/usx/bad_element.usx', {
57
+ lang: 'fra',
58
+ abbr: 'hello',
59
+ }), /Unexpected .+bananas/);
60
+ } catch (err) {
61
+ console.log(err);
62
+ }
63
+ },
64
+ );
65
+
66
+ test(
67
+ `No mt (${testGroup})`,
68
+ async function (t) {
69
+ try {
70
+ t.plan(1);
71
+ t.throws(() => pkWithDoc('../test_data/usfm/no_mt.usfm', {
72
+ lang: 'fra',
73
+ abbr: 'hello',
74
+ }), /wordLike content/);
75
+ } catch (err) {
76
+ console.log(err);
77
+ }
78
+ },
79
+ );
@@ -0,0 +1,534 @@
1
+ const test = require('tape');
2
+
3
+ const { Proskomma } = require('../../../src/index.cjs');
4
+ const {
5
+ pkWithDoc,
6
+ pkWithDocs,
7
+ } = require('../../lib/load.js');
8
+
9
+ const testGroup = 'Graph Basics';
10
+
11
+ const [pk, pkDoc] = pkWithDoc('../test_data/usx/web_rut.usx', {
12
+ lang: 'eng',
13
+ abbr: 'web',
14
+ });
15
+ const pk2 = pkWithDocs([
16
+ ['../test_data/usx/web_psa150.usx', {
17
+ lang: 'eng',
18
+ abbr: 'webbe',
19
+ }],
20
+ ['../test_data/usx/web_rut.usx', {
21
+ lang: 'eng',
22
+ abbr: 'webbe',
23
+ }],
24
+ ['../test_data/usfm/ust_psa.usfm', {
25
+ lang: 'eng',
26
+ abbr: 'ust',
27
+ }],
28
+ ['../test_data/usx/not_nfc18_phm.usx', {
29
+ lang: 'eng',
30
+ abbr: 'nnfc18',
31
+ }],
32
+ ]);
33
+
34
+ const pk3 = pkWithDocs([
35
+ ['../test_data/usx/web_rut.usx', {
36
+ lang: 'eng',
37
+ abbr: 'webbe',
38
+ }],
39
+ ['../test_data/usfm/web_ecc.usfm', {
40
+ lang: 'eng',
41
+ abbr: 'webbe',
42
+ }],
43
+ ['../test_data/usx/web_psa150.usx', {
44
+ lang: 'eng',
45
+ abbr: 'webbe',
46
+ }],
47
+ ]);
48
+
49
+ test(
50
+ `Scalar Root Fields (${testGroup})`,
51
+ async function (t) {
52
+ try {
53
+ t.plan(9);
54
+ const query = '{ id processor packageVersion nDocSets nDocuments }';
55
+ const pk = new Proskomma();
56
+ const result = await pk.gqlQuery(query);
57
+ t.equal(result.errors, undefined);
58
+ t.ok('id' in result.data);
59
+ t.ok('processor' in result.data);
60
+ t.ok('packageVersion' in result.data);
61
+ t.equal(result.data.packageVersion, pk.packageVersion());
62
+ t.ok('nDocSets' in result.data);
63
+ t.equal(result.data.nDocSets, 0);
64
+ t.ok('nDocuments' in result.data);
65
+ t.equal(result.data.nDocuments, 0);
66
+ } catch (err) {
67
+ console.log(err);
68
+ }
69
+ },
70
+ );
71
+
72
+ test(
73
+ `Sync query (${testGroup})`,
74
+ function (t) {
75
+ try {
76
+ t.plan(2);
77
+ const query = '{ id }';
78
+ const pk = new Proskomma();
79
+ const result = pk.gqlQuerySync(query);
80
+ t.equal(result.errors, undefined);
81
+ t.ok('id' in result.data);
82
+ } catch (err) {
83
+ console.log(err);
84
+ }
85
+ },
86
+ );
87
+
88
+ test(
89
+ `DocSets (${testGroup})`,
90
+ async function (t) {
91
+ try {
92
+ t.plan(4);
93
+ const query = '{ docSets { id lang: selector(id:"lang") abbr: selector(id:"abbr") } }';
94
+ const result = await pk.gqlQuery(query);
95
+ t.equal(result.errors, undefined);
96
+ t.ok('id' in result.data.docSets[0]);
97
+ t.equal(result.data.docSets[0].lang, 'eng');
98
+ t.equal(result.data.docSets[0].abbr, 'web');
99
+ } catch (err) {
100
+ console.log(err);
101
+ }
102
+ },
103
+ );
104
+
105
+ test(
106
+ `Sort DocSet Documents (${testGroup})`,
107
+ async function (t) {
108
+ try {
109
+ t.plan(8);
110
+ let query = '{ docSets { documents(sortedBy:"paratext") { bookCode: header(id:"bookCode") } } }';
111
+ let result = await pk3.gqlQuery(query);
112
+ t.equal(result.errors, undefined);
113
+ t.equal(result.data.docSets[0].documents[0].bookCode, 'RUT');
114
+ t.equal(result.data.docSets[0].documents[2].bookCode, 'ECC');
115
+ query = '{ docSets { documents(sortedBy:"alpha") { bookCode: header(id:"bookCode") } } }';
116
+ result = await pk3.gqlQuery(query);
117
+ t.equal(result.errors, undefined);
118
+ t.equal(result.data.docSets[0].documents[0].bookCode, 'ECC');
119
+ t.equal(result.data.docSets[0].documents[2].bookCode, 'RUT');
120
+ query = '{ docSets { documents(sortedBy:"banana") { bookCode: header(id:"bookCode") } } }';
121
+ result = await pk3.gqlQuery(query);
122
+ t.equal(result.errors.length, 1);
123
+ t.ok(result.errors[0].message.includes('banana'));
124
+ } catch (err) {
125
+ console.log(err);
126
+ }
127
+ },
128
+ );
129
+
130
+ test(
131
+ `nDocuments in docSet (${testGroup})`,
132
+ async function (t) {
133
+ try {
134
+ t.plan(3);
135
+ const query = '{ docSets { nDocuments } }';
136
+ const result = await pk.gqlQuery(query);
137
+ t.equal(result.errors, undefined);
138
+ t.ok('nDocuments' in result.data.docSets[0]);
139
+ t.equal(result.data.docSets[0].nDocuments, 1);
140
+ } catch (err) {
141
+ console.log(err);
142
+ }
143
+ },
144
+ );
145
+
146
+ test(
147
+ `DocSet (${testGroup})`,
148
+ async function (t) {
149
+ try {
150
+ t.plan(5);
151
+ const query = `{ docSet(id: "${pkDoc.docSetId}") { id lang: selector(id:"lang") abbr: selector(id:"abbr") documents { id } } }`;
152
+ const result = await pk.gqlQuery(query);
153
+ t.equal(result.errors, undefined);
154
+ t.ok('id' in result.data.docSet);
155
+ t.equal(result.data.docSet.lang, 'eng');
156
+ t.equal(result.data.docSet.abbr, 'web');
157
+ t.ok('id' in result.data.docSet.documents[0]);
158
+ } catch (err) {
159
+ console.log(err);
160
+ }
161
+ },
162
+ );
163
+
164
+ test(
165
+ `Filter docSets by IDs (${testGroup})`,
166
+ async function (t) {
167
+ try {
168
+ t.plan(5);
169
+ const query = `{ docSets(ids: ["${pkDoc.docSetId}"]) { id lang: selector(id:"lang") abbr: selector(id:"abbr") documents { id } } }`;
170
+ const result = await pk.gqlQuery(query);
171
+ t.equal(result.errors, undefined);
172
+ t.ok('id' in result.data.docSets[0]);
173
+ t.equal(result.data.docSets[0].lang, 'eng');
174
+ t.equal(result.data.docSets[0].abbr, 'web');
175
+ t.ok('id' in result.data.docSets[0].documents[0]);
176
+ } catch (err) {
177
+ console.log(err);
178
+ }
179
+ },
180
+ );
181
+
182
+ test(
183
+ `Filter docSets by withBooks (${testGroup})`,
184
+ async function (t) {
185
+ try {
186
+ t.plan(4);
187
+ const query = `{ docSets(withBook: "PSA") { id lang: selector(id:"lang") selector(id:"abbr") document(bookCode: "PSA") { id header(id:"bookCode")} } }`;
188
+ const result = await pk2.gqlQuery(query);
189
+ t.equal(result.errors, undefined);
190
+ t.equal(result.data.docSets.length, 2);
191
+ t.equal(result.data.docSets[0].document.header, 'PSA');
192
+ t.equal(result.data.docSets[1].document.header, 'PSA');
193
+ } catch (err) {
194
+ console.log(err);
195
+ }
196
+ },
197
+ );
198
+
199
+ test(
200
+ `Filter docSets documents by withChars (${testGroup})`,
201
+ async function (t) {
202
+ try {
203
+ const docSetDocuments = ds => ds
204
+ .map(ds => ds.documents)
205
+ .reduce((a, b) => a.concat(b));
206
+ t.plan(5);
207
+ let query = `{ docSets { documents(withChars: ["Boaz" "banana"]) { id header(id:"bookCode")} } }`;
208
+ let result = await pk2.gqlQuery(query);
209
+ t.equal(result.errors, undefined);
210
+ let documents = docSetDocuments(result.data.docSets);
211
+ t.equal(documents.length, 1);
212
+ t.equal(documents[0].header, 'RUT');
213
+ query = `{ docSets { documents(withChars: ["Boaz" "banana"] allChars: true) { id header(id:"bookCode")} } }`;
214
+ result = await pk2.gqlQuery(query);
215
+ t.equal(result.errors, undefined);
216
+ documents = docSetDocuments(result.data.docSets);
217
+ t.equal(documents.length, 0);
218
+ } catch (err) {
219
+ console.log(err);
220
+ }
221
+ },
222
+ );
223
+
224
+ test(
225
+ `Filter docSets documents by withMatchingChars (${testGroup})`,
226
+ async function (t) {
227
+ try {
228
+ const docSetDocuments = ds => ds
229
+ .map(ds => ds.documents)
230
+ .reduce((a, b) => a.concat(b));
231
+ t.plan(5);
232
+ let query = `{ docSets { documents(withMatchingChars: ["boaz" "banana"]) { id header(id:"bookCode")} } }`;
233
+ let result = await pk2.gqlQuery(query);
234
+ t.equal(result.errors, undefined);
235
+ let documents = docSetDocuments(result.data.docSets);
236
+ t.equal(documents.length, 1);
237
+ t.equal(documents[0].header, 'RUT');
238
+ query = `{ docSets { documents(withMatchingChars: ["boaz" "banana"] allChars: true) { id header(id:"bookCode")} } }`;
239
+ result = await pk2.gqlQuery(query);
240
+ t.equal(result.errors, undefined);
241
+ documents = docSetDocuments(result.data.docSets);
242
+ t.equal(documents.length, 0);
243
+ } catch (err) {
244
+ console.log(err);
245
+ }
246
+ },
247
+ );
248
+
249
+ test(
250
+ `Filter docSets documents by withScopes (${testGroup})`,
251
+ async function (t) {
252
+ try {
253
+ const docSetDocuments = ds => ds
254
+ .map(ds => ds.documents)
255
+ .reduce((a, b) => a.concat(b));
256
+ t.plan(4);
257
+ let query = `{ docSets { documents(withScopes: ["blockTag/p" "blockTag/q" "blockTag/q2"]) { id header(id:"bookCode")} } }`;
258
+ let result = await pk2.gqlQuery(query);
259
+ t.equal(result.errors, undefined);
260
+ let documents = docSetDocuments(result.data.docSets);
261
+ t.equal(documents.length, 4);
262
+ query = `{ docSets { documents(withScopes: ["blockTag/q" "blockTag/q2"] allScopes:true) { id header(id:"bookCode")} } }`;
263
+ result = await pk2.gqlQuery(query);
264
+ t.equal(result.errors, undefined);
265
+ documents = docSetDocuments(result.data.docSets);
266
+ t.equal(documents.length, 2);
267
+ } catch (err) {
268
+ console.log(err);
269
+ }
270
+ },
271
+ );
272
+
273
+ test(
274
+ `Filter docSets documents by withHeaderValues (${testGroup})`,
275
+ async function (t) {
276
+ try {
277
+ const docSetDocuments = ds => ds
278
+ .map(ds => ds.documents)
279
+ .reduce((a, b) => a.concat(b));
280
+ t.plan(8);
281
+ let query = `{ docSets { documents(withHeaderValues: { key: "bookCode" value: "PSA" }) { id } } }`;
282
+ let result = await pk2.gqlQuery(query);
283
+ t.equal(result.errors, undefined);
284
+ let documents = docSetDocuments(result.data.docSets);
285
+ t.equal(documents.length, 2);
286
+ query = `{ docSets { documents(withHeaderValues: { key: "ide" value: "UTF-8" }) { id } } }`;
287
+ result = await pk2.gqlQuery(query);
288
+ t.equal(result.errors, undefined);
289
+ documents = docSetDocuments(result.data.docSets);
290
+ t.equal(documents.length, 3);
291
+ query = `{ docSets { documents(withHeaderValues: { key: "ide" value: "EDBIC" }) { id } } }`;
292
+ result = await pk2.gqlQuery(query);
293
+ t.equal(result.errors, undefined);
294
+ documents = docSetDocuments(result.data.docSets);
295
+ t.equal(documents.length, 0);
296
+ query = `{ docSets { documents(withHeaderValues: { key: "banana" value: "split" }) { id } } }`;
297
+ result = await pk2.gqlQuery(query);
298
+ t.equal(result.errors, undefined);
299
+ documents = docSetDocuments(result.data.docSets);
300
+ t.equal(documents.length, 0);
301
+ } catch (err) {
302
+ console.log(err);
303
+ }
304
+ },
305
+ );
306
+
307
+ test(
308
+ `Documents (${testGroup})`,
309
+ async function (t) {
310
+ try {
311
+ t.plan(2);
312
+ const query = '{ documents { id } }';
313
+ const result = await pk.gqlQuery(query);
314
+ t.equal(result.errors, undefined);
315
+ t.ok('id' in result.data.documents[0]);
316
+ } catch (err) {
317
+ console.log(err);
318
+ }
319
+ },
320
+ );
321
+
322
+ test(
323
+ `Sort Documents (${testGroup})`,
324
+ async function (t) {
325
+ try {
326
+ t.plan(5);
327
+ let query = '{ documents(sortedBy:"paratext") { bookCode: header(id:"bookCode") } }';
328
+ let result = await pk2.gqlQuery(query);
329
+ t.equal(result.errors, undefined);
330
+ t.equal(result.data.documents[0].bookCode, 'RUT');
331
+ t.equal(result.data.documents[3].bookCode, 'PHM');
332
+ query = '{ documents(sortedBy:"banana") { bookCode: header(id:"bookCode") } }';
333
+ result = await pk2.gqlQuery(query);
334
+ t.equal(result.errors.length, 1);
335
+ t.ok(result.errors[0].message.includes('banana'));
336
+ } catch (err) {
337
+ console.log(err);
338
+ }
339
+ },
340
+ );
341
+
342
+ test(
343
+ `Document (${testGroup})`,
344
+ async function (t) {
345
+ try {
346
+ t.plan(8);
347
+ let query = `{ document(id: "${pkDoc.id}") { id } }`;
348
+ let result = await pk.gqlQuery(query);
349
+ t.equal(result.errors, undefined);
350
+ t.ok('id' in result.data.document);
351
+ query = `{ document(withBook: "RUT" docSetId: "${pkDoc.docSetId}") { id } }`;
352
+ result = await pk.gqlQuery(query);
353
+ t.equal(result.errors, undefined);
354
+ t.ok('id' in result.data.document);
355
+ query = `{ document(withBook: "XYZ" docSetId: "${pkDoc.docSetId}") { id } }`;
356
+ result = await pk.gqlQuery(query);
357
+ t.equal(result.errors, undefined);
358
+ t.ok(!result.data.document);
359
+ query = `{ document(withBook: "RUT") { id } }`;
360
+ result = await pk.gqlQuery(query);
361
+ t.equal(result.errors.length, 1);
362
+ t.ok(result.errors[0].message.includes('but not all three'));
363
+ } catch (err) {
364
+ console.log(err);
365
+ }
366
+ },
367
+ );
368
+
369
+ test(
370
+ `Filter documents by id (${testGroup})`,
371
+ async function (t) {
372
+ try {
373
+ t.plan(3);
374
+ const query = `{ documents(ids: ["${pkDoc.id}"]) { id } noDocs: documents(ids: ["abc"]) { id }}`;
375
+ const result = await pk.gqlQuery(query);
376
+ t.equal(result.errors, undefined);
377
+ t.ok('id' in result.data.documents[0]);
378
+ t.equal(result.data.noDocs.length, 0);
379
+ } catch (err) {
380
+ console.log(err);
381
+ }
382
+ },
383
+ );
384
+
385
+ test(
386
+ `Filter docSet documents by id (${testGroup})`,
387
+ async function (t) {
388
+ try {
389
+ t.plan(3);
390
+ const query = `{ docSet(id: "${pkDoc.docSetId}") { documents(ids: ["${pkDoc.id}"]) { id } noDocs: documents(ids: ["abc"]) { id } } }`;
391
+ const result = await pk.gqlQuery(query);
392
+ t.equal(result.errors, undefined);
393
+ t.ok('id' in result.data.docSet.documents[0]);
394
+ t.equal(result.data.docSet.noDocs.length, 0);
395
+ } catch (err) {
396
+ console.log(err);
397
+ }
398
+ },
399
+ );
400
+
401
+ test(
402
+ `Filter documents by withBook (${testGroup})`,
403
+ async function (t) {
404
+ try {
405
+ t.plan(4);
406
+ const query = `{ documents(withBook:"PSA") { id header(id:"bookCode") } }`;
407
+ const result = await pk2.gqlQuery(query);
408
+ t.equal(result.errors, undefined);
409
+ t.equal(result.data.documents.length, 2);
410
+ t.equal(result.data.documents[0].header, 'PSA');
411
+ t.equal(result.data.documents[1].header, 'PSA');
412
+ } catch (err) {
413
+ console.log(err);
414
+ }
415
+ },
416
+ );
417
+
418
+ test(
419
+ `Filter documents by withHeaderValues (${testGroup})`,
420
+ async function (t) {
421
+ try {
422
+ t.plan(10);
423
+ let query = `{ documents(withHeaderValues:{key: "bookCode" value: "PSA" }) { id } }`;
424
+ let result = await pk2.gqlQuery(query);
425
+ t.equal(result.errors, undefined);
426
+ t.equal(result.data.documents.length, 2);
427
+ query = `{ documents(withHeaderValues:{key: "bookCode" value: "RUT" }) { id } }`;
428
+ result = await pk2.gqlQuery(query);
429
+ t.equal(result.errors, undefined);
430
+ t.equal(result.data.documents.length, 1);
431
+ query = `{ documents(withHeaderValues:{key: "ide" value: "UTF-8" }) { id } }`;
432
+ result = await pk2.gqlQuery(query);
433
+ t.equal(result.errors, undefined);
434
+ t.equal(result.data.documents.length, 3);
435
+ query = `{ documents(withHeaderValues:{key: "ide" value: "EDBIC" }) { id } }`;
436
+ result = await pk2.gqlQuery(query);
437
+ t.equal(result.errors, undefined);
438
+ t.equal(result.data.documents.length, 0);
439
+ query = `{ documents(withHeaderValues:{key: "banana" value: "split" }) { id } }`;
440
+ result = await pk2.gqlQuery(query);
441
+ t.equal(result.errors, undefined);
442
+ t.equal(result.data.documents.length, 0);
443
+ } catch (err) {
444
+ console.log(err);
445
+ }
446
+ },
447
+ );
448
+
449
+ test(
450
+ `Enum index for string (${testGroup})`,
451
+ async function (t) {
452
+ try {
453
+ t.plan(3);
454
+ const query =
455
+ '{' +
456
+ ' docSets {' +
457
+ ' boaz: enumIndexForString(enumType:"wordLike" searchString:"Boaz")' +
458
+ ' banana: enumIndexForString(enumType:"wordLike" searchString:"Banana")' +
459
+ ' }' +
460
+ '}';
461
+ const result = await pk.gqlQuery(query);
462
+ t.equal(result.errors, undefined);
463
+ t.ok(result.data.docSets[0].boaz > 0);
464
+ t.equal(result.data.docSets[0].banana, -1);
465
+ } catch (err) {
466
+ console.log(err);
467
+ }
468
+ },
469
+ );
470
+
471
+ test(
472
+ `Enum regex indexes for string (${testGroup})`,
473
+ async function (t) {
474
+ try {
475
+ t.plan(3);
476
+ const query =
477
+ '{' +
478
+ ' docSets {' +
479
+ ' kin: enumRegexIndexesForString(enumType:"wordLike" searchRegex:"kinsm[ae]n") { index matched }' +
480
+ ' banana: enumRegexIndexesForString(enumType:"wordLike" searchRegex:"Banana") { index matched }' +
481
+ ' }' +
482
+ '}';
483
+ const result = await pk.gqlQuery(query);
484
+ t.equal(result.errors, undefined);
485
+ t.equal(result.data.docSets[0].kin.length, 2);
486
+ t.equal(result.data.docSets[0].banana.length, 0);
487
+ // console.log(JSON.stringify(result.data, null, 2));
488
+ } catch (err) {
489
+ console.log(err);
490
+ }
491
+ },
492
+ );
493
+
494
+ test(
495
+ `Unique Chars (${testGroup})`,
496
+ async function (t) {
497
+ try {
498
+ t.plan(7);
499
+ const query = '{ docSets { uniqueChars } }';
500
+ const result = await pk.gqlQuery(query);
501
+ t.equal(result.errors, undefined);
502
+ // console.log(JSON.stringify(result.data, null, 2));
503
+ t.ok(result.data.docSets[0].uniqueChars.length > 0);
504
+ t.ok(result.data.docSets[0].uniqueChars.includes(' '));
505
+ t.ok(result.data.docSets[0].uniqueChars.includes('!'));
506
+ t.ok(result.data.docSets[0].uniqueChars.includes('A'));
507
+ t.ok(result.data.docSets[0].uniqueChars.includes('1'));
508
+ t.ok(result.data.docSets[0].uniqueChars.includes('א'));
509
+ } catch (err) {
510
+ console.log(err);
511
+ }
512
+ },
513
+ );
514
+
515
+ test(
516
+ `Unique Chars String (${testGroup})`,
517
+ async function (t) {
518
+ try {
519
+ t.plan(7);
520
+ const query = '{ docSets { uniqueCharsString } }';
521
+ const result = await pk.gqlQuery(query);
522
+ t.equal(result.errors, undefined);
523
+ // console.log(JSON.stringify(result.data, null, 2));
524
+ t.ok(result.data.docSets[0].uniqueCharsString.length > 0);
525
+ t.ok(result.data.docSets[0].uniqueCharsString.includes(' '));
526
+ t.ok(result.data.docSets[0].uniqueCharsString.includes('!'));
527
+ t.ok(result.data.docSets[0].uniqueCharsString.includes('A'));
528
+ t.ok(result.data.docSets[0].uniqueCharsString.includes('1'));
529
+ t.ok(result.data.docSets[0].uniqueCharsString.includes('א'));
530
+ } catch (err) {
531
+ console.log(err);
532
+ }
533
+ },
534
+ );