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