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