@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,1042 @@
1
+ /*
2
+ * Generated by PEG.js 0.10.0.
3
+ *
4
+ * http://pegjs.org/
5
+ */
6
+
7
+ 'use strict';
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 = function (expr) {
155
+ const node = newNode();
156
+
157
+ if (expr.$name === '*') {
158
+ node.$allRecursive = true;
159
+ } else {
160
+ assertDuplicateRelation(node, expr);
161
+ node[expr.$name] = expr;
162
+ node.$childNames.push(expr.$name);
163
+ }
164
+
165
+ return node;
166
+ },
167
+ peg$c1 = function (list) {
168
+ const node = newNode();
169
+
170
+ list.forEach((expr) => {
171
+ assertDuplicateRelation(node, expr);
172
+ node[expr.$name] = expr;
173
+ node.$childNames.push(expr.$name);
174
+ });
175
+
176
+ return node;
177
+ },
178
+ peg$c2 = function (name, args, alias, list) {
179
+ const node = newNode();
180
+
181
+ node.$name = alias || name;
182
+ node.$relation = name;
183
+ node.$modify = args || [];
184
+
185
+ list.forEach((expr) => {
186
+ assertDuplicateRelation(node, expr);
187
+ node[expr.$name] = expr;
188
+ node.$childNames.push(expr.$name);
189
+ });
190
+
191
+ return node;
192
+ },
193
+ peg$c3 = function (name, args, alias, expr) {
194
+ const node = newNode();
195
+
196
+ node.$name = alias || name;
197
+ node.$relation = name;
198
+ node.$modify = args || [];
199
+
200
+ if (expr) {
201
+ const match = /^\^(\d*)$/.exec(expr.$name);
202
+
203
+ if (match) {
204
+ if (match[1]) {
205
+ node.$recursive = parseInt(match[1], 10);
206
+ } else {
207
+ node.$recursive = true;
208
+ }
209
+ } else if (expr.$name === '*') {
210
+ node.$allRecursive = true;
211
+ } else {
212
+ assertDuplicateRelation(node, expr);
213
+ node[expr.$name] = expr;
214
+ node.$childNames.push(expr.$name);
215
+ }
216
+ }
217
+
218
+ return node;
219
+ },
220
+ peg$c4 = 'as',
221
+ peg$c5 = peg$literalExpectation('as', false),
222
+ peg$c6 = function (alias) {
223
+ return alias;
224
+ },
225
+ peg$c7 = function (name) {
226
+ return name.join('');
227
+ },
228
+ peg$c8 = /^[^[\](),. \t\r\n]/,
229
+ peg$c9 = peg$classExpectation(
230
+ ['[', ']', '(', ')', ',', '.', ' ', '\t', '\r', '\n'],
231
+ true,
232
+ false,
233
+ ),
234
+ peg$c10 = '(',
235
+ peg$c11 = peg$literalExpectation('(', false),
236
+ peg$c12 = ')',
237
+ peg$c13 = peg$literalExpectation(')', false),
238
+ peg$c14 = function (args) {
239
+ return args;
240
+ },
241
+ peg$c15 = ',',
242
+ peg$c16 = peg$literalExpectation(',', false),
243
+ peg$c17 = function (arg) {
244
+ return arg;
245
+ },
246
+ peg$c18 = /^[ \t\r\n]/,
247
+ peg$c19 = peg$classExpectation([' ', '\t', '\r', '\n'], false, false),
248
+ peg$c20 = '.',
249
+ peg$c21 = peg$literalExpectation('.', false),
250
+ peg$c22 = function (list) {
251
+ return list;
252
+ },
253
+ peg$c23 = '[',
254
+ peg$c24 = peg$literalExpectation('[', false),
255
+ peg$c25 = ']',
256
+ peg$c26 = peg$literalExpectation(']', false),
257
+ peg$c27 = function (items) {
258
+ return items;
259
+ },
260
+ peg$c28 = function (expr) {
261
+ return expr;
262
+ },
263
+ peg$c29 = function (sub) {
264
+ return sub;
265
+ },
266
+ peg$currPos = 0,
267
+ peg$savedPos = 0,
268
+ peg$posDetailsCache = [{ line: 1, column: 1 }],
269
+ peg$maxFailPos = 0,
270
+ peg$maxFailExpected = [],
271
+ peg$silentFails = 0,
272
+ peg$result;
273
+
274
+ if ('startRule' in options) {
275
+ if (!(options.startRule in peg$startRuleFunctions)) {
276
+ throw new Error('Can\'t start parsing from rule "' + options.startRule + '".');
277
+ }
278
+
279
+ peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
280
+ }
281
+
282
+ function text() {
283
+ return input.substring(peg$savedPos, peg$currPos);
284
+ }
285
+
286
+ function location() {
287
+ return peg$computeLocation(peg$savedPos, peg$currPos);
288
+ }
289
+
290
+ function expected(description, location) {
291
+ location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
292
+
293
+ throw peg$buildStructuredError(
294
+ [peg$otherExpectation(description)],
295
+ input.substring(peg$savedPos, peg$currPos),
296
+ location,
297
+ );
298
+ }
299
+
300
+ function error(message, location) {
301
+ location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
302
+
303
+ throw peg$buildSimpleError(message, location);
304
+ }
305
+
306
+ function peg$literalExpectation(text, ignoreCase) {
307
+ return { type: 'literal', text: text, ignoreCase: ignoreCase };
308
+ }
309
+
310
+ function peg$classExpectation(parts, inverted, ignoreCase) {
311
+ return { type: 'class', parts: parts, inverted: inverted, ignoreCase: ignoreCase };
312
+ }
313
+
314
+ function peg$anyExpectation() {
315
+ return { type: 'any' };
316
+ }
317
+
318
+ function peg$endExpectation() {
319
+ return { type: 'end' };
320
+ }
321
+
322
+ function peg$otherExpectation(description) {
323
+ return { type: 'other', description: description };
324
+ }
325
+
326
+ function peg$computePosDetails(pos) {
327
+ var details = peg$posDetailsCache[pos],
328
+ p;
329
+
330
+ if (details) {
331
+ return details;
332
+ } else {
333
+ p = pos - 1;
334
+ while (!peg$posDetailsCache[p]) {
335
+ p--;
336
+ }
337
+
338
+ details = peg$posDetailsCache[p];
339
+ details = {
340
+ line: details.line,
341
+ column: details.column,
342
+ };
343
+
344
+ while (p < pos) {
345
+ if (input.charCodeAt(p) === 10) {
346
+ details.line++;
347
+ details.column = 1;
348
+ } else {
349
+ details.column++;
350
+ }
351
+
352
+ p++;
353
+ }
354
+
355
+ peg$posDetailsCache[pos] = details;
356
+ return details;
357
+ }
358
+ }
359
+
360
+ function peg$computeLocation(startPos, endPos) {
361
+ var startPosDetails = peg$computePosDetails(startPos),
362
+ endPosDetails = peg$computePosDetails(endPos);
363
+
364
+ return {
365
+ start: {
366
+ offset: startPos,
367
+ line: startPosDetails.line,
368
+ column: startPosDetails.column,
369
+ },
370
+ end: {
371
+ offset: endPos,
372
+ line: endPosDetails.line,
373
+ column: endPosDetails.column,
374
+ },
375
+ };
376
+ }
377
+
378
+ function peg$fail(expected) {
379
+ if (peg$currPos < peg$maxFailPos) {
380
+ return;
381
+ }
382
+
383
+ if (peg$currPos > peg$maxFailPos) {
384
+ peg$maxFailPos = peg$currPos;
385
+ peg$maxFailExpected = [];
386
+ }
387
+
388
+ peg$maxFailExpected.push(expected);
389
+ }
390
+
391
+ function peg$buildSimpleError(message, location) {
392
+ return new peg$SyntaxError(message, null, null, location);
393
+ }
394
+
395
+ function peg$buildStructuredError(expected, found, location) {
396
+ return new peg$SyntaxError(
397
+ peg$SyntaxError.buildMessage(expected, found),
398
+ expected,
399
+ found,
400
+ location,
401
+ );
402
+ }
403
+
404
+ function peg$parsestart() {
405
+ var s0, s1;
406
+
407
+ s0 = peg$currPos;
408
+ s1 = peg$parseexpression();
409
+ if (s1 !== peg$FAILED) {
410
+ peg$savedPos = s0;
411
+ s1 = peg$c0(s1);
412
+ }
413
+ s0 = s1;
414
+ if (s0 === peg$FAILED) {
415
+ s0 = peg$currPos;
416
+ s1 = peg$parselistExpression();
417
+ if (s1 !== peg$FAILED) {
418
+ peg$savedPos = s0;
419
+ s1 = peg$c1(s1);
420
+ }
421
+ s0 = s1;
422
+ }
423
+
424
+ return s0;
425
+ }
426
+
427
+ function peg$parseexpression() {
428
+ var s0, s1, s2, s3, s4;
429
+
430
+ s0 = peg$currPos;
431
+ s1 = peg$parsename();
432
+ if (s1 !== peg$FAILED) {
433
+ s2 = peg$parseargs();
434
+ if (s2 === peg$FAILED) {
435
+ s2 = null;
436
+ }
437
+ if (s2 !== peg$FAILED) {
438
+ s3 = peg$parsealias();
439
+ if (s3 === peg$FAILED) {
440
+ s3 = null;
441
+ }
442
+ if (s3 !== peg$FAILED) {
443
+ s4 = peg$parsesubListExpression();
444
+ if (s4 !== peg$FAILED) {
445
+ peg$savedPos = s0;
446
+ s1 = peg$c2(s1, s2, s3, s4);
447
+ s0 = s1;
448
+ } else {
449
+ peg$currPos = s0;
450
+ s0 = peg$FAILED;
451
+ }
452
+ } else {
453
+ peg$currPos = s0;
454
+ s0 = peg$FAILED;
455
+ }
456
+ } else {
457
+ peg$currPos = s0;
458
+ s0 = peg$FAILED;
459
+ }
460
+ } else {
461
+ peg$currPos = s0;
462
+ s0 = peg$FAILED;
463
+ }
464
+ if (s0 === peg$FAILED) {
465
+ s0 = peg$currPos;
466
+ s1 = peg$parsename();
467
+ if (s1 !== peg$FAILED) {
468
+ s2 = peg$parseargs();
469
+ if (s2 === peg$FAILED) {
470
+ s2 = null;
471
+ }
472
+ if (s2 !== peg$FAILED) {
473
+ s3 = peg$parsealias();
474
+ if (s3 === peg$FAILED) {
475
+ s3 = null;
476
+ }
477
+ if (s3 !== peg$FAILED) {
478
+ s4 = peg$parsesubExpression();
479
+ if (s4 === peg$FAILED) {
480
+ s4 = null;
481
+ }
482
+ if (s4 !== peg$FAILED) {
483
+ peg$savedPos = s0;
484
+ s1 = peg$c3(s1, s2, s3, s4);
485
+ s0 = s1;
486
+ } else {
487
+ peg$currPos = s0;
488
+ s0 = peg$FAILED;
489
+ }
490
+ } else {
491
+ peg$currPos = s0;
492
+ s0 = peg$FAILED;
493
+ }
494
+ } else {
495
+ peg$currPos = s0;
496
+ s0 = peg$FAILED;
497
+ }
498
+ } else {
499
+ peg$currPos = s0;
500
+ s0 = peg$FAILED;
501
+ }
502
+ }
503
+
504
+ return s0;
505
+ }
506
+
507
+ function peg$parsealias() {
508
+ var s0, s1, s2, s3, s4;
509
+
510
+ s0 = peg$currPos;
511
+ s1 = [];
512
+ s2 = peg$parsews();
513
+ if (s2 !== peg$FAILED) {
514
+ while (s2 !== peg$FAILED) {
515
+ s1.push(s2);
516
+ s2 = peg$parsews();
517
+ }
518
+ } else {
519
+ s1 = peg$FAILED;
520
+ }
521
+ if (s1 !== peg$FAILED) {
522
+ if (input.substr(peg$currPos, 2) === peg$c4) {
523
+ s2 = peg$c4;
524
+ peg$currPos += 2;
525
+ } else {
526
+ s2 = peg$FAILED;
527
+ if (peg$silentFails === 0) {
528
+ peg$fail(peg$c5);
529
+ }
530
+ }
531
+ if (s2 !== peg$FAILED) {
532
+ s3 = [];
533
+ s4 = peg$parsews();
534
+ if (s4 !== peg$FAILED) {
535
+ while (s4 !== peg$FAILED) {
536
+ s3.push(s4);
537
+ s4 = peg$parsews();
538
+ }
539
+ } else {
540
+ s3 = peg$FAILED;
541
+ }
542
+ if (s3 !== peg$FAILED) {
543
+ s4 = peg$parsename();
544
+ if (s4 !== peg$FAILED) {
545
+ peg$savedPos = s0;
546
+ s1 = peg$c6(s4);
547
+ s0 = s1;
548
+ } else {
549
+ peg$currPos = s0;
550
+ s0 = peg$FAILED;
551
+ }
552
+ } else {
553
+ peg$currPos = s0;
554
+ s0 = peg$FAILED;
555
+ }
556
+ } else {
557
+ peg$currPos = s0;
558
+ s0 = peg$FAILED;
559
+ }
560
+ } else {
561
+ peg$currPos = s0;
562
+ s0 = peg$FAILED;
563
+ }
564
+
565
+ return s0;
566
+ }
567
+
568
+ function peg$parsename() {
569
+ var s0, s1, s2;
570
+
571
+ s0 = peg$currPos;
572
+ s1 = [];
573
+ s2 = peg$parsechar();
574
+ if (s2 !== peg$FAILED) {
575
+ while (s2 !== peg$FAILED) {
576
+ s1.push(s2);
577
+ s2 = peg$parsechar();
578
+ }
579
+ } else {
580
+ s1 = peg$FAILED;
581
+ }
582
+ if (s1 !== peg$FAILED) {
583
+ peg$savedPos = s0;
584
+ s1 = peg$c7(s1);
585
+ }
586
+ s0 = s1;
587
+
588
+ return s0;
589
+ }
590
+
591
+ function peg$parsechar() {
592
+ var s0;
593
+
594
+ if (peg$c8.test(input.charAt(peg$currPos))) {
595
+ s0 = input.charAt(peg$currPos);
596
+ peg$currPos++;
597
+ } else {
598
+ s0 = peg$FAILED;
599
+ if (peg$silentFails === 0) {
600
+ peg$fail(peg$c9);
601
+ }
602
+ }
603
+
604
+ return s0;
605
+ }
606
+
607
+ function peg$parseargs() {
608
+ var s0, s1, s2, s3, s4, s5;
609
+
610
+ s0 = peg$currPos;
611
+ s1 = [];
612
+ s2 = peg$parsews();
613
+ while (s2 !== peg$FAILED) {
614
+ s1.push(s2);
615
+ s2 = peg$parsews();
616
+ }
617
+ if (s1 !== peg$FAILED) {
618
+ if (input.charCodeAt(peg$currPos) === 40) {
619
+ s2 = peg$c10;
620
+ peg$currPos++;
621
+ } else {
622
+ s2 = peg$FAILED;
623
+ if (peg$silentFails === 0) {
624
+ peg$fail(peg$c11);
625
+ }
626
+ }
627
+ if (s2 !== peg$FAILED) {
628
+ s3 = [];
629
+ s4 = peg$parseargListItem();
630
+ while (s4 !== peg$FAILED) {
631
+ s3.push(s4);
632
+ s4 = peg$parseargListItem();
633
+ }
634
+ if (s3 !== peg$FAILED) {
635
+ s4 = [];
636
+ s5 = peg$parsews();
637
+ while (s5 !== peg$FAILED) {
638
+ s4.push(s5);
639
+ s5 = peg$parsews();
640
+ }
641
+ if (s4 !== peg$FAILED) {
642
+ if (input.charCodeAt(peg$currPos) === 41) {
643
+ s5 = peg$c12;
644
+ peg$currPos++;
645
+ } else {
646
+ s5 = peg$FAILED;
647
+ if (peg$silentFails === 0) {
648
+ peg$fail(peg$c13);
649
+ }
650
+ }
651
+ if (s5 !== peg$FAILED) {
652
+ peg$savedPos = s0;
653
+ s1 = peg$c14(s3);
654
+ s0 = s1;
655
+ } else {
656
+ peg$currPos = s0;
657
+ s0 = peg$FAILED;
658
+ }
659
+ } else {
660
+ peg$currPos = s0;
661
+ s0 = peg$FAILED;
662
+ }
663
+ } else {
664
+ peg$currPos = s0;
665
+ s0 = peg$FAILED;
666
+ }
667
+ } else {
668
+ peg$currPos = s0;
669
+ s0 = peg$FAILED;
670
+ }
671
+ } else {
672
+ peg$currPos = s0;
673
+ s0 = peg$FAILED;
674
+ }
675
+
676
+ return s0;
677
+ }
678
+
679
+ function peg$parseargListItem() {
680
+ var s0, s1, s2, s3, s4;
681
+
682
+ s0 = peg$currPos;
683
+ s1 = [];
684
+ s2 = peg$parsews();
685
+ while (s2 !== peg$FAILED) {
686
+ s1.push(s2);
687
+ s2 = peg$parsews();
688
+ }
689
+ if (s1 !== peg$FAILED) {
690
+ s2 = peg$parsename();
691
+ if (s2 !== peg$FAILED) {
692
+ s3 = [];
693
+ s4 = peg$parsews();
694
+ while (s4 !== peg$FAILED) {
695
+ s3.push(s4);
696
+ s4 = peg$parsews();
697
+ }
698
+ if (s3 !== peg$FAILED) {
699
+ if (input.charCodeAt(peg$currPos) === 44) {
700
+ s4 = peg$c15;
701
+ peg$currPos++;
702
+ } else {
703
+ s4 = peg$FAILED;
704
+ if (peg$silentFails === 0) {
705
+ peg$fail(peg$c16);
706
+ }
707
+ }
708
+ if (s4 === peg$FAILED) {
709
+ s4 = null;
710
+ }
711
+ if (s4 !== peg$FAILED) {
712
+ peg$savedPos = s0;
713
+ s1 = peg$c17(s2);
714
+ s0 = s1;
715
+ } else {
716
+ peg$currPos = s0;
717
+ s0 = peg$FAILED;
718
+ }
719
+ } else {
720
+ peg$currPos = s0;
721
+ s0 = peg$FAILED;
722
+ }
723
+ } else {
724
+ peg$currPos = s0;
725
+ s0 = peg$FAILED;
726
+ }
727
+ } else {
728
+ peg$currPos = s0;
729
+ s0 = peg$FAILED;
730
+ }
731
+
732
+ return s0;
733
+ }
734
+
735
+ function peg$parsews() {
736
+ var s0;
737
+
738
+ if (peg$c18.test(input.charAt(peg$currPos))) {
739
+ s0 = input.charAt(peg$currPos);
740
+ peg$currPos++;
741
+ } else {
742
+ s0 = peg$FAILED;
743
+ if (peg$silentFails === 0) {
744
+ peg$fail(peg$c19);
745
+ }
746
+ }
747
+
748
+ return s0;
749
+ }
750
+
751
+ function peg$parsesubListExpression() {
752
+ var s0, s1, s2, s3;
753
+
754
+ s0 = peg$currPos;
755
+ s1 = [];
756
+ s2 = peg$parsews();
757
+ while (s2 !== peg$FAILED) {
758
+ s1.push(s2);
759
+ s2 = peg$parsews();
760
+ }
761
+ if (s1 !== peg$FAILED) {
762
+ if (input.charCodeAt(peg$currPos) === 46) {
763
+ s2 = peg$c20;
764
+ peg$currPos++;
765
+ } else {
766
+ s2 = peg$FAILED;
767
+ if (peg$silentFails === 0) {
768
+ peg$fail(peg$c21);
769
+ }
770
+ }
771
+ if (s2 !== peg$FAILED) {
772
+ s3 = peg$parselistExpression();
773
+ if (s3 !== peg$FAILED) {
774
+ peg$savedPos = s0;
775
+ s1 = peg$c22(s3);
776
+ s0 = s1;
777
+ } else {
778
+ peg$currPos = s0;
779
+ s0 = peg$FAILED;
780
+ }
781
+ } else {
782
+ peg$currPos = s0;
783
+ s0 = peg$FAILED;
784
+ }
785
+ } else {
786
+ peg$currPos = s0;
787
+ s0 = peg$FAILED;
788
+ }
789
+
790
+ return s0;
791
+ }
792
+
793
+ function peg$parselistExpression() {
794
+ var s0, s1, s2, s3, s4, s5, s6, s7;
795
+
796
+ s0 = peg$currPos;
797
+ s1 = [];
798
+ s2 = peg$parsews();
799
+ while (s2 !== peg$FAILED) {
800
+ s1.push(s2);
801
+ s2 = peg$parsews();
802
+ }
803
+ if (s1 !== peg$FAILED) {
804
+ if (input.charCodeAt(peg$currPos) === 91) {
805
+ s2 = peg$c23;
806
+ peg$currPos++;
807
+ } else {
808
+ s2 = peg$FAILED;
809
+ if (peg$silentFails === 0) {
810
+ peg$fail(peg$c24);
811
+ }
812
+ }
813
+ if (s2 !== peg$FAILED) {
814
+ s3 = [];
815
+ s4 = peg$parselistExpressionItem();
816
+ while (s4 !== peg$FAILED) {
817
+ s3.push(s4);
818
+ s4 = peg$parselistExpressionItem();
819
+ }
820
+ if (s3 !== peg$FAILED) {
821
+ s4 = [];
822
+ s5 = peg$parsews();
823
+ while (s5 !== peg$FAILED) {
824
+ s4.push(s5);
825
+ s5 = peg$parsews();
826
+ }
827
+ if (s4 !== peg$FAILED) {
828
+ if (input.charCodeAt(peg$currPos) === 93) {
829
+ s5 = peg$c25;
830
+ peg$currPos++;
831
+ } else {
832
+ s5 = peg$FAILED;
833
+ if (peg$silentFails === 0) {
834
+ peg$fail(peg$c26);
835
+ }
836
+ }
837
+ if (s5 !== peg$FAILED) {
838
+ s6 = [];
839
+ s7 = peg$parsews();
840
+ while (s7 !== peg$FAILED) {
841
+ s6.push(s7);
842
+ s7 = peg$parsews();
843
+ }
844
+ if (s6 !== peg$FAILED) {
845
+ peg$savedPos = s0;
846
+ s1 = peg$c27(s3);
847
+ s0 = s1;
848
+ } else {
849
+ peg$currPos = s0;
850
+ s0 = peg$FAILED;
851
+ }
852
+ } else {
853
+ peg$currPos = s0;
854
+ s0 = peg$FAILED;
855
+ }
856
+ } else {
857
+ peg$currPos = s0;
858
+ s0 = peg$FAILED;
859
+ }
860
+ } else {
861
+ peg$currPos = s0;
862
+ s0 = peg$FAILED;
863
+ }
864
+ } else {
865
+ peg$currPos = s0;
866
+ s0 = peg$FAILED;
867
+ }
868
+ } else {
869
+ peg$currPos = s0;
870
+ s0 = peg$FAILED;
871
+ }
872
+
873
+ return s0;
874
+ }
875
+
876
+ function peg$parselistExpressionItem() {
877
+ var s0, s1, s2, s3, s4;
878
+
879
+ s0 = peg$currPos;
880
+ s1 = [];
881
+ s2 = peg$parsews();
882
+ while (s2 !== peg$FAILED) {
883
+ s1.push(s2);
884
+ s2 = peg$parsews();
885
+ }
886
+ if (s1 !== peg$FAILED) {
887
+ s2 = peg$parseexpression();
888
+ if (s2 !== peg$FAILED) {
889
+ s3 = [];
890
+ s4 = peg$parsews();
891
+ while (s4 !== peg$FAILED) {
892
+ s3.push(s4);
893
+ s4 = peg$parsews();
894
+ }
895
+ if (s3 !== peg$FAILED) {
896
+ if (input.charCodeAt(peg$currPos) === 44) {
897
+ s4 = peg$c15;
898
+ peg$currPos++;
899
+ } else {
900
+ s4 = peg$FAILED;
901
+ if (peg$silentFails === 0) {
902
+ peg$fail(peg$c16);
903
+ }
904
+ }
905
+ if (s4 === peg$FAILED) {
906
+ s4 = null;
907
+ }
908
+ if (s4 !== peg$FAILED) {
909
+ peg$savedPos = s0;
910
+ s1 = peg$c28(s2);
911
+ s0 = s1;
912
+ } else {
913
+ peg$currPos = s0;
914
+ s0 = peg$FAILED;
915
+ }
916
+ } else {
917
+ peg$currPos = s0;
918
+ s0 = peg$FAILED;
919
+ }
920
+ } else {
921
+ peg$currPos = s0;
922
+ s0 = peg$FAILED;
923
+ }
924
+ } else {
925
+ peg$currPos = s0;
926
+ s0 = peg$FAILED;
927
+ }
928
+
929
+ return s0;
930
+ }
931
+
932
+ function peg$parsesubExpression() {
933
+ var s0, s1, s2, s3, s4, s5, s6;
934
+
935
+ s0 = peg$currPos;
936
+ s1 = [];
937
+ s2 = peg$parsews();
938
+ while (s2 !== peg$FAILED) {
939
+ s1.push(s2);
940
+ s2 = peg$parsews();
941
+ }
942
+ if (s1 !== peg$FAILED) {
943
+ if (input.charCodeAt(peg$currPos) === 46) {
944
+ s2 = peg$c20;
945
+ peg$currPos++;
946
+ } else {
947
+ s2 = peg$FAILED;
948
+ if (peg$silentFails === 0) {
949
+ peg$fail(peg$c21);
950
+ }
951
+ }
952
+ if (s2 !== peg$FAILED) {
953
+ s3 = [];
954
+ s4 = peg$parsews();
955
+ while (s4 !== peg$FAILED) {
956
+ s3.push(s4);
957
+ s4 = peg$parsews();
958
+ }
959
+ if (s3 !== peg$FAILED) {
960
+ s4 = peg$parseexpression();
961
+ if (s4 !== peg$FAILED) {
962
+ s5 = [];
963
+ s6 = peg$parsews();
964
+ while (s6 !== peg$FAILED) {
965
+ s5.push(s6);
966
+ s6 = peg$parsews();
967
+ }
968
+ if (s5 !== peg$FAILED) {
969
+ peg$savedPos = s0;
970
+ s1 = peg$c29(s4);
971
+ s0 = s1;
972
+ } else {
973
+ peg$currPos = s0;
974
+ s0 = peg$FAILED;
975
+ }
976
+ } else {
977
+ peg$currPos = s0;
978
+ s0 = peg$FAILED;
979
+ }
980
+ } else {
981
+ peg$currPos = s0;
982
+ s0 = peg$FAILED;
983
+ }
984
+ } else {
985
+ peg$currPos = s0;
986
+ s0 = peg$FAILED;
987
+ }
988
+ } else {
989
+ peg$currPos = s0;
990
+ s0 = peg$FAILED;
991
+ }
992
+
993
+ return s0;
994
+ }
995
+
996
+ function assertDuplicateRelation(node, expr) {
997
+ if (expr.$name in node) {
998
+ console.warn(
999
+ `Duplicate relation "${expr.$name}" in a relation expression. You should use "a.[b, c]" instead of "[a.b, a.c]". This will cause an error in objection 2.0`,
1000
+ );
1001
+
1002
+ // TODO: enable for v2.0.
1003
+ // const err = new Error();
1004
+ // err.duplicateRelationName = expr.$name;
1005
+ // throw err;
1006
+ }
1007
+ }
1008
+
1009
+ function newNode() {
1010
+ return {
1011
+ $name: null,
1012
+ $relation: null,
1013
+ $modify: [],
1014
+ $recursive: false,
1015
+ $allRecursive: false,
1016
+ $childNames: [],
1017
+ };
1018
+ }
1019
+
1020
+ peg$result = peg$startRuleFunction();
1021
+
1022
+ if (peg$result !== peg$FAILED && peg$currPos === input.length) {
1023
+ return peg$result;
1024
+ } else {
1025
+ if (peg$result !== peg$FAILED && peg$currPos < input.length) {
1026
+ peg$fail(peg$endExpectation());
1027
+ }
1028
+
1029
+ throw peg$buildStructuredError(
1030
+ peg$maxFailExpected,
1031
+ peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
1032
+ peg$maxFailPos < input.length
1033
+ ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
1034
+ : peg$computeLocation(peg$maxFailPos, peg$maxFailPos),
1035
+ );
1036
+ }
1037
+ }
1038
+
1039
+ module.exports = {
1040
+ SyntaxError: peg$SyntaxError,
1041
+ parse: peg$parse,
1042
+ };