@abedmurrar/objection 0.0.0-stage → 4.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +105 -2
  3. package/lib/index.mjs +6 -0
  4. package/lib/initialize.js +11 -0
  5. package/lib/model/AjvValidator.js +278 -0
  6. package/lib/model/Model.js +772 -0
  7. package/lib/model/ModifierNotFoundError.js +10 -0
  8. package/lib/model/NotFoundError.js +19 -0
  9. package/lib/model/RelationDoesNotExistError.js +11 -0
  10. package/lib/model/ValidationError.js +46 -0
  11. package/lib/model/Validator.js +20 -0
  12. package/lib/model/getModel.js +7 -0
  13. package/lib/model/graph/ModelGraph.js +60 -0
  14. package/lib/model/graph/ModelGraphBuilder.js +188 -0
  15. package/lib/model/graph/ModelGraphEdge.js +40 -0
  16. package/lib/model/graph/ModelGraphNode.js +201 -0
  17. package/lib/model/inheritModel.js +19 -0
  18. package/lib/model/modelBindKnex.js +69 -0
  19. package/lib/model/modelClone.js +102 -0
  20. package/lib/model/modelColPropMap.js +24 -0
  21. package/lib/model/modelConcurrency.js +24 -0
  22. package/lib/model/modelId.js +57 -0
  23. package/lib/model/modelJsonAttributes.js +72 -0
  24. package/lib/model/modelParseRelations.js +83 -0
  25. package/lib/model/modelQueryProps.js +116 -0
  26. package/lib/model/modelSet.js +116 -0
  27. package/lib/model/modelTableMetadata.js +71 -0
  28. package/lib/model/modelToJson.js +157 -0
  29. package/lib/model/modelUtils.js +40 -0
  30. package/lib/model/modelValidate.js +40 -0
  31. package/lib/model/modelValues.js +113 -0
  32. package/lib/model/modelVisitor.js +34 -0
  33. package/lib/objection.js +89 -0
  34. package/lib/queryBuilder/FunctionBuilder.js +291 -0
  35. package/lib/queryBuilder/InternalOptions.js +24 -0
  36. package/lib/queryBuilder/JoinBuilder.js +124 -0
  37. package/lib/queryBuilder/QueryBuilder.js +1136 -0
  38. package/lib/queryBuilder/QueryBuilderBase.js +666 -0
  39. package/lib/queryBuilder/QueryBuilderContext.js +20 -0
  40. package/lib/queryBuilder/QueryBuilderContextBase.js +26 -0
  41. package/lib/queryBuilder/QueryBuilderOperationSupport.js +484 -0
  42. package/lib/queryBuilder/QueryBuilderUserContext.js +25 -0
  43. package/lib/queryBuilder/RawBuilder.js +78 -0
  44. package/lib/queryBuilder/ReferenceBuilder.js +246 -0
  45. package/lib/queryBuilder/RelationExpression.js +373 -0
  46. package/lib/queryBuilder/StaticHookArguments.js +122 -0
  47. package/lib/queryBuilder/ValueBuilder.js +115 -0
  48. package/lib/queryBuilder/expressions.js +121 -0
  49. package/lib/queryBuilder/functions/mysql.js +762 -0
  50. package/lib/queryBuilder/graph/GraphAction.js +54 -0
  51. package/lib/queryBuilder/graph/GraphData.js +12 -0
  52. package/lib/queryBuilder/graph/GraphFetcher.js +155 -0
  53. package/lib/queryBuilder/graph/GraphNodeDbExistence.js +146 -0
  54. package/lib/queryBuilder/graph/GraphOperation.js +21 -0
  55. package/lib/queryBuilder/graph/GraphOptions.js +165 -0
  56. package/lib/queryBuilder/graph/GraphUpsert.js +231 -0
  57. package/lib/queryBuilder/graph/delete/GraphDelete.js +15 -0
  58. package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +56 -0
  59. package/lib/queryBuilder/graph/insert/GraphInsert.js +116 -0
  60. package/lib/queryBuilder/graph/insert/GraphInsertAction.js +183 -0
  61. package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +70 -0
  62. package/lib/queryBuilder/graph/patch/GraphPatch.js +15 -0
  63. package/lib/queryBuilder/graph/patch/GraphPatchAction.js +205 -0
  64. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +26 -0
  65. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +96 -0
  66. package/lib/queryBuilder/join/JoinResultColumn.js +19 -0
  67. package/lib/queryBuilder/join/JoinResultParser.js +106 -0
  68. package/lib/queryBuilder/join/RelationJoiner.js +258 -0
  69. package/lib/queryBuilder/join/TableNode.js +136 -0
  70. package/lib/queryBuilder/join/TableTree.js +69 -0
  71. package/lib/queryBuilder/join/utils.js +19 -0
  72. package/lib/queryBuilder/operations/DelegateOperation.js +101 -0
  73. package/lib/queryBuilder/operations/DeleteOperation.js +47 -0
  74. package/lib/queryBuilder/operations/FindByIdOperation.js +29 -0
  75. package/lib/queryBuilder/operations/FindByIdsOperation.js +23 -0
  76. package/lib/queryBuilder/operations/FindOperation.js +147 -0
  77. package/lib/queryBuilder/operations/FirstOperation.js +22 -0
  78. package/lib/queryBuilder/operations/FromOperation.js +91 -0
  79. package/lib/queryBuilder/operations/InsertAndFetchOperation.js +38 -0
  80. package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +35 -0
  81. package/lib/queryBuilder/operations/InsertGraphOperation.js +87 -0
  82. package/lib/queryBuilder/operations/InsertOperation.js +173 -0
  83. package/lib/queryBuilder/operations/InstanceDeleteOperation.js +37 -0
  84. package/lib/queryBuilder/operations/InstanceFindOperation.js +17 -0
  85. package/lib/queryBuilder/operations/InstanceInsertOperation.js +20 -0
  86. package/lib/queryBuilder/operations/InstanceUpdateOperation.js +45 -0
  87. package/lib/queryBuilder/operations/JoinRelatedOperation.js +83 -0
  88. package/lib/queryBuilder/operations/KnexOperation.js +11 -0
  89. package/lib/queryBuilder/operations/MergeOperation.js +43 -0
  90. package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +173 -0
  91. package/lib/queryBuilder/operations/OnBuildKnexOperation.js +23 -0
  92. package/lib/queryBuilder/operations/OnBuildOperation.js +23 -0
  93. package/lib/queryBuilder/operations/OnErrorOperation.js +23 -0
  94. package/lib/queryBuilder/operations/QueryBuilderOperation.js +258 -0
  95. package/lib/queryBuilder/operations/RangeOperation.js +37 -0
  96. package/lib/queryBuilder/operations/RelateOperation.js +20 -0
  97. package/lib/queryBuilder/operations/ReturningOperation.js +24 -0
  98. package/lib/queryBuilder/operations/RunAfterOperation.js +23 -0
  99. package/lib/queryBuilder/operations/RunBeforeOperation.js +23 -0
  100. package/lib/queryBuilder/operations/UnrelateOperation.js +18 -0
  101. package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +63 -0
  102. package/lib/queryBuilder/operations/UpdateOperation.js +130 -0
  103. package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +35 -0
  104. package/lib/queryBuilder/operations/UpsertGraphOperation.js +47 -0
  105. package/lib/queryBuilder/operations/WhereCompositeOperation.js +48 -0
  106. package/lib/queryBuilder/operations/WhereInOperation.js +46 -0
  107. package/lib/queryBuilder/operations/eager/EagerOperation.js +46 -0
  108. package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +41 -0
  109. package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +10 -0
  110. package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +227 -0
  111. package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +29 -0
  112. package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +37 -0
  113. package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +30 -0
  114. package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +33 -0
  115. package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +155 -0
  116. package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +135 -0
  117. package/lib/queryBuilder/operations/select/SelectOperation.js +50 -0
  118. package/lib/queryBuilder/operations/select/Selection.js +112 -0
  119. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +84 -0
  120. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +90 -0
  121. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +95 -0
  122. package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +787 -0
  123. package/lib/queryBuilder/parsers/relationExpressionParser.js +930 -0
  124. package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +17 -0
  125. package/lib/queryBuilder/transformations/QueryTransformation.js +9 -0
  126. package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +57 -0
  127. package/lib/queryBuilder/transformations/index.js +9 -0
  128. package/lib/queryBuilder/whereScopes.js +199 -0
  129. package/lib/relations/Relation.js +317 -0
  130. package/lib/relations/RelationDeleteOperation.js +23 -0
  131. package/lib/relations/RelationFindOperation.js +116 -0
  132. package/lib/relations/RelationInsertOperation.js +25 -0
  133. package/lib/relations/RelationOwner.js +199 -0
  134. package/lib/relations/RelationProperty.js +207 -0
  135. package/lib/relations/RelationUpdateOperation.js +23 -0
  136. package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +18 -0
  137. package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +33 -0
  138. package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +39 -0
  139. package/lib/relations/belongsToOne/BelongsToOneRelation.js +45 -0
  140. package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +46 -0
  141. package/lib/relations/hasMany/HasManyInsertOperation.js +45 -0
  142. package/lib/relations/hasMany/HasManyRelateOperation.js +48 -0
  143. package/lib/relations/hasMany/HasManyRelation.js +41 -0
  144. package/lib/relations/hasMany/HasManyUnrelateOperation.js +26 -0
  145. package/lib/relations/hasOne/HasOneRelation.js +10 -0
  146. package/lib/relations/hasOneThrough/HasOneThroughRelation.js +10 -0
  147. package/lib/relations/manyToMany/ManyToManyModifyMixin.js +82 -0
  148. package/lib/relations/manyToMany/ManyToManyRelation.js +405 -0
  149. package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +29 -0
  150. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +8 -0
  151. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +20 -0
  152. package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +8 -0
  153. package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +82 -0
  154. package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +40 -0
  155. package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +64 -0
  156. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +11 -0
  157. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +27 -0
  158. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +11 -0
  159. package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +8 -0
  160. package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +65 -0
  161. package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +8 -0
  162. package/lib/transaction.js +66 -0
  163. package/lib/utils/assert.js +19 -0
  164. package/lib/utils/buildUtils.js +19 -0
  165. package/lib/utils/classUtils.js +9 -0
  166. package/lib/utils/cloneDeep.js +365 -0
  167. package/lib/utils/createModifier.js +37 -0
  168. package/lib/utils/deprecate.js +11 -0
  169. package/lib/utils/identifierMapping.js +188 -0
  170. package/lib/utils/internalPropUtils.js +7 -0
  171. package/lib/utils/knexUtils.js +81 -0
  172. package/lib/utils/mixin.js +18 -0
  173. package/lib/utils/mysqlJsonPath.js +70 -0
  174. package/lib/utils/normalizeIds.js +127 -0
  175. package/lib/utils/objectUtils.js +314 -0
  176. package/lib/utils/parseFieldExpression.js +73 -0
  177. package/lib/utils/postgresJsonPath.js +96 -0
  178. package/lib/utils/promiseUtils/after.js +14 -0
  179. package/lib/utils/promiseUtils/afterReturn.js +14 -0
  180. package/lib/utils/promiseUtils/index.js +15 -0
  181. package/lib/utils/promiseUtils/isPromise.js +8 -0
  182. package/lib/utils/promiseUtils/map.js +96 -0
  183. package/lib/utils/promiseUtils/mapAfterAllReturn.js +23 -0
  184. package/lib/utils/promiseUtils/try.js +19 -0
  185. package/lib/utils/resolveModel.js +104 -0
  186. package/lib/utils/tmpColumnUtils.js +7 -0
  187. package/package.json +113 -4
  188. package/typings/objection/index.d.mts +362 -0
  189. package/typings/objection/index.d.ts +4131 -0
  190. package/typings/objection/relation-expression.d.ts +237 -0
@@ -0,0 +1,787 @@
1
+ 'use strict';
2
+ /*
3
+ * Generated by PEG.js 0.10.0.
4
+ *
5
+ * http://pegjs.org/
6
+ */
7
+ function peg$subclass(child, parent) {
8
+ function ctor() {
9
+ this.constructor = child;
10
+ }
11
+ ctor.prototype = parent.prototype;
12
+ child.prototype = new ctor();
13
+ }
14
+ function peg$SyntaxError(message, expected, found, location) {
15
+ this.message = message;
16
+ this.expected = expected;
17
+ this.found = found;
18
+ this.location = location;
19
+ this.name = 'SyntaxError';
20
+ if (typeof Error.captureStackTrace === 'function') {
21
+ Error.captureStackTrace(this, peg$SyntaxError);
22
+ }
23
+ }
24
+ peg$subclass(peg$SyntaxError, Error);
25
+ peg$SyntaxError.buildMessage = function (expected, found) {
26
+ var DESCRIBE_EXPECTATION_FNS = {
27
+ literal: function (expectation) {
28
+ return '"' + literalEscape(expectation.text) + '"';
29
+ },
30
+ class: function (expectation) {
31
+ var escapedParts = '', i;
32
+ for (i = 0; i < expectation.parts.length; i++) {
33
+ escapedParts +=
34
+ expectation.parts[i] instanceof Array
35
+ ? classEscape(expectation.parts[i][0]) + '-' + classEscape(expectation.parts[i][1])
36
+ : classEscape(expectation.parts[i]);
37
+ }
38
+ return '[' + (expectation.inverted ? '^' : '') + escapedParts + ']';
39
+ },
40
+ any: function (expectation) {
41
+ return 'any character';
42
+ },
43
+ end: function (expectation) {
44
+ return 'end of input';
45
+ },
46
+ other: function (expectation) {
47
+ return expectation.description;
48
+ },
49
+ };
50
+ function hex(ch) {
51
+ return ch.charCodeAt(0).toString(16).toUpperCase();
52
+ }
53
+ function literalEscape(s) {
54
+ return s
55
+ .replace(/\\/g, '\\\\')
56
+ .replace(/"/g, '\\"')
57
+ .replace(/\0/g, '\\0')
58
+ .replace(/\t/g, '\\t')
59
+ .replace(/\n/g, '\\n')
60
+ .replace(/\r/g, '\\r')
61
+ .replace(/[\x00-\x0F]/g, function (ch) {
62
+ return '\\x0' + hex(ch);
63
+ })
64
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
65
+ return '\\x' + hex(ch);
66
+ });
67
+ }
68
+ function classEscape(s) {
69
+ return s
70
+ .replace(/\\/g, '\\\\')
71
+ .replace(/\]/g, '\\]')
72
+ .replace(/\^/g, '\\^')
73
+ .replace(/-/g, '\\-')
74
+ .replace(/\0/g, '\\0')
75
+ .replace(/\t/g, '\\t')
76
+ .replace(/\n/g, '\\n')
77
+ .replace(/\r/g, '\\r')
78
+ .replace(/[\x00-\x0F]/g, function (ch) {
79
+ return '\\x0' + hex(ch);
80
+ })
81
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
82
+ return '\\x' + hex(ch);
83
+ });
84
+ }
85
+ function describeExpectation(expectation) {
86
+ return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
87
+ }
88
+ function describeExpected(expected) {
89
+ var descriptions = new Array(expected.length), i, j;
90
+ for (i = 0; i < expected.length; i++) {
91
+ descriptions[i] = describeExpectation(expected[i]);
92
+ }
93
+ descriptions.sort();
94
+ if (descriptions.length > 0) {
95
+ for (i = 1, j = 1; i < descriptions.length; i++) {
96
+ if (descriptions[i - 1] !== descriptions[i]) {
97
+ descriptions[j] = descriptions[i];
98
+ j++;
99
+ }
100
+ }
101
+ descriptions.length = j;
102
+ }
103
+ switch (descriptions.length) {
104
+ case 1:
105
+ return descriptions[0];
106
+ case 2:
107
+ return descriptions[0] + ' or ' + descriptions[1];
108
+ default:
109
+ return (descriptions.slice(0, -1).join(', ') + ', or ' + descriptions[descriptions.length - 1]);
110
+ }
111
+ }
112
+ function describeFound(found) {
113
+ return found ? '"' + literalEscape(found) + '"' : 'end of input';
114
+ }
115
+ return 'Expected ' + describeExpected(expected) + ' but ' + describeFound(found) + ' found.';
116
+ };
117
+ function peg$parse(input, options) {
118
+ options = options !== void 0 ? options : {};
119
+ var peg$FAILED = {}, peg$startRuleFunctions = { start: peg$parsestart }, peg$startRuleFunction = peg$parsestart, peg$c0 = ':', peg$c1 = peg$literalExpectation(':', false), peg$c2 = function (column, refs) {
120
+ var access = [];
121
+ if (refs) {
122
+ var firstAccess = refs[1];
123
+ access = refs[2];
124
+ access.unshift(firstAccess);
125
+ }
126
+ return { columnName: column, access: access };
127
+ }, peg$c3 = '[', peg$c4 = peg$literalExpectation('[', false), peg$c5 = '"', peg$c6 = peg$literalExpectation('"', false), peg$c7 = "'", peg$c8 = peg$literalExpectation("'", false), peg$c9 = ']', peg$c10 = peg$literalExpectation(']', false), peg$c11 = function (key) {
128
+ return { type: 'object', ref: Array.isArray(key) ? key[1] : key };
129
+ }, peg$c12 = function (index) {
130
+ return { type: 'array', ref: parseInt(index, 10) };
131
+ }, peg$c13 = function (key) {
132
+ return { type: 'object', ref: key };
133
+ }, peg$c14 = '.', peg$c15 = peg$literalExpectation('.', false), peg$c16 = /^[^\][]/, peg$c17 = peg$classExpectation([']', '['], true, false), peg$c18 = function (chars) {
134
+ return chars.join('');
135
+ }, peg$c19 = /^[^:]/, peg$c20 = peg$classExpectation([':'], true, false), peg$c21 = /^[^"]/, peg$c22 = peg$classExpectation(['"'], true, false), peg$c23 = /^[^']/, peg$c24 = peg$classExpectation(["'"], true, false), peg$c25 = /^[^.\][]/, peg$c26 = peg$classExpectation(['.', ']', '['], true, false), peg$c27 = /^[0-9]/, peg$c28 = peg$classExpectation([['0', '9']], false, false), peg$c29 = function (digits) {
136
+ return digits.join('');
137
+ }, peg$currPos = 0, peg$savedPos = 0, peg$posDetailsCache = [{ line: 1, column: 1 }], peg$maxFailPos = 0, peg$maxFailExpected = [], peg$silentFails = 0, peg$result;
138
+ if ('startRule' in options) {
139
+ if (!(options.startRule in peg$startRuleFunctions)) {
140
+ throw new Error('Can\'t start parsing from rule "' + options.startRule + '".');
141
+ }
142
+ peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
143
+ }
144
+ function text() {
145
+ return input.substring(peg$savedPos, peg$currPos);
146
+ }
147
+ function location() {
148
+ return peg$computeLocation(peg$savedPos, peg$currPos);
149
+ }
150
+ function expected(description, location) {
151
+ location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
152
+ throw peg$buildStructuredError([peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location);
153
+ }
154
+ function error(message, location) {
155
+ location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
156
+ throw peg$buildSimpleError(message, location);
157
+ }
158
+ function peg$literalExpectation(text, ignoreCase) {
159
+ return { type: 'literal', text: text, ignoreCase: ignoreCase };
160
+ }
161
+ function peg$classExpectation(parts, inverted, ignoreCase) {
162
+ return { type: 'class', parts: parts, inverted: inverted, ignoreCase: ignoreCase };
163
+ }
164
+ function peg$anyExpectation() {
165
+ return { type: 'any' };
166
+ }
167
+ function peg$endExpectation() {
168
+ return { type: 'end' };
169
+ }
170
+ function peg$otherExpectation(description) {
171
+ return { type: 'other', description: description };
172
+ }
173
+ function peg$computePosDetails(pos) {
174
+ var details = peg$posDetailsCache[pos], p;
175
+ if (details) {
176
+ return details;
177
+ }
178
+ else {
179
+ p = pos - 1;
180
+ while (!peg$posDetailsCache[p]) {
181
+ p--;
182
+ }
183
+ details = peg$posDetailsCache[p];
184
+ details = {
185
+ line: details.line,
186
+ column: details.column,
187
+ };
188
+ while (p < pos) {
189
+ if (input.charCodeAt(p) === 10) {
190
+ details.line++;
191
+ details.column = 1;
192
+ }
193
+ else {
194
+ details.column++;
195
+ }
196
+ p++;
197
+ }
198
+ peg$posDetailsCache[pos] = details;
199
+ return details;
200
+ }
201
+ }
202
+ function peg$computeLocation(startPos, endPos) {
203
+ var startPosDetails = peg$computePosDetails(startPos), endPosDetails = peg$computePosDetails(endPos);
204
+ return {
205
+ start: {
206
+ offset: startPos,
207
+ line: startPosDetails.line,
208
+ column: startPosDetails.column,
209
+ },
210
+ end: {
211
+ offset: endPos,
212
+ line: endPosDetails.line,
213
+ column: endPosDetails.column,
214
+ },
215
+ };
216
+ }
217
+ function peg$fail(expected) {
218
+ if (peg$currPos < peg$maxFailPos) {
219
+ return;
220
+ }
221
+ if (peg$currPos > peg$maxFailPos) {
222
+ peg$maxFailPos = peg$currPos;
223
+ peg$maxFailExpected = [];
224
+ }
225
+ peg$maxFailExpected.push(expected);
226
+ }
227
+ function peg$buildSimpleError(message, location) {
228
+ return new peg$SyntaxError(message, null, null, location);
229
+ }
230
+ function peg$buildStructuredError(expected, found, location) {
231
+ return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
232
+ }
233
+ function peg$parsestart() {
234
+ var s0, s1, s2, s3, s4, s5, s6;
235
+ s0 = peg$currPos;
236
+ s1 = peg$parsestringWithoutColon();
237
+ if (s1 !== peg$FAILED) {
238
+ s2 = peg$currPos;
239
+ if (input.charCodeAt(peg$currPos) === 58) {
240
+ s3 = peg$c0;
241
+ peg$currPos++;
242
+ }
243
+ else {
244
+ s3 = peg$FAILED;
245
+ if (peg$silentFails === 0) {
246
+ peg$fail(peg$c1);
247
+ }
248
+ }
249
+ if (s3 !== peg$FAILED) {
250
+ s4 = peg$parsebracketIndexRef();
251
+ if (s4 === peg$FAILED) {
252
+ s4 = peg$parsebracketStringRef();
253
+ if (s4 === peg$FAILED) {
254
+ s4 = peg$parsecolonReference();
255
+ }
256
+ }
257
+ if (s4 !== peg$FAILED) {
258
+ s5 = [];
259
+ s6 = peg$parsebracketIndexRef();
260
+ if (s6 === peg$FAILED) {
261
+ s6 = peg$parsebracketStringRef();
262
+ if (s6 === peg$FAILED) {
263
+ s6 = peg$parsedotReference();
264
+ }
265
+ }
266
+ while (s6 !== peg$FAILED) {
267
+ s5.push(s6);
268
+ s6 = peg$parsebracketIndexRef();
269
+ if (s6 === peg$FAILED) {
270
+ s6 = peg$parsebracketStringRef();
271
+ if (s6 === peg$FAILED) {
272
+ s6 = peg$parsedotReference();
273
+ }
274
+ }
275
+ }
276
+ if (s5 !== peg$FAILED) {
277
+ s3 = [s3, s4, s5];
278
+ s2 = s3;
279
+ }
280
+ else {
281
+ peg$currPos = s2;
282
+ s2 = peg$FAILED;
283
+ }
284
+ }
285
+ else {
286
+ peg$currPos = s2;
287
+ s2 = peg$FAILED;
288
+ }
289
+ }
290
+ else {
291
+ peg$currPos = s2;
292
+ s2 = peg$FAILED;
293
+ }
294
+ if (s2 === peg$FAILED) {
295
+ s2 = null;
296
+ }
297
+ if (s2 !== peg$FAILED) {
298
+ peg$savedPos = s0;
299
+ s1 = peg$c2(s1, s2);
300
+ s0 = s1;
301
+ }
302
+ else {
303
+ peg$currPos = s0;
304
+ s0 = peg$FAILED;
305
+ }
306
+ }
307
+ else {
308
+ peg$currPos = s0;
309
+ s0 = peg$FAILED;
310
+ }
311
+ return s0;
312
+ }
313
+ function peg$parsebracketStringRef() {
314
+ var s0, s1, s2, s3, s4, s5;
315
+ s0 = peg$currPos;
316
+ if (input.charCodeAt(peg$currPos) === 91) {
317
+ s1 = peg$c3;
318
+ peg$currPos++;
319
+ }
320
+ else {
321
+ s1 = peg$FAILED;
322
+ if (peg$silentFails === 0) {
323
+ peg$fail(peg$c4);
324
+ }
325
+ }
326
+ if (s1 !== peg$FAILED) {
327
+ s2 = peg$currPos;
328
+ if (input.charCodeAt(peg$currPos) === 34) {
329
+ s3 = peg$c5;
330
+ peg$currPos++;
331
+ }
332
+ else {
333
+ s3 = peg$FAILED;
334
+ if (peg$silentFails === 0) {
335
+ peg$fail(peg$c6);
336
+ }
337
+ }
338
+ if (s3 !== peg$FAILED) {
339
+ s4 = peg$parsestringWithoutDoubleQuotes();
340
+ if (s4 !== peg$FAILED) {
341
+ if (input.charCodeAt(peg$currPos) === 34) {
342
+ s5 = peg$c5;
343
+ peg$currPos++;
344
+ }
345
+ else {
346
+ s5 = peg$FAILED;
347
+ if (peg$silentFails === 0) {
348
+ peg$fail(peg$c6);
349
+ }
350
+ }
351
+ if (s5 !== peg$FAILED) {
352
+ s3 = [s3, s4, s5];
353
+ s2 = s3;
354
+ }
355
+ else {
356
+ peg$currPos = s2;
357
+ s2 = peg$FAILED;
358
+ }
359
+ }
360
+ else {
361
+ peg$currPos = s2;
362
+ s2 = peg$FAILED;
363
+ }
364
+ }
365
+ else {
366
+ peg$currPos = s2;
367
+ s2 = peg$FAILED;
368
+ }
369
+ if (s2 === peg$FAILED) {
370
+ s2 = peg$currPos;
371
+ if (input.charCodeAt(peg$currPos) === 39) {
372
+ s3 = peg$c7;
373
+ peg$currPos++;
374
+ }
375
+ else {
376
+ s3 = peg$FAILED;
377
+ if (peg$silentFails === 0) {
378
+ peg$fail(peg$c8);
379
+ }
380
+ }
381
+ if (s3 !== peg$FAILED) {
382
+ s4 = peg$parsestringWithoutSingleQuotes();
383
+ if (s4 !== peg$FAILED) {
384
+ if (input.charCodeAt(peg$currPos) === 39) {
385
+ s5 = peg$c7;
386
+ peg$currPos++;
387
+ }
388
+ else {
389
+ s5 = peg$FAILED;
390
+ if (peg$silentFails === 0) {
391
+ peg$fail(peg$c8);
392
+ }
393
+ }
394
+ if (s5 !== peg$FAILED) {
395
+ s3 = [s3, s4, s5];
396
+ s2 = s3;
397
+ }
398
+ else {
399
+ peg$currPos = s2;
400
+ s2 = peg$FAILED;
401
+ }
402
+ }
403
+ else {
404
+ peg$currPos = s2;
405
+ s2 = peg$FAILED;
406
+ }
407
+ }
408
+ else {
409
+ peg$currPos = s2;
410
+ s2 = peg$FAILED;
411
+ }
412
+ if (s2 === peg$FAILED) {
413
+ s2 = peg$parsestringWithoutSquareBrackets();
414
+ }
415
+ }
416
+ if (s2 !== peg$FAILED) {
417
+ if (input.charCodeAt(peg$currPos) === 93) {
418
+ s3 = peg$c9;
419
+ peg$currPos++;
420
+ }
421
+ else {
422
+ s3 = peg$FAILED;
423
+ if (peg$silentFails === 0) {
424
+ peg$fail(peg$c10);
425
+ }
426
+ }
427
+ if (s3 !== peg$FAILED) {
428
+ peg$savedPos = s0;
429
+ s1 = peg$c11(s2);
430
+ s0 = s1;
431
+ }
432
+ else {
433
+ peg$currPos = s0;
434
+ s0 = peg$FAILED;
435
+ }
436
+ }
437
+ else {
438
+ peg$currPos = s0;
439
+ s0 = peg$FAILED;
440
+ }
441
+ }
442
+ else {
443
+ peg$currPos = s0;
444
+ s0 = peg$FAILED;
445
+ }
446
+ return s0;
447
+ }
448
+ function peg$parsebracketIndexRef() {
449
+ var s0, s1, s2, s3;
450
+ s0 = peg$currPos;
451
+ if (input.charCodeAt(peg$currPos) === 91) {
452
+ s1 = peg$c3;
453
+ peg$currPos++;
454
+ }
455
+ else {
456
+ s1 = peg$FAILED;
457
+ if (peg$silentFails === 0) {
458
+ peg$fail(peg$c4);
459
+ }
460
+ }
461
+ if (s1 !== peg$FAILED) {
462
+ s2 = peg$parseinteger();
463
+ if (s2 !== peg$FAILED) {
464
+ if (input.charCodeAt(peg$currPos) === 93) {
465
+ s3 = peg$c9;
466
+ peg$currPos++;
467
+ }
468
+ else {
469
+ s3 = peg$FAILED;
470
+ if (peg$silentFails === 0) {
471
+ peg$fail(peg$c10);
472
+ }
473
+ }
474
+ if (s3 !== peg$FAILED) {
475
+ peg$savedPos = s0;
476
+ s1 = peg$c12(s2);
477
+ s0 = s1;
478
+ }
479
+ else {
480
+ peg$currPos = s0;
481
+ s0 = peg$FAILED;
482
+ }
483
+ }
484
+ else {
485
+ peg$currPos = s0;
486
+ s0 = peg$FAILED;
487
+ }
488
+ }
489
+ else {
490
+ peg$currPos = s0;
491
+ s0 = peg$FAILED;
492
+ }
493
+ return s0;
494
+ }
495
+ function peg$parsecolonReference() {
496
+ var s0, s1;
497
+ s0 = peg$currPos;
498
+ s1 = peg$parsestringWithoutSquareBracketsOrDots();
499
+ if (s1 !== peg$FAILED) {
500
+ peg$savedPos = s0;
501
+ s1 = peg$c13(s1);
502
+ }
503
+ s0 = s1;
504
+ return s0;
505
+ }
506
+ function peg$parsedotReference() {
507
+ var s0, s1, s2;
508
+ s0 = peg$currPos;
509
+ if (input.charCodeAt(peg$currPos) === 46) {
510
+ s1 = peg$c14;
511
+ peg$currPos++;
512
+ }
513
+ else {
514
+ s1 = peg$FAILED;
515
+ if (peg$silentFails === 0) {
516
+ peg$fail(peg$c15);
517
+ }
518
+ }
519
+ if (s1 !== peg$FAILED) {
520
+ s2 = peg$parsestringWithoutSquareBracketsOrDots();
521
+ if (s2 !== peg$FAILED) {
522
+ peg$savedPos = s0;
523
+ s1 = peg$c13(s2);
524
+ s0 = s1;
525
+ }
526
+ else {
527
+ peg$currPos = s0;
528
+ s0 = peg$FAILED;
529
+ }
530
+ }
531
+ else {
532
+ peg$currPos = s0;
533
+ s0 = peg$FAILED;
534
+ }
535
+ return s0;
536
+ }
537
+ function peg$parsestringWithoutSquareBrackets() {
538
+ var s0, s1, s2;
539
+ s0 = peg$currPos;
540
+ s1 = [];
541
+ if (peg$c16.test(input.charAt(peg$currPos))) {
542
+ s2 = input.charAt(peg$currPos);
543
+ peg$currPos++;
544
+ }
545
+ else {
546
+ s2 = peg$FAILED;
547
+ if (peg$silentFails === 0) {
548
+ peg$fail(peg$c17);
549
+ }
550
+ }
551
+ if (s2 !== peg$FAILED) {
552
+ while (s2 !== peg$FAILED) {
553
+ s1.push(s2);
554
+ if (peg$c16.test(input.charAt(peg$currPos))) {
555
+ s2 = input.charAt(peg$currPos);
556
+ peg$currPos++;
557
+ }
558
+ else {
559
+ s2 = peg$FAILED;
560
+ if (peg$silentFails === 0) {
561
+ peg$fail(peg$c17);
562
+ }
563
+ }
564
+ }
565
+ }
566
+ else {
567
+ s1 = peg$FAILED;
568
+ }
569
+ if (s1 !== peg$FAILED) {
570
+ peg$savedPos = s0;
571
+ s1 = peg$c18(s1);
572
+ }
573
+ s0 = s1;
574
+ return s0;
575
+ }
576
+ function peg$parsestringWithoutColon() {
577
+ var s0, s1, s2;
578
+ s0 = peg$currPos;
579
+ s1 = [];
580
+ if (peg$c19.test(input.charAt(peg$currPos))) {
581
+ s2 = input.charAt(peg$currPos);
582
+ peg$currPos++;
583
+ }
584
+ else {
585
+ s2 = peg$FAILED;
586
+ if (peg$silentFails === 0) {
587
+ peg$fail(peg$c20);
588
+ }
589
+ }
590
+ if (s2 !== peg$FAILED) {
591
+ while (s2 !== peg$FAILED) {
592
+ s1.push(s2);
593
+ if (peg$c19.test(input.charAt(peg$currPos))) {
594
+ s2 = input.charAt(peg$currPos);
595
+ peg$currPos++;
596
+ }
597
+ else {
598
+ s2 = peg$FAILED;
599
+ if (peg$silentFails === 0) {
600
+ peg$fail(peg$c20);
601
+ }
602
+ }
603
+ }
604
+ }
605
+ else {
606
+ s1 = peg$FAILED;
607
+ }
608
+ if (s1 !== peg$FAILED) {
609
+ peg$savedPos = s0;
610
+ s1 = peg$c18(s1);
611
+ }
612
+ s0 = s1;
613
+ return s0;
614
+ }
615
+ function peg$parsestringWithoutDoubleQuotes() {
616
+ var s0, s1, s2;
617
+ s0 = peg$currPos;
618
+ s1 = [];
619
+ if (peg$c21.test(input.charAt(peg$currPos))) {
620
+ s2 = input.charAt(peg$currPos);
621
+ peg$currPos++;
622
+ }
623
+ else {
624
+ s2 = peg$FAILED;
625
+ if (peg$silentFails === 0) {
626
+ peg$fail(peg$c22);
627
+ }
628
+ }
629
+ if (s2 !== peg$FAILED) {
630
+ while (s2 !== peg$FAILED) {
631
+ s1.push(s2);
632
+ if (peg$c21.test(input.charAt(peg$currPos))) {
633
+ s2 = input.charAt(peg$currPos);
634
+ peg$currPos++;
635
+ }
636
+ else {
637
+ s2 = peg$FAILED;
638
+ if (peg$silentFails === 0) {
639
+ peg$fail(peg$c22);
640
+ }
641
+ }
642
+ }
643
+ }
644
+ else {
645
+ s1 = peg$FAILED;
646
+ }
647
+ if (s1 !== peg$FAILED) {
648
+ peg$savedPos = s0;
649
+ s1 = peg$c18(s1);
650
+ }
651
+ s0 = s1;
652
+ return s0;
653
+ }
654
+ function peg$parsestringWithoutSingleQuotes() {
655
+ var s0, s1, s2;
656
+ s0 = peg$currPos;
657
+ s1 = [];
658
+ if (peg$c23.test(input.charAt(peg$currPos))) {
659
+ s2 = input.charAt(peg$currPos);
660
+ peg$currPos++;
661
+ }
662
+ else {
663
+ s2 = peg$FAILED;
664
+ if (peg$silentFails === 0) {
665
+ peg$fail(peg$c24);
666
+ }
667
+ }
668
+ if (s2 !== peg$FAILED) {
669
+ while (s2 !== peg$FAILED) {
670
+ s1.push(s2);
671
+ if (peg$c23.test(input.charAt(peg$currPos))) {
672
+ s2 = input.charAt(peg$currPos);
673
+ peg$currPos++;
674
+ }
675
+ else {
676
+ s2 = peg$FAILED;
677
+ if (peg$silentFails === 0) {
678
+ peg$fail(peg$c24);
679
+ }
680
+ }
681
+ }
682
+ }
683
+ else {
684
+ s1 = peg$FAILED;
685
+ }
686
+ if (s1 !== peg$FAILED) {
687
+ peg$savedPos = s0;
688
+ s1 = peg$c18(s1);
689
+ }
690
+ s0 = s1;
691
+ return s0;
692
+ }
693
+ function peg$parsestringWithoutSquareBracketsOrDots() {
694
+ var s0, s1, s2;
695
+ s0 = peg$currPos;
696
+ s1 = [];
697
+ if (peg$c25.test(input.charAt(peg$currPos))) {
698
+ s2 = input.charAt(peg$currPos);
699
+ peg$currPos++;
700
+ }
701
+ else {
702
+ s2 = peg$FAILED;
703
+ if (peg$silentFails === 0) {
704
+ peg$fail(peg$c26);
705
+ }
706
+ }
707
+ if (s2 !== peg$FAILED) {
708
+ while (s2 !== peg$FAILED) {
709
+ s1.push(s2);
710
+ if (peg$c25.test(input.charAt(peg$currPos))) {
711
+ s2 = input.charAt(peg$currPos);
712
+ peg$currPos++;
713
+ }
714
+ else {
715
+ s2 = peg$FAILED;
716
+ if (peg$silentFails === 0) {
717
+ peg$fail(peg$c26);
718
+ }
719
+ }
720
+ }
721
+ }
722
+ else {
723
+ s1 = peg$FAILED;
724
+ }
725
+ if (s1 !== peg$FAILED) {
726
+ peg$savedPos = s0;
727
+ s1 = peg$c18(s1);
728
+ }
729
+ s0 = s1;
730
+ return s0;
731
+ }
732
+ function peg$parseinteger() {
733
+ var s0, s1, s2;
734
+ s0 = peg$currPos;
735
+ s1 = [];
736
+ if (peg$c27.test(input.charAt(peg$currPos))) {
737
+ s2 = input.charAt(peg$currPos);
738
+ peg$currPos++;
739
+ }
740
+ else {
741
+ s2 = peg$FAILED;
742
+ if (peg$silentFails === 0) {
743
+ peg$fail(peg$c28);
744
+ }
745
+ }
746
+ if (s2 !== peg$FAILED) {
747
+ while (s2 !== peg$FAILED) {
748
+ s1.push(s2);
749
+ if (peg$c27.test(input.charAt(peg$currPos))) {
750
+ s2 = input.charAt(peg$currPos);
751
+ peg$currPos++;
752
+ }
753
+ else {
754
+ s2 = peg$FAILED;
755
+ if (peg$silentFails === 0) {
756
+ peg$fail(peg$c28);
757
+ }
758
+ }
759
+ }
760
+ }
761
+ else {
762
+ s1 = peg$FAILED;
763
+ }
764
+ if (s1 !== peg$FAILED) {
765
+ peg$savedPos = s0;
766
+ s1 = peg$c29(s1);
767
+ }
768
+ s0 = s1;
769
+ return s0;
770
+ }
771
+ peg$result = peg$startRuleFunction();
772
+ if (peg$result !== peg$FAILED && peg$currPos === input.length) {
773
+ return peg$result;
774
+ }
775
+ else {
776
+ if (peg$result !== peg$FAILED && peg$currPos < input.length) {
777
+ peg$fail(peg$endExpectation());
778
+ }
779
+ throw peg$buildStructuredError(peg$maxFailExpected, peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, peg$maxFailPos < input.length
780
+ ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
781
+ : peg$computeLocation(peg$maxFailPos, peg$maxFailPos));
782
+ }
783
+ }
784
+ module.exports = {
785
+ SyntaxError: peg$SyntaxError,
786
+ parse: peg$parse,
787
+ };