proskomma-core 0.9.10 → 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 (136) hide show
  1. package/.eslintrc.json +79 -0
  2. package/.gitattributes +2 -0
  3. package/docs/_config.yml +1 -0
  4. package/docs/index.md +3 -0
  5. package/docs/pk_edit_0_9.odt +0 -0
  6. package/docs/pk_edit_0_9.pdf +0 -0
  7. package/docs/proskomma_101_slideshow.odp +0 -0
  8. package/docs/proskomma_101_slideshow.pdf +0 -0
  9. package/docs/proskomma_edit_html.png +0 -0
  10. package/docs/proskomma_edit_html.svg +451 -0
  11. package/docs/proskomma_edit_reference.png +0 -0
  12. package/docs/proskomma_edit_reference.svg +349 -0
  13. package/docs/repo_logo.png +0 -0
  14. package/esm/package.json +3 -0
  15. package/esm/wrapper.mjs +5 -0
  16. package/index.cjs +6 -0
  17. package/package.json +18 -15
  18. package/src/graph/index.cjs +201 -0
  19. package/src/graph/lib/do_cv.cjs +249 -0
  20. package/src/graph/lib/dump.cjs +40 -0
  21. package/src/graph/lib/remake_blocks.cjs +57 -0
  22. package/src/graph/lib/sequence_chars.cjs +84 -0
  23. package/src/graph/lib/sort.cjs +39 -0
  24. package/src/graph/lib/tribos.cjs +97 -0
  25. package/src/graph/lib/tribos_expression.cjs +556 -0
  26. package/src/graph/lib/tribos_ohm_UNUSED.cjs +37 -0
  27. package/src/graph/lib/tribos_step.cjs +434 -0
  28. package/src/graph/mutations/add.cjs +91 -0
  29. package/src/graph/mutations/delete.cjs +61 -0
  30. package/src/graph/mutations/index.cjs +54 -0
  31. package/src/graph/mutations/rehash.cjs +17 -0
  32. package/src/graph/mutations/tags.cjs +120 -0
  33. package/src/graph/mutations/update.cjs +210 -0
  34. package/src/graph/mutations/versification.cjs +96 -0
  35. package/src/graph/queries/block.cjs +228 -0
  36. package/src/graph/queries/cIndex.cjs +87 -0
  37. package/src/graph/queries/cell.cjs +42 -0
  38. package/src/graph/queries/cv.cjs +19 -0
  39. package/src/graph/queries/cvBook.cjs +16 -0
  40. package/src/graph/queries/cvChapter.cjs +16 -0
  41. package/src/graph/queries/cvIndex.cjs +47 -0
  42. package/src/graph/queries/cvNavigation.cjs +116 -0
  43. package/src/graph/queries/cvVerseElement.cjs +84 -0
  44. package/src/graph/queries/cvVerses.cjs +14 -0
  45. package/src/graph/queries/doc_set.cjs +220 -0
  46. package/src/graph/queries/document.cjs +555 -0
  47. package/src/graph/queries/idParts.cjs +30 -0
  48. package/src/graph/queries/index.cjs +151 -0
  49. package/src/graph/queries/inputBlockSpec.cjs +17 -0
  50. package/src/graph/queries/inputItemObject.cjs +12 -0
  51. package/src/graph/queries/input_att_spec.cjs +14 -0
  52. package/src/graph/queries/input_key_matches.cjs +11 -0
  53. package/src/graph/queries/input_key_value.cjs +11 -0
  54. package/src/graph/queries/input_key_values.cjs +11 -0
  55. package/src/graph/queries/input_selector_spec.cjs +19 -0
  56. package/src/graph/queries/item.cjs +71 -0
  57. package/src/graph/queries/itemGroup.cjs +75 -0
  58. package/src/graph/queries/key_value.cjs +18 -0
  59. package/src/graph/queries/kv_entry.cjs +21 -0
  60. package/src/graph/queries/kv_sequence.cjs +151 -0
  61. package/src/graph/queries/node.cjs +44 -0
  62. package/src/graph/queries/orig.cjs +11 -0
  63. package/src/graph/queries/regex_index.cjs +18 -0
  64. package/src/graph/queries/row_equals_spec.cjs +11 -0
  65. package/src/graph/queries/row_match_spec.cjs +11 -0
  66. package/src/graph/queries/selector_spec.cjs +29 -0
  67. package/src/graph/queries/sequence.cjs +314 -0
  68. package/src/graph/queries/table_sequence.cjs +192 -0
  69. package/src/graph/queries/tree_sequence.cjs +58 -0
  70. package/src/graph/queries/verseNumber.cjs +44 -0
  71. package/src/graph/queries/verseRange.cjs +11 -0
  72. package/src/graph/queries/versification.cjs +25 -0
  73. package/src/index.cjs +583 -0
  74. package/src/model/doc_set.cjs +389 -0
  75. package/src/model/doc_set_helpers/block.cjs +232 -0
  76. package/src/model/doc_set_helpers/enum.cjs +87 -0
  77. package/src/model/doc_set_helpers/item.cjs +198 -0
  78. package/src/model/doc_set_helpers/rehash.cjs +53 -0
  79. package/src/model/doc_set_helpers/selectors.cjs +58 -0
  80. package/src/model/doc_set_helpers/serialize.cjs +22 -0
  81. package/src/model/doc_set_helpers/unsuccinctify.cjs +288 -0
  82. package/src/model/doc_set_helpers/update.cjs +290 -0
  83. package/src/model/document.cjs +369 -0
  84. package/src/model/document_helpers/blocks.cjs +135 -0
  85. package/src/model/document_helpers/chapter_verse.cjs +291 -0
  86. package/src/model/document_helpers/pre_enums.cjs +67 -0
  87. package/src/model/document_helpers/sequences.cjs +205 -0
  88. package/src/model/document_helpers/serialize_succinct.cjs +55 -0
  89. package/src/model/document_helpers/succinct_filter.cjs +102 -0
  90. package/src/model/versifications/eng_vrs.cjs +455 -0
  91. package/src/model/versifications/index.cjs +38 -0
  92. package/src/model/versifications/lxx_vrs.cjs +950 -0
  93. package/src/model/versifications/org_vrs.cjs +155 -0
  94. package/src/model/versifications/rsc_vrs.cjs +342 -0
  95. package/src/model/versifications/rso_vrs.cjs +541 -0
  96. package/src/model/versifications/vul_vrs.cjs +835 -0
  97. package/src/parser/index.cjs +506 -0
  98. package/src/parser/lexers/index.cjs +11 -0
  99. package/src/parser/lexers/lexingRegexes.cjs +45 -0
  100. package/src/parser/lexers/nodes.cjs +123 -0
  101. package/src/parser/lexers/object_for_fragment.cjs +123 -0
  102. package/src/parser/lexers/tsv.cjs +45 -0
  103. package/src/parser/lexers/usfm.cjs +17 -0
  104. package/src/parser/lexers/usx/index.cjs +7 -0
  105. package/src/parser/lexers/usx/usx_lexer.cjs +321 -0
  106. package/src/parser/lib/tokenize.cjs +37 -0
  107. package/src/parser/model/index.cjs +637 -0
  108. package/src/parser/parser_specs.cjs +781 -0
  109. package/src/pipelines/perf2x/index.cjs +7 -0
  110. package/src/pipelines/perf2x/perf2PkJsonPipeline.json +41 -0
  111. package/src/pipelines/perf2x/perf2usfmPipeline.json +65 -0
  112. package/src/transforms/calculateUsfmChapterPositions.cjs +106 -0
  113. package/src/transforms/index.cjs +9 -0
  114. package/src/transforms/perf2PkJson.cjs +534 -0
  115. package/src/transforms/perf2usfm.cjs +294 -0
  116. package/src/util/byteArray.cjs +251 -0
  117. package/src/util/canons.cjs +117 -0
  118. package/src/util/enums.cjs +41 -0
  119. package/src/util/generateId.cjs +6 -0
  120. package/src/util/graftDefs.cjs +15 -0
  121. package/src/util/index.cjs +29 -0
  122. package/src/util/inspectSuccinct.cjs +59 -0
  123. package/src/util/itemDefs.cjs +33 -0
  124. package/src/util/parserConstantDefs.cjs +30 -0
  125. package/src/util/scopeDefs.cjs +173 -0
  126. package/src/util/scriptlike/blocksSpec.cjs +192 -0
  127. package/src/util/scriptlike/dodson_lexicon.xsl +19 -0
  128. package/src/util/scriptlike/dodson_lexicon_to_entries.cjs +85 -0
  129. package/src/util/scriptlike/open_scriptures_hebrew_lexicon.xsl +28 -0
  130. package/src/util/scriptlike/open_scriptures_hebrew_lexicon_to_entries.cjs +85 -0
  131. package/src/util/succinct.cjs +159 -0
  132. package/src/util/tags.cjs +28 -0
  133. package/src/util/tokenDefs.cjs +27 -0
  134. package/src/util/versification.cjs +364 -0
  135. package/dist/index.js +0 -8
  136. package/dist/index.js.LICENSE.txt +0 -23
@@ -0,0 +1,151 @@
1
+ const { bookCodeCompareFunctions } = require('../lib/sort.cjs');
2
+ const versifications = require('../../model/versifications/index.cjs');
3
+
4
+ const querySchemaString = `
5
+ """The top level of Proskomma queries"""
6
+ type Query {
7
+ """The id of the processor, which is different for each Proskomma instance"""
8
+ id: String!
9
+ """A string describing the processor class"""
10
+ processor: String!
11
+ """The NPM package version"""
12
+ packageVersion: String!
13
+ """The selectors used to define docSets"""
14
+ selectors: [selectorSpec!]!
15
+ """The number of docSets"""
16
+ nDocSets: Int!
17
+ """The docSets in the processor"""
18
+ docSets(
19
+ """A whitelist of ids of docSets to include"""
20
+ ids: [String!]
21
+ """Only return docSets that match the list of selector values"""
22
+ withSelectors: [InputKeyValue!]
23
+ """Only return docSets containing a document with the specified bookCode"""
24
+ withBook: String
25
+ """Only return docSets with all the specified tags"""
26
+ withTags: [String!]
27
+ """Only return docSets with none of the specified tags"""
28
+ withoutTags: [String!]
29
+ ): [DocSet!]!
30
+ """The docSet with the specified id"""
31
+ docSet(
32
+ """The id of the docSet"""
33
+ id: String!
34
+ ): DocSet
35
+ """The number of documents in the processor"""
36
+ nDocuments: Int!
37
+ """The documents in the processor"""
38
+ documents(
39
+ """A whitelist of ids of documents to include"""
40
+ ids: [String!]
41
+ """Only return documents with the specified bookCode"""
42
+ withBook: String
43
+ """Only return documents with the specified header key/values"""
44
+ withHeaderValues: [InputKeyValue!]
45
+ """Only return documents with all the specified tags"""
46
+ withTags: [String!]
47
+ """Only return documents with none of the specified tags"""
48
+ withoutTags: [String!]
49
+ """Sort returned documents by the designated method (currently ${Object.keys(bookCodeCompareFunctions).join(', ')})"""
50
+ sortedBy: String
51
+ ): [Document!]!
52
+ """The document with the specified id, or the specified docSet and withBook"""
53
+ document(
54
+ """The id of the document"""
55
+ id: String
56
+ """The docSet of the document (use with withBook)"""
57
+ docSetId: String
58
+ """The book of the document (use with docSetId)"""
59
+ withBook: String
60
+ ) : Document
61
+ """Reference information about standard versifications"""
62
+ versifications: [versification!]!
63
+ """Reference information about a named, standard versification"""
64
+ versification(
65
+ """The id of the versification"""
66
+ id: String!
67
+ ) : versification!
68
+ }
69
+ `;
70
+ const queryResolvers = {
71
+ id: root => root.processorId,
72
+ selectors: root => root.selectors,
73
+ docSets: (root, args) => {
74
+ const docSetMatchesSelectors = (ds, selectors) => {
75
+ for (const selector of selectors) {
76
+ if (ds.selectors[selector.key].toString() !== selector.value) {
77
+ return false;
78
+ }
79
+ }
80
+ return true;
81
+ };
82
+
83
+ let ret = ('withBook' in args ? root.docSetsWithBook(args.withBook) : Object.values(root.docSets))
84
+ .filter(ds => !args.ids || args.ids.includes(ds.id));
85
+
86
+ if (args.withSelectors) {
87
+ ret = ret.filter(ds => docSetMatchesSelectors(ds, args.withSelectors));
88
+ }
89
+
90
+ if (args.withTags) {
91
+ ret = ret.filter(ds => args.withTags.filter(t => ds.tags.has(t)).length === args.withTags.length);
92
+ }
93
+
94
+ if (args.withoutTags) {
95
+ ret = ret.filter(ds => args.withoutTags.filter(t => ds.tags.has(t)).length === 0);
96
+ }
97
+
98
+ return ret;
99
+ },
100
+ docSet: (root, args) => root.docSetById(args.id),
101
+ documents: (root, args) => {
102
+ const headerValuesMatch = (docHeaders, requiredHeaders) => {
103
+ for (const requiredHeader of requiredHeaders || []) {
104
+ if (!(requiredHeader.key in docHeaders) || docHeaders[requiredHeader.key] !== requiredHeader.value) {
105
+ return false;
106
+ }
107
+ }
108
+ return true;
109
+ };
110
+
111
+ let ret = args.withBook ? root.documentsWithBook(args.withBook) : root.documentList();
112
+ ret = ret.filter(d => !args.ids || args.ids.includes(d.id));
113
+
114
+ if (args.withHeaderValues) {
115
+ ret = ret.filter(d => headerValuesMatch(d.headers, args.withHeaderValues));
116
+ }
117
+
118
+ if (args.withTags) {
119
+ ret = ret.filter(d => args.withTags.filter(t => d.tags.has(t)).length === args.withTags.length);
120
+ }
121
+
122
+ if (args.withoutTags) {
123
+ ret = ret.filter(d => args.withoutTags.filter(t => d.tags.has(t)).length === 0);
124
+ }
125
+
126
+ if (args.sortedBy) {
127
+ if (!(args.sortedBy in bookCodeCompareFunctions)) {
128
+ throw new Error(`sortedBy value must be one of [${Object.keys(bookCodeCompareFunctions).join(', ')}], not ${args.sortedBy}`);
129
+ }
130
+ ret.sort(bookCodeCompareFunctions[args.sortedBy]);
131
+ }
132
+
133
+ return ret;
134
+ },
135
+ document: (root, args) => {
136
+ if (args.id && !args.docSetId && !args.withBook) {
137
+ return root.documentById(args.id);
138
+ } else if (!args.id && args.docSetId && args.withBook) {
139
+ return root.documentsWithBook(args.withBook).filter(d => d.docSetId === args.docSetId)[0];
140
+ } else {
141
+ throw new Error('document requires either id or both docSetId and withBook (but not all three)');
142
+ }
143
+ },
144
+ versifications: () => Object.entries(versifications),
145
+ versification: (root, args) => Object.entries(versifications).filter(v => v[0] === args.id)[0],
146
+ };
147
+
148
+ module.exports = {
149
+ querySchemaString,
150
+ queryResolvers,
151
+ };
@@ -0,0 +1,17 @@
1
+ const inputBlockSpecSchemaString = `
2
+ """A specification to create or update a block"""
3
+ input inputBlockSpec {
4
+ """The block scope as an item"""
5
+ bs: InputItemObject!
6
+ """The block grafts as items"""
7
+ bg: [InputItemObject!]!
8
+ """The open scopes as items"""
9
+ os: [InputItemObject!]!
10
+ """The included scopes as items"""
11
+ is: [InputItemObject!]!
12
+ """The items"""
13
+ items: [InputItemObject!]!
14
+ }
15
+ `;
16
+
17
+ module.exports = { inputBlockSpecSchemaString };
@@ -0,0 +1,12 @@
1
+ const inputItemObjectSchemaString = `
2
+ """Item for arguments"""
3
+ input InputItemObject {
4
+ """The basic item type (token, scope or graft)'"""
5
+ type: String!
6
+ """The type-dependent subtype of the item"""
7
+ subType: String!
8
+ """The content of the item (the text for tokens, the label for scopes and the sequence id for grafts)"""
9
+ payload: String!
10
+ }`;
11
+
12
+ module.exports = { inputItemObjectSchemaString };
@@ -0,0 +1,14 @@
1
+ const inputAttSpecSchemaString = `
2
+ """Attribute Specification"""
3
+ input AttSpec {
4
+ """The type of attribute, ie what type of thing it's connected to"""
5
+ attType: String!
6
+ """The name of the USFM tag to which the attribute is connected"""
7
+ tagName: String!
8
+ """The attribute key (ie the bit to the left of the equals sign in USX)"""
9
+ attKey: String!
10
+ """The position of the value (which is 0 except for attributes with multiple values)"""
11
+ valueN: Int!
12
+ }`;
13
+
14
+ module.exports = { inputAttSpecSchemaString };
@@ -0,0 +1,11 @@
1
+ const keyMatchesSchemaString = `
2
+ """Key/Regex tuple"""
3
+ input KeyMatches {
4
+ """The key"""
5
+ key: String!
6
+ """The regex to match"""
7
+ matches: String!
8
+ }
9
+ `;
10
+
11
+ module.exports = { keyMatchesSchemaString };
@@ -0,0 +1,11 @@
1
+ const inputKeyValueSchemaString = `
2
+ """Input Key/Value Object"""
3
+ input InputKeyValue {
4
+ """The key"""
5
+ key: String!
6
+ """The value"""
7
+ value: String!
8
+ }
9
+ `;
10
+
11
+ module.exports = { inputKeyValueSchemaString };
@@ -0,0 +1,11 @@
1
+ const keyValuesSchemaString = `
2
+ """Input Key/Values Object"""
3
+ input KeyValues {
4
+ """The key"""
5
+ key: String!
6
+ """The values"""
7
+ values: [String!]!
8
+ }
9
+ `;
10
+
11
+ module.exports = { keyValuesSchemaString };
@@ -0,0 +1,19 @@
1
+ const inputSelectorSpecSchemaString = `
2
+ """Input specification of a selector"""
3
+ input inputSelectorSpec {
4
+ """Name (ie the key)"""
5
+ name: String!
6
+ """Data type (string or integer)"""
7
+ type: String!
8
+ """Regex for validating string selector"""
9
+ regex: String
10
+ """Inclusive minimum value for integer selector"""
11
+ min: String
12
+ """Inclusive maximum value for integer selector"""
13
+ max: String
14
+ """Enum of permitted string values"""
15
+ enum: [String!]
16
+ }
17
+ `;
18
+
19
+ module.exports = { inputSelectorSpecSchemaString };
@@ -0,0 +1,71 @@
1
+ const scopeMatchesStartsWith = (sw, s) => {
2
+ if (sw.length === 0) {
3
+ return true;
4
+ }
5
+
6
+ for (const swv of sw) {
7
+ if (s.startsWith(swv)) {
8
+ return true;
9
+ }
10
+ }
11
+ return false;
12
+ };
13
+
14
+ const itemSchemaString = `
15
+ """Item"""
16
+ type Item {
17
+ """The basic item type (token, scope or graft)"""
18
+ type: String!
19
+ """The type-dependent subtype of the item"""
20
+ subType: String!
21
+ """The content of the item (the text for tokens, the label for scopes and the sequence id for grafts)"""
22
+ payload(
23
+ """If true, turn all whitespace into a normal space"""
24
+ normalizeSpace: Boolean
25
+ """A whitelist of characters to include"""
26
+ includeChars: [String!]
27
+ """A blacklist of characters to exclude"""
28
+ excludeChars: [String!],
29
+ ): String!
30
+ """If 'includeContext' was selected, and for tokens, the index of the token from the start of the sequence"""
31
+ position(
32
+ """Only include scopes that begin with this value"""
33
+ startsWith: [String!]
34
+ ): Int
35
+ """If 'includeContext' was selected, a list of scopes that are open around the item"""
36
+ scopes(
37
+ """Only include scopes that begin with this value"""
38
+ startsWith: [String!]
39
+ ): [String!]
40
+ }
41
+ `;
42
+
43
+ const itemResolvers = {
44
+ type: root => root[0],
45
+ subType: root => root[1],
46
+ payload: (root, args) => {
47
+ let ret = root[2];
48
+
49
+ if (root[0] === 'token') {
50
+ if (args.normalizeSpace) {
51
+ ret = root[2].replace(/[ \t\n\r]+/g, ' ');
52
+ }
53
+
54
+ if (args.includeChars || args.excludeChars) {
55
+ let retArray = ret.split('');
56
+ retArray = retArray.filter(c => !args.includeChars || args.includeChars.includes(c));
57
+ retArray = retArray.filter(c => !args.excludeChars || !args.excludeChars.includes(c));
58
+ ret = retArray.join('');
59
+ }
60
+ }
61
+ return ret;
62
+ },
63
+ position: root => root[3],
64
+ scopes: (root, args) =>
65
+ root[4] ? root[4].filter(s => !args.startsWith || scopeMatchesStartsWith(args.startsWith, s)) : [],
66
+ };
67
+
68
+ module.exports = {
69
+ itemSchemaString,
70
+ itemResolvers,
71
+ };
@@ -0,0 +1,75 @@
1
+ const { dumpItemGroup } = require('../lib/dump.cjs');
2
+
3
+ const scopeMatchesStartsWith = (sw, s) => {
4
+ if (sw.length === 0) {
5
+ return true;
6
+ }
7
+
8
+ for (const swv of sw) {
9
+ if (s.startsWith(swv)) {
10
+ return true;
11
+ }
12
+ }
13
+ return false;
14
+ };
15
+
16
+ // [scopeLabels, items]
17
+
18
+ const itemGroupSchemaString = `
19
+ """A collection of items, with scope context"""
20
+ type ItemGroup {
21
+ """Items for this itemGroup"""
22
+ items: [Item!]!
23
+ """Tokens for this itemGroup"""
24
+ tokens(
25
+ """Return tokens whose payload is an exact match to one of the specified strings"""
26
+ withChars: [String!]
27
+ """Return tokens with one of the specified subTypes"""
28
+ withSubTypes: [String!]
29
+ ): [Item!]!
30
+ """The text of the itemGroup as a single string"""
31
+ text(
32
+ """If true, converts each whitespace character to a single space"""
33
+ normalizeSpace: Boolean
34
+ ): String!
35
+ """The labels of scopes that were open at the beginning of the itemGroup"""
36
+ scopeLabels(
37
+ """Only include scopes that begin with this value"""
38
+ startsWith: [String!]
39
+ ): [String!]!
40
+ """The itemGroup content as a string in a compact eyeballable format"""
41
+ dump: String!
42
+ """A list of scopes from the items of the itemGroup"""
43
+ includedScopes: [String!]!
44
+ }
45
+ `;
46
+
47
+ const itemGroupResolvers = {
48
+ items: root => root[1],
49
+ tokens: (root, args) =>
50
+ root[1].filter(i =>
51
+ i[0] === 'token' &&
52
+ (!args.withChars || args.withChars.includes(i[2])) &&
53
+ (!args.withSubTypes || args.withSubTypes.includes(i[1])),
54
+ ),
55
+ text: (root, args) => {
56
+ const tokensText = root[1].filter(i => i[0] === 'token').map(t => t[2]).join('');
57
+ return args.normalizeSpace ? tokensText.replace(/[ \t\n\r]+/g, ' ') : tokensText;
58
+ },
59
+ scopeLabels: (root, args) =>
60
+ root[0].filter(s => !args.startsWith || scopeMatchesStartsWith(args.startsWith, s)),
61
+ dump: root => dumpItemGroup(root),
62
+ includedScopes: root =>
63
+ Array.from(
64
+ new Set(
65
+ root[1]
66
+ .filter(i => i[0] === 'scope' && i[1] === 'start')
67
+ .map(t => t[2]),
68
+ ),
69
+ ),
70
+ };
71
+
72
+ module.exports = {
73
+ itemGroupSchemaString,
74
+ itemGroupResolvers,
75
+ };
@@ -0,0 +1,18 @@
1
+ const keyValueSchemaString = `
2
+ """Key/Value tuple"""
3
+ type KeyValue {
4
+ """The key"""
5
+ key: String!
6
+ """The value"""
7
+ value: String!
8
+ }`;
9
+
10
+ const keyValueResolvers = {
11
+ key: root => root[0],
12
+ value: root => root[1],
13
+ };
14
+
15
+ module.exports = {
16
+ keyValueSchemaString,
17
+ keyValueResolvers,
18
+ };
@@ -0,0 +1,21 @@
1
+ const kvEntrySchemaString = `
2
+ """Key/Items tuple"""
3
+ type kvEntry {
4
+ """The key"""
5
+ key: String!
6
+ """The secondary keys"""
7
+ secondaryKeys: [KeyValue!]
8
+ """The fields as itemGroups"""
9
+ itemGroups: [ItemGroup]!
10
+ }`;
11
+
12
+ const kvEntryResolvers = {
13
+ key: root => root[0],
14
+ secondaryKeys: root => root[1],
15
+ itemGroups: root => root[2],
16
+ };
17
+
18
+ module.exports = {
19
+ kvEntrySchemaString,
20
+ kvEntryResolvers,
21
+ };
@@ -0,0 +1,151 @@
1
+ const xre = require('xregexp');
2
+
3
+ const kvSequenceSchemaString = `
4
+ """A contiguous flow of content for key-values"""
5
+ type kvSequence {
6
+ """The id of the sequence"""
7
+ id: String!
8
+ """The number of entries in the key-value sequence"""
9
+ nEntries: Int!
10
+ """The entries in the key-value sequence"""
11
+ entries(
12
+ """Only return entries whose key matches the specification"""
13
+ keyMatches: String
14
+ """Only return entries whose key equals one of the values in the specification"""
15
+ keyEquals: [String!]
16
+ """Only return entries whose secondary keys match the specification"""
17
+ secondaryMatches: [KeyMatches!]
18
+ """Only return entries whose secondary keys equal one of the values in the specification"""
19
+ secondaryEquals: [KeyValues!]
20
+ """Only return entries whose content matches the specification"""
21
+ contentMatches: [KeyMatches!]
22
+ """Only return entries whose content equals one of the values in the specification"""
23
+ contentEquals: [KeyValues!]
24
+ ): [kvEntry!]
25
+ """A list of the tags of this sequence"""
26
+ tags: [String!]!
27
+ """A list of the tags of this sequence as key/value tuples"""
28
+ tagsKv: [KeyValue!]!
29
+ """Whether or not the sequence has the specified tag"""
30
+ hasTag(
31
+ """The tag name"""
32
+ tagName: String
33
+ ): Boolean!
34
+ }
35
+ `;
36
+
37
+ const kvSequenceResolvers = {
38
+ nEntries: root => root.blocks.length,
39
+ entries: (root, args, context) => {
40
+ let ret = root.blocks.map(
41
+ b => [
42
+ context.docSet.unsuccinctifyScopes(b.bs)
43
+ .map(s => s[2].split('/')[1])[0],
44
+ context.docSet.unsuccinctifyScopes(b.is)
45
+ .filter(s => s[2].startsWith('kvSecondary/'))
46
+ .map(s => [s[2].split('/')[1], s[2].split('/')[2]]),
47
+ context.docSet.sequenceItemsByScopes([b], ['kvField/'], false),
48
+ ],
49
+ );
50
+
51
+ if (args.keyMatches) {
52
+ ret = ret.filter(e => xre.test(e[0], xre(args.keyMatches)));
53
+ }
54
+
55
+ if (args.keyEquals) {
56
+ ret = ret.filter(e => args.keyEquals.includes(e[0]));
57
+ }
58
+
59
+ if (args.secondaryMatches) {
60
+ const matchesOb = {};
61
+ args.secondaryMatches.forEach(sm => (matchesOb[sm.key] = sm.matches));
62
+ ret = ret.filter(
63
+ e => {
64
+ const secondaryOb = {};
65
+ e[1].forEach(st => (secondaryOb[st[0]] = st[1]));
66
+
67
+ for (const mo of Object.entries(matchesOb)) {
68
+ const secondaryString = secondaryOb[mo[0]];
69
+
70
+ if (!secondaryString || !xre.test(secondaryString, xre(mo[1]))) {
71
+ return false;
72
+ }
73
+ }
74
+ return true;
75
+ });
76
+ }
77
+
78
+ if (args.secondaryEquals) {
79
+ const equalsOb = {};
80
+ args.secondaryEquals.forEach(sm => (equalsOb[sm.key] = sm.values));
81
+ ret = ret.filter(
82
+ e => {
83
+ const secondaryOb = {};
84
+ e[1].forEach(st => (secondaryOb[st[0]] = st[1]));
85
+
86
+ for (const mo of Object.entries(equalsOb)) {
87
+ const secondaryString = secondaryOb[mo[0]];
88
+
89
+ if (!secondaryString || !mo[1].includes(secondaryString)) {
90
+ return false;
91
+ }
92
+ }
93
+ return true;
94
+ });
95
+ }
96
+
97
+ if (args.contentMatches) {
98
+ const matchesOb = {};
99
+ args.contentMatches.forEach(sm => (matchesOb[sm.key] = sm.matches));
100
+ ret = ret.filter(
101
+ e => {
102
+ const contentOb = {};
103
+ e[2].forEach(st => (contentOb[st[0].filter(s => s.startsWith('kvField'))[0].split('/')[1]] = st[1].filter(i => i[0] === 'token').map(t => t[2]).join('')));
104
+
105
+ for (const mo of Object.entries(matchesOb)) {
106
+ const contentString = contentOb[mo[0]];
107
+
108
+ if (!contentString || !xre.test(contentString, xre(mo[1]))) {
109
+ return false;
110
+ }
111
+ }
112
+ return true;
113
+ });
114
+ }
115
+
116
+ if (args.contentEquals) {
117
+ const equalsOb = {};
118
+ args.contentEquals.forEach(sm => (equalsOb[sm.key] = sm.values));
119
+ ret = ret.filter(
120
+ e => {
121
+ const contentOb = {};
122
+ e[2].forEach(st => (contentOb[st[0].filter(s => s.startsWith('kvField'))[0].split('/')[1]] = st[1].filter(i => i[0] === 'token').map(t => t[2]).join('')));
123
+
124
+ for (const mo of Object.entries(equalsOb)) {
125
+ const contentString = contentOb[mo[0]];
126
+
127
+ if (!contentString || !contentString.includes(mo[1])) {
128
+ return false;
129
+ }
130
+ }
131
+ return true;
132
+ });
133
+ }
134
+
135
+ return ret;
136
+ },
137
+ tags: root => Array.from(root.tags),
138
+ tagsKv: root => Array.from(root.tags).map(t => {
139
+ if (t.includes(':')) {
140
+ return [t.substring(0, t.indexOf(':')), t.substring(t.indexOf(':') + 1)];
141
+ } else {
142
+ return [t, ''];
143
+ }
144
+ }),
145
+ hasTag: (root, args) => root.tags.has(args.tagName),
146
+ };
147
+
148
+ module.exports = {
149
+ kvSequenceSchemaString,
150
+ kvSequenceResolvers,
151
+ };
@@ -0,0 +1,44 @@
1
+ const utils = require('../../util/index.cjs');
2
+
3
+ const nodeSchemaString = `
4
+ """A tree node"""
5
+ type node {
6
+ """The node id"""
7
+ id: String!
8
+ """The node parent id"""
9
+ parentId: String
10
+ """The keys for content"""
11
+ keys: [String!]!
12
+ """The content as itemGroups"""
13
+ itemGroups(
14
+ """If true, adds scope and nextToken information to each token"""
15
+ includeContext: Boolean
16
+ ): [ItemGroup!]!
17
+ """The node children ids"""
18
+ childIds: [String!]!
19
+ }
20
+ `;
21
+
22
+ const nodeResolvers = {
23
+ id: (root, args, context) => {
24
+ const [itemLength, itemType, itemSubtype] = utils.succinct.headerBytes(root.bs, 0);
25
+ return context.docSet.unsuccinctifyScope(root.bs, itemType, itemSubtype, 0)[2].split('/')[1];
26
+ },
27
+ parentId: (root, args, context) => {
28
+ const parentId = context.docSet.unsuccinctifyScopes(root.is).filter(s => s[2].startsWith('tTreeParent'))[0][2].split('/')[1];
29
+ return parentId === 'none' ? null: parentId;
30
+ },
31
+ keys: (root, args, context) => context.docSet.unsuccinctifyScopes(root.is)
32
+ .filter(s => s[2].startsWith('tTreeContent'))
33
+ .map(s => s[2].split('/')[1]),
34
+ itemGroups: (root, args, context) =>
35
+ context.docSet.sequenceItemsByScopes([root], ['tTreeContent/'], args.includeContext || false),
36
+ childIds: (root, args, context) =>
37
+ context.docSet.unsuccinctifyScopes(root.is).filter(s => s[2].startsWith('tTreeChild'))
38
+ .map(s => s[2].split('/')[2]),
39
+ };
40
+
41
+ module.exports = {
42
+ nodeSchemaString,
43
+ nodeResolvers,
44
+ };
@@ -0,0 +1,11 @@
1
+ const origSchemaString = `
2
+ """Mapped verse information"""
3
+ type orig {
4
+ """The book code"""
5
+ book: String
6
+ """A list of chapter-verse references"""
7
+ cvs: [cv!]!
8
+ }
9
+ `;
10
+
11
+ module.exports = { origSchemaString };
@@ -0,0 +1,18 @@
1
+ const regexIndexSchemaString = `
2
+ """Information about a regex match on an enum"""
3
+ type regexIndex {
4
+ """The index in the enum"""
5
+ index: String!
6
+ """The string in the enum that matched"""
7
+ matched: String!
8
+ }`;
9
+
10
+ const regexIndexResolvers = {
11
+ index: root => root[0],
12
+ matched: root => root[1],
13
+ };
14
+
15
+ module.exports = {
16
+ regexIndexSchemaString,
17
+ regexIndexResolvers,
18
+ };
@@ -0,0 +1,11 @@
1
+ const rowEqualsSpecSchemaString = `
2
+ """Row Equals Specification"""
3
+ input rowEqualsSpec {
4
+ """The position of the column in which to search a match"""
5
+ colN: Int!
6
+ """The values to match"""
7
+ values: [String!]!
8
+ }
9
+ `;
10
+
11
+ module.exports = { rowEqualsSpecSchemaString };